jiren 1.1.0 → 1.1.5

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.
@@ -1,105 +0,0 @@
1
- import type {
2
- RequestOptions,
3
- GetRequestOptions,
4
- PostRequestOptions,
5
- HttpResponse,
6
- } from "../types/index.js";
7
-
8
- /**
9
- * Node.js fallback client using native fetch
10
- */
11
- export class NodeJirenClient {
12
- constructor() {
13
- // No initialization needed for Node.js fetch
14
- }
15
-
16
- public close(): void {
17
- // No cleanup needed
18
- }
19
-
20
- public async request(
21
- url: string,
22
- options: RequestOptions = {}
23
- ): Promise<HttpResponse> {
24
- const method = options.method || "GET";
25
- const headers = options.headers || {};
26
-
27
- const fetchOptions: RequestInit = {
28
- method,
29
- headers,
30
- redirect:
31
- options.maxRedirects && options.maxRedirects > 0 ? "follow" : "manual",
32
- };
33
-
34
- if (options.body) {
35
- fetchOptions.body =
36
- typeof options.body === "string"
37
- ? options.body
38
- : JSON.stringify(options.body);
39
- }
40
-
41
- try {
42
- const response = await fetch(url, fetchOptions);
43
- const body = await response.text();
44
-
45
- // Convert Headers to plain object
46
- const responseHeaders: Record<string, string> = {};
47
- response.headers.forEach((value, key) => {
48
- responseHeaders[key.toLowerCase()] = value;
49
- });
50
-
51
- return {
52
- status: response.status,
53
- body,
54
- headers: responseHeaders,
55
- json: <T = any>() => {
56
- if (!body) return null as T;
57
- return JSON.parse(body) as T;
58
- },
59
- };
60
- } catch (error) {
61
- throw new Error(`HTTP request failed: ${error}`);
62
- }
63
- }
64
-
65
- public async get(url: string, options: GetRequestOptions = {}) {
66
- return this.request(url, { ...options, method: "GET" });
67
- }
68
-
69
- public async post(
70
- url: string,
71
- body: string | object,
72
- options: PostRequestOptions = {}
73
- ) {
74
- return this.request(url, { ...options, method: "POST", body });
75
- }
76
-
77
- public async put(
78
- url: string,
79
- body: string | object,
80
- options: PostRequestOptions = {}
81
- ) {
82
- return this.request(url, { ...options, method: "PUT", body });
83
- }
84
-
85
- public async delete(url: string, options: GetRequestOptions = {}) {
86
- return this.request(url, { ...options, method: "DELETE" });
87
- }
88
-
89
- public async patch(
90
- url: string,
91
- body: string | object,
92
- options: PostRequestOptions = {}
93
- ) {
94
- return this.request(url, { ...options, method: "PATCH", body });
95
- }
96
-
97
- public async head(url: string, options: GetRequestOptions = {}) {
98
- return this.request(url, { ...options, method: "HEAD" });
99
- }
100
-
101
- public prefetch(urls: string[]) {
102
- // No-op in Node.js
103
- // Could implement DNS prefetch here if needed
104
- }
105
- }
@@ -1,11 +0,0 @@
1
- // Runtime detection
2
- export const isBun = typeof Bun !== "undefined";
3
- export const isNode = !isBun && typeof process !== "undefined";
4
-
5
- // Re-export types
6
- export type {
7
- HttpResponse,
8
- RequestOptions,
9
- GetRequestOptions,
10
- PostRequestOptions,
11
- } from "../types/index.js";
package/dist/index.js DELETED
@@ -1,271 +0,0 @@
1
- // @bun
2
- var __defProp = Object.defineProperty;
3
- var __export = (target, all) => {
4
- for (var name in all)
5
- __defProp(target, name, {
6
- get: all[name],
7
- enumerable: true,
8
- configurable: true,
9
- set: (newValue) => all[name] = () => newValue
10
- });
11
- };
12
- var __esm = (fn, res) => () => (fn && (res = fn(fn = 0)), res);
13
-
14
- // components/native.ts
15
- import { dlopen, FFIType, suffix } from "bun:ffi";
16
- import { join } from "path";
17
- var libPath, ffiDef, lib;
18
- var init_native = __esm(() => {
19
- libPath = join(import.meta.dir, `../lib/libhttpclient.${suffix}`);
20
- ffiDef = {
21
- zclient_new: {
22
- args: [],
23
- returns: FFIType.ptr
24
- },
25
- zclient_free: {
26
- args: [FFIType.ptr],
27
- returns: FFIType.void
28
- },
29
- zclient_get: {
30
- args: [FFIType.ptr, FFIType.cstring],
31
- returns: FFIType.ptr
32
- },
33
- zclient_post: {
34
- args: [FFIType.ptr, FFIType.cstring, FFIType.cstring],
35
- returns: FFIType.ptr
36
- },
37
- zclient_prefetch: {
38
- args: [FFIType.ptr, FFIType.cstring],
39
- returns: FFIType.void
40
- },
41
- zclient_response_status: {
42
- args: [FFIType.ptr],
43
- returns: FFIType.u16
44
- },
45
- zclient_response_body: {
46
- args: [FFIType.ptr],
47
- returns: FFIType.ptr
48
- },
49
- zclient_response_body_len: {
50
- args: [FFIType.ptr],
51
- returns: FFIType.u64
52
- },
53
- zclient_response_headers: {
54
- args: [FFIType.ptr],
55
- returns: FFIType.ptr
56
- },
57
- zclient_response_headers_len: {
58
- args: [FFIType.ptr],
59
- returns: FFIType.u64
60
- },
61
- zclient_response_free: {
62
- args: [FFIType.ptr],
63
- returns: FFIType.void
64
- },
65
- zclient_request: {
66
- args: [
67
- FFIType.ptr,
68
- FFIType.cstring,
69
- FFIType.cstring,
70
- FFIType.cstring,
71
- FFIType.cstring
72
- ],
73
- returns: FFIType.ptr
74
- }
75
- };
76
- lib = dlopen(libPath, ffiDef);
77
- });
78
-
79
- // components/client-bun.ts
80
- var exports_client_bun = {};
81
- __export(exports_client_bun, {
82
- JirenClient: () => JirenClient
83
- });
84
- import { CString } from "bun:ffi";
85
-
86
- class JirenClient {
87
- ptr;
88
- constructor() {
89
- this.ptr = lib.symbols.zclient_new();
90
- if (!this.ptr)
91
- throw new Error("Failed to create native client instance");
92
- }
93
- close() {
94
- if (this.ptr) {
95
- lib.symbols.zclient_free(this.ptr);
96
- this.ptr = null;
97
- }
98
- }
99
- request(url, options = {}) {
100
- if (!this.ptr)
101
- throw new Error("Client is closed");
102
- const method = options.method || "GET";
103
- const methodBuffer = Buffer.from(method + "\x00");
104
- const urlBuffer = Buffer.from(url + "\x00");
105
- let headersBuffer = null;
106
- if (options.headers) {
107
- const headerStr = Object.entries(options.headers).map(([k, v]) => `${k.toLowerCase()}: ${v}`).join(`\r
108
- `);
109
- if (headerStr.length > 0) {
110
- headersBuffer = Buffer.from(headerStr + "\x00");
111
- }
112
- }
113
- let bodyBuffer = null;
114
- if (options.body) {
115
- const bodyStr = typeof options.body === "string" ? options.body : JSON.stringify(options.body);
116
- bodyBuffer = Buffer.from(bodyStr + "\x00");
117
- }
118
- const respPtr = lib.symbols.zclient_request(this.ptr, methodBuffer, urlBuffer, headersBuffer, bodyBuffer);
119
- const response = this.parseResponse(respPtr);
120
- if (options.maxRedirects && options.maxRedirects > 0 && response.status >= 300 && response.status < 400 && response.headers && response.headers["location"]) {
121
- const location = response.headers["location"];
122
- const newUrl = new URL(location, url).toString();
123
- const newOptions = { ...options, maxRedirects: options.maxRedirects - 1 };
124
- return this.request(newUrl, newOptions);
125
- }
126
- return response;
127
- }
128
- get(url, options = {}) {
129
- return this.request(url, { ...options, method: "GET" });
130
- }
131
- post(url, body, options = {}) {
132
- return this.request(url, { ...options, method: "POST", body });
133
- }
134
- put(url, body, options = {}) {
135
- return this.request(url, { ...options, method: "PUT", body });
136
- }
137
- delete(url, options = {}) {
138
- return this.request(url, { ...options, method: "DELETE" });
139
- }
140
- patch(url, body, options = {}) {
141
- return this.request(url, { ...options, method: "PATCH", body });
142
- }
143
- head(url, options = {}) {
144
- return this.request(url, { ...options, method: "HEAD" });
145
- }
146
- prefetch(urls) {
147
- if (!this.ptr)
148
- throw new Error("Client is closed");
149
- for (const url of urls) {
150
- const urlBuffer = Buffer.from(url + "\x00");
151
- lib.symbols.zclient_prefetch(this.ptr, urlBuffer);
152
- }
153
- }
154
- parseResponse(respPtr) {
155
- if (!respPtr)
156
- throw new Error("Native request failed (returned null pointer)");
157
- try {
158
- const status = lib.symbols.zclient_response_status(respPtr);
159
- const bodyLen = Number(lib.symbols.zclient_response_body_len(respPtr));
160
- const bodyPtr = lib.symbols.zclient_response_body(respPtr);
161
- const headersLen = Number(lib.symbols.zclient_response_headers_len(respPtr));
162
- const headersPtr = lib.symbols.zclient_response_headers(respPtr);
163
- let bodyString = "";
164
- if (bodyLen > 0 && bodyPtr) {
165
- bodyString = new CString(bodyPtr).toString();
166
- }
167
- const headers = {};
168
- if (headersLen > 0 && headersPtr) {
169
- const headersStr = new CString(headersPtr).toString();
170
- const lines = headersStr.split(`\r
171
- `);
172
- for (const line of lines) {
173
- if (!line)
174
- continue;
175
- const colonIdx = line.indexOf(":");
176
- if (colonIdx !== -1) {
177
- const key = line.substring(0, colonIdx).trim().toLowerCase();
178
- const val = line.substring(colonIdx + 1).trim();
179
- headers[key] = val;
180
- }
181
- }
182
- }
183
- return {
184
- status,
185
- body: bodyString,
186
- headers,
187
- json: () => {
188
- if (!bodyString)
189
- return null;
190
- return JSON.parse(bodyString);
191
- }
192
- };
193
- } finally {
194
- lib.symbols.zclient_response_free(respPtr);
195
- }
196
- }
197
- }
198
- var init_client_bun = __esm(() => {
199
- init_native();
200
- });
201
-
202
- // components/client-node.ts
203
- var exports_client_node = {};
204
- __export(exports_client_node, {
205
- NodeJirenClient: () => NodeJirenClient
206
- });
207
-
208
- class NodeJirenClient {
209
- constructor() {}
210
- close() {}
211
- async request(url, options = {}) {
212
- const method = options.method || "GET";
213
- const headers = options.headers || {};
214
- const fetchOptions = {
215
- method,
216
- headers,
217
- redirect: options.maxRedirects && options.maxRedirects > 0 ? "follow" : "manual"
218
- };
219
- if (options.body) {
220
- fetchOptions.body = typeof options.body === "string" ? options.body : JSON.stringify(options.body);
221
- }
222
- try {
223
- const response = await fetch(url, fetchOptions);
224
- const body = await response.text();
225
- const responseHeaders = {};
226
- response.headers.forEach((value, key) => {
227
- responseHeaders[key.toLowerCase()] = value;
228
- });
229
- return {
230
- status: response.status,
231
- body,
232
- headers: responseHeaders,
233
- json: () => {
234
- if (!body)
235
- return null;
236
- return JSON.parse(body);
237
- }
238
- };
239
- } catch (error) {
240
- throw new Error(`HTTP request failed: ${error}`);
241
- }
242
- }
243
- async get(url, options = {}) {
244
- return this.request(url, { ...options, method: "GET" });
245
- }
246
- async post(url, body, options = {}) {
247
- return this.request(url, { ...options, method: "POST", body });
248
- }
249
- async put(url, body, options = {}) {
250
- return this.request(url, { ...options, method: "PUT", body });
251
- }
252
- async delete(url, options = {}) {
253
- return this.request(url, { ...options, method: "DELETE" });
254
- }
255
- async patch(url, body, options = {}) {
256
- return this.request(url, { ...options, method: "PATCH", body });
257
- }
258
- async head(url, options = {}) {
259
- return this.request(url, { ...options, method: "HEAD" });
260
- }
261
- prefetch(urls) {}
262
- }
263
-
264
- // components/runtime.ts
265
- var isBun = typeof Bun !== "undefined";
266
-
267
- // components/index.ts
268
- var JirenClient2 = isBun ? (await Promise.resolve().then(() => (init_client_bun(), exports_client_bun))).JirenClient : (await Promise.resolve().then(() => exports_client_node)).NodeJirenClient;
269
- export {
270
- JirenClient2 as JirenClient
271
- };