@yaks/file 0.0.0-stage → 0.2.36

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.
Files changed (54) hide show
  1. package/LICENSE +202 -0
  2. package/README.md +121 -2
  3. package/_dist/blobs.d.ts +16 -0
  4. package/_dist/blobs.d.ts.map +1 -0
  5. package/_dist/io.d.ts +148 -0
  6. package/_dist/io.d.ts.map +1 -0
  7. package/_dist/local.d.ts +18 -0
  8. package/_dist/local.d.ts.map +1 -0
  9. package/_dist/mod.d.ts +27 -0
  10. package/_dist/mod.d.ts.map +1 -0
  11. package/_dist/occupancy.d.ts +207 -0
  12. package/_dist/occupancy.d.ts.map +1 -0
  13. package/_dist/service.d.ts +31 -0
  14. package/_dist/service.d.ts.map +1 -0
  15. package/_dist/views.d.ts +24 -0
  16. package/_dist/views.d.ts.map +1 -0
  17. package/_dist/vocab.d.ts +9 -0
  18. package/_dist/vocab.d.ts.map +1 -0
  19. package/blobs.js +47 -0
  20. package/blobs.js.map +1 -0
  21. package/blobs.ts +52 -0
  22. package/deno.json +1 -0
  23. package/io.js +361 -0
  24. package/io.js.map +1 -0
  25. package/io.ts +528 -0
  26. package/local.js +105 -0
  27. package/local.js.map +1 -0
  28. package/local.ts +91 -0
  29. package/measure.js +88 -0
  30. package/measure.js.map +1 -0
  31. package/measure.ts +109 -0
  32. package/mod.js +86 -0
  33. package/mod.js.map +1 -0
  34. package/mod.ts +84 -0
  35. package/occupancy.js +256 -0
  36. package/occupancy.js.map +1 -0
  37. package/occupancy.ts +341 -0
  38. package/package.json +54 -4
  39. package/page.js +296 -0
  40. package/page.js.map +1 -0
  41. package/page.ts +444 -0
  42. package/service.js +116 -0
  43. package/service.js.map +1 -0
  44. package/service.ts +155 -0
  45. package/upkeep.js +52 -0
  46. package/upkeep.js.map +1 -0
  47. package/upkeep.ts +78 -0
  48. package/views.js +27 -0
  49. package/views.js.map +1 -0
  50. package/views.ts +25 -0
  51. package/vocab.js +19 -0
  52. package/vocab.js.map +1 -0
  53. package/vocab.json +163 -0
  54. package/vocab.ts +20 -0
package/LICENSE ADDED
@@ -0,0 +1,202 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ APPENDIX: How to apply the Apache License to your work.
180
+
181
+ To apply the Apache License to your work, attach the following
182
+ boilerplate notice, with the fields enclosed by brackets "[]"
183
+ replaced with your own identifying information. (Don't include
184
+ the brackets!) The text should be enclosed in the appropriate
185
+ comment syntax for the file format. We also recommend that a
186
+ file or class name and description of purpose be included on the
187
+ same "printed page" as the copyright notice for easier
188
+ identification within third-party archives.
189
+
190
+ Copyright 2026 Jeff Peterson
191
+
192
+ Licensed under the Apache License, Version 2.0 (the "License");
193
+ you may not use this file except in compliance with the License.
194
+ You may obtain a copy of the License at
195
+
196
+ http://www.apache.org/licenses/LICENSE-2.0
197
+
198
+ Unless required by applicable law or agreed to in writing, software
199
+ distributed under the License is distributed on an "AS IS" BASIS,
200
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201
+ See the License for the specific language governing permissions and
202
+ limitations under the License.
package/README.md CHANGED
@@ -1,3 +1,122 @@
1
- # Temporary Holding Version
1
+ # @yaks/file
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Files as entities. A **file** is a path read in a **root**, and anything in the
4
+ graph refers to it by its eid instead of repeating the path. A **place** in a
5
+ file is the lines an entity sits at. A **look** at a volume says how full it is
6
+ and what fills it, one a day.
7
+
8
+ ## Components
9
+
10
+ | component | properties | what it is |
11
+ | ----------- | ----------------------------------------------------------------- | -------------------------------------------------------------------------- |
12
+ | `file` | `path`, `root` | a path in a root; its eid is derived from both (`fileOf`) |
13
+ | `lines` | `file`, `start`, `end` | where in a file the entity sits, lines `start` through `end` (absent: one) |
14
+ | `volume` | `machine`, `mount` | a filesystem as a machine mounts it; its eid is derived from both |
15
+ | `occupancy` | `volume`, `day`, `at`, `size`, `used`, `free`, `counted`, `paths` | a volume's latest look on a UTC day; its eid is derived from both |
16
+
17
+ A root is any entity paths are read in. Two kinds hold files today:
18
+
19
+ - a **repository** (@yaks/git): its files are abstract, a path in its tree at
20
+ any commit, on no disk. The path is as Git spells it.
21
+ - a **volume**: its files are bytes on a disk. The path is from its mount, so
22
+ `/home/me/notes.md` on a machine's root volume is the path `home/me/notes.md`.
23
+
24
+ A file carries its contents as `content{body}` where the graph keeps them (the
25
+ skill mirror keeps a skill's support files this way) and goes without where the
26
+ bytes are elsewhere (a transcript on disk).
27
+
28
+ A place is `lines` on the entity that sits there. An entry read from line 812 of
29
+ a transcript wears `lines{file, start: 812}`. A citation of lines 10 to 20 is a
30
+ `cites` edge (@yaks/git) to an entity wearing `lines{file, start, end}` with
31
+ those numbers, holding the text it quoted as `content{body}`.
32
+
33
+ ## Placing a path
34
+
35
+ ```ts
36
+ import { fileOf, joined, placed, volumeOf } from '@yaks/file'
37
+ import { assertEquals } from '@std/assert'
38
+
39
+ let at = placed(['/', '/mnt/data'], '/mnt/data/photos/cat.jpg')
40
+ assertEquals(at, { mount: '/mnt/data', path: 'photos/cat.jpg' })
41
+ assertEquals(joined(at!.mount, at!.path), '/mnt/data/photos/cat.jpg')
42
+
43
+ let volume = volumeOf('machine-eid', '/mnt/data')
44
+ assertEquals(fileOf(volume, 'photos/cat.jpg'), fileOf(volume, 'photos/cat.jpg'))
45
+ ```
46
+
47
+ A machine's volumes are rows. A path sits on the one with the longest mount that
48
+ contains it, and a machine's root volume (`/`) is written the first time a path
49
+ needs it. A volume's identity is where its machine mounts it, so the same disk
50
+ mounted by another machine is another volume there.
51
+
52
+ ## This computer
53
+
54
+ `@yaks/file/local` holds the effects: `here(g)` is this computer, the machine
55
+ addressed `local://` (written the first time a graph asks), and
56
+ `onDisk(g, absolute)` is the bundle that makes a path on it a file. Both read
57
+ the graph once per graph; a volume written later is seen by processes started
58
+ after it.
59
+
60
+ `@yaks/file/blobs` is @yaks/blob's store over a directory: `fileBlobs(dir)`
61
+ keeps the bytes stored under each address in `<dir>/<sha>`, and
62
+ `artifactsAt(path)` is the one beside a file-backed graph. It lives here, by the
63
+ filesystem, so @yaks/blob itself loads none.
64
+
65
+ ## What fills a disk
66
+
67
+ A host that lists `@yaks/file` among its plugins runs its duty
68
+ (`@yaks/file/service`) for the computer it is on. Every five minutes it reads
69
+ the computer's disks: the filesystems holding its root and the home directory,
70
+ each at its mount, the highest directory still on the same device. It walks each
71
+ one whose day has no look yet, once a day, using file APIs without starting
72
+ commands: a walk lstats every file on the disk. The walk stays on one device,
73
+ counts allocated blocks and hard links once, and never follows symlinks.
74
+ Protected or disappearing paths remain uncounted. Cancellation keeps partial
75
+ walks out of the graph.
76
+
77
+ A disk whose free bytes fall below its floor is reported through the host's
78
+ telemetry, once each time it falls: a full disk fails every write on it. The
79
+ `floor` option sets the bytes; the default is a tenth of the disk. The `mirrors`
80
+ option names caches laid out by the absolute paths of the files they were made
81
+ from, such as Deno's emit cache at `~/.cache/deno/gen/file`. Every hour the duty
82
+ removes each of their directories whose own directory is gone, such as a
83
+ worktree's after it was taken back. Rebuildable SQLite cache budgets are
84
+ maintained in place by
85
+ [@yaks/sqlite/service](../sqlite/README.md#cache-budgets).
86
+
87
+ The walk lists every directory and file holding at least a thousandth of the
88
+ volume. The day's `occupancy` row keeps those paths beside the filesystem's
89
+ size, used and available bytes. A later look that day replaces the earlier, so a
90
+ run of days is the trend.
91
+
92
+ ```ts
93
+ import { lines, walked } from '@yaks/file/occupancy'
94
+ import { equal } from '@yaks/testing'
95
+
96
+ let found: [number, string][] = [
97
+ [300, '/home/me/yak.db'],
98
+ [700, '/home/me'],
99
+ [900, '/home'],
100
+ [1000, '/'],
101
+ ]
102
+ let walk = walked(found, '/', new Set(['/home/me', '/home', '/']))
103
+ equal(walk, {
104
+ counted: 1000,
105
+ paths: { 'home/me/yak.db': 300, 'home/me/': 700, 'home/': 900 },
106
+ })
107
+ // The tree with `home/` open: what it lists, then what is too small to list.
108
+ equal(lines(walk, (path) => path == 'home/').map((l) => [l.path, l.bytes]), [
109
+ ['home/', 900],
110
+ ['home/me/', 700],
111
+ ['home/', 200],
112
+ ['', 100],
113
+ ])
114
+ ```
115
+
116
+ The browsing app draws them (`@yaks/file/views`): the Disks page in the sidebar,
117
+ and the Disks tab a machine or a volume opens on. Each volume shows how full it
118
+ is and how fast that changes, what fills it as a tree whose directories holding
119
+ a tenth of what is used start open, each path's change since a week before, its
120
+ largest files and day by day. The file the graph keeps its pages in says how
121
+ many of them are free, from @yaks/journal's `kept{file, free}`. The page reads
122
+ only the rows; opening it measures nothing.
@@ -0,0 +1,16 @@
1
+ import { type Blobs } from "@yaks/blob/store";
2
+ /**
3
+ * A {@link Blobs} over a directory: `<dir>/<sha>` holds the bytes stored under
4
+ * `sha`. The directory is created on the first write.
5
+ *
6
+ * ```ts
7
+ * import { fileBlobs } from '@yaks/file/blobs'
8
+ * import { env } from '@yaks/process/env'
9
+ *
10
+ * let store = fileBlobs(`${env.get('HOME')}/.blobs`)
11
+ * ```
12
+ *
13
+ * Asynchronous, so a graph writing through it applies asynchronously.
14
+ */ export declare let fileBlobs: (dir: string) => Blobs;
15
+ /** The default binary store: beside a file-backed graph, or in memory. */ export declare let artifactsAt: (path: string) => Blobs;
16
+ //# sourceMappingURL=blobs.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"blobs.d.ts","sources":["../blobs.ts"],"names":[],"mappings":"AAYA,SAAS,KAAK,KAAK,gCAAkD;AAGrE;;;;;;;;;;;;CAYC,GACD,OAAO,YAAI,YAAa,KAAK,MAAM,KAAG,MAiBrC;AAED,wEAAwE,GACxE,OAAO,YAAI,cAAe,MAAM,MAAM,KAAG,MAG2B"}
package/_dist/io.d.ts ADDED
@@ -0,0 +1,148 @@
1
+ /** The host filesystem, shared by packages without exposing its runtime. */ import * as fs from 'node:fs';
2
+ import * as fsp from 'node:fs/promises';
3
+ export { homedir } from 'node:os';
4
+ import type { TextTail } from "./mod.js";
5
+ export { basename, dirname, extname, isAbsolute, join, relative, resolve } from 'node:path';
6
+ export { fileURLToPath, pathToFileURL } from 'node:url';
7
+ export type Path = string | URL;
8
+ export type MkdirOptions = {
9
+ recursive?: boolean;
10
+ mode?: number;
11
+ };
12
+ export type WriteFileOptions = {
13
+ append?: boolean;
14
+ create?: boolean;
15
+ createNew?: boolean;
16
+ mode?: number;
17
+ signal?: AbortSignal;
18
+ };
19
+ export type OpenOptions = {
20
+ read?: boolean;
21
+ write?: boolean;
22
+ append?: boolean;
23
+ truncate?: boolean;
24
+ create?: boolean;
25
+ createNew?: boolean;
26
+ mode?: number;
27
+ };
28
+ export type DirEntry = {
29
+ name: string;
30
+ isFile: boolean;
31
+ isDirectory: boolean;
32
+ isSymlink: boolean;
33
+ };
34
+ export type FileInfo = Pick<fs.Stats, 'dev' | 'ino' | 'mode' | 'nlink' | 'uid' | 'gid' | 'rdev' | 'size' | 'blksize' | 'blocks' | 'atime' | 'mtime' | 'ctime' | 'birthtime'> & {
35
+ isFile: boolean;
36
+ isDirectory: boolean;
37
+ isSymlink: boolean;
38
+ };
39
+ type Failure = {
40
+ new(message?: string): Error;
41
+ [Symbol.hasInstance]: (error: unknown) => boolean;
42
+ };
43
+ export declare let errors: Record<'NotFound' | 'NotADirectory' | 'AlreadyExists' | 'PermissionDenied', Failure>;
44
+ export declare let isNotADirectory: (error: unknown) => boolean;
45
+ export declare let isNotFound: (error: unknown) => boolean;
46
+ export declare let isAlreadyExists: (error: unknown) => boolean;
47
+ export declare let isPermissionDenied: (error: unknown) => boolean;
48
+ /** Observe filesystem inputs read by this process; returns an unsubscribe. */ export declare let watchReads: (read: (path: Path) => void) => () => void;
49
+ export declare let readTextFile: (path: Path) => Promise<string>;
50
+ export declare let readTextFileSync: (path: Path) => string;
51
+ /** A bounded, best-effort tail. Skip special files that could block or stream. */ export declare let tailTextSync: TextTail;
52
+ export declare let readFile: (path: Path) => Promise<Uint8Array>;
53
+ export declare let readFileSync: (path: Path) => Uint8Array;
54
+ export declare let writeTextFile: (path: Path, data: string, o?: WriteFileOptions) => Promise<void>;
55
+ export declare let writeTextFileSync: (path: Path, data: string, o?: WriteFileOptions) => void;
56
+ export declare let writeFile: (path: Path, data: Uint8Array, o?: WriteFileOptions) => Promise<void>;
57
+ export declare let writeFileSync: (path: Path, data: Uint8Array, o?: WriteFileOptions) => void;
58
+ export declare let mkdir: (path: Path, o?: MkdirOptions) => Promise<void>;
59
+ export declare let mkdirSync: (path: Path, o?: MkdirOptions) => void;
60
+ /** What `remove` takes: `recursive` removes a directory with its contents,
61
+ * and `force` lets a path that is already gone count as removed. */ export type RemoveOptions = {
62
+ recursive?: boolean;
63
+ force?: boolean;
64
+ };
65
+ export declare let remove: (path: Path, o?: RemoveOptions) => Promise<void>;
66
+ export declare let removeSync: (path: Path, o?: RemoveOptions) => void;
67
+ export declare let stat: (path: Path) => Promise<FileInfo>;
68
+ export declare let statSync: (path: Path) => FileInfo;
69
+ export declare let lstat: (path: Path) => Promise<FileInfo>;
70
+ export declare let lstatSync: (path: Path) => FileInfo;
71
+ export declare let readDir: (path: Path) => AsyncGenerator<DirEntry>;
72
+ export declare let readDirSync: (path: Path) => Iterable<DirEntry>;
73
+ /** The bytes of the filesystem holding a path: its size, those in use, and
74
+ * those free to a writer without privilege. */ export type Space = {
75
+ size: number;
76
+ used: number;
77
+ free: number;
78
+ };
79
+ export declare let space: (path: Path) => Promise<Space>;
80
+ export declare let realPath: (path: Path) => Promise<string>;
81
+ export declare let realPathSync: (path: Path) => string;
82
+ export declare let readLink: (path: Path) => Promise<string>;
83
+ export declare let readLinkSync: (path: Path) => string;
84
+ export declare let rename: typeof fsp.rename;
85
+ export declare let renameSync: typeof fs.renameSync;
86
+ export declare let copyFile: (from: Path, to: Path) => Promise<void>;
87
+ export declare let copyFileSync: (from: Path, to: Path) => void;
88
+ export declare let chmod: typeof fsp.chmod;
89
+ export declare let chmodSync: typeof fs.chmodSync;
90
+ export declare let utime: typeof fsp.utimes;
91
+ export declare let utimeSync: typeof fs.utimesSync;
92
+ export declare let link: typeof fsp.link;
93
+ export declare let linkSync: typeof fs.linkSync;
94
+ export declare let symlink: (target: Path, path: Path, options?: {
95
+ type?: 'file' | 'dir' | 'junction';
96
+ }) => Promise<void>;
97
+ export declare let symlinkSync: (target: Path, path: Path, options?: {
98
+ type?: 'file' | 'dir' | 'junction';
99
+ }) => void;
100
+ export declare let makeTempDir: (o?: {
101
+ dir?: string;
102
+ prefix?: string;
103
+ suffix?: string;
104
+ }) => Promise<string>;
105
+ export declare let makeTempDirSync: (o?: {
106
+ dir?: string;
107
+ prefix?: string;
108
+ suffix?: string;
109
+ }) => string;
110
+ export declare let makeTempFile: (o?: {
111
+ dir?: string;
112
+ prefix?: string;
113
+ suffix?: string;
114
+ }) => Promise<string>;
115
+ export declare let makeTempFileSync: (o?: {
116
+ dir?: string;
117
+ prefix?: string;
118
+ suffix?: string;
119
+ }) => string;
120
+ export declare let SeekMode: {
121
+ readonly Start: 0;
122
+ readonly Current: 1;
123
+ readonly End: 2;
124
+ };
125
+ /** An open file. Closing releases its descriptor and any lock it holds. */ export type FsFile = {
126
+ readonly fd: number;
127
+ read: (buffer: Uint8Array) => Promise<number | null>;
128
+ readSync: (buffer: Uint8Array) => number | null;
129
+ write: (buffer: Uint8Array) => Promise<number>;
130
+ writeSync: (buffer: Uint8Array) => number;
131
+ seek: (offset: number, mode: number) => Promise<number>;
132
+ seekSync: (offset: number, mode: number) => number;
133
+ stat: () => Promise<FileInfo>;
134
+ statSync: () => FileInfo;
135
+ truncate: (size?: number) => Promise<void>;
136
+ truncateSync: (size?: number) => void;
137
+ sync: () => Promise<void>;
138
+ syncSync: () => void;
139
+ lock: (exclusive?: boolean) => Promise<void>;
140
+ tryLock: (exclusive?: boolean) => Promise<boolean>;
141
+ tryLockSync: (exclusive?: boolean) => boolean;
142
+ unlock: () => Promise<void>;
143
+ close: () => void;
144
+ [Symbol.dispose]: () => void;
145
+ };
146
+ export declare let open: (path: Path, o?: OpenOptions) => Promise<FsFile>;
147
+ export declare let openSync: (path: Path, o?: OpenOptions) => FsFile;
148
+ //# sourceMappingURL=io.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"io.d.ts","sources":["../io.ts"],"names":[],"mappings":"AAAA,0EAA0E,GAC1E,YAAY,QAAQ,UAAS;AAC7B,YAAY,SAAS,mBAAkB;AAEvC,SAAS,OAAO,QAAQ,UAAS;AAGjC,cAAc,QAAQ,mBAAkB;AACxC,SACE,QAAQ,EACR,OAAO,EACP,OAAO,EACP,UAAU,EACV,IAAI,EACJ,QAAQ,EACR,OAAO,QACF,YAAW;AAClB,SAAS,aAAa,EAAE,aAAa,QAAQ,WAAU;AAEvD,YAAY,OAAO,MAAM,GAAG;AAC5B,YAAY;EAAiB,YAAY,OAAO;EAAE,OAAO,MAAM;;AAC/D,YAAY;EACV,SAAS,OAAO;EA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EAAE,MAAM,MAAM,KAAK,QAAQ,MAAM;EACtD,WAAW,QAAQ,MAAM,EAAE,MAAM,MAAM,KAAK,MAAM;EAClD,YAAY,QAAQ;EACpB,gBAAgB;EAChB,WAAW,OAAO,MAAM,KAAK,QAAQ,IAAI;EACzC,eAAe,OAAO,MAAM,KAAK,IAAI;EACrC,YAAY,QAAQ,IAAI;EACxB,gBAAgB,IAAI;EACpB,OAAO,YAAY,OAAO,KAAK,QAAQ,IAAI;EAC3C,UAAU,YAAY,OAAO,KAAK,QAAQ,OAAO;EACjD,cAAc,YAAY,OAAO,KAAK,OAAO;EAC7C,cAAc,QAAQ,IAAI;EAC1B,aAAa,IAAI;GAChB,OAAO,OAAO,SAAS,IAAI;;AAsI9B,OAAO,YAAI,OAAc,MAAM,MAAM,IAAG,gBAAmB,QAAQ,QAKhE;AACH,OAAO,YAAI,WAAY,MAAM,MAAM,IAAG,gBAAmB,OACH"}
@@ -0,0 +1,18 @@
1
+ import type { Bundle, Eid, Graph } from "@yaks/graph";
2
+ /** This computer: the machine addressed `local://`, written the first time
3
+ * a graph is asked for it. */ export declare let here: (g: Graph) => Promise<Eid>;
4
+ /**
5
+ * An absolute path on this computer, as the file it is: the bundle that makes
6
+ * it one, on the volume that holds it. Writing it again writes the same
7
+ * entity.
8
+ *
9
+ * ```ts
10
+ * import { onDisk } from '@yaks/file/local'
11
+ *
12
+ * // let [file] = await onDisk(graph, '/home/me/.claude/projects/x.jsonl')
13
+ * // file.file -> { path: 'home/me/.claude/projects/x.jsonl', root: <volume> }
14
+ * ```
15
+ */ export declare let onDisk: (g: Graph, absolute: string) => Promise<Bundle[]>;
16
+ /** Where a file is on this computer's disks: its absolute path, or nothing
17
+ * for a file in a repository or on another machine. */ export declare let absolute: (g: Graph, file: Bundle) => Promise<string | undefined>;
18
+ //# sourceMappingURL=local.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"local.d.ts","sources":["../local.ts"],"names":[],"mappings":"AAUA,cAAc,MAAM,EAAQ,GAAG,EAAE,KAAK,2BAAgC;AAwCtE;4BAC4B,GAC5B,OAAO,YAAI,OAAO,GAAG,UAAU,QAAQ,KAAsB;AAI7D;;;;;;;;;;;CAWC,GACD,OAAO,YAAI,SAAgB,GAAG,OAAO,UAAU,MAAM,KAAG,QAAQ,UAK/D;AAED;qDACqD,GACrD,OAAO,YAAI,WACT,GAAG,OACH,MAAM,WACL,QAAQ,MAAM,GAAG,SAAS,EAU5B"}
package/_dist/mod.d.ts ADDED
@@ -0,0 +1,27 @@
1
+ import type { Bundle, Eid } from "@yaks/graph";
2
+ /** Read at most `limit` trailing bytes of a regular file as UTF-8. */ export type TextTail = (path: string | URL, limit: number) => {
3
+ text: string;
4
+ truncated: boolean;
5
+ } | undefined;
6
+ /**
7
+ * Bytes as a reader takes them in, to three figures.
8
+ *
9
+ * ```ts
10
+ * import { size } from '@yaks/file'
11
+ * import { equal } from '@yaks/testing'
12
+ *
13
+ * equal([size(147), size(41_300_000), size(14_341_947_392), size(-2_000)], ['147 B', '41.3 MB', '14.3 GB', '−2 kB'])
14
+ * ```
15
+ */ export declare let size: (n?: number) => string;
16
+ /** The entity a path in a root is: the eid `file{path, root}` derives. */ export declare let fileOf: (root: Eid, path: string) => Eid;
17
+ /** The entity a machine's mount is: the eid `volume{machine, mount}`
18
+ * derives. */ export declare let volumeOf: (machine: Eid, mount: string) => Eid;
19
+ /** Where an absolute path sits among a machine's mounts: on the longest
20
+ * mount that contains it, at the path from there. Nothing when no mount
21
+ * contains it. */ export declare let placed: (mounts: string[], absolute: string) => {
22
+ mount: string;
23
+ path: string;
24
+ } | undefined;
25
+ /** The absolute path a file on a volume has on the machine that mounts it. */ export declare let joined: (mount: string, path: string) => string;
26
+ /** The bundle that makes a path on a volume a file. */ export declare let onVolume: (volume: Eid, path: string) => Bundle[];
27
+ //# sourceMappingURL=mod.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mod.d.ts","sources":["../mod.ts"],"names":[],"mappings":"AASA,cAAc,MAAM,EAAE,GAAG,2BAAgC;AAGzD,oEAAoE,GACpE,YAAY,YACV,MAAM,MAAM,GAAG,KACf,OAAO,MAAM;EACR,MAAM,MAAM;EAAE,WAAW,OAAO;IAAK,SAAS;AASrD;;;;;;;;;CASC,GACD,OAAO,YAAI,OAAQ,eAAQ,MAAM,CAKhC;AAID,wEAAwE,GACxE,OAAO,YAAI,SAAU,MAAM,KAAK,MAAM,MAAM,KAAG,IACZ;AAGnC;YACY,GACZ,OAAO,YAAI,WAAY,SAAS,KAAK,OAAO,MAAM,KAAG,IACZ;AAKzC;;gBAEgB,GAChB,OAAO,YAAI,SACT,QAAQ,MAAM,IACd,UAAU,MAAM;EACb,OAAO,MAAM;EAAE,MAAM,MAAM;IAAK,SAAS,CAO7C;AAID,4EAA4E,GAC5E,OAAO,YAAI,SAAU,OAAO,MAAM,EAAE,MAAM,MAAM,KAAG,MAAM,CACjB;AAGxC,qDAAqD,GACrD,OAAO,YAAI,WAAY,QAAQ,KAAK,MAAM,MAAM,KAAG,SAGjD"}