@muhkoo/connect 0.10.5-alpha.0 → 0.10.7-alpha.0

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
@@ -4146,6 +4146,17 @@ declare class Space {
4146
4146
  data: Uint8Array;
4147
4147
  stat: FileStat;
4148
4148
  }>;
4149
+ /** Declare a file's shards (ref++ + meter) for a manifest already stored —
4150
+ * used to back-fill accounting for files written before commit existed, or to
4151
+ * register a manifest received via sharing. `putFile` already commits new
4152
+ * writes automatically; this is the explicit form. */
4153
+ commitFile(manifest: FileManifest): Promise<void>;
4154
+ /** Release a file's shards (ref--) when the owner deletes or unshares it. At
4155
+ * zero references a shard enters a retention window, then is GC'd. Idempotent-
4156
+ * ish: safe to call once per manifest the owner drops. */
4157
+ releaseFile(manifest: FileManifest): Promise<void>;
4158
+ /** Commit/release a manifest's shards with the accelerator (metering + refcount). */
4159
+ private commitShards;
4149
4160
  private fileStorage;
4150
4161
  /** Wire the RAW_FRAME handler that drives fan-out events. */
4151
4162
  private wireFanout;
@@ -2976,7 +2976,7 @@ function base64UrlDecode(s) {
2976
2976
  * expect (and isn't serving a stale cached bundle). Keep this in sync with
2977
2977
  * `package.json` `version`.
2978
2978
  */
2979
- const VERSION = "0.10.5-alpha.0";
2979
+ const VERSION = "0.10.7-alpha.0";
2980
2980
 
2981
2981
  /**
2982
2982
  * `HttpClient` — the one place the unified {@link Client} talks to the
@@ -7330,12 +7330,53 @@ class Space {
7330
7330
  }
7331
7331
  // -- room-scoped files (no websocket needed) -------------------------------
7332
7332
  async putFile(file, metadata, opts = {}) {
7333
- return this.fileStorage(opts.backgroundUpload)
7333
+ const result = await this.fileStorage(opts.backgroundUpload)
7334
7334
  .writeFileToShards({ data: file, metadata, onProgress: opts.onProgress });
7335
+ // Declare this manifest's shards to the accelerator: attributes the stored
7336
+ // bytes to the owning app (so storage is never unmetered) and reference-
7337
+ // counts the shards for GC. Public shard hashes only — the per-chunk keys
7338
+ // stay inside the manifest, which the caller keeps in a vault/Space.
7339
+ await this.commitShards(result.manifest, "commit");
7340
+ return result;
7335
7341
  }
7336
7342
  async getFile(manifest) {
7337
7343
  return this.fileStorage().readFileFromShards(manifest);
7338
7344
  }
7345
+ /** Declare a file's shards (ref++ + meter) for a manifest already stored —
7346
+ * used to back-fill accounting for files written before commit existed, or to
7347
+ * register a manifest received via sharing. `putFile` already commits new
7348
+ * writes automatically; this is the explicit form. */
7349
+ async commitFile(manifest) {
7350
+ await this.commitShards(manifest, "commit");
7351
+ }
7352
+ /** Release a file's shards (ref--) when the owner deletes or unshares it. At
7353
+ * zero references a shard enters a retention window, then is GC'd. Idempotent-
7354
+ * ish: safe to call once per manifest the owner drops. */
7355
+ async releaseFile(manifest) {
7356
+ await this.commitShards(manifest, "release");
7357
+ }
7358
+ /** Commit/release a manifest's shards with the accelerator (metering + refcount). */
7359
+ async commitShards(manifest, action) {
7360
+ const hashes = manifest.chunks.flatMap((c) => c.shardHashes);
7361
+ if (hashes.length === 0)
7362
+ return;
7363
+ const body = JSON.stringify({ hashes, bytes: manifest.size });
7364
+ for (let attempt = 0; attempt < 3; attempt++) {
7365
+ try {
7366
+ const res = await this.deps.fetch(`${this.deps.httpBaseUrl}/api/storage/${action}`, {
7367
+ method: "POST", headers: { "Content-Type": "application/json" }, body,
7368
+ });
7369
+ if (res.ok)
7370
+ return;
7371
+ }
7372
+ catch { /* retry */ }
7373
+ await new Promise((r) => setTimeout(r, 400 * (attempt + 1)));
7374
+ }
7375
+ // Best-effort: a missed commit leaves the shards to orphan-GC (still not
7376
+ // durable-unmetered long-term); a missed release just delays GC. Reconciled
7377
+ // by the platform sweep. Don't fail the caller's write on a metering hiccup.
7378
+ console.warn(`[muhkoo] storage ${action} did not confirm for ${hashes.length} shard(s)`);
7379
+ }
7339
7380
  fileStorage(backgroundUpload = false) {
7340
7381
  // Global, content-addressed shard store — same store `client.storage`
7341
7382
  // uses, so a file shared into a channel resolves from anywhere by