@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,388 @@
|
|
|
1
|
+
import {
|
|
2
|
+
type HttpRouter as ConvexHttpRouter,
|
|
3
|
+
httpActionGeneric,
|
|
4
|
+
httpRouter,
|
|
5
|
+
ROUTABLE_HTTP_METHODS,
|
|
6
|
+
type RouteSpecWithPathPrefix,
|
|
7
|
+
type GenericActionCtx,
|
|
8
|
+
type GenericDataModel,
|
|
9
|
+
} from "convex/server";
|
|
10
|
+
import * as Array from "effect/Array";
|
|
11
|
+
import * as Console from "effect/Console";
|
|
12
|
+
import * as Context from "effect/Context";
|
|
13
|
+
import * as Config from "effect/Config";
|
|
14
|
+
import * as Effect from "effect/Effect";
|
|
15
|
+
import type * as FileSystem from "effect/FileSystem";
|
|
16
|
+
import * as Layer from "effect/Layer";
|
|
17
|
+
import * as Match from "effect/Match";
|
|
18
|
+
import type * as Path from "effect/Path";
|
|
19
|
+
import * as Schema from "effect/Schema";
|
|
20
|
+
import * as SchemaAST from "effect/SchemaAST";
|
|
21
|
+
import * as FindMyWay from "effect/http/FindMyWay";
|
|
22
|
+
import * as HttpApi from "effect/http-api/HttpApi";
|
|
23
|
+
import type * as HttpApiGroup from "effect/http-api/HttpApiGroup";
|
|
24
|
+
import type * as Etag from "effect/http/Etag";
|
|
25
|
+
import type * as HttpPlatform from "effect/http/HttpPlatform";
|
|
26
|
+
import * as HttpRouter from "effect/http/HttpRouter";
|
|
27
|
+
import * as HttpServer from "effect/http/HttpServer";
|
|
28
|
+
import type * as ActionRunner from "./ActionRunner";
|
|
29
|
+
import type * as Auth from "./Auth";
|
|
30
|
+
import type { ExecutionMetadata } from "./ExecutionMetadata";
|
|
31
|
+
import type { RequestMetadata } from "./RequestMetadata";
|
|
32
|
+
import type * as DatabaseSchema from "./DatabaseSchema";
|
|
33
|
+
import type * as DataModel from "./DataModel";
|
|
34
|
+
import type * as Handler from "./Handler";
|
|
35
|
+
import * as ConvexConfigProvider from "./ConvexConfigProvider";
|
|
36
|
+
import * as ConvexLogger from "./ConvexLogger";
|
|
37
|
+
import type * as MutationRunner from "./MutationRunner";
|
|
38
|
+
import type * as QueryRunner from "./QueryRunner";
|
|
39
|
+
import * as RegisteredFunction from "./RegisteredFunction";
|
|
40
|
+
import type * as Scheduler from "./Scheduler";
|
|
41
|
+
import type { Storage } from "./Storage";
|
|
42
|
+
import type { StorageActionWriter } from "./StorageActionWriter";
|
|
43
|
+
import type { StorageReader } from "./StorageReader";
|
|
44
|
+
import type { StorageWriter } from "./StorageWriter";
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* The Confect services available to HTTP route handlers and middleware,
|
|
48
|
+
* supplied per request from the Convex action context.
|
|
49
|
+
*/
|
|
50
|
+
export type Services =
|
|
51
|
+
| QueryRunner.QueryRunner
|
|
52
|
+
| MutationRunner.MutationRunner
|
|
53
|
+
| ActionRunner.ActionRunner
|
|
54
|
+
| Scheduler.Scheduler
|
|
55
|
+
| Auth.Auth
|
|
56
|
+
| ExecutionMetadata
|
|
57
|
+
| RequestMetadata
|
|
58
|
+
| Storage
|
|
59
|
+
| StorageReader
|
|
60
|
+
| StorageWriter
|
|
61
|
+
| StorageActionWriter;
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* A layer that registers routes on the HTTP router—the input to {@link make}.
|
|
65
|
+
*
|
|
66
|
+
* Compose it from Effect's `effect/http` and `effect/http-api` modules:
|
|
67
|
+
* `HttpApiBuilder.layer(api)` registers an `HttpApi`'s endpoints (provide its
|
|
68
|
+
* group handler layers with `Layer.provide`), `HttpApiScalar.layer(api, ...)`
|
|
69
|
+
* serves interactive API docs, `HttpRouter.add` registers a plain route, and
|
|
70
|
+
* `HttpRouter.middleware(fn, { global: true })` applies middleware to every
|
|
71
|
+
* route. Merge any number of these with `Layer.mergeAll`.
|
|
72
|
+
*
|
|
73
|
+
* Route handlers and middleware may require any of the Confect {@link Services},
|
|
74
|
+
* which surface as request-level `Requires` markers and are supplied per
|
|
75
|
+
* request. Anything else the layer requires is a type error—notably, an
|
|
76
|
+
* `HttpApiBuilder.layer(api)` whose group handler layers are not provided
|
|
77
|
+
* leaves an `HttpApiGroup.ToService` requirement behind, so a missing handler
|
|
78
|
+
* group is caught at compile time.
|
|
79
|
+
*
|
|
80
|
+
* Layers are built with Confect's Convex-aware `ConfigProvider` in context, so
|
|
81
|
+
* `Config` reads (e.g. in `Layer.unwrap`) resolve against Convex environment
|
|
82
|
+
* variables.
|
|
83
|
+
*/
|
|
84
|
+
export type Routes<Services_ = Services> = Layer.Layer<
|
|
85
|
+
never,
|
|
86
|
+
never,
|
|
87
|
+
| HttpRouter.HttpRouter
|
|
88
|
+
| Etag.Generator
|
|
89
|
+
| FileSystem.FileSystem
|
|
90
|
+
| HttpPlatform.HttpPlatform
|
|
91
|
+
| Path.Path
|
|
92
|
+
| HttpRouter.Request<"Requires", Services_>
|
|
93
|
+
| HttpRouter.Request<"GlobalRequires", Services_>
|
|
94
|
+
| HttpRouter.Request<"Error", any>
|
|
95
|
+
| HttpRouter.Request<"GlobalError", any>
|
|
96
|
+
>;
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* Create a Convex HTTP router serving the given routes.
|
|
100
|
+
*
|
|
101
|
+
* A single catch-all `httpAction` is registered for every routable method under
|
|
102
|
+
* the path prefix `"/"`, making the Effect router the single source of truth
|
|
103
|
+
* for paths: place an API with `HttpApi.prefix` or absolute route paths.
|
|
104
|
+
* Requests that match no route receive the Effect router's 404 response.
|
|
105
|
+
*
|
|
106
|
+
* Supply `{ api }` with the `HttpApi` registered by the routes layer to show
|
|
107
|
+
* endpoint patterns in Convex completion logs and the dashboard. Requests that
|
|
108
|
+
* match no reflected endpoint keep the catch-all completion label. Without the
|
|
109
|
+
* option, Convex reports the catch-all registrations. Application endpoints
|
|
110
|
+
* must not overlap component HTTP mounts: Convex also uses dashboard route
|
|
111
|
+
* entries to select between application and component routers.
|
|
112
|
+
*
|
|
113
|
+
* Plain Convex routes can still be added to the returned router—Convex matches
|
|
114
|
+
* exact paths first and longer path prefixes before the catch-all, so they take
|
|
115
|
+
* precedence.
|
|
116
|
+
*/
|
|
117
|
+
export const make = <Id extends string, Groups extends HttpApiGroup.Constraint>(
|
|
118
|
+
routes: Routes,
|
|
119
|
+
options?: { readonly api?: HttpApi.HttpApi<Id, Groups> | undefined },
|
|
120
|
+
): ConvexHttpRouter =>
|
|
121
|
+
makeWithLayer(routes, RegisteredFunction.baseActionLayer, options?.api);
|
|
122
|
+
|
|
123
|
+
/**
|
|
124
|
+
* Derive HTTP capabilities and ID scopes from the generated database schema.
|
|
125
|
+
* Component routes are relative to their installation's HTTP mount prefix.
|
|
126
|
+
* Supply `{ api }` as in {@link make}; labels stay component-relative.
|
|
127
|
+
*/
|
|
128
|
+
export const forSchema =
|
|
129
|
+
<DatabaseSchema_ extends DatabaseSchema.AnyWithProps>(
|
|
130
|
+
schema: DatabaseSchema_,
|
|
131
|
+
) =>
|
|
132
|
+
<Id extends string, Groups extends HttpApiGroup.Constraint>(
|
|
133
|
+
routes: Routes<Handler.ActionServices<DatabaseSchema_>>,
|
|
134
|
+
options?: { readonly api?: HttpApi.HttpApi<Id, Groups> | undefined },
|
|
135
|
+
): ConvexHttpRouter =>
|
|
136
|
+
makeWithLayer<
|
|
137
|
+
Handler.ActionServices<DatabaseSchema_>,
|
|
138
|
+
DataModel.ToConvex<DataModel.FromSchema<DatabaseSchema_>>,
|
|
139
|
+
Id,
|
|
140
|
+
Groups
|
|
141
|
+
>(
|
|
142
|
+
Match.value(schema.target.kind).pipe(
|
|
143
|
+
Match.when("app", () => routes),
|
|
144
|
+
Match.when("component", () =>
|
|
145
|
+
routes.pipe(Layer.provide(componentRouter)),
|
|
146
|
+
),
|
|
147
|
+
Match.exhaustive,
|
|
148
|
+
),
|
|
149
|
+
(ctx) => RegisteredFunction.actionLayer(schema, ctx),
|
|
150
|
+
options?.api,
|
|
151
|
+
);
|
|
152
|
+
|
|
153
|
+
// Convex uses a component-relative path to select its HTTP action but passes
|
|
154
|
+
// the original request URL to that action. Its CONVEX_SITE_URL includes the
|
|
155
|
+
// installation's full mount prefix (including parent mounts). Prefixing the
|
|
156
|
+
// Effect router preserves relative routes without rewriting the Request body.
|
|
157
|
+
const componentRouter = Layer.effect(
|
|
158
|
+
HttpRouter.HttpRouter,
|
|
159
|
+
Effect.gen(function* () {
|
|
160
|
+
const router = yield* HttpRouter.HttpRouter;
|
|
161
|
+
const siteUrl = yield* Config.schema(
|
|
162
|
+
Schema.URLFromString,
|
|
163
|
+
"CONVEX_SITE_URL",
|
|
164
|
+
);
|
|
165
|
+
return router.prefixed(siteUrl.pathname);
|
|
166
|
+
}).pipe(Effect.orDie),
|
|
167
|
+
);
|
|
168
|
+
|
|
169
|
+
const makeWithLayer = <
|
|
170
|
+
Services_,
|
|
171
|
+
DataModel_ extends GenericDataModel,
|
|
172
|
+
Id extends string,
|
|
173
|
+
Groups extends HttpApiGroup.Constraint,
|
|
174
|
+
>(
|
|
175
|
+
routes: Routes<Services_>,
|
|
176
|
+
layer: (ctx: GenericActionCtx<DataModel_>) => Layer.Layer<Services_>,
|
|
177
|
+
api: HttpApi.HttpApi<Id, Groups> | undefined,
|
|
178
|
+
): ConvexHttpRouter => {
|
|
179
|
+
applyMonkeyPatches();
|
|
180
|
+
|
|
181
|
+
// Provided (not just merged) so that route layers' own construction—e.g.
|
|
182
|
+
// a `Layer.unwrap` reading `Config`—resolves configuration through the
|
|
183
|
+
// Convex-aware provider; merged so that request fibers—endpoint handlers
|
|
184
|
+
// and middleware—do too.
|
|
185
|
+
const AppLayer = routes.pipe(
|
|
186
|
+
Layer.provideMerge(ConvexLogger.layer),
|
|
187
|
+
Layer.provideMerge(ConvexConfigProvider.layer),
|
|
188
|
+
Layer.provide(HttpServer.layerServices),
|
|
189
|
+
);
|
|
190
|
+
|
|
191
|
+
// The Confect service requirements of route handlers and middleware surface
|
|
192
|
+
// as request-level `Requires` markers on the layer, which the web handler
|
|
193
|
+
// exposes as a per-request context argument.
|
|
194
|
+
const { handler } = HttpRouter.toWebHandler(AppLayer, {
|
|
195
|
+
disableLogger: true,
|
|
196
|
+
});
|
|
197
|
+
|
|
198
|
+
const httpAction = httpActionGeneric((ctx, request): Promise<Response> => {
|
|
199
|
+
// The ctx-backed service layers are all synchronous and finalizer-free,
|
|
200
|
+
// so the scope can close as soon as the context is built.
|
|
201
|
+
// Convex's HTTP registration erases the data model. The supplied generated
|
|
202
|
+
// schema restores it; this does not change the runtime context or services.
|
|
203
|
+
const services = Effect.runSync(
|
|
204
|
+
Effect.scoped(
|
|
205
|
+
Layer.build(layer(ctx as unknown as GenericActionCtx<DataModel_>)),
|
|
206
|
+
),
|
|
207
|
+
);
|
|
208
|
+
return handler(
|
|
209
|
+
request,
|
|
210
|
+
Context.add(services, Console.Console, globalThis.console),
|
|
211
|
+
);
|
|
212
|
+
});
|
|
213
|
+
|
|
214
|
+
const convexHttpRouter = httpRouter();
|
|
215
|
+
|
|
216
|
+
Array.forEach(ROUTABLE_HTTP_METHODS, (method) => {
|
|
217
|
+
const routeSpec: RouteSpecWithPathPrefix = {
|
|
218
|
+
pathPrefix: "/",
|
|
219
|
+
method,
|
|
220
|
+
handler: httpAction,
|
|
221
|
+
};
|
|
222
|
+
convexHttpRouter.route(routeSpec);
|
|
223
|
+
});
|
|
224
|
+
|
|
225
|
+
if (api !== undefined) {
|
|
226
|
+
const matcher = FindMyWay.make<string>();
|
|
227
|
+
const reflected: ReturnType<ConvexHttpRouter["getRoutes"]> = [];
|
|
228
|
+
HttpApi.reflect(api, {
|
|
229
|
+
onGroup: () => {},
|
|
230
|
+
onEndpoint: ({ endpoint }) => {
|
|
231
|
+
const method = ROUTABLE_HTTP_METHODS.find(
|
|
232
|
+
(candidate) => candidate === endpoint.method,
|
|
233
|
+
);
|
|
234
|
+
if (method === undefined) return;
|
|
235
|
+
const path = apiRouterPath(
|
|
236
|
+
endpoint.path as FindMyWay.PathInput,
|
|
237
|
+
endpoint.params,
|
|
238
|
+
);
|
|
239
|
+
matcher.on(method, path, endpoint.path);
|
|
240
|
+
// Effect also matches a wildcard route's base path without its slash.
|
|
241
|
+
if (path.endsWith("/*")) {
|
|
242
|
+
matcher.on(method, path.slice(0, -2) as `/${string}`, endpoint.path);
|
|
243
|
+
}
|
|
244
|
+
reflected.push([endpoint.path, method, httpAction]);
|
|
245
|
+
},
|
|
246
|
+
});
|
|
247
|
+
reflected.sort(
|
|
248
|
+
([pathA, methodA], [pathB, methodB]) =>
|
|
249
|
+
pathA.localeCompare(pathB) || methodA.localeCompare(methodB),
|
|
250
|
+
);
|
|
251
|
+
|
|
252
|
+
const getRoutes = convexHttpRouter.getRoutes;
|
|
253
|
+
convexHttpRouter.getRoutes = () =>
|
|
254
|
+
reflected.length === 0
|
|
255
|
+
? getRoutes()
|
|
256
|
+
: [
|
|
257
|
+
...getRoutes().filter(([, , action]) => action !== httpAction),
|
|
258
|
+
...reflected,
|
|
259
|
+
];
|
|
260
|
+
const lookup = convexHttpRouter.lookup;
|
|
261
|
+
convexHttpRouter.lookup = (path, method) => {
|
|
262
|
+
const match = lookup(path, method);
|
|
263
|
+
if (match === null || match[0] !== httpAction) return match;
|
|
264
|
+
const normalized = match[1];
|
|
265
|
+
const reflectedPath = matcher.find(normalized, path)?.handler;
|
|
266
|
+
return reflectedPath === undefined
|
|
267
|
+
? match
|
|
268
|
+
: [httpAction, normalized, reflectedPath];
|
|
269
|
+
};
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
return convexHttpRouter;
|
|
273
|
+
};
|
|
274
|
+
|
|
275
|
+
/*!
|
|
276
|
+
* apiRouterPath is adapted from Effect 4.0.1 http-api/internal/path.ts.
|
|
277
|
+
*
|
|
278
|
+
* MIT License
|
|
279
|
+
*
|
|
280
|
+
* Copyright (c) 2023 Effectful Technologies Inc
|
|
281
|
+
*
|
|
282
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
283
|
+
* of this software and associated documentation files (the "Software"), to deal
|
|
284
|
+
* in the Software without restriction, including without limitation the rights
|
|
285
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
286
|
+
* copies of the Software, and to permit persons to whom the Software is
|
|
287
|
+
* furnished to do so, subject to the following conditions:
|
|
288
|
+
*
|
|
289
|
+
* The above copyright notice and this permission notice shall be included in all
|
|
290
|
+
* copies or substantial portions of the Software.
|
|
291
|
+
*
|
|
292
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
293
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
294
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
295
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
296
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
297
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
298
|
+
* SOFTWARE.
|
|
299
|
+
*/
|
|
300
|
+
// Match Effect's HttpApiBuilder path normalization, which is not publicly
|
|
301
|
+
// exported (effect/http-api/internal/path.ts). Undeclared colons are literals;
|
|
302
|
+
// declared params followed by a literal suffix need an explicit regex boundary.
|
|
303
|
+
const apiRouterPath = (
|
|
304
|
+
path: FindMyWay.PathInput,
|
|
305
|
+
params: Schema.Top | undefined,
|
|
306
|
+
): FindMyWay.PathInput => {
|
|
307
|
+
if (params === undefined || !path.includes(":")) return path;
|
|
308
|
+
let ast = params.ast;
|
|
309
|
+
while (ast.encoding !== undefined) {
|
|
310
|
+
ast = ast.encoding[ast.encoding.length - 1].to;
|
|
311
|
+
}
|
|
312
|
+
if (!SchemaAST.isObjects(ast) || ast.indexSignatures.length !== 0)
|
|
313
|
+
return path;
|
|
314
|
+
const names = new Set(
|
|
315
|
+
ast.propertySignatures.map((property) => String(property.name)),
|
|
316
|
+
);
|
|
317
|
+
let normalized = "";
|
|
318
|
+
let depth = 0;
|
|
319
|
+
let regexStart = -1;
|
|
320
|
+
for (let i = 0; i < path.length; i++) {
|
|
321
|
+
const char = path[i];
|
|
322
|
+
if (depth > 0 || i === regexStart) {
|
|
323
|
+
normalized += char;
|
|
324
|
+
if (char === "\\") normalized += path[++i] ?? "";
|
|
325
|
+
else if (char === "(") depth++;
|
|
326
|
+
else if (char === ")") depth--;
|
|
327
|
+
} else if (char !== ":") {
|
|
328
|
+
normalized += char;
|
|
329
|
+
} else if (path[i + 1] === ":") {
|
|
330
|
+
normalized += "::";
|
|
331
|
+
i++;
|
|
332
|
+
} else {
|
|
333
|
+
const param = /^:(\w+)/.exec(path.slice(i));
|
|
334
|
+
if (param !== null && names.has(param[1])) {
|
|
335
|
+
normalized += param[0];
|
|
336
|
+
i += param[0].length - 1;
|
|
337
|
+
const next = path[i + 1];
|
|
338
|
+
if (next === "(") regexStart = i + 1;
|
|
339
|
+
else if (next !== undefined && !"/.-?".includes(next))
|
|
340
|
+
normalized += "(.*?)";
|
|
341
|
+
} else {
|
|
342
|
+
normalized += "::";
|
|
343
|
+
}
|
|
344
|
+
}
|
|
345
|
+
}
|
|
346
|
+
return normalized as FindMyWay.PathInput;
|
|
347
|
+
};
|
|
348
|
+
|
|
349
|
+
// These are necessary until the Convex runtime supports these APIs. See
|
|
350
|
+
// https://discord.com/channels/1019350475847499849/1281364098419785760
|
|
351
|
+
// Each patch is applied only where the API is actually broken, so runtimes
|
|
352
|
+
// with working implementations—Node under convex-test, notably, where
|
|
353
|
+
// `new AbortSignal()` is an illegal constructor—keep their native behavior.
|
|
354
|
+
const applyMonkeyPatches = () => {
|
|
355
|
+
const urlCredentialsBroken = (() => {
|
|
356
|
+
try {
|
|
357
|
+
return new URL("https://confect.dev").username === undefined;
|
|
358
|
+
} catch {
|
|
359
|
+
return true;
|
|
360
|
+
}
|
|
361
|
+
})();
|
|
362
|
+
if (urlCredentialsBroken) {
|
|
363
|
+
URL = class extends URL {
|
|
364
|
+
override get username() {
|
|
365
|
+
return "";
|
|
366
|
+
}
|
|
367
|
+
override get password() {
|
|
368
|
+
return "";
|
|
369
|
+
}
|
|
370
|
+
};
|
|
371
|
+
}
|
|
372
|
+
|
|
373
|
+
const requestSignalBroken = (() => {
|
|
374
|
+
try {
|
|
375
|
+
return new Request("https://confect.dev").signal === undefined;
|
|
376
|
+
} catch {
|
|
377
|
+
return true;
|
|
378
|
+
}
|
|
379
|
+
})();
|
|
380
|
+
if (requestSignalBroken) {
|
|
381
|
+
// `configurable` so repeated definition—e.g. module re-evaluation in a
|
|
382
|
+
// long-lived environment—does not throw.
|
|
383
|
+
Object.defineProperty(Request.prototype, "signal", {
|
|
384
|
+
get: () => new AbortSignal(),
|
|
385
|
+
configurable: true,
|
|
386
|
+
});
|
|
387
|
+
}
|
|
388
|
+
};
|
|
@@ -0,0 +1,247 @@
|
|
|
1
|
+
import type * as FunctionSpec from "@confect/core/FunctionSpec";
|
|
2
|
+
import type * as GroupSpec from "@confect/core/GroupSpec";
|
|
3
|
+
import * as MiddlewareSpec from "@confect/core/MiddlewareSpec";
|
|
4
|
+
import * as Registry from "./Registry";
|
|
5
|
+
import type { FunctionType } from "convex/server";
|
|
6
|
+
import * as Context from "effect/Context";
|
|
7
|
+
import * as Effect from "effect/Effect";
|
|
8
|
+
import * as Layer from "effect/Layer";
|
|
9
|
+
import * as Ref from "effect/Ref";
|
|
10
|
+
import type * as Auth from "./Auth";
|
|
11
|
+
import type * as DatabaseReader from "./DatabaseReader";
|
|
12
|
+
import type * as DatabaseSchema from "./DatabaseSchema";
|
|
13
|
+
import type * as Handler from "./Handler";
|
|
14
|
+
import type { ExecutionMetadata } from "./ExecutionMetadata";
|
|
15
|
+
import type { RequestMetadata } from "./RequestMetadata";
|
|
16
|
+
import type { TransactionMetadata } from "./TransactionMetadata";
|
|
17
|
+
import type * as MutationRunner from "./MutationRunner";
|
|
18
|
+
import type * as QueryRunner from "./QueryRunner";
|
|
19
|
+
import type { QueryTransactionContext } from "./QueryTransactionContext";
|
|
20
|
+
import type * as Scheduler from "./Scheduler";
|
|
21
|
+
import type { Storage } from "./Storage";
|
|
22
|
+
import type * as StorageReader from "./StorageReader";
|
|
23
|
+
import type * as StorageWriter from "./StorageWriter";
|
|
24
|
+
import * as MiddlewareRegistryItem from "./MiddlewareRegistryItem";
|
|
25
|
+
import { setNestedProperty } from "./internal/utils";
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Marker service produced by providing a middleware's implementation to a
|
|
29
|
+
* group's impl layer. `GroupImpl.make` requires one per middleware attached to
|
|
30
|
+
* the group's spec (via {@link FromGroupSpec}), so `GroupImpl.finalize`'s `RIn =
|
|
31
|
+
* never` bound rejects a group that attaches a middleware but never provides
|
|
32
|
+
* its implementation—the exact mechanism used for `FunctionImpl`s.
|
|
33
|
+
*/
|
|
34
|
+
export interface MiddlewareImpl<MiddlewareKey extends string> {
|
|
35
|
+
readonly middlewareKey: MiddlewareKey;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export const MiddlewareImpl = <MiddlewareKey extends string>({
|
|
39
|
+
middlewareKey,
|
|
40
|
+
}: {
|
|
41
|
+
middlewareKey: MiddlewareKey;
|
|
42
|
+
}) =>
|
|
43
|
+
Context.Service<MiddlewareImpl<MiddlewareKey>>(
|
|
44
|
+
`@confect/server/MiddlewareImpl/${middlewareKey}`,
|
|
45
|
+
);
|
|
46
|
+
|
|
47
|
+
export type FromGroupSpec<Group extends GroupSpec.AnyWithProps> =
|
|
48
|
+
| GroupSpec.MiddlewareSpecs<Group>
|
|
49
|
+
| FunctionSpec.MiddlewareSpecs<
|
|
50
|
+
GroupSpec.Functions<Group>
|
|
51
|
+
> extends infer MiddlewareSpec_
|
|
52
|
+
? MiddlewareSpec_ extends MiddlewareSpec.AnyMiddlewareSpec
|
|
53
|
+
? MiddlewareImpl<MiddlewareSpec.Key<MiddlewareSpec_>>
|
|
54
|
+
: never
|
|
55
|
+
: never;
|
|
56
|
+
|
|
57
|
+
export type FunctionTypeServices<
|
|
58
|
+
DatabaseSchema_ extends DatabaseSchema.AnyWithProps,
|
|
59
|
+
FunctionType_ extends FunctionType,
|
|
60
|
+
> = FunctionType_ extends "query"
|
|
61
|
+
? Handler.QueryServices<DatabaseSchema_>
|
|
62
|
+
: FunctionType_ extends "mutation"
|
|
63
|
+
? Handler.MutationServices<DatabaseSchema_>
|
|
64
|
+
: FunctionType_ extends "action"
|
|
65
|
+
? Handler.ActionServices<DatabaseSchema_>
|
|
66
|
+
: never;
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* The services a single middleware implementation may use: the set-theoretic
|
|
70
|
+
* intersection of the ctx-service unions of the middleware's declared
|
|
71
|
+
* `functionTypes`, so one implementation is valid in every runtime it can be
|
|
72
|
+
* invoked in. Enumerated by hand rather than derived with
|
|
73
|
+
* `Exclude`/`Extract`—several ctx services are structurally typed (e.g. the raw
|
|
74
|
+
* `GenericQueryCtx`/`GenericMutationCtx` tags), so conditional-type set
|
|
75
|
+
* arithmetic over them is not reliable.
|
|
76
|
+
*/
|
|
77
|
+
export type CommonServices<
|
|
78
|
+
DatabaseSchema_ extends DatabaseSchema.AnyWithProps,
|
|
79
|
+
FunctionTypes extends FunctionType,
|
|
80
|
+
> = [FunctionTypes] extends ["query"]
|
|
81
|
+
? Handler.QueryServices<DatabaseSchema_>
|
|
82
|
+
: [FunctionTypes] extends ["mutation"]
|
|
83
|
+
? Handler.MutationServices<DatabaseSchema_>
|
|
84
|
+
: [FunctionTypes] extends ["action"]
|
|
85
|
+
? Handler.ActionServices<DatabaseSchema_>
|
|
86
|
+
: [FunctionTypes] extends ["query" | "mutation"]
|
|
87
|
+
? QueryMutationCommonServices<DatabaseSchema_>
|
|
88
|
+
: [FunctionTypes] extends ["mutation" | "action"]
|
|
89
|
+
? MutationActionCommonServices
|
|
90
|
+
: AllFunctionTypesCommonServices;
|
|
91
|
+
|
|
92
|
+
type QueryMutationCommonServices<
|
|
93
|
+
DatabaseSchema_ extends DatabaseSchema.AnyWithProps,
|
|
94
|
+
> =
|
|
95
|
+
| DatabaseReader.DatabaseReader<DatabaseSchema_>
|
|
96
|
+
| Auth.Auth
|
|
97
|
+
| ExecutionMetadata
|
|
98
|
+
| TransactionMetadata
|
|
99
|
+
| QueryTransactionContext
|
|
100
|
+
| Storage
|
|
101
|
+
| StorageReader.StorageReader
|
|
102
|
+
| QueryRunner.QueryRunner;
|
|
103
|
+
|
|
104
|
+
type MutationActionCommonServices =
|
|
105
|
+
| Auth.Auth
|
|
106
|
+
| ExecutionMetadata
|
|
107
|
+
| RequestMetadata
|
|
108
|
+
| Scheduler.Scheduler
|
|
109
|
+
| Storage
|
|
110
|
+
| StorageReader.StorageReader
|
|
111
|
+
| StorageWriter.StorageWriter
|
|
112
|
+
| QueryRunner.QueryRunner
|
|
113
|
+
| MutationRunner.MutationRunner;
|
|
114
|
+
|
|
115
|
+
type AllFunctionTypesCommonServices =
|
|
116
|
+
| Auth.Auth
|
|
117
|
+
| ExecutionMetadata
|
|
118
|
+
| Storage
|
|
119
|
+
| StorageReader.StorageReader
|
|
120
|
+
| QueryRunner.QueryRunner;
|
|
121
|
+
|
|
122
|
+
const layerFromImpls = <
|
|
123
|
+
MiddlewareSpec_ extends MiddlewareSpec.AnyMiddlewareSpec,
|
|
124
|
+
>(
|
|
125
|
+
middlewareSpec: MiddlewareSpec_,
|
|
126
|
+
impls: MiddlewareRegistryItem.MiddlewareRegistryItem["impls"],
|
|
127
|
+
): Layer.Layer<MiddlewareImpl<MiddlewareSpec.Key<MiddlewareSpec_>>> =>
|
|
128
|
+
Layer.effect(
|
|
129
|
+
MiddlewareImpl<MiddlewareSpec.Key<MiddlewareSpec_>>({
|
|
130
|
+
middlewareKey: middlewareSpec.key,
|
|
131
|
+
}),
|
|
132
|
+
Effect.gen(function* () {
|
|
133
|
+
const registry = yield* Registry.Registry;
|
|
134
|
+
|
|
135
|
+
yield* Ref.update(registry, (registryItems) =>
|
|
136
|
+
setNestedProperty(
|
|
137
|
+
registryItems,
|
|
138
|
+
[MiddlewareRegistryItem.registryKey(middlewareSpec.key)],
|
|
139
|
+
{
|
|
140
|
+
[MiddlewareRegistryItem.TypeId]: MiddlewareRegistryItem.TypeId,
|
|
141
|
+
middlewareSpec,
|
|
142
|
+
impls,
|
|
143
|
+
} satisfies MiddlewareRegistryItem.MiddlewareRegistryItem,
|
|
144
|
+
),
|
|
145
|
+
);
|
|
146
|
+
|
|
147
|
+
return { middlewareKey: middlewareSpec.key };
|
|
148
|
+
}),
|
|
149
|
+
);
|
|
150
|
+
|
|
151
|
+
/**
|
|
152
|
+
* Provide a middleware's implementation with a single strategy shared by every
|
|
153
|
+
* function type the middleware declares. The implementation's environment is
|
|
154
|
+
* bounded by {@link CommonServices}—the intersection of the declared
|
|
155
|
+
* functionTypes' ctx services—plus the middleware's declared `requires`, which
|
|
156
|
+
* middleware running earlier in the chain provide. Reach for
|
|
157
|
+
* {@link makeByFunctionType} when one strategy can't fit all declared
|
|
158
|
+
* functionTypes (the usual case for database-touching middleware attached to
|
|
159
|
+
* actions).
|
|
160
|
+
*
|
|
161
|
+
* Like `FunctionImpl.make`, `databaseSchema` is a type-level carrier only.
|
|
162
|
+
*/
|
|
163
|
+
export const make = <
|
|
164
|
+
DatabaseSchema_ extends DatabaseSchema.AnyWithProps,
|
|
165
|
+
MiddlewareSpec_ extends MiddlewareSpec.AnyMiddlewareSpec,
|
|
166
|
+
>(
|
|
167
|
+
_databaseSchema: DatabaseSchema_,
|
|
168
|
+
middlewareSpec: MiddlewareSpec_,
|
|
169
|
+
impl: MiddlewareSpec.MiddlewareImpl<
|
|
170
|
+
MiddlewareSpec.Provides<MiddlewareSpec_>,
|
|
171
|
+
MiddlewareSpec.Error<MiddlewareSpec_>,
|
|
172
|
+
| CommonServices<
|
|
173
|
+
DatabaseSchema_,
|
|
174
|
+
MiddlewareSpec.FunctionTypes<MiddlewareSpec_>
|
|
175
|
+
>
|
|
176
|
+
| MiddlewareSpec.Requires<MiddlewareSpec_>,
|
|
177
|
+
MiddlewareSpec.Options<MiddlewareSpec_>
|
|
178
|
+
>,
|
|
179
|
+
): Layer.Layer<MiddlewareImpl<MiddlewareSpec.Key<MiddlewareSpec_>>> =>
|
|
180
|
+
layerFromImpls(
|
|
181
|
+
middlewareSpec,
|
|
182
|
+
Object.fromEntries(
|
|
183
|
+
MiddlewareSpec.allFunctionTypes
|
|
184
|
+
.filter((functionType) => middlewareSpec.functionTypes[functionType])
|
|
185
|
+
.map((functionType) => [
|
|
186
|
+
functionType,
|
|
187
|
+
impl as MiddlewareSpec.AnyMiddlewareImpl,
|
|
188
|
+
]),
|
|
189
|
+
),
|
|
190
|
+
);
|
|
191
|
+
|
|
192
|
+
/**
|
|
193
|
+
* Provide a middleware's implementation with one strategy per declared function
|
|
194
|
+
* type. Each entry may use that function type's full ctx-service union—the
|
|
195
|
+
* recommended shape for database-touching middleware that also covers actions:
|
|
196
|
+
* use `DatabaseReader`/`DatabaseWriter` in queries and mutations, and
|
|
197
|
+
* `runQuery` of an internal query in actions.
|
|
198
|
+
*/
|
|
199
|
+
export const makeByFunctionType = <
|
|
200
|
+
DatabaseSchema_ extends DatabaseSchema.AnyWithProps,
|
|
201
|
+
MiddlewareSpec_ extends MiddlewareSpec.AnyMiddlewareSpec,
|
|
202
|
+
>(
|
|
203
|
+
_databaseSchema: DatabaseSchema_,
|
|
204
|
+
middlewareSpec: MiddlewareSpec_,
|
|
205
|
+
impls: {
|
|
206
|
+
readonly [
|
|
207
|
+
FunctionType_ in MiddlewareSpec.FunctionTypes<MiddlewareSpec_>
|
|
208
|
+
]: MiddlewareSpec.MiddlewareImpl<
|
|
209
|
+
MiddlewareSpec.Provides<MiddlewareSpec_>,
|
|
210
|
+
MiddlewareSpec.Error<MiddlewareSpec_>,
|
|
211
|
+
| FunctionTypeServices<DatabaseSchema_, FunctionType_>
|
|
212
|
+
| MiddlewareSpec.Requires<MiddlewareSpec_>,
|
|
213
|
+
MiddlewareSpec.Options<MiddlewareSpec_>
|
|
214
|
+
>;
|
|
215
|
+
},
|
|
216
|
+
): Layer.Layer<MiddlewareImpl<MiddlewareSpec.Key<MiddlewareSpec_>>> =>
|
|
217
|
+
layerFromImpls(
|
|
218
|
+
middlewareSpec,
|
|
219
|
+
impls as MiddlewareRegistryItem.MiddlewareRegistryItem["impls"],
|
|
220
|
+
);
|
|
221
|
+
|
|
222
|
+
/**
|
|
223
|
+
* Sugar over {@link make} for the flagship "run something, provide a service"
|
|
224
|
+
* shape: run `effect` before the rest of the chain and provide its result under
|
|
225
|
+
* `tag` (the runtime tag for the middleware's type-level `provides` service,
|
|
226
|
+
* passed explicitly since the spec class only knows it at the type level).
|
|
227
|
+
*/
|
|
228
|
+
export const provides = <
|
|
229
|
+
DatabaseSchema_ extends DatabaseSchema.AnyWithProps,
|
|
230
|
+
MiddlewareSpec_ extends MiddlewareSpec.AnyMiddlewareSpec,
|
|
231
|
+
Shape,
|
|
232
|
+
>(
|
|
233
|
+
databaseSchema: DatabaseSchema_,
|
|
234
|
+
middlewareSpec: MiddlewareSpec_,
|
|
235
|
+
tag: Context.Key<MiddlewareSpec.Provides<MiddlewareSpec_>, Shape>,
|
|
236
|
+
effect: Effect.Effect<
|
|
237
|
+
Shape,
|
|
238
|
+
MiddlewareSpec.Error<MiddlewareSpec_>,
|
|
239
|
+
| CommonServices<
|
|
240
|
+
DatabaseSchema_,
|
|
241
|
+
MiddlewareSpec.FunctionTypes<MiddlewareSpec_>
|
|
242
|
+
>
|
|
243
|
+
| MiddlewareSpec.Requires<MiddlewareSpec_>
|
|
244
|
+
>,
|
|
245
|
+
): Layer.Layer<MiddlewareImpl<MiddlewareSpec.Key<MiddlewareSpec_>>> =>
|
|
246
|
+
make(databaseSchema, middlewareSpec, ((handlerEffect: Effect.Effect<any>) =>
|
|
247
|
+
Effect.provideServiceEffect(handlerEffect, tag, effect)) as any);
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type * as MiddlewareSpec from "@confect/core/MiddlewareSpec";
|
|
2
|
+
import type { FunctionType } from "convex/server";
|
|
3
|
+
import * as Predicate from "effect/Predicate";
|
|
4
|
+
|
|
5
|
+
export const TypeId = "~@confect/server/MiddlewareRegistryItem";
|
|
6
|
+
export type TypeId = typeof TypeId;
|
|
7
|
+
|
|
8
|
+
export interface MiddlewareRegistryItem {
|
|
9
|
+
readonly [TypeId]: TypeId;
|
|
10
|
+
readonly middlewareSpec: MiddlewareSpec.AnyMiddlewareSpec;
|
|
11
|
+
readonly impls: Partial<
|
|
12
|
+
Record<FunctionType, MiddlewareSpec.AnyMiddlewareImpl>
|
|
13
|
+
>;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export const isMiddlewareRegistryItem = (
|
|
17
|
+
u: unknown,
|
|
18
|
+
): u is MiddlewareRegistryItem => Predicate.hasProperty(u, TypeId);
|
|
19
|
+
|
|
20
|
+
export const registryKey = (middlewareKey: string): string =>
|
|
21
|
+
`middleware:${middlewareKey}`;
|