1- import { v , Infer } from "convex/values" ;
1+ import { v , Infer , Validator } from "convex/values" ;
22import { internalMutation , mutation , query , QueryCtx } from "./_generated/server" ;
33import { paginator } from "convex-helpers/server/pagination" ;
44import schema from "./schema.js" ;
@@ -85,16 +85,22 @@ export const update = mutation({
8585 } ,
8686} ) ;
8787
88+ function paginationResultValidator < T > ( itemValidator : Validator < T , "required" , string > ) {
89+ return v . object ( {
90+ continueCursor : v . string ( ) ,
91+ isDone : v . boolean ( ) ,
92+ page : v . array ( itemValidator ) ,
93+ pageStatus : v . optional ( v . union ( v . null ( ) , v . literal ( "SplitRequired" ) , v . literal ( "SplitRecommended" ) ) ) ,
94+ splitCursor : v . optional ( v . union ( v . null ( ) , v . string ( ) ) ) ,
95+ } ) ;
96+ }
97+
8898export const listHistory = query ( {
8999 args : {
90100 maxTs : v . number ( ) ,
91101 paginationOpts : paginationOptsValidator ,
92102 } ,
93- returns : v . object ( {
94- continueCursor : v . string ( ) ,
95- isDone : v . boolean ( ) ,
96- page : v . array ( historyEntryValidator ) ,
97- } ) ,
103+ returns : paginationResultValidator ( historyEntryValidator ) ,
98104 handler : async ( ctx , args ) => {
99105 const results = await paginator ( ctx . db , schema )
100106 . query ( "history" )
@@ -124,11 +130,7 @@ export const listDocumentHistory = query({
124130 maxTs : v . number ( ) ,
125131 paginationOpts : paginationOptsValidator ,
126132 } ,
127- returns : v . object ( {
128- continueCursor : v . string ( ) ,
129- isDone : v . boolean ( ) ,
130- page : v . array ( historyEntryValidator ) ,
131- } ) ,
133+ returns : paginationResultValidator ( historyEntryValidator ) ,
132134 handler : async ( ctx , args ) => {
133135 const results = await paginator ( ctx . db , schema )
134136 . query ( "history" )
@@ -151,13 +153,7 @@ export const listSnapshot = query({
151153 currentTs : v . number ( ) ,
152154 paginationOpts : paginationOptsValidator ,
153155 } ,
154- returns : v . object ( {
155- continueCursor : v . string ( ) ,
156- isDone : v . boolean ( ) ,
157- page : v . array ( historyEntryValidator ) ,
158- splitCursor : v . optional ( v . string ( ) ) ,
159- pageStatus : v . optional ( v . literal ( "SplitRecommended" ) ) ,
160- } ) ,
156+ returns : paginationResultValidator ( historyEntryValidator ) ,
161157 handler : async ( ctx , args ) => {
162158 const pageSize = args . paginationOpts . numItems ;
163159 const page : HistoryEntry [ ] = [ ] ;
@@ -234,12 +230,13 @@ export const listSnapshot = query({
234230 page . push ( extractHistoryEntry ( revision ) ) ;
235231 }
236232 }
237- return {
233+ const output : Infer < ReturnType < typeof paginationResultValidator < HistoryEntry > > > = {
238234 continueCursor : allIdsBeforeCurrentTs [ allIdsBeforeCurrentTs . length - 1 ] ,
239235 isDone : false ,
240236 page,
241237 ...maybeSplit ( allIdsSeen , pageSize ) ,
242238 } ;
239+ return output ;
243240 } ,
244241} ) ;
245242
0 commit comments