@confect/server 1.0.3 → 3.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 +22 -0
- package/dist/ActionRunner.d.ts +2 -2
- package/dist/ActionRunner.d.ts.map +1 -1
- package/dist/ActionRunner.js +9 -7
- package/dist/ActionRunner.js.map +1 -1
- package/dist/Auth.d.ts.map +1 -1
- package/dist/Auth.js +1 -1
- package/dist/Auth.js.map +1 -1
- package/dist/ConvexConfigProvider.d.ts +10 -0
- package/dist/ConvexConfigProvider.d.ts.map +1 -0
- package/dist/ConvexConfigProvider.js +25 -0
- package/dist/ConvexConfigProvider.js.map +1 -0
- package/dist/Document.d.ts.map +1 -1
- package/dist/Document.js +2 -2
- package/dist/Document.js.map +1 -1
- package/dist/FunctionImpl.js +2 -2
- package/dist/FunctionImpl.js.map +1 -1
- package/dist/Handler.d.ts +18 -12
- package/dist/Handler.d.ts.map +1 -1
- package/dist/Handler.js.map +1 -1
- package/dist/HttpApi.d.ts.map +1 -1
- package/dist/HttpApi.js +2 -1
- package/dist/HttpApi.js.map +1 -1
- package/dist/MutationRunner.d.ts +2 -2
- package/dist/MutationRunner.d.ts.map +1 -1
- package/dist/MutationRunner.js +10 -8
- package/dist/MutationRunner.js.map +1 -1
- package/dist/QueryInitializer.d.ts.map +1 -1
- package/dist/QueryInitializer.js +2 -2
- package/dist/QueryInitializer.js.map +1 -1
- package/dist/QueryRunner.d.ts +2 -2
- package/dist/QueryRunner.d.ts.map +1 -1
- package/dist/QueryRunner.js +7 -5
- package/dist/QueryRunner.js.map +1 -1
- package/dist/RegisteredConvexFunction.d.ts +4 -4
- package/dist/RegisteredConvexFunction.d.ts.map +1 -1
- package/dist/RegisteredConvexFunction.js +25 -21
- package/dist/RegisteredConvexFunction.js.map +1 -1
- package/dist/RegisteredFunction.d.ts +15 -4
- package/dist/RegisteredFunction.d.ts.map +1 -1
- package/dist/RegisteredFunction.js.map +1 -1
- package/dist/RegisteredFunctions.d.ts +4 -4
- package/dist/RegisteredFunctions.d.ts.map +1 -1
- package/dist/RegisteredFunctions.js.map +1 -1
- package/dist/RegisteredNodeFunction.d.ts +3 -3
- package/dist/RegisteredNodeFunction.d.ts.map +1 -1
- package/dist/RegisteredNodeFunction.js +6 -5
- package/dist/RegisteredNodeFunction.js.map +1 -1
- package/dist/RegistryItem.d.ts +9 -9
- package/dist/RegistryItem.d.ts.map +1 -1
- package/dist/RegistryItem.js +2 -2
- package/dist/RegistryItem.js.map +1 -1
- package/dist/SchemaToValidator.d.ts +7 -6
- package/dist/SchemaToValidator.d.ts.map +1 -1
- package/dist/SchemaToValidator.js.map +1 -1
- package/dist/Storage.d.ts.map +1 -1
- package/dist/Storage.js +1 -1
- package/dist/Storage.js.map +1 -1
- package/dist/index.d.ts +3 -2
- package/dist/index.js +2 -1
- package/package.json +16 -14
- package/src/ActionRunner.ts +27 -13
- package/src/Auth.ts +3 -2
- package/src/ConvexConfigProvider.ts +58 -0
- package/src/Document.ts +14 -12
- package/src/FunctionImpl.ts +3 -3
- package/src/Handler.ts +39 -14
- package/src/HttpApi.ts +3 -1
- package/src/MutationRunner.ts +33 -18
- package/src/QueryInitializer.ts +13 -11
- package/src/QueryRunner.ts +22 -8
- package/src/RegisteredConvexFunction.ts +59 -41
- package/src/RegisteredFunction.ts +86 -1
- package/src/RegisteredFunctions.ts +10 -11
- package/src/RegisteredNodeFunction.ts +23 -13
- package/src/RegistryItem.ts +9 -12
- package/src/SchemaToValidator.ts +56 -39
- package/src/Storage.ts +5 -4
- package/src/index.ts +1 -0
package/src/Handler.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { FunctionSpec, RuntimeAndFunctionType } from "@confect/core";
|
|
2
|
+
import type * as FunctionProvenance from "@confect/core/FunctionProvenance";
|
|
2
3
|
import type { NodeContext } from "@effect/platform-node";
|
|
3
4
|
import type { Effect } from "effect";
|
|
4
5
|
import type * as ActionCtx from "./ActionCtx";
|
|
@@ -12,6 +13,7 @@ import type * as MutationCtx from "./MutationCtx";
|
|
|
12
13
|
import type * as MutationRunner from "./MutationRunner";
|
|
13
14
|
import type * as QueryCtx from "./QueryCtx";
|
|
14
15
|
import type * as QueryRunner from "./QueryRunner";
|
|
16
|
+
import type * as RegisteredFunction from "./RegisteredFunction";
|
|
15
17
|
import type * as Scheduler from "./Scheduler";
|
|
16
18
|
import type {
|
|
17
19
|
StorageActionWriter,
|
|
@@ -23,27 +25,49 @@ import type * as VectorSearch from "./VectorSearch";
|
|
|
23
25
|
export type Handler<
|
|
24
26
|
DatabaseSchema_ extends DatabaseSchema.AnyWithProps,
|
|
25
27
|
FunctionSpec_ extends FunctionSpec.AnyWithProps,
|
|
28
|
+
> =
|
|
29
|
+
FunctionSpec_ extends FunctionSpec.WithFunctionProvenance<
|
|
30
|
+
FunctionSpec_,
|
|
31
|
+
FunctionProvenance.AnyConvex
|
|
32
|
+
>
|
|
33
|
+
? ConvexProvenanceHandler<FunctionSpec_>
|
|
34
|
+
: FunctionSpec_ extends FunctionSpec.WithFunctionProvenance<
|
|
35
|
+
FunctionSpec_,
|
|
36
|
+
FunctionProvenance.AnyConfect
|
|
37
|
+
>
|
|
38
|
+
? ConfectProvenanceHandler<DatabaseSchema_, FunctionSpec_>
|
|
39
|
+
: never;
|
|
40
|
+
|
|
41
|
+
type ConvexProvenanceHandler<
|
|
42
|
+
FunctionSpec_ extends
|
|
43
|
+
FunctionSpec.AnyWithPropsWithFunctionProvenance<FunctionProvenance.AnyConvex>,
|
|
44
|
+
> = RegisteredFunction.ConvexRegisteredFunction<FunctionSpec_>;
|
|
45
|
+
|
|
46
|
+
type ConfectProvenanceHandler<
|
|
47
|
+
DatabaseSchema_ extends DatabaseSchema.AnyWithProps,
|
|
48
|
+
FunctionSpec_ extends
|
|
49
|
+
FunctionSpec.AnyWithPropsWithFunctionProvenance<FunctionProvenance.AnyConfect>,
|
|
26
50
|
> =
|
|
27
51
|
FunctionSpec_ extends FunctionSpec.WithFunctionType<FunctionSpec_, "query">
|
|
28
|
-
?
|
|
52
|
+
? ConfectProvenanceQuery<DatabaseSchema_, FunctionSpec_>
|
|
29
53
|
: FunctionSpec_ extends FunctionSpec.WithFunctionType<
|
|
30
54
|
FunctionSpec_,
|
|
31
55
|
"mutation"
|
|
32
56
|
>
|
|
33
|
-
?
|
|
57
|
+
? ConfectProvenanceMutation<DatabaseSchema_, FunctionSpec_>
|
|
34
58
|
: FunctionSpec_ extends FunctionSpec.WithRuntimeAndFunctionType<
|
|
35
59
|
FunctionSpec_,
|
|
36
60
|
RuntimeAndFunctionType.ConvexAction
|
|
37
61
|
>
|
|
38
|
-
?
|
|
62
|
+
? ConvexRuntimeAction<DatabaseSchema_, FunctionSpec_>
|
|
39
63
|
: FunctionSpec_ extends FunctionSpec.WithRuntimeAndFunctionType<
|
|
40
64
|
FunctionSpec_,
|
|
41
65
|
RuntimeAndFunctionType.NodeAction
|
|
42
66
|
>
|
|
43
|
-
?
|
|
67
|
+
? NodeRuntimeAction<DatabaseSchema_, FunctionSpec_>
|
|
44
68
|
: never;
|
|
45
69
|
|
|
46
|
-
export type
|
|
70
|
+
export type ConfectProvenanceQuery<
|
|
47
71
|
DatabaseSchema_ extends DatabaseSchema.AnyWithProps,
|
|
48
72
|
FunctionSpec_ extends
|
|
49
73
|
FunctionSpec.AnyWithPropsWithFunctionType<RuntimeAndFunctionType.AnyQuery>,
|
|
@@ -56,7 +80,7 @@ export type Query<
|
|
|
56
80
|
| QueryCtx.QueryCtx<DataModel.ToConvex<DataModel.FromSchema<DatabaseSchema_>>>
|
|
57
81
|
>;
|
|
58
82
|
|
|
59
|
-
export type
|
|
83
|
+
export type ConfectProvenanceMutation<
|
|
60
84
|
DatabaseSchema_ extends DatabaseSchema.AnyWithProps,
|
|
61
85
|
FunctionSpec_ extends
|
|
62
86
|
FunctionSpec.AnyWithPropsWithFunctionType<RuntimeAndFunctionType.AnyMutation>,
|
|
@@ -89,13 +113,13 @@ type ActionServices<DatabaseSchema_ extends DatabaseSchema.AnyWithProps> =
|
|
|
89
113
|
DataModel.ToConvex<DataModel.FromSchema<DatabaseSchema_>>
|
|
90
114
|
>;
|
|
91
115
|
|
|
92
|
-
export type
|
|
116
|
+
export type ConvexRuntimeAction<
|
|
93
117
|
DatabaseSchema_ extends DatabaseSchema.AnyWithProps,
|
|
94
118
|
FunctionSpec_ extends
|
|
95
119
|
FunctionSpec.AnyWithPropsWithFunctionType<RuntimeAndFunctionType.AnyAction>,
|
|
96
120
|
> = Base<FunctionSpec_, ActionServices<DatabaseSchema_>>;
|
|
97
121
|
|
|
98
|
-
export type
|
|
122
|
+
export type NodeRuntimeAction<
|
|
99
123
|
DatabaseSchema_ extends DatabaseSchema.AnyWithProps,
|
|
100
124
|
FunctionSpec_ extends
|
|
101
125
|
FunctionSpec.AnyWithPropsWithFunctionType<RuntimeAndFunctionType.NodeAction>,
|
|
@@ -105,13 +129,14 @@ export type NodeAction<
|
|
|
105
129
|
>;
|
|
106
130
|
|
|
107
131
|
type Base<FunctionSpec_ extends FunctionSpec.AnyWithProps, R> = (
|
|
108
|
-
args: FunctionSpec.Args<FunctionSpec_
|
|
109
|
-
) => Effect.Effect<FunctionSpec.Returns<FunctionSpec_
|
|
132
|
+
args: FunctionSpec.Args<FunctionSpec_>,
|
|
133
|
+
) => Effect.Effect<FunctionSpec.Returns<FunctionSpec_>, never, R>;
|
|
110
134
|
|
|
111
|
-
export type
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
135
|
+
export type Any = AnyConfectProvenance | AnyConvexProvenance;
|
|
136
|
+
|
|
137
|
+
export type AnyConfectProvenance = Base<FunctionSpec.AnyConfect, any>;
|
|
138
|
+
|
|
139
|
+
export type AnyConvexProvenance = RegisteredFunction.Any;
|
|
115
140
|
|
|
116
141
|
export type WithName<
|
|
117
142
|
DatabaseSchema_ extends DatabaseSchema.AnyWithProps,
|
package/src/HttpApi.ts
CHANGED
|
@@ -16,13 +16,14 @@ import {
|
|
|
16
16
|
type RouteSpecWithPathPrefix,
|
|
17
17
|
} from "convex/server";
|
|
18
18
|
import { Array, Layer, pipe, Record } from "effect";
|
|
19
|
+
import * as ActionCtx from "./ActionCtx";
|
|
19
20
|
import * as ActionRunner from "./ActionRunner";
|
|
20
21
|
import * as Auth from "./Auth";
|
|
22
|
+
import * as ConvexConfigProvider from "./ConvexConfigProvider";
|
|
21
23
|
import * as MutationRunner from "./MutationRunner";
|
|
22
24
|
import * as QueryRunner from "./QueryRunner";
|
|
23
25
|
import * as Scheduler from "./Scheduler";
|
|
24
26
|
import { StorageActionWriter, StorageReader, StorageWriter } from "./Storage";
|
|
25
|
-
import * as ActionCtx from "./ActionCtx";
|
|
26
27
|
|
|
27
28
|
type Middleware = (
|
|
28
29
|
httpApp: HttpApp.Default,
|
|
@@ -84,6 +85,7 @@ const makeHandler =
|
|
|
84
85
|
ApiLive,
|
|
85
86
|
ApiDocsLive,
|
|
86
87
|
HttpServer.layerContext,
|
|
88
|
+
Layer.setConfigProvider(ConvexConfigProvider.make()),
|
|
87
89
|
);
|
|
88
90
|
|
|
89
91
|
const { handler } = HttpApiBuilder.toWebHandler(
|
package/src/MutationRunner.ts
CHANGED
|
@@ -1,39 +1,54 @@
|
|
|
1
1
|
import * as Ref from "@confect/core/Ref";
|
|
2
2
|
import { type GenericMutationCtx } from "convex/server";
|
|
3
3
|
import type { ParseResult } from "effect";
|
|
4
|
-
import { Context, Effect, Layer, Schema } from "effect";
|
|
4
|
+
import { Context, Effect, Layer, Match, Schema } from "effect";
|
|
5
5
|
|
|
6
|
-
const
|
|
6
|
+
const make =
|
|
7
7
|
(runMutation: GenericMutationCtx<any>["runMutation"]) =>
|
|
8
8
|
<Mutation extends Ref.AnyMutation>(
|
|
9
9
|
mutation: Mutation,
|
|
10
|
-
args: Ref.Args<Mutation
|
|
11
|
-
): Effect.Effect<Ref.Returns<Mutation
|
|
10
|
+
args: Ref.Args<Mutation>,
|
|
11
|
+
): Effect.Effect<Ref.Returns<Mutation>, ParseResult.ParseError> =>
|
|
12
12
|
Effect.gen(function* () {
|
|
13
|
-
const
|
|
13
|
+
const functionSpec = Ref.getFunctionSpec(mutation);
|
|
14
14
|
const functionName = Ref.getConvexFunctionName(mutation);
|
|
15
15
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
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,
|
|
19
34
|
);
|
|
20
|
-
return yield* Schema.decode(function_.returns)(encodedReturns);
|
|
21
35
|
});
|
|
22
36
|
|
|
23
|
-
export const MutationRunner = Context.GenericTag<
|
|
24
|
-
|
|
25
|
-
|
|
37
|
+
export const MutationRunner = Context.GenericTag<ReturnType<typeof make>>(
|
|
38
|
+
"@confect/server/MutationRunner",
|
|
39
|
+
);
|
|
26
40
|
export type MutationRunner = typeof MutationRunner.Identifier;
|
|
27
41
|
|
|
28
42
|
export const layer = (runMutation: GenericMutationCtx<any>["runMutation"]) =>
|
|
29
|
-
Layer.succeed(MutationRunner,
|
|
43
|
+
Layer.succeed(MutationRunner, make(runMutation));
|
|
30
44
|
|
|
31
|
-
export class MutationRollback extends Schema.TaggedError<MutationRollback>(
|
|
45
|
+
export class MutationRollback extends Schema.TaggedError<MutationRollback>()(
|
|
32
46
|
"MutationRollback",
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
}
|
|
47
|
+
{
|
|
48
|
+
mutationName: Schema.String,
|
|
49
|
+
error: Schema.Unknown,
|
|
50
|
+
},
|
|
51
|
+
) {
|
|
37
52
|
/* v8 ignore start */
|
|
38
53
|
override get message(): string {
|
|
39
54
|
return `Mutation ${this.mutationName} failed and was rolled back.\n\n${this.error}`;
|
package/src/QueryInitializer.ts
CHANGED
|
@@ -280,12 +280,13 @@ export const getById =
|
|
|
280
280
|
Effect.andThen(Document.decode(tableName, table.Fields)),
|
|
281
281
|
);
|
|
282
282
|
|
|
283
|
-
export class GetByIdFailure extends Schema.TaggedError<GetByIdFailure>(
|
|
283
|
+
export class GetByIdFailure extends Schema.TaggedError<GetByIdFailure>()(
|
|
284
284
|
"GetByIdFailure",
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
}
|
|
285
|
+
{
|
|
286
|
+
id: Schema.String,
|
|
287
|
+
tableName: Schema.String,
|
|
288
|
+
},
|
|
289
|
+
) {
|
|
289
290
|
override get message(): string {
|
|
290
291
|
return Document.documentErrorMessage({
|
|
291
292
|
id: this.id,
|
|
@@ -295,13 +296,14 @@ export class GetByIdFailure extends Schema.TaggedError<GetByIdFailure>(
|
|
|
295
296
|
}
|
|
296
297
|
}
|
|
297
298
|
|
|
298
|
-
export class GetByIndexFailure extends Schema.TaggedError<GetByIndexFailure>(
|
|
299
|
+
export class GetByIndexFailure extends Schema.TaggedError<GetByIndexFailure>()(
|
|
299
300
|
"GetByIndexFailure",
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
}
|
|
301
|
+
{
|
|
302
|
+
tableName: Schema.String,
|
|
303
|
+
indexName: Schema.String,
|
|
304
|
+
indexFieldValues: Schema.Array(Schema.String),
|
|
305
|
+
},
|
|
306
|
+
) {
|
|
305
307
|
override get message(): string {
|
|
306
308
|
return `No documents found in table '${this.tableName}' with index '${this.indexName}' and field values '${this.indexFieldValues}'`;
|
|
307
309
|
}
|
package/src/QueryRunner.ts
CHANGED
|
@@ -1,23 +1,37 @@
|
|
|
1
1
|
import * as Ref from "@confect/core/Ref";
|
|
2
2
|
import { type GenericQueryCtx } from "convex/server";
|
|
3
3
|
import type { ParseResult } from "effect";
|
|
4
|
-
import { Context, Effect, Layer, Schema } from "effect";
|
|
4
|
+
import { Context, Effect, Layer, Match, Schema } from "effect";
|
|
5
5
|
|
|
6
6
|
const make =
|
|
7
7
|
(runQuery: GenericQueryCtx<any>["runQuery"]) =>
|
|
8
8
|
<Query extends Ref.AnyQuery>(
|
|
9
9
|
query: Query,
|
|
10
|
-
args: Ref.Args<Query
|
|
11
|
-
): Effect.Effect<Ref.Returns<Query
|
|
10
|
+
args: Ref.Args<Query>,
|
|
11
|
+
): Effect.Effect<Ref.Returns<Query>, ParseResult.ParseError> =>
|
|
12
12
|
Effect.gen(function* () {
|
|
13
|
-
const
|
|
13
|
+
const functionSpec = Ref.getFunctionSpec(query);
|
|
14
14
|
const functionName = Ref.getConvexFunctionName(query);
|
|
15
15
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
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,
|
|
19
34
|
);
|
|
20
|
-
return yield* Schema.decode(function_.returns)(encodedReturns);
|
|
21
35
|
});
|
|
22
36
|
|
|
23
37
|
export const QueryRunner = Context.GenericTag<ReturnType<typeof make>>(
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type * as FunctionSpec from "@confect/core/FunctionSpec";
|
|
1
2
|
import {
|
|
2
3
|
actionGeneric,
|
|
3
4
|
type DefaultFunctionArgs,
|
|
@@ -12,10 +13,12 @@ import {
|
|
|
12
13
|
import { Effect, Layer, Match, pipe, Schema } from "effect";
|
|
13
14
|
import type * as Api from "./Api";
|
|
14
15
|
import * as Auth from "./Auth";
|
|
16
|
+
import * as ConvexConfigProvider from "./ConvexConfigProvider";
|
|
15
17
|
import * as DatabaseReader from "./DatabaseReader";
|
|
16
18
|
import type * as DatabaseSchema from "./DatabaseSchema";
|
|
17
19
|
import * as DatabaseWriter from "./DatabaseWriter";
|
|
18
20
|
import type * as DataModel from "./DataModel";
|
|
21
|
+
import type * as Handler from "./Handler";
|
|
19
22
|
import * as MutationCtx from "./MutationCtx";
|
|
20
23
|
import * as MutationRunner from "./MutationRunner";
|
|
21
24
|
import * as QueryCtx from "./QueryCtx";
|
|
@@ -28,52 +31,61 @@ import { StorageReader, StorageWriter } from "./Storage";
|
|
|
28
31
|
|
|
29
32
|
export const make = <Api_ extends Api.AnyWithPropsWithRuntime<"Convex">>(
|
|
30
33
|
api: Api_,
|
|
31
|
-
{
|
|
32
|
-
): RegisteredFunction.
|
|
33
|
-
Match.value(
|
|
34
|
-
Match.
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
Match.exhaustive,
|
|
39
|
-
);
|
|
34
|
+
{ functionSpec, handler }: RegistryItem.AnyWithProps,
|
|
35
|
+
): RegisteredFunction.Any =>
|
|
36
|
+
Match.value(functionSpec.functionProvenance).pipe(
|
|
37
|
+
Match.tag("Convex", () => handler as RegisteredFunction.Any),
|
|
38
|
+
Match.tag("Confect", () => {
|
|
39
|
+
const { functionVisibility, functionProvenance } =
|
|
40
|
+
functionSpec as FunctionSpec.AnyConfect;
|
|
40
41
|
|
|
41
|
-
return
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
42
|
+
return Match.value(functionSpec.runtimeAndFunctionType.functionType).pipe(
|
|
43
|
+
Match.when("query", () => {
|
|
44
|
+
const genericFunction = Match.value(functionVisibility).pipe(
|
|
45
|
+
Match.when("public", () => queryGeneric),
|
|
46
|
+
Match.when("internal", () => internalQueryGeneric),
|
|
47
|
+
Match.exhaustive,
|
|
48
|
+
);
|
|
49
|
+
|
|
50
|
+
return genericFunction(
|
|
51
|
+
queryFunction(api.databaseSchema, {
|
|
52
|
+
args: functionProvenance.args,
|
|
53
|
+
returns: functionProvenance.returns,
|
|
54
|
+
handler: handler as Handler.AnyConfectProvenance,
|
|
55
|
+
}),
|
|
56
|
+
);
|
|
46
57
|
}),
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
Match.exhaustive,
|
|
54
|
-
);
|
|
58
|
+
Match.when("mutation", () => {
|
|
59
|
+
const genericFunction = Match.value(functionVisibility).pipe(
|
|
60
|
+
Match.when("public", () => mutationGeneric),
|
|
61
|
+
Match.when("internal", () => internalMutationGeneric),
|
|
62
|
+
Match.exhaustive,
|
|
63
|
+
);
|
|
55
64
|
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
65
|
+
return genericFunction(
|
|
66
|
+
mutationFunction(api.databaseSchema, {
|
|
67
|
+
args: functionProvenance.args,
|
|
68
|
+
returns: functionProvenance.returns,
|
|
69
|
+
handler: handler as Handler.AnyConfectProvenance,
|
|
70
|
+
}),
|
|
71
|
+
);
|
|
61
72
|
}),
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
Match.exhaustive,
|
|
69
|
-
);
|
|
73
|
+
Match.when("action", () => {
|
|
74
|
+
const genericFunction = Match.value(functionVisibility).pipe(
|
|
75
|
+
Match.when("public", () => actionGeneric),
|
|
76
|
+
Match.when("internal", () => internalActionGeneric),
|
|
77
|
+
Match.exhaustive,
|
|
78
|
+
);
|
|
70
79
|
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
80
|
+
return genericFunction(
|
|
81
|
+
convexActionFunction(api.databaseSchema, {
|
|
82
|
+
args: functionProvenance.args,
|
|
83
|
+
returns: functionProvenance.returns,
|
|
84
|
+
handler: handler as Handler.AnyConfectProvenance,
|
|
85
|
+
}),
|
|
86
|
+
);
|
|
76
87
|
}),
|
|
88
|
+
Match.exhaustive,
|
|
77
89
|
);
|
|
78
90
|
}),
|
|
79
91
|
Match.exhaustive,
|
|
@@ -137,6 +149,7 @@ const queryFunction = <
|
|
|
137
149
|
>(),
|
|
138
150
|
ctx,
|
|
139
151
|
),
|
|
152
|
+
Layer.setConfigProvider(ConvexConfigProvider.make()),
|
|
140
153
|
),
|
|
141
154
|
),
|
|
142
155
|
),
|
|
@@ -167,6 +180,7 @@ export const mutationLayer = <Schema extends DatabaseSchema.AnyWithProps>(
|
|
|
167
180
|
>(),
|
|
168
181
|
ctx,
|
|
169
182
|
),
|
|
183
|
+
Layer.setConfigProvider(ConvexConfigProvider.make()),
|
|
170
184
|
);
|
|
171
185
|
|
|
172
186
|
export type MutationServices<Schema extends DatabaseSchema.AnyWithProps> =
|
|
@@ -248,5 +262,9 @@ const convexActionFunction = <
|
|
|
248
262
|
args,
|
|
249
263
|
returns,
|
|
250
264
|
handler,
|
|
251
|
-
createLayer: (ctx) =>
|
|
265
|
+
createLayer: (ctx) =>
|
|
266
|
+
Layer.mergeAll(
|
|
267
|
+
RegisteredFunction.actionLayer(schema, ctx),
|
|
268
|
+
Layer.setConfigProvider(ConvexConfigProvider.make()),
|
|
269
|
+
),
|
|
252
270
|
});
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import type { FunctionSpec, RuntimeAndFunctionType } from "@confect/core";
|
|
2
|
+
import type * as FunctionProvenance from "@confect/core/FunctionProvenance";
|
|
1
3
|
import {
|
|
2
4
|
type DefaultFunctionArgs,
|
|
3
5
|
type FunctionVisibility,
|
|
@@ -19,11 +21,94 @@ import * as SchemaToValidator from "./SchemaToValidator";
|
|
|
19
21
|
import { StorageActionWriter, StorageReader, StorageWriter } from "./Storage";
|
|
20
22
|
import * as VectorSearch from "./VectorSearch";
|
|
21
23
|
|
|
22
|
-
export type
|
|
24
|
+
export type Any =
|
|
23
25
|
| RegisteredQuery<FunctionVisibility, DefaultFunctionArgs, any>
|
|
24
26
|
| RegisteredMutation<FunctionVisibility, DefaultFunctionArgs, any>
|
|
25
27
|
| RegisteredAction<FunctionVisibility, DefaultFunctionArgs, any>;
|
|
26
28
|
|
|
29
|
+
type ConfectRegisteredFunction<
|
|
30
|
+
FunctionSpec_ extends FunctionSpec.AnyWithProps,
|
|
31
|
+
> =
|
|
32
|
+
FunctionSpec.EncodedArgs<FunctionSpec_> extends infer Args_ extends
|
|
33
|
+
DefaultFunctionArgs
|
|
34
|
+
? RuntimeAndFunctionType.GetFunctionType<
|
|
35
|
+
FunctionSpec_["runtimeAndFunctionType"]
|
|
36
|
+
> extends "query"
|
|
37
|
+
? RegisteredQuery<
|
|
38
|
+
FunctionSpec.GetFunctionVisibility<FunctionSpec_>,
|
|
39
|
+
Args_,
|
|
40
|
+
Promise<FunctionSpec.EncodedReturns<FunctionSpec_>>
|
|
41
|
+
>
|
|
42
|
+
: RuntimeAndFunctionType.GetFunctionType<
|
|
43
|
+
FunctionSpec_["runtimeAndFunctionType"]
|
|
44
|
+
> extends "mutation"
|
|
45
|
+
? RegisteredMutation<
|
|
46
|
+
FunctionSpec.GetFunctionVisibility<FunctionSpec_>,
|
|
47
|
+
Args_,
|
|
48
|
+
Promise<FunctionSpec.EncodedReturns<FunctionSpec_>>
|
|
49
|
+
>
|
|
50
|
+
: RuntimeAndFunctionType.GetFunctionType<
|
|
51
|
+
FunctionSpec_["runtimeAndFunctionType"]
|
|
52
|
+
> extends "action"
|
|
53
|
+
? RegisteredAction<
|
|
54
|
+
FunctionSpec.GetFunctionVisibility<FunctionSpec_>,
|
|
55
|
+
Args_,
|
|
56
|
+
Promise<FunctionSpec.EncodedReturns<FunctionSpec_>>
|
|
57
|
+
>
|
|
58
|
+
: never
|
|
59
|
+
: never;
|
|
60
|
+
|
|
61
|
+
export type ConvexRegisteredFunction<
|
|
62
|
+
FunctionSpec_ extends FunctionSpec.AnyWithProps,
|
|
63
|
+
> = FunctionSpec_ extends {
|
|
64
|
+
functionProvenance: {
|
|
65
|
+
_tag: "Convex";
|
|
66
|
+
_args: infer Args_ extends DefaultFunctionArgs;
|
|
67
|
+
_returns: infer Returns_;
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
? RuntimeAndFunctionType.GetFunctionType<
|
|
71
|
+
FunctionSpec_["runtimeAndFunctionType"]
|
|
72
|
+
> extends "query"
|
|
73
|
+
? RegisteredQuery<
|
|
74
|
+
FunctionSpec.GetFunctionVisibility<FunctionSpec_>,
|
|
75
|
+
Args_,
|
|
76
|
+
Returns_
|
|
77
|
+
>
|
|
78
|
+
: RuntimeAndFunctionType.GetFunctionType<
|
|
79
|
+
FunctionSpec_["runtimeAndFunctionType"]
|
|
80
|
+
> extends "mutation"
|
|
81
|
+
? RegisteredMutation<
|
|
82
|
+
FunctionSpec.GetFunctionVisibility<FunctionSpec_>,
|
|
83
|
+
Args_,
|
|
84
|
+
Returns_
|
|
85
|
+
>
|
|
86
|
+
: RuntimeAndFunctionType.GetFunctionType<
|
|
87
|
+
FunctionSpec_["runtimeAndFunctionType"]
|
|
88
|
+
> extends "action"
|
|
89
|
+
? RegisteredAction<
|
|
90
|
+
FunctionSpec.GetFunctionVisibility<FunctionSpec_>,
|
|
91
|
+
Args_,
|
|
92
|
+
Returns_
|
|
93
|
+
>
|
|
94
|
+
: never
|
|
95
|
+
: never;
|
|
96
|
+
|
|
97
|
+
export type RegisteredFunction<
|
|
98
|
+
FunctionSpec_ extends FunctionSpec.AnyWithProps,
|
|
99
|
+
> =
|
|
100
|
+
FunctionSpec_ extends FunctionSpec.WithFunctionProvenance<
|
|
101
|
+
FunctionSpec_,
|
|
102
|
+
FunctionProvenance.AnyConvex
|
|
103
|
+
>
|
|
104
|
+
? ConvexRegisteredFunction<FunctionSpec_>
|
|
105
|
+
: FunctionSpec_ extends FunctionSpec.WithFunctionProvenance<
|
|
106
|
+
FunctionSpec_,
|
|
107
|
+
FunctionProvenance.AnyConfect
|
|
108
|
+
>
|
|
109
|
+
? ConfectRegisteredFunction<FunctionSpec_>
|
|
110
|
+
: never;
|
|
111
|
+
|
|
27
112
|
export const actionFunctionBase = <
|
|
28
113
|
Schema extends DatabaseSchema.AnyWithProps,
|
|
29
114
|
Args,
|
|
@@ -27,8 +27,8 @@ type RegisteredFunctionsHelper<Groups extends GroupSpec.AnyWithProps> = {
|
|
|
27
27
|
>]: FunctionSpec.WithName<
|
|
28
28
|
GroupSpec.Functions<Group>,
|
|
29
29
|
FunctionName
|
|
30
|
-
> extends infer
|
|
31
|
-
?
|
|
30
|
+
> extends infer FunctionSpec_ extends FunctionSpec.AnyWithProps
|
|
31
|
+
? RegisteredFunction.RegisteredFunction<FunctionSpec_>
|
|
32
32
|
: never;
|
|
33
33
|
}
|
|
34
34
|
>
|
|
@@ -38,15 +38,15 @@ type RegisteredFunctionsHelper<Groups extends GroupSpec.AnyWithProps> = {
|
|
|
38
38
|
>]: FunctionSpec.WithName<
|
|
39
39
|
GroupSpec.Functions<Group>,
|
|
40
40
|
FunctionName
|
|
41
|
-
> extends infer
|
|
42
|
-
?
|
|
41
|
+
> extends infer FunctionSpec_ extends FunctionSpec.AnyWithProps
|
|
42
|
+
? RegisteredFunction.RegisteredFunction<FunctionSpec_>
|
|
43
43
|
: never;
|
|
44
44
|
}
|
|
45
45
|
: never;
|
|
46
46
|
};
|
|
47
47
|
|
|
48
48
|
export interface AnyWithProps {
|
|
49
|
-
readonly [key: string]: RegisteredFunction.
|
|
49
|
+
readonly [key: string]: RegisteredFunction.Any | AnyWithProps;
|
|
50
50
|
}
|
|
51
51
|
|
|
52
52
|
export const make = <Api_ extends Api.AnyWithProps>(
|
|
@@ -54,7 +54,7 @@ export const make = <Api_ extends Api.AnyWithProps>(
|
|
|
54
54
|
makeRegisteredFunction: (
|
|
55
55
|
api: Api_,
|
|
56
56
|
registryItem: RegistryItem.AnyWithProps,
|
|
57
|
-
) => RegisteredFunction.
|
|
57
|
+
) => RegisteredFunction.Any,
|
|
58
58
|
) =>
|
|
59
59
|
Effect.gen(function* () {
|
|
60
60
|
const registry = yield* Registry.Registry;
|
|
@@ -70,11 +70,10 @@ export const make = <Api_ extends Api.AnyWithProps>(
|
|
|
70
70
|
),
|
|
71
71
|
Match.when("Finalized", () =>
|
|
72
72
|
Effect.succeed(
|
|
73
|
-
mapLeaves<
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
makeRegisteredFunction(api, registryItem),
|
|
73
|
+
mapLeaves<RegistryItem.AnyWithProps, RegisteredFunction.Any>(
|
|
74
|
+
functionImplItems,
|
|
75
|
+
RegistryItem.isRegistryItem,
|
|
76
|
+
(registryItem) => makeRegisteredFunction(api, registryItem),
|
|
78
77
|
) as RegisteredFunctions<Api_["spec"]>,
|
|
79
78
|
),
|
|
80
79
|
),
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type * as FunctionSpec from "@confect/core/FunctionSpec";
|
|
1
2
|
import { NodeContext } from "@effect/platform-node";
|
|
2
3
|
import {
|
|
3
4
|
actionGeneric,
|
|
@@ -8,27 +9,36 @@ import type { Effect } from "effect";
|
|
|
8
9
|
import { Layer, Match, type Schema } from "effect";
|
|
9
10
|
import type * as Api from "./Api";
|
|
10
11
|
import type * as DatabaseSchema from "./DatabaseSchema";
|
|
12
|
+
import type * as Handler from "./Handler";
|
|
11
13
|
import * as RegisteredFunction from "./RegisteredFunction";
|
|
12
14
|
import type * as RegistryItem from "./RegistryItem";
|
|
13
15
|
|
|
14
16
|
export const make = <Api_ extends Api.AnyWithPropsWithRuntime<"Node">>(
|
|
15
17
|
api: Api_,
|
|
16
|
-
{
|
|
17
|
-
): RegisteredFunction.
|
|
18
|
-
|
|
19
|
-
Match.
|
|
20
|
-
Match.
|
|
21
|
-
|
|
22
|
-
|
|
18
|
+
{ functionSpec, handler }: RegistryItem.AnyWithProps,
|
|
19
|
+
): RegisteredFunction.Any =>
|
|
20
|
+
Match.value(functionSpec.functionProvenance).pipe(
|
|
21
|
+
Match.tag("Convex", () => handler as RegisteredFunction.Any),
|
|
22
|
+
Match.tag("Confect", () => {
|
|
23
|
+
const { functionVisibility, functionProvenance } =
|
|
24
|
+
functionSpec as FunctionSpec.AnyConfect;
|
|
23
25
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
26
|
+
const genericFunction = Match.value(functionVisibility).pipe(
|
|
27
|
+
Match.when("public", () => actionGeneric),
|
|
28
|
+
Match.when("internal", () => internalActionGeneric),
|
|
29
|
+
Match.exhaustive,
|
|
30
|
+
);
|
|
31
|
+
|
|
32
|
+
return genericFunction(
|
|
33
|
+
nodeActionFunction(api.databaseSchema, {
|
|
34
|
+
args: functionProvenance.args,
|
|
35
|
+
returns: functionProvenance.returns,
|
|
36
|
+
handler: handler as Handler.AnyConfectProvenance,
|
|
37
|
+
}),
|
|
38
|
+
);
|
|
29
39
|
}),
|
|
40
|
+
Match.exhaustive,
|
|
30
41
|
);
|
|
31
|
-
};
|
|
32
42
|
|
|
33
43
|
const nodeActionFunction = <
|
|
34
44
|
DatabaseSchema_ extends DatabaseSchema.AnyWithProps,
|