@confect/server 1.0.0-next.3 → 1.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.
@@ -1 +1 @@
1
- {"version":3,"file":"RegisteredFunctions.js","names":["Registry.Registry","Impl.Impl","RegistryItem.isRegistryItem","SchemaToValidator.compileArgsSchema","SchemaToValidator.compileReturnsSchema","DatabaseReader.layer","Auth.layer","StorageReader","QueryRunner.layer","QueryCtx.QueryCtx","DatabaseWriter.layer","Scheduler.layer","StorageWriter","MutationRunner.layer","MutationCtx.MutationCtx","StorageActionWriter","ActionRunner.layer","VectorSearch.layer","ActionCtx.ActionCtx"],"sources":["../src/RegisteredFunctions.ts"],"sourcesContent":["import type * as FunctionSpec from \"@confect/core/FunctionSpec\";\nimport type * as GroupSpec from \"@confect/core/GroupSpec\";\nimport type * as Spec from \"@confect/core/Spec\";\nimport {\n actionGeneric,\n type DefaultFunctionArgs,\n type FunctionVisibility,\n type GenericActionCtx,\n type GenericMutationCtx,\n type GenericQueryCtx,\n internalActionGeneric,\n internalMutationGeneric,\n internalQueryGeneric,\n mutationGeneric,\n queryGeneric,\n type RegisteredAction,\n type RegisteredMutation,\n type RegisteredQuery,\n} from \"convex/server\";\nimport { Effect, Layer, Match, pipe, Ref, Schema, type Types } from \"effect\";\nimport * as ActionCtx from \"./ActionCtx\";\nimport * as ActionRunner from \"./ActionRunner\";\nimport type * as Api from \"./Api\";\nimport * as Auth from \"./Auth\";\nimport * as DatabaseReader from \"./DatabaseReader\";\nimport type * as DatabaseSchema from \"./DatabaseSchema\";\nimport * as DatabaseWriter from \"./DatabaseWriter\";\nimport type * as DataModel from \"./DataModel\";\nimport * as Impl from \"./Impl\";\nimport { mapLeaves } from \"./internal/utils\";\nimport * as MutationCtx from \"./MutationCtx\";\nimport * as MutationRunner from \"./MutationRunner\";\nimport * as QueryCtx from \"./QueryCtx\";\nimport * as QueryRunner from \"./QueryRunner\";\nimport * as Registry from \"./Registry\";\nimport * as RegistryItem from \"./RegistryItem\";\nimport * as Scheduler from \"./Scheduler\";\nimport * as SchemaToValidator from \"./SchemaToValidator\";\nimport { StorageActionWriter, StorageReader, StorageWriter } from \"./Storage\";\nimport * as VectorSearch from \"./VectorSearch\";\n\nexport type RegisteredFunction =\n | RegisteredQuery<FunctionVisibility, DefaultFunctionArgs, any>\n | RegisteredMutation<FunctionVisibility, DefaultFunctionArgs, any>\n | RegisteredAction<FunctionVisibility, DefaultFunctionArgs, any>;\n\nexport type RegisteredFunctions<Spec_ extends Spec.AnyWithProps> =\n Types.Simplify<RegisteredFunctionsHelper<Spec.Groups<Spec_>>>;\n\ntype RegisteredFunctionsHelper<Groups extends GroupSpec.AnyWithProps> = {\n [GroupName in GroupSpec.Name<Groups>]: GroupSpec.WithName<\n Groups,\n GroupName\n > extends infer Group extends GroupSpec.AnyWithProps\n ? GroupSpec.Groups<Group> extends infer SubGroups extends\n GroupSpec.AnyWithProps\n ? Types.Simplify<\n RegisteredFunctionsHelper<SubGroups> & {\n [FunctionName in FunctionSpec.Name<\n GroupSpec.Functions<Group>\n >]: FunctionSpec.WithName<\n GroupSpec.Functions<Group>,\n FunctionName\n > extends infer Function extends FunctionSpec.AnyWithProps\n ? FunctionSpec.RegisteredFunction<Function>\n : never;\n }\n >\n : {\n [FunctionName in FunctionSpec.Name<\n GroupSpec.Functions<Group>\n >]: FunctionSpec.WithName<\n GroupSpec.Functions<Group>,\n FunctionName\n > extends infer Function extends FunctionSpec.AnyWithProps\n ? FunctionSpec.RegisteredFunction<Function>\n : never;\n }\n : never;\n};\n\nexport interface AnyWithProps {\n readonly [key: string]: RegisteredFunction | AnyWithProps;\n}\n\nexport const make = <Api_ extends Api.AnyWithProps>(\n impl: Layer.Layer<Impl.Impl<Api_, \"Finalized\">>,\n) =>\n Effect.gen(function* () {\n const registry = yield* Registry.Registry;\n const functionImplItems = yield* Ref.get(registry);\n const { api, finalizationStatus } = yield* Impl.Impl<Api_, \"Finalized\">();\n\n return yield* Match.value(\n finalizationStatus as Impl.FinalizationStatus,\n ).pipe(\n Match.withReturnType<Effect.Effect<RegisteredFunctions<Api_[\"spec\"]>>>(),\n Match.when(\"Unfinalized\", () =>\n Effect.dieMessage(\"Impl is not finalized\"),\n ),\n Match.when(\"Finalized\", () =>\n Effect.succeed(\n mapLeaves<RegistryItem.AnyWithProps, RegisteredFunction>(\n functionImplItems,\n RegistryItem.isRegistryItem,\n (registryItem) => makeRegisteredFunction(api, registryItem),\n ) as RegisteredFunctions<Api_[\"spec\"]>,\n ),\n ),\n Match.exhaustive,\n );\n }).pipe(Effect.provide(impl), Effect.runSync);\n\nconst makeRegisteredFunction = <Api_ extends Api.AnyWithProps>(\n api: Api_,\n { function_, handler }: RegistryItem.AnyWithProps,\n): RegisteredFunction =>\n Match.value(function_.functionType).pipe(\n Match.when(\"query\", () => {\n const genericFunction = Match.value(function_.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: function_.args,\n returns: function_.returns,\n handler,\n }),\n );\n }),\n Match.when(\"mutation\", () => {\n const genericFunction = Match.value(function_.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: function_.args,\n returns: function_.returns,\n handler,\n }),\n );\n }),\n Match.when(\"action\", () => {\n const genericFunction = Match.value(function_.functionVisibility).pipe(\n Match.when(\"public\", () => actionGeneric),\n Match.when(\"internal\", () => internalActionGeneric),\n Match.exhaustive,\n );\n\n return genericFunction(\n actionFunction({\n args: function_.args,\n returns: function_.returns,\n handler,\n }),\n );\n }),\n Match.exhaustive,\n );\n\nconst queryFunction = <\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: (\n a: Args,\n ) => Effect.Effect<\n Returns,\n E,\n | DatabaseReader.DatabaseReader<Schema>\n | Auth.Auth\n | StorageReader\n | QueryRunner.QueryRunner\n | QueryCtx.QueryCtx<DataModel.ToConvex<DataModel.FromSchema<Schema>>>\n >;\n },\n) => ({\n args: SchemaToValidator.compileArgsSchema(args),\n returns: SchemaToValidator.compileReturnsSchema(returns),\n handler: (\n ctx: GenericQueryCtx<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 pipe(\n handler(decodedArgs),\n Effect.provide(\n Layer.mergeAll(\n DatabaseReader.layer(schema, 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<Schema>>\n >(),\n ctx,\n ),\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 );\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 actionFunction = <\n Schema extends DatabaseSchema.AnyWithProps,\n Args,\n ConvexArgs extends DefaultFunctionArgs,\n Returns,\n ConvexReturns,\n E,\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 | Scheduler.Scheduler\n | Auth.Auth\n | StorageReader\n | StorageWriter\n | StorageActionWriter\n | QueryRunner.QueryRunner\n | MutationRunner.MutationRunner\n | ActionRunner.ActionRunner\n | VectorSearch.VectorSearch<DataModel.FromSchema<Schema>>\n | ActionCtx.ActionCtx<DataModel.ToConvex<DataModel.FromSchema<Schema>>>\n >;\n}) => ({\n args: SchemaToValidator.compileArgsSchema(args),\n returns: SchemaToValidator.compileReturnsSchema(returns),\n handler: (\n ctx: GenericActionCtx<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 pipe(\n handler(decodedArgs),\n Effect.provide(\n Layer.mergeAll(\n Scheduler.layer(ctx.scheduler),\n Auth.layer(ctx.auth),\n StorageReader.layer(ctx.storage),\n StorageWriter.layer(ctx.storage),\n StorageActionWriter.layer(ctx.storage),\n QueryRunner.layer(ctx.runQuery),\n MutationRunner.layer(ctx.runMutation),\n ActionRunner.layer(ctx.runAction),\n VectorSearch.layer(ctx.vectorSearch),\n Layer.succeed(\n ActionCtx.ActionCtx<\n DataModel.ToConvex<DataModel.FromSchema<Schema>>\n >(),\n ctx,\n ),\n ),\n ),\n ),\n ),\n Effect.andThen((convexReturns) =>\n Schema.encodeUnknown(returns)(convexReturns),\n ),\n Effect.runPromise,\n ),\n});\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAqFA,MAAa,QACX,SAEA,OAAO,IAAI,aAAa;CACtB,MAAM,WAAW,OAAOA;CACxB,MAAM,oBAAoB,OAAO,IAAI,IAAI,SAAS;CAClD,MAAM,EAAE,KAAK,uBAAuB,OAAOC,MAA8B;AAEzE,QAAO,OAAO,MAAM,MAClB,mBACD,CAAC,KACA,MAAM,gBAAkE,EACxE,MAAM,KAAK,qBACT,OAAO,WAAW,wBAAwB,CAC3C,EACD,MAAM,KAAK,mBACT,OAAO,QACL,UACE,mBACAC,iBACC,iBAAiB,uBAAuB,KAAK,aAAa,CAC5D,CACF,CACF,EACD,MAAM,WACP;EACD,CAAC,KAAK,OAAO,QAAQ,KAAK,EAAE,OAAO,QAAQ;AAE/C,MAAM,0BACJ,KACA,EAAE,WAAW,cAEb,MAAM,MAAM,UAAU,aAAa,CAAC,KAClC,MAAM,KAAK,eAAe;AAOxB,QANwB,MAAM,MAAM,UAAU,mBAAmB,CAAC,KAChE,MAAM,KAAK,gBAAgB,aAAa,EACxC,MAAM,KAAK,kBAAkB,qBAAqB,EAClD,MAAM,WACP,CAGC,cAAc,IAAI,gBAAgB;EAChC,MAAM,UAAU;EAChB,SAAS,UAAU;EACnB;EACD,CAAC,CACH;EACD,EACF,MAAM,KAAK,kBAAkB;AAO3B,QANwB,MAAM,MAAM,UAAU,mBAAmB,CAAC,KAChE,MAAM,KAAK,gBAAgB,gBAAgB,EAC3C,MAAM,KAAK,kBAAkB,wBAAwB,EACrD,MAAM,WACP,CAGC,iBAAiB,IAAI,gBAAgB;EACnC,MAAM,UAAU;EAChB,SAAS,UAAU;EACnB;EACD,CAAC,CACH;EACD,EACF,MAAM,KAAK,gBAAgB;AAOzB,QANwB,MAAM,MAAM,UAAU,mBAAmB,CAAC,KAChE,MAAM,KAAK,gBAAgB,cAAc,EACzC,MAAM,KAAK,kBAAkB,sBAAsB,EACnD,MAAM,WACP,CAGC,eAAe;EACb,MAAM,UAAU;EAChB,SAAS,UAAU;EACnB;EACD,CAAC,CACH;EACD,EACF,MAAM,WACP;AAEH,MAAM,iBAQJ,QACA,EACE,MACA,SACA,eAgBE;CACJ,MAAMC,kBAAoC,KAAK;CAC/C,SAASC,qBAAuC,QAAQ;CACxD,UACE,KACA,eAEA,KACE,YACA,OAAO,OAAO,KAAK,EACnB,OAAO,OACP,OAAO,SAAS,gBACd,KACE,QAAQ,YAAY,EACpB,OAAO,QACL,MAAM,SACJC,QAAqB,QAAQ,IAAI,GAAG,EACpCC,QAAW,IAAI,KAAK,EACpBC,gBAAc,MAAM,IAAI,QAAQ,EAChCC,QAAkB,IAAI,SAAS,EAC/B,MAAM,QACJC,UAEG,EACH,IACD,CACF,CACF,CACF,CACF,EACD,OAAO,SAAS,kBACd,OAAO,cAAc,QAAQ,CAAC,cAAc,CAC7C,EACD,OAAO,WACR;CACJ;AAED,MAAa,iBACX,QACA,QAEA,MAAM,SACJJ,QAAqB,QAAQ,IAAI,GAAG,EACpCK,QAAqB,QAAQ,IAAI,GAAG,EACpCJ,QAAW,IAAI,KAAK,EACpBK,QAAgB,IAAI,UAAU,EAC9BJ,gBAAc,MAAM,IAAI,QAAQ,EAChCK,gBAAc,MAAM,IAAI,QAAQ,EAChCJ,QAAkB,IAAI,SAAS,EAC/BK,QAAqB,IAAI,YAAY,EACrC,MAAM,QACJC,aAEG,EACH,IACD,CACF;AAaH,MAAM,oBAQJ,QACA,EACE,MACA,SACA,eAME;CACJ,MAAMX,kBAAoC,KAAK;CAC/C,SAASC,qBAAuC,QAAQ;CACxD,UACE,KACA,eAEA,KACE,YACA,OAAO,OAAO,KAAK,EACnB,OAAO,OACP,OAAO,SAAS,gBACd,QAAQ,YAAY,CAAC,KAAK,OAAO,QAAQ,cAAc,QAAQ,IAAI,CAAC,CAAC,CACtE,EACD,OAAO,SAAS,kBACd,OAAO,cAAc,QAAQ,CAAC,cAAc,CAC7C,EACD,OAAO,WACR;CACJ;AAED,MAAM,kBAOJ,EACA,MACA,SACA,eAoBK;CACL,MAAMD,kBAAoC,KAAK;CAC/C,SAASC,qBAAuC,QAAQ;CACxD,UACE,KACA,eAEA,KACE,YACA,OAAO,OAAO,KAAK,EACnB,OAAO,OACP,OAAO,SAAS,gBACd,KACE,QAAQ,YAAY,EACpB,OAAO,QACL,MAAM,SACJO,QAAgB,IAAI,UAAU,EAC9BL,QAAW,IAAI,KAAK,EACpBC,gBAAc,MAAM,IAAI,QAAQ,EAChCK,gBAAc,MAAM,IAAI,QAAQ,EAChCG,sBAAoB,MAAM,IAAI,QAAQ,EACtCP,QAAkB,IAAI,SAAS,EAC/BK,QAAqB,IAAI,YAAY,EACrCG,MAAmB,IAAI,UAAU,EACjCC,QAAmB,IAAI,aAAa,EACpC,MAAM,QACJC,WAEG,EACH,IACD,CACF,CACF,CACF,CACF,EACD,OAAO,SAAS,kBACd,OAAO,cAAc,QAAQ,CAAC,cAAc,CAC7C,EACD,OAAO,WACR;CACJ"}
1
+ {"version":3,"file":"RegisteredFunctions.js","names":["Registry.Registry","Impl.Impl","RegistryItem.isRegistryItem"],"sources":["../src/RegisteredFunctions.ts"],"sourcesContent":["import type * as FunctionSpec from \"@confect/core/FunctionSpec\";\nimport type * as GroupSpec from \"@confect/core/GroupSpec\";\nimport type * as Spec from \"@confect/core/Spec\";\nimport type { Layer } from \"effect\";\nimport { Effect, Match, Ref, type Types } from \"effect\";\nimport type * as Api from \"./Api\";\nimport * as Impl from \"./Impl\";\nimport { mapLeaves } from \"./internal/utils\";\nimport type * as RegisteredFunction from \"./RegisteredFunction\";\nimport * as Registry from \"./Registry\";\nimport * as RegistryItem from \"./RegistryItem\";\n\nexport type RegisteredFunctions<Spec_ extends Spec.AnyWithProps> =\n Types.Simplify<RegisteredFunctionsHelper<Spec.Groups<Spec_>>>;\n\ntype RegisteredFunctionsHelper<Groups extends GroupSpec.AnyWithProps> = {\n [GroupName in GroupSpec.Name<Groups>]: GroupSpec.WithName<\n Groups,\n GroupName\n > extends infer Group extends GroupSpec.AnyWithProps\n ? GroupSpec.Groups<Group> extends infer SubGroups extends\n GroupSpec.AnyWithProps\n ? Types.Simplify<\n RegisteredFunctionsHelper<SubGroups> & {\n [FunctionName in FunctionSpec.Name<\n GroupSpec.Functions<Group>\n >]: FunctionSpec.WithName<\n GroupSpec.Functions<Group>,\n FunctionName\n > extends infer Function extends FunctionSpec.AnyWithProps\n ? FunctionSpec.RegisteredFunction<Function>\n : never;\n }\n >\n : {\n [FunctionName in FunctionSpec.Name<\n GroupSpec.Functions<Group>\n >]: FunctionSpec.WithName<\n GroupSpec.Functions<Group>,\n FunctionName\n > extends infer Function extends FunctionSpec.AnyWithProps\n ? FunctionSpec.RegisteredFunction<Function>\n : never;\n }\n : never;\n};\n\nexport interface AnyWithProps {\n readonly [key: string]: RegisteredFunction.RegisteredFunction | AnyWithProps;\n}\n\nexport const make = <Api_ extends Api.AnyWithProps>(\n impl: Layer.Layer<Impl.Impl<Api_, \"Finalized\">>,\n makeRegisteredFunction: (\n api: Api_,\n registryItem: RegistryItem.AnyWithProps,\n ) => RegisteredFunction.RegisteredFunction,\n) =>\n Effect.gen(function* () {\n const registry = yield* Registry.Registry;\n const functionImplItems = yield* Ref.get(registry);\n const { api, finalizationStatus } = yield* Impl.Impl<Api_, \"Finalized\">();\n\n return yield* Match.value(\n finalizationStatus as Impl.FinalizationStatus,\n ).pipe(\n Match.withReturnType<Effect.Effect<RegisteredFunctions<Api_[\"spec\"]>>>(),\n Match.when(\"Unfinalized\", () =>\n Effect.dieMessage(\"Impl is not finalized\"),\n ),\n Match.when(\"Finalized\", () =>\n Effect.succeed(\n mapLeaves<\n RegistryItem.AnyWithProps,\n RegisteredFunction.RegisteredFunction\n >(functionImplItems, RegistryItem.isRegistryItem, (registryItem) =>\n makeRegisteredFunction(api, registryItem),\n ) as RegisteredFunctions<Api_[\"spec\"]>,\n ),\n ),\n Match.exhaustive,\n );\n }).pipe(Effect.provide(impl), Effect.runSync);\n"],"mappings":";;;;;;;;;AAmDA,MAAa,QACX,MACA,2BAKA,OAAO,IAAI,aAAa;CACtB,MAAM,WAAW,OAAOA;CACxB,MAAM,oBAAoB,OAAO,IAAI,IAAI,SAAS;CAClD,MAAM,EAAE,KAAK,uBAAuB,OAAOC,MAA8B;AAEzE,QAAO,OAAO,MAAM,MAClB,mBACD,CAAC,KACA,MAAM,gBAAkE,EACxE,MAAM,KAAK,qBACT,OAAO,WAAW,wBAAwB,CAC3C,EACD,MAAM,KAAK,mBACT,OAAO,QACL,UAGE,mBAAmBC,iBAA8B,iBACjD,uBAAuB,KAAK,aAAa,CAC1C,CACF,CACF,EACD,MAAM,WACP;EACD,CAAC,KAAK,OAAO,QAAQ,KAAK,EAAE,OAAO,QAAQ"}
@@ -0,0 +1,15 @@
1
+ import { AnyWithPropsWithRuntime } from "./Api.js";
2
+ import { RegisteredFunction } from "./RegisteredFunction.js";
3
+ import { AnyWithProps } from "./RegistryItem.js";
4
+
5
+ //#region src/RegisteredNodeFunction.d.ts
6
+ declare namespace RegisteredNodeFunction_d_exports {
7
+ export { make };
8
+ }
9
+ declare const make: <Api_ extends AnyWithPropsWithRuntime<"Node">>(api: Api_, {
10
+ function_,
11
+ handler
12
+ }: AnyWithProps) => RegisteredFunction;
13
+ //#endregion
14
+ export { RegisteredNodeFunction_d_exports, make };
15
+ //# sourceMappingURL=RegisteredNodeFunction.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"RegisteredNodeFunction.d.ts","names":[],"sources":["../src/RegisteredNodeFunction.ts"],"mappings":";;;;;;;;cAaa,IAAA,gBAAqB,uBAAA,UAChC,GAAA,EAAK,IAAA;EACL,SAAA;EAAA;AAAA,GAAwB,YAAA,KACvB,kBAAA"}
@@ -0,0 +1,25 @@
1
+ import { __exportAll } from "./_virtual/_rolldown/runtime.js";
2
+ import { actionFunctionBase, actionLayer } from "./RegisteredFunction.js";
3
+ import { Layer, Match } from "effect";
4
+ import { actionGeneric, internalActionGeneric } from "convex/server";
5
+ import { NodeContext } from "@effect/platform-node";
6
+
7
+ //#region src/RegisteredNodeFunction.ts
8
+ var RegisteredNodeFunction_exports = /* @__PURE__ */ __exportAll({ make: () => make });
9
+ const make = (api, { function_, handler }) => {
10
+ return Match.value(function_.functionVisibility).pipe(Match.when("public", () => actionGeneric), Match.when("internal", () => internalActionGeneric), Match.exhaustive)(nodeActionFunction(api.databaseSchema, {
11
+ args: function_.args,
12
+ returns: function_.returns,
13
+ handler
14
+ }));
15
+ };
16
+ const nodeActionFunction = (databaseSchema, { args, returns, handler }) => actionFunctionBase({
17
+ args,
18
+ returns,
19
+ handler,
20
+ createLayer: (ctx) => Layer.mergeAll(actionLayer(databaseSchema, ctx), NodeContext.layer)
21
+ });
22
+
23
+ //#endregion
24
+ export { RegisteredNodeFunction_exports, make };
25
+ //# sourceMappingURL=RegisteredNodeFunction.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"RegisteredNodeFunction.js","names":["RegisteredFunction.actionFunctionBase","RegisteredFunction.actionLayer"],"sources":["../src/RegisteredNodeFunction.ts"],"sourcesContent":["import { NodeContext } from \"@effect/platform-node\";\nimport {\n actionGeneric,\n type DefaultFunctionArgs,\n internalActionGeneric,\n} from \"convex/server\";\nimport type { Effect } from \"effect\";\nimport { Layer, Match, type Schema } from \"effect\";\nimport type * as Api from \"./Api\";\nimport type * as DatabaseSchema from \"./DatabaseSchema\";\nimport * as RegisteredFunction from \"./RegisteredFunction\";\nimport type * as RegistryItem from \"./RegistryItem\";\n\nexport const make = <Api_ extends Api.AnyWithPropsWithRuntime<\"Node\">>(\n api: Api_,\n { function_, handler }: RegistryItem.AnyWithProps,\n): RegisteredFunction.RegisteredFunction => {\n const genericFunction = Match.value(function_.functionVisibility).pipe(\n Match.when(\"public\", () => actionGeneric),\n Match.when(\"internal\", () => internalActionGeneric),\n Match.exhaustive,\n );\n\n return genericFunction(\n nodeActionFunction(api.databaseSchema, {\n args: function_.args,\n returns: function_.returns,\n handler,\n }),\n );\n};\n\nconst nodeActionFunction = <\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 | RegisteredFunction.ActionServices<DatabaseSchema_>\n | NodeContext.NodeContext\n >;\n },\n) =>\n RegisteredFunction.actionFunctionBase({\n args,\n returns,\n handler,\n createLayer: (ctx) =>\n Layer.mergeAll(\n RegisteredFunction.actionLayer(databaseSchema, ctx),\n NodeContext.layer,\n ),\n });\n"],"mappings":";;;;;;;;AAaA,MAAa,QACX,KACA,EAAE,WAAW,cAC6B;AAO1C,QANwB,MAAM,MAAM,UAAU,mBAAmB,CAAC,KAChE,MAAM,KAAK,gBAAgB,cAAc,EACzC,MAAM,KAAK,kBAAkB,sBAAsB,EACnD,MAAM,WACP,CAGC,mBAAmB,IAAI,gBAAgB;EACrC,MAAM,UAAU;EAChB,SAAS,UAAU;EACnB;EACD,CAAC,CACH;;AAGH,MAAM,sBAQJ,gBACA,EACE,MACA,SACA,cAcFA,mBAAsC;CACpC;CACA;CACA;CACA,cAAc,QACZ,MAAM,SACJC,YAA+B,gBAAgB,IAAI,EACnD,YAAY,MACb;CACJ,CAAC"}
package/dist/index.d.ts CHANGED
@@ -24,7 +24,9 @@ import { FunctionImpl_d_exports } from "./FunctionImpl.js";
24
24
  import { GroupImpl_d_exports } from "./GroupImpl.js";
25
25
  import { HttpApi_d_exports } from "./HttpApi.js";
26
26
  import { Impl_d_exports } from "./Impl.js";
27
- import { RegisteredFunctions_d_exports } from "./RegisteredFunctions.js";
27
+ import { RegisteredFunction_d_exports } from "./RegisteredFunction.js";
28
28
  import { RegistryItem_d_exports } from "./RegistryItem.js";
29
+ import { RegisteredConvexFunction_d_exports } from "./RegisteredConvexFunction.js";
30
+ import { RegisteredFunctions_d_exports } from "./RegisteredFunctions.js";
29
31
  import { Registry_d_exports } from "./Registry.js";
30
- export { ActionCtx_d_exports as ActionCtx, ActionRunner_d_exports as ActionRunner, Api_d_exports as Api, Auth_d_exports as Auth, DataModel_d_exports as DataModel, DatabaseReader_d_exports as DatabaseReader, DatabaseSchema_d_exports as DatabaseSchema, DatabaseWriter_d_exports as DatabaseWriter, Document_d_exports as Document, FunctionImpl_d_exports as FunctionImpl, GroupImpl_d_exports as GroupImpl, Handler_d_exports as Handler, HttpApi_d_exports as HttpApi, Impl_d_exports as Impl, MutationCtx_d_exports as MutationCtx, MutationRunner_d_exports as MutationRunner, OrderedQuery_d_exports as OrderedQuery, QueryCtx_d_exports as QueryCtx, QueryInitializer_d_exports as QueryInitializer, QueryRunner_d_exports as QueryRunner, RegisteredFunctions_d_exports as RegisteredFunctions, Registry_d_exports as Registry, RegistryItem_d_exports as RegistryItem, Scheduler_d_exports as Scheduler, SchemaToValidator_d_exports as SchemaToValidator, Storage_d_exports as Storage, Table_d_exports as Table, TableInfo_d_exports as TableInfo, VectorSearch_d_exports as VectorSearch };
32
+ export { ActionCtx_d_exports as ActionCtx, ActionRunner_d_exports as ActionRunner, Api_d_exports as Api, Auth_d_exports as Auth, DataModel_d_exports as DataModel, DatabaseReader_d_exports as DatabaseReader, DatabaseSchema_d_exports as DatabaseSchema, DatabaseWriter_d_exports as DatabaseWriter, Document_d_exports as Document, FunctionImpl_d_exports as FunctionImpl, GroupImpl_d_exports as GroupImpl, Handler_d_exports as Handler, HttpApi_d_exports as HttpApi, Impl_d_exports as Impl, MutationCtx_d_exports as MutationCtx, MutationRunner_d_exports as MutationRunner, OrderedQuery_d_exports as OrderedQuery, QueryCtx_d_exports as QueryCtx, QueryInitializer_d_exports as QueryInitializer, QueryRunner_d_exports as QueryRunner, RegisteredConvexFunction_d_exports as RegisteredConvexFunction, RegisteredFunction_d_exports as RegisteredFunction, RegisteredFunctions_d_exports as RegisteredFunctions, Registry_d_exports as Registry, RegistryItem_d_exports as RegistryItem, Scheduler_d_exports as Scheduler, SchemaToValidator_d_exports as SchemaToValidator, Storage_d_exports as Storage, Table_d_exports as Table, TableInfo_d_exports as TableInfo, VectorSearch_d_exports as VectorSearch };
package/dist/index.js CHANGED
@@ -25,7 +25,9 @@ import { Impl_exports } from "./Impl.js";
25
25
  import { MutationCtx_exports } from "./MutationCtx.js";
26
26
  import { QueryCtx_exports } from "./QueryCtx.js";
27
27
  import { VectorSearch_exports } from "./VectorSearch.js";
28
+ import { RegisteredFunction_exports } from "./RegisteredFunction.js";
29
+ import { RegisteredConvexFunction_exports } from "./RegisteredConvexFunction.js";
28
30
  import { RegisteredFunctions_exports } from "./RegisteredFunctions.js";
29
31
  import { TableInfo_exports } from "./TableInfo.js";
30
32
 
31
- export { ActionCtx_exports as ActionCtx, ActionRunner_exports as ActionRunner, Api_exports as Api, Auth_exports as Auth, DataModel_exports as DataModel, DatabaseReader_exports as DatabaseReader, DatabaseSchema_exports as DatabaseSchema, DatabaseWriter_exports as DatabaseWriter, Document_exports as Document, FunctionImpl_exports as FunctionImpl, GroupImpl_exports as GroupImpl, Handler_exports as Handler, HttpApi_exports as HttpApi, Impl_exports as Impl, MutationCtx_exports as MutationCtx, MutationRunner_exports as MutationRunner, OrderedQuery_exports as OrderedQuery, QueryCtx_exports as QueryCtx, QueryInitializer_exports as QueryInitializer, QueryRunner_exports as QueryRunner, RegisteredFunctions_exports as RegisteredFunctions, Registry_exports as Registry, RegistryItem_exports as RegistryItem, Scheduler_exports as Scheduler, SchemaToValidator_exports as SchemaToValidator, Storage_exports as Storage, Table_exports as Table, TableInfo_exports as TableInfo, VectorSearch_exports as VectorSearch };
33
+ export { ActionCtx_exports as ActionCtx, ActionRunner_exports as ActionRunner, Api_exports as Api, Auth_exports as Auth, DataModel_exports as DataModel, DatabaseReader_exports as DatabaseReader, DatabaseSchema_exports as DatabaseSchema, DatabaseWriter_exports as DatabaseWriter, Document_exports as Document, FunctionImpl_exports as FunctionImpl, GroupImpl_exports as GroupImpl, Handler_exports as Handler, HttpApi_exports as HttpApi, Impl_exports as Impl, MutationCtx_exports as MutationCtx, MutationRunner_exports as MutationRunner, OrderedQuery_exports as OrderedQuery, QueryCtx_exports as QueryCtx, QueryInitializer_exports as QueryInitializer, QueryRunner_exports as QueryRunner, RegisteredConvexFunction_exports as RegisteredConvexFunction, RegisteredFunction_exports as RegisteredFunction, RegisteredFunctions_exports as RegisteredFunctions, Registry_exports as Registry, RegistryItem_exports as RegistryItem, Scheduler_exports as Scheduler, SchemaToValidator_exports as SchemaToValidator, Storage_exports as Storage, Table_exports as Table, TableInfo_exports as TableInfo, VectorSearch_exports as VectorSearch };
package/dist/node.d.ts ADDED
@@ -0,0 +1,2 @@
1
+ import { RegisteredNodeFunction_d_exports } from "./RegisteredNodeFunction.js";
2
+ export { RegisteredNodeFunction_d_exports as RegisteredNodeFunction };
package/dist/node.js ADDED
@@ -0,0 +1,3 @@
1
+ import { RegisteredNodeFunction_exports } from "./RegisteredNodeFunction.js";
2
+
3
+ export { RegisteredNodeFunction_exports as RegisteredNodeFunction };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@confect/server",
3
- "version": "1.0.0-next.3",
3
+ "version": "1.0.0",
4
4
  "description": "Backend bindings to the Convex platform",
5
5
  "repository": {
6
6
  "type": "git",
@@ -30,7 +30,11 @@
30
30
  "default": "./dist/*.js"
31
31
  },
32
32
  "./package.json": "./package.json",
33
- "./internal/*": null
33
+ "./internal/*": null,
34
+ "./node": {
35
+ "types": "./dist/node.d.ts",
36
+ "default": "./dist/node.js"
37
+ }
34
38
  },
35
39
  "keywords": [
36
40
  "effect",
@@ -43,7 +47,6 @@
43
47
  "@effect/experimental": "0.58.0",
44
48
  "@effect/language-service": "0.73.1",
45
49
  "@effect/platform": "0.94.4",
46
- "@effect/platform-node": "0.104.1",
47
50
  "@effect/rpc": "0.73.0",
48
51
  "@effect/sql": "0.49.0",
49
52
  "@effect/vitest": "0.27.0",
@@ -63,14 +66,15 @@
63
66
  "vite": "7.3.1",
64
67
  "vite-tsconfig-paths": "6.1.1",
65
68
  "vitest": "3.2.4",
66
- "@confect/cli": "1.0.0-next.3",
67
- "@confect/test": "1.0.0-next.3"
69
+ "@confect/cli": "1.0.0",
70
+ "@confect/test": "1.0.0"
68
71
  },
69
72
  "peerDependencies": {
70
73
  "@effect/platform": "^0.94.4",
74
+ "@effect/platform-node": "^0.104.1",
71
75
  "convex": "^1.30.0",
72
76
  "effect": "^3.19.16",
73
- "@confect/core": "1.0.0-next.3"
77
+ "@confect/core": "1.0.0"
74
78
  },
75
79
  "engines": {
76
80
  "node": ">=22",
package/src/Api.ts CHANGED
@@ -1,3 +1,4 @@
1
+ import type { RuntimeAndFunctionType } from "@confect/core";
1
2
  import type * as Spec from "@confect/core/Spec";
2
3
  import type { GenericSchema, SchemaDefinition } from "convex/server";
3
4
  import { defineSchema as defineConvexSchema } from "convex/server";
@@ -28,8 +29,17 @@ export interface AnyWithProps extends Api<
28
29
  Spec.AnyWithProps
29
30
  > {}
30
31
 
32
+ export interface AnyWithPropsWithRuntime<
33
+ Runtime extends RuntimeAndFunctionType.Runtime,
34
+ > extends Api<
35
+ DatabaseSchema.AnyWithProps,
36
+ Spec.AnyWithPropsWithRuntime<Runtime>
37
+ > {}
38
+
31
39
  export type Schema<Api_ extends AnyWithProps> = Api_["databaseSchema"];
32
40
 
41
+ export type GetSpec<Api_ extends AnyWithProps> = Api_["spec"];
42
+
33
43
  export type Groups<Api_ extends AnyWithProps> = Spec.Groups<Api_["spec"]>;
34
44
 
35
45
  const Proto = {
package/src/Handler.ts CHANGED
@@ -1,4 +1,5 @@
1
- import type { FunctionSpec } from "@confect/core";
1
+ import type { FunctionSpec, RuntimeAndFunctionType } from "@confect/core";
2
+ import type { NodeContext } from "@effect/platform-node";
2
3
  import type { Effect } from "effect";
3
4
  import type * as ActionCtx from "./ActionCtx";
4
5
  import type * as ActionRunner from "./ActionRunner";
@@ -30,16 +31,22 @@ export type Handler<
30
31
  "mutation"
31
32
  >
32
33
  ? Mutation<DatabaseSchema_, FunctionSpec_>
33
- : FunctionSpec_ extends FunctionSpec.WithFunctionType<
34
+ : FunctionSpec_ extends FunctionSpec.WithRuntimeAndFunctionType<
34
35
  FunctionSpec_,
35
- "action"
36
+ RuntimeAndFunctionType.ConvexAction
36
37
  >
37
- ? Action<DatabaseSchema_, FunctionSpec_>
38
- : never;
38
+ ? ConvexAction<DatabaseSchema_, FunctionSpec_>
39
+ : FunctionSpec_ extends FunctionSpec.WithRuntimeAndFunctionType<
40
+ FunctionSpec_,
41
+ RuntimeAndFunctionType.NodeAction
42
+ >
43
+ ? NodeAction<DatabaseSchema_, FunctionSpec_>
44
+ : never;
39
45
 
40
46
  export type Query<
41
47
  DatabaseSchema_ extends DatabaseSchema.AnyWithProps,
42
- FunctionSpec_ extends FunctionSpec.AnyWithPropsWithFunctionType<"query">,
48
+ FunctionSpec_ extends
49
+ FunctionSpec.AnyWithPropsWithFunctionType<RuntimeAndFunctionType.AnyQuery>,
43
50
  > = Base<
44
51
  FunctionSpec_,
45
52
  | DatabaseReader.DatabaseReader<DatabaseSchema_>
@@ -51,7 +58,8 @@ export type Query<
51
58
 
52
59
  export type Mutation<
53
60
  DatabaseSchema_ extends DatabaseSchema.AnyWithProps,
54
- FunctionSpec_ extends FunctionSpec.AnyWithPropsWithFunctionType<"mutation">,
61
+ FunctionSpec_ extends
62
+ FunctionSpec.AnyWithPropsWithFunctionType<RuntimeAndFunctionType.AnyMutation>,
55
63
  > = Base<
56
64
  FunctionSpec_,
57
65
  | DatabaseReader.DatabaseReader<DatabaseSchema_>
@@ -67,11 +75,7 @@ export type Mutation<
67
75
  >
68
76
  >;
69
77
 
70
- export type Action<
71
- DatabaseSchema_ extends DatabaseSchema.AnyWithProps,
72
- FunctionSpec_ extends FunctionSpec.AnyWithPropsWithFunctionType<"action">,
73
- > = Base<
74
- FunctionSpec_,
78
+ type ActionServices<DatabaseSchema_ extends DatabaseSchema.AnyWithProps> =
75
79
  | Scheduler.Scheduler
76
80
  | Auth.Auth
77
81
  | StorageReader
@@ -83,7 +87,21 @@ export type Action<
83
87
  | VectorSearch.VectorSearch<DataModel.FromSchema<DatabaseSchema_>>
84
88
  | ActionCtx.ActionCtx<
85
89
  DataModel.ToConvex<DataModel.FromSchema<DatabaseSchema_>>
86
- >
90
+ >;
91
+
92
+ export type ConvexAction<
93
+ DatabaseSchema_ extends DatabaseSchema.AnyWithProps,
94
+ FunctionSpec_ extends
95
+ FunctionSpec.AnyWithPropsWithFunctionType<RuntimeAndFunctionType.AnyAction>,
96
+ > = Base<FunctionSpec_, ActionServices<DatabaseSchema_>>;
97
+
98
+ export type NodeAction<
99
+ DatabaseSchema_ extends DatabaseSchema.AnyWithProps,
100
+ FunctionSpec_ extends
101
+ FunctionSpec.AnyWithPropsWithFunctionType<RuntimeAndFunctionType.NodeAction>,
102
+ > = Base<
103
+ FunctionSpec_,
104
+ ActionServices<DatabaseSchema_> | NodeContext.NodeContext
87
105
  >;
88
106
 
89
107
  type Base<FunctionSpec_ extends FunctionSpec.AnyWithProps, R> = (
@@ -0,0 +1,252 @@
1
+ import {
2
+ actionGeneric,
3
+ type DefaultFunctionArgs,
4
+ type GenericMutationCtx,
5
+ type GenericQueryCtx,
6
+ internalActionGeneric,
7
+ internalMutationGeneric,
8
+ internalQueryGeneric,
9
+ mutationGeneric,
10
+ queryGeneric,
11
+ } from "convex/server";
12
+ import { Effect, Layer, Match, pipe, Schema } from "effect";
13
+ import type * as Api from "./Api";
14
+ import * as Auth from "./Auth";
15
+ import * as DatabaseReader from "./DatabaseReader";
16
+ import type * as DatabaseSchema from "./DatabaseSchema";
17
+ import * as DatabaseWriter from "./DatabaseWriter";
18
+ import type * as DataModel from "./DataModel";
19
+ import * as MutationCtx from "./MutationCtx";
20
+ import * as MutationRunner from "./MutationRunner";
21
+ import * as QueryCtx from "./QueryCtx";
22
+ import * as QueryRunner from "./QueryRunner";
23
+ import * as RegisteredFunction from "./RegisteredFunction";
24
+ import type * as RegistryItem from "./RegistryItem";
25
+ import * as Scheduler from "./Scheduler";
26
+ import * as SchemaToValidator from "./SchemaToValidator";
27
+ import { StorageReader, StorageWriter } from "./Storage";
28
+
29
+ export const make = <Api_ extends Api.AnyWithPropsWithRuntime<"Convex">>(
30
+ api: Api_,
31
+ { function_, handler }: RegistryItem.AnyWithProps,
32
+ ): RegisteredFunction.RegisteredFunction =>
33
+ Match.value(function_.runtimeAndFunctionType.functionType).pipe(
34
+ Match.when("query", () => {
35
+ const genericFunction = Match.value(function_.functionVisibility).pipe(
36
+ Match.when("public", () => queryGeneric),
37
+ Match.when("internal", () => internalQueryGeneric),
38
+ Match.exhaustive,
39
+ );
40
+
41
+ return genericFunction(
42
+ queryFunction(api.databaseSchema, {
43
+ args: function_.args,
44
+ returns: function_.returns,
45
+ handler,
46
+ }),
47
+ );
48
+ }),
49
+ Match.when("mutation", () => {
50
+ const genericFunction = Match.value(function_.functionVisibility).pipe(
51
+ Match.when("public", () => mutationGeneric),
52
+ Match.when("internal", () => internalMutationGeneric),
53
+ Match.exhaustive,
54
+ );
55
+
56
+ return genericFunction(
57
+ mutationFunction(api.databaseSchema, {
58
+ args: function_.args,
59
+ returns: function_.returns,
60
+ handler,
61
+ }),
62
+ );
63
+ }),
64
+ Match.when("action", () => {
65
+ const genericFunction = Match.value(function_.functionVisibility).pipe(
66
+ Match.when("public", () => actionGeneric),
67
+ Match.when("internal", () => internalActionGeneric),
68
+ Match.exhaustive,
69
+ );
70
+
71
+ return genericFunction(
72
+ convexActionFunction(api.databaseSchema, {
73
+ args: function_.args,
74
+ returns: function_.returns,
75
+ handler,
76
+ }),
77
+ );
78
+ }),
79
+ Match.exhaustive,
80
+ );
81
+
82
+ const queryFunction = <
83
+ DatabaseSchema_ extends DatabaseSchema.AnyWithProps,
84
+ Args,
85
+ ConvexArgs extends DefaultFunctionArgs,
86
+ Returns,
87
+ ConvexReturns,
88
+ E,
89
+ >(
90
+ databaseSchema: DatabaseSchema_,
91
+ {
92
+ args,
93
+ returns,
94
+ handler,
95
+ }: {
96
+ args: Schema.Schema<Args, ConvexArgs>;
97
+ returns: Schema.Schema<Returns, ConvexReturns>;
98
+ handler: (
99
+ a: Args,
100
+ ) => Effect.Effect<
101
+ Returns,
102
+ E,
103
+ | DatabaseReader.DatabaseReader<DatabaseSchema_>
104
+ | Auth.Auth
105
+ | StorageReader
106
+ | QueryRunner.QueryRunner
107
+ | QueryCtx.QueryCtx<
108
+ DataModel.ToConvex<DataModel.FromSchema<DatabaseSchema_>>
109
+ >
110
+ >;
111
+ },
112
+ ) => ({
113
+ args: SchemaToValidator.compileArgsSchema(args),
114
+ returns: SchemaToValidator.compileReturnsSchema(returns),
115
+ handler: (
116
+ ctx: GenericQueryCtx<
117
+ DataModel.ToConvex<DataModel.FromSchema<DatabaseSchema_>>
118
+ >,
119
+ actualArgs: ConvexArgs,
120
+ ): Promise<ConvexReturns> =>
121
+ pipe(
122
+ actualArgs,
123
+ Schema.decode(args),
124
+ Effect.orDie,
125
+ Effect.andThen((decodedArgs) =>
126
+ pipe(
127
+ handler(decodedArgs),
128
+ Effect.provide(
129
+ Layer.mergeAll(
130
+ DatabaseReader.layer(databaseSchema, ctx.db),
131
+ Auth.layer(ctx.auth),
132
+ StorageReader.layer(ctx.storage),
133
+ QueryRunner.layer(ctx.runQuery),
134
+ Layer.succeed(
135
+ QueryCtx.QueryCtx<
136
+ DataModel.ToConvex<DataModel.FromSchema<DatabaseSchema_>>
137
+ >(),
138
+ ctx,
139
+ ),
140
+ ),
141
+ ),
142
+ ),
143
+ ),
144
+ Effect.andThen((convexReturns) =>
145
+ Schema.encodeUnknown(returns)(convexReturns),
146
+ ),
147
+ Effect.runPromise,
148
+ ),
149
+ });
150
+
151
+ export const mutationLayer = <Schema extends DatabaseSchema.AnyWithProps>(
152
+ schema: Schema,
153
+ ctx: GenericMutationCtx<DataModel.ToConvex<DataModel.FromSchema<Schema>>>,
154
+ ) =>
155
+ Layer.mergeAll(
156
+ DatabaseReader.layer(schema, ctx.db),
157
+ DatabaseWriter.layer(schema, ctx.db),
158
+ Auth.layer(ctx.auth),
159
+ Scheduler.layer(ctx.scheduler),
160
+ StorageReader.layer(ctx.storage),
161
+ StorageWriter.layer(ctx.storage),
162
+ QueryRunner.layer(ctx.runQuery),
163
+ MutationRunner.layer(ctx.runMutation),
164
+ Layer.succeed(
165
+ MutationCtx.MutationCtx<
166
+ DataModel.ToConvex<DataModel.FromSchema<Schema>>
167
+ >(),
168
+ ctx,
169
+ ),
170
+ );
171
+
172
+ export type MutationServices<Schema extends DatabaseSchema.AnyWithProps> =
173
+ | DatabaseReader.DatabaseReader<Schema>
174
+ | DatabaseWriter.DatabaseWriter<Schema>
175
+ | Auth.Auth
176
+ | Scheduler.Scheduler
177
+ | StorageReader
178
+ | StorageWriter
179
+ | QueryRunner.QueryRunner
180
+ | MutationRunner.MutationRunner
181
+ | MutationCtx.MutationCtx<DataModel.ToConvex<DataModel.FromSchema<Schema>>>;
182
+
183
+ const mutationFunction = <
184
+ Schema extends DatabaseSchema.AnyWithProps,
185
+ Args,
186
+ ConvexArgs extends DefaultFunctionArgs,
187
+ Returns,
188
+ ConvexReturns,
189
+ E,
190
+ >(
191
+ schema: Schema,
192
+ {
193
+ args,
194
+ returns,
195
+ handler,
196
+ }: {
197
+ args: Schema.Schema<Args, ConvexArgs>;
198
+ returns: Schema.Schema<Returns, ConvexReturns>;
199
+ handler: (a: Args) => Effect.Effect<Returns, E, MutationServices<Schema>>;
200
+ },
201
+ ) => ({
202
+ args: SchemaToValidator.compileArgsSchema(args),
203
+ returns: SchemaToValidator.compileReturnsSchema(returns),
204
+ handler: (
205
+ ctx: GenericMutationCtx<DataModel.ToConvex<DataModel.FromSchema<Schema>>>,
206
+ actualArgs: ConvexArgs,
207
+ ): Promise<ConvexReturns> =>
208
+ pipe(
209
+ actualArgs,
210
+ Schema.decode(args),
211
+ Effect.orDie,
212
+ Effect.andThen((decodedArgs) =>
213
+ handler(decodedArgs).pipe(Effect.provide(mutationLayer(schema, ctx))),
214
+ ),
215
+ Effect.andThen((convexReturns) =>
216
+ Schema.encodeUnknown(returns)(convexReturns),
217
+ ),
218
+ Effect.runPromise,
219
+ ),
220
+ });
221
+
222
+ const convexActionFunction = <
223
+ DatabaseSchema_ extends DatabaseSchema.AnyWithProps,
224
+ Args,
225
+ ConvexArgs extends DefaultFunctionArgs,
226
+ Returns,
227
+ ConvexReturns,
228
+ E,
229
+ >(
230
+ schema: DatabaseSchema_,
231
+ {
232
+ args,
233
+ returns,
234
+ handler,
235
+ }: {
236
+ args: Schema.Schema<Args, ConvexArgs>;
237
+ returns: Schema.Schema<Returns, ConvexReturns>;
238
+ handler: (
239
+ a: Args,
240
+ ) => Effect.Effect<
241
+ Returns,
242
+ E,
243
+ RegisteredFunction.ActionServices<DatabaseSchema_>
244
+ >;
245
+ },
246
+ ) =>
247
+ RegisteredFunction.actionFunctionBase({
248
+ args,
249
+ returns,
250
+ handler,
251
+ createLayer: (ctx) => RegisteredFunction.actionLayer(schema, ctx),
252
+ });
@@ -0,0 +1,108 @@
1
+ import {
2
+ type DefaultFunctionArgs,
3
+ type FunctionVisibility,
4
+ type GenericActionCtx,
5
+ type RegisteredAction,
6
+ type RegisteredMutation,
7
+ type RegisteredQuery,
8
+ } from "convex/server";
9
+ import { Effect, Layer, pipe, Schema } from "effect";
10
+ import * as ActionCtx from "./ActionCtx";
11
+ import * as ActionRunner from "./ActionRunner";
12
+ import * as Auth from "./Auth";
13
+ import type * as DatabaseSchema from "./DatabaseSchema";
14
+ import type * as DataModel from "./DataModel";
15
+ import * as MutationRunner from "./MutationRunner";
16
+ import * as QueryRunner from "./QueryRunner";
17
+ import * as Scheduler from "./Scheduler";
18
+ import * as SchemaToValidator from "./SchemaToValidator";
19
+ import { StorageActionWriter, StorageReader, StorageWriter } from "./Storage";
20
+ import * as VectorSearch from "./VectorSearch";
21
+
22
+ export type RegisteredFunction =
23
+ | RegisteredQuery<FunctionVisibility, DefaultFunctionArgs, any>
24
+ | RegisteredMutation<FunctionVisibility, DefaultFunctionArgs, any>
25
+ | RegisteredAction<FunctionVisibility, DefaultFunctionArgs, any>;
26
+
27
+ export const actionFunctionBase = <
28
+ Schema extends DatabaseSchema.AnyWithProps,
29
+ Args,
30
+ ConvexArgs extends DefaultFunctionArgs,
31
+ Returns,
32
+ ConvexReturns,
33
+ E,
34
+ R,
35
+ >({
36
+ args,
37
+ returns,
38
+ handler,
39
+ createLayer,
40
+ }: {
41
+ args: Schema.Schema<Args, ConvexArgs>;
42
+ returns: Schema.Schema<Returns, ConvexReturns>;
43
+ handler: (a: Args) => Effect.Effect<Returns, E, R>;
44
+ createLayer: (
45
+ ctx: GenericActionCtx<DataModel.ToConvex<DataModel.FromSchema<Schema>>>,
46
+ ) => Layer.Layer<R>;
47
+ }) => ({
48
+ args: SchemaToValidator.compileArgsSchema(args),
49
+ returns: SchemaToValidator.compileReturnsSchema(returns),
50
+ handler: (
51
+ ctx: GenericActionCtx<DataModel.ToConvex<DataModel.FromSchema<Schema>>>,
52
+ actualArgs: ConvexArgs,
53
+ ): Promise<ConvexReturns> =>
54
+ pipe(
55
+ actualArgs,
56
+ Schema.decode(args),
57
+ Effect.orDie,
58
+ Effect.andThen((decodedArgs) =>
59
+ handler(decodedArgs).pipe(Effect.provide(createLayer(ctx))),
60
+ ),
61
+ Effect.andThen((convexReturns) =>
62
+ Schema.encodeUnknown(returns)(convexReturns),
63
+ ),
64
+ Effect.runPromise,
65
+ ),
66
+ });
67
+
68
+ export type ActionServices<
69
+ DatabaseSchema_ extends DatabaseSchema.AnyWithProps,
70
+ > =
71
+ | Scheduler.Scheduler
72
+ | Auth.Auth
73
+ | StorageReader
74
+ | StorageWriter
75
+ | StorageActionWriter
76
+ | QueryRunner.QueryRunner
77
+ | MutationRunner.MutationRunner
78
+ | ActionRunner.ActionRunner
79
+ | VectorSearch.VectorSearch<DataModel.FromSchema<DatabaseSchema_>>
80
+ | ActionCtx.ActionCtx<
81
+ DataModel.ToConvex<DataModel.FromSchema<DatabaseSchema_>>
82
+ >;
83
+
84
+ export const actionLayer = <
85
+ DatabaseSchema_ extends DatabaseSchema.AnyWithProps,
86
+ >(
87
+ databaseSchema: DatabaseSchema_,
88
+ ctx: GenericActionCtx<
89
+ DataModel.ToConvex<DataModel.FromSchema<DatabaseSchema_>>
90
+ >,
91
+ ) =>
92
+ Layer.mergeAll(
93
+ Scheduler.layer(ctx.scheduler),
94
+ Auth.layer(ctx.auth),
95
+ StorageReader.layer(ctx.storage),
96
+ StorageWriter.layer(ctx.storage),
97
+ StorageActionWriter.layer(ctx.storage),
98
+ QueryRunner.layer(ctx.runQuery),
99
+ MutationRunner.layer(ctx.runMutation),
100
+ ActionRunner.layer(ctx.runAction),
101
+ VectorSearch.layer(ctx.vectorSearch),
102
+ Layer.succeed(
103
+ ActionCtx.ActionCtx<
104
+ DataModel.ToConvex<DataModel.FromSchema<DatabaseSchema_>>
105
+ >(),
106
+ ctx,
107
+ ),
108
+ );