@tinycloud/sdk-services 3.12.0-beta.10 → 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.
@@ -550,7 +550,7 @@ declare class KVService extends BaseService implements IKVService {
550
550
  private readThrough;
551
551
  private readThroughReady;
552
552
  /** Delay KV routing until an asynchronously loaded read-through is attached. */
553
- setReadThroughReady(ready: Promise<unknown>): void;
553
+ setReadThroughReady(ready: Promise<unknown> | (() => Promise<unknown>)): void;
554
554
  /**
555
555
  * Create a new KVService instance.
556
556
  *
@@ -550,7 +550,7 @@ declare class KVService extends BaseService implements IKVService {
550
550
  private readThrough;
551
551
  private readThroughReady;
552
552
  /** Delay KV routing until an asynchronously loaded read-through is attached. */
553
- setReadThroughReady(ready: Promise<unknown>): void;
553
+ setReadThroughReady(ready: Promise<unknown> | (() => Promise<unknown>)): void;
554
554
  /**
555
555
  * Create a new KVService instance.
556
556
  *
package/dist/kv/index.js CHANGED
@@ -979,11 +979,15 @@ var KVService = class extends BaseService {
979
979
  }
980
980
  /** Delay KV routing until an asynchronously loaded read-through is attached. */
981
981
  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
- });
982
+ const start = () => {
983
+ if (typeof ready === "function") ready = Promise.resolve().then(ready);
984
+ const finish = () => {
985
+ if (this.readThroughReady === start) this.readThroughReady = null;
986
+ };
987
+ return ready.then(finish, finish);
988
+ };
989
+ this.readThroughReady = start;
990
+ if (typeof ready !== "function") void start();
987
991
  }
988
992
  /**
989
993
  * Get the service configuration.
@@ -1230,7 +1234,6 @@ var KVService = class extends BaseService {
1230
1234
  return aligned;
1231
1235
  }
1232
1236
  async batchRead(keys, action, options) {
1233
- if (this.readThroughReady !== null) await this.readThroughReady;
1234
1237
  if (!this.requireAuth()) return err(authRequiredError("kv"));
1235
1238
  if (keys.length === 0) return ok({ results: [], count: 0 });
1236
1239
  if (keys.length > MAX_KV_BATCH_READ_ITEMS) {
@@ -1481,7 +1484,7 @@ var KVService = class extends BaseService {
1481
1484
  */
1482
1485
  async get(key, options) {
1483
1486
  return this.withTelemetry("get", key, async () => {
1484
- if (this.readThroughReady !== null) await this.readThroughReady;
1487
+ if (options?.source !== "network" && this.readThroughReady !== null) await this.readThroughReady();
1485
1488
  if (!this.requireAuth()) {
1486
1489
  return err(authRequiredError("kv"));
1487
1490
  }
@@ -1600,7 +1603,7 @@ var KVService = class extends BaseService {
1600
1603
  */
1601
1604
  async put(key, value, options) {
1602
1605
  return this.withTelemetry("put", key, async () => {
1603
- if (this.readThroughReady !== null) await this.readThroughReady;
1606
+ if (this.readThroughReady !== null) await this.readThroughReady();
1604
1607
  if (!this.requireAuth()) {
1605
1608
  return err(authRequiredError("kv"));
1606
1609
  }
@@ -1685,7 +1688,7 @@ var KVService = class extends BaseService {
1685
1688
  */
1686
1689
  async batchPut(items, options) {
1687
1690
  return this.withTelemetry("batchPut", String(items.length), async () => {
1688
- if (this.readThroughReady !== null) await this.readThroughReady;
1691
+ if (this.readThroughReady !== null) await this.readThroughReady();
1689
1692
  if (!this.requireAuth()) {
1690
1693
  return err(authRequiredError("kv"));
1691
1694
  }
@@ -1884,7 +1887,7 @@ var KVService = class extends BaseService {
1884
1887
  */
1885
1888
  async list(options) {
1886
1889
  return this.withTelemetry("list", options?.prefix, async () => {
1887
- if (this.readThroughReady !== null) await this.readThroughReady;
1890
+ if (options?.source !== "network" && this.readThroughReady !== null) await this.readThroughReady();
1888
1891
  if (!this.requireAuth()) {
1889
1892
  return err(authRequiredError("kv"));
1890
1893
  }
@@ -2172,7 +2175,7 @@ var KVService = class extends BaseService {
2172
2175
  */
2173
2176
  async delete(key, options) {
2174
2177
  return this.withTelemetry("delete", key, async () => {
2175
- if (this.readThroughReady !== null) await this.readThroughReady;
2178
+ if (this.readThroughReady !== null) await this.readThroughReady();
2176
2179
  if (!this.requireAuth()) {
2177
2180
  return err(authRequiredError("kv"));
2178
2181
  }