@mesh-kit/server 2.0.6 → 2.0.8
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.d.mts +142 -134
- package/dist/index.d.ts +142 -134
- package/dist/index.js +8 -8
- package/dist/index.mjs +8 -8
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -71,21 +71,19 @@ interface ChannelPersistenceOptions {
|
|
|
71
71
|
*/
|
|
72
72
|
maxBufferSize?: number;
|
|
73
73
|
}
|
|
74
|
-
interface
|
|
75
|
-
/**
|
|
76
|
-
* Optional adapter override for this pattern
|
|
77
|
-
*/
|
|
74
|
+
interface RecordPersistenceAdapterConfig {
|
|
78
75
|
adapter?: PersistenceAdapter;
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
76
|
+
restorePattern: string;
|
|
77
|
+
}
|
|
78
|
+
interface RecordPersistenceHooksConfig {
|
|
79
|
+
persist: (records: CustomPersistedRecord[]) => Promise<void>;
|
|
80
|
+
restore: () => Promise<CustomPersistedRecord[]>;
|
|
81
|
+
}
|
|
82
|
+
interface RecordPersistenceConfig {
|
|
83
|
+
pattern: string | RegExp;
|
|
84
|
+
adapter?: RecordPersistenceAdapterConfig;
|
|
85
|
+
hooks?: RecordPersistenceHooksConfig;
|
|
83
86
|
flushInterval?: number;
|
|
84
|
-
/**
|
|
85
|
-
* Maximum number of records to hold in memory before flushing
|
|
86
|
-
* If this limit is reached, the buffer is flushed immediately
|
|
87
|
-
* @default 100
|
|
88
|
-
*/
|
|
89
87
|
maxBufferSize?: number;
|
|
90
88
|
}
|
|
91
89
|
interface PersistedRecord {
|
|
@@ -94,6 +92,11 @@ interface PersistedRecord {
|
|
|
94
92
|
value: string;
|
|
95
93
|
timestamp: number;
|
|
96
94
|
}
|
|
95
|
+
interface CustomPersistedRecord {
|
|
96
|
+
recordId: string;
|
|
97
|
+
value: unknown;
|
|
98
|
+
version: number;
|
|
99
|
+
}
|
|
97
100
|
interface PersistenceAdapterOptions {
|
|
98
101
|
/**
|
|
99
102
|
* Database file path for file-based adapters
|
|
@@ -683,121 +686,6 @@ declare class RecordManager {
|
|
|
683
686
|
}) => Promise<void> | void): () => void;
|
|
684
687
|
}
|
|
685
688
|
|
|
686
|
-
type RecordPersistencePattern = {
|
|
687
|
-
writePattern: string | RegExp;
|
|
688
|
-
restorePattern: string;
|
|
689
|
-
};
|
|
690
|
-
declare class PersistenceManager extends EventEmitter$1 {
|
|
691
|
-
private defaultAdapter;
|
|
692
|
-
private channelPatterns;
|
|
693
|
-
private recordPatterns;
|
|
694
|
-
private messageBuffer;
|
|
695
|
-
private recordBuffer;
|
|
696
|
-
private flushTimers;
|
|
697
|
-
private recordFlushTimer;
|
|
698
|
-
private isShuttingDown;
|
|
699
|
-
private initialized;
|
|
700
|
-
private recordManager;
|
|
701
|
-
private pendingRecordUpdates;
|
|
702
|
-
private messageStream;
|
|
703
|
-
constructor(options: {
|
|
704
|
-
defaultAdapterOptions?: any;
|
|
705
|
-
adapterType?: "sqlite" | "postgres";
|
|
706
|
-
});
|
|
707
|
-
/**
|
|
708
|
-
* Sets the record manager reference for record restoration
|
|
709
|
-
* @param recordManager The record manager instance
|
|
710
|
-
*/
|
|
711
|
-
setRecordManager(recordManager: RecordManager): void;
|
|
712
|
-
/**
|
|
713
|
-
* Waits until the persistence manager is fully ready and initialized.
|
|
714
|
-
*
|
|
715
|
-
* @returns {Promise<void>} A promise that resolves when persistence is ready.
|
|
716
|
-
*/
|
|
717
|
-
ready(): Promise<void>;
|
|
718
|
-
/**
|
|
719
|
-
* Processes any record updates that were buffered during initialization
|
|
720
|
-
*/
|
|
721
|
-
private processPendingRecordUpdates;
|
|
722
|
-
initialize(): Promise<void>;
|
|
723
|
-
/**
|
|
724
|
-
* Restores persisted records from storage into Redis on startup
|
|
725
|
-
*/
|
|
726
|
-
restorePersistedRecords(): Promise<void>;
|
|
727
|
-
/**
|
|
728
|
-
* Handle a message received from the internal message stream.
|
|
729
|
-
*/
|
|
730
|
-
private handleStreamMessage;
|
|
731
|
-
/**
|
|
732
|
-
* Enable persistence for channels matching the given pattern.
|
|
733
|
-
* @param pattern string or regexp pattern to match channel names
|
|
734
|
-
* @param options persistence options
|
|
735
|
-
*/
|
|
736
|
-
enableChannelPersistence(pattern: string | RegExp, options?: ChannelPersistenceOptions): void;
|
|
737
|
-
/**
|
|
738
|
-
* Enable persistence for records matching the given pattern.
|
|
739
|
-
* @param pattern object with writePattern (for runtime matching) and restorePattern (for database queries)
|
|
740
|
-
* @param options persistence options
|
|
741
|
-
*/
|
|
742
|
-
enableRecordPersistence(pattern: RecordPersistencePattern, options?: RecordPersistenceOptions): void;
|
|
743
|
-
/**
|
|
744
|
-
* Check if a channel has persistence enabled and return its options.
|
|
745
|
-
* @param channel channel name to check
|
|
746
|
-
* @returns the persistence options if enabled, undefined otherwise
|
|
747
|
-
*/
|
|
748
|
-
getChannelPersistenceOptions(channel: string): Required<ChannelPersistenceOptions> | undefined;
|
|
749
|
-
/**
|
|
750
|
-
* Check if a record has persistence enabled and return its options.
|
|
751
|
-
* @param recordId record ID to check
|
|
752
|
-
* @returns the persistence options if enabled, undefined otherwise
|
|
753
|
-
*/
|
|
754
|
-
getRecordPersistenceOptions(recordId: string): Required<RecordPersistenceOptions> | undefined;
|
|
755
|
-
/**
|
|
756
|
-
* Handle an incoming message for potential persistence.
|
|
757
|
-
* @param channel channel the message was published to
|
|
758
|
-
* @param message the message content
|
|
759
|
-
* @param instanceId id of the server instance
|
|
760
|
-
*/
|
|
761
|
-
handleChannelMessage(channel: string, message: string, instanceId: string, timestamp?: number): void;
|
|
762
|
-
/**
|
|
763
|
-
* Flush buffered messages for a specific channel to its adapter.
|
|
764
|
-
* @param channel channel to flush
|
|
765
|
-
*/
|
|
766
|
-
private flushChannel;
|
|
767
|
-
/**
|
|
768
|
-
* Flush all buffered messages across all channels.
|
|
769
|
-
*/
|
|
770
|
-
flushAll(): Promise<void>;
|
|
771
|
-
/**
|
|
772
|
-
* Get persisted messages for a channel.
|
|
773
|
-
* @param channel channel to get messages for
|
|
774
|
-
* @param since optional cursor (timestamp or message id) to retrieve messages after
|
|
775
|
-
* @param limit maximum number of messages to retrieve
|
|
776
|
-
*/
|
|
777
|
-
getMessages(channel: string, since?: string | number, limit?: number): Promise<PersistedMessage[]>;
|
|
778
|
-
/**
|
|
779
|
-
* Handles a record update for potential persistence
|
|
780
|
-
* @param recordId ID of the record
|
|
781
|
-
* @param value record value (will be stringified)
|
|
782
|
-
* @param version record version
|
|
783
|
-
*/
|
|
784
|
-
handleRecordUpdate(recordId: string, value: any, version: number): void;
|
|
785
|
-
/**
|
|
786
|
-
* Flush all buffered records to storage
|
|
787
|
-
*/
|
|
788
|
-
flushRecords(): Promise<void>;
|
|
789
|
-
/**
|
|
790
|
-
* Retrieve persisted records matching a pattern
|
|
791
|
-
* @param pattern pattern to match record IDs
|
|
792
|
-
* @returns array of persisted records
|
|
793
|
-
*/
|
|
794
|
-
getPersistedRecords(pattern: string): Promise<PersistedRecord[]>;
|
|
795
|
-
/**
|
|
796
|
-
* Shutdown the persistence manager, flushing pending messages and closing adapters.
|
|
797
|
-
*/
|
|
798
|
-
shutdown(): Promise<void>;
|
|
799
|
-
}
|
|
800
|
-
|
|
801
689
|
declare class MeshServer extends WebSocketServer {
|
|
802
690
|
readonly instanceId: string;
|
|
803
691
|
private redisManager;
|
|
@@ -891,12 +779,9 @@ declare class MeshServer extends WebSocketServer {
|
|
|
891
779
|
enableChannelPersistence(pattern: ChannelPattern$1, options?: ChannelPersistenceOptions): void;
|
|
892
780
|
/**
|
|
893
781
|
* Enables persistence for records matching the specified pattern.
|
|
894
|
-
*
|
|
895
|
-
* @param {RecordPersistencePattern} pattern - The record ID pattern to enable persistence for.
|
|
896
|
-
* @param {RecordPersistenceOptions} [options] - Options for persistence.
|
|
897
|
-
* @throws {Error} If persistence is not enabled for this server instance.
|
|
782
|
+
* Use either adapter (for mesh's internal JSON blob storage) or hooks (for custom DB persistence).
|
|
898
783
|
*/
|
|
899
|
-
enableRecordPersistence(
|
|
784
|
+
enableRecordPersistence(config: RecordPersistenceConfig): void;
|
|
900
785
|
/**
|
|
901
786
|
* Exposes a record or pattern for client subscriptions, optionally adding a guard function.
|
|
902
787
|
*
|
|
@@ -1161,4 +1046,127 @@ declare class MessageStream extends EventEmitter$1 {
|
|
|
1161
1046
|
}) => void): void;
|
|
1162
1047
|
}
|
|
1163
1048
|
|
|
1164
|
-
|
|
1049
|
+
interface RecordPatternConfig {
|
|
1050
|
+
pattern: string | RegExp;
|
|
1051
|
+
adapter?: {
|
|
1052
|
+
adapter: PersistenceAdapter;
|
|
1053
|
+
restorePattern: string;
|
|
1054
|
+
};
|
|
1055
|
+
hooks?: {
|
|
1056
|
+
persist: (records: CustomPersistedRecord[]) => Promise<void>;
|
|
1057
|
+
restore: () => Promise<CustomPersistedRecord[]>;
|
|
1058
|
+
};
|
|
1059
|
+
flushInterval: number;
|
|
1060
|
+
maxBufferSize: number;
|
|
1061
|
+
}
|
|
1062
|
+
declare class PersistenceManager extends EventEmitter$1 {
|
|
1063
|
+
private defaultAdapter;
|
|
1064
|
+
private channelPatterns;
|
|
1065
|
+
private recordPatterns;
|
|
1066
|
+
private messageBuffer;
|
|
1067
|
+
private recordBuffer;
|
|
1068
|
+
private flushTimers;
|
|
1069
|
+
private recordFlushTimer;
|
|
1070
|
+
private isShuttingDown;
|
|
1071
|
+
private initialized;
|
|
1072
|
+
private recordManager;
|
|
1073
|
+
private pendingRecordUpdates;
|
|
1074
|
+
private messageStream;
|
|
1075
|
+
constructor(options: {
|
|
1076
|
+
defaultAdapterOptions?: any;
|
|
1077
|
+
adapterType?: "sqlite" | "postgres";
|
|
1078
|
+
});
|
|
1079
|
+
/**
|
|
1080
|
+
* Sets the record manager reference for record restoration
|
|
1081
|
+
* @param recordManager The record manager instance
|
|
1082
|
+
*/
|
|
1083
|
+
setRecordManager(recordManager: RecordManager): void;
|
|
1084
|
+
/**
|
|
1085
|
+
* Waits until the persistence manager is fully ready and initialized.
|
|
1086
|
+
*
|
|
1087
|
+
* @returns {Promise<void>} A promise that resolves when persistence is ready.
|
|
1088
|
+
*/
|
|
1089
|
+
ready(): Promise<void>;
|
|
1090
|
+
/**
|
|
1091
|
+
* Processes any record updates that were buffered during initialization
|
|
1092
|
+
*/
|
|
1093
|
+
private processPendingRecordUpdates;
|
|
1094
|
+
initialize(): Promise<void>;
|
|
1095
|
+
/**
|
|
1096
|
+
* Restores persisted records from storage into Redis on startup
|
|
1097
|
+
*/
|
|
1098
|
+
restorePersistedRecords(): Promise<void>;
|
|
1099
|
+
/**
|
|
1100
|
+
* Handle a message received from the internal message stream.
|
|
1101
|
+
*/
|
|
1102
|
+
private handleStreamMessage;
|
|
1103
|
+
/**
|
|
1104
|
+
* Enable persistence for channels matching the given pattern.
|
|
1105
|
+
* @param pattern string or regexp pattern to match channel names
|
|
1106
|
+
* @param options persistence options
|
|
1107
|
+
*/
|
|
1108
|
+
enableChannelPersistence(pattern: string | RegExp, options?: ChannelPersistenceOptions): void;
|
|
1109
|
+
/**
|
|
1110
|
+
* Enable persistence for records matching the given pattern.
|
|
1111
|
+
* Use either adapter (for mesh's internal JSON blob storage) or hooks (for custom DB persistence).
|
|
1112
|
+
*/
|
|
1113
|
+
enableRecordPersistence(config: RecordPersistenceConfig): void;
|
|
1114
|
+
/**
|
|
1115
|
+
* Check if a channel has persistence enabled and return its options.
|
|
1116
|
+
* @param channel channel name to check
|
|
1117
|
+
* @returns the persistence options if enabled, undefined otherwise
|
|
1118
|
+
*/
|
|
1119
|
+
getChannelPersistenceOptions(channel: string): Required<ChannelPersistenceOptions> | undefined;
|
|
1120
|
+
/**
|
|
1121
|
+
* Check if a record has persistence enabled and return its config.
|
|
1122
|
+
* @param recordId record ID to check
|
|
1123
|
+
* @returns the persistence config if enabled, undefined otherwise
|
|
1124
|
+
*/
|
|
1125
|
+
getRecordPersistenceConfig(recordId: string): RecordPatternConfig | undefined;
|
|
1126
|
+
/**
|
|
1127
|
+
* Handle an incoming message for potential persistence.
|
|
1128
|
+
* @param channel channel the message was published to
|
|
1129
|
+
* @param message the message content
|
|
1130
|
+
* @param instanceId id of the server instance
|
|
1131
|
+
*/
|
|
1132
|
+
handleChannelMessage(channel: string, message: string, instanceId: string, timestamp?: number): void;
|
|
1133
|
+
/**
|
|
1134
|
+
* Flush buffered messages for a specific channel to its adapter.
|
|
1135
|
+
* @param channel channel to flush
|
|
1136
|
+
*/
|
|
1137
|
+
private flushChannel;
|
|
1138
|
+
/**
|
|
1139
|
+
* Flush all buffered messages across all channels.
|
|
1140
|
+
*/
|
|
1141
|
+
flushAll(): Promise<void>;
|
|
1142
|
+
/**
|
|
1143
|
+
* Get persisted messages for a channel.
|
|
1144
|
+
* @param channel channel to get messages for
|
|
1145
|
+
* @param since optional cursor (timestamp or message id) to retrieve messages after
|
|
1146
|
+
* @param limit maximum number of messages to retrieve
|
|
1147
|
+
*/
|
|
1148
|
+
getMessages(channel: string, since?: string | number, limit?: number): Promise<PersistedMessage[]>;
|
|
1149
|
+
/**
|
|
1150
|
+
* Handles a record update for potential persistence
|
|
1151
|
+
* @param recordId ID of the record
|
|
1152
|
+
* @param value record value (will be stringified)
|
|
1153
|
+
* @param version record version
|
|
1154
|
+
*/
|
|
1155
|
+
handleRecordUpdate(recordId: string, value: any, version: number): void;
|
|
1156
|
+
/**
|
|
1157
|
+
* Flush all buffered records to storage
|
|
1158
|
+
*/
|
|
1159
|
+
flushRecords(): Promise<void>;
|
|
1160
|
+
/**
|
|
1161
|
+
* Retrieve persisted records matching a pattern
|
|
1162
|
+
* @param pattern pattern to match record IDs
|
|
1163
|
+
* @returns array of persisted records
|
|
1164
|
+
*/
|
|
1165
|
+
getPersistedRecords(pattern: string): Promise<PersistedRecord[]>;
|
|
1166
|
+
/**
|
|
1167
|
+
* Shutdown the persistence manager, flushing pending messages and closing adapters.
|
|
1168
|
+
*/
|
|
1169
|
+
shutdown(): Promise<void>;
|
|
1170
|
+
}
|
|
1171
|
+
|
|
1172
|
+
export { type AuthenticateConnectionFn, type AuthenticationError, type ChannelPattern$1 as ChannelPattern, Connection, ConnectionManager, type CustomPersistedRecord, MeshContext, MeshServer, type MeshServerOptions, MessageStream, type PersistenceAdapter, type PersistenceAdapterOptions, PersistenceManager, type PostgreSQLAdapterOptions, PostgreSQLPersistenceAdapter, PresenceManager, RecordManager, type RecordPersistenceConfig, RoomManager, SQLitePersistenceAdapter, type SocketMiddleware };
|
package/dist/index.d.ts
CHANGED
|
@@ -71,21 +71,19 @@ interface ChannelPersistenceOptions {
|
|
|
71
71
|
*/
|
|
72
72
|
maxBufferSize?: number;
|
|
73
73
|
}
|
|
74
|
-
interface
|
|
75
|
-
/**
|
|
76
|
-
* Optional adapter override for this pattern
|
|
77
|
-
*/
|
|
74
|
+
interface RecordPersistenceAdapterConfig {
|
|
78
75
|
adapter?: PersistenceAdapter;
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
76
|
+
restorePattern: string;
|
|
77
|
+
}
|
|
78
|
+
interface RecordPersistenceHooksConfig {
|
|
79
|
+
persist: (records: CustomPersistedRecord[]) => Promise<void>;
|
|
80
|
+
restore: () => Promise<CustomPersistedRecord[]>;
|
|
81
|
+
}
|
|
82
|
+
interface RecordPersistenceConfig {
|
|
83
|
+
pattern: string | RegExp;
|
|
84
|
+
adapter?: RecordPersistenceAdapterConfig;
|
|
85
|
+
hooks?: RecordPersistenceHooksConfig;
|
|
83
86
|
flushInterval?: number;
|
|
84
|
-
/**
|
|
85
|
-
* Maximum number of records to hold in memory before flushing
|
|
86
|
-
* If this limit is reached, the buffer is flushed immediately
|
|
87
|
-
* @default 100
|
|
88
|
-
*/
|
|
89
87
|
maxBufferSize?: number;
|
|
90
88
|
}
|
|
91
89
|
interface PersistedRecord {
|
|
@@ -94,6 +92,11 @@ interface PersistedRecord {
|
|
|
94
92
|
value: string;
|
|
95
93
|
timestamp: number;
|
|
96
94
|
}
|
|
95
|
+
interface CustomPersistedRecord {
|
|
96
|
+
recordId: string;
|
|
97
|
+
value: unknown;
|
|
98
|
+
version: number;
|
|
99
|
+
}
|
|
97
100
|
interface PersistenceAdapterOptions {
|
|
98
101
|
/**
|
|
99
102
|
* Database file path for file-based adapters
|
|
@@ -683,121 +686,6 @@ declare class RecordManager {
|
|
|
683
686
|
}) => Promise<void> | void): () => void;
|
|
684
687
|
}
|
|
685
688
|
|
|
686
|
-
type RecordPersistencePattern = {
|
|
687
|
-
writePattern: string | RegExp;
|
|
688
|
-
restorePattern: string;
|
|
689
|
-
};
|
|
690
|
-
declare class PersistenceManager extends EventEmitter$1 {
|
|
691
|
-
private defaultAdapter;
|
|
692
|
-
private channelPatterns;
|
|
693
|
-
private recordPatterns;
|
|
694
|
-
private messageBuffer;
|
|
695
|
-
private recordBuffer;
|
|
696
|
-
private flushTimers;
|
|
697
|
-
private recordFlushTimer;
|
|
698
|
-
private isShuttingDown;
|
|
699
|
-
private initialized;
|
|
700
|
-
private recordManager;
|
|
701
|
-
private pendingRecordUpdates;
|
|
702
|
-
private messageStream;
|
|
703
|
-
constructor(options: {
|
|
704
|
-
defaultAdapterOptions?: any;
|
|
705
|
-
adapterType?: "sqlite" | "postgres";
|
|
706
|
-
});
|
|
707
|
-
/**
|
|
708
|
-
* Sets the record manager reference for record restoration
|
|
709
|
-
* @param recordManager The record manager instance
|
|
710
|
-
*/
|
|
711
|
-
setRecordManager(recordManager: RecordManager): void;
|
|
712
|
-
/**
|
|
713
|
-
* Waits until the persistence manager is fully ready and initialized.
|
|
714
|
-
*
|
|
715
|
-
* @returns {Promise<void>} A promise that resolves when persistence is ready.
|
|
716
|
-
*/
|
|
717
|
-
ready(): Promise<void>;
|
|
718
|
-
/**
|
|
719
|
-
* Processes any record updates that were buffered during initialization
|
|
720
|
-
*/
|
|
721
|
-
private processPendingRecordUpdates;
|
|
722
|
-
initialize(): Promise<void>;
|
|
723
|
-
/**
|
|
724
|
-
* Restores persisted records from storage into Redis on startup
|
|
725
|
-
*/
|
|
726
|
-
restorePersistedRecords(): Promise<void>;
|
|
727
|
-
/**
|
|
728
|
-
* Handle a message received from the internal message stream.
|
|
729
|
-
*/
|
|
730
|
-
private handleStreamMessage;
|
|
731
|
-
/**
|
|
732
|
-
* Enable persistence for channels matching the given pattern.
|
|
733
|
-
* @param pattern string or regexp pattern to match channel names
|
|
734
|
-
* @param options persistence options
|
|
735
|
-
*/
|
|
736
|
-
enableChannelPersistence(pattern: string | RegExp, options?: ChannelPersistenceOptions): void;
|
|
737
|
-
/**
|
|
738
|
-
* Enable persistence for records matching the given pattern.
|
|
739
|
-
* @param pattern object with writePattern (for runtime matching) and restorePattern (for database queries)
|
|
740
|
-
* @param options persistence options
|
|
741
|
-
*/
|
|
742
|
-
enableRecordPersistence(pattern: RecordPersistencePattern, options?: RecordPersistenceOptions): void;
|
|
743
|
-
/**
|
|
744
|
-
* Check if a channel has persistence enabled and return its options.
|
|
745
|
-
* @param channel channel name to check
|
|
746
|
-
* @returns the persistence options if enabled, undefined otherwise
|
|
747
|
-
*/
|
|
748
|
-
getChannelPersistenceOptions(channel: string): Required<ChannelPersistenceOptions> | undefined;
|
|
749
|
-
/**
|
|
750
|
-
* Check if a record has persistence enabled and return its options.
|
|
751
|
-
* @param recordId record ID to check
|
|
752
|
-
* @returns the persistence options if enabled, undefined otherwise
|
|
753
|
-
*/
|
|
754
|
-
getRecordPersistenceOptions(recordId: string): Required<RecordPersistenceOptions> | undefined;
|
|
755
|
-
/**
|
|
756
|
-
* Handle an incoming message for potential persistence.
|
|
757
|
-
* @param channel channel the message was published to
|
|
758
|
-
* @param message the message content
|
|
759
|
-
* @param instanceId id of the server instance
|
|
760
|
-
*/
|
|
761
|
-
handleChannelMessage(channel: string, message: string, instanceId: string, timestamp?: number): void;
|
|
762
|
-
/**
|
|
763
|
-
* Flush buffered messages for a specific channel to its adapter.
|
|
764
|
-
* @param channel channel to flush
|
|
765
|
-
*/
|
|
766
|
-
private flushChannel;
|
|
767
|
-
/**
|
|
768
|
-
* Flush all buffered messages across all channels.
|
|
769
|
-
*/
|
|
770
|
-
flushAll(): Promise<void>;
|
|
771
|
-
/**
|
|
772
|
-
* Get persisted messages for a channel.
|
|
773
|
-
* @param channel channel to get messages for
|
|
774
|
-
* @param since optional cursor (timestamp or message id) to retrieve messages after
|
|
775
|
-
* @param limit maximum number of messages to retrieve
|
|
776
|
-
*/
|
|
777
|
-
getMessages(channel: string, since?: string | number, limit?: number): Promise<PersistedMessage[]>;
|
|
778
|
-
/**
|
|
779
|
-
* Handles a record update for potential persistence
|
|
780
|
-
* @param recordId ID of the record
|
|
781
|
-
* @param value record value (will be stringified)
|
|
782
|
-
* @param version record version
|
|
783
|
-
*/
|
|
784
|
-
handleRecordUpdate(recordId: string, value: any, version: number): void;
|
|
785
|
-
/**
|
|
786
|
-
* Flush all buffered records to storage
|
|
787
|
-
*/
|
|
788
|
-
flushRecords(): Promise<void>;
|
|
789
|
-
/**
|
|
790
|
-
* Retrieve persisted records matching a pattern
|
|
791
|
-
* @param pattern pattern to match record IDs
|
|
792
|
-
* @returns array of persisted records
|
|
793
|
-
*/
|
|
794
|
-
getPersistedRecords(pattern: string): Promise<PersistedRecord[]>;
|
|
795
|
-
/**
|
|
796
|
-
* Shutdown the persistence manager, flushing pending messages and closing adapters.
|
|
797
|
-
*/
|
|
798
|
-
shutdown(): Promise<void>;
|
|
799
|
-
}
|
|
800
|
-
|
|
801
689
|
declare class MeshServer extends WebSocketServer {
|
|
802
690
|
readonly instanceId: string;
|
|
803
691
|
private redisManager;
|
|
@@ -891,12 +779,9 @@ declare class MeshServer extends WebSocketServer {
|
|
|
891
779
|
enableChannelPersistence(pattern: ChannelPattern$1, options?: ChannelPersistenceOptions): void;
|
|
892
780
|
/**
|
|
893
781
|
* Enables persistence for records matching the specified pattern.
|
|
894
|
-
*
|
|
895
|
-
* @param {RecordPersistencePattern} pattern - The record ID pattern to enable persistence for.
|
|
896
|
-
* @param {RecordPersistenceOptions} [options] - Options for persistence.
|
|
897
|
-
* @throws {Error} If persistence is not enabled for this server instance.
|
|
782
|
+
* Use either adapter (for mesh's internal JSON blob storage) or hooks (for custom DB persistence).
|
|
898
783
|
*/
|
|
899
|
-
enableRecordPersistence(
|
|
784
|
+
enableRecordPersistence(config: RecordPersistenceConfig): void;
|
|
900
785
|
/**
|
|
901
786
|
* Exposes a record or pattern for client subscriptions, optionally adding a guard function.
|
|
902
787
|
*
|
|
@@ -1161,4 +1046,127 @@ declare class MessageStream extends EventEmitter$1 {
|
|
|
1161
1046
|
}) => void): void;
|
|
1162
1047
|
}
|
|
1163
1048
|
|
|
1164
|
-
|
|
1049
|
+
interface RecordPatternConfig {
|
|
1050
|
+
pattern: string | RegExp;
|
|
1051
|
+
adapter?: {
|
|
1052
|
+
adapter: PersistenceAdapter;
|
|
1053
|
+
restorePattern: string;
|
|
1054
|
+
};
|
|
1055
|
+
hooks?: {
|
|
1056
|
+
persist: (records: CustomPersistedRecord[]) => Promise<void>;
|
|
1057
|
+
restore: () => Promise<CustomPersistedRecord[]>;
|
|
1058
|
+
};
|
|
1059
|
+
flushInterval: number;
|
|
1060
|
+
maxBufferSize: number;
|
|
1061
|
+
}
|
|
1062
|
+
declare class PersistenceManager extends EventEmitter$1 {
|
|
1063
|
+
private defaultAdapter;
|
|
1064
|
+
private channelPatterns;
|
|
1065
|
+
private recordPatterns;
|
|
1066
|
+
private messageBuffer;
|
|
1067
|
+
private recordBuffer;
|
|
1068
|
+
private flushTimers;
|
|
1069
|
+
private recordFlushTimer;
|
|
1070
|
+
private isShuttingDown;
|
|
1071
|
+
private initialized;
|
|
1072
|
+
private recordManager;
|
|
1073
|
+
private pendingRecordUpdates;
|
|
1074
|
+
private messageStream;
|
|
1075
|
+
constructor(options: {
|
|
1076
|
+
defaultAdapterOptions?: any;
|
|
1077
|
+
adapterType?: "sqlite" | "postgres";
|
|
1078
|
+
});
|
|
1079
|
+
/**
|
|
1080
|
+
* Sets the record manager reference for record restoration
|
|
1081
|
+
* @param recordManager The record manager instance
|
|
1082
|
+
*/
|
|
1083
|
+
setRecordManager(recordManager: RecordManager): void;
|
|
1084
|
+
/**
|
|
1085
|
+
* Waits until the persistence manager is fully ready and initialized.
|
|
1086
|
+
*
|
|
1087
|
+
* @returns {Promise<void>} A promise that resolves when persistence is ready.
|
|
1088
|
+
*/
|
|
1089
|
+
ready(): Promise<void>;
|
|
1090
|
+
/**
|
|
1091
|
+
* Processes any record updates that were buffered during initialization
|
|
1092
|
+
*/
|
|
1093
|
+
private processPendingRecordUpdates;
|
|
1094
|
+
initialize(): Promise<void>;
|
|
1095
|
+
/**
|
|
1096
|
+
* Restores persisted records from storage into Redis on startup
|
|
1097
|
+
*/
|
|
1098
|
+
restorePersistedRecords(): Promise<void>;
|
|
1099
|
+
/**
|
|
1100
|
+
* Handle a message received from the internal message stream.
|
|
1101
|
+
*/
|
|
1102
|
+
private handleStreamMessage;
|
|
1103
|
+
/**
|
|
1104
|
+
* Enable persistence for channels matching the given pattern.
|
|
1105
|
+
* @param pattern string or regexp pattern to match channel names
|
|
1106
|
+
* @param options persistence options
|
|
1107
|
+
*/
|
|
1108
|
+
enableChannelPersistence(pattern: string | RegExp, options?: ChannelPersistenceOptions): void;
|
|
1109
|
+
/**
|
|
1110
|
+
* Enable persistence for records matching the given pattern.
|
|
1111
|
+
* Use either adapter (for mesh's internal JSON blob storage) or hooks (for custom DB persistence).
|
|
1112
|
+
*/
|
|
1113
|
+
enableRecordPersistence(config: RecordPersistenceConfig): void;
|
|
1114
|
+
/**
|
|
1115
|
+
* Check if a channel has persistence enabled and return its options.
|
|
1116
|
+
* @param channel channel name to check
|
|
1117
|
+
* @returns the persistence options if enabled, undefined otherwise
|
|
1118
|
+
*/
|
|
1119
|
+
getChannelPersistenceOptions(channel: string): Required<ChannelPersistenceOptions> | undefined;
|
|
1120
|
+
/**
|
|
1121
|
+
* Check if a record has persistence enabled and return its config.
|
|
1122
|
+
* @param recordId record ID to check
|
|
1123
|
+
* @returns the persistence config if enabled, undefined otherwise
|
|
1124
|
+
*/
|
|
1125
|
+
getRecordPersistenceConfig(recordId: string): RecordPatternConfig | undefined;
|
|
1126
|
+
/**
|
|
1127
|
+
* Handle an incoming message for potential persistence.
|
|
1128
|
+
* @param channel channel the message was published to
|
|
1129
|
+
* @param message the message content
|
|
1130
|
+
* @param instanceId id of the server instance
|
|
1131
|
+
*/
|
|
1132
|
+
handleChannelMessage(channel: string, message: string, instanceId: string, timestamp?: number): void;
|
|
1133
|
+
/**
|
|
1134
|
+
* Flush buffered messages for a specific channel to its adapter.
|
|
1135
|
+
* @param channel channel to flush
|
|
1136
|
+
*/
|
|
1137
|
+
private flushChannel;
|
|
1138
|
+
/**
|
|
1139
|
+
* Flush all buffered messages across all channels.
|
|
1140
|
+
*/
|
|
1141
|
+
flushAll(): Promise<void>;
|
|
1142
|
+
/**
|
|
1143
|
+
* Get persisted messages for a channel.
|
|
1144
|
+
* @param channel channel to get messages for
|
|
1145
|
+
* @param since optional cursor (timestamp or message id) to retrieve messages after
|
|
1146
|
+
* @param limit maximum number of messages to retrieve
|
|
1147
|
+
*/
|
|
1148
|
+
getMessages(channel: string, since?: string | number, limit?: number): Promise<PersistedMessage[]>;
|
|
1149
|
+
/**
|
|
1150
|
+
* Handles a record update for potential persistence
|
|
1151
|
+
* @param recordId ID of the record
|
|
1152
|
+
* @param value record value (will be stringified)
|
|
1153
|
+
* @param version record version
|
|
1154
|
+
*/
|
|
1155
|
+
handleRecordUpdate(recordId: string, value: any, version: number): void;
|
|
1156
|
+
/**
|
|
1157
|
+
* Flush all buffered records to storage
|
|
1158
|
+
*/
|
|
1159
|
+
flushRecords(): Promise<void>;
|
|
1160
|
+
/**
|
|
1161
|
+
* Retrieve persisted records matching a pattern
|
|
1162
|
+
* @param pattern pattern to match record IDs
|
|
1163
|
+
* @returns array of persisted records
|
|
1164
|
+
*/
|
|
1165
|
+
getPersistedRecords(pattern: string): Promise<PersistedRecord[]>;
|
|
1166
|
+
/**
|
|
1167
|
+
* Shutdown the persistence manager, flushing pending messages and closing adapters.
|
|
1168
|
+
*/
|
|
1169
|
+
shutdown(): Promise<void>;
|
|
1170
|
+
}
|
|
1171
|
+
|
|
1172
|
+
export { type AuthenticateConnectionFn, type AuthenticationError, type ChannelPattern$1 as ChannelPattern, Connection, ConnectionManager, type CustomPersistedRecord, MeshContext, MeshServer, type MeshServerOptions, MessageStream, type PersistenceAdapter, type PersistenceAdapterOptions, PersistenceManager, type PostgreSQLAdapterOptions, PostgreSQLPersistenceAdapter, PresenceManager, RecordManager, type RecordPersistenceConfig, RoomManager, SQLitePersistenceAdapter, type SocketMiddleware };
|