statewire 0.23.0 → 0.24.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 (43) hide show
  1. package/dist/client/core.d.ts +4 -3
  2. package/dist/client/core.d.ts.map +1 -1
  3. package/dist/client/core.js +56 -45
  4. package/dist/client/core.js.map +1 -1
  5. package/dist/client/session.d.ts +56 -12
  6. package/dist/client/session.d.ts.map +1 -1
  7. package/dist/client/session.js +632 -260
  8. package/dist/client/session.js.map +1 -1
  9. package/dist/client/sessionStore.d.ts +1 -0
  10. package/dist/client/sessionStore.d.ts.map +1 -1
  11. package/dist/client/sessionStore.js +1 -0
  12. package/dist/client/sessionStore.js.map +1 -1
  13. package/dist/host/host.d.ts +6 -5
  14. package/dist/host/host.d.ts.map +1 -1
  15. package/dist/host/host.js.map +1 -1
  16. package/dist/indexedDb.d.ts +15 -0
  17. package/dist/indexedDb.d.ts.map +1 -0
  18. package/dist/indexedDb.js +171 -0
  19. package/dist/indexedDb.js.map +1 -0
  20. package/dist/statewire.d.ts +117 -59
  21. package/dist/statewire.d.ts.map +1 -1
  22. package/dist/statewire.js +13 -25
  23. package/dist/statewire.js.map +1 -1
  24. package/dist/storage.d.ts +42 -0
  25. package/dist/storage.d.ts.map +1 -1
  26. package/dist/storage.js +387 -125
  27. package/dist/storage.js.map +1 -1
  28. package/dist/transports/remote.d.ts.map +1 -1
  29. package/dist/transports/remote.js +7 -9
  30. package/dist/transports/remote.js.map +1 -1
  31. package/dist/types.d.ts +6 -7
  32. package/dist/types.d.ts.map +1 -1
  33. package/dist/types.js.map +1 -1
  34. package/package.json +2 -1
  35. package/src/client/core.ts +81 -64
  36. package/src/client/session.ts +886 -424
  37. package/src/client/sessionStore.ts +2 -0
  38. package/src/host/host.ts +10 -3
  39. package/src/indexedDb.ts +167 -0
  40. package/src/statewire.ts +133 -86
  41. package/src/storage.ts +548 -112
  42. package/src/transports/remote.ts +13 -14
  43. package/src/types.ts +6 -7
@@ -4,13 +4,12 @@ import type { Statewire } from "../types";
4
4
  import {
5
5
  documentSource,
6
6
  invokeProtocol,
7
- discardFailed,
8
- failedCommands,
9
7
  holdOutbox,
8
+ insertOutbox,
10
9
  outboxEntries,
11
10
  releaseOutbox,
12
11
  removeOutbox,
13
- retryFailed,
12
+ updateOutbox,
14
13
  setTransport,
15
14
  useStatewireSession,
16
15
  setContext,
@@ -48,19 +47,19 @@ export const useStatewireRemote = <
48
47
  params: readonly unknown[],
49
48
  options?: StatewireClient.InvokeOptions,
50
49
  ) => invokeProtocol(s, protocol, method, params, options),
51
- failures: {
52
- list: () => failedCommands(s),
53
- retry: (entry: StatewireClient.FailedCommand) => retryFailed(s, entry),
54
- discard: (entry: StatewireClient.FailedCommand) =>
55
- discardFailed(s, entry),
56
- },
57
50
  outbox: {
58
51
  list: () => outboxEntries(s),
59
- hold: (entry: StatewireClient.OutboxEntry, meta?: unknown) =>
60
- holdOutbox(s, entry, meta),
61
- release: (entry: StatewireClient.OutboxEntry) =>
62
- releaseOutbox(s, entry),
63
- remove: (entry: StatewireClient.OutboxEntry) => removeOutbox(s, entry),
52
+ clientId: () => s.record.clientId,
53
+ hold: (id: string) => holdOutbox(s, id),
54
+ release: (id: string) => releaseOutbox(s, id),
55
+ remove: (id: string) => removeOutbox(s, id),
56
+ update: (
57
+ id: string,
58
+ fn: (
59
+ entry: StatewireClient.OutboxEntry,
60
+ ) => StatewireClient.OutboxPatch,
61
+ ) => updateOutbox(s, id, fn),
62
+ insert: (entry: StatewireClient.OutboxInsert) => insertOutbox(s, entry),
64
63
  },
65
64
  }),
66
65
  [s],
package/src/types.ts CHANGED
@@ -30,6 +30,8 @@ export namespace Statewire {
30
30
  status: "queued" | "posted" | "applied" | "settled";
31
31
  result?: unknown;
32
32
  failure?: StatewireClient.SendFailure;
33
+ /** The command's client-only `localMeta`. */
34
+ localMeta?: unknown;
33
35
  };
34
36
  }[keyof TCommands];
35
37
 
@@ -87,18 +89,15 @@ export interface Statewire<
87
89
  attaching?: (attach: StatewireHost.Attach) => void;
88
90
  /** Called by the serving host when an attach ends; its ephemeral documents and includes are gone. */
89
91
  detached?: (attach: StatewireHost.Attach) => void;
90
- /** The retained failed-send lane; present on transports with a durable session. */
91
- failures?: {
92
- list: () => readonly StatewireClient.FailedCommand[];
93
- retry: (entry: StatewireClient.FailedCommand) => Promise<unknown>;
94
- discard: (entry: StatewireClient.FailedCommand) => void;
95
- };
96
- /** The outbox of commands without a seq; present on transports with a durable session. */
92
+ /** The outbox; present on transports with a durable session. */
97
93
  outbox?: {
98
94
  list: () => readonly StatewireClient.OutboxEntry[];
95
+ clientId: () => string;
99
96
  hold: StatewireClient.Outbox["hold"];
100
97
  release: StatewireClient.Outbox["release"];
101
98
  remove: StatewireClient.Outbox["remove"];
99
+ update: StatewireClient.Outbox["update"];
100
+ insert: StatewireClient.Outbox["insert"];
102
101
  };
103
102
  }
104
103