Skip to content

Commit 8d3dc4c

Browse files
committed
Refactor, cleanup
1 parent b942eba commit 8d3dc4c

File tree

120 files changed

+1141
-1103
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

120 files changed

+1141
-1103
lines changed

build_web.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ export async function copyAssets(dist: string) {
7979
bundleJs = patchDenoLibJS(bundleJs);
8080
await Deno.writeTextFile(`${dist}/client.js`, bundleJs);
8181
}
82+
8283
async function buildCopyBundleAssets() {
8384
await Deno.mkdir("dist_client_bundle", { recursive: true });
8485
await Deno.mkdir("dist_plug_bundle", { recursive: true });

cmd/compile.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,7 @@ export async function compileManifests(
145145
) {
146146
let building = false;
147147
dist = path.resolve(dist);
148+
148149
async function buildAll() {
149150
if (building) {
150151
return;

cmd/test/runtime.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import { createSandbox } from "../../lib/plugos/sandboxes/deno_worker_sandbox.ts";
2+
import type { SysCallMapping } from "../../lib/plugos/system.ts";
23
import { System } from "../../lib/plugos/system.ts";
34
import { assertEquals } from "@std/assert";
45
import { compileManifest } from "../compile.ts";
56
import * as esbuild from "esbuild";
6-
import type { SysCallMapping } from "../../lib/plugos/system.ts";
77
import { fileURLToPath } from "node:url";
88

99
Deno.test("Run a deno sandbox", {

deno.json

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -31,30 +31,23 @@
3131
"tasks": {
3232
"clean": "rm -rf dist dist_client_bundle dist_plug_bundle",
3333
"deep-clean-mac": "rm -f deno.lock && rm -rf $HOME/Library/Caches/deno && deno task clean",
34-
3534
"install": "deno install -g -f -A --import-map deno.json silverbullet.ts",
36-
3735
"check": "find . -name '*.ts*' | xargs deno check",
3836
"lint": "deno lint",
3937
"fmt": "deno fmt",
4038
"test": "deno test -A",
4139
"bench": "deno bench",
42-
4340
"build": "rm -rf dist dist_client_bundle dist_plug_bundle && deno run -A build_plugs.ts && deno run -A build_web.ts && deno task compile",
4441
"plugs": "deno run -A build_plugs.ts",
4542
"server": "deno run -A --check silverbullet.ts",
4643
"generate": "./scripts/generate.sh",
4744
"docker": "./scripts/build_docker.sh",
48-
4945
"watch-web": "deno run -A --check build_web.ts --watch",
5046
"watch-server": "deno run -A --check --watch silverbullet.ts",
5147
"watch-plugs": "deno run -A --check build_plugs.ts -w",
5248
"watch-all": "deno task watch-web & deno task watch-plugs & deno task watch-server",
53-
5449
"bundle": "deno run -A build_bundle.ts",
55-
5650
"compile": "deno task bundle && deno compile -A -o silverbullet dist/silverbullet.js",
57-
5851
"server:dist:linux-x86_64": "deno task bundle && deno compile -A --target x86_64-unknown-linux-gnu -o silverbullet dist/silverbullet.js",
5952
"server:zip:linux-x86_64": "deno task server:dist:linux-x86_64 && zip silverbullet-server-linux-x86_64.zip silverbullet",
6053
"server:dist:linux-aarch64": "deno task bundle && deno compile -A --target aarch64-unknown-linux-gnu -o silverbullet dist/silverbullet.js",
@@ -75,7 +68,11 @@
7568
"cmd/test/test_space"
7669
],
7770
"rules": {
78-
"exclude": ["no-explicit-any", "no-slow-types", "jsx-boolean-value"]
71+
"exclude": [
72+
"no-explicit-any",
73+
"no-slow-types",
74+
"jsx-boolean-value"
75+
]
7976
}
8077
},
8178
"fmt": {
@@ -90,7 +87,12 @@
9087
]
9188
},
9289
"compilerOptions": {
93-
"lib": ["dom", "dom.iterable", "dom.asynciterable", "deno.ns"],
90+
"lib": [
91+
"dom",
92+
"dom.iterable",
93+
"dom.asynciterable",
94+
"deno.ns"
95+
],
9496
"jsx": "react-jsx",
9597
"jsxImportSource": "https://esm.sh/preact@10.26.4"
9698
},

lib/README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
This folder contains library functions that is generally reusable, not specific to SilverBullet. This code can be used from within plugs or the core code base. It may move out of this repo at some point.
1+
This folder contains library functions that is generally reusable, not specific to SilverBullet. This code can be used
2+
from within plugs or the core code base. It may move out of this repo at some point.

lib/data/datastore.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ import type { KvPrimitives } from "../data/kv_primitives.ts";
55
import { assertEquals } from "@std/assert";
66
import { PrefixedKvPrimitives } from "../data/prefixed_kv_primitives.ts";
77
import { DataStore } from "$lib/data/datastore.ts";
8-
import { LuaEnv, LuaStackFrame } from "../../web/space_lua/runtime.ts";
9-
import { parseExpressionString } from "../../web/space_lua/parse.ts";
8+
import { LuaEnv, LuaStackFrame } from "../space_lua/runtime.ts";
9+
import { parseExpressionString } from "../space_lua/parse.ts";
1010

1111
async function test(db: KvPrimitives) {
1212
const datastore = new DataStore(new PrefixedKvPrimitives(db, ["ds"]));

lib/data/datastore.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import {
22
type LuaCollectionQuery,
33
queryLua,
4-
} from "../../web/space_lua/query_collection.ts";
5-
import { LuaEnv, LuaStackFrame } from "../../web/space_lua/runtime.ts";
4+
} from "../space_lua/query_collection.ts";
5+
import { LuaEnv, LuaStackFrame } from "../space_lua/runtime.ts";
66
import type { KV, KvKey } from "../../plug-api/types.ts";
77
import type { KvPrimitives, KvQueryOptions } from "./kv_primitives.ts";
88

lib/data/indexeddb_kv_primitives.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,10 @@ export class IndexedDBKvPrimitives implements KvPrimitives {
7575
}
7676
}
7777

78+
close() {
79+
this.db.close();
80+
}
81+
7882
private buildKey(key: KvKey): string {
7983
for (const k of key) {
8084
if (k.includes(sep)) {
@@ -87,8 +91,4 @@ export class IndexedDBKvPrimitives implements KvPrimitives {
8791
private extractKey(key: string): KvKey {
8892
return key.split(sep);
8993
}
90-
91-
close() {
92-
this.db.close();
93-
}
9494
}

lib/data/kv_primitives.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,15 @@ export type KvQueryOptions = {
66

77
export interface KvPrimitives {
88
batchGet(keys: KvKey[]): Promise<(any | undefined)[]>;
9+
910
batchSet(entries: KV[]): Promise<void>;
11+
1012
batchDelete(keys: KvKey[]): Promise<void>;
13+
1114
query(options: KvQueryOptions): AsyncIterableIterator<KV>;
15+
1216
// Completely clear all data from this datastore
1317
clear(): Promise<void>;
18+
1419
close(): void;
1520
}

lib/data/memory_kv_primitives.ts

Lines changed: 34 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,27 @@ export class MemoryKvPrimitives implements KvPrimitives {
2828
}
2929
}
3030
}
31+
32+
static fromJSON(json: Record<string, any>): MemoryKvPrimitives {
33+
const result = new MemoryKvPrimitives();
34+
for (const key of Object.keys(json)) {
35+
result.store.set(key, json[key]);
36+
}
37+
return result;
38+
}
39+
40+
/**
41+
* Create a new MemoryKvPrimitives instance from a file and initialize it
42+
*/
43+
static async fromFile(
44+
filePath: string,
45+
options: { throttleMs?: number } = {},
46+
): Promise<MemoryKvPrimitives> {
47+
const instance = new MemoryKvPrimitives(filePath, options);
48+
await instance.init();
49+
return instance;
50+
}
51+
3152
clear(): Promise<void> {
3253
this.store.clear();
3354
return Promise.resolve();
@@ -62,23 +83,6 @@ export class MemoryKvPrimitives implements KvPrimitives {
6283
}
6384
}
6485

65-
/**
66-
* Persist the current state to disk
67-
*/
68-
private async persistToDisk(): Promise<void> {
69-
if (!this.filePath) return;
70-
71-
try {
72-
const jsonData = this.toJSON();
73-
await Deno.writeTextFile(
74-
this.filePath,
75-
JSON.stringify(jsonData, null, 2),
76-
);
77-
} catch (error) {
78-
console.error(`Failed to persist KV store to ${this.filePath}:`, error);
79-
}
80-
}
81-
8286
batchGet(keys: KvKey[]): Promise<any[]> {
8387
return Promise.resolve(
8488
keys.map((key) => this.store.get(key.join(memoryKeySeparator))),
@@ -125,14 +129,6 @@ export class MemoryKvPrimitives implements KvPrimitives {
125129
return result;
126130
}
127131

128-
static fromJSON(json: Record<string, any>): MemoryKvPrimitives {
129-
const result = new MemoryKvPrimitives();
130-
for (const key of Object.keys(json)) {
131-
result.store.set(key, json[key]);
132-
}
133-
return result;
134-
}
135-
136132
async *query(options: KvQueryOptions): AsyncIterableIterator<KV> {
137133
const prefix = options.prefix?.join(memoryKeySeparator);
138134
const sortedKeys = [...this.store.keys()].sort();
@@ -155,14 +151,19 @@ export class MemoryKvPrimitives implements KvPrimitives {
155151
}
156152

157153
/**
158-
* Create a new MemoryKvPrimitives instance from a file and initialize it
154+
* Persist the current state to disk
159155
*/
160-
static async fromFile(
161-
filePath: string,
162-
options: { throttleMs?: number } = {},
163-
): Promise<MemoryKvPrimitives> {
164-
const instance = new MemoryKvPrimitives(filePath, options);
165-
await instance.init();
166-
return instance;
156+
private async persistToDisk(): Promise<void> {
157+
if (!this.filePath) return;
158+
159+
try {
160+
const jsonData = this.toJSON();
161+
await Deno.writeTextFile(
162+
this.filePath,
163+
JSON.stringify(jsonData, null, 2),
164+
);
165+
} catch (error) {
166+
console.error(`Failed to persist KV store to ${this.filePath}:`, error);
167+
}
167168
}
168169
}

0 commit comments

Comments
 (0)