@tinycloud/replica 0.4.4 → 0.4.5-beta.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.
@@ -2767,6 +2767,10 @@ var ErrorCodes = {
2767
2767
  /** HTTP 401: a delegation the cited one rests on was revoked. */
2768
2768
  AUTH_DELEGATION_ANCESTOR_REVOKED: "AUTH_DELEGATION_ANCESTOR_REVOKED",
2769
2769
  NETWORK_ERROR: "NETWORK_ERROR",
2770
+ NODE_NOT_RESPONDING: "NODE_NOT_RESPONDING",
2771
+ NODE_IDENTITY_MISMATCH: "NODE_IDENTITY_MISMATCH",
2772
+ PARTIAL_NODE_WRITE: "PARTIAL_NODE_WRITE",
2773
+ RESOURCE_NOT_ROUTED: "RESOURCE_NOT_ROUTED",
2770
2774
  TIMEOUT: "TIMEOUT",
2771
2775
  ABORTED: "ABORTED",
2772
2776
  INVALID_INPUT: "INVALID_INPUT",
@@ -7107,6 +7111,10 @@ var ErrorCodes2 = {
7107
7111
  /** HTTP 401: a delegation the cited one rests on was revoked. */
7108
7112
  AUTH_DELEGATION_ANCESTOR_REVOKED: "AUTH_DELEGATION_ANCESTOR_REVOKED",
7109
7113
  NETWORK_ERROR: "NETWORK_ERROR",
7114
+ NODE_NOT_RESPONDING: "NODE_NOT_RESPONDING",
7115
+ NODE_IDENTITY_MISMATCH: "NODE_IDENTITY_MISMATCH",
7116
+ PARTIAL_NODE_WRITE: "PARTIAL_NODE_WRITE",
7117
+ RESOURCE_NOT_ROUTED: "RESOURCE_NOT_ROUTED",
7110
7118
  TIMEOUT: "TIMEOUT",
7111
7119
  ABORTED: "ABORTED",
7112
7120
  INVALID_INPUT: "INVALID_INPUT",
@@ -7250,6 +7258,32 @@ function parseNetworkId(networkId) {
7250
7258
  }
7251
7259
  return { networkId, ownerDid, name };
7252
7260
  }
7261
+ var ROUTING_FAILURE_CODES = {
7262
+ NODE_NOT_RESPONDING: true,
7263
+ PARTIAL_NODE_WRITE: true,
7264
+ NODE_IDENTITY_MISMATCH: true,
7265
+ RESOURCE_NOT_ROUTED: true,
7266
+ DECRYPTION_DEPENDENCY_UNAVAILABLE: true,
7267
+ registry_unavailable: true,
7268
+ node_not_found: true,
7269
+ node_registry_entry_exists: true
7270
+ };
7271
+ function isRoutingFailureCode(code) {
7272
+ return Object.prototype.hasOwnProperty.call(ROUTING_FAILURE_CODES, code);
7273
+ }
7274
+ function routingFailure(error) {
7275
+ if (typeof error === "object" && error !== null && "code" in error && "message" in error && typeof error.code === "string" && typeof error.message === "string" && isRoutingFailureCode(error.code)) {
7276
+ const candidate = "meta" in error ? error.meta : void 0;
7277
+ let meta = typeof candidate === "object" && candidate !== null && !Array.isArray(candidate) ? candidate : void 0;
7278
+ if (error.code === "NODE_NOT_RESPONDING" && "hosts" in error && Array.isArray(error.hosts)) {
7279
+ meta = { ...meta, hosts: error.hosts };
7280
+ } else if (error.code === "PARTIAL_NODE_WRITE" && "succeeded" in error && Array.isArray(error.succeeded) && "failed" in error && Array.isArray(error.failed)) {
7281
+ meta = { ...meta, succeeded: error.succeeded, failed: error.failed };
7282
+ }
7283
+ return { code: error.code, message: error.message, ...error instanceof Error ? { cause: error } : {}, ...meta ? { meta } : {} };
7284
+ }
7285
+ return void 0;
7286
+ }
7253
7287
  function parsePermissionHint(value) {
7254
7288
  if (typeof value !== "object" || value === null || Array.isArray(value)) return void 0;
7255
7289
  const candidate = value;
@@ -7522,6 +7556,8 @@ function storageRejectionError(service, status, meta, responseText) {
7522
7556
  return status === 402 ? storageQuotaExceededError(service, STORAGE_FULL_MESSAGE, quotaMeta) : storageLimitReachedError(service, STORAGE_WRITE_TOO_LARGE_MESSAGE, quotaMeta);
7523
7557
  }
7524
7558
  function wrapError(service, error, defaultCode = ErrorCodes2.NETWORK_ERROR) {
7559
+ const routing = routingFailure(error);
7560
+ if (routing) return { ...routing, service };
7525
7561
  if (error instanceof Error) {
7526
7562
  if (isRequestTimeoutError(error)) {
7527
7563
  return timeoutError(service, error.timeoutMs, error);
@@ -9455,6 +9491,10 @@ var ErrorCodes3 = {
9455
9491
  /** HTTP 401: a delegation the cited one rests on was revoked. */
9456
9492
  AUTH_DELEGATION_ANCESTOR_REVOKED: "AUTH_DELEGATION_ANCESTOR_REVOKED",
9457
9493
  NETWORK_ERROR: "NETWORK_ERROR",
9494
+ NODE_NOT_RESPONDING: "NODE_NOT_RESPONDING",
9495
+ NODE_IDENTITY_MISMATCH: "NODE_IDENTITY_MISMATCH",
9496
+ PARTIAL_NODE_WRITE: "PARTIAL_NODE_WRITE",
9497
+ RESOURCE_NOT_ROUTED: "RESOURCE_NOT_ROUTED",
9458
9498
  TIMEOUT: "TIMEOUT",
9459
9499
  ABORTED: "ABORTED",
9460
9500
  INVALID_INPUT: "INVALID_INPUT",
@@ -10291,7 +10331,7 @@ function replicaErrorFromService(error, context, request) {
10291
10331
  if (status !== void 0) {
10292
10332
  return new ReplicaError(ReplicaErrorCode.NODE_ERROR, `${context}: ${error.message}`, detail);
10293
10333
  }
10294
- if (error.code === "NETWORK_ERROR" || /TIMEOUT|ABORT/.test(error.code)) {
10334
+ if (error.code === "NETWORK_ERROR" || error.code === "NODE_NOT_RESPONDING" || /TIMEOUT|ABORT/.test(error.code)) {
10295
10335
  return new ReplicaError(ReplicaErrorCode.NETWORK_ERROR, `${context}: ${error.message}`, detail);
10296
10336
  }
10297
10337
  return new ReplicaError(ReplicaErrorCode.NODE_ERROR, `${context}: ${error.message}`, detail);
@@ -2767,6 +2767,10 @@ var ErrorCodes = {
2767
2767
  /** HTTP 401: a delegation the cited one rests on was revoked. */
2768
2768
  AUTH_DELEGATION_ANCESTOR_REVOKED: "AUTH_DELEGATION_ANCESTOR_REVOKED",
2769
2769
  NETWORK_ERROR: "NETWORK_ERROR",
2770
+ NODE_NOT_RESPONDING: "NODE_NOT_RESPONDING",
2771
+ NODE_IDENTITY_MISMATCH: "NODE_IDENTITY_MISMATCH",
2772
+ PARTIAL_NODE_WRITE: "PARTIAL_NODE_WRITE",
2773
+ RESOURCE_NOT_ROUTED: "RESOURCE_NOT_ROUTED",
2770
2774
  TIMEOUT: "TIMEOUT",
2771
2775
  ABORTED: "ABORTED",
2772
2776
  INVALID_INPUT: "INVALID_INPUT",
@@ -7107,6 +7111,10 @@ var ErrorCodes2 = {
7107
7111
  /** HTTP 401: a delegation the cited one rests on was revoked. */
7108
7112
  AUTH_DELEGATION_ANCESTOR_REVOKED: "AUTH_DELEGATION_ANCESTOR_REVOKED",
7109
7113
  NETWORK_ERROR: "NETWORK_ERROR",
7114
+ NODE_NOT_RESPONDING: "NODE_NOT_RESPONDING",
7115
+ NODE_IDENTITY_MISMATCH: "NODE_IDENTITY_MISMATCH",
7116
+ PARTIAL_NODE_WRITE: "PARTIAL_NODE_WRITE",
7117
+ RESOURCE_NOT_ROUTED: "RESOURCE_NOT_ROUTED",
7110
7118
  TIMEOUT: "TIMEOUT",
7111
7119
  ABORTED: "ABORTED",
7112
7120
  INVALID_INPUT: "INVALID_INPUT",
@@ -7250,6 +7258,32 @@ function parseNetworkId(networkId) {
7250
7258
  }
7251
7259
  return { networkId, ownerDid, name };
7252
7260
  }
7261
+ var ROUTING_FAILURE_CODES = {
7262
+ NODE_NOT_RESPONDING: true,
7263
+ PARTIAL_NODE_WRITE: true,
7264
+ NODE_IDENTITY_MISMATCH: true,
7265
+ RESOURCE_NOT_ROUTED: true,
7266
+ DECRYPTION_DEPENDENCY_UNAVAILABLE: true,
7267
+ registry_unavailable: true,
7268
+ node_not_found: true,
7269
+ node_registry_entry_exists: true
7270
+ };
7271
+ function isRoutingFailureCode(code) {
7272
+ return Object.prototype.hasOwnProperty.call(ROUTING_FAILURE_CODES, code);
7273
+ }
7274
+ function routingFailure(error) {
7275
+ if (typeof error === "object" && error !== null && "code" in error && "message" in error && typeof error.code === "string" && typeof error.message === "string" && isRoutingFailureCode(error.code)) {
7276
+ const candidate = "meta" in error ? error.meta : void 0;
7277
+ let meta = typeof candidate === "object" && candidate !== null && !Array.isArray(candidate) ? candidate : void 0;
7278
+ if (error.code === "NODE_NOT_RESPONDING" && "hosts" in error && Array.isArray(error.hosts)) {
7279
+ meta = { ...meta, hosts: error.hosts };
7280
+ } else if (error.code === "PARTIAL_NODE_WRITE" && "succeeded" in error && Array.isArray(error.succeeded) && "failed" in error && Array.isArray(error.failed)) {
7281
+ meta = { ...meta, succeeded: error.succeeded, failed: error.failed };
7282
+ }
7283
+ return { code: error.code, message: error.message, ...error instanceof Error ? { cause: error } : {}, ...meta ? { meta } : {} };
7284
+ }
7285
+ return void 0;
7286
+ }
7253
7287
  function parsePermissionHint(value) {
7254
7288
  if (typeof value !== "object" || value === null || Array.isArray(value)) return void 0;
7255
7289
  const candidate = value;
@@ -7522,6 +7556,8 @@ function storageRejectionError(service, status, meta, responseText) {
7522
7556
  return status === 402 ? storageQuotaExceededError(service, STORAGE_FULL_MESSAGE, quotaMeta) : storageLimitReachedError(service, STORAGE_WRITE_TOO_LARGE_MESSAGE, quotaMeta);
7523
7557
  }
7524
7558
  function wrapError(service, error, defaultCode = ErrorCodes2.NETWORK_ERROR) {
7559
+ const routing = routingFailure(error);
7560
+ if (routing) return { ...routing, service };
7525
7561
  if (error instanceof Error) {
7526
7562
  if (isRequestTimeoutError(error)) {
7527
7563
  return timeoutError(service, error.timeoutMs, error);
@@ -9455,6 +9491,10 @@ var ErrorCodes3 = {
9455
9491
  /** HTTP 401: a delegation the cited one rests on was revoked. */
9456
9492
  AUTH_DELEGATION_ANCESTOR_REVOKED: "AUTH_DELEGATION_ANCESTOR_REVOKED",
9457
9493
  NETWORK_ERROR: "NETWORK_ERROR",
9494
+ NODE_NOT_RESPONDING: "NODE_NOT_RESPONDING",
9495
+ NODE_IDENTITY_MISMATCH: "NODE_IDENTITY_MISMATCH",
9496
+ PARTIAL_NODE_WRITE: "PARTIAL_NODE_WRITE",
9497
+ RESOURCE_NOT_ROUTED: "RESOURCE_NOT_ROUTED",
9458
9498
  TIMEOUT: "TIMEOUT",
9459
9499
  ABORTED: "ABORTED",
9460
9500
  INVALID_INPUT: "INVALID_INPUT",
@@ -10291,7 +10331,7 @@ function replicaErrorFromService(error, context, request) {
10291
10331
  if (status !== void 0) {
10292
10332
  return new ReplicaError(ReplicaErrorCode.NODE_ERROR, `${context}: ${error.message}`, detail);
10293
10333
  }
10294
- if (error.code === "NETWORK_ERROR" || /TIMEOUT|ABORT/.test(error.code)) {
10334
+ if (error.code === "NETWORK_ERROR" || error.code === "NODE_NOT_RESPONDING" || /TIMEOUT|ABORT/.test(error.code)) {
10295
10335
  return new ReplicaError(ReplicaErrorCode.NETWORK_ERROR, `${context}: ${error.message}`, detail);
10296
10336
  }
10297
10337
  return new ReplicaError(ReplicaErrorCode.NODE_ERROR, `${context}: ${error.message}`, detail);