@liveink/server 0.0.0-stage → 0.1.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.
package/dist/index.js ADDED
@@ -0,0 +1,11 @@
1
+ import {
2
+ FileStorage,
3
+ MemoryStorage,
4
+ createInkServer
5
+ } from "./chunks/chunk-5WGYVCZI.js";
6
+ export {
7
+ FileStorage,
8
+ MemoryStorage,
9
+ createInkServer
10
+ };
11
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": [],
4
+ "sourcesContent": [],
5
+ "mappings": "",
6
+ "names": []
7
+ }
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env node
2
+ export {};
@@ -0,0 +1,3 @@
1
+ /** @liveink/server: sync server library for <ink-canvas>. The `liveink-server` command wraps it. */
2
+ export { createInkServer, type InkServer, type InkServerOptions, type InkRoom } from './server.js';
3
+ export { FileStorage, MemoryStorage, type RoomStorage } from './storage.js';
@@ -0,0 +1,61 @@
1
+ /**
2
+ * @liveink/server: WebSocket sync for <ink-canvas> rooms, standalone (HTTP + WebSocket on one
3
+ * port, optionally serving a static site) or attached to an existing Node HTTP(S) server.
4
+ * Holds one authoritative Y.Doc + Awareness per active room, relays updates,
5
+ * persists via a pluggable RoomStorage.
6
+ */
7
+ import http from 'node:http';
8
+ import https from 'node:https';
9
+ import * as Y from 'yjs';
10
+ import { type RoomStorage } from './storage.js';
11
+ export interface InkServerOptions {
12
+ /**
13
+ * Attach to an existing HTTP(S) server instead of starting one: only WebSocket upgrades on
14
+ * `path` are handled; all other requests stay with your app, and `port`, `host`, `staticDir`,
15
+ * `https` and `info` are ignored. close() does not close your server.
16
+ */
17
+ server?: http.Server | https.Server;
18
+ /** WebSocket path (default '/ws'). */
19
+ path?: string;
20
+ /** Serve GET /api/info (LAN addresses + port, used by the demo's share link). Default false. */
21
+ info?: boolean;
22
+ port?: number;
23
+ host?: string;
24
+ storage?: RoomStorage;
25
+ /** Directory with the built demo (index.html etc). null = no static serving. */
26
+ staticDir?: string | null;
27
+ /** Debounce before persisting a changed room. */
28
+ saveDebounceMs?: number;
29
+ /** Max time a dirty room may stay unsaved while edits keep coming. */
30
+ saveMaxWaitMs?: number;
31
+ /** Keep an empty room in memory this long before unloading it. */
32
+ roomIdleMs?: number;
33
+ log?: (...args: unknown[]) => void;
34
+ /** Optionally ALSO serve HTTPS/WSS (same rooms) on another port, e.g. to unlock secure-context-only input APIs. */
35
+ https?: {
36
+ key: string | Buffer;
37
+ cert: string | Buffer;
38
+ port: number;
39
+ };
40
+ }
41
+ export interface InkServer {
42
+ /** Listening port (when attached: the host server's port, or 0 if it isn't listening yet). */
43
+ port: number;
44
+ http: http.Server | https.Server;
45
+ https: https.Server | null;
46
+ httpsPort: number | null;
47
+ /** Rooms currently loaded in memory. */
48
+ rooms: ReadonlyMap<string, InkRoom>;
49
+ /** Persist all dirty rooms now. */
50
+ flush(): Promise<void>;
51
+ close(): Promise<void>;
52
+ }
53
+ /** Public view of an active room. */
54
+ export interface InkRoom {
55
+ readonly name: string;
56
+ /** The room's authoritative Yjs document (read it; edits made here sync to every client). */
57
+ readonly doc: Y.Doc;
58
+ /** Connected clients. */
59
+ readonly clients: number;
60
+ }
61
+ export declare function createInkServer(options?: InkServerOptions): Promise<InkServer>;
@@ -0,0 +1,29 @@
1
+ export interface RoomStorage {
2
+ /** Return the stored Yjs state for a room, or null if the room is new. */
3
+ loadRoom(room: string): Promise<Uint8Array | null>;
4
+ /** Persist the full Yjs state of a room (replaces previous snapshot). */
5
+ saveRoom(room: string, state: Uint8Array): Promise<void>;
6
+ /** Optional: remove a room. */
7
+ deleteRoom?(room: string): Promise<void>;
8
+ }
9
+ export declare class MemoryStorage implements RoomStorage {
10
+ private rooms;
11
+ loadRoom(room: string): Promise<Uint8Array<ArrayBuffer> | null>;
12
+ saveRoom(room: string, state: Uint8Array): Promise<void>;
13
+ deleteRoom(room: string): Promise<void>;
14
+ }
15
+ /**
16
+ * One file per room in `dir` (default ./data). File name = readable slug + hash of the
17
+ * exact room id, so arbitrary room strings can't escape the directory or collide.
18
+ * Writes are atomic (temp file + rename).
19
+ */
20
+ export declare class FileStorage implements RoomStorage {
21
+ readonly dir: string;
22
+ private ready;
23
+ private writing;
24
+ constructor(dir?: string);
25
+ fileFor(room: string): string;
26
+ loadRoom(room: string): Promise<Uint8Array | null>;
27
+ saveRoom(room: string, state: Uint8Array): Promise<void>;
28
+ deleteRoom(room: string): Promise<void>;
29
+ }
package/package.json CHANGED
@@ -1,6 +1,72 @@
1
1
  {
2
2
  "name": "@liveink/server",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.1.0",
4
+ "description": "Reference sync server for @liveink/canvas (<ink-canvas>): WebSocket rooms, pluggable storage, standalone CLI or attached to your own Node HTTP server.",
5
+ "keywords": [
6
+ "liveink",
7
+ "ink-canvas",
8
+ "websocket",
9
+ "yjs",
10
+ "crdt",
11
+ "collaborative",
12
+ "drawing",
13
+ "whiteboard",
14
+ "server"
15
+ ],
16
+ "license": "MIT",
17
+ "repository": {
18
+ "type": "git",
19
+ "url": "git+https://github.com/Danpythonman/liveink.git",
20
+ "directory": "packages/server"
21
+ },
22
+ "homepage": "https://github.com/Danpythonman/liveink/tree/main/packages/server#readme",
23
+ "bugs": {
24
+ "url": "https://github.com/Danpythonman/liveink/issues"
25
+ },
26
+ "type": "module",
27
+ "main": "./dist/index.js",
28
+ "types": "./dist/types/index.d.ts",
29
+ "exports": {
30
+ ".": {
31
+ "types": "./dist/types/index.d.ts",
32
+ "import": "./dist/index.js"
33
+ },
34
+ "./package.json": "./package.json"
35
+ },
36
+ "bin": {
37
+ "liveink-server": "dist/cli.js"
38
+ },
39
+ "files": [
40
+ "dist",
41
+ "README.md",
42
+ "LICENSE",
43
+ "PROTOCOL.md"
44
+ ],
45
+ "engines": {
46
+ "node": ">=20"
47
+ },
48
+ "scripts": {
49
+ "build": "node -e \"require('fs').rmSync('dist',{recursive:true,force:true})\" && tsc -p tsconfig.build.json && node build.mjs",
50
+ "typecheck": "tsc -p tsconfig.json --noEmit",
51
+ "test": "node --import tsx --test test/*.test.ts",
52
+ "prepublishOnly": "npm run typecheck && npm test && npm run build",
53
+ "prepack": "node -e \"require('fs').copyFileSync('../../docs/protocol.md','PROTOCOL.md')\"",
54
+ "postpack": "node -e \"require('fs').rmSync('PROTOCOL.md',{force:true})\""
55
+ },
56
+ "dependencies": {
57
+ "@liveink/canvas": "^0.1.0",
58
+ "ws": "^8.23.1",
59
+ "y-protocols": "^1.0.7",
60
+ "yjs": "^13.6.33"
61
+ },
62
+ "devDependencies": {
63
+ "@types/node": "^26.6.11",
64
+ "@types/ws": "^8.18.2",
65
+ "esbuild": "^0.28.2",
66
+ "tsx": "^4.23.15",
67
+ "typescript": "^7.0.2"
68
+ },
69
+ "publishConfig": {
70
+ "access": "public"
71
+ }
72
+ }