From 8450c374083aaa1d42b1b033695c0baf53265350 Mon Sep 17 00:00:00 2001 From: Francesco Ceccon Date: Mon, 20 Jan 2025 22:19:21 +0100 Subject: [PATCH 1/2] protocol: make endCursor non-nullable --- packages/protocol/src/stream.test.ts | 14 ++++++++++++++ packages/protocol/src/stream.ts | 6 +++--- packages/protocol/src/testing/client.test.ts | 16 ++++++++++++++++ 3 files changed, 33 insertions(+), 3 deletions(-) diff --git a/packages/protocol/src/stream.test.ts b/packages/protocol/src/stream.test.ts index e9920d1..92e9b0e 100644 --- a/packages/protocol/src/stream.test.ts +++ b/packages/protocol/src/stream.test.ts @@ -96,6 +96,10 @@ describe("StreamDataResponse", () => { finality: "accepted", data: [{ value: "hello" }, { value: "world" }], production: "backfill", + endCursor: { + orderKey: 5_000_000n, + uniqueKey: "0x1234567890", + }, }, } as const; @@ -120,6 +124,16 @@ describe("StreamDataResponse", () => { 100, ], ], + "endCursor": { + "orderKey": 5000000n, + "uniqueKey": Uint8Array [ + 18, + 52, + 86, + 120, + 144, + ], + }, "finality": 2, "production": 1, }, diff --git a/packages/protocol/src/stream.ts b/packages/protocol/src/stream.ts index 24d1314..d8fb927 100644 --- a/packages/protocol/src/stream.ts +++ b/packages/protocol/src/stream.ts @@ -126,7 +126,7 @@ export type StdErr = typeof StdErr.Type; export const SystemMessage = Schema.Struct({ _tag: tag("systemMessage"), systemMessage: Schema.Struct({ - output: Schema.optional(Schema.Union(StdOut, StdErr)), + output: Schema.Union(StdOut, StdErr), }), }); @@ -139,7 +139,7 @@ export const Data = ( _tag: tag("data"), data: Schema.Struct({ cursor: Schema.optional(Cursor), - endCursor: Schema.optional(Cursor), + endCursor: Cursor, finality: DataFinality, production: DataProduction, data: Schema.Array(schema), @@ -164,7 +164,7 @@ export type StreamDataResponse = _tag: "data"; data: { cursor?: Cursor | undefined; - endCursor?: Cursor | undefined; + endCursor: Cursor; finality: DataFinality; production: DataProduction; data: readonly (TA | null)[]; diff --git a/packages/protocol/src/testing/client.test.ts b/packages/protocol/src/testing/client.test.ts index b8d9d34..39d1a23 100644 --- a/packages/protocol/src/testing/client.test.ts +++ b/packages/protocol/src/testing/client.test.ts @@ -13,6 +13,10 @@ describe("MockClient", () => { finality: "finalized", data: [{ data: "hello" }], production: "backfill", + endCursor: { + orderKey: 5_000_000n, + uniqueKey: "0x1234567890", + }, }, }, ]; @@ -33,6 +37,10 @@ describe("MockClient", () => { "data": "hello", }, ], + "endCursor": { + "orderKey": 5000000n, + "uniqueKey": "0x1234567890", + }, "finality": "finalized", "production": "backfill", }, @@ -50,6 +58,10 @@ describe("MockClient", () => { finality: "finalized", data: [{ data: "hello" }, null], production: "backfill", + endCursor: { + orderKey: 5_000_000n, + uniqueKey: "0x1234567890", + }, }, }, ]; @@ -71,6 +83,10 @@ describe("MockClient", () => { }, null, ], + "endCursor": { + "orderKey": 5000000n, + "uniqueKey": "0x1234567890", + }, "finality": "finalized", "production": "backfill", }, From 330006308404bc04a54521579af2fe5594bf49c5 Mon Sep 17 00:00:00 2001 From: Francesco Ceccon Date: Mon, 20 Jan 2025 22:19:41 +0100 Subject: [PATCH 2/2] Change files --- ...bara-protocol-214b6685-d554-4d94-9256-a80ee0fd751b.json | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 change/@apibara-protocol-214b6685-d554-4d94-9256-a80ee0fd751b.json diff --git a/change/@apibara-protocol-214b6685-d554-4d94-9256-a80ee0fd751b.json b/change/@apibara-protocol-214b6685-d554-4d94-9256-a80ee0fd751b.json new file mode 100644 index 0000000..172577f --- /dev/null +++ b/change/@apibara-protocol-214b6685-d554-4d94-9256-a80ee0fd751b.json @@ -0,0 +1,7 @@ +{ + "type": "prerelease", + "comment": "protocol: make endCursor non-nullable", + "packageName": "@apibara/protocol", + "email": "francesco@ceccon.me", + "dependentChangeType": "patch" +}