@sublang/spex 6.0.0 → 7.0.0-beta.2
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 +419 -12
- package/dist/cli.js +12 -1
- package/dist/commands/add.d.ts +1 -1
- package/dist/commands/add.js +2 -2
- package/dist/commands/environment.d.ts +3 -3
- package/dist/commands/environment.js +5 -7
- package/dist/commands/export.js +2 -2
- package/dist/commands/home.d.ts +2 -2
- package/dist/commands/home.js +3 -3
- package/dist/commands/list.js +1 -1
- package/dist/commands/login.js +12 -7
- package/dist/commands/logout.js +2 -3
- package/dist/commands/publish.js +1 -1
- package/dist/commands/remove.js +1 -1
- package/dist/commands/run.d.ts +1 -1
- package/dist/commands/run.js +16 -0
- package/dist/commands/settle.d.ts +1 -1
- package/dist/commands/settle.js +1 -1
- package/dist/guards/approval.d.ts +56 -0
- package/dist/guards/approval.js +158 -0
- package/dist/guards/checks.d.ts +207 -0
- package/dist/guards/checks.js +681 -0
- package/dist/guards/commands.d.ts +15 -0
- package/dist/guards/commands.js +313 -0
- package/dist/guards/copy.d.ts +67 -0
- package/dist/guards/copy.js +306 -0
- package/dist/guards/declaration.d.ts +45 -0
- package/dist/guards/declaration.js +224 -0
- package/dist/guards/files.d.ts +137 -0
- package/dist/guards/files.js +544 -0
- package/dist/guards/harness.d.ts +58 -0
- package/dist/guards/harness.js +420 -0
- package/dist/guards/items.d.ts +61 -0
- package/dist/guards/items.js +161 -0
- package/dist/guards/patch.d.ts +55 -0
- package/dist/guards/patch.js +258 -0
- package/dist/guards/processes.d.ts +49 -0
- package/dist/guards/processes.js +233 -0
- package/dist/guards/proofs.d.ts +88 -0
- package/dist/guards/proofs.js +503 -0
- package/dist/guards/records.d.ts +176 -0
- package/dist/guards/records.js +513 -0
- package/dist/guards/report.d.ts +26 -0
- package/dist/guards/report.js +492 -0
- package/dist/guards/runner.d.ts +42 -0
- package/dist/guards/runner.js +167 -0
- package/dist/guards/tla.d.ts +51 -0
- package/dist/guards/tla.js +352 -0
- package/dist/guards/tlapm.d.ts +81 -0
- package/dist/guards/tlapm.js +172 -0
- package/dist/guards/tlc.d.ts +191 -0
- package/dist/guards/tlc.js +457 -0
- package/dist/guards/translation.d.ts +66 -0
- package/dist/guards/translation.js +202 -0
- package/dist/guards/types.d.ts +185 -0
- package/dist/guards/types.js +437 -0
- package/dist/guards/verify.d.ts +290 -0
- package/dist/guards/verify.js +1191 -0
- package/dist/guards/xml.d.ts +18 -0
- package/dist/guards/xml.js +105 -0
- package/dist/lib/environment/archive.d.ts +2 -2
- package/dist/lib/environment/archive.js +1 -1
- package/dist/lib/environment/builtins.d.ts +10 -12
- package/dist/lib/environment/builtins.js +17 -19
- package/dist/lib/environment/exports.d.ts +14 -13
- package/dist/lib/environment/exports.js +31 -16
- package/dist/lib/environment/format.d.ts +2 -2
- package/dist/lib/environment/format.js +3 -3
- package/dist/lib/environment/git-source.js +6 -3
- package/dist/lib/environment/install.d.ts +14 -16
- package/dist/lib/environment/install.js +66 -61
- package/dist/lib/environment/lock.d.ts +4 -3
- package/dist/lib/environment/lock.js +6 -5
- package/dist/lib/environment/marker.js +1 -2
- package/dist/lib/environment/own-paths.d.ts +7 -10
- package/dist/lib/environment/own-paths.js +10 -13
- package/dist/lib/environment/placed-record.d.ts +3 -2
- package/dist/lib/environment/placed-record.js +5 -4
- package/dist/lib/environment/registry.d.ts +1 -1
- package/dist/lib/environment/registry.js +1 -1
- package/dist/lib/environment/requests.d.ts +2 -2
- package/dist/lib/environment/requests.js +2 -2
- package/dist/lib/environment/resolve.d.ts +4 -4
- package/dist/lib/environment/resolve.js +3 -4
- package/dist/lib/environment/store.d.ts +34 -8
- package/dist/lib/environment/store.js +138 -43
- package/dist/lib/files.d.ts +72 -12
- package/dist/lib/files.js +200 -65
- package/dist/lib/git-host.d.ts +52 -258
- package/dist/lib/git-host.js +52 -265
- package/dist/lib/home-file.d.ts +13 -10
- package/dist/lib/home-file.js +28 -18
- package/dist/lib/instance.d.ts +1 -1
- package/dist/lib/instance.js +1 -1
- package/dist/lint.d.ts +22 -0
- package/dist/lint.js +36 -0
- package/dist/testing/standin-registry.js +1 -1
- package/package.json +7 -3
- package/scaffold/.file-history.json +14 -7
- package/scaffold/i18n/zh/source-pins.json +41 -0
- package/scaffold/i18n/zh/specs/decisions/000-spec-structure-format.md +0 -1
- package/scaffold/i18n/zh/specs/intents/000-spdx-headers.md +0 -1
- package/scaffold/i18n/zh/specs/map.md +0 -1
- package/scaffold/i18n/zh/specs/meta.md +18 -35
- package/scaffold/i18n/zh/specs/packages/git.md +0 -1
- package/scaffold/i18n/zh/specs/packages/licensing.md +0 -1
- package/scaffold/specs/meta.md +18 -3
- package/scripts/test-exit-guard.mjs +28 -0
|
@@ -57,7 +57,7 @@ export function isInsidePath(path) {
|
|
|
57
57
|
}
|
|
58
58
|
const REQUEST_FIELDS = new Set(["version", "path", "git", "rev", "select", "alias"]);
|
|
59
59
|
/** Every reason a request for a name is refused (environments-2,
|
|
60
|
-
* environments-
|
|
60
|
+
* environments-65): a bad name, no or several sources, a malformed
|
|
61
61
|
* requirement, a path that is not relative or leads out of the folder
|
|
62
62
|
* it is relative to, a bad select or alias. */
|
|
63
63
|
export function requestIssues(name, request) {
|
|
@@ -375,7 +375,7 @@ export async function editRequests(file, edit) {
|
|
|
375
375
|
writeVersionedBytes(file, text, version);
|
|
376
376
|
return { requests, text, digest: requestsDigest(text) };
|
|
377
377
|
}
|
|
378
|
-
/** Set one package's request, or remove it with null (environments-
|
|
378
|
+
/** Set one package's request, or remove it with null (environments-65). */
|
|
379
379
|
export async function setRequest(file, name, request) {
|
|
380
380
|
if (request !== null) {
|
|
381
381
|
const issues = requestIssues(name, request);
|
|
@@ -26,11 +26,11 @@ export interface ResolveInput {
|
|
|
26
26
|
requestsText?: string;
|
|
27
27
|
registry: RegistrySource;
|
|
28
28
|
/** The folder a request's `path` is relative to (environments-2): the
|
|
29
|
-
* paired working folder's root, or
|
|
29
|
+
* paired working folder's root, or the global records repository's; null
|
|
30
30
|
* where this device has none. */
|
|
31
31
|
pathRoot: string | null;
|
|
32
|
-
/** Whether `pathRoot` is
|
|
33
|
-
* path name only a folder that syncs with it
|
|
32
|
+
/** Whether `pathRoot` is the global records repository, whose requests by
|
|
33
|
+
* path name only a folder that syncs with it. */
|
|
34
34
|
confined?: boolean;
|
|
35
35
|
git: GitSource;
|
|
36
36
|
/** The credential for a Git repository, where one applies. */
|
|
@@ -48,7 +48,7 @@ export type ResolveErrorKind = "no_working_folder" | "path_outside" | "path_conf
|
|
|
48
48
|
* the request's folder or Git repository at its revision; whether the
|
|
49
49
|
* folder itself is missing; the package a folder holds in place of the
|
|
50
50
|
* one asked; the issues of a `meta.yaml` that does not read; and the
|
|
51
|
-
* reason
|
|
51
|
+
* reason the global records repository refuses a folder. */
|
|
52
52
|
export interface ResolveErrorDetail {
|
|
53
53
|
path?: string;
|
|
54
54
|
git?: string;
|
|
@@ -52,8 +52,7 @@ function selectionHolds(selection, artifacts) {
|
|
|
52
52
|
return artifact !== undefined && (entry.language === undefined || artifact.languages.includes(entry.language));
|
|
53
53
|
});
|
|
54
54
|
}
|
|
55
|
-
/** A path
|
|
56
|
-
* (environments-32), with its reason for a host to phrase. */
|
|
55
|
+
/** A path the global records repository refuses, in the library's words, with its reason for a host to phrase. */
|
|
57
56
|
function confinedError(name, path, issue) {
|
|
58
57
|
return new ResolveError("path_confined", name, ownPathMessage(name, path, issue), { path, confined: issue });
|
|
59
58
|
}
|
|
@@ -96,7 +95,7 @@ async function loadFixed(name, request, input) {
|
|
|
96
95
|
if (real.startsWith("..") || isAbsolute(real))
|
|
97
96
|
throw new ResolveError("path_outside", name, `${name}: ${path} leads out of ${place} through a link`, { path });
|
|
98
97
|
const release = await readRequested(name, dir, path, { path });
|
|
99
|
-
//
|
|
98
|
+
// The global records repository syncs the files it tracks.
|
|
100
99
|
if (input.confined) {
|
|
101
100
|
const issue = ownFolderIssue(root, request.path, release.files.map((file) => file.path));
|
|
102
101
|
if (issue)
|
|
@@ -419,7 +418,7 @@ export async function resolve(input) {
|
|
|
419
418
|
.sort((a, b) => (a.path < b.path ? -1 : a.path > b.path ? 1 : 0))
|
|
420
419
|
: [];
|
|
421
420
|
// 4. Exports: one skill per provided skill and playbook under its
|
|
422
|
-
// id, and per provided spec under `<org>-<pkg>` (DR-
|
|
421
|
+
// id, and per provided spec under `<org>-<pkg>` (DR-174), or alias;
|
|
423
422
|
// a selected artifact its release does not provide — a sibling's
|
|
424
423
|
// support, or of a kind `provides` leaves out — is installed with the
|
|
425
424
|
// rest and placed nowhere, so its name clashes with none.
|
|
@@ -5,19 +5,45 @@ export declare class DigestError extends Error {
|
|
|
5
5
|
readonly what: string;
|
|
6
6
|
constructor(expected: string, actual: string, what: string);
|
|
7
7
|
}
|
|
8
|
-
/**
|
|
9
|
-
export declare function storeKey(sha256: string, executable: boolean): string;
|
|
10
|
-
/** Every store entry the given locks select. */
|
|
8
|
+
/** Every stored file the given locks select, by digest. */
|
|
11
9
|
export declare function lockStoreKeys(locks: Iterable<Lock>): Set<string>;
|
|
12
10
|
export declare class ContentStore {
|
|
13
11
|
readonly root: string;
|
|
14
12
|
constructor(homeDir: string);
|
|
15
|
-
pathOf(sha256: string
|
|
16
|
-
has(sha256: string
|
|
13
|
+
pathOf(sha256: string): string;
|
|
14
|
+
has(sha256: string): boolean;
|
|
17
15
|
/** Store bytes under their digest, verified first; written once. */
|
|
18
|
-
put(bytes: Uint8Array, sha256: string,
|
|
19
|
-
/**
|
|
16
|
+
put(bytes: Uint8Array, sha256: string, what?: string): string;
|
|
17
|
+
/** Take a file's former copy under `x/` as the stored file where the
|
|
18
|
+
* store lacks it, verified as any bytes are (environments-7): whether
|
|
19
|
+
* the store now holds the file. A copy that does not match its digest
|
|
20
|
+
* is no stored file; one that cannot be taken for another reason is
|
|
21
|
+
* none here either, an install then fetching the file. */
|
|
22
|
+
adoptFormer(sha256: string): boolean;
|
|
23
|
+
/** `adoptFormer`, throwing where the copy stands and matches or cannot
|
|
24
|
+
* be read, yet cannot be stored: the store refusing the write, or the
|
|
25
|
+
* device full. False where no copy stands or it does not match. */
|
|
26
|
+
private takeFormer;
|
|
27
|
+
/** Every stored file's digest. */
|
|
20
28
|
keys(): string[];
|
|
21
|
-
/**
|
|
29
|
+
/** Copy a stored file to `to`, where no file stands, as an ordinary
|
|
30
|
+
* writable file, executable or not as the lock says, whatever the
|
|
31
|
+
* umask. The bytes are checked against their digest as they are read:
|
|
32
|
+
* a stored file that no longer matches is removed and nothing is
|
|
33
|
+
* written (environments-7). */
|
|
34
|
+
copy(sha256: string, executable: boolean, to: string, what?: string): void;
|
|
35
|
+
/** Remove every stored file no lock selects, read-only as it is, and
|
|
36
|
+
* the former `x/`, each of its copies a lock selects taken as the
|
|
37
|
+
* stored file first where the store lacks it — a lock whose install
|
|
38
|
+
* did not run, stale or with no folder here, keeps its bytes. A
|
|
39
|
+
* selected copy that could not be taken for another reason than its
|
|
40
|
+
* digest stands, with `x/`, for a later collection. Every step is
|
|
41
|
+
* tried whatever another's failure, and the failures are thrown once
|
|
42
|
+
* all are done; returns the removed digests (environments-7). */
|
|
22
43
|
gc(selected: Set<string>): string[];
|
|
44
|
+
/** The former `x/` at a collection: each copy a lock selects taken as
|
|
45
|
+
* the stored file, then removed with every copy no lock selects and
|
|
46
|
+
* every one that does not match its digest; one that could not be
|
|
47
|
+
* taken stands, its cause noted in `failures`, and `x/` with it. */
|
|
48
|
+
private collectFormer;
|
|
23
49
|
}
|
|
@@ -1,13 +1,16 @@
|
|
|
1
1
|
// SPDX-License-Identifier: Apache-2.0
|
|
2
2
|
// SPDX-FileCopyrightText: 2026 SubLang International <https://sublang.ai>
|
|
3
|
-
// The content-addressed store under the home (environments-7, DR-104
|
|
4
|
-
// each distinct file once, named by
|
|
5
|
-
//
|
|
6
|
-
//
|
|
7
|
-
//
|
|
3
|
+
// The content-addressed store under the home (environments-7, DR-104,
|
|
4
|
+
// DR-251): a cache of verified bytes, each distinct file once, named by
|
|
5
|
+
// its SHA-256, written once after its digest is verified. An install
|
|
6
|
+
// copies a file out, its digest checked again as it is read, so an
|
|
7
|
+
// installed tree shares nothing with the store. A stored file is written
|
|
8
|
+
// read-only against an edit by mistake; nothing relies on that mark. A
|
|
9
|
+
// file stays while a lock of an environment the home knows selects it.
|
|
8
10
|
import { randomUUID } from "node:crypto";
|
|
9
|
-
import { chmodSync, closeSync, existsSync, fsyncSync, mkdirSync, openSync, readdirSync,
|
|
11
|
+
import { chmodSync, closeSync, existsSync, fsyncSync, mkdirSync, openSync, readdirSync, readFileSync, renameSync, statSync, writeFileSync, writeSync } from "node:fs";
|
|
10
12
|
import { join } from "node:path";
|
|
13
|
+
import { removeTree } from "../files.js";
|
|
11
14
|
import { sha256Hex } from "./format.js";
|
|
12
15
|
export class DigestError extends Error {
|
|
13
16
|
expected;
|
|
@@ -21,45 +24,43 @@ export class DigestError extends Error {
|
|
|
21
24
|
this.name = "DigestError";
|
|
22
25
|
}
|
|
23
26
|
}
|
|
24
|
-
/**
|
|
25
|
-
export function storeKey(sha256, executable) {
|
|
26
|
-
return executable ? `x/${sha256}` : sha256;
|
|
27
|
-
}
|
|
28
|
-
/** Every store entry the given locks select. */
|
|
27
|
+
/** Every stored file the given locks select, by digest. */
|
|
29
28
|
export function lockStoreKeys(locks) {
|
|
30
29
|
const keys = new Set();
|
|
31
30
|
for (const lock of locks) {
|
|
32
31
|
for (const resolution of Object.values(lock.packages)) {
|
|
33
32
|
for (const file of resolution.files)
|
|
34
|
-
keys.add(
|
|
33
|
+
keys.add(file.sha256);
|
|
35
34
|
}
|
|
36
35
|
}
|
|
37
36
|
return keys;
|
|
38
37
|
}
|
|
39
38
|
const SHA_RE = /^[0-9a-f]{64}$/;
|
|
39
|
+
/** Where an earlier release kept an executable file's own copy, links
|
|
40
|
+
* sharing one mode (DR-251). */
|
|
41
|
+
const FORMER_COPIES = "x";
|
|
40
42
|
export class ContentStore {
|
|
41
43
|
root;
|
|
42
44
|
constructor(homeDir) {
|
|
43
45
|
this.root = join(homeDir, "store");
|
|
44
46
|
}
|
|
45
|
-
pathOf(sha256
|
|
47
|
+
pathOf(sha256) {
|
|
46
48
|
if (!SHA_RE.test(sha256))
|
|
47
49
|
throw new Error(`"${sha256}" is not a SHA-256 digest`);
|
|
48
|
-
return
|
|
50
|
+
return join(this.root, sha256);
|
|
49
51
|
}
|
|
50
|
-
has(sha256
|
|
51
|
-
return existsSync(this.pathOf(sha256
|
|
52
|
+
has(sha256) {
|
|
53
|
+
return existsSync(this.pathOf(sha256));
|
|
52
54
|
}
|
|
53
55
|
/** Store bytes under their digest, verified first; written once. */
|
|
54
|
-
put(bytes, sha256,
|
|
55
|
-
const target = this.pathOf(sha256
|
|
56
|
+
put(bytes, sha256, what = "file") {
|
|
57
|
+
const target = this.pathOf(sha256);
|
|
56
58
|
const actual = sha256Hex(bytes);
|
|
57
59
|
if (actual !== sha256)
|
|
58
60
|
throw new DigestError(sha256, actual, what);
|
|
59
61
|
if (existsSync(target))
|
|
60
62
|
return target;
|
|
61
|
-
|
|
62
|
-
mkdirSync(dir, { recursive: true });
|
|
63
|
+
mkdirSync(this.root, { recursive: true });
|
|
63
64
|
const temporary = join(this.root, `.tmp-${randomUUID()}`);
|
|
64
65
|
const fd = openSync(temporary, "wx", 0o600);
|
|
65
66
|
try {
|
|
@@ -71,40 +72,105 @@ export class ContentStore {
|
|
|
71
72
|
finally {
|
|
72
73
|
closeSync(fd);
|
|
73
74
|
}
|
|
74
|
-
chmodSync(temporary,
|
|
75
|
+
chmodSync(temporary, 0o444);
|
|
75
76
|
if (existsSync(target))
|
|
76
|
-
|
|
77
|
+
removeTree(temporary);
|
|
77
78
|
else
|
|
78
79
|
renameSync(temporary, target);
|
|
79
80
|
return target;
|
|
80
81
|
}
|
|
81
|
-
/**
|
|
82
|
+
/** Take a file's former copy under `x/` as the stored file where the
|
|
83
|
+
* store lacks it, verified as any bytes are (environments-7): whether
|
|
84
|
+
* the store now holds the file. A copy that does not match its digest
|
|
85
|
+
* is no stored file; one that cannot be taken for another reason is
|
|
86
|
+
* none here either, an install then fetching the file. */
|
|
87
|
+
adoptFormer(sha256) {
|
|
88
|
+
try {
|
|
89
|
+
return this.takeFormer(sha256);
|
|
90
|
+
}
|
|
91
|
+
catch {
|
|
92
|
+
return false;
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
/** `adoptFormer`, throwing where the copy stands and matches or cannot
|
|
96
|
+
* be read, yet cannot be stored: the store refusing the write, or the
|
|
97
|
+
* device full. False where no copy stands or it does not match. */
|
|
98
|
+
takeFormer(sha256) {
|
|
99
|
+
if (this.has(sha256))
|
|
100
|
+
return true;
|
|
101
|
+
let bytes;
|
|
102
|
+
try {
|
|
103
|
+
bytes = readFileSync(join(this.root, FORMER_COPIES, sha256));
|
|
104
|
+
}
|
|
105
|
+
catch (error) {
|
|
106
|
+
if (error.code === "ENOENT")
|
|
107
|
+
return false;
|
|
108
|
+
throw error;
|
|
109
|
+
}
|
|
110
|
+
try {
|
|
111
|
+
this.put(bytes, sha256);
|
|
112
|
+
}
|
|
113
|
+
catch (error) {
|
|
114
|
+
if (error instanceof DigestError)
|
|
115
|
+
return false;
|
|
116
|
+
throw error;
|
|
117
|
+
}
|
|
118
|
+
return true;
|
|
119
|
+
}
|
|
120
|
+
/** Every stored file's digest. */
|
|
82
121
|
keys() {
|
|
83
|
-
const out = [];
|
|
84
122
|
if (!existsSync(this.root))
|
|
85
|
-
return
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
123
|
+
return [];
|
|
124
|
+
return readdirSync(this.root).filter((name) => SHA_RE.test(name));
|
|
125
|
+
}
|
|
126
|
+
/** Copy a stored file to `to`, where no file stands, as an ordinary
|
|
127
|
+
* writable file, executable or not as the lock says, whatever the
|
|
128
|
+
* umask. The bytes are checked against their digest as they are read:
|
|
129
|
+
* a stored file that no longer matches is removed and nothing is
|
|
130
|
+
* written (environments-7). */
|
|
131
|
+
copy(sha256, executable, to, what = "file") {
|
|
132
|
+
const from = this.pathOf(sha256);
|
|
133
|
+
const bytes = readFileSync(from);
|
|
134
|
+
const actual = sha256Hex(bytes);
|
|
135
|
+
if (actual !== sha256) {
|
|
136
|
+
removeTree(from);
|
|
137
|
+
throw new DigestError(sha256, actual, `the stored copy of ${what}`);
|
|
138
|
+
}
|
|
139
|
+
const mode = executable ? 0o755 : 0o644;
|
|
140
|
+
writeFileSync(to, bytes, { flag: "wx", mode });
|
|
141
|
+
chmodSync(to, mode);
|
|
95
142
|
}
|
|
96
|
-
/** Remove every
|
|
143
|
+
/** Remove every stored file no lock selects, read-only as it is, and
|
|
144
|
+
* the former `x/`, each of its copies a lock selects taken as the
|
|
145
|
+
* stored file first where the store lacks it — a lock whose install
|
|
146
|
+
* did not run, stale or with no folder here, keeps its bytes. A
|
|
147
|
+
* selected copy that could not be taken for another reason than its
|
|
148
|
+
* digest stands, with `x/`, for a later collection. Every step is
|
|
149
|
+
* tried whatever another's failure, and the failures are thrown once
|
|
150
|
+
* all are done; returns the removed digests (environments-7). */
|
|
97
151
|
gc(selected) {
|
|
98
152
|
const removed = [];
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
153
|
+
if (!existsSync(this.root))
|
|
154
|
+
return removed;
|
|
155
|
+
const failures = [];
|
|
156
|
+
const step = (run) => { try {
|
|
157
|
+
run();
|
|
104
158
|
}
|
|
159
|
+
catch (error) {
|
|
160
|
+
failures.push(error);
|
|
161
|
+
} };
|
|
162
|
+
step(() => this.collectFormer(selected, failures));
|
|
163
|
+
step(() => {
|
|
164
|
+
for (const key of this.keys()) {
|
|
165
|
+
if (selected.has(key))
|
|
166
|
+
continue;
|
|
167
|
+
removeTree(join(this.root, key));
|
|
168
|
+
removed.push(key);
|
|
169
|
+
}
|
|
170
|
+
});
|
|
105
171
|
// A temporary file an interrupted put left behind, once it is old
|
|
106
172
|
// enough not to be a put still running.
|
|
107
|
-
|
|
173
|
+
step(() => {
|
|
108
174
|
const before = Date.now() - 60 * 60 * 1000;
|
|
109
175
|
for (const name of readdirSync(this.root)) {
|
|
110
176
|
if (!name.startsWith(".tmp-"))
|
|
@@ -112,12 +178,41 @@ export class ContentStore {
|
|
|
112
178
|
const file = join(this.root, name);
|
|
113
179
|
try {
|
|
114
180
|
if (statSync(file).mtimeMs < before)
|
|
115
|
-
|
|
181
|
+
removeTree(file);
|
|
116
182
|
}
|
|
117
183
|
catch { /* gone */ }
|
|
118
184
|
}
|
|
119
|
-
}
|
|
185
|
+
});
|
|
186
|
+
if (failures.length === 1)
|
|
187
|
+
throw failures[0];
|
|
188
|
+
if (failures.length > 1)
|
|
189
|
+
throw new AggregateError(failures, failures.map((failure) => (failure instanceof Error ? failure.message : String(failure))).join("; "));
|
|
120
190
|
return removed;
|
|
121
191
|
}
|
|
192
|
+
/** The former `x/` at a collection: each copy a lock selects taken as
|
|
193
|
+
* the stored file, then removed with every copy no lock selects and
|
|
194
|
+
* every one that does not match its digest; one that could not be
|
|
195
|
+
* taken stands, its cause noted in `failures`, and `x/` with it. */
|
|
196
|
+
collectFormer(selected, failures) {
|
|
197
|
+
const former = join(this.root, FORMER_COPIES);
|
|
198
|
+
if (!existsSync(former))
|
|
199
|
+
return;
|
|
200
|
+
let kept = false;
|
|
201
|
+
for (const name of readdirSync(former)) {
|
|
202
|
+
if (selected.has(name)) {
|
|
203
|
+
try {
|
|
204
|
+
this.takeFormer(name);
|
|
205
|
+
}
|
|
206
|
+
catch (error) {
|
|
207
|
+
kept = true;
|
|
208
|
+
failures.push(new Error(`store/${FORMER_COPIES}/${name} stays, not taken as the stored file: ${error instanceof Error ? error.message : String(error)}`, { cause: error }));
|
|
209
|
+
continue;
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
removeTree(join(former, name));
|
|
213
|
+
}
|
|
214
|
+
if (!kept)
|
|
215
|
+
removeTree(former);
|
|
216
|
+
}
|
|
122
217
|
}
|
|
123
218
|
//# sourceMappingURL=store.js.map
|
package/dist/lib/files.d.ts
CHANGED
|
@@ -1,20 +1,29 @@
|
|
|
1
1
|
import { type Stats } from "node:fs";
|
|
2
2
|
/** A canonical lowercase UUID. */
|
|
3
3
|
export declare const UUID: RegExp;
|
|
4
|
-
/** A list a language punctuates its own way
|
|
4
|
+
/** A list a language punctuates its own way. */
|
|
5
5
|
export declare const listed: (names: readonly string[]) => string;
|
|
6
6
|
export declare class StorageFormatError extends Error {
|
|
7
7
|
readonly file: string;
|
|
8
8
|
readonly reason: string;
|
|
9
9
|
constructor(file: string, reason: string);
|
|
10
10
|
}
|
|
11
|
-
/** Spex's private-storage
|
|
12
|
-
*
|
|
11
|
+
/** Spex's private-storage check (storage-57) over facts inspected by
|
|
12
|
+
* fs-safe, applied only where an entry's integrity is relied on — the
|
|
13
|
+
* root lease, a clone's lease before a move, and upload staging. POSIX admits the current user's entry with no group or
|
|
14
|
+
* other bit. Windows admits an entry the current user, LocalSystem or
|
|
15
|
+
* built-in Administrators own, as root is on POSIX, whose descriptor
|
|
16
|
+
* grants no other principal a right to change it; a read grant another
|
|
17
|
+
* tool added, such as the Codex sandbox's, is admitted (DR-223). */
|
|
13
18
|
export declare function hasPrivatePermissions(file: string, stat: Pick<Stats, "mode" | "uid">): boolean;
|
|
14
|
-
/** Create a Windows state root privately from its first appearance
|
|
15
|
-
*
|
|
19
|
+
/** Create a Windows state root privately from its first appearance; an
|
|
20
|
+
* existing root is admitted whatever its permissions, as on POSIX
|
|
21
|
+
* (storage-57, DR-223). */
|
|
16
22
|
export declare function prepareWindowsStorageDirectory(directory: string): Promise<void>;
|
|
17
|
-
/**
|
|
23
|
+
/** Make a folder owner-only where none stands — on Windows through
|
|
24
|
+
* fs-safe's protected creator, each missing parent the same way — and
|
|
25
|
+
* admit one that stands whatever its permissions, refusing only a link or
|
|
26
|
+
* a non-directory (storage-57). */
|
|
18
27
|
export declare function makePrivateDirectory(directory: string): void;
|
|
19
28
|
/** A directory reader never follows a linked root. Missing roots are
|
|
20
29
|
* empty; a present non-directory is a storage diagnostic. */
|
|
@@ -31,11 +40,12 @@ export declare const isRecordedPath: (value: unknown) => value is string;
|
|
|
31
40
|
export declare function need(condition: unknown, file: string, reason: string): asserts condition;
|
|
32
41
|
/** A closed object: the required fields present, nothing undeclared. */
|
|
33
42
|
export declare function closed(value: unknown, required: string[], optional: string[], file: string): asserts value is Record<string, unknown>;
|
|
34
|
-
/** A reader refuses a layout version it does not know
|
|
43
|
+
/** A reader refuses a layout version it does not know: one
|
|
35
44
|
* format, or any of a list a reader reads. */
|
|
36
45
|
export declare function knownFormat(value: Record<string, unknown>, file: string, format?: number | readonly number[]): void;
|
|
37
46
|
export declare function readJsonFile(file: string): unknown;
|
|
38
|
-
/** Atomic same-directory replacement
|
|
47
|
+
/** Atomic same-directory replacement of a Spex-owned file, created
|
|
48
|
+
* owner-only and synced before and after the rename (storage-57). */
|
|
39
49
|
export declare function writeApplicationBytes(file: string, bytes: Buffer | string): void;
|
|
40
50
|
export declare function writeApplicationFile(file: string, value: unknown): void;
|
|
41
51
|
export declare const sha256: (bytes: Buffer | string) => string;
|
|
@@ -56,11 +66,61 @@ export declare function readVersioned(file: string): {
|
|
|
56
66
|
export declare const fileVersion: (file: string) => FileVersion;
|
|
57
67
|
/** Atomic same-directory replacement under a version: the file is
|
|
58
68
|
* checked at the instant before the rename and the write refused as a
|
|
59
|
-
* conflict where it no longer stands at `expected`.
|
|
60
|
-
* with `mode` exactly, the umask applying to none of it. No folder is made:
|
|
69
|
+
* conflict where it no longer stands at `expected`. No folder is made:
|
|
61
70
|
* a write whose folder is gone is refused the same way. The temporary
|
|
62
|
-
* file never outlives a refusal or a failure.
|
|
71
|
+
* file never outlives a refusal or a failure.
|
|
72
|
+
*
|
|
73
|
+
* This is an ordinary file of its folder (environments-49): it takes the
|
|
74
|
+
* folder's inherited permissions, none of them checked, and is published
|
|
75
|
+
* with `mode` exactly, else the mode the file holds, else `0644`, the
|
|
76
|
+
* umask applying to none of it. A Spex-owned file the home keeps private
|
|
77
|
+
* is written with `writePrivateVersionedBytes`. */
|
|
63
78
|
export declare function writeVersionedBytes(file: string, bytes: Buffer | string, expected: FileVersion, mode?: number): void;
|
|
79
|
+
/** `writeVersionedBytes` for a Spex-owned file, created owner-only
|
|
80
|
+
* (storage-57). */
|
|
81
|
+
export declare function writePrivateVersionedBytes(file: string, bytes: Buffer | string, expected: FileVersion): void;
|
|
82
|
+
/** Atomic same-directory replacement of an ordinary file of its folder,
|
|
83
|
+
* under no version (environments-49): the mode as `writeVersionedBytes`
|
|
84
|
+
* keeps it. No folder is made. */
|
|
85
|
+
export declare function writeWorkingBytes(file: string, bytes: Buffer | string): void;
|
|
64
86
|
/** Whether a path of a clone may leave the device: not one of the
|
|
65
|
-
* catalog's ignored families
|
|
87
|
+
* catalog's ignored families. */
|
|
66
88
|
export declare const portable: (file: string) => boolean;
|
|
89
|
+
/** Remove a file or a tree as `rmSync` with `recursive` and `force`
|
|
90
|
+
* does, read-only files included, following no link: a link or Windows
|
|
91
|
+
* junction goes itself, its target untouched (environments-7). On
|
|
92
|
+
* Windows the Node the app's Electron ships refuses read-only files in
|
|
93
|
+
* `rmSync` and empties a junction's target, so the tree is walked here
|
|
94
|
+
* with `unlinkSync`, which clears a read-only mark, and `rmdirSync`. */
|
|
95
|
+
export declare function removeTree(path: string): void;
|
|
96
|
+
/** A folder's rename refused because something holds a file or folder
|
|
97
|
+
* beneath it open: Windows refuses to rename a folder while any handle
|
|
98
|
+
* inside it stands — a watch, an open file, a process's working folder —
|
|
99
|
+
* a rule no other platform has (moveFolder). */
|
|
100
|
+
export declare class FolderInUseError extends Error {
|
|
101
|
+
readonly path: string;
|
|
102
|
+
readonly code: string | undefined;
|
|
103
|
+
constructor(path: string, cause: NodeJS.ErrnoException);
|
|
104
|
+
}
|
|
105
|
+
/** Rename a folder as `renameSync` does; where Windows refuses it with
|
|
106
|
+
* `EPERM` or `EBUSY`, which it answers while something holds a file or
|
|
107
|
+
* folder beneath it open, the refusal is a FolderInUseError, which
|
|
108
|
+
* holds on no other platform. */
|
|
109
|
+
export declare function moveFolder(from: string, to: string): void;
|
|
110
|
+
/** How often, and how far apart, a step a held folder refuses is tried
|
|
111
|
+
* again (retryWhileInUse): counted in tries, not time, so an event loop
|
|
112
|
+
* busy meanwhile spends none of them. */
|
|
113
|
+
export declare const IN_USE_RETRIES = 20;
|
|
114
|
+
export declare const IN_USE_RETRY_WAIT_MS = 50;
|
|
115
|
+
/** Run `attempt` — one step at its instant, which undoes what it did
|
|
116
|
+
* before it throws — and run it again, whole, while a folder it renames
|
|
117
|
+
* is held (FolderInUseError) or `again` takes its refusal for one worth
|
|
118
|
+
* the same, up to IN_USE_RETRIES more times IN_USE_RETRY_WAIT_MS apart,
|
|
119
|
+
* so what holds it briefly — a process finishing, a file being closed —
|
|
120
|
+
* lets go; the last refusal then stands. The first try runs at once,
|
|
121
|
+
* within its caller's step. */
|
|
122
|
+
export declare function retryWhileInUse<T>(attempt: () => T | Promise<T>, again?: (error: unknown) => boolean): Promise<T>;
|
|
123
|
+
/** `removeTree` for garbage — a stage, or what a removal set aside —
|
|
124
|
+
* whose failure is said on the console, never in place of the outcome
|
|
125
|
+
* of the work that made it. */
|
|
126
|
+
export declare function discardTree(path: string, what: string): void;
|