Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion scenarios/test_codegen/test/ConcurrentWrite_test.res
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ describe("Concurrent batch write and processing", () => {
await indexerMock.getBatchWritePromise()

t.expect(
(writeBatchErrors, await indexerMock.queryHistory(SimpleEntity)),
(writeBatchErrors, await (indexerMock.queryHistory("SimpleEntity"): promise<array<Change.t<Indexer.Entities.SimpleEntity.t>>>)),
~message="The delete history row persisted by the in-flight write must not be written again by the next write",
).toEqual((
[],
Expand Down
8 changes: 4 additions & 4 deletions scenarios/test_codegen/test/E2E_test.res
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ describe("E2E tests", () => {
])
await indexerMock.getBatchWritePromise()

t.expect(await indexerMock.query(SimpleEntity)).toEqual([
t.expect(await (indexerMock.query("SimpleEntity"): promise<array<Indexer.Entities.SimpleEntity.t>>)).toEqual([
{Indexer.Entities.SimpleEntity.id: "1", value: "value-2"},
])
t.expect(errors, ~message="should have an error thrown during set").toEqual([
Expand Down Expand Up @@ -1388,7 +1388,7 @@ describe("E2E tests", () => {
// Item at 2000 should NOT be in DB yet — earlier chunks haven't completed,
// so bufferBlockNumber=800 and 2000 > 800 means it's not ready.
t.expect(
await indexerMock.query(SimpleEntity),
await (indexerMock.query("SimpleEntity"): promise<array<Indexer.Entities.SimpleEntity.t>>),
~message="Item at block 2000 should not be ready while earlier chunks are pending",
).toEqual([])

Expand All @@ -1415,7 +1415,7 @@ describe("E2E tests", () => {
// Only item-850 should be in DB — chunk2 hasn't completed,
// so chunk3's item at 2000 is still beyond the buffer.
t.expect(
await indexerMock.query(SimpleEntity),
await (indexerMock.query("SimpleEntity"): promise<array<Indexer.Entities.SimpleEntity.t>>),
~message="Only item-850 should be in DB while chunk2 is pending",
).toEqual([{Indexer.Entities.SimpleEntity.id: "item-850", value: "from-chunk1"}])

Expand All @@ -1434,7 +1434,7 @@ describe("E2E tests", () => {

// Both items should now be in DB
t.expect(
await indexerMock.query(SimpleEntity),
await (indexerMock.query("SimpleEntity"): promise<array<Indexer.Entities.SimpleEntity.t>>),
~message="Both items should be in DB after chunk1 fully completes",
).toEqual([
{Indexer.Entities.SimpleEntity.id: "item-850", value: "from-chunk1"},
Expand Down
52 changes: 26 additions & 26 deletions scenarios/test_codegen/test/LoadLayer_test.res
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ describe("LoadLayer", () => {
LoadLayer.loadById(
~loadManager,
~persistence=storageMock->MockIndexer.Storage.toPersistence,
~entityConfig=MockIndexer.entityConfig(User),
~entityConfig=MockIndexer.entityConfig("User"),
~indexerState,
~entityId,
~item=MockEvents.newGravatarLog1->MockEvents.newGravatarEventToBatchItem,
Expand Down Expand Up @@ -38,7 +38,7 @@ describe("LoadLayer", () => {
LoadLayer.loadById(
~loadManager,
~persistence=storageMock->MockIndexer.Storage.toPersistence,
~entityConfig=MockIndexer.entityConfig(User),
~entityConfig=MockIndexer.entityConfig("User"),
~indexerState,
~entityId,
~item=MockEvents.newGravatarLog1->MockEvents.newGravatarEventToBatchItem,
Expand Down Expand Up @@ -73,7 +73,7 @@ describe("LoadLayer", () => {
LoadLayer.loadById(
~loadManager,
~persistence=storageMock->MockIndexer.Storage.toPersistence,
~entityConfig=MockIndexer.entityConfig(User),
~entityConfig=MockIndexer.entityConfig("User"),
~indexerState,
~entityId,
~item=MockEvents.newGravatarLog1->MockEvents.newGravatarEventToBatchItem,
Expand Down Expand Up @@ -103,7 +103,7 @@ describe("LoadLayer", () => {
LoadLayer.loadById(
~loadManager,
~persistence=storageMock->MockIndexer.Storage.toPersistence,
~entityConfig=MockIndexer.entityConfig(User),
~entityConfig=MockIndexer.entityConfig("User"),
~indexerState,
~entityId,
~item=MockEvents.newGravatarLog1->MockEvents.newGravatarEventToBatchItem,
Expand Down Expand Up @@ -148,7 +148,7 @@ describe("LoadLayer", () => {
LoadLayer.loadById(
~loadManager,
~persistence=storageMock->MockIndexer.Storage.toPersistence,
~entityConfig=MockIndexer.entityConfig(User),
~entityConfig=MockIndexer.entityConfig("User"),
~indexerState,
~entityId,
~item=MockEvents.newGravatarLog1->MockEvents.newGravatarEventToBatchItem,
Expand Down Expand Up @@ -184,13 +184,13 @@ describe("LoadLayer", () => {
)

let indexerState = MockIndexer.InMemoryStore.make(
~entities=[(MockIndexer.entityConfig(User), [user1])],
~entities=[(MockIndexer.entityConfig("User"), [user1])],
)
let getUser = entityId =>
LoadLayer.loadById(
~loadManager,
~persistence=storageMock->MockIndexer.Storage.toPersistence,
~entityConfig=MockIndexer.entityConfig(User),
~entityConfig=MockIndexer.entityConfig("User"),
~indexerState,
~entityId,
~item=MockEvents.newGravatarLog1->MockEvents.newGravatarEventToBatchItem,
Expand Down Expand Up @@ -234,7 +234,7 @@ describe("LoadLayer", () => {
LoadLayer.loadById(
~loadManager,
~persistence=storageMock->MockIndexer.Storage.toPersistence,
~entityConfig=MockIndexer.entityConfig(User),
~entityConfig=MockIndexer.entityConfig("User"),
~indexerState,
~entityId,
~item=MockEvents.newGravatarLog1->MockEvents.newGravatarEventToBatchItem,
Expand All @@ -250,7 +250,7 @@ describe("LoadLayer", () => {
await Promise.resolve()

indexerState->MockIndexer.InMemoryStore.setEntity(
~entityConfig=MockIndexer.entityConfig(User),
~entityConfig=MockIndexer.entityConfig("User"),
user1,
)

Expand Down Expand Up @@ -284,14 +284,14 @@ describe("LoadLayer", () => {
)

let indexerState = MockIndexer.InMemoryStore.make(
~entities=[(MockIndexer.entityConfig(User), [user1])],
~entities=[(MockIndexer.entityConfig("User"), [user1])],
)

let getUser = entityId =>
LoadLayer.loadById(
~loadManager,
~persistence=storageMock->MockIndexer.Storage.toPersistence,
~entityConfig=MockIndexer.entityConfig(User),
~entityConfig=MockIndexer.entityConfig("User"),
~indexerState,
~entityId,
~item=MockEvents.newGravatarLog1->MockEvents.newGravatarEventToBatchItem,
Expand Down Expand Up @@ -335,7 +335,7 @@ describe("LoadLayer", () => {
LoadLayer.loadByFilter(
~loadManager,
~persistence=storageMock->MockIndexer.Storage.toPersistence,
~entityConfig=MockIndexer.entityConfig(User),
~entityConfig=MockIndexer.entityConfig("User"),
~indexerState,
~item,
~ecosystem=MockIndexer.config.ecosystem,
Expand All @@ -349,7 +349,7 @@ describe("LoadLayer", () => {
LoadLayer.loadByFilter(
~loadManager,
~persistence=storageMock->MockIndexer.Storage.toPersistence,
~entityConfig=MockIndexer.entityConfig(User),
~entityConfig=MockIndexer.entityConfig("User"),
~indexerState,
~item,
~ecosystem=MockIndexer.config.ecosystem,
Expand Down Expand Up @@ -381,7 +381,7 @@ describe("LoadLayer", () => {
LoadLayer.loadByFilter(
~loadManager,
~persistence=storageMock->MockIndexer.Storage.toPersistence,
~entityConfig=MockIndexer.entityConfig(User),
~entityConfig=MockIndexer.entityConfig("User"),
~indexerState,
~item,
~ecosystem=MockIndexer.config.ecosystem,
Expand Down Expand Up @@ -419,15 +419,15 @@ describe("LoadLayer", () => {
}

let indexerState = MockIndexer.InMemoryStore.make(
~entities=[(MockIndexer.entityConfig(User), [user1])],
~entities=[(MockIndexer.entityConfig("User"), [user1])],
)

let item = MockEvents.newGravatarLog1->MockEvents.newGravatarEventToBatchItem
let getUsersWithAddress = fieldValue =>
LoadLayer.loadByFilter(
~loadManager,
~persistence=storageMock->MockIndexer.Storage.toPersistence,
~entityConfig=MockIndexer.entityConfig(User),
~entityConfig=MockIndexer.entityConfig("User"),
~indexerState,
~item,
~ecosystem=MockIndexer.config.ecosystem,
Expand Down Expand Up @@ -469,7 +469,7 @@ describe("LoadLayer", () => {

let storageMock = MockIndexer.Storage.make(
[#loadOrThrow],
~dbEntities=[(MockIndexer.entityConfig(User), [user1, user2, user("3", "0x3")])],
~dbEntities=[(MockIndexer.entityConfig("User"), [user1, user2, user("3", "0x3")])],
)
let loadManager = LoadManager.make()
let indexerState = MockIndexer.InMemoryStore.make()
Expand All @@ -479,7 +479,7 @@ describe("LoadLayer", () => {
LoadLayer.loadByFilter(
~loadManager,
~persistence=storageMock->MockIndexer.Storage.toPersistence,
~entityConfig=MockIndexer.entityConfig(User),
~entityConfig=MockIndexer.entityConfig("User"),
~indexerState,
~item,
~ecosystem=MockIndexer.config.ecosystem,
Expand Down Expand Up @@ -520,7 +520,7 @@ describe("LoadLayer", () => {
LoadLayer.loadByFilter(
~loadManager,
~persistence=storageMock->MockIndexer.Storage.toPersistence,
~entityConfig=MockIndexer.entityConfig(User),
~entityConfig=MockIndexer.entityConfig("User"),
~indexerState,
~item,
~ecosystem=MockIndexer.config.ecosystem,
Expand Down Expand Up @@ -560,7 +560,7 @@ describe("LoadLayer", () => {
LoadLayer.loadByFilter(
~loadManager,
~persistence=storageMock->MockIndexer.Storage.toPersistence,
~entityConfig=MockIndexer.entityConfig(User),
~entityConfig=MockIndexer.entityConfig("User"),
~indexerState,
~item,
~ecosystem=MockIndexer.config.ecosystem,
Expand Down Expand Up @@ -614,15 +614,15 @@ describe("LoadLayer", () => {
}

let indexerState = MockIndexer.InMemoryStore.make(
~entities=[(MockIndexer.entityConfig(User), [user1, user2])],
~entities=[(MockIndexer.entityConfig("User"), [user1, user2])],
)

let item = MockEvents.newGravatarLog1->MockEvents.newGravatarEventToBatchItem
let getUsersWithId = fieldValue =>
LoadLayer.loadByFilter(
~loadManager,
~persistence=storageMock->MockIndexer.Storage.toPersistence,
~entityConfig=MockIndexer.entityConfig(User),
~entityConfig=MockIndexer.entityConfig("User"),
~indexerState,
~item,
~ecosystem=MockIndexer.config.ecosystem,
Expand All @@ -637,7 +637,7 @@ describe("LoadLayer", () => {
LoadLayer.loadByFilter(
~loadManager,
~persistence=storageMock->MockIndexer.Storage.toPersistence,
~entityConfig=MockIndexer.entityConfig(User),
~entityConfig=MockIndexer.entityConfig("User"),
~indexerState,
~item,
~ecosystem=MockIndexer.config.ecosystem,
Expand Down Expand Up @@ -678,7 +678,7 @@ describe("LoadLayer", () => {
).toEqual(2)

indexerState->MockIndexer.InMemoryStore.setEntity(
~entityConfig=MockIndexer.entityConfig(User),
~entityConfig=MockIndexer.entityConfig("User"),
{...user2, updatesCountOnUserForTesting: 0},
)

Expand Down Expand Up @@ -714,7 +714,7 @@ describe("LoadLayer", () => {
LoadLayer.loadByFilter(
~loadManager,
~persistence=storageMock->MockIndexer.Storage.toPersistence,
~entityConfig=MockIndexer.entityConfig(User),
~entityConfig=MockIndexer.entityConfig("User"),
~indexerState,
~item,
~ecosystem=MockIndexer.config.ecosystem,
Expand All @@ -737,7 +737,7 @@ describe("LoadLayer", () => {
t.expect(storageMock.loadOrThrowCalls).toEqual(loadEntitiesByFieldSingleDbCall)

indexerState->MockIndexer.InMemoryStore.setEntity(
~entityConfig=MockIndexer.entityConfig(User),
~entityConfig=MockIndexer.entityConfig("User"),
user1,
)

Expand Down
22 changes: 9 additions & 13 deletions scenarios/test_codegen/test/WriteRead_test.res
Original file line number Diff line number Diff line change
Expand Up @@ -96,18 +96,18 @@ describe("Write/read tests", () => {
])
await indexerMock.getBatchWritePromise()

t.expect(await indexerMock.query(EntityWithAllTypes)).toEqual([entityWithAllTypes])
t.expect(await indexerMock.queryHistory(EntityWithAllTypes)).toEqual([
t.expect(await (indexerMock.query("EntityWithAllTypes"): promise<array<Indexer.Entities.EntityWithAllTypes.t>>)).toEqual([entityWithAllTypes])
t.expect(await (indexerMock.queryHistory("EntityWithAllTypes"): promise<array<Change.t<Indexer.Entities.EntityWithAllTypes.t>>>)).toEqual([
Set({
checkpointId: 1n,
entityId: "1"->EntityId.unsafeOfString,
entity: entityWithAllTypes,
}),
])
t.expect(await indexerMock.query(EntityWithAllNonArrayTypes)).toEqual([
t.expect(await (indexerMock.query("EntityWithAllNonArrayTypes"): promise<array<Indexer.Entities.EntityWithAllNonArrayTypes.t>>)).toEqual([
entityWithAllNonArrayTypes,
])
t.expect(await indexerMock.queryHistory(EntityWithAllNonArrayTypes)).toEqual([
t.expect(await (indexerMock.queryHistory("EntityWithAllNonArrayTypes"): promise<array<Change.t<Indexer.Entities.EntityWithAllNonArrayTypes.t>>>)).toEqual([
Set({
checkpointId: 1n,
entityId: "1"->EntityId.unsafeOfString,
Expand All @@ -116,16 +116,14 @@ describe("Write/read tests", () => {
])

t.expect(
await indexerMock.query(EntityWith63LenghtName______________________________________one),
await (indexerMock.query("EntityWith63LenghtName______________________________________one"): promise<array<Indexer.Entities.EntityWith63LenghtName______________________________________one.t>>),
).toEqual([
{
id: "1",
},
])
t.expect(
await indexerMock.queryHistory(
EntityWith63LenghtName______________________________________one,
),
await (indexerMock.queryHistory("EntityWith63LenghtName______________________________________one"): promise<array<Change.t<Indexer.Entities.EntityWith63LenghtName______________________________________one.t>>>),
).toEqual([
Set({
checkpointId: 1n,
Expand All @@ -136,16 +134,14 @@ describe("Write/read tests", () => {
}),
])
t.expect(
await indexerMock.query(EntityWith63LenghtName______________________________________two),
await (indexerMock.query("EntityWith63LenghtName______________________________________two"): promise<array<Indexer.Entities.EntityWith63LenghtName______________________________________two.t>>),
).toEqual([
{
id: "2",
},
])
t.expect(
await indexerMock.queryHistory(
EntityWith63LenghtName______________________________________two,
),
await (indexerMock.queryHistory("EntityWith63LenghtName______________________________________two"): promise<array<Change.t<Indexer.Entities.EntityWith63LenghtName______________________________________two.t>>>),
).toEqual([
Set({
checkpointId: 1n,
Expand Down Expand Up @@ -219,7 +215,7 @@ breaking precicion on big values. https://github.com/enviodev/hyperindex/issues/
])
await indexerMock.getBatchWritePromise()

t.expect(await indexerMock.queryHistory(SimpleEntity)).toEqual([
t.expect(await (indexerMock.queryHistory("SimpleEntity"): promise<array<Change.t<Indexer.Entities.SimpleEntity.t>>>)).toEqual([
Set({checkpointId: 1n, entityId: "untouched"->EntityId.unsafeOfString, entity: {id: "untouched", value: "batch1"}}),
Set({checkpointId: 1n, entityId: "updated"->EntityId.unsafeOfString, entity: {id: "updated", value: "batch1"}}),
Set({checkpointId: 3n, entityId: "updated"->EntityId.unsafeOfString, entity: {id: "updated", value: "batch2"}}),
Expand Down
19 changes: 8 additions & 11 deletions scenarios/test_codegen/test/helpers/MockIndexer.res
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@ let config = Config.load()
let entityConfigByName = (config: Config.t, name): Internal.entityConfig =>
config.userEntitiesByName->Dict.get(name)->Option.getOrThrow

let entityConfig = (name: Indexer.Entities.name<_, _>): Internal.entityConfig =>
config->entityConfigByName(name->(Utils.magic: Indexer.Entities.name<_, _> => string))
let entityConfig = (name: string): Internal.entityConfig => config->entityConfigByName(name)

// The store requires a persistence/config even when the cycle never runs; reuse one.
// Lazy so importing the helper doesn't open a pg client for tests that never use it.
Expand Down Expand Up @@ -384,8 +383,8 @@ module Indexer = {
type rec t = {
getBatchWritePromise: unit => promise<unit>,
getRollbackReadyPromise: unit => promise<unit>,
query: 'entity 'id. Indexer.Entities.name<'entity, 'id> => promise<array<'entity>>,
queryHistory: 'entity 'id. Indexer.Entities.name<'entity, 'id> => promise<array<Change.t<'entity>>>,
query: 'entity. string => promise<array<'entity>>,
queryHistory: 'entity. string => promise<array<Change.t<'entity>>>,
queryRaw: 'entity. Internal.entityConfig => promise<array<'entity>>,
queryCheckpoints: unit => promise<array<InternalTable.Checkpoints.t>>,
queryEffectCache: 'input 'output. (
Expand Down Expand Up @@ -590,19 +589,17 @@ module Indexer = {
resolve()
})
},
query: (type entity id, name: Indexer.Entities.name<entity, id>) => {
let ec =
config->entityConfigByName(name->(Utils.magic: Indexer.Entities.name<entity, id> => string))
query: (type entity, name) => {
let ec = config->entityConfigByName(name)
sql
->Postgres.unsafe(PgStorage.makeLoadAllQuery(~pgSchema, ~tableName=ec.table.tableName))
->Promise.thenResolve(items => {
items->S.parseOrThrow(ec.table->Table.pgRowsSchema)
})
->(Utils.magic: promise<array<unknown>> => promise<array<entity>>)
},
queryHistory: (type entity id, name: Indexer.Entities.name<entity, id>) => {
let ec =
config->entityConfigByName(name->(Utils.magic: Indexer.Entities.name<entity, id> => string))
queryHistory: (type entity, name) => {
let ec = config->entityConfigByName(name)
sql
->Postgres.unsafe(
PgStorage.makeLoadAllQuery(
Expand All @@ -618,7 +615,7 @@ module Indexer = {
S.array(
S.union([
PgStorage.getEntityHistory(~entityConfig=ec).setChangeSchema,
S.object((s): Change.t<'entity> => {
S.object((s): Change.t<Internal.entity> => {
s.tag(EntityHistory.changeFieldName, EntityHistory.RowAction.DELETE)
Delete({
entityId: s.field("id", ec.table->Table.getIdSchema),
Expand Down
Loading