@confect/server 4.0.0 → 6.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (42) hide show
  1. package/CHANGELOG.md +27 -0
  2. package/dist/ActionRunner.d.ts +5 -3
  3. package/dist/ActionRunner.d.ts.map +1 -1
  4. package/dist/ActionRunner.js +2 -10
  5. package/dist/ActionRunner.js.map +1 -1
  6. package/dist/CronJob.d.ts +1 -2
  7. package/dist/CronJob.d.ts.map +1 -1
  8. package/dist/CronJob.js.map +1 -1
  9. package/dist/CronJobs.d.ts +6 -14
  10. package/dist/CronJobs.d.ts.map +1 -1
  11. package/dist/CronJobs.js +5 -6
  12. package/dist/CronJobs.js.map +1 -1
  13. package/dist/DatabaseReader.d.ts +1 -1
  14. package/dist/DatabaseWriter.d.ts +4 -4
  15. package/dist/MutationRunner.d.ts +5 -3
  16. package/dist/MutationRunner.d.ts.map +1 -1
  17. package/dist/MutationRunner.js +2 -10
  18. package/dist/MutationRunner.js.map +1 -1
  19. package/dist/QueryInitializer.d.ts +1 -1
  20. package/dist/QueryInitializer.d.ts.map +1 -1
  21. package/dist/QueryRunner.d.ts +5 -3
  22. package/dist/QueryRunner.d.ts.map +1 -1
  23. package/dist/QueryRunner.js +2 -10
  24. package/dist/QueryRunner.js.map +1 -1
  25. package/dist/RegisteredConvexFunction.d.ts +8 -8
  26. package/dist/RegisteredConvexFunction.d.ts.map +1 -1
  27. package/dist/RegisteredConvexFunction.js +24 -2
  28. package/dist/RegisteredConvexFunction.js.map +1 -1
  29. package/dist/RegisteredFunction.d.ts +5 -5
  30. package/dist/RegisteredFunction.d.ts.map +1 -1
  31. package/dist/Scheduler.d.ts +8 -7
  32. package/dist/Scheduler.d.ts.map +1 -1
  33. package/dist/Scheduler.js +9 -4
  34. package/dist/Scheduler.js.map +1 -1
  35. package/package.json +4 -4
  36. package/src/ActionRunner.ts +9 -28
  37. package/src/CronJob.ts +1 -4
  38. package/src/CronJobs.ts +5 -19
  39. package/src/MutationRunner.ts +9 -28
  40. package/src/QueryRunner.ts +9 -28
  41. package/src/RegisteredConvexFunction.ts +64 -24
  42. package/src/Scheduler.ts +20 -13
@@ -1 +1 @@
1
- {"version":3,"file":"RegisteredConvexFunction.js","names":["SchemaToValidator.compileArgsSchema","SchemaToValidator.compileReturnsSchema","DatabaseReader.layer","Auth.layer","StorageReader","QueryRunner.layer","QueryCtx.QueryCtx","ConvexConfigProvider.make","DatabaseWriter.layer","Scheduler.layer","StorageWriter","MutationRunner.layer","MutationCtx.MutationCtx","RegisteredFunction.actionFunctionBase","RegisteredFunction.actionLayer"],"sources":["../src/RegisteredConvexFunction.ts"],"sourcesContent":["import type * as FunctionSpec from \"@confect/core/FunctionSpec\";\nimport {\n actionGeneric,\n type DefaultFunctionArgs,\n type GenericMutationCtx,\n type GenericQueryCtx,\n internalActionGeneric,\n internalMutationGeneric,\n internalQueryGeneric,\n mutationGeneric,\n queryGeneric,\n} from \"convex/server\";\nimport { Effect, Layer, Match, pipe, Schema } from \"effect\";\nimport type * as Api from \"./Api\";\nimport * as Auth from \"./Auth\";\nimport * as ConvexConfigProvider from \"./ConvexConfigProvider\";\nimport * as DatabaseReader from \"./DatabaseReader\";\nimport type * as DatabaseSchema from \"./DatabaseSchema\";\nimport * as DatabaseWriter from \"./DatabaseWriter\";\nimport type * as DataModel from \"./DataModel\";\nimport type * as Handler from \"./Handler\";\nimport * as MutationCtx from \"./MutationCtx\";\nimport * as MutationRunner from \"./MutationRunner\";\nimport * as QueryCtx from \"./QueryCtx\";\nimport * as QueryRunner from \"./QueryRunner\";\nimport * as RegisteredFunction from \"./RegisteredFunction\";\nimport type * as RegistryItem from \"./RegistryItem\";\nimport * as Scheduler from \"./Scheduler\";\nimport * as SchemaToValidator from \"./SchemaToValidator\";\nimport { StorageReader } from \"./StorageReader\";\nimport { StorageWriter } from \"./StorageWriter\";\n\nexport const make = <Api_ extends Api.AnyWithPropsWithRuntime<\"Convex\">>(\n api: Api_,\n { functionSpec, handler }: RegistryItem.AnyWithProps,\n): RegisteredFunction.Any =>\n Match.value(functionSpec.functionProvenance).pipe(\n Match.tag(\"Convex\", () => handler as RegisteredFunction.Any),\n Match.tag(\"Confect\", () => {\n const { functionVisibility, functionProvenance } =\n functionSpec as FunctionSpec.AnyConfect;\n\n return Match.value(functionSpec.runtimeAndFunctionType.functionType).pipe(\n Match.when(\"query\", () => {\n const genericFunction = Match.value(functionVisibility).pipe(\n Match.when(\"public\", () => queryGeneric),\n Match.when(\"internal\", () => internalQueryGeneric),\n Match.exhaustive,\n );\n\n return genericFunction(\n queryFunction(api.databaseSchema, {\n args: functionProvenance.args,\n returns: functionProvenance.returns,\n handler: handler as Handler.AnyConfectProvenance,\n }),\n );\n }),\n Match.when(\"mutation\", () => {\n const genericFunction = Match.value(functionVisibility).pipe(\n Match.when(\"public\", () => mutationGeneric),\n Match.when(\"internal\", () => internalMutationGeneric),\n Match.exhaustive,\n );\n\n return genericFunction(\n mutationFunction(api.databaseSchema, {\n args: functionProvenance.args,\n returns: functionProvenance.returns,\n handler: handler as Handler.AnyConfectProvenance,\n }),\n );\n }),\n Match.when(\"action\", () => {\n const genericFunction = Match.value(functionVisibility).pipe(\n Match.when(\"public\", () => actionGeneric),\n Match.when(\"internal\", () => internalActionGeneric),\n Match.exhaustive,\n );\n\n return genericFunction(\n convexActionFunction(api.databaseSchema, {\n args: functionProvenance.args,\n returns: functionProvenance.returns,\n handler: handler as Handler.AnyConfectProvenance,\n }),\n );\n }),\n Match.exhaustive,\n );\n }),\n Match.exhaustive,\n );\n\nconst queryFunction = <\n DatabaseSchema_ extends DatabaseSchema.AnyWithProps,\n Args,\n ConvexArgs extends DefaultFunctionArgs,\n Returns,\n ConvexReturns,\n E,\n>(\n databaseSchema: DatabaseSchema_,\n {\n args,\n returns,\n handler,\n }: {\n args: Schema.Schema<Args, ConvexArgs>;\n returns: Schema.Schema<Returns, ConvexReturns>;\n handler: (\n a: Args,\n ) => Effect.Effect<\n Returns,\n E,\n | DatabaseReader.DatabaseReader<DatabaseSchema_>\n | Auth.Auth\n | StorageReader\n | QueryRunner.QueryRunner\n | QueryCtx.QueryCtx<\n DataModel.ToConvex<DataModel.FromSchema<DatabaseSchema_>>\n >\n >;\n },\n) => ({\n args: SchemaToValidator.compileArgsSchema(args),\n returns: SchemaToValidator.compileReturnsSchema(returns),\n handler: (\n ctx: GenericQueryCtx<\n DataModel.ToConvex<DataModel.FromSchema<DatabaseSchema_>>\n >,\n actualArgs: ConvexArgs,\n ): Promise<ConvexReturns> =>\n pipe(\n actualArgs,\n Schema.decode(args),\n Effect.orDie,\n Effect.andThen((decodedArgs) =>\n pipe(\n handler(decodedArgs),\n Effect.provide(\n Layer.mergeAll(\n DatabaseReader.layer(databaseSchema, ctx.db),\n Auth.layer(ctx.auth),\n StorageReader.layer(ctx.storage),\n QueryRunner.layer(ctx.runQuery),\n Layer.succeed(\n QueryCtx.QueryCtx<\n DataModel.ToConvex<DataModel.FromSchema<DatabaseSchema_>>\n >(),\n ctx,\n ),\n Layer.setConfigProvider(ConvexConfigProvider.make()),\n ),\n ),\n ),\n ),\n Effect.andThen((convexReturns) =>\n Schema.encodeUnknown(returns)(convexReturns),\n ),\n Effect.runPromise,\n ),\n});\n\nexport const mutationLayer = <Schema extends DatabaseSchema.AnyWithProps>(\n schema: Schema,\n ctx: GenericMutationCtx<DataModel.ToConvex<DataModel.FromSchema<Schema>>>,\n) =>\n Layer.mergeAll(\n DatabaseReader.layer(schema, ctx.db),\n DatabaseWriter.layer(schema, ctx.db),\n Auth.layer(ctx.auth),\n Scheduler.layer(ctx.scheduler),\n StorageReader.layer(ctx.storage),\n StorageWriter.layer(ctx.storage),\n QueryRunner.layer(ctx.runQuery),\n MutationRunner.layer(ctx.runMutation),\n Layer.succeed(\n MutationCtx.MutationCtx<\n DataModel.ToConvex<DataModel.FromSchema<Schema>>\n >(),\n ctx,\n ),\n Layer.setConfigProvider(ConvexConfigProvider.make()),\n );\n\nexport type MutationServices<Schema extends DatabaseSchema.AnyWithProps> =\n | DatabaseReader.DatabaseReader<Schema>\n | DatabaseWriter.DatabaseWriter<Schema>\n | Auth.Auth\n | Scheduler.Scheduler\n | StorageReader\n | StorageWriter\n | QueryRunner.QueryRunner\n | MutationRunner.MutationRunner\n | MutationCtx.MutationCtx<DataModel.ToConvex<DataModel.FromSchema<Schema>>>;\n\nconst mutationFunction = <\n Schema extends DatabaseSchema.AnyWithProps,\n Args,\n ConvexArgs extends DefaultFunctionArgs,\n Returns,\n ConvexReturns,\n E,\n>(\n schema: Schema,\n {\n args,\n returns,\n handler,\n }: {\n args: Schema.Schema<Args, ConvexArgs>;\n returns: Schema.Schema<Returns, ConvexReturns>;\n handler: (a: Args) => Effect.Effect<Returns, E, MutationServices<Schema>>;\n },\n) => ({\n args: SchemaToValidator.compileArgsSchema(args),\n returns: SchemaToValidator.compileReturnsSchema(returns),\n handler: (\n ctx: GenericMutationCtx<DataModel.ToConvex<DataModel.FromSchema<Schema>>>,\n actualArgs: ConvexArgs,\n ): Promise<ConvexReturns> =>\n pipe(\n actualArgs,\n Schema.decode(args),\n Effect.orDie,\n Effect.andThen((decodedArgs) =>\n handler(decodedArgs).pipe(Effect.provide(mutationLayer(schema, ctx))),\n ),\n Effect.andThen((convexReturns) =>\n Schema.encodeUnknown(returns)(convexReturns),\n ),\n Effect.runPromise,\n ),\n});\n\nconst convexActionFunction = <\n DatabaseSchema_ extends DatabaseSchema.AnyWithProps,\n Args,\n ConvexArgs extends DefaultFunctionArgs,\n Returns,\n ConvexReturns,\n E,\n>(\n schema: DatabaseSchema_,\n {\n args,\n returns,\n handler,\n }: {\n args: Schema.Schema<Args, ConvexArgs>;\n returns: Schema.Schema<Returns, ConvexReturns>;\n handler: (\n a: Args,\n ) => Effect.Effect<\n Returns,\n E,\n RegisteredFunction.ActionServices<DatabaseSchema_>\n >;\n },\n) =>\n RegisteredFunction.actionFunctionBase({\n args,\n returns,\n handler,\n createLayer: (ctx) =>\n Layer.mergeAll(\n RegisteredFunction.actionLayer(schema, ctx),\n Layer.setConfigProvider(ConvexConfigProvider.make()),\n ),\n });\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAgCA,MAAa,QACX,KACA,EAAE,cAAc,cAEhB,MAAM,MAAM,aAAa,mBAAmB,CAAC,KAC3C,MAAM,IAAI,gBAAgB,QAAkC,EAC5D,MAAM,IAAI,iBAAiB;CACzB,MAAM,EAAE,oBAAoB,uBAC1B;AAEF,QAAO,MAAM,MAAM,aAAa,uBAAuB,aAAa,CAAC,KACnE,MAAM,KAAK,eAAe;AAOxB,SANwB,MAAM,MAAM,mBAAmB,CAAC,KACtD,MAAM,KAAK,gBAAgB,aAAa,EACxC,MAAM,KAAK,kBAAkB,qBAAqB,EAClD,MAAM,WACP,CAGC,cAAc,IAAI,gBAAgB;GAChC,MAAM,mBAAmB;GACzB,SAAS,mBAAmB;GACnB;GACV,CAAC,CACH;GACD,EACF,MAAM,KAAK,kBAAkB;AAO3B,SANwB,MAAM,MAAM,mBAAmB,CAAC,KACtD,MAAM,KAAK,gBAAgB,gBAAgB,EAC3C,MAAM,KAAK,kBAAkB,wBAAwB,EACrD,MAAM,WACP,CAGC,iBAAiB,IAAI,gBAAgB;GACnC,MAAM,mBAAmB;GACzB,SAAS,mBAAmB;GACnB;GACV,CAAC,CACH;GACD,EACF,MAAM,KAAK,gBAAgB;AAOzB,SANwB,MAAM,MAAM,mBAAmB,CAAC,KACtD,MAAM,KAAK,gBAAgB,cAAc,EACzC,MAAM,KAAK,kBAAkB,sBAAsB,EACnD,MAAM,WACP,CAGC,qBAAqB,IAAI,gBAAgB;GACvC,MAAM,mBAAmB;GACzB,SAAS,mBAAmB;GACnB;GACV,CAAC,CACH;GACD,EACF,MAAM,WACP;EACD,EACF,MAAM,WACP;AAEH,MAAM,iBAQJ,gBACA,EACE,MACA,SACA,eAkBE;CACJ,MAAMA,kBAAoC,KAAK;CAC/C,SAASC,qBAAuC,QAAQ;CACxD,UACE,KAGA,eAEA,KAC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B,CAAC,CACrD;CACJ,CAAC"}
1
+ {"version":3,"file":"RegisteredConvexFunction.js","names":["SchemaToValidator.compileArgsSchema","SchemaToValidator.compileReturnsSchema","DatabaseReader.layer","Auth.layer","StorageReader","QueryRunner.layer","QueryCtx.QueryCtx","ConvexConfigProvider.make","DatabaseWriter.layer","Scheduler.layer","StorageWriter","MutationRunner.layer","MutationCtx.MutationCtx","RegisteredFunction.actionFunctionBase","RegisteredFunction.actionLayer"],"sources":["../src/RegisteredConvexFunction.ts"],"sourcesContent":["import type * as FunctionSpec from \"@confect/core/FunctionSpec\";\nimport {\n actionGeneric,\n type DefaultFunctionArgs,\n type GenericMutationCtx,\n type GenericQueryCtx,\n internalActionGeneric,\n internalMutationGeneric,\n internalQueryGeneric,\n mutationGeneric,\n queryGeneric,\n} from \"convex/server\";\nimport { Clock, Effect, Layer, Match, pipe, Schema } from \"effect\";\nimport type * as Api from \"./Api\";\nimport * as Auth from \"./Auth\";\nimport * as ConvexConfigProvider from \"./ConvexConfigProvider\";\nimport * as DatabaseReader from \"./DatabaseReader\";\nimport type * as DatabaseSchema from \"./DatabaseSchema\";\nimport * as DatabaseWriter from \"./DatabaseWriter\";\nimport type * as DataModel from \"./DataModel\";\nimport type * as Handler from \"./Handler\";\nimport * as MutationCtx from \"./MutationCtx\";\nimport * as MutationRunner from \"./MutationRunner\";\nimport * as QueryCtx from \"./QueryCtx\";\nimport * as QueryRunner from \"./QueryRunner\";\nimport * as RegisteredFunction from \"./RegisteredFunction\";\nimport type * as RegistryItem from \"./RegistryItem\";\nimport * as Scheduler from \"./Scheduler\";\nimport * as SchemaToValidator from \"./SchemaToValidator\";\nimport { StorageReader } from \"./StorageReader\";\nimport { StorageWriter } from \"./StorageWriter\";\n\nexport const make = <Api_ extends Api.AnyWithPropsWithRuntime<\"Convex\">>(\n api: Api_,\n { functionSpec, handler }: RegistryItem.AnyWithProps,\n): RegisteredFunction.Any =>\n Match.value(functionSpec.functionProvenance).pipe(\n Match.tag(\"Convex\", () => handler as RegisteredFunction.Any),\n Match.tag(\"Confect\", () => {\n const { functionVisibility, functionProvenance } =\n functionSpec as FunctionSpec.AnyConfect;\n\n return Match.value(functionSpec.runtimeAndFunctionType.functionType).pipe(\n Match.when(\"query\", () => {\n const genericFunction = Match.value(functionVisibility).pipe(\n Match.when(\"public\", () => queryGeneric),\n Match.when(\"internal\", () => internalQueryGeneric),\n Match.exhaustive,\n );\n\n return genericFunction(\n queryFunction(api.databaseSchema, {\n args: functionProvenance.args,\n returns: functionProvenance.returns,\n handler: handler as Handler.AnyConfectProvenance,\n }),\n );\n }),\n Match.when(\"mutation\", () => {\n const genericFunction = Match.value(functionVisibility).pipe(\n Match.when(\"public\", () => mutationGeneric),\n Match.when(\"internal\", () => internalMutationGeneric),\n Match.exhaustive,\n );\n\n return genericFunction(\n mutationFunction(api.databaseSchema, {\n args: functionProvenance.args,\n returns: functionProvenance.returns,\n handler: handler as Handler.AnyConfectProvenance,\n }),\n );\n }),\n Match.when(\"action\", () => {\n const genericFunction = Match.value(functionVisibility).pipe(\n Match.when(\"public\", () => actionGeneric),\n Match.when(\"internal\", () => internalActionGeneric),\n Match.exhaustive,\n );\n\n return genericFunction(\n convexActionFunction(api.databaseSchema, {\n args: functionProvenance.args,\n returns: functionProvenance.returns,\n handler: handler as Handler.AnyConfectProvenance,\n }),\n );\n }),\n Match.exhaustive,\n );\n }),\n Match.exhaustive,\n );\n\n// Convex's query cache is invalidated by any Date.now() call during handler\n// execution. Effect's unsafeFork calls Date.now() when constructing a\n// FiberId.Runtime, which trips the cache for every confect-wrapped query. We\n// stub Date.now to 0 for the span of the handler; queries are forbidden from\n// relying on real time for correctness anyway.\n//\n// Users who explicitly want the real timestamp can still reach it via Effect's\n// Clock service (Clock.currentTimeMillis / Clock.currentTimeNanos). We provide\n// a Clock layer whose methods close over the *original* Date.now, so opting in\n// to Clock is an opt-in to worse caching — but caching is not broken by default.\nconst unpatchedClock = (realDateNow: () => number): Clock.Clock => {\n const bigint1e6 = BigInt(1_000_000);\n const unsafeCurrentTimeMillis = () => realDateNow();\n const unsafeCurrentTimeNanos = () => BigInt(realDateNow()) * bigint1e6;\n const defaultClock = Clock.make();\n return {\n ...defaultClock,\n unsafeCurrentTimeMillis,\n unsafeCurrentTimeNanos,\n currentTimeMillis: Effect.sync(unsafeCurrentTimeMillis),\n currentTimeNanos: Effect.sync(unsafeCurrentTimeNanos),\n };\n};\n\nconst withStubbedDateNow = async <T>(\n queryHandler: (clock: Clock.Clock) => Promise<T>,\n): Promise<T> => {\n const realDateNow = Date.now;\n const clock = unpatchedClock(realDateNow);\n Date.now = () => 0;\n try {\n return await queryHandler(clock);\n } finally {\n Date.now = realDateNow;\n }\n};\n\nconst queryFunction = <\n DatabaseSchema_ extends DatabaseSchema.AnyWithProps,\n Args,\n ConvexArgs extends DefaultFunctionArgs,\n Returns,\n ConvexReturns,\n E,\n>(\n databaseSchema: DatabaseSchema_,\n {\n args,\n returns,\n handler,\n }: {\n args: Schema.Schema<Args, ConvexArgs>;\n returns: Schema.Schema<Returns, ConvexReturns>;\n handler: (\n a: Args,\n ) => Effect.Effect<\n Returns,\n E,\n | DatabaseReader.DatabaseReader<DatabaseSchema_>\n | Auth.Auth\n | StorageReader\n | QueryRunner.QueryRunner\n | QueryCtx.QueryCtx<\n DataModel.ToConvex<DataModel.FromSchema<DatabaseSchema_>>\n >\n >;\n },\n) => ({\n args: SchemaToValidator.compileArgsSchema(args),\n returns: SchemaToValidator.compileReturnsSchema(returns),\n handler: (\n ctx: GenericQueryCtx<\n DataModel.ToConvex<DataModel.FromSchema<DatabaseSchema_>>\n >,\n actualArgs: ConvexArgs,\n ): Promise<ConvexReturns> =>\n withStubbedDateNow((clock) =>\n pipe(\n actualArgs,\n Schema.decode(args),\n Effect.orDie,\n Effect.andThen((decodedArgs) =>\n pipe(\n handler(decodedArgs),\n Effect.provide(\n Layer.mergeAll(\n DatabaseReader.layer(databaseSchema, ctx.db),\n Auth.layer(ctx.auth),\n StorageReader.layer(ctx.storage),\n QueryRunner.layer(ctx.runQuery),\n Layer.succeed(\n QueryCtx.QueryCtx<\n DataModel.ToConvex<DataModel.FromSchema<DatabaseSchema_>>\n >(),\n ctx,\n ),\n Layer.setConfigProvider(ConvexConfigProvider.make()),\n ),\n ),\n ),\n ),\n Effect.andThen((convexReturns) =>\n Schema.encodeUnknown(returns)(convexReturns),\n ),\n Effect.withClock(clock),\n Effect.runPromise,\n ),\n ),\n});\n\nexport const mutationLayer = <Schema extends DatabaseSchema.AnyWithProps>(\n schema: Schema,\n ctx: GenericMutationCtx<DataModel.ToConvex<DataModel.FromSchema<Schema>>>,\n) =>\n Layer.mergeAll(\n DatabaseReader.layer(schema, ctx.db),\n DatabaseWriter.layer(schema, ctx.db),\n Auth.layer(ctx.auth),\n Scheduler.layer(ctx.scheduler),\n StorageReader.layer(ctx.storage),\n StorageWriter.layer(ctx.storage),\n QueryRunner.layer(ctx.runQuery),\n MutationRunner.layer(ctx.runMutation),\n Layer.succeed(\n MutationCtx.MutationCtx<\n DataModel.ToConvex<DataModel.FromSchema<Schema>>\n >(),\n ctx,\n ),\n Layer.setConfigProvider(ConvexConfigProvider.make()),\n );\n\nexport type MutationServices<Schema extends DatabaseSchema.AnyWithProps> =\n | DatabaseReader.DatabaseReader<Schema>\n | DatabaseWriter.DatabaseWriter<Schema>\n | Auth.Auth\n | Scheduler.Scheduler\n | StorageReader\n | StorageWriter\n | QueryRunner.QueryRunner\n | MutationRunner.MutationRunner\n | MutationCtx.MutationCtx<DataModel.ToConvex<DataModel.FromSchema<Schema>>>;\n\nconst mutationFunction = <\n Schema extends DatabaseSchema.AnyWithProps,\n Args,\n ConvexArgs extends DefaultFunctionArgs,\n Returns,\n ConvexReturns,\n E,\n>(\n schema: Schema,\n {\n args,\n returns,\n handler,\n }: {\n args: Schema.Schema<Args, ConvexArgs>;\n returns: Schema.Schema<Returns, ConvexReturns>;\n handler: (a: Args) => Effect.Effect<Returns, E, MutationServices<Schema>>;\n },\n) => ({\n args: SchemaToValidator.compileArgsSchema(args),\n returns: SchemaToValidator.compileReturnsSchema(returns),\n handler: (\n ctx: GenericMutationCtx<DataModel.ToConvex<DataModel.FromSchema<Schema>>>,\n actualArgs: ConvexArgs,\n ): Promise<ConvexReturns> =>\n pipe(\n actualArgs,\n Schema.decode(args),\n Effect.orDie,\n Effect.andThen((decodedArgs) =>\n handler(decodedArgs).pipe(Effect.provide(mutationLayer(schema, ctx))),\n ),\n Effect.andThen((convexReturns) =>\n Schema.encodeUnknown(returns)(convexReturns),\n ),\n Effect.runPromise,\n ),\n});\n\nconst convexActionFunction = <\n DatabaseSchema_ extends DatabaseSchema.AnyWithProps,\n Args,\n ConvexArgs extends DefaultFunctionArgs,\n Returns,\n ConvexReturns,\n E,\n>(\n schema: DatabaseSchema_,\n {\n args,\n returns,\n handler,\n }: {\n args: Schema.Schema<Args, ConvexArgs>;\n returns: Schema.Schema<Returns, ConvexReturns>;\n handler: (\n a: Args,\n ) => Effect.Effect<\n Returns,\n E,\n RegisteredFunction.ActionServices<DatabaseSchema_>\n >;\n },\n) =>\n RegisteredFunction.actionFunctionBase({\n args,\n returns,\n handler,\n createLayer: (ctx) =>\n Layer.mergeAll(\n RegisteredFunction.actionLayer(schema, ctx),\n Layer.setConfigProvider(ConvexConfigProvider.make()),\n ),\n });\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAgCA,MAAa,QACX,KACA,EAAE,cAAc,cAEhB,MAAM,MAAM,aAAa,mBAAmB,CAAC,KAC3C,MAAM,IAAI,gBAAgB,QAAkC,EAC5D,MAAM,IAAI,iBAAiB;CACzB,MAAM,EAAE,oBAAoB,uBAC1B;AAEF,QAAO,MAAM,MAAM,aAAa,uBAAuB,aAAa,CAAC,KACnE,MAAM,KAAK,eAAe;AAOxB,SANwB,MAAM,MAAM,mBAAmB,CAAC,KACtD,MAAM,KAAK,gBAAgB,aAAa,EACxC,MAAM,KAAK,kBAAkB,qBAAqB,EAClD,MAAM,WACP,CAGC,cAAc,IAAI,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}
@@ -16,8 +16,8 @@ import * as convex_server0 from "convex/server";
16
16
  import { DefaultFunctionArgs, FunctionVisibility, GenericActionCtx, RegisteredAction, RegisteredMutation, RegisteredQuery } from "convex/server";
17
17
  import { FunctionSpec, RuntimeAndFunctionType } from "@confect/core";
18
18
  import * as convex_values0 from "convex/values";
19
- import * as FunctionProvenance from "@confect/core/FunctionProvenance";
20
19
  import * as effect_ParseResult0 from "effect/ParseResult";
20
+ import * as FunctionProvenance from "@confect/core/FunctionProvenance";
21
21
  import * as effect_Duration0 from "effect/Duration";
22
22
  import * as effect_DateTime0 from "effect/DateTime";
23
23
 
@@ -51,10 +51,10 @@ declare const actionFunctionBase: <Schema extends AnyWithProps, Args, ConvexArgs
51
51
  handler: (ctx: GenericActionCtx<ToConvex<FromSchema<Schema>>>, actualArgs: ConvexArgs) => Promise<ConvexReturns>;
52
52
  };
53
53
  type ActionServices<DatabaseSchema_ extends AnyWithProps> = Scheduler$1 | Auth$1 | StorageReader$1 | StorageWriter$1 | StorageActionWriter$1 | QueryRunner | MutationRunner | ActionRunner | VectorSearch<FromSchema<DatabaseSchema_>> | ActionCtx<ToConvex<FromSchema<DatabaseSchema_>>>;
54
- declare const actionLayer: <DatabaseSchema_ extends AnyWithProps>(databaseSchema: DatabaseSchema_, ctx: GenericActionCtx<ToConvex<FromSchema<DatabaseSchema_>>>) => Layer.Layer<Auth$1 | (<Mutation extends _confect_core_Ref0.AnyMutation>(mutation: Mutation, args: _confect_core_Ref0.Args<Mutation>) => Effect.Effect<_confect_core_Ref0.Returns<Mutation>, effect_ParseResult0.ParseError>) | StorageActionWriter$1 | {
55
- runAfter: <FuncRef extends convex_server0.SchedulableFunctionReference>(delay: effect_Duration0.Duration, functionReference: FuncRef, ...args: convex_server0.OptionalRestArgs<FuncRef>) => Effect.Effect<convex_values0.GenericId<"_scheduled_functions">, never, never>;
56
- runAt: <FuncRef extends convex_server0.SchedulableFunctionReference>(dateTime: effect_DateTime0.DateTime, functionReference: FuncRef, ...args: convex_server0.OptionalRestArgs<FuncRef>) => Effect.Effect<convex_values0.GenericId<"_scheduled_functions">, never, never>;
57
- } | StorageReader$1 | StorageWriter$1 | (<Query extends _confect_core_Ref0.AnyQuery>(query: Query, args: _confect_core_Ref0.Args<Query>) => Effect.Effect<_confect_core_Ref0.Returns<Query>, effect_ParseResult0.ParseError>) | GenericActionCtx<ToConvex<FromSchema<DatabaseSchema_>>> | (<Action extends _confect_core_Ref0.AnyAction>(action: Action, args: _confect_core_Ref0.Args<Action>) => Effect.Effect<_confect_core_Ref0.Returns<Action>, effect_ParseResult0.ParseError>) | (<TableName extends TableNames<FromSchema<DatabaseSchema_>>, IndexName extends keyof convex_server0.VectorIndexes<convex_server0.NamedTableInfo<ToConvex<FromSchema<DatabaseSchema_>>, TableName>>>(tableName: TableName, indexName: IndexName, query: {
54
+ declare const actionLayer: <DatabaseSchema_ extends AnyWithProps>(databaseSchema: DatabaseSchema_, ctx: GenericActionCtx<ToConvex<FromSchema<DatabaseSchema_>>>) => Layer.Layer<(<Action extends _confect_core_Ref0.AnyAction>(action: Action, ...args: _confect_core_Ref0.OptionalArgs<Action>) => Effect.Effect<_confect_core_Ref0.Returns<Action>, effect_ParseResult0.ParseError, never>) | GenericActionCtx<ToConvex<FromSchema<DatabaseSchema_>>> | {
55
+ runAfter: <Ref_ extends _confect_core_Ref0.AnyMutation | _confect_core_Ref0.AnyAction>(delay: effect_Duration0.Duration, ref: Ref_, ...args: _confect_core_Ref0.OptionalArgs<Ref_>) => Effect.Effect<convex_values0.GenericId<"_scheduled_functions">, never, never>;
56
+ runAt: <Ref_ extends _confect_core_Ref0.AnyMutation | _confect_core_Ref0.AnyAction>(dateTime: effect_DateTime0.DateTime, ref: Ref_, ...args: _confect_core_Ref0.OptionalArgs<Ref_>) => Effect.Effect<convex_values0.GenericId<"_scheduled_functions">, never, never>;
57
+ } | Auth$1 | StorageReader$1 | StorageWriter$1 | StorageActionWriter$1 | (<Query extends _confect_core_Ref0.AnyQuery>(query: Query, ...args: _confect_core_Ref0.OptionalArgs<Query>) => Effect.Effect<_confect_core_Ref0.Returns<Query>, effect_ParseResult0.ParseError, never>) | (<Mutation extends _confect_core_Ref0.AnyMutation>(mutation: Mutation, ...args: _confect_core_Ref0.OptionalArgs<Mutation>) => Effect.Effect<_confect_core_Ref0.Returns<Mutation>, effect_ParseResult0.ParseError, never>) | (<TableName extends TableNames<FromSchema<DatabaseSchema_>>, IndexName extends keyof convex_server0.VectorIndexes<convex_server0.NamedTableInfo<ToConvex<FromSchema<DatabaseSchema_>>, TableName>>>(tableName: TableName, indexName: IndexName, query: {
58
58
  vector: number[];
59
59
  limit?: number;
60
60
  filter?: (q: convex_server0.VectorFilterBuilder<convex_server0.DocumentByInfo<convex_server0.NamedTableInfo<ToConvex<FromSchema<DatabaseSchema_>>, TableName>>, convex_server0.NamedVectorIndex<convex_server0.NamedTableInfo<ToConvex<FromSchema<DatabaseSchema_>>, TableName>, IndexName>>) => convex_server0.FilterExpression<boolean>;
@@ -1 +1 @@
1
- {"version":3,"file":"RegisteredFunction.d.ts","names":[],"sources":["../src/RegisteredFunction.ts"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;KAyBY,GAAA,GACR,eAAA,CAAgB,kBAAA,EAAoB,mBAAA,SACpC,kBAAA,CAAmB,kBAAA,EAAoB,mBAAA,SACvC,gBAAA,CAAiB,kBAAA,EAAoB,mBAAA;AAAA,KAEpC,yBAAA,uBACmB,YAAA,CAAa,YAAA,IAEnC,YAAA,CAAa,WAAA,CAAY,aAAA,8BACvB,mBAAA,GACE,sBAAA,CAAuB,eAAA,CACrB,aAAA,8CAEA,eAAA,CACE,YAAA,CAAa,qBAAA,CAAsB,aAAA,GACnC,KAAA,EACA,OAAA,CAAQ,YAAA,CAAa,cAAA,CAAe,aAAA,MAEtC,sBAAA,CAAuB,eAAA,CACnB,aAAA,iDAEF,kBAAA,CACE,YAAA,CAAa,qBAAA,CAAsB,aAAA,GACnC,KAAA,EACA,OAAA,CAA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CAAO,MAAA,CAAO,IAAA,EAAM,UAAA;EAC1B,OAAA,EAAS,MAAA,CAAO,MAAA,CAAO,OAAA,EAAS,aAAA;EAChC,OAAA,GAAU,CAAA,EAAG,IAAA,KAAS,MAAA,CAAO,MAAA,CAAO,OAAA,EAAS,CAAA,EAAG,CAAA;EAChD,WAAA,GACE,GAAA,EAAK,gBAAA,CAAiB,QAAA,CAAmB,UAAA,CAAqB,MAAA,QAC3D,KAAA,CAAM,KAAA,CAAM,CAAA;AAAA;QAAD,cAAA,CAAA,kBAAA;;iBAKT,gBAAA,CAAiB,QAAA,CAAmB,UAAA,CAAqB,MAAA,KAAS,UAAA,EAC3D,UAAA,KACX,OAAA,CAAQ,aAAA;AAAA;AAAA,KAeD,cAAA,yBACc,YAAA,IAEtB,WAAA,GACA,MAAA,GACA,eAAA,GACA,eAAA,GACA,qBAAA,GACA,WAAA,GACA,cAAA,GACA,YAAA,GACA,YAAA,CAA0B,UAAA,CAAqB,eAAA,KAC/C,SAAA,CACE,QAAA,CAAmB,UAAA,CAAqB,eAAA;AAAA,cAGjC,WAAA,2BACa,YAAA,EAExB,cAAA,EAAgB,eAAA,EAChB,GAAA,EAAK,gBAAA,CACH,QAAA,CAAmB,UAAA,CAAqB,eAAA,QACzC,KAAA,CAAA,KAAA,kBAFoB,kBAAA,CAEpB,SAAA,EAAA,MAAA,EAAA,MAAA,KAAA,IAAA,EAAA,kBAAA,CAAA,YAAA,CAAA,MAAA,MAAA,MAAA,CAAA,MAAA,CAAA,kBAAA,CAAA,OAAA,CAAA,MAAA,GAAA,mBAAA,CAAA,UAAA,YAAA,gBAAA,CAAA,QAAA,CAAA,UAAA,CAAA,eAAA;0BAAA,kBAAA,CAAA,WAAA"}
@@ -1,5 +1,6 @@
1
1
  import { Context, DateTime, Duration, Effect, Layer } from "effect";
2
- import { OptionalRestArgs, SchedulableFunctionReference, Scheduler as Scheduler$1 } from "convex/server";
2
+ import { Scheduler as Scheduler$1 } from "convex/server";
3
+ import { Ref as Ref$1 } from "@confect/core";
3
4
  import * as convex_values0 from "convex/values";
4
5
 
5
6
  //#region src/Scheduler.d.ts
@@ -7,16 +8,16 @@ declare namespace Scheduler_d_exports {
7
8
  export { Scheduler, layer };
8
9
  }
9
10
  declare const Scheduler: Context.Tag<{
10
- runAfter: <FuncRef extends SchedulableFunctionReference>(delay: Duration.Duration, functionReference: FuncRef, ...args: OptionalRestArgs<FuncRef>) => Effect.Effect<convex_values0.GenericId<"_scheduled_functions">, never, never>;
11
- runAt: <FuncRef extends SchedulableFunctionReference>(dateTime: DateTime.DateTime, functionReference: FuncRef, ...args: OptionalRestArgs<FuncRef>) => Effect.Effect<convex_values0.GenericId<"_scheduled_functions">, never, never>;
11
+ runAfter: <Ref_ extends Ref$1.AnyMutation | Ref$1.AnyAction>(delay: Duration.Duration, ref: Ref_, ...args: Ref$1.OptionalArgs<Ref_>) => Effect.Effect<convex_values0.GenericId<"_scheduled_functions">, never, never>;
12
+ runAt: <Ref_ extends Ref$1.AnyMutation | Ref$1.AnyAction>(dateTime: DateTime.DateTime, ref: Ref_, ...args: Ref$1.OptionalArgs<Ref_>) => Effect.Effect<convex_values0.GenericId<"_scheduled_functions">, never, never>;
12
13
  }, {
13
- runAfter: <FuncRef extends SchedulableFunctionReference>(delay: Duration.Duration, functionReference: FuncRef, ...args: OptionalRestArgs<FuncRef>) => Effect.Effect<convex_values0.GenericId<"_scheduled_functions">, never, never>;
14
- runAt: <FuncRef extends SchedulableFunctionReference>(dateTime: DateTime.DateTime, functionReference: FuncRef, ...args: OptionalRestArgs<FuncRef>) => Effect.Effect<convex_values0.GenericId<"_scheduled_functions">, never, never>;
14
+ runAfter: <Ref_ extends Ref$1.AnyMutation | Ref$1.AnyAction>(delay: Duration.Duration, ref: Ref_, ...args: Ref$1.OptionalArgs<Ref_>) => Effect.Effect<convex_values0.GenericId<"_scheduled_functions">, never, never>;
15
+ runAt: <Ref_ extends Ref$1.AnyMutation | Ref$1.AnyAction>(dateTime: DateTime.DateTime, ref: Ref_, ...args: Ref$1.OptionalArgs<Ref_>) => Effect.Effect<convex_values0.GenericId<"_scheduled_functions">, never, never>;
15
16
  }>;
16
17
  type Scheduler = typeof Scheduler.Identifier;
17
18
  declare const layer: (scheduler: Scheduler$1) => Layer.Layer<{
18
- runAfter: <FuncRef extends SchedulableFunctionReference>(delay: Duration.Duration, functionReference: FuncRef, ...args: OptionalRestArgs<FuncRef>) => Effect.Effect<convex_values0.GenericId<"_scheduled_functions">, never, never>;
19
- runAt: <FuncRef extends SchedulableFunctionReference>(dateTime: DateTime.DateTime, functionReference: FuncRef, ...args: OptionalRestArgs<FuncRef>) => Effect.Effect<convex_values0.GenericId<"_scheduled_functions">, never, never>;
19
+ runAfter: <Ref_ extends Ref$1.AnyMutation | Ref$1.AnyAction>(delay: Duration.Duration, ref: Ref_, ...args: Ref$1.OptionalArgs<Ref_>) => Effect.Effect<convex_values0.GenericId<"_scheduled_functions">, never, never>;
20
+ runAt: <Ref_ extends Ref$1.AnyMutation | Ref$1.AnyAction>(dateTime: DateTime.DateTime, ref: Ref_, ...args: Ref$1.OptionalArgs<Ref_>) => Effect.Effect<convex_values0.GenericId<"_scheduled_functions">, never, never>;
20
21
  }, never, never>;
21
22
  //#endregion
22
23
  export { Scheduler, Scheduler_d_exports, layer };
@@ -1 +1 @@
1
- {"version":3,"file":"Scheduler.d.ts","names":[],"sources":["../src/Scheduler.ts"],"mappings":";;;;;;;;cAgCa,SAAA,EAAS,OAAA,CAAA,GAAA;6BAxBO,4BAAA,EAA4B,KAAA,EAC9C,QAAA,CAAS,QAAA,EAAQ,iBAAA,EACL,OAAA,KAAO,IAAA,EACjB,gBAAA,CAAiB,OAAA,MAAQ,MAAA,CAAA,MAAA,CAAT,cAAA,CAAS,SAAA;0BAQZ,4BAAA,EAA4B,QAAA,EACxC,QAAA,CAAS,QAAA,EAAQ,iBAAA,EACR,OAAA,KAAO,IAAA,EACjB,gBAAA,CAAiB,OAAA,MAAQ,MAAA,CAAA,MAAA,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Q,GAAA,EACtB,IAAA,KAAI,IAAA,EACA,KAAA,CAAI,YAAA,CAAa,IAAA,MAAK,MAAA,CAAA,MAAA,CAAN,cAAA,CAAM,SAAA;AAAA;0BAnBT,KAAA,CAAI,WAAA,GAAc,KAAA,CAAI,SAAA,EAAS,KAAA,EAC9C,QAAA,CAAS,QAAA,EAAQ,GAAA,EACnB,IAAA,KAAI,IAAA,EACA,KAAA,CAAI,YAAA,CAAa,IAAA,MAAK,MAAA,CAAA,MAAA,CAAN,cAAA,CAAM,SAAA;uBAaZ,KAAA,CAAI,WAAA,GAAc,KAAA,CAAI,SAAA,EAAS,QAAA,EACxC,QAAA,CAAS,QAAA,EAAQ,GAAA,EACtB,IAAA,KAAI,IAAA,EACA,KAAA,CAAI,YAAA,CAAa,IAAA,MAAK,MAAA,CAAA,MAAA,CAAN,cAAA,CAAM,SAAA;AAAA;AAAA,KAkBvB,SAAA,UAAmB,SAAA,CAAU,UAAA;AAAA,cAE5B,KAAA,GAAS,SAAA,EAAW,WAAA,KAAe,KAAA,CAAA,KAAA;0BAvCtB,KAAA,CAAI,WAAA,GAAc,KAAA,CAAI,SAAA,EAAS,KAAA,EAC9C,QAAA,CAAS,QAAA,EAAQ,GAAA,EACnB,IAAA,KAAI,IAAA,EACA,KAAA,CAAI,YAAA,CAAa,IAAA,MAAK,MAAA,CAAA,MAAA,CAAN,cAAA,CAAM,SAAA;uBAaZ,KAAA,CAAI,WAAA,GAAc,KAAA,CAAI,SAAA,EAAS,QAAA,EACxC,QAAA,CAAS,QAAA,EAAQ,GAAA,EACtB,IAAA,KAAI,IAAA,EACA,KAAA,CAAI,YAAA,CAAa,IAAA,MAAK,MAAA,CAAA,MAAA,CAAN,cAAA,CAAM,SAAA;AAAA"}
package/dist/Scheduler.js CHANGED
@@ -1,5 +1,6 @@
1
1
  import { __exportAll } from "./_virtual/_rolldown/runtime.js";
2
2
  import { Context, DateTime, Duration, Effect, Layer } from "effect";
3
+ import { Ref as Ref$1 } from "@confect/core";
3
4
 
4
5
  //#region src/Scheduler.ts
5
6
  var Scheduler_exports = /* @__PURE__ */ __exportAll({
@@ -7,13 +8,17 @@ var Scheduler_exports = /* @__PURE__ */ __exportAll({
7
8
  layer: () => layer
8
9
  });
9
10
  const make = (scheduler) => ({
10
- runAfter: (delay, functionReference, ...args) => {
11
+ runAfter: (delay, ref, ...args) => {
11
12
  const delayMs = Duration.toMillis(delay);
12
- return Effect.promise(() => scheduler.runAfter(delayMs, functionReference, ...args));
13
+ const functionReference = Ref$1.getFunctionReference(ref);
14
+ const encodedArgs = Ref$1.encodeArgsSync(ref, args[0] ?? {});
15
+ return Effect.promise(() => scheduler.runAfter(delayMs, functionReference, encodedArgs));
13
16
  },
14
- runAt: (dateTime, functionReference, ...args) => {
17
+ runAt: (dateTime, ref, ...args) => {
15
18
  const timestamp = DateTime.toEpochMillis(dateTime);
16
- return Effect.promise(() => scheduler.runAt(timestamp, functionReference, ...args));
19
+ const functionReference = Ref$1.getFunctionReference(ref);
20
+ const encodedArgs = Ref$1.encodeArgsSync(ref, args[0] ?? {});
21
+ return Effect.promise(() => scheduler.runAt(timestamp, functionReference, encodedArgs));
17
22
  }
18
23
  });
19
24
  const Scheduler = Context.GenericTag("@confect/server/Scheduler");
@@ -1 +1 @@
1
- {"version":3,"file":"Scheduler.js","names":[],"sources":["../src/Scheduler.ts"],"sourcesContent":["import type {\n OptionalRestArgs,\n SchedulableFunctionReference,\n Scheduler as ConvexScheduler,\n} from \"convex/server\";\nimport { Context, DateTime, Duration, Effect, Layer } from \"effect\";\n\nconst make = (scheduler: ConvexScheduler) => ({\n runAfter: <FuncRef extends SchedulableFunctionReference>(\n delay: Duration.Duration,\n functionReference: FuncRef,\n ...args: OptionalRestArgs<FuncRef>\n ) => {\n const delayMs = Duration.toMillis(delay);\n\n return Effect.promise(() =>\n scheduler.runAfter(delayMs, functionReference, ...args),\n );\n },\n runAt: <FuncRef extends SchedulableFunctionReference>(\n dateTime: DateTime.DateTime,\n functionReference: FuncRef,\n ...args: OptionalRestArgs<FuncRef>\n ) => {\n const timestamp = DateTime.toEpochMillis(dateTime);\n\n return Effect.promise(() =>\n scheduler.runAt(timestamp, functionReference, ...args),\n );\n },\n});\n\nexport const Scheduler = Context.GenericTag<ReturnType<typeof make>>(\n \"@confect/server/Scheduler\",\n);\nexport type Scheduler = typeof Scheduler.Identifier;\n\nexport const layer = (scheduler: ConvexScheduler) =>\n Layer.succeed(Scheduler, make(scheduler));\n"],"mappings":";;;;;;;;AAOA,MAAM,QAAQ,eAAgC;CAC5C,WACE,OACA,mBACA,GAAG,SACA;EACH,MAAM,UAAU,SAAS,SAAS,MAAM;AAExC,SAAO,OAAO,cACZ,UAAU,SAAS,SAAS,mBAAmB,GAAG,KAAK,CACxD;;CAEH,QACE,UACA,mBACA,GAAG,SACA;EACH,MAAM,YAAY,SAAS,cAAc,SAAS;AAElD,SAAO,OAAO,cACZ,UAAU,MAAM,WAAW,mBAAmB,GAAG,KAAK,CACvD;;CAEJ;AAED,MAAa,YAAY,QAAQ,WAC/B,4BACD;AAGD,MAAa,SAAS,cACpB,MAAM,QAAQ,WAAW,KAAK,UAAU,CAAC"}
1
+ {"version":3,"file":"Scheduler.js","names":["Ref"],"sources":["../src/Scheduler.ts"],"sourcesContent":["import { Ref } from \"@confect/core\";\nimport type { Scheduler as ConvexScheduler } from \"convex/server\";\nimport { Context, DateTime, Duration, Effect, Layer } from \"effect\";\n\nconst make = (scheduler: ConvexScheduler) => ({\n runAfter: <Ref_ extends Ref.AnyMutation | Ref.AnyAction>(\n delay: Duration.Duration,\n ref: Ref_,\n ...args: Ref.OptionalArgs<Ref_>\n ) => {\n const delayMs = Duration.toMillis(delay);\n const functionReference = Ref.getFunctionReference(ref);\n const encodedArgs = Ref.encodeArgsSync(\n ref,\n (args[0] ?? {}) as Ref.Args<Ref_>,\n );\n\n return Effect.promise(() =>\n scheduler.runAfter(delayMs, functionReference, encodedArgs),\n );\n },\n runAt: <Ref_ extends Ref.AnyMutation | Ref.AnyAction>(\n dateTime: DateTime.DateTime,\n ref: Ref_,\n ...args: Ref.OptionalArgs<Ref_>\n ) => {\n const timestamp = DateTime.toEpochMillis(dateTime);\n const functionReference = Ref.getFunctionReference(ref);\n const encodedArgs = Ref.encodeArgsSync(\n ref,\n (args[0] ?? {}) as Ref.Args<Ref_>,\n );\n\n return Effect.promise(() =>\n scheduler.runAt(timestamp, functionReference, encodedArgs),\n );\n },\n});\n\nexport const Scheduler = Context.GenericTag<ReturnType<typeof make>>(\n \"@confect/server/Scheduler\",\n);\nexport type Scheduler = typeof Scheduler.Identifier;\n\nexport const layer = (scheduler: ConvexScheduler) =>\n Layer.succeed(Scheduler, make(scheduler));\n"],"mappings":";;;;;;;;;AAIA,MAAM,QAAQ,eAAgC;CAC5C,WACE,OACA,KACA,GAAG,SACA;EACH,MAAM,UAAU,SAAS,SAAS,MAAM;EACxC,MAAM,oBAAoBA,MAAI,qBAAqB,IAAI;EACvD,MAAM,cAAcA,MAAI,eACtB,KACC,KAAK,MAAM,EAAE,CACf;AAED,SAAO,OAAO,cACZ,UAAU,SAAS,SAAS,mBAAmB,YAAY,CAC5D;;CAEH,QACE,UACA,KACA,GAAG,SACA;EACH,MAAM,YAAY,SAAS,cAAc,SAAS;EAClD,MAAM,oBAAoBA,MAAI,qBAAqB,IAAI;EACvD,MAAM,cAAcA,MAAI,eACtB,KACC,KAAK,MAAM,EAAE,CACf;AAED,SAAO,OAAO,cACZ,UAAU,MAAM,WAAW,mBAAmB,YAAY,CAC3D;;CAEJ;AAED,MAAa,YAAY,QAAQ,WAC/B,4BACD;AAGD,MAAa,SAAS,cACpB,MAAM,QAAQ,WAAW,KAAK,UAAU,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@confect/server",
3
- "version": "4.0.0",
3
+ "version": "6.0.0",
4
4
  "description": "Backend bindings to the Convex platform",
5
5
  "repository": {
6
6
  "type": "git",
@@ -67,15 +67,15 @@
67
67
  "vite": "7.3.1",
68
68
  "vite-tsconfig-paths": "6.1.1",
69
69
  "vitest": "3.2.4",
70
- "@confect/cli": "4.0.0",
71
- "@confect/test": "4.0.0"
70
+ "@confect/cli": "6.0.0",
71
+ "@confect/test": "6.0.0"
72
72
  },
73
73
  "peerDependencies": {
74
74
  "@effect/platform": "^0.94.5",
75
75
  "@effect/platform-node": "^0.104.1",
76
76
  "convex": "^1.30.0",
77
77
  "effect": "^3.19.16",
78
- "@confect/core": "4.0.0"
78
+ "@confect/core": "6.0.0"
79
79
  },
80
80
  "engines": {
81
81
  "node": ">=22",
@@ -1,38 +1,19 @@
1
1
  import * as Ref from "@confect/core/Ref";
2
2
  import { type GenericActionCtx } from "convex/server";
3
- import type { ParseResult } from "effect";
4
- import { Context, Effect, Layer, Match, Schema } from "effect";
3
+ import { Context, Layer } from "effect";
5
4
 
6
5
  const make =
7
6
  (runAction: GenericActionCtx<any>["runAction"]) =>
8
7
  <Action extends Ref.AnyAction>(
9
8
  action: Action,
10
- args: Ref.Args<Action>,
11
- ): Effect.Effect<Ref.Returns<Action>, ParseResult.ParseError> =>
12
- Effect.gen(function* () {
13
- const functionSpec = Ref.getFunctionSpec(action);
14
- const functionName = Ref.getConvexFunctionName(action);
15
-
16
- return yield* Match.value(functionSpec.functionProvenance).pipe(
17
- Match.tag("Confect", (confectFunctionSpec) =>
18
- Effect.gen(function* () {
19
- const encodedArgs = yield* Schema.encode(confectFunctionSpec.args)(
20
- args,
21
- );
22
- const encodedReturns = yield* Effect.promise(() =>
23
- runAction(functionName as any, encodedArgs),
24
- );
25
- return yield* Schema.decode(confectFunctionSpec.returns)(
26
- encodedReturns,
27
- );
28
- }),
29
- ),
30
- Match.tag("Convex", () =>
31
- Effect.promise(() => runAction(functionName as any, args as any)),
32
- ),
33
- Match.exhaustive,
34
- );
35
- });
9
+ ...args: Ref.OptionalArgs<Action>
10
+ ) =>
11
+ Ref.runWithCodec(
12
+ action,
13
+ (args[0] ?? {}) as Ref.Args<Action>,
14
+ (functionReference, encodedArgs) =>
15
+ runAction(functionReference, encodedArgs),
16
+ );
36
17
 
37
18
  export const ActionRunner = Context.GenericTag<ReturnType<typeof make>>(
38
19
  "@confect/server/ActionRunner",
package/src/CronJob.ts CHANGED
@@ -17,9 +17,6 @@ export interface CronJob {
17
17
  export const isCronJob = (u: unknown): u is CronJob =>
18
18
  Predicate.hasProperty(u, TypeId);
19
19
 
20
- type OptionalArgs<R extends Ref.AnyMutation | Ref.AnyAction> =
21
- keyof Ref.Args<R> extends never ? [args?: Ref.Args<R>] : [args: Ref.Args<R>];
22
-
23
20
  const Proto = {
24
21
  [TypeId]: TypeId,
25
22
  };
@@ -41,5 +38,5 @@ export const make = <R extends Ref.AnyMutation | Ref.AnyAction>(
41
38
  identifier: string,
42
39
  schedule: Cron.Cron | Duration.Duration,
43
40
  ref: R,
44
- ...args: OptionalArgs<R>
41
+ ...args: Ref.OptionalArgs<R>
45
42
  ): CronJob => makeProto(identifier, schedule, ref, args[0] ?? {});
package/src/CronJobs.ts CHANGED
@@ -1,8 +1,5 @@
1
1
  import { Ref } from "@confect/core";
2
- import type {
3
- CronJob as ConvexCronJob,
4
- SchedulableFunctionReference,
5
- } from "convex/server";
2
+ import type { CronJob as ConvexCronJob } from "convex/server";
6
3
  import { cronJobs as makeConvexCrons, type Crons } from "convex/server";
7
4
  import {
8
5
  Array,
@@ -13,7 +10,6 @@ import {
13
10
  pipe,
14
11
  Predicate,
15
12
  Record,
16
- Schema,
17
13
  } from "effect";
18
14
  import type * as CronJob from "./CronJob";
19
15
 
@@ -39,25 +35,15 @@ const Proto = {
39
35
  crons: { ...this.convexCronJobs.crons },
40
36
  });
41
37
 
42
- const schedulableFunctionReference = Ref.getConvexFunctionName(
43
- cronJob.ref,
44
- ) as unknown as SchedulableFunctionReference;
45
-
46
- const functionSpec = Ref.getFunctionSpec(cronJob.ref);
47
- const encodedArgs = Match.value(functionSpec.functionProvenance).pipe(
48
- Match.tag("Confect", (confect) =>
49
- Schema.encodeSync(confect.args)(cronJob.args),
50
- ),
51
- Match.tag("Convex", () => cronJob.args),
52
- Match.exhaustive,
53
- );
38
+ const functionReference = Ref.getFunctionReference(cronJob.ref);
39
+ const encodedArgs = Ref.encodeArgsSync(cronJob.ref, cronJob.args);
54
40
 
55
41
  Match.value(cronJob.schedule).pipe(
56
42
  Match.when(Cron.isCron, (cron) => {
57
43
  newConvexCrons.cron(
58
44
  cronJob.identifier,
59
45
  cronToConvexCronString(cron),
60
- schedulableFunctionReference,
46
+ functionReference,
61
47
  encodedArgs,
62
48
  );
63
49
  }),
@@ -65,7 +51,7 @@ const Proto = {
65
51
  newConvexCrons.interval(
66
52
  cronJob.identifier,
67
53
  durationToConvexIntervalSchedule(duration),
68
- schedulableFunctionReference,
54
+ functionReference,
69
55
  encodedArgs,
70
56
  );
71
57
  }),
@@ -1,38 +1,19 @@
1
1
  import * as Ref from "@confect/core/Ref";
2
2
  import { type GenericMutationCtx } from "convex/server";
3
- import type { ParseResult } from "effect";
4
- import { Context, Effect, Layer, Match, Schema } from "effect";
3
+ import { Context, Layer, Schema } from "effect";
5
4
 
6
5
  const make =
7
6
  (runMutation: GenericMutationCtx<any>["runMutation"]) =>
8
7
  <Mutation extends Ref.AnyMutation>(
9
8
  mutation: Mutation,
10
- args: Ref.Args<Mutation>,
11
- ): Effect.Effect<Ref.Returns<Mutation>, ParseResult.ParseError> =>
12
- Effect.gen(function* () {
13
- const functionSpec = Ref.getFunctionSpec(mutation);
14
- const functionName = Ref.getConvexFunctionName(mutation);
15
-
16
- return yield* Match.value(functionSpec.functionProvenance).pipe(
17
- Match.tag("Confect", (confectFunctionSpec) =>
18
- Effect.gen(function* () {
19
- const encodedArgs = yield* Schema.encode(confectFunctionSpec.args)(
20
- args,
21
- );
22
- const encodedReturns = yield* Effect.promise(() =>
23
- runMutation(functionName as any, encodedArgs),
24
- );
25
- return yield* Schema.decode(confectFunctionSpec.returns)(
26
- encodedReturns,
27
- );
28
- }),
29
- ),
30
- Match.tag("Convex", () =>
31
- Effect.promise(() => runMutation(functionName as any, args as any)),
32
- ),
33
- Match.exhaustive,
34
- );
35
- });
9
+ ...args: Ref.OptionalArgs<Mutation>
10
+ ) =>
11
+ Ref.runWithCodec(
12
+ mutation,
13
+ (args[0] ?? {}) as Ref.Args<Mutation>,
14
+ (functionReference, encodedArgs) =>
15
+ runMutation(functionReference, encodedArgs),
16
+ );
36
17
 
37
18
  export const MutationRunner = Context.GenericTag<ReturnType<typeof make>>(
38
19
  "@confect/server/MutationRunner",
@@ -1,38 +1,19 @@
1
1
  import * as Ref from "@confect/core/Ref";
2
2
  import { type GenericQueryCtx } from "convex/server";
3
- import type { ParseResult } from "effect";
4
- import { Context, Effect, Layer, Match, Schema } from "effect";
3
+ import { Context, Layer } from "effect";
5
4
 
6
5
  const make =
7
6
  (runQuery: GenericQueryCtx<any>["runQuery"]) =>
8
7
  <Query extends Ref.AnyQuery>(
9
8
  query: Query,
10
- args: Ref.Args<Query>,
11
- ): Effect.Effect<Ref.Returns<Query>, ParseResult.ParseError> =>
12
- Effect.gen(function* () {
13
- const functionSpec = Ref.getFunctionSpec(query);
14
- const functionName = Ref.getConvexFunctionName(query);
15
-
16
- return yield* Match.value(functionSpec.functionProvenance).pipe(
17
- Match.tag("Confect", (confectFunctionSpec) =>
18
- Effect.gen(function* () {
19
- const encodedArgs = yield* Schema.encode(confectFunctionSpec.args)(
20
- args,
21
- );
22
- const encodedReturns = yield* Effect.promise(() =>
23
- runQuery(functionName as any, encodedArgs),
24
- );
25
- return yield* Schema.decode(confectFunctionSpec.returns)(
26
- encodedReturns,
27
- );
28
- }),
29
- ),
30
- Match.tag("Convex", () =>
31
- Effect.promise(() => runQuery(functionName as any, args as any)),
32
- ),
33
- Match.exhaustive,
34
- );
35
- });
9
+ ...args: Ref.OptionalArgs<Query>
10
+ ) =>
11
+ Ref.runWithCodec(
12
+ query,
13
+ (args[0] ?? {}) as Ref.Args<Query>,
14
+ (functionReference, encodedArgs) =>
15
+ runQuery(functionReference, encodedArgs),
16
+ );
36
17
 
37
18
  export const QueryRunner = Context.GenericTag<ReturnType<typeof make>>(
38
19
  "@confect/server/QueryRunner",
@@ -10,7 +10,7 @@ import {
10
10
  mutationGeneric,
11
11
  queryGeneric,
12
12
  } from "convex/server";
13
- import { Effect, Layer, Match, pipe, Schema } from "effect";
13
+ import { Clock, Effect, Layer, Match, pipe, Schema } from "effect";
14
14
  import type * as Api from "./Api";
15
15
  import * as Auth from "./Auth";
16
16
  import * as ConvexConfigProvider from "./ConvexConfigProvider";
@@ -92,6 +92,43 @@ export const make = <Api_ extends Api.AnyWithPropsWithRuntime<"Convex">>(
92
92
  Match.exhaustive,
93
93
  );
94
94
 
95
+ // Convex's query cache is invalidated by any Date.now() call during handler
96
+ // execution. Effect's unsafeFork calls Date.now() when constructing a
97
+ // FiberId.Runtime, which trips the cache for every confect-wrapped query. We
98
+ // stub Date.now to 0 for the span of the handler; queries are forbidden from
99
+ // relying on real time for correctness anyway.
100
+ //
101
+ // Users who explicitly want the real timestamp can still reach it via Effect's
102
+ // Clock service (Clock.currentTimeMillis / Clock.currentTimeNanos). We provide
103
+ // a Clock layer whose methods close over the *original* Date.now, so opting in
104
+ // to Clock is an opt-in to worse caching — but caching is not broken by default.
105
+ const unpatchedClock = (realDateNow: () => number): Clock.Clock => {
106
+ const bigint1e6 = BigInt(1_000_000);
107
+ const unsafeCurrentTimeMillis = () => realDateNow();
108
+ const unsafeCurrentTimeNanos = () => BigInt(realDateNow()) * bigint1e6;
109
+ const defaultClock = Clock.make();
110
+ return {
111
+ ...defaultClock,
112
+ unsafeCurrentTimeMillis,
113
+ unsafeCurrentTimeNanos,
114
+ currentTimeMillis: Effect.sync(unsafeCurrentTimeMillis),
115
+ currentTimeNanos: Effect.sync(unsafeCurrentTimeNanos),
116
+ };
117
+ };
118
+
119
+ const withStubbedDateNow = async <T>(
120
+ queryHandler: (clock: Clock.Clock) => Promise<T>,
121
+ ): Promise<T> => {
122
+ const realDateNow = Date.now;
123
+ const clock = unpatchedClock(realDateNow);
124
+ Date.now = () => 0;
125
+ try {
126
+ return await queryHandler(clock);
127
+ } finally {
128
+ Date.now = realDateNow;
129
+ }
130
+ };
131
+
95
132
  const queryFunction = <
96
133
  DatabaseSchema_ extends DatabaseSchema.AnyWithProps,
97
134
  Args,
@@ -131,34 +168,37 @@ const queryFunction = <
131
168
  >,
132
169
  actualArgs: ConvexArgs,
133
170
  ): Promise<ConvexReturns> =>
134
- pipe(
135
- actualArgs,
136
- Schema.decode(args),
137
- Effect.orDie,
138
- Effect.andThen((decodedArgs) =>
139
- pipe(
140
- handler(decodedArgs),
141
- Effect.provide(
142
- Layer.mergeAll(
143
- DatabaseReader.layer(databaseSchema, ctx.db),
144
- Auth.layer(ctx.auth),
145
- StorageReader.layer(ctx.storage),
146
- QueryRunner.layer(ctx.runQuery),
147
- Layer.succeed(
148
- QueryCtx.QueryCtx<
149
- DataModel.ToConvex<DataModel.FromSchema<DatabaseSchema_>>
150
- >(),
151
- ctx,
171
+ withStubbedDateNow((clock) =>
172
+ pipe(
173
+ actualArgs,
174
+ Schema.decode(args),
175
+ Effect.orDie,
176
+ Effect.andThen((decodedArgs) =>
177
+ pipe(
178
+ handler(decodedArgs),
179
+ Effect.provide(
180
+ Layer.mergeAll(
181
+ DatabaseReader.layer(databaseSchema, ctx.db),
182
+ Auth.layer(ctx.auth),
183
+ StorageReader.layer(ctx.storage),
184
+ QueryRunner.layer(ctx.runQuery),
185
+ Layer.succeed(
186
+ QueryCtx.QueryCtx<
187
+ DataModel.ToConvex<DataModel.FromSchema<DatabaseSchema_>>
188
+ >(),
189
+ ctx,
190
+ ),
191
+ Layer.setConfigProvider(ConvexConfigProvider.make()),
152
192
  ),
153
- Layer.setConfigProvider(ConvexConfigProvider.make()),
154
193
  ),
155
194
  ),
156
195
  ),
196
+ Effect.andThen((convexReturns) =>
197
+ Schema.encodeUnknown(returns)(convexReturns),
198
+ ),
199
+ Effect.withClock(clock),
200
+ Effect.runPromise,
157
201
  ),
158
- Effect.andThen((convexReturns) =>
159
- Schema.encodeUnknown(returns)(convexReturns),
160
- ),
161
- Effect.runPromise,
162
202
  ),
163
203
  });
164
204
 
package/src/Scheduler.ts CHANGED
@@ -1,31 +1,38 @@
1
- import type {
2
- OptionalRestArgs,
3
- SchedulableFunctionReference,
4
- Scheduler as ConvexScheduler,
5
- } from "convex/server";
1
+ import { Ref } from "@confect/core";
2
+ import type { Scheduler as ConvexScheduler } from "convex/server";
6
3
  import { Context, DateTime, Duration, Effect, Layer } from "effect";
7
4
 
8
5
  const make = (scheduler: ConvexScheduler) => ({
9
- runAfter: <FuncRef extends SchedulableFunctionReference>(
6
+ runAfter: <Ref_ extends Ref.AnyMutation | Ref.AnyAction>(
10
7
  delay: Duration.Duration,
11
- functionReference: FuncRef,
12
- ...args: OptionalRestArgs<FuncRef>
8
+ ref: Ref_,
9
+ ...args: Ref.OptionalArgs<Ref_>
13
10
  ) => {
14
11
  const delayMs = Duration.toMillis(delay);
12
+ const functionReference = Ref.getFunctionReference(ref);
13
+ const encodedArgs = Ref.encodeArgsSync(
14
+ ref,
15
+ (args[0] ?? {}) as Ref.Args<Ref_>,
16
+ );
15
17
 
16
18
  return Effect.promise(() =>
17
- scheduler.runAfter(delayMs, functionReference, ...args),
19
+ scheduler.runAfter(delayMs, functionReference, encodedArgs),
18
20
  );
19
21
  },
20
- runAt: <FuncRef extends SchedulableFunctionReference>(
22
+ runAt: <Ref_ extends Ref.AnyMutation | Ref.AnyAction>(
21
23
  dateTime: DateTime.DateTime,
22
- functionReference: FuncRef,
23
- ...args: OptionalRestArgs<FuncRef>
24
+ ref: Ref_,
25
+ ...args: Ref.OptionalArgs<Ref_>
24
26
  ) => {
25
27
  const timestamp = DateTime.toEpochMillis(dateTime);
28
+ const functionReference = Ref.getFunctionReference(ref);
29
+ const encodedArgs = Ref.encodeArgsSync(
30
+ ref,
31
+ (args[0] ?? {}) as Ref.Args<Ref_>,
32
+ );
26
33
 
27
34
  return Effect.promise(() =>
28
- scheduler.runAt(timestamp, functionReference, ...args),
35
+ scheduler.runAt(timestamp, functionReference, encodedArgs),
29
36
  );
30
37
  },
31
38
  });