memeloop 0.2.0 → 0.2.1

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 (39) hide show
  1. package/dist/browser.cjs +1 -1
  2. package/dist/browser.cjs.map +1 -1
  3. package/dist/browser.d.cts +5 -5
  4. package/dist/browser.d.ts +5 -5
  5. package/dist/browser.js +1 -1
  6. package/dist/{chunk-ECNKBH5A.js → chunk-E5R24U4I.js} +76 -19
  7. package/dist/chunk-E5R24U4I.js.map +1 -0
  8. package/dist/{chunk-CCEFAOSH.js → chunk-WHXFUMDE.js} +2 -2
  9. package/dist/{chunk-CCEFAOSH.js.map → chunk-WHXFUMDE.js.map} +1 -1
  10. package/dist/device-network-portable.cjs +75 -18
  11. package/dist/device-network-portable.cjs.map +1 -1
  12. package/dist/device-network-portable.d.cts +3 -3
  13. package/dist/device-network-portable.d.ts +3 -3
  14. package/dist/device-network-portable.js +1 -1
  15. package/dist/device-network.cjs +75 -18
  16. package/dist/device-network.cjs.map +1 -1
  17. package/dist/device-network.d.cts +2 -2
  18. package/dist/device-network.d.ts +2 -2
  19. package/dist/device-network.js +1 -1
  20. package/dist/index.cjs +77 -20
  21. package/dist/index.cjs.map +1 -1
  22. package/dist/index.d.cts +4 -4
  23. package/dist/index.d.ts +4 -4
  24. package/dist/index.js +3 -3
  25. package/dist/index.js.map +1 -1
  26. package/dist/loop-api.cjs.map +1 -1
  27. package/dist/{orchestration-portable-BbkwLbC9.d.ts → orchestration-portable-B4udCSVd.d.ts} +1 -1
  28. package/dist/{orchestration-portable-DNKzAtNq.d.cts → orchestration-portable-BWaCsCGK.d.cts} +1 -1
  29. package/dist/orchestration-portable.cjs +1 -1
  30. package/dist/orchestration-portable.cjs.map +1 -1
  31. package/dist/orchestration-portable.d.cts +2 -2
  32. package/dist/orchestration-portable.d.ts +2 -2
  33. package/dist/orchestration-portable.js +1 -1
  34. package/dist/{pairingInvite-DDx_-IAp.d.cts → pairingInvite-DENOiqa0.d.cts} +1 -1
  35. package/dist/{pairingInvite-Dkz8CLsb.d.ts → pairingInvite-DZy77i0p.d.ts} +1 -1
  36. package/dist/{remoteClient-BKmQEQY9.d.cts → remoteClient-DFIyCZEv.d.cts} +1 -1
  37. package/dist/{remoteClient-D5hco6cS.d.ts → remoteClient-DwBCoHpc.d.ts} +1 -1
  38. package/package.json +1 -1
  39. package/dist/chunk-ECNKBH5A.js.map +0 -1
@@ -124,8 +124,12 @@ var DeviceCloudConnectionCoordinator = class {
124
124
  async stop() {
125
125
  this.started = false;
126
126
  this.clearTimer();
127
- this.controller.abort(new Error("device cloud coordinator stopped"));
127
+ const stoppedController = this.controller;
128
+ stoppedController.abort(new Error("device cloud coordinator stopped"));
128
129
  await this.inFlight?.catch(() => void 0);
130
+ if (this.controller === stoppedController) {
131
+ this.controller = new AbortController();
132
+ }
129
133
  }
130
134
  async setConfiguration(configuration) {
131
135
  this.configuration = configuration;
@@ -696,39 +700,92 @@ async function readSingleRequest(stream, maxFrameBytes) {
696
700
  }
697
701
  async function* withWatchBookmarks(source, request, signal) {
698
702
  const iterator = source[Symbol.asyncIterator]();
699
- let pending = iterator.next();
703
+ let activity;
704
+ let activityWaiter;
705
+ let bookmarkTimer;
706
+ let readInFlight = false;
707
+ let lastResourceVersion = watchResourceVersion(request.payload.options) ?? "0";
708
+ const clearBookmarkTimer = () => {
709
+ if (bookmarkTimer !== void 0) clearTimeout(bookmarkTimer);
710
+ bookmarkTimer = void 0;
711
+ };
712
+ const publishActivity = (value) => {
713
+ if (activityWaiter) {
714
+ const resolve = activityWaiter;
715
+ activityWaiter = void 0;
716
+ clearBookmarkTimer();
717
+ resolve(value);
718
+ return;
719
+ }
720
+ activity = value;
721
+ };
722
+ const readNext = () => {
723
+ if (readInFlight) return;
724
+ readInFlight = true;
725
+ void iterator.next().then(
726
+ (value) => {
727
+ readInFlight = false;
728
+ publishActivity({ kind: "value", value });
729
+ },
730
+ (error) => {
731
+ readInFlight = false;
732
+ publishActivity({ kind: "error", error });
733
+ }
734
+ );
735
+ };
736
+ const waitForActivity = () => {
737
+ if (activity) {
738
+ const value = activity;
739
+ activity = void 0;
740
+ return Promise.resolve(value);
741
+ }
742
+ if (signal.aborted) return Promise.resolve({ kind: "aborted" });
743
+ return new Promise((resolve) => {
744
+ activityWaiter = resolve;
745
+ bookmarkTimer = setTimeout(() => {
746
+ bookmarkTimer = void 0;
747
+ activityWaiter = void 0;
748
+ resolve({ kind: "bookmark" });
749
+ }, WATCH_BOOKMARK_INTERVAL_MS);
750
+ });
751
+ };
752
+ const onAbort = () => {
753
+ publishActivity({ kind: "aborted" });
754
+ };
755
+ signal.addEventListener("abort", onAbort, { once: true });
756
+ readNext();
700
757
  try {
701
758
  for (; ; ) {
702
- const result = await Promise.race([
703
- pending.then((value) => ({ kind: "value", value })),
704
- new Promise((resolve) => {
705
- const timer = setTimeout(() => {
706
- resolve({ kind: "bookmark" });
707
- }, WATCH_BOOKMARK_INTERVAL_MS);
708
- signal.addEventListener("abort", () => {
709
- clearTimeout(timer);
710
- resolve({ kind: "bookmark" });
711
- }, { once: true });
712
- })
713
- ]);
714
- if (signal.aborted) return;
759
+ const result = await waitForActivity();
760
+ if (result.kind === "aborted") return;
715
761
  if (result.kind === "bookmark") {
716
762
  yield {
717
763
  protocol: request.protocol,
718
764
  requestId: request.requestId,
719
765
  ok: true,
720
- result: { type: "BOOKMARK", resourceVersion: String(Date.now()) }
766
+ result: { type: "BOOKMARK", resourceVersion: lastResourceVersion }
721
767
  };
722
768
  continue;
723
769
  }
770
+ if (result.kind === "error") throw result.error;
724
771
  if (result.value.done) return;
725
- yield result.value.value;
726
- pending = iterator.next();
772
+ const response = result.value.value;
773
+ lastResourceVersion = response.ok ? watchResourceVersion(response.result) ?? lastResourceVersion : lastResourceVersion;
774
+ yield response;
775
+ readNext();
727
776
  }
728
777
  } finally {
778
+ clearBookmarkTimer();
779
+ activityWaiter = void 0;
780
+ signal.removeEventListener("abort", onAbort);
729
781
  void iterator.return?.();
730
782
  }
731
783
  }
784
+ function watchResourceVersion(value) {
785
+ if (value === null || typeof value !== "object" || Array.isArray(value)) return void 0;
786
+ const resourceVersion = value.resourceVersion;
787
+ return typeof resourceVersion === "string" && resourceVersion.length > 0 ? resourceVersion : void 0;
788
+ }
732
789
  function createDeviceOrchestrationStreamHandler(options) {
733
790
  const maxFrameBytes = options.maxFrameBytes ?? DEFAULT_MAX_FRAME_BYTES;
734
791
  assertFrameLimit(maxFrameBytes);