holosphere 2.0.0-alpha6 → 2.0.0-alpha7

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.
Files changed (28) hide show
  1. package/dist/cjs/holosphere.cjs +1 -1
  2. package/dist/esm/holosphere.js +1 -1
  3. package/dist/{index-BtKHqqet.cjs → index-Bvwyvd0T.cjs} +3 -3
  4. package/dist/index-Bvwyvd0T.cjs.map +1 -0
  5. package/dist/{index-CmzkI7SI.cjs → index-C-IlLYlk.cjs} +2 -2
  6. package/dist/{index-CmzkI7SI.cjs.map → index-C-IlLYlk.cjs.map} +1 -1
  7. package/dist/{index-NOravBLu.js → index-d6f4RJBM.js} +35 -52
  8. package/dist/index-d6f4RJBM.js.map +1 -0
  9. package/dist/{index-JFz-dW43.js → index-jmTHEbR2.js} +2 -2
  10. package/dist/{index-JFz-dW43.js.map → index-jmTHEbR2.js.map} +1 -1
  11. package/dist/{indexeddb-storage-OtSAVDZY.js → indexeddb-storage-D8kOl0oK.js} +2 -2
  12. package/dist/{indexeddb-storage-OtSAVDZY.js.map → indexeddb-storage-D8kOl0oK.js.map} +1 -1
  13. package/dist/{indexeddb-storage-C4HsulhA.cjs → indexeddb-storage-a8GipaDr.cjs} +2 -2
  14. package/dist/{indexeddb-storage-C4HsulhA.cjs.map → indexeddb-storage-a8GipaDr.cjs.map} +1 -1
  15. package/dist/{memory-storage-ChpcYvxA.js → memory-storage-DBQK622V.js} +2 -2
  16. package/dist/{memory-storage-ChpcYvxA.js.map → memory-storage-DBQK622V.js.map} +1 -1
  17. package/dist/{memory-storage-MD6ED00P.cjs → memory-storage-gfRovk2O.cjs} +2 -2
  18. package/dist/{memory-storage-MD6ED00P.cjs.map → memory-storage-gfRovk2O.cjs.map} +1 -1
  19. package/dist/{secp256k1-DcTYQrqC.cjs → secp256k1-BCAPF45D.cjs} +2 -2
  20. package/dist/{secp256k1-DcTYQrqC.cjs.map → secp256k1-BCAPF45D.cjs.map} +1 -1
  21. package/dist/{secp256k1-PfNOEI7a.js → secp256k1-DYm_CMqW.js} +2 -2
  22. package/dist/{secp256k1-PfNOEI7a.js.map → secp256k1-DYm_CMqW.js.map} +1 -1
  23. package/package.json +1 -1
  24. package/src/storage/gun-async.js +14 -12
  25. package/src/storage/gun-auth.js +26 -18
  26. package/src/storage/gun-wrapper.js +11 -25
  27. package/dist/index-BtKHqqet.cjs.map +0 -1
  28. package/dist/index-NOravBLu.js.map +0 -1
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "holosphere",
3
- "version": "2.0.0-alpha6",
3
+ "version": "2.0.0-alpha7",
4
4
  "description": "Holonic geospatial communication infrastructure combining H3 hexagonal indexing with distributed P2P storage",
5
5
  "type": "module",
6
6
  "bin": {
@@ -101,22 +101,24 @@ export async function gunMap(gunChain, timeout = 5000) {
101
101
  return;
102
102
  }
103
103
 
104
- // Count references that need fetching
105
- expectedCount = keys.filter(k => {
106
- const item = parentData[k];
107
- return item && typeof item === 'object' && item['#'];
108
- }).length;
109
-
110
- // If no references, we're done
111
- if (expectedCount === 0) {
112
- settled = true;
113
- resolve({});
114
- return;
104
+ // Pre-collect inline items (not Gun references)
105
+ for (const key of keys) {
106
+ const rawItem = parentData[key];
107
+ if (!rawItem) continue;
108
+
109
+ // Skip Gun references - will be fetched via map().once()
110
+ if (typeof rawItem === 'object' && rawItem['#']) continue;
111
+
112
+ items[key] = rawItem;
115
113
  }
116
114
 
117
- // Step 2: Collect items, counting as we go
115
+ // Expected count is ALL keys (map().once() fires for all)
116
+ expectedCount = keys.length;
117
+
118
+ // Step 2: Collect items via map().once(), counting as we go
118
119
  gunChain.map().once((data, key) => {
119
120
  if (settled || !data || key.startsWith('_')) return;
121
+ // Add/update the item (inline items may be updated by map().once())
120
122
  items[key] = data;
121
123
  receivedCount++;
122
124
  tryResolve();
@@ -274,28 +274,36 @@ export class GunAuth {
274
274
  return;
275
275
  }
276
276
 
277
- // Count references that need fetching
278
- expectedCount = keys.filter(k => {
279
- const item = parentData[k];
280
- return item && typeof item === 'object' && item['#'];
281
- }).length;
282
-
283
- // If no references, we're done
284
- if (expectedCount === 0) {
285
- settled = true;
286
- resolve([]);
287
- return;
288
- }
277
+ // Pre-parse inline items (not Gun references)
278
+ for (const key of keys) {
279
+ const rawItem = parentData[key];
280
+ if (!rawItem) continue;
289
281
 
290
- // Step 2: Collect items, counting as we go
291
- ref.map().once((data, key) => {
292
- if (settled || !data || key.startsWith('_') || seen.has(key)) return;
293
- seen.add(key);
282
+ // Skip Gun references - will be fetched via map().once()
283
+ if (typeof rawItem === 'object' && rawItem['#']) continue;
294
284
 
295
- const parsed = parseItem(data);
296
- if (parsed && !parsed._deleted) {
285
+ const parsed = parseItem(rawItem);
286
+ if (parsed && !parsed._deleted && !seen.has(key)) {
287
+ seen.add(key);
297
288
  results.push(parsed);
298
289
  }
290
+ }
291
+
292
+ // Expected count is ALL keys (map().once() fires for all)
293
+ expectedCount = keys.length;
294
+
295
+ // Step 2: Collect items via map().once(), counting as we go
296
+ ref.map().once((data, key) => {
297
+ if (settled || !data || key.startsWith('_')) return;
298
+
299
+ // Count every item, but only add if not already seen
300
+ if (!seen.has(key)) {
301
+ seen.add(key);
302
+ const parsed = parseItem(data);
303
+ if (parsed && !parsed._deleted) {
304
+ results.push(parsed);
305
+ }
306
+ }
299
307
  receivedCount++;
300
308
  tryResolve();
301
309
  });
@@ -210,19 +210,7 @@ export async function readAll(gun, path, timeout = 5000) {
210
210
  };
211
211
 
212
212
  const parseItem = (data) => {
213
- if (!data) return null;
214
-
215
- let item = null;
216
- if (data._json && typeof data._json === 'string') {
217
- try {
218
- item = JSON.parse(data._json);
219
- } catch (e) {}
220
- } else if (typeof data === 'string') {
221
- try {
222
- item = JSON.parse(data);
223
- } catch (e) {}
224
- }
225
- return item;
213
+ return deserializeFromGun(data);
226
214
  };
227
215
 
228
216
  // Step 1: Get the parent data to count expected items
@@ -257,40 +245,38 @@ export async function readAll(gun, path, timeout = 5000) {
257
245
  continue;
258
246
  }
259
247
 
260
- // Try to parse inline data
248
+ // Try to parse inline data (don't count yet - will count in map().once() phase)
261
249
  const item = parseItem(rawItem);
262
250
  if (item && item.id && !item._deleted) {
263
251
  output.set(item.id, item);
264
- receivedCount++;
265
252
  }
266
253
  }
267
254
 
268
- // Set expected count: references that need fetching
269
- expectedCount = referenceKeys.length;
255
+ // Set expected count: ALL keys that could have data (references + inline)
256
+ // We use total keys because map().once() will fire for all of them
257
+ expectedCount = keys.length;
270
258
 
271
- // If no references to resolve, we're done
259
+ // If no keys, we're done (shouldn't happen but be safe)
272
260
  if (expectedCount === 0) {
273
261
  settled = true;
274
262
  resolve(Array.from(output.values()));
275
263
  return;
276
264
  }
277
265
 
278
- // Step 2: Use map().once() to resolve references, counting as we go
266
+ // Step 2: Use map().once() to resolve all items, counting as we go
279
267
  ref.map().once((data, key) => {
280
268
  if (settled || !data || key === '_') return;
281
269
 
282
270
  const item = parseItem(data);
283
271
  if (item && item.id && !item._deleted) {
272
+ // Add to output if not already there (inline items already added)
284
273
  if (!output.has(item.id)) {
285
274
  output.set(item.id, item);
286
- receivedCount++;
287
- tryResolve();
288
275
  }
289
- } else {
290
- // Item was null/deleted, still count it as received
291
- receivedCount++;
292
- tryResolve();
293
276
  }
277
+ // Count every item received (inline or reference)
278
+ receivedCount++;
279
+ tryResolve();
294
280
  });
295
281
  });
296
282