@fenglimg/fabric-shared 2.0.0 → 2.0.1

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.
@@ -8,6 +8,22 @@ declare function atomicWriteText(path: string, content: string, opts?: AtomicWri
8
8
  declare function atomicWriteJson(path: string, value: unknown, opts?: AtomicWriteJsonOptions): Promise<void>;
9
9
  interface LedgerWriteQueue {
10
10
  append(path: string, line: string): Promise<void>;
11
+ /**
12
+ * Run `fn` with exclusive access to `path` against all other queue operations
13
+ * (other `runExclusive` calls and `append` calls) on the same path within
14
+ * this LedgerWriteQueue instance.
15
+ *
16
+ * Scope: per-path, in-process (same Node process, same queue instance).
17
+ * Does NOT provide cross-process locking — separate concern.
18
+ *
19
+ * Error semantics: a rejection from `fn` is propagated to the returned
20
+ * Promise but does NOT poison the chain — subsequent `runExclusive` /
21
+ * `append` calls on the same path will still acquire and run.
22
+ *
23
+ * Ordering: submission-order FIFO. Calls on different paths run independently
24
+ * (in parallel where possible).
25
+ */
26
+ runExclusive<T>(path: string, fn: () => Promise<T>): Promise<T>;
11
27
  }
12
28
  declare function createLedgerWriteQueue(): LedgerWriteQueue;
13
29
 
@@ -38,18 +38,27 @@ function createLedgerWriteQueue() {
38
38
  const normalized = line.endsWith("\n") ? line : line + "\n";
39
39
  await appendFile(path, normalized, "utf8");
40
40
  }
41
+ function enqueue(path, work) {
42
+ const prev = chains.get(path) ?? Promise.resolve();
43
+ const result = prev.catch(() => void 0).then(() => work());
44
+ const chainSlot = result.then(
45
+ () => void 0,
46
+ () => void 0
47
+ );
48
+ chains.set(path, chainSlot);
49
+ chainSlot.finally(() => {
50
+ if (chains.get(path) === chainSlot) {
51
+ chains.delete(path);
52
+ }
53
+ });
54
+ return result;
55
+ }
41
56
  return {
42
57
  append(path, line) {
43
- const prev = chains.get(path) ?? Promise.resolve();
44
- const next = prev.catch(() => void 0).then(() => doAppend(path, line));
45
- chains.set(path, next);
46
- const guarded = next.catch(() => void 0);
47
- guarded.finally(() => {
48
- if (chains.get(path) === next) {
49
- chains.delete(path);
50
- }
51
- });
52
- return next;
58
+ return enqueue(path, () => doAppend(path, line));
59
+ },
60
+ runExclusive(path, fn) {
61
+ return enqueue(path, fn);
53
62
  }
54
63
  };
55
64
  }
@@ -11,6 +11,8 @@ interface PayloadGuardResult {
11
11
  threshold: number;
12
12
  };
13
13
  }
14
+ declare const PAYLOAD_LIMIT_DEFAULT_WARN_BYTES = 16384;
15
+ declare const PAYLOAD_LIMIT_DEFAULT_HARD_BYTES = 65536;
14
16
  declare function enforcePayloadLimit(serializedPayload: string, opts?: PayloadGuardOptions): PayloadGuardResult;
15
17
 
16
- export { type PayloadGuardOptions, type PayloadGuardResult, enforcePayloadLimit };
18
+ export { PAYLOAD_LIMIT_DEFAULT_HARD_BYTES, PAYLOAD_LIMIT_DEFAULT_WARN_BYTES, type PayloadGuardOptions, type PayloadGuardResult, enforcePayloadLimit };
@@ -7,8 +7,10 @@ var McpPayloadTooLargeError = class extends MCPError {
7
7
  code = "MCP_PAYLOAD_TOO_LARGE";
8
8
  httpStatus = 413;
9
9
  };
10
- var DEFAULT_WARN = 16384;
11
- var DEFAULT_HARD = 65536;
10
+ var PAYLOAD_LIMIT_DEFAULT_WARN_BYTES = 16384;
11
+ var PAYLOAD_LIMIT_DEFAULT_HARD_BYTES = 65536;
12
+ var DEFAULT_WARN = PAYLOAD_LIMIT_DEFAULT_WARN_BYTES;
13
+ var DEFAULT_HARD = PAYLOAD_LIMIT_DEFAULT_HARD_BYTES;
12
14
  function enforcePayloadLimit(serializedPayload, opts) {
13
15
  const warnAt = opts?.warnBytes ?? DEFAULT_WARN;
14
16
  const hardAt = opts?.hardBytes ?? DEFAULT_HARD;
@@ -36,5 +38,7 @@ function enforcePayloadLimit(serializedPayload, opts) {
36
38
  return { bytes };
37
39
  }
38
40
  export {
41
+ PAYLOAD_LIMIT_DEFAULT_HARD_BYTES,
42
+ PAYLOAD_LIMIT_DEFAULT_WARN_BYTES,
39
43
  enforcePayloadLimit
40
44
  };