@xyo-network/xl1-driver-mongodb 4.0.8 → 4.0.9
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/README.md +5 -0
- package/dist/neutral/MongoIndexPublishRunner.d.ts +65 -0
- package/dist/neutral/MongoIndexPublishRunner.d.ts.map +1 -0
- package/dist/neutral/MongoIndexViewer.d.ts +45 -0
- package/dist/neutral/MongoIndexViewer.d.ts.map +1 -0
- package/dist/neutral/index.d.ts +3 -0
- package/dist/neutral/index.d.ts.map +1 -1
- package/dist/neutral/index.mjs +298 -1
- package/dist/neutral/index.mjs.map +4 -4
- package/dist/neutral/mongoConnectionSdkConfig.d.ts +7 -0
- package/dist/neutral/mongoConnectionSdkConfig.d.ts.map +1 -0
- package/package.json +53 -45
package/README.md
CHANGED
|
@@ -44,6 +44,11 @@ bun add @xyo-network/xl1-driver-mongodb
|
|
|
44
44
|
## What's Inside
|
|
45
45
|
|
|
46
46
|
- **`MongoMap`** — a `MongoDB`-backed `AsyncIterableMap<K, V>`: async `get`/`set`/`has`/`getMany`/`setMany`/`delete`/`clear`, optional `LruCacheMap` read cache, and cursor-streamed iteration over the whole collection.
|
|
47
|
+
- **`MongoIndexViewer`** — an `IndexViewer` provider that reads published step-summary documents from a shared Mongo collection, keyed identically to the static REST layout (`indexSummaryPath`).
|
|
48
|
+
- **`MongoIndexPublishRunner`** — an `IndexPublishRunner` provider that builds and writes the multi-family chain index (blocks, balances, schemas, transfers) to that same collection, immutable-frame and watermark-last semantics matching the S3-backed publisher.
|
|
49
|
+
- **`mongoConnectionSdkConfig`** — maps a `mongo` connection config (`connectionString`/`database`/`domain`/`password`/`username`/`collection`) to the `BaseMongoSdk` config shape, defaulting to the `index` collection when the connection doesn't specify its own.
|
|
50
|
+
|
|
51
|
+
`MongoIndexViewer`/`MongoIndexPublishRunner` are Node-only (they depend on the `mongodb` driver) and are not part of `@xyo-network/xl1-providers`' universal (browser + node) candidate registry — construct and register them directly in a Node-side locator, e.g. `locator.register(MongoIndexViewer.factory(MongoIndexViewer.dependencies, {}))`, resolving their Mongo connection from `providerBindings`/`connections` or by passing `connection`/`map` explicitly.
|
|
47
52
|
|
|
48
53
|
## Building Locally
|
|
49
54
|
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import type { BlockViewer, IndexPublishRunner, IndexSummaryFamily, IndexWatermark, MapType, XL1BlockNumber } from '@xyo-network/xl1-protocol-lib';
|
|
2
|
+
import type { CreatableProviderParams, MongoConnectionConfig } from '@xyo-network/xl1-protocol-sdk';
|
|
3
|
+
import { AbstractCreatableProvider } from '@xyo-network/xl1-protocol-sdk';
|
|
4
|
+
import type { Document } from 'mongodb';
|
|
5
|
+
/** Parameters for MongoIndexPublishRunner. */
|
|
6
|
+
export interface MongoIndexPublishRunnerParams extends CreatableProviderParams {
|
|
7
|
+
connection?: MongoConnectionConfig;
|
|
8
|
+
/** Pre-built backing map (tests, or a caller-managed Mongo connection). Defaults to a `MongoMap` built from `connection`. */
|
|
9
|
+
map?: MapType<string, Document>;
|
|
10
|
+
/**
|
|
11
|
+
* The viewer to build the index from (only finalized chains should be indexed). When omitted,
|
|
12
|
+
* resolved from the locator via BlockViewerMoniker.
|
|
13
|
+
*/
|
|
14
|
+
source?: BlockViewer;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Publishes the multi-family chain index (blocks, balances, schemas, transfers) to a shared Mongo
|
|
18
|
+
* collection that `MongoIndexViewer` reads, using the same document-id scheme (`indexSummaryPath`)
|
|
19
|
+
* as the static REST layout. Frames are immutable: only complete frames are ever published, and a
|
|
20
|
+
* completed frame never changes. The head watermark and manifest are written last so a reader
|
|
21
|
+
* never sees a watermark pointing past the frames that back it.
|
|
22
|
+
*/
|
|
23
|
+
export declare class MongoIndexPublishRunner extends AbstractCreatableProvider<MongoIndexPublishRunnerParams> implements IndexPublishRunner {
|
|
24
|
+
static readonly connectionTypes: readonly ["mongo"];
|
|
25
|
+
static readonly defaultMoniker: "IndexPublishRunner";
|
|
26
|
+
static readonly dependencies: "BlockViewer"[];
|
|
27
|
+
static readonly monikers: "IndexPublishRunner"[];
|
|
28
|
+
moniker: "IndexPublishRunner";
|
|
29
|
+
protected _map: MapType<string, Document>;
|
|
30
|
+
protected _source?: BlockViewer;
|
|
31
|
+
get source(): BlockViewer;
|
|
32
|
+
static paramsHandler(params: Partial<MongoIndexPublishRunnerParams>): Promise<{
|
|
33
|
+
connection: {
|
|
34
|
+
type: "mongo";
|
|
35
|
+
connectionString?: string | undefined;
|
|
36
|
+
database?: string | undefined;
|
|
37
|
+
domain?: string | undefined;
|
|
38
|
+
password?: string | undefined;
|
|
39
|
+
username?: string | undefined;
|
|
40
|
+
collection?: string | undefined;
|
|
41
|
+
} | undefined;
|
|
42
|
+
map: MapType<string, Document> | undefined;
|
|
43
|
+
source: BlockViewer<"BlockViewer"> | undefined;
|
|
44
|
+
context: import("@xyo-network/xl1-protocol-sdk").CreatableProviderContextType;
|
|
45
|
+
name?: import("@ariestools/sdk").CreatableName;
|
|
46
|
+
statusReporter?: import("@ariestools/sdk").CreatableStatusReporter<void> | undefined;
|
|
47
|
+
logger?: import("@ariestools/sdk").Logger;
|
|
48
|
+
meterProvider?: import("@opentelemetry/api").MeterProvider;
|
|
49
|
+
traceProvider?: import("@opentelemetry/api").TracerProvider;
|
|
50
|
+
}>;
|
|
51
|
+
createHandler(): Promise<void>;
|
|
52
|
+
/** Builds every family's frames completed up to the ceiling, then writes the manifest and watermark. */
|
|
53
|
+
publishCompletedFramesUpTo(ceiling: XL1BlockNumber): Promise<IndexWatermark>;
|
|
54
|
+
/** Publishes one completed frame for a family (and any missing sub-frames it depends on). */
|
|
55
|
+
publishFrame(family: IndexSummaryFamily, stepLevel: number, stepIndex: number): Promise<void>;
|
|
56
|
+
/** Dispatches a single frame to its family builder, writing it (and missing sub-frames) to the collection. */
|
|
57
|
+
private buildFamilyFrame;
|
|
58
|
+
/** Builds a family's frames in (previous, ceiling] across every level; returns total completed frames. */
|
|
59
|
+
private publishFamily;
|
|
60
|
+
private readWatermark;
|
|
61
|
+
private summaryMap;
|
|
62
|
+
private writeHead;
|
|
63
|
+
private writeManifest;
|
|
64
|
+
}
|
|
65
|
+
//# sourceMappingURL=MongoIndexPublishRunner.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"MongoIndexPublishRunner.d.ts","sourceRoot":"","sources":["../../src/MongoIndexPublishRunner.ts"],"names":[],"mappings":"AAYA,OAAO,KAAK,EACA,WAAW,EAAkB,kBAAkB,EAAE,kBAAkB,EAAE,cAAc,EAAE,OAAO,EACtG,cAAc,EACf,MAAM,+BAA+B,CAAA;AAItC,OAAO,KAAK,EAAE,uBAAuB,EAAE,qBAAqB,EAAE,MAAM,+BAA+B,CAAA;AACnG,OAAO,EACL,yBAAyB,EAO1B,MAAM,+BAA+B,CAAA;AAEtC,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAA;AAgGvC,8CAA8C;AAC9C,MAAM,WAAW,6BAA8B,SAAQ,uBAAuB;IAC5E,UAAU,CAAC,EAAE,qBAAqB,CAAA;IAClC,6HAA6H;IAC7H,GAAG,CAAC,EAAE,OAAO,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAA;IAC/B;;;OAGG;IACH,MAAM,CAAC,EAAE,WAAW,CAAA;CACrB;AAED;;;;;;GAMG;AACH,qBACa,uBAAwB,SAAQ,yBAAyB,CAAC,6BAA6B,CAAE,YAAW,kBAAkB;IACjI,MAAM,CAAC,QAAQ,CAAC,eAAe,qBAAqB;IACpD,MAAM,CAAC,QAAQ,CAAC,cAAc,uBAA4B;IAC1D,MAAM,CAAC,QAAQ,CAAC,YAAY,kBAAuB;IACnD,MAAM,CAAC,QAAQ,CAAC,QAAQ,yBAA8B;IACtD,OAAO,uBAAyC;IAEhD,SAAS,CAAC,IAAI,EAAG,OAAO,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAA;IAC1C,SAAS,CAAC,OAAO,CAAC,EAAE,WAAW,CAAA;IAE/B,IAAI,MAAM,IAAI,WAAW,CAExB;WAEqB,aAAa,CAAC,MAAM,EAAE,OAAO,CAAC,6BAA6B,CAAC;;;;;;;;;;;;;;;;;;;IAgBnE,aAAa;IAc5B,wGAAwG;IAClG,0BAA0B,CAAC,OAAO,EAAE,cAAc,GAAG,OAAO,CAAC,cAAc,CAAC;IAqBlF,6FAA6F;IACvF,YAAY,CAAC,MAAM,EAAE,kBAAkB,EAAE,SAAS,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAUnG,8GAA8G;YAChG,gBAAgB;IAsB9B,0GAA0G;YAC5F,aAAa;YAwBb,aAAa;IAK3B,OAAO,CAAC,UAAU;YAIJ,SAAS;YAKT,aAAa;CAS5B"}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import type { IndexSummaryFamily, IndexViewer, MapType } from '@xyo-network/xl1-protocol-lib';
|
|
2
|
+
import type { CreatableProviderParams, MongoConnectionConfig } from '@xyo-network/xl1-protocol-sdk';
|
|
3
|
+
import { AbstractCreatableProvider } from '@xyo-network/xl1-protocol-sdk';
|
|
4
|
+
import type { Document } from 'mongodb';
|
|
5
|
+
/** Parameters for MongoIndexViewer. */
|
|
6
|
+
export interface MongoIndexViewerParams extends CreatableProviderParams {
|
|
7
|
+
connection?: MongoConnectionConfig;
|
|
8
|
+
/** Pre-built backing map (tests, or a caller-managed Mongo connection). Defaults to a `MongoMap` built from `connection`. */
|
|
9
|
+
map?: MapType<string, Document>;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* An IndexViewer over the same chain index a `MongoIndexPublishRunner` writes to: reads
|
|
13
|
+
* completed step-summary documents from a shared Mongo collection, keyed identically to the
|
|
14
|
+
* static REST layout (`indexSummaryPath`) so both backends can serve the same logical index.
|
|
15
|
+
*/
|
|
16
|
+
export declare class MongoIndexViewer extends AbstractCreatableProvider<MongoIndexViewerParams> implements IndexViewer {
|
|
17
|
+
static readonly connectionTypes: readonly ["mongo"];
|
|
18
|
+
static readonly defaultMoniker: "IndexViewer";
|
|
19
|
+
static readonly dependencies: never[];
|
|
20
|
+
static readonly monikers: "IndexViewer"[];
|
|
21
|
+
moniker: "IndexViewer";
|
|
22
|
+
private _map;
|
|
23
|
+
static paramsHandler(params: Partial<MongoIndexViewerParams>): Promise<{
|
|
24
|
+
connection: {
|
|
25
|
+
type: "mongo";
|
|
26
|
+
connectionString?: string | undefined;
|
|
27
|
+
database?: string | undefined;
|
|
28
|
+
domain?: string | undefined;
|
|
29
|
+
password?: string | undefined;
|
|
30
|
+
username?: string | undefined;
|
|
31
|
+
collection?: string | undefined;
|
|
32
|
+
} | undefined;
|
|
33
|
+
map: MapType<string, Document> | undefined;
|
|
34
|
+
context: import("@xyo-network/xl1-protocol-sdk").CreatableProviderContextType;
|
|
35
|
+
name?: import("@ariestools/sdk").CreatableName;
|
|
36
|
+
statusReporter?: import("@ariestools/sdk").CreatableStatusReporter<void> | undefined;
|
|
37
|
+
logger?: import("@ariestools/sdk").Logger;
|
|
38
|
+
meterProvider?: import("@opentelemetry/api").MeterProvider;
|
|
39
|
+
traceProvider?: import("@opentelemetry/api").TracerProvider;
|
|
40
|
+
}>;
|
|
41
|
+
createHandler(): Promise<void>;
|
|
42
|
+
/** The published summary for a completed step in the given family, or null when not (yet) published. */
|
|
43
|
+
stepSummary<T = unknown>(family: IndexSummaryFamily, stepLevel: number, stepIndex: number): Promise<T | null>;
|
|
44
|
+
}
|
|
45
|
+
//# sourceMappingURL=MongoIndexViewer.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"MongoIndexViewer.d.ts","sourceRoot":"","sources":["../../src/MongoIndexViewer.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EACV,kBAAkB,EAAE,WAAW,EAAE,OAAO,EACzC,MAAM,+BAA+B,CAAA;AAEtC,OAAO,KAAK,EAAE,uBAAuB,EAAE,qBAAqB,EAAE,MAAM,+BAA+B,CAAA;AACnG,OAAO,EACL,yBAAyB,EAC1B,MAAM,+BAA+B,CAAA;AACtC,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAA;AAKvC,uCAAuC;AACvC,MAAM,WAAW,sBAAuB,SAAQ,uBAAuB;IACrE,UAAU,CAAC,EAAE,qBAAqB,CAAA;IAClC,6HAA6H;IAC7H,GAAG,CAAC,EAAE,OAAO,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAA;CAChC;AAED;;;;GAIG;AACH,qBACa,gBAAiB,SAAQ,yBAAyB,CAAC,sBAAsB,CAAE,YAAW,WAAW;IAC5G,MAAM,CAAC,QAAQ,CAAC,eAAe,qBAAqB;IACpD,MAAM,CAAC,QAAQ,CAAC,cAAc,gBAAqB;IACnD,MAAM,CAAC,QAAQ,CAAC,YAAY,UAAK;IACjC,MAAM,CAAC,QAAQ,CAAC,QAAQ,kBAAuB;IAC/C,OAAO,gBAAkC;IAEzC,OAAO,CAAC,IAAI,CAA4B;WAElB,aAAa,CAAC,MAAM,EAAE,OAAO,CAAC,sBAAsB,CAAC;;;;;;;;;;;;;;;;;;IAe5D,aAAa;IAa5B,wGAAwG;IAClG,WAAW,CAAC,CAAC,GAAG,OAAO,EAAE,MAAM,EAAE,kBAAkB,EAAE,SAAS,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,CAAC,GAAG,IAAI,CAAC;CAMpH"}
|
package/dist/neutral/index.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,eAAe,CAAA"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,+BAA+B,CAAA;AAC7C,cAAc,8BAA8B,CAAA;AAC5C,cAAc,uBAAuB,CAAA;AACrC,cAAc,eAAe,CAAA"}
|
package/dist/neutral/index.mjs
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
var __defProp = Object.defineProperty;
|
|
2
2
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
3
4
|
var __decorateClass = (decorators, target, key, kind) => {
|
|
4
5
|
var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc(target, key) : target;
|
|
5
6
|
for (var i = decorators.length - 1, decorator; i >= 0; i--)
|
|
@@ -8,6 +9,53 @@ var __decorateClass = (decorators, target, key, kind) => {
|
|
|
8
9
|
if (kind && result) __defProp(target, key, result);
|
|
9
10
|
return result;
|
|
10
11
|
};
|
|
12
|
+
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
13
|
+
|
|
14
|
+
// src/mongoConnectionSdkConfig.ts
|
|
15
|
+
var DEFAULT_INDEX_COLLECTION = "index";
|
|
16
|
+
function mongoConnectionSdkConfig(connection, defaultCollection) {
|
|
17
|
+
return {
|
|
18
|
+
collection: connection.collection ?? defaultCollection,
|
|
19
|
+
dbConnectionString: connection.connectionString,
|
|
20
|
+
dbDomain: connection.domain,
|
|
21
|
+
dbName: connection.database,
|
|
22
|
+
dbPassword: connection.password,
|
|
23
|
+
dbUserName: connection.username
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
// src/MongoIndexPublishRunner.ts
|
|
28
|
+
import { assertEx as assertEx2 } from "@ariestools/sdk";
|
|
29
|
+
import { BaseMongoSdk } from "@xylabs/mongo";
|
|
30
|
+
import {
|
|
31
|
+
asIndexHead,
|
|
32
|
+
createIndexHead,
|
|
33
|
+
createIndexManifest,
|
|
34
|
+
indexHeadPath,
|
|
35
|
+
indexManifestPath,
|
|
36
|
+
indexSummaryPath
|
|
37
|
+
} from "@xyo-network/xl1-network-model";
|
|
38
|
+
import {
|
|
39
|
+
asXL1BlockRange,
|
|
40
|
+
BlockViewerMoniker,
|
|
41
|
+
IndexPublishRunnerMoniker,
|
|
42
|
+
stepPlacementForBlockNumber,
|
|
43
|
+
StepSizes
|
|
44
|
+
} from "@xyo-network/xl1-protocol-lib";
|
|
45
|
+
import {
|
|
46
|
+
AbstractCreatableProvider,
|
|
47
|
+
balancesMaxStep,
|
|
48
|
+
balancesStepSummaryFromRange,
|
|
49
|
+
blocksMaxStep,
|
|
50
|
+
blocksStepSummaryFromRange,
|
|
51
|
+
creatableProvider,
|
|
52
|
+
resolveMongoConnectionConfig,
|
|
53
|
+
schemasMaxStep,
|
|
54
|
+
schemasStepSummaryFromRange,
|
|
55
|
+
transfersMaxStep,
|
|
56
|
+
transfersStepSummaryFromRange
|
|
57
|
+
} from "@xyo-network/xl1-protocol-sdk";
|
|
58
|
+
import { Semaphore } from "async-mutex";
|
|
11
59
|
|
|
12
60
|
// src/MongoMap.ts
|
|
13
61
|
import {
|
|
@@ -123,7 +171,256 @@ var MongoMap = class extends AbstractCreatable {
|
|
|
123
171
|
MongoMap = __decorateClass([
|
|
124
172
|
creatable()
|
|
125
173
|
], MongoMap);
|
|
174
|
+
|
|
175
|
+
// src/MongoIndexPublishRunner.ts
|
|
176
|
+
var MongoIndexSummaryMap = class {
|
|
177
|
+
family;
|
|
178
|
+
map;
|
|
179
|
+
numberCache = /* @__PURE__ */ new Map();
|
|
180
|
+
source;
|
|
181
|
+
constructor(family, source, map) {
|
|
182
|
+
this.family = family;
|
|
183
|
+
this.source = source;
|
|
184
|
+
this.map = map;
|
|
185
|
+
}
|
|
186
|
+
async clear() {
|
|
187
|
+
this.numberCache.clear();
|
|
188
|
+
}
|
|
189
|
+
delete(_id) {
|
|
190
|
+
return false;
|
|
191
|
+
}
|
|
192
|
+
async get(id) {
|
|
193
|
+
const docId = await this.idForKey(id);
|
|
194
|
+
if (docId === void 0) return void 0;
|
|
195
|
+
const found = await this.map.get(docId);
|
|
196
|
+
return found === void 0 ? void 0 : found;
|
|
197
|
+
}
|
|
198
|
+
async getMany(ids) {
|
|
199
|
+
const found = await Promise.all(ids.map((id) => this.get(id)));
|
|
200
|
+
return found.flatMap((value) => value === void 0 ? [] : [value]);
|
|
201
|
+
}
|
|
202
|
+
async has(id) {
|
|
203
|
+
return await this.get(id) !== void 0;
|
|
204
|
+
}
|
|
205
|
+
async set(id, data) {
|
|
206
|
+
const docId = await this.idForFrame(data.hash, data.stepSize) ?? await this.idForKey(id);
|
|
207
|
+
if (docId === void 0) return;
|
|
208
|
+
await this.map.set(docId, data);
|
|
209
|
+
}
|
|
210
|
+
async setMany(entries) {
|
|
211
|
+
await Promise.all(entries.map(([id, data]) => this.set(id, data)));
|
|
212
|
+
}
|
|
213
|
+
async idForFrame(hash, stepSize) {
|
|
214
|
+
const blockNumber = await this.resolveBlockNumber(hash);
|
|
215
|
+
if (blockNumber === void 0) return void 0;
|
|
216
|
+
const placement = stepPlacementForBlockNumber(blockNumber, stepSize);
|
|
217
|
+
return placement ? indexSummaryPath(this.family, placement.stepLevel, placement.stepIndex) : void 0;
|
|
218
|
+
}
|
|
219
|
+
async idForKey(key) {
|
|
220
|
+
const [hash, sizeText] = key.split("|");
|
|
221
|
+
return await this.idForFrame(hash, Number(sizeText));
|
|
222
|
+
}
|
|
223
|
+
async resolveBlockNumber(hash) {
|
|
224
|
+
const cached = this.numberCache.get(hash);
|
|
225
|
+
if (cached !== void 0) return cached;
|
|
226
|
+
const block = await this.source.blockByHash(hash);
|
|
227
|
+
if (!block) return void 0;
|
|
228
|
+
const blockNumber = block[0].block;
|
|
229
|
+
this.numberCache.set(hash, blockNumber);
|
|
230
|
+
return blockNumber;
|
|
231
|
+
}
|
|
232
|
+
};
|
|
233
|
+
var MongoIndexPublishRunner = class extends AbstractCreatableProvider {
|
|
234
|
+
moniker = MongoIndexPublishRunner.defaultMoniker;
|
|
235
|
+
_map;
|
|
236
|
+
_source;
|
|
237
|
+
get source() {
|
|
238
|
+
return assertEx2(this._source, () => "No source specified");
|
|
239
|
+
}
|
|
240
|
+
static async paramsHandler(params) {
|
|
241
|
+
const moniker = IndexPublishRunnerMoniker;
|
|
242
|
+
const connection = params.connection ?? (params.map ? void 0 : resolveMongoConnectionConfig(
|
|
243
|
+
assertEx2(params.context?.config, () => "Context config is required to resolve Mongo index connection"),
|
|
244
|
+
moniker
|
|
245
|
+
));
|
|
246
|
+
return {
|
|
247
|
+
...await super.paramsHandler(params),
|
|
248
|
+
connection,
|
|
249
|
+
map: params.map,
|
|
250
|
+
source: params.source
|
|
251
|
+
};
|
|
252
|
+
}
|
|
253
|
+
async createHandler() {
|
|
254
|
+
await super.createHandler();
|
|
255
|
+
this._source = this.params.source ?? await this.locator.getInstance(BlockViewerMoniker);
|
|
256
|
+
if (this.params.map) {
|
|
257
|
+
this._map = this.params.map;
|
|
258
|
+
return;
|
|
259
|
+
}
|
|
260
|
+
const connection = assertEx2(this.params.connection, () => "No Mongo connection specified");
|
|
261
|
+
const sdk = new BaseMongoSdk(mongoConnectionSdkConfig(connection, DEFAULT_INDEX_COLLECTION));
|
|
262
|
+
const map = await MongoMap.create({ sdk, getCache: { enabled: true } });
|
|
263
|
+
await map.start();
|
|
264
|
+
this._map = map;
|
|
265
|
+
}
|
|
266
|
+
/** Builds every family's frames completed up to the ceiling, then writes the manifest and watermark. */
|
|
267
|
+
async publishCompletedFramesUpTo(ceiling) {
|
|
268
|
+
const head = await this.source.currentBlockNumber();
|
|
269
|
+
assertEx2(ceiling <= head, () => `Ceiling ${ceiling} exceeds source head ${head}`);
|
|
270
|
+
const existingWatermark = await this.readWatermark();
|
|
271
|
+
const previous = existingWatermark?.block ?? -1;
|
|
272
|
+
const families = {
|
|
273
|
+
balances: await this.publishFamily("balances", balancesMaxStep, balancesStepSummaryFromRange, previous, ceiling),
|
|
274
|
+
blocks: await this.publishFamily("blocks", blocksMaxStep, blocksStepSummaryFromRange, previous, ceiling),
|
|
275
|
+
schemas: await this.publishFamily("schemas", schemasMaxStep, schemasStepSummaryFromRange, previous, ceiling),
|
|
276
|
+
transfers: await this.publishFamily("transfers", transfersMaxStep, transfersStepSummaryFromRange, previous, ceiling)
|
|
277
|
+
};
|
|
278
|
+
const ceilingBlock = assertEx2(await this.source.blockByNumber(ceiling), () => `Block not found for ceiling ${ceiling}`);
|
|
279
|
+
const watermark = {
|
|
280
|
+
block: ceiling,
|
|
281
|
+
hash: ceilingBlock[0]._hash,
|
|
282
|
+
families
|
|
283
|
+
};
|
|
284
|
+
await this.writeManifest();
|
|
285
|
+
await this.writeHead(watermark);
|
|
286
|
+
this.logger?.info(`MongoIndexPublishRunner: index complete through block ${ceiling}`);
|
|
287
|
+
return watermark;
|
|
288
|
+
}
|
|
289
|
+
/** Publishes one completed frame for a family (and any missing sub-frames it depends on). */
|
|
290
|
+
async publishFrame(family, stepLevel, stepIndex) {
|
|
291
|
+
const size = StepSizes[stepLevel];
|
|
292
|
+
const lastBlock = (stepIndex + 1) * size - 1;
|
|
293
|
+
const head = await this.source.currentBlockNumber();
|
|
294
|
+
assertEx2(lastBlock <= head, () => `Frame ${family} ${stepLevel}/${stepIndex} is not complete (head ${head})`);
|
|
295
|
+
const range = asXL1BlockRange([stepIndex * size, lastBlock], true);
|
|
296
|
+
await this.buildFamilyFrame(family, range);
|
|
297
|
+
this.logger?.info(`MongoIndexPublishRunner: published frame ${family} ${stepLevel}/${stepIndex}`);
|
|
298
|
+
}
|
|
299
|
+
/** Dispatches a single frame to its family builder, writing it (and missing sub-frames) to the collection. */
|
|
300
|
+
async buildFamilyFrame(family, range) {
|
|
301
|
+
const semaphores = StepSizes.map(() => new Semaphore(20));
|
|
302
|
+
switch (family) {
|
|
303
|
+
case "balances": {
|
|
304
|
+
await balancesStepSummaryFromRange(this.context, semaphores, this.source, this.summaryMap("balances"), range);
|
|
305
|
+
break;
|
|
306
|
+
}
|
|
307
|
+
case "blocks": {
|
|
308
|
+
await blocksStepSummaryFromRange(this.context, semaphores, this.source, this.summaryMap("blocks"), range);
|
|
309
|
+
break;
|
|
310
|
+
}
|
|
311
|
+
case "schemas": {
|
|
312
|
+
await schemasStepSummaryFromRange(this.context, semaphores, this.source, this.summaryMap("schemas"), range);
|
|
313
|
+
break;
|
|
314
|
+
}
|
|
315
|
+
case "transfers": {
|
|
316
|
+
await transfersStepSummaryFromRange(this.context, semaphores, this.source, this.summaryMap("transfers"), range);
|
|
317
|
+
break;
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
|
+
}
|
|
321
|
+
/** Builds a family's frames in (previous, ceiling] across every level; returns total completed frames. */
|
|
322
|
+
async publishFamily(family, maxStep, build, previous, ceiling) {
|
|
323
|
+
const map = this.summaryMap(family);
|
|
324
|
+
const semaphores = StepSizes.map(() => new Semaphore(20));
|
|
325
|
+
let completed = 0;
|
|
326
|
+
for (let stepLevel = 0; stepLevel <= maxStep; stepLevel++) {
|
|
327
|
+
const size = StepSizes[stepLevel];
|
|
328
|
+
const fromIndex = Math.floor((previous + 1) / size);
|
|
329
|
+
const toIndex = Math.floor((ceiling + 1) / size);
|
|
330
|
+
completed += toIndex;
|
|
331
|
+
for (let stepIndex = fromIndex; stepIndex < toIndex; stepIndex++) {
|
|
332
|
+
const start = stepIndex * size;
|
|
333
|
+
await build(this.context, semaphores, this.source, map, asXL1BlockRange([start, start + size - 1], true));
|
|
334
|
+
}
|
|
335
|
+
}
|
|
336
|
+
return completed;
|
|
337
|
+
}
|
|
338
|
+
async readWatermark() {
|
|
339
|
+
const found = await this._map.get(indexHeadPath());
|
|
340
|
+
return found === void 0 ? void 0 : asIndexHead(found, true);
|
|
341
|
+
}
|
|
342
|
+
summaryMap(family) {
|
|
343
|
+
return new MongoIndexSummaryMap(family, this.source, this._map);
|
|
344
|
+
}
|
|
345
|
+
async writeHead(watermark) {
|
|
346
|
+
const head = createIndexHead(watermark);
|
|
347
|
+
await this._map.set(indexHeadPath(), head);
|
|
348
|
+
}
|
|
349
|
+
async writeManifest() {
|
|
350
|
+
const manifest = createIndexManifest({
|
|
351
|
+
balances: balancesMaxStep,
|
|
352
|
+
blocks: blocksMaxStep,
|
|
353
|
+
schemas: schemasMaxStep,
|
|
354
|
+
transfers: transfersMaxStep
|
|
355
|
+
});
|
|
356
|
+
await this._map.set(indexManifestPath(), manifest);
|
|
357
|
+
}
|
|
358
|
+
};
|
|
359
|
+
__publicField(MongoIndexPublishRunner, "connectionTypes", ["mongo"]);
|
|
360
|
+
__publicField(MongoIndexPublishRunner, "defaultMoniker", IndexPublishRunnerMoniker);
|
|
361
|
+
__publicField(MongoIndexPublishRunner, "dependencies", [BlockViewerMoniker]);
|
|
362
|
+
__publicField(MongoIndexPublishRunner, "monikers", [IndexPublishRunnerMoniker]);
|
|
363
|
+
MongoIndexPublishRunner = __decorateClass([
|
|
364
|
+
creatableProvider()
|
|
365
|
+
], MongoIndexPublishRunner);
|
|
366
|
+
|
|
367
|
+
// src/MongoIndexViewer.ts
|
|
368
|
+
import { assertEx as assertEx3 } from "@ariestools/sdk";
|
|
369
|
+
import { BaseMongoSdk as BaseMongoSdk2 } from "@xylabs/mongo";
|
|
370
|
+
import { indexSummaryPath as indexSummaryPath2 } from "@xyo-network/xl1-network-model";
|
|
371
|
+
import { IndexViewerMoniker } from "@xyo-network/xl1-protocol-lib";
|
|
372
|
+
import {
|
|
373
|
+
AbstractCreatableProvider as AbstractCreatableProvider2,
|
|
374
|
+
creatableProvider as creatableProvider2,
|
|
375
|
+
resolveMongoConnectionConfig as resolveMongoConnectionConfig2
|
|
376
|
+
} from "@xyo-network/xl1-protocol-sdk";
|
|
377
|
+
var MongoIndexViewer = class extends AbstractCreatableProvider2 {
|
|
378
|
+
moniker = MongoIndexViewer.defaultMoniker;
|
|
379
|
+
_map;
|
|
380
|
+
static async paramsHandler(params) {
|
|
381
|
+
const moniker = this.defaultMoniker;
|
|
382
|
+
const connection = params.connection ?? (params.map ? void 0 : resolveMongoConnectionConfig2(
|
|
383
|
+
assertEx3(params.context?.config, () => "Context config is required to resolve Mongo index connection"),
|
|
384
|
+
moniker
|
|
385
|
+
));
|
|
386
|
+
return {
|
|
387
|
+
...await super.paramsHandler(params),
|
|
388
|
+
connection,
|
|
389
|
+
map: params.map
|
|
390
|
+
};
|
|
391
|
+
}
|
|
392
|
+
async createHandler() {
|
|
393
|
+
await super.createHandler();
|
|
394
|
+
if (this.params.map) {
|
|
395
|
+
this._map = this.params.map;
|
|
396
|
+
return;
|
|
397
|
+
}
|
|
398
|
+
const connection = assertEx3(this.params.connection, () => "No Mongo connection specified");
|
|
399
|
+
const sdk = new BaseMongoSdk2(mongoConnectionSdkConfig(connection, DEFAULT_INDEX_COLLECTION));
|
|
400
|
+
const map = await MongoMap.create({ sdk, getCache: { enabled: true } });
|
|
401
|
+
await map.start();
|
|
402
|
+
this._map = map;
|
|
403
|
+
}
|
|
404
|
+
/** The published summary for a completed step in the given family, or null when not (yet) published. */
|
|
405
|
+
async stepSummary(family, stepLevel, stepIndex) {
|
|
406
|
+
return await this.spanAsync("stepSummary", async () => {
|
|
407
|
+
const summary = await this._map.get(indexSummaryPath2(family, stepLevel, stepIndex));
|
|
408
|
+
return summary ?? null;
|
|
409
|
+
}, this.context);
|
|
410
|
+
}
|
|
411
|
+
};
|
|
412
|
+
__publicField(MongoIndexViewer, "connectionTypes", ["mongo"]);
|
|
413
|
+
__publicField(MongoIndexViewer, "defaultMoniker", IndexViewerMoniker);
|
|
414
|
+
__publicField(MongoIndexViewer, "dependencies", []);
|
|
415
|
+
__publicField(MongoIndexViewer, "monikers", [IndexViewerMoniker]);
|
|
416
|
+
MongoIndexViewer = __decorateClass([
|
|
417
|
+
creatableProvider2()
|
|
418
|
+
], MongoIndexViewer);
|
|
126
419
|
export {
|
|
127
|
-
|
|
420
|
+
DEFAULT_INDEX_COLLECTION,
|
|
421
|
+
MongoIndexPublishRunner,
|
|
422
|
+
MongoIndexViewer,
|
|
423
|
+
MongoMap,
|
|
424
|
+
mongoConnectionSdkConfig
|
|
128
425
|
};
|
|
129
426
|
//# sourceMappingURL=index.mjs.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
|
-
"sources": ["../../src/MongoMap.ts"],
|
|
4
|
-
"sourcesContent": ["import type { CreatableParams } from '@ariestools/sdk'\nimport {\n AbstractCreatable, assertEx, creatable, isNull,\n} from '@ariestools/sdk'\nimport type { BaseMongoSdk } from '@xylabs/mongo'\nimport { LruCacheMap } from '@xyo-network/xl1-driver-memory'\nimport type { AsyncIterableMap, MapType } from '@xyo-network/xl1-protocol-lib'\nimport type {\n Document, Filter, OptionalUnlessRequiredId, WithId,\n} from 'mongodb'\n\nexport interface MongoMapParams<TData extends Document = Document> extends CreatableParams {\n getCache?: {\n enabled: boolean\n maxEntries?: number\n }\n sdk: BaseMongoSdk<TData>\n}\n\nconst stripMongoId = <V extends Document>(doc: WithId<V>): V => {\n const { _id, ...rest } = doc\n return rest as unknown as V\n}\n\n@creatable()\nexport class MongoMap<K extends {} = string, V extends Document = Document>\n extends AbstractCreatable<MongoMapParams<V>>\n implements AsyncIterableMap<K, V> {\n private _getCache: MapType<K, V> | undefined\n\n get sdk(): BaseMongoSdk<V> {\n return assertEx(this.params.sdk, () => 'No sdk specified')\n }\n\n /**\n * Enable `for await...of` iteration over all entries in the map.\n * Streams through the Mongo cursor so no driver-level limit is applied.\n */\n [Symbol.asyncIterator](): AsyncIterator<[K, V]> {\n // Create cursor lazily so async iterator construction remains synchronous.\n // `find()` must be called exactly once; calling it in `next()` risks recreating cursors.\n // Using a closure ensures refactors cannot accidentally duplicate cursor creation.\n const cursorPromise = this.sdk.find({})\n\n // Holds the resolved Mongo cursor; shared across all iterations.\n // Declared outside `next()` to avoid accidental recreation during refactors.\n let cursor: Awaited<typeof cursorPromise> | undefined\n\n // Lazily resolve the cursor on first iteration; keeps `next()` simple.\n const loadCursor = async () => {\n cursor ??= await cursorPromise\n }\n\n return {\n next: async (): Promise<IteratorResult<[K, V]>> => {\n // Ensure cursor is initialized once before iteration.\n await loadCursor()\n if (!cursor) return { value: undefined, done: true }\n\n // Pull next document from the cursor; Mongo driver returns null when exhausted.\n const doc = await cursor.next()\n if (!doc) return { value: undefined, done: true }\n\n // Convert MongoDB document into key/value tuple.\n const key = doc._id as unknown as K\n const value = stripMongoId(doc)\n\n // Cache the value if caching is enabled.\n if (this._getCache) await this._getCache.set(key, value)\n\n // Yield the entry to the async iterator consumer.\n return { value: [key, value], done: false }\n },\n }\n }\n\n async clear(): Promise<void> {\n await this._getCache?.clear()\n await this.sdk.deleteMany({})\n }\n\n async delete(id: K): Promise<boolean> {\n await this._getCache?.delete(id)\n\n const filter = { _id: id } as Filter<V>\n const result = await this.sdk.deleteOne(filter)\n return result.deletedCount > 0\n }\n\n async get(id: K): Promise<V | undefined> {\n if (this._getCache) {\n const getCacheResult = this._getCache.get(id)\n if (getCacheResult) {\n return getCacheResult\n }\n }\n const filter = { _id: id } as Filter<V>\n const doc = await this.sdk.findOne(filter)\n return isNull(doc) ? undefined : stripMongoId(doc)\n }\n\n async getMany(ids: K[]): Promise<V[]> {\n const cache = this._getCache\n const idSet = new Set(ids)\n const results: V[] = []\n if (cache) {\n const getCacheResult = ids.map(id => ([id, cache.get(id)])).filter(([, item]) => item !== undefined) as [K, V][]\n for (const [id] of getCacheResult) {\n idSet.delete(id)\n }\n results.push(...getCacheResult.map(([, item]) => item))\n }\n const filter = { _id: { $in: [...idSet] } } as Filter<V>\n const cursor = await this.sdk.find(filter)\n const items = await cursor.toArray()\n for (const item of items) {\n const id = item._id\n const stripped = stripMongoId(item)\n if (cache) await cache.set(id as unknown as K, stripped)\n results.push(stripped)\n }\n return results\n }\n\n async has(id: K): Promise<boolean> {\n if (this._getCache) {\n const getCacheResult = await this._getCache.has(id)\n if (getCacheResult) return getCacheResult\n }\n const filter = { _id: id } as Filter<V>\n const exists = await this.sdk.findOne(filter)\n return isNull(exists) ? false : true\n }\n\n async set(id: K, data: V): Promise<void> {\n const filter = { _id: id } as Filter<V>\n const value = { ...data, _id: id } as OptionalUnlessRequiredId<V>\n await this.sdk.replaceOne(filter, value, { upsert: true })\n await this._getCache?.set(id, data)\n }\n\n async setMany(entries: [K, V][]): Promise<void> {\n // TODO: Optimize with bulkWrite\n for (const [key, value] of entries) {\n await this.set(key, value)\n }\n }\n\n override async startHandler(): Promise<void> {\n await super.startHandler()\n // TODO: Ensure index\n if (this.params.getCache?.enabled === true) {\n const maxEntries = this.params.getCache?.maxEntries ?? 5000\n this._getCache = new LruCacheMap<K, V>({ max: maxEntries })\n }\n }\n}\n"],
|
|
5
|
-
"mappings": "
|
|
6
|
-
"names": []
|
|
3
|
+
"sources": ["../../src/mongoConnectionSdkConfig.ts", "../../src/MongoIndexPublishRunner.ts", "../../src/MongoMap.ts", "../../src/MongoIndexViewer.ts"],
|
|
4
|
+
"sourcesContent": ["import type { BaseMongoSdkConfig } from '@xylabs/mongo'\nimport type { MongoConnectionConfig } from '@xyo-network/xl1-protocol-sdk'\n\n/** Collection routed to when a `mongo` connection doesn't specify its own `collection`. */\nexport const DEFAULT_INDEX_COLLECTION = 'index'\n\n/** Maps a `mongo` connection config to the `BaseMongoSdk` config shape, defaulting the collection when the connection doesn't specify its own. */\nexport function mongoConnectionSdkConfig(connection: MongoConnectionConfig, defaultCollection: string): BaseMongoSdkConfig {\n return {\n collection: connection.collection ?? defaultCollection,\n dbConnectionString: connection.connectionString,\n dbDomain: connection.domain,\n dbName: connection.database,\n dbPassword: connection.password,\n dbUserName: connection.username,\n }\n}\n", "import type { Hash } from '@ariestools/sdk'\nimport { assertEx } from '@ariestools/sdk'\nimport { BaseMongoSdk } from '@xylabs/mongo'\nimport type { IndexHead } from '@xyo-network/xl1-network-model'\nimport {\n asIndexHead,\n createIndexHead,\n createIndexManifest,\n indexHeadPath,\n indexManifestPath,\n indexSummaryPath,\n} from '@xyo-network/xl1-network-model'\nimport type {\n AsyncMap, BlockViewer, CachingContext, IndexPublishRunner, IndexSummaryFamily, IndexWatermark, MapType,\n XL1BlockNumber, XL1BlockRange,\n} from '@xyo-network/xl1-protocol-lib'\nimport {\n asXL1BlockRange, BlockViewerMoniker, IndexPublishRunnerMoniker, stepPlacementForBlockNumber, StepSizes,\n} from '@xyo-network/xl1-protocol-lib'\nimport type { CreatableProviderParams, MongoConnectionConfig } from '@xyo-network/xl1-protocol-sdk'\nimport {\n AbstractCreatableProvider,\n balancesMaxStep, balancesStepSummaryFromRange,\n blocksMaxStep, blocksStepSummaryFromRange,\n creatableProvider,\n resolveMongoConnectionConfig,\n schemasMaxStep, schemasStepSummaryFromRange,\n transfersMaxStep, transfersStepSummaryFromRange,\n} from '@xyo-network/xl1-protocol-sdk'\nimport { Semaphore } from 'async-mutex'\nimport type { Document } from 'mongodb'\n\nimport { DEFAULT_INDEX_COLLECTION, mongoConnectionSdkConfig } from './mongoConnectionSdkConfig.ts'\nimport { MongoMap } from './MongoMap.ts'\n\n/** The minimum shape the summary map needs to place a frame: its head hash and frame size. */\ninterface FramePlacement {\n hash: Hash\n stepSize: number\n}\n\n/** The signature shared by every `*StepSummaryFromRange` builder. */\ntype SummaryBuilder<T extends FramePlacement> = (\n context: CachingContext,\n semaphores: Semaphore[],\n blockViewer: BlockViewer,\n summaryMap: MapType<string, T>,\n range: XL1BlockRange,\n) => Promise<T>\n\n/**\n * A summary map backed by the shared index collection. The builders cache completed frames here\n * keyed by `${frameHeadHash}|${frameSize}`; this map turns that key into the frame's\n * `indexSummaryPath` (resolving the head hash to a block number via the source viewer) so `get`\n * reads the published document and `set` writes it \u2014 making the collection itself the builders'\n * frame cache, which gives skip-if-present resume and cascading sub-frame writes for free.\n */\nclass MongoIndexSummaryMap<T extends FramePlacement> implements AsyncMap<string, T> {\n private readonly family: IndexSummaryFamily\n private readonly map: MapType<string, Document>\n private readonly numberCache = new Map<Hash, number>()\n private readonly source: BlockViewer\n\n constructor(family: IndexSummaryFamily, source: BlockViewer, map: MapType<string, Document>) {\n this.family = family\n this.source = source\n this.map = map\n }\n\n async clear(): Promise<void> {\n this.numberCache.clear()\n }\n\n delete(_id: string): boolean {\n return false\n }\n\n async get(id: string): Promise<T | undefined> {\n const docId = await this.idForKey(id)\n if (docId === undefined) return undefined\n const found = await this.map.get(docId)\n return found === undefined ? undefined : (found as T)\n }\n\n async getMany(ids: string[]): Promise<T[]> {\n const found = await Promise.all(ids.map(id => this.get(id)))\n return found.flatMap(value => (value === undefined ? [] : [value]))\n }\n\n async has(id: string): Promise<boolean> {\n return (await this.get(id)) !== undefined\n }\n\n async set(id: string, data: T): Promise<void> {\n const docId = (await this.idForFrame(data.hash, data.stepSize)) ?? (await this.idForKey(id))\n if (docId === undefined) return\n await this.map.set(docId, data)\n }\n\n async setMany(entries: [string, T][]): Promise<void> {\n await Promise.all(entries.map(([id, data]) => this.set(id, data)))\n }\n\n private async idForFrame(hash: Hash, stepSize: number): Promise<string | undefined> {\n const blockNumber = await this.resolveBlockNumber(hash)\n if (blockNumber === undefined) return undefined\n const placement = stepPlacementForBlockNumber(blockNumber, stepSize)\n return placement ? indexSummaryPath(this.family, placement.stepLevel, placement.stepIndex) : undefined\n }\n\n private async idForKey(key: string): Promise<string | undefined> {\n const [hash, sizeText] = key.split('|')\n return await this.idForFrame(hash as Hash, Number(sizeText))\n }\n\n private async resolveBlockNumber(hash: Hash): Promise<number | undefined> {\n const cached = this.numberCache.get(hash)\n if (cached !== undefined) return cached\n const block = await this.source.blockByHash(hash)\n if (!block) return undefined\n const blockNumber = block[0].block\n this.numberCache.set(hash, blockNumber)\n return blockNumber\n }\n}\n\n/** Parameters for MongoIndexPublishRunner. */\nexport interface MongoIndexPublishRunnerParams extends CreatableProviderParams {\n connection?: MongoConnectionConfig\n /** Pre-built backing map (tests, or a caller-managed Mongo connection). Defaults to a `MongoMap` built from `connection`. */\n map?: MapType<string, Document>\n /**\n * The viewer to build the index from (only finalized chains should be indexed). When omitted,\n * resolved from the locator via BlockViewerMoniker.\n */\n source?: BlockViewer\n}\n\n/**\n * Publishes the multi-family chain index (blocks, balances, schemas, transfers) to a shared Mongo\n * collection that `MongoIndexViewer` reads, using the same document-id scheme (`indexSummaryPath`)\n * as the static REST layout. Frames are immutable: only complete frames are ever published, and a\n * completed frame never changes. The head watermark and manifest are written last so a reader\n * never sees a watermark pointing past the frames that back it.\n */\n@creatableProvider()\nexport class MongoIndexPublishRunner extends AbstractCreatableProvider<MongoIndexPublishRunnerParams> implements IndexPublishRunner {\n static readonly connectionTypes = ['mongo'] as const\n static readonly defaultMoniker = IndexPublishRunnerMoniker\n static readonly dependencies = [BlockViewerMoniker]\n static readonly monikers = [IndexPublishRunnerMoniker]\n moniker = MongoIndexPublishRunner.defaultMoniker\n\n protected _map!: MapType<string, Document>\n protected _source?: BlockViewer\n\n get source(): BlockViewer {\n return assertEx(this._source, () => 'No source specified')\n }\n\n static override async paramsHandler(params: Partial<MongoIndexPublishRunnerParams>) {\n const moniker = IndexPublishRunnerMoniker\n const connection = params.connection ?? (params.map\n ? undefined\n : resolveMongoConnectionConfig(\n assertEx(params.context?.config, () => 'Context config is required to resolve Mongo index connection'),\n moniker,\n ))\n return {\n ...await super.paramsHandler(params),\n connection,\n map: params.map,\n source: params.source,\n } satisfies MongoIndexPublishRunnerParams\n }\n\n override async createHandler() {\n await super.createHandler()\n this._source = this.params.source ?? await this.locator.getInstance(BlockViewerMoniker)\n if (this.params.map) {\n this._map = this.params.map\n return\n }\n const connection = assertEx(this.params.connection, () => 'No Mongo connection specified')\n const sdk = new BaseMongoSdk<Document>(mongoConnectionSdkConfig(connection, DEFAULT_INDEX_COLLECTION))\n const map = await MongoMap.create({ sdk, getCache: { enabled: true } })\n await map.start()\n this._map = map\n }\n\n /** Builds every family's frames completed up to the ceiling, then writes the manifest and watermark. */\n async publishCompletedFramesUpTo(ceiling: XL1BlockNumber): Promise<IndexWatermark> {\n const head = await this.source.currentBlockNumber()\n assertEx(ceiling <= head, () => `Ceiling ${ceiling} exceeds source head ${head}`)\n const existingWatermark = await this.readWatermark()\n const previous = existingWatermark?.block ?? -1\n const families: Record<IndexSummaryFamily, number> = {\n balances: await this.publishFamily('balances', balancesMaxStep, balancesStepSummaryFromRange, previous, ceiling),\n blocks: await this.publishFamily('blocks', blocksMaxStep, blocksStepSummaryFromRange, previous, ceiling),\n schemas: await this.publishFamily('schemas', schemasMaxStep, schemasStepSummaryFromRange, previous, ceiling),\n transfers: await this.publishFamily('transfers', transfersMaxStep, transfersStepSummaryFromRange, previous, ceiling),\n }\n const ceilingBlock = assertEx(await this.source.blockByNumber(ceiling), () => `Block not found for ceiling ${ceiling}`)\n const watermark: IndexWatermark = {\n block: ceiling, hash: ceilingBlock[0]._hash, families,\n }\n await this.writeManifest()\n await this.writeHead(watermark)\n this.logger?.info(`MongoIndexPublishRunner: index complete through block ${ceiling}`)\n return watermark\n }\n\n /** Publishes one completed frame for a family (and any missing sub-frames it depends on). */\n async publishFrame(family: IndexSummaryFamily, stepLevel: number, stepIndex: number): Promise<void> {\n const size = StepSizes[stepLevel]\n const lastBlock = (stepIndex + 1) * size - 1\n const head = await this.source.currentBlockNumber()\n assertEx(lastBlock <= head, () => `Frame ${family} ${stepLevel}/${stepIndex} is not complete (head ${head})`)\n const range = asXL1BlockRange([stepIndex * size, lastBlock], true)\n await this.buildFamilyFrame(family, range)\n this.logger?.info(`MongoIndexPublishRunner: published frame ${family} ${stepLevel}/${stepIndex}`)\n }\n\n /** Dispatches a single frame to its family builder, writing it (and missing sub-frames) to the collection. */\n private async buildFamilyFrame(family: IndexSummaryFamily, range: XL1BlockRange): Promise<void> {\n const semaphores = StepSizes.map(() => new Semaphore(20))\n switch (family) {\n case 'balances': {\n await balancesStepSummaryFromRange(this.context, semaphores, this.source, this.summaryMap('balances'), range)\n break\n }\n case 'blocks': {\n await blocksStepSummaryFromRange(this.context, semaphores, this.source, this.summaryMap('blocks'), range)\n break\n }\n case 'schemas': {\n await schemasStepSummaryFromRange(this.context, semaphores, this.source, this.summaryMap('schemas'), range)\n break\n }\n case 'transfers': {\n await transfersStepSummaryFromRange(this.context, semaphores, this.source, this.summaryMap('transfers'), range)\n break\n }\n }\n }\n\n /** Builds a family's frames in (previous, ceiling] across every level; returns total completed frames. */\n private async publishFamily<T extends FramePlacement>(\n family: IndexSummaryFamily,\n maxStep: number,\n build: SummaryBuilder<T>,\n previous: number,\n ceiling: number,\n ): Promise<number> {\n const map = this.summaryMap<T>(family)\n const semaphores = StepSizes.map(() => new Semaphore(20))\n let completed = 0\n // Bottom-up so a level's sub-frames exist (in the collection) before the level above is built.\n for (let stepLevel = 0; stepLevel <= maxStep; stepLevel++) {\n const size = StepSizes[stepLevel]\n const fromIndex = Math.floor((previous + 1) / size)\n const toIndex = Math.floor((ceiling + 1) / size)\n completed += toIndex\n for (let stepIndex = fromIndex; stepIndex < toIndex; stepIndex++) {\n const start = stepIndex * size\n await build(this.context, semaphores, this.source, map, asXL1BlockRange([start, start + size - 1], true))\n }\n }\n return completed\n }\n\n private async readWatermark(): Promise<IndexHead | undefined> {\n const found = await this._map.get(indexHeadPath())\n return found === undefined ? undefined : asIndexHead(found, true)\n }\n\n private summaryMap<T extends FramePlacement>(family: IndexSummaryFamily): MongoIndexSummaryMap<T> {\n return new MongoIndexSummaryMap<T>(family, this.source, this._map)\n }\n\n private async writeHead(watermark: IndexWatermark): Promise<void> {\n const head = createIndexHead(watermark)\n await this._map.set(indexHeadPath(), head)\n }\n\n private async writeManifest(): Promise<void> {\n const manifest = createIndexManifest({\n balances: balancesMaxStep,\n blocks: blocksMaxStep,\n schemas: schemasMaxStep,\n transfers: transfersMaxStep,\n })\n await this._map.set(indexManifestPath(), manifest)\n }\n}\n", "import type { CreatableParams } from '@ariestools/sdk'\nimport {\n AbstractCreatable, assertEx, creatable, isNull,\n} from '@ariestools/sdk'\nimport type { BaseMongoSdk } from '@xylabs/mongo'\nimport { LruCacheMap } from '@xyo-network/xl1-driver-memory'\nimport type { AsyncIterableMap, MapType } from '@xyo-network/xl1-protocol-lib'\nimport type {\n Document, Filter, OptionalUnlessRequiredId, WithId,\n} from 'mongodb'\n\nexport interface MongoMapParams<TData extends Document = Document> extends CreatableParams {\n getCache?: {\n enabled: boolean\n maxEntries?: number\n }\n sdk: BaseMongoSdk<TData>\n}\n\nconst stripMongoId = <V extends Document>(doc: WithId<V>): V => {\n const { _id, ...rest } = doc\n return rest as unknown as V\n}\n\n@creatable()\nexport class MongoMap<K extends {} = string, V extends Document = Document>\n extends AbstractCreatable<MongoMapParams<V>>\n implements AsyncIterableMap<K, V> {\n private _getCache: MapType<K, V> | undefined\n\n get sdk(): BaseMongoSdk<V> {\n return assertEx(this.params.sdk, () => 'No sdk specified')\n }\n\n /**\n * Enable `for await...of` iteration over all entries in the map.\n * Streams through the Mongo cursor so no driver-level limit is applied.\n */\n [Symbol.asyncIterator](): AsyncIterator<[K, V]> {\n // Create cursor lazily so async iterator construction remains synchronous.\n // `find()` must be called exactly once; calling it in `next()` risks recreating cursors.\n // Using a closure ensures refactors cannot accidentally duplicate cursor creation.\n const cursorPromise = this.sdk.find({})\n\n // Holds the resolved Mongo cursor; shared across all iterations.\n // Declared outside `next()` to avoid accidental recreation during refactors.\n let cursor: Awaited<typeof cursorPromise> | undefined\n\n // Lazily resolve the cursor on first iteration; keeps `next()` simple.\n const loadCursor = async () => {\n cursor ??= await cursorPromise\n }\n\n return {\n next: async (): Promise<IteratorResult<[K, V]>> => {\n // Ensure cursor is initialized once before iteration.\n await loadCursor()\n if (!cursor) return { value: undefined, done: true }\n\n // Pull next document from the cursor; Mongo driver returns null when exhausted.\n const doc = await cursor.next()\n if (!doc) return { value: undefined, done: true }\n\n // Convert MongoDB document into key/value tuple.\n const key = doc._id as unknown as K\n const value = stripMongoId(doc)\n\n // Cache the value if caching is enabled.\n if (this._getCache) await this._getCache.set(key, value)\n\n // Yield the entry to the async iterator consumer.\n return { value: [key, value], done: false }\n },\n }\n }\n\n async clear(): Promise<void> {\n await this._getCache?.clear()\n await this.sdk.deleteMany({})\n }\n\n async delete(id: K): Promise<boolean> {\n await this._getCache?.delete(id)\n\n const filter = { _id: id } as Filter<V>\n const result = await this.sdk.deleteOne(filter)\n return result.deletedCount > 0\n }\n\n async get(id: K): Promise<V | undefined> {\n if (this._getCache) {\n const getCacheResult = this._getCache.get(id)\n if (getCacheResult) {\n return getCacheResult\n }\n }\n const filter = { _id: id } as Filter<V>\n const doc = await this.sdk.findOne(filter)\n return isNull(doc) ? undefined : stripMongoId(doc)\n }\n\n async getMany(ids: K[]): Promise<V[]> {\n const cache = this._getCache\n const idSet = new Set(ids)\n const results: V[] = []\n if (cache) {\n const getCacheResult = ids.map(id => ([id, cache.get(id)])).filter(([, item]) => item !== undefined) as [K, V][]\n for (const [id] of getCacheResult) {\n idSet.delete(id)\n }\n results.push(...getCacheResult.map(([, item]) => item))\n }\n const filter = { _id: { $in: [...idSet] } } as Filter<V>\n const cursor = await this.sdk.find(filter)\n const items = await cursor.toArray()\n for (const item of items) {\n const id = item._id\n const stripped = stripMongoId(item)\n if (cache) await cache.set(id as unknown as K, stripped)\n results.push(stripped)\n }\n return results\n }\n\n async has(id: K): Promise<boolean> {\n if (this._getCache) {\n const getCacheResult = await this._getCache.has(id)\n if (getCacheResult) return getCacheResult\n }\n const filter = { _id: id } as Filter<V>\n const exists = await this.sdk.findOne(filter)\n return isNull(exists) ? false : true\n }\n\n async set(id: K, data: V): Promise<void> {\n const filter = { _id: id } as Filter<V>\n const value = { ...data, _id: id } as OptionalUnlessRequiredId<V>\n await this.sdk.replaceOne(filter, value, { upsert: true })\n await this._getCache?.set(id, data)\n }\n\n async setMany(entries: [K, V][]): Promise<void> {\n // TODO: Optimize with bulkWrite\n for (const [key, value] of entries) {\n await this.set(key, value)\n }\n }\n\n override async startHandler(): Promise<void> {\n await super.startHandler()\n // TODO: Ensure index\n if (this.params.getCache?.enabled === true) {\n const maxEntries = this.params.getCache?.maxEntries ?? 5000\n this._getCache = new LruCacheMap<K, V>({ max: maxEntries })\n }\n }\n}\n", "import { assertEx } from '@ariestools/sdk'\nimport { BaseMongoSdk } from '@xylabs/mongo'\nimport { indexSummaryPath } from '@xyo-network/xl1-network-model'\nimport type {\n IndexSummaryFamily, IndexViewer, MapType, ProviderMoniker,\n} from '@xyo-network/xl1-protocol-lib'\nimport { IndexViewerMoniker } from '@xyo-network/xl1-protocol-lib'\nimport type { CreatableProviderParams, MongoConnectionConfig } from '@xyo-network/xl1-protocol-sdk'\nimport {\n AbstractCreatableProvider, creatableProvider, resolveMongoConnectionConfig,\n} from '@xyo-network/xl1-protocol-sdk'\nimport type { Document } from 'mongodb'\n\nimport { DEFAULT_INDEX_COLLECTION, mongoConnectionSdkConfig } from './mongoConnectionSdkConfig.ts'\nimport { MongoMap } from './MongoMap.ts'\n\n/** Parameters for MongoIndexViewer. */\nexport interface MongoIndexViewerParams extends CreatableProviderParams {\n connection?: MongoConnectionConfig\n /** Pre-built backing map (tests, or a caller-managed Mongo connection). Defaults to a `MongoMap` built from `connection`. */\n map?: MapType<string, Document>\n}\n\n/**\n * An IndexViewer over the same chain index a `MongoIndexPublishRunner` writes to: reads\n * completed step-summary documents from a shared Mongo collection, keyed identically to the\n * static REST layout (`indexSummaryPath`) so both backends can serve the same logical index.\n */\n@creatableProvider()\nexport class MongoIndexViewer extends AbstractCreatableProvider<MongoIndexViewerParams> implements IndexViewer {\n static readonly connectionTypes = ['mongo'] as const\n static readonly defaultMoniker = IndexViewerMoniker\n static readonly dependencies = []\n static readonly monikers = [IndexViewerMoniker]\n moniker = MongoIndexViewer.defaultMoniker\n\n private _map!: MapType<string, Document>\n\n static override async paramsHandler(params: Partial<MongoIndexViewerParams>) {\n const moniker = (this as unknown as { defaultMoniker: ProviderMoniker }).defaultMoniker\n const connection = params.connection ?? (params.map\n ? undefined\n : resolveMongoConnectionConfig(\n assertEx(params.context?.config, () => 'Context config is required to resolve Mongo index connection'),\n moniker,\n ))\n return {\n ...await super.paramsHandler(params),\n connection,\n map: params.map,\n } satisfies MongoIndexViewerParams\n }\n\n override async createHandler() {\n await super.createHandler()\n if (this.params.map) {\n this._map = this.params.map\n return\n }\n const connection = assertEx(this.params.connection, () => 'No Mongo connection specified')\n const sdk = new BaseMongoSdk<Document>(mongoConnectionSdkConfig(connection, DEFAULT_INDEX_COLLECTION))\n const map = await MongoMap.create({ sdk, getCache: { enabled: true } })\n await map.start()\n this._map = map\n }\n\n /** The published summary for a completed step in the given family, or null when not (yet) published. */\n async stepSummary<T = unknown>(family: IndexSummaryFamily, stepLevel: number, stepIndex: number): Promise<T | null> {\n return await this.spanAsync('stepSummary', async () => {\n const summary = await this._map.get(indexSummaryPath(family, stepLevel, stepIndex))\n return (summary as T | undefined) ?? null\n }, this.context)\n }\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;AAIO,IAAM,2BAA2B;AAGjC,SAAS,yBAAyB,YAAmC,mBAA+C;AACzH,SAAO;AAAA,IACL,YAAY,WAAW,cAAc;AAAA,IACrC,oBAAoB,WAAW;AAAA,IAC/B,UAAU,WAAW;AAAA,IACrB,QAAQ,WAAW;AAAA,IACnB,YAAY,WAAW;AAAA,IACvB,YAAY,WAAW;AAAA,EACzB;AACF;;;ACfA,SAAS,YAAAA,iBAAgB;AACzB,SAAS,oBAAoB;AAE7B;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AAKP;AAAA,EACE;AAAA,EAAiB;AAAA,EAAoB;AAAA,EAA2B;AAAA,EAA6B;AAAA,OACxF;AAEP;AAAA,EACE;AAAA,EACA;AAAA,EAAiB;AAAA,EACjB;AAAA,EAAe;AAAA,EACf;AAAA,EACA;AAAA,EACA;AAAA,EAAgB;AAAA,EAChB;AAAA,EAAkB;AAAA,OACb;AACP,SAAS,iBAAiB;;;AC5B1B;AAAA,EACE;AAAA,EAAmB;AAAA,EAAU;AAAA,EAAW;AAAA,OACnC;AAEP,SAAS,mBAAmB;AAc5B,IAAM,eAAe,CAAqB,QAAsB;AAC9D,QAAM,EAAE,KAAK,GAAG,KAAK,IAAI;AACzB,SAAO;AACT;AAGO,IAAM,WAAN,cACG,kBAC0B;A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AAuB,yBAAyB,YAAY,wBAAwB,CAAC;AACrG,UAAM,MAAM,MAAM,SAAS,OAAO,EAAE,KAAK,UAAU,EAAE,SAAS,KAAK,EAAE,CAAC;AACtE,UAAM,IAAI,MAAM;AAChB,SAAK,OAAO;AAAA,EACd;AAAA;AAAA,EAGA,MAAM,YAAyB,QAA4B,WAAmB,WAAsC;AAClH,WAAO,MAAM,KAAK,UAAU,eAAe,YAAY;AACrD,YAAM,UAAU,MAAM,KAAK,KAAK,IAAIC,kBAAiB,QAAQ,WAAW,SAAS,CAAC;AAClF,aAAQ,WAA6B;AAAA,IACvC,GAAG,KAAK,OAAO;AAAA,EACjB;AACF;AA3CE,cADW,kBACK,mBAAkB,CAAC,OAAO;AAC1C,cAFW,kBAEK,kBAAiB;AACjC,cAHW,kBAGK,gBAAe,CAAC;AAChC,cAJW,kBAIK,YAAW,CAAC,kBAAkB;AAJnC,mBAAN;AAAA,EADNC,mBAAkB;AAAA,GACN;",
|
|
6
|
+
"names": ["assertEx", "assertEx", "assertEx", "BaseMongoSdk", "indexSummaryPath", "AbstractCreatableProvider", "creatableProvider", "resolveMongoConnectionConfig", "AbstractCreatableProvider", "resolveMongoConnectionConfig", "assertEx", "BaseMongoSdk", "indexSummaryPath", "creatableProvider"]
|
|
7
7
|
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { BaseMongoSdkConfig } from '@xylabs/mongo';
|
|
2
|
+
import type { MongoConnectionConfig } from '@xyo-network/xl1-protocol-sdk';
|
|
3
|
+
/** Collection routed to when a `mongo` connection doesn't specify its own `collection`. */
|
|
4
|
+
export declare const DEFAULT_INDEX_COLLECTION = "index";
|
|
5
|
+
/** Maps a `mongo` connection config to the `BaseMongoSdk` config shape, defaulting the collection when the connection doesn't specify its own. */
|
|
6
|
+
export declare function mongoConnectionSdkConfig(connection: MongoConnectionConfig, defaultCollection: string): BaseMongoSdkConfig;
|
|
7
|
+
//# sourceMappingURL=mongoConnectionSdkConfig.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mongoConnectionSdkConfig.d.ts","sourceRoot":"","sources":["../../src/mongoConnectionSdkConfig.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAA;AACvD,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,+BAA+B,CAAA;AAE1E,2FAA2F;AAC3F,eAAO,MAAM,wBAAwB,UAAU,CAAA;AAE/C,kJAAkJ;AAClJ,wBAAgB,wBAAwB,CAAC,UAAU,EAAE,qBAAqB,EAAE,iBAAiB,EAAE,MAAM,GAAG,kBAAkB,CASzH"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"$schema": "http://json.schemastore.org/package.json",
|
|
3
3
|
"name": "@xyo-network/xl1-driver-mongodb",
|
|
4
|
-
"version": "4.0.
|
|
4
|
+
"version": "4.0.9",
|
|
5
5
|
"description": "XYO Layer One SDK Protocol MongoDB Driver",
|
|
6
6
|
"homepage": "https://xylabs.com",
|
|
7
7
|
"bugs": {
|
|
@@ -35,63 +35,71 @@
|
|
|
35
35
|
"README.md"
|
|
36
36
|
],
|
|
37
37
|
"dependencies": {
|
|
38
|
-
"@xyo-network/xl1-driver-memory": "~4.0.
|
|
39
|
-
"@xyo-network/xl1-
|
|
38
|
+
"@xyo-network/xl1-driver-memory": "~4.0.9",
|
|
39
|
+
"@xyo-network/xl1-network-model": "~4.0.9",
|
|
40
|
+
"@xyo-network/xl1-protocol-lib": "~4.0.9",
|
|
41
|
+
"@xyo-network/xl1-protocol-sdk": "~4.0.9"
|
|
40
42
|
},
|
|
41
43
|
"devDependencies": {
|
|
42
|
-
"@ariestools/sdk": "
|
|
44
|
+
"@ariestools/sdk": "~7.0.8",
|
|
43
45
|
"@bitauth/libauth": "~3.0.0",
|
|
46
|
+
"@metamask/providers": "~22.1.1",
|
|
44
47
|
"@noble/post-quantum": "~0.6.1",
|
|
45
|
-
"@opentelemetry/api": "
|
|
46
|
-
"@opentelemetry/sdk-trace-base": "
|
|
48
|
+
"@opentelemetry/api": "~1.9.1",
|
|
49
|
+
"@opentelemetry/sdk-trace-base": "~2.9.0",
|
|
47
50
|
"@scure/base": "~2.2.0",
|
|
48
51
|
"@scure/bip39": "~2.2.0",
|
|
49
|
-
"@xylabs/geo": "
|
|
50
|
-
"@xylabs/mongo": "
|
|
51
|
-
"@xylabs/
|
|
52
|
-
"@xylabs/
|
|
53
|
-
"@xylabs/
|
|
54
|
-
"@
|
|
55
|
-
"@xyo-network/sdk-
|
|
56
|
-
"
|
|
57
|
-
"
|
|
58
|
-
"
|
|
52
|
+
"@xylabs/geo": "~7.0.8",
|
|
53
|
+
"@xylabs/mongo": "~7.0.8",
|
|
54
|
+
"@xylabs/threads": "~7.0.8",
|
|
55
|
+
"@xylabs/toolchain": "~8.6.2",
|
|
56
|
+
"@xylabs/tsconfig": "~8.6.2",
|
|
57
|
+
"@xyo-network/sdk": "~7.0.8",
|
|
58
|
+
"@xyo-network/sdk-protocol": "~7.0.13",
|
|
59
|
+
"ajv": "~8.20.0",
|
|
60
|
+
"async-mutex": "~0.5.0",
|
|
61
|
+
"cosmiconfig": "~9.0.2",
|
|
59
62
|
"debug": "~4.4.3",
|
|
60
|
-
"eslint": "
|
|
61
|
-
"ethers": "
|
|
63
|
+
"eslint": "~10.6.0",
|
|
64
|
+
"ethers": "~6.17.0",
|
|
62
65
|
"hash-wasm": "~4.12.0",
|
|
63
|
-
"idb": "
|
|
64
|
-
"lru-cache": "
|
|
65
|
-
"mongodb": "
|
|
66
|
+
"idb": "~8.0.3",
|
|
67
|
+
"lru-cache": "~11.5.1",
|
|
68
|
+
"mongodb": "~7.4.0",
|
|
66
69
|
"observable-fns": "~0.6.1",
|
|
67
|
-
"tslib": "
|
|
70
|
+
"tslib": "~2.8.1",
|
|
68
71
|
"typescript": "~6.0.3",
|
|
72
|
+
"vite": "~8.1.3",
|
|
73
|
+
"vitest": "~4.1.9",
|
|
74
|
+
"webextension-polyfill": "~0.12.0",
|
|
69
75
|
"zod": "~4.4.3"
|
|
70
76
|
},
|
|
71
77
|
"peerDependencies": {
|
|
72
|
-
"@ariestools/sdk": "^7.0",
|
|
73
|
-
"@bitauth/libauth": "
|
|
74
|
-
"@
|
|
75
|
-
"@
|
|
76
|
-
"@opentelemetry/
|
|
77
|
-
"@
|
|
78
|
-
"@scure/
|
|
79
|
-
"@
|
|
80
|
-
"@xylabs/
|
|
81
|
-
"@xylabs/
|
|
82
|
-
"@xylabs/threads": "^7.0",
|
|
83
|
-
"@xyo-network/sdk
|
|
84
|
-
"@xyo-network/sdk-protocol": "
|
|
85
|
-
"ajv": "^8.20",
|
|
86
|
-
"async-mutex": "^0.5",
|
|
87
|
-
"
|
|
88
|
-
"
|
|
89
|
-
"
|
|
90
|
-
"
|
|
91
|
-
"
|
|
92
|
-
"
|
|
93
|
-
"
|
|
94
|
-
"
|
|
78
|
+
"@ariestools/sdk": "^7.0.8",
|
|
79
|
+
"@bitauth/libauth": "^3.0.0",
|
|
80
|
+
"@metamask/providers": "^22.1.1",
|
|
81
|
+
"@noble/post-quantum": "^0.6.1",
|
|
82
|
+
"@opentelemetry/api": "^1.9.1",
|
|
83
|
+
"@opentelemetry/sdk-trace-base": "^2.9.0",
|
|
84
|
+
"@scure/base": "^2.2.0",
|
|
85
|
+
"@scure/bip39": "^2.2.0",
|
|
86
|
+
"@xylabs/geo": "^7.0.8",
|
|
87
|
+
"@xylabs/mongo": "^7.0.8",
|
|
88
|
+
"@xylabs/threads": "^7.0.8",
|
|
89
|
+
"@xyo-network/sdk": "^7.0.8",
|
|
90
|
+
"@xyo-network/sdk-protocol": "^7.0.13",
|
|
91
|
+
"ajv": "^8.20.0",
|
|
92
|
+
"async-mutex": "^0.5.0",
|
|
93
|
+
"cosmiconfig": "^9.0.2",
|
|
94
|
+
"debug": "^4.4.3",
|
|
95
|
+
"ethers": "^6.17.0",
|
|
96
|
+
"hash-wasm": "^4.12.0",
|
|
97
|
+
"idb": "^8.0.3",
|
|
98
|
+
"lru-cache": "^11.5.1",
|
|
99
|
+
"mongodb": "^7.4.0",
|
|
100
|
+
"observable-fns": "^0.6.1",
|
|
101
|
+
"webextension-polyfill": "^0.12.0",
|
|
102
|
+
"zod": "^4.4.3"
|
|
95
103
|
},
|
|
96
104
|
"peerDependenciesMeta": {
|
|
97
105
|
"mongodb": {
|