tetherdb 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/LICENSE +21 -0
- package/README.md +277 -0
- package/bin/tetherdb.js +7 -0
- package/dist/cli/args.d.cts +20 -0
- package/dist/cli/args.d.ts +20 -0
- package/dist/cli/args.d.ts.map +1 -0
- package/dist/cli/backend.d.cts +15 -0
- package/dist/cli/backend.d.ts +15 -0
- package/dist/cli/backend.d.ts.map +1 -0
- package/dist/cli/cli.d.cts +8 -0
- package/dist/cli/cli.d.ts +8 -0
- package/dist/cli/cli.d.ts.map +1 -0
- package/dist/cli/commands/apps.d.cts +9 -0
- package/dist/cli/commands/apps.d.ts +9 -0
- package/dist/cli/commands/apps.d.ts.map +1 -0
- package/dist/cli/commands/help.d.cts +5 -0
- package/dist/cli/commands/help.d.ts +5 -0
- package/dist/cli/commands/help.d.ts.map +1 -0
- package/dist/cli/commands/index.d.cts +8 -0
- package/dist/cli/commands/index.d.ts +8 -0
- package/dist/cli/commands/index.d.ts.map +1 -0
- package/dist/cli/commands/maintenance.d.cts +9 -0
- package/dist/cli/commands/maintenance.d.ts +9 -0
- package/dist/cli/commands/maintenance.d.ts.map +1 -0
- package/dist/cli/commands/serve.d.cts +14 -0
- package/dist/cli/commands/serve.d.ts +14 -0
- package/dist/cli/commands/serve.d.ts.map +1 -0
- package/dist/cli/commands/status.d.cts +9 -0
- package/dist/cli/commands/status.d.ts +9 -0
- package/dist/cli/commands/status.d.ts.map +1 -0
- package/dist/cli/commands/tables.d.cts +9 -0
- package/dist/cli/commands/tables.d.ts +9 -0
- package/dist/cli/commands/tables.d.ts.map +1 -0
- package/dist/cli/commands/users.d.cts +9 -0
- package/dist/cli/commands/users.d.ts +9 -0
- package/dist/cli/commands/users.d.ts.map +1 -0
- package/dist/cli/index.cjs +3999 -0
- package/dist/cli/index.cjs.map +1 -0
- package/dist/cli/index.d.cts +7 -0
- package/dist/cli/index.d.ts +7 -0
- package/dist/cli/index.d.ts.map +1 -0
- package/dist/cli/index.js +3958 -0
- package/dist/cli/index.js.map +1 -0
- package/dist/client/auth.d.cts +155 -0
- package/dist/client/auth.d.ts +155 -0
- package/dist/client/auth.d.ts.map +1 -0
- package/dist/client/client.d.cts +122 -0
- package/dist/client/client.d.ts +122 -0
- package/dist/client/client.d.ts.map +1 -0
- package/dist/client/errors.d.cts +39 -0
- package/dist/client/errors.d.ts +39 -0
- package/dist/client/errors.d.ts.map +1 -0
- package/dist/client/index.cjs +1742 -0
- package/dist/client/index.cjs.map +1 -0
- package/dist/client/index.d.cts +12 -0
- package/dist/client/index.d.ts +12 -0
- package/dist/client/index.d.ts.map +1 -0
- package/dist/client/index.js +1707 -0
- package/dist/client/index.js.map +1 -0
- package/dist/client/shared/event.d.cts +29 -0
- package/dist/client/shared/event.d.ts +29 -0
- package/dist/client/shared/event.d.ts.map +1 -0
- package/dist/client/shared/id.d.cts +5 -0
- package/dist/client/shared/id.d.ts +5 -0
- package/dist/client/shared/id.d.ts.map +1 -0
- package/dist/client/storage.d.cts +183 -0
- package/dist/client/storage.d.ts +183 -0
- package/dist/client/storage.d.ts.map +1 -0
- package/dist/client/sync.d.cts +126 -0
- package/dist/client/sync.d.ts +126 -0
- package/dist/client/sync.d.ts.map +1 -0
- package/dist/client/table.d.cts +146 -0
- package/dist/client/table.d.ts +146 -0
- package/dist/client/table.d.ts.map +1 -0
- package/dist/index.cjs +1742 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +7 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +1707 -0
- package/dist/index.js.map +1 -0
- package/dist/server/crypto.d.cts +55 -0
- package/dist/server/crypto.d.ts +55 -0
- package/dist/server/crypto.d.ts.map +1 -0
- package/dist/server/errors.d.cts +39 -0
- package/dist/server/errors.d.ts +39 -0
- package/dist/server/errors.d.ts.map +1 -0
- package/dist/server/index.cjs +3621 -0
- package/dist/server/index.cjs.map +1 -0
- package/dist/server/index.d.cts +10 -0
- package/dist/server/index.d.ts +10 -0
- package/dist/server/index.d.ts.map +1 -0
- package/dist/server/index.js +3569 -0
- package/dist/server/index.js.map +1 -0
- package/dist/server/lock.d.cts +56 -0
- package/dist/server/lock.d.ts +56 -0
- package/dist/server/lock.d.ts.map +1 -0
- package/dist/server/rate-limiter.d.cts +81 -0
- package/dist/server/rate-limiter.d.ts +81 -0
- package/dist/server/rate-limiter.d.ts.map +1 -0
- package/dist/server/server.d.cts +206 -0
- package/dist/server/server.d.ts +206 -0
- package/dist/server/server.d.ts.map +1 -0
- package/dist/server/storage/app.d.cts +70 -0
- package/dist/server/storage/app.d.ts +70 -0
- package/dist/server/storage/app.d.ts.map +1 -0
- package/dist/server/storage/base/app.d.cts +42 -0
- package/dist/server/storage/base/app.d.ts +42 -0
- package/dist/server/storage/base/app.d.ts.map +1 -0
- package/dist/server/storage/base/index.d.cts +5 -0
- package/dist/server/storage/base/index.d.ts +5 -0
- package/dist/server/storage/base/index.d.ts.map +1 -0
- package/dist/server/storage/base/storage.d.cts +40 -0
- package/dist/server/storage/base/storage.d.ts +40 -0
- package/dist/server/storage/base/storage.d.ts.map +1 -0
- package/dist/server/storage/base/table.d.cts +32 -0
- package/dist/server/storage/base/table.d.ts +32 -0
- package/dist/server/storage/base/table.d.ts.map +1 -0
- package/dist/server/storage/base/user.d.cts +31 -0
- package/dist/server/storage/base/user.d.ts +31 -0
- package/dist/server/storage/base/user.d.ts.map +1 -0
- package/dist/server/storage/file/app.d.cts +50 -0
- package/dist/server/storage/file/app.d.ts +50 -0
- package/dist/server/storage/file/app.d.ts.map +1 -0
- package/dist/server/storage/file/index.d.cts +5 -0
- package/dist/server/storage/file/index.d.ts +5 -0
- package/dist/server/storage/file/index.d.ts.map +1 -0
- package/dist/server/storage/file/storage.d.cts +67 -0
- package/dist/server/storage/file/storage.d.ts +67 -0
- package/dist/server/storage/file/storage.d.ts.map +1 -0
- package/dist/server/storage/file/table.d.cts +14 -0
- package/dist/server/storage/file/table.d.ts +14 -0
- package/dist/server/storage/file/table.d.ts.map +1 -0
- package/dist/server/storage/file/user.d.cts +14 -0
- package/dist/server/storage/file/user.d.ts +14 -0
- package/dist/server/storage/file/user.d.ts.map +1 -0
- package/dist/server/storage/index.d.cts +14 -0
- package/dist/server/storage/index.d.ts +14 -0
- package/dist/server/storage/index.d.ts.map +1 -0
- package/dist/server/storage/memory/app.d.cts +29 -0
- package/dist/server/storage/memory/app.d.ts +29 -0
- package/dist/server/storage/memory/app.d.ts.map +1 -0
- package/dist/server/storage/memory/index.d.cts +5 -0
- package/dist/server/storage/memory/index.d.ts +5 -0
- package/dist/server/storage/memory/index.d.ts.map +1 -0
- package/dist/server/storage/memory/storage.d.cts +47 -0
- package/dist/server/storage/memory/storage.d.ts +47 -0
- package/dist/server/storage/memory/storage.d.ts.map +1 -0
- package/dist/server/storage/memory/table.d.cts +17 -0
- package/dist/server/storage/memory/table.d.ts +17 -0
- package/dist/server/storage/memory/table.d.ts.map +1 -0
- package/dist/server/storage/memory/user.d.cts +21 -0
- package/dist/server/storage/memory/user.d.ts +21 -0
- package/dist/server/storage/memory/user.d.ts.map +1 -0
- package/dist/server/storage/sqlite/app.d.cts +31 -0
- package/dist/server/storage/sqlite/app.d.ts +31 -0
- package/dist/server/storage/sqlite/app.d.ts.map +1 -0
- package/dist/server/storage/sqlite/index.d.cts +5 -0
- package/dist/server/storage/sqlite/index.d.ts +5 -0
- package/dist/server/storage/sqlite/index.d.ts.map +1 -0
- package/dist/server/storage/sqlite/storage.d.cts +92 -0
- package/dist/server/storage/sqlite/storage.d.ts +92 -0
- package/dist/server/storage/sqlite/storage.d.ts.map +1 -0
- package/dist/server/storage/sqlite/table.d.cts +15 -0
- package/dist/server/storage/sqlite/table.d.ts +15 -0
- package/dist/server/storage/sqlite/table.d.ts.map +1 -0
- package/dist/server/storage/sqlite/user.d.cts +14 -0
- package/dist/server/storage/sqlite/user.d.ts +14 -0
- package/dist/server/storage/sqlite/user.d.ts.map +1 -0
- package/dist/server/storage/storage.d.cts +152 -0
- package/dist/server/storage/storage.d.ts +152 -0
- package/dist/server/storage/storage.d.ts.map +1 -0
- package/dist/server/storage/table.d.cts +45 -0
- package/dist/server/storage/table.d.ts +45 -0
- package/dist/server/storage/table.d.ts.map +1 -0
- package/dist/server/storage/user.d.cts +45 -0
- package/dist/server/storage/user.d.ts +45 -0
- package/dist/server/storage/user.d.ts.map +1 -0
- package/dist/server/sync.d.cts +67 -0
- package/dist/server/sync.d.ts +67 -0
- package/dist/server/sync.d.ts.map +1 -0
- package/dist/server/validate.d.cts +113 -0
- package/dist/server/validate.d.ts +113 -0
- package/dist/server/validate.d.ts.map +1 -0
- package/dist/shared/clock.d.cts +22 -0
- package/dist/shared/clock.d.ts +22 -0
- package/dist/shared/clock.d.ts.map +1 -0
- package/dist/shared/path.d.cts +12 -0
- package/dist/shared/path.d.ts +12 -0
- package/dist/shared/path.d.ts.map +1 -0
- package/dist/shared/types.d.cts +234 -0
- package/dist/shared/types.d.ts +234 -0
- package/dist/shared/types.d.ts.map +1 -0
- package/package.json +133 -0
|
@@ -0,0 +1,206 @@
|
|
|
1
|
+
import * as http from 'node:http';
|
|
2
|
+
import { WebSocketServer } from 'ws';
|
|
3
|
+
import type { Storage, UserStorage } from './storage/index.js';
|
|
4
|
+
import { Sync } from './sync.js';
|
|
5
|
+
/**
|
|
6
|
+
* Rate limiting and resource control options for authentication endpoints and sync streams.
|
|
7
|
+
*/
|
|
8
|
+
export interface RateLimitOptions {
|
|
9
|
+
/** Maximum login attempts per IP within the time window (defaults to 100). */
|
|
10
|
+
ipLoginMaxRequests?: number;
|
|
11
|
+
/** Maximum login attempts per target username within the time window (defaults to 20). */
|
|
12
|
+
userLoginMaxRequests?: number;
|
|
13
|
+
/** Maximum registration attempts per IP within the time window (defaults to 100). */
|
|
14
|
+
ipRegisterMaxRequests?: number;
|
|
15
|
+
/** Maximum WebSocket connection handshakes per IP within the time window (defaults to 100). */
|
|
16
|
+
ipSyncMaxRequests?: number;
|
|
17
|
+
/** Maximum concurrent active WebSocket connections allowed per user channel (defaults to 20). */
|
|
18
|
+
maxConcurrentConnectionsPerUser?: number;
|
|
19
|
+
/** Maximum duration in milliseconds to wait for authentication before terminating socket (defaults to 10,000ms). */
|
|
20
|
+
authTimeoutMs?: number;
|
|
21
|
+
/** Sliding window duration in milliseconds (defaults to 60,000ms / 1 minute). */
|
|
22
|
+
windowMs?: number;
|
|
23
|
+
/** Consecutive failed attempts before progressive backoff begins (defaults to 5). */
|
|
24
|
+
maxFailures?: number;
|
|
25
|
+
/** Initial backoff duration in milliseconds (defaults to 1,000ms). */
|
|
26
|
+
initialBackoffMs?: number;
|
|
27
|
+
/** Maximum backoff duration in milliseconds (defaults to 900,000ms / 15 minutes). */
|
|
28
|
+
maxBackoffMs?: number;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Options for configuring Cross-Origin Resource Sharing (CORS) on HTTP endpoints.
|
|
32
|
+
*/
|
|
33
|
+
export interface CorsOptions {
|
|
34
|
+
/**
|
|
35
|
+
* Allowed origin(s). Can be `'*'` for unrestricted access, a specific origin string (e.g. `'https://example.com'`),
|
|
36
|
+
* an array of allowed origin strings, `true` to reflect the request's `Origin` header, or `false` to disable CORS headers.
|
|
37
|
+
* Defaults to `'*'`.
|
|
38
|
+
*/
|
|
39
|
+
origin?: string | string[] | boolean;
|
|
40
|
+
/** Whether to set `Access-Control-Allow-Credentials: true` (defaults to false). */
|
|
41
|
+
credentials?: boolean;
|
|
42
|
+
/** Allowed request headers for preflight OPTIONS checks (defaults to `['Content-Type', 'Authorization']`). */
|
|
43
|
+
allowedHeaders?: string[];
|
|
44
|
+
/** Exposed response headers (Access-Control-Expose-Headers). */
|
|
45
|
+
exposedHeaders?: string[];
|
|
46
|
+
/** Maximum age in seconds to cache preflight responses (Access-Control-Max-Age). */
|
|
47
|
+
maxAge?: number;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Pluggable logger interface for TetherServer logging.
|
|
51
|
+
*/
|
|
52
|
+
export interface TetherLogger {
|
|
53
|
+
/** Logs debug information. */
|
|
54
|
+
debug(message: string, ...args: unknown[]): void;
|
|
55
|
+
/** Logs operational information. */
|
|
56
|
+
info(message: string, ...args: unknown[]): void;
|
|
57
|
+
/** Logs warning conditions. */
|
|
58
|
+
warn(message: string, ...args: unknown[]): void;
|
|
59
|
+
/** Logs error conditions. */
|
|
60
|
+
error(message: string, ...args: unknown[]): void;
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Configuration options for the TetherServer.
|
|
64
|
+
*/
|
|
65
|
+
export interface TetherServerOptions {
|
|
66
|
+
/** Custom storage instance. Defaults to MemoryStorage if not defined. */
|
|
67
|
+
storage?: Storage;
|
|
68
|
+
/** Base path for HTTP REST endpoints (defaults to ''). */
|
|
69
|
+
basePath?: string;
|
|
70
|
+
/** Path for WebSocket upgrade requests (defaults to '/sync'). */
|
|
71
|
+
webSocketPath?: string;
|
|
72
|
+
/** Whether user self-registration is allowed via `/auth/register` (defaults to true). */
|
|
73
|
+
allowRegistration?: boolean;
|
|
74
|
+
/** Rate limiting options for auth and sync endpoints, or `false` to disable rate limiting (defaults to true). */
|
|
75
|
+
rateLimiting?: boolean | RateLimitOptions;
|
|
76
|
+
/** Whether to trust the `X-Forwarded-For` header for resolving client IP addresses (defaults to false). */
|
|
77
|
+
trustProxy?: boolean;
|
|
78
|
+
/** CORS options for HTTP endpoints, `false` to disable CORS headers, or `true` for default permissive CORS (defaults to true). */
|
|
79
|
+
cors?: boolean | CorsOptions;
|
|
80
|
+
/** Optional custom logger instance, or `false` to silence internal server logs (defaults to `console`). */
|
|
81
|
+
logger?: TetherLogger | false;
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Options for starting the standard server launcher.
|
|
85
|
+
*/
|
|
86
|
+
export interface StartServerOptions extends TetherServerOptions {
|
|
87
|
+
/** Port number to bind (defaults to 8080 or PORT environment variable). */
|
|
88
|
+
port?: number;
|
|
89
|
+
/** Host interface to bind (defaults to '0.0.0.0'). */
|
|
90
|
+
host?: string;
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Result returned when launching a server using `startServer()`.
|
|
94
|
+
*/
|
|
95
|
+
export interface RunningServer {
|
|
96
|
+
/** The TetherServer instance. */
|
|
97
|
+
server: TetherServer;
|
|
98
|
+
/** The running Node.js HTTP server instance. */
|
|
99
|
+
httpServer: http.Server;
|
|
100
|
+
/** Bound port number. */
|
|
101
|
+
port: number;
|
|
102
|
+
/** Bound host address. */
|
|
103
|
+
host: string;
|
|
104
|
+
/** Closes both HTTP and WebSocket server cleanly. */
|
|
105
|
+
close(): Promise<void>;
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* Starts a complete standalone HTTP & WebSocket synchronization server.
|
|
109
|
+
*
|
|
110
|
+
* @param options - Start options including port, host, storage, and limits.
|
|
111
|
+
* @returns Handle to the running server.
|
|
112
|
+
*/
|
|
113
|
+
export declare function startServer(options?: StartServerOptions): Promise<RunningServer>;
|
|
114
|
+
/**
|
|
115
|
+
* Unified HTTP and WebSocket server handling authentication endpoints (`/auth/register`, `/auth/login`)
|
|
116
|
+
* and real-time streaming connections (`/sync`).
|
|
117
|
+
*/
|
|
118
|
+
export declare class TetherServer {
|
|
119
|
+
/** Underlying storage engine for users, apps, and tables. */
|
|
120
|
+
readonly storage: Storage;
|
|
121
|
+
/** Real-time synchronization connection and broadcast coordinator. */
|
|
122
|
+
readonly sync: Sync;
|
|
123
|
+
/** Base path for HTTP REST endpoints. */
|
|
124
|
+
readonly basePath: string;
|
|
125
|
+
/** Path for WebSocket upgrade requests. */
|
|
126
|
+
readonly webSocketPath: string;
|
|
127
|
+
readonly trustProxy: boolean;
|
|
128
|
+
private readonly allowRegistration;
|
|
129
|
+
private readonly corsConfig;
|
|
130
|
+
private readonly logger;
|
|
131
|
+
private readonly ipLoginLimiter;
|
|
132
|
+
private readonly userLoginLimiter;
|
|
133
|
+
private readonly ipRegisterLimiter;
|
|
134
|
+
private _httpServer;
|
|
135
|
+
private _webSocketServer;
|
|
136
|
+
private lockHandle;
|
|
137
|
+
/**
|
|
138
|
+
* Initializes a new TetherServer instance.
|
|
139
|
+
*
|
|
140
|
+
* @param options - Configuration options for storage, endpoints, and rate limiting.
|
|
141
|
+
*/
|
|
142
|
+
constructor(options?: TetherServerOptions);
|
|
143
|
+
/**
|
|
144
|
+
* Active Node.js HTTP server instance, or `null` if not listening.
|
|
145
|
+
*/
|
|
146
|
+
get httpServer(): http.Server | null;
|
|
147
|
+
/**
|
|
148
|
+
* Active WebSocketServer instance, or `null` if not listening.
|
|
149
|
+
*/
|
|
150
|
+
get webSocketServer(): WebSocketServer | null;
|
|
151
|
+
/**
|
|
152
|
+
* Declares an application and its tables.
|
|
153
|
+
* Registers the application and any declared tables if not already present.
|
|
154
|
+
*
|
|
155
|
+
* @param appId - Application identifier.
|
|
156
|
+
* @param tables - Array of table names.
|
|
157
|
+
*/
|
|
158
|
+
declareApp(appId: string, tables?: string[]): Promise<void>;
|
|
159
|
+
/**
|
|
160
|
+
* Declares a user account with the specified username and password.
|
|
161
|
+
* Creates the user if not already registered, or updates the existing user's password.
|
|
162
|
+
*
|
|
163
|
+
* @param username - Username for the account.
|
|
164
|
+
* @param password - Plaintext password for the account.
|
|
165
|
+
* @returns UserStorage handle for the declared user.
|
|
166
|
+
*/
|
|
167
|
+
declareUser(username: string, password: string): Promise<UserStorage>;
|
|
168
|
+
/**
|
|
169
|
+
* Attaches WebSocket synchronization handling to an existing HTTP server.
|
|
170
|
+
*
|
|
171
|
+
* @param server - The HTTP server instance to attach to.
|
|
172
|
+
*/
|
|
173
|
+
attach(server: http.Server): void;
|
|
174
|
+
/**
|
|
175
|
+
* Starts the HTTP and WebSocket server listening on the specified port and host.
|
|
176
|
+
*
|
|
177
|
+
* @param port - Port number to bind. Defaults to 8080.
|
|
178
|
+
* @param host - Host interface to bind. Defaults to '0.0.0.0'.
|
|
179
|
+
* @returns The active Node.js HTTP server instance.
|
|
180
|
+
*/
|
|
181
|
+
listen(port?: number, host?: string): Promise<http.Server>;
|
|
182
|
+
/**
|
|
183
|
+
* Closes active HTTP server and WebSocket server listeners.
|
|
184
|
+
*/
|
|
185
|
+
close(): Promise<void>;
|
|
186
|
+
/**
|
|
187
|
+
* Handles incoming HTTP requests for authentication and discovery endpoints.
|
|
188
|
+
*
|
|
189
|
+
* @param req - Incoming HTTP request.
|
|
190
|
+
* @param res - Server HTTP response.
|
|
191
|
+
* @returns `true` if the request was handled by TetherDB; `false` if the path did not match.
|
|
192
|
+
*/
|
|
193
|
+
handleHttpRequest(req: http.IncomingMessage, res: http.ServerResponse): Promise<boolean>;
|
|
194
|
+
private getCorsHeaders;
|
|
195
|
+
private sendJson;
|
|
196
|
+
private readJsonBody;
|
|
197
|
+
private handleOptions;
|
|
198
|
+
private handleHealth;
|
|
199
|
+
private handleReady;
|
|
200
|
+
private handleMetrics;
|
|
201
|
+
private handleRegister;
|
|
202
|
+
private handleLogin;
|
|
203
|
+
private readCredentials;
|
|
204
|
+
private getClientIp;
|
|
205
|
+
}
|
|
206
|
+
//# sourceMappingURL=server.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../../src/server/server.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,IAAI,MAAM,WAAW,CAAC;AAClC,OAAO,EAAE,eAAe,EAAE,MAAM,IAAI,CAAC;AAMrC,OAAO,KAAK,EAAE,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AAE/D,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAGjC;;GAEG;AACH,MAAM,WAAW,gBAAgB;IAC/B,8EAA8E;IAC9E,kBAAkB,CAAC,EAAE,MAAM,CAAC;IAC5B,0FAA0F;IAC1F,oBAAoB,CAAC,EAAE,MAAM,CAAC;IAC9B,qFAAqF;IACrF,qBAAqB,CAAC,EAAE,MAAM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,CAAC,cAAc,GACvB,OAAO,CAAC,OAAO,CAAC,CAsDlB;IAID,OAAO,CAAC,cAAc;IAsDtB,OAAO,CAAC,QAAQ;YAaF,YAAY;IA8B1B,OAAO,CAAC,aAAa;IAQrB,OAAO,CAAC,YAAY;YAeN,WAAW;YAeX,aAAa;YAkBb,cAAc;YAyCd,WAAW;YA2DX,eAAe;IAyB7B,OAAO,CAAC,WAAW;CAUpB"}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import type { ChangeRecord } from '../../shared/types.cjs';
|
|
2
|
+
import type { TableStorage } from './table.cjs';
|
|
3
|
+
import type { UserStorage } from './user.cjs';
|
|
4
|
+
/**
|
|
5
|
+
* Application namespace storage managing tables, batch changelogs, and user sequence counters.
|
|
6
|
+
*/
|
|
7
|
+
export interface AppStorage {
|
|
8
|
+
/** Application namespace identifier. */
|
|
9
|
+
readonly id: string;
|
|
10
|
+
/**
|
|
11
|
+
* Creates/registers a new table within this application.
|
|
12
|
+
* Throws an error if a table with the specified name already exists.
|
|
13
|
+
*
|
|
14
|
+
* @param name - Name of the table.
|
|
15
|
+
* @returns Created TableStorage handle.
|
|
16
|
+
* @throws Error if the table already exists.
|
|
17
|
+
*/
|
|
18
|
+
createTable(name: string): Promise<TableStorage>;
|
|
19
|
+
/**
|
|
20
|
+
* Retrieves a table handle if it exists.
|
|
21
|
+
*
|
|
22
|
+
* @param name - Name of the table.
|
|
23
|
+
* @returns TableStorage handle or `undefined`.
|
|
24
|
+
*/
|
|
25
|
+
getTable(name: string): Promise<TableStorage | undefined>;
|
|
26
|
+
/**
|
|
27
|
+
* Lists all registered tables in this application.
|
|
28
|
+
*
|
|
29
|
+
* @returns Array of TableStorage handles.
|
|
30
|
+
*/
|
|
31
|
+
getTables(): Promise<TableStorage[]>;
|
|
32
|
+
/**
|
|
33
|
+
* Applies an array of mutation changes for a user applying LWW conflict resolution,
|
|
34
|
+
* assigning sequential change numbers, and appending to the changelog.
|
|
35
|
+
*
|
|
36
|
+
* @param user - Target user handle.
|
|
37
|
+
* @param changes - Array of change records.
|
|
38
|
+
* @returns Applied changes with assigned sequence numbers and new sequence number.
|
|
39
|
+
*/
|
|
40
|
+
applyChanges(user: UserStorage, changes: ChangeRecord[]): Promise<{
|
|
41
|
+
applied: ChangeRecord[];
|
|
42
|
+
newSeq: number;
|
|
43
|
+
}>;
|
|
44
|
+
/**
|
|
45
|
+
* Retrieves change operations for a user since a given sequence number within this app.
|
|
46
|
+
*
|
|
47
|
+
* @param user - Target user handle.
|
|
48
|
+
* @param fromSeq - Starting sequence number (exclusive).
|
|
49
|
+
* @returns Changes, current sequence, and snapshot requirement flag.
|
|
50
|
+
*/
|
|
51
|
+
getChangesSince(user: UserStorage, fromSeq: number): Promise<{
|
|
52
|
+
changes: ChangeRecord[];
|
|
53
|
+
currentSeq: number;
|
|
54
|
+
requiresSnapshot?: boolean;
|
|
55
|
+
}>;
|
|
56
|
+
/**
|
|
57
|
+
* Returns the current global sequence number for a user within this application.
|
|
58
|
+
*
|
|
59
|
+
* @param user - Target user handle.
|
|
60
|
+
* @returns Current integer sequence number.
|
|
61
|
+
*/
|
|
62
|
+
getCurrentSeq(user: UserStorage): Promise<number>;
|
|
63
|
+
/**
|
|
64
|
+
* Deletes this entire application and all associated data across all users and tables.
|
|
65
|
+
*
|
|
66
|
+
* @returns True if deleted successfully.
|
|
67
|
+
*/
|
|
68
|
+
delete(): Promise<boolean>;
|
|
69
|
+
}
|
|
70
|
+
//# sourceMappingURL=app.d.ts.map
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import type { ChangeRecord } from '../../shared/types.js';
|
|
2
|
+
import type { TableStorage } from './table.js';
|
|
3
|
+
import type { UserStorage } from './user.js';
|
|
4
|
+
/**
|
|
5
|
+
* Application namespace storage managing tables, batch changelogs, and user sequence counters.
|
|
6
|
+
*/
|
|
7
|
+
export interface AppStorage {
|
|
8
|
+
/** Application namespace identifier. */
|
|
9
|
+
readonly id: string;
|
|
10
|
+
/**
|
|
11
|
+
* Creates/registers a new table within this application.
|
|
12
|
+
* Throws an error if a table with the specified name already exists.
|
|
13
|
+
*
|
|
14
|
+
* @param name - Name of the table.
|
|
15
|
+
* @returns Created TableStorage handle.
|
|
16
|
+
* @throws Error if the table already exists.
|
|
17
|
+
*/
|
|
18
|
+
createTable(name: string): Promise<TableStorage>;
|
|
19
|
+
/**
|
|
20
|
+
* Retrieves a table handle if it exists.
|
|
21
|
+
*
|
|
22
|
+
* @param name - Name of the table.
|
|
23
|
+
* @returns TableStorage handle or `undefined`.
|
|
24
|
+
*/
|
|
25
|
+
getTable(name: string): Promise<TableStorage | undefined>;
|
|
26
|
+
/**
|
|
27
|
+
* Lists all registered tables in this application.
|
|
28
|
+
*
|
|
29
|
+
* @returns Array of TableStorage handles.
|
|
30
|
+
*/
|
|
31
|
+
getTables(): Promise<TableStorage[]>;
|
|
32
|
+
/**
|
|
33
|
+
* Applies an array of mutation changes for a user applying LWW conflict resolution,
|
|
34
|
+
* assigning sequential change numbers, and appending to the changelog.
|
|
35
|
+
*
|
|
36
|
+
* @param user - Target user handle.
|
|
37
|
+
* @param changes - Array of change records.
|
|
38
|
+
* @returns Applied changes with assigned sequence numbers and new sequence number.
|
|
39
|
+
*/
|
|
40
|
+
applyChanges(user: UserStorage, changes: ChangeRecord[]): Promise<{
|
|
41
|
+
applied: ChangeRecord[];
|
|
42
|
+
newSeq: number;
|
|
43
|
+
}>;
|
|
44
|
+
/**
|
|
45
|
+
* Retrieves change operations for a user since a given sequence number within this app.
|
|
46
|
+
*
|
|
47
|
+
* @param user - Target user handle.
|
|
48
|
+
* @param fromSeq - Starting sequence number (exclusive).
|
|
49
|
+
* @returns Changes, current sequence, and snapshot requirement flag.
|
|
50
|
+
*/
|
|
51
|
+
getChangesSince(user: UserStorage, fromSeq: number): Promise<{
|
|
52
|
+
changes: ChangeRecord[];
|
|
53
|
+
currentSeq: number;
|
|
54
|
+
requiresSnapshot?: boolean;
|
|
55
|
+
}>;
|
|
56
|
+
/**
|
|
57
|
+
* Returns the current global sequence number for a user within this application.
|
|
58
|
+
*
|
|
59
|
+
* @param user - Target user handle.
|
|
60
|
+
* @returns Current integer sequence number.
|
|
61
|
+
*/
|
|
62
|
+
getCurrentSeq(user: UserStorage): Promise<number>;
|
|
63
|
+
/**
|
|
64
|
+
* Deletes this entire application and all associated data across all users and tables.
|
|
65
|
+
*
|
|
66
|
+
* @returns True if deleted successfully.
|
|
67
|
+
*/
|
|
68
|
+
delete(): Promise<boolean>;
|
|
69
|
+
}
|
|
70
|
+
//# sourceMappingURL=app.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"app.d.ts","sourceRoot":"","sources":["../../../src/server/storage/app.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC;AAC1D,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAC/C,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,WAAW,CAAC;AAE7C;;GAEG;AACH,MAAM,WAAW,UAAU;IACzB,wCAAwC;IACxC,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IAEpB;;;;;;;OAOG;IACH,WAAW,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,YAAY,CAAC,CAAC;IAEjD;;;;;OAKG;IACH,QAAQ,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,YAAY,GAAG,SAAS,CAAC,CAAC;IAE1D;;;;OAIG;IACH,SAAS,IAAI,OAAO,CAAC,YAAY,EAAE,CAAC,CAAC;IAErC;;;;;;;OAOG;IACH,YAAY,CACV,IAAI,EAAE,WAAW,EACjB,OAAO,EAAE,YAAY,EAAE,GACtB,OAAO,CAAC;QAAE,OAAO,EAAE,YAAY,EAAE,CAAC;QAAC,MAAM,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;IAExD;;;;;;OAMG;IACH,eAAe,CACb,IAAI,EAAE,WAAW,EACjB,OAAO,EAAE,MAAM,GACd,OAAO,CAAC;QACT,OAAO,EAAE,YAAY,EAAE,CAAC;QACxB,UAAU,EAAE,MAAM,CAAC;QACnB,gBAAgB,CAAC,EAAE,OAAO,CAAC;KAC5B,CAAC,CAAC;IAEH;;;;;OAKG;IACH,aAAa,CAAC,IAAI,EAAE,WAAW,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;IAElD;;;;OAIG;IACH,MAAM,IAAI,OAAO,CAAC,OAAO,CAAC,CAAC;CAC5B"}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { type ChangeRecord, type StoredRecord } from '../../../shared/types.cjs';
|
|
2
|
+
import type { AppStorage } from '../app.cjs';
|
|
3
|
+
import type { TableStorage } from '../table.cjs';
|
|
4
|
+
import type { UserStorage } from '../user.cjs';
|
|
5
|
+
/**
|
|
6
|
+
* Common abstract base class for AppStorage implementations.
|
|
7
|
+
*/
|
|
8
|
+
export declare abstract class AppBaseStorage implements AppStorage {
|
|
9
|
+
readonly id: string;
|
|
10
|
+
constructor(id: string);
|
|
11
|
+
/** Creates/registers a new table within this application. */
|
|
12
|
+
abstract createTable(name: string): Promise<TableStorage>;
|
|
13
|
+
/** Retrieves a table handle if it exists. */
|
|
14
|
+
abstract getTable(name: string): Promise<TableStorage | undefined>;
|
|
15
|
+
/** Lists all registered tables in this application. */
|
|
16
|
+
abstract getTables(): Promise<TableStorage[]>;
|
|
17
|
+
/** Applies batch mutation changes for a user. */
|
|
18
|
+
abstract applyChanges(user: UserStorage, changes: ChangeRecord[]): Promise<{
|
|
19
|
+
applied: ChangeRecord[];
|
|
20
|
+
newSeq: number;
|
|
21
|
+
}>;
|
|
22
|
+
/** Retrieves changes for a user since a given sequence number. */
|
|
23
|
+
abstract getChangesSince(user: UserStorage, fromSeq: number): Promise<{
|
|
24
|
+
changes: ChangeRecord[];
|
|
25
|
+
currentSeq: number;
|
|
26
|
+
requiresSnapshot?: boolean;
|
|
27
|
+
}>;
|
|
28
|
+
/** Returns the current global sequence number for a user within this application. */
|
|
29
|
+
abstract getCurrentSeq(user: UserStorage): Promise<number>;
|
|
30
|
+
/** Deletes this entire application and all associated data. */
|
|
31
|
+
abstract delete(): Promise<boolean>;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Applies a change to an existing (or undefined) record and assigns the sequence number.
|
|
35
|
+
*/
|
|
36
|
+
export declare function applyChangeToRecord(change: ChangeRecord, existing: StoredRecord | undefined, seq: number): {
|
|
37
|
+
updatedRecord: StoredRecord;
|
|
38
|
+
appliedChange: ChangeRecord & {
|
|
39
|
+
seq: number;
|
|
40
|
+
};
|
|
41
|
+
};
|
|
42
|
+
//# sourceMappingURL=app.d.ts.map
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { type ChangeRecord, type StoredRecord } from '../../../shared/types.js';
|
|
2
|
+
import type { AppStorage } from '../app.js';
|
|
3
|
+
import type { TableStorage } from '../table.js';
|
|
4
|
+
import type { UserStorage } from '../user.js';
|
|
5
|
+
/**
|
|
6
|
+
* Common abstract base class for AppStorage implementations.
|
|
7
|
+
*/
|
|
8
|
+
export declare abstract class AppBaseStorage implements AppStorage {
|
|
9
|
+
readonly id: string;
|
|
10
|
+
constructor(id: string);
|
|
11
|
+
/** Creates/registers a new table within this application. */
|
|
12
|
+
abstract createTable(name: string): Promise<TableStorage>;
|
|
13
|
+
/** Retrieves a table handle if it exists. */
|
|
14
|
+
abstract getTable(name: string): Promise<TableStorage | undefined>;
|
|
15
|
+
/** Lists all registered tables in this application. */
|
|
16
|
+
abstract getTables(): Promise<TableStorage[]>;
|
|
17
|
+
/** Applies batch mutation changes for a user. */
|
|
18
|
+
abstract applyChanges(user: UserStorage, changes: ChangeRecord[]): Promise<{
|
|
19
|
+
applied: ChangeRecord[];
|
|
20
|
+
newSeq: number;
|
|
21
|
+
}>;
|
|
22
|
+
/** Retrieves changes for a user since a given sequence number. */
|
|
23
|
+
abstract getChangesSince(user: UserStorage, fromSeq: number): Promise<{
|
|
24
|
+
changes: ChangeRecord[];
|
|
25
|
+
currentSeq: number;
|
|
26
|
+
requiresSnapshot?: boolean;
|
|
27
|
+
}>;
|
|
28
|
+
/** Returns the current global sequence number for a user within this application. */
|
|
29
|
+
abstract getCurrentSeq(user: UserStorage): Promise<number>;
|
|
30
|
+
/** Deletes this entire application and all associated data. */
|
|
31
|
+
abstract delete(): Promise<boolean>;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Applies a change to an existing (or undefined) record and assigns the sequence number.
|
|
35
|
+
*/
|
|
36
|
+
export declare function applyChangeToRecord(change: ChangeRecord, existing: StoredRecord | undefined, seq: number): {
|
|
37
|
+
updatedRecord: StoredRecord;
|
|
38
|
+
appliedChange: ChangeRecord & {
|
|
39
|
+
seq: number;
|
|
40
|
+
};
|
|
41
|
+
};
|
|
42
|
+
//# sourceMappingURL=app.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"app.d.ts","sourceRoot":"","sources":["../../../../src/server/storage/base/app.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,YAAY,EAEjB,KAAK,YAAY,EAClB,MAAM,0BAA0B,CAAC;AAClC,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AAC5C,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAChD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAE9C;;GAEG;AACH,8BAAsB,cAAe,YAAW,UAAU;IACxD,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IAEpB,YAAY,EAAE,EAAE,MAAM,EAErB;IAED,6DAA6D;IAC7D,QAAQ,CAAC,WAAW,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,YAAY,CAAC,CAAC;IAE1D,6CAA6C;IAC7C,QAAQ,CAAC,QAAQ,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,YAAY,GAAG,SAAS,CAAC,CAAC;IAEnE,uDAAuD;IACvD,QAAQ,CAAC,SAAS,IAAI,OAAO,CAAC,YAAY,EAAE,CAAC,CAAC;IAE9C,iDAAiD;IACjD,QAAQ,CAAC,YAAY,CACnB,IAAI,EAAE,WAAW,EACjB,OAAO,EAAE,YAAY,EAAE,GACtB,OAAO,CAAC;QAAE,OAAO,EAAE,YAAY,EAAE,CAAC;QAAC,MAAM,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;IAExD,kEAAkE;IAClE,QAAQ,CAAC,eAAe,CACtB,IAAI,EAAE,WAAW,EACjB,OAAO,EAAE,MAAM,GACd,OAAO,CAAC;QACT,OAAO,EAAE,YAAY,EAAE,CAAC;QACxB,UAAU,EAAE,MAAM,CAAC;QACnB,gBAAgB,CAAC,EAAE,OAAO,CAAC;KAC5B,CAAC,CAAC;IAEH,qFAAqF;IACrF,QAAQ,CAAC,aAAa,CAAC,IAAI,EAAE,WAAW,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;IAE3D,+DAA+D;IAC/D,QAAQ,CAAC,MAAM,IAAI,OAAO,CAAC,OAAO,CAAC,CAAC;CACrC;AAED;;GAEG;AACH,wBAAgB,mBAAmB,CACjC,MAAM,EAAE,YAAY,EACpB,QAAQ,EAAE,YAAY,GAAG,SAAS,EAClC,GAAG,EAAE,MAAM,GACV;IACD,aAAa,EAAE,YAAY,CAAC;IAC5B,aAAa,EAAE,YAAY,GAAG;QAAE,GAAG,EAAE,MAAM,CAAA;KAAE,CAAC;CAC/C,CAyBA"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export { AppBaseStorage, applyChangeToRecord } from './app.cjs';
|
|
2
|
+
export { BaseStorage, buildAppSummaries, filterTargetApps, } from './storage.cjs';
|
|
3
|
+
export { filterActiveRecords, TableBaseStorage, targetChangesForTable, } from './table.cjs';
|
|
4
|
+
export { hashUserPassword, UserBaseStorage, verifyUserPassword, } from './user.cjs';
|
|
5
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export { AppBaseStorage, applyChangeToRecord } from './app.js';
|
|
2
|
+
export { BaseStorage, buildAppSummaries, filterTargetApps, } from './storage.js';
|
|
3
|
+
export { filterActiveRecords, TableBaseStorage, targetChangesForTable, } from './table.js';
|
|
4
|
+
export { hashUserPassword, UserBaseStorage, verifyUserPassword, } from './user.js';
|
|
5
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/server/storage/base/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,mBAAmB,EAAE,MAAM,UAAU,CAAC;AAC/D,OAAO,EACL,WAAW,EACX,iBAAiB,EACjB,gBAAgB,GACjB,MAAM,cAAc,CAAC;AACtB,OAAO,EACL,mBAAmB,EACnB,gBAAgB,EAChB,qBAAqB,GACtB,MAAM,YAAY,CAAC;AACpB,OAAO,EACL,gBAAgB,EAChB,eAAe,EACf,kBAAkB,GACnB,MAAM,WAAW,CAAC"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import type { AppStorage } from '../app.cjs';
|
|
2
|
+
import type { MaintenanceResult, Storage, StorageOptions, StorageStatus } from '../storage.cjs';
|
|
3
|
+
import type { UserStorage } from '../user.cjs';
|
|
4
|
+
/**
|
|
5
|
+
* Common abstract base class for Storage implementations.
|
|
6
|
+
*/
|
|
7
|
+
export declare abstract class BaseStorage implements Storage {
|
|
8
|
+
readonly options?: StorageOptions;
|
|
9
|
+
constructor(options?: StorageOptions);
|
|
10
|
+
/** Backend persistence type name ('file', 'memory', 'sqlite'). */
|
|
11
|
+
abstract readonly backend: string;
|
|
12
|
+
/** Secret key used for signing session tokens. */
|
|
13
|
+
abstract readonly secret: string;
|
|
14
|
+
/** Optional storage base directory if disk-backed. */
|
|
15
|
+
protected getBaseDir(): string | undefined;
|
|
16
|
+
abstract createApp(id: string): Promise<AppStorage>;
|
|
17
|
+
abstract getApp(id: string): Promise<AppStorage | undefined>;
|
|
18
|
+
abstract getApps(): Promise<AppStorage[]>;
|
|
19
|
+
abstract createUser(username: string, password: string): Promise<UserStorage>;
|
|
20
|
+
abstract getUser(id: string): Promise<UserStorage | undefined>;
|
|
21
|
+
abstract getUserByUsername(username: string): Promise<UserStorage | undefined>;
|
|
22
|
+
abstract getUsers(): Promise<UserStorage[]>;
|
|
23
|
+
abstract checkpoint(appId?: string): Promise<MaintenanceResult>;
|
|
24
|
+
abstract vacuum(appId?: string): Promise<MaintenanceResult>;
|
|
25
|
+
abstract prune(appId?: string, keepCount?: number): Promise<MaintenanceResult>;
|
|
26
|
+
getUserByToken(token: string): Promise<UserStorage | undefined>;
|
|
27
|
+
getStatus(appId?: string): Promise<StorageStatus>;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Filters the list of applications by an optional target appId, validating format and existence.
|
|
31
|
+
*/
|
|
32
|
+
export declare function filterTargetApps(allApps: AppStorage[], appId?: string): AppStorage[];
|
|
33
|
+
/**
|
|
34
|
+
* Builds array of application summaries including their table names.
|
|
35
|
+
*/
|
|
36
|
+
export declare function buildAppSummaries(apps: AppStorage[]): Promise<Array<{
|
|
37
|
+
id: string;
|
|
38
|
+
tables: string[];
|
|
39
|
+
}>>;
|
|
40
|
+
//# sourceMappingURL=storage.d.ts.map
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import type { AppStorage } from '../app.js';
|
|
2
|
+
import type { MaintenanceResult, Storage, StorageOptions, StorageStatus } from '../storage.js';
|
|
3
|
+
import type { UserStorage } from '../user.js';
|
|
4
|
+
/**
|
|
5
|
+
* Common abstract base class for Storage implementations.
|
|
6
|
+
*/
|
|
7
|
+
export declare abstract class BaseStorage implements Storage {
|
|
8
|
+
readonly options?: StorageOptions;
|
|
9
|
+
constructor(options?: StorageOptions);
|
|
10
|
+
/** Backend persistence type name ('file', 'memory', 'sqlite'). */
|
|
11
|
+
abstract readonly backend: string;
|
|
12
|
+
/** Secret key used for signing session tokens. */
|
|
13
|
+
abstract readonly secret: string;
|
|
14
|
+
/** Optional storage base directory if disk-backed. */
|
|
15
|
+
protected getBaseDir(): string | undefined;
|
|
16
|
+
abstract createApp(id: string): Promise<AppStorage>;
|
|
17
|
+
abstract getApp(id: string): Promise<AppStorage | undefined>;
|
|
18
|
+
abstract getApps(): Promise<AppStorage[]>;
|
|
19
|
+
abstract createUser(username: string, password: string): Promise<UserStorage>;
|
|
20
|
+
abstract getUser(id: string): Promise<UserStorage | undefined>;
|
|
21
|
+
abstract getUserByUsername(username: string): Promise<UserStorage | undefined>;
|
|
22
|
+
abstract getUsers(): Promise<UserStorage[]>;
|
|
23
|
+
abstract checkpoint(appId?: string): Promise<MaintenanceResult>;
|
|
24
|
+
abstract vacuum(appId?: string): Promise<MaintenanceResult>;
|
|
25
|
+
abstract prune(appId?: string, keepCount?: number): Promise<MaintenanceResult>;
|
|
26
|
+
getUserByToken(token: string): Promise<UserStorage | undefined>;
|
|
27
|
+
getStatus(appId?: string): Promise<StorageStatus>;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Filters the list of applications by an optional target appId, validating format and existence.
|
|
31
|
+
*/
|
|
32
|
+
export declare function filterTargetApps(allApps: AppStorage[], appId?: string): AppStorage[];
|
|
33
|
+
/**
|
|
34
|
+
* Builds array of application summaries including their table names.
|
|
35
|
+
*/
|
|
36
|
+
export declare function buildAppSummaries(apps: AppStorage[]): Promise<Array<{
|
|
37
|
+
id: string;
|
|
38
|
+
tables: string[];
|
|
39
|
+
}>>;
|
|
40
|
+
//# sourceMappingURL=storage.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"storage.d.ts","sourceRoot":"","sources":["../../../../src/server/storage/base/storage.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AAC5C,OAAO,KAAK,EACV,iBAAiB,EACjB,OAAO,EACP,cAAc,EACd,aAAa,EACd,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AAC,CAAC;IAC5D,QAAQ,CAAC,KAAK,CACZ,KAAK,CAAC,EAAE,MAAM,EACd,SAAS,CAAC,EAAE,MAAM,GACjB,OAAO,CAAC,iBAAiB,CAAC,CAAC;IAExB,cAAc,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,WAAW,GAAG,SAAS,CAAC,CAIpE;IAEK,SAAS,CAAC,KAAK,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,aAAa,CAAC,CAiBtD;CACF;AAED;;GAEG;AACH,wBAAgB,gBAAgB,CAC9B,OAAO,EAAE,UAAU,EAAE,EACrB,KAAK,CAAC,EAAE,MAAM,GACb,UAAU,EAAE,CAad;AAED;;GAEG;AACH,wBAAsB,iBAAiB,CACrC,IAAI,EAAE,UAAU,EAAE,GACjB,OAAO,CAAC,KAAK,CAAC;IAAE,EAAE,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,EAAE,CAAA;CAAE,CAAC,CAAC,CAUlD"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import type { ChangeRecord, SnapshotRecord, StoredRecord } from '../../../shared/types.cjs';
|
|
2
|
+
import type { AppStorage } from '../app.cjs';
|
|
3
|
+
import type { TableStorage } from '../table.cjs';
|
|
4
|
+
import type { UserStorage } from '../user.cjs';
|
|
5
|
+
/**
|
|
6
|
+
* Common abstract base class for TableStorage implementations.
|
|
7
|
+
*/
|
|
8
|
+
export declare abstract class TableBaseStorage implements TableStorage {
|
|
9
|
+
readonly name: string;
|
|
10
|
+
readonly app: AppStorage;
|
|
11
|
+
constructor(name: string, app: AppStorage);
|
|
12
|
+
/** Retrieves a single record for a user. */
|
|
13
|
+
abstract getRecord(user: UserStorage, id: string): Promise<StoredRecord | undefined>;
|
|
14
|
+
/** Retrieves all active records in this table for a user. */
|
|
15
|
+
abstract getAllRecords(user: UserStorage): Promise<SnapshotRecord[]>;
|
|
16
|
+
/** Deletes this table and its data. */
|
|
17
|
+
abstract delete(): Promise<boolean>;
|
|
18
|
+
/** Applies batch mutation changes to this table. */
|
|
19
|
+
applyChanges(user: UserStorage, changes: ChangeRecord[]): Promise<{
|
|
20
|
+
applied: ChangeRecord[];
|
|
21
|
+
newSeq: number;
|
|
22
|
+
}>;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Filters non-deleted records and attaches table name for snapshot responses.
|
|
26
|
+
*/
|
|
27
|
+
export declare function filterActiveRecords(tableName: string, records: Iterable<StoredRecord>): SnapshotRecord[];
|
|
28
|
+
/**
|
|
29
|
+
* Targets generic changes with table name and app ID.
|
|
30
|
+
*/
|
|
31
|
+
export declare function targetChangesForTable(tableName: string, appId: string, changes: ChangeRecord[]): ChangeRecord[];
|
|
32
|
+
//# sourceMappingURL=table.d.ts.map
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import type { ChangeRecord, SnapshotRecord, StoredRecord } from '../../../shared/types.js';
|
|
2
|
+
import type { AppStorage } from '../app.js';
|
|
3
|
+
import type { TableStorage } from '../table.js';
|
|
4
|
+
import type { UserStorage } from '../user.js';
|
|
5
|
+
/**
|
|
6
|
+
* Common abstract base class for TableStorage implementations.
|
|
7
|
+
*/
|
|
8
|
+
export declare abstract class TableBaseStorage implements TableStorage {
|
|
9
|
+
readonly name: string;
|
|
10
|
+
readonly app: AppStorage;
|
|
11
|
+
constructor(name: string, app: AppStorage);
|
|
12
|
+
/** Retrieves a single record for a user. */
|
|
13
|
+
abstract getRecord(user: UserStorage, id: string): Promise<StoredRecord | undefined>;
|
|
14
|
+
/** Retrieves all active records in this table for a user. */
|
|
15
|
+
abstract getAllRecords(user: UserStorage): Promise<SnapshotRecord[]>;
|
|
16
|
+
/** Deletes this table and its data. */
|
|
17
|
+
abstract delete(): Promise<boolean>;
|
|
18
|
+
/** Applies batch mutation changes to this table. */
|
|
19
|
+
applyChanges(user: UserStorage, changes: ChangeRecord[]): Promise<{
|
|
20
|
+
applied: ChangeRecord[];
|
|
21
|
+
newSeq: number;
|
|
22
|
+
}>;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Filters non-deleted records and attaches table name for snapshot responses.
|
|
26
|
+
*/
|
|
27
|
+
export declare function filterActiveRecords(tableName: string, records: Iterable<StoredRecord>): SnapshotRecord[];
|
|
28
|
+
/**
|
|
29
|
+
* Targets generic changes with table name and app ID.
|
|
30
|
+
*/
|
|
31
|
+
export declare function targetChangesForTable(tableName: string, appId: string, changes: ChangeRecord[]): ChangeRecord[];
|
|
32
|
+
//# sourceMappingURL=table.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"table.d.ts","sourceRoot":"","sources":["../../../../src/server/storage/base/table.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,YAAY,EACZ,cAAc,EACd,YAAY,EACb,MAAM,0BAA0B,CAAC;AAClC,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AAC5C,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAChD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAE9C;;GAEG;AACH,8BAAsB,gBAAiB,YAAW,YAAY;IAC5D,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,GAAG,EAAE,UAAU,CAAC;IAEzB,YAAY,IAAI,EAAE,MAAM,EAAE,GAAG,EAAE,UAAU,EAGxC;IAED,4CAA4C;IAC5C,QAAQ,CAAC,SAAS,CAChB,IAAI,EAAE,WAAW,EACjB,EAAE,EAAE,MAAM,GACT,OAAO,CAAC,YAAY,GAAG,SAAS,CAAC,CAAC;IAErC,6DAA6D;IAC7D,QAAQ,CAAC,aAAa,CAAC,IAAI,EAAE,WAAW,GAAG,OAAO,CAAC,cAAc,EAAE,CAAC,CAAC;IAErE,uCAAuC;IACvC,QAAQ,CAAC,MAAM,IAAI,OAAO,CAAC,OAAO,CAAC,CAAC;IAEpC,oDAAoD;IAC9C,YAAY,CAChB,IAAI,EA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