SilverBullet pivot to become an offline-first PWA (#403)
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import type { FilterOption } from "../../web/types.ts";
|
||||
import { syscall } from "./syscall.ts";
|
||||
import { FilterOption } from "../../common/types.ts";
|
||||
|
||||
export function getCurrentPage(): Promise<string> {
|
||||
return syscall("editor.getCurrentPage");
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
export * as clientStore from "./clientStore.ts";
|
||||
export * as editor from "./editor.ts";
|
||||
export * as index from "./index.ts";
|
||||
export * as markdown from "./markdown.ts";
|
||||
export * as sandbox from "./sandbox.ts";
|
||||
export { default as space } from "./space.ts";
|
||||
export * as space from "./space.ts";
|
||||
export * as system from "./system.ts";
|
||||
export * as collab from "./collab.ts";
|
||||
// Legacy redirect, use "store" in $sb/plugos-syscall/mod.ts instead
|
||||
export * as clientStore from "./store.ts";
|
||||
export * as sync from "./sync.ts";
|
||||
|
||||
@@ -1,5 +0,0 @@
|
||||
import type { LogEntry } from "../../plugos/sandbox.ts";
|
||||
|
||||
export function getServerLogs(): Promise<LogEntry[]> {
|
||||
return syscall("sandbox.getServerLogs");
|
||||
}
|
||||
@@ -1,98 +1,70 @@
|
||||
import { syscall } from "./syscall.ts";
|
||||
import { AttachmentMeta, PageMeta } from "../../common/types.ts";
|
||||
import { FileMeta, ProxyFileSystem } from "../plugos-syscall/types.ts";
|
||||
import type { AttachmentMeta, PageMeta } from "../../web/types.ts";
|
||||
|
||||
export class SpaceFileSystem implements ProxyFileSystem {
|
||||
// More space-specific methods
|
||||
|
||||
listPages(unfiltered = false): Promise<PageMeta[]> {
|
||||
return syscall("space.listPages", unfiltered);
|
||||
}
|
||||
|
||||
getPageMeta(name: string): Promise<PageMeta> {
|
||||
return syscall("space.getPageMeta", name);
|
||||
}
|
||||
|
||||
readPage(
|
||||
name: string,
|
||||
): Promise<string> {
|
||||
return syscall("space.readPage", name);
|
||||
}
|
||||
|
||||
writePage(name: string, text: string): Promise<PageMeta> {
|
||||
return syscall("space.writePage", name, text);
|
||||
}
|
||||
|
||||
deletePage(name: string): Promise<void> {
|
||||
return syscall("space.deletePage", name);
|
||||
}
|
||||
|
||||
listPlugs(): Promise<string[]> {
|
||||
return syscall("space.listPlugs");
|
||||
}
|
||||
|
||||
listAttachments(): Promise<PageMeta[]> {
|
||||
return syscall("space.listAttachments");
|
||||
}
|
||||
|
||||
getAttachmentMeta(name: string): Promise<AttachmentMeta> {
|
||||
return syscall("space.getAttachmentMeta", name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Read an attachment from the space
|
||||
* @param name path of the attachment to read
|
||||
* @returns the attachment data encoded as a data URL
|
||||
*/
|
||||
readAttachment(
|
||||
name: string,
|
||||
): Promise<string> {
|
||||
return syscall("space.readAttachment", name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes an attachment to the space
|
||||
* @param name path of the attachment to write
|
||||
* @param encoding encoding of the data ("utf8" or "dataurl)
|
||||
* @param data data itself
|
||||
* @returns
|
||||
*/
|
||||
writeAttachment(
|
||||
name: string,
|
||||
encoding: "utf8" | "dataurl",
|
||||
data: string,
|
||||
): Promise<AttachmentMeta> {
|
||||
return syscall("space.writeAttachment", name, encoding, data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes an attachment from the space
|
||||
* @param name path of the attachment to delete
|
||||
*/
|
||||
deleteAttachment(name: string): Promise<void> {
|
||||
return syscall("space.deleteAttachment", name);
|
||||
}
|
||||
|
||||
// Filesystem implementation
|
||||
readFile(path: string, encoding: "dataurl" | "utf8"): Promise<string> {
|
||||
return syscall("space.readFile", path, encoding);
|
||||
}
|
||||
getFileMeta(path: string): Promise<FileMeta> {
|
||||
return syscall("space.getFileMeta", path);
|
||||
}
|
||||
writeFile(
|
||||
path: string,
|
||||
text: string,
|
||||
encoding: "dataurl" | "utf8",
|
||||
): Promise<FileMeta> {
|
||||
return syscall("space.writeFile", path, text, encoding);
|
||||
}
|
||||
deleteFile(path: string): Promise<void> {
|
||||
return syscall("space.deleteFile", path);
|
||||
}
|
||||
listFiles(path: string): Promise<FileMeta[]> {
|
||||
return syscall("space.listFiles", path);
|
||||
}
|
||||
export function listPages(unfiltered = false): Promise<PageMeta[]> {
|
||||
return syscall("space.listPages", unfiltered);
|
||||
}
|
||||
|
||||
export default new SpaceFileSystem();
|
||||
export function getPageMeta(name: string): Promise<PageMeta> {
|
||||
return syscall("space.getPageMeta", name);
|
||||
}
|
||||
|
||||
export function readPage(
|
||||
name: string,
|
||||
): Promise<string> {
|
||||
return syscall("space.readPage", name);
|
||||
}
|
||||
|
||||
export function writePage(name: string, text: string): Promise<PageMeta> {
|
||||
return syscall("space.writePage", name, text);
|
||||
}
|
||||
|
||||
export function deletePage(name: string): Promise<void> {
|
||||
return syscall("space.deletePage", name);
|
||||
}
|
||||
|
||||
export function listPlugs(): Promise<string[]> {
|
||||
return syscall("space.listPlugs");
|
||||
}
|
||||
|
||||
export function listAttachments(): Promise<PageMeta[]> {
|
||||
return syscall("space.listAttachments");
|
||||
}
|
||||
|
||||
export function getAttachmentMeta(name: string): Promise<AttachmentMeta> {
|
||||
return syscall("space.getAttachmentMeta", name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Read an attachment from the space
|
||||
* @param name path of the attachment to read
|
||||
* @returns the attachment data encoded as a data URL
|
||||
*/
|
||||
export function readAttachment(
|
||||
name: string,
|
||||
): Promise<string> {
|
||||
return syscall("space.readAttachment", name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes an attachment to the space
|
||||
* @param name path of the attachment to write
|
||||
* @param encoding encoding of the data ("utf8" or "dataurl)
|
||||
* @param data data itself
|
||||
* @returns
|
||||
*/
|
||||
export function writeAttachment(
|
||||
name: string,
|
||||
encoding: "utf8" | "dataurl",
|
||||
data: string,
|
||||
): Promise<AttachmentMeta> {
|
||||
return syscall("space.writeAttachment", name, encoding, data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes an attachment from the space
|
||||
* @param name path of the attachment to delete
|
||||
*/
|
||||
export function deleteAttachment(name: string): Promise<void> {
|
||||
return syscall("space.deleteAttachment", name);
|
||||
}
|
||||
|
||||
+3
-3
@@ -1,13 +1,13 @@
|
||||
import { syscall } from "./syscall.ts";
|
||||
|
||||
export function set(key: string, value: any): Promise<void> {
|
||||
return syscall("clientStore.set", key, value);
|
||||
return syscall("store.set", key, value);
|
||||
}
|
||||
|
||||
export function get(key: string): Promise<any> {
|
||||
return syscall("clientStore.get", key);
|
||||
return syscall("store.get", key);
|
||||
}
|
||||
|
||||
export function del(key: string): Promise<void> {
|
||||
return syscall("clientStore.delete", key);
|
||||
return syscall("store.delete", key);
|
||||
}
|
||||
@@ -1,45 +1,9 @@
|
||||
import type { SyncStatusItem } from "../../common/spaces/sync.ts";
|
||||
import { syscall } from "./syscall.ts";
|
||||
import { syscall } from "$sb/silverbullet-syscall/syscall.ts";
|
||||
|
||||
export type SyncEndpoint = {
|
||||
url: string;
|
||||
user?: string;
|
||||
password?: string;
|
||||
excludePrefixes?: string[];
|
||||
};
|
||||
|
||||
// Perform a sync with the server, based on the given status (to be persisted)
|
||||
// returns a new sync status to persist
|
||||
export function syncAll(
|
||||
endpoint: SyncEndpoint,
|
||||
snapshot: Record<string, SyncStatusItem>,
|
||||
): Promise<
|
||||
{
|
||||
snapshot: Record<string, SyncStatusItem>;
|
||||
operations: number;
|
||||
error?: string;
|
||||
}
|
||||
> {
|
||||
return syscall("sync.syncAll", endpoint, snapshot);
|
||||
export function isSyncing(): Promise<boolean> {
|
||||
return syscall("sync.isSyncing");
|
||||
}
|
||||
|
||||
// Perform a sync with the server, based on the given status (to be persisted)
|
||||
// returns a new sync status to persist
|
||||
export function syncFile(
|
||||
endpoint: SyncEndpoint,
|
||||
snapshot: Record<string, SyncStatusItem>,
|
||||
name: string,
|
||||
): Promise<
|
||||
{
|
||||
snapshot: Record<string, SyncStatusItem>;
|
||||
operations: number;
|
||||
error?: string;
|
||||
}
|
||||
> {
|
||||
return syscall("sync.syncFile", endpoint, snapshot, name);
|
||||
}
|
||||
|
||||
// Checks the sync endpoint for connectivity and authentication, throws and Error on failure
|
||||
export function check(endpoint: SyncEndpoint): Promise<void> {
|
||||
return syscall("sync.check", endpoint);
|
||||
export function hasInitialSyncCompleted(): Promise<boolean> {
|
||||
return syscall("sync.hasInitialSyncCompleted");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user