@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.
@@ -2719,6 +2719,10 @@ var ErrorCodes = {
2719
2719
  /** HTTP 401: a delegation the cited one rests on was revoked. */
2720
2720
  AUTH_DELEGATION_ANCESTOR_REVOKED: "AUTH_DELEGATION_ANCESTOR_REVOKED",
2721
2721
  NETWORK_ERROR: "NETWORK_ERROR",
2722
+ NODE_NOT_RESPONDING: "NODE_NOT_RESPONDING",
2723
+ NODE_IDENTITY_MISMATCH: "NODE_IDENTITY_MISMATCH",
2724
+ PARTIAL_NODE_WRITE: "PARTIAL_NODE_WRITE",
2725
+ RESOURCE_NOT_ROUTED: "RESOURCE_NOT_ROUTED",
2722
2726
  TIMEOUT: "TIMEOUT",
2723
2727
  ABORTED: "ABORTED",
2724
2728
  INVALID_INPUT: "INVALID_INPUT",
@@ -2862,6 +2866,32 @@ function parseNetworkId(networkId) {
2862
2866
  }
2863
2867
  return { networkId, ownerDid, name };
2864
2868
  }
2869
+ var ROUTING_FAILURE_CODES = {
2870
+ NODE_NOT_RESPONDING: true,
2871
+ PARTIAL_NODE_WRITE: true,
2872
+ NODE_IDENTITY_MISMATCH: true,
2873
+ RESOURCE_NOT_ROUTED: true,
2874
+ DECRYPTION_DEPENDENCY_UNAVAILABLE: true,
2875
+ registry_unavailable: true,
2876
+ node_not_found: true,
2877
+ node_registry_entry_exists: true
2878
+ };
2879
+ function isRoutingFailureCode(code) {
2880
+ return Object.prototype.hasOwnProperty.call(ROUTING_FAILURE_CODES, code);
2881
+ }
2882
+ function routingFailure(error) {
2883
+ if (typeof error === "object" && error !== null && "code" in error && "message" in error && typeof error.code === "string" && typeof error.message === "string" && isRoutingFailureCode(error.code)) {
2884
+ const candidate = "meta" in error ? error.meta : void 0;
2885
+ let meta = typeof candidate === "object" && candidate !== null && !Array.isArray(candidate) ? candidate : void 0;
2886
+ if (error.code === "NODE_NOT_RESPONDING" && "hosts" in error && Array.isArray(error.hosts)) {
2887
+ meta = { ...meta, hosts: error.hosts };
2888
+ } else if (error.code === "PARTIAL_NODE_WRITE" && "succeeded" in error && Array.isArray(error.succeeded) && "failed" in error && Array.isArray(error.failed)) {
2889
+ meta = { ...meta, succeeded: error.succeeded, failed: error.failed };
2890
+ }
2891
+ return { code: error.code, message: error.message, ...error instanceof Error ? { cause: error } : {}, ...meta ? { meta } : {} };
2892
+ }
2893
+ return void 0;
2894
+ }
2865
2895
  function parsePermissionHint(value) {
2866
2896
  if (typeof value !== "object" || value === null || Array.isArray(value)) return void 0;
2867
2897
  const candidate = value;
@@ -3134,6 +3164,8 @@ function storageRejectionError(service, status, meta, responseText) {
3134
3164
  return status === 402 ? storageQuotaExceededError(service, STORAGE_FULL_MESSAGE, quotaMeta) : storageLimitReachedError(service, STORAGE_WRITE_TOO_LARGE_MESSAGE, quotaMeta);
3135
3165
  }
3136
3166
  function wrapError(service, error, defaultCode = ErrorCodes.NETWORK_ERROR) {
3167
+ const routing = routingFailure(error);
3168
+ if (routing) return { ...routing, service };
3137
3169
  if (error instanceof Error) {
3138
3170
  if (isRequestTimeoutError(error)) {
3139
3171
  return timeoutError(service, error.timeoutMs, error);
@@ -5067,6 +5099,10 @@ var ErrorCodes2 = {
5067
5099
  /** HTTP 401: a delegation the cited one rests on was revoked. */
5068
5100
  AUTH_DELEGATION_ANCESTOR_REVOKED: "AUTH_DELEGATION_ANCESTOR_REVOKED",
5069
5101
  NETWORK_ERROR: "NETWORK_ERROR",
5102
+ NODE_NOT_RESPONDING: "NODE_NOT_RESPONDING",
5103
+ NODE_IDENTITY_MISMATCH: "NODE_IDENTITY_MISMATCH",
5104
+ PARTIAL_NODE_WRITE: "PARTIAL_NODE_WRITE",
5105
+ RESOURCE_NOT_ROUTED: "RESOURCE_NOT_ROUTED",
5070
5106
  TIMEOUT: "TIMEOUT",
5071
5107
  ABORTED: "ABORTED",
5072
5108
  INVALID_INPUT: "INVALID_INPUT",
@@ -8574,7 +8610,7 @@ function replicaErrorFromService(error, context, request) {
8574
8610
  if (status !== void 0) {
8575
8611
  return new ReplicaError(ReplicaErrorCode.NODE_ERROR, `${context}: ${error.message}`, detail);
8576
8612
  }
8577
- if (error.code === "NETWORK_ERROR" || /TIMEOUT|ABORT/.test(error.code)) {
8613
+ if (error.code === "NETWORK_ERROR" || error.code === "NODE_NOT_RESPONDING" || /TIMEOUT|ABORT/.test(error.code)) {
8578
8614
  return new ReplicaError(ReplicaErrorCode.NETWORK_ERROR, `${context}: ${error.message}`, detail);
8579
8615
  }
8580
8616
  return new ReplicaError(ReplicaErrorCode.NODE_ERROR, `${context}: ${error.message}`, detail);