@@ -11,10 +11,12 @@ import type { ConnectionId } from '../lib/connection_id';
1111import { Identity } from '../lib/identity' ;
1212import type { ParamsObj , ReducerCtx } from '../lib/reducers' ;
1313import { type UntypedSchemaDef } from '../lib/schema' ;
14+ import type { ScheduleTableForParams } from '../lib/table_schema' ;
1415import { Timestamp } from '../lib/timestamp' ;
1516import {
1617 type Infer ,
1718 type InferTypeOfRow ,
19+ type t ,
1820 type TypeBuilder ,
1921} from '../lib/type_builders' ;
2022import { bsatnBaseSize } from '../lib/util' ;
@@ -42,7 +44,7 @@ export function makeProcedureExport<
4244 Ret extends TypeBuilder < any , any > ,
4345> (
4446 ctx : SchemaInner ,
45- opts : ProcedureOpts | undefined ,
47+ opts : ProcedureOptsWithOptionalName < Params , Ret > | undefined ,
4648 params : Params ,
4749 ret : Ret ,
4850 fn : ProcedureFn < S , Params , Ret >
@@ -58,6 +60,12 @@ export function makeProcedureExport<
5860 procedureExport as ProcedureExport < any , any , any > ,
5961 name ?? exportName
6062 ) ;
63+ if ( opts ?. onSchedule !== undefined ) {
64+ ctx . pendingSchedules . push ( {
65+ table : opts . onSchedule ,
66+ functionName : name ?? exportName ,
67+ } ) ;
68+ }
6169 } ;
6270
6371 return procedureExport ;
@@ -69,10 +77,21 @@ export type ProcedureFn<
6977 Ret extends TypeBuilder < any , any > ,
7078> = ( ctx : ProcedureCtx < S > , args : InferTypeOfRow < Params > ) => Infer < Ret > ;
7179
72- export interface ProcedureOpts {
80+ export interface ProcedureOpts <
81+ Params extends ParamsObj = ParamsObj ,
82+ Ret extends TypeBuilder < any , any > = TypeBuilder < any , any > ,
83+ > {
7384 name : string ;
85+ onSchedule ?: Ret extends ReturnType < typeof t . unit >
86+ ? ScheduleTableForParams < Params >
87+ : never ;
7488}
7589
90+ export type ProcedureOptsWithOptionalName <
91+ Params extends ParamsObj = ParamsObj ,
92+ Ret extends TypeBuilder < any , any > = TypeBuilder < any , any > ,
93+ > = Omit < ProcedureOpts < Params , Ret > , 'name' > & { name ?: string } ;
94+
7695export interface ProcedureCtx < S extends UntypedSchemaDef > {
7796 readonly sender : Identity ;
7897 readonly databaseIdentity : Identity ;
@@ -107,7 +126,7 @@ function registerProcedure<
107126 params : Params ,
108127 ret : Ret ,
109128 fn : ProcedureFn < S , Params , Ret > ,
110- opts ?: ProcedureOpts
129+ opts ?: ProcedureOptsWithOptionalName < any , any >
111130) {
112131 ctx . defineFunction ( exportName ) ;
113132 const paramsType : ProductType = {
0 commit comments