@secondlayer/subgraphs 3.15.0 → 3.15.2

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/src/index.js CHANGED
@@ -4,6 +4,7 @@ var __require = /* @__PURE__ */ createRequire(import.meta.url);
4
4
  // src/validate.ts
5
5
  import { z } from "zod/v4";
6
6
  var SubgraphNameSchema = z.string().min(1).max(63).regex(/^[a-z][a-z0-9-]*$/, "Must start with lowercase letter, contain only lowercase alphanumeric and hyphens");
7
+ var SqlIdentifierSchema = z.string().min(1).max(63).regex(/^[a-z_][a-z0-9_]*$/i, "Must be a valid SQL identifier: start with a letter or underscore, then letters/digits/underscores only");
7
8
  var ColumnTypeSchema = z.enum([
8
9
  "text",
9
10
  "uint",
@@ -21,17 +22,17 @@ var SubgraphColumnSchema = z.object({
21
22
  default: z.union([z.string(), z.number(), z.boolean()]).optional()
22
23
  });
23
24
  var SubgraphTableSchema = z.object({
24
- columns: z.record(z.string(), SubgraphColumnSchema).refine((c) => Object.keys(c).length > 0, "Table must have at least one column"),
25
- indexes: z.array(z.array(z.string())).optional(),
26
- uniqueKeys: z.array(z.array(z.string())).optional(),
25
+ columns: z.record(SqlIdentifierSchema, SubgraphColumnSchema).refine((c) => Object.keys(c).length > 0, "Table must have at least one column"),
26
+ indexes: z.array(z.array(SqlIdentifierSchema)).optional(),
27
+ uniqueKeys: z.array(z.array(SqlIdentifierSchema)).optional(),
27
28
  relations: z.array(z.object({
28
29
  name: z.string(),
29
- references: z.string(),
30
- fields: z.array(z.string()).min(1),
31
- referencedColumns: z.array(z.string()).min(1)
30
+ references: SqlIdentifierSchema,
31
+ fields: z.array(SqlIdentifierSchema).min(1),
32
+ referencedColumns: z.array(SqlIdentifierSchema).min(1)
32
33
  })).optional()
33
34
  });
34
- var SubgraphSchemaSchema = z.record(z.string(), SubgraphTableSchema).refine((s) => Object.keys(s).length > 0, "Schema must have at least one table");
35
+ var SubgraphSchemaSchema = z.record(SqlIdentifierSchema, SubgraphTableSchema).refine((s) => Object.keys(s).length > 0, "Schema must have at least one table");
35
36
  var VALID_FILTER_TYPES = [
36
37
  "stx_transfer",
37
38
  "stx_mint",
@@ -359,6 +360,8 @@ class SubgraphContext {
359
360
  return this.overlayMany(table, where, dbRows);
360
361
  }
361
362
  overlayOne(table, where, dbRow) {
363
+ if (this.ops.length === 0)
364
+ return dbRow;
362
365
  let row = dbRow;
363
366
  for (const op of this.ops) {
364
367
  if (op.table !== table)
@@ -368,12 +371,17 @@ class SubgraphContext {
368
371
  return row;
369
372
  }
370
373
  overlayMany(table, where, dbRows) {
374
+ if (this.ops.length === 0)
375
+ return [...dbRows];
371
376
  let result = [...dbRows];
372
377
  for (const op of this.ops) {
373
378
  if (op.table !== table)
374
379
  continue;
375
380
  if (op.kind === "update") {
376
- result = result.map((r) => rowMatches(r, op.data) ? { ...r, ...op.set ?? {} } : r);
381
+ for (let i = 0;i < result.length; i++) {
382
+ if (rowMatches(result[i], op.data))
383
+ result[i] = { ...result[i], ...op.set ?? {} };
384
+ }
377
385
  } else if (op.kind === "delete") {
378
386
  result = result.filter((r) => !rowMatches(r, op.data));
379
387
  } else {
@@ -1752,7 +1760,7 @@ function buildHttpClient() {
1752
1760
  return new IndexHttpClient({
1753
1761
  indexBaseUrl: baseUrl,
1754
1762
  streamsBaseUrl: baseUrl,
1755
- streamsApiKey: process.env.STREAMS_INTERNAL_API_KEY ?? "sk-sl_streams_l2_internal"
1763
+ streamsApiKey: process.env.STREAMS_INTERNAL_API_KEY ?? "sk-sl_streams_decode_internal"
1756
1764
  });
1757
1765
  }
1758
1766
  function resolveBlockSource(subgraph) {
@@ -4029,5 +4037,5 @@ export {
4029
4037
  ByoBreakingChangeError
4030
4038
  };
4031
4039
 
4032
- //# debugId=A05B04227E2702A264756E2164756E21
4040
+ //# debugId=D13A7E4F60723ACE64756E2164756E21
4033
4041
  //# sourceMappingURL=index.js.map