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
package/dist/index.cjs CHANGED
@@ -22323,7 +22323,7 @@ var init_remoteClient = __esm({
22323
22323
  "src/orchestration/remoteClient.ts"() {
22324
22324
  "use strict";
22325
22325
  init_errors();
22326
- REMOTE_ORCHESTRATION_PROTOCOL = "memeloop.resource.v1";
22326
+ REMOTE_ORCHESTRATION_PROTOCOL = "memeloop.resource.v2";
22327
22327
  REMOTE_OPERATIONS = /* @__PURE__ */ new Set([
22328
22328
  "capabilities",
22329
22329
  "apply",
@@ -28888,8 +28888,12 @@ var DeviceCloudConnectionCoordinator = class {
28888
28888
  async stop() {
28889
28889
  this.started = false;
28890
28890
  this.clearTimer();
28891
- this.controller.abort(new Error("device cloud coordinator stopped"));
28891
+ const stoppedController = this.controller;
28892
+ stoppedController.abort(new Error("device cloud coordinator stopped"));
28892
28893
  await this.inFlight?.catch(() => void 0);
28894
+ if (this.controller === stoppedController) {
28895
+ this.controller = new AbortController();
28896
+ }
28893
28897
  }
28894
28898
  async setConfiguration(configuration) {
28895
28899
  this.configuration = configuration;
@@ -29435,39 +29439,92 @@ async function readSingleRequest(stream, maxFrameBytes) {
29435
29439
  }
29436
29440
  async function* withWatchBookmarks(source, request, signal) {
29437
29441
  const iterator = source[Symbol.asyncIterator]();
29438
- let pending2 = iterator.next();
29442
+ let activity;
29443
+ let activityWaiter;
29444
+ let bookmarkTimer;
29445
+ let readInFlight = false;
29446
+ let lastResourceVersion = watchResourceVersion(request.payload.options) ?? "0";
29447
+ const clearBookmarkTimer = () => {
29448
+ if (bookmarkTimer !== void 0) clearTimeout(bookmarkTimer);
29449
+ bookmarkTimer = void 0;
29450
+ };
29451
+ const publishActivity = (value) => {
29452
+ if (activityWaiter) {
29453
+ const resolve = activityWaiter;
29454
+ activityWaiter = void 0;
29455
+ clearBookmarkTimer();
29456
+ resolve(value);
29457
+ return;
29458
+ }
29459
+ activity = value;
29460
+ };
29461
+ const readNext = () => {
29462
+ if (readInFlight) return;
29463
+ readInFlight = true;
29464
+ void iterator.next().then(
29465
+ (value) => {
29466
+ readInFlight = false;
29467
+ publishActivity({ kind: "value", value });
29468
+ },
29469
+ (error2) => {
29470
+ readInFlight = false;
29471
+ publishActivity({ kind: "error", error: error2 });
29472
+ }
29473
+ );
29474
+ };
29475
+ const waitForActivity = () => {
29476
+ if (activity) {
29477
+ const value = activity;
29478
+ activity = void 0;
29479
+ return Promise.resolve(value);
29480
+ }
29481
+ if (signal.aborted) return Promise.resolve({ kind: "aborted" });
29482
+ return new Promise((resolve) => {
29483
+ activityWaiter = resolve;
29484
+ bookmarkTimer = setTimeout(() => {
29485
+ bookmarkTimer = void 0;
29486
+ activityWaiter = void 0;
29487
+ resolve({ kind: "bookmark" });
29488
+ }, WATCH_BOOKMARK_INTERVAL_MS);
29489
+ });
29490
+ };
29491
+ const onAbort = () => {
29492
+ publishActivity({ kind: "aborted" });
29493
+ };
29494
+ signal.addEventListener("abort", onAbort, { once: true });
29495
+ readNext();
29439
29496
  try {
29440
29497
  for (; ; ) {
29441
- const result = await Promise.race([
29442
- pending2.then((value) => ({ kind: "value", value })),
29443
- new Promise((resolve) => {
29444
- const timer = setTimeout(() => {
29445
- resolve({ kind: "bookmark" });
29446
- }, WATCH_BOOKMARK_INTERVAL_MS);
29447
- signal.addEventListener("abort", () => {
29448
- clearTimeout(timer);
29449
- resolve({ kind: "bookmark" });
29450
- }, { once: true });
29451
- })
29452
- ]);
29453
- if (signal.aborted) return;
29498
+ const result = await waitForActivity();
29499
+ if (result.kind === "aborted") return;
29454
29500
  if (result.kind === "bookmark") {
29455
29501
  yield {
29456
29502
  protocol: request.protocol,
29457
29503
  requestId: request.requestId,
29458
29504
  ok: true,
29459
- result: { type: "BOOKMARK", resourceVersion: String(Date.now()) }
29505
+ result: { type: "BOOKMARK", resourceVersion: lastResourceVersion }
29460
29506
  };
29461
29507
  continue;
29462
29508
  }
29509
+ if (result.kind === "error") throw result.error;
29463
29510
  if (result.value.done) return;
29464
- yield result.value.value;
29465
- pending2 = iterator.next();
29511
+ const response = result.value.value;
29512
+ lastResourceVersion = response.ok ? watchResourceVersion(response.result) ?? lastResourceVersion : lastResourceVersion;
29513
+ yield response;
29514
+ readNext();
29466
29515
  }
29467
29516
  } finally {
29517
+ clearBookmarkTimer();
29518
+ activityWaiter = void 0;
29519
+ signal.removeEventListener("abort", onAbort);
29468
29520
  void iterator.return?.();
29469
29521
  }
29470
29522
  }
29523
+ function watchResourceVersion(value) {
29524
+ if (value === null || typeof value !== "object" || Array.isArray(value)) return void 0;
29525
+ const resourceVersion = value.resourceVersion;
29526
+ return typeof resourceVersion === "string" && resourceVersion.length > 0 ? resourceVersion : void 0;
29527
+ }
29471
29528
  function createDeviceOrchestrationStreamHandler(options) {
29472
29529
  const maxFrameBytes = options.maxFrameBytes ?? DEFAULT_MAX_FRAME_BYTES;
29473
29530
  assertFrameLimit(maxFrameBytes);
@@ -29947,7 +30004,7 @@ async function parseDevicePairingInvite(serialized, options) {
29947
30004
  }
29948
30005
 
29949
30006
  // src/device-network/peerDriverTransport.ts
29950
- var PEER_DRIVER_PROTOCOL_VERSION = "memeloop-peer-driver/v1";
30007
+ var PEER_DRIVER_PROTOCOL_VERSION = "memeloop-peer-driver/v2";
29951
30008
  var IDENTIFIER_PATTERN = /^[A-Za-z0-9][A-Za-z0-9._:/-]*$/;
29952
30009
  var MAX_ASSIGNMENT_ID_LENGTH = 256;
29953
30010
  var MAX_OPERATION_LENGTH = 128;