@excitedjs/dreamux-utils 0.2.0-beta.84 → 0.2.0-beta.86

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/fs.d.ts ADDED
@@ -0,0 +1,15 @@
1
+ /**
2
+ * Filesystem write helpers shared across Dreamux providers and host.
3
+ *
4
+ * Domain note: these are primitives (atomic write, future: tmpdir,
5
+ * safe unlink). Dreamux host-owned path/layout contracts live in
6
+ * `@excitedjs/dreamux` — do not add them here.
7
+ */
8
+ /**
9
+ * Atomic write: tmpfile in same dir → write with O_CREAT|O_EXCL (fail loud on
10
+ * collision instead of clobbering) → rename over final path.
11
+ * Permissions applied at open (never chmod final path).
12
+ * Parent dir must exist.
13
+ */
14
+ export declare function writeAtomic(dir: string, filename: string, data: string, mode?: number): Promise<void>;
15
+ //# sourceMappingURL=fs.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fs.d.ts","sourceRoot":"","sources":["../src/fs.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAMH;;;;;GAKG;AACH,wBAAsB,WAAW,CAC/B,GAAG,EAAE,MAAM,EACX,QAAQ,EAAE,MAAM,EAChB,IAAI,EAAE,MAAM,EACZ,IAAI,GAAE,MAAc,GACnB,OAAO,CAAC,IAAI,CAAC,CA2Bf"}
package/dist/fs.js ADDED
@@ -0,0 +1,50 @@
1
+ /**
2
+ * Filesystem write helpers shared across Dreamux providers and host.
3
+ *
4
+ * Domain note: these are primitives (atomic write, future: tmpdir,
5
+ * safe unlink). Dreamux host-owned path/layout contracts live in
6
+ * `@excitedjs/dreamux` — do not add them here.
7
+ */
8
+ import { randomBytes } from 'node:crypto';
9
+ import { open, rename, rm } from 'node:fs/promises';
10
+ import { join } from 'node:path';
11
+ /**
12
+ * Atomic write: tmpfile in same dir → write with O_CREAT|O_EXCL (fail loud on
13
+ * collision instead of clobbering) → rename over final path.
14
+ * Permissions applied at open (never chmod final path).
15
+ * Parent dir must exist.
16
+ */
17
+ export async function writeAtomic(dir, filename, data, mode = 0o600) {
18
+ const suffix = process.pid.toString(16) +
19
+ '-' +
20
+ Date.now().toString(36) +
21
+ '-' +
22
+ randomBytes(4).toString('hex');
23
+ const tmp = join(dir, `${filename}.tmp-${suffix}`);
24
+ const final = join(dir, filename);
25
+ // O_CREAT | O_EXCL | O_WRONLY = 'wx' — a name collision throws instead of
26
+ // silently overwriting (infinitesimally unlikely given pid+time+random, but
27
+ // the invariant calls for it).
28
+ let fd = null;
29
+ try {
30
+ fd = await open(tmp, 'wx', mode);
31
+ await fd.writeFile(data);
32
+ await fd.close();
33
+ fd = null;
34
+ await rename(tmp, final);
35
+ }
36
+ catch (err) {
37
+ if (fd) {
38
+ try {
39
+ await fd.close();
40
+ }
41
+ catch { /* swallow */ }
42
+ }
43
+ try {
44
+ await rm(tmp, { force: true });
45
+ }
46
+ catch { /* swallow */ }
47
+ throw err;
48
+ }
49
+ }
50
+ //# sourceMappingURL=fs.js.map
package/dist/fs.js.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fs.js","sourceRoot":"","sources":["../src/fs.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC1C,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,kBAAkB,CAAC;AACpD,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAEjC;;;;;GAKG;AACH,MAAM,CAAC,KAAK,UAAU,WAAW,CAC/B,GAAW,EACX,QAAgB,EAChB,IAAY,EACZ,OAAe,KAAK;IAEpB,MAAM,MAAM,GACV,OAAO,CAAC,GAAG,CAAC,QAAQ,CAAC,EAAE,CAAC;QACxB,GAAG;QACH,IAAI,CAAC,GAAG,EAAE,CAAC,QAAQ,CAAC,EAAE,CAAC;QACvB,GAAG;QACH,WAAW,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;IACjC,MAAM,GAAG,GAAG,IAAI,CAAC,GAAG,EAAE,GAAG,QAAQ,QAAQ,MAAM,EAAE,CAAC,CAAC;IACnD,MAAM,KAAK,GAAG,IAAI,CAAC,GAAG,EAAE,QAAQ,CAAC,CAAC;IAElC,0EAA0E;IAC1E,4EAA4E;IAC5E,+BAA+B;IAC/B,IAAI,EAAE,GAAiD,IAAI,CAAC;IAC5D,IAAI,CAAC;QACH,EAAE,GAAG,MAAM,IAAI,CAAC,GAAG,EAAE,IAAI,EAAE,IAAI,CAAC,CAAC;QACjC,MAAM,EAAE,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC;QACzB,MAAM,EAAE,CAAC,KAAK,EAAE,CAAC;QACjB,EAAE,GAAG,IAAI,CAAC;QACV,MAAM,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC;IAC3B,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACb,IAAI,EAAE,EAAE,CAAC;YACP,IAAI,CAAC;gBAAC,MAAM,EAAE,CAAC,KAAK,EAAE,CAAC;YAAC,CAAC;YAAC,MAAM,CAAC,CAAC,aAAa,CAAC,CAAC;QACnD,CAAC;QACD,IAAI,CAAC;YAAC,MAAM,EAAE,CAAC,GAAG,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;QAAC,CAAC;QAAC,MAAM,CAAC,CAAC,aAAa,CAAC,CAAC;QAC/D,MAAM,GAAG,CAAC;IACZ,CAAC;AACH,CAAC"}
package/dist/index.d.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  export * from './config-validate.js';
2
2
  export * from './os.js';
3
+ export * from './fs.js';
3
4
  export * from './completion-body.js';
4
5
  export * from './socket-budget.js';
5
6
  export * from './turn-render.js';
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,sBAAsB,CAAC;AACrC,cAAc,SAAS,CAAC;AACxB,cAAc,sBAAsB,CAAC;AACrC,cAAc,oBAAoB,CAAC;AACnC,cAAc,kBAAkB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,sBAAsB,CAAC;AACrC,cAAc,SAAS,CAAC;AACxB,cAAc,SAAS,CAAC;AACxB,cAAc,sBAAsB,CAAC;AACrC,cAAc,oBAAoB,CAAC;AACnC,cAAc,kBAAkB,CAAC"}
package/dist/index.js CHANGED
@@ -1,5 +1,6 @@
1
1
  export * from './config-validate.js';
2
2
  export * from './os.js';
3
+ export * from './fs.js';
3
4
  export * from './completion-body.js';
4
5
  export * from './socket-budget.js';
5
6
  export * from './turn-render.js';
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,sBAAsB,CAAC;AACrC,cAAc,SAAS,CAAC;AACxB,cAAc,sBAAsB,CAAC;AACrC,cAAc,oBAAoB,CAAC;AACnC,cAAc,kBAAkB,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,sBAAsB,CAAC;AACrC,cAAc,SAAS,CAAC;AACxB,cAAc,SAAS,CAAC;AACxB,cAAc,sBAAsB,CAAC;AACrC,cAAc,oBAAoB,CAAC;AACnC,cAAc,kBAAkB,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@excitedjs/dreamux-utils",
3
- "version": "0.2.0-beta.84",
3
+ "version": "0.2.0-beta.86",
4
4
  "description": "Pure shared utilities for Dreamux providers and host: neutral config-validation primitives, OS/filesystem helpers, completion-body resolution, and inbound-turn render helpers. Depends on @excitedjs/dreamux-types only, never on @excitedjs/dreamux core (issue excitedjs/dreamux#209).",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -27,7 +27,7 @@
27
27
  "LICENSE"
28
28
  ],
29
29
  "dependencies": {
30
- "@excitedjs/dreamux-types": "0.2.0-beta.84"
30
+ "@excitedjs/dreamux-types": "0.2.0-beta.86"
31
31
  },
32
32
  "devDependencies": {
33
33
  "@types/node": "^22.10.0",