@mesadev/sdk 0.34.0 → 0.36.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.
@@ -1,70 +0,0 @@
1
- // Automatic lifecycle management for API keys minted by mesa.fs.mount().
2
- //
3
- // Each Mesa filesystem instance gets a scoped API key. These keys persist server-side
4
- // until explicitly revoked, so we need to clean them up when they're no longer
5
- // needed. Three cleanup paths, in order of likelihood:
6
- //
7
- // 1. Process exit (SIGINT/SIGTERM/beforeExit) — revokes all outstanding keys.
8
- // This is the primary path. Handles Ctrl+C, container shutdown, and natural
9
- // event loop drain.
10
- //
11
- // 2. FinalizationRegistry — when a Mesa filesystem instance is garbage collected, its
12
- // key is revoked. This handles long-running processes that create and discard
13
- // many FS instances. GC timing is non-deterministic, so this is best-effort.
14
- //
15
- // 3. If all else fails (e.g. process.kill(pid, 'SIGKILL')), keys leak. The
16
- // server-side TTL or manual cleanup via mesa.apiKeys.revoke() covers this.
17
- //
18
- // The registry stores only the key id (a string primitive) as the weak callback
19
- // value — not the KeyHandle itself. This avoids preventing GC of the Mesa filesystem
20
- // instance via a reference chain through the revoke closure.
21
- // Maps key id → handle. Used by both the FinalizationRegistry callback and
22
- // the process shutdown path to find keys that still need revocation.
23
- const activeKeys = new Map();
24
- // The registry weak-references Mesa filesystem instances. When one is GC'd, the
25
- // callback receives its key id, looks up the handle, and fires revocation.
26
- // If the key was already revoked (e.g. by process shutdown), the lookup
27
- // returns nothing and it's a no-op.
28
- const registry = new FinalizationRegistry((id) => {
29
- const handle = activeKeys.get(id);
30
- if (!handle)
31
- return;
32
- activeKeys.delete(id);
33
- handle.revoke({ id }).catch(() => { });
34
- });
35
- export function trackMintedKey(fsInstance, id, revoke) {
36
- const handle = { id, revoke };
37
- activeKeys.set(id, handle);
38
- registry.register(fsInstance, id);
39
- }
40
- export async function revokeAllActiveKeys() {
41
- const handles = [...activeKeys.values()];
42
- activeKeys.clear();
43
- await Promise.allSettled(handles.map((h) => h.revoke({ id: h.id })));
44
- }
45
- function installProcessHandlers() {
46
- if (typeof process === 'undefined' || typeof process.on !== 'function')
47
- return;
48
- // Guard against double-revocation if multiple signals fire (e.g. SIGINT
49
- // followed by beforeExit during the same shutdown sequence).
50
- let shuttingDown = false;
51
- async function shutdown() {
52
- if (shuttingDown)
53
- return;
54
- shuttingDown = true;
55
- await revokeAllActiveKeys();
56
- }
57
- // beforeExit fires when the event loop drains naturally. Node re-emits it
58
- // after async work completes, so awaiting the revocations is safe here.
59
- process.on('beforeExit', shutdown);
60
- // SIGINT (Ctrl+C) and SIGTERM (kill, container stop) don't fire beforeExit,
61
- // so we handle them explicitly. After revocation, we re-exit so the process
62
- // doesn't hang.
63
- for (const signal of ['SIGINT', 'SIGTERM']) {
64
- process.on(signal, () => {
65
- shutdown().finally(() => process.exit());
66
- });
67
- }
68
- }
69
- installProcessHandlers();
70
- //# sourceMappingURL=key-cleanup.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"key-cleanup.js","sourceRoot":"","sources":["../../src/fs/key-cleanup.ts"],"names":[],"mappings":"AAAA,yEAAyE;AACzE,EAAE;AACF,sFAAsF;AACtF,+EAA+E;AAC/E,uDAAuD;AACvD,EAAE;AACF,8EAA8E;AAC9E,+EAA+E;AAC/E,uBAAuB;AACvB,EAAE;AACF,sFAAsF;AACtF,iFAAiF;AACjF,gFAAgF;AAChF,EAAE;AACF,2EAA2E;AAC3E,8EAA8E;AAC9E,EAAE;AACF,gFAAgF;AAChF,qFAAqF;AACrF,6DAA6D;AAS7D,2EAA2E;AAC3E,qEAAqE;AACrE,MAAM,UAAU,GAAG,IAAI,GAAG,EAAqB,CAAC;AAEhD,gFAAgF;AAChF,2EAA2E;AAC3E,wEAAwE;AACxE,oCAAoC;AACpC,MAAM,QAAQ,GAAG,IAAI,oBAAoB,CAAS,CAAC,EAAE,EAAE,EAAE;IACvD,MAAM,MAAM,GAAG,UAAU,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;IAClC,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