@fnndsc/fond 0.1.2 → 0.3.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.
@@ -0,0 +1,159 @@
1
+ /**
2
+ * @file The virtual filesystem's contracts: a mount (provider), the items it
3
+ * lists, and the options a copy takes.
4
+ *
5
+ * A session's filesystem is a tree of mounts. Each provider claims a path
6
+ * prefix and answers for everything at or under it; whatever no provider
7
+ * claims goes to the dispatcher's fallback (see `dispatcher.ts`).
8
+ *
9
+ * @module
10
+ */
11
+ import { Result } from "../result.js";
12
+ import type { VfsOutcome } from "./outcome.js";
13
+ /**
14
+ * Standard interface representing a virtual file system item.
15
+ */
16
+ export interface VFSItem {
17
+ /** The display name of the item. */
18
+ name: string;
19
+ /**
20
+ * What the item is: `dir`, `file`, `link` or `vfs` (a mount), or a kind a
21
+ * backend lists beside them. An open string: a consumer handles the kinds it
22
+ * knows and treats any other as a plain entry.
23
+ */
24
+ type: string;
25
+ /** Size in bytes. */
26
+ size: number;
27
+ /** Username of the owner. */
28
+ owner: string;
29
+ /** Creation date (ISO string). */
30
+ date: string;
31
+ /** Target path (for links). */
32
+ target?: string;
33
+ /** Version string (for plugins). */
34
+ version?: string;
35
+ /** Title or description, when the item has one. */
36
+ title?: string;
37
+ /** Backing resource ID, when the virtual entry represents one. */
38
+ id?: number;
39
+ /** Execution status (for job type items). */
40
+ status?: string;
41
+ /** Tags a backend hangs on the item, shown in a long listing as `#tag`. */
42
+ tags?: string[];
43
+ }
44
+ /**
45
+ * Options for VFS copy operations.
46
+ */
47
+ export interface CpOptions {
48
+ /** Recursively copy subdirectories. */
49
+ recursive?: boolean;
50
+ }
51
+ /**
52
+ * Base contract that every Virtual File System Provider must implement.
53
+ */
54
+ export interface VFSProvider {
55
+ /** The path prefix this provider matches (e.g. '/net/pacs', '/bin'); empty for a fallback. */
56
+ prefix: string;
57
+ /**
58
+ * Lists the contents of a directory matching this provider.
59
+ *
60
+ * @param path - The absolute virtual directory path.
61
+ * @param options - Optional sorting controls.
62
+ * @returns A Promise resolving to a Result containing VFSItems.
63
+ */
64
+ list(path: string, options?: {
65
+ sort?: "name" | "size" | "date" | "owner";
66
+ reverse?: boolean;
67
+ }): Promise<Result<VFSItem[]>>;
68
+ /**
69
+ * Copies files or folders from/to paths under this provider.
70
+ *
71
+ * @param src - The absolute source path.
72
+ * @param dest - The absolute destination path.
73
+ * @param options - Copy flags like recursive.
74
+ * @returns Done, or why not.
75
+ */
76
+ cp(src: string, dest: string, options: CpOptions): Promise<VfsOutcome>;
77
+ /**
78
+ * Reads a file whole, as text.
79
+ *
80
+ * @param path - The absolute path of the file.
81
+ * @returns Its content, or why not (`ENOENT`, `EISDIR`, ...).
82
+ */
83
+ read?(path: string): Promise<VfsOutcome<string>>;
84
+ /**
85
+ * Reads a file whole, as bytes.
86
+ *
87
+ * @param path - The absolute path of the file.
88
+ * @returns Its bytes, or why not.
89
+ */
90
+ readBinary?(path: string): Promise<VfsOutcome<Buffer>>;
91
+ /**
92
+ * Writes a file whole: its content after the write is exactly what was
93
+ * given, whether or not it existed before. Absent, the mount holds no
94
+ * writable files.
95
+ *
96
+ * @param path - The absolute path of the file.
97
+ * @param content - The new content, whole.
98
+ * @returns Done, or why not (`ENOENT` for a missing folder, `EISDIR`, ...).
99
+ */
100
+ write?(path: string, content: string | Buffer): Promise<VfsOutcome>;
101
+ /**
102
+ * Makes one folder; its parent must exist. Absent, the mount makes none.
103
+ *
104
+ * @param path - The absolute path of the new folder.
105
+ * @returns Done, or why not (`EEXIST`, `ENOENT` for a missing parent, ...).
106
+ */
107
+ mkdir?(path: string): Promise<VfsOutcome>;
108
+ /**
109
+ * Makes a folder and any missing parents in one step, for a mount whose
110
+ * store can (`mkdir -p`). Absent, `mkdir -p` makes each missing parent in
111
+ * turn.
112
+ *
113
+ * @param path - The absolute path of the folder.
114
+ * @returns Done, or why not (`EEXIST` when something is already there).
115
+ */
116
+ mkdirTree?(path: string): Promise<VfsOutcome>;
117
+ /**
118
+ * Removes an empty folder (`rmdir`).
119
+ *
120
+ * @param path - The absolute path of the folder.
121
+ * @returns Done, or why not (`ENOENT`, `ENOTDIR`, `ENOTEMPTY`, ...).
122
+ */
123
+ rmdir?(path: string): Promise<VfsOutcome>;
124
+ /**
125
+ * Renames an entry within this mount (`mv`).
126
+ *
127
+ * @param src - The absolute path now.
128
+ * @param dest - The absolute path it takes.
129
+ * @returns Done, or why not (`ENOENT`, `EEXIST` where the mount cannot replace, ...).
130
+ */
131
+ rename?(src: string, dest: string): Promise<VfsOutcome>;
132
+ /**
133
+ * Removes a file or a link (`rm`); a folder is refused with `EISDIR`.
134
+ *
135
+ * @param path - The absolute path of the entry.
136
+ * @returns Done, or why not.
137
+ */
138
+ rm?(path: string): Promise<VfsOutcome>;
139
+ /**
140
+ * Removes a folder and everything under it in one step, for a mount
141
+ * whose store can (`rm -r`). Absent, `rm -r` removes what it holds one
142
+ * entry at a time.
143
+ *
144
+ * @param path - The absolute path of the folder.
145
+ * @returns Done, or why not.
146
+ */
147
+ rmTree?(path: string): Promise<VfsOutcome>;
148
+ /**
149
+ * Resolves the target of a provider-defined lazy link when an operation
150
+ * actually follows it.
151
+ *
152
+ * Listings must not use this hook: providers may expose an unresolved link
153
+ * as structural metadata without paying for its target until navigation.
154
+ *
155
+ * @param path - Absolute virtual path naming the link.
156
+ * @returns The target path, or an error when the provider cannot resolve it.
157
+ */
158
+ linkTarget_resolve?(path: string): Promise<Result<string>>;
159
+ }
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+ /**
3
+ * @file The virtual filesystem's contracts: a mount (provider), the items it
4
+ * lists, and the options a copy takes.
5
+ *
6
+ * A session's filesystem is a tree of mounts. Each provider claims a path
7
+ * prefix and answers for everything at or under it; whatever no provider
8
+ * claims goes to the dispatcher's fallback (see `dispatcher.ts`).
9
+ *
10
+ * @module
11
+ */
12
+ Object.defineProperty(exports, "__esModule", { value: true });
13
+ //# sourceMappingURL=provider.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"provider.js","sourceRoot":"","sources":["../../src/vfs/provider.ts"],"names":[],"mappings":";AAAA;;;;;;;;;GASG"}
@@ -0,0 +1,73 @@
1
+ import { VFSItem } from './provider.js';
2
+ /** How one kind of item shows in a listing. */
3
+ export interface ItemKindLook {
4
+ /** The item type it describes. */
5
+ readonly type: string;
6
+ /** The long view's first column: `d` for a folder, `-` for a file. */
7
+ readonly mark: string;
8
+ /** Whether it holds other items: its name ends in `/`. */
9
+ readonly container?: boolean;
10
+ /**
11
+ * What the long view shows in the size column, when it is not the size
12
+ * (a job shows its status); null keeps the size.
13
+ */
14
+ readonly sizeColumn?: (item: VFSItem) => string | null;
15
+ }
16
+ /** How a listing shows: its kinds, and how a name is coloured. */
17
+ export interface ListingLook {
18
+ /** The kinds it knows; a kind not here shows as a file. */
19
+ readonly kinds: ReadonlyArray<ItemKindLook>;
20
+ /** Colours one name by its type. */
21
+ readonly name_colorize: (name: string, type: string) => string;
22
+ }
23
+ /** The kinds every listing knows. */
24
+ export declare const LISTING_CORE_KINDS: ReadonlyArray<ItemKindLook>;
25
+ /** The look of a listing with only the core's kinds and plain names. */
26
+ export declare const LISTING_LOOK_PLAIN: ListingLook;
27
+ /** The options a listing renders with. */
28
+ export interface ListingViewOptions {
29
+ /** Sizes in B, KB, MB... rather than bytes. */
30
+ human?: boolean;
31
+ /** One name per line, as `ls -1`. */
32
+ oneColumn?: boolean;
33
+ }
34
+ /**
35
+ * Formats a byte count for people.
36
+ *
37
+ * @param bytes - The count.
38
+ * @returns `0 B`, `1.5 KB`, `12 MB`...
39
+ */
40
+ export declare function size_format(bytes: number): string;
41
+ /**
42
+ * Sorts a listing's items by one field, without changing the array given.
43
+ *
44
+ * Numbers compare numerically, strings by locale; an item missing the field
45
+ * sorts after one that has it. `reverse` reverses each comparison, so items
46
+ * that compare equal keep their order (unlike {@link vfsItems_sort}, which
47
+ * reverses the sorted array).
48
+ *
49
+ * @param items - The items.
50
+ * @param sortField - The field; none leaves the order as given.
51
+ * @param reverse - Whether to sort descending.
52
+ * @returns The items, sorted.
53
+ */
54
+ export declare function listingItems_sort<T extends VFSItem>(items: T[], sortField?: string, reverse?: boolean): T[];
55
+ /**
56
+ * Renders items as `ls` does: names in as many columns as the terminal holds.
57
+ *
58
+ * @param items - The items, already sorted.
59
+ * @param options - The view options.
60
+ * @param look - The listing's look.
61
+ * @returns The grid.
62
+ */
63
+ export declare function grid_render(items: VFSItem[], options?: ListingViewOptions, look?: ListingLook): string;
64
+ /**
65
+ * Renders items as `ls -l` does: one line each, with mark, owner, size,
66
+ * date, name, and the title, tags and link target an item carries.
67
+ *
68
+ * @param items - The items, already sorted.
69
+ * @param options - The view options.
70
+ * @param look - The listing's look.
71
+ * @returns The lines.
72
+ */
73
+ export declare function long_render(items: VFSItem[], options?: ListingViewOptions, look?: ListingLook): string;
@@ -0,0 +1,203 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.LISTING_LOOK_PLAIN = exports.LISTING_CORE_KINDS = void 0;
7
+ exports.size_format = size_format;
8
+ exports.listingItems_sort = listingItems_sort;
9
+ exports.grid_render = grid_render;
10
+ exports.long_render = long_render;
11
+ /**
12
+ * @file A listing as a terminal shows it: `ls`'s grid and long views, and the
13
+ * sort they are given.
14
+ *
15
+ * The core knows four kinds of item: files, folders, links and mounts. A
16
+ * backend adds the kinds it lists (each with its long-view mark, and whether
17
+ * it is a container) and says how a name is coloured; that is the listing's
18
+ * look. A look with no colouring writes names plainly.
19
+ *
20
+ * @module
21
+ */
22
+ const chalk_1 = __importDefault(require("chalk"));
23
+ /** The kinds every listing knows. */
24
+ exports.LISTING_CORE_KINDS = [
25
+ { type: 'file', mark: '-' },
26
+ { type: 'dir', mark: 'd', container: true },
27
+ { type: 'link', mark: 'l' },
28
+ { type: 'vfs', mark: 'v' },
29
+ ];
30
+ /** The look of a listing with only the core's kinds and plain names. */
31
+ exports.LISTING_LOOK_PLAIN = {
32
+ kinds: exports.LISTING_CORE_KINDS,
33
+ name_colorize: (name) => name,
34
+ };
35
+ /**
36
+ * Formats a byte count for people.
37
+ *
38
+ * @param bytes - The count.
39
+ * @returns `0 B`, `1.5 KB`, `12 MB`...
40
+ */
41
+ function size_format(bytes) {
42
+ if (bytes === 0)
43
+ return '0 B';
44
+ const k = 1024;
45
+ const sizes = ['B', 'KB', 'MB', 'GB', 'TB'];
46
+ const i = Math.floor(Math.log(bytes) / Math.log(k));
47
+ return parseFloat((bytes / Math.pow(k, i)).toFixed(1)) + ' ' + sizes[i];
48
+ }
49
+ /**
50
+ * Sorts a listing's items by one field, without changing the array given.
51
+ *
52
+ * Numbers compare numerically, strings by locale; an item missing the field
53
+ * sorts after one that has it. `reverse` reverses each comparison, so items
54
+ * that compare equal keep their order (unlike {@link vfsItems_sort}, which
55
+ * reverses the sorted array).
56
+ *
57
+ * @param items - The items.
58
+ * @param sortField - The field; none leaves the order as given.
59
+ * @param reverse - Whether to sort descending.
60
+ * @returns The items, sorted.
61
+ */
62
+ function listingItems_sort(items, sortField, reverse = false) {
63
+ if (!sortField || items.length === 0) {
64
+ return items;
65
+ }
66
+ return [...items].sort((a, b) => {
67
+ const aVal = Reflect.get(a, sortField);
68
+ const bVal = Reflect.get(b, sortField);
69
+ if (aVal === undefined || aVal === null)
70
+ return 1;
71
+ if (bVal === undefined || bVal === null)
72
+ return -1;
73
+ let comparison;
74
+ if (typeof aVal === 'number' && typeof bVal === 'number') {
75
+ comparison = aVal - bVal;
76
+ }
77
+ else if (typeof aVal === 'string' && typeof bVal === 'string') {
78
+ comparison = aVal.localeCompare(bVal);
79
+ }
80
+ else if (aVal instanceof Date && bVal instanceof Date) {
81
+ comparison = aVal.getTime() - bVal.getTime();
82
+ }
83
+ else {
84
+ comparison = String(aVal).localeCompare(String(bVal));
85
+ }
86
+ return reverse ? -comparison : comparison;
87
+ });
88
+ }
89
+ /**
90
+ * The look of one kind.
91
+ *
92
+ * @param look - The listing's look.
93
+ * @param type - The item's type.
94
+ * @returns Its kind, or undefined for a kind the look does not know.
95
+ */
96
+ function kind_find(look, type) {
97
+ return look.kinds.find((kind) => kind.type === type);
98
+ }
99
+ /**
100
+ * One item's name as a listing shows it: coloured, and ending in `/` when
101
+ * it is a container.
102
+ *
103
+ * @param item - The item.
104
+ * @param look - The listing's look.
105
+ * @returns The name.
106
+ */
107
+ function name_format(item, look) {
108
+ const base = look.name_colorize(item.name, item.type);
109
+ return kind_find(look, item.type)?.container === true ? base + chalk_1.default.cyan.bold('/') : base;
110
+ }
111
+ /**
112
+ * A string's length on screen, its ANSI codes left out.
113
+ *
114
+ * @param str - The string.
115
+ * @returns How many columns it takes.
116
+ */
117
+ function string_lengthVisible(str) {
118
+ return str.replace(/\u001b\[[0-9;]*m/g, '').length;
119
+ }
120
+ /**
121
+ * Renders items as `ls` does: names in as many columns as the terminal holds.
122
+ *
123
+ * @param items - The items, already sorted.
124
+ * @param options - The view options.
125
+ * @param look - The listing's look.
126
+ * @returns The grid.
127
+ */
128
+ function grid_render(items, options = {}, look = exports.LISTING_LOOK_PLAIN) {
129
+ if (items.length === 0)
130
+ return '';
131
+ const formattedItems = items.map((item) => {
132
+ let str = name_format(item, look);
133
+ if (item.version)
134
+ str += chalk_1.default.dim(` (${item.version})`);
135
+ return str;
136
+ });
137
+ if (options.oneColumn) {
138
+ return formattedItems.join('\n');
139
+ }
140
+ const termWidth = process.stdout.columns || 80;
141
+ const padding = 2;
142
+ const maxLen = Math.max(...formattedItems.map(string_lengthVisible));
143
+ // Cap colWidth at termWidth so padding never causes a terminal line wrap.
144
+ const colWidth = Math.min(maxLen + padding, termWidth);
145
+ const cols = Math.max(1, Math.floor(termWidth / colWidth));
146
+ let output = '';
147
+ for (let i = 0; i < formattedItems.length; i++) {
148
+ const item = formattedItems[i];
149
+ const visibleLen = string_lengthVisible(item);
150
+ const padLen = Math.max(0, colWidth - visibleLen);
151
+ output += item + ' '.repeat(padLen);
152
+ if ((i + 1) % cols === 0) {
153
+ output += '\n';
154
+ }
155
+ }
156
+ return output.trimEnd();
157
+ }
158
+ /**
159
+ * Renders items as `ls -l` does: one line each, with mark, owner, size,
160
+ * date, name, and the title, tags and link target an item carries.
161
+ *
162
+ * @param items - The items, already sorted.
163
+ * @param options - The view options.
164
+ * @param look - The listing's look.
165
+ * @returns The lines.
166
+ */
167
+ function long_render(items, options = {}, look = exports.LISTING_LOOK_PLAIN) {
168
+ if (items.length === 0)
169
+ return '';
170
+ // Calculate max name width for alignment
171
+ const maxNameWidth = Math.max(...items.map((item) => {
172
+ const visibleLen = string_lengthVisible(name_format(item, look));
173
+ return item.version ? visibleLen + item.version.length + 3 : visibleLen;
174
+ }));
175
+ return items.map((item) => {
176
+ const kind = kind_find(look, item.type);
177
+ const typeChar = kind?.mark ?? '-';
178
+ const owner = item.owner.padEnd(10);
179
+ const column = kind?.sizeColumn?.(item) ?? null;
180
+ const sizeStr = column ?? (options.human ? size_format(item.size) : item.size.toString()).padEnd(8);
181
+ // The date as `YYYY-MM-DD HH:mm:ss`, from an ISO string.
182
+ const dateStr = item.date.replace('T', ' ').slice(0, 19);
183
+ let nameStr = name_format(item, look);
184
+ if (item.version)
185
+ nameStr += ` (${item.version})`;
186
+ // Pad name to max width for alignment
187
+ const nameVisibleLen = string_lengthVisible(nameStr);
188
+ const namePadding = ' '.repeat(Math.max(0, maxNameWidth - nameVisibleLen));
189
+ let line = `${typeChar} ${owner} ${sizeStr} ${dateStr} ${nameStr}${namePadding}`;
190
+ if (item.title) {
191
+ line += ` ${chalk_1.default.greenBright(item.title)}`;
192
+ }
193
+ // Tags, as #tags after the title.
194
+ if (item.tags !== undefined && item.tags.length > 0) {
195
+ line += ` ${chalk_1.default.cyan(item.tags.map((tag) => `#${tag}`).join(' '))}`;
196
+ }
197
+ if (item.type === 'link' && item.target) {
198
+ line += ` -> ${item.target}`;
199
+ }
200
+ return line;
201
+ }).join('\n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
8
+ * Sorts VFS items by a field (name/size/date/owner), non-destructively.
9
+ *
10
+ * Strings are compared with localeCompare, numbers numerically; mismatched or
11
+ * unsupported types are left in their original relative order.
12
+ *
13
+ * @param items - Items to sort.
14
+ * @param sortField - Field to sort by (default 'name').
15
+ * @param reverse - Whether to reverse the resulting order.
16
+ * @returns A new sorted array.
17
+ */
18
+ export declare function vfsItems_sort(items: VFSItem[], sortField?: 'name' | 'size' | 'date' | 'owner', reverse?: boolean): VFSItem[];
@@ -0,0 +1,33 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.vfsItems_sort = vfsItems_sort;
4
+ /**
5
+ * Sorts VFS items by a field (name/size/date/owner), non-destructively.
6
+ *
7
+ * Strings are compared with localeCompare, numbers numerically; mismatched or
8
+ * unsupported types are left in their original relative order.
9
+ *
10
+ * @param items - Items to sort.
11
+ * @param sortField - Field to sort by (default 'name').
12
+ * @param reverse - Whether to reverse the resulting order.
13
+ * @returns A new sorted array.
14
+ */
15
+ function vfsItems_sort(items, sortField, reverse) {
16
+ const field = sortField || 'name';
17
+ const sorted = [...items].sort((a, b) => {
18
+ const valA = a[field];
19
+ const valB = b[field];
20
+ if (typeof valA === 'string' && typeof valB === 'string') {
21
+ return valA.localeCompare(valB);
22
+ }
23
+ if (typeof valA === 'number' && typeof valB === 'number') {
24
+ return valA - valB;
25
+ }
26
+ return 0;
27
+ });
28
+ if (reverse) {
29
+ sorted.reverse();
30
+ }
31
+ return sorted;
32
+ }
33
+ //# sourceMappingURL=sort.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sort.js","sourceRoot":"","sources":["../../src/vfs/sort.ts"],"names":[],"mappings":";;AAkBA,sCAqBC;AAhCD;;;;;;;;;;GAUG;AACH,SAAgB,aAAa,CAC3B,KAAgB,EAChB,SAA8C,EAC9C,OAAiB;IAEjB,MAAM,KAAK,GAAkB,SAAS,IAAI,MAAM,CAAC;IACjD,MAAM,MAAM,GAAc,CAAC,GAAG,KAAK,CAAC,CAAC,IAAI,CAAC,CAAC,CAAU,EAAE,CAAU,EAAE,EAAE;QACnE,MAAM,IAAI,GAA2B,CAAC,CAAC,KAAK,CAAC,CAAC;QAC9C,MAAM,IAAI,GAA2B,CAAC,CAAC,KAAK,CAAC,CAAC;QAC9C,IAAI,OAAO,IAAI,KAAK,QAAQ,IAAI,OAAO,IAAI,KAAK,QAAQ,EAAE,CAAC;YACzD,OAAO,IAAI,CAAC,aAAa,CAAC,IAAI,CAAC,CAAC;QAClC,CAAC;QACD,IAAI,OAAO,IAAI,KAAK,QAAQ,IAAI,OAAO,IAAI,KAAK,QAAQ,EAAE,CAAC;YACzD,OAAO,IAAI,GAAG,IAAI,CAAC;QACrB,CAAC;QACD,OAAO,CAAC,CAAC;IACX,CAAC,CAAC,CAAC;IACH,IAAI,OAAO,EAAE,CAAC;QACZ,MAAM,CAAC,OAAO,EAAE,CAAC;IACnB,CAAC;IACD,OAAO,MAAM,CAAC;AAChB,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fnndsc/fond",
3
- "version": "0.1.2",
3
+ "version": "0.3.0",
4
4
  "description": "The pieces every layer of mise needs, whatever the backend. Depends on nothing in @fnndsc.",
5
5
  "repository": {
6
6
  "type": "git",
@@ -36,6 +36,9 @@
36
36
  ],
37
37
  "author": "Rudolph Pienaar",
38
38
  "license": "MIT",
39
+ "dependencies": {
40
+ "chalk": "^4.1.2"
41
+ },
39
42
  "devDependencies": {
40
43
  "@jest/globals": "^30.2.0",
41
44
  "@types/jest": "^30.0.0",