@tinycloud/sdk-services 3.11.0 → 3.12.0-beta.16

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.
Files changed (71) hide show
  1. package/dist/{BaseService-Ma2MwJAd.d.ts → BaseService-BRDG69KR.d.ts} +1 -1
  2. package/dist/{BaseService-O0iyuFLk.d.cts → BaseService-CdBkfPGE.d.cts} +1 -1
  3. package/dist/{IHooksService-4QNODVy6.d.cts → IHooksService-C9p3stsB.d.cts} +1 -1
  4. package/dist/{IHooksService-CvTpJbQD.d.ts → IHooksService-D6eyZat1.d.ts} +1 -1
  5. package/dist/{ISQLService-Aly1CBsW.d.ts → ISQLService-B_4KcGA-.d.ts} +1 -1
  6. package/dist/{ISQLService-BOgWzHLT.d.cts → ISQLService-C6nNpcls.d.cts} +1 -1
  7. package/dist/context.cjs +4 -0
  8. package/dist/context.cjs.map +1 -1
  9. package/dist/context.d.cts +1 -1
  10. package/dist/context.d.ts +1 -1
  11. package/dist/context.js +4 -0
  12. package/dist/context.js.map +1 -1
  13. package/dist/encryption/index.cjs +276 -14
  14. package/dist/encryption/index.cjs.map +1 -1
  15. package/dist/encryption/index.d.cts +26 -28
  16. package/dist/encryption/index.d.ts +26 -28
  17. package/dist/encryption/index.js +268 -14
  18. package/dist/encryption/index.js.map +1 -1
  19. package/dist/encryption/named-keys.cjs +225 -14
  20. package/dist/encryption/named-keys.cjs.map +1 -1
  21. package/dist/encryption/named-keys.d.cts +7 -2
  22. package/dist/encryption/named-keys.d.ts +7 -2
  23. package/dist/encryption/named-keys.js +225 -14
  24. package/dist/encryption/named-keys.js.map +1 -1
  25. package/dist/encryption/resource.cjs.map +1 -1
  26. package/dist/encryption/resource.js.map +1 -1
  27. package/dist/feed/index.cjs +4 -0
  28. package/dist/feed/index.cjs.map +1 -1
  29. package/dist/feed/index.d.cts +3 -3
  30. package/dist/feed/index.d.ts +3 -3
  31. package/dist/feed/index.js +4 -0
  32. package/dist/feed/index.js.map +1 -1
  33. package/dist/index.cjs +523 -29
  34. package/dist/index.cjs.map +1 -1
  35. package/dist/index.d.cts +14 -12
  36. package/dist/index.d.ts +14 -12
  37. package/dist/index.js +513 -29
  38. package/dist/index.js.map +1 -1
  39. package/dist/internal/decrypt-transport-response-error.d.cts +1 -1
  40. package/dist/internal/decrypt-transport-response-error.d.ts +1 -1
  41. package/dist/kv/index.cjs +48 -11
  42. package/dist/kv/index.cjs.map +1 -1
  43. package/dist/kv/index.d.cts +5 -5
  44. package/dist/kv/index.d.ts +5 -5
  45. package/dist/kv/index.js +48 -11
  46. package/dist/kv/index.js.map +1 -1
  47. package/dist/kv/replication/index.cjs +39 -8
  48. package/dist/kv/replication/index.cjs.map +1 -1
  49. package/dist/kv/replication/index.d.cts +3 -3
  50. package/dist/kv/replication/index.d.ts +3 -3
  51. package/dist/kv/replication/index.js +38 -7
  52. package/dist/kv/replication/index.js.map +1 -1
  53. package/dist/{scope-DEgc9f-W.d.cts → scope-DtcbyRKY.d.cts} +1 -1
  54. package/dist/{scope-BZr0QwxX.d.ts → scope-J20PQP3u.d.ts} +1 -1
  55. package/dist/sql/index.cjs +36 -0
  56. package/dist/sql/index.cjs.map +1 -1
  57. package/dist/sql/index.d.cts +4 -4
  58. package/dist/sql/index.d.ts +4 -4
  59. package/dist/sql/index.js +36 -0
  60. package/dist/sql/index.js.map +1 -1
  61. package/dist/telemetry/requestLog.cjs +4 -0
  62. package/dist/telemetry/requestLog.cjs.map +1 -1
  63. package/dist/telemetry/requestLog.d.cts +1 -1
  64. package/dist/telemetry/requestLog.d.ts +1 -1
  65. package/dist/telemetry/requestLog.js +4 -0
  66. package/dist/telemetry/requestLog.js.map +1 -1
  67. package/dist/{types-D4XbIfFJ.d.cts → types-DfqNz9Nu.d.cts} +135 -6
  68. package/dist/{types-CSd0RYir.d.ts → types-DjAP8dve.d.cts} +4 -0
  69. package/dist/{types-CSd0RYir.d.cts → types-DjAP8dve.d.ts} +4 -0
  70. package/dist/{types-Bf91gup6.d.ts → types-Nvi_RckJ.d.ts} +135 -6
  71. package/package.json +4 -1
@@ -1,4 +1,4 @@
1
- import { P as PermissionHint } from '../types-CSd0RYir.cjs';
1
+ import { P as PermissionHint } from '../types-DjAP8dve.cjs';
2
2
 
3
3
  /** A reachable node returned an HTTP failure for a decrypt request. */
4
4
  declare class DecryptTransportResponseError extends Error {
@@ -1,4 +1,4 @@
1
- import { P as PermissionHint } from '../types-CSd0RYir.js';
1
+ import { P as PermissionHint } from '../types-DjAP8dve.js';
2
2
 
3
3
  /** A reachable node returned an HTTP failure for a decrypt request. */
4
4
  declare class DecryptTransportResponseError extends Error {
package/dist/kv/index.cjs CHANGED
@@ -44,6 +44,10 @@ var ErrorCodes = {
44
44
  /** HTTP 401: a delegation the cited one rests on was revoked. */
45
45
  AUTH_DELEGATION_ANCESTOR_REVOKED: "AUTH_DELEGATION_ANCESTOR_REVOKED",
46
46
  NETWORK_ERROR: "NETWORK_ERROR",
47
+ NODE_NOT_RESPONDING: "NODE_NOT_RESPONDING",
48
+ NODE_IDENTITY_MISMATCH: "NODE_IDENTITY_MISMATCH",
49
+ PARTIAL_NODE_WRITE: "PARTIAL_NODE_WRITE",
50
+ RESOURCE_NOT_ROUTED: "RESOURCE_NOT_ROUTED",
47
51
  TIMEOUT: "TIMEOUT",
48
52
  ABORTED: "ABORTED",
49
53
  INVALID_INPUT: "INVALID_INPUT",
@@ -195,6 +199,34 @@ function parseNetworkId(networkId) {
195
199
  return { networkId, ownerDid, name };
196
200
  }
197
201
 
202
+ // src/resourceRouting.ts
203
+ var ROUTING_FAILURE_CODES = {
204
+ NODE_NOT_RESPONDING: true,
205
+ PARTIAL_NODE_WRITE: true,
206
+ NODE_IDENTITY_MISMATCH: true,
207
+ RESOURCE_NOT_ROUTED: true,
208
+ DECRYPTION_DEPENDENCY_UNAVAILABLE: true,
209
+ registry_unavailable: true,
210
+ node_not_found: true,
211
+ node_registry_entry_exists: true
212
+ };
213
+ function isRoutingFailureCode(code) {
214
+ return Object.prototype.hasOwnProperty.call(ROUTING_FAILURE_CODES, code);
215
+ }
216
+ function routingFailure(error) {
217
+ if (typeof error === "object" && error !== null && "code" in error && "message" in error && typeof error.code === "string" && typeof error.message === "string" && isRoutingFailureCode(error.code)) {
218
+ const candidate = "meta" in error ? error.meta : void 0;
219
+ let meta = typeof candidate === "object" && candidate !== null && !Array.isArray(candidate) ? candidate : void 0;
220
+ if (error.code === "NODE_NOT_RESPONDING" && "hosts" in error && Array.isArray(error.hosts)) {
221
+ meta = { ...meta, hosts: error.hosts };
222
+ } else if (error.code === "PARTIAL_NODE_WRITE" && "succeeded" in error && Array.isArray(error.succeeded) && "failed" in error && Array.isArray(error.failed)) {
223
+ meta = { ...meta, succeeded: error.succeeded, failed: error.failed };
224
+ }
225
+ return { code: error.code, message: error.message, ...error instanceof Error ? { cause: error } : {}, ...meta ? { meta } : {} };
226
+ }
227
+ return void 0;
228
+ }
229
+
198
230
  // src/errors.ts
199
231
  function parsePermissionHint(value) {
200
232
  if (typeof value !== "object" || value === null || Array.isArray(value)) return void 0;
@@ -468,6 +500,8 @@ function storageRejectionError(service, status, meta, responseText) {
468
500
  return status === 402 ? storageQuotaExceededError(service, STORAGE_FULL_MESSAGE, quotaMeta) : storageLimitReachedError(service, STORAGE_WRITE_TOO_LARGE_MESSAGE, quotaMeta);
469
501
  }
470
502
  function wrapError(service, error, defaultCode = ErrorCodes.NETWORK_ERROR) {
503
+ const routing = routingFailure(error);
504
+ if (routing) return { ...routing, service };
471
505
  if (error instanceof Error) {
472
506
  if (isRequestTimeoutError(error)) {
473
507
  return timeoutError(service, error.timeoutMs, error);
@@ -979,11 +1013,15 @@ var KVService = class extends BaseService {
979
1013
  }
980
1014
  /** Delay KV routing until an asynchronously loaded read-through is attached. */
981
1015
  setReadThroughReady(ready) {
982
- const settled = ready.then(() => void 0, () => void 0);
983
- this.readThroughReady = settled;
984
- void settled.then(() => {
985
- if (this.readThroughReady === settled) this.readThroughReady = null;
986
- });
1016
+ const start = () => {
1017
+ if (typeof ready === "function") ready = Promise.resolve().then(ready);
1018
+ const finish = () => {
1019
+ if (this.readThroughReady === start) this.readThroughReady = null;
1020
+ };
1021
+ return ready.then(finish, finish);
1022
+ };
1023
+ this.readThroughReady = start;
1024
+ if (typeof ready !== "function") void start();
987
1025
  }
988
1026
  /**
989
1027
  * Get the service configuration.
@@ -1230,7 +1268,6 @@ var KVService = class extends BaseService {
1230
1268
  return aligned;
1231
1269
  }
1232
1270
  async batchRead(keys, action, options) {
1233
- if (this.readThroughReady !== null) await this.readThroughReady;
1234
1271
  if (!this.requireAuth()) return err(authRequiredError("kv"));
1235
1272
  if (keys.length === 0) return ok({ results: [], count: 0 });
1236
1273
  if (keys.length > MAX_KV_BATCH_READ_ITEMS) {
@@ -1481,7 +1518,7 @@ var KVService = class extends BaseService {
1481
1518
  */
1482
1519
  async get(key, options) {
1483
1520
  return this.withTelemetry("get", key, async () => {
1484
- if (this.readThroughReady !== null) await this.readThroughReady;
1521
+ if (options?.source !== "network" && this.readThroughReady !== null) await this.readThroughReady();
1485
1522
  if (!this.requireAuth()) {
1486
1523
  return err(authRequiredError("kv"));
1487
1524
  }
@@ -1600,7 +1637,7 @@ var KVService = class extends BaseService {
1600
1637
  */
1601
1638
  async put(key, value, options) {
1602
1639
  return this.withTelemetry("put", key, async () => {
1603
- if (this.readThroughReady !== null) await this.readThroughReady;
1640
+ if (this.readThroughReady !== null) await this.readThroughReady();
1604
1641
  if (!this.requireAuth()) {
1605
1642
  return err(authRequiredError("kv"));
1606
1643
  }
@@ -1685,7 +1722,7 @@ var KVService = class extends BaseService {
1685
1722
  */
1686
1723
  async batchPut(items, options) {
1687
1724
  return this.withTelemetry("batchPut", String(items.length), async () => {
1688
- if (this.readThroughReady !== null) await this.readThroughReady;
1725
+ if (this.readThroughReady !== null) await this.readThroughReady();
1689
1726
  if (!this.requireAuth()) {
1690
1727
  return err(authRequiredError("kv"));
1691
1728
  }
@@ -1884,7 +1921,7 @@ var KVService = class extends BaseService {
1884
1921
  */
1885
1922
  async list(options) {
1886
1923
  return this.withTelemetry("list", options?.prefix, async () => {
1887
- if (this.readThroughReady !== null) await this.readThroughReady;
1924
+ if (options?.source !== "network" && this.readThroughReady !== null) await this.readThroughReady();
1888
1925
  if (!this.requireAuth()) {
1889
1926
  return err(authRequiredError("kv"));
1890
1927
  }
@@ -2172,7 +2209,7 @@ var KVService = class extends BaseService {
2172
2209
  */
2173
2210
  async delete(key, options) {
2174
2211
  return this.withTelemetry("delete", key, async () => {
2175
- if (this.readThroughReady !== null) await this.readThroughReady;
2212
+ if (this.readThroughReady !== null) await this.readThroughReady();
2176
2213
  if (!this.requireAuth()) {
2177
2214
  return err(authRequiredError("kv"));
2178
2215
  }