@secondlayer/sdk 10.6.0 → 12.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.
@@ -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" | "sort"> & {
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
- queryTable(name: string, table: string, params?: SubgraphQueryParams): Promise<unknown[]>;
205
- queryTableCount(name: string, table: string, params?: SubgraphQueryParams): Promise<{
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
- queryTableAggregate(name: string, table: string, params?: SubgraphAggregateParams): Promise<SubgraphAggregateResponse>;
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 rows = await client.transfers.findMany({ where: { sender: 'SP...' } })
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 rows = await client.transfers.findMany({ where: { sender: 'SP...' } })
2666
+ * const page = await client.transfers.findMany({ where: { sender: 'SP...' } })
2663
2667
  * ```
2664
2668
  */
2665
2669
  declare function getSubgraph<T extends {
@@ -198,7 +198,6 @@ function raceAbort(promise, signal) {
198
198
  var LOCAL_API_URL = "http://127.0.0.1:3800";
199
199
  var INSTANCE_TOKEN_ENV = "INSTANCE_TOKEN";
200
200
  var ACCOUNT_KEY_ENV = "SECONDLAYER_API_KEY";
201
- var warnedUrlAlias = false;
202
201
  function resolveBaseUrl(explicit) {
203
202
  if (explicit && explicit.length > 0)
204
203
  return explicit.replace(/\/+$/, "");
@@ -206,14 +205,6 @@ function resolveBaseUrl(explicit) {
206
205
  const primary = process.env?.SECONDLAYER_API_URL || undefined;
207
206
  if (primary)
208
207
  return primary.replace(/\/+$/, "");
209
- const legacy = process.env?.SL_API_URL || undefined;
210
- if (legacy) {
211
- if (!warnedUrlAlias) {
212
- warnedUrlAlias = true;
213
- console.warn("[secondlayer] SL_API_URL is a legacy alias of SECONDLAYER_API_URL; using the alias this once.");
214
- }
215
- return legacy.replace(/\/+$/, "");
216
- }
217
208
  }
218
209
  return LOCAL_API_URL;
219
210
  }
@@ -225,26 +216,12 @@ function resolveApiKey(apiKey) {
225
216
  const token = process.env?.INSTANCE_TOKEN || undefined;
226
217
  return token;
227
218
  }
228
- var warnedArchiveAlias = false;
229
219
  function resolveAccountKey(accountKey) {
230
220
  if (accountKey !== undefined)
231
221
  return accountKey;
232
222
  if (typeof process === "undefined")
233
223
  return;
234
- const primary = process.env?.SECONDLAYER_API_KEY || undefined;
235
- const slAlias = process.env?.SL_API_KEY || undefined;
236
- const archiveAlias = process.env?.SL_ARCHIVE_API_KEY || undefined;
237
- if (primary)
238
- return primary;
239
- const legacy = slAlias ?? archiveAlias;
240
- if (legacy) {
241
- if (!warnedArchiveAlias) {
242
- warnedArchiveAlias = true;
243
- console.warn("[secondlayer] SL_API_KEY / SL_ARCHIVE_API_KEY are legacy aliases of SECONDLAYER_API_KEY; using the alias this once.");
244
- }
245
- return legacy;
246
- }
247
- return;
224
+ return process.env?.SECONDLAYER_API_KEY || undefined;
248
225
  }
249
226
  function seg(value) {
250
227
  return encodeURIComponent(String(value));
@@ -730,7 +707,6 @@ function buildSubgraphQueryString(params) {
730
707
  _sort: params.sort,
731
708
  _order: params.order,
732
709
  _limit: params.limit,
733
- _offset: params.offset,
734
710
  _fields: params.fields,
735
711
  ...params.filters
736
712
  });
@@ -808,15 +784,11 @@ class Subgraphs extends BaseClient {
808
784
  async bundle(data) {
809
785
  return this.request("POST", "/api/subgraphs/bundle", data);
810
786
  }
811
- async queryTable(name, table, params = {}) {
812
- const result = await this.request("GET", `/api/subgraphs/${seg(name)}/${seg(table)}${buildSubgraphQueryString(params)}`);
813
- return Array.isArray(result) ? result : result.data;
814
- }
815
- async queryTableCount(name, table, params = {}) {
816
- return this.request("GET", `/api/subgraphs/${seg(name)}/${seg(table)}/count${buildSubgraphQueryString(params)}`);
787
+ async count(name, table, params = {}) {
788
+ return this.request("GET", `/v1/subgraphs/${seg(name)}/${seg(table)}/count${buildSubgraphQueryString(params)}`);
817
789
  }
818
- async queryTableAggregate(name, table, params = {}) {
819
- return this.request("GET", `/api/subgraphs/${seg(name)}/${seg(table)}/aggregate${buildAggregateQueryString(params)}`);
790
+ async aggregate(name, table, params = {}) {
791
+ return this.request("GET", `/v1/subgraphs/${seg(name)}/${seg(table)}/aggregate${buildAggregateQueryString(params)}`);
820
792
  }
821
793
  typed(def) {
822
794
  const result = {};
@@ -833,32 +805,41 @@ class Subgraphs extends BaseClient {
833
805
  let sort;
834
806
  let order;
835
807
  if (options.orderBy) {
836
- const entries = Array.isArray(options.orderBy) ? options.orderBy : Object.entries(options.orderBy);
837
- if (entries.length > 0) {
838
- sort = entries.map(([col]) => resolveOrderByColumn(col, columns)).join(",");
839
- order = entries.map(([, dir]) => dir ?? "asc").join(",");
808
+ const entries = Object.entries(options.orderBy);
809
+ if (entries.length > 1) {
810
+ 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.`);
811
+ }
812
+ const entry = entries[0];
813
+ if (entry) {
814
+ const [col, dir] = entry;
815
+ sort = resolveOrderByColumn(col, columns);
816
+ order = dir ?? "asc";
840
817
  }
841
818
  }
842
- const params = {
819
+ const result = await self.rows(subgraphName, tableName, {
843
820
  sort,
844
821
  order,
845
822
  limit: options.limit,
846
- offset: options.offset,
847
823
  fields: options.fields?.join(","),
848
- filters
824
+ filters,
825
+ cursor: options.cursor
826
+ });
827
+ return {
828
+ rows: result.rows,
829
+ nextCursor: result.next_cursor,
830
+ tip: result.tip
849
831
  };
850
- return self.queryTable(subgraphName, tableName, params);
851
832
  },
852
833
  async count(where) {
853
834
  const filters = where ? serializeWhere(where, columns) : undefined;
854
- const result = await self.queryTableCount(subgraphName, tableName, {
835
+ const result = await self.count(subgraphName, tableName, {
855
836
  filters
856
837
  });
857
838
  return result.count;
858
839
  },
859
840
  async aggregate(spec) {
860
841
  const filters = spec.where ? serializeWhere(spec.where, columns) : undefined;
861
- const result = await self.queryTableAggregate(subgraphName, tableName, {
842
+ const result = await self.aggregate(subgraphName, tableName, {
862
843
  filters,
863
844
  count: spec.count,
864
845
  countDistinct: spec.countDistinct,
@@ -2688,5 +2669,5 @@ export {
2688
2669
  getSubgraph
2689
2670
  };
2690
2671
 
2691
- //# debugId=8E4B27D4BE8A894F64756E2164756E21
2672
+ //# debugId=351ADA07395C9F6764756E2164756E21
2692
2673
  //# sourceMappingURL=index.js.map