@celljs/ta-client 4.16.0 → 4.18.0

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,39 @@
1
+ import { TaErrorCode, type TaErrorData } from '@celljs/ta-protocol';
2
+ /**
3
+ * A failed call. `code` is set for failures the server names; `rpcCode` is the code of JSON-RPC's error,
4
+ * by which a client tells a method an older ta serve does not have (`TaRemoteError.METHOD_NOT_FOUND`).
5
+ */
6
+ export declare class TaRemoteError extends Error {
7
+ readonly code?: TaErrorCode | undefined;
8
+ readonly hint?: string | undefined;
9
+ readonly rpcCode?: number | undefined;
10
+ /** All ta serve said of the failure: for a refused call, the action it needs (TaForbiddenData). */
11
+ readonly data?: Readonly<Record<string, unknown>> | undefined;
12
+ /** JSON-RPC's code for a method the server does not have. */
13
+ static readonly METHOD_NOT_FOUND = -32601;
14
+ constructor(message: string, code?: TaErrorCode | undefined, hint?: string | undefined, rpcCode?: number | undefined,
15
+ /** All ta serve said of the failure: for a refused call, the action it needs (TaForbiddenData). */
16
+ data?: Readonly<Record<string, unknown>> | undefined);
17
+ /** The error of a JSON-RPC answer: its code, and the code and hint of ta serve when it named the failure. */
18
+ static of(error: {
19
+ message: string;
20
+ code?: number;
21
+ data?: {
22
+ data?: TaErrorData;
23
+ };
24
+ }): TaRemoteError;
25
+ /** What a call says that waited for a connection that did not come back. */
26
+ static readonly NOT_CONNECTED = "Not connected to ta serve.";
27
+ /** What a call says that was sent on a connection lost before its answer. */
28
+ static readonly LOST = "The connection to ta serve was lost.";
29
+ /** A call that waited for a connection that did not come back. */
30
+ static notConnected(): TaRemoteError;
31
+ /**
32
+ * Whether a failure is only that the connection was lost, which mends itself: by its code, or by its
33
+ * words in a text (a web extension shows `error.message`, often inside its own words).
34
+ */
35
+ static isConnectionLost(cause: unknown): boolean;
36
+ /** Whether the server has no such method: a ta serve from before it was added. */
37
+ static isMethodNotFound(error: unknown): boolean;
38
+ }
39
+ //# sourceMappingURL=ta-remote-error.d.ts.map
@@ -0,0 +1,52 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.TaRemoteError = void 0;
4
+ const ta_protocol_1 = require("@celljs/ta-protocol");
5
+ /**
6
+ * A failed call. `code` is set for failures the server names; `rpcCode` is the code of JSON-RPC's error,
7
+ * by which a client tells a method an older ta serve does not have (`TaRemoteError.METHOD_NOT_FOUND`).
8
+ */
9
+ class TaRemoteError extends Error {
10
+ constructor(message, code, hint, rpcCode,
11
+ /** All ta serve said of the failure: for a refused call, the action it needs (TaForbiddenData). */
12
+ data) {
13
+ super(message);
14
+ this.code = code;
15
+ this.hint = hint;
16
+ this.rpcCode = rpcCode;
17
+ this.data = data;
18
+ this.name = 'TaRemoteError';
19
+ }
20
+ /** The error of a JSON-RPC answer: its code, and the code and hint of ta serve when it named the failure. */
21
+ static of(error) {
22
+ var _a;
23
+ const data = (_a = error.data) === null || _a === void 0 ? void 0 : _a.data;
24
+ return new TaRemoteError(error.message, data === null || data === void 0 ? void 0 : data.code, data === null || data === void 0 ? void 0 : data.hint, error.code, data);
25
+ }
26
+ /** A call that waited for a connection that did not come back. */
27
+ static notConnected() {
28
+ return new TaRemoteError(TaRemoteError.NOT_CONNECTED, ta_protocol_1.TaErrorCode.CONNECTION_LOST, 'Try again once the connection is back.');
29
+ }
30
+ /**
31
+ * Whether a failure is only that the connection was lost, which mends itself: by its code, or by its
32
+ * words in a text (a web extension shows `error.message`, often inside its own words).
33
+ */
34
+ static isConnectionLost(cause) {
35
+ if (typeof cause === 'string') {
36
+ return cause.includes(TaRemoteError.NOT_CONNECTED) || cause.includes(TaRemoteError.LOST);
37
+ }
38
+ return (cause === null || cause === void 0 ? void 0 : cause.code) === ta_protocol_1.TaErrorCode.CONNECTION_LOST;
39
+ }
40
+ /** Whether the server has no such method: a ta serve from before it was added. */
41
+ static isMethodNotFound(error) {
42
+ return error instanceof TaRemoteError && error.rpcCode === TaRemoteError.METHOD_NOT_FOUND;
43
+ }
44
+ }
45
+ exports.TaRemoteError = TaRemoteError;
46
+ /** JSON-RPC's code for a method the server does not have. */
47
+ TaRemoteError.METHOD_NOT_FOUND = -32601;
48
+ /** What a call says that waited for a connection that did not come back. */
49
+ TaRemoteError.NOT_CONNECTED = 'Not connected to ta serve.';
50
+ /** What a call says that was sent on a connection lost before its answer. */
51
+ TaRemoteError.LOST = 'The connection to ta serve was lost.';
52
+ //# sourceMappingURL=ta-remote-error.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@celljs/ta-client",
3
- "version": "4.16.0",
3
+ "version": "4.18.0",
4
4
  "description": "A client of ta serve for any JavaScript runtime: connection and UI-independent session state",
5
5
  "homepage": "https://github.com/cellbang/ta",
6
6
  "bugs": {
@@ -29,7 +29,7 @@
29
29
  "watch": "tsc -b -w --preserveWatchOutput"
30
30
  },
31
31
  "dependencies": {
32
- "@celljs/ta-protocol": "4.16.0"
32
+ "@celljs/ta-protocol": "4.18.0"
33
33
  },
34
34
  "devDependencies": {
35
35
  "@earendil-works/pi-ai": "^1.5.2",