@wovin/core 0.1.17 → 0.1.19
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.
- package/dist/applog/applog-helpers.d.ts +5 -4
- package/dist/applog/applog-helpers.d.ts.map +1 -1
- package/dist/applog.min.js +3 -1
- package/dist/{chunk-C22YMCSL.min.js → chunk-3HHBRM32.min.js} +8 -7
- package/dist/{chunk-C22YMCSL.min.js.map → chunk-3HHBRM32.min.js.map} +1 -1
- package/dist/{chunk-I73T6OVV.min.js → chunk-73CG5VUI.min.js} +20 -4
- package/dist/chunk-73CG5VUI.min.js.map +1 -0
- package/dist/{chunk-MPOFY7NX.min.js → chunk-CZTDDXGE.min.js} +5 -1
- package/dist/{chunk-MPOFY7NX.min.js.map → chunk-CZTDDXGE.min.js.map} +1 -1
- package/dist/{chunk-IIZCL4FQ.min.js → chunk-DYHLKKOE.min.js} +2 -2
- package/dist/chunk-DYHLKKOE.min.js.map +1 -0
- package/dist/{chunk-IFB3AKYA.min.js → chunk-NDHTR5QC.min.js} +2 -2
- package/dist/{chunk-AIITTHC6.min.js → chunk-UJMWWDG4.min.js} +2 -2
- package/dist/{chunk-TPV3JAXV.min.js → chunk-W477A74Z.min.js} +25 -5
- package/dist/chunk-W477A74Z.min.js.map +1 -0
- package/dist/index.min.js +9 -7
- package/dist/ipfs/fetch-snapshot-chain.d.ts +5 -0
- package/dist/ipfs/fetch-snapshot-chain.d.ts.map +1 -1
- package/dist/ipfs.min.js +4 -4
- package/dist/pubsub/pubsub-types.d.ts +1 -0
- package/dist/pubsub/pubsub-types.d.ts.map +1 -1
- package/dist/pubsub/snap-push.d.ts +2 -2
- package/dist/pubsub/snap-push.d.ts.map +1 -1
- package/dist/pubsub.min.js +4 -4
- package/dist/query.min.js +3 -3
- package/dist/retrieve/update-thread.d.ts +7 -0
- package/dist/retrieve/update-thread.d.ts.map +1 -1
- package/dist/retrieve.min.js +4 -4
- package/dist/thread.min.js +1 -1
- package/package.json +2 -1
- package/dist/chunk-I73T6OVV.min.js.map +0 -1
- package/dist/chunk-IIZCL4FQ.min.js.map +0 -1
- package/dist/chunk-TPV3JAXV.min.js.map +0 -1
- /package/dist/{chunk-IFB3AKYA.min.js.map → chunk-NDHTR5QC.min.js.map} +0 -0
- /package/dist/{chunk-AIITTHC6.min.js.map → chunk-UJMWWDG4.min.js.map} +0 -0
|
@@ -3,16 +3,18 @@ import {
|
|
|
3
3
|
areCidsEqual,
|
|
4
4
|
decode,
|
|
5
5
|
g
|
|
6
|
-
} from "./chunk-
|
|
6
|
+
} from "./chunk-CZTDDXGE.min.js";
|
|
7
7
|
|
|
8
8
|
// src/ipfs/fetch-snapshot-chain.ts
|
|
9
9
|
var { WARN, LOG, DEBUG, VERBOSE, ERROR } = g.setup(g.INFO);
|
|
10
10
|
async function fetchSnapshotChainUntil(options) {
|
|
11
|
-
const { rootCID, stopAtCID, fetchBlock, fetchAll, maxDepth = 100 } = options;
|
|
11
|
+
const { rootCID, stopAtCID, stopAtCounter, fetchBlock, fetchAll, maxDepth = 100 } = options;
|
|
12
12
|
const blockStore = createMemoryBlockStore();
|
|
13
13
|
const visited = /* @__PURE__ */ new Set();
|
|
14
14
|
let currentCID = rootCID;
|
|
15
15
|
let snapshotCount = 0;
|
|
16
|
+
let minCounter = Infinity;
|
|
17
|
+
let maxCounter = -Infinity;
|
|
16
18
|
while (currentCID && snapshotCount < maxDepth) {
|
|
17
19
|
const cidStr = currentCID.toString();
|
|
18
20
|
if (visited.has(cidStr)) {
|
|
@@ -31,6 +33,14 @@ async function fetchSnapshotChainUntil(options) {
|
|
|
31
33
|
throw ERROR("[fetchSnapshotChain] root block not in store after fetch", { currentCID: cidStr });
|
|
32
34
|
}
|
|
33
35
|
const root = decode(rootBytes);
|
|
36
|
+
if (root.prevCounter !== void 0) {
|
|
37
|
+
minCounter = Math.min(minCounter, root.prevCounter);
|
|
38
|
+
maxCounter = Math.max(maxCounter, root.prevCounter);
|
|
39
|
+
}
|
|
40
|
+
if (stopAtCounter !== void 0 && root.prevCounter !== void 0 && root.prevCounter <= stopAtCounter) {
|
|
41
|
+
DEBUG("[fetchSnapshotChain] reached stopAtCounter", { stopAtCounter, prevCounter: root.prevCounter });
|
|
42
|
+
break;
|
|
43
|
+
}
|
|
34
44
|
DEBUG("[fetchSnapshotChain] fetching applogs", root.applogs.toString());
|
|
35
45
|
const applogsCar = await fetchAll(root.applogs);
|
|
36
46
|
await addCarBlocksToStore(applogsCar, blockStore);
|
|
@@ -41,7 +51,13 @@ async function fetchSnapshotChainUntil(options) {
|
|
|
41
51
|
currentCID = root.prev;
|
|
42
52
|
}
|
|
43
53
|
DEBUG("[fetchSnapshotChain] done", { snapshotCount, rootCID: rootCID.toString() });
|
|
44
|
-
return {
|
|
54
|
+
return {
|
|
55
|
+
rootCID,
|
|
56
|
+
blockStore,
|
|
57
|
+
blocks: blockStore.getBlocksArray(),
|
|
58
|
+
snapshotCount,
|
|
59
|
+
counterRange: minCounter !== Infinity ? { minCounter, maxCounter } : void 0
|
|
60
|
+
};
|
|
45
61
|
}
|
|
46
62
|
async function addCarBlocksToStore(car, store) {
|
|
47
63
|
for await (const { cid, bytes } of car.blocks()) {
|
|
@@ -67,4 +83,4 @@ function createMemoryBlockStore() {
|
|
|
67
83
|
export {
|
|
68
84
|
fetchSnapshotChainUntil
|
|
69
85
|
};
|
|
70
|
-
//# sourceMappingURL=chunk-
|
|
86
|
+
//# sourceMappingURL=chunk-73CG5VUI.min.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/ipfs/fetch-snapshot-chain.ts"],"sourcesContent":["import { CarReader } from '@ipld/car'\nimport * as dagJson from '@ipld/dag-json'\nimport { Logger } from 'besonders-logger'\nimport { CID } from 'multiformats/cid'\nimport type { SnapRootBlock } from '../pubsub/pubsub-types'\nimport { areCidsEqual } from './ipfs-utils'\n\nconst { WARN, LOG, DEBUG, VERBOSE, ERROR } = Logger.setup(Logger.INFO) // eslint-disable-line no-unused-vars\n\nexport interface BlockStoreForFetch {\n get(cid: CID): Promise<Uint8Array | undefined>\n put(cid: CID, bytes: Uint8Array): Promise<void>\n}\n\nexport interface FetchChainOptions {\n rootCID: CID\n stopAtCID?: CID // Stop when we hit this CID (lastCID from subscription)\n stopAtCounter?: number // Stop when we reach this counter (walking backwards)\n fetchBlock: (cid: CID) => Promise<CarReader> // dag-scope=block\n fetchAll: (cid: CID) => Promise<CarReader> // dag-scope=all\n maxDepth?: number\n}\n\nexport interface FetchChainResult {\n rootCID: CID\n blockStore: BlockStoreForFetch\n /** Serializable blocks array for worker boundary crossing */\n blocks: [string, Uint8Array][]\n snapshotCount: number\n counterRange?: { minCounter: number; maxCounter: number }\n}\n\n/**\n * Fetches a snapshot chain iteratively, stopping at stopAtCID.\n * Uses 3 requests per snapshot: root(block), applogs(all), info(all).\n * This avoids the gateway's dag-scope=all following prev links recursively.\n */\nexport async function fetchSnapshotChainUntil(options: FetchChainOptions): Promise<FetchChainResult> {\n const { rootCID, stopAtCID, stopAtCounter, fetchBlock, fetchAll, maxDepth = 100 } = options\n const blockStore = createMemoryBlockStore()\n const visited = new Set<string>() // Loop detection for fetch\n let currentCID: CID | undefined = rootCID\n let snapshotCount = 0\n let minCounter = Infinity\n let maxCounter = -Infinity\n\n while (currentCID && snapshotCount < maxDepth) {\n const cidStr = currentCID.toString()\n\n // Loop detection\n if (visited.has(cidStr)) {\n throw ERROR('[fetchSnapshotChain] snapshot chain has a loop', { currentCID: cidStr, visited: [...visited] })\n }\n visited.add(cidStr)\n\n // Check stop condition BEFORE fetching content\n if (stopAtCID && areCidsEqual(currentCID, stopAtCID)) {\n DEBUG('[fetchSnapshotChain] reached stopAtCID, stopping', stopAtCID.toString())\n break // We've reached the last pulled snapshot - don't fetch it again\n }\n\n // 1. Fetch root block only (dag-scope=block)\n DEBUG('[fetchSnapshotChain] fetching root block', cidStr)\n const rootCar = await fetchBlock(currentCID)\n await addCarBlocksToStore(rootCar, blockStore)\n\n // Parse root to get applogs, info, prev CIDs\n const rootBytes = await blockStore.get(currentCID)\n if (!rootBytes) {\n throw ERROR('[fetchSnapshotChain] root block not in store after fetch', { currentCID: cidStr })\n }\n const root = dagJson.decode(rootBytes) as SnapRootBlock\n\n // Track counter range\n if (root.prevCounter !== undefined) {\n minCounter = Math.min(minCounter, root.prevCounter)\n maxCounter = Math.max(maxCounter, root.prevCounter)\n }\n\n // Stop condition based on counter\n if (stopAtCounter !== undefined && root.prevCounter !== undefined && root.prevCounter <= stopAtCounter) {\n DEBUG('[fetchSnapshotChain] reached stopAtCounter', { stopAtCounter, prevCounter: root.prevCounter })\n break\n }\n\n // 2. Fetch applogs with dag-scope=all (gets applogs block + all linked applog blocks)\n DEBUG('[fetchSnapshotChain] fetching applogs', root.applogs.toString())\n const applogsCar = await fetchAll(root.applogs)\n await addCarBlocksToStore(applogsCar, blockStore)\n\n // 3. Fetch info with dag-scope=all (gets info block + all linked info log blocks)\n DEBUG('[fetchSnapshotChain] fetching info', root.info.toString())\n const infoCar = await fetchAll(root.info)\n await addCarBlocksToStore(infoCar, blockStore)\n\n snapshotCount++\n currentCID = root.prev // Move to previous snapshot\n }\n\n DEBUG('[fetchSnapshotChain] done', { snapshotCount, rootCID: rootCID.toString() })\n return {\n rootCID,\n blockStore,\n blocks: blockStore.getBlocksArray(),\n snapshotCount,\n counterRange: minCounter !== Infinity ? { minCounter, maxCounter } : undefined,\n }\n}\n\nasync function addCarBlocksToStore(car: CarReader, store: BlockStoreForFetch) {\n for await (const { cid, bytes } of car.blocks()) {\n const validCid = typeof cid.toV1 === 'function' ? cid : CID.decode(cid.bytes)\n await store.put(validCid, bytes)\n }\n}\n\ninterface MemoryBlockStoreWithBlocks extends BlockStoreForFetch {\n /** Get all blocks as serializable array */\n getBlocksArray(): [string, Uint8Array][]\n}\n\nfunction createMemoryBlockStore(): MemoryBlockStoreWithBlocks {\n const blocks = new Map<string, Uint8Array>()\n return {\n async get(cid: CID) {\n return blocks.get(cid.toV1().toString())\n },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, ts };
|
|
10511
10511
|
}
|
|
10512
|
+
function withAg(log, ag) {
|
|
10513
|
+
return hasAg(log) ? log : { ...log, ag };
|
|
10514
|
+
}
|
|
10512
10515
|
function withPvFrom(log, thread) {
|
|
10513
10516
|
DEBUG5(`[withPvFrom] ENTER - en=${log.en}, at=${log.at}, hasPv=${log.pv !== void 0}`);
|
|
10514
10517
|
if (log.pv !== void 0) {
|
|
@@ -11253,6 +11256,7 @@ export {
|
|
|
11253
11256
|
hasTs,
|
|
11254
11257
|
hasPv,
|
|
11255
11258
|
withTs,
|
|
11259
|
+
withAg,
|
|
11256
11260
|
withPvFrom,
|
|
11257
11261
|
joinThreads
|
|
11258
11262
|
};
|
|
@@ -11272,4 +11276,4 @@ lodash-es/lodash.js:
|
|
|
11272
11276
|
@noble/hashes/utils.js:
|
|
11273
11277
|
(*! noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com) *)
|
|
11274
11278
|
*/
|
|
11275
|
-
//# sourceMappingURL=chunk-
|
|
11279
|
+
//# sourceMappingURL=chunk-CZTDDXGE.min.js.map
|