diff --git a/packages/core/src/_test/art-gobblers/app/ponder.schema.ts b/packages/core/src/_test/art-gobblers/app/ponder.schema.ts index 1deecea2b..98974b07f 100644 --- a/packages/core/src/_test/art-gobblers/app/ponder.schema.ts +++ b/packages/core/src/_test/art-gobblers/app/ponder.schema.ts @@ -1,15 +1,15 @@ -import { createSchema, createTable, p } from "../../../../dist"; +import { p } from "../../../../dist"; -export const schema = createSchema({ - SetupEntity: createTable({ +export const schema = p.createSchema({ + SetupEntity: p.createTable({ id: p.string(), }), - Account: createTable({ + Account: p.createTable({ id: p.string(), tokens: p.virtual("Token.ownerId"), }), - Token: createTable({ + Token: p.createTable({ id: p.bigint(), claimedById: p.string().references("Account.id").optional(), ownerId: p.string().references("Account.id"), diff --git a/packages/core/src/_test/ens/app/ponder.schema.ts b/packages/core/src/_test/ens/app/ponder.schema.ts index ad2f21b55..6aece7127 100644 --- a/packages/core/src/_test/ens/app/ponder.schema.ts +++ b/packages/core/src/_test/ens/app/ponder.schema.ts @@ -1,7 +1,7 @@ -import { createSchema, createTable, p } from "../../../../dist"; +import { p } from "../../../../dist"; -export const schema = createSchema({ - EnsNft: createTable({ +export const schema = p.createSchema({ + EnsNft: p.createTable({ id: p.string(), labelHash: p.string(), ownerId: p.string().references("Account.id"), @@ -9,7 +9,7 @@ export const schema = createSchema({ stringArray: p.string().list(), intArray: p.int().list(), }), - Account: createTable({ + Account: p.createTable({ id: p.string(), lastActive: p.int(), tokens: p.virtual("EnsNft.ownerId"), diff --git a/packages/core/src/codegen/service.test.ts b/packages/core/src/codegen/service.test.ts index a2708659d..0556c82ab 100644 --- a/packages/core/src/codegen/service.test.ts +++ b/packages/core/src/codegen/service.test.ts @@ -1,12 +1,12 @@ import { expect, test } from "vitest"; import { buildEntityTypes } from "@/codegen/entity"; -import { createEnum, createSchema, createTable, p } from "@/schema"; +import * as p from "@/schema"; test("entity type codegen succeeds", () => { const output = buildEntityTypes( - createSchema({ - name: createTable({ + p.createSchema({ + name: p.createTable({ id: p.bigint(), age: p.int(), }), @@ -19,9 +19,9 @@ test("entity type codegen succeeds", () => { test("enum type codegen succeeds", () => { const output = buildEntityTypes( - createSchema({ - e: createEnum(["ONE", "TWO"]), - name: createTable({ + p.createSchema({ + e: p.createEnum(["ONE", "TWO"]), + name: p.createTable({ id: p.bigint(), age: p.enum("e"), }), diff --git a/packages/core/src/index.ts b/packages/core/src/index.ts index d4d8a270f..75f9f9213 100644 --- a/packages/core/src/index.ts +++ b/packages/core/src/index.ts @@ -1,6 +1,6 @@ export { PonderApp } from "@/build/functions"; export type { Config, ResolvedConfig } from "@/config/types"; -export { type Infer, createEnum, createSchema, createTable, p } from "@/schema"; +export * as p from "@/schema"; export type { Block } from "@/types/block"; export type { ReadOnlyContract } from "@/types/contract"; export type { Log } from "@/types/log"; diff --git a/packages/core/src/indexing/service.test.ts b/packages/core/src/indexing/service.test.ts index 32eb0ebba..289a512f9 100644 --- a/packages/core/src/indexing/service.test.ts +++ b/packages/core/src/indexing/service.test.ts @@ -6,7 +6,7 @@ import { publicClient } from "@/_test/utils"; import type { IndexingFunctions } from "@/build/functions"; import { LogEventMetadata } from "@/config/abi"; import { EventAggregatorService } from "@/event-aggregator/service"; -import { createSchema, createTable, p } from "@/schema"; +import * as p from "@/schema"; import { IndexingService } from "./service"; @@ -35,8 +35,8 @@ const logFilters = [ const contracts = [{ name: "USDC", ...usdcContractConfig, network }]; -const schema = createSchema({ - TransferEvent: createTable({ +const schema = p.createSchema({ + TransferEvent: p.createTable({ id: p.string(), timestamp: p.int(), }), diff --git a/packages/core/src/schema/index.ts b/packages/core/src/schema/index.ts index 8dd06227a..8731c9abd 100644 --- a/packages/core/src/schema/index.ts +++ b/packages/core/src/schema/index.ts @@ -1,3 +1,16 @@ -export { p } from "./p"; -export { createEnum, createSchema, createTable } from "./schema"; -export type { Infer } from "./types"; +import { + _enum, + bigint, + boolean, + bytes, + float, + int, + string, + virtual, +} from "./p"; +import { createEnum, createSchema, createTable } from "./schema"; +import type { Infer } from "./types"; + +export { bigint, boolean, bytes, _enum as enum, float, int, string, virtual }; +export type { Infer }; +export { createEnum, createSchema, createTable }; diff --git a/packages/core/src/schema/p.test-d.ts b/packages/core/src/schema/p.test-d.ts index aab5b48f0..5d08fc5ed 100644 --- a/packages/core/src/schema/p.test-d.ts +++ b/packages/core/src/schema/p.test-d.ts @@ -1,7 +1,7 @@ import { Hex } from "viem"; import { assertType, test } from "vitest"; -import { p } from "./p"; +import * as p from "./index"; import { type BaseColumn, type RecoverColumnType, diff --git a/packages/core/src/schema/p.test.ts b/packages/core/src/schema/p.test.ts index b9ff64abc..0550539c9 100644 --- a/packages/core/src/schema/p.test.ts +++ b/packages/core/src/schema/p.test.ts @@ -1,6 +1,6 @@ import { expect, test } from "vitest"; -import { p } from "./p"; +import * as p from "./index"; test("string", () => { const c = p.string(); diff --git a/packages/core/src/schema/p.ts b/packages/core/src/schema/p.ts index e919da4e6..a5d6ca9ab 100644 --- a/packages/core/src/schema/p.ts +++ b/packages/core/src/schema/p.ts @@ -157,18 +157,20 @@ const _enum = (type: TType): Enum => ({ /** * Column values in a Ponder schema */ -export const p = { - string: emptyColumn("string"), - int: emptyColumn("int"), - float: emptyColumn("float"), - boolean: emptyColumn("boolean"), - bytes: emptyColumn("bytes"), - bigint: emptyColumn("bigint"), - enum: _enum, - virtual: (derived: T): VirtualColumn => - ({ - _type: "v", - referenceTable: derived.split(".")[0], - referenceColumn: derived.split(".")[1], - } as VirtualColumn), -} as const; +const string = emptyColumn("string"); +const int = emptyColumn("int"); +const float = emptyColumn("float"); +const boolean = emptyColumn("boolean"); +const bytes = emptyColumn("bytes"); +const bigint = emptyColumn("bigint"); + +const virtual = ( + derived: T +): VirtualColumn => + ({ + _type: "v", + referenceTable: derived.split(".")[0], + referenceColumn: derived.split(".")[1], + } as VirtualColumn); + +export { _enum, bigint, boolean, bytes, float, int, string, virtual }; diff --git a/packages/core/src/schema/schema.test-d.ts b/packages/core/src/schema/schema.test-d.ts index d0cc354b4..2d9fc9a4c 100644 --- a/packages/core/src/schema/schema.test-d.ts +++ b/packages/core/src/schema/schema.test-d.ts @@ -1,19 +1,17 @@ import { assertType, test } from "vitest"; -import { p } from "./p"; -import { createEnum, createSchema, createTable } from "./schema"; +import * as p from "./index"; import { BaseColumn, ExtractAllNames, FilterEnums, FilterTables, - Infer, RecoverTableType, Schema, } from "./types"; test("table", () => { - const a = createTable({ + const a = p.createTable({ id: p.string(), age: p.int(), }); @@ -25,7 +23,7 @@ test("table", () => { }); test("table optional", () => { - const t = createTable({ + const t = p.createTable({ id: p.string(), age: p.int().optional(), }); @@ -39,10 +37,10 @@ test("table optional", () => { test("filter enums", () => { const a = { // ^? - t: createTable({ + t: p.createTable({ id: p.string(), }), - e: createEnum(["ONE", "TWO"]), + e: p.createEnum(["ONE", "TWO"]), }; type t = FilterEnums; @@ -54,10 +52,10 @@ test("filter enums", () => { test("filter tables", () => { const a = { // ^? - t: createTable({ + t: p.createTable({ id: p.string(), }), - e: createEnum(["ONE", "TWO"]), + e: p.createEnum(["ONE", "TWO"]), }; type t = FilterTables; @@ -69,12 +67,12 @@ test("filter tables", () => { test("extract all names", () => { const a = { // ^? - t: createTable({ + t: p.createTable({ id: p.string(), ref: p.string().references("OtherTable.id"), ref2: p.string().references("OtherTable.id"), }), - e: createEnum(["ONE", "TWO"]), + e: p.createEnum(["ONE", "TWO"]), }; type t = ExtractAllNames<"OtherTable", typeof a>; @@ -84,10 +82,10 @@ test("extract all names", () => { }); test("schema", () => { - const s = createSchema({ + const s = p.createSchema({ // ^? - e: createEnum(["ONE", "TWO"]), - t: createTable({ + e: p.createEnum(["ONE", "TWO"]), + t: p.createTable({ id: p.string(), e: p.enum("e"), }), @@ -95,7 +93,7 @@ test("schema", () => { assertType(s); - type t = Infer; + type t = p.Infer; // ^? assertType({} as { t: { id: string; e: ["ONE", "TWO"] } }); diff --git a/packages/core/src/schema/schema.test.ts b/packages/core/src/schema/schema.test.ts index c770339da..e94ac4ffa 100644 --- a/packages/core/src/schema/schema.test.ts +++ b/packages/core/src/schema/schema.test.ts @@ -1,10 +1,9 @@ import { expect, test } from "vitest"; -import { p } from "./p"; -import { createEnum, createSchema, createTable } from "./schema"; +import * as p from "./index"; test("table", () => { - const t = createTable({ + const t = p.createTable({ id: p.string(), }); @@ -12,14 +11,14 @@ test("table", () => { }); test("enum", () => { - const e = createEnum(["ONE", "TWO"]); + const e = p.createEnum(["ONE", "TWO"]); expect(e).toStrictEqual(["ONE", "TWO"]); }); test("schema table", () => { - const s = createSchema({ - t: createTable({ + const s = p.createSchema({ + t: p.createTable({ id: p.string(), age: p.int().optional(), }), @@ -30,9 +29,9 @@ test("schema table", () => { }); test("schema enum", () => { - const s = createSchema({ - e: createEnum(["ONE", "TWO"]), - t: createTable({ + const s = p.createSchema({ + e: p.createEnum(["ONE", "TWO"]), + t: p.createTable({ id: p.string(), age: p.enum("e"), }), @@ -43,11 +42,11 @@ test("schema enum", () => { }); test("schema references", () => { - const s = createSchema({ - a: createTable({ + const s = p.createSchema({ + a: p.createTable({ id: p.int(), }), - t: createTable({ + t: p.createTable({ id: p.string(), ageId: p.int().references("a.id"), }), @@ -58,12 +57,12 @@ test("schema references", () => { }); test("schema virtual", () => { - const s = createSchema({ - a: createTable({ + const s = p.createSchema({ + a: p.createTable({ id: p.int(), b: p.virtual("t.ageId"), }), - t: createTable({ + t: p.createTable({ id: p.string(), ageId: p.int().references("a.id"), selfId: p.string().references("t.id"), diff --git a/packages/core/src/schema/utils.test.ts b/packages/core/src/schema/utils.test.ts index 1ff4c3b65..be0dafc57 100644 --- a/packages/core/src/schema/utils.test.ts +++ b/packages/core/src/schema/utils.test.ts @@ -1,6 +1,6 @@ import { expect, test } from "vitest"; -import { p } from "./p"; +import * as p from "./index"; import { isEnumColumn, isReferenceColumn, isVirtualColumn } from "./utils"; test("virtual column", () => { diff --git a/packages/core/src/server/graphql/schema.test.ts b/packages/core/src/server/graphql/schema.test.ts index ef313756d..db99d2f5c 100644 --- a/packages/core/src/server/graphql/schema.test.ts +++ b/packages/core/src/server/graphql/schema.test.ts @@ -1,16 +1,16 @@ import { type GraphQLType } from "graphql"; import { expect, test } from "vitest"; -import { createEnum, createSchema, createTable, p } from "@/schema"; +import * as p from "@/schema"; import { buildGqlSchema } from "./schema"; test("filter type has correct suffixes and types", () => { - const s = createSchema({ - SimpleEnum: createEnum(["VALUE", "ANOTHER_VALUE"]), - RelatedEntityStringId: createTable({ id: p.string() }), - RelatedEntityBigIntId: createTable({ id: p.bigint() }), - Entity: createTable({ + const s = p.createSchema({ + SimpleEnum: p.createEnum(["VALUE", "ANOTHER_VALUE"]), + RelatedEntityStringId: p.createTable({ id: p.string() }), + RelatedEntityBigIntId: p.createTable({ id: p.bigint() }), + Entity: p.createTable({ id: p.string(), int: p.int(), float: p.float(), diff --git a/packages/core/src/server/service.test.ts b/packages/core/src/server/service.test.ts index 0ac35dfc6..0d008d799 100644 --- a/packages/core/src/server/service.test.ts +++ b/packages/core/src/server/service.test.ts @@ -3,7 +3,7 @@ import { beforeEach, expect, test } from "vitest"; import { setupUserStore } from "@/_test/setup"; import type { Common } from "@/Ponder"; -import { createEnum, createSchema, createTable, p } from "@/schema"; +import * as p from "@/schema"; import type { UserStore } from "@/user-store/store"; import { range } from "@/utils/range"; @@ -12,9 +12,9 @@ import { ServerService } from "./service"; beforeEach((context) => setupUserStore(context)); -const s = createSchema({ - TestEnum: createEnum(["ZERO", "ONE", "TWO"]), - TestEntity: createTable({ +const s = p.createSchema({ + TestEnum: p.createEnum(["ZERO", "ONE", "TWO"]), + TestEntity: p.createTable({ id: p.string(), string: p.string(), int: p.int(), @@ -30,9 +30,9 @@ const s = createSchema({ enum: p.enum("TestEnum"), derived: p.virtual("EntityWithBigIntId.testEntityId"), }), - EntityWithIntId: createTable({ id: p.int() }), + EntityWithIntId: p.createTable({ id: p.int() }), - EntityWithBigIntId: createTable({ + EntityWithBigIntId: p.createTable({ id: p.bigint(), testEntityId: p.string().references("TestEntity.id"), }), diff --git a/packages/core/src/types/model.test-d.ts b/packages/core/src/types/model.test-d.ts index 76131b82e..7a61dec8d 100644 --- a/packages/core/src/types/model.test-d.ts +++ b/packages/core/src/types/model.test-d.ts @@ -1,13 +1,13 @@ import { test } from "vitest"; -import { createSchema, createTable, p } from "@/schema"; +import * as p from "@/schema"; import { RecoverTableType } from "@/schema/types"; import { Model } from ".."; test("model", () => { - const schema = createSchema({ - name: createTable({ + const schema = p.createSchema({ + name: p.createTable({ id: p.bigint(), }), }); diff --git a/packages/core/src/user-store/store.test.ts b/packages/core/src/user-store/store.test.ts index eab336c1e..b6a07256d 100644 --- a/packages/core/src/user-store/store.test.ts +++ b/packages/core/src/user-store/store.test.ts @@ -1,20 +1,20 @@ import { beforeEach, expect, test } from "vitest"; import { setupUserStore } from "@/_test/setup"; -import { createEnum, createSchema, createTable, p } from "@/schema"; +import * as p from "@/schema"; beforeEach((context) => setupUserStore(context)); -const schema = createSchema({ - PetKind: createEnum(["CAT", "DOG"]), - Pet: createTable({ +const schema = p.createSchema({ + PetKind: p.createEnum(["CAT", "DOG"]), + Pet: p.createTable({ id: p.string(), name: p.string(), age: p.int().optional(), bigAge: p.bigint().optional(), kind: p.enum("PetKind").optional(), }), - Person: createTable({ + Person: p.createTable({ id: p.string(), name: p.string(), }),