Skip to content

Commit 8a0dbf9

Browse files
committed
Add dirs
1 parent 1dbc0db commit 8a0dbf9

File tree

4 files changed

+96
-5
lines changed

4 files changed

+96
-5
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,11 @@
11
module SkipRuntime;
2+
3+
@export("SkipRuntime_Debug__dirs")
4+
fun dirs(): SKJSON.CJSON {
5+
SKStore.runWithResult(contextDirs) match {
6+
| Success(result) -> SKJSON.CJArray(result)
7+
| Failure(err) -> SKJSON.CJFloat(getErrorHdl(err))
8+
}
9+
}
10+
211
module end;
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,46 @@
11
module SkipRuntime;
2+
3+
private fun dirInfo(
4+
dirNameDir: readonly (SKStore.DirName, SKStore.Dir),
5+
): SKJSON.CJSON {
6+
(dirName, dir) = dirNameDir;
7+
fields = mutable Vector<(.String, SKJSON.CJSON)>[];
8+
fields.push(("name", SKJSON.CJString(dirName.toString())));
9+
fields.push(("isInput", SKJSON.CJBool(dir.isInput())));
10+
fields.push(("time", SKJSON.CJInt(dir.getTime().value)));
11+
dir match {
12+
| SKStore.EagerDir{totalSize, creator} ->
13+
fields.push(("kind", SKJSON.CJString("eager")));
14+
fields.push(("totalSize", SKJSON.CJInt(totalSize)));
15+
creator match {
16+
| None() -> void
17+
| Some(SKStore.ArrowKey(parentName, childName, key)) ->
18+
fields.push(
19+
(
20+
"creator",
21+
SKJSON.CJObject(
22+
SKJSON.CJFields::create(
23+
Array[
24+
("key", SKJSON.CJString(key.toString())),
25+
("parent", SKJSON.CJString(parentName.toString())),
26+
("child", SKJSON.CJString(childName.toString())),
27+
],
28+
x -> x,
29+
),
30+
),
31+
),
32+
)
33+
}
34+
| SKStore.LazyDir _ -> fields.push(("kind", SKJSON.CJString("lazy")))
35+
| SKStore.DeletedDir _ -> fields.push(("kind", SKJSON.CJString("deleted")))
36+
};
37+
SKJSON.CJObject(SKJSON.CJFields::create(fields.toArray(), x -> x))
38+
}
39+
40+
private fun contextDirs(
41+
context: readonly SKStore.Context,
42+
): Array<SKJSON.CJSON> {
43+
context.dirs.state.items().map(dirInfo).collect(Array)
44+
}
45+
246
module end;

skipruntime-ts/server/src/restDebugging.ts

+12-2
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,21 @@ import { DebuggingServiceInstance, type ServiceInstance } from "skip-wasm";
44
export function debuggingService(
55
baseService: ServiceInstance,
66
): express.Express {
7-
// @ts-expect-error error TS6133: '_service' is declared but its value is never read.
8-
const _service = new DebuggingServiceInstance(baseService);
7+
const service = new DebuggingServiceInstance(baseService);
98

109
const app = express();
1110
app.use(express.json());
1211

12+
// LOW-LEVEL
13+
app.get("/v1/debug/raw/dirs", (_req, res) => {
14+
try {
15+
const result = service.dirs();
16+
res.status(200).json(result);
17+
} catch (e: unknown) {
18+
console.log(e);
19+
res.status(500).json(e instanceof Error ? e.message : e);
20+
}
21+
});
22+
1323
return app;
1424
}
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,34 @@
1+
import type { int, ptr, ErrorObject } from "@skip-wasm/std";
2+
import type * as Internal from "./skipruntime_internal_types.js";
3+
import type { Handle } from "./skipruntime_module.js";
14
import { ServiceInstance } from "./skipruntime_module.js";
25

3-
// eslint-disable-next-line @typescript-eslint/no-empty-object-type
4-
export interface FromWasm {}
6+
export interface FromWasm {
7+
SkipRuntime_Debug__dirs(): ptr<
8+
Internal.CJFloat | Internal.CJArray<Internal.CJObject>
9+
>;
10+
}
511

6-
export class DebuggingServiceInstance extends ServiceInstance {}
12+
type DirList = ({ name: string; isInput: boolean; time: int } & (
13+
| {
14+
kind: "eager";
15+
totalSize: int;
16+
creator?: { parent: string; child: string; key: string };
17+
}
18+
| { kind: "lazy" }
19+
| { kind: "deleted" }
20+
))[];
21+
22+
export class DebuggingServiceInstance extends ServiceInstance {
23+
dirs(): DirList {
24+
const result = this.refs.skjson.runWithGC(() => {
25+
return this.refs.skjson.importJSON(
26+
this.refs.fromWasm.SkipRuntime_Debug__dirs(),
27+
);
28+
});
29+
if (typeof result == "number") {
30+
throw this.refs.handles.deleteAsError(result as Handle<ErrorObject>);
31+
}
32+
return result as DirList;
33+
}
34+
}

0 commit comments

Comments
 (0)