@secondlayer/subgraphs 3.14.4 → 3.15.1
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 +20 -11
- package/dist/src/index.js.map +6 -6
- package/dist/src/runtime/block-processor.js +11 -3
- package/dist/src/runtime/block-processor.js.map +3 -3
- package/dist/src/runtime/catchup.js +11 -3
- package/dist/src/runtime/catchup.js.map +3 -3
- package/dist/src/runtime/context.js +11 -3
- package/dist/src/runtime/context.js.map +3 -3
- package/dist/src/runtime/emitter.js.map +2 -2
- package/dist/src/runtime/processor.js +13 -4
- package/dist/src/runtime/processor.js.map +4 -4
- package/dist/src/runtime/reindex.js +11 -3
- package/dist/src/runtime/reindex.js.map +3 -3
- package/dist/src/runtime/reorg.js +13 -4
- package/dist/src/runtime/reorg.js.map +4 -4
- package/dist/src/runtime/replay.js +16 -3
- package/dist/src/runtime/replay.js.map +3 -3
- package/dist/src/schema/index.js +10 -9
- package/dist/src/schema/index.js.map +4 -4
- package/dist/src/service.js +13 -4
- package/dist/src/service.js.map +4 -4
- package/dist/src/validate.d.ts +8 -1
- package/dist/src/validate.js +10 -8
- package/dist/src/validate.js.map +3 -3
- package/package.json +2 -2
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(
|
|
25
|
-
indexes: z.array(z.array(
|
|
26
|
-
uniqueKeys: z.array(z.array(
|
|
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:
|
|
30
|
-
fields: z.array(
|
|
31
|
-
referencedColumns: z.array(
|
|
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(
|
|
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
|
-
|
|
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 {
|
|
@@ -381,7 +389,8 @@ class SubgraphContext {
|
|
|
381
389
|
const clean = stripControlKeys(op.data);
|
|
382
390
|
const idx = upsertKeys ? result.findIndex((r) => upsertKeys.every((k) => valEq(r[k], clean[k]))) : -1;
|
|
383
391
|
if (idx >= 0) {
|
|
384
|
-
|
|
392
|
+
const existing = result[idx];
|
|
393
|
+
result[idx] = this.applyOpToRow(op, existing, where) ?? existing;
|
|
385
394
|
} else {
|
|
386
395
|
const created = this.applyOpToRow(op, null, where);
|
|
387
396
|
if (created)
|
|
@@ -3820,7 +3829,7 @@ function renderDeployPlan(def, schemaName) {
|
|
|
3820
3829
|
"-- Run once on YOUR database as an owner/superuser, replacing <role>",
|
|
3821
3830
|
"-- with the role whose credentials you give Secondlayer.",
|
|
3822
3831
|
"-- Secondlayer then creates and owns only this one schema:",
|
|
3823
|
-
|
|
3832
|
+
"GRANT CREATE ON DATABASE current_database() TO <role>;",
|
|
3824
3833
|
`-- (after first deploy <role> owns "${schema}"; no further grants needed)`
|
|
3825
3834
|
].join(`
|
|
3826
3835
|
`);
|
|
@@ -4028,5 +4037,5 @@ export {
|
|
|
4028
4037
|
ByoBreakingChangeError
|
|
4029
4038
|
};
|
|
4030
4039
|
|
|
4031
|
-
//# debugId=
|
|
4040
|
+
//# debugId=25484A9D8E58948C64756E2164756E21
|
|
4032
4041
|
//# sourceMappingURL=index.js.map
|