shell work, json deserializer working, not fully tested but should produce a correct base map

This commit is contained in:
2026-08-12 11:01:07 +02:00
parent 0149937526
commit 3ec3de71f4
8 changed files with 164 additions and 13 deletions
+23 -11
View File
@@ -8,6 +8,9 @@
"name": "termos", "name": "termos",
"version": "1.0.0", "version": "1.0.0",
"license": "ISC", "license": "ISC",
"dependencies": {
"zod": "^4.4.3"
},
"devDependencies": { "devDependencies": {
"@eslint/js": "^10.0.1", "@eslint/js": "^10.0.1",
"@types/node": "^26.1.0", "@types/node": "^26.1.0",
@@ -1494,16 +1497,16 @@
} }
}, },
"node_modules/brace-expansion": { "node_modules/brace-expansion": {
"version": "5.0.7", "version": "5.0.9",
"resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-5.0.7.tgz", "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-5.0.9.tgz",
"integrity": "sha512-7oFy703dxfY3/NLxC1fh2SUCQ0H9rmAY+5EpDVfXjUTTs+HEwR2nYaqLv+GWcTsumwxPfiz6CzCNkwXwBUwqCA==", "integrity": "sha512-ScQ4IuvIEF1TMlP7Zt+vjJ//9zlPb2SDcxWxM3bk8s6t6GGdJ7KO1dCcTidOPJKePW30LE/2cT7wCyPho9/Wxg==",
"dev": true, "dev": true,
"license": "MIT", "license": "MIT",
"dependencies": { "dependencies": {
"balanced-match": "^4.0.2" "balanced-match": "^4.0.2"
}, },
"engines": { "engines": {
"node": "18 || 20 || >=22" "node": "20 || >=22"
} }
}, },
"node_modules/chai": { "node_modules/chai": {
@@ -2493,9 +2496,9 @@
"license": "MIT" "license": "MIT"
}, },
"node_modules/nanoid": { "node_modules/nanoid": {
"version": "3.3.15", "version": "3.3.18",
"resolved": "https://registry.npmjs.org/nanoid/-/nanoid-3.3.15.tgz", "resolved": "https://registry.npmjs.org/nanoid/-/nanoid-3.3.18.tgz",
"integrity": "sha512-y7Wygv/7mEOvxTuEQDB8StXdMRBWf1kR/tlhAzBRUFkB2jfcLOAxO/SHmOO2zgz1pVgK29/kyupn059/bCHdjA==", "integrity": "sha512-DTg4MJbGMWkfi6VZFdNt2/caMbQy4Ou+Op/hJQvGEWcnVfoA1QA+xzRKAzw9jD6+GVOOeYr/mIcuDSdug6F6+w==",
"dev": true, "dev": true,
"funding": [ "funding": [
{ {
@@ -2630,9 +2633,9 @@
} }
}, },
"node_modules/postcss": { "node_modules/postcss": {
"version": "8.5.16", "version": "8.5.26",
"resolved": "https://registry.npmjs.org/postcss/-/postcss-8.5.16.tgz", "resolved": "https://registry.npmjs.org/postcss/-/postcss-8.5.26.tgz",
"integrity": "sha512-vuwillviilfKZsg0VGj5R/YwwcHx4SLsIOI/7K6mQkWx+l5cUHTjj5g0AasTBcyXsbfTgrwsUNmVUb5xVwyPwg==", "integrity": "sha512-u82N74LFzG8ca+dD8puPnplTXoGH4fTPpVGuIbt36G3qvNlkvfD0lEAZSxaly3KX8TS/L1A1gsCEmvKmBcVbkQ==",
"dev": true, "dev": true,
"funding": [ "funding": [
{ {
@@ -2650,7 +2653,7 @@
], ],
"license": "MIT", "license": "MIT",
"dependencies": { "dependencies": {
"nanoid": "^3.3.12", "nanoid": "^3.3.17",
"picocolors": "^1.1.1", "picocolors": "^1.1.1",
"source-map-js": "^1.2.1" "source-map-js": "^1.2.1"
}, },
@@ -3260,6 +3263,15 @@
"funding": { "funding": {
"url": "https://github.com/sponsors/sindresorhus" "url": "https://github.com/sponsors/sindresorhus"
} }
},
"node_modules/zod": {
"version": "4.4.3",
"resolved": "https://registry.npmjs.org/zod/-/zod-4.4.3.tgz",
"integrity": "sha512-ytENFjIJFl2UwYglde2jchW2Hwm4GJFLDiSXWdTrJQBIN9Fcyp7n4DhxJEiWNAJMV1/BqWfW/kkg71UDcHJyTQ==",
"license": "MIT",
"funding": {
"url": "https://github.com/sponsors/colinhacks"
}
} }
} }
} }
+3
View File
@@ -26,5 +26,8 @@
"typescript-eslint": "^8.63.0", "typescript-eslint": "^8.63.0",
"vite-tsconfig-paths": "^6.1.1", "vite-tsconfig-paths": "^6.1.1",
"vitest": "^4.1.10" "vitest": "^4.1.10"
},
"dependencies": {
"zod": "^4.4.3"
} }
} }
+9
View File
@@ -0,0 +1,9 @@
export interface TermosConfig {
serverAddress: string;
dbName: string;
}
export const defaultConfig: TermosConfig = {
serverAddress: "",
dbName: "termos",
};
+13
View File
@@ -1,2 +1,15 @@
import { defaultConfig, TermosConfig } from "./config";
let config: TermosConfig = { ...defaultConfig };
namespace Termos {
export function init(config: Partial<TermosConfig>) {
config = { ...defaultConfig, ...config};
console.log("termos initialized");
}
}
const message: string = "Hello, World!"; const message: string = "Hello, World!";
console.log(message); console.log(message);
export { Termos };
+12
View File
@@ -3,3 +3,15 @@
To do that, implement a termos config that will contain the table and db names, aswell as other relevant information - To do that, implement a termos config that will contain the table and db names, aswell as other relevant information -
maybe a flag for headless mode (uses the built-in console frontend module - need to evaluate this idea more) maybe a flag for headless mode (uses the built-in console frontend module - need to evaluate this idea more)
*/ */
export async fetchFileSystem(): Promise<JSON> {
}
export async fetchUserGroups(): Promise<JSON> {
}
export async fetchUsers(): Promise<JSON> {
}
+88
View File
@@ -0,0 +1,88 @@
import { createImmutableBuffer } from "@core/util/immutable_buffer";
import { z } from "zod";
import { TreeNodeType, type DirectoryNode, type FileNode, type TreeNode } from "../core/filesystem/treenode";
const FileNodeSchema = z.object({
inode: z.number(),
name: z.string(),
mode: z.number(),
parent: z.number(),
owner: z.number(),
group: z.number(),
mtime: z.number(),
ctime: z.number(),
atime: z.number(),
type: z.literal("regular"),
content: z.array(z.number()),
});
const DirectoryNodeSchema = z.object({
inode: z.number(),
name: z.string(),
mode: z.number(),
parent: z.number(),
owner: z.number(),
group: z.number(),
mtime: z.number(),
ctime: z.number(),
atime: z.number(),
type: z.literal("directory"),
children: z.array(z.lazy((): any => TreeNodeSchema)),
});
const TreeNodeSchema = z.union([FileNodeSchema, DirectoryNodeSchema]);
export function serializeFileSystem() {}
export function deserializeFileSystem(json: string): ReadonlyMap<number, TreeNode> {
const raw = JSON.parse(json);
const validated = TreeNodeSchema.parse(raw);
const map = new Map<number, TreeNode>();
function parseNode(tree: any, parent: number): void {
if (tree.type === "directory") {
const children: Record<string, number> = {};
for (const child of tree.children) {
parseNode(child, tree.inode);
children[child.name] = child.inode;
}
const directoryNode: DirectoryNode = {
type: TreeNodeType.Directory,
inode: tree.inode,
name: tree.name,
parent,
mode: tree.mode,
owner: tree.owner,
group: tree.group,
mtime: tree.mtime,
ctime: tree.ctime,
atime: tree.atime,
children,
};
map.set(tree.inode, Object.freeze(directoryNode));
} else {
const fileNode: FileNode = {
type: TreeNodeType.File,
inode: tree.inode,
name: tree.name,
parent,
mode: tree.mode,
owner: tree.owner,
group: tree.group,
mtime: tree.mtime,
ctime: tree.ctime,
atime: tree.atime,
content: createImmutableBuffer(new Uint8Array()),
};
map.set(tree.inode, Object.freeze(fileNode));
}
}
parseNode(validated, validated.inode);
const base: ReadonlyMap<number, TreeNode> = map;
return base;
}
+7 -2
View File
@@ -1,5 +1,6 @@
import { FileSystem } from "@core/filesystem/filesystem";
import type { Result } from "@core/result"; import type { Result } from "@core/result";
import { type ShellState } from "@core/shell_state"; import { createInitialShellState, type ShellState } from "@core/shell_state";
import type { ShellError } from "@core/util/errors"; import type { ShellError } from "@core/util/errors";
export class Shell { export class Shell {
@@ -19,7 +20,11 @@ export class Shell {
if (Shell.#promise) return Shell.#promise; if (Shell.#promise) return Shell.#promise;
const state; //Create initial shell state, const fs = FileSystem.init()
const users =
const sessionStack =
const state: ShellState = createInitialShellState(); //Create initial shell state,
Shell.#promise = (async () => { Shell.#promise = (async () => {
try { try {
+9
View File
@@ -0,0 +1,9 @@
import { deserializeFileSystem } from "@shell/serializer";
import { test } from "vitest";
const rawJson = `{"atime": 1786341244,"children": [{"atime": 1786341264,"children": [{"atime": 1786341330,"children": [],"content": null,"ctime": 1786341330,"group": 1000,"inode": 2,"mode": 493,"mtime": 1786341330,"name": "subdir1","owner": 1000,"parent": 1,"type": "directory"}],"content": null,"ctime": 1786341330,"group": 1000,"inode": 1,"mode": 493,"mtime": 1786341330,"name": "folder1","owner": 1000,"parent": 0,"type": "directory"},{"atime": 1786341269,"children": [{"atime": 1786341344,"children": [],"content": null,"ctime": 1786341344,"group": 1000,"inode": 4,"mode": 493,"mtime": 1786341344,"name": "subdir2","owner": 1000,"parent": 3,"type": "directory"},{"atime": 1786341345,"children": [{"atime": 1786341356,"children": [],"content": [],"ctime": 1786341356,"group": 1000,"inode": 6,"mode": 420,"mtime": 1786341356,"name": "empty-foo","owner": 1000,"parent": 5,"type": "regular"}],"content": null,"ctime": 1786341356,"group": 1000,"inode": 5,"mode": 493,"mtime": 1786341356,"name": "subdir3","owner": 1000,"parent": 3,"type": "directory"}],"content": null,"ctime": 1786341345,"group": 1000,"inode": 3,"mode": 493,"mtime": 1786341345,"name": "folder2","owner": 1000,"parent": 0,"type": "directory"},{"atime": 1786341312,"children": [],"content": [72,101,108,108,111,44,32,87,111,114,108,100,33,10],"ctime": 1786341312,"group": 1000,"inode": 7,"mode": 420,"mtime": 1786341312,"name": "some-file","owner": 1000,"parent": 0,"type": "regular"}],"content": null,"ctime": 1786341312,"group": 1000,"inode": 0,"mode": 493,"mtime": 1786341312,"name": "root","owner": 1000,"parent": 0,"type": "directory"}`;
test("deserialize json into the correct tree structure", () => {
const base = deserializeFileSystem(rawJson);
console.log(base);
});