@secondlayer/subgraphs 6.3.2 → 6.3.4
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/index.d.ts +19 -2
- package/dist/index.js +77 -20
- package/dist/index.js.map +3 -3
- package/dist/runtime/replay.js +76 -20
- package/dist/runtime/replay.js.map +3 -3
- package/dist/testing/index.js.map +2 -2
- package/package.json +2 -2
package/dist/index.d.ts
CHANGED
|
@@ -1197,8 +1197,25 @@ type SparseProbeTarget = {
|
|
|
1197
1197
|
* a contract_call/contract_deploy source matches transactions, which the
|
|
1198
1198
|
* event probe can't see. */
|
|
1199
1199
|
declare function canSparseScan(subgraph: SubgraphDefinition): boolean;
|
|
1200
|
-
/**
|
|
1200
|
+
/**
|
|
1201
|
+
* The (decoded event type, contract scope) pairs a subgraph's filters can
|
|
1202
|
+
* match. One function feeds BOTH the sparse probe and the event walks, so a
|
|
1203
|
+
* new contract-pinning filter field is added here once.
|
|
1204
|
+
*
|
|
1205
|
+
* Per event type: if ANY filter for it is unscoped, a single unscoped target
|
|
1206
|
+
* covers everything (today's behavior); otherwise one target per distinct
|
|
1207
|
+
* pinned contract.
|
|
1208
|
+
*/
|
|
1201
1209
|
declare function sparseProbeTargets(subgraph: SubgraphDefinition): SparseProbeTarget[];
|
|
1210
|
+
/**
|
|
1211
|
+
* streams-index eligibility: every source must be a known event-type or
|
|
1212
|
+
* contract_call/contract_deploy filter (no array-style sources, which leak the
|
|
1213
|
+
* unreconstructable `_eventId`). Trait scope IS allowed — trait resolution
|
|
1214
|
+
* reads the contract registry on the platform DB (`targetDb`), which the
|
|
1215
|
+
* processor always holds, so it's source-independent. Everything else stays on
|
|
1216
|
+
* the DB tap.
|
|
1217
|
+
*/
|
|
1218
|
+
declare function isStreamsIndexEligible(subgraph: SubgraphDefinition): boolean;
|
|
1202
1219
|
interface ReindexOptions {
|
|
1203
1220
|
/**
|
|
1204
1221
|
* Floor on the walk's first block — NOT a caller-supplied range. When set
|
|
@@ -1212,4 +1229,4 @@ interface ReindexOptions {
|
|
|
1212
1229
|
operationId?: string;
|
|
1213
1230
|
signal?: AbortSignal;
|
|
1214
1231
|
}
|
|
1215
|
-
export { AggregateResult, AggregateSpec, AnyEvent, ChainReadCacheMode, ChainReadClient, ChainReadError, ChainReadMethods, ChainReadOptions, ColumnDiff, ColumnToTS, ColumnType, ComparisonFilter, ContractCallEvent, ContractCallFilter, ContractCallPayload, ContractDeployFilter, ContractDeployPayload, DeployDiff, DeployPlan, DrizzleGenOptions, ErasedChainReadClient, EventForFilter, FactoryScope, FindManyOptions, FindManyPage, FtBurnFilter, FtBurnPayload, FtMintFilter, FtMintPayload, FtTransferFilter, FtTransferPayload, GeneratedSQL, IndexCodegenOptions, IndexCodegenTarget, InferColumnType, InferContext, InferSubgraphClient, InferTableRow, InferredPrintField, InferredTopicSchema, KyselyGenOptions, MapDeletePayload, MapWritePayload, NestedContractCallPayload, NftBurnFilter, NftBurnPayload, NftMintFilter, NftMintPayload, NftTransferFilter, NftTransferPayload, PinnedPrintEventFilter, PrintDataOf, PrintEventFilter, PrintEventFor, PrintEventPayload, PrintEventPrints, PrintField, PrintFieldToTS, PrintSample, PrintValidationResult, PrismaGenOptions, ReindexOptions, RowValue, SparseProbeTarget, StxBurnFilter, StxBurnPayload, StxLockFilter, StxLockPayload, StxMintFilter, StxMintPayload, StxTransferFilter, StxTransferPayload, SubgraphColumn, SubgraphContext, SubgraphDefinition, SubgraphFilter, SubgraphHandler, SubgraphSchema, SubgraphTable, SubgraphTableClient, SubgraphTip, SubscribeOptions, SystemRow, TableDiff, TraitPrintEventFilter, TxMeta, TypedHandlers, TypedSubgraphContext, TypedSubgraphDefinition, UnpinnedPrintEventFilter, VarSetPayload, WhereInput, WriteRow, camelizeKeys, canSparseScan, defineSchema, defineSubgraph, deploySchema, diffSchema, filterFieldsByType, generateDrizzleSchema, generateIndexSchema, generateKyselySchema, generatePrismaSchema, generateSubgraphSQL, hasBreakingChanges, inferPrintTopics, pgSchemaName, readContractAt, renderDeployPlan, sparseProbeTargets, validateSubgraphDefinition };
|
|
1232
|
+
export { AggregateResult, AggregateSpec, AnyEvent, ChainReadCacheMode, ChainReadClient, ChainReadError, ChainReadMethods, ChainReadOptions, ColumnDiff, ColumnToTS, ColumnType, ComparisonFilter, ContractCallEvent, ContractCallFilter, ContractCallPayload, ContractDeployFilter, ContractDeployPayload, DeployDiff, DeployPlan, DrizzleGenOptions, ErasedChainReadClient, EventForFilter, FactoryScope, FindManyOptions, FindManyPage, FtBurnFilter, FtBurnPayload, FtMintFilter, FtMintPayload, FtTransferFilter, FtTransferPayload, GeneratedSQL, IndexCodegenOptions, IndexCodegenTarget, InferColumnType, InferContext, InferSubgraphClient, InferTableRow, InferredPrintField, InferredTopicSchema, KyselyGenOptions, MapDeletePayload, MapWritePayload, NestedContractCallPayload, NftBurnFilter, NftBurnPayload, NftMintFilter, NftMintPayload, NftTransferFilter, NftTransferPayload, PinnedPrintEventFilter, PrintDataOf, PrintEventFilter, PrintEventFor, PrintEventPayload, PrintEventPrints, PrintField, PrintFieldToTS, PrintSample, PrintValidationResult, PrismaGenOptions, ReindexOptions, RowValue, SparseProbeTarget, StxBurnFilter, StxBurnPayload, StxLockFilter, StxLockPayload, StxMintFilter, StxMintPayload, StxTransferFilter, StxTransferPayload, SubgraphColumn, SubgraphContext, SubgraphDefinition, SubgraphFilter, SubgraphHandler, SubgraphSchema, SubgraphTable, SubgraphTableClient, SubgraphTip, SubscribeOptions, SystemRow, TableDiff, TraitPrintEventFilter, TxMeta, TypedHandlers, TypedSubgraphContext, TypedSubgraphDefinition, UnpinnedPrintEventFilter, VarSetPayload, WhereInput, WriteRow, camelizeKeys, canSparseScan, defineSchema, defineSubgraph, deploySchema, diffSchema, filterFieldsByType, generateDrizzleSchema, generateIndexSchema, generateKyselySchema, generatePrismaSchema, generateSubgraphSQL, hasBreakingChanges, inferPrintTopics, isStreamsIndexEligible, pgSchemaName, readContractAt, renderDeployPlan, sparseProbeTargets, validateSubgraphDefinition };
|
package/dist/index.js
CHANGED
|
@@ -1979,18 +1979,44 @@ function canSparseScan(subgraph) {
|
|
|
1979
1979
|
return false;
|
|
1980
1980
|
return filters.every((f) => Boolean(EVENT_FILTER_TO_INDEX_TYPE[f.type]));
|
|
1981
1981
|
}
|
|
1982
|
+
var MAX_PINNED_CONTRACTS = 20;
|
|
1983
|
+
function pinnedContracts(filter) {
|
|
1984
|
+
const f = filter;
|
|
1985
|
+
if (f.trait || f.factory)
|
|
1986
|
+
return null;
|
|
1987
|
+
const ids = Array.isArray(f.contractId) ? [...f.contractId] : f.contractId ? [f.contractId] : f.assetIdentifier ? [f.assetIdentifier.split("::")[0]] : [];
|
|
1988
|
+
if (ids.length === 0 || ids.length > MAX_PINNED_CONTRACTS)
|
|
1989
|
+
return null;
|
|
1990
|
+
if (ids.some((id) => !id || id.includes("*")))
|
|
1991
|
+
return null;
|
|
1992
|
+
return ids;
|
|
1993
|
+
}
|
|
1982
1994
|
function sparseProbeTargets(subgraph) {
|
|
1983
|
-
const
|
|
1995
|
+
const byType = new Map;
|
|
1984
1996
|
for (const f of sourceFilters(subgraph)) {
|
|
1985
1997
|
const eventType = EVENT_FILTER_TO_INDEX_TYPE[f.type];
|
|
1986
1998
|
if (!eventType)
|
|
1987
1999
|
continue;
|
|
1988
|
-
const
|
|
1989
|
-
const
|
|
1990
|
-
|
|
1991
|
-
|
|
2000
|
+
const pinned = pinnedContracts(f);
|
|
2001
|
+
const prev = byType.get(eventType);
|
|
2002
|
+
if (!pinned || prev === "all") {
|
|
2003
|
+
byType.set(eventType, "all");
|
|
2004
|
+
continue;
|
|
2005
|
+
}
|
|
2006
|
+
const set = prev ?? new Set;
|
|
2007
|
+
for (const id of pinned)
|
|
2008
|
+
set.add(id);
|
|
2009
|
+
byType.set(eventType, set);
|
|
2010
|
+
}
|
|
2011
|
+
const targets = [];
|
|
2012
|
+
for (const [eventType, scope] of byType) {
|
|
2013
|
+
if (scope === "all")
|
|
2014
|
+
targets.push({ eventType });
|
|
2015
|
+
else
|
|
2016
|
+
for (const contractId of scope)
|
|
2017
|
+
targets.push({ eventType, contractId });
|
|
1992
2018
|
}
|
|
1993
|
-
return
|
|
2019
|
+
return targets;
|
|
1994
2020
|
}
|
|
1995
2021
|
|
|
1996
2022
|
class PostgresBlockSource {
|
|
@@ -2056,6 +2082,30 @@ function indexEventTypesForFilterTypes(filterTypes) {
|
|
|
2056
2082
|
}
|
|
2057
2083
|
return [...types];
|
|
2058
2084
|
}
|
|
2085
|
+
function isStreamsIndexEligible(subgraph) {
|
|
2086
|
+
if (Array.isArray(subgraph.sources))
|
|
2087
|
+
return false;
|
|
2088
|
+
const filters = sourceFilters(subgraph);
|
|
2089
|
+
if (filters.length === 0)
|
|
2090
|
+
return false;
|
|
2091
|
+
for (const f of filters) {
|
|
2092
|
+
const known = EVENT_FILTER_TO_INDEX_TYPE[f.type] || TX_SOURCE_TYPES.has(f.type);
|
|
2093
|
+
if (!known)
|
|
2094
|
+
return false;
|
|
2095
|
+
}
|
|
2096
|
+
return true;
|
|
2097
|
+
}
|
|
2098
|
+
function dedupeEvents(rows) {
|
|
2099
|
+
const seen = new Set;
|
|
2100
|
+
return rows.filter((e) => {
|
|
2101
|
+
const key = `${e.event_type}|${e.block_height}|${e.event_index}`;
|
|
2102
|
+
if (seen.has(key))
|
|
2103
|
+
return false;
|
|
2104
|
+
seen.add(key);
|
|
2105
|
+
return true;
|
|
2106
|
+
});
|
|
2107
|
+
}
|
|
2108
|
+
|
|
2059
2109
|
class PublicApiBlockSource {
|
|
2060
2110
|
http;
|
|
2061
2111
|
eventTypes;
|
|
@@ -2067,6 +2117,13 @@ class PublicApiBlockSource {
|
|
|
2067
2117
|
this.probeTargets = probeTargets;
|
|
2068
2118
|
this.needsTransactions = needsTransactions;
|
|
2069
2119
|
}
|
|
2120
|
+
walkTargets() {
|
|
2121
|
+
const scoped = this.needsTransactions ? undefined : this.probeTargets;
|
|
2122
|
+
return this.eventTypes.flatMap((eventType) => {
|
|
2123
|
+
const own = scoped?.filter((t) => t.eventType === eventType);
|
|
2124
|
+
return own?.length ? own : [{ eventType }];
|
|
2125
|
+
});
|
|
2126
|
+
}
|
|
2070
2127
|
async nextDataHeight(afterHeight, untilHeight) {
|
|
2071
2128
|
if (!this.probeTargets?.length)
|
|
2072
2129
|
return afterHeight + 1;
|
|
@@ -2088,8 +2145,9 @@ class PublicApiBlockSource {
|
|
|
2088
2145
|
const [blocks, txRows, eventLists] = await Promise.all([
|
|
2089
2146
|
this.http.walkBlocks(fromHeight, toHeight),
|
|
2090
2147
|
this.needsTransactions ? this.http.walkTransactions(fromHeight, toHeight) : Promise.resolve([]),
|
|
2091
|
-
Promise.all(this.
|
|
2148
|
+
Promise.all(this.walkTargets().map((t) => this.http.walkEvents(t.eventType, fromHeight, toHeight, withTx, t.contractId)))
|
|
2092
2149
|
]);
|
|
2150
|
+
const events = dedupeEvents(eventLists.flat());
|
|
2093
2151
|
const map = new Map;
|
|
2094
2152
|
for (const b of blocks) {
|
|
2095
2153
|
map.set(b.block_height, {
|
|
@@ -2098,21 +2156,19 @@ class PublicApiBlockSource {
|
|
|
2098
2156
|
events: []
|
|
2099
2157
|
});
|
|
2100
2158
|
}
|
|
2101
|
-
const txs = this.needsTransactions ? txRows.map(reconstructTransaction) : synthesizeTxsFromEvents(
|
|
2159
|
+
const txs = this.needsTransactions ? txRows.map(reconstructTransaction) : synthesizeTxsFromEvents(events);
|
|
2102
2160
|
for (const t of txs) {
|
|
2103
2161
|
map.get(t.block_height)?.txs.push(t);
|
|
2104
2162
|
}
|
|
2105
|
-
for (const
|
|
2106
|
-
|
|
2107
|
-
|
|
2108
|
-
|
|
2109
|
-
|
|
2110
|
-
|
|
2111
|
-
|
|
2112
|
-
|
|
2113
|
-
|
|
2114
|
-
bd.events.push(reconstructEvent(e));
|
|
2115
|
-
}
|
|
2163
|
+
for (const e of events) {
|
|
2164
|
+
const bd = map.get(e.block_height);
|
|
2165
|
+
if (!bd)
|
|
2166
|
+
continue;
|
|
2167
|
+
if (VM_INDEX_EVENT_TYPES.has(e.event_type)) {
|
|
2168
|
+
bd.vmEvents ??= [];
|
|
2169
|
+
bd.vmEvents.push(reconstructEvent(e));
|
|
2170
|
+
} else {
|
|
2171
|
+
bd.events.push(reconstructEvent(e));
|
|
2116
2172
|
}
|
|
2117
2173
|
}
|
|
2118
2174
|
for (const bd of map.values()) {
|
|
@@ -2143,6 +2199,7 @@ export {
|
|
|
2143
2199
|
generateSubgraphSQL,
|
|
2144
2200
|
hasBreakingChanges,
|
|
2145
2201
|
inferPrintTopics,
|
|
2202
|
+
isStreamsIndexEligible,
|
|
2146
2203
|
pgSchemaName,
|
|
2147
2204
|
readContractAt,
|
|
2148
2205
|
renderDeployPlan,
|
|
@@ -2150,5 +2207,5 @@ export {
|
|
|
2150
2207
|
validateSubgraphDefinition
|
|
2151
2208
|
};
|
|
2152
2209
|
|
|
2153
|
-
//# debugId=
|
|
2210
|
+
//# debugId=9E0F3F4652CCD15164756E2164756E21
|
|
2154
2211
|
//# sourceMappingURL=index.js.map
|