@muhkoo/connect 0.15.0-alpha.1 → 0.15.0-alpha.3

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.
package/dist/connect.d.ts CHANGED
@@ -2463,7 +2463,7 @@ declare class ShardClient {
2463
2463
  private readonly pathPrefix;
2464
2464
  private readonly fetchFn;
2465
2465
  private readonly cache?;
2466
- /** Hashes waiting for the next batch, each with everyone awaiting it. */
2466
+ /** Hashes waiting for the next batch, each with everyone awaiting it and its size if a caller gave it. */
2467
2467
  private pendingShards;
2468
2468
  private batchTimer;
2469
2469
  /** False once the server is known not to have the batch route. */
@@ -2496,8 +2496,13 @@ declare class ShardClient {
2496
2496
  /**
2497
2497
  * Fetch a shard by hash. Throws if the server returns a non-200; returns
2498
2498
  * `null` for 404 so callers can distinguish "missing" from "errored".
2499
+ *
2500
+ * `size`, the shard's byte length when known (a manifest's `shardSize`),
2501
+ * lets concurrent reads be batched within what the server will send.
2499
2502
  */
2500
- getShard(hash: string): Promise<Uint8Array | null>;
2503
+ getShard(hash: string, opts?: {
2504
+ size?: number;
2505
+ }): Promise<Uint8Array | null>;
2501
2506
  /**
2502
2507
  * Fetch from origin, COALESCING concurrent requests into one batch.
2503
2508
  *
@@ -2520,6 +2525,8 @@ declare class ShardClient {
2520
2525
  private fetchFromOrigin;
2521
2526
  /** Send one batch of whatever has accumulated, and settle those callers. */
2522
2527
  private flushShardBatch;
2528
+ /** POST one batch and settle everyone waiting on it. Never throws. */
2529
+ private sendShardBatch;
2523
2530
  /** Fetch a shard from origin. Returns `null` for 404 (or offline when a
2524
2531
  * cache is present, so RS recovery can proceed); throws otherwise. */
2525
2532
  private fetchOneFromOrigin;
@@ -4328,8 +4335,12 @@ declare class KvCache {
4328
4335
  * state but a fresh local write wins.
4329
4336
  */
4330
4337
  mergeRemote(commitment: string, fullKey: string, envelope: unknown | null, op: "set" | "delete", hlc?: string): Promise<void>;
4331
- /** Non-tombstoned full keys for a commitment (used for offline `list`). */
4332
- liveKeys(commitment: string): Promise<string[]>;
4338
+ /**
4339
+ * Non-tombstoned full keys for a commitment that start with `prefix` (all
4340
+ * of them by default), for offline `list`. The store scans the key range
4341
+ * `${commitment}|${prefix}`, so other collections are never read.
4342
+ */
4343
+ liveKeys(commitment: string, prefix?: string): Promise<string[]>;
4333
4344
  /** Queue a kv mutation for replay on reconnect. */
4334
4345
  enqueue(method: "set" | "delete", args: unknown, hlc: string, clientId: string): Promise<void>;
4335
4346
  }
@@ -4341,6 +4352,7 @@ declare class KvCache {
4341
4352
  * await client.kv.set('todos', id, { title, completed })
4342
4353
  * const todo = await client.kv.get('todos', id)
4343
4354
  * const ids = await client.kv.list('todos')
4355
+ * const keys = await client.kv.keys('todos/') // full keys, any prefix
4344
4356
  * await client.kv.delete('todos', id)
4345
4357
  * const off = client.kv.on('change', e => …) // realtime, cross-device
4346
4358
  *
@@ -4392,8 +4404,23 @@ declare class KvNamespace {
4392
4404
  get<T = unknown>(collection: string, id: string): Promise<T | null>;
4393
4405
  /** Delete `collection`/`id`. Returns whether the key existed. */
4394
4406
  delete(collection: string, id: string): Promise<boolean>;
4395
- /** List the ids present in `collection`. */
4407
+ /**
4408
+ * List the ids present in `collection`. The server filters by
4409
+ * `${collection}/` and pages; values are not fetched.
4410
+ */
4396
4411
  list(collection: string): Promise<string[]>;
4412
+ /**
4413
+ * Every key in the signed-in user's personal space that starts with
4414
+ * `prefix` (all of them when it is ""), as full keys: `todos/t1`, not
4415
+ * `t1`. Values are not fetched. The personal space is shared by every
4416
+ * app the user signs into, so expect keys you did not write: the VFS's
4417
+ * `vfs/…`, version control's `vcs/…`, the SDK's own `chat-keys` and
4418
+ * `space-keys/…`.
4419
+ *
4420
+ * The local `startsWith` filter stays on purpose: a server older than
4421
+ * the key index ignores `prefix` and returns every key.
4422
+ */
4423
+ keys(prefix?: string): Promise<string[]>;
4397
4424
  /** Reserved — server-side query is deferred (see the overhaul plan). */
4398
4425
  query(_collection: string, _filter?: unknown): Promise<never>;
4399
4426
  /**
@@ -6657,8 +6684,14 @@ interface VfsStore {
6657
6684
  get(key: string): Promise<unknown | null>;
6658
6685
  put(key: string, value: unknown): Promise<void>;
6659
6686
  delete(key: string): Promise<void>;
6660
- /** Every key in the store — the personal space is shared, so this is NOT VFS-only. */
6661
- list(): Promise<string[]>;
6687
+ /**
6688
+ * Keys in the store that start with `prefix`, or every key without one.
6689
+ * The personal space is shared, so this is NOT VFS-only. An implementation
6690
+ * may ignore `prefix` and return more (the parameter is optional so that
6691
+ * a store written for the old no-argument `list()` still fits), so callers
6692
+ * filter what they get back.
6693
+ */
6694
+ list(prefix?: string): Promise<string[]>;
6662
6695
  }
6663
6696
  /** Raised when the master seed is not held, so the root key cannot be derived. */
6664
6697
  declare class VfsLockedError extends Error {
@@ -6737,11 +6770,20 @@ declare class VfsLimitError extends Error {
6737
6770
  * Every mutation is a read-modify-write of exactly ONE directory record, so a
6738
6771
  * write cannot leave the tree half-updated: either the parent names the new
6739
6772
  * child or it does not. Two tabs writing different directories never conflict;
6740
- * two tabs writing the SAME directory resolve last-writer-wins at the personal
6741
- * space, which carries an HLC per key. Orphaned records (a directory whose
6742
- * parent entry lost the race) are unreachable rather than corrupting — they
6743
- * cost storage until a future sweep, which is the trade this shape makes in
6773
+ * two tabs (or devices) writing the SAME directory are last-writer-wins. A VFS
6774
+ * write sends no HLC and the personal space has no compare-and-swap: it applies
6775
+ * puts of one key in the order they arrive, so whichever arrives last is kept,
6776
+ * and the other tab's edit is lost. Orphaned records (a directory whose parent
6777
+ * entry lost the race) are unreachable rather than corrupting — they cost
6778
+ * storage until a future sweep, which is the trade this shape makes in
6744
6779
  * exchange for single-record writes.
6780
+ *
6781
+ * Within ONE tab, writes of a record are queued and sent one at a time, in the
6782
+ * order they were made, and a read that has to fetch a record waits for its
6783
+ * write in flight (see `writing`). Every edit of a record is made to one
6784
+ * in-memory copy of it, and that copy is what is written (see `mutate`). All
6785
+ * of this is per namespace instance only; nothing orders writes across tabs
6786
+ * or devices - that would take a compare-and-swap at the server.
6745
6787
  */
6746
6788
 
6747
6789
  /**
@@ -6817,8 +6859,25 @@ declare class VfsNamespace {
6817
6859
  * The file tree re-lists constantly while typing, and every miss is a
6818
6860
  * network round trip plus a decrypt. Invalidated precisely on write rather
6819
6861
  * than by TTL — a stale directory listing shows files that are not there.
6862
+ *
6863
+ * What a cached read resolves to is also THE copy of that record: the one
6864
+ * every edit of it is made to, and the one written. See `mutate`.
6820
6865
  */
6821
6866
  private cache;
6867
+ /**
6868
+ * Bumped by `clearCache`, which is for a change of identity.
6869
+ *
6870
+ * A read or write begun before it can finish after it, and what it read
6871
+ * or wrote belongs to whoever was signed in before. So every record
6872
+ * carries the generation it was read under, and none goes into the cache,
6873
+ * or is edited as the cache's copy, under another.
6874
+ */
6875
+ private generation;
6876
+ /**
6877
+ * The record each promise in `cache` resolved to, and each write in
6878
+ * `writing` is sending: what `editable` finds without waiting.
6879
+ */
6880
+ private readonly copyOf;
6822
6881
  /**
6823
6882
  * The write of each directory record still in flight, by id.
6824
6883
  *
@@ -6828,7 +6887,9 @@ declare class VfsNamespace {
6828
6887
  * that is often the one sent first. Then the earlier write, sealed before
6829
6888
  * the later edit was made, undoes it. That is how a file deleted forever
6830
6889
  * from the Trash, while the move that put it there was still being
6831
- * written, came back. So each write waits for the one before it.
6890
+ * written, came back. So each write waits for the one before it, and a
6891
+ * read that has to fetch the record waits for its write too: see
6892
+ * `openDirById`.
6832
6893
  */
6833
6894
  private readonly writing;
6834
6895
  private readonly historyLimit;
@@ -7052,8 +7113,11 @@ declare class VfsNamespace {
7052
7113
  * Delete metadata records no longer reachable from the root.
7053
7114
  *
7054
7115
  * These accumulate because every write touches exactly one record: if two
7055
- * tabs edit the same directory, last-writer-wins at the personal space can
7056
- * leave a child whose parent entry lost the race. Unreachable is harmless —
7116
+ * tabs or devices edit the same directory, the personal space keeps
7117
+ * whichever put arrives last (a VFS write sends no HLC, and the space
7118
+ * applies puts of one key in arrival order), which can leave a child whose
7119
+ * parent entry lost the race. The per-record write queue (`writing`) only
7120
+ * orders writes within one tab. Unreachable is harmless —
7057
7121
  * it is invisible and undecryptable-by-nobody — but it costs storage, so
7058
7122
  * this reclaims it.
7059
7123
  *
@@ -7101,8 +7165,47 @@ declare class VfsNamespace {
7101
7165
  * aside in `hidden` instead: out of every read, but kept for the write.
7102
7166
  */
7103
7167
  private readRecord;
7104
- /** Apply an edit to a directory record and persist it. */
7168
+ /**
7169
+ * Apply an edit to a directory record and persist it.
7170
+ *
7171
+ * `dir` says which record - its id, key and path - and nothing more. The
7172
+ * edit is made to THE copy of that record (see `editable`), which `dir`
7173
+ * may no longer be, and that copy is what is written. Editing whichever
7174
+ * copy the caller held let two copies of one record exist at once: an
7175
+ * overwrite held its directory across storing the old version's
7176
+ * history, a write of the directory failed meanwhile and dropped it from
7177
+ * the cache, and a save that then read a second copy and stored it,
7178
+ * successfully, was undone when the overwrite stored the first.
7179
+ *
7180
+ * So `edit` must take what it writes from the record it is given, not
7181
+ * from anything read off `dir` before an await - and re-check whatever it
7182
+ * relies on from then, throwing if another write changed it. Returning
7183
+ * false writes nothing after all.
7184
+ */
7105
7185
  private mutate;
7186
+ /**
7187
+ * The copy of `dir`'s record that edits are made to, if there is one
7188
+ * without waiting: the one the cache holds, once read.
7189
+ *
7190
+ * Failing that, the one a write in flight is sending. The record was
7191
+ * dropped from the cache - a change was reported, our own write's echo
7192
+ * among them - and a read that came in since is waiting for that write,
7193
+ * to answer with this very copy if it lands (see `openDirById`); if it
7194
+ * fails, the write an edit now queues behind it carries the copy instead.
7195
+ *
7196
+ * Undefined when the record is not cached and nothing is writing it, or
7197
+ * it is still being read: `reopen` waits for that. A record read before
7198
+ * `clearCache` is edited as it is, as it always was. It is not the copy of
7199
+ * anything the cache holds now, and must not be handed the next identity's.
7200
+ */
7201
+ private editable;
7202
+ /**
7203
+ * Read `dir`'s record - the cached read, or a fetch made once any write of
7204
+ * it in flight has settled - and then find the copy edits are made to.
7205
+ */
7206
+ private reopen;
7207
+ /** Make `dir` the cached copy of its record - unless the cache has been cleared since it was read. */
7208
+ private adopt;
7106
7209
  /**
7107
7210
  * Seal a directory record as it stands NOW and put it in the store.
7108
7211
  *
@@ -7111,6 +7214,7 @@ declare class VfsNamespace {
7111
7214
  * then, its own included.
7112
7215
  */
7113
7216
  private writeRecord;
7217
+ /** For `mkdir`: name a new, empty directory `path` in the one at `parentPath`. */
7114
7218
  private createDir;
7115
7219
  /**
7116
7220
  * Every directory record in a subtree, each once, opened - and nothing
@@ -8998,7 +9102,7 @@ declare function getId(row: {
8998
9102
  * expect (and isn't serving a stale cached bundle). Keep this in sync with
8999
9103
  * `package.json` `version`.
9000
9104
  */
9001
- declare const VERSION = "0.15.0-alpha.1";
9105
+ declare const VERSION = "0.15.0-alpha.3";
9002
9106
 
9003
9107
  /**
9004
9108
  * The SDK's process-global logger.