Skip to content

Commit

Permalink
only export p
Browse files Browse the repository at this point in the history
  • Loading branch information
kyscott18 committed Nov 1, 2023
1 parent b531747 commit 52c2b10
Show file tree
Hide file tree
Showing 16 changed files with 102 additions and 90 deletions.
10 changes: 5 additions & 5 deletions packages/core/src/_test/art-gobblers/app/ponder.schema.ts
Original file line number Diff line number Diff line change
@@ -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"),
Expand Down
8 changes: 4 additions & 4 deletions packages/core/src/_test/ens/app/ponder.schema.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
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"),
transferredAt: p.int(),
stringArray: p.string().list(),
intArray: p.int().list(),
}),
Account: createTable({
Account: p.createTable({
id: p.string(),
lastActive: p.int(),
tokens: p.virtual("EnsNft.ownerId"),
Expand Down
12 changes: 6 additions & 6 deletions packages/core/src/codegen/service.test.ts
Original file line number Diff line number Diff line change
@@ -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(),
}),
Expand All @@ -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"),
}),
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/index.ts
Original file line number Diff line number Diff line change
@@ -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";
Expand Down
6 changes: 3 additions & 3 deletions packages/core/src/indexing/service.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand Down Expand Up @@ -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(),
}),
Expand Down
19 changes: 16 additions & 3 deletions packages/core/src/schema/index.ts
Original file line number Diff line number Diff line change
@@ -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 };
2 changes: 1 addition & 1 deletion packages/core/src/schema/p.test-d.ts
Original file line number Diff line number Diff line change
@@ -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,
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/schema/p.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { expect, test } from "vitest";

import { p } from "./p";
import * as p from "./index";

test("string", () => {
const c = p.string();
Expand Down
32 changes: 17 additions & 15 deletions packages/core/src/schema/p.ts
Original file line number Diff line number Diff line change
Expand Up @@ -157,18 +157,20 @@ const _enum = <TType extends string>(type: TType): Enum<TType, false> => ({
/**
* 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: <T extends `${string}.${string}`>(derived: T): VirtualColumn<T> =>
({
_type: "v",
referenceTable: derived.split(".")[0],
referenceColumn: derived.split(".")[1],
} as VirtualColumn<T>),
} 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 = <T extends `${string}.${string}`>(
derived: T
): VirtualColumn<T> =>
({
_type: "v",
referenceTable: derived.split(".")[0],
referenceColumn: derived.split(".")[1],
} as VirtualColumn<T>);

export { _enum, bigint, boolean, bytes, float, int, string, virtual };
28 changes: 13 additions & 15 deletions packages/core/src/schema/schema.test-d.ts
Original file line number Diff line number Diff line change
@@ -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(),
});
Expand All @@ -25,7 +23,7 @@ test("table", () => {
});

test("table optional", () => {
const t = createTable({
const t = p.createTable({
id: p.string(),
age: p.int().optional(),
});
Expand All @@ -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<typeof a>;
Expand All @@ -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<typeof a>;
Expand All @@ -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>;
Expand All @@ -84,18 +82,18 @@ 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"),
}),
});

assertType<Schema>(s);

type t = Infer<typeof s>;
type t = p.Infer<typeof s>;
// ^?

assertType<t>({} as { t: { id: string; e: ["ONE", "TWO"] } });
Expand Down
29 changes: 14 additions & 15 deletions packages/core/src/schema/schema.test.ts
Original file line number Diff line number Diff line change
@@ -1,25 +1,24 @@
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(),
});

expect(t.id).toBeTruthy();
});

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(),
}),
Expand All @@ -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"),
}),
Expand All @@ -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"),
}),
Expand All @@ -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"),
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/schema/utils.test.ts
Original file line number Diff line number Diff line change
@@ -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", () => {
Expand Down
12 changes: 6 additions & 6 deletions packages/core/src/server/graphql/schema.test.ts
Original file line number Diff line number Diff line change
@@ -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(),
Expand Down
Loading

0 comments on commit 52c2b10

Please sign in to comment.