1
- import { BuildURI , Lazy , ResolveOnce , runtimeFn , URI } from "@adviser/cement" ;
1
+ import { BuildURI , ResolveOnce , runtimeFn , URI } from "@adviser/cement" ;
2
2
import { SuperThis , PARAM } from "@fireproof/core-types-base" ;
3
- import { SerdeGateway , Gateway } from "@fireproof/core-types-blockstore" ;
4
- import { MemoryGateway } from "@fireproof/core-gateways-memory" ;
5
- import { FileGateway , FILESTORE_VERSION , sysFileSystemFactory } from "@fireproof/core-gateways-file" ;
3
+ import { SerdeGateway , Gateway , FPIndexedDB } from "@fireproof/core-types-blockstore" ;
4
+ import { memFPIndexedDB , MemoryGateway } from "@fireproof/core-gateways-memory" ;
5
+ import { FileGateway , FILESTORE_VERSION , sysFileFPIndexedDB , sysFileSystemFactory } from "@fireproof/core-gateways-file" ;
6
6
import { DefSerdeGateway , INDEXEDDB_VERSION } from "@fireproof/core-gateways-base" ;
7
7
import { CloudGateway } from "@fireproof/core-gateways-cloud" ;
8
- import { FPSyncProtocol } from "../types/protocols/sync/index.js" ;
9
8
10
9
export interface SerdeGatewayFactoryItem {
11
10
readonly protocol : string ;
12
11
readonly isDefault ?: boolean ;
13
12
defaultURI ( sthis : SuperThis ) : URI ;
14
13
serdegateway ( sthis : SuperThis ) : Promise < SerdeGateway > ;
15
- fpsync ( sthis : SuperThis , uri : URI ) : Promise < FPSyncProtocol < unknown > > ;
14
+ fpIndexedDB ( sthis : SuperThis , uri : URI ) : Promise < FPIndexedDB > ;
16
15
}
17
16
18
17
class OneSerdeGatewayFactoryItem implements SerdeGatewayFactoryItem {
@@ -45,7 +44,9 @@ class OneSerdeGatewayFactoryItem implements SerdeGatewayFactoryItem {
45
44
return this . once . once ( ( ) => this . item . serdegateway ( sthis ) ) ;
46
45
}
47
46
48
- fpsync = Lazy ( ( sthis : SuperThis , uri : URI ) => this . item . fpsync ( sthis , uri ) ) ;
47
+ async fpIndexedDB ( sthis : SuperThis , uri : URI ) : Promise < FPIndexedDB > {
48
+ return this . item . fpIndexedDB ( sthis , uri ) ;
49
+ }
49
50
}
50
51
51
52
const storeFactory = new Map < string , OneSerdeGatewayFactoryItem > ( ) ;
@@ -76,11 +77,10 @@ export interface SerdeOrGatewayFactoryItem {
76
77
readonly serdegateway ?: ( sthis : SuperThis ) => Promise < SerdeGateway > ;
77
78
readonly gateway ?: ( sthis : SuperThis ) => Promise < Gateway > ;
78
79
79
- readonly fpsync : ( sthis : SuperThis , uri : URI ) => Promise < FPSyncProtocol < unknown > > ;
80
+ readonly fpIndexedDB : ( sthis : SuperThis , uri : URI ) => Promise < FPIndexedDB > ;
80
81
}
81
82
82
83
export function registerStoreProtocol ( item : SerdeOrGatewayFactoryItem ) : ( ) => void {
83
- console . log ( "registerStoreProtocol" , item . protocol ) ;
84
84
let protocol = item . protocol ;
85
85
if ( ! protocol . endsWith ( ":" ) ) {
86
86
protocol += ":" ;
@@ -151,10 +151,8 @@ if (runtimeFn().isNodeIsh || runtimeFn().isDeno) {
151
151
gateway : async ( sthis ) => {
152
152
return new FileGateway ( sthis , await sysFileSystemFactory ( defaultURI ( sthis ) ) ) ;
153
153
} ,
154
- fpsync : async ( _sthis , _uri ) => {
155
- throw new Error ( "fpsync for file: Not implemented" ) ;
156
- // const { fileFPSync } = await import("@fireproof/core-gateways-file");
157
- // return fileFPSync(sthis, uri) as Promise<FPSyncProtocol<unknown>>;
154
+ fpIndexedDB : async ( sthis , uri ) => {
155
+ return sysFileFPIndexedDB ( sthis , uri ) ;
158
156
} ,
159
157
} ) ;
160
158
}
@@ -174,9 +172,9 @@ if (runtimeFn().isBrowser) {
174
172
const { GatewayImpl } = await import ( "@fireproof/core-gateways-indexeddb" ) ;
175
173
return new GatewayImpl ( ) ;
176
174
} ,
177
- fpsync : async ( sthis , uri ) => {
178
- const { indexedDBFPSync } = await import ( "@fireproof/core-gateways-indexeddb" ) ;
179
- return indexedDBFPSync ( sthis , uri ) as Promise < FPSyncProtocol < unknown > > ;
175
+ fpIndexedDB : async ( sthis , uri ) => {
176
+ const { indexeddbFPIndexedDB } = await import ( "@fireproof/core-gateways-indexeddb" ) ;
177
+ return indexeddbFPIndexedDB ( sthis , uri ) ;
180
178
} ,
181
179
} ) ;
182
180
}
@@ -191,10 +189,9 @@ registerStoreProtocol({
191
189
gateway : async ( sthis ) => {
192
190
return new MemoryGateway ( sthis , memory ) ;
193
191
} ,
194
- fpsync : ( ) => {
195
- throw new Error ( "fpsync for memory: Not implemented" ) ;
196
- // memoryFPSync as (sthis: SuperThis, uri: URI) => Promise<FPSyncProtocol<unknown>>,
197
- }
192
+ fpIndexedDB : ( sthis , uri ) => {
193
+ return memFPIndexedDB ( sthis , uri , memory ) ;
194
+ } ,
198
195
} ) ;
199
196
200
197
//const onceRegisterFireproofCloudStoreProtocol = new KeyedResolvOnce<() => void>();
@@ -209,7 +206,7 @@ registerStoreProtocol({
209
206
serdegateway : async ( sthis : SuperThis ) => {
210
207
return new CloudGateway ( sthis ) ;
211
208
} ,
212
- fpsync : async ( ) => {
209
+ fpIndexedDB : async ( ) => {
213
210
throw new Error ( "fpsync for fpcloud: Not implemented" ) ;
214
211
} ,
215
212
} ) ;
0 commit comments