@fnndsc/fond 0.6.1 → 0.7.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.
- package/README.md +1 -3
- package/dist/errorStack.d.ts +10 -6
- package/dist/errorStack.js +12 -9
- package/dist/errorStack.js.map +1 -1
- package/dist/heldWriter.d.ts +130 -0
- package/dist/heldWriter.js +539 -0
- package/dist/heldWriter.js.map +1 -0
- package/dist/homePath.d.ts +60 -0
- package/dist/homePath.js +117 -0
- package/dist/homePath.js.map +1 -0
- package/dist/hostPlace.d.ts +275 -0
- package/dist/hostPlace.js +777 -0
- package/dist/hostPlace.js.map +1 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.js +24 -0
- package/dist/index.js.map +1 -1
- package/dist/placedPath.d.ts +250 -0
- package/dist/placedPath.js +757 -0
- package/dist/placedPath.js.map +1 -0
- package/dist/publication.d.ts +43 -0
- package/dist/publication.js +55 -0
- package/dist/publication.js.map +1 -0
- package/dist/recordFile.d.ts +61 -0
- package/dist/recordFile.js +258 -0
- package/dist/recordFile.js.map +1 -0
- package/dist/vfs/contract.js +19 -5
- package/dist/vfs/contract.js.map +1 -1
- package/dist/vfs/dispatcher.d.ts +222 -13
- package/dist/vfs/dispatcher.js +483 -73
- package/dist/vfs/dispatcher.js.map +1 -1
- package/dist/vfs/memory.d.ts +107 -3
- package/dist/vfs/memory.js +198 -24
- package/dist/vfs/memory.js.map +1 -1
- package/dist/vfs/naming.d.ts +97 -0
- package/dist/vfs/naming.js +122 -0
- package/dist/vfs/naming.js.map +1 -0
- package/dist/vfs/outcome.d.ts +72 -2
- package/dist/vfs/outcome.js +84 -3
- package/dist/vfs/outcome.js.map +1 -1
- package/dist/vfs/provider.d.ts +191 -6
- package/dist/vfs/render.d.ts +7 -0
- package/dist/vfs/render.js +16 -13
- package/dist/vfs/render.js.map +1 -1
- package/package.json +1 -1
package/dist/homePath.js
ADDED
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* @file The home folder's two readings every package shares: a typed `~`,
|
|
4
|
+
* and the XDG base folders.
|
|
5
|
+
*
|
|
6
|
+
* Key components:
|
|
7
|
+
* - home_expand: `~` and `~/…` made the home folder; anything else as given.
|
|
8
|
+
* - xdgDir_resolve: `$XDG_<KIND>_HOME` when it names an absolute folder,
|
|
9
|
+
* else the home's default for that kind.
|
|
10
|
+
*
|
|
11
|
+
* Typical usage:
|
|
12
|
+
* ```ts
|
|
13
|
+
* const jobs: string = path.join(xdgDir_resolve('state', env), 'brasa', 'jobs');
|
|
14
|
+
* ```
|
|
15
|
+
*
|
|
16
|
+
* Dependencies: node:os, node:path.
|
|
17
|
+
*
|
|
18
|
+
* @module
|
|
19
|
+
*/
|
|
20
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
21
|
+
if (k2 === undefined) k2 = k;
|
|
22
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
23
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
24
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
25
|
+
}
|
|
26
|
+
Object.defineProperty(o, k2, desc);
|
|
27
|
+
}) : (function(o, m, k, k2) {
|
|
28
|
+
if (k2 === undefined) k2 = k;
|
|
29
|
+
o[k2] = m[k];
|
|
30
|
+
}));
|
|
31
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
32
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
33
|
+
}) : function(o, v) {
|
|
34
|
+
o["default"] = v;
|
|
35
|
+
});
|
|
36
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
37
|
+
var ownKeys = function(o) {
|
|
38
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
39
|
+
var ar = [];
|
|
40
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
41
|
+
return ar;
|
|
42
|
+
};
|
|
43
|
+
return ownKeys(o);
|
|
44
|
+
};
|
|
45
|
+
return function (mod) {
|
|
46
|
+
if (mod && mod.__esModule) return mod;
|
|
47
|
+
var result = {};
|
|
48
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
49
|
+
__setModuleDefault(result, mod);
|
|
50
|
+
return result;
|
|
51
|
+
};
|
|
52
|
+
})();
|
|
53
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
54
|
+
exports.home_expand = home_expand;
|
|
55
|
+
exports.xdgDir_resolve = xdgDir_resolve;
|
|
56
|
+
const node_os_1 = require("node:os");
|
|
57
|
+
const path = __importStar(require("node:path"));
|
|
58
|
+
/**
|
|
59
|
+
* A path with a leading `~` made the home folder, as a shell would: `~` alone
|
|
60
|
+
* and `~/` followed by a path. Anything else is returned as given: a
|
|
61
|
+
* relative path stays relative (the caller decides what it is relative to),
|
|
62
|
+
* and `~name` is another account's home, which this does not look up.
|
|
63
|
+
*
|
|
64
|
+
* @param typed - The path as typed.
|
|
65
|
+
* @param home - Reads the home folder, asked only for a path that starts with `~` (a test's seam).
|
|
66
|
+
* @returns The path, its `~` expanded.
|
|
67
|
+
*
|
|
68
|
+
* @example
|
|
69
|
+
* ```ts
|
|
70
|
+
* home_expand('~/.ssh/id_ed25519.pub'); // '/home/chris/.ssh/id_ed25519.pub'
|
|
71
|
+
* home_expand('keys/id.pub'); // 'keys/id.pub'
|
|
72
|
+
* ```
|
|
73
|
+
*/
|
|
74
|
+
function home_expand(typed, home = node_os_1.homedir) {
|
|
75
|
+
if (typed === '~')
|
|
76
|
+
return home();
|
|
77
|
+
return typed.startsWith('~/') ? path.join(home(), typed.slice(2)) : typed;
|
|
78
|
+
}
|
|
79
|
+
/** Each kind's variable and its default under the home folder (the XDG Base Directory specification). */
|
|
80
|
+
const XDG_KINDS = {
|
|
81
|
+
config: { variable: 'XDG_CONFIG_HOME', under: '.config' },
|
|
82
|
+
state: { variable: 'XDG_STATE_HOME', under: '.local/state' },
|
|
83
|
+
cache: { variable: 'XDG_CACHE_HOME', under: '.cache' },
|
|
84
|
+
data: { variable: 'XDG_DATA_HOME', under: '.local/share' },
|
|
85
|
+
};
|
|
86
|
+
/**
|
|
87
|
+
* An XDG base folder, as the specification reads it: the variable when it
|
|
88
|
+
* names an absolute path, else the kind's default under the home folder. An
|
|
89
|
+
* empty variable is unset, and a relative one is passed over (the
|
|
90
|
+
* specification calls it invalid), so neither puts a program's files in
|
|
91
|
+
* whatever folder it was started in.
|
|
92
|
+
*
|
|
93
|
+
* The result is spelled, not normalised: a `..` in the variable or the home
|
|
94
|
+
* reaches the caller's folder check rather than being folded away first,
|
|
95
|
+
* and a trailing `/` is trimmed from the home.
|
|
96
|
+
*
|
|
97
|
+
* @param kind - Which base folder.
|
|
98
|
+
* @param env - The environment holding the variable; `process.env` in production.
|
|
99
|
+
* @param home - Reads the home folder, asked only when the variable does not answer (a test's seam).
|
|
100
|
+
* @returns The base folder, absolute when the home is.
|
|
101
|
+
*
|
|
102
|
+
* @example
|
|
103
|
+
* ```ts
|
|
104
|
+
* xdgDir_resolve('cache', { XDG_CACHE_HOME: '' }, () => '/home/chris'); // '/home/chris/.cache'
|
|
105
|
+
* xdgDir_resolve('state', { XDG_STATE_HOME: '/s' }); // '/s'
|
|
106
|
+
* ```
|
|
107
|
+
*/
|
|
108
|
+
function xdgDir_resolve(kind, env = process.env, home = node_os_1.homedir) {
|
|
109
|
+
const { variable, under } = XDG_KINDS[kind];
|
|
110
|
+
const given = env[variable];
|
|
111
|
+
if (given !== undefined && given !== '' && path.isAbsolute(given))
|
|
112
|
+
return given;
|
|
113
|
+
const spelled = home();
|
|
114
|
+
// An empty home stays relative, as a join gave; a home of only slashes is the root.
|
|
115
|
+
return spelled === '' ? under : `${spelled.replace(/\/+$/, '')}/${under}`;
|
|
116
|
+
}
|
|
117
|
+
//# sourceMappingURL=homePath.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"homePath.js","sourceRoot":"","sources":["../src/homePath.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;GAiBG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAqBH,kCAGC;AA2CD,wCAOC;AAxED,qCAAkC;AAClC,gDAAkC;AAElC;;;;;;;;;;;;;;;GAeG;AACH,SAAgB,WAAW,CAAC,KAAa,EAAE,OAAqB,iBAAO;IACrE,IAAI,KAAK,KAAK,GAAG;QAAE,OAAO,IAAI,EAAE,CAAC;IACjC,OAAO,KAAK,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,EAAE,EAAE,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC;AAC5E,CAAC;AAaD,yGAAyG;AACzG,MAAM,SAAS,GAAwC;IACrD,MAAM,EAAE,EAAE,QAAQ,EAAE,iBAAiB,EAAE,KAAK,EAAE,SAAS,EAAE;IACzD,KAAK,EAAE,EAAE,QAAQ,EAAE,gBAAgB,EAAE,KAAK,EAAE,cAAc,EAAE;IAC5D,KAAK,EAAE,EAAE,QAAQ,EAAE,gBAAgB,EAAE,KAAK,EAAE,QAAQ,EAAE;IACtD,IAAI,EAAE,EAAE,QAAQ,EAAE,eAAe,EAAE,KAAK,EAAE,cAAc,EAAE;CAC3D,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,SAAgB,cAAc,CAAC,IAAa,EAAE,MAAoD,OAAO,CAAC,GAAG,EAAE,OAAqB,iBAAO;IACzI,MAAM,EAAE,QAAQ,EAAE,KAAK,EAAE,GAAG,SAAS,CAAC,IAAI,CAAC,CAAC;IAC5C,MAAM,KAAK,GAAuB,GAAG,CAAC,QAAQ,CAAC,CAAC;IAChD,IAAI,KAAK,KAAK,SAAS,IAAI,KAAK,KAAK,EAAE,IAAI,IAAI,CAAC,UAAU,CAAC,KAAK,CAAC;QAAE,OAAO,KAAK,CAAC;IAChF,MAAM,OAAO,GAAW,IAAI,EAAE,CAAC;IAC/B,oFAAoF;IACpF,OAAO,OAAO,KAAK,EAAE,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC,IAAI,KAAK,EAAE,CAAC;AAC5E,CAAC"}
|
|
@@ -0,0 +1,275 @@
|
|
|
1
|
+
/** Where a name belongs under a folder, or why it has no place there. */
|
|
2
|
+
export type HostPlace = {
|
|
3
|
+
readonly ok: true;
|
|
4
|
+
readonly place: string;
|
|
5
|
+
}
|
|
6
|
+
/**
|
|
7
|
+
* `unseen` is set when the name was not refused for what it says but because a part of its way could not be
|
|
8
|
+
* looked at: a failure of this host, not of the name. It is the file system's own code for why (`EACCES`
|
|
9
|
+
* for a folder that may not be entered, `ENOTDIR` for a file standing where a folder was wanted).
|
|
10
|
+
*/
|
|
11
|
+
| {
|
|
12
|
+
readonly ok: false;
|
|
13
|
+
readonly reason: string;
|
|
14
|
+
readonly unseen?: string;
|
|
15
|
+
};
|
|
16
|
+
/**
|
|
17
|
+
* Places a name from another system inside a folder on this host.
|
|
18
|
+
*
|
|
19
|
+
* The name may have folders of its own (`anat/t1.nii`), under either
|
|
20
|
+
* separator. It is refused when it is empty, holds a NUL, is absolute by
|
|
21
|
+
* either system's rules, has an empty, `.` or `..` part, or when the place
|
|
22
|
+
* it comes to, with every link already on this disk followed, is not
|
|
23
|
+
* inside the folder, or when a part of it could not be looked at.
|
|
24
|
+
*
|
|
25
|
+
* @param folder - The folder the name belongs in.
|
|
26
|
+
* @param name - The name as it arrived.
|
|
27
|
+
* @returns The absolute place inside the folder, or the reason it has none.
|
|
28
|
+
*
|
|
29
|
+
* @example
|
|
30
|
+
* ```ts
|
|
31
|
+
* wireName_place('/data/in', 'anat/t1.nii'); // { ok: true, place: '/data/in/anat/t1.nii' }
|
|
32
|
+
* wireName_place('/data/in', '../x'); // { ok: false, reason: "'../x' has a '..' part" }
|
|
33
|
+
* ```
|
|
34
|
+
*/
|
|
35
|
+
export declare function wireName_place(folder: string, name: string): HostPlace;
|
|
36
|
+
/**
|
|
37
|
+
* Whether one part of a name that arrived is an ordinary file or folder name on this platform: not empty, not `.`
|
|
38
|
+
* or `..`, no NUL; on Windows also no reserved device name, no `:` (a drive or an alternate data stream), none of
|
|
39
|
+
* `<>"|?*`, no trailing dot or space. An ordinary colon in a POSIX name is allowed.
|
|
40
|
+
*
|
|
41
|
+
* @param part - One part.
|
|
42
|
+
* @param platform - The platform the file is written on.
|
|
43
|
+
* @returns Null when it is ordinary, else why not.
|
|
44
|
+
*
|
|
45
|
+
* @example
|
|
46
|
+
* ```ts
|
|
47
|
+
* namePart_judge('T:map.nii', 'linux'); // null
|
|
48
|
+
* namePart_judge('CON', 'win32'); // 'has "CON", a name Windows keeps for a device'
|
|
49
|
+
* ```
|
|
50
|
+
*/
|
|
51
|
+
export declare function namePart_judge(part: string, platform: NodeJS.Platform): string | null;
|
|
52
|
+
/** A file suffix a caller may ask for (`.mise`, `.json`): a dot and a few plain characters. */
|
|
53
|
+
export declare const SAFE_SUFFIX: RegExp;
|
|
54
|
+
/**
|
|
55
|
+
* A temporary file only this account can open: in a fresh folder of its own (`mkdtemp`, 0700), created anew
|
|
56
|
+
* (`wx`, so nothing standing at the name is followed or reused), 0600.
|
|
57
|
+
*
|
|
58
|
+
* @example
|
|
59
|
+
* ```ts
|
|
60
|
+
* const temp: PrivateTemp = privateTemp_write('chell-edit-', 'edit.txt', 'text');
|
|
61
|
+
* try { use(temp.path); } finally { temp.folder_remove(); }
|
|
62
|
+
* ```
|
|
63
|
+
*/
|
|
64
|
+
export interface PrivateTemp {
|
|
65
|
+
/** The private folder. */
|
|
66
|
+
folder: string;
|
|
67
|
+
/** The file in it. */
|
|
68
|
+
path: string;
|
|
69
|
+
/** Removes the folder and the file. */
|
|
70
|
+
folder_remove: () => void;
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Writes a private temporary file.
|
|
74
|
+
*
|
|
75
|
+
* @param prefix - The folder's prefix under the system's temporary folder (`chell-edit-`).
|
|
76
|
+
* @param name - The file's name inside it: a plain name (no separator, `..` or NUL), else refused.
|
|
77
|
+
* @param data - What it holds: text or bytes.
|
|
78
|
+
* @returns The file, its folder, and how to remove them.
|
|
79
|
+
* @throws {Error} When the name or the prefix is not a plain name, the data neither text nor bytes, or the file cannot be written (the folder is then removed).
|
|
80
|
+
*
|
|
81
|
+
* @example
|
|
82
|
+
* ```ts
|
|
83
|
+
* const temp: PrivateTemp = privateTemp_write('chell-config-', 'config.tmp', bytes);
|
|
84
|
+
* ```
|
|
85
|
+
*/
|
|
86
|
+
export declare function privateTemp_write(prefix: string, name: string, data: unknown): PrivateTemp;
|
|
87
|
+
/**
|
|
88
|
+
* A suffix as asked, when it is a safe one; else the default.
|
|
89
|
+
*
|
|
90
|
+
* @param asked - The suffix asked for (a remote surface's, an operand's).
|
|
91
|
+
* @param fallback - What is used otherwise.
|
|
92
|
+
* @returns The suffix.
|
|
93
|
+
*
|
|
94
|
+
* @example
|
|
95
|
+
* ```ts
|
|
96
|
+
* suffix_safe('../x', '.txt'); // '.txt'
|
|
97
|
+
* ```
|
|
98
|
+
*/
|
|
99
|
+
export declare function suffix_safe(asked: string | undefined, fallback: string): string;
|
|
100
|
+
/**
|
|
101
|
+
* Why an owner-only place was not taken: its path and what was wrong with it, never what it holds.
|
|
102
|
+
*
|
|
103
|
+
* @example
|
|
104
|
+
* ```ts
|
|
105
|
+
* const refused: OwnRefusal = { ok: false, reason: '/tmp/calypso-1000: another account\'s' };
|
|
106
|
+
* ```
|
|
107
|
+
*/
|
|
108
|
+
export interface OwnRefusal {
|
|
109
|
+
/** Refused. */
|
|
110
|
+
ok: false;
|
|
111
|
+
/** The path and why. */
|
|
112
|
+
reason: string;
|
|
113
|
+
/** Set when the place is simply not there (ENOENT): absence, not a fault. */
|
|
114
|
+
missing?: true;
|
|
115
|
+
/** For a trusted walk that met a missing name: the trusted folder it stood in, links before it resolved. */
|
|
116
|
+
stoppedAt?: string;
|
|
117
|
+
/** For a trusted walk that met a missing name: that name and the ones after it, as the walk would have taken them. */
|
|
118
|
+
stillToGo?: string[];
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* An owner-only place taken.
|
|
122
|
+
*
|
|
123
|
+
* @example
|
|
124
|
+
* ```ts
|
|
125
|
+
* const held: OwnHeld = { ok: true };
|
|
126
|
+
* ```
|
|
127
|
+
*/
|
|
128
|
+
export interface OwnHeld {
|
|
129
|
+
/** Taken. */
|
|
130
|
+
ok: true;
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
* An owner-only folder held: its path as resolved through the trusted walk, the one every later use names.
|
|
134
|
+
*
|
|
135
|
+
* @example
|
|
136
|
+
* ```ts
|
|
137
|
+
* const held: OwnFolder = { ok: true, path: '/run/user/1000/calypso' };
|
|
138
|
+
* ```
|
|
139
|
+
*/
|
|
140
|
+
export interface OwnFolder {
|
|
141
|
+
/** Held. */
|
|
142
|
+
ok: true;
|
|
143
|
+
/** The folder, every link on the way resolved. */
|
|
144
|
+
path: string;
|
|
145
|
+
}
|
|
146
|
+
/**
|
|
147
|
+
* Resolves a folder's path through trusted folders only: from `/` (itself trusted), each name as spelled, every
|
|
148
|
+
* folder root's or this account's and not open to others (unless root's and sticky), every link found in such a
|
|
149
|
+
* folder followed the same way. No folder another account could change is passed through, by any spelling.
|
|
150
|
+
*
|
|
151
|
+
* @param folder - The folder.
|
|
152
|
+
* @param uid - This account's uid.
|
|
153
|
+
* @returns The resolved path, or why not (`missing` when a name on the way is not there).
|
|
154
|
+
*
|
|
155
|
+
* @example
|
|
156
|
+
* ```ts
|
|
157
|
+
* const walked: OwnFolder | OwnRefusal = trustedPath_resolve('/home/me/.local/state/porter', uid);
|
|
158
|
+
* ```
|
|
159
|
+
*/
|
|
160
|
+
export declare function trustedPath_resolve(folder: string, uid?: number | null): OwnFolder | OwnRefusal;
|
|
161
|
+
/**
|
|
162
|
+
* Holds a host's state root: its path resolved through trusted folders only, and the root itself, when it is there,
|
|
163
|
+
* root's or this account's and not writable by group or others, sticky or not (a shared `/tmp` is a fine place to
|
|
164
|
+
* pass through and no place to keep state in). A root not made yet, below trusted folders, is a first start: its
|
|
165
|
+
* path is the resolved folder that is there joined with the names still to make.
|
|
166
|
+
*
|
|
167
|
+
* @param folder - The state root.
|
|
168
|
+
* @param uid - This account's uid (a test's seam).
|
|
169
|
+
* @returns The root's resolved path, or the first thing on the way another account could change.
|
|
170
|
+
*
|
|
171
|
+
* @example
|
|
172
|
+
* ```ts
|
|
173
|
+
* const root: OwnFolder | OwnRefusal = trustedRoot_settle(stateDir);
|
|
174
|
+
* if (root.ok) host_start(root.path);
|
|
175
|
+
* ```
|
|
176
|
+
*/
|
|
177
|
+
export declare function trustedRoot_settle(folder: string, uid?: number | null): OwnFolder | OwnRefusal;
|
|
178
|
+
/**
|
|
179
|
+
* Holds a folder only this account can use: its parent resolved through trusted folders only
|
|
180
|
+
* (`trustedPath_resolve`); the folder itself a real directory, not a link, this account's, with no group or other
|
|
181
|
+
* bits. Once that holds, no other account can swap the folder or write in it, so its resolved path is as good as a
|
|
182
|
+
* handle: every later use names `path`, never the spelling it was asked by.
|
|
183
|
+
*
|
|
184
|
+
* @param folder - The folder.
|
|
185
|
+
* @param create - Make it (0700) when it is missing; a reader passes false and a missing folder is refused.
|
|
186
|
+
* @param uid - This account's uid (a test's seam).
|
|
187
|
+
* @returns Held with its path, or why not (`missing` when it, or its parent, is simply not there).
|
|
188
|
+
*
|
|
189
|
+
* @example
|
|
190
|
+
* ```ts
|
|
191
|
+
* const held: OwnFolder | OwnRefusal = ownFolder_settle(berthDir, true);
|
|
192
|
+
* ```
|
|
193
|
+
*/
|
|
194
|
+
export declare function ownFolder_settle(folder: string, create: boolean, uid?: number | null): OwnFolder | OwnRefusal;
|
|
195
|
+
/**
|
|
196
|
+
* An owner-only file read whole.
|
|
197
|
+
*
|
|
198
|
+
* @example
|
|
199
|
+
* ```ts
|
|
200
|
+
* const read: OwnText = { ok: true, text: '{}' };
|
|
201
|
+
* ```
|
|
202
|
+
*/
|
|
203
|
+
export interface OwnText {
|
|
204
|
+
/** Read. */
|
|
205
|
+
ok: true;
|
|
206
|
+
/** What it holds. */
|
|
207
|
+
text: string;
|
|
208
|
+
}
|
|
209
|
+
/** What an owner-only read gave: the text, or why it was refused. */
|
|
210
|
+
export type OwnRead = OwnText | OwnRefusal;
|
|
211
|
+
/**
|
|
212
|
+
* Reads an owner-only file in a held folder: opened without following a link, a regular file of this account's
|
|
213
|
+
* with no group or other bits, at most `maxBytes` (more is refused).
|
|
214
|
+
*
|
|
215
|
+
* @param file - The file, named under a held folder's `path`.
|
|
216
|
+
* @param maxBytes - The most it may hold.
|
|
217
|
+
* @param uid - This account's uid (a test's seam).
|
|
218
|
+
* @returns Its text, or why not (`missing` when it is not there).
|
|
219
|
+
*
|
|
220
|
+
* @example
|
|
221
|
+
* ```ts
|
|
222
|
+
* const read: OwnRead = ownFile_read(join(held.path, 'berth-0123.json'), 64 * 1024);
|
|
223
|
+
* ```
|
|
224
|
+
*/
|
|
225
|
+
export declare function ownFile_read(file: string, maxBytes: number, uid?: number | null): OwnRead;
|
|
226
|
+
/**
|
|
227
|
+
* Writes every byte of a buffer on an open descriptor, however many calls it takes.
|
|
228
|
+
*
|
|
229
|
+
* @param handle - The descriptor.
|
|
230
|
+
* @param bytes - What to write.
|
|
231
|
+
* @param write - The write call (a test's seam).
|
|
232
|
+
* @throws {Error} When a write makes no progress.
|
|
233
|
+
*
|
|
234
|
+
* @example
|
|
235
|
+
* ```ts
|
|
236
|
+
* bytes_writeAll(handle, Buffer.from(text, 'utf8'));
|
|
237
|
+
* ```
|
|
238
|
+
*/
|
|
239
|
+
export declare function bytes_writeAll(handle: number, bytes: Uint8Array, write?: (handle: number, bytes: Uint8Array, offset: number, length: number) => number): void;
|
|
240
|
+
/**
|
|
241
|
+
* Writes an owner-only file in a held folder, atomically: a fresh temporary file (`O_EXCL|O_NOFOLLOW`, 0600), every
|
|
242
|
+
* byte written, synced, renamed over the name. A standing entry that is not this account's regular 0600 file (a
|
|
243
|
+
* link, another account's, wider) is refused and left as it is, its target untouched; a failed write leaves the
|
|
244
|
+
* standing record as it was.
|
|
245
|
+
*
|
|
246
|
+
* @param folder - The held folder's `path`.
|
|
247
|
+
* @param name - The file's name in it (a plain name).
|
|
248
|
+
* @param text - What it holds.
|
|
249
|
+
* @param uid - This account's uid (a test's seam).
|
|
250
|
+
* @param write - The write call (a test's seam).
|
|
251
|
+
* @returns Held, or why not.
|
|
252
|
+
*
|
|
253
|
+
* @example
|
|
254
|
+
* ```ts
|
|
255
|
+
* ownFile_write(held.path, 'berth-0123456789abcdef.json', JSON.stringify(record));
|
|
256
|
+
* ```
|
|
257
|
+
*/
|
|
258
|
+
export declare function ownFile_write(folder: string, name: string, text: string, uid?: number | null, write?: (handle: number, bytes: Uint8Array, offset: number, length: number) => number): OwnHeld | OwnRefusal;
|
|
259
|
+
/**
|
|
260
|
+
* Takes an owner-only file: judged where it stands (a link, another account's or a wider file is refused and left
|
|
261
|
+
* as it is), then renamed aside (atomic), read and the aside name removed. What is taken is never put back; a note
|
|
262
|
+
* taken by two readers is had by one.
|
|
263
|
+
*
|
|
264
|
+
* @param folder - The held folder's `path`.
|
|
265
|
+
* @param name - The file's name.
|
|
266
|
+
* @param maxBytes - The most it may hold.
|
|
267
|
+
* @param uid - This account's uid (a test's seam).
|
|
268
|
+
* @returns Its text, or why not.
|
|
269
|
+
*
|
|
270
|
+
* @example
|
|
271
|
+
* ```ts
|
|
272
|
+
* const note: OwnRead = ownFile_take(held.path, 'closing-0123.json', 4096);
|
|
273
|
+
* ```
|
|
274
|
+
*/
|
|
275
|
+
export declare function ownFile_take(folder: string, name: string, maxBytes: number, uid?: number | null): OwnRead;
|