@gjsify/http 0.4.34 → 0.4.36

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.
@@ -0,0 +1 @@
1
+ import"./_virtual/_rolldown/runtime.js";import{EventEmitter as e}from"@gjsify/events";const t=`ACL.BIND.CHECKOUT.CONNECT.COPY.DELETE.GET.HEAD.LINK.LOCK.M-SEARCH.MERGE.MKACTIVITY.MKCALENDAR.MKCOL.MOVE.NOTIFY.OPTIONS.PATCH.POST.PROPFIND.PROPPATCH.PURGE.PUT.REBIND.REPORT.SEARCH.SOURCE.SUBSCRIBE.TRACE.UNBIND.UNLINK.UNLOCK.UNSUBSCRIBE`.split(`.`),n={100:`Continue`,101:`Switching Protocols`,102:`Processing`,103:`Early Hints`,200:`OK`,201:`Created`,202:`Accepted`,203:`Non-Authoritative Information`,204:`No Content`,205:`Reset Content`,206:`Partial Content`,207:`Multi-Status`,208:`Already Reported`,226:`IM Used`,300:`Multiple Choices`,301:`Moved Permanently`,302:`Found`,303:`See Other`,304:`Not Modified`,305:`Use Proxy`,307:`Temporary Redirect`,308:`Permanent Redirect`,400:`Bad Request`,401:`Unauthorized`,402:`Payment Required`,403:`Forbidden`,404:`Not Found`,405:`Method Not Allowed`,406:`Not Acceptable`,407:`Proxy Authentication Required`,408:`Request Timeout`,409:`Conflict`,410:`Gone`,411:`Length Required`,412:`Precondition Failed`,413:`Payload Too Large`,414:`URI Too Long`,415:`Unsupported Media Type`,416:`Range Not Satisfiable`,417:`Expectation Failed`,418:`I'm a Teapot`,421:`Misdirected Request`,422:`Unprocessable Entity`,423:`Locked`,424:`Failed Dependency`,425:`Too Early`,426:`Upgrade Required`,428:`Precondition Required`,429:`Too Many Requests`,431:`Request Header Fields Too Large`,451:`Unavailable For Legal Reasons`,500:`Internal Server Error`,501:`Not Implemented`,502:`Bad Gateway`,503:`Service Unavailable`,504:`Gateway Timeout`,505:`HTTP Version Not Supported`,506:`Variant Also Negotiates`,507:`Insufficient Storage`,508:`Loop Detected`,509:`Bandwidth Limit Exceeded`,510:`Not Extended`,511:`Network Authentication Required`},r=16384;var Agent=class extends e{maxSockets=1/0;maxFreeSockets=256;maxTotalSockets=1/0;sockets={};freeSockets={};requests={};destroy(){}};const i=new Agent;function urlToOptions(e){return{protocol:e.protocol,hostname:e.hostname,host:e.host,port:e.port,path:`${e.pathname}${e.search}`,auth:e.username||e.password?`${e.username}:${e.password}`:void 0}}function buildUrl(e){return`${e.protocol||`http:`}//${e.hostname||e.host||`localhost`}${e.port?`:${e.port}`:``}${e.path||`/`}`}var IncomingMessage=class extends e{statusCode;statusMessage;httpVersion=`1.1`;httpVersionMajor=1;httpVersionMinor=1;headers={};rawHeaders=[];trailers={};rawTrailers=[];url=``;method;readable=!0;destroyed=!1;complete=!1;constructor(e){super(),this.statusCode=e.status,this.statusMessage=e.statusText,e.headers.forEach((e,t)=>{this.headers[t.toLowerCase()]=e,this.rawHeaders.push(t,e)})}setEncoding(e){return this}pause(){return this}resume(){return this}destroy(e){return this.destroyed?this:(this.destroyed=!0,this.readable=!1,queueMicrotask(()=>{e&&this.emit(`error`,e),this.emit(`close`)}),this)}},ClientRequest=class extends e{method;path;_url;_headers;_bodyChunks=[];_started=!1;_ended=!1;_aborted=!1;_signal;_abortCtrl=new AbortController;_responseCb;socket=null;connection=null;writable=!0;destroyed=!1;constructor(e,t){if(super(),this.method=(e.method||`GET`).toUpperCase(),this.path=e.path||`/`,this._url=buildUrl(e),this._headers=e.headers?{...e.headers}:{},this._signal=e.signal,t&&(this._responseCb=t,this.once(`response`,t)),this._signal){let onAbort=()=>this.abort();this._signal.aborted?queueMicrotask(onAbort):this._signal.addEventListener(`abort`,onAbort,{once:!0})}}setHeader(e,t){return this._headers[e]=t,this}getHeader(e){return this._headers[e]}removeHeader(e){delete this._headers[e]}write(e,t,n){if(this._ended)return!1;let r=typeof t==`function`?t:n,i=typeof e==`string`?new TextEncoder().encode(e):e;return this._bodyChunks.push(i),r&&queueMicrotask(r),!0}end(e,t,n){if(this._ended)return this;e&&this.write(e,typeof t==`string`?t:void 0);let r=typeof t==`function`?t:n;return this._ended=!0,queueMicrotask(()=>this._flush(r)),this}abort(){this._aborted||(this._aborted=!0,this._abortCtrl.abort(),this.emit(`abort`))}destroy(e){return this.destroyed?this:(this.destroyed=!0,this._abortCtrl.abort(),e&&queueMicrotask(()=>this.emit(`error`,e)),this)}setTimeout(e,t){return t&&this.once(`timeout`,t),setTimeout(()=>this.emit(`timeout`),e),this}setNoDelay(e){}setSocketKeepAlive(e,t){}flushHeaders(){}async _flush(e){if(this._started)return;this._started=!0;let t=this._bodyChunks.length>0?new Blob(this._bodyChunks):void 0;try{let n=await fetch(this._url,{method:this.method,headers:this._normalizeHeaders(),body:t,signal:this._abortCtrl.signal,credentials:`same-origin`}),r=new IncomingMessage(n);this.emit(`response`,r),e&&queueMicrotask(e);let i=n.body?.getReader();if(!i){r.complete=!0,queueMicrotask(()=>r.emit(`end`));return}let pump=async()=>{try{for(;;){let{done:e,value:t}=await i.read();if(e)break;r.emit(`data`,t)}r.complete=!0,r.emit(`end`),r.emit(`close`)}catch(e){r.emit(`error`,e)}};pump()}catch(e){if(this._aborted)return;queueMicrotask(()=>this.emit(`error`,e))}}_normalizeHeaders(){let e={};for(let[t,n]of Object.entries(this._headers))e[t]=Array.isArray(n)?n.join(`, `):String(n);return e}};function request(e,t,n){let r,i;return typeof e==`string`||e instanceof URL?(r={...urlToOptions(typeof e==`string`?new URL(e):e),...typeof t==`object`?t:{}},i=typeof t==`function`?t:n):(r=e,i=typeof t==`function`?t:void 0),new ClientRequest(r,i)}function get(e,t,n){let r=request(e,t,n);return r.end(),r}function notSupported(e){let t=Error(`http.${e} is not supported in the browser`);throw t.code=`ENOTSUP`,t.errno=-45,t.syscall=e,t}var Server=class extends e{constructor(){super(),notSupported(`Server`)}},ServerResponse=class extends e{constructor(){super(),notSupported(`ServerResponse`)}},OutgoingMessage=class extends e{constructor(){super(),notSupported(`OutgoingMessage`)}};function createServer(...e){return notSupported(`createServer`)}function validateHeaderName(e){}function validateHeaderValue(e,t){}function setMaxIdleHTTPParsers(e){}const a={METHODS:t,STATUS_CODES:n,maxHeaderSize:r,Agent,globalAgent:i,IncomingMessage,ClientRequest,Server,ServerResponse,OutgoingMessage,createServer,request,get,validateHeaderName,validateHeaderValue,setMaxIdleHTTPParsers};export{Agent,ClientRequest,IncomingMessage,t as METHODS,OutgoingMessage,n as STATUS_CODES,Server,ServerResponse,createServer,a as default,get,i as globalAgent,r as maxHeaderSize,request,setMaxIdleHTTPParsers,validateHeaderName,validateHeaderValue};
@@ -0,0 +1,118 @@
1
+ import { EventEmitter } from '@gjsify/events';
2
+ export declare const METHODS: string[];
3
+ export declare const STATUS_CODES: Record<number, string>;
4
+ export declare const maxHeaderSize = 16384;
5
+ export declare class Agent extends EventEmitter {
6
+ maxSockets: number;
7
+ maxFreeSockets: number;
8
+ maxTotalSockets: number;
9
+ sockets: Record<string, unknown[]>;
10
+ freeSockets: Record<string, unknown[]>;
11
+ requests: Record<string, unknown[]>;
12
+ destroy(): void;
13
+ }
14
+ export declare const globalAgent: Agent;
15
+ export interface RequestOptions {
16
+ protocol?: string;
17
+ host?: string;
18
+ hostname?: string;
19
+ family?: number;
20
+ port?: number | string;
21
+ defaultPort?: number | string;
22
+ localAddress?: string;
23
+ socketPath?: string;
24
+ method?: string;
25
+ path?: string;
26
+ headers?: Record<string, string | string[]>;
27
+ auth?: string;
28
+ agent?: Agent | boolean;
29
+ timeout?: number;
30
+ signal?: AbortSignal;
31
+ setHost?: boolean;
32
+ }
33
+ export declare class IncomingMessage extends EventEmitter {
34
+ statusCode: number;
35
+ statusMessage: string;
36
+ httpVersion: string;
37
+ httpVersionMajor: number;
38
+ httpVersionMinor: number;
39
+ headers: Record<string, string>;
40
+ rawHeaders: string[];
41
+ trailers: Record<string, string>;
42
+ rawTrailers: string[];
43
+ url: string;
44
+ method?: string;
45
+ readable: boolean;
46
+ destroyed: boolean;
47
+ complete: boolean;
48
+ constructor(response: Response);
49
+ setEncoding(_enc: string): this;
50
+ pause(): this;
51
+ resume(): this;
52
+ destroy(err?: Error): this;
53
+ }
54
+ export declare class ClientRequest extends EventEmitter {
55
+ method: string;
56
+ path: string;
57
+ private _url;
58
+ private _headers;
59
+ private _bodyChunks;
60
+ private _started;
61
+ private _ended;
62
+ private _aborted;
63
+ private _signal?;
64
+ private _abortCtrl;
65
+ private _responseCb?;
66
+ socket: any;
67
+ connection: any;
68
+ writable: boolean;
69
+ destroyed: boolean;
70
+ constructor(options: RequestOptions, callback?: (res: IncomingMessage) => void);
71
+ setHeader(name: string, value: string | string[]): this;
72
+ getHeader(name: string): string | string[] | undefined;
73
+ removeHeader(name: string): void;
74
+ write(chunk: string | Uint8Array, encOrCb?: string | (() => void), cb?: () => void): boolean;
75
+ end(chunk?: string | Uint8Array, encOrCb?: string | (() => void), cb?: () => void): this;
76
+ abort(): void;
77
+ destroy(err?: Error): this;
78
+ setTimeout(msec: number, cb?: () => void): this;
79
+ setNoDelay(_noDelay?: boolean): void;
80
+ setSocketKeepAlive(_enable?: boolean, _delay?: number): void;
81
+ flushHeaders(): void;
82
+ private _flush;
83
+ private _normalizeHeaders;
84
+ }
85
+ export declare function request(urlOrOptions: string | URL | RequestOptions, optsOrCb?: RequestOptions | ((res: IncomingMessage) => void), maybeCb?: (res: IncomingMessage) => void): ClientRequest;
86
+ export declare function get(urlOrOptions: string | URL | RequestOptions, optsOrCb?: RequestOptions | ((res: IncomingMessage) => void), maybeCb?: (res: IncomingMessage) => void): ClientRequest;
87
+ export declare class Server extends EventEmitter {
88
+ constructor();
89
+ }
90
+ export declare class ServerResponse extends EventEmitter {
91
+ constructor();
92
+ }
93
+ export declare class OutgoingMessage extends EventEmitter {
94
+ constructor();
95
+ }
96
+ export declare function createServer(..._args: unknown[]): Server;
97
+ export declare function validateHeaderName(_name: string): void;
98
+ export declare function validateHeaderValue(_name: string, _value: string): void;
99
+ export declare function setMaxIdleHTTPParsers(_max: number): void;
100
+ declare const httpDefault: {
101
+ METHODS: string[];
102
+ STATUS_CODES: Record<number, string>;
103
+ maxHeaderSize: number;
104
+ Agent: typeof Agent;
105
+ globalAgent: Agent;
106
+ IncomingMessage: typeof IncomingMessage;
107
+ ClientRequest: typeof ClientRequest;
108
+ Server: typeof Server;
109
+ ServerResponse: typeof ServerResponse;
110
+ OutgoingMessage: typeof OutgoingMessage;
111
+ createServer: typeof createServer;
112
+ request: typeof request;
113
+ get: typeof get;
114
+ validateHeaderName: typeof validateHeaderName;
115
+ validateHeaderValue: typeof validateHeaderValue;
116
+ setMaxIdleHTTPParsers: typeof setMaxIdleHTTPParsers;
117
+ };
118
+ export default httpDefault;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gjsify/http",
3
- "version": "0.4.34",
3
+ "version": "0.4.36",
4
4
  "description": "Node.js http module for Gjs",
5
5
  "module": "lib/esm/index.js",
6
6
  "types": "lib/types/index.d.ts",
@@ -13,6 +13,10 @@
13
13
  "types": "./lib/types/index.d.ts",
14
14
  "default": "./lib/esm/index.js"
15
15
  },
16
+ "./browser": {
17
+ "types": "./lib/types/browser.d.ts",
18
+ "default": "./lib/esm/browser.js"
19
+ },
16
20
  "./validators": {
17
21
  "types": "./lib/types/validators.d.ts",
18
22
  "default": "./lib/esm/validators.js"
@@ -37,28 +41,38 @@
37
41
  "http"
38
42
  ],
39
43
  "devDependencies": {
40
- "@gjsify/cli": "^0.4.34",
41
- "@gjsify/unit": "^0.4.34",
44
+ "@gjsify/cli": "^0.4.36",
45
+ "@gjsify/unit": "^0.4.36",
42
46
  "@types/node": "^25.9.1",
43
- "typescript": "^6.0.3"
47
+ "typescript": "^5.9.3"
44
48
  },
45
49
  "dependencies": {
46
- "@girs/gio-2.0": "2.88.0-4.0.1",
47
- "@girs/glib-2.0": "2.88.0-4.0.1",
48
- "@girs/soup-3.0": "3.6.6-4.0.1",
49
- "@gjsify/buffer": "^0.4.34",
50
- "@gjsify/events": "^0.4.34",
51
- "@gjsify/http-soup-bridge": "^0.4.34",
52
- "@gjsify/net": "^0.4.34",
53
- "@gjsify/stream": "^0.4.34",
54
- "@gjsify/url": "^0.4.34",
55
- "@gjsify/utils": "^0.4.34"
50
+ "@girs/gio-2.0": "2.88.0-4.0.4",
51
+ "@girs/glib-2.0": "2.88.0-4.0.4",
52
+ "@girs/soup-3.0": "3.6.6-4.0.4",
53
+ "@gjsify/buffer": "^0.4.36",
54
+ "@gjsify/events": "^0.4.36",
55
+ "@gjsify/http-soup-bridge": "^0.4.36",
56
+ "@gjsify/net": "^0.4.36",
57
+ "@gjsify/stream": "^0.4.36",
58
+ "@gjsify/url": "^0.4.36",
59
+ "@gjsify/utils": "^0.4.36"
56
60
  },
57
61
  "gjsify": {
58
62
  "runtimes": {
59
63
  "gjs": "polyfill",
60
64
  "node": "none",
61
- "browser": "none"
65
+ "browser": "partial"
62
66
  }
63
- }
67
+ },
68
+ "license": "MIT",
69
+ "repository": {
70
+ "type": "git",
71
+ "url": "git+https://github.com/gjsify/gjsify.git",
72
+ "directory": "packages/node/http"
73
+ },
74
+ "bugs": {
75
+ "url": "https://github.com/gjsify/gjsify/issues"
76
+ },
77
+ "homepage": "https://github.com/gjsify/gjsify/tree/main/packages/node/http#readme"
64
78
  }