Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make endCursor non-nullable #139

Merged
merged 2 commits into from
Jan 20, 2025
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "prerelease",
"comment": "protocol: make endCursor non-nullable",
"packageName": "@apibara/protocol",
"email": "[email protected]",
"dependentChangeType": "patch"
}
14 changes: 14 additions & 0 deletions packages/protocol/src/stream.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,10 @@ describe("StreamDataResponse", () => {
finality: "accepted",
data: [{ value: "hello" }, { value: "world" }],
production: "backfill",
endCursor: {
orderKey: 5_000_000n,
uniqueKey: "0x1234567890",
},
},
} as const;

Expand All @@ -120,6 +124,16 @@ describe("StreamDataResponse", () => {
100,
],
],
"endCursor": {
"orderKey": 5000000n,
"uniqueKey": Uint8Array [
18,
52,
86,
120,
144,
],
},
"finality": 2,
"production": 1,
},
Expand Down
6 changes: 3 additions & 3 deletions packages/protocol/src/stream.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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),
}),
});

Expand All @@ -139,7 +139,7 @@ export const Data = <TA, TR>(
_tag: tag("data"),
data: Schema.Struct({
cursor: Schema.optional(Cursor),
endCursor: Schema.optional(Cursor),
endCursor: Cursor,
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Fix inconsistency in type definition for endCursor.

While making endCursor non-optional in the schema is correct, there's an inconsistency in the exported type definition that still shows it as optional:

export type StreamDataResponse<TA> = ... {
  data: {
    endCursor?: Cursor | undefined;  // Still optional
  }
}

Please update the type definition to match the schema:

export type StreamDataResponse<TA> =
  | ResponseWithoutData
  | {
      _tag: "data";
      data: {
        cursor?: Cursor | undefined;
-       endCursor?: Cursor | undefined;
+       endCursor: Cursor;
        finality: DataFinality;
        production: DataProduction;
        data: readonly (TA | null)[];
      };
    };

finality: DataFinality,
production: DataProduction,
data: Schema.Array(schema),
Expand All @@ -164,7 +164,7 @@ export type StreamDataResponse<TA> =
_tag: "data";
data: {
cursor?: Cursor | undefined;
endCursor?: Cursor | undefined;
endCursor: Cursor;
finality: DataFinality;
production: DataProduction;
data: readonly (TA | null)[];
Expand Down
16 changes: 16 additions & 0 deletions packages/protocol/src/testing/client.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ describe("MockClient", () => {
finality: "finalized",
data: [{ data: "hello" }],
production: "backfill",
endCursor: {
orderKey: 5_000_000n,
uniqueKey: "0x1234567890",
},
},
},
];
Expand All @@ -33,6 +37,10 @@ describe("MockClient", () => {
"data": "hello",
},
],
"endCursor": {
"orderKey": 5000000n,
"uniqueKey": "0x1234567890",
},
"finality": "finalized",
"production": "backfill",
},
Expand All @@ -50,6 +58,10 @@ describe("MockClient", () => {
finality: "finalized",
data: [{ data: "hello" }, null],
production: "backfill",
endCursor: {
orderKey: 5_000_000n,
uniqueKey: "0x1234567890",
},
},
},
];
Expand All @@ -71,6 +83,10 @@ describe("MockClient", () => {
},
null,
],
"endCursor": {
"orderKey": 5000000n,
"uniqueKey": "0x1234567890",
},
"finality": "finalized",
"production": "backfill",
},
Expand Down
Loading