@@ -25,15 +25,17 @@ namespace Magic.IndexedDb
2525 internal class IndexedDbManager
2626 {
2727 private readonly IJSObjectReference _jsModule ; // Shared JS module
28+ private readonly long _jsMessageSizeBytes ;
2829
2930 /// <summary>
3031 /// Ctor
3132 /// </summary>
3233 /// <param name="dbStore"></param>
3334 /// <param name="jsRuntime"></param>
34- internal IndexedDbManager ( IJSObjectReference jsModule )
35+ internal IndexedDbManager ( IJSObjectReference jsModule , long jsMessageSizeBytes )
3536 {
3637 _jsModule = jsModule ; // Use shared JS module reference
38+ _jsMessageSizeBytes = jsMessageSizeBytes ;
3739 }
3840
3941 //public string DbName => _dbStore.Name;
@@ -49,7 +51,7 @@ internal Task DeleteDbAsync(string dbName)
4951 {
5052 throw new ArgumentException ( "dbName cannot be null or empty" , nameof ( dbName ) ) ;
5153 }
52- return new MagicJsInvoke ( _jsModule ) . CallInvokeVoidDefaultJsAsync ( Cache . MagicDbJsImportPath ,
54+ return new MagicJsInvoke ( _jsModule , _jsMessageSizeBytes ) . CallInvokeVoidDefaultJsAsync ( Cache . MagicDbJsImportPath ,
5355 IndexedDbFunctions . DELETE_DB , dbName ) ;
5456 }
5557
@@ -59,7 +61,7 @@ internal Task CloseDbAsync(string dbName)
5961 {
6062 throw new ArgumentException ( "dbName cannot be null or empty" , nameof ( dbName ) ) ;
6163 }
62- return new MagicJsInvoke ( _jsModule ) . CallInvokeVoidDefaultJsAsync ( Cache . MagicDbJsImportPath ,
64+ return new MagicJsInvoke ( _jsModule , _jsMessageSizeBytes ) . CallInvokeVoidDefaultJsAsync ( Cache . MagicDbJsImportPath ,
6365 IndexedDbFunctions . CLOSE_DB , dbName ) ;
6466 }
6567
@@ -69,7 +71,7 @@ internal Task OpenDbAsync(string dbName)
6971 {
7072 throw new ArgumentException ( "dbName cannot be null or empty" , nameof ( dbName ) ) ;
7173 }
72- return new MagicJsInvoke ( _jsModule ) . CallInvokeVoidDefaultJsAsync ( Cache . MagicDbJsImportPath ,
74+ return new MagicJsInvoke ( _jsModule , _jsMessageSizeBytes ) . CallInvokeVoidDefaultJsAsync ( Cache . MagicDbJsImportPath ,
7375 IndexedDbFunctions . OPEN_DB , dbName ) ;
7476 }
7577
@@ -79,7 +81,7 @@ internal Task<bool> DoesDbExist(string dbName)
7981 {
8082 throw new ArgumentException ( "dbName cannot be null or empty" , nameof ( dbName ) ) ;
8183 }
82- return new MagicJsInvoke ( _jsModule ) . CallInvokeDefaultJsAsync < bool > ( Cache . MagicDbJsImportPath ,
84+ return new MagicJsInvoke ( _jsModule , _jsMessageSizeBytes ) . CallInvokeDefaultJsAsync < bool > ( Cache . MagicDbJsImportPath ,
8385 IndexedDbFunctions . DOES_DB_EXIST , dbName ) ;
8486 }
8587
@@ -89,7 +91,7 @@ internal Task<bool> IsDbOpen(string dbName)
8991 {
9092 throw new ArgumentException ( "dbName cannot be null or empty" , nameof ( dbName ) ) ;
9193 }
92- return new MagicJsInvoke ( _jsModule ) . CallInvokeDefaultJsAsync < bool > ( Cache . MagicDbJsImportPath ,
94+ return new MagicJsInvoke ( _jsModule , _jsMessageSizeBytes ) . CallInvokeDefaultJsAsync < bool > ( Cache . MagicDbJsImportPath ,
9395 IndexedDbFunctions . IS_DB_CLosed , dbName ) ;
9496 }
9597
@@ -103,7 +105,7 @@ internal async Task<TKey> AddAsync<T, TKey>(T record, string dbName, Cancellatio
103105 StoreName = schemaName ,
104106 Record = record
105107 } ;
106- return await new MagicJsInvoke ( _jsModule ) . CallJsAsync < TKey > ( Cache . MagicDbJsImportPath ,
108+ return await new MagicJsInvoke ( _jsModule , _jsMessageSizeBytes ) . CallJsAsync < TKey > ( Cache . MagicDbJsImportPath ,
107109 IndexedDbFunctions . ADD_ITEM , cancellationToken , new TypedArgument < StoreRecord < T ? > > ( RecordToSend ) )
108110 ?? throw new Exception ( $ "An Error occurred trying to add your record of type: { typeof ( T ) . Name } ") ;
109111 }
@@ -122,7 +124,7 @@ internal Task BulkAddRecordAsync<T>(
122124 {
123125 // TODO: https://github.com/magiccodingman/Magic.IndexedDb/issues/9
124126
125- return new MagicJsInvoke ( _jsModule ) . CallJsAsync ( Cache . MagicDbJsImportPath , IndexedDbFunctions . BULKADD_ITEM , cancellationToken ,
127+ return new MagicJsInvoke ( _jsModule , _jsMessageSizeBytes ) . CallJsAsync ( Cache . MagicDbJsImportPath , IndexedDbFunctions . BULKADD_ITEM , cancellationToken ,
126128 new ITypedArgument [ ] { new TypedArgument < string > ( dbName ) ,
127129 new TypedArgument < string > ( storeName ) ,
128130 new TypedArgument < IEnumerable < T > > ( recordsToBulkAdd ) } ) ;
@@ -146,13 +148,13 @@ internal async Task<int> UpdateAsync<T>(T item, string dbName, CancellationToken
146148 Record = item
147149 } ;
148150
149- return await new MagicJsInvoke ( _jsModule ) . CallJsAsync < int > ( Cache . MagicDbJsImportPath ,
151+ return await new MagicJsInvoke ( _jsModule , _jsMessageSizeBytes ) . CallJsAsync < int > ( Cache . MagicDbJsImportPath ,
150152 IndexedDbFunctions . UPDATE_ITEM , cancellationToken , new TypedArgument < UpdateRecord < T ? > > ( record ) ) ;
151153 }
152154
153155 internal async Task < int > CountEntireTableAsync < T > ( string schemaName , string dbName )
154156 {
155- return await new MagicJsInvoke ( _jsModule ) . CallInvokeDefaultJsAsync < int > ( Cache . MagicDbJsImportPath ,
157+ return await new MagicJsInvoke ( _jsModule , _jsMessageSizeBytes ) . CallInvokeDefaultJsAsync < int > ( Cache . MagicDbJsImportPath ,
156158 IndexedDbFunctions . COUNT_TABLE ,
157159 dbName , schemaName
158160 ) ;
@@ -179,7 +181,7 @@ internal async Task<int> UpdateRangeAsync<T>(
179181 } ;
180182 } ) ;
181183
182- return await new MagicJsInvoke ( _jsModule ) . CallJsAsync < int > ( Cache . MagicDbJsImportPath ,
184+ return await new MagicJsInvoke ( _jsModule , _jsMessageSizeBytes ) . CallJsAsync < int > ( Cache . MagicDbJsImportPath ,
183185 IndexedDbFunctions . BULKADD_UPDATE , cancellationToken , new TypedArgument < IEnumerable < UpdateRecord < T > > > ( recordsToUpdate ) ) ;
184186 }
185187
@@ -218,7 +220,7 @@ internal IMagicDatabaseScoped Database(IndexedDbManager manager, IndexedDbSet in
218220 new TypedArgument < bool > ( query ? . ForceCursorMode ?? false ) ,
219221 } ;
220222
221- return await new MagicJsInvoke ( _jsModule ) . CallJsAsync < IEnumerable < T > >
223+ return await new MagicJsInvoke ( _jsModule , _jsMessageSizeBytes ) . CallJsAsync < IEnumerable < T > >
222224 ( Cache . MagicDbJsImportPath , IndexedDbFunctions . MAGIC_QUERY_ASYNC , cancellationToken ,
223225 args ) ;
224226 }
@@ -249,7 +251,7 @@ internal IMagicDatabaseScoped Database(IndexedDbManager manager, IndexedDbSet in
249251 } ;
250252
251253 // Yield results **as they arrive** from JS
252- await foreach ( var item in new MagicJsInvoke ( _jsModule ) . CallYieldJsAsync < T > ( Cache . MagicDbJsImportPath , IndexedDbFunctions . MAGIC_QUERY_YIELD , cancellationToken , args ) )
254+ await foreach ( var item in new MagicJsInvoke ( _jsModule , _jsMessageSizeBytes ) . CallYieldJsAsync < T > ( Cache . MagicDbJsImportPath , IndexedDbFunctions . MAGIC_QUERY_YIELD , cancellationToken , args ) )
253255 {
254256 yield return item ; // Stream each item immediately
255257 }
@@ -269,7 +271,7 @@ internal async Task DeleteAsync<T>(T item, string dbName, CancellationToken canc
269271 Record = item
270272 } ;
271273
272- await new MagicJsInvoke ( _jsModule ) . CallJsAsync ( Cache . MagicDbJsImportPath , IndexedDbFunctions . DELETE_ITEM , cancellationToken , new TypedArgument < UpdateRecord < T ? > > ( record ) ) ;
274+ await new MagicJsInvoke ( _jsModule , _jsMessageSizeBytes ) . CallJsAsync ( Cache . MagicDbJsImportPath , IndexedDbFunctions . DELETE_ITEM , cancellationToken , new TypedArgument < UpdateRecord < T ? > > ( record ) ) ;
273275 }
274276
275277 internal async Task < int > DeleteRangeAsync < T > (
@@ -290,7 +292,7 @@ internal async Task<int> DeleteRangeAsync<T>(
290292 new TypedArgument < string > ( schemaName ) ,
291293 new TypedArgument < IEnumerable < object > ? > ( keys ) } ;
292294
293- return await new MagicJsInvoke ( _jsModule ) . CallJsAsync < int > ( Cache . MagicDbJsImportPath ,
295+ return await new MagicJsInvoke ( _jsModule , _jsMessageSizeBytes ) . CallJsAsync < int > ( Cache . MagicDbJsImportPath ,
294296 IndexedDbFunctions . BULK_DELETE , cancellationToken ,
295297 args ) ;
296298 }
@@ -304,7 +306,7 @@ internal async Task<int> DeleteRangeAsync<T>(
304306 /// <returns></returns>
305307 internal Task ClearTableAsync ( string storeName , string dbName )
306308 {
307- return new MagicJsInvoke ( _jsModule ) . CallInvokeVoidDefaultJsAsync ( Cache . MagicDbJsImportPath ,
309+ return new MagicJsInvoke ( _jsModule , _jsMessageSizeBytes ) . CallInvokeVoidDefaultJsAsync ( Cache . MagicDbJsImportPath ,
308310 IndexedDbFunctions . CLEAR_TABLE , dbName , storeName ) ;
309311 }
310312
0 commit comments