@confect/server 6.0.0 → 7.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.
- package/CHANGELOG.md +128 -1
- package/dist/ActionRunner.d.ts +3 -5
- package/dist/ActionRunner.d.ts.map +1 -1
- package/dist/ActionRunner.js.map +1 -1
- package/dist/DatabaseReader.d.ts +1 -1
- package/dist/Handler.d.ts +1 -1
- package/dist/Handler.d.ts.map +1 -1
- package/dist/Handler.js.map +1 -1
- package/dist/MutationRunner.d.ts +5 -16
- package/dist/MutationRunner.d.ts.map +1 -1
- package/dist/MutationRunner.js +2 -12
- package/dist/MutationRunner.js.map +1 -1
- package/dist/QueryRunner.d.ts +3 -5
- package/dist/QueryRunner.d.ts.map +1 -1
- package/dist/QueryRunner.js.map +1 -1
- package/dist/RegisteredConvexFunction.d.ts +6 -6
- package/dist/RegisteredConvexFunction.d.ts.map +1 -1
- package/dist/RegisteredConvexFunction.js +18 -8
- package/dist/RegisteredConvexFunction.js.map +1 -1
- package/dist/RegisteredFunction.d.ts +24 -5
- package/dist/RegisteredFunction.d.ts.map +1 -1
- package/dist/RegisteredFunction.js +34 -5
- package/dist/RegisteredFunction.js.map +1 -1
- package/dist/RegisteredNodeFunction.js +3 -1
- package/dist/RegisteredNodeFunction.js.map +1 -1
- package/package.json +5 -5
- package/src/ActionRunner.ts +5 -1
- package/src/Handler.ts +5 -1
- package/src/MutationRunner.ts +6 -16
- package/src/QueryRunner.ts +5 -1
- package/src/RegisteredConvexFunction.ts +95 -79
- package/src/RegisteredFunction.ts +67 -22
- package/src/RegisteredNodeFunction.ts +4 -0
|
@@ -16,14 +16,15 @@ 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
|
|
19
|
+
import { Value } from "convex/values";
|
|
20
20
|
import * as FunctionProvenance from "@confect/core/FunctionProvenance";
|
|
21
|
+
import * as effect_ParseResult0 from "effect/ParseResult";
|
|
21
22
|
import * as effect_Duration0 from "effect/Duration";
|
|
22
23
|
import * as effect_DateTime0 from "effect/DateTime";
|
|
23
24
|
|
|
24
25
|
//#region src/RegisteredFunction.d.ts
|
|
25
26
|
declare namespace RegisteredFunction_d_exports {
|
|
26
|
-
export { ActionServices, Any, ConvexRegisteredFunction, RegisteredFunction, actionFunctionBase, actionLayer };
|
|
27
|
+
export { ActionServices, Any, ConvexRegisteredFunction, RegisteredFunction, actionFunctionBase, actionLayer, runHandlerPromise };
|
|
27
28
|
}
|
|
28
29
|
type Any = RegisteredQuery<FunctionVisibility, DefaultFunctionArgs, any> | RegisteredMutation<FunctionVisibility, DefaultFunctionArgs, any> | RegisteredAction<FunctionVisibility, DefaultFunctionArgs, any>;
|
|
29
30
|
type ConfectRegisteredFunction<FunctionSpec_ extends FunctionSpec.AnyWithProps> = FunctionSpec.EncodedArgs<FunctionSpec_> extends infer Args_ extends DefaultFunctionArgs ? RuntimeAndFunctionType.GetFunctionType<FunctionSpec_["runtimeAndFunctionType"]> extends "query" ? RegisteredQuery<FunctionSpec.GetFunctionVisibility<FunctionSpec_>, Args_, Promise<FunctionSpec.EncodedReturns<FunctionSpec_>>> : RuntimeAndFunctionType.GetFunctionType<FunctionSpec_["runtimeAndFunctionType"]> extends "mutation" ? RegisteredMutation<FunctionSpec.GetFunctionVisibility<FunctionSpec_>, Args_, Promise<FunctionSpec.EncodedReturns<FunctionSpec_>>> : RuntimeAndFunctionType.GetFunctionType<FunctionSpec_["runtimeAndFunctionType"]> extends "action" ? RegisteredAction<FunctionSpec.GetFunctionVisibility<FunctionSpec_>, Args_, Promise<FunctionSpec.EncodedReturns<FunctionSpec_>>> : never : never;
|
|
@@ -35,14 +36,32 @@ type ConvexRegisteredFunction<FunctionSpec_ extends FunctionSpec.AnyWithProps> =
|
|
|
35
36
|
};
|
|
36
37
|
} ? RuntimeAndFunctionType.GetFunctionType<FunctionSpec_["runtimeAndFunctionType"]> extends "query" ? RegisteredQuery<FunctionSpec.GetFunctionVisibility<FunctionSpec_>, Args_, Returns_> : RuntimeAndFunctionType.GetFunctionType<FunctionSpec_["runtimeAndFunctionType"]> extends "mutation" ? RegisteredMutation<FunctionSpec.GetFunctionVisibility<FunctionSpec_>, Args_, Returns_> : RuntimeAndFunctionType.GetFunctionType<FunctionSpec_["runtimeAndFunctionType"]> extends "action" ? RegisteredAction<FunctionSpec.GetFunctionVisibility<FunctionSpec_>, Args_, Returns_> : never : never;
|
|
37
38
|
type RegisteredFunction<FunctionSpec_ extends FunctionSpec.AnyWithProps> = FunctionSpec_ extends FunctionSpec.WithFunctionProvenance<FunctionSpec_, FunctionProvenance.AnyConvex> ? ConvexRegisteredFunction<FunctionSpec_> : FunctionSpec_ extends FunctionSpec.WithFunctionProvenance<FunctionSpec_, FunctionProvenance.AnyConfect> ? ConfectRegisteredFunction<FunctionSpec_> : never;
|
|
39
|
+
/**
|
|
40
|
+
* Run the `Effect` as a `Promise`. The error schema acts as an allowlist of
|
|
41
|
+
* failures that may be surfaced to the client as a `ConvexError`:
|
|
42
|
+
*
|
|
43
|
+
* - With a schema: typed errors are schema-encoded and wrapped in a
|
|
44
|
+
* `ConvexError`, then thrown so Convex surfaces the data to the client.
|
|
45
|
+
* `Effect.either` escapes the failure channel before `runPromise` so the thrown
|
|
46
|
+
* `ConvexError` retains its `Symbol.for("ConvexError")` identity instead of
|
|
47
|
+
* being wrapped in Effect's `FiberFailure`.
|
|
48
|
+
*
|
|
49
|
+
* - Without a schema: every failure is converted to a defect via
|
|
50
|
+
* `Effect.orDie`, so nothing—not even a `ConvexError` the handler placed in its
|
|
51
|
+
* error channel—reaches the client as a `ConvexError`. The fiber dies and
|
|
52
|
+
* `runPromise` rejects with a generic failure.
|
|
53
|
+
*/
|
|
54
|
+
declare const runHandlerPromise: (errorSchema: Schema.Schema.AnyNoContext | undefined) => <A, E>(effect: Effect.Effect<A, E>) => Promise<A>;
|
|
38
55
|
declare const actionFunctionBase: <Schema extends AnyWithProps, Args, ConvexArgs extends DefaultFunctionArgs, Returns, ConvexReturns, E, R>({
|
|
39
56
|
args,
|
|
40
57
|
returns,
|
|
58
|
+
error,
|
|
41
59
|
handler,
|
|
42
60
|
createLayer
|
|
43
61
|
}: {
|
|
44
62
|
args: Schema.Schema<Args, ConvexArgs>;
|
|
45
63
|
returns: Schema.Schema<Returns, ConvexReturns>;
|
|
64
|
+
error: Schema.Schema<Error, Value> | undefined;
|
|
46
65
|
handler: (a: Args) => Effect.Effect<Returns, E, R>;
|
|
47
66
|
createLayer: (ctx: GenericActionCtx<ToConvex<FromSchema<Schema>>>) => Layer.Layer<R>;
|
|
48
67
|
}) => {
|
|
@@ -51,10 +70,10 @@ declare const actionFunctionBase: <Schema extends AnyWithProps, Args, ConvexArgs
|
|
|
51
70
|
handler: (ctx: GenericActionCtx<ToConvex<FromSchema<Schema>>>, actualArgs: ConvexArgs) => Promise<ConvexReturns>;
|
|
52
71
|
};
|
|
53
72
|
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<(<Action extends _confect_core_Ref0.AnyAction>(action: Action, ...args: _confect_core_Ref0.OptionalArgs<Action>) => Effect.Effect<_confect_core_Ref0.Returns<Action>, effect_ParseResult0.ParseError,
|
|
73
|
+
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>, _confect_core_Ref0.Error<Action> | effect_ParseResult0.ParseError>) | Auth$1 | StorageReader$1 | StorageWriter$1 | (<Query extends _confect_core_Ref0.AnyQuery>(query: Query, ...args: _confect_core_Ref0.OptionalArgs<Query>) => Effect.Effect<_confect_core_Ref0.Returns<Query>, _confect_core_Ref0.Error<Query> | effect_ParseResult0.ParseError>) | {
|
|
55
74
|
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
75
|
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
|
-
} |
|
|
76
|
+
} | (<Mutation extends _confect_core_Ref0.AnyMutation>(mutation: Mutation, ...args: _confect_core_Ref0.OptionalArgs<Mutation>) => Effect.Effect<_confect_core_Ref0.Returns<Mutation>, _confect_core_Ref0.Error<Mutation> | effect_ParseResult0.ParseError>) | GenericActionCtx<ToConvex<FromSchema<DatabaseSchema_>>> | StorageActionWriter$1 | (<TableName extends TableNames<FromSchema<DatabaseSchema_>>, IndexName extends keyof convex_server0.VectorIndexes<convex_server0.NamedTableInfo<ToConvex<FromSchema<DatabaseSchema_>>, TableName>>>(tableName: TableName, indexName: IndexName, query: {
|
|
58
77
|
vector: number[];
|
|
59
78
|
limit?: number;
|
|
60
79
|
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>;
|
|
@@ -63,5 +82,5 @@ declare const actionLayer: <DatabaseSchema_ extends AnyWithProps>(databaseSchema
|
|
|
63
82
|
_score: number;
|
|
64
83
|
}[], never, never>), never, never>;
|
|
65
84
|
//#endregion
|
|
66
|
-
export { ActionServices, Any, ConvexRegisteredFunction, RegisteredFunction, RegisteredFunction_d_exports, actionFunctionBase, actionLayer };
|
|
85
|
+
export { ActionServices, Any, ConvexRegisteredFunction, RegisteredFunction, RegisteredFunction_d_exports, actionFunctionBase, actionLayer, runHandlerPromise };
|
|
67
86
|
//# sourceMappingURL=RegisteredFunction.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"RegisteredFunction.d.ts","names":[],"sources":["../src/RegisteredFunction.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"RegisteredFunction.d.ts","names":[],"sources":["../src/RegisteredFunction.ts"],"mappings":"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"}
|
|
@@ -10,21 +10,50 @@ import { StorageActionWriter as StorageActionWriter$1 } from "./StorageActionWri
|
|
|
10
10
|
import { StorageReader as StorageReader$1 } from "./StorageReader.js";
|
|
11
11
|
import { StorageWriter as StorageWriter$1 } from "./StorageWriter.js";
|
|
12
12
|
import { layer as layer$5 } from "./VectorSearch.js";
|
|
13
|
-
import { Effect, Layer, Schema, pipe } from "effect";
|
|
13
|
+
import { Effect, Either, Layer, Schema, pipe } from "effect";
|
|
14
14
|
import "convex/server";
|
|
15
|
+
import { ConvexError } from "convex/values";
|
|
15
16
|
|
|
16
17
|
//#region src/RegisteredFunction.ts
|
|
17
18
|
var RegisteredFunction_exports = /* @__PURE__ */ __exportAll({
|
|
18
19
|
actionFunctionBase: () => actionFunctionBase,
|
|
19
|
-
actionLayer: () => actionLayer
|
|
20
|
+
actionLayer: () => actionLayer,
|
|
21
|
+
runHandlerPromise: () => runHandlerPromise
|
|
20
22
|
});
|
|
21
|
-
|
|
23
|
+
/**
|
|
24
|
+
* Run the `Effect` as a `Promise`. The error schema acts as an allowlist of
|
|
25
|
+
* failures that may be surfaced to the client as a `ConvexError`:
|
|
26
|
+
*
|
|
27
|
+
* - With a schema: typed errors are schema-encoded and wrapped in a
|
|
28
|
+
* `ConvexError`, then thrown so Convex surfaces the data to the client.
|
|
29
|
+
* `Effect.either` escapes the failure channel before `runPromise` so the thrown
|
|
30
|
+
* `ConvexError` retains its `Symbol.for("ConvexError")` identity instead of
|
|
31
|
+
* being wrapped in Effect's `FiberFailure`.
|
|
32
|
+
*
|
|
33
|
+
* - Without a schema: every failure is converted to a defect via
|
|
34
|
+
* `Effect.orDie`, so nothing—not even a `ConvexError` the handler placed in its
|
|
35
|
+
* error channel—reaches the client as a `ConvexError`. The fiber dies and
|
|
36
|
+
* `runPromise` rejects with a generic failure.
|
|
37
|
+
*/
|
|
38
|
+
const runHandlerPromise = (errorSchema) => (effect) => {
|
|
39
|
+
if (errorSchema === void 0) return Effect.runPromise(Effect.orDie(effect));
|
|
40
|
+
const withConvexError = effect.pipe(Effect.catchAll((typedError) => pipe(Schema.encode(errorSchema)(typedError), Effect.orDie, Effect.andThen((encodedError) => Effect.fail(new ConvexError(encodedError))))));
|
|
41
|
+
return Effect.runPromise(Effect.either(withConvexError)).then(Either.match({
|
|
42
|
+
onLeft: (error) => {
|
|
43
|
+
throw error;
|
|
44
|
+
},
|
|
45
|
+
onRight: (value) => value
|
|
46
|
+
}));
|
|
47
|
+
};
|
|
48
|
+
const actionFunctionBase = ({ args, returns, error, handler, createLayer }) => ({
|
|
22
49
|
args: compileArgsSchema(args),
|
|
23
50
|
returns: compileReturnsSchema(returns),
|
|
24
|
-
handler: (ctx, actualArgs) =>
|
|
51
|
+
handler: (ctx, actualArgs) => Effect.gen(function* () {
|
|
52
|
+
return yield* pipe(yield* handler(yield* pipe(actualArgs, Schema.decode(args), Effect.orDie)).pipe(Effect.provide(createLayer(ctx))), Schema.encode(returns), Effect.orDie);
|
|
53
|
+
}).pipe(runHandlerPromise(error))
|
|
25
54
|
});
|
|
26
55
|
const actionLayer = (databaseSchema, ctx) => Layer.mergeAll(layer$4(ctx.scheduler), layer$1(ctx.auth), StorageReader$1.layer(ctx.storage), StorageWriter$1.layer(ctx.storage), StorageActionWriter$1.layer(ctx.storage), layer$3(ctx.runQuery), layer$2(ctx.runMutation), layer(ctx.runAction), layer$5(ctx.vectorSearch), Layer.succeed(ActionCtx(), ctx));
|
|
27
56
|
|
|
28
57
|
//#endregion
|
|
29
|
-
export { RegisteredFunction_exports, actionFunctionBase, actionLayer };
|
|
58
|
+
export { RegisteredFunction_exports, actionFunctionBase, actionLayer, runHandlerPromise };
|
|
30
59
|
//# sourceMappingURL=RegisteredFunction.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"RegisteredFunction.js","names":["SchemaToValidator.compileArgsSchema","SchemaToValidator.compileReturnsSchema","Scheduler.layer","Auth.layer","
|
|
1
|
+
{"version":3,"file":"RegisteredFunction.js","names":["SchemaToValidator.compileArgsSchema","SchemaToValidator.compileReturnsSchema","Scheduler.layer","Auth.layer","QueryRunner.layer","MutationRunner.layer","ActionRunner.layer","VectorSearch.layer","ActionCtx.ActionCtx"],"sources":["../src/RegisteredFunction.ts"],"sourcesContent":["import type { FunctionSpec, RuntimeAndFunctionType } from \"@confect/core\";\nimport type * as FunctionProvenance from \"@confect/core/FunctionProvenance\";\nimport {\n type DefaultFunctionArgs,\n type FunctionVisibility,\n type GenericActionCtx,\n type RegisteredAction,\n type RegisteredMutation,\n type RegisteredQuery,\n} from \"convex/server\";\nimport type { Value } from \"convex/values\";\nimport { ConvexError } from \"convex/values\";\nimport { Effect, Either, Layer, pipe, Schema } from \"effect\";\nimport * as ActionCtx from \"./ActionCtx\";\nimport * as ActionRunner from \"./ActionRunner\";\nimport * as Auth from \"./Auth\";\nimport type * as DatabaseSchema from \"./DatabaseSchema\";\nimport type * as DataModel from \"./DataModel\";\nimport * as MutationRunner from \"./MutationRunner\";\nimport * as QueryRunner from \"./QueryRunner\";\nimport * as Scheduler from \"./Scheduler\";\nimport * as SchemaToValidator from \"./SchemaToValidator\";\nimport * as StorageActionWriter from \"./StorageActionWriter\";\nimport * as StorageReader from \"./StorageReader\";\nimport * as StorageWriter from \"./StorageWriter\";\nimport * as VectorSearch from \"./VectorSearch\";\n\nexport type Any =\n | RegisteredQuery<FunctionVisibility, DefaultFunctionArgs, any>\n | RegisteredMutation<FunctionVisibility, DefaultFunctionArgs, any>\n | RegisteredAction<FunctionVisibility, DefaultFunctionArgs, any>;\n\ntype ConfectRegisteredFunction<\n FunctionSpec_ extends FunctionSpec.AnyWithProps,\n> =\n FunctionSpec.EncodedArgs<FunctionSpec_> extends infer Args_ extends\n DefaultFunctionArgs\n ? RuntimeAndFunctionType.GetFunctionType<\n FunctionSpec_[\"runtimeAndFunctionType\"]\n > extends \"query\"\n ? RegisteredQuery<\n FunctionSpec.GetFunctionVisibility<FunctionSpec_>,\n Args_,\n Promise<FunctionSpec.EncodedReturns<FunctionSpec_>>\n >\n : RuntimeAndFunctionType.GetFunctionType<\n FunctionSpec_[\"runtimeAndFunctionType\"]\n > extends \"mutation\"\n ? RegisteredMutation<\n FunctionSpec.GetFunctionVisibility<FunctionSpec_>,\n Args_,\n Promise<FunctionSpec.EncodedReturns<FunctionSpec_>>\n >\n : RuntimeAndFunctionType.GetFunctionType<\n FunctionSpec_[\"runtimeAndFunctionType\"]\n > extends \"action\"\n ? RegisteredAction<\n FunctionSpec.GetFunctionVisibility<FunctionSpec_>,\n Args_,\n Promise<FunctionSpec.EncodedReturns<FunctionSpec_>>\n >\n : never\n : never;\n\nexport type ConvexRegisteredFunction<\n FunctionSpec_ extends FunctionSpec.AnyWithProps,\n> = FunctionSpec_ extends {\n functionProvenance: {\n _tag: \"Convex\";\n _args: infer Args_ extends DefaultFunctionArgs;\n _returns: infer Returns_;\n };\n}\n ? RuntimeAndFunctionType.GetFunctionType<\n FunctionSpec_[\"runtimeAndFunctionType\"]\n > extends \"query\"\n ? RegisteredQuery<\n FunctionSpec.GetFunctionVisibility<FunctionSpec_>,\n Args_,\n Returns_\n >\n : RuntimeAndFunctionType.GetFunctionType<\n FunctionSpec_[\"runtimeAndFunctionType\"]\n > extends \"mutation\"\n ? RegisteredMutation<\n FunctionSpec.GetFunctionVisibility<FunctionSpec_>,\n Args_,\n Returns_\n >\n : RuntimeAndFunctionType.GetFunctionType<\n FunctionSpec_[\"runtimeAndFunctionType\"]\n > extends \"action\"\n ? RegisteredAction<\n FunctionSpec.GetFunctionVisibility<FunctionSpec_>,\n Args_,\n Returns_\n >\n : never\n : never;\n\nexport type RegisteredFunction<\n FunctionSpec_ extends FunctionSpec.AnyWithProps,\n> =\n FunctionSpec_ extends FunctionSpec.WithFunctionProvenance<\n FunctionSpec_,\n FunctionProvenance.AnyConvex\n >\n ? ConvexRegisteredFunction<FunctionSpec_>\n : FunctionSpec_ extends FunctionSpec.WithFunctionProvenance<\n FunctionSpec_,\n FunctionProvenance.AnyConfect\n >\n ? ConfectRegisteredFunction<FunctionSpec_>\n : never;\n\n/**\n * Run the `Effect` as a `Promise`. The error schema acts as an allowlist of\n * failures that may be surfaced to the client as a `ConvexError`:\n *\n * - With a schema: typed errors are schema-encoded and wrapped in a\n * `ConvexError`, then thrown so Convex surfaces the data to the client.\n * `Effect.either` escapes the failure channel before `runPromise` so the thrown\n * `ConvexError` retains its `Symbol.for(\"ConvexError\")` identity instead of\n * being wrapped in Effect's `FiberFailure`.\n *\n * - Without a schema: every failure is converted to a defect via\n * `Effect.orDie`, so nothing—not even a `ConvexError` the handler placed in its\n * error channel—reaches the client as a `ConvexError`. The fiber dies and\n * `runPromise` rejects with a generic failure.\n */\nexport const runHandlerPromise =\n (errorSchema: Schema.Schema.AnyNoContext | undefined) =>\n <A, E>(effect: Effect.Effect<A, E>): Promise<A> => {\n if (errorSchema === undefined) {\n return Effect.runPromise(Effect.orDie(effect));\n }\n const withConvexError = effect.pipe(\n Effect.catchAll((typedError) =>\n pipe(\n Schema.encode(errorSchema)(typedError),\n Effect.orDie,\n Effect.andThen((encodedError) =>\n Effect.fail(new ConvexError(encodedError)),\n ),\n ),\n ),\n );\n return Effect.runPromise(Effect.either(withConvexError)).then(\n Either.match({\n onLeft: (error) => {\n throw error;\n },\n onRight: (value) => value,\n }),\n );\n };\n\nexport const actionFunctionBase = <\n Schema extends DatabaseSchema.AnyWithProps,\n Args,\n ConvexArgs extends DefaultFunctionArgs,\n Returns,\n ConvexReturns,\n E,\n R,\n>({\n args,\n returns,\n error,\n handler,\n createLayer,\n}: {\n args: Schema.Schema<Args, ConvexArgs>;\n returns: Schema.Schema<Returns, ConvexReturns>;\n error: Schema.Schema<Error, Value> | undefined;\n handler: (a: Args) => Effect.Effect<Returns, E, R>;\n createLayer: (\n ctx: GenericActionCtx<DataModel.ToConvex<DataModel.FromSchema<Schema>>>,\n ) => Layer.Layer<R>;\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 Effect.gen(function* () {\n const decodedArgs = yield* pipe(\n actualArgs,\n Schema.decode(args),\n Effect.orDie,\n );\n const decodedReturns = yield* handler(decodedArgs).pipe(\n Effect.provide(createLayer(ctx)),\n );\n return yield* pipe(decodedReturns, Schema.encode(returns), Effect.orDie);\n }).pipe(runHandlerPromise(error)),\n});\n\nexport type ActionServices<\n DatabaseSchema_ extends DatabaseSchema.AnyWithProps,\n> =\n | Scheduler.Scheduler\n | Auth.Auth\n | StorageReader.StorageReader\n | StorageWriter.StorageWriter\n | StorageActionWriter.StorageActionWriter\n | QueryRunner.QueryRunner\n | MutationRunner.MutationRunner\n | ActionRunner.ActionRunner\n | VectorSearch.VectorSearch<DataModel.FromSchema<DatabaseSchema_>>\n | ActionCtx.ActionCtx<\n DataModel.ToConvex<DataModel.FromSchema<DatabaseSchema_>>\n >;\n\nexport const actionLayer = <\n DatabaseSchema_ extends DatabaseSchema.AnyWithProps,\n>(\n databaseSchema: DatabaseSchema_,\n ctx: GenericActionCtx<\n DataModel.ToConvex<DataModel.FromSchema<DatabaseSchema_>>\n >,\n) =>\n Layer.mergeAll(\n Scheduler.layer(ctx.scheduler),\n Auth.layer(ctx.auth),\n StorageReader.StorageReader.layer(ctx.storage),\n StorageWriter.StorageWriter.layer(ctx.storage),\n StorageActionWriter.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<DatabaseSchema_>>\n >(),\n ctx,\n ),\n );\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAkIA,MAAa,qBACV,iBACM,WAA4C;AACjD,KAAI,gBAAgB,OAClB,QAAO,OAAO,WAAW,OAAO,MAAM,OAAO,CAAC;CAEhD,MAAM,kBAAkB,OAAO,KAC7B,OAAO,UAAU,eACf,KACE,OAAO,OAAO,YAAY,CAAC,WAAW,EACtC,OAAO,OACP,OAAO,SAAS,iBACd,OAAO,KAAK,IAAI,YAAY,aAAa,CAAC,CAC3C,CACF,CACF,CACF;AACD,QAAO,OAAO,WAAW,OAAO,OAAO,gBAAgB,CAAC,CAAC,KACvD,OAAO,MAAM;EACX,SAAS,UAAU;AACjB,SAAM;;EAER,UAAU,UAAU;EACrB,CAAC,CACH;;AAGL,MAAa,sBAQX,EACA,MACA,SACA,OACA,SACA,mBASK;CACL,MAAMA,kBAAoC,KAAK;CAC/C,SAASC,qBAAuC,QAAQ;CACxD,UACE,KACA,eAEA,OAAO,IAAI,aAAa;AAStB,SAAO,OAAO,KAHS,OAAO,QALV,OAAO,KACzB,YACA,OAAO,OAAO,KAAK,EACnB,OAAO,MACR,CACiD,CAAC,KACjD,OAAO,QAAQ,YAAY,IAAI,CAAC,CACjC,EACkC,OAAO,OAAO,QAAQ,EAAE,OAAO,MAAM;GACxE,CAAC,KAAK,kBAAkB,MAAM,CAAC;CACpC;AAkBD,MAAa,eAGX,gBACA,QAIA,MAAM,SACJC,QAAgB,IAAI,UAAU,EAC9BC,QAAW,IAAI,KAAK,kBACQ,MAAM,IAAI,QAAQ,kBAClB,MAAM,IAAI,QAAQ,wBACN,MAAM,IAAI,QAAQ,EAC1DC,QAAkB,IAAI,SAAS,EAC/BC,QAAqB,IAAI,YAAY,EACrCC,MAAmB,IAAI,UAAU,EACjCC,QAAmB,IAAI,aAAa,EACpC,MAAM,QACJC,WAEG,EACH,IACD,CACF"}
|
|
@@ -11,12 +11,14 @@ const make = (api, { functionSpec, handler }) => Match.value(functionSpec.functi
|
|
|
11
11
|
return Match.value(functionVisibility).pipe(Match.when("public", () => actionGeneric), Match.when("internal", () => internalActionGeneric), Match.exhaustive)(nodeActionFunction(api.databaseSchema, {
|
|
12
12
|
args: functionProvenance.args,
|
|
13
13
|
returns: functionProvenance.returns,
|
|
14
|
+
error: functionProvenance.error,
|
|
14
15
|
handler
|
|
15
16
|
}));
|
|
16
17
|
}), Match.exhaustive);
|
|
17
|
-
const nodeActionFunction = (databaseSchema, { args, returns, handler }) => actionFunctionBase({
|
|
18
|
+
const nodeActionFunction = (databaseSchema, { args, returns, error, handler }) => actionFunctionBase({
|
|
18
19
|
args,
|
|
19
20
|
returns,
|
|
21
|
+
error,
|
|
20
22
|
handler,
|
|
21
23
|
createLayer: (ctx) => Layer.mergeAll(actionLayer(databaseSchema, ctx), NodeContext.layer)
|
|
22
24
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"RegisteredNodeFunction.js","names":["RegisteredFunction.actionFunctionBase","RegisteredFunction.actionLayer"],"sources":["../src/RegisteredNodeFunction.ts"],"sourcesContent":["import type * as FunctionSpec from \"@confect/core/FunctionSpec\";\nimport { 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 type * as Handler from \"./Handler\";\nimport * as RegisteredFunction from \"./RegisteredFunction\";\nimport type * as RegistryItem from \"./RegistryItem\";\n\nexport const make = <Api_ extends Api.AnyWithPropsWithRuntime<\"Node\">>(\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 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 nodeActionFunction(api.databaseSchema, {\n args: functionProvenance.args,\n returns: functionProvenance.returns,\n handler: handler as Handler.AnyConfectProvenance,\n }),\n );\n }),\n Match.exhaustive,\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":";;;;;;;;AAeA,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;AAQF,QANwB,MAAM,MAAM,mBAAmB,CAAC,KACtD,MAAM,KAAK,gBAAgB,cAAc,EACzC,MAAM,KAAK,kBAAkB,sBAAsB,EACnD,MAAM,WACP,CAGC,mBAAmB,IAAI,gBAAgB;EACrC,MAAM,mBAAmB;EACzB,SAAS,mBAAmB;
|
|
1
|
+
{"version":3,"file":"RegisteredNodeFunction.js","names":["RegisteredFunction.actionFunctionBase","RegisteredFunction.actionLayer"],"sources":["../src/RegisteredNodeFunction.ts"],"sourcesContent":["import type * as FunctionSpec from \"@confect/core/FunctionSpec\";\nimport { 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 type * as Handler from \"./Handler\";\nimport * as RegisteredFunction from \"./RegisteredFunction\";\nimport type * as RegistryItem from \"./RegistryItem\";\n\nexport const make = <Api_ extends Api.AnyWithPropsWithRuntime<\"Node\">>(\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 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 nodeActionFunction(api.databaseSchema, {\n args: functionProvenance.args,\n returns: functionProvenance.returns,\n error: functionProvenance.error,\n handler: handler as Handler.AnyConfectProvenance,\n }),\n );\n }),\n Match.exhaustive,\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 error,\n handler,\n }: {\n args: Schema.Schema<Args, ConvexArgs>;\n returns: Schema.Schema<Returns, ConvexReturns>;\n error: Schema.Schema.AnyNoContext | undefined;\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 error,\n handler,\n createLayer: (ctx) =>\n Layer.mergeAll(\n RegisteredFunction.actionLayer(databaseSchema, ctx),\n NodeContext.layer,\n ),\n });\n"],"mappings":";;;;;;;;AAeA,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;AAQF,QANwB,MAAM,MAAM,mBAAmB,CAAC,KACtD,MAAM,KAAK,gBAAgB,cAAc,EACzC,MAAM,KAAK,kBAAkB,sBAAsB,EACnD,MAAM,WACP,CAGC,mBAAmB,IAAI,gBAAgB;EACrC,MAAM,mBAAmB;EACzB,SAAS,mBAAmB;EAC5B,OAAO,mBAAmB;EACjB;EACV,CAAC,CACH;EACD,EACF,MAAM,WACP;AAEH,MAAM,sBAQJ,gBACA,EACE,MACA,SACA,OACA,cAeFA,mBAAsC;CACpC;CACA;CACA;CACA;CACA,cAAc,QACZ,MAAM,SACJC,YAA+B,gBAAgB,IAAI,EACnD,YAAY,MACb;CACJ,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@confect/server",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "7.0.0",
|
|
4
4
|
"description": "Backend bindings to the Convex platform",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -55,7 +55,7 @@
|
|
|
55
55
|
"@swc/jest": "0.2.39",
|
|
56
56
|
"@types/node": "25.3.3",
|
|
57
57
|
"@vitest/coverage-v8": "3.2.4",
|
|
58
|
-
"convex-test": "0.0.
|
|
58
|
+
"convex-test": "0.0.50",
|
|
59
59
|
"dotenv": "17.3.1",
|
|
60
60
|
"effect": "3.19.19",
|
|
61
61
|
"eslint": "10.0.2",
|
|
@@ -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": "
|
|
71
|
-
"@confect/test": "
|
|
70
|
+
"@confect/cli": "7.0.0",
|
|
71
|
+
"@confect/test": "7.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": "
|
|
78
|
+
"@confect/core": "7.0.0"
|
|
79
79
|
},
|
|
80
80
|
"engines": {
|
|
81
81
|
"node": ">=22",
|
package/src/ActionRunner.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import * as Ref from "@confect/core/Ref";
|
|
2
2
|
import { type GenericActionCtx } from "convex/server";
|
|
3
|
+
import type { ParseResult, Effect } from "effect";
|
|
3
4
|
import { Context, Layer } from "effect";
|
|
4
5
|
|
|
5
6
|
const make =
|
|
@@ -7,7 +8,10 @@ const make =
|
|
|
7
8
|
<Action extends Ref.AnyAction>(
|
|
8
9
|
action: Action,
|
|
9
10
|
...args: Ref.OptionalArgs<Action>
|
|
10
|
-
)
|
|
11
|
+
): Effect.Effect<
|
|
12
|
+
Ref.Returns<Action>,
|
|
13
|
+
Ref.Error<Action> | ParseResult.ParseError
|
|
14
|
+
> =>
|
|
11
15
|
Ref.runWithCodec(
|
|
12
16
|
action,
|
|
13
17
|
(args[0] ?? {}) as Ref.Args<Action>,
|
package/src/Handler.ts
CHANGED
|
@@ -128,7 +128,11 @@ export type NodeRuntimeAction<
|
|
|
128
128
|
|
|
129
129
|
type Base<FunctionSpec_ extends FunctionSpec.AnyWithProps, R> = (
|
|
130
130
|
args: FunctionSpec.Args<FunctionSpec_>,
|
|
131
|
-
) => Effect.Effect<
|
|
131
|
+
) => Effect.Effect<
|
|
132
|
+
FunctionSpec.Returns<FunctionSpec_>,
|
|
133
|
+
FunctionSpec.Error<FunctionSpec_>,
|
|
134
|
+
R
|
|
135
|
+
>;
|
|
132
136
|
|
|
133
137
|
export type Any = AnyConfectProvenance | AnyConvexProvenance;
|
|
134
138
|
|
package/src/MutationRunner.ts
CHANGED
|
@@ -1,13 +1,17 @@
|
|
|
1
1
|
import * as Ref from "@confect/core/Ref";
|
|
2
2
|
import { type GenericMutationCtx } from "convex/server";
|
|
3
|
-
import {
|
|
3
|
+
import type { ParseResult, Effect } from "effect";
|
|
4
|
+
import { Context, Layer } from "effect";
|
|
4
5
|
|
|
5
6
|
const make =
|
|
6
7
|
(runMutation: GenericMutationCtx<any>["runMutation"]) =>
|
|
7
8
|
<Mutation extends Ref.AnyMutation>(
|
|
8
9
|
mutation: Mutation,
|
|
9
10
|
...args: Ref.OptionalArgs<Mutation>
|
|
10
|
-
)
|
|
11
|
+
): Effect.Effect<
|
|
12
|
+
Ref.Returns<Mutation>,
|
|
13
|
+
Ref.Error<Mutation> | ParseResult.ParseError
|
|
14
|
+
> =>
|
|
11
15
|
Ref.runWithCodec(
|
|
12
16
|
mutation,
|
|
13
17
|
(args[0] ?? {}) as Ref.Args<Mutation>,
|
|
@@ -22,17 +26,3 @@ export type MutationRunner = typeof MutationRunner.Identifier;
|
|
|
22
26
|
|
|
23
27
|
export const layer = (runMutation: GenericMutationCtx<any>["runMutation"]) =>
|
|
24
28
|
Layer.succeed(MutationRunner, make(runMutation));
|
|
25
|
-
|
|
26
|
-
export class MutationRollback extends Schema.TaggedError<MutationRollback>()(
|
|
27
|
-
"MutationRollback",
|
|
28
|
-
{
|
|
29
|
-
mutationName: Schema.String,
|
|
30
|
-
error: Schema.Unknown,
|
|
31
|
-
},
|
|
32
|
-
) {
|
|
33
|
-
/* v8 ignore start */
|
|
34
|
-
override get message(): string {
|
|
35
|
-
return `Mutation ${this.mutationName} failed and was rolled back.\n\n${this.error}`;
|
|
36
|
-
}
|
|
37
|
-
/* v8 ignore stop */
|
|
38
|
-
}
|
package/src/QueryRunner.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import * as Ref from "@confect/core/Ref";
|
|
2
2
|
import { type GenericQueryCtx } from "convex/server";
|
|
3
|
+
import type { ParseResult, Effect } from "effect";
|
|
3
4
|
import { Context, Layer } from "effect";
|
|
4
5
|
|
|
5
6
|
const make =
|
|
@@ -7,7 +8,10 @@ const make =
|
|
|
7
8
|
<Query extends Ref.AnyQuery>(
|
|
8
9
|
query: Query,
|
|
9
10
|
...args: Ref.OptionalArgs<Query>
|
|
10
|
-
)
|
|
11
|
+
): Effect.Effect<
|
|
12
|
+
Ref.Returns<Query>,
|
|
13
|
+
Ref.Error<Query> | ParseResult.ParseError
|
|
14
|
+
> =>
|
|
11
15
|
Ref.runWithCodec(
|
|
12
16
|
query,
|
|
13
17
|
(args[0] ?? {}) as Ref.Args<Query>,
|
|
@@ -10,6 +10,7 @@ import {
|
|
|
10
10
|
mutationGeneric,
|
|
11
11
|
queryGeneric,
|
|
12
12
|
} from "convex/server";
|
|
13
|
+
import type { Value } from "convex/values";
|
|
13
14
|
import { Clock, Effect, Layer, Match, pipe, Schema } from "effect";
|
|
14
15
|
import type * as Api from "./Api";
|
|
15
16
|
import * as Auth from "./Auth";
|
|
@@ -49,9 +50,11 @@ export const make = <Api_ extends Api.AnyWithPropsWithRuntime<"Convex">>(
|
|
|
49
50
|
);
|
|
50
51
|
|
|
51
52
|
return genericFunction(
|
|
52
|
-
queryFunction(
|
|
53
|
+
queryFunction({
|
|
54
|
+
databaseSchema: api.databaseSchema,
|
|
53
55
|
args: functionProvenance.args,
|
|
54
56
|
returns: functionProvenance.returns,
|
|
57
|
+
error: functionProvenance.error,
|
|
55
58
|
handler: handler as Handler.AnyConfectProvenance,
|
|
56
59
|
}),
|
|
57
60
|
);
|
|
@@ -64,9 +67,11 @@ export const make = <Api_ extends Api.AnyWithPropsWithRuntime<"Convex">>(
|
|
|
64
67
|
);
|
|
65
68
|
|
|
66
69
|
return genericFunction(
|
|
67
|
-
mutationFunction(
|
|
70
|
+
mutationFunction({
|
|
71
|
+
databaseSchema: api.databaseSchema,
|
|
68
72
|
args: functionProvenance.args,
|
|
69
73
|
returns: functionProvenance.returns,
|
|
74
|
+
error: functionProvenance.error,
|
|
70
75
|
handler: handler as Handler.AnyConfectProvenance,
|
|
71
76
|
}),
|
|
72
77
|
);
|
|
@@ -82,6 +87,7 @@ export const make = <Api_ extends Api.AnyWithPropsWithRuntime<"Convex">>(
|
|
|
82
87
|
convexActionFunction(api.databaseSchema, {
|
|
83
88
|
args: functionProvenance.args,
|
|
84
89
|
returns: functionProvenance.returns,
|
|
90
|
+
error: functionProvenance.error,
|
|
85
91
|
handler: handler as Handler.AnyConfectProvenance,
|
|
86
92
|
}),
|
|
87
93
|
);
|
|
@@ -99,9 +105,9 @@ export const make = <Api_ extends Api.AnyWithPropsWithRuntime<"Convex">>(
|
|
|
99
105
|
// relying on real time for correctness anyway.
|
|
100
106
|
//
|
|
101
107
|
// Users who explicitly want the real timestamp can still reach it via Effect's
|
|
102
|
-
// Clock service (Clock.currentTimeMillis
|
|
108
|
+
// Clock service (Clock.currentTimeMillis/Clock.currentTimeNanos). We provide
|
|
103
109
|
// a Clock layer whose methods close over the *original* Date.now, so opting in
|
|
104
|
-
// to Clock is an opt-in to worse caching
|
|
110
|
+
// to Clock is an opt-in to worse caching—but caching is not broken by default.
|
|
105
111
|
const unpatchedClock = (realDateNow: () => number): Clock.Clock => {
|
|
106
112
|
const bigint1e6 = BigInt(1_000_000);
|
|
107
113
|
const unsafeCurrentTimeMillis = () => realDateNow();
|
|
@@ -136,30 +142,31 @@ const queryFunction = <
|
|
|
136
142
|
Returns,
|
|
137
143
|
ConvexReturns,
|
|
138
144
|
E,
|
|
139
|
-
>(
|
|
140
|
-
databaseSchema
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
145
|
+
>({
|
|
146
|
+
databaseSchema,
|
|
147
|
+
args,
|
|
148
|
+
returns,
|
|
149
|
+
error,
|
|
150
|
+
handler,
|
|
151
|
+
}: {
|
|
152
|
+
databaseSchema: DatabaseSchema_;
|
|
153
|
+
args: Schema.Schema<Args, ConvexArgs>;
|
|
154
|
+
returns: Schema.Schema<Returns, ConvexReturns>;
|
|
155
|
+
error: Schema.Schema<Error, Value> | undefined;
|
|
156
|
+
handler: (
|
|
157
|
+
a: Args,
|
|
158
|
+
) => Effect.Effect<
|
|
159
|
+
Returns,
|
|
160
|
+
E,
|
|
161
|
+
| DatabaseReader.DatabaseReader<DatabaseSchema_>
|
|
162
|
+
| Auth.Auth
|
|
163
|
+
| StorageReader
|
|
164
|
+
| QueryRunner.QueryRunner
|
|
165
|
+
| QueryCtx.QueryCtx<
|
|
166
|
+
DataModel.ToConvex<DataModel.FromSchema<DatabaseSchema_>>
|
|
167
|
+
>
|
|
168
|
+
>;
|
|
169
|
+
}) => ({
|
|
163
170
|
args: SchemaToValidator.compileArgsSchema(args),
|
|
164
171
|
returns: SchemaToValidator.compileReturnsSchema(returns),
|
|
165
172
|
handler: (
|
|
@@ -169,35 +176,37 @@ const queryFunction = <
|
|
|
169
176
|
actualArgs: ConvexArgs,
|
|
170
177
|
): Promise<ConvexReturns> =>
|
|
171
178
|
withStubbedDateNow((clock) =>
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
),
|
|
191
|
-
Layer.setConfigProvider(ConvexConfigProvider.make()),
|
|
179
|
+
Effect.gen(function* () {
|
|
180
|
+
const decodedArgs = yield* pipe(
|
|
181
|
+
actualArgs,
|
|
182
|
+
Schema.decode(args),
|
|
183
|
+
Effect.orDie,
|
|
184
|
+
);
|
|
185
|
+
const decodedReturns = yield* handler(decodedArgs).pipe(
|
|
186
|
+
Effect.provide(
|
|
187
|
+
Layer.mergeAll(
|
|
188
|
+
DatabaseReader.layer(databaseSchema, ctx.db),
|
|
189
|
+
Auth.layer(ctx.auth),
|
|
190
|
+
StorageReader.layer(ctx.storage),
|
|
191
|
+
QueryRunner.layer(ctx.runQuery),
|
|
192
|
+
Layer.succeed(
|
|
193
|
+
QueryCtx.QueryCtx<
|
|
194
|
+
DataModel.ToConvex<DataModel.FromSchema<DatabaseSchema_>>
|
|
195
|
+
>(),
|
|
196
|
+
ctx,
|
|
192
197
|
),
|
|
198
|
+
Layer.setConfigProvider(ConvexConfigProvider.make()),
|
|
193
199
|
),
|
|
194
200
|
),
|
|
195
|
-
)
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
201
|
+
);
|
|
202
|
+
return yield* pipe(
|
|
203
|
+
decodedReturns,
|
|
204
|
+
Schema.encode(returns),
|
|
205
|
+
Effect.orDie,
|
|
206
|
+
);
|
|
207
|
+
}).pipe(
|
|
199
208
|
Effect.withClock(clock),
|
|
200
|
-
|
|
209
|
+
RegisteredFunction.runHandlerPromise(error),
|
|
201
210
|
),
|
|
202
211
|
),
|
|
203
212
|
});
|
|
@@ -236,42 +245,46 @@ export type MutationServices<Schema extends DatabaseSchema.AnyWithProps> =
|
|
|
236
245
|
| MutationCtx.MutationCtx<DataModel.ToConvex<DataModel.FromSchema<Schema>>>;
|
|
237
246
|
|
|
238
247
|
const mutationFunction = <
|
|
239
|
-
|
|
248
|
+
DatabaseSchema_ extends DatabaseSchema.AnyWithProps,
|
|
240
249
|
Args,
|
|
241
250
|
ConvexArgs extends DefaultFunctionArgs,
|
|
242
251
|
Returns,
|
|
243
252
|
ConvexReturns,
|
|
244
253
|
E,
|
|
245
|
-
>(
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
254
|
+
>({
|
|
255
|
+
databaseSchema,
|
|
256
|
+
args,
|
|
257
|
+
returns,
|
|
258
|
+
error,
|
|
259
|
+
handler,
|
|
260
|
+
}: {
|
|
261
|
+
databaseSchema: DatabaseSchema_;
|
|
262
|
+
args: Schema.Schema<Args, ConvexArgs>;
|
|
263
|
+
returns: Schema.Schema<Returns, ConvexReturns>;
|
|
264
|
+
error: Schema.Schema<Error, Value> | undefined;
|
|
265
|
+
handler: (
|
|
266
|
+
a: Args,
|
|
267
|
+
) => Effect.Effect<Returns, E, MutationServices<DatabaseSchema_>>;
|
|
268
|
+
}) => ({
|
|
257
269
|
args: SchemaToValidator.compileArgsSchema(args),
|
|
258
270
|
returns: SchemaToValidator.compileReturnsSchema(returns),
|
|
259
271
|
handler: (
|
|
260
|
-
ctx: GenericMutationCtx<
|
|
272
|
+
ctx: GenericMutationCtx<
|
|
273
|
+
DataModel.ToConvex<DataModel.FromSchema<DatabaseSchema_>>
|
|
274
|
+
>,
|
|
261
275
|
actualArgs: ConvexArgs,
|
|
262
276
|
): Promise<ConvexReturns> =>
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
)
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
),
|
|
273
|
-
|
|
274
|
-
),
|
|
277
|
+
Effect.gen(function* () {
|
|
278
|
+
const decodedArgs = yield* pipe(
|
|
279
|
+
actualArgs,
|
|
280
|
+
Schema.decode(args),
|
|
281
|
+
Effect.orDie,
|
|
282
|
+
);
|
|
283
|
+
const decodedReturns = yield* handler(decodedArgs).pipe(
|
|
284
|
+
Effect.provide(mutationLayer(databaseSchema, ctx)),
|
|
285
|
+
);
|
|
286
|
+
return yield* pipe(decodedReturns, Schema.encode(returns), Effect.orDie);
|
|
287
|
+
}).pipe(RegisteredFunction.runHandlerPromise(error)),
|
|
275
288
|
});
|
|
276
289
|
|
|
277
290
|
const convexActionFunction = <
|
|
@@ -286,10 +299,12 @@ const convexActionFunction = <
|
|
|
286
299
|
{
|
|
287
300
|
args,
|
|
288
301
|
returns,
|
|
302
|
+
error,
|
|
289
303
|
handler,
|
|
290
304
|
}: {
|
|
291
305
|
args: Schema.Schema<Args, ConvexArgs>;
|
|
292
306
|
returns: Schema.Schema<Returns, ConvexReturns>;
|
|
307
|
+
error: Schema.Schema.AnyNoContext | undefined;
|
|
293
308
|
handler: (
|
|
294
309
|
a: Args,
|
|
295
310
|
) => Effect.Effect<
|
|
@@ -302,6 +317,7 @@ const convexActionFunction = <
|
|
|
302
317
|
RegisteredFunction.actionFunctionBase({
|
|
303
318
|
args,
|
|
304
319
|
returns,
|
|
320
|
+
error,
|
|
305
321
|
handler,
|
|
306
322
|
createLayer: (ctx) =>
|
|
307
323
|
Layer.mergeAll(
|