@secondlayer/sdk 10.6.0 → 11.0.0
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 +19 -13
- package/dist/index.d.ts +11 -7
- package/dist/index.js +24 -20
- package/dist/index.js.map +4 -4
- package/dist/subgraphs/index.d.ts +11 -7
- package/dist/subgraphs/index.js +24 -20
- package/dist/subgraphs/index.js.map +4 -4
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -412,7 +412,9 @@ Exported types: `TransactionProof`, `TransactionProofVerifyResult`, `RewardSet`.
|
|
|
412
412
|
|
|
413
413
|
Deploy and query app-specific tables.
|
|
414
414
|
|
|
415
|
-
Subgraphs and webhooks live on the instance API alongside Streams and Index.
|
|
415
|
+
Subgraphs and webhooks live on the instance API alongside Streams and Index. Reads (`rows`, `count`, `aggregate`, typed `findMany`/`count`/`aggregate`, and `subscribe`) all hit the open `/v1` surface — keyless on loopback, `INSTANCE_TOKEN` once the API is bound beyond it. Everything else here (deploy, status, ops) calls `/api`, which needs `INSTANCE_TOKEN` once one is configured (init always configures one), loopback included.
|
|
416
|
+
|
|
417
|
+
`/v1` paginates by cursor, not offset: `rows`/`count`/`aggregate` take no `offset` param — pass the previous page's `next_cursor` back as `cursor` to resume.
|
|
416
418
|
|
|
417
419
|
```typescript
|
|
418
420
|
// List
|
|
@@ -421,25 +423,18 @@ const { data } = await sl.subgraphs.list();
|
|
|
421
423
|
// Get
|
|
422
424
|
const subgraph = await sl.subgraphs.status("my-subgraph");
|
|
423
425
|
|
|
424
|
-
//
|
|
426
|
+
// Untyped row read (/v1)
|
|
425
427
|
const { rows, next_cursor, tip } = await sl.subgraphs.rows("my-subgraph", "transfers", {
|
|
428
|
+
sort: "block_height",
|
|
426
429
|
order: "desc",
|
|
427
430
|
limit: 50,
|
|
428
431
|
// cursor: next_cursor — pass back to resume
|
|
429
432
|
});
|
|
430
433
|
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
sort: "block_height",
|
|
434
|
-
order: "desc",
|
|
435
|
-
limit: 50,
|
|
434
|
+
const { count } = await sl.subgraphs.count("my-subgraph", "transfers", {
|
|
435
|
+
filters: { status: "active" },
|
|
436
436
|
});
|
|
437
437
|
|
|
438
|
-
const { count } = await sl.subgraphs.queryTableCount(
|
|
439
|
-
"my-subgraph",
|
|
440
|
-
"transfers",
|
|
441
|
-
);
|
|
442
|
-
|
|
443
438
|
const spec = await sl.subgraphs.openapi("my-subgraph");
|
|
444
439
|
const source = await sl.subgraphs.getSource("my-subgraph");
|
|
445
440
|
const gaps = await sl.subgraphs.gaps("my-subgraph");
|
|
@@ -455,11 +450,22 @@ system column only when your table declares no column of that name; a declared
|
|
|
455
450
|
`id` column is always your `id`.
|
|
456
451
|
|
|
457
452
|
Stream rows live with the typed client — each table exposes `subscribe`
|
|
458
|
-
alongside `findMany`/`count`:
|
|
453
|
+
alongside `findMany`/`count`/`aggregate`:
|
|
459
454
|
|
|
460
455
|
```typescript
|
|
461
456
|
const subgraph = sl.subgraphs.typed(myDefinition); // { transfers, ... }
|
|
462
457
|
|
|
458
|
+
// findMany returns a page, not a bare array — `nextCursor` resumes it.
|
|
459
|
+
// `orderBy` sorts one column only (the /v1 keyset cursor pairs it with `_id`
|
|
460
|
+
// as a tiebreaker); a second key throws.
|
|
461
|
+
const page = await subgraph.transfers.findMany({
|
|
462
|
+
where: { amount: { gte: "1000000" } },
|
|
463
|
+
orderBy: { blockHeight: "desc" },
|
|
464
|
+
limit: 50,
|
|
465
|
+
// cursor: page.nextCursor — pass back to resume
|
|
466
|
+
});
|
|
467
|
+
// page.rows, page.nextCursor, page.tip
|
|
468
|
+
|
|
463
469
|
const unsubscribe = subgraph.transfers.subscribe(
|
|
464
470
|
(row) => console.log(row),
|
|
465
471
|
{
|
package/dist/index.d.ts
CHANGED
|
@@ -2589,7 +2589,7 @@ declare class Subgraphs extends BaseClient {
|
|
|
2589
2589
|
* pass an apiKey on the client where reads are closed. Resume with the
|
|
2590
2590
|
* returned `next_cursor`.
|
|
2591
2591
|
*/
|
|
2592
|
-
rows<T = unknown>(name: string, table: string, params?: Omit<SubgraphQueryParams, "offset"
|
|
2592
|
+
rows<T = unknown>(name: string, table: string, params?: Omit<SubgraphQueryParams, "offset"> & {
|
|
2593
2593
|
cursor?: string;
|
|
2594
2594
|
}): Promise<SubgraphRowsEnvelope<T>>;
|
|
2595
2595
|
/** Recent reindex/backfill operations for a subgraph, newest first. */
|
|
@@ -2611,11 +2611,14 @@ declare class Subgraphs extends BaseClient {
|
|
|
2611
2611
|
bundle(data: {
|
|
2612
2612
|
code: string;
|
|
2613
2613
|
}): Promise<BundleSubgraphResponse>;
|
|
2614
|
-
|
|
2615
|
-
|
|
2614
|
+
/** Open /v1 read: exact row count for a filtered set. Same auth posture as
|
|
2615
|
+
* {@link rows}. */
|
|
2616
|
+
count(name: string, table: string, params?: Pick<SubgraphQueryParams, "filters">): Promise<{
|
|
2616
2617
|
count: number;
|
|
2617
2618
|
}>;
|
|
2618
|
-
|
|
2619
|
+
/** Open /v1 read: scalar aggregates over a filtered set. Same auth posture
|
|
2620
|
+
* as {@link rows}. */
|
|
2621
|
+
aggregate(name: string, table: string, params?: SubgraphAggregateParams): Promise<SubgraphAggregateResponse>;
|
|
2619
2622
|
/**
|
|
2620
2623
|
* Returns a typed client for a subgraph defined with `defineSubgraph()`.
|
|
2621
2624
|
* Row types are inferred from the subgraph's schema literal types.
|
|
@@ -2624,8 +2627,9 @@ declare class Subgraphs extends BaseClient {
|
|
|
2624
2627
|
* ```ts
|
|
2625
2628
|
* import mySubgraph from './subgraphs/my-token-subgraph'
|
|
2626
2629
|
* const client = sl.subgraphs.typed(mySubgraph)
|
|
2627
|
-
* const
|
|
2628
|
-
* // rows: InferTableRow<typeof mySubgraph.schema.transfers>[]
|
|
2630
|
+
* const page = await client.transfers.findMany({ where: { sender: 'SP...' } })
|
|
2631
|
+
* // page.rows: InferTableRow<typeof mySubgraph.schema.transfers>[]
|
|
2632
|
+
* // page.nextCursor: string | null — pass back as `cursor` to resume
|
|
2629
2633
|
* ```
|
|
2630
2634
|
*/
|
|
2631
2635
|
typed<T extends {
|
|
@@ -2777,7 +2781,7 @@ import { InferSubgraphClient as InferSubgraphClient2 } from "@secondlayer/subgra
|
|
|
2777
2781
|
* import { getSubgraph } from '@secondlayer/sdk'
|
|
2778
2782
|
*
|
|
2779
2783
|
* const client = getSubgraph(mySubgraph, { apiKey: 'sl_...' })
|
|
2780
|
-
* const
|
|
2784
|
+
* const page = await client.transfers.findMany({ where: { sender: 'SP...' } })
|
|
2781
2785
|
* ```
|
|
2782
2786
|
*/
|
|
2783
2787
|
declare function getSubgraph<T extends {
|
package/dist/index.js
CHANGED
|
@@ -2317,7 +2317,6 @@ function buildSubgraphQueryString(params) {
|
|
|
2317
2317
|
_sort: params.sort,
|
|
2318
2318
|
_order: params.order,
|
|
2319
2319
|
_limit: params.limit,
|
|
2320
|
-
_offset: params.offset,
|
|
2321
2320
|
_fields: params.fields,
|
|
2322
2321
|
...params.filters
|
|
2323
2322
|
});
|
|
@@ -2395,15 +2394,11 @@ class Subgraphs extends BaseClient {
|
|
|
2395
2394
|
async bundle(data) {
|
|
2396
2395
|
return this.request("POST", "/api/subgraphs/bundle", data);
|
|
2397
2396
|
}
|
|
2398
|
-
async
|
|
2399
|
-
|
|
2400
|
-
return Array.isArray(result) ? result : result.data;
|
|
2397
|
+
async count(name, table, params = {}) {
|
|
2398
|
+
return this.request("GET", `/v1/subgraphs/${seg(name)}/${seg(table)}/count${buildSubgraphQueryString(params)}`);
|
|
2401
2399
|
}
|
|
2402
|
-
async
|
|
2403
|
-
return this.request("GET", `/
|
|
2404
|
-
}
|
|
2405
|
-
async queryTableAggregate(name, table, params = {}) {
|
|
2406
|
-
return this.request("GET", `/api/subgraphs/${seg(name)}/${seg(table)}/aggregate${buildAggregateQueryString(params)}`);
|
|
2400
|
+
async aggregate(name, table, params = {}) {
|
|
2401
|
+
return this.request("GET", `/v1/subgraphs/${seg(name)}/${seg(table)}/aggregate${buildAggregateQueryString(params)}`);
|
|
2407
2402
|
}
|
|
2408
2403
|
typed(def) {
|
|
2409
2404
|
const result = {};
|
|
@@ -2420,32 +2415,41 @@ class Subgraphs extends BaseClient {
|
|
|
2420
2415
|
let sort;
|
|
2421
2416
|
let order;
|
|
2422
2417
|
if (options.orderBy) {
|
|
2423
|
-
const entries =
|
|
2424
|
-
if (entries.length >
|
|
2425
|
-
|
|
2426
|
-
|
|
2418
|
+
const entries = Object.entries(options.orderBy);
|
|
2419
|
+
if (entries.length > 1) {
|
|
2420
|
+
throw new Error(`findMany orderBy accepts a single column; got ${entries.length}: ${entries.map(([col]) => col).join(", ")}. Sort one column — the cursor pairs it with _id as a tiebreaker.`);
|
|
2421
|
+
}
|
|
2422
|
+
const entry = entries[0];
|
|
2423
|
+
if (entry) {
|
|
2424
|
+
const [col, dir] = entry;
|
|
2425
|
+
sort = resolveOrderByColumn(col, columns);
|
|
2426
|
+
order = dir ?? "asc";
|
|
2427
2427
|
}
|
|
2428
2428
|
}
|
|
2429
|
-
const
|
|
2429
|
+
const result = await self.rows(subgraphName, tableName, {
|
|
2430
2430
|
sort,
|
|
2431
2431
|
order,
|
|
2432
2432
|
limit: options.limit,
|
|
2433
|
-
offset: options.offset,
|
|
2434
2433
|
fields: options.fields?.join(","),
|
|
2435
|
-
filters
|
|
2434
|
+
filters,
|
|
2435
|
+
cursor: options.cursor
|
|
2436
|
+
});
|
|
2437
|
+
return {
|
|
2438
|
+
rows: result.rows,
|
|
2439
|
+
nextCursor: result.next_cursor,
|
|
2440
|
+
tip: result.tip
|
|
2436
2441
|
};
|
|
2437
|
-
return self.queryTable(subgraphName, tableName, params);
|
|
2438
2442
|
},
|
|
2439
2443
|
async count(where) {
|
|
2440
2444
|
const filters = where ? serializeWhere(where, columns) : undefined;
|
|
2441
|
-
const result = await self.
|
|
2445
|
+
const result = await self.count(subgraphName, tableName, {
|
|
2442
2446
|
filters
|
|
2443
2447
|
});
|
|
2444
2448
|
return result.count;
|
|
2445
2449
|
},
|
|
2446
2450
|
async aggregate(spec) {
|
|
2447
2451
|
const filters = spec.where ? serializeWhere(spec.where, columns) : undefined;
|
|
2448
|
-
const result = await self.
|
|
2452
|
+
const result = await self.aggregate(subgraphName, tableName, {
|
|
2449
2453
|
filters,
|
|
2450
2454
|
count: spec.count,
|
|
2451
2455
|
countDistinct: spec.countDistinct,
|
|
@@ -2982,5 +2986,5 @@ export {
|
|
|
2982
2986
|
verifyWebhookSignature
|
|
2983
2987
|
};
|
|
2984
2988
|
|
|
2985
|
-
//# debugId=
|
|
2989
|
+
//# debugId=8B8A60AF0DDA966664756E2164756E21
|
|
2986
2990
|
//# sourceMappingURL=index.js.map
|