MCPcopy
hub / github.com/tinyplex/tinybase / loadStoreFromStorage

Function loadStoreFromStorage

src/persisters/persister-partykit-server/index.ts:64–87  ·  view source on GitHub ↗
(
  storage: Storage,
  storagePrefix = EMPTY_STRING,
)

Source from the content-addressed store, hash-verified

62): Promise<boolean> => !!(await storage.get<1>(storagePrefix + HAS_STORE));
63
64export 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
89export const broadcastChanges = async (
90 server: TinyBasePartyKitServer,

Callers 2

partykit.test.tsFile · 0.90
onRequestMethod · 0.85

Calls 3

mapForEachFunction · 0.90
deconstructFunction · 0.90
objEnsureFunction · 0.90

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…