@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,80 @@
|
|
|
1
|
+
import { type HttpRouter as ConvexHttpRouter } from "convex/server";
|
|
2
|
+
import type * as FileSystem from "effect/FileSystem";
|
|
3
|
+
import * as Layer from "effect/Layer";
|
|
4
|
+
import type * as Path from "effect/Path";
|
|
5
|
+
import * as HttpApi from "effect/http-api/HttpApi";
|
|
6
|
+
import type * as HttpApiGroup from "effect/http-api/HttpApiGroup";
|
|
7
|
+
import type * as Etag from "effect/http/Etag";
|
|
8
|
+
import type * as HttpPlatform from "effect/http/HttpPlatform";
|
|
9
|
+
import * as HttpRouter from "effect/http/HttpRouter";
|
|
10
|
+
import type * as ActionRunner from "./ActionRunner";
|
|
11
|
+
import type * as Auth from "./Auth";
|
|
12
|
+
import type { ExecutionMetadata } from "./ExecutionMetadata";
|
|
13
|
+
import type { RequestMetadata } from "./RequestMetadata";
|
|
14
|
+
import type * as DatabaseSchema from "./DatabaseSchema";
|
|
15
|
+
import type * as Handler from "./Handler";
|
|
16
|
+
import type * as MutationRunner from "./MutationRunner";
|
|
17
|
+
import type * as QueryRunner from "./QueryRunner";
|
|
18
|
+
import type * as Scheduler from "./Scheduler";
|
|
19
|
+
import type { Storage } from "./Storage";
|
|
20
|
+
import type { StorageActionWriter } from "./StorageActionWriter";
|
|
21
|
+
import type { StorageReader } from "./StorageReader";
|
|
22
|
+
import type { StorageWriter } from "./StorageWriter";
|
|
23
|
+
/**
|
|
24
|
+
* The Confect services available to HTTP route handlers and middleware,
|
|
25
|
+
* supplied per request from the Convex action context.
|
|
26
|
+
*/
|
|
27
|
+
export type Services = QueryRunner.QueryRunner | MutationRunner.MutationRunner | ActionRunner.ActionRunner | Scheduler.Scheduler | Auth.Auth | ExecutionMetadata | RequestMetadata | Storage | StorageReader | StorageWriter | StorageActionWriter;
|
|
28
|
+
/**
|
|
29
|
+
* A layer that registers routes on the HTTP router—the input to {@link make}.
|
|
30
|
+
*
|
|
31
|
+
* Compose it from Effect's `effect/http` and `effect/http-api` modules:
|
|
32
|
+
* `HttpApiBuilder.layer(api)` registers an `HttpApi`'s endpoints (provide its
|
|
33
|
+
* group handler layers with `Layer.provide`), `HttpApiScalar.layer(api, ...)`
|
|
34
|
+
* serves interactive API docs, `HttpRouter.add` registers a plain route, and
|
|
35
|
+
* `HttpRouter.middleware(fn, { global: true })` applies middleware to every
|
|
36
|
+
* route. Merge any number of these with `Layer.mergeAll`.
|
|
37
|
+
*
|
|
38
|
+
* Route handlers and middleware may require any of the Confect {@link Services},
|
|
39
|
+
* which surface as request-level `Requires` markers and are supplied per
|
|
40
|
+
* request. Anything else the layer requires is a type error—notably, an
|
|
41
|
+
* `HttpApiBuilder.layer(api)` whose group handler layers are not provided
|
|
42
|
+
* leaves an `HttpApiGroup.ToService` requirement behind, so a missing handler
|
|
43
|
+
* group is caught at compile time.
|
|
44
|
+
*
|
|
45
|
+
* Layers are built with Confect's Convex-aware `ConfigProvider` in context, so
|
|
46
|
+
* `Config` reads (e.g. in `Layer.unwrap`) resolve against Convex environment
|
|
47
|
+
* variables.
|
|
48
|
+
*/
|
|
49
|
+
export type Routes<Services_ = Services> = Layer.Layer<never, never, HttpRouter.HttpRouter | Etag.Generator | FileSystem.FileSystem | HttpPlatform.HttpPlatform | Path.Path | HttpRouter.Request<"Requires", Services_> | HttpRouter.Request<"GlobalRequires", Services_> | HttpRouter.Request<"Error", any> | HttpRouter.Request<"GlobalError", any>>;
|
|
50
|
+
/**
|
|
51
|
+
* Create a Convex HTTP router serving the given routes.
|
|
52
|
+
*
|
|
53
|
+
* A single catch-all `httpAction` is registered for every routable method under
|
|
54
|
+
* the path prefix `"/"`, making the Effect router the single source of truth
|
|
55
|
+
* for paths: place an API with `HttpApi.prefix` or absolute route paths.
|
|
56
|
+
* Requests that match no route receive the Effect router's 404 response.
|
|
57
|
+
*
|
|
58
|
+
* Supply `{ api }` with the `HttpApi` registered by the routes layer to show
|
|
59
|
+
* endpoint patterns in Convex completion logs and the dashboard. Requests that
|
|
60
|
+
* match no reflected endpoint keep the catch-all completion label. Without the
|
|
61
|
+
* option, Convex reports the catch-all registrations. Application endpoints
|
|
62
|
+
* must not overlap component HTTP mounts: Convex also uses dashboard route
|
|
63
|
+
* entries to select between application and component routers.
|
|
64
|
+
*
|
|
65
|
+
* Plain Convex routes can still be added to the returned router—Convex matches
|
|
66
|
+
* exact paths first and longer path prefixes before the catch-all, so they take
|
|
67
|
+
* precedence.
|
|
68
|
+
*/
|
|
69
|
+
export declare const make: <Id extends string, Groups extends HttpApiGroup.Constraint>(routes: Routes, options?: {
|
|
70
|
+
readonly api?: HttpApi.HttpApi<Id, Groups> | undefined;
|
|
71
|
+
}) => ConvexHttpRouter;
|
|
72
|
+
/**
|
|
73
|
+
* Derive HTTP capabilities and ID scopes from the generated database schema.
|
|
74
|
+
* Component routes are relative to their installation's HTTP mount prefix.
|
|
75
|
+
* Supply `{ api }` as in {@link make}; labels stay component-relative.
|
|
76
|
+
*/
|
|
77
|
+
export declare const forSchema: <DatabaseSchema_ extends DatabaseSchema.AnyWithProps>(schema: DatabaseSchema_) => <Id extends string, Groups extends HttpApiGroup.Constraint>(routes: Routes<Handler.ActionServices<DatabaseSchema_>>, options?: {
|
|
78
|
+
readonly api?: HttpApi.HttpApi<Id, Groups> | undefined;
|
|
79
|
+
}) => ConvexHttpRouter;
|
|
80
|
+
//# sourceMappingURL=HttpRouter.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"HttpRouter.d.ts","sourceRoot":"","sources":["../src/HttpRouter.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,UAAU,IAAI,gBAAgB,EAOpC,MAAM,eAAe,CAAC;AAMvB,OAAO,KAAK,KAAK,UAAU,MAAM,mBAAmB,CAAC;AACrD,OAAO,KAAK,KAAK,MAAM,cAAc,CAAC;AAEtC,OAAO,KAAK,KAAK,IAAI,MAAM,aAAa,CAAC;AAIzC,OAAO,KAAK,OAAO,MAAM,yBAAyB,CAAC;AACnD,OAAO,KAAK,KAAK,YAAY,MAAM,8BAA8B,CAAC;AAClE,OAAO,KAAK,KAAK,IAAI,MAAM,kBAAkB,CAAC;AAC9C,OAAO,KAAK,KAAK,YAAY,MAAM,0BAA0B,CAAC;AAC9D,OAAO,KAAK,UAAU,MAAM,wBAAwB,CAAC;AAErD,OAAO,KAAK,KAAK,YAAY,MAAM,gBAAgB,CAAC;AACpD,OAAO,KAAK,KAAK,IAAI,MAAM,QAAQ,CAAC;AACpC,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AAC7D,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AACzD,OAAO,KAAK,KAAK,cAAc,MAAM,kBAAkB,CAAC;AAExD,OAAO,KAAK,KAAK,OAAO,MAAM,WAAW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;IAAE,QAAQ,CAAC,GAAG,CAAC,EAAE,OAAO,CAAC,OAAO,CAAC,EAAE,EAAE,MAAM,CAAC,GAAG,SAAS,CAAA;CAAE,KACnE,gBACsE,CAAC;AAE1E;;;;GAIG;AACH,eAAO,MAAM,SAAS,GACnB,eAAe,SAAS,cAAc,CAAC,YAAY,UAC1C,eAAe,MAExB,EAAE,SAAS,MAAM,EAAE,MAAM,SAAS,YAAY,CAAC,UAAU,UAChD,MAAM,CAAC,OAAO,CAAC,cAAc,CAAC,eAAe,CAAC,CAAC,YAC7C;IAAE,QAAQ,CAAC,GAAG,CAAC,EAAE,OAAO,CAAC,OAAO,CAAC,EAAE,EAAE,MAAM,CAAC,GAAG,SAAS,CAAA;CAAE,KACnE,gBAgBA,CAAC"}
|
|
@@ -0,0 +1,195 @@
|
|
|
1
|
+
import { __exportAll } from "./_virtual/_rolldown/runtime.js";
|
|
2
|
+
import { layer } from "./ConvexConfigProvider.js";
|
|
3
|
+
import { layer as layer$1 } from "./ConvexLogger.js";
|
|
4
|
+
import { actionLayer, baseActionLayer } from "./RegisteredFunction.js";
|
|
5
|
+
import * as Context from "effect/Context";
|
|
6
|
+
import * as Layer from "effect/Layer";
|
|
7
|
+
import * as Effect from "effect/Effect";
|
|
8
|
+
import { ROUTABLE_HTTP_METHODS, httpActionGeneric, httpRouter } from "convex/server";
|
|
9
|
+
import * as Schema from "effect/Schema";
|
|
10
|
+
import * as Match from "effect/Match";
|
|
11
|
+
import * as Array from "effect/Array";
|
|
12
|
+
import * as SchemaAST from "effect/SchemaAST";
|
|
13
|
+
import * as Console from "effect/Console";
|
|
14
|
+
import * as Config from "effect/Config";
|
|
15
|
+
import * as FindMyWay from "effect/http/FindMyWay";
|
|
16
|
+
import * as HttpApi from "effect/http-api/HttpApi";
|
|
17
|
+
import * as HttpRouter from "effect/http/HttpRouter";
|
|
18
|
+
import * as HttpServer from "effect/http/HttpServer";
|
|
19
|
+
//#region src/HttpRouter.ts
|
|
20
|
+
var HttpRouter_exports = /* @__PURE__ */ __exportAll({
|
|
21
|
+
forSchema: () => forSchema,
|
|
22
|
+
make: () => make
|
|
23
|
+
});
|
|
24
|
+
/**
|
|
25
|
+
* Create a Convex HTTP router serving the given routes.
|
|
26
|
+
*
|
|
27
|
+
* A single catch-all `httpAction` is registered for every routable method under
|
|
28
|
+
* the path prefix `"/"`, making the Effect router the single source of truth
|
|
29
|
+
* for paths: place an API with `HttpApi.prefix` or absolute route paths.
|
|
30
|
+
* Requests that match no route receive the Effect router's 404 response.
|
|
31
|
+
*
|
|
32
|
+
* Supply `{ api }` with the `HttpApi` registered by the routes layer to show
|
|
33
|
+
* endpoint patterns in Convex completion logs and the dashboard. Requests that
|
|
34
|
+
* match no reflected endpoint keep the catch-all completion label. Without the
|
|
35
|
+
* option, Convex reports the catch-all registrations. Application endpoints
|
|
36
|
+
* must not overlap component HTTP mounts: Convex also uses dashboard route
|
|
37
|
+
* entries to select between application and component routers.
|
|
38
|
+
*
|
|
39
|
+
* Plain Convex routes can still be added to the returned router—Convex matches
|
|
40
|
+
* exact paths first and longer path prefixes before the catch-all, so they take
|
|
41
|
+
* precedence.
|
|
42
|
+
*/
|
|
43
|
+
const make = (routes, options) => makeWithLayer(routes, baseActionLayer, options?.api);
|
|
44
|
+
/**
|
|
45
|
+
* Derive HTTP capabilities and ID scopes from the generated database schema.
|
|
46
|
+
* Component routes are relative to their installation's HTTP mount prefix.
|
|
47
|
+
* Supply `{ api }` as in {@link make}; labels stay component-relative.
|
|
48
|
+
*/
|
|
49
|
+
const forSchema = (schema) => (routes, options) => makeWithLayer(Match.value(schema.target.kind).pipe(Match.when("app", () => routes), Match.when("component", () => routes.pipe(Layer.provide(componentRouter))), Match.exhaustive), (ctx) => actionLayer(schema, ctx), options?.api);
|
|
50
|
+
const componentRouter = Layer.effect(HttpRouter.HttpRouter, Effect.gen(function* () {
|
|
51
|
+
const router = yield* HttpRouter.HttpRouter;
|
|
52
|
+
const siteUrl = yield* Config.schema(Schema.URLFromString, "CONVEX_SITE_URL");
|
|
53
|
+
return router.prefixed(siteUrl.pathname);
|
|
54
|
+
}).pipe(Effect.orDie));
|
|
55
|
+
const makeWithLayer = (routes, layer$2, api) => {
|
|
56
|
+
applyMonkeyPatches();
|
|
57
|
+
const AppLayer = routes.pipe(Layer.provideMerge(layer$1), Layer.provideMerge(layer), Layer.provide(HttpServer.layerServices));
|
|
58
|
+
const { handler } = HttpRouter.toWebHandler(AppLayer, { disableLogger: true });
|
|
59
|
+
const httpAction = httpActionGeneric((ctx, request) => {
|
|
60
|
+
const services = Effect.runSync(Effect.scoped(Layer.build(layer$2(ctx))));
|
|
61
|
+
return handler(request, Context.add(services, Console.Console, globalThis.console));
|
|
62
|
+
});
|
|
63
|
+
const convexHttpRouter = httpRouter();
|
|
64
|
+
Array.forEach(ROUTABLE_HTTP_METHODS, (method) => {
|
|
65
|
+
const routeSpec = {
|
|
66
|
+
pathPrefix: "/",
|
|
67
|
+
method,
|
|
68
|
+
handler: httpAction
|
|
69
|
+
};
|
|
70
|
+
convexHttpRouter.route(routeSpec);
|
|
71
|
+
});
|
|
72
|
+
if (api !== void 0) {
|
|
73
|
+
const matcher = FindMyWay.make();
|
|
74
|
+
const reflected = [];
|
|
75
|
+
HttpApi.reflect(api, {
|
|
76
|
+
onGroup: () => {},
|
|
77
|
+
onEndpoint: ({ endpoint }) => {
|
|
78
|
+
const method = ROUTABLE_HTTP_METHODS.find((candidate) => candidate === endpoint.method);
|
|
79
|
+
if (method === void 0) return;
|
|
80
|
+
const path = apiRouterPath(endpoint.path, endpoint.params);
|
|
81
|
+
matcher.on(method, path, endpoint.path);
|
|
82
|
+
if (path.endsWith("/*")) matcher.on(method, path.slice(0, -2), endpoint.path);
|
|
83
|
+
reflected.push([
|
|
84
|
+
endpoint.path,
|
|
85
|
+
method,
|
|
86
|
+
httpAction
|
|
87
|
+
]);
|
|
88
|
+
}
|
|
89
|
+
});
|
|
90
|
+
reflected.sort(([pathA, methodA], [pathB, methodB]) => pathA.localeCompare(pathB) || methodA.localeCompare(methodB));
|
|
91
|
+
const getRoutes = convexHttpRouter.getRoutes;
|
|
92
|
+
convexHttpRouter.getRoutes = () => reflected.length === 0 ? getRoutes() : [...getRoutes().filter(([, , action]) => action !== httpAction), ...reflected];
|
|
93
|
+
const lookup = convexHttpRouter.lookup;
|
|
94
|
+
convexHttpRouter.lookup = (path, method) => {
|
|
95
|
+
const match = lookup(path, method);
|
|
96
|
+
if (match === null || match[0] !== httpAction) return match;
|
|
97
|
+
const normalized = match[1];
|
|
98
|
+
const reflectedPath = matcher.find(normalized, path)?.handler;
|
|
99
|
+
return reflectedPath === void 0 ? match : [
|
|
100
|
+
httpAction,
|
|
101
|
+
normalized,
|
|
102
|
+
reflectedPath
|
|
103
|
+
];
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
return convexHttpRouter;
|
|
107
|
+
};
|
|
108
|
+
/*!
|
|
109
|
+
* apiRouterPath is adapted from Effect 4.0.1 http-api/internal/path.ts.
|
|
110
|
+
*
|
|
111
|
+
* MIT License
|
|
112
|
+
*
|
|
113
|
+
* Copyright (c) 2023 Effectful Technologies Inc
|
|
114
|
+
*
|
|
115
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
116
|
+
* of this software and associated documentation files (the "Software"), to deal
|
|
117
|
+
* in the Software without restriction, including without limitation the rights
|
|
118
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
119
|
+
* copies of the Software, and to permit persons to whom the Software is
|
|
120
|
+
* furnished to do so, subject to the following conditions:
|
|
121
|
+
*
|
|
122
|
+
* The above copyright notice and this permission notice shall be included in all
|
|
123
|
+
* copies or substantial portions of the Software.
|
|
124
|
+
*
|
|
125
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
126
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
127
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
128
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
129
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
130
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
131
|
+
* SOFTWARE.
|
|
132
|
+
*/
|
|
133
|
+
const apiRouterPath = (path, params) => {
|
|
134
|
+
if (params === void 0 || !path.includes(":")) return path;
|
|
135
|
+
let ast = params.ast;
|
|
136
|
+
while (ast.encoding !== void 0) ast = ast.encoding[ast.encoding.length - 1].to;
|
|
137
|
+
if (!SchemaAST.isObjects(ast) || ast.indexSignatures.length !== 0) return path;
|
|
138
|
+
const names = new Set(ast.propertySignatures.map((property) => String(property.name)));
|
|
139
|
+
let normalized = "";
|
|
140
|
+
let depth = 0;
|
|
141
|
+
let regexStart = -1;
|
|
142
|
+
for (let i = 0; i < path.length; i++) {
|
|
143
|
+
const char = path[i];
|
|
144
|
+
if (depth > 0 || i === regexStart) {
|
|
145
|
+
normalized += char;
|
|
146
|
+
if (char === "\\") normalized += path[++i] ?? "";
|
|
147
|
+
else if (char === "(") depth++;
|
|
148
|
+
else if (char === ")") depth--;
|
|
149
|
+
} else if (char !== ":") normalized += char;
|
|
150
|
+
else if (path[i + 1] === ":") {
|
|
151
|
+
normalized += "::";
|
|
152
|
+
i++;
|
|
153
|
+
} else {
|
|
154
|
+
const param = /^:(\w+)/.exec(path.slice(i));
|
|
155
|
+
if (param !== null && names.has(param[1])) {
|
|
156
|
+
normalized += param[0];
|
|
157
|
+
i += param[0].length - 1;
|
|
158
|
+
const next = path[i + 1];
|
|
159
|
+
if (next === "(") regexStart = i + 1;
|
|
160
|
+
else if (next !== void 0 && !"/.-?".includes(next)) normalized += "(.*?)";
|
|
161
|
+
} else normalized += "::";
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
return normalized;
|
|
165
|
+
};
|
|
166
|
+
const applyMonkeyPatches = () => {
|
|
167
|
+
if ((() => {
|
|
168
|
+
try {
|
|
169
|
+
return new URL("https://confect.dev").username === void 0;
|
|
170
|
+
} catch {
|
|
171
|
+
return true;
|
|
172
|
+
}
|
|
173
|
+
})()) URL = class extends URL {
|
|
174
|
+
get username() {
|
|
175
|
+
return "";
|
|
176
|
+
}
|
|
177
|
+
get password() {
|
|
178
|
+
return "";
|
|
179
|
+
}
|
|
180
|
+
};
|
|
181
|
+
if ((() => {
|
|
182
|
+
try {
|
|
183
|
+
return new Request("https://confect.dev").signal === void 0;
|
|
184
|
+
} catch {
|
|
185
|
+
return true;
|
|
186
|
+
}
|
|
187
|
+
})()) Object.defineProperty(Request.prototype, "signal", {
|
|
188
|
+
get: () => new AbortSignal(),
|
|
189
|
+
configurable: true
|
|
190
|
+
});
|
|
191
|
+
};
|
|
192
|
+
//#endregion
|
|
193
|
+
export { HttpRouter_exports, forSchema, make };
|
|
194
|
+
|
|
195
|
+
//# sourceMappingURL=HttpRouter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"HttpRouter.js","names":["RegisteredFunction.baseActionLayer","RegisteredFunction.actionLayer","ConvexLogger.layer","ConvexConfigProvider.layer","layer"],"sources":["../src/HttpRouter.ts"],"sourcesContent":["import {\n type HttpRouter as ConvexHttpRouter,\n httpActionGeneric,\n httpRouter,\n ROUTABLE_HTTP_METHODS,\n type RouteSpecWithPathPrefix,\n type GenericActionCtx,\n type GenericDataModel,\n} from \"convex/server\";\nimport * as Array from \"effect/Array\";\nimport * as Console from \"effect/Console\";\nimport * as Context from \"effect/Context\";\nimport * as Config from \"effect/Config\";\nimport * as Effect from \"effect/Effect\";\nimport type * as FileSystem from \"effect/FileSystem\";\nimport * as Layer from \"effect/Layer\";\nimport * as Match from \"effect/Match\";\nimport type * as Path from \"effect/Path\";\nimport * as Schema from \"effect/Schema\";\nimport * as SchemaAST from \"effect/SchemaAST\";\nimport * as FindMyWay from \"effect/http/FindMyWay\";\nimport * as HttpApi from \"effect/http-api/HttpApi\";\nimport type * as HttpApiGroup from \"effect/http-api/HttpApiGroup\";\nimport type * as Etag from \"effect/http/Etag\";\nimport type * as HttpPlatform from \"effect/http/HttpPlatform\";\nimport * as HttpRouter from \"effect/http/HttpRouter\";\nimport * as HttpServer from \"effect/http/HttpServer\";\nimport type * as ActionRunner from \"./ActionRunner\";\nimport type * as Auth from \"./Auth\";\nimport type { ExecutionMetadata } from \"./ExecutionMetadata\";\nimport type { RequestMetadata } from \"./RequestMetadata\";\nimport type * as DatabaseSchema from \"./DatabaseSchema\";\nimport type * as DataModel from \"./DataModel\";\nimport type * as Handler from \"./Handler\";\nimport * as ConvexConfigProvider from \"./ConvexConfigProvider\";\nimport * as ConvexLogger from \"./ConvexLogger\";\nimport type * as MutationRunner from \"./MutationRunner\";\nimport type * as QueryRunner from \"./QueryRunner\";\nimport * as RegisteredFunction from \"./RegisteredFunction\";\nimport type * as Scheduler from \"./Scheduler\";\nimport type { Storage } from \"./Storage\";\nimport type { StorageActionWriter } from \"./StorageActionWriter\";\nimport type { StorageReader } from \"./StorageReader\";\nimport type { StorageWriter } from \"./StorageWriter\";\n\n/**\n * The Confect services available to HTTP route handlers and middleware,\n * supplied per request from the Convex action context.\n */\nexport type Services =\n | QueryRunner.QueryRunner\n | MutationRunner.MutationRunner\n | ActionRunner.ActionRunner\n | Scheduler.Scheduler\n | Auth.Auth\n | ExecutionMetadata\n | RequestMetadata\n | Storage\n | StorageReader\n | StorageWriter\n | StorageActionWriter;\n\n/**\n * A layer that registers routes on the HTTP router—the input to {@link make}.\n *\n * Compose it from Effect's `effect/http` and `effect/http-api` modules:\n * `HttpApiBuilder.layer(api)` registers an `HttpApi`'s endpoints (provide its\n * group handler layers with `Layer.provide`), `HttpApiScalar.layer(api, ...)`\n * serves interactive API docs, `HttpRouter.add` registers a plain route, and\n * `HttpRouter.middleware(fn, { global: true })` applies middleware to every\n * route. Merge any number of these with `Layer.mergeAll`.\n *\n * Route handlers and middleware may require any of the Confect {@link Services},\n * which surface as request-level `Requires` markers and are supplied per\n * request. Anything else the layer requires is a type error—notably, an\n * `HttpApiBuilder.layer(api)` whose group handler layers are not provided\n * leaves an `HttpApiGroup.ToService` requirement behind, so a missing handler\n * group is caught at compile time.\n *\n * Layers are built with Confect's Convex-aware `ConfigProvider` in context, so\n * `Config` reads (e.g. in `Layer.unwrap`) resolve against Convex environment\n * variables.\n */\nexport type Routes<Services_ = Services> = Layer.Layer<\n never,\n never,\n | HttpRouter.HttpRouter\n | Etag.Generator\n | FileSystem.FileSystem\n | HttpPlatform.HttpPlatform\n | Path.Path\n | HttpRouter.Request<\"Requires\", Services_>\n | HttpRouter.Request<\"GlobalRequires\", Services_>\n | HttpRouter.Request<\"Error\", any>\n | HttpRouter.Request<\"GlobalError\", any>\n>;\n\n/**\n * Create a Convex HTTP router serving the given routes.\n *\n * A single catch-all `httpAction` is registered for every routable method under\n * the path prefix `\"/\"`, making the Effect router the single source of truth\n * for paths: place an API with `HttpApi.prefix` or absolute route paths.\n * Requests that match no route receive the Effect router's 404 response.\n *\n * Supply `{ api }` with the `HttpApi` registered by the routes layer to show\n * endpoint patterns in Convex completion logs and the dashboard. Requests that\n * match no reflected endpoint keep the catch-all completion label. Without the\n * option, Convex reports the catch-all registrations. Application endpoints\n * must not overlap component HTTP mounts: Convex also uses dashboard route\n * entries to select between application and component routers.\n *\n * Plain Convex routes can still be added to the returned router—Convex matches\n * exact paths first and longer path prefixes before the catch-all, so they take\n * precedence.\n */\nexport const make = <Id extends string, Groups extends HttpApiGroup.Constraint>(\n routes: Routes,\n options?: { readonly api?: HttpApi.HttpApi<Id, Groups> | undefined },\n): ConvexHttpRouter =>\n makeWithLayer(routes, RegisteredFunction.baseActionLayer, options?.api);\n\n/**\n * Derive HTTP capabilities and ID scopes from the generated database schema.\n * Component routes are relative to their installation's HTTP mount prefix.\n * Supply `{ api }` as in {@link make}; labels stay component-relative.\n */\nexport const forSchema =\n <DatabaseSchema_ extends DatabaseSchema.AnyWithProps>(\n schema: DatabaseSchema_,\n ) =>\n <Id extends string, Groups extends HttpApiGroup.Constraint>(\n routes: Routes<Handler.ActionServices<DatabaseSchema_>>,\n options?: { readonly api?: HttpApi.HttpApi<Id, Groups> | undefined },\n ): ConvexHttpRouter =>\n makeWithLayer<\n Handler.ActionServices<DatabaseSchema_>,\n DataModel.ToConvex<DataModel.FromSchema<DatabaseSchema_>>,\n Id,\n Groups\n >(\n Match.value(schema.target.kind).pipe(\n Match.when(\"app\", () => routes),\n Match.when(\"component\", () =>\n routes.pipe(Layer.provide(componentRouter)),\n ),\n Match.exhaustive,\n ),\n (ctx) => RegisteredFunction.actionLayer(schema, ctx),\n options?.api,\n );\n\n// Convex uses a component-relative path to select its HTTP action but passes\n// the original request URL to that action. Its CONVEX_SITE_URL includes the\n// installation's full mount prefix (including parent mounts). Prefixing the\n// Effect router preserves relative routes without rewriting the Request body.\nconst componentRouter = Layer.effect(\n HttpRouter.HttpRouter,\n Effect.gen(function* () {\n const router = yield* HttpRouter.HttpRouter;\n const siteUrl = yield* Config.schema(\n Schema.URLFromString,\n \"CONVEX_SITE_URL\",\n );\n return router.prefixed(siteUrl.pathname);\n }).pipe(Effect.orDie),\n);\n\nconst makeWithLayer = <\n Services_,\n DataModel_ extends GenericDataModel,\n Id extends string,\n Groups extends HttpApiGroup.Constraint,\n>(\n routes: Routes<Services_>,\n layer: (ctx: GenericActionCtx<DataModel_>) => Layer.Layer<Services_>,\n api: HttpApi.HttpApi<Id, Groups> | undefined,\n): ConvexHttpRouter => {\n applyMonkeyPatches();\n\n // Provided (not just merged) so that route layers' own construction—e.g.\n // a `Layer.unwrap` reading `Config`—resolves configuration through the\n // Convex-aware provider; merged so that request fibers—endpoint handlers\n // and middleware—do too.\n const AppLayer = routes.pipe(\n Layer.provideMerge(ConvexLogger.layer),\n Layer.provideMerge(ConvexConfigProvider.layer),\n Layer.provide(HttpServer.layerServices),\n );\n\n // The Confect service requirements of route handlers and middleware surface\n // as request-level `Requires` markers on the layer, which the web handler\n // exposes as a per-request context argument.\n const { handler } = HttpRouter.toWebHandler(AppLayer, {\n disableLogger: true,\n });\n\n const httpAction = httpActionGeneric((ctx, request): Promise<Response> => {\n // The ctx-backed service layers are all synchronous and finalizer-free,\n // so the scope can close as soon as the context is built.\n // Convex's HTTP registration erases the data model. The supplied generated\n // schema restores it; this does not change the runtime context or services.\n const services = Effect.runSync(\n Effect.scoped(\n Layer.build(layer(ctx as unknown as GenericActionCtx<DataModel_>)),\n ),\n );\n return handler(\n request,\n Context.add(services, Console.Console, globalThis.console),\n );\n });\n\n const convexHttpRouter = httpRouter();\n\n Array.forEach(ROUTABLE_HTTP_METHODS, (method) => {\n const routeSpec: RouteSpecWithPathPrefix = {\n pathPrefix: \"/\",\n method,\n handler: httpAction,\n };\n convexHttpRouter.route(routeSpec);\n });\n\n if (api !== undefined) {\n const matcher = FindMyWay.make<string>();\n const reflected: ReturnType<ConvexHttpRouter[\"getRoutes\"]> = [];\n HttpApi.reflect(api, {\n onGroup: () => {},\n onEndpoint: ({ endpoint }) => {\n const method = ROUTABLE_HTTP_METHODS.find(\n (candidate) => candidate === endpoint.method,\n );\n if (method === undefined) return;\n const path = apiRouterPath(\n endpoint.path as FindMyWay.PathInput,\n endpoint.params,\n );\n matcher.on(method, path, endpoint.path);\n // Effect also matches a wildcard route's base path without its slash.\n if (path.endsWith(\"/*\")) {\n matcher.on(method, path.slice(0, -2) as `/${string}`, endpoint.path);\n }\n reflected.push([endpoint.path, method, httpAction]);\n },\n });\n reflected.sort(\n ([pathA, methodA], [pathB, methodB]) =>\n pathA.localeCompare(pathB) || methodA.localeCompare(methodB),\n );\n\n const getRoutes = convexHttpRouter.getRoutes;\n convexHttpRouter.getRoutes = () =>\n reflected.length === 0\n ? getRoutes()\n : [\n ...getRoutes().filter(([, , action]) => action !== httpAction),\n ...reflected,\n ];\n const lookup = convexHttpRouter.lookup;\n convexHttpRouter.lookup = (path, method) => {\n const match = lookup(path, method);\n if (match === null || match[0] !== httpAction) return match;\n const normalized = match[1];\n const reflectedPath = matcher.find(normalized, path)?.handler;\n return reflectedPath === undefined\n ? match\n : [httpAction, normalized, reflectedPath];\n };\n }\n\n return convexHttpRouter;\n};\n\n/*!\n * apiRouterPath is adapted from Effect 4.0.1 http-api/internal/path.ts.\n *\n * MIT License\n *\n * Copyright (c) 2023 Effectful Technologies Inc\n *\n * Permission is hereby granted, free of charge, to any person obtaining a copy\n * of this software and associated documentation files (the \"Software\"), to deal\n * in the Software without restriction, including without limitation the rights\n * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n * copies of the Software, and to permit persons to whom the Software is\n * furnished to do so, subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in all\n * copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n * SOFTWARE.\n */\n// Match Effect's HttpApiBuilder path normalization, which is not publicly\n// exported (effect/http-api/internal/path.ts). Undeclared colons are literals;\n// declared params followed by a literal suffix need an explicit regex boundary.\nconst apiRouterPath = (\n path: FindMyWay.PathInput,\n params: Schema.Top | undefined,\n): FindMyWay.PathInput => {\n if (params === undefined || !path.includes(\":\")) return path;\n let ast = params.ast;\n while (ast.encoding !== undefined) {\n ast = ast.encoding[ast.encoding.length - 1].to;\n }\n if (!SchemaAST.isObjects(ast) || ast.indexSignatures.length !== 0)\n return path;\n const names = new Set(\n ast.propertySignatures.map((property) => String(property.name)),\n );\n let normalized = \"\";\n let depth = 0;\n let regexStart = -1;\n for (let i = 0; i < path.length; i++) {\n const char = path[i];\n if (depth > 0 || i === regexStart) {\n normalized += char;\n if (char === \"\\\\\") normalized += path[++i] ?? \"\";\n else if (char === \"(\") depth++;\n else if (char === \")\") depth--;\n } else if (char !== \":\") {\n normalized += char;\n } else if (path[i + 1] === \":\") {\n normalized += \"::\";\n i++;\n } else {\n const param = /^:(\\w+)/.exec(path.slice(i));\n if (param !== null && names.has(param[1])) {\n normalized += param[0];\n i += param[0].length - 1;\n const next = path[i + 1];\n if (next === \"(\") regexStart = i + 1;\n else if (next !== undefined && !\"/.-?\".includes(next))\n normalized += \"(.*?)\";\n } else {\n normalized += \"::\";\n }\n }\n }\n return normalized as FindMyWay.PathInput;\n};\n\n// These are necessary until the Convex runtime supports these APIs. See\n// https://discord.com/channels/1019350475847499849/1281364098419785760\n// Each patch is applied only where the API is actually broken, so runtimes\n// with working implementations—Node under convex-test, notably, where\n// `new AbortSignal()` is an illegal constructor—keep their native behavior.\nconst applyMonkeyPatches = () => {\n const urlCredentialsBroken = (() => {\n try {\n return new URL(\"https://confect.dev\").username === undefined;\n } catch {\n return true;\n }\n })();\n if (urlCredentialsBroken) {\n URL = class extends URL {\n override get username() {\n return \"\";\n }\n override get password() {\n return \"\";\n }\n };\n }\n\n const requestSignalBroken = (() => {\n try {\n return new Request(\"https://confect.dev\").signal === undefined;\n } catch {\n return true;\n }\n })();\n if (requestSignalBroken) {\n // `configurable` so repeated definition—e.g. module re-evaluation in a\n // long-lived environment—does not throw.\n Object.defineProperty(Request.prototype, \"signal\", {\n get: () => new AbortSignal(),\n configurable: true,\n });\n }\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAoHA,MAAa,QACX,QACA,YAEA,cAAc,QAAQA,iBAAoC,SAAS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EACjD,WAAW,IAAI,YAAY;EAC3B,cAAc;CAChB,CAAC;AAEL"}
|
|
@@ -0,0 +1,79 @@
|
|
|
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 type { FunctionType } from "convex/server";
|
|
5
|
+
import * as Context from "effect/Context";
|
|
6
|
+
import * as Effect from "effect/Effect";
|
|
7
|
+
import * as Layer from "effect/Layer";
|
|
8
|
+
import type * as Auth from "./Auth";
|
|
9
|
+
import type * as DatabaseReader from "./DatabaseReader";
|
|
10
|
+
import type * as DatabaseSchema from "./DatabaseSchema";
|
|
11
|
+
import type * as Handler from "./Handler";
|
|
12
|
+
import type { ExecutionMetadata } from "./ExecutionMetadata";
|
|
13
|
+
import type { RequestMetadata } from "./RequestMetadata";
|
|
14
|
+
import type { TransactionMetadata } from "./TransactionMetadata";
|
|
15
|
+
import type * as MutationRunner from "./MutationRunner";
|
|
16
|
+
import type * as QueryRunner from "./QueryRunner";
|
|
17
|
+
import type { QueryTransactionContext } from "./QueryTransactionContext";
|
|
18
|
+
import type * as Scheduler from "./Scheduler";
|
|
19
|
+
import type { Storage } from "./Storage";
|
|
20
|
+
import type * as StorageReader from "./StorageReader";
|
|
21
|
+
import type * as StorageWriter from "./StorageWriter";
|
|
22
|
+
/**
|
|
23
|
+
* Marker service produced by providing a middleware's implementation to a
|
|
24
|
+
* group's impl layer. `GroupImpl.make` requires one per middleware attached to
|
|
25
|
+
* the group's spec (via {@link FromGroupSpec}), so `GroupImpl.finalize`'s `RIn =
|
|
26
|
+
* never` bound rejects a group that attaches a middleware but never provides
|
|
27
|
+
* its implementation—the exact mechanism used for `FunctionImpl`s.
|
|
28
|
+
*/
|
|
29
|
+
export interface MiddlewareImpl<MiddlewareKey extends string> {
|
|
30
|
+
readonly middlewareKey: MiddlewareKey;
|
|
31
|
+
}
|
|
32
|
+
export declare const MiddlewareImpl: <MiddlewareKey extends string>({ middlewareKey, }: {
|
|
33
|
+
middlewareKey: MiddlewareKey;
|
|
34
|
+
}) => Context.Service<MiddlewareImpl<MiddlewareKey>, MiddlewareImpl<MiddlewareKey>>;
|
|
35
|
+
export type FromGroupSpec<Group extends GroupSpec.AnyWithProps> = GroupSpec.MiddlewareSpecs<Group> | FunctionSpec.MiddlewareSpecs<GroupSpec.Functions<Group>> extends infer MiddlewareSpec_ ? MiddlewareSpec_ extends MiddlewareSpec.AnyMiddlewareSpec ? MiddlewareImpl<MiddlewareSpec.Key<MiddlewareSpec_>> : never : never;
|
|
36
|
+
export type FunctionTypeServices<DatabaseSchema_ extends DatabaseSchema.AnyWithProps, FunctionType_ extends FunctionType> = FunctionType_ extends "query" ? Handler.QueryServices<DatabaseSchema_> : FunctionType_ extends "mutation" ? Handler.MutationServices<DatabaseSchema_> : FunctionType_ extends "action" ? Handler.ActionServices<DatabaseSchema_> : never;
|
|
37
|
+
/**
|
|
38
|
+
* The services a single middleware implementation may use: the set-theoretic
|
|
39
|
+
* intersection of the ctx-service unions of the middleware's declared
|
|
40
|
+
* `functionTypes`, so one implementation is valid in every runtime it can be
|
|
41
|
+
* invoked in. Enumerated by hand rather than derived with
|
|
42
|
+
* `Exclude`/`Extract`—several ctx services are structurally typed (e.g. the raw
|
|
43
|
+
* `GenericQueryCtx`/`GenericMutationCtx` tags), so conditional-type set
|
|
44
|
+
* arithmetic over them is not reliable.
|
|
45
|
+
*/
|
|
46
|
+
export type CommonServices<DatabaseSchema_ extends DatabaseSchema.AnyWithProps, FunctionTypes extends FunctionType> = [FunctionTypes] extends ["query"] ? Handler.QueryServices<DatabaseSchema_> : [FunctionTypes] extends ["mutation"] ? Handler.MutationServices<DatabaseSchema_> : [FunctionTypes] extends ["action"] ? Handler.ActionServices<DatabaseSchema_> : [FunctionTypes] extends ["query" | "mutation"] ? QueryMutationCommonServices<DatabaseSchema_> : [FunctionTypes] extends ["mutation" | "action"] ? MutationActionCommonServices : AllFunctionTypesCommonServices;
|
|
47
|
+
type QueryMutationCommonServices<DatabaseSchema_ extends DatabaseSchema.AnyWithProps> = DatabaseReader.DatabaseReader<DatabaseSchema_> | Auth.Auth | ExecutionMetadata | TransactionMetadata | QueryTransactionContext | Storage | StorageReader.StorageReader | QueryRunner.QueryRunner;
|
|
48
|
+
type MutationActionCommonServices = Auth.Auth | ExecutionMetadata | RequestMetadata | Scheduler.Scheduler | Storage | StorageReader.StorageReader | StorageWriter.StorageWriter | QueryRunner.QueryRunner | MutationRunner.MutationRunner;
|
|
49
|
+
type AllFunctionTypesCommonServices = Auth.Auth | ExecutionMetadata | Storage | StorageReader.StorageReader | QueryRunner.QueryRunner;
|
|
50
|
+
/**
|
|
51
|
+
* Provide a middleware's implementation with a single strategy shared by every
|
|
52
|
+
* function type the middleware declares. The implementation's environment is
|
|
53
|
+
* bounded by {@link CommonServices}—the intersection of the declared
|
|
54
|
+
* functionTypes' ctx services—plus the middleware's declared `requires`, which
|
|
55
|
+
* middleware running earlier in the chain provide. Reach for
|
|
56
|
+
* {@link makeByFunctionType} when one strategy can't fit all declared
|
|
57
|
+
* functionTypes (the usual case for database-touching middleware attached to
|
|
58
|
+
* actions).
|
|
59
|
+
*
|
|
60
|
+
* Like `FunctionImpl.make`, `databaseSchema` is a type-level carrier only.
|
|
61
|
+
*/
|
|
62
|
+
export declare const make: <DatabaseSchema_ extends DatabaseSchema.AnyWithProps, MiddlewareSpec_ extends MiddlewareSpec.AnyMiddlewareSpec>(_databaseSchema: DatabaseSchema_, middlewareSpec: MiddlewareSpec_, impl: MiddlewareSpec.MiddlewareImpl<MiddlewareSpec.Provides<MiddlewareSpec_>, MiddlewareSpec.Error<MiddlewareSpec_>, CommonServices<DatabaseSchema_, MiddlewareSpec.FunctionTypes<MiddlewareSpec_>> | MiddlewareSpec.Requires<MiddlewareSpec_>, MiddlewareSpec.Options<MiddlewareSpec_>>) => Layer.Layer<MiddlewareImpl<MiddlewareSpec.Key<MiddlewareSpec_>>>;
|
|
63
|
+
/**
|
|
64
|
+
* Provide a middleware's implementation with one strategy per declared function
|
|
65
|
+
* type. Each entry may use that function type's full ctx-service union—the
|
|
66
|
+
* recommended shape for database-touching middleware that also covers actions:
|
|
67
|
+
* use `DatabaseReader`/`DatabaseWriter` in queries and mutations, and
|
|
68
|
+
* `runQuery` of an internal query in actions.
|
|
69
|
+
*/
|
|
70
|
+
export declare const makeByFunctionType: <DatabaseSchema_ extends DatabaseSchema.AnyWithProps, MiddlewareSpec_ extends MiddlewareSpec.AnyMiddlewareSpec>(_databaseSchema: DatabaseSchema_, middlewareSpec: MiddlewareSpec_, impls: { readonly [FunctionType_ in MiddlewareSpec.FunctionTypes<MiddlewareSpec_>]: MiddlewareSpec.MiddlewareImpl<MiddlewareSpec.Provides<MiddlewareSpec_>, MiddlewareSpec.Error<MiddlewareSpec_>, FunctionTypeServices<DatabaseSchema_, FunctionType_> | MiddlewareSpec.Requires<MiddlewareSpec_>, MiddlewareSpec.Options<MiddlewareSpec_>>; }) => Layer.Layer<MiddlewareImpl<MiddlewareSpec.Key<MiddlewareSpec_>>>;
|
|
71
|
+
/**
|
|
72
|
+
* Sugar over {@link make} for the flagship "run something, provide a service"
|
|
73
|
+
* shape: run `effect` before the rest of the chain and provide its result under
|
|
74
|
+
* `tag` (the runtime tag for the middleware's type-level `provides` service,
|
|
75
|
+
* passed explicitly since the spec class only knows it at the type level).
|
|
76
|
+
*/
|
|
77
|
+
export declare const provides: <DatabaseSchema_ extends DatabaseSchema.AnyWithProps, MiddlewareSpec_ extends MiddlewareSpec.AnyMiddlewareSpec, Shape>(databaseSchema: DatabaseSchema_, middlewareSpec: MiddlewareSpec_, tag: Context.Key<MiddlewareSpec.Provides<MiddlewareSpec_>, Shape>, effect: Effect.Effect<Shape, MiddlewareSpec.Error<MiddlewareSpec_>, CommonServices<DatabaseSchema_, MiddlewareSpec.FunctionTypes<MiddlewareSpec_>> | MiddlewareSpec.Requires<MiddlewareSpec_>>) => Layer.Layer<MiddlewareImpl<MiddlewareSpec.Key<MiddlewareSpec_>>>;
|
|
78
|
+
export {};
|
|
79
|
+
//# sourceMappingURL=MiddlewareImpl.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"MiddlewareImpl.d.ts","sourceRoot":"","sources":["../src/MiddlewareImpl.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,YAAY,MAAM,4BAA4B,CAAC;AAChE,OAAO,KAAK,KAAK,SAAS,MAAM,yBAAyB,CAAC;AAC1D,OAAO,KAAK,cAAc,MAAM,8BAA8B,CAAC;AAE/D,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAClD,OAAO,KAAK,OAAO,MAAM,gBAAgB,CAAC;AAC1C,OAAO,KAAK,MAAM,MAAM,eAAe,CAAC;AACxC,OAAO,KAAK,KAAK,MAAM,cAAc,CAAC;AAEtC,OAAO,KAAK,KAAK,IAAI,MAAM,QAAQ,CAAC;AACpC,OAAO,KAAK,KAAK,cAAc,MAAM,kBAAkB,CAAC;AACxD,OAAO,KAAK,KAAK,cAAc,MAAM,kBAAkB,CAAC;AACxD,OAAO,KAAK,KAAK,OAAO,MAAM,WAAW,CAAC;AAC1C,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AAC7D,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AACzD,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AACjE,OAAO,KAAK,KAAK,cAAc,MAAM,kBAAkB,CAAC;AACxD,OAAO,KAAK,KAAK,WAAW,MAAM,eAAe,CAAC;AAClD,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,2BAA2B,CAAC;AACzE,OAAO,KAAK,KAAK,SAAS,MAAM,aAAa,CAAC;AAC9C,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACzC,OAAO,KAAK,KAA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CAAC"}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { __exportAll } from "./_virtual/_rolldown/runtime.js";
|
|
2
|
+
import { Registry } from "./Registry.js";
|
|
3
|
+
import { TypeId, registryKey } from "./MiddlewareRegistryItem.js";
|
|
4
|
+
import { setNestedProperty } from "./internal/utils.js";
|
|
5
|
+
import * as Context from "effect/Context";
|
|
6
|
+
import * as Layer from "effect/Layer";
|
|
7
|
+
import * as Effect from "effect/Effect";
|
|
8
|
+
import * as MiddlewareSpec from "@confect/core/MiddlewareSpec";
|
|
9
|
+
import * as Ref from "effect/Ref";
|
|
10
|
+
//#region src/MiddlewareImpl.ts
|
|
11
|
+
var MiddlewareImpl_exports = /* @__PURE__ */ __exportAll({
|
|
12
|
+
MiddlewareImpl: () => MiddlewareImpl,
|
|
13
|
+
make: () => make,
|
|
14
|
+
makeByFunctionType: () => makeByFunctionType,
|
|
15
|
+
provides: () => provides
|
|
16
|
+
});
|
|
17
|
+
const MiddlewareImpl = ({ middlewareKey }) => Context.Service(`@confect/server/MiddlewareImpl/${middlewareKey}`);
|
|
18
|
+
const layerFromImpls = (middlewareSpec, impls) => Layer.effect(MiddlewareImpl({ middlewareKey: middlewareSpec.key }), Effect.gen(function* () {
|
|
19
|
+
const registry = yield* Registry;
|
|
20
|
+
yield* Ref.update(registry, (registryItems) => setNestedProperty(registryItems, [registryKey(middlewareSpec.key)], {
|
|
21
|
+
[TypeId]: TypeId,
|
|
22
|
+
middlewareSpec,
|
|
23
|
+
impls
|
|
24
|
+
}));
|
|
25
|
+
return { middlewareKey: middlewareSpec.key };
|
|
26
|
+
}));
|
|
27
|
+
/**
|
|
28
|
+
* Provide a middleware's implementation with a single strategy shared by every
|
|
29
|
+
* function type the middleware declares. The implementation's environment is
|
|
30
|
+
* bounded by {@link CommonServices}—the intersection of the declared
|
|
31
|
+
* functionTypes' ctx services—plus the middleware's declared `requires`, which
|
|
32
|
+
* middleware running earlier in the chain provide. Reach for
|
|
33
|
+
* {@link makeByFunctionType} when one strategy can't fit all declared
|
|
34
|
+
* functionTypes (the usual case for database-touching middleware attached to
|
|
35
|
+
* actions).
|
|
36
|
+
*
|
|
37
|
+
* Like `FunctionImpl.make`, `databaseSchema` is a type-level carrier only.
|
|
38
|
+
*/
|
|
39
|
+
const make = (_databaseSchema, middlewareSpec, impl) => layerFromImpls(middlewareSpec, Object.fromEntries(MiddlewareSpec.allFunctionTypes.filter((functionType) => middlewareSpec.functionTypes[functionType]).map((functionType) => [functionType, impl])));
|
|
40
|
+
/**
|
|
41
|
+
* Provide a middleware's implementation with one strategy per declared function
|
|
42
|
+
* type. Each entry may use that function type's full ctx-service union—the
|
|
43
|
+
* recommended shape for database-touching middleware that also covers actions:
|
|
44
|
+
* use `DatabaseReader`/`DatabaseWriter` in queries and mutations, and
|
|
45
|
+
* `runQuery` of an internal query in actions.
|
|
46
|
+
*/
|
|
47
|
+
const makeByFunctionType = (_databaseSchema, middlewareSpec, impls) => layerFromImpls(middlewareSpec, impls);
|
|
48
|
+
/**
|
|
49
|
+
* Sugar over {@link make} for the flagship "run something, provide a service"
|
|
50
|
+
* shape: run `effect` before the rest of the chain and provide its result under
|
|
51
|
+
* `tag` (the runtime tag for the middleware's type-level `provides` service,
|
|
52
|
+
* passed explicitly since the spec class only knows it at the type level).
|
|
53
|
+
*/
|
|
54
|
+
const provides = (databaseSchema, middlewareSpec, tag, effect) => make(databaseSchema, middlewareSpec, ((handlerEffect) => Effect.provideServiceEffect(handlerEffect, tag, effect)));
|
|
55
|
+
//#endregion
|
|
56
|
+
export { MiddlewareImpl, MiddlewareImpl_exports, make, makeByFunctionType, provides };
|
|
57
|
+
|
|
58
|
+
//# sourceMappingURL=MiddlewareImpl.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"MiddlewareImpl.js","names":["Registry.Registry","MiddlewareRegistryItem.registryKey","MiddlewareRegistryItem.TypeId"],"sources":["../src/MiddlewareImpl.ts"],"sourcesContent":["import type * as FunctionSpec from \"@confect/core/FunctionSpec\";\nimport type * as GroupSpec from \"@confect/core/GroupSpec\";\nimport * as MiddlewareSpec from \"@confect/core/MiddlewareSpec\";\nimport * as Registry from \"./Registry\";\nimport type { FunctionType } from \"convex/server\";\nimport * as Context from \"effect/Context\";\nimport * as Effect from \"effect/Effect\";\nimport * as Layer from \"effect/Layer\";\nimport * as Ref from \"effect/Ref\";\nimport type * as Auth from \"./Auth\";\nimport type * as DatabaseReader from \"./DatabaseReader\";\nimport type * as DatabaseSchema from \"./DatabaseSchema\";\nimport type * as Handler from \"./Handler\";\nimport type { ExecutionMetadata } from \"./ExecutionMetadata\";\nimport type { RequestMetadata } from \"./RequestMetadata\";\nimport type { TransactionMetadata } from \"./TransactionMetadata\";\nimport type * as MutationRunner from \"./MutationRunner\";\nimport type * as QueryRunner from \"./QueryRunner\";\nimport type { QueryTransactionContext } from \"./QueryTransactionContext\";\nimport type * as Scheduler from \"./Scheduler\";\nimport type { Storage } from \"./Storage\";\nimport type * as StorageReader from \"./StorageReader\";\nimport type * as StorageWriter from \"./StorageWriter\";\nimport * as MiddlewareRegistryItem from \"./MiddlewareRegistryItem\";\nimport { setNestedProperty } from \"./internal/utils\";\n\n/**\n * Marker service produced by providing a middleware's implementation to a\n * group's impl layer. `GroupImpl.make` requires one per middleware attached to\n * the group's spec (via {@link FromGroupSpec}), so `GroupImpl.finalize`'s `RIn =\n * never` bound rejects a group that attaches a middleware but never provides\n * its implementation—the exact mechanism used for `FunctionImpl`s.\n */\nexport interface MiddlewareImpl<MiddlewareKey extends string> {\n readonly middlewareKey: MiddlewareKey;\n}\n\nexport const MiddlewareImpl = <MiddlewareKey extends string>({\n middlewareKey,\n}: {\n middlewareKey: MiddlewareKey;\n}) =>\n Context.Service<MiddlewareImpl<MiddlewareKey>>(\n `@confect/server/MiddlewareImpl/${middlewareKey}`,\n );\n\nexport type FromGroupSpec<Group extends GroupSpec.AnyWithProps> =\n | GroupSpec.MiddlewareSpecs<Group>\n | FunctionSpec.MiddlewareSpecs<\n GroupSpec.Functions<Group>\n > extends infer MiddlewareSpec_\n ? MiddlewareSpec_ extends MiddlewareSpec.AnyMiddlewareSpec\n ? MiddlewareImpl<MiddlewareSpec.Key<MiddlewareSpec_>>\n : never\n : never;\n\nexport type FunctionTypeServices<\n DatabaseSchema_ extends DatabaseSchema.AnyWithProps,\n FunctionType_ extends FunctionType,\n> = FunctionType_ extends \"query\"\n ? Handler.QueryServices<DatabaseSchema_>\n : FunctionType_ extends \"mutation\"\n ? Handler.MutationServices<DatabaseSchema_>\n : FunctionType_ extends \"action\"\n ? Handler.ActionServices<DatabaseSchema_>\n : never;\n\n/**\n * The services a single middleware implementation may use: the set-theoretic\n * intersection of the ctx-service unions of the middleware's declared\n * `functionTypes`, so one implementation is valid in every runtime it can be\n * invoked in. Enumerated by hand rather than derived with\n * `Exclude`/`Extract`—several ctx services are structurally typed (e.g. the raw\n * `GenericQueryCtx`/`GenericMutationCtx` tags), so conditional-type set\n * arithmetic over them is not reliable.\n */\nexport type CommonServices<\n DatabaseSchema_ extends DatabaseSchema.AnyWithProps,\n FunctionTypes extends FunctionType,\n> = [FunctionTypes] extends [\"query\"]\n ? Handler.QueryServices<DatabaseSchema_>\n : [FunctionTypes] extends [\"mutation\"]\n ? Handler.MutationServices<DatabaseSchema_>\n : [FunctionTypes] extends [\"action\"]\n ? Handler.ActionServices<DatabaseSchema_>\n : [FunctionTypes] extends [\"query\" | \"mutation\"]\n ? QueryMutationCommonServices<DatabaseSchema_>\n : [FunctionTypes] extends [\"mutation\" | \"action\"]\n ? MutationActionCommonServices\n : AllFunctionTypesCommonServices;\n\ntype QueryMutationCommonServices<\n DatabaseSchema_ extends DatabaseSchema.AnyWithProps,\n> =\n | DatabaseReader.DatabaseReader<DatabaseSchema_>\n | Auth.Auth\n | ExecutionMetadata\n | TransactionMetadata\n | QueryTransactionContext\n | Storage\n | StorageReader.StorageReader\n | QueryRunner.QueryRunner;\n\ntype MutationActionCommonServices =\n | Auth.Auth\n | ExecutionMetadata\n | RequestMetadata\n | Scheduler.Scheduler\n | Storage\n | StorageReader.StorageReader\n | StorageWriter.StorageWriter\n | QueryRunner.QueryRunner\n | MutationRunner.MutationRunner;\n\ntype AllFunctionTypesCommonServices =\n | Auth.Auth\n | ExecutionMetadata\n | Storage\n | StorageReader.StorageReader\n | QueryRunner.QueryRunner;\n\nconst layerFromImpls = <\n MiddlewareSpec_ extends MiddlewareSpec.AnyMiddlewareSpec,\n>(\n middlewareSpec: MiddlewareSpec_,\n impls: MiddlewareRegistryItem.MiddlewareRegistryItem[\"impls\"],\n): Layer.Layer<MiddlewareImpl<MiddlewareSpec.Key<MiddlewareSpec_>>> =>\n Layer.effect(\n MiddlewareImpl<MiddlewareSpec.Key<MiddlewareSpec_>>({\n middlewareKey: middlewareSpec.key,\n }),\n Effect.gen(function* () {\n const registry = yield* Registry.Registry;\n\n yield* Ref.update(registry, (registryItems) =>\n setNestedProperty(\n registryItems,\n [MiddlewareRegistryItem.registryKey(middlewareSpec.key)],\n {\n [MiddlewareRegistryItem.TypeId]: MiddlewareRegistryItem.TypeId,\n middlewareSpec,\n impls,\n } satisfies MiddlewareRegistryItem.MiddlewareRegistryItem,\n ),\n );\n\n return { middlewareKey: middlewareSpec.key };\n }),\n );\n\n/**\n * Provide a middleware's implementation with a single strategy shared by every\n * function type the middleware declares. The implementation's environment is\n * bounded by {@link CommonServices}—the intersection of the declared\n * functionTypes' ctx services—plus the middleware's declared `requires`, which\n * middleware running earlier in the chain provide. Reach for\n * {@link makeByFunctionType} when one strategy can't fit all declared\n * functionTypes (the usual case for database-touching middleware attached to\n * actions).\n *\n * Like `FunctionImpl.make`, `databaseSchema` is a type-level carrier only.\n */\nexport const make = <\n DatabaseSchema_ extends DatabaseSchema.AnyWithProps,\n MiddlewareSpec_ extends MiddlewareSpec.AnyMiddlewareSpec,\n>(\n _databaseSchema: DatabaseSchema_,\n middlewareSpec: MiddlewareSpec_,\n impl: MiddlewareSpec.MiddlewareImpl<\n MiddlewareSpec.Provides<MiddlewareSpec_>,\n MiddlewareSpec.Error<MiddlewareSpec_>,\n | CommonServices<\n DatabaseSchema_,\n MiddlewareSpec.FunctionTypes<MiddlewareSpec_>\n >\n | MiddlewareSpec.Requires<MiddlewareSpec_>,\n MiddlewareSpec.Options<MiddlewareSpec_>\n >,\n): Layer.Layer<MiddlewareImpl<MiddlewareSpec.Key<MiddlewareSpec_>>> =>\n layerFromImpls(\n middlewareSpec,\n Object.fromEntries(\n MiddlewareSpec.allFunctionTypes\n .filter((functionType) => middlewareSpec.functionTypes[functionType])\n .map((functionType) => [\n functionType,\n impl as MiddlewareSpec.AnyMiddlewareImpl,\n ]),\n ),\n );\n\n/**\n * Provide a middleware's implementation with one strategy per declared function\n * type. Each entry may use that function type's full ctx-service union—the\n * recommended shape for database-touching middleware that also covers actions:\n * use `DatabaseReader`/`DatabaseWriter` in queries and mutations, and\n * `runQuery` of an internal query in actions.\n */\nexport const makeByFunctionType = <\n DatabaseSchema_ extends DatabaseSchema.AnyWithProps,\n MiddlewareSpec_ extends MiddlewareSpec.AnyMiddlewareSpec,\n>(\n _databaseSchema: DatabaseSchema_,\n middlewareSpec: MiddlewareSpec_,\n impls: {\n readonly [\n FunctionType_ in MiddlewareSpec.FunctionTypes<MiddlewareSpec_>\n ]: MiddlewareSpec.MiddlewareImpl<\n MiddlewareSpec.Provides<MiddlewareSpec_>,\n MiddlewareSpec.Error<MiddlewareSpec_>,\n | FunctionTypeServices<DatabaseSchema_, FunctionType_>\n | MiddlewareSpec.Requires<MiddlewareSpec_>,\n MiddlewareSpec.Options<MiddlewareSpec_>\n >;\n },\n): Layer.Layer<MiddlewareImpl<MiddlewareSpec.Key<MiddlewareSpec_>>> =>\n layerFromImpls(\n middlewareSpec,\n impls as MiddlewareRegistryItem.MiddlewareRegistryItem[\"impls\"],\n );\n\n/**\n * Sugar over {@link make} for the flagship \"run something, provide a service\"\n * shape: run `effect` before the rest of the chain and provide its result under\n * `tag` (the runtime tag for the middleware's type-level `provides` service,\n * passed explicitly since the spec class only knows it at the type level).\n */\nexport const provides = <\n DatabaseSchema_ extends DatabaseSchema.AnyWithProps,\n MiddlewareSpec_ extends MiddlewareSpec.AnyMiddlewareSpec,\n Shape,\n>(\n databaseSchema: DatabaseSchema_,\n middlewareSpec: MiddlewareSpec_,\n tag: Context.Key<MiddlewareSpec.Provides<MiddlewareSpec_>, Shape>,\n effect: Effect.Effect<\n Shape,\n MiddlewareSpec.Error<MiddlewareSpec_>,\n | CommonServices<\n DatabaseSchema_,\n MiddlewareSpec.FunctionTypes<MiddlewareSpec_>\n >\n | MiddlewareSpec.Requires<MiddlewareSpec_>\n >,\n): Layer.Layer<MiddlewareImpl<MiddlewareSpec.Key<MiddlewareSpec_>>> =>\n make(databaseSchema, middlewareSpec, ((handlerEffect: Effect.Effect<any>) =>\n Effect.provideServiceEffect(handlerEffect, tag, effect)) as any);\n"],"mappings":";;;;;;;;;;;;;;;;AAqCA,MAAa,kBAAgD,EAC3D,oBAIA,QAAQ,QACN,kCAAkC,eACpC;AA6EF,MAAM,kBAGJ,gBACA,UAEA,MAAM,OACJ,eAAoD,EAClD,eAAe,eAAe,IAChC,CAAC,GACD,OAAO,IAAI,aAAa;CACtB,MAAM,WAAW,OAAOA;CAExB,OAAO,IAAI,OAAO,WAAW,kBAC3B,kBACE,eACA,CAACC,YAAmC,eAAe,GAAG,CAAC,GACvD;GACGC,SAAgCA;EACjC;EACA;CACF,CACF,CACF;CAEA,OAAO,EAAE,eAAe,eAAe,IAAI;AAC7C,CAAC,CACH;;;;;;;;;;;;;AAcF,MAAa,QAIX,iBACA,gBACA,SAWA,eACE,gBACA,OAAO,YACL,eAAe,iBACZ,QAAQ,iBAAiB,eAAe,cAAc,aAAa,CAAC,CACpE,KAAK,iBAAiB,CACrB,cACA,IACF,CAAC,CACL,CACF;;;;;;;;AASF,MAAa,sBAIX,iBACA,gBACA,UAYA,eACE,gBACA,KACF;;;;;;;AAQF,MAAa,YAKX,gBACA,gBACA,KACA,WAUA,KAAK,gBAAgB,kBAAkB,kBACrC,OAAO,qBAAqB,eAAe,KAAK,MAAM,EAAS"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type * as MiddlewareSpec from "@confect/core/MiddlewareSpec";
|
|
2
|
+
import type { FunctionType } from "convex/server";
|
|
3
|
+
export declare const TypeId = "~@confect/server/MiddlewareRegistryItem";
|
|
4
|
+
export type TypeId = typeof TypeId;
|
|
5
|
+
export interface MiddlewareRegistryItem {
|
|
6
|
+
readonly [TypeId]: TypeId;
|
|
7
|
+
readonly middlewareSpec: MiddlewareSpec.AnyMiddlewareSpec;
|
|
8
|
+
readonly impls: Partial<Record<FunctionType, MiddlewareSpec.AnyMiddlewareImpl>>;
|
|
9
|
+
}
|
|
10
|
+
export declare const isMiddlewareRegistryItem: (u: unknown) => u is MiddlewareRegistryItem;
|
|
11
|
+
export declare const registryKey: (middlewareKey: string) => string;
|
|
12
|
+
//# sourceMappingURL=MiddlewareRegistryItem.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"MiddlewareRegistryItem.d.ts","sourceRoot":"","sources":["../src/MiddlewareRegistryItem.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,cAAc,MAAM,8BAA8B,CAAC;AACpE,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAGlD,eAAO,MAAM,MAAM,4CAA4C,CAAC;AAChE,MAAM,MAAM,MAAM,GAAG,OAAO,MAAM,CAAC;AAEnC,MAAM,WAAW,sBAAsB;IACrC,QAAQ,CAAC,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,cAAc,EAAE,cAAc,CAAC,iBAAiB,CAAC;IAC1D,QAAQ,CAAC,KAAK,EAAE,OAAO,CACrB,MAAM,CAAC,YAAY,EAAE,cAAc,CAAC,iBAAiB,CAAC,CACvD,CAAC;CACH;AAED,eAAO,MAAM,wBAAwB,MAChC,OAAO,KACT,CAAC,IAAI,sBAA0D,CAAC;AAEnE,eAAO,MAAM,WAAW,kBAAmB,MAAM,KAAG,MACrB,CAAC"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { __exportAll } from "./_virtual/_rolldown/runtime.js";
|
|
2
|
+
import * as Predicate from "effect/Predicate";
|
|
3
|
+
//#region src/MiddlewareRegistryItem.ts
|
|
4
|
+
var MiddlewareRegistryItem_exports = /* @__PURE__ */ __exportAll({
|
|
5
|
+
TypeId: () => TypeId,
|
|
6
|
+
isMiddlewareRegistryItem: () => isMiddlewareRegistryItem,
|
|
7
|
+
registryKey: () => registryKey
|
|
8
|
+
});
|
|
9
|
+
const TypeId = "~@confect/server/MiddlewareRegistryItem";
|
|
10
|
+
const isMiddlewareRegistryItem = (u) => Predicate.hasProperty(u, TypeId);
|
|
11
|
+
const registryKey = (middlewareKey) => `middleware:${middlewareKey}`;
|
|
12
|
+
//#endregion
|
|
13
|
+
export { MiddlewareRegistryItem_exports, TypeId, isMiddlewareRegistryItem, registryKey };
|
|
14
|
+
|
|
15
|
+
//# sourceMappingURL=MiddlewareRegistryItem.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"MiddlewareRegistryItem.js","names":[],"sources":["../src/MiddlewareRegistryItem.ts"],"sourcesContent":["import type * as MiddlewareSpec from \"@confect/core/MiddlewareSpec\";\nimport type { FunctionType } from \"convex/server\";\nimport * as Predicate from \"effect/Predicate\";\n\nexport const TypeId = \"~@confect/server/MiddlewareRegistryItem\";\nexport type TypeId = typeof TypeId;\n\nexport interface MiddlewareRegistryItem {\n readonly [TypeId]: TypeId;\n readonly middlewareSpec: MiddlewareSpec.AnyMiddlewareSpec;\n readonly impls: Partial<\n Record<FunctionType, MiddlewareSpec.AnyMiddlewareImpl>\n >;\n}\n\nexport const isMiddlewareRegistryItem = (\n u: unknown,\n): u is MiddlewareRegistryItem => Predicate.hasProperty(u, TypeId);\n\nexport const registryKey = (middlewareKey: string): string =>\n `middleware:${middlewareKey}`;\n"],"mappings":";;;;;;;;AAIA,MAAa,SAAS;AAWtB,MAAa,4BACX,MACgC,UAAU,YAAY,GAAG,MAAM;AAEjE,MAAa,eAAe,kBAC1B,cAAc"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type * as IdScope from "@confect/core/IdScope";
|
|
2
|
+
import type { GenericDataModel, GenericMutationCtx } from "convex/server";
|
|
3
|
+
import * as Context from "effect/Context";
|
|
4
|
+
import type * as ComponentCtx from "./ComponentCtx";
|
|
5
|
+
import * as Layer from "effect/Layer";
|
|
6
|
+
export type MutationCtxTag<DataModel extends GenericDataModel, Scope extends IdScope.IdScope = IdScope.App> = Context.Service<MutationCtx<DataModel, Scope>, Scope extends IdScope.App ? GenericMutationCtx<DataModel> : ComponentCtx.Mutation<DataModel, Scope>>;
|
|
7
|
+
export declare const MutationCtx: <DataModel extends GenericDataModel, Scope extends IdScope.IdScope = IdScope.App>() => MutationCtxTag<DataModel, Scope>;
|
|
8
|
+
export type MutationCtx<DataModel extends GenericDataModel, Scope extends IdScope.IdScope = IdScope.App> = Scope extends IdScope.App ? GenericMutationCtx<DataModel> : ComponentCtx.Identifier<"mutation", DataModel, Scope>;
|
|
9
|
+
export declare const layer: <DataModel extends GenericDataModel, Scope extends IdScope.IdScope>(ctx: GenericMutationCtx<DataModel>, scope: Scope) => Layer.Layer<MutationCtx<DataModel, Scope>, never, never>;
|
|
10
|
+
//# sourceMappingURL=MutationCtx.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"MutationCtx.d.ts","sourceRoot":"","sources":["../src/MutationCtx.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,OAAO,MAAM,uBAAuB,CAAC;AACtD,OAAO,KAAK,EAAE,gBAAgB,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAC;AAC1E,OAAO,KAAK,OAAO,MAAM,gBAAgB,CAAC;AAC1C,OAAO,KAAK,KAAK,YAAY,MAAM,gBAAgB,CAAC;AACpD,OAAO,KAAK,KAAK,MAAM,cAAc,CAAC;AAEtC,MAAM,MAAM,cAAc,CACxB,SAAS,SAAS,gBAAgB,EAClC,KAAK,SAAS,OAAO,CAAC,OAAO,GAAG,OAAO,CAAC,GAAG,IACzC,OAAO,CAAC,OAAO,CACjB,WAAW,CAAC,SAAS,EAAE,KAAK,CAAC,EAC7B,KAAK,SAAS,OAAO,CAAC,GAAG,GACrB,kBAAkB,CAAC,SAAS,CAAC,GAC7B,YAAY,CAAC,QAAQ,CAAC,SAAS,EAAE,KAAK,CAAC,CAC5C,CAAC;AAEF,eAAO,MAAM,WAAW,GACtB,SAAS,SAAS,gBAAgB,EAClC,KAAK,SAAS,OAAO,CAAC,OAAO,GAAG,OAAO,CAAC,GAAG,OACxC,cAAc,CAAC,SAAS,EAAE,KAAK,CACY,CAAC;AAEjD,MAAM,MAAM,WAAW,CACrB,SAAS,SAAS,gBAAgB,EAClC,KAAK,SAAS,OAAO,CAAC,OAAO,GAAG,OAAO,CAAC,GAAG,IACzC,KAAK,SAAS,OAAO,CAAC,GAAG,GACzB,kBAAkB,CAAC,SAAS,CAAC,GAC7B,YAAY,CAAC,UAAU,CAAC,UAAU,EAAE,SAAS,EAAE,KAAK,CAAC,CAAC;AAE1D,eAAO,MAAM,KAAK,GAChB,SAAS,SAAS,gBAAgB,EAClC,KAAK,SAAS,OAAO,CAAC,OAAO,OAExB,kBAAkB,CAAC,SAAS,CAAC,SAC3B,KAAK,6DAUb,CAAC"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { __exportAll } from "./_virtual/_rolldown/runtime.js";
|
|
2
|
+
import * as Context from "effect/Context";
|
|
3
|
+
import * as Layer from "effect/Layer";
|
|
4
|
+
//#region src/MutationCtx.ts
|
|
5
|
+
var MutationCtx_exports = /* @__PURE__ */ __exportAll({
|
|
6
|
+
MutationCtx: () => MutationCtx,
|
|
7
|
+
layer: () => layer
|
|
8
|
+
});
|
|
9
|
+
const MutationCtx = () => Context.Service("@confect/server/MutationCtx");
|
|
10
|
+
const layer = (ctx, scope) => {
|
|
11
|
+
const tag = MutationCtx();
|
|
12
|
+
const { auth: _auth, ...componentCtx } = ctx;
|
|
13
|
+
return Layer.succeed(tag, scope === "" ? ctx : componentCtx);
|
|
14
|
+
};
|
|
15
|
+
//#endregion
|
|
16
|
+
export { MutationCtx, MutationCtx_exports, layer };
|
|
17
|
+
|
|
18
|
+
//# sourceMappingURL=MutationCtx.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"MutationCtx.js","names":[],"sources":["../src/MutationCtx.ts"],"sourcesContent":["import type * as IdScope from \"@confect/core/IdScope\";\nimport type { GenericDataModel, GenericMutationCtx } from \"convex/server\";\nimport * as Context from \"effect/Context\";\nimport type * as ComponentCtx from \"./ComponentCtx\";\nimport * as Layer from \"effect/Layer\";\n\nexport type MutationCtxTag<\n DataModel extends GenericDataModel,\n Scope extends IdScope.IdScope = IdScope.App,\n> = Context.Service<\n MutationCtx<DataModel, Scope>,\n Scope extends IdScope.App\n ? GenericMutationCtx<DataModel>\n : ComponentCtx.Mutation<DataModel, Scope>\n>;\n\nexport const MutationCtx = <\n DataModel extends GenericDataModel,\n Scope extends IdScope.IdScope = IdScope.App,\n>(): MutationCtxTag<DataModel, Scope> =>\n Context.Service(\"@confect/server/MutationCtx\");\n\nexport type MutationCtx<\n DataModel extends GenericDataModel,\n Scope extends IdScope.IdScope = IdScope.App,\n> = Scope extends IdScope.App\n ? GenericMutationCtx<DataModel>\n : ComponentCtx.Identifier<\"mutation\", DataModel, Scope>;\n\nexport const layer = <\n DataModel extends GenericDataModel,\n Scope extends IdScope.IdScope,\n>(\n ctx: GenericMutationCtx<DataModel>,\n scope: Scope,\n) => {\n const tag = MutationCtx<DataModel, Scope>();\n const { auth: _auth, ...componentCtx } = ctx;\n return Layer.succeed(\n tag,\n (scope === \"\" ? ctx : componentCtx) as unknown as Context.Service.Shape<\n typeof tag\n >,\n );\n};\n"],"mappings":";;;;;;;;AAgBA,MAAa,oBAIX,QAAQ,QAAQ,6BAA6B;AAS/C,MAAa,SAIX,KACA,UACG;CACH,MAAM,MAAM,YAA8B;CAC1C,MAAM,EAAE,MAAM,OAAO,GAAG,iBAAiB;CACzC,OAAO,MAAM,QACX,KACC,UAAU,KAAK,MAAM,YAGxB;AACF"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import * as Ref from "@confect/core/Ref";
|
|
2
|
+
import type { GenericActionCtx } from "convex/server";
|
|
3
|
+
import * as Context from "effect/Context";
|
|
4
|
+
import * as Effect from "effect/Effect";
|
|
5
|
+
import * as Layer from "effect/Layer";
|
|
6
|
+
import type * as Schema from "effect/Schema";
|
|
7
|
+
import * as MutationTransactionContext from "./MutationTransactionContext";
|
|
8
|
+
export type Options = MutationTransactionContext.MutationOptions;
|
|
9
|
+
export declare const MutationRunner: Context.Service<{
|
|
10
|
+
runMutation: {
|
|
11
|
+
<Mutation extends Ref.AnyMutation>(mutation: Mutation, ...args: [...Ref.OptionalArgs<Mutation>, options?: undefined]): Effect.Effect<Ref.Returns<Mutation>, Ref.Error<Mutation> | Schema.SchemaError>;
|
|
12
|
+
<Mutation extends Ref.AnyMutation>(mutation: Mutation, args: Ref.Args<Mutation>, options: Options | undefined): Effect.Effect<Ref.Returns<Mutation>, Ref.Error<Mutation> | Schema.SchemaError, MutationTransactionContext.MutationTransactionContext>;
|
|
13
|
+
};
|
|
14
|
+
}, {
|
|
15
|
+
runMutation: {
|
|
16
|
+
<Mutation extends Ref.AnyMutation>(mutation: Mutation, ...args: [...Ref.OptionalArgs<Mutation>, options?: undefined]): Effect.Effect<Ref.Returns<Mutation>, Ref.Error<Mutation> | Schema.SchemaError>;
|
|
17
|
+
<Mutation extends Ref.AnyMutation>(mutation: Mutation, args: Ref.Args<Mutation>, options: Options | undefined): Effect.Effect<Ref.Returns<Mutation>, Ref.Error<Mutation> | Schema.SchemaError, MutationTransactionContext.MutationTransactionContext>;
|
|
18
|
+
};
|
|
19
|
+
}>;
|
|
20
|
+
export type MutationRunner = typeof MutationRunner.Identifier;
|
|
21
|
+
export declare const layer: (runMutation: GenericActionCtx<any>["runMutation"]) => Layer.Layer<{
|
|
22
|
+
runMutation: {
|
|
23
|
+
<Mutation extends Ref.AnyMutation>(mutation: Mutation, ...args: [...Ref.OptionalArgs<Mutation>, options?: undefined]): Effect.Effect<Ref.Returns<Mutation>, Ref.Error<Mutation> | Schema.SchemaError>;
|
|
24
|
+
<Mutation extends Ref.AnyMutation>(mutation: Mutation, args: Ref.Args<Mutation>, options: Options | undefined): Effect.Effect<Ref.Returns<Mutation>, Ref.Error<Mutation> | Schema.SchemaError, MutationTransactionContext.MutationTransactionContext>;
|
|
25
|
+
};
|
|
26
|
+
}, never, never>;
|
|
27
|
+
//# sourceMappingURL=MutationRunner.d.ts.map
|