@yydb/yydb-client 0.0.11 → 0.0.15

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/dist/client.d.ts CHANGED
@@ -3,7 +3,7 @@ import type { MicroHostHandler, Transport } from './transport.js';
3
3
  export type { Frame, MicroHostInvokePayload, MicroRegisterPayload, MsgTypeCode, SchemaVersion, WireErrorBody, WireUdfScalarKind, WireUdfScalarValue, } from './wire.js';
4
4
  export type { MicroHostHandler } from './transport.js';
5
5
  export { MsgType, encodeFrame, decodeFrame, encodeErrorBody, decodeErrorBody } from './wire.js';
6
- export { YydbError, YydbErrorCodes, isRetryableYydbCode, isYydbError } from './errors.js';
6
+ export { YydbError, YydbErrorCodes, YydbClientErrorCodes, isYydbError } from './errors.js';
7
7
  export type { YydbErrorCode, YydbErrorOptions } from './errors.js';
8
8
  export interface ConnectOptions {
9
9
  /** `ws://127.0.0.1:7700/wire` or `127.0.0.1:7700` (upgraded to `/wire`). */
package/dist/client.js CHANGED
@@ -2,7 +2,7 @@ import { decodeErrorBody, decodeKvGetOk, decodeScalarCallOk, decodeSchemaGetOk,
2
2
  import { openWebSocketTransport } from './ws.js';
3
3
  import { YydbError, YydbErrorCodes } from './errors.js';
4
4
  export { MsgType, encodeFrame, decodeFrame, encodeErrorBody, decodeErrorBody } from './wire.js';
5
- export { YydbError, YydbErrorCodes, isRetryableYydbCode, isYydbError } from './errors.js';
5
+ export { YydbError, YydbErrorCodes, YydbClientErrorCodes, isYydbError } from './errors.js';
6
6
  /** Expected reply type and operation label per request type. */
7
7
  const REQUESTS = {
8
8
  [MsgType.Hello]: { operation: 'hello', ok: MsgType.HelloOk },
@@ -47,6 +47,7 @@ export class Client {
47
47
  catch (cause) {
48
48
  throw new YydbError(YydbErrorCodes.clientTransportFailure, `connect ${endpoint}: transport failed`, {
49
49
  operation: 'connect',
50
+ retryable: true,
50
51
  cause,
51
52
  });
52
53
  }
@@ -122,7 +123,7 @@ export class Client {
122
123
  });
123
124
  }
124
125
  catch (cause) {
125
- throw new YydbError(YydbErrorCodes.clientTransportFailure, `${operation}: transport failed`, { operation, cause });
126
+ throw new YydbError(YydbErrorCodes.clientTransportFailure, `${operation}: transport failed`, { operation, retryable: true, cause });
126
127
  }
127
128
  if (response.requestId !== requestId) {
128
129
  throw new YydbError(YydbErrorCodes.clientRequestIdMismatch, `${operation}: wire response request_id mismatch (got ${response.requestId}, want ${requestId})`, { operation });
package/dist/errors.d.ts CHANGED
@@ -1,57 +1,12 @@
1
1
  /**
2
- * Host-facing YYDB error surface.
2
+ * @yydb/yydb-client consumes the same error surface as @yydb/yydb.
3
3
  *
4
- * Every public failure carries a stable `code`: engine codes come from the
5
- * Rust core (`yydb.schema.invalid`, …) over the wire, client codes are minted
6
- * locally with the `yydb.client.` prefix. Branch on `code` — `message` is
7
- * display text only.
4
+ * YydbError / YydbErrorCodes / YydbClientErrorCodes / isYydbError are re-exported
5
+ * from {@linkcode @yydb/yydb/shared/errors} so engine code, retryability and
6
+ * params handling live in exactly one place. Client authors minting
7
+ * client-local errors (connect failure, request-id mismatch, …) still use
8
+ * {@link YydbClientErrorCodes} from this package via YydbErrorCodes or the
9
+ * named export.
8
10
  */
9
- /** Stable codes known to the TypeScript hosts. */
10
- export declare const YydbErrorCodes: {
11
- readonly io: "yydb.io";
12
- readonly corrupt: "yydb.corrupt";
13
- readonly schemaConflict: "yydb.schema.conflict";
14
- readonly schemaInvalid: "yydb.schema.invalid";
15
- readonly udfNotFound: "yydb.udf.not_found";
16
- readonly udfArity: "yydb.udf.arity";
17
- readonly udfFailed: "yydb.udf.failed";
18
- readonly udfVersionMismatch: "yydb.udf.version_mismatch";
19
- readonly objectNotFound: "yydb.object.not_found";
20
- readonly objectCorrupt: "yydb.object.corrupt";
21
- readonly unsupported: "yydb.unsupported";
22
- readonly protocol: "yydb.protocol";
23
- readonly casConflict: "yydb.cas.conflict";
24
- readonly leaseUnavailable: "yydb.lease.unavailable";
25
- readonly fencingMismatch: "yydb.fencing.mismatch";
26
- readonly leaseExpired: "yydb.lease.expired";
27
- readonly quotaExceeded: "yydb.quota.exceeded";
28
- readonly sessionClosed: "yydb.session.closed";
29
- readonly clientInvalidEndpoint: "yydb.client.invalid_endpoint";
30
- readonly clientTransportFailure: "yydb.client.transport_failure";
31
- readonly clientRequestIdMismatch: "yydb.client.request_id_mismatch";
32
- readonly clientUnexpectedResponse: "yydb.client.unexpected_response";
33
- readonly clientDecodeFailure: "yydb.client.decode_failure";
34
- };
35
- /** A known code, or any future code the engine introduces. */
36
- export type YydbErrorCode = (typeof YydbErrorCodes)[keyof typeof YydbErrorCodes] | (string & {});
37
- /** Whether `code` may be retried with the same arguments. */
38
- export declare function isRetryableYydbCode(code: string): boolean;
39
- /** Options carried by a {@link YydbError}. */
40
- export interface YydbErrorOptions {
41
- /** Operation that failed (`schemaGet`, `kvPut`, `query`, …). */
42
- operation?: string;
43
- /** Underlying failure when this error wraps one. */
44
- cause?: unknown;
45
- }
46
- /** YYDB failure with a stable machine-readable {@link YydbError.code}. */
47
- export declare class YydbError extends Error {
48
- /** Stable code — engine code or `yydb.client.*`. */
49
- readonly code: string;
50
- /** Operation that failed. */
51
- readonly operation: string;
52
- /** Whether the same call may be retried. */
53
- readonly retryable: boolean;
54
- constructor(code: YydbErrorCode, message: string, options?: YydbErrorOptions);
55
- }
56
- /** Narrowing helper so callers can branch without `instanceof` imports. */
57
- export declare function isYydbError(value: unknown): value is YydbError;
11
+ export { YydbError, YydbErrorCodes, YydbClientErrorCodes, isYydbError, } from '@yydb/yydb';
12
+ export type { YydbErrorCode, YydbErrorOptions } from '@yydb/yydb';
package/dist/errors.js CHANGED
@@ -1,68 +1,11 @@
1
1
  /**
2
- * Host-facing YYDB error surface.
2
+ * @yydb/yydb-client consumes the same error surface as @yydb/yydb.
3
3
  *
4
- * Every public failure carries a stable `code`: engine codes come from the
5
- * Rust core (`yydb.schema.invalid`, …) over the wire, client codes are minted
6
- * locally with the `yydb.client.` prefix. Branch on `code` — `message` is
7
- * display text only.
4
+ * YydbError / YydbErrorCodes / YydbClientErrorCodes / isYydbError are re-exported
5
+ * from {@linkcode @yydb/yydb/shared/errors} so engine code, retryability and
6
+ * params handling live in exactly one place. Client authors minting
7
+ * client-local errors (connect failure, request-id mismatch, …) still use
8
+ * {@link YydbClientErrorCodes} from this package via YydbErrorCodes or the
9
+ * named export.
8
10
  */
9
- /** Stable codes known to the TypeScript hosts. */
10
- export const YydbErrorCodes = {
11
- io: 'yydb.io',
12
- corrupt: 'yydb.corrupt',
13
- schemaConflict: 'yydb.schema.conflict',
14
- schemaInvalid: 'yydb.schema.invalid',
15
- udfNotFound: 'yydb.udf.not_found',
16
- udfArity: 'yydb.udf.arity',
17
- udfFailed: 'yydb.udf.failed',
18
- udfVersionMismatch: 'yydb.udf.version_mismatch',
19
- objectNotFound: 'yydb.object.not_found',
20
- objectCorrupt: 'yydb.object.corrupt',
21
- unsupported: 'yydb.unsupported',
22
- protocol: 'yydb.protocol',
23
- casConflict: 'yydb.cas.conflict',
24
- leaseUnavailable: 'yydb.lease.unavailable',
25
- fencingMismatch: 'yydb.fencing.mismatch',
26
- leaseExpired: 'yydb.lease.expired',
27
- quotaExceeded: 'yydb.quota.exceeded',
28
- sessionClosed: 'yydb.session.closed',
29
- clientInvalidEndpoint: 'yydb.client.invalid_endpoint',
30
- clientTransportFailure: 'yydb.client.transport_failure',
31
- clientRequestIdMismatch: 'yydb.client.request_id_mismatch',
32
- clientUnexpectedResponse: 'yydb.client.unexpected_response',
33
- clientDecodeFailure: 'yydb.client.decode_failure',
34
- };
35
- /**
36
- * Codes where retrying the same operation can legitimately succeed: a socket or
37
- * lease hiccup, or a compare-and-set that lost a benign race. Every other code
38
- * needs the caller to change input, schema, or wiring first.
39
- */
40
- const RETRYABLE_CODES = new Set([
41
- YydbErrorCodes.clientTransportFailure,
42
- YydbErrorCodes.casConflict,
43
- YydbErrorCodes.leaseUnavailable,
44
- ]);
45
- /** Whether `code` may be retried with the same arguments. */
46
- export function isRetryableYydbCode(code) {
47
- return RETRYABLE_CODES.has(code);
48
- }
49
- /** YYDB failure with a stable machine-readable {@link YydbError.code}. */
50
- export class YydbError extends Error {
51
- /** Stable code — engine code or `yydb.client.*`. */
52
- code;
53
- /** Operation that failed. */
54
- operation;
55
- /** Whether the same call may be retried. */
56
- retryable;
57
- constructor(code, message, options = {}) {
58
- super(message, { cause: options.cause });
59
- this.name = 'YydbError';
60
- this.code = code;
61
- this.operation = options.operation ?? 'unknown';
62
- this.retryable = isRetryableYydbCode(code);
63
- }
64
- }
65
- /** Narrowing helper so callers can branch without `instanceof` imports. */
66
- export function isYydbError(value) {
67
- return value instanceof YydbError;
68
- }
11
+ export { YydbError, YydbErrorCodes, YydbClientErrorCodes, isYydbError, } from '@yydb/yydb';
package/dist/index.d.ts CHANGED
@@ -3,6 +3,6 @@ export { Client } from './client.js';
3
3
  export type { ConnectOptions } from './client.js';
4
4
  export { MAGIC, MAGIC_YYDB, MAGIC_YYDS, WIRE_VERSION, WIRE_VERSION_NEXT, HEADER_LEN, MsgType, encodeFrame, decodeFrame, encodeSchemaEnsure, encodeKvGet, encodeKvPut, encodeMicroRegister, encodeScalarCall, encodeErrorBody, decodeErrorBody, decodeScalarCallOk, decodeSchemaGetOk, decodeKvGetOk, } from './wire.js';
5
5
  export type { Frame, MicroRegisterPayload, MsgTypeCode, ProductMagic, SchemaVersion, WireErrorBody, WireUdfScalarKind, WireUdfScalarValue, } from './wire.js';
6
- export { YydbError, YydbErrorCodes, isRetryableYydbCode, isYydbError } from './errors.js';
6
+ export { YydbError, YydbErrorCodes, YydbClientErrorCodes, isYydbError } from './errors.js';
7
7
  export type { YydbErrorCode, YydbErrorOptions } from './errors.js';
8
8
  export type { MicroHostHandler, Transport } from './transport.js';
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
1
  /** Browser-safe entry (WebSocket). For Node TCP use `@yydb/yydb-client/node`. */
2
2
  export { Client } from './client.js';
3
3
  export { MAGIC, MAGIC_YYDB, MAGIC_YYDS, WIRE_VERSION, WIRE_VERSION_NEXT, HEADER_LEN, MsgType, encodeFrame, decodeFrame, encodeSchemaEnsure, encodeKvGet, encodeKvPut, encodeMicroRegister, encodeScalarCall, encodeErrorBody, decodeErrorBody, decodeScalarCallOk, decodeSchemaGetOk, decodeKvGetOk, } from './wire.js';
4
- export { YydbError, YydbErrorCodes, isRetryableYydbCode, isYydbError } from './errors.js';
4
+ export { YydbError, YydbErrorCodes, YydbClientErrorCodes, isYydbError } from './errors.js';
package/dist/node.d.ts CHANGED
@@ -3,7 +3,7 @@ export { Client } from './client.js';
3
3
  export type { ConnectOptions } from './client.js';
4
4
  export { MsgType, encodeFrame, decodeFrame, encodeSchemaEnsure, encodeKvGet, encodeKvPut, decodeSchemaGetOk, decodeKvGetOk, encodeErrorBody, decodeErrorBody, } from './wire.js';
5
5
  export type { Frame, MsgTypeCode, SchemaVersion, WireErrorBody } from './wire.js';
6
- export { YydbError, YydbErrorCodes, isRetryableYydbCode, isYydbError } from './errors.js';
6
+ export { YydbError, YydbErrorCodes, YydbClientErrorCodes, isYydbError } from './errors.js';
7
7
  export type { YydbErrorCode, YydbErrorOptions } from './errors.js';
8
8
  export type { MicroHostHandler, Transport } from './transport.js';
9
9
  /** Node entry: TCP by default; `ws://` uses WebSocket. */
package/dist/node.js CHANGED
@@ -5,7 +5,7 @@ import { normalizeWsUrl } from './transport.js';
5
5
  import { YydbError, YydbErrorCodes } from './errors.js';
6
6
  export { Client } from './client.js';
7
7
  export { MsgType, encodeFrame, decodeFrame, encodeSchemaEnsure, encodeKvGet, encodeKvPut, decodeSchemaGetOk, decodeKvGetOk, encodeErrorBody, decodeErrorBody, } from './wire.js';
8
- export { YydbError, YydbErrorCodes, isRetryableYydbCode, isYydbError } from './errors.js';
8
+ export { YydbError, YydbErrorCodes, YydbClientErrorCodes, isYydbError } from './errors.js';
9
9
  function wantsWebSocket(endpoint) {
10
10
  const trimmed = endpoint.trim();
11
11
  return trimmed.startsWith('ws://') || trimmed.startsWith('wss://');
package/package.json CHANGED
@@ -1,38 +1,33 @@
1
1
  {
2
- "name": "@yydb/yydb-client",
3
- "version": "0.0.11",
2
+ "bugs": {
3
+ "url": "https://github.com/yy-database/yydb.rs/issues"
4
+ },
5
+ "dependencies": {
6
+ "@yydb/yydb": "0.0.15"
7
+ },
4
8
  "description": "TypeScript client for the YYDB WebSocket and TCP wire protocol",
5
- "license": "MPL-2.0",
6
- "type": "module",
7
- "main": "./dist/index.js",
8
- "types": "./dist/index.d.ts",
9
+ "devDependencies": {
10
+ "@types/node": "^20.10.0",
11
+ "typescript": "~5.3.0"
12
+ },
13
+ "engines": {
14
+ "node": ">=18"
15
+ },
9
16
  "exports": {
10
17
  ".": {
11
- "types": "./dist/index.d.ts",
12
- "import": "./dist/index.js"
18
+ "import": "./dist/index.js",
19
+ "types": "./dist/index.d.ts"
13
20
  },
14
21
  "./node": {
15
- "types": "./dist/node.d.ts",
16
- "import": "./dist/node.js"
22
+ "import": "./dist/node.js",
23
+ "types": "./dist/node.d.ts"
17
24
  }
18
25
  },
19
26
  "files": [
20
27
  "dist",
21
28
  "README.md"
22
29
  ],
23
- "scripts": {
24
- "build": "tsc -p tsconfig.json",
25
- "test": "pnpm run build && node --experimental-strip-types --test src/**/*.test.ts"
26
- },
27
- "repository": {
28
- "type": "git",
29
- "url": "git+https://github.com/yy-database/yydb.git",
30
- "directory": "projects/packages/yydb-client"
31
- },
32
- "homepage": "https://github.com/yy-database/yydb/tree/dev/projects/packages/yydb-client#readme",
33
- "bugs": {
34
- "url": "https://github.com/yy-database/yydb/issues"
35
- },
30
+ "homepage": "https://github.com/yy-database/yydb.rs/tree/dev/projects/packages/yydb-client#readme",
36
31
  "keywords": [
37
32
  "yydb",
38
33
  "yyds",
@@ -40,14 +35,22 @@
40
35
  "wire-protocol",
41
36
  "typescript"
42
37
  ],
38
+ "license": "MPL-2.0",
39
+ "main": "./dist/index.js",
40
+ "name": "@yydb/yydb-client",
43
41
  "publishConfig": {
44
42
  "access": "public"
45
43
  },
46
- "devDependencies": {
47
- "@types/node": "^20.10.0",
48
- "typescript": "~5.3.0"
44
+ "repository": {
45
+ "directory": "projects/packages/yydb-client",
46
+ "type": "git",
47
+ "url": "git+https://github.com/yy-database/yydb.rs.git"
49
48
  },
50
- "engines": {
51
- "node": ">=18"
52
- }
49
+ "scripts": {
50
+ "build": "tsc -p tsconfig.json",
51
+ "test": "pnpm run build && node --experimental-strip-types --test src/**/*.test.ts"
52
+ },
53
+ "type": "module",
54
+ "types": "./dist/index.d.ts",
55
+ "version": "0.0.15"
53
56
  }