@korajs/server 1.0.0-beta.10 → 1.0.0-beta.12
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.cjs +279 -55
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +40 -3
- package/dist/index.d.ts +40 -3
- package/dist/index.js +275 -54
- package/dist/index.js.map +1 -1
- package/package.json +4 -4
package/dist/index.d.cts
CHANGED
|
@@ -35,6 +35,18 @@ type RoutePredicate = Record<string, RoutePredicateOperators>;
|
|
|
35
35
|
* Per-collection scope map from auth context.
|
|
36
36
|
*/
|
|
37
37
|
type ScopeMap = Record<string, Record<string, unknown>>;
|
|
38
|
+
declare const DEFAULT_MAX_SCOPE_PREDICATE_VALUES = 100;
|
|
39
|
+
/** Canonicalize bounded `$in` predicates so equivalent authorization has one signature. */
|
|
40
|
+
declare function normalizeScopeMap(scopes: ScopeMap, maxValues?: number): ScopeMap;
|
|
41
|
+
/**
|
|
42
|
+
* Returns true if an operation is visible to a session based on its scopes.
|
|
43
|
+
*
|
|
44
|
+
* Rules:
|
|
45
|
+
* - No scopes configured => visible
|
|
46
|
+
* - Collection missing from scope map => hidden
|
|
47
|
+
* - All scoped field/value pairs must match the operation snapshot
|
|
48
|
+
*/
|
|
49
|
+
declare function operationMatchesScopes(op: Operation, scopes: ScopeMap | undefined, fullRecord?: Record<string, unknown> | null): boolean;
|
|
38
50
|
|
|
39
51
|
/**
|
|
40
52
|
* A materialized record reconstructed from the operation log
|
|
@@ -302,6 +314,10 @@ interface ServerMetricsSnapshot {
|
|
|
302
314
|
peakConnections: number;
|
|
303
315
|
connectionsTotal: number;
|
|
304
316
|
operationsReceived: number;
|
|
317
|
+
batchesReceived: number;
|
|
318
|
+
uniqueOperationsReceived: number;
|
|
319
|
+
duplicateOperationsReceived: number;
|
|
320
|
+
rejectedOperations: number;
|
|
305
321
|
operationsSent: number;
|
|
306
322
|
bytesReceived: number;
|
|
307
323
|
bytesSent: number;
|
|
@@ -320,6 +336,10 @@ interface ClientMetrics {
|
|
|
320
336
|
state: SessionState$1;
|
|
321
337
|
connectedAt: number;
|
|
322
338
|
operationsReceived: number;
|
|
339
|
+
batchesReceived: number;
|
|
340
|
+
uniqueOperationsReceived: number;
|
|
341
|
+
duplicateOperationsReceived: number;
|
|
342
|
+
rejectedOperations: number;
|
|
323
343
|
operationsSent: number;
|
|
324
344
|
authContext: AuthContext | null;
|
|
325
345
|
}
|
|
@@ -328,6 +348,10 @@ declare class ServerMetricsCollector {
|
|
|
328
348
|
private peakConnections;
|
|
329
349
|
private connectionsTotal;
|
|
330
350
|
private operationsReceived;
|
|
351
|
+
private batchesReceived;
|
|
352
|
+
private uniqueOperationsReceived;
|
|
353
|
+
private duplicateOperationsReceived;
|
|
354
|
+
private rejectedOperations;
|
|
331
355
|
private operationsSent;
|
|
332
356
|
private bytesReceived;
|
|
333
357
|
private bytesSent;
|
|
@@ -345,7 +369,11 @@ declare class ServerMetricsCollector {
|
|
|
345
369
|
/** Record authentication context for a session. */
|
|
346
370
|
recordAuth(sessionId: string, authContext: AuthContext | null): void;
|
|
347
371
|
/** Record operations received from a client. */
|
|
348
|
-
recordReceived(sessionId: string, count: number, byteSize: number
|
|
372
|
+
recordReceived(sessionId: string, count: number, byteSize: number, outcomes?: {
|
|
373
|
+
unique: number;
|
|
374
|
+
duplicates: number;
|
|
375
|
+
rejected: number;
|
|
376
|
+
}): void;
|
|
349
377
|
/** Record operations sent to a client. */
|
|
350
378
|
recordSent(sessionId: string, count: number, byteSize: number): void;
|
|
351
379
|
/** Record an error. */
|
|
@@ -786,6 +814,10 @@ interface AuthContext {
|
|
|
786
814
|
userId: string;
|
|
787
815
|
/** Per-collection sync scopes (optional) */
|
|
788
816
|
scopes?: Record<string, Record<string, unknown>>;
|
|
817
|
+
/** Server-authoritative records this session may receive. Overrides `scopes`. */
|
|
818
|
+
downlinkScopes?: Record<string, Record<string, unknown>>;
|
|
819
|
+
/** Server-authoritative records this session may upload. Overrides `scopes`. */
|
|
820
|
+
uplinkScopes?: Record<string, Record<string, unknown>>;
|
|
789
821
|
/** Arbitrary metadata about the authenticated user */
|
|
790
822
|
metadata?: Record<string, unknown>;
|
|
791
823
|
}
|
|
@@ -1157,6 +1189,7 @@ declare class ClientSession {
|
|
|
1157
1189
|
private clientNodeId;
|
|
1158
1190
|
private authContext;
|
|
1159
1191
|
private syncQuerySubsets;
|
|
1192
|
+
private scopeExitPolicy;
|
|
1160
1193
|
private resumeDeltaCursor;
|
|
1161
1194
|
/**
|
|
1162
1195
|
* The delivery watermark the client reported at handshake, or null when the client
|
|
@@ -1181,7 +1214,7 @@ declare class ClientSession {
|
|
|
1181
1214
|
* batches every server tick while the first batch is still being applied.
|
|
1182
1215
|
*/
|
|
1183
1216
|
private lastDeliveryPushAttemptAtMs;
|
|
1184
|
-
private
|
|
1217
|
+
private outstandingDelivery;
|
|
1185
1218
|
/** Serializes incremental delivery pushes so their batches never interleave. */
|
|
1186
1219
|
private deliveryPushChain;
|
|
1187
1220
|
/**
|
|
@@ -1252,6 +1285,7 @@ declare class ClientSession {
|
|
|
1252
1285
|
*/
|
|
1253
1286
|
pushDeliveryStreamIfSupported(staleMs?: number, options?: {
|
|
1254
1287
|
trackStall?: boolean;
|
|
1288
|
+
serverFrontier?: number;
|
|
1255
1289
|
}): void;
|
|
1256
1290
|
/**
|
|
1257
1291
|
* Close this session.
|
|
@@ -1310,6 +1344,9 @@ declare class ClientSession {
|
|
|
1310
1344
|
/** Build, track, and send one chained delivery-stream batch. */
|
|
1311
1345
|
private sendDeliveryBatch;
|
|
1312
1346
|
private operationVisibleToClient;
|
|
1347
|
+
/** Upload authorization is independent from the client's downloaded/query view. */
|
|
1348
|
+
private operationAllowedFromClient;
|
|
1349
|
+
private scopeRetractionFor;
|
|
1313
1350
|
/**
|
|
1314
1351
|
* Read a record's current field values from the materialized store for scope /
|
|
1315
1352
|
* query-subset backfill. Includes soft-deleted rows so a relayed delete (whose op
|
|
@@ -2011,4 +2048,4 @@ declare class AwarenessRelay {
|
|
|
2011
2048
|
*/
|
|
2012
2049
|
declare function createKoraServer(config: KoraSyncServerConfig): KoraSyncServer;
|
|
2013
2050
|
|
|
2014
|
-
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, type OperationDecision, type OperationRejection, type OperationValidationContext, type OperationValidator, PostgresServerStore, type ProductionHttpRoute, type ProductionHttpRouteContext, type ProductionHttpRouteRequest, type ProductionHttpRouteResponse, type ProductionServer, type ProductionServerConfig, RETRIABLE_REJECTION_CODES, type RelayCallback, type RouteApplyResult, type RouteConditionalApply, type RouteConditionalResult, type RouteMutation, type RoutePredicate, type RoutePredicateOperators, type RouteScopeOptions, 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, isRetriableRejection };
|
|
2051
|
+
export { type AuthContext, type AuthProvider, AwarenessRelay, type AwarenessRelayCallback, type ClientMetrics, ClientSession, type ClientSessionOptions, type CollectionQueryOptions, DEFAULT_MAX_SCOPE_PREDICATE_VALUES, 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, type OperationDecision, type OperationRejection, type OperationValidationContext, type OperationValidator, PostgresServerStore, type ProductionHttpRoute, type ProductionHttpRouteContext, type ProductionHttpRouteRequest, type ProductionHttpRouteResponse, type ProductionServer, type ProductionServerConfig, RETRIABLE_REJECTION_CODES, type RelayCallback, type RouteApplyResult, type RouteConditionalApply, type RouteConditionalResult, type RouteMutation, type RoutePredicate, type RoutePredicateOperators, type RouteScopeOptions, 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, isRetriableRejection, normalizeScopeMap, operationMatchesScopes };
|
package/dist/index.d.ts
CHANGED
|
@@ -35,6 +35,18 @@ type RoutePredicate = Record<string, RoutePredicateOperators>;
|
|
|
35
35
|
* Per-collection scope map from auth context.
|
|
36
36
|
*/
|
|
37
37
|
type ScopeMap = Record<string, Record<string, unknown>>;
|
|
38
|
+
declare const DEFAULT_MAX_SCOPE_PREDICATE_VALUES = 100;
|
|
39
|
+
/** Canonicalize bounded `$in` predicates so equivalent authorization has one signature. */
|
|
40
|
+
declare function normalizeScopeMap(scopes: ScopeMap, maxValues?: number): ScopeMap;
|
|
41
|
+
/**
|
|
42
|
+
* Returns true if an operation is visible to a session based on its scopes.
|
|
43
|
+
*
|
|
44
|
+
* Rules:
|
|
45
|
+
* - No scopes configured => visible
|
|
46
|
+
* - Collection missing from scope map => hidden
|
|
47
|
+
* - All scoped field/value pairs must match the operation snapshot
|
|
48
|
+
*/
|
|
49
|
+
declare function operationMatchesScopes(op: Operation, scopes: ScopeMap | undefined, fullRecord?: Record<string, unknown> | null): boolean;
|
|
38
50
|
|
|
39
51
|
/**
|
|
40
52
|
* A materialized record reconstructed from the operation log
|
|
@@ -302,6 +314,10 @@ interface ServerMetricsSnapshot {
|
|
|
302
314
|
peakConnections: number;
|
|
303
315
|
connectionsTotal: number;
|
|
304
316
|
operationsReceived: number;
|
|
317
|
+
batchesReceived: number;
|
|
318
|
+
uniqueOperationsReceived: number;
|
|
319
|
+
duplicateOperationsReceived: number;
|
|
320
|
+
rejectedOperations: number;
|
|
305
321
|
operationsSent: number;
|
|
306
322
|
bytesReceived: number;
|
|
307
323
|
bytesSent: number;
|
|
@@ -320,6 +336,10 @@ interface ClientMetrics {
|
|
|
320
336
|
state: SessionState$1;
|
|
321
337
|
connectedAt: number;
|
|
322
338
|
operationsReceived: number;
|
|
339
|
+
batchesReceived: number;
|
|
340
|
+
uniqueOperationsReceived: number;
|
|
341
|
+
duplicateOperationsReceived: number;
|
|
342
|
+
rejectedOperations: number;
|
|
323
343
|
operationsSent: number;
|
|
324
344
|
authContext: AuthContext | null;
|
|
325
345
|
}
|
|
@@ -328,6 +348,10 @@ declare class ServerMetricsCollector {
|
|
|
328
348
|
private peakConnections;
|
|
329
349
|
private connectionsTotal;
|
|
330
350
|
private operationsReceived;
|
|
351
|
+
private batchesReceived;
|
|
352
|
+
private uniqueOperationsReceived;
|
|
353
|
+
private duplicateOperationsReceived;
|
|
354
|
+
private rejectedOperations;
|
|
331
355
|
private operationsSent;
|
|
332
356
|
private bytesReceived;
|
|
333
357
|
private bytesSent;
|
|
@@ -345,7 +369,11 @@ declare class ServerMetricsCollector {
|
|
|
345
369
|
/** Record authentication context for a session. */
|
|
346
370
|
recordAuth(sessionId: string, authContext: AuthContext | null): void;
|
|
347
371
|
/** Record operations received from a client. */
|
|
348
|
-
recordReceived(sessionId: string, count: number, byteSize: number
|
|
372
|
+
recordReceived(sessionId: string, count: number, byteSize: number, outcomes?: {
|
|
373
|
+
unique: number;
|
|
374
|
+
duplicates: number;
|
|
375
|
+
rejected: number;
|
|
376
|
+
}): void;
|
|
349
377
|
/** Record operations sent to a client. */
|
|
350
378
|
recordSent(sessionId: string, count: number, byteSize: number): void;
|
|
351
379
|
/** Record an error. */
|
|
@@ -786,6 +814,10 @@ interface AuthContext {
|
|
|
786
814
|
userId: string;
|
|
787
815
|
/** Per-collection sync scopes (optional) */
|
|
788
816
|
scopes?: Record<string, Record<string, unknown>>;
|
|
817
|
+
/** Server-authoritative records this session may receive. Overrides `scopes`. */
|
|
818
|
+
downlinkScopes?: Record<string, Record<string, unknown>>;
|
|
819
|
+
/** Server-authoritative records this session may upload. Overrides `scopes`. */
|
|
820
|
+
uplinkScopes?: Record<string, Record<string, unknown>>;
|
|
789
821
|
/** Arbitrary metadata about the authenticated user */
|
|
790
822
|
metadata?: Record<string, unknown>;
|
|
791
823
|
}
|
|
@@ -1157,6 +1189,7 @@ declare class ClientSession {
|
|
|
1157
1189
|
private clientNodeId;
|
|
1158
1190
|
private authContext;
|
|
1159
1191
|
private syncQuerySubsets;
|
|
1192
|
+
private scopeExitPolicy;
|
|
1160
1193
|
private resumeDeltaCursor;
|
|
1161
1194
|
/**
|
|
1162
1195
|
* The delivery watermark the client reported at handshake, or null when the client
|
|
@@ -1181,7 +1214,7 @@ declare class ClientSession {
|
|
|
1181
1214
|
* batches every server tick while the first batch is still being applied.
|
|
1182
1215
|
*/
|
|
1183
1216
|
private lastDeliveryPushAttemptAtMs;
|
|
1184
|
-
private
|
|
1217
|
+
private outstandingDelivery;
|
|
1185
1218
|
/** Serializes incremental delivery pushes so their batches never interleave. */
|
|
1186
1219
|
private deliveryPushChain;
|
|
1187
1220
|
/**
|
|
@@ -1252,6 +1285,7 @@ declare class ClientSession {
|
|
|
1252
1285
|
*/
|
|
1253
1286
|
pushDeliveryStreamIfSupported(staleMs?: number, options?: {
|
|
1254
1287
|
trackStall?: boolean;
|
|
1288
|
+
serverFrontier?: number;
|
|
1255
1289
|
}): void;
|
|
1256
1290
|
/**
|
|
1257
1291
|
* Close this session.
|
|
@@ -1310,6 +1344,9 @@ declare class ClientSession {
|
|
|
1310
1344
|
/** Build, track, and send one chained delivery-stream batch. */
|
|
1311
1345
|
private sendDeliveryBatch;
|
|
1312
1346
|
private operationVisibleToClient;
|
|
1347
|
+
/** Upload authorization is independent from the client's downloaded/query view. */
|
|
1348
|
+
private operationAllowedFromClient;
|
|
1349
|
+
private scopeRetractionFor;
|
|
1313
1350
|
/**
|
|
1314
1351
|
* Read a record's current field values from the materialized store for scope /
|
|
1315
1352
|
* query-subset backfill. Includes soft-deleted rows so a relayed delete (whose op
|
|
@@ -2011,4 +2048,4 @@ declare class AwarenessRelay {
|
|
|
2011
2048
|
*/
|
|
2012
2049
|
declare function createKoraServer(config: KoraSyncServerConfig): KoraSyncServer;
|
|
2013
2050
|
|
|
2014
|
-
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, type OperationDecision, type OperationRejection, type OperationValidationContext, type OperationValidator, PostgresServerStore, type ProductionHttpRoute, type ProductionHttpRouteContext, type ProductionHttpRouteRequest, type ProductionHttpRouteResponse, type ProductionServer, type ProductionServerConfig, RETRIABLE_REJECTION_CODES, type RelayCallback, type RouteApplyResult, type RouteConditionalApply, type RouteConditionalResult, type RouteMutation, type RoutePredicate, type RoutePredicateOperators, type RouteScopeOptions, 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, isRetriableRejection };
|
|
2051
|
+
export { type AuthContext, type AuthProvider, AwarenessRelay, type AwarenessRelayCallback, type ClientMetrics, ClientSession, type ClientSessionOptions, type CollectionQueryOptions, DEFAULT_MAX_SCOPE_PREDICATE_VALUES, 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, type OperationDecision, type OperationRejection, type OperationValidationContext, type OperationValidator, PostgresServerStore, type ProductionHttpRoute, type ProductionHttpRouteContext, type ProductionHttpRouteRequest, type ProductionHttpRouteResponse, type ProductionServer, type ProductionServerConfig, RETRIABLE_REJECTION_CODES, type RelayCallback, type RouteApplyResult, type RouteConditionalApply, type RouteConditionalResult, type RouteMutation, type RoutePredicate, type RoutePredicateOperators, type RouteScopeOptions, 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, isRetriableRejection, normalizeScopeMap, operationMatchesScopes };
|