@korajs/server 0.4.0 → 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.
- package/README.md +10 -0
- package/dist/index.cjs +1459 -57
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +302 -9
- package/dist/index.d.ts +302 -9
- package/dist/index.js +1286 -39
- package/dist/index.js.map +1 -1
- package/dist/internal.cjs +1 -1
- package/dist/internal.cjs.map +1 -1
- package/dist/internal.js +1 -1
- package/dist/internal.js.map +1 -1
- package/dist/server-backup-MOICK6MI.js +116 -0
- package/dist/server-backup-MOICK6MI.js.map +1 -0
- package/package.json +4 -3
package/dist/index.d.ts
CHANGED
|
@@ -1,10 +1,129 @@
|
|
|
1
1
|
import { SchemaDefinition, KoraEventEmitter, Operation, VersionVector } from '@korajs/core';
|
|
2
2
|
import * as _korajs_sync from '@korajs/sync';
|
|
3
|
-
import { SyncStore, MessageSerializer, SyncMessage, AwarenessUpdateMessage, ApplyResult } from '@korajs/sync';
|
|
3
|
+
import { SyncStore, MessageSerializer, SyncMessage, AwarenessUpdateMessage, YjsDocUpdateMessage, ApplyResult } from '@korajs/sync';
|
|
4
4
|
import { S as ServerTransport, a as ServerMessageHandler, b as ServerCloseHandler, c as ServerErrorHandler } from './server-transport-CU1BLWgr.js';
|
|
5
5
|
import { PostgresJsDatabase } from 'drizzle-orm/postgres-js';
|
|
6
6
|
import { BetterSQLite3Database } from 'drizzle-orm/better-sqlite3';
|
|
7
7
|
|
|
8
|
+
/**
|
|
9
|
+
* Snapshot of server-side sync metrics at a point in time.
|
|
10
|
+
*/
|
|
11
|
+
interface ServerMetricsSnapshot {
|
|
12
|
+
connectedClients: number;
|
|
13
|
+
connectedNodeIds: string[];
|
|
14
|
+
peakConnections: number;
|
|
15
|
+
connectionsTotal: number;
|
|
16
|
+
operationsReceived: number;
|
|
17
|
+
operationsSent: number;
|
|
18
|
+
bytesReceived: number;
|
|
19
|
+
bytesSent: number;
|
|
20
|
+
clients: ClientMetrics[];
|
|
21
|
+
uptime: number;
|
|
22
|
+
totalOperations: number;
|
|
23
|
+
errorCount: number;
|
|
24
|
+
schemaVersion: number;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Per-client metrics tracked by the server.
|
|
28
|
+
*/
|
|
29
|
+
interface ClientMetrics {
|
|
30
|
+
sessionId: string;
|
|
31
|
+
nodeId: string | null;
|
|
32
|
+
state: SessionState$1;
|
|
33
|
+
connectedAt: number;
|
|
34
|
+
operationsReceived: number;
|
|
35
|
+
operationsSent: number;
|
|
36
|
+
authContext: AuthContext | null;
|
|
37
|
+
}
|
|
38
|
+
declare class ServerMetricsCollector {
|
|
39
|
+
private startedAt;
|
|
40
|
+
private peakConnections;
|
|
41
|
+
private connectionsTotal;
|
|
42
|
+
private operationsReceived;
|
|
43
|
+
private operationsSent;
|
|
44
|
+
private bytesReceived;
|
|
45
|
+
private bytesSent;
|
|
46
|
+
private errorCount;
|
|
47
|
+
private schemaVersion;
|
|
48
|
+
private readonly clientMetrics;
|
|
49
|
+
/** Record a new client connection. */
|
|
50
|
+
recordConnection(sessionId: string): void;
|
|
51
|
+
/** Record a client disconnection. */
|
|
52
|
+
recordDisconnection(sessionId: string): void;
|
|
53
|
+
/** Update the node ID after a handshake completes. */
|
|
54
|
+
recordHandshake(sessionId: string, nodeId: string): void;
|
|
55
|
+
/** Update session state. */
|
|
56
|
+
updateSessionState(sessionId: string, state: SessionState$1): void;
|
|
57
|
+
/** Record authentication context for a session. */
|
|
58
|
+
recordAuth(sessionId: string, authContext: AuthContext | null): void;
|
|
59
|
+
/** Record operations received from a client. */
|
|
60
|
+
recordReceived(sessionId: string, count: number, byteSize: number): void;
|
|
61
|
+
/** Record operations sent to a client. */
|
|
62
|
+
recordSent(sessionId: string, count: number, byteSize: number): void;
|
|
63
|
+
/** Record an error. */
|
|
64
|
+
recordError(): void;
|
|
65
|
+
/** Set the schema version. */
|
|
66
|
+
setSchemaVersion(version: number): void;
|
|
67
|
+
/** Return a full snapshot of current metrics. */
|
|
68
|
+
getSnapshot(totalOperations: number): ServerMetricsSnapshot;
|
|
69
|
+
/** Reset all metrics. */
|
|
70
|
+
reset(): void;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* Log severity levels.
|
|
75
|
+
*/
|
|
76
|
+
type LogLevel = 'info' | 'warn' | 'error';
|
|
77
|
+
/**
|
|
78
|
+
* A structured log entry with timestamp and metadata.
|
|
79
|
+
*/
|
|
80
|
+
interface LogEntry {
|
|
81
|
+
timestamp: number;
|
|
82
|
+
level: LogLevel;
|
|
83
|
+
event: string;
|
|
84
|
+
sessionId?: string;
|
|
85
|
+
nodeId?: string;
|
|
86
|
+
duration?: number;
|
|
87
|
+
count?: number;
|
|
88
|
+
bytes?: number;
|
|
89
|
+
error?: string;
|
|
90
|
+
details?: Record<string, unknown>;
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Logger interface for structured logging.
|
|
94
|
+
* Implementations control output format and destination.
|
|
95
|
+
*/
|
|
96
|
+
interface Logger {
|
|
97
|
+
log(entry: LogEntry): void;
|
|
98
|
+
child?(context: Partial<LogEntry>): Logger;
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Creates a JSON-lines logger that writes to stdout/stderr.
|
|
102
|
+
* Suitable for production use where log aggregators (Datadog, Loki, etc.) consume JSON.
|
|
103
|
+
*/
|
|
104
|
+
declare function createJsonLogger(writer?: {
|
|
105
|
+
info: (s: string) => void;
|
|
106
|
+
error: (s: string) => void;
|
|
107
|
+
}): Logger;
|
|
108
|
+
/**
|
|
109
|
+
* Creates a pretty-printed logger for development use.
|
|
110
|
+
* Writes human-readable colored output to the terminal.
|
|
111
|
+
*/
|
|
112
|
+
declare function createPrettyLogger(writer?: {
|
|
113
|
+
write: (s: string) => void;
|
|
114
|
+
}): Logger;
|
|
115
|
+
/**
|
|
116
|
+
* A logger that discards all entries (for testing or when logging is disabled).
|
|
117
|
+
*/
|
|
118
|
+
declare function createSilentLogger(): Logger;
|
|
119
|
+
/**
|
|
120
|
+
* Creates a logger based on the NODE_ENV environment variable.
|
|
121
|
+
* - production: JSON lines to stdout/stderr
|
|
122
|
+
* - test: silent
|
|
123
|
+
* - otherwise: pretty-printed to stdout
|
|
124
|
+
*/
|
|
125
|
+
declare function createDefaultLogger(): Logger;
|
|
126
|
+
|
|
8
127
|
/**
|
|
9
128
|
* A materialized record reconstructed from the operation log
|
|
10
129
|
* or read from a materialized collection table.
|
|
@@ -48,6 +167,8 @@ interface ServerStore extends SyncStore {
|
|
|
48
167
|
* @param schema - The schema definition describing all collections
|
|
49
168
|
*/
|
|
50
169
|
setSchema(schema: SchemaDefinition): Promise<void>;
|
|
170
|
+
/** Schema used for materialized tables and server-side validation, if set. */
|
|
171
|
+
getSchema(): SchemaDefinition | null;
|
|
51
172
|
/**
|
|
52
173
|
* Get all records from a materialized collection.
|
|
53
174
|
* When schema is set, reads directly from the collection table (O(1) indexed).
|
|
@@ -85,6 +206,23 @@ interface ServerStore extends SyncStore {
|
|
|
85
206
|
* @returns Number of matching records
|
|
86
207
|
*/
|
|
87
208
|
countCollection(collection: string, where?: Record<string, unknown>): Promise<number>;
|
|
209
|
+
/**
|
|
210
|
+
* Export all data as a portable backup binary.
|
|
211
|
+
* Ships operations, version vector, and metadata in a self-describing format
|
|
212
|
+
* with SHA-256 checksum.
|
|
213
|
+
*/
|
|
214
|
+
exportBackup(): Promise<Uint8Array>;
|
|
215
|
+
/**
|
|
216
|
+
* Restore data from a portable backup binary.
|
|
217
|
+
* Operations are applied through applyRemoteOperation for safe merge.
|
|
218
|
+
*
|
|
219
|
+
* @param data - Backup binary
|
|
220
|
+
* @param merge - If true, merge with existing operations; if false, replace all
|
|
221
|
+
*/
|
|
222
|
+
importBackup(data: Uint8Array, merge?: boolean): Promise<{
|
|
223
|
+
operationsRestored: number;
|
|
224
|
+
success: boolean;
|
|
225
|
+
}>;
|
|
88
226
|
}
|
|
89
227
|
|
|
90
228
|
/**
|
|
@@ -132,8 +270,22 @@ interface KoraSyncServerConfig {
|
|
|
132
270
|
batchSize?: number;
|
|
133
271
|
/** Schema version the server expects. Defaults to 1. */
|
|
134
272
|
schemaVersion?: number;
|
|
273
|
+
/**
|
|
274
|
+
* Inclusive range of client schema versions accepted at handshake.
|
|
275
|
+
* Defaults to `{ min: schemaVersion, max: schemaVersion }`.
|
|
276
|
+
*/
|
|
277
|
+
supportedSchemaVersions?: {
|
|
278
|
+
min: number;
|
|
279
|
+
max: number;
|
|
280
|
+
};
|
|
135
281
|
/** WebSocket path (standalone mode). Defaults to '/'. */
|
|
136
282
|
path?: string;
|
|
283
|
+
/** Structured logger. Defaults to pretty-print in dev, JSON lines in production. */
|
|
284
|
+
logger?: Logger;
|
|
285
|
+
/** Server metrics collector. Created automatically if omitted. */
|
|
286
|
+
metricsCollector?: ServerMetricsCollector;
|
|
287
|
+
/** Enable built-in dashboard and metrics endpoints. Defaults to true. */
|
|
288
|
+
enableDashboard?: boolean;
|
|
137
289
|
}
|
|
138
290
|
/**
|
|
139
291
|
* Request envelope for the server-side HTTP sync endpoint.
|
|
@@ -161,6 +313,15 @@ interface HttpSyncResponse {
|
|
|
161
313
|
/** Optional response headers */
|
|
162
314
|
headers?: Record<string, string>;
|
|
163
315
|
}
|
|
316
|
+
/**
|
|
317
|
+
* Session state machine states.
|
|
318
|
+
* - connected: initial state after transport connects
|
|
319
|
+
* - authenticated: auth check passed (or skipped)
|
|
320
|
+
* - syncing: exchanging delta operations during handshake
|
|
321
|
+
* - streaming: steady state, real-time operation relay
|
|
322
|
+
* - closed: session terminated
|
|
323
|
+
*/
|
|
324
|
+
type SessionState$1 = 'connected' | 'authenticated' | 'syncing' | 'streaming' | 'closed';
|
|
164
325
|
/**
|
|
165
326
|
* Runtime status of a KoraSyncServer.
|
|
166
327
|
*/
|
|
@@ -173,6 +334,24 @@ interface ServerStatus {
|
|
|
173
334
|
port: number | null;
|
|
174
335
|
/** Total operations stored */
|
|
175
336
|
totalOperations: number;
|
|
337
|
+
/** Server uptime in milliseconds */
|
|
338
|
+
uptime: number;
|
|
339
|
+
/** Server package version */
|
|
340
|
+
version: string;
|
|
341
|
+
/** Schema version the server expects */
|
|
342
|
+
schemaVersion: number;
|
|
343
|
+
/** Array of connected node IDs */
|
|
344
|
+
connectedNodeIds: string[];
|
|
345
|
+
/** Peak connections since server start */
|
|
346
|
+
peakConnections: number;
|
|
347
|
+
/** Total connections handled since server start */
|
|
348
|
+
connectionsTotal: number;
|
|
349
|
+
/** Operations received since server start */
|
|
350
|
+
operationsReceived: number;
|
|
351
|
+
/** Operations sent since server start */
|
|
352
|
+
operationsSent: number;
|
|
353
|
+
/** Error count since server start */
|
|
354
|
+
errorCount: number;
|
|
176
355
|
}
|
|
177
356
|
|
|
178
357
|
interface HttpPollResponse {
|
|
@@ -256,6 +435,10 @@ type RelayCallback = (sourceSessionId: string, operations: Operation[]) => void;
|
|
|
256
435
|
* Callback invoked when a session receives an awareness update to relay to other sessions.
|
|
257
436
|
*/
|
|
258
437
|
type AwarenessRelayCallback = (sourceSessionId: string, message: AwarenessUpdateMessage) => void;
|
|
438
|
+
/**
|
|
439
|
+
* Callback invoked when a session receives a Yjs doc channel update to relay.
|
|
440
|
+
*/
|
|
441
|
+
type YjsDocRelayCallback = (sourceSessionId: string, message: YjsDocUpdateMessage) => void;
|
|
259
442
|
/**
|
|
260
443
|
* Options for creating a ClientSession.
|
|
261
444
|
*/
|
|
@@ -276,12 +459,23 @@ interface ClientSessionOptions {
|
|
|
276
459
|
batchSize?: number;
|
|
277
460
|
/** Schema version the server expects */
|
|
278
461
|
schemaVersion?: number;
|
|
462
|
+
/** Inclusive client schema versions accepted at handshake */
|
|
463
|
+
supportedSchemaVersions?: {
|
|
464
|
+
min: number;
|
|
465
|
+
max: number;
|
|
466
|
+
};
|
|
279
467
|
/** Called when this session has operations to relay to other sessions */
|
|
280
468
|
onRelay?: RelayCallback;
|
|
281
469
|
/** Called when this session receives an awareness update to broadcast */
|
|
282
470
|
onAwarenessUpdate?: AwarenessRelayCallback;
|
|
471
|
+
/** Called when this session receives a Yjs doc channel update to broadcast */
|
|
472
|
+
onYjsDocUpdate?: YjsDocRelayCallback;
|
|
283
473
|
/** Called when this session closes */
|
|
284
474
|
onClose?: (sessionId: string) => void;
|
|
475
|
+
/** Maximum serialized operation size in bytes. Defaults to 256 KiB. */
|
|
476
|
+
maxOperationBytes?: number;
|
|
477
|
+
/** Maximum operations accepted per minute for this session. Defaults to 600. */
|
|
478
|
+
maxOpsPerMinute?: number;
|
|
285
479
|
}
|
|
286
480
|
/**
|
|
287
481
|
* Handles the sync protocol for a single connected client.
|
|
@@ -301,6 +495,8 @@ declare class ClientSession {
|
|
|
301
495
|
private state;
|
|
302
496
|
private clientNodeId;
|
|
303
497
|
private authContext;
|
|
498
|
+
private syncQuerySubsets;
|
|
499
|
+
private resumeDeltaCursor;
|
|
304
500
|
private readonly sessionId;
|
|
305
501
|
private readonly transport;
|
|
306
502
|
private readonly store;
|
|
@@ -309,9 +505,14 @@ declare class ClientSession {
|
|
|
309
505
|
private readonly emitter;
|
|
310
506
|
private readonly batchSize;
|
|
311
507
|
private readonly schemaVersion;
|
|
508
|
+
private readonly supportedSchemaVersions;
|
|
312
509
|
private readonly onRelay;
|
|
313
510
|
private readonly onAwarenessUpdate;
|
|
511
|
+
private readonly onYjsDocUpdate;
|
|
314
512
|
private readonly onClose;
|
|
513
|
+
private readonly maxOperationBytes;
|
|
514
|
+
private readonly maxOpsPerMinute;
|
|
515
|
+
private readonly rateLimiter;
|
|
315
516
|
constructor(options: ClientSessionOptions);
|
|
316
517
|
/**
|
|
317
518
|
* Start handling messages from the client transport.
|
|
@@ -336,11 +537,18 @@ declare class ClientSession {
|
|
|
336
537
|
* Used by the awareness relay to send messages to this client.
|
|
337
538
|
*/
|
|
338
539
|
getTransport(): ServerTransport;
|
|
339
|
-
private
|
|
540
|
+
private messageChain;
|
|
541
|
+
/** Send to the client when the transport is still connected; no-op otherwise. */
|
|
542
|
+
private sendToClient;
|
|
543
|
+
private enqueueMessage;
|
|
544
|
+
private handleMessageAsync;
|
|
545
|
+
private handleMessageFailure;
|
|
340
546
|
private handleHandshake;
|
|
341
547
|
private handleOperationBatch;
|
|
342
548
|
private sendDelta;
|
|
549
|
+
private operationVisibleToClient;
|
|
343
550
|
private handleAwarenessUpdate;
|
|
551
|
+
private handleYjsDocUpdate;
|
|
344
552
|
private sendError;
|
|
345
553
|
private setSerializerWireFormat;
|
|
346
554
|
private handleTransportClose;
|
|
@@ -382,16 +590,34 @@ declare class KoraSyncServer {
|
|
|
382
590
|
private readonly maxConnections;
|
|
383
591
|
private readonly batchSize;
|
|
384
592
|
private readonly schemaVersion;
|
|
593
|
+
private readonly supportedSchemaVersions;
|
|
385
594
|
private readonly port;
|
|
386
595
|
private readonly host;
|
|
387
596
|
private readonly path;
|
|
597
|
+
private readonly logger;
|
|
598
|
+
private readonly metrics;
|
|
388
599
|
private readonly awarenessRelay;
|
|
600
|
+
private readonly yjsDocRelay;
|
|
389
601
|
private readonly sessions;
|
|
390
602
|
private readonly httpClients;
|
|
391
603
|
private readonly httpSessionToClient;
|
|
604
|
+
private readonly serverVersion;
|
|
392
605
|
private wsServer;
|
|
393
606
|
private running;
|
|
394
607
|
constructor(config: KoraSyncServerConfig);
|
|
608
|
+
/**
|
|
609
|
+
* Subscribe to session-level events for metrics collection and logging.
|
|
610
|
+
* Called when a new session is created.
|
|
611
|
+
*/
|
|
612
|
+
private attachSessionEvents;
|
|
613
|
+
/**
|
|
614
|
+
* Get the metrics collector for external access (e.g., HTTP endpoints).
|
|
615
|
+
*/
|
|
616
|
+
getMetricsCollector(): ServerMetricsCollector;
|
|
617
|
+
/**
|
|
618
|
+
* Get the logger for external access (e.g., event streaming).
|
|
619
|
+
*/
|
|
620
|
+
getLogger(): Logger;
|
|
395
621
|
/**
|
|
396
622
|
* Start the WebSocket server in standalone mode.
|
|
397
623
|
*
|
|
@@ -427,6 +653,7 @@ declare class KoraSyncServer {
|
|
|
427
653
|
private handleRelay;
|
|
428
654
|
private handleSessionClose;
|
|
429
655
|
private handleAwarenessRelay;
|
|
656
|
+
private handleYjsDocRelay;
|
|
430
657
|
private getOrCreateHttpClient;
|
|
431
658
|
}
|
|
432
659
|
|
|
@@ -445,6 +672,48 @@ interface ProductionServerConfig {
|
|
|
445
672
|
syncPath?: string;
|
|
446
673
|
/** Additional KoraSyncServer options */
|
|
447
674
|
syncOptions?: Omit<KoraSyncServerConfig, 'store' | 'port' | 'host' | 'path'>;
|
|
675
|
+
/**
|
|
676
|
+
* Optional HTTP route handlers mounted before static file serving.
|
|
677
|
+
*
|
|
678
|
+
* This is intentionally framework-agnostic so packages such as
|
|
679
|
+
* `@korajs/auth` can plug into the production server without requiring
|
|
680
|
+
* Express, Hono, or another HTTP framework.
|
|
681
|
+
*/
|
|
682
|
+
httpRoutes?: ProductionHttpRoute[];
|
|
683
|
+
/**
|
|
684
|
+
* Optional token protection for operational endpoints.
|
|
685
|
+
*
|
|
686
|
+
* When a token is omitted, the matching endpoint group remains public for
|
|
687
|
+
* backward compatibility. Production apps should set at least adminToken and
|
|
688
|
+
* backupToken.
|
|
689
|
+
*/
|
|
690
|
+
operationalAuth?: ProductionOperationalAuth;
|
|
691
|
+
}
|
|
692
|
+
interface ProductionOperationalAuth {
|
|
693
|
+
/** Protects /__kora, /__kora/status, and /__kora/events. */
|
|
694
|
+
adminToken?: string;
|
|
695
|
+
/** Protects /__kora/metrics. Falls back to adminToken when omitted. */
|
|
696
|
+
metricsToken?: string;
|
|
697
|
+
/** Protects /__kora/backup/*. Falls back to adminToken when omitted. */
|
|
698
|
+
backupToken?: string;
|
|
699
|
+
}
|
|
700
|
+
interface ProductionHttpRouteRequest {
|
|
701
|
+
method: string;
|
|
702
|
+
path: string;
|
|
703
|
+
body?: unknown;
|
|
704
|
+
headers?: Record<string, string | string[] | undefined>;
|
|
705
|
+
query?: Record<string, string | string[] | undefined>;
|
|
706
|
+
ip?: string;
|
|
707
|
+
}
|
|
708
|
+
interface ProductionHttpRouteResponse {
|
|
709
|
+
status: number;
|
|
710
|
+
body?: unknown;
|
|
711
|
+
headers?: Record<string, string>;
|
|
712
|
+
}
|
|
713
|
+
interface ProductionHttpRoute {
|
|
714
|
+
/** URL path prefix, for example `/auth`. */
|
|
715
|
+
path: string;
|
|
716
|
+
handle(request: ProductionHttpRouteRequest): Promise<ProductionHttpRouteResponse>;
|
|
448
717
|
}
|
|
449
718
|
/**
|
|
450
719
|
* A production server handle returned by createProductionServer.
|
|
@@ -457,22 +726,17 @@ interface ProductionServer {
|
|
|
457
726
|
}
|
|
458
727
|
/**
|
|
459
728
|
* Creates a production server that serves both static files and WebSocket sync
|
|
460
|
-
* on a single port
|
|
461
|
-
* means one tunnel (ngrok, cloudflared) handles everything.
|
|
729
|
+
* on a single port, plus built-in dashboard and observability endpoints.
|
|
462
730
|
*
|
|
463
731
|
* @param config - Production server configuration
|
|
464
732
|
* @returns A ProductionServer instance
|
|
465
733
|
*
|
|
466
734
|
* @example
|
|
467
735
|
* ```typescript
|
|
468
|
-
* import { createProductionServer, createSqliteServerStore } from '@korajs/server'
|
|
469
|
-
*
|
|
470
736
|
* const server = createProductionServer({
|
|
471
737
|
* store: createSqliteServerStore({ filename: './kora-server.db' }),
|
|
472
738
|
* })
|
|
473
|
-
*
|
|
474
739
|
* const url = await server.start()
|
|
475
|
-
* console.log(`App running at ${url}`)
|
|
476
740
|
* ```
|
|
477
741
|
*/
|
|
478
742
|
declare function createProductionServer(config: ProductionServerConfig): ProductionServer;
|
|
@@ -517,6 +781,11 @@ interface TokenValidator {
|
|
|
517
781
|
dev: string;
|
|
518
782
|
type: string;
|
|
519
783
|
} | null;
|
|
784
|
+
validateTokenWithRevocation?(token: string): Promise<{
|
|
785
|
+
sub: string;
|
|
786
|
+
dev: string;
|
|
787
|
+
type: string;
|
|
788
|
+
} | null>;
|
|
520
789
|
}
|
|
521
790
|
/**
|
|
522
791
|
* Looks up a user by ID. Returns null if the user doesn't exist.
|
|
@@ -543,6 +812,8 @@ interface KoraAuthProviderOptions {
|
|
|
543
812
|
/**
|
|
544
813
|
* Token validator that verifies JWT signatures and returns claims.
|
|
545
814
|
* Typically a `TokenManager` instance from `@korajs/auth/server`.
|
|
815
|
+
* If the validator also implements `validateTokenWithRevocation`, the sync
|
|
816
|
+
* server uses it so signed-out sessions and revoked devices are rejected.
|
|
546
817
|
*/
|
|
547
818
|
tokenValidator: TokenValidator;
|
|
548
819
|
/**
|
|
@@ -701,6 +972,7 @@ declare class MemoryServerStore implements ServerStore {
|
|
|
701
972
|
constructor(nodeId?: string);
|
|
702
973
|
getVersionVector(): VersionVector;
|
|
703
974
|
getNodeId(): string;
|
|
975
|
+
getSchema(): SchemaDefinition | null;
|
|
704
976
|
setSchema(schema: SchemaDefinition): Promise<void>;
|
|
705
977
|
applyRemoteOperation(op: Operation): Promise<ApplyResult>;
|
|
706
978
|
getOperationRange(nodeId: string, fromSeq: number, toSeq: number): Promise<Operation[]>;
|
|
@@ -710,6 +982,15 @@ declare class MemoryServerStore implements ServerStore {
|
|
|
710
982
|
findRecord(collection: string, id: string): Promise<MaterializedRecord | null>;
|
|
711
983
|
countCollection(collection: string, where?: Record<string, unknown>): Promise<number>;
|
|
712
984
|
close(): Promise<void>;
|
|
985
|
+
/**
|
|
986
|
+
* Wipes all in-memory state. For tests and E2E isolation only.
|
|
987
|
+
*/
|
|
988
|
+
resetForTests(): void;
|
|
989
|
+
exportBackup(): Promise<Uint8Array>;
|
|
990
|
+
importBackup(data: Uint8Array, merge?: boolean): Promise<{
|
|
991
|
+
operationsRestored: number;
|
|
992
|
+
success: boolean;
|
|
993
|
+
}>;
|
|
713
994
|
/**
|
|
714
995
|
* Get all stored operations (for test assertions).
|
|
715
996
|
*/
|
|
@@ -739,6 +1020,7 @@ declare class PostgresServerStore implements ServerStore {
|
|
|
739
1020
|
constructor(db: PostgresJsDatabase, nodeId?: string);
|
|
740
1021
|
getVersionVector(): VersionVector;
|
|
741
1022
|
getNodeId(): string;
|
|
1023
|
+
getSchema(): SchemaDefinition | null;
|
|
742
1024
|
setSchema(schema: SchemaDefinition): Promise<void>;
|
|
743
1025
|
applyRemoteOperation(op: Operation): Promise<ApplyResult>;
|
|
744
1026
|
getOperationRange(nodeId: string, fromSeq: number, toSeq: number): Promise<Operation[]>;
|
|
@@ -748,6 +1030,11 @@ declare class PostgresServerStore implements ServerStore {
|
|
|
748
1030
|
findRecord(collection: string, id: string): Promise<MaterializedRecord | null>;
|
|
749
1031
|
countCollection(collection: string, where?: Record<string, unknown>): Promise<number>;
|
|
750
1032
|
close(): Promise<void>;
|
|
1033
|
+
exportBackup(): Promise<Uint8Array>;
|
|
1034
|
+
importBackup(data: Uint8Array, merge?: boolean): Promise<{
|
|
1035
|
+
operationsRestored: number;
|
|
1036
|
+
success: boolean;
|
|
1037
|
+
}>;
|
|
751
1038
|
/**
|
|
752
1039
|
* Rebuild a single record in the materialized collection table by replaying
|
|
753
1040
|
* all operations for that record.
|
|
@@ -801,6 +1088,7 @@ declare class SqliteServerStore implements ServerStore {
|
|
|
801
1088
|
constructor(db: BetterSQLite3Database, nodeId?: string);
|
|
802
1089
|
getVersionVector(): VersionVector;
|
|
803
1090
|
getNodeId(): string;
|
|
1091
|
+
getSchema(): SchemaDefinition | null;
|
|
804
1092
|
setSchema(schema: SchemaDefinition): Promise<void>;
|
|
805
1093
|
applyRemoteOperation(op: Operation): Promise<ApplyResult>;
|
|
806
1094
|
getOperationRange(nodeId: string, fromSeq: number, toSeq: number): Promise<Operation[]>;
|
|
@@ -810,6 +1098,11 @@ declare class SqliteServerStore implements ServerStore {
|
|
|
810
1098
|
findRecord(collection: string, id: string): Promise<MaterializedRecord | null>;
|
|
811
1099
|
countCollection(collection: string, where?: Record<string, unknown>): Promise<number>;
|
|
812
1100
|
close(): Promise<void>;
|
|
1101
|
+
exportBackup(): Promise<Uint8Array>;
|
|
1102
|
+
importBackup(data: Uint8Array, merge?: boolean): Promise<{
|
|
1103
|
+
operationsRestored: number;
|
|
1104
|
+
success: boolean;
|
|
1105
|
+
}>;
|
|
813
1106
|
/**
|
|
814
1107
|
* Rebuild a single record in the materialized collection table by replaying
|
|
815
1108
|
* all operations for that record. Called within the applyRemoteOperation
|
|
@@ -939,4 +1232,4 @@ declare class AwarenessRelay {
|
|
|
939
1232
|
*/
|
|
940
1233
|
declare function createKoraServer(config: KoraSyncServerConfig): KoraSyncServer;
|
|
941
1234
|
|
|
942
|
-
export { type AuthContext, type AuthProvider, AwarenessRelay, type AwarenessRelayCallback, ClientSession, type ClientSessionOptions, type CollectionQueryOptions, type HttpPollResponse, HttpServerTransport, type HttpSyncRequest, type HttpSyncResponse, KoraAuthProvider, type KoraAuthProviderOptions, KoraSyncServer, type KoraSyncServerConfig, type MaterializedRecord, MemoryServerStore, MixedAuthProvider, type MixedAuthProviderOptions, NoAuthProvider, PostgresServerStore, type ProductionServer, type ProductionServerConfig, type RelayCallback, ServerCloseHandler, ServerErrorHandler, ServerMessageHandler, type ServerStatus, type ServerStore, ServerTransport, type SessionState, SqliteServerStore, TokenAuthProvider, type TokenAuthProviderOptions, type WsServerConstructor, type WsServerLike, WsServerTransport, type WsServerTransportOptions, type WsWebSocket, createKoraServer, createPostgresServerStore, createProductionServer, createSqliteServerStore };
|
|
1235
|
+
export { type AuthContext, type AuthProvider, AwarenessRelay, type AwarenessRelayCallback, type ClientMetrics, ClientSession, type ClientSessionOptions, type CollectionQueryOptions, type HttpPollResponse, HttpServerTransport, type HttpSyncRequest, type HttpSyncResponse, KoraAuthProvider, type KoraAuthProviderOptions, KoraSyncServer, type KoraSyncServerConfig, type LogEntry, type LogLevel, type Logger, type MaterializedRecord, MemoryServerStore, MixedAuthProvider, type MixedAuthProviderOptions, NoAuthProvider, PostgresServerStore, type ProductionHttpRoute, type ProductionHttpRouteRequest, type ProductionHttpRouteResponse, type ProductionServer, type ProductionServerConfig, type RelayCallback, ServerCloseHandler, ServerErrorHandler, ServerMessageHandler, ServerMetricsCollector, type ServerMetricsSnapshot, type ServerStatus, type ServerStore, ServerTransport, type SessionState, SqliteServerStore, TokenAuthProvider, type TokenAuthProviderOptions, type WsServerConstructor, type WsServerLike, WsServerTransport, type WsServerTransportOptions, type WsWebSocket, createDefaultLogger, createJsonLogger, createKoraServer, createPostgresServerStore, createPrettyLogger, createProductionServer, createSilentLogger, createSqliteServerStore };
|