@confect/server 2.0.0 → 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 +11 -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/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/MutationRunner.d.ts +2 -2
- package/dist/MutationRunner.d.ts.map +1 -1
- package/dist/MutationRunner.js +9 -7
- package/dist/MutationRunner.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 +21 -18
- package/dist/RegisteredConvexFunction.js.map +1 -1
- package/dist/RegisteredFunction.d.ts +16 -5
- 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/index.d.ts +1 -1
- package/package.json +4 -4
- package/src/ActionRunner.ts +27 -13
- package/src/FunctionImpl.ts +3 -3
- package/src/Handler.ts +39 -14
- package/src/MutationRunner.ts +27 -13
- package/src/QueryRunner.ts +22 -8
- package/src/RegisteredConvexFunction.ts +52 -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/index.ts +1 -1
|
@@ -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";
|
|
@@ -24,57 +27,65 @@ import * as RegisteredFunction from "./RegisteredFunction";
|
|
|
24
27
|
import type * as RegistryItem from "./RegistryItem";
|
|
25
28
|
import * as Scheduler from "./Scheduler";
|
|
26
29
|
import * as SchemaToValidator from "./SchemaToValidator";
|
|
27
|
-
import * as ConvexConfigProvider from "./ConvexConfigProvider";
|
|
28
30
|
import { StorageReader, StorageWriter } from "./Storage";
|
|
29
31
|
|
|
30
32
|
export const make = <Api_ extends Api.AnyWithPropsWithRuntime<"Convex">>(
|
|
31
33
|
api: Api_,
|
|
32
|
-
{
|
|
33
|
-
): RegisteredFunction.
|
|
34
|
-
Match.value(
|
|
35
|
-
Match.
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
Match.exhaustive,
|
|
40
|
-
);
|
|
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;
|
|
41
41
|
|
|
42
|
-
return
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
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
|
+
);
|
|
47
57
|
}),
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
Match.exhaustive,
|
|
55
|
-
);
|
|
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
|
+
);
|
|
56
64
|
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
65
|
+
return genericFunction(
|
|
66
|
+
mutationFunction(api.databaseSchema, {
|
|
67
|
+
args: functionProvenance.args,
|
|
68
|
+
returns: functionProvenance.returns,
|
|
69
|
+
handler: handler as Handler.AnyConfectProvenance,
|
|
70
|
+
}),
|
|
71
|
+
);
|
|
62
72
|
}),
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
Match.exhaustive,
|
|
70
|
-
);
|
|
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
|
+
);
|
|
71
79
|
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
80
|
+
return genericFunction(
|
|
81
|
+
convexActionFunction(api.databaseSchema, {
|
|
82
|
+
args: functionProvenance.args,
|
|
83
|
+
returns: functionProvenance.returns,
|
|
84
|
+
handler: handler as Handler.AnyConfectProvenance,
|
|
85
|
+
}),
|
|
86
|
+
);
|
|
77
87
|
}),
|
|
88
|
+
Match.exhaustive,
|
|
78
89
|
);
|
|
79
90
|
}),
|
|
80
91
|
Match.exhaustive,
|
|
@@ -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,
|
package/src/RegistryItem.ts
CHANGED
|
@@ -18,27 +18,24 @@ export interface RegistryItem<
|
|
|
18
18
|
FunctionSpec_ extends FunctionSpec.AnyWithProps,
|
|
19
19
|
> {
|
|
20
20
|
readonly [TypeId]: TypeId;
|
|
21
|
-
readonly
|
|
21
|
+
readonly functionSpec: FunctionSpec_;
|
|
22
22
|
readonly handler: Handler.Handler<DatabaseSchema_, FunctionSpec_>;
|
|
23
23
|
}
|
|
24
24
|
|
|
25
25
|
export interface AnyWithProps {
|
|
26
26
|
readonly [TypeId]: TypeId;
|
|
27
|
-
readonly
|
|
28
|
-
readonly handler: Handler.
|
|
27
|
+
readonly functionSpec: FunctionSpec.AnyWithProps;
|
|
28
|
+
readonly handler: Handler.Any;
|
|
29
29
|
}
|
|
30
30
|
|
|
31
|
-
export const make =
|
|
32
|
-
|
|
33
|
-
FunctionSpec_ extends FunctionSpec.AnyWithProps,
|
|
34
|
-
>({
|
|
35
|
-
function_,
|
|
31
|
+
export const make = ({
|
|
32
|
+
functionSpec,
|
|
36
33
|
handler,
|
|
37
34
|
}: {
|
|
38
|
-
|
|
39
|
-
handler:
|
|
40
|
-
}):
|
|
35
|
+
functionSpec: FunctionSpec.AnyWithProps;
|
|
36
|
+
handler: AnyWithProps["handler"];
|
|
37
|
+
}): AnyWithProps =>
|
|
41
38
|
Object.assign(Object.create(RegistryItemProto), {
|
|
42
|
-
|
|
39
|
+
functionSpec,
|
|
43
40
|
handler,
|
|
44
41
|
});
|
package/src/index.ts
CHANGED
|
@@ -2,12 +2,12 @@ export * as ActionCtx from "./ActionCtx";
|
|
|
2
2
|
export * as ActionRunner from "./ActionRunner";
|
|
3
3
|
export * as Api from "./Api";
|
|
4
4
|
export * as Auth from "./Auth";
|
|
5
|
+
export * as ConvexConfigProvider from "./ConvexConfigProvider";
|
|
5
6
|
export * as DatabaseReader from "./DatabaseReader";
|
|
6
7
|
export * as DatabaseSchema from "./DatabaseSchema";
|
|
7
8
|
export * as DatabaseWriter from "./DatabaseWriter";
|
|
8
9
|
export * as DataModel from "./DataModel";
|
|
9
10
|
export * as Document from "./Document";
|
|
10
|
-
export * as ConvexConfigProvider from "./ConvexConfigProvider";
|
|
11
11
|
export * as FunctionImpl from "./FunctionImpl";
|
|
12
12
|
export * as GroupImpl from "./GroupImpl";
|
|
13
13
|
export * as Handler from "./Handler";
|