@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
|
@@ -179,7 +179,7 @@ declare class Subgraphs extends BaseClient {
|
|
|
179
179
|
* pass an apiKey on the client where reads are closed. Resume with the
|
|
180
180
|
* returned `next_cursor`.
|
|
181
181
|
*/
|
|
182
|
-
rows<T = unknown>(name: string, table: string, params?: Omit<SubgraphQueryParams, "offset"
|
|
182
|
+
rows<T = unknown>(name: string, table: string, params?: Omit<SubgraphQueryParams, "offset"> & {
|
|
183
183
|
cursor?: string;
|
|
184
184
|
}): Promise<SubgraphRowsEnvelope<T>>;
|
|
185
185
|
/** Recent reindex/backfill operations for a subgraph, newest first. */
|
|
@@ -201,11 +201,14 @@ declare class Subgraphs extends BaseClient {
|
|
|
201
201
|
bundle(data: {
|
|
202
202
|
code: string;
|
|
203
203
|
}): Promise<BundleSubgraphResponse>;
|
|
204
|
-
|
|
205
|
-
|
|
204
|
+
/** Open /v1 read: exact row count for a filtered set. Same auth posture as
|
|
205
|
+
* {@link rows}. */
|
|
206
|
+
count(name: string, table: string, params?: Pick<SubgraphQueryParams, "filters">): Promise<{
|
|
206
207
|
count: number;
|
|
207
208
|
}>;
|
|
208
|
-
|
|
209
|
+
/** Open /v1 read: scalar aggregates over a filtered set. Same auth posture
|
|
210
|
+
* as {@link rows}. */
|
|
211
|
+
aggregate(name: string, table: string, params?: SubgraphAggregateParams): Promise<SubgraphAggregateResponse>;
|
|
209
212
|
/**
|
|
210
213
|
* Returns a typed client for a subgraph defined with `defineSubgraph()`.
|
|
211
214
|
* Row types are inferred from the subgraph's schema literal types.
|
|
@@ -214,8 +217,9 @@ declare class Subgraphs extends BaseClient {
|
|
|
214
217
|
* ```ts
|
|
215
218
|
* import mySubgraph from './subgraphs/my-token-subgraph'
|
|
216
219
|
* const client = sl.subgraphs.typed(mySubgraph)
|
|
217
|
-
* const
|
|
218
|
-
* // rows: InferTableRow<typeof mySubgraph.schema.transfers>[]
|
|
220
|
+
* const page = await client.transfers.findMany({ where: { sender: 'SP...' } })
|
|
221
|
+
* // page.rows: InferTableRow<typeof mySubgraph.schema.transfers>[]
|
|
222
|
+
* // page.nextCursor: string | null — pass back as `cursor` to resume
|
|
219
223
|
* ```
|
|
220
224
|
*/
|
|
221
225
|
typed<T extends {
|
|
@@ -2659,7 +2663,7 @@ declare class SecondLayer extends BaseClient {
|
|
|
2659
2663
|
* import { getSubgraph } from '@secondlayer/sdk'
|
|
2660
2664
|
*
|
|
2661
2665
|
* const client = getSubgraph(mySubgraph, { apiKey: 'sl_...' })
|
|
2662
|
-
* const
|
|
2666
|
+
* const page = await client.transfers.findMany({ where: { sender: 'SP...' } })
|
|
2663
2667
|
* ```
|
|
2664
2668
|
*/
|
|
2665
2669
|
declare function getSubgraph<T extends {
|
package/dist/subgraphs/index.js
CHANGED
|
@@ -730,7 +730,6 @@ function buildSubgraphQueryString(params) {
|
|
|
730
730
|
_sort: params.sort,
|
|
731
731
|
_order: params.order,
|
|
732
732
|
_limit: params.limit,
|
|
733
|
-
_offset: params.offset,
|
|
734
733
|
_fields: params.fields,
|
|
735
734
|
...params.filters
|
|
736
735
|
});
|
|
@@ -808,15 +807,11 @@ class Subgraphs extends BaseClient {
|
|
|
808
807
|
async bundle(data) {
|
|
809
808
|
return this.request("POST", "/api/subgraphs/bundle", data);
|
|
810
809
|
}
|
|
811
|
-
async
|
|
812
|
-
|
|
813
|
-
return Array.isArray(result) ? result : result.data;
|
|
810
|
+
async count(name, table, params = {}) {
|
|
811
|
+
return this.request("GET", `/v1/subgraphs/${seg(name)}/${seg(table)}/count${buildSubgraphQueryString(params)}`);
|
|
814
812
|
}
|
|
815
|
-
async
|
|
816
|
-
return this.request("GET", `/
|
|
817
|
-
}
|
|
818
|
-
async queryTableAggregate(name, table, params = {}) {
|
|
819
|
-
return this.request("GET", `/api/subgraphs/${seg(name)}/${seg(table)}/aggregate${buildAggregateQueryString(params)}`);
|
|
813
|
+
async aggregate(name, table, params = {}) {
|
|
814
|
+
return this.request("GET", `/v1/subgraphs/${seg(name)}/${seg(table)}/aggregate${buildAggregateQueryString(params)}`);
|
|
820
815
|
}
|
|
821
816
|
typed(def) {
|
|
822
817
|
const result = {};
|
|
@@ -833,32 +828,41 @@ class Subgraphs extends BaseClient {
|
|
|
833
828
|
let sort;
|
|
834
829
|
let order;
|
|
835
830
|
if (options.orderBy) {
|
|
836
|
-
const entries =
|
|
837
|
-
if (entries.length >
|
|
838
|
-
|
|
839
|
-
|
|
831
|
+
const entries = Object.entries(options.orderBy);
|
|
832
|
+
if (entries.length > 1) {
|
|
833
|
+
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.`);
|
|
834
|
+
}
|
|
835
|
+
const entry = entries[0];
|
|
836
|
+
if (entry) {
|
|
837
|
+
const [col, dir] = entry;
|
|
838
|
+
sort = resolveOrderByColumn(col, columns);
|
|
839
|
+
order = dir ?? "asc";
|
|
840
840
|
}
|
|
841
841
|
}
|
|
842
|
-
const
|
|
842
|
+
const result = await self.rows(subgraphName, tableName, {
|
|
843
843
|
sort,
|
|
844
844
|
order,
|
|
845
845
|
limit: options.limit,
|
|
846
|
-
offset: options.offset,
|
|
847
846
|
fields: options.fields?.join(","),
|
|
848
|
-
filters
|
|
847
|
+
filters,
|
|
848
|
+
cursor: options.cursor
|
|
849
|
+
});
|
|
850
|
+
return {
|
|
851
|
+
rows: result.rows,
|
|
852
|
+
nextCursor: result.next_cursor,
|
|
853
|
+
tip: result.tip
|
|
849
854
|
};
|
|
850
|
-
return self.queryTable(subgraphName, tableName, params);
|
|
851
855
|
},
|
|
852
856
|
async count(where) {
|
|
853
857
|
const filters = where ? serializeWhere(where, columns) : undefined;
|
|
854
|
-
const result = await self.
|
|
858
|
+
const result = await self.count(subgraphName, tableName, {
|
|
855
859
|
filters
|
|
856
860
|
});
|
|
857
861
|
return result.count;
|
|
858
862
|
},
|
|
859
863
|
async aggregate(spec) {
|
|
860
864
|
const filters = spec.where ? serializeWhere(spec.where, columns) : undefined;
|
|
861
|
-
const result = await self.
|
|
865
|
+
const result = await self.aggregate(subgraphName, tableName, {
|
|
862
866
|
filters,
|
|
863
867
|
count: spec.count,
|
|
864
868
|
countDistinct: spec.countDistinct,
|
|
@@ -2688,5 +2692,5 @@ export {
|
|
|
2688
2692
|
getSubgraph
|
|
2689
2693
|
};
|
|
2690
2694
|
|
|
2691
|
-
//# debugId=
|
|
2695
|
+
//# debugId=0162A8C28478658D64756E2164756E21
|
|
2692
2696
|
//# sourceMappingURL=index.js.map
|