xshell 1.0.97 → 1.0.99

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.
package/net.browser.js CHANGED
@@ -424,10 +424,8 @@ export class Remote {
424
424
  if (data)
425
425
  await this.send({ id, data }, websocket);
426
426
  }
427
- else if (message.error)
428
- throw message.error;
429
427
  else
430
- throw new Error(`${t('找不到 rpc handler')}: ${func ? `func: ${func.quote()}` : `id: ${id}`}`);
428
+ throw message.error || new Error(`${t('找不到 rpc handler')}: ${func ? `func: ${func.quote()}` : `id: ${id}`}`);
431
429
  }
432
430
  catch (error) {
433
431
  // handler 出错并不意味着 rpc 一定会结束,可能 error 是运行中的正常数据,所以不能清理 handler
package/net.js CHANGED
@@ -632,10 +632,8 @@ export class Remote {
632
632
  if (data)
633
633
  await this.send({ id, data }, websocket);
634
634
  }
635
- else if (message.error)
636
- throw message.error;
637
635
  else
638
- throw new Error(`${t('找不到 rpc handler')}: ${func ? `func: ${func.quote()}` : `id: ${id}`}`);
636
+ throw message.error || new Error(`${t('找不到 rpc handler')}: ${func ? `func: ${func.quote()}` : `id: ${id}`}`);
639
637
  }
640
638
  catch (error) {
641
639
  // handler 出错并不意味着 rpc 一定会结束,可能 error 是运行中的正常数据,所以不能清理 handler
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "xshell",
3
- "version": "1.0.97",
3
+ "version": "1.0.99",
4
4
  "type": "module",
5
5
  "main": "./index.js",
6
6
  "bin": {
@@ -77,26 +77,26 @@
77
77
  "gulp-sort": "^2.0.0",
78
78
  "hash-string": "^1.0.0",
79
79
  "https-proxy-agent": "^7.0.4",
80
- "i18next": "^23.11.3",
80
+ "i18next": "^23.11.4",
81
81
  "i18next-scanner": "^4.4.0",
82
82
  "js-cookie": "^3.0.5",
83
83
  "koa": "^2.15.3",
84
84
  "koa-compress": "^5.1.1",
85
85
  "lodash": "^4.17.21",
86
- "map-stream": "0.0.7",
86
+ "map-stream": "^0.0.7",
87
87
  "mime-types": "^2.1.35",
88
88
  "ora": "^8.0.1",
89
89
  "react": "^18.3.1",
90
90
  "react-i18next": "^14.1.1",
91
- "react-object-model": "^1.2.4",
91
+ "react-object-model": "^1.2.5",
92
92
  "resolve-path": "^1.4.0",
93
93
  "strip-ansi": "^7.1.0",
94
94
  "through2": "^4.0.2",
95
95
  "tough-cookie": "^4.1.4",
96
96
  "tslib": "^2.6.2",
97
97
  "typescript": "^5.4.5",
98
- "ua-parser-js": "2.0.0-alpha.2",
99
- "undici": "^6.16.0",
98
+ "ua-parser-js": "^2.0.0-beta.2",
99
+ "undici": "^6.16.1",
100
100
  "vinyl": "^3.0.0",
101
101
  "vinyl-fs": "^4.0.0",
102
102
  "ws": "^8.17.0",
@@ -114,14 +114,14 @@
114
114
  "@types/chardet": "^0.8.3",
115
115
  "@types/eslint": "^8.56.10",
116
116
  "@types/estree": "^1.0.5",
117
- "@types/gulp-sort": "2.0.4",
117
+ "@types/gulp-sort": "^2.0.4",
118
118
  "@types/js-cookie": "^3.0.6",
119
119
  "@types/koa": "^2.15.0",
120
120
  "@types/koa-compress": "^4.0.6",
121
121
  "@types/lodash": "^4.17.1",
122
122
  "@types/mime-types": "^2.1.4",
123
123
  "@types/node": "^20.12.11",
124
- "@types/react": "^18.3.1",
124
+ "@types/react": "^18.3.2",
125
125
  "@types/through2": "^2.0.41",
126
126
  "@types/tough-cookie": "^4.0.5",
127
127
  "@types/ua-parser-js": "^0.7.39",
@@ -121,6 +121,8 @@ declare global {
121
121
  to_oct_str(this: number): string;
122
122
  }
123
123
  interface Array<T> {
124
+ /** 等价于 .at(-1) */
125
+ last: T;
124
126
  indent(this: string[], width: number, c?: string): string[];
125
127
  /**
126
128
  - trim_line?: `true`
@@ -406,6 +406,11 @@ Object.defineProperties(Number.prototype, to_method_property_descriptors({
406
406
  }));
407
407
  // ------------------------------------ Array.prototype
408
408
  Object.defineProperties(Array.prototype, {
409
+ ...to_getter_property_descriptors({
410
+ last() {
411
+ return this.at(-1);
412
+ }
413
+ }),
409
414
  // --- 文本处理工具方法
410
415
  ...to_method_property_descriptors({
411
416
  trim_lines({ trim_line = true, rm_empty_lines = true, rm_last_empty_lines = false } = {}) {
package/prototype.d.ts CHANGED
@@ -145,6 +145,8 @@ declare global {
145
145
  to_oct_str(this: number): string;
146
146
  }
147
147
  interface Array<T> {
148
+ /** 等价于 .at(-1) */
149
+ last: T;
148
150
  log(this: string[], limit?: number): void;
149
151
  indent(this: string[], width: number, c?: string): string[];
150
152
  indent2to4(this: string[]): string[];
package/prototype.js CHANGED
@@ -435,6 +435,11 @@ if (!globalThis.my_prototype_defined) {
435
435
  }));
436
436
  // ------------------------------------ Array.prototype
437
437
  Object.defineProperties(Array.prototype, {
438
+ ...to_getter_property_descriptors({
439
+ last() {
440
+ return this.at(-1);
441
+ }
442
+ }),
438
443
  // --- 文本处理工具方法
439
444
  ...to_method_property_descriptors({
440
445
  log(limit = 10000) {
@@ -9,7 +9,10 @@ export declare function seq<T = number>(n: number, generator?: (index: number) =
9
9
  /** 将 keys, values 数组按对应的顺序组合成一个对象 */
10
10
  export declare function zip_object<TValue>(keys: (string | number)[], values: TValue[]): Record<string, TValue>;
11
11
  export declare function delay(milliseconds: number): Promise<void>;
12
- export declare function timeout(milliseconds: number): Promise<void>;
12
+ export declare class TimeoutError extends Error {
13
+ constructor(message?: string, options?: ErrorOptions);
14
+ }
15
+ export declare function timeout<TReturn>(milliseconds: number, action: () => Promise<TReturn>): Promise<TReturn>;
13
16
  /** https://stackoverflow.com/questions/63297164/how-to-only-accept-arraybuffer-as-parameter */
14
17
  export type StrictArrayBuffer = ArrayBuffer & {
15
18
  buffer?: undefined;
package/utils.browser.js CHANGED
@@ -32,10 +32,18 @@ export async function delay(milliseconds) {
32
32
  setTimeout(resolve, milliseconds);
33
33
  });
34
34
  }
35
- export async function timeout(milliseconds) {
36
- const error = new Error(t('超时错误'));
37
- await delay(milliseconds);
38
- throw error;
35
+ export class TimeoutError extends Error {
36
+ constructor(message, options) {
37
+ super(message, options);
38
+ this.name = this.constructor.name;
39
+ }
40
+ }
41
+ export async function timeout(milliseconds, action) {
42
+ const error = new TimeoutError();
43
+ return new Promise((resolve, reject) => {
44
+ delay(milliseconds).then(() => { reject(error); });
45
+ action().then(resolve, reject);
46
+ });
39
47
  }
40
48
  /** 创建一个 promise,后续可调用 promise.resolve, promise.reject 方法设置其状态和值
41
49
  - initial?: `undefined` 传入非 undefined 值(包括 null)时直接设置为 resolved 状态
package/utils.d.ts CHANGED
@@ -67,7 +67,10 @@ export declare class Timer {
67
67
  }
68
68
  export declare function log_line(): void;
69
69
  export declare function delay(milliseconds: number): Promise<void>;
70
- export declare function timeout(milliseconds: number): Promise<void>;
70
+ export declare class TimeoutError extends Error {
71
+ constructor(message?: string, options?: ErrorOptions);
72
+ }
73
+ export declare function timeout<TReturn>(milliseconds: number, action: () => Promise<TReturn>): Promise<TReturn>;
71
74
  /** https://stackoverflow.com/questions/63297164/how-to-only-accept-arraybuffer-as-parameter */
72
75
  export type StrictArrayBuffer = ArrayBuffer & {
73
76
  buffer?: undefined;
package/utils.js CHANGED
@@ -199,10 +199,18 @@ export async function delay(milliseconds) {
199
199
  setTimeout(resolve, milliseconds);
200
200
  });
201
201
  }
202
- export async function timeout(milliseconds) {
203
- const error = new Error(t('超时错误'));
204
- await delay(milliseconds);
205
- throw error;
202
+ export class TimeoutError extends Error {
203
+ constructor(message, options) {
204
+ super(message, options);
205
+ this.name = this.constructor.name;
206
+ }
207
+ }
208
+ export async function timeout(milliseconds, action) {
209
+ const error = new TimeoutError();
210
+ return new Promise((resolve, reject) => {
211
+ delay(milliseconds).then(() => { reject(error); });
212
+ action().then(resolve, reject);
213
+ });
206
214
  }
207
215
  /** 创建一个 promise,后续可调用 promise.resolve, promise.reject 方法设置其状态和值
208
216
  - initial?: `undefined` 传入非 undefined 值(包括 null)时直接设置为 resolved 状态