@telepath-computer/vault-server 0.4.2 → 0.5.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.
@@ -1,14 +1,13 @@
1
- /** Composes the vault HTTP API, filesystem watcher, and WebSocket subscriptions. */
2
- import { type Server } from "node:http";
3
- import express from "express";
4
- import { type RecordContent } from "./notes.ts";
1
+ import { type IncomingMessage } from "node:http";
2
+ import type { Duplex } from "node:stream";
3
+ import { FileServer, type ListenOptions } from "@telepath-computer/file-server";
4
+ import { type BodyFormat, type LinkFormat, type RecordContent } from "./notes.ts";
5
5
  /** A record in the form it will be stored, offered for approval before it is written. */
6
6
  export type ValidatedRecord = RecordContent & {
7
7
  path: string;
8
8
  };
9
9
  export type Validate = (record: ValidatedRecord) => void | Promise<void>;
10
- export type LinkFormat = "wikilink" | "markdown";
11
- export type BodyFormat = "markdown" | "raw";
10
+ export type { BodyFormat, LinkFormat, ListenOptions };
12
11
  export type VaultServerOptions = {
13
12
  root: string;
14
13
  linkFormat?: LinkFormat;
@@ -17,48 +16,53 @@ export type VaultServerOptions = {
17
16
  jsonLimit?: string | number;
18
17
  pingIntervalMs?: number;
19
18
  };
19
+ /** A file server with cached structured views for visible markdown files. */
20
20
  export declare class VaultServer {
21
- readonly app: express.Express;
22
- readonly server: Server;
23
- /** Resolves once the watcher has indexed the vault and the root is known good. */
21
+ readonly app: FileServer["app"];
22
+ readonly server: FileServer["server"];
24
23
  readonly ready: Promise<void>;
25
- private readonly root;
26
- private readonly index;
24
+ private readonly files;
27
25
  private readonly validate;
28
- private readonly watcher;
29
- private readonly webSockets;
30
- private readonly sockets;
31
- private readonly pendingIndexRefreshes;
32
- private readonly pendingWatcherEvents;
33
- private readonly pingTimer;
34
- private isReady;
35
- private isClosing;
36
- private startupRefreshFailed;
37
- private startupRefreshError;
38
- private boundHost;
26
+ private readonly maximumJsonBytes;
27
+ private readonly activeChanges;
28
+ private readonly changesByPath;
29
+ private readonly bootstrapPathGenerations;
30
+ private readonly directories;
31
+ private readonly pathView;
32
+ private root;
33
+ private index;
34
+ private linkFormat;
35
+ private bodyFormat;
36
+ private resolveIndex;
37
+ private readonly indexAvailable;
38
+ private changeGeneration;
39
+ private bootstrapComplete;
39
40
  constructor(options: VaultServerOptions);
40
- /** The address the server is bound to, or undefined before listening. */
41
+ /** The URL currently bound, or undefined before listening and after closing. */
41
42
  get url(): string | undefined;
42
- /** The port actually bound, which for port 0 is the one the OS chose. */
43
+ /** The port currently bound, including an operating-system-selected port. */
43
44
  get port(): number | undefined;
44
- /** Every visible disk path currently held by the live index. */
45
+ /** Every visible regular-file disk path currently held by the live index. */
45
46
  get paths(): Iterable<string>;
46
- /** Replace runtime formatting settings, rebuilding data derived from bodies. */
47
+ /** Replace runtime formatting settings, rebuilding data derived from bodies synchronously. */
47
48
  configure(options: {
48
49
  linkFormat?: LinkFormat;
49
50
  bodyFormat?: BodyFormat | ((path: string) => BodyFormat);
50
51
  }): void;
51
- /** Accept connections, once the vault is indexed. Resolves with the server. */
52
- listen(options?: {
53
- host?: string;
54
- port?: number;
55
- }): Promise<this>;
52
+ /** Start accepting connections after the base watcher and record index are ready. */
53
+ listen(options?: ListenOptions): Promise<this>;
54
+ /** Release the embedded file server resources. */
56
55
  close(): Promise<void>;
57
- private context;
58
- private readonly runMutation;
59
- private emitEvent;
60
- private handleWatcherChange;
61
- private flushWatcherEvent;
62
- private cancelPendingWatcherEvent;
63
- private refreshIndex;
56
+ /** Delegate a mount-relative WebSocket upgrade after the record index is ready. */
57
+ handleUpgrade(request: IncomingMessage, socket: Duplex, head: Buffer, requestTarget?: string): Promise<void>;
58
+ private bootstrap;
59
+ private refreshTree;
60
+ private bootstrapGenerationFor;
61
+ private drainBootstrapChanges;
62
+ private handle;
63
+ private mutateRecord;
64
+ private approve;
65
+ private change;
66
+ private refreshChange;
67
+ private forgetDirectoryTree;
64
68
  }