ddan-js 4.0.1 → 4.0.3

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,5 +1,6 @@
1
1
  import { Ddan } from '../../typings';
2
2
  declare function to<T = any, U extends object = any>(promise: Promise<T>, errorExt?: object, fn?: Ddan.noop): Promise<[null, T] | [U, undefined]>;
3
+ declare function jsonParse<T = unknown>(text: string, defaultValue?: T | null): T | null;
3
4
  declare const _default: {
4
5
  to: typeof to;
5
6
  go: <T = any>(task?: Ddan.PFunction<T> | undefined, fn?: Ddan.noop | undefined) => Promise<[any, undefined] | [null, T]>;
@@ -11,5 +12,6 @@ declare const _default: {
11
12
  resolveValue: <T_4 = any>(value: T_4 | (() => T_4)) => T_4;
12
13
  compareVersion: (ver1: string, ver2: string) => 0 | 1 | -1;
13
14
  toOpen: (content: string, defaultOpen?: boolean) => boolean;
15
+ jsonParse: typeof jsonParse;
14
16
  };
15
17
  export default _default;
@@ -53,5 +53,6 @@ declare const _default: {
53
53
  resolveValue: <T_6 = any>(value: T_6 | (() => T_6)) => T_6;
54
54
  compareVersion: (ver1: string, ver2: string) => 0 | 1 | -1;
55
55
  toOpen: (content: string, defaultOpen?: boolean) => boolean;
56
+ jsonParse: <T_7 = unknown>(text: string, defaultValue?: T_7 | null) => T_7 | null;
56
57
  };
57
58
  export default _default;
@@ -1,20 +1,42 @@
1
1
  import DEvent from '../../class/event';
2
2
  import DPipeline from '../hook/modules/pipeline';
3
- interface IProxy {
3
+ /**
4
+ * 代理配置接口
5
+ */
6
+ export interface IProxy {
4
7
  ipaddress: string;
5
8
  port: number;
6
9
  type?: 5;
7
10
  userId?: string;
8
11
  password?: string;
9
12
  }
10
- interface IRuleProxy extends IProxy {
13
+ /**
14
+ * 带规则的代理配置接口
15
+ */
16
+ export interface IRuleProxy extends IProxy {
11
17
  rules?: string[];
12
18
  }
13
- declare const Socks5Event: {
19
+ /**
20
+ * 目标地址接口
21
+ */
22
+ export interface IDestination {
23
+ addr: string;
24
+ port: number;
25
+ }
26
+ /**
27
+ * SOCKS5事件类型
28
+ */
29
+ export declare const Socks5Event: {
14
30
  readonly Error: "error";
15
31
  };
16
- type Socks5EventType = (typeof Socks5Event)[keyof typeof Socks5Event];
17
- interface ILogger {
32
+ /**
33
+ * SOCKS5事件类型
34
+ */
35
+ export type Socks5EventType = (typeof Socks5Event)[keyof typeof Socks5Event];
36
+ /**
37
+ * 日志接口
38
+ */
39
+ export interface ILogger {
18
40
  log: (...args: any[]) => void;
19
41
  info: (...args: any[]) => void;
20
42
  warn: (...args: any[]) => void;
@@ -51,12 +73,29 @@ export declare class Socks5 {
51
73
  setSystemProxy(use: boolean, config?: IProxy): void;
52
74
  /**
53
75
  * 查找可用端口
54
- * @param startPort
55
- * @param maxRetries
56
- * @returns
76
+ * @param startPort 起始端口
77
+ * @param maxRetries 最大重试次数
78
+ * @returns 可用端口或0(表示失败)
57
79
  */
58
80
  private findAvailablePort;
81
+ /**
82
+ * 处理SOCKS5客户端连接
83
+ * @param clientSocket 客户端socket连接
84
+ */
59
85
  private handleSocksConnection;
86
+ /**
87
+ * 设置客户端socket事件处理
88
+ * @param clientSocket 客户端socket连接
89
+ */
90
+ private setupClientSocketEvents;
91
+ /**
92
+ * 根据代理配置建立连接
93
+ * @param clientSocket 客户端socket连接
94
+ * @param destination 目标地址
95
+ * @param proxyConfig 代理配置
96
+ * @param addrport 地址端口字符串
97
+ */
98
+ private establishConnection;
60
99
  /**
61
100
  * 回复客户端请求响应数据
62
101
  * VER是SOCKS版本,这里应该是0x05;
@@ -89,7 +128,18 @@ export declare class Socks5 {
89
128
  private connectToProxy;
90
129
  private connectToLocal;
91
130
  private setupDataForwarding;
131
+ /**
132
+ * 查找适合目标地址的代理配置
133
+ * @param addr 目标地址
134
+ * @returns 匹配的代理配置或undefined
135
+ */
92
136
  findProxyConfig(addr: string): IRuleProxy | undefined;
137
+ /**
138
+ * 检查域名是否符合规则
139
+ * @param addr 目标地址
140
+ * @param rules 规则列表
141
+ * @returns 是否符合规则
142
+ */
93
143
  private isAllowedDomain;
94
144
  close(): void;
95
145
  on(name: Socks5EventType, listener: (...args: any[]) => void): void;
@@ -98,4 +148,3 @@ export declare class Socks5 {
98
148
  private _emit;
99
149
  private _updateRules;
100
150
  }
101
- export {};
@@ -157,6 +157,7 @@ declare const dHook: {
157
157
  resolveValue: <T_10 = any>(value: T_10 | (() => T_10)) => T_10;
158
158
  compareVersion: (ver1: string, ver2: string) => 0 | 1 | -1;
159
159
  toOpen: (content: string, defaultOpen?: boolean) => boolean;
160
+ jsonParse: <T_11 = unknown>(text: string, defaultValue?: T_11 | null) => T_11 | null;
160
161
  base64: {
161
162
  encode: (input: string) => string;
162
163
  decode: (base64Str: string) => string;
@@ -213,7 +214,7 @@ declare const dHook: {
213
214
  bytes2hex: (bytes: Uint8Array) => string;
214
215
  toUint32: (str: string) => Uint32Array;
215
216
  fromUint32: (uint32: Uint32Array) => string;
216
- flatten: <T_11>(data: T_11[], recursive?: boolean, list?: T_11[]) => T_11[];
217
+ flatten: <T_12>(data: T_12[], recursive?: boolean, list?: T_12[]) => T_12[];
217
218
  flattenPath: (data: Record<string, any>) => Record<string, any>;
218
219
  normalizeStructure: (data: any, prevData: any) => void;
219
220
  diffPath: (data: Record<string, any>, prevData: Record<string, any>) => Record<string, any>;
@@ -229,12 +230,12 @@ declare const dHook: {
229
230
  ignoreEmptyString?: boolean | undefined;
230
231
  }) => any;
231
232
  clone: (source: any, weakMap?: WeakMap<object, any>) => any;
232
- cloneClass: <T_12>(source: T_12) => T_12;
233
- isEqual: <T_13 = any>(value: T_13, other: T_13, depth?: number) => boolean;
233
+ cloneClass: <T_13>(source: T_13) => T_13;
234
+ isEqual: <T_14 = any>(value: T_14, other: T_14, depth?: number) => boolean;
234
235
  isEqualArray: (value: any[], other: any[], depth?: number) => boolean;
235
236
  isEqualObject: (value: Record<string, any>, other: Record<string, any>, depth?: number) => boolean;
236
- isEqualValue: <T_14>(value: T_14, other: T_14, type: string) => boolean;
237
+ isEqualValue: <T_15>(value: T_15, other: T_15, type: string) => boolean;
237
238
  isEqualAB: (value: ArrayBuffer, other: ArrayBuffer) => boolean;
238
- isEqualDeep: <T_15>(value: T_15, other: T_15) => boolean;
239
+ isEqualDeep: <T_16>(value: T_16, other: T_16) => boolean;
239
240
  };
240
241
  export default dHook;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ddan-js",
3
- "version": "4.0.1",
3
+ "version": "4.0.3",
4
4
  "description": "",
5
5
  "keywords": [
6
6
  "ddan-js",