jiren 1.5.5 → 1.6.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.
Files changed (45) hide show
  1. package/README.md +123 -313
  2. package/components/cache.ts +1 -1
  3. package/components/client-node-native.ts +602 -159
  4. package/components/client.ts +51 -29
  5. package/components/metrics.ts +1 -4
  6. package/components/native-node.ts +48 -3
  7. package/components/native.ts +29 -0
  8. package/components/persistent-worker.ts +73 -0
  9. package/components/subprocess-worker.ts +65 -0
  10. package/components/types.ts +2 -0
  11. package/components/worker-pool.ts +169 -0
  12. package/components/worker.ts +39 -23
  13. package/dist/components/cache.d.ts +76 -0
  14. package/dist/components/cache.d.ts.map +1 -0
  15. package/dist/components/cache.js +439 -0
  16. package/dist/components/cache.js.map +1 -0
  17. package/dist/components/client-node-native.d.ts +134 -0
  18. package/dist/components/client-node-native.d.ts.map +1 -0
  19. package/dist/components/client-node-native.js +811 -0
  20. package/dist/components/client-node-native.js.map +1 -0
  21. package/dist/components/metrics.d.ts +104 -0
  22. package/dist/components/metrics.d.ts.map +1 -0
  23. package/dist/components/metrics.js +296 -0
  24. package/dist/components/metrics.js.map +1 -0
  25. package/dist/components/native-node.d.ts +67 -0
  26. package/dist/components/native-node.d.ts.map +1 -0
  27. package/dist/components/native-node.js +137 -0
  28. package/dist/components/native-node.js.map +1 -0
  29. package/dist/components/types.d.ts +252 -0
  30. package/dist/components/types.d.ts.map +1 -0
  31. package/dist/components/types.js +5 -0
  32. package/dist/components/types.js.map +1 -0
  33. package/dist/index-node.d.ts +10 -0
  34. package/dist/index-node.d.ts.map +1 -0
  35. package/dist/index-node.js +12 -0
  36. package/dist/index-node.js.map +1 -0
  37. package/dist/types/index.d.ts +63 -0
  38. package/dist/types/index.d.ts.map +1 -0
  39. package/dist/types/index.js +6 -0
  40. package/dist/types/index.js.map +1 -0
  41. package/index-node.ts +6 -6
  42. package/index.ts +4 -3
  43. package/lib/libhttpclient.dylib +0 -0
  44. package/package.json +15 -8
  45. package/types/index.ts +0 -68
@@ -0,0 +1,134 @@
1
+ import type { RequestOptions, JirenResponse, TargetUrlConfig, UrlEndpoint, CacheConfig, RetryConfig, Interceptors, MetricsAPI } from "./types.js";
2
+ /** URL configuration with optional cache and antibot */
3
+ export type UrlConfig = string | {
4
+ url: string;
5
+ cache?: boolean | CacheConfig;
6
+ antibot?: boolean;
7
+ };
8
+ /** Options for JirenClient constructor */
9
+ export interface JirenClientOptions<T extends readonly TargetUrlConfig[] | Record<string, UrlConfig> = readonly TargetUrlConfig[] | Record<string, UrlConfig>> {
10
+ /** Target URLs to pre-connect on client creation */
11
+ targets?: string[] | T;
12
+ /** Enable benchmark mode (Force HTTP/2, disable probing) */
13
+ benchmark?: boolean;
14
+ /** Global retry configuration */
15
+ retry?: number | RetryConfig;
16
+ /** Request/response interceptors */
17
+ interceptors?: Interceptors;
18
+ /** Performance mode: disable metrics, skip cache checks for non-cached endpoints (default: true) */
19
+ performanceMode?: boolean;
20
+ /** Enable default browser emulation headers (default: true) */
21
+ defaultHeaders?: boolean;
22
+ }
23
+ export type ExtractTargetKeys<T extends readonly TargetUrlConfig[] | Record<string, UrlConfig>> = T extends readonly TargetUrlConfig[] ? T[number]["key"] : T extends Record<string, UrlConfig> ? keyof T : never;
24
+ export type UrlAccessor<T extends readonly TargetUrlConfig[] | Record<string, UrlConfig>> = {
25
+ [K in ExtractTargetKeys<T>]: UrlEndpoint;
26
+ };
27
+ /**
28
+ * Helper to define target URLs with type inference.
29
+ */
30
+ export declare function defineUrls<const T extends readonly TargetUrlConfig[]>(urls: T): T;
31
+ export declare class JirenClient<T extends readonly TargetUrlConfig[] | Record<string, UrlConfig> = readonly TargetUrlConfig[] | Record<string, UrlConfig>> implements Disposable {
32
+ private ptr;
33
+ private urlMap;
34
+ private cacheConfig;
35
+ private antibotConfig;
36
+ private cache;
37
+ private inflightRequests;
38
+ private globalRetry?;
39
+ private requestInterceptors;
40
+ private responseInterceptors;
41
+ private errorInterceptors;
42
+ private targetsPromise;
43
+ private targetsComplete;
44
+ private performanceMode;
45
+ private useDefaultHeaders;
46
+ private readonly defaultHeadersStr;
47
+ private readonly defaultHeaders;
48
+ /** Type-safe URL accessor for warmed-up URLs */
49
+ readonly url: UrlAccessor<T>;
50
+ private metricsCollector;
51
+ /** Public metrics API */
52
+ readonly metrics: MetricsAPI;
53
+ constructor(options?: JirenClientOptions<T>);
54
+ private waitFor;
55
+ /**
56
+ * Wait for lazy pre-connection to complete.
57
+ */
58
+ waitForTargets(): Promise<void>;
59
+ /**
60
+ * @deprecated Use waitForTargets() instead
61
+ */
62
+ waitForWarmup(): Promise<void>;
63
+ /**
64
+ * Creates a proxy-based URL accessor for type-safe access.
65
+ */
66
+ private createUrlAccessor;
67
+ /**
68
+ * Free the native client resources.
69
+ * Note: This is called automatically when the client is garbage collected,
70
+ * or you can use the `using` keyword for automatic cleanup in a scope.
71
+ */
72
+ close(): void;
73
+ /**
74
+ * Dispose method for the `using` keyword (ECMAScript Explicit Resource Management)
75
+ * @example
76
+ * ```typescript
77
+ * using client = new JirenClient({ targets: [...] });
78
+ * // client is automatically closed when the scope ends
79
+ * ```
80
+ */
81
+ [Symbol.dispose](): void;
82
+ /**
83
+ * Register interceptors dynamically.
84
+ */
85
+ use(interceptors: Interceptors): this;
86
+ /**
87
+ * Pre-connect to URLs in parallel.
88
+ */
89
+ preconnect(urls: string[]): Promise<void>;
90
+ /**
91
+ * @deprecated Use preconnect() instead
92
+ */
93
+ warmup(urls: string[]): Promise<void>;
94
+ /**
95
+ * @deprecated Use preconnect() instead
96
+ */
97
+ prefetch(urls: string[]): void;
98
+ /**
99
+ * Pre-warm a single URL (establishes connection, caches DNS, TLS session)
100
+ * Call this before making requests to eliminate first-request latency.
101
+ */
102
+ prewarm(url: string): Promise<void>;
103
+ /**
104
+ * Execute multiple requests in a single pipelined batch (100k+ RPS)
105
+ * All requests must go to the same host.
106
+ * @param host - The host (e.g., "localhost")
107
+ * @param port - The port (e.g., 4000)
108
+ * @param requests - Array of { method, path } objects
109
+ * @returns Array of response bodies as strings
110
+ */
111
+ batch(host: string, port: number, requests: Array<{
112
+ method: string;
113
+ path: string;
114
+ }>): string[];
115
+ request<T = any>(method: string, url: string, body?: string | null, options?: RequestOptions & {
116
+ responseType: "json";
117
+ }): Promise<T>;
118
+ request<T = any>(method: string, url: string, body?: string | null, options?: RequestOptions & {
119
+ responseType: "text";
120
+ }): Promise<string>;
121
+ request<T = any>(method: string, url: string, body?: string | null, options?: RequestOptions & {
122
+ responseType: "arraybuffer";
123
+ }): Promise<ArrayBuffer>;
124
+ request<T = any>(method: string, url: string, body?: string | null, options?: RequestOptions & {
125
+ responseType: "blob";
126
+ }): Promise<Blob>;
127
+ request<T = any>(method: string, url: string, body?: string | null, options?: RequestOptions): Promise<JirenResponse<T>>;
128
+ private parseResponse;
129
+ /**
130
+ * Helper to prepare body and headers for requests.
131
+ */
132
+ private prepareBody;
133
+ }
134
+ //# sourceMappingURL=client-node-native.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"client-node-native.d.ts","sourceRoot":"","sources":["../../components/client-node-native.ts"],"names":[],"mappings":"AAUA,OAAO,KAAK,EACV,cAAc,EACd,aAAa,EAEb,eAAe,EAEf,WAAW,EACX,WAAW,EACX,WAAW,EACX,YAAY,EAMZ,UAAU,EACX,MAAM,YAAY,CAAC;AAiBpB,wDAAwD;AACxD,MAAM,MAAM,SAAS,GACjB,MAAM,GACN;IAAE,GAAG,EAAE,MAAM,CAAC;IAAC,KAAK,CAAC,EAAE,OAAO,GAAG,WAAW,CAAC;IAAC,OAAO,CAAC,EAAE,OAAO,CAAA;CAAE,CAAC;AAEtE,0CAA0C;AAC1C,MAAM,WAAW,kBAAkB,CACjC,CAAC,SAAS,SAAS,eAAe,EAAE,GAAG,MAAM,CAAC,MAAM,EAAE,SAAS,CAAC,GAC5D,SAAS,eAAe,EAAE,GAC1B,MAAM,CAAC,MAAM,EAAE,SAAS,CAAC;IAE7B,oDAAoD;IAC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