@gaganref/confect-server 0.0.0-stage → 10.3.1-fork.1
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 +2119 -0
- package/LICENSE +7 -0
- package/README.md +16 -2
- package/dist/ActionCtx.d.ts +10 -0
- package/dist/ActionCtx.d.ts.map +1 -0
- package/dist/ActionCtx.js +18 -0
- package/dist/ActionCtx.js.map +1 -0
- package/dist/ActionRunner.d.ts +16 -0
- package/dist/ActionRunner.d.ts.map +1 -0
- package/dist/ActionRunner.js +18 -0
- package/dist/ActionRunner.js.map +1 -0
- package/dist/AiGatewayDecisionClient.d.ts +20 -0
- package/dist/AiGatewayDecisionClient.d.ts.map +1 -0
- package/dist/AiGatewayDecisionClient.js +31 -0
- package/dist/AiGatewayDecisionClient.js.map +1 -0
- package/dist/AiGatewayDecisionModel.d.ts +24 -0
- package/dist/AiGatewayDecisionModel.d.ts.map +1 -0
- package/dist/AiGatewayDecisionModel.js +27 -0
- package/dist/AiGatewayDecisionModel.js.map +1 -0
- package/dist/AiGatewayLanguageClient.d.ts +21 -0
- package/dist/AiGatewayLanguageClient.d.ts.map +1 -0
- package/dist/AiGatewayLanguageClient.js +32 -0
- package/dist/AiGatewayLanguageClient.js.map +1 -0
- package/dist/AiGatewayLanguageModel.d.ts +95 -0
- package/dist/AiGatewayLanguageModel.d.ts.map +1 -0
- package/dist/AiGatewayLanguageModel.js +42 -0
- package/dist/AiGatewayLanguageModel.js.map +1 -0
- package/dist/Auth.d.ts +20 -0
- package/dist/Auth.d.ts.map +1 -0
- package/dist/Auth.js +31 -0
- package/dist/Auth.js.map +1 -0
- package/dist/BlobNotFoundError.d.ts +9 -0
- package/dist/BlobNotFoundError.d.ts.map +1 -0
- package/dist/BlobNotFoundError.js +13 -0
- package/dist/BlobNotFoundError.js.map +1 -0
- package/dist/Callback.d.ts +31 -0
- package/dist/Callback.d.ts.map +1 -0
- package/dist/Callback.js +182 -0
- package/dist/Callback.js.map +1 -0
- package/dist/ComponentCtx.d.ts +71 -0
- package/dist/ComponentCtx.d.ts.map +1 -0
- package/dist/ComponentCtx.js +0 -0
- package/dist/ConvexConfigProvider.d.ts +21 -0
- package/dist/ConvexConfigProvider.d.ts.map +1 -0
- package/dist/ConvexConfigProvider.js +36 -0
- package/dist/ConvexConfigProvider.js.map +1 -0
- package/dist/ConvexFunctionDefinitions.d.ts +25 -0
- package/dist/ConvexFunctionDefinitions.d.ts.map +1 -0
- package/dist/ConvexFunctionDefinitions.js +25 -0
- package/dist/ConvexFunctionDefinitions.js.map +1 -0
- package/dist/ConvexLogger.d.ts +17 -0
- package/dist/ConvexLogger.d.ts.map +1 -0
- package/dist/ConvexLogger.js +33 -0
- package/dist/ConvexLogger.js.map +1 -0
- package/dist/CronJob.d.ts +14 -0
- package/dist/CronJob.d.ts.map +1 -0
- package/dist/CronJob.js +22 -0
- package/dist/CronJob.js.map +1 -0
- package/dist/CronJobs.d.ts +22 -0
- package/dist/CronJobs.d.ts.map +1 -0
- package/dist/CronJobs.js +83 -0
- package/dist/CronJobs.js.map +1 -0
- package/dist/DataModel.d.ts +28 -0
- package/dist/DataModel.d.ts.map +1 -0
- package/dist/DataModel.js +7 -0
- package/dist/DataModel.js.map +1 -0
- package/dist/DatabaseReader.d.ts +26 -0
- package/dist/DatabaseReader.d.ts.map +1 -0
- package/dist/DatabaseReader.js +33 -0
- package/dist/DatabaseReader.js.map +1 -0
- package/dist/DatabaseSchema.d.ts +67 -0
- package/dist/DatabaseSchema.d.ts.map +1 -0
- package/dist/DatabaseSchema.js +61 -0
- package/dist/DatabaseSchema.js.map +1 -0
- package/dist/DatabaseWriter.d.ts +44 -0
- package/dist/DatabaseWriter.d.ts.map +1 -0
- package/dist/DatabaseWriter.js +47 -0
- package/dist/DatabaseWriter.js.map +1 -0
- package/dist/Document.d.ts +37 -0
- package/dist/Document.d.ts.map +1 -0
- package/dist/Document.js +54 -0
- package/dist/Document.js.map +1 -0
- package/dist/ExecutionMetadata.d.ts +13 -0
- package/dist/ExecutionMetadata.d.ts.map +1 -0
- package/dist/ExecutionMetadata.js +19 -0
- package/dist/ExecutionMetadata.js.map +1 -0
- package/dist/FunctionImpl.d.ts +39 -0
- package/dist/FunctionImpl.d.ts.map +1 -0
- package/dist/FunctionImpl.js +46 -0
- package/dist/FunctionImpl.js.map +1 -0
- package/dist/FunctionRegistryItem.d.ts +36 -0
- package/dist/FunctionRegistryItem.d.ts.map +1 -0
- package/dist/FunctionRegistryItem.js +34 -0
- package/dist/FunctionRegistryItem.js.map +1 -0
- package/dist/GroupImpl.d.ts +77 -0
- package/dist/GroupImpl.d.ts.map +1 -0
- package/dist/GroupImpl.js +81 -0
- package/dist/GroupImpl.js.map +1 -0
- package/dist/GroupRegistry.d.ts +8 -0
- package/dist/GroupRegistry.d.ts.map +1 -0
- package/dist/GroupRegistry.js +26 -0
- package/dist/GroupRegistry.js.map +1 -0
- package/dist/Handler.d.ts +47 -0
- package/dist/Handler.d.ts.map +1 -0
- package/dist/Handler.js +7 -0
- package/dist/Handler.js.map +1 -0
- package/dist/HttpRouter.d.ts +80 -0
- package/dist/HttpRouter.d.ts.map +1 -0
- package/dist/HttpRouter.js +195 -0
- package/dist/HttpRouter.js.map +1 -0
- package/dist/MiddlewareImpl.d.ts +79 -0
- package/dist/MiddlewareImpl.d.ts.map +1 -0
- package/dist/MiddlewareImpl.js +58 -0
- package/dist/MiddlewareImpl.js.map +1 -0
- package/dist/MiddlewareRegistryItem.d.ts +12 -0
- package/dist/MiddlewareRegistryItem.d.ts.map +1 -0
- package/dist/MiddlewareRegistryItem.js +15 -0
- package/dist/MiddlewareRegistryItem.js.map +1 -0
- package/dist/MutationCtx.d.ts +10 -0
- package/dist/MutationCtx.d.ts.map +1 -0
- package/dist/MutationCtx.js +18 -0
- package/dist/MutationCtx.js.map +1 -0
- package/dist/MutationRunner.d.ts +27 -0
- package/dist/MutationRunner.d.ts.map +1 -0
- package/dist/MutationRunner.js +28 -0
- package/dist/MutationRunner.js.map +1 -0
- package/dist/MutationTransactionContext.d.ts +17 -0
- package/dist/MutationTransactionContext.d.ts.map +1 -0
- package/dist/MutationTransactionContext.js +20 -0
- package/dist/MutationTransactionContext.js.map +1 -0
- package/dist/OrderedQuery.d.ts +32 -0
- package/dist/OrderedQuery.d.ts.map +1 -0
- package/dist/OrderedQuery.js +36 -0
- package/dist/OrderedQuery.js.map +1 -0
- package/dist/QueryCtx.d.ts +10 -0
- package/dist/QueryCtx.d.ts.map +1 -0
- package/dist/QueryCtx.js +18 -0
- package/dist/QueryCtx.js.map +1 -0
- package/dist/QueryInitializer.d.ts +75 -0
- package/dist/QueryInitializer.d.ts.map +1 -0
- package/dist/QueryInitializer.js +105 -0
- package/dist/QueryInitializer.js.map +1 -0
- package/dist/QueryRunner.d.ts +46 -0
- package/dist/QueryRunner.d.ts.map +1 -0
- package/dist/QueryRunner.js +30 -0
- package/dist/QueryRunner.js.map +1 -0
- package/dist/QueryStream.d.ts +678 -0
- package/dist/QueryStream.d.ts.map +1 -0
- package/dist/QueryStream.js +943 -0
- package/dist/QueryStream.js.map +1 -0
- package/dist/QueryStreamCursor.d.ts +39 -0
- package/dist/QueryStreamCursor.d.ts.map +1 -0
- package/dist/QueryStreamCursor.js +52 -0
- package/dist/QueryStreamCursor.js.map +1 -0
- package/dist/QueryStreamIndexPrefix.d.ts +48 -0
- package/dist/QueryStreamIndexPrefix.d.ts.map +1 -0
- package/dist/QueryStreamIndexPrefix.js +38 -0
- package/dist/QueryStreamIndexPrefix.js.map +1 -0
- package/dist/QueryStreamIndexRange.d.ts +193 -0
- package/dist/QueryStreamIndexRange.d.ts.map +1 -0
- package/dist/QueryStreamIndexRange.js +241 -0
- package/dist/QueryStreamIndexRange.js.map +1 -0
- package/dist/QueryStreamKey.d.ts +64 -0
- package/dist/QueryStreamKey.d.ts.map +1 -0
- package/dist/QueryStreamKey.js +69 -0
- package/dist/QueryStreamKey.js.map +1 -0
- package/dist/QueryStreamKeyBounds.d.ts +136 -0
- package/dist/QueryStreamKeyBounds.d.ts.map +1 -0
- package/dist/QueryStreamKeyBounds.js +208 -0
- package/dist/QueryStreamKeyBounds.js.map +1 -0
- package/dist/QueryStreamKeyLabels.d.ts +27 -0
- package/dist/QueryStreamKeyLabels.d.ts.map +1 -0
- package/dist/QueryStreamKeyLabels.js +22 -0
- package/dist/QueryStreamKeyLabels.js.map +1 -0
- package/dist/QueryStreamKeyLayout.d.ts +179 -0
- package/dist/QueryStreamKeyLayout.d.ts.map +1 -0
- package/dist/QueryStreamKeyLayout.js +167 -0
- package/dist/QueryStreamKeyLayout.js.map +1 -0
- package/dist/QueryStreamKeyValues.d.ts +40 -0
- package/dist/QueryStreamKeyValues.d.ts.map +1 -0
- package/dist/QueryStreamKeyValues.js +57 -0
- package/dist/QueryStreamKeyValues.js.map +1 -0
- package/dist/QueryStreamOrderDirection.d.ts +24 -0
- package/dist/QueryStreamOrderDirection.d.ts.map +1 -0
- package/dist/QueryStreamOrderDirection.js +11 -0
- package/dist/QueryStreamOrderDirection.js.map +1 -0
- package/dist/QueryStreamPagination.d.ts +264 -0
- package/dist/QueryStreamPagination.d.ts.map +1 -0
- package/dist/QueryStreamPagination.js +172 -0
- package/dist/QueryStreamPagination.js.map +1 -0
- package/dist/QueryStreamReadBudget.d.ts +63 -0
- package/dist/QueryStreamReadBudget.d.ts.map +1 -0
- package/dist/QueryStreamReadBudget.js +81 -0
- package/dist/QueryStreamReadBudget.js.map +1 -0
- package/dist/QueryTransactionContext.d.ts +16 -0
- package/dist/QueryTransactionContext.d.ts.map +1 -0
- package/dist/QueryTransactionContext.js +17 -0
- package/dist/QueryTransactionContext.js.map +1 -0
- package/dist/RegisteredConvexFunction.d.ts +359 -0
- package/dist/RegisteredConvexFunction.d.ts.map +1 -0
- package/dist/RegisteredConvexFunction.js +154 -0
- package/dist/RegisteredConvexFunction.js.map +1 -0
- package/dist/RegisteredFunction.d.ts +143 -0
- package/dist/RegisteredFunction.d.ts.map +1 -0
- package/dist/RegisteredFunction.js +125 -0
- package/dist/RegisteredFunction.js.map +1 -0
- package/dist/RegisteredFunctions.d.ts +57 -0
- package/dist/RegisteredFunctions.d.ts.map +1 -0
- package/dist/RegisteredFunctions.js +32 -0
- package/dist/RegisteredFunctions.js.map +1 -0
- package/dist/RegisteredNodeFunction.d.ts +11 -0
- package/dist/RegisteredNodeFunction.d.ts.map +1 -0
- package/dist/RegisteredNodeFunction.js +45 -0
- package/dist/RegisteredNodeFunction.js.map +1 -0
- package/dist/Registry.d.ts +12 -0
- package/dist/Registry.d.ts.map +1 -0
- package/dist/Registry.js +17 -0
- package/dist/Registry.js.map +1 -0
- package/dist/RegistryItems.d.ts +21 -0
- package/dist/RegistryItems.d.ts.map +1 -0
- package/dist/RegistryItems.js +27 -0
- package/dist/RegistryItems.js.map +1 -0
- package/dist/RequestMetadata.d.ts +12 -0
- package/dist/RequestMetadata.d.ts.map +1 -0
- package/dist/RequestMetadata.js +16 -0
- package/dist/RequestMetadata.js.map +1 -0
- package/dist/ResolvedMiddleware.d.ts +24 -0
- package/dist/ResolvedMiddleware.d.ts.map +1 -0
- package/dist/ResolvedMiddleware.js +34 -0
- package/dist/ResolvedMiddleware.js.map +1 -0
- package/dist/Scheduler.d.ts +31 -0
- package/dist/Scheduler.d.ts.map +1 -0
- package/dist/Scheduler.js +35 -0
- package/dist/Scheduler.js.map +1 -0
- package/dist/Storage.d.ts +22 -0
- package/dist/Storage.d.ts.map +1 -0
- package/dist/Storage.js +27 -0
- package/dist/Storage.js.map +1 -0
- package/dist/StorageActionWriter.d.ts +35 -0
- package/dist/StorageActionWriter.d.ts.map +1 -0
- package/dist/StorageActionWriter.js +24 -0
- package/dist/StorageActionWriter.js.map +1 -0
- package/dist/StorageReader.d.ts +26 -0
- package/dist/StorageReader.d.ts.map +1 -0
- package/dist/StorageReader.js +22 -0
- package/dist/StorageReader.js.map +1 -0
- package/dist/StorageWriter.d.ts +29 -0
- package/dist/StorageWriter.d.ts.map +1 -0
- package/dist/StorageWriter.js +24 -0
- package/dist/StorageWriter.js.map +1 -0
- package/dist/Table.d.ts +274 -0
- package/dist/Table.d.ts.map +1 -0
- package/dist/Table.js +70 -0
- package/dist/Table.js.map +1 -0
- package/dist/TableInfo.d.ts +44 -0
- package/dist/TableInfo.d.ts.map +1 -0
- package/dist/TableInfo.js +7 -0
- package/dist/TableInfo.js.map +1 -0
- package/dist/TransactionMetadata.d.ts +12 -0
- package/dist/TransactionMetadata.d.ts.map +1 -0
- package/dist/TransactionMetadata.js +16 -0
- package/dist/TransactionMetadata.js.map +1 -0
- package/dist/VectorSearch.d.ts +23 -0
- package/dist/VectorSearch.d.ts.map +1 -0
- package/dist/VectorSearch.js +17 -0
- package/dist/VectorSearch.js.map +1 -0
- package/dist/_virtual/_rolldown/runtime.js +13 -0
- package/dist/index.d.ts +88 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +61 -0
- package/dist/internal/AiGatewayDecisionClient.d.ts +7 -0
- package/dist/internal/AiGatewayDecisionClient.d.ts.map +1 -0
- package/dist/internal/AiGatewayDecisionClient.js +19 -0
- package/dist/internal/AiGatewayDecisionClient.js.map +1 -0
- package/dist/internal/AiGatewayLanguageClient.d.ts +7 -0
- package/dist/internal/AiGatewayLanguageClient.d.ts.map +1 -0
- package/dist/internal/AiGatewayLanguageClient.js +19 -0
- package/dist/internal/AiGatewayLanguageClient.js.map +1 -0
- package/dist/internal/AiGatewayServiceToken.d.ts +46 -0
- package/dist/internal/AiGatewayServiceToken.d.ts.map +1 -0
- package/dist/internal/AiGatewayServiceToken.js +62 -0
- package/dist/internal/AiGatewayServiceToken.js.map +1 -0
- package/dist/internal/constants.d.ts +2 -0
- package/dist/internal/constants.d.ts.map +1 -0
- package/dist/internal/constants.js +6 -0
- package/dist/internal/constants.js.map +1 -0
- package/dist/internal/utils.d.ts +13 -0
- package/dist/internal/utils.d.ts.map +1 -0
- package/dist/internal/utils.js +50 -0
- package/dist/internal/utils.js.map +1 -0
- package/dist/node.d.ts +2 -0
- package/dist/node.d.ts.map +1 -0
- package/dist/node.js +1 -0
- package/package.json +68 -3
- package/src/ActionCtx.ts +45 -0
- package/src/ActionRunner.ts +36 -0
- package/src/AiGatewayDecisionClient.ts +40 -0
- package/src/AiGatewayDecisionModel.ts +46 -0
- package/src/AiGatewayLanguageClient.ts +41 -0
- package/src/AiGatewayLanguageModel.ts +61 -0
- package/src/Auth.ts +51 -0
- package/src/BlobNotFoundError.ts +12 -0
- package/src/Callback.ts +313 -0
- package/src/ComponentCtx.ts +192 -0
- package/src/ConvexConfigProvider.ts +39 -0
- package/src/ConvexFunctionDefinitions.ts +91 -0
- package/src/ConvexLogger.ts +43 -0
- package/src/CronJob.ts +42 -0
- package/src/CronJobs.ts +165 -0
- package/src/DataModel.ts +81 -0
- package/src/DatabaseReader.ts +118 -0
- package/src/DatabaseSchema.ts +139 -0
- package/src/DatabaseWriter.ts +232 -0
- package/src/Document.ts +146 -0
- package/src/ExecutionMetadata.ts +26 -0
- package/src/FunctionImpl.ts +96 -0
- package/src/FunctionRegistryItem.ts +85 -0
- package/src/GroupImpl.ts +167 -0
- package/src/GroupRegistry.ts +41 -0
- package/src/Handler.ts +191 -0
- package/src/HttpRouter.ts +388 -0
- package/src/MiddlewareImpl.ts +247 -0
- package/src/MiddlewareRegistryItem.ts +21 -0
- package/src/MutationCtx.ts +45 -0
- package/src/MutationRunner.ts +66 -0
- package/src/MutationTransactionContext.ts +48 -0
- package/src/OrderedQuery.ts +136 -0
- package/src/QueryCtx.ts +45 -0
- package/src/QueryInitializer.ts +537 -0
- package/src/QueryRunner.ts +91 -0
- package/src/QueryStream.ts +2476 -0
- package/src/QueryStreamCursor.ts +99 -0
- package/src/QueryStreamIndexPrefix.ts +79 -0
- package/src/QueryStreamIndexRange.ts +489 -0
- package/src/QueryStreamKey.ts +118 -0
- package/src/QueryStreamKeyBounds.ts +395 -0
- package/src/QueryStreamKeyLabels.ts +56 -0
- package/src/QueryStreamKeyLayout.ts +382 -0
- package/src/QueryStreamKeyValues.ts +112 -0
- package/src/QueryStreamOrderDirection.ts +29 -0
- package/src/QueryStreamPagination.ts +357 -0
- package/src/QueryStreamReadBudget.ts +167 -0
- package/src/QueryTransactionContext.ts +37 -0
- package/src/RegisteredConvexFunction.ts +415 -0
- package/src/RegisteredFunction.ts +391 -0
- package/src/RegisteredFunctions.ts +88 -0
- package/src/RegisteredNodeFunction.ts +120 -0
- package/src/Registry.ts +17 -0
- package/src/RegistryItems.ts +40 -0
- package/src/RequestMetadata.ts +20 -0
- package/src/ResolvedMiddleware.ts +70 -0
- package/src/Scheduler.ts +85 -0
- package/src/Storage.ts +37 -0
- package/src/StorageActionWriter.ts +59 -0
- package/src/StorageReader.ts +59 -0
- package/src/StorageWriter.ts +58 -0
- package/src/Table.ts +156 -0
- package/src/TableInfo.ts +106 -0
- package/src/TransactionMetadata.ts +20 -0
- package/src/VectorSearch.ts +75 -0
- package/src/index.ts +87 -0
- package/src/internal/AiGatewayDecisionClient.ts +16 -0
- package/src/internal/AiGatewayLanguageClient.ts +16 -0
- package/src/internal/AiGatewayServiceToken.ts +129 -0
- package/src/internal/constants.ts +1 -0
- package/src/internal/utils.ts +89 -0
- package/src/node.ts +1 -0
|
@@ -0,0 +1,391 @@
|
|
|
1
|
+
import type { FunctionSpec, RuntimeAndFunctionType } from "@confect/core";
|
|
2
|
+
import * as IdScope from "@confect/core/IdScope";
|
|
3
|
+
import type * as FunctionProvenance from "@confect/core/FunctionProvenance";
|
|
4
|
+
import * as MiddlewareSpec from "@confect/core/MiddlewareSpec";
|
|
5
|
+
import {
|
|
6
|
+
compileArgsSchema,
|
|
7
|
+
compileReturnsSchema,
|
|
8
|
+
} from "@confect/core/SchemaToValidator";
|
|
9
|
+
import {
|
|
10
|
+
type DefaultFunctionArgs,
|
|
11
|
+
type FunctionVisibility,
|
|
12
|
+
type GenericActionCtx,
|
|
13
|
+
type GenericDataModel,
|
|
14
|
+
type StorageReader as ConvexStorageReader,
|
|
15
|
+
type RegisteredAction,
|
|
16
|
+
type RegisteredMutation,
|
|
17
|
+
type RegisteredQuery,
|
|
18
|
+
} from "convex/server";
|
|
19
|
+
import type { Value } from "convex/values";
|
|
20
|
+
import { ConvexError } from "convex/values";
|
|
21
|
+
import { pipe } from "effect/Function";
|
|
22
|
+
import * as Console from "effect/Console";
|
|
23
|
+
import * as Effect from "effect/Effect";
|
|
24
|
+
import * as Result from "effect/Result";
|
|
25
|
+
import * as Layer from "effect/Layer";
|
|
26
|
+
import * as Schema from "effect/Schema";
|
|
27
|
+
import type * as EffectScheduler from "effect/Scheduler";
|
|
28
|
+
import * as ActionCtx from "./ActionCtx";
|
|
29
|
+
import * as ActionRunner from "./ActionRunner";
|
|
30
|
+
import * as Auth from "./Auth";
|
|
31
|
+
import * as ConvexLogger from "./ConvexLogger";
|
|
32
|
+
import type * as DatabaseSchema from "./DatabaseSchema";
|
|
33
|
+
import type * as DataModel from "./DataModel";
|
|
34
|
+
import * as ExecutionMetadata from "./ExecutionMetadata";
|
|
35
|
+
import * as RequestMetadata from "./RequestMetadata";
|
|
36
|
+
import * as MutationRunner from "./MutationRunner";
|
|
37
|
+
import * as QueryRunner from "./QueryRunner";
|
|
38
|
+
import type * as ResolvedMiddleware from "./ResolvedMiddleware";
|
|
39
|
+
import * as Scheduler from "./Scheduler";
|
|
40
|
+
import * as Storage from "./Storage";
|
|
41
|
+
import * as StorageActionWriter from "./StorageActionWriter";
|
|
42
|
+
import type * as StorageReader from "./StorageReader";
|
|
43
|
+
import * as StorageWriter from "./StorageWriter";
|
|
44
|
+
import * as VectorSearch from "./VectorSearch";
|
|
45
|
+
import type * as Handler from "./Handler";
|
|
46
|
+
|
|
47
|
+
export type Any =
|
|
48
|
+
| RegisteredQuery<FunctionVisibility, DefaultFunctionArgs, any>
|
|
49
|
+
| RegisteredMutation<FunctionVisibility, DefaultFunctionArgs, any>
|
|
50
|
+
| RegisteredAction<FunctionVisibility, DefaultFunctionArgs, any>;
|
|
51
|
+
|
|
52
|
+
type ConfectRegisteredFunction<
|
|
53
|
+
FunctionSpec_ extends FunctionSpec.AnyWithProps,
|
|
54
|
+
> =
|
|
55
|
+
FunctionSpec.EncodedArgs<FunctionSpec_> extends infer Args_ extends
|
|
56
|
+
DefaultFunctionArgs
|
|
57
|
+
? RuntimeAndFunctionType.GetFunctionType<
|
|
58
|
+
FunctionSpec_["runtimeAndFunctionType"]
|
|
59
|
+
> extends "query"
|
|
60
|
+
? RegisteredQuery<
|
|
61
|
+
FunctionSpec.GetFunctionVisibility<FunctionSpec_>,
|
|
62
|
+
Args_,
|
|
63
|
+
Promise<FunctionSpec.EncodedReturns<FunctionSpec_>>
|
|
64
|
+
>
|
|
65
|
+
: RuntimeAndFunctionType.GetFunctionType<
|
|
66
|
+
FunctionSpec_["runtimeAndFunctionType"]
|
|
67
|
+
> extends "mutation"
|
|
68
|
+
? RegisteredMutation<
|
|
69
|
+
FunctionSpec.GetFunctionVisibility<FunctionSpec_>,
|
|
70
|
+
Args_,
|
|
71
|
+
Promise<FunctionSpec.EncodedReturns<FunctionSpec_>>
|
|
72
|
+
>
|
|
73
|
+
: RuntimeAndFunctionType.GetFunctionType<
|
|
74
|
+
FunctionSpec_["runtimeAndFunctionType"]
|
|
75
|
+
> extends "action"
|
|
76
|
+
? RegisteredAction<
|
|
77
|
+
FunctionSpec.GetFunctionVisibility<FunctionSpec_>,
|
|
78
|
+
Args_,
|
|
79
|
+
Promise<FunctionSpec.EncodedReturns<FunctionSpec_>>
|
|
80
|
+
>
|
|
81
|
+
: never
|
|
82
|
+
: never;
|
|
83
|
+
|
|
84
|
+
export type ConvexRegisteredFunction<
|
|
85
|
+
FunctionSpec_ extends FunctionSpec.AnyWithProps,
|
|
86
|
+
> = FunctionSpec_ extends FunctionSpec.AnyWithProps
|
|
87
|
+
? FunctionSpec.GetFunctionProvenance<FunctionSpec_> extends FunctionProvenance.Convex<
|
|
88
|
+
infer Args_ extends DefaultFunctionArgs,
|
|
89
|
+
infer Returns_
|
|
90
|
+
>
|
|
91
|
+
? RuntimeAndFunctionType.GetFunctionType<
|
|
92
|
+
FunctionSpec_["runtimeAndFunctionType"]
|
|
93
|
+
> extends "query"
|
|
94
|
+
? RegisteredQuery<
|
|
95
|
+
FunctionSpec.GetFunctionVisibility<FunctionSpec_>,
|
|
96
|
+
Args_,
|
|
97
|
+
Returns_
|
|
98
|
+
>
|
|
99
|
+
: RuntimeAndFunctionType.GetFunctionType<
|
|
100
|
+
FunctionSpec_["runtimeAndFunctionType"]
|
|
101
|
+
> extends "mutation"
|
|
102
|
+
? RegisteredMutation<
|
|
103
|
+
FunctionSpec.GetFunctionVisibility<FunctionSpec_>,
|
|
104
|
+
Args_,
|
|
105
|
+
Returns_
|
|
106
|
+
>
|
|
107
|
+
: RuntimeAndFunctionType.GetFunctionType<
|
|
108
|
+
FunctionSpec_["runtimeAndFunctionType"]
|
|
109
|
+
> extends "action"
|
|
110
|
+
? RegisteredAction<
|
|
111
|
+
FunctionSpec.GetFunctionVisibility<FunctionSpec_>,
|
|
112
|
+
Args_,
|
|
113
|
+
Returns_
|
|
114
|
+
>
|
|
115
|
+
: never
|
|
116
|
+
: never
|
|
117
|
+
: never;
|
|
118
|
+
|
|
119
|
+
export type RegisteredFunction<
|
|
120
|
+
FunctionSpec_ extends FunctionSpec.AnyWithProps,
|
|
121
|
+
> =
|
|
122
|
+
FunctionSpec_ extends FunctionSpec.WithFunctionProvenance<
|
|
123
|
+
FunctionSpec_,
|
|
124
|
+
FunctionProvenance.AnyConvex
|
|
125
|
+
>
|
|
126
|
+
? ConvexRegisteredFunction<FunctionSpec_>
|
|
127
|
+
: FunctionSpec_ extends FunctionSpec.WithFunctionProvenance<
|
|
128
|
+
FunctionSpec_,
|
|
129
|
+
FunctionProvenance.AnyConfect
|
|
130
|
+
>
|
|
131
|
+
? ConfectRegisteredFunction<FunctionSpec_>
|
|
132
|
+
: never;
|
|
133
|
+
|
|
134
|
+
/**
|
|
135
|
+
* Wrap a function's handler effect in its resolved middleware chain, per
|
|
136
|
+
* invocation, after args decode. Iterated innermost-first so that the
|
|
137
|
+
* first-attached (group-level, in attachment order) middleware ends up
|
|
138
|
+
* outermost and runs first. Erased types: the public safety story lives at the
|
|
139
|
+
* `MiddlewareSpec.MiddlewareImpl`/`MiddlewareImpl.make` signatures, and the
|
|
140
|
+
* composed effect's error channel is re-accounted by
|
|
141
|
+
* {@link combineErrorSchemas}.
|
|
142
|
+
*/
|
|
143
|
+
export const applyMiddleware = <A, E, R>(
|
|
144
|
+
effect: Effect.Effect<A, E, R>,
|
|
145
|
+
resolvedMiddlewares: ReadonlyArray<ResolvedMiddleware.ResolvedMiddleware>,
|
|
146
|
+
invocation: MiddlewareSpec.MiddlewareOptions["invocation"],
|
|
147
|
+
): Effect.Effect<A, any, R> => {
|
|
148
|
+
return resolvedMiddlewares.reduceRight<Effect.Effect<any, any, any>>(
|
|
149
|
+
// oxlint-disable-next-line effecttsgo/any-unknown-in-error-context -- The erased middleware error remains intact so runHandlerPromise can validate it against the combined error schema.
|
|
150
|
+
(wrapped, middleware) => {
|
|
151
|
+
const context =
|
|
152
|
+
"options" in middleware.middlewareSpec
|
|
153
|
+
? { options: middleware.options, invocation }
|
|
154
|
+
: { invocation };
|
|
155
|
+
// oxlint-disable-next-line effecttsgo/any-unknown-in-error-context -- Resolved middleware is type-erased after its public implementation boundary; its error and service channels are restored by the surrounding function contract.
|
|
156
|
+
return middleware.middlewareImpl(wrapped, context);
|
|
157
|
+
},
|
|
158
|
+
effect,
|
|
159
|
+
);
|
|
160
|
+
};
|
|
161
|
+
|
|
162
|
+
/**
|
|
163
|
+
* The error-schema allowlist for a function with middleware: the function's own
|
|
164
|
+
* declared `error` schema unioned with every covering middleware's error
|
|
165
|
+
* schema. `undefined` (⇒ every failure dies) only when neither declares
|
|
166
|
+
* one—mirroring the ref-side union clients decode against.
|
|
167
|
+
*/
|
|
168
|
+
export const combineErrorSchemas = (
|
|
169
|
+
error: Schema.Codec<any, any> | undefined,
|
|
170
|
+
resolvedMiddlewares: ReadonlyArray<ResolvedMiddleware.ResolvedMiddleware>,
|
|
171
|
+
): Schema.Codec<any, any> | undefined => {
|
|
172
|
+
const schemas = [
|
|
173
|
+
...(error !== undefined ? [error] : []),
|
|
174
|
+
...MiddlewareSpec.errorSchemas(
|
|
175
|
+
resolvedMiddlewares.map(({ middlewareSpec }) => middlewareSpec),
|
|
176
|
+
),
|
|
177
|
+
];
|
|
178
|
+
return schemas.length === 0
|
|
179
|
+
? undefined
|
|
180
|
+
: schemas.length === 1
|
|
181
|
+
? schemas[0]
|
|
182
|
+
: Schema.Union(schemas);
|
|
183
|
+
};
|
|
184
|
+
|
|
185
|
+
/**
|
|
186
|
+
* Run the `Effect` as a `Promise`. The error schema acts as an allowlist of
|
|
187
|
+
* failures that may be surfaced to the client as a `ConvexError`:
|
|
188
|
+
*
|
|
189
|
+
* - With a schema: typed errors are schema-encoded and wrapped in a
|
|
190
|
+
* `ConvexError`, then thrown so Convex surfaces the data to the client.
|
|
191
|
+
* `Effect.either` escapes the failure channel before `runPromise` so the
|
|
192
|
+
* thrown `ConvexError` retains its `Symbol.for("ConvexError")` identity
|
|
193
|
+
* instead of being wrapped in Effect's `FiberFailure`.
|
|
194
|
+
* - Without a schema: every failure is converted to a defect via `Effect.orDie`,
|
|
195
|
+
* so nothing—not even a `ConvexError` the handler placed in its error
|
|
196
|
+
* channel—reaches the client as a `ConvexError`. The fiber dies and
|
|
197
|
+
* `runPromise` rejects with a generic failure.
|
|
198
|
+
*
|
|
199
|
+
* Either way, a `ConvexError` _defect_—thrown imperatively rather than placed
|
|
200
|
+
* in the error channel, e.g. the pagination protocol's `InvalidCursor` signal
|
|
201
|
+
* from `QueryStream.paginate`—is rethrown bare so it retains its identity and
|
|
202
|
+
* Convex serializes its `data` to the client, matching how a thrown
|
|
203
|
+
* `ConvexError` behaves in a plain Convex handler.
|
|
204
|
+
*
|
|
205
|
+
* A `scheduler` in `runOptions` must be passed here as a run option rather than
|
|
206
|
+
* provided via `Effect.provideService` inside `effect`: the run option lands in
|
|
207
|
+
* the fiber's root context, while a service provided within `effect` pops
|
|
208
|
+
* before the `orDie`/`catch`/`result` wrappers this function adds. The fiber's
|
|
209
|
+
* op counter survives context pops, so a cooperative yield can fire inside
|
|
210
|
+
* those wrappers—only a root-context scheduler covers them.
|
|
211
|
+
*/
|
|
212
|
+
export const runHandlerPromise =
|
|
213
|
+
(
|
|
214
|
+
errorSchema: Schema.Codec<any, any> | undefined,
|
|
215
|
+
runOptions?: {
|
|
216
|
+
readonly scheduler?: EffectScheduler.Scheduler | undefined;
|
|
217
|
+
},
|
|
218
|
+
) =>
|
|
219
|
+
<A, E>(effect: Effect.Effect<A, E>): Promise<A> => {
|
|
220
|
+
// A `ConvexError` defect escapes into the (escaped) failure channel so
|
|
221
|
+
// the `throw` below rethrows it with its identity intact.
|
|
222
|
+
const rethrowConvexErrorDefects = Effect.catchDefect(
|
|
223
|
+
(defect: unknown): Effect.Effect<never, ConvexError<any>> =>
|
|
224
|
+
defect instanceof ConvexError
|
|
225
|
+
? Effect.fail(defect)
|
|
226
|
+
: Effect.die(defect),
|
|
227
|
+
);
|
|
228
|
+
|
|
229
|
+
const withConvexError =
|
|
230
|
+
errorSchema === undefined
|
|
231
|
+
? Effect.orDie(effect)
|
|
232
|
+
: effect.pipe(
|
|
233
|
+
Effect.catch((typedError) =>
|
|
234
|
+
pipe(
|
|
235
|
+
Schema.encodeEffect(errorSchema)(typedError),
|
|
236
|
+
Effect.catchTag("SchemaError", Effect.die),
|
|
237
|
+
Effect.andThen((encodedError) =>
|
|
238
|
+
Effect.fail(new ConvexError(encodedError)),
|
|
239
|
+
),
|
|
240
|
+
),
|
|
241
|
+
),
|
|
242
|
+
);
|
|
243
|
+
return Effect.runPromise(
|
|
244
|
+
Effect.result(rethrowConvexErrorDefects(withConvexError)).pipe(
|
|
245
|
+
Effect.provide(ConvexLogger.layer),
|
|
246
|
+
Effect.provideService(Console.Console, globalThis.console),
|
|
247
|
+
),
|
|
248
|
+
runOptions,
|
|
249
|
+
).then(
|
|
250
|
+
Result.match({
|
|
251
|
+
onFailure: (error) => {
|
|
252
|
+
throw error;
|
|
253
|
+
},
|
|
254
|
+
onSuccess: (value) => value,
|
|
255
|
+
}),
|
|
256
|
+
);
|
|
257
|
+
};
|
|
258
|
+
|
|
259
|
+
export const actionFunctionBase = <
|
|
260
|
+
Schema extends DatabaseSchema.AnyWithProps,
|
|
261
|
+
Args,
|
|
262
|
+
ConvexArgs extends DefaultFunctionArgs,
|
|
263
|
+
Returns,
|
|
264
|
+
ConvexReturns,
|
|
265
|
+
E,
|
|
266
|
+
R,
|
|
267
|
+
>({
|
|
268
|
+
name,
|
|
269
|
+
functionVisibility,
|
|
270
|
+
args,
|
|
271
|
+
returns,
|
|
272
|
+
error,
|
|
273
|
+
handler,
|
|
274
|
+
resolvedMiddlewares = [],
|
|
275
|
+
createLayer,
|
|
276
|
+
scope = IdScope.app,
|
|
277
|
+
}: {
|
|
278
|
+
name: string;
|
|
279
|
+
functionVisibility: FunctionVisibility;
|
|
280
|
+
args: Schema.Codec<Args, ConvexArgs>;
|
|
281
|
+
returns: Schema.Codec<Returns, ConvexReturns>;
|
|
282
|
+
error: Schema.Codec<Error, Value> | undefined;
|
|
283
|
+
handler: (a: Args) => Effect.Effect<Returns, E, R>;
|
|
284
|
+
resolvedMiddlewares?: ReadonlyArray<ResolvedMiddleware.ResolvedMiddleware>;
|
|
285
|
+
createLayer: (
|
|
286
|
+
ctx: GenericActionCtx<DataModel.ToConvex<DataModel.FromSchema<Schema>>>,
|
|
287
|
+
) => Layer.Layer<R>;
|
|
288
|
+
scope?: IdScope.IdScope;
|
|
289
|
+
}) => ({
|
|
290
|
+
args: compileArgsSchema(args, scope),
|
|
291
|
+
returns: compileReturnsSchema(returns, scope),
|
|
292
|
+
handler: (
|
|
293
|
+
ctx: GenericActionCtx<DataModel.ToConvex<DataModel.FromSchema<Schema>>>,
|
|
294
|
+
actualArgs: ConvexArgs,
|
|
295
|
+
): Promise<ConvexReturns> =>
|
|
296
|
+
Effect.gen(function* () {
|
|
297
|
+
const decodedArgs = yield* pipe(
|
|
298
|
+
actualArgs,
|
|
299
|
+
Schema.decodeUnknownEffect(args),
|
|
300
|
+
Effect.catchTag("SchemaError", Effect.die),
|
|
301
|
+
);
|
|
302
|
+
// oxlint-disable-next-line effecttsgo/any-unknown-in-error-context -- Middleware errors are intentionally erased here and validated by runHandlerPromise against the combined error schema below.
|
|
303
|
+
const decodedReturns = yield* applyMiddleware(
|
|
304
|
+
handler(decodedArgs),
|
|
305
|
+
resolvedMiddlewares,
|
|
306
|
+
{
|
|
307
|
+
name,
|
|
308
|
+
functionType: "action",
|
|
309
|
+
functionVisibility,
|
|
310
|
+
args: decodedArgs,
|
|
311
|
+
},
|
|
312
|
+
).pipe(Effect.provide(createLayer(ctx)));
|
|
313
|
+
return yield* pipe(
|
|
314
|
+
decodedReturns,
|
|
315
|
+
Schema.encodeEffect(returns),
|
|
316
|
+
Effect.catchTag("SchemaError", Effect.die),
|
|
317
|
+
);
|
|
318
|
+
}).pipe(runHandlerPromise(combineErrorSchemas(error, resolvedMiddlewares))),
|
|
319
|
+
});
|
|
320
|
+
|
|
321
|
+
export type ActionServices<
|
|
322
|
+
DatabaseSchema_ extends DatabaseSchema.AnyWithProps,
|
|
323
|
+
> = Handler.ActionServices<DatabaseSchema_>;
|
|
324
|
+
|
|
325
|
+
/**
|
|
326
|
+
* The ctx-backed action services that don't depend on a Confect database
|
|
327
|
+
* schema. {@link actionLayer} adds the schema-typed `VectorSearch` on top; the
|
|
328
|
+
* HTTP API handler uses this base directly.
|
|
329
|
+
*/
|
|
330
|
+
export const baseActionLayer = <ConvexDataModel extends GenericDataModel>(
|
|
331
|
+
ctx: GenericActionCtx<ConvexDataModel>,
|
|
332
|
+
) =>
|
|
333
|
+
Layer.mergeAll(
|
|
334
|
+
Scheduler.layer(ctx.scheduler),
|
|
335
|
+
Auth.layer(ctx.auth),
|
|
336
|
+
ExecutionMetadata.layer(ctx.meta),
|
|
337
|
+
RequestMetadata.layer(ctx.meta),
|
|
338
|
+
Storage.layer(ctx.storage),
|
|
339
|
+
StorageWriter.StorageWriter.layer(ctx.storage),
|
|
340
|
+
StorageActionWriter.StorageActionWriter.layer(ctx.storage),
|
|
341
|
+
QueryRunner.layer(ctx.runQuery.bind(ctx)),
|
|
342
|
+
MutationRunner.layer(ctx.runMutation.bind(ctx)),
|
|
343
|
+
ActionRunner.layer(ctx.runAction.bind(ctx)),
|
|
344
|
+
Layer.succeed(ActionCtx.ActionCtx<ConvexDataModel>(), ctx),
|
|
345
|
+
);
|
|
346
|
+
|
|
347
|
+
export const actionLayer = <
|
|
348
|
+
DatabaseSchema_ extends DatabaseSchema.AnyWithProps,
|
|
349
|
+
>(
|
|
350
|
+
databaseSchema: DatabaseSchema_,
|
|
351
|
+
ctx: GenericActionCtx<
|
|
352
|
+
DataModel.ToConvex<DataModel.FromSchema<DatabaseSchema_>>
|
|
353
|
+
>,
|
|
354
|
+
) =>
|
|
355
|
+
Layer.mergeAll(
|
|
356
|
+
Scheduler.layer<DatabaseSchema.Scope<DatabaseSchema_>>(
|
|
357
|
+
ctx.scheduler,
|
|
358
|
+
databaseSchema.target.scope,
|
|
359
|
+
),
|
|
360
|
+
Auth.layerForTarget<DatabaseSchema_["target"]>(
|
|
361
|
+
databaseSchema.target,
|
|
362
|
+
ctx.auth,
|
|
363
|
+
),
|
|
364
|
+
ExecutionMetadata.layer(ctx.meta),
|
|
365
|
+
RequestMetadata.layer(ctx.meta),
|
|
366
|
+
storageLayer<DatabaseSchema.Scope<DatabaseSchema_>>(ctx.storage),
|
|
367
|
+
StorageWriter.StorageWriter.layer<DatabaseSchema.Scope<DatabaseSchema_>>(
|
|
368
|
+
ctx.storage,
|
|
369
|
+
databaseSchema.target.scope,
|
|
370
|
+
),
|
|
371
|
+
StorageActionWriter.StorageActionWriter.layer<
|
|
372
|
+
DatabaseSchema.Scope<DatabaseSchema_>
|
|
373
|
+
>(ctx.storage, databaseSchema.target.scope),
|
|
374
|
+
QueryRunner.layer(ctx.runQuery.bind(ctx)),
|
|
375
|
+
MutationRunner.layer(ctx.runMutation.bind(ctx)),
|
|
376
|
+
ActionRunner.layer(ctx.runAction.bind(ctx)),
|
|
377
|
+
ActionCtx.layer<
|
|
378
|
+
DataModel.ToConvex<DataModel.FromSchema<DatabaseSchema_>>,
|
|
379
|
+
DatabaseSchema.Scope<DatabaseSchema_>
|
|
380
|
+
>(ctx, databaseSchema.target.scope),
|
|
381
|
+
VectorSearch.layer(ctx.vectorSearch.bind(ctx)),
|
|
382
|
+
);
|
|
383
|
+
|
|
384
|
+
// Scoped readers share the same runtime service and ID strings. Reuse the
|
|
385
|
+
// reader supplied by Storage so both APIs keep the same reader instance.
|
|
386
|
+
export const storageLayer = <Scope extends IdScope.IdScope>(
|
|
387
|
+
reader: ConvexStorageReader,
|
|
388
|
+
): Layer.Layer<Storage.Storage | StorageReader.ForScope<Scope>> =>
|
|
389
|
+
Storage.layer(reader) as Layer.Layer<
|
|
390
|
+
Storage.Storage | StorageReader.ForScope<Scope>
|
|
391
|
+
>;
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import * as ConvexFunctionDefinitions from "./ConvexFunctionDefinitions";
|
|
2
|
+
import type * as FunctionSpec from "@confect/core/FunctionSpec";
|
|
3
|
+
import type * as GroupSpec from "@confect/core/GroupSpec";
|
|
4
|
+
import type * as Spec from "@confect/core/Spec";
|
|
5
|
+
import type { Layer, Types } from "effect";
|
|
6
|
+
import type * as DatabaseSchema from "./DatabaseSchema";
|
|
7
|
+
import type * as GroupImpl from "./GroupImpl";
|
|
8
|
+
import type * as RegisteredFunction from "./RegisteredFunction";
|
|
9
|
+
|
|
10
|
+
export type RegisteredFunctions<Spec_ extends Spec.AnyWithProps> =
|
|
11
|
+
Types.Simplify<RegisteredFunctionsHelper<Spec.Groups<Spec_>>>;
|
|
12
|
+
|
|
13
|
+
type RegisteredFunctionsHelper<Groups extends GroupSpec.AnyWithProps> = {
|
|
14
|
+
[GroupName in GroupSpec.Name<Groups>]: GroupSpec.WithName<
|
|
15
|
+
Groups,
|
|
16
|
+
GroupName
|
|
17
|
+
> extends infer Group extends GroupSpec.AnyWithProps
|
|
18
|
+
? RegisteredFunctionsForGroupSpec<Group>
|
|
19
|
+
: never;
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* The `RegisteredFunction` record for a group's own declared functions.
|
|
24
|
+
*/
|
|
25
|
+
type RegisteredFunctionsOf<Group extends GroupSpec.AnyWithProps> = {
|
|
26
|
+
[
|
|
27
|
+
FunctionName in FunctionSpec.Name<GroupSpec.Functions<Group>>
|
|
28
|
+
]: FunctionSpec.WithName<
|
|
29
|
+
GroupSpec.Functions<Group>,
|
|
30
|
+
FunctionName
|
|
31
|
+
> extends infer FunctionSpec_ extends FunctionSpec.AnyWithProps
|
|
32
|
+
? RegisteredFunction.RegisteredFunction<FunctionSpec_>
|
|
33
|
+
: never;
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* The registered-functions record for a single group, derived from the group's
|
|
38
|
+
* own `GroupSpec`: its declared functions, plus any nested subgroups it carries
|
|
39
|
+
* directly. This is the node that `buildForGroup` returns—computed from the
|
|
40
|
+
* leaf `GroupSpec` itself rather than by navigating the project-wide assembled
|
|
41
|
+
* `Spec` to a dot-path, so the per-group registry's type depends only on its
|
|
42
|
+
* own leaf. For the filesystem layout a leaf `GroupSpec` carries no subgroups
|
|
43
|
+
* (subdirectory children are assembled separately into `_generated/spec.ts`),
|
|
44
|
+
* so this resolves to just the leaf's functions.
|
|
45
|
+
*/
|
|
46
|
+
export type RegisteredFunctionsForGroupSpec<
|
|
47
|
+
Group extends GroupSpec.AnyWithProps,
|
|
48
|
+
> =
|
|
49
|
+
GroupSpec.Groups<Group> extends infer SubGroups extends GroupSpec.AnyWithProps
|
|
50
|
+
? Types.Simplify<
|
|
51
|
+
RegisteredFunctionsHelper<SubGroups> & RegisteredFunctionsOf<Group>
|
|
52
|
+
>
|
|
53
|
+
: RegisteredFunctionsOf<Group>;
|
|
54
|
+
|
|
55
|
+
export interface AnyWithProps {
|
|
56
|
+
readonly [key: string]: RegisteredFunction.Any | AnyWithProps;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* Build the registered Convex functions for a single group from its finalized
|
|
61
|
+
* `GroupImpl` layer.
|
|
62
|
+
*
|
|
63
|
+
* The `groupLayer` parameter requires `GroupImpl<"Finalized">`, so impls that
|
|
64
|
+
* were never piped through `GroupImpl.finalize` (and impls with unmet
|
|
65
|
+
* `FunctionImpl` requirements, which cannot be finalized) are rejected at the
|
|
66
|
+
* codegen boundary, not just deep inside Convex at runtime.
|
|
67
|
+
*
|
|
68
|
+
* The group layer is built with a fresh, isolated `Registry` (rather than the
|
|
69
|
+
* globally-cached default `Context.Reference`), so each `FunctionImpl.make`
|
|
70
|
+
* registers under its flat, single-segment function-name key without colliding
|
|
71
|
+
* with any other group built in the same process—the built registry holds
|
|
72
|
+
* exactly this group's functions at the top level.
|
|
73
|
+
*
|
|
74
|
+
* Only the runtime `databaseSchema` value is needed at runtime (it is forwarded
|
|
75
|
+
* to isolate registration to build each function's ctx services); the group's
|
|
76
|
+
* `GroupSpec` is supplied purely as the `Group` type parameter to shape the
|
|
77
|
+
* returned record. Generated isolate modules instead prepare definitions with
|
|
78
|
+
* `ConvexFunctionDefinitions.buildForGroup` and add local forwarding handlers
|
|
79
|
+
* before shared registration. Node groups use
|
|
80
|
+
* `RegisteredNodeFunction.buildForGroup` from the Node entry.
|
|
81
|
+
*/
|
|
82
|
+
export const buildForGroup = <Group extends GroupSpec.AnyWithProps>(
|
|
83
|
+
databaseSchema: DatabaseSchema.AnyWithProps,
|
|
84
|
+
groupLayer: Layer.Layer<GroupImpl.GroupImpl<"Finalized">>,
|
|
85
|
+
): RegisteredFunctionsForGroupSpec<Group> =>
|
|
86
|
+
ConvexFunctionDefinitions.register<Group>(
|
|
87
|
+
ConvexFunctionDefinitions.buildForGroup(databaseSchema, groupLayer),
|
|
88
|
+
);
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
import * as NodeServices from "@effect/platform-node/NodeServices";
|
|
2
|
+
import {
|
|
3
|
+
actionGeneric,
|
|
4
|
+
type DefaultFunctionArgs,
|
|
5
|
+
type FunctionVisibility,
|
|
6
|
+
internalActionGeneric,
|
|
7
|
+
} from "convex/server";
|
|
8
|
+
import type { Effect } from "effect";
|
|
9
|
+
import type { Schema } from "effect";
|
|
10
|
+
import * as Layer from "effect/Layer";
|
|
11
|
+
import * as Match from "effect/Match";
|
|
12
|
+
import type * as DatabaseSchema from "./DatabaseSchema";
|
|
13
|
+
import * as RegisteredFunction from "./RegisteredFunction";
|
|
14
|
+
import * as FunctionRegistryItem from "./FunctionRegistryItem";
|
|
15
|
+
import * as ResolvedMiddleware from "./ResolvedMiddleware";
|
|
16
|
+
import * as GroupRegistry from "./GroupRegistry";
|
|
17
|
+
import type * as GroupSpec from "@confect/core/GroupSpec";
|
|
18
|
+
import type * as GroupImpl from "./GroupImpl";
|
|
19
|
+
import type * as RegisteredFunctions from "./RegisteredFunctions";
|
|
20
|
+
import { mapLeaves } from "./internal/utils";
|
|
21
|
+
|
|
22
|
+
export const buildForGroup = <Group extends GroupSpec.AnyWithProps>(
|
|
23
|
+
databaseSchema: DatabaseSchema.AnyWithProps,
|
|
24
|
+
groupLayer: Layer.Layer<GroupImpl.GroupImpl<"Finalized">>,
|
|
25
|
+
): RegisteredFunctions.RegisteredFunctionsForGroupSpec<Group> => {
|
|
26
|
+
const { functionRegistryItems, middlewareRegistryItems } =
|
|
27
|
+
GroupRegistry.make(groupLayer);
|
|
28
|
+
return mapLeaves<FunctionRegistryItem.AnyWithProps, RegisteredFunction.Any>(
|
|
29
|
+
functionRegistryItems as {
|
|
30
|
+
[key: string]: FunctionRegistryItem.AnyWithProps;
|
|
31
|
+
},
|
|
32
|
+
FunctionRegistryItem.isFunctionRegistryItem,
|
|
33
|
+
(item) =>
|
|
34
|
+
Match.value(item).pipe(
|
|
35
|
+
Match.tag("Convex", ({ handler }) => handler),
|
|
36
|
+
Match.tag("Confect", (confect) =>
|
|
37
|
+
make(
|
|
38
|
+
databaseSchema,
|
|
39
|
+
confect,
|
|
40
|
+
ResolvedMiddleware.resolve(confect, middlewareRegistryItems),
|
|
41
|
+
),
|
|
42
|
+
),
|
|
43
|
+
Match.exhaustive,
|
|
44
|
+
),
|
|
45
|
+
) as RegisteredFunctions.RegisteredFunctionsForGroupSpec<Group>;
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
export const make = (
|
|
49
|
+
databaseSchema: DatabaseSchema.AnyWithProps,
|
|
50
|
+
item: FunctionRegistryItem.ConfectFunctionRegistryItem,
|
|
51
|
+
resolvedMiddlewares: ReadonlyArray<ResolvedMiddleware.ResolvedMiddleware> = [],
|
|
52
|
+
): RegisteredFunction.Any => {
|
|
53
|
+
const genericFunction = Match.value(item.functionVisibility).pipe(
|
|
54
|
+
Match.when("public", () => actionGeneric),
|
|
55
|
+
Match.when("internal", () => internalActionGeneric),
|
|
56
|
+
Match.exhaustive,
|
|
57
|
+
);
|
|
58
|
+
|
|
59
|
+
return genericFunction(
|
|
60
|
+
nodeActionFunction(databaseSchema, {
|
|
61
|
+
name: item.name,
|
|
62
|
+
functionVisibility: item.functionVisibility,
|
|
63
|
+
args: item.args,
|
|
64
|
+
returns: item.returns,
|
|
65
|
+
error: item.error,
|
|
66
|
+
handler: item.handler,
|
|
67
|
+
resolvedMiddlewares,
|
|
68
|
+
}),
|
|
69
|
+
);
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
const nodeActionFunction = <
|
|
73
|
+
DatabaseSchema_ extends DatabaseSchema.AnyWithProps,
|
|
74
|
+
Args,
|
|
75
|
+
ConvexArgs extends DefaultFunctionArgs,
|
|
76
|
+
Returns,
|
|
77
|
+
ConvexReturns,
|
|
78
|
+
E,
|
|
79
|
+
>(
|
|
80
|
+
databaseSchema: DatabaseSchema_,
|
|
81
|
+
{
|
|
82
|
+
name,
|
|
83
|
+
functionVisibility,
|
|
84
|
+
args,
|
|
85
|
+
returns,
|
|
86
|
+
error,
|
|
87
|
+
handler,
|
|
88
|
+
resolvedMiddlewares,
|
|
89
|
+
}: {
|
|
90
|
+
name: string;
|
|
91
|
+
functionVisibility: FunctionVisibility;
|
|
92
|
+
args: Schema.Codec<Args, ConvexArgs>;
|
|
93
|
+
returns: Schema.Codec<Returns, ConvexReturns>;
|
|
94
|
+
error: Schema.Codec<any, any> | undefined;
|
|
95
|
+
handler: (
|
|
96
|
+
a: Args,
|
|
97
|
+
) => Effect.Effect<
|
|
98
|
+
Returns,
|
|
99
|
+
E,
|
|
100
|
+
| RegisteredFunction.ActionServices<DatabaseSchema_>
|
|
101
|
+
| NodeServices.NodeServices
|
|
102
|
+
>;
|
|
103
|
+
resolvedMiddlewares: ReadonlyArray<ResolvedMiddleware.ResolvedMiddleware>;
|
|
104
|
+
},
|
|
105
|
+
) =>
|
|
106
|
+
RegisteredFunction.actionFunctionBase({
|
|
107
|
+
scope: databaseSchema.target.scope,
|
|
108
|
+
name,
|
|
109
|
+
functionVisibility,
|
|
110
|
+
args,
|
|
111
|
+
returns,
|
|
112
|
+
error,
|
|
113
|
+
handler,
|
|
114
|
+
resolvedMiddlewares,
|
|
115
|
+
createLayer: (ctx) =>
|
|
116
|
+
Layer.mergeAll(
|
|
117
|
+
RegisteredFunction.actionLayer(databaseSchema, ctx),
|
|
118
|
+
NodeServices.layer,
|
|
119
|
+
),
|
|
120
|
+
});
|
package/src/Registry.ts
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import * as Context from "effect/Context";
|
|
2
|
+
import * as Ref from "effect/Ref";
|
|
3
|
+
import type { RegistryItems } from "./RegistryItems";
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Effect `Context.Reference` shared by everything that touches a group's
|
|
7
|
+
* registry—`FunctionImpl`/`MiddlewareImpl` initializers write to it,
|
|
8
|
+
* `RegisteredFunctions` reads it, and the CLI's impl validation inspects it—all
|
|
9
|
+
* through this one tag, without relying on Effect's global default-value cache
|
|
10
|
+
* to align separately-defined tags by string key.
|
|
11
|
+
*/
|
|
12
|
+
export const Registry = Context.Reference<Ref.Ref<RegistryItems>>(
|
|
13
|
+
"@confect/server/Registry",
|
|
14
|
+
{
|
|
15
|
+
defaultValue: () => Ref.makeUnsafe<RegistryItems>({}),
|
|
16
|
+
},
|
|
17
|
+
);
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import * as Array from "effect/Array";
|
|
2
|
+
import { pipe } from "effect/Function";
|
|
3
|
+
import * as Record from "effect/Record";
|
|
4
|
+
import * as FunctionRegistryItem from "./FunctionRegistryItem";
|
|
5
|
+
import * as MiddlewareRegistryItem from "./MiddlewareRegistryItem";
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Runtime tree that mirrors a `Spec`'s group structure. Values remain unknown
|
|
9
|
+
* at this boundary so producers and consumers can narrow branches and registry
|
|
10
|
+
* items as needed.
|
|
11
|
+
*/
|
|
12
|
+
export interface RegistryItems {
|
|
13
|
+
readonly [key: string]: unknown;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* The names of the function-shaped entries in a group's (flat, isolated)
|
|
18
|
+
* registry. `FunctionImpl.make` registers each function under a single-segment
|
|
19
|
+
* key, so the registry built for one group contains exactly that group's
|
|
20
|
+
* functions at the top level.
|
|
21
|
+
*/
|
|
22
|
+
export const functionNames = (items: RegistryItems): ReadonlyArray<string> =>
|
|
23
|
+
pipe(
|
|
24
|
+
Record.toEntries(items),
|
|
25
|
+
Array.filter(([, value]) =>
|
|
26
|
+
FunctionRegistryItem.isFunctionRegistryItem(value),
|
|
27
|
+
),
|
|
28
|
+
Array.map(([name]) => name),
|
|
29
|
+
);
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* The keys of the middleware implementations registered into a group's registry
|
|
33
|
+
* (stored under `middleware:<key>` entries by `MiddlewareImpl`).
|
|
34
|
+
*/
|
|
35
|
+
export const middlewareKeys = (items: RegistryItems): ReadonlyArray<string> =>
|
|
36
|
+
pipe(
|
|
37
|
+
Record.values(items),
|
|
38
|
+
Array.filter(MiddlewareRegistryItem.isMiddlewareRegistryItem),
|
|
39
|
+
Array.map((item) => item.middlewareSpec.key),
|
|
40
|
+
);
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { MutationMeta } from "convex/server";
|
|
2
|
+
import * as Context from "effect/Context";
|
|
3
|
+
import * as Effect from "effect/Effect";
|
|
4
|
+
import * as Layer from "effect/Layer";
|
|
5
|
+
|
|
6
|
+
export type { RequestMetadata as Metadata } from "convex/server";
|
|
7
|
+
|
|
8
|
+
const make = (meta: Pick<MutationMeta, "getRequestMetadata">) => ({
|
|
9
|
+
get: Effect.fn("RequestMetadata.get")(() =>
|
|
10
|
+
Effect.promise(() => meta.getRequestMetadata()),
|
|
11
|
+
),
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
export class RequestMetadata extends Context.Service<
|
|
15
|
+
RequestMetadata,
|
|
16
|
+
ReturnType<typeof make>
|
|
17
|
+
>()("@confect/server/RequestMetadata") {}
|
|
18
|
+
|
|
19
|
+
export const layer = (meta: Pick<MutationMeta, "getRequestMetadata">) =>
|
|
20
|
+
Layer.succeed(RequestMetadata, make(meta));
|