@crouter/api 0.3.387 → 0.3.389
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/api/__tests__/integration/client.test.js +97 -0
- package/dist/api/client.d.ts +7 -0
- package/dist/api/client.js +40 -21
- package/dist/api/dto/config.d.ts +11 -1
- package/dist/core/asset-root.d.ts +7 -0
- package/dist/core/asset-root.js +18 -0
- package/dist/core/canvas/boot-id.d.ts +6 -0
- package/dist/core/canvas/boot-id.js +26 -0
- package/dist/core/canvas/paths.d.ts +72 -0
- package/dist/core/canvas/paths.js +163 -0
- package/dist/core/canvas/pid.d.ts +391 -0
- package/dist/core/canvas/pid.js +948 -0
- package/dist/core/command-plugins/bundle.d.ts +149 -0
- package/dist/core/command-plugins/bundle.js +588 -0
- package/dist/core/command-plugins/endpoint.d.ts +24 -0
- package/dist/core/command-plugins/endpoint.js +51 -0
- package/dist/core/config.d.ts +233 -0
- package/dist/core/config.js +1120 -0
- package/dist/core/env-name.d.ts +6 -0
- package/dist/core/env-name.js +9 -0
- package/dist/core/errors.d.ts +38 -0
- package/dist/core/errors.js +90 -0
- package/dist/core/events/emit.d.ts +6 -0
- package/dist/core/events/emit.js +42 -0
- package/dist/core/events/envelope.d.ts +2 -0
- package/dist/core/events/envelope.js +84 -0
- package/dist/core/events/errors.d.ts +4 -0
- package/dist/core/events/errors.js +69 -0
- package/dist/core/events/operation-id.d.ts +4 -0
- package/dist/core/events/operation-id.js +24 -0
- package/dist/core/events/serialize.d.ts +4 -0
- package/dist/core/events/serialize.js +199 -0
- package/dist/core/events/source.d.ts +16 -0
- package/dist/core/events/source.js +31 -0
- package/dist/core/events/types.d.ts +68 -0
- package/dist/core/events/types.js +11 -0
- package/dist/core/exclusive-lock.d.ts +34 -0
- package/dist/core/exclusive-lock.js +197 -0
- package/dist/core/fs-utils.d.ts +44 -0
- package/dist/core/fs-utils.js +208 -0
- package/dist/core/help.d.ts +309 -0
- package/dist/core/help.js +406 -0
- package/dist/core/human/page-catalog.d.ts +57 -0
- package/dist/core/human/page-catalog.js +172 -0
- package/dist/core/installed-plugins.d.ts +2 -0
- package/dist/core/installed-plugins.js +79 -0
- package/dist/core/io.d.ts +122 -0
- package/dist/core/io.js +373 -0
- package/dist/core/keybindings/attach-control.d.ts +49 -0
- package/dist/core/keybindings/attach-control.js +42 -0
- package/dist/core/keybindings/catalog.d.ts +18 -0
- package/dist/core/keybindings/catalog.js +257 -0
- package/dist/core/keybindings/types.d.ts +42 -0
- package/dist/core/keybindings/types.js +1 -0
- package/dist/core/layout.d.ts +26 -0
- package/dist/core/layout.js +94 -0
- package/dist/core/locked-file.d.ts +27 -0
- package/dist/core/locked-file.js +118 -0
- package/dist/core/log.d.ts +9 -0
- package/dist/core/log.js +89 -0
- package/dist/core/manifest.d.ts +5 -0
- package/dist/core/manifest.js +15 -0
- package/dist/core/plugin-env.d.ts +8 -0
- package/dist/core/plugin-env.js +31 -0
- package/dist/core/plugin-extensions.d.ts +29 -0
- package/dist/core/plugin-extensions.js +191 -0
- package/dist/core/plugin-swap-lock.d.ts +9 -0
- package/dist/core/plugin-swap-lock.js +31 -0
- package/dist/core/preview-result-path.d.ts +4 -0
- package/dist/core/preview-result-path.js +26 -0
- package/dist/core/profiles/env-store.d.ts +22 -0
- package/dist/core/profiles/env-store.js +163 -0
- package/dist/core/profiles/fuzzy-match.d.ts +19 -0
- package/dist/core/profiles/fuzzy-match.js +92 -0
- package/dist/core/profiles/manifest.d.ts +120 -0
- package/dist/core/profiles/manifest.js +529 -0
- package/dist/core/rate-limit-scope.d.ts +25 -0
- package/dist/core/rate-limit-scope.js +64 -0
- package/dist/core/render.d.ts +12 -0
- package/dist/core/render.js +138 -0
- package/dist/core/resolver.d.ts +14 -0
- package/dist/core/resolver.js +111 -0
- package/dist/core/runtime/branded-host.d.ts +25 -0
- package/dist/core/runtime/branded-host.js +264 -0
- package/dist/core/runtime/broker/daemon-ops.d.ts +65 -0
- package/dist/core/runtime/broker/daemon-ops.js +177 -0
- package/dist/core/runtime/broker/signal-stream.d.ts +30 -0
- package/dist/core/runtime/broker/signal-stream.js +149 -0
- package/dist/core/scope.d.ts +32 -0
- package/dist/core/scope.js +184 -0
- package/dist/core/scoped-state/db.d.ts +17 -0
- package/dist/core/scoped-state/db.js +247 -0
- package/dist/core/scoped-state/migrate.d.ts +8 -0
- package/dist/core/scoped-state/migrate.js +187 -0
- package/dist/core/scoped-state/paths.d.ts +9 -0
- package/dist/core/scoped-state/paths.js +27 -0
- package/dist/core/scoped-state/profiles.d.ts +27 -0
- package/dist/core/scoped-state/profiles.js +93 -0
- package/dist/core/scoped-state/providers.d.ts +24 -0
- package/dist/core/scoped-state/providers.js +19 -0
- package/dist/core/scoped-state/schema.d.ts +6 -0
- package/dist/core/scoped-state/schema.js +43 -0
- package/dist/core/scoped-state/settings.d.ts +28 -0
- package/dist/core/scoped-state/settings.js +83 -0
- package/dist/core/spaces/open-beneath.d.ts +71 -0
- package/dist/core/spaces/open-beneath.js +581 -0
- package/dist/core/sqlite-statements.d.ts +4 -0
- package/dist/core/sqlite-statements.js +17 -0
- package/dist/core/subscription-state.d.ts +121 -0
- package/dist/core/subscription-state.js +287 -0
- package/dist/core/user-settings.d.ts +377 -0
- package/dist/core/user-settings.js +458 -0
- package/dist/daemon/broker-signals/bus.d.ts +30 -0
- package/dist/daemon/broker-signals/bus.js +87 -0
- package/dist/daemon/manage.d.ts +176 -0
- package/dist/daemon/manage.js +664 -0
- package/dist/daemon/pidfile.d.ts +8 -0
- package/dist/daemon/pidfile.js +37 -0
- package/dist/daemon/startup-policy.d.ts +1 -0
- package/dist/daemon/startup-policy.js +1 -0
- package/dist/native/linux.d.ts +29 -0
- package/dist/native/linux.js +20 -0
- package/dist/shared/env.d.ts +116 -0
- package/dist/shared/env.js +271 -0
- package/dist/shared/inbox-entry-body.d.ts +22 -0
- package/dist/shared/inbox-entry-body.js +116 -0
- package/dist/shared/working-activity.d.ts +9 -0
- package/dist/shared/working-activity.js +27 -0
- package/dist/types.d.ts +562 -0
- package/dist/types.js +186 -0
- package/package.json +1 -1
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { DatabaseSync } from 'node:sqlite';
|
|
2
|
+
export declare const SCOPED_SCHEMA_VERSION = 5;
|
|
3
|
+
export declare const PROVIDER_SCHEMA_VERSION = 1;
|
|
4
|
+
/** Adds the model-cooldown table to a provider store that predates it; a no-op (no write) once present. */
|
|
5
|
+
export declare function ensureProviderModelCooldowns(db: DatabaseSync): void;
|
|
6
|
+
export declare function createScopedSchema(db: DatabaseSync, kind: 'user' | 'project' | 'provider'): void;
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { prepared as cachedStatement } from '../sqlite-statements.js';
|
|
2
|
+
export const SCOPED_SCHEMA_VERSION = 5;
|
|
3
|
+
export const PROVIDER_SCHEMA_VERSION = 1;
|
|
4
|
+
const SCOPE_SCHEMA = `
|
|
5
|
+
CREATE TABLE scope_owners (owner_key TEXT PRIMARY KEY, kind TEXT NOT NULL CHECK(kind IN ('user','profile','project')), root TEXT NOT NULL UNIQUE, profile_id TEXT UNIQUE);
|
|
6
|
+
CREATE TABLE profiles (id TEXT PRIMARY KEY, name TEXT NOT NULL, created_at TEXT NOT NULL, last_used_at TEXT, paused_at TEXT, default_kind TEXT, grantee TEXT, metadata_json TEXT NOT NULL CHECK(json_valid(metadata_json)), delivery_limits_json TEXT NOT NULL DEFAULT '{}' CHECK(json_valid(delivery_limits_json)));
|
|
7
|
+
CREATE TABLE profile_projects (profile_id TEXT NOT NULL REFERENCES profiles(id) ON DELETE CASCADE, path TEXT NOT NULL, position INTEGER NOT NULL, PRIMARY KEY(profile_id,path), UNIQUE(profile_id,position));
|
|
8
|
+
-- Pre-canvas per-project memory caps awaiting the canvas import, which turns them into delivery_limits and deletes the rows.
|
|
9
|
+
CREATE TABLE legacy_project_caps (profile_id TEXT NOT NULL, path TEXT NOT NULL, memory TEXT NOT NULL CHECK(memory IN ('none','name','preview')), PRIMARY KEY(profile_id,path));
|
|
10
|
+
CREATE TABLE profile_defaults (directory TEXT PRIMARY KEY, profile_id TEXT NOT NULL REFERENCES profiles(id) ON DELETE CASCADE);
|
|
11
|
+
CREATE TABLE scope_settings (owner_key TEXT PRIMARY KEY REFERENCES scope_owners(owner_key), raw_json TEXT NOT NULL CHECK(json_valid(raw_json)));
|
|
12
|
+
CREATE TABLE scope_bookkeeping (owner_key TEXT PRIMARY KEY REFERENCES scope_owners(owner_key), last_self_check TEXT, active_canvas TEXT);
|
|
13
|
+
CREATE TABLE scope_marketplaces (owner_key TEXT NOT NULL REFERENCES scope_owners(owner_key), name TEXT NOT NULL, last_updated TEXT, PRIMARY KEY(owner_key,name));
|
|
14
|
+
CREATE TABLE scope_plugins (owner_key TEXT NOT NULL REFERENCES scope_owners(owner_key), name TEXT NOT NULL, last_updated TEXT, etag TEXT, checked_at TEXT, PRIMARY KEY(owner_key,name));`;
|
|
15
|
+
// A subscription 429 on one model family's window (Anthropic `seven_day_opus` /
|
|
16
|
+
// `seven_day_sonnet`) cools only that family on that account. Additive to v1: a
|
|
17
|
+
// store written before this table existed gains it on open (ensureProviderModelCooldowns),
|
|
18
|
+
// and older crtr generations sharing the store simply never read it, so the provider
|
|
19
|
+
// schema version stays 1 and a runtime rollback keeps opening the store.
|
|
20
|
+
const MODEL_COOLDOWNS_TABLE = 'CREATE TABLE IF NOT EXISTS managed_account_model_cooldowns (provider_id TEXT NOT NULL, account_id TEXT NOT NULL, family TEXT NOT NULL, rate_limited_until INTEGER NOT NULL, last_rate_limited_at INTEGER NOT NULL, PRIMARY KEY(provider_id,account_id,family));';
|
|
21
|
+
/** Adds the model-cooldown table to a provider store that predates it; a no-op (no write) once present. */
|
|
22
|
+
export function ensureProviderModelCooldowns(db) {
|
|
23
|
+
const present = db.prepare("SELECT 1 FROM sqlite_master WHERE type='table' AND name='managed_account_model_cooldowns'").get();
|
|
24
|
+
if (present === undefined)
|
|
25
|
+
db.exec(MODEL_COOLDOWNS_TABLE);
|
|
26
|
+
}
|
|
27
|
+
const PROVIDER_SCHEMA = `
|
|
28
|
+
CREATE TABLE managed_accounts (provider_id TEXT NOT NULL, id TEXT NOT NULL, label TEXT NOT NULL, label_key TEXT NOT NULL, position INTEGER NOT NULL, last_attempt_at INTEGER NOT NULL, last_rate_limited_at INTEGER NOT NULL, rate_limited_until INTEGER NOT NULL, auth_failure TEXT CHECK(auth_failure IS NULL OR auth_failure='invalid_grant'), PRIMARY KEY(provider_id,id), UNIQUE(provider_id,label_key));
|
|
29
|
+
CREATE INDEX managed_accounts_order ON managed_accounts(provider_id,position);
|
|
30
|
+
CREATE TABLE rotation_settings (singleton INTEGER PRIMARY KEY CHECK(singleton=1), default_fallback_strength TEXT, revert_when_available INTEGER CHECK(revert_when_available IN (0,1)));
|
|
31
|
+
CREATE TABLE provider_revision (singleton INTEGER PRIMARY KEY CHECK(singleton=1), revision INTEGER NOT NULL);
|
|
32
|
+
${MODEL_COOLDOWNS_TABLE}`;
|
|
33
|
+
export function createScopedSchema(db, kind) {
|
|
34
|
+
db.exec(kind === 'provider' ? PROVIDER_SCHEMA : SCOPE_SCHEMA);
|
|
35
|
+
if (kind !== 'provider') {
|
|
36
|
+
const ownerKey = kind === 'user' ? 'user' : 'project';
|
|
37
|
+
cachedStatement(db, 'INSERT INTO scope_owners(owner_key, kind, root, profile_id) VALUES (?, ?, ?, NULL)').run(ownerKey, kind, '');
|
|
38
|
+
}
|
|
39
|
+
else {
|
|
40
|
+
cachedStatement(db, 'INSERT INTO provider_revision(singleton, revision) VALUES (1, 0)').run();
|
|
41
|
+
}
|
|
42
|
+
db.exec(`PRAGMA user_version = ${kind === 'provider' ? PROVIDER_SCHEMA_VERSION : SCOPED_SCHEMA_VERSION}`);
|
|
43
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type { ScopeState } from '../../types.js';
|
|
2
|
+
import type { ScopedStore } from './paths.js';
|
|
3
|
+
export type SettingsOwner = {
|
|
4
|
+
store: ScopedStore;
|
|
5
|
+
key: string;
|
|
6
|
+
kind: 'user' | 'profile' | 'project';
|
|
7
|
+
root: string;
|
|
8
|
+
profileId?: string;
|
|
9
|
+
};
|
|
10
|
+
export declare class SettingsRevisionConflictError extends Error {
|
|
11
|
+
constructor();
|
|
12
|
+
}
|
|
13
|
+
export declare function readRawSettingsWithRevision(owner: SettingsOwner): {
|
|
14
|
+
settings: Record<string, unknown> | null;
|
|
15
|
+
revision: string;
|
|
16
|
+
};
|
|
17
|
+
export declare function readRawSettings(owner: SettingsOwner): Record<string, unknown> | null;
|
|
18
|
+
export declare function replaceRawSettings(owner: SettingsOwner, next: Record<string, unknown>, ifRevision: string, validate: (settings: Record<string, unknown>) => void): {
|
|
19
|
+
revision: string;
|
|
20
|
+
changed: boolean;
|
|
21
|
+
};
|
|
22
|
+
export declare function writeRawSettings(owner: SettingsOwner, raw: Record<string, unknown>): void;
|
|
23
|
+
export declare function mutateRawSettings<T>(owner: SettingsOwner, mutate: (current: Record<string, unknown>) => {
|
|
24
|
+
value: T;
|
|
25
|
+
next: Record<string, unknown>;
|
|
26
|
+
}): T;
|
|
27
|
+
export declare function readBookkeeping(owner: SettingsOwner): ScopeState;
|
|
28
|
+
export declare function writeBookkeeping(owner: SettingsOwner, state: ScopeState): void;
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import { prepared as cachedStatement } from '../sqlite-statements.js';
|
|
2
|
+
import { createHash } from 'node:crypto';
|
|
3
|
+
import { openScopedStore, withScopedWrite } from './db.js';
|
|
4
|
+
function ensureOwner(db, owner) {
|
|
5
|
+
const row = cachedStatement(db, 'SELECT kind, root, profile_id FROM scope_owners WHERE owner_key = ?').get(owner.key);
|
|
6
|
+
if (!row)
|
|
7
|
+
throw new Error(`scoped SQL owner is missing: ${owner.key}`);
|
|
8
|
+
if (row.kind !== owner.kind || row.root !== owner.root || (owner.profileId ?? null) !== row.profile_id) {
|
|
9
|
+
throw new Error(`scoped SQL owner does not match its root: ${owner.key}`);
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
function revisionFor(row) {
|
|
13
|
+
return row === undefined ? 'absent' : createHash('sha256').update(row.raw_json).digest('hex');
|
|
14
|
+
}
|
|
15
|
+
function readRawSettingsRow(db, owner) {
|
|
16
|
+
return cachedStatement(db, 'SELECT raw_json FROM scope_settings WHERE owner_key = ?').get(owner.key);
|
|
17
|
+
}
|
|
18
|
+
export class SettingsRevisionConflictError extends Error {
|
|
19
|
+
constructor() {
|
|
20
|
+
super('settings changed since the supplied revision');
|
|
21
|
+
this.name = 'SettingsRevisionConflictError';
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
export function readRawSettingsWithRevision(owner) {
|
|
25
|
+
const db = openScopedStore(owner.store);
|
|
26
|
+
ensureOwner(db, owner);
|
|
27
|
+
const row = readRawSettingsRow(db, owner);
|
|
28
|
+
return { revision: revisionFor(row), settings: row === undefined ? null : JSON.parse(row.raw_json) };
|
|
29
|
+
}
|
|
30
|
+
export function readRawSettings(owner) {
|
|
31
|
+
return readRawSettingsWithRevision(owner).settings;
|
|
32
|
+
}
|
|
33
|
+
export function replaceRawSettings(owner, next, ifRevision, validate) {
|
|
34
|
+
return withScopedWrite(owner.store, (db) => {
|
|
35
|
+
ensureOwner(db, owner);
|
|
36
|
+
const current = readRawSettingsRow(db, owner);
|
|
37
|
+
if (ifRevision !== revisionFor(current))
|
|
38
|
+
throw new SettingsRevisionConflictError();
|
|
39
|
+
validate(next);
|
|
40
|
+
const rawJson = JSON.stringify(next);
|
|
41
|
+
if (current?.raw_json === rawJson)
|
|
42
|
+
return { revision: revisionFor(current), changed: false };
|
|
43
|
+
cachedStatement(db, `INSERT INTO scope_settings(owner_key, raw_json) VALUES (?, ?) ON CONFLICT(owner_key) DO UPDATE SET raw_json=excluded.raw_json`).run(owner.key, rawJson);
|
|
44
|
+
return { revision: revisionFor({ raw_json: rawJson }), changed: true };
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
export function writeRawSettings(owner, raw) {
|
|
48
|
+
withScopedWrite(owner.store, (db) => {
|
|
49
|
+
ensureOwner(db, owner);
|
|
50
|
+
cachedStatement(db, `INSERT INTO scope_settings(owner_key, raw_json) VALUES (?, ?) ON CONFLICT(owner_key) DO UPDATE SET raw_json=excluded.raw_json`).run(owner.key, JSON.stringify(raw));
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
export function mutateRawSettings(owner, mutate) {
|
|
54
|
+
return withScopedWrite(owner.store, (db) => {
|
|
55
|
+
ensureOwner(db, owner);
|
|
56
|
+
const row = cachedStatement(db, 'SELECT raw_json FROM scope_settings WHERE owner_key = ?').get(owner.key);
|
|
57
|
+
const result = mutate(row ? JSON.parse(row.raw_json) : {});
|
|
58
|
+
cachedStatement(db, `INSERT INTO scope_settings(owner_key, raw_json) VALUES (?, ?) ON CONFLICT(owner_key) DO UPDATE SET raw_json=excluded.raw_json`).run(owner.key, JSON.stringify(result.next));
|
|
59
|
+
return result.value;
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
export function readBookkeeping(owner) {
|
|
63
|
+
const db = openScopedStore(owner.store);
|
|
64
|
+
ensureOwner(db, owner);
|
|
65
|
+
const bookkeeping = cachedStatement(db, 'SELECT last_self_check, active_canvas FROM scope_bookkeeping WHERE owner_key = ?').get(owner.key);
|
|
66
|
+
const marketplaces = Object.fromEntries(cachedStatement(db, 'SELECT name, last_updated FROM scope_marketplaces WHERE owner_key = ?').all(owner.key).map((row) => [row.name, row.last_updated === null ? {} : { last_updated: row.last_updated }]));
|
|
67
|
+
const plugins = Object.fromEntries(cachedStatement(db, 'SELECT name, last_updated, etag, checked_at FROM scope_plugins WHERE owner_key = ?').all(owner.key).map((row) => [row.name, { ...(row.last_updated === null ? {} : { last_updated: row.last_updated }), ...(row.etag === null ? {} : { etag: row.etag }), ...(row.checked_at === null ? {} : { checked_at: row.checked_at }) }]));
|
|
68
|
+
return { marketplaces, plugins, ...(bookkeeping?.last_self_check === null || bookkeeping === undefined ? {} : { last_self_check: bookkeeping.last_self_check }), activeCanvas: bookkeeping?.active_canvas ?? null };
|
|
69
|
+
}
|
|
70
|
+
export function writeBookkeeping(owner, state) {
|
|
71
|
+
withScopedWrite(owner.store, (db) => {
|
|
72
|
+
ensureOwner(db, owner);
|
|
73
|
+
cachedStatement(db, `INSERT INTO scope_bookkeeping(owner_key, last_self_check, active_canvas) VALUES (?, ?, ?) ON CONFLICT(owner_key) DO UPDATE SET last_self_check=excluded.last_self_check, active_canvas=excluded.active_canvas`).run(owner.key, state.last_self_check ?? null, state.activeCanvas ?? null);
|
|
74
|
+
cachedStatement(db, 'DELETE FROM scope_marketplaces WHERE owner_key = ?').run(owner.key);
|
|
75
|
+
cachedStatement(db, 'DELETE FROM scope_plugins WHERE owner_key = ?').run(owner.key);
|
|
76
|
+
const market = cachedStatement(db, 'INSERT INTO scope_marketplaces(owner_key, name, last_updated) VALUES (?, ?, ?)');
|
|
77
|
+
for (const [name, value] of Object.entries(state.marketplaces))
|
|
78
|
+
market.run(owner.key, name, value.last_updated ?? null);
|
|
79
|
+
const plugin = cachedStatement(db, 'INSERT INTO scope_plugins(owner_key, name, last_updated, etag, checked_at) VALUES (?, ?, ?, ?, ?)');
|
|
80
|
+
for (const [name, value] of Object.entries(state.plugins))
|
|
81
|
+
plugin.run(owner.key, name, value.last_updated ?? null, value.etag ?? null, value.checked_at ?? null);
|
|
82
|
+
});
|
|
83
|
+
}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { type Dirent, type Stats } from 'node:fs';
|
|
2
|
+
export declare function isBeneathRefusal(error: unknown): boolean;
|
|
3
|
+
/** Whether a beneath read failed because nothing usable is there: absent, not a
|
|
4
|
+
* directory, unreadable, or refused (see `BeneathRefusal`). */
|
|
5
|
+
export declare function isAbsentOrRefused(error: unknown): boolean;
|
|
6
|
+
/** An fd for `path` opened with `flags`, resolved beneath `root`. Never creates:
|
|
7
|
+
* `openat2` takes no mode, so a file it created would be mode 0000. On Linux
|
|
8
|
+
* the fd is a regular file or a directory, except with O_PATH, which opens
|
|
9
|
+
* nothing and is only stat'd. */
|
|
10
|
+
export declare function openBeneath(root: string, path: string, flags: number): number;
|
|
11
|
+
export declare function readFileBeneath(root: string, path: string): Buffer;
|
|
12
|
+
/** The file's text, or null when it is missing or refused. */
|
|
13
|
+
export declare function readTextBeneathIfExists(root: string, path: string): string | null;
|
|
14
|
+
export declare function statBeneath(root: string, path: string): Stats;
|
|
15
|
+
export declare function existsBeneath(root: string, path: string): boolean;
|
|
16
|
+
/** Run `fn` with `at(name)`, a pathname that reaches one entry of `dir` after
|
|
17
|
+
* `dir` itself resolved beneath `root` (`at()` is the directory). With
|
|
18
|
+
* `create`, missing directories on the way are made. */
|
|
19
|
+
export declare function withDirBeneath<T>(root: string, dir: string, fn: (at: (name?: string) => string) => T, create?: boolean): T;
|
|
20
|
+
/** Write `data` to `path` beneath `root`, making missing parents. `atomic`
|
|
21
|
+
* writes a temporary file and renames it over the target, so on Linux a
|
|
22
|
+
* symlink at the target is replaced, never followed. A Mac writes through a
|
|
23
|
+
* symlink to its target, as it always has (a dangling one fails ENOENT). */
|
|
24
|
+
export declare function writeFileBeneath(root: string, path: string, data: Buffer | string, options?: {
|
|
25
|
+
mode?: number;
|
|
26
|
+
atomic?: boolean;
|
|
27
|
+
}): void;
|
|
28
|
+
/** Create `path` beneath `root` only if absent (`wx`), making missing parents. */
|
|
29
|
+
export declare function createFileBeneath(root: string, path: string, data: Buffer | string, mode?: number): void;
|
|
30
|
+
export declare function appendFileBeneath(root: string, path: string, data: string): void;
|
|
31
|
+
export declare function unlinkBeneath(root: string, path: string): void;
|
|
32
|
+
export declare function rmdirBeneath(root: string, path: string): void;
|
|
33
|
+
export declare function renameBeneath(root: string, from: string, to: string): void;
|
|
34
|
+
/** link(2) without replacement: fails if `to` exists. */
|
|
35
|
+
export declare function linkBeneath(root: string, from: string, to: string): void;
|
|
36
|
+
export declare function fsyncDirBeneath(root: string, dir: string): void;
|
|
37
|
+
/** Directory entries typed by the directory itself (a symlink stays a symlink). */
|
|
38
|
+
export declare function readdirBeneath(root: string, dir: string): Dirent[];
|
|
39
|
+
/** The first `limit` entries by name, each with its own (unfollowed on Linux)
|
|
40
|
+
* stat; an entry removed before its stat is left out. */
|
|
41
|
+
export declare function listBeneath(root: string, dir: string, limit: number): Array<{
|
|
42
|
+
name: string;
|
|
43
|
+
stat: Stats;
|
|
44
|
+
}>;
|
|
45
|
+
/** Regular files under `dir` matching `predicate`, never descending a symlink. */
|
|
46
|
+
export declare function walkFilesBeneath(root: string, dir: string, predicate?: (name: string) => boolean, skipDir?: (name: string) => boolean): string[];
|
|
47
|
+
/** Copy the entries of `from` (beneath `fromRoot`) into `to` (beneath
|
|
48
|
+
* `toRoot`): directories and regular files with their permission bits, and
|
|
49
|
+
* symlinks as links, never followed. Any other entry, any entry removed or
|
|
50
|
+
* refused after the directory was read, and any top-level name in `skip`, is
|
|
51
|
+
* left out. A name `to` already holds is overwritten, except by a symlink. */
|
|
52
|
+
export declare function copyTreeBeneath(fromRoot: string, from: string, toRoot: string, to: string, skip?: ReadonlySet<string>): void;
|
|
53
|
+
/** Set the mode (and, with `owner`, the owner) of the file or directory at
|
|
54
|
+
* `path` beneath `root` through an fd opened without following a symlink. A
|
|
55
|
+
* Mac sets them by pathname, as it always has. */
|
|
56
|
+
export declare function setModeBeneath(root: string, path: string, mode: number, owner?: {
|
|
57
|
+
uid: number;
|
|
58
|
+
gid: number;
|
|
59
|
+
}): void;
|
|
60
|
+
/** Remove the tree at `path` beneath `root`, never descending a symlink: a
|
|
61
|
+
* symlink at `path` or inside it is unlinked itself. Absent is not an error.
|
|
62
|
+
* On Linux the walk holds one directory fd per level and opens each child
|
|
63
|
+
* relative to its parent, so a deep tree costs one open per entry. */
|
|
64
|
+
export declare function removeTreeBeneath(root: string, path: string): void;
|
|
65
|
+
/** A pathname that connects to the unix socket at `path` beneath `root`
|
|
66
|
+
* without following a symlink, and `release`, to call once the connect has
|
|
67
|
+
* settled. On Linux it is the magic link of an O_PATH fd held until release. */
|
|
68
|
+
export declare function socketBeneath(root: string, path: string): {
|
|
69
|
+
path: string;
|
|
70
|
+
release: () => void;
|
|
71
|
+
};
|