@tangle-network/sdk-session-persistence 0.7.5 → 0.7.6
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/index.d.mts +6 -1
- package/dist/index.mjs +25 -8
- package/package.json +3 -3
package/dist/index.d.mts
CHANGED
|
@@ -6,7 +6,12 @@ import { AgentExecutionInput, ToolState } from "@tangle-network/agent-interface"
|
|
|
6
6
|
declare const DURABLE_FILE_MODE = 384;
|
|
7
7
|
/** The `<file>.tmp-<hex>` sibling a durable write fills before its rename. */
|
|
8
8
|
declare const temporarySibling: (target: string) => string;
|
|
9
|
-
|
|
9
|
+
/**
|
|
10
|
+
* A group commit: resolves after an fsync of `directory` that began after the
|
|
11
|
+
* call. Callers arriving before the queued fsync starts share it, so a burst
|
|
12
|
+
* of writers into one directory pays one fsync per batch, not one each.
|
|
13
|
+
*/
|
|
14
|
+
declare function syncDirectory(path: string): Promise<void>;
|
|
10
15
|
interface DurableWriteOptions {
|
|
11
16
|
/** The file's exact mode; owner-only unless the caller shares it. */
|
|
12
17
|
mode?: number;
|
package/dist/index.mjs
CHANGED
|
@@ -2,19 +2,36 @@ import { randomBytes, randomUUID } from "node:crypto";
|
|
|
2
2
|
import * as fs$1 from "node:fs/promises";
|
|
3
3
|
import fs from "node:fs/promises";
|
|
4
4
|
import * as path from "node:path";
|
|
5
|
-
import { dirname } from "node:path";
|
|
5
|
+
import { dirname, resolve } from "node:path";
|
|
6
6
|
//#region src/durable-write.ts
|
|
7
7
|
/** A durable record is owner-only unless the caller shares it with another uid. */
|
|
8
8
|
const DURABLE_FILE_MODE = 384;
|
|
9
9
|
/** The `<file>.tmp-<hex>` sibling a durable write fills before its rename. */
|
|
10
10
|
const temporarySibling = (target) => `${target}.tmp-${randomBytes(6).toString("hex")}`;
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
11
|
+
/** Per directory: the fsync running, and the one queued behind it. */
|
|
12
|
+
const directorySyncs = /* @__PURE__ */ new Map();
|
|
13
|
+
/**
|
|
14
|
+
* A group commit: resolves after an fsync of `directory` that began after the
|
|
15
|
+
* call. Callers arriving before the queued fsync starts share it, so a burst
|
|
16
|
+
* of writers into one directory pays one fsync per batch, not one each.
|
|
17
|
+
*/
|
|
18
|
+
function syncDirectory(path) {
|
|
19
|
+
const directory = resolve(path);
|
|
20
|
+
const syncs = directorySyncs.get(directory) ?? {};
|
|
21
|
+
directorySyncs.set(directory, syncs);
|
|
22
|
+
if (syncs.queued) return syncs.queued;
|
|
23
|
+
const sync = (syncs.running ?? Promise.resolve()).catch(() => void 0).then(async () => {
|
|
24
|
+
syncs.running = sync;
|
|
25
|
+
syncs.queued = void 0;
|
|
26
|
+
try {
|
|
27
|
+
const handle = await fs.open(directory, "r");
|
|
28
|
+
await handle.sync().finally(() => handle.close());
|
|
29
|
+
} finally {
|
|
30
|
+
if (!syncs.queued) directorySyncs.delete(directory);
|
|
31
|
+
}
|
|
32
|
+
});
|
|
33
|
+
syncs.queued = sync;
|
|
34
|
+
return sync;
|
|
18
35
|
}
|
|
19
36
|
/**
|
|
20
37
|
* Durably replaces `target` with `contents`; its directory must exist. A crash
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tangle-network/sdk-session-persistence",
|
|
3
|
-
"version": "0.7.
|
|
3
|
+
"version": "0.7.6",
|
|
4
4
|
"description": "File-based session and message storage for CLI providers without built-in persistence",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.mjs",
|
|
@@ -29,8 +29,8 @@
|
|
|
29
29
|
"registry": "https://registry.npmjs.org"
|
|
30
30
|
},
|
|
31
31
|
"tangleRelease": {
|
|
32
|
-
"sourceSha": "
|
|
33
|
-
"mergedAt": "2026-11-
|
|
32
|
+
"sourceSha": "8b1aa095a48e3053541625b20d6c514c936c114b",
|
|
33
|
+
"mergedAt": "2026-11-07T17:36:23-08:00"
|
|
34
34
|
},
|
|
35
35
|
"scripts": {
|
|
36
36
|
"build": "tsdown",
|