( storage: Storage, storagePrefix = EMPTY_STRING, )
| 62 | ): Promise<boolean> => !!(await storage.get<1>(storagePrefix + HAS_STORE)); |
| 63 | |
| 64 | export const loadStoreFromStorage = async ( |
| 65 | storage: Storage, |
| 66 | storagePrefix = EMPTY_STRING, |
| 67 | ): Promise<Content> => { |
| 68 | const tables: Tables = {}; |
| 69 | const values: Values = {}; |
| 70 | mapForEach( |
| 71 | await storage.list<string | number | boolean>(), |
| 72 | (key, cellOrValue) => |
| 73 | ifNotUndefined(deconstruct(storagePrefix, key), ([type, ids]) => { |
| 74 | if (type == T) { |
| 75 | const [tableId, rowId, cellId] = jsonParse('[' + ids + ']'); |
| 76 | objEnsure( |
| 77 | objEnsure(tables, tableId, objNew<Row>), |
| 78 | rowId, |
| 79 | objNew<Cell>, |
| 80 | )[cellId] = cellOrValue; |
| 81 | } else if (type == V) { |
| 82 | values[ids] = cellOrValue; |
| 83 | } |
| 84 | }), |
| 85 | ); |
| 86 | return [tables, values]; |
| 87 | }; |
| 88 | |
| 89 | export const broadcastChanges = async ( |
| 90 | server: TinyBasePartyKitServer, |
no test coverage detected
searching dependent graphs…