@muhkoo/connect 0.10.5-alpha.0 → 0.10.6-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/browser/index.js +36 -2
- package/dist/browser/index.js.map +1 -1
- package/dist/connect.d.ts +6 -0
- package/dist/server/index.js +36 -2
- package/dist/server/index.js.map +1 -1
- package/package.json +1 -1
package/dist/connect.d.ts
CHANGED
|
@@ -4146,6 +4146,12 @@ declare class Space {
|
|
|
4146
4146
|
data: Uint8Array;
|
|
4147
4147
|
stat: FileStat;
|
|
4148
4148
|
}>;
|
|
4149
|
+
/** Release a file's shards (ref--) when the owner deletes or unshares it. At
|
|
4150
|
+
* zero references a shard enters a retention window, then is GC'd. Idempotent-
|
|
4151
|
+
* ish: safe to call once per manifest the owner drops. */
|
|
4152
|
+
releaseFile(manifest: FileManifest): Promise<void>;
|
|
4153
|
+
/** Commit/release a manifest's shards with the accelerator (metering + refcount). */
|
|
4154
|
+
private commitShards;
|
|
4149
4155
|
private fileStorage;
|
|
4150
4156
|
/** Wire the RAW_FRAME handler that drives fan-out events. */
|
|
4151
4157
|
private wireFanout;
|
package/dist/server/index.js
CHANGED
|
@@ -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.
|
|
2979
|
+
const VERSION = "0.10.6-alpha.0";
|
|
2980
2980
|
|
|
2981
2981
|
/**
|
|
2982
2982
|
* `HttpClient` — the one place the unified {@link Client} talks to the
|
|
@@ -7330,12 +7330,46 @@ class Space {
|
|
|
7330
7330
|
}
|
|
7331
7331
|
// -- room-scoped files (no websocket needed) -------------------------------
|
|
7332
7332
|
async putFile(file, metadata, opts = {}) {
|
|
7333
|
-
|
|
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
|
+
/** Release a file's shards (ref--) when the owner deletes or unshares it. At
|
|
7346
|
+
* zero references a shard enters a retention window, then is GC'd. Idempotent-
|
|
7347
|
+
* ish: safe to call once per manifest the owner drops. */
|
|
7348
|
+
async releaseFile(manifest) {
|
|
7349
|
+
await this.commitShards(manifest, "release");
|
|
7350
|
+
}
|
|
7351
|
+
/** Commit/release a manifest's shards with the accelerator (metering + refcount). */
|
|
7352
|
+
async commitShards(manifest, action) {
|
|
7353
|
+
const hashes = manifest.chunks.flatMap((c) => c.shardHashes);
|
|
7354
|
+
if (hashes.length === 0)
|
|
7355
|
+
return;
|
|
7356
|
+
const body = JSON.stringify({ hashes, bytes: manifest.size });
|
|
7357
|
+
for (let attempt = 0; attempt < 3; attempt++) {
|
|
7358
|
+
try {
|
|
7359
|
+
const res = await this.deps.fetch(`${this.deps.httpBaseUrl}/api/storage/${action}`, {
|
|
7360
|
+
method: "POST", headers: { "Content-Type": "application/json" }, body,
|
|
7361
|
+
});
|
|
7362
|
+
if (res.ok)
|
|
7363
|
+
return;
|
|
7364
|
+
}
|
|
7365
|
+
catch { /* retry */ }
|
|
7366
|
+
await new Promise((r) => setTimeout(r, 400 * (attempt + 1)));
|
|
7367
|
+
}
|
|
7368
|
+
// Best-effort: a missed commit leaves the shards to orphan-GC (still not
|
|
7369
|
+
// durable-unmetered long-term); a missed release just delays GC. Reconciled
|
|
7370
|
+
// by the platform sweep. Don't fail the caller's write on a metering hiccup.
|
|
7371
|
+
console.warn(`[muhkoo] storage ${action} did not confirm for ${hashes.length} shard(s)`);
|
|
7372
|
+
}
|
|
7339
7373
|
fileStorage(backgroundUpload = false) {
|
|
7340
7374
|
// Global, content-addressed shard store — same store `client.storage`
|
|
7341
7375
|
// uses, so a file shared into a channel resolves from anywhere by
|