@gaganref/confect-server 0.0.0-stage → 10.3.1-fork.10
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,70 @@
|
|
|
1
|
+
import * as MiddlewareAttachment from "@confect/core/MiddlewareAttachment";
|
|
2
|
+
import type * as MiddlewareSpec from "@confect/core/MiddlewareSpec";
|
|
3
|
+
import * as Result from "effect/Result";
|
|
4
|
+
import type * as FunctionRegistryItem from "./FunctionRegistryItem.js";
|
|
5
|
+
import type * as MiddlewareRegistryItem from "./MiddlewareRegistryItem.js";
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* A middleware spec paired with its implementation for one function's type—the
|
|
9
|
+
* resolved form consumed by runtime-specific function preparation.
|
|
10
|
+
*/
|
|
11
|
+
export interface ResolvedMiddleware {
|
|
12
|
+
readonly middlewareSpec: MiddlewareSpec.AnyMiddlewareSpec;
|
|
13
|
+
readonly middlewareImpl: MiddlewareSpec.AnyMiddlewareImpl;
|
|
14
|
+
readonly options?: unknown;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Pair each middleware spec attached to a function with its registered
|
|
19
|
+
* implementation for the function's type. Both misses are ruled out by the type
|
|
20
|
+
* system (`GroupImpl.finalize` demands every attached middleware's
|
|
21
|
+
* `MiddlewareImpl` service; `MiddlewareImpl.make`/`makeByFunctionType` cover
|
|
22
|
+
* exactly the declared functionTypes, which `GroupSpec.middleware` requires to
|
|
23
|
+
* cover every function). Spec identity is checked separately because
|
|
24
|
+
* implementation services are keyed by string, so the type system cannot
|
|
25
|
+
* distinguish same-key specs.
|
|
26
|
+
*/
|
|
27
|
+
export const resolve = (
|
|
28
|
+
functionRegistryItem: FunctionRegistryItem.ConfectFunctionRegistryItem,
|
|
29
|
+
middlewareRegistryItems: ReadonlyMap<
|
|
30
|
+
string,
|
|
31
|
+
MiddlewareRegistryItem.MiddlewareRegistryItem
|
|
32
|
+
>,
|
|
33
|
+
): ReadonlyArray<ResolvedMiddleware> => {
|
|
34
|
+
Result.getOrThrowWith(
|
|
35
|
+
MiddlewareAttachment.validateAll(
|
|
36
|
+
functionRegistryItem.middlewareAttachments,
|
|
37
|
+
`function "${functionRegistryItem.name}"`,
|
|
38
|
+
),
|
|
39
|
+
(error) => new Error(MiddlewareAttachment.formatValidationError(error)),
|
|
40
|
+
);
|
|
41
|
+
return functionRegistryItem.middlewareAttachments.map(
|
|
42
|
+
({ spec: middlewareSpec, options }) => {
|
|
43
|
+
const registered = middlewareRegistryItems.get(middlewareSpec.key);
|
|
44
|
+
if (registered === undefined) {
|
|
45
|
+
throw new Error(
|
|
46
|
+
`Middleware "${middlewareSpec.key}" is attached to this group's spec, but no implementation was provided—pipe the group's impl through \`Layer.provide(MiddlewareImpl.make(...))\` (or \`makeByFunctionType\`/\`provides\`).`,
|
|
47
|
+
);
|
|
48
|
+
}
|
|
49
|
+
if (registered.middlewareSpec !== middlewareSpec) {
|
|
50
|
+
throw new Error(
|
|
51
|
+
`Middleware "${middlewareSpec.key}" attached to function "${functionRegistryItem.name}" has an implementation registered for a different spec with the same key. Register the implementation using the attached middleware spec.`,
|
|
52
|
+
);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
const middlewareImpl =
|
|
56
|
+
registered.impls[functionRegistryItem.functionType];
|
|
57
|
+
if (middlewareImpl === undefined) {
|
|
58
|
+
throw new Error(
|
|
59
|
+
`Middleware "${middlewareSpec.key}" has no implementation for function type "${functionRegistryItem.functionType}", the type of function "${functionRegistryItem.name}". Declare the function type in the middleware's \`functionTypes\` and cover it in \`MiddlewareImpl.makeByFunctionType\`.`,
|
|
60
|
+
);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
return {
|
|
64
|
+
middlewareImpl,
|
|
65
|
+
middlewareSpec,
|
|
66
|
+
options,
|
|
67
|
+
};
|
|
68
|
+
},
|
|
69
|
+
);
|
|
70
|
+
};
|
package/src/Scheduler.ts
ADDED
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import type * as IdScope from "@confect/core/IdScope";
|
|
2
|
+
import { Ref } from "@confect/core";
|
|
3
|
+
import type { GenericId } from "@confect/core/GenericId";
|
|
4
|
+
import type { Scheduler as ConvexScheduler } from "convex/server";
|
|
5
|
+
import type { GenericId as ConvexGenericId } from "convex/values";
|
|
6
|
+
import * as Context from "effect/Context";
|
|
7
|
+
import * as DateTime from "effect/DateTime";
|
|
8
|
+
import * as Duration from "effect/Duration";
|
|
9
|
+
import * as Effect from "effect/Effect";
|
|
10
|
+
import * as Layer from "effect/Layer";
|
|
11
|
+
|
|
12
|
+
const make = (scheduler: ConvexScheduler) => ({
|
|
13
|
+
cancel: (id: ConvexGenericId<"_scheduled_functions">) =>
|
|
14
|
+
Effect.promise(() => scheduler.cancel(id)),
|
|
15
|
+
runAfter: <Ref_ extends Ref.AnyMutation | Ref.AnyAction>(
|
|
16
|
+
delay: Duration.Duration,
|
|
17
|
+
ref: Ref_,
|
|
18
|
+
...args: Ref.OptionalArgs<Ref_>
|
|
19
|
+
) => {
|
|
20
|
+
const delayMs = Duration.toMillis(delay);
|
|
21
|
+
const functionReference = Ref.getFunctionReference(ref);
|
|
22
|
+
const encodedArgs = Ref.encodeArgsSync(
|
|
23
|
+
ref,
|
|
24
|
+
(args[0] ?? {}) as Ref.Args<Ref_>,
|
|
25
|
+
);
|
|
26
|
+
|
|
27
|
+
return Effect.promise(() =>
|
|
28
|
+
scheduler.runAfter(delayMs, functionReference, encodedArgs),
|
|
29
|
+
);
|
|
30
|
+
},
|
|
31
|
+
runAt: <Ref_ extends Ref.AnyMutation | Ref.AnyAction>(
|
|
32
|
+
dateTime: DateTime.DateTime,
|
|
33
|
+
ref: Ref_,
|
|
34
|
+
...args: Ref.OptionalArgs<Ref_>
|
|
35
|
+
) => {
|
|
36
|
+
const timestamp = DateTime.toEpochMillis(dateTime);
|
|
37
|
+
const functionReference = Ref.getFunctionReference(ref);
|
|
38
|
+
const encodedArgs = Ref.encodeArgsSync(
|
|
39
|
+
ref,
|
|
40
|
+
(args[0] ?? {}) as Ref.Args<Ref_>,
|
|
41
|
+
);
|
|
42
|
+
|
|
43
|
+
return Effect.promise(() =>
|
|
44
|
+
scheduler.runAt(timestamp, functionReference, encodedArgs),
|
|
45
|
+
);
|
|
46
|
+
},
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
export const Scheduler = Context.Service<ReturnType<typeof make>>(
|
|
50
|
+
"@confect/server/Scheduler",
|
|
51
|
+
);
|
|
52
|
+
export type Scheduler = typeof Scheduler.Identifier;
|
|
53
|
+
|
|
54
|
+
export interface Service<Scope extends IdScope.IdScope = IdScope.App> {
|
|
55
|
+
cancel(id: GenericId<"_scheduled_functions", Scope>): Effect.Effect<void>;
|
|
56
|
+
runAfter<Ref_ extends Ref.AnyMutation | Ref.AnyAction>(
|
|
57
|
+
delay: Duration.Duration,
|
|
58
|
+
ref: Ref_,
|
|
59
|
+
...args: Ref.OptionalArgs<Ref_>
|
|
60
|
+
): Effect.Effect<GenericId<"_scheduled_functions", Scope>>;
|
|
61
|
+
runAt<Ref_ extends Ref.AnyMutation | Ref.AnyAction>(
|
|
62
|
+
dateTime: DateTime.DateTime,
|
|
63
|
+
ref: Ref_,
|
|
64
|
+
...args: Ref.OptionalArgs<Ref_>
|
|
65
|
+
): Effect.Effect<GenericId<"_scheduled_functions", Scope>>;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
export type ForScope<Scope extends IdScope.IdScope> = Scope extends IdScope.App
|
|
69
|
+
? Scheduler
|
|
70
|
+
: { readonly "~ScopedScheduler": Scope };
|
|
71
|
+
|
|
72
|
+
export const forScope = <
|
|
73
|
+
Scope extends IdScope.IdScope = IdScope.App,
|
|
74
|
+
>(): Context.Service<ForScope<Scope>, Service<Scope>> =>
|
|
75
|
+
Context.Service("@confect/server/Scheduler");
|
|
76
|
+
|
|
77
|
+
export const layer = <Scope extends IdScope.IdScope = IdScope.App>(
|
|
78
|
+
scheduler: ConvexScheduler,
|
|
79
|
+
_scope?: Scope,
|
|
80
|
+
) =>
|
|
81
|
+
// Scopes are phantom: Convex still receives and returns the same ID strings.
|
|
82
|
+
Layer.succeed(
|
|
83
|
+
forScope<Scope>(),
|
|
84
|
+
make(scheduler) as unknown as Service<Scope>,
|
|
85
|
+
);
|
package/src/Storage.ts
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import type { StorageReader as ConvexStorageReader } from "convex/server";
|
|
2
|
+
import type { GenericId } from "convex/values";
|
|
3
|
+
import * as Context from "effect/Context";
|
|
4
|
+
import * as Effect from "effect/Effect";
|
|
5
|
+
import * as Layer from "effect/Layer";
|
|
6
|
+
import { StorageActionWriter } from "./StorageActionWriter.js";
|
|
7
|
+
import { StorageReader } from "./StorageReader.js";
|
|
8
|
+
import { StorageWriter } from "./StorageWriter.js";
|
|
9
|
+
|
|
10
|
+
const make = Effect.gen(function* () {
|
|
11
|
+
const reader = yield* StorageReader;
|
|
12
|
+
return {
|
|
13
|
+
getUrl: reader.getUrl,
|
|
14
|
+
generateUploadUrl: Effect.flatMap(
|
|
15
|
+
StorageWriter,
|
|
16
|
+
(writer) => writer.generateUploadUrl,
|
|
17
|
+
),
|
|
18
|
+
delete: (storageId: GenericId<"_storage">) =>
|
|
19
|
+
Effect.flatMap(StorageWriter, (writer) => writer.delete(storageId)),
|
|
20
|
+
get: (storageId: GenericId<"_storage">) =>
|
|
21
|
+
Effect.flatMap(StorageActionWriter, (writer) => writer.get(storageId)),
|
|
22
|
+
store: (blob: Blob, options?: { sha256?: string }) =>
|
|
23
|
+
Effect.flatMap(StorageActionWriter, (writer) =>
|
|
24
|
+
writer.store(blob, options),
|
|
25
|
+
),
|
|
26
|
+
};
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
export class Storage extends Context.Service<
|
|
30
|
+
Storage,
|
|
31
|
+
Effect.Success<typeof make>
|
|
32
|
+
>()("@confect/server/Storage") {}
|
|
33
|
+
|
|
34
|
+
export const layer = (storageReader: ConvexStorageReader) =>
|
|
35
|
+
Layer.effect(Storage, make).pipe(
|
|
36
|
+
Layer.provideMerge(StorageReader.layer(storageReader)),
|
|
37
|
+
);
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import type * as IdScope from "@confect/core/IdScope";
|
|
2
|
+
import type { StorageActionWriter as ConvexStorageActionWriter } from "convex/server";
|
|
3
|
+
import type { GenericId } from "convex/values";
|
|
4
|
+
import * as Context from "effect/Context";
|
|
5
|
+
import { flow } from "effect/Function";
|
|
6
|
+
import * as Effect from "effect/Effect";
|
|
7
|
+
import * as Layer from "effect/Layer";
|
|
8
|
+
import * as Option from "effect/Option";
|
|
9
|
+
import { BlobNotFoundError } from "./BlobNotFoundError.js";
|
|
10
|
+
import type * as ScopedId from "@confect/core/GenericId";
|
|
11
|
+
|
|
12
|
+
export type Service<Scope extends IdScope.IdScope = IdScope.App> = {
|
|
13
|
+
get: (
|
|
14
|
+
id: ScopedId.GenericId<"_storage", Scope>,
|
|
15
|
+
) => ReturnType<ReturnType<typeof make>["get"]>;
|
|
16
|
+
store: (
|
|
17
|
+
blob: Blob,
|
|
18
|
+
options?: { sha256?: string },
|
|
19
|
+
) => Effect.Effect<ScopedId.GenericId<"_storage", Scope>>;
|
|
20
|
+
};
|
|
21
|
+
export type ForScope<Scope extends IdScope.IdScope> = Scope extends IdScope.App
|
|
22
|
+
? StorageActionWriter
|
|
23
|
+
: { readonly "~ScopedStorageActionWriter": Scope };
|
|
24
|
+
|
|
25
|
+
const make = (storageActionWriter: ConvexStorageActionWriter) => ({
|
|
26
|
+
get: (storageId: GenericId<"_storage">) =>
|
|
27
|
+
Effect.promise(() => storageActionWriter.get(storageId)).pipe(
|
|
28
|
+
Effect.andThen(
|
|
29
|
+
flow(
|
|
30
|
+
Option.fromNullishOr,
|
|
31
|
+
Option.match({
|
|
32
|
+
onNone: () => Effect.fail(new BlobNotFoundError({ id: storageId })),
|
|
33
|
+
onSome: Effect.succeed,
|
|
34
|
+
}),
|
|
35
|
+
),
|
|
36
|
+
),
|
|
37
|
+
),
|
|
38
|
+
store: (blob: Blob, options?: { sha256?: string }) =>
|
|
39
|
+
Effect.promise(() => storageActionWriter.store(blob, options)),
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
export class StorageActionWriter extends Context.Service<
|
|
43
|
+
StorageActionWriter,
|
|
44
|
+
ReturnType<typeof make>
|
|
45
|
+
>()("@confect/server/StorageActionWriter") {
|
|
46
|
+
static readonly forScope = <
|
|
47
|
+
Scope extends IdScope.IdScope = IdScope.App,
|
|
48
|
+
>(): Context.Service<ForScope<Scope>, Service<Scope>> =>
|
|
49
|
+
Context.Service("@confect/server/StorageActionWriter");
|
|
50
|
+
|
|
51
|
+
static readonly layer = <Scope extends IdScope.IdScope = IdScope.App>(
|
|
52
|
+
storageActionWriter: ConvexStorageActionWriter,
|
|
53
|
+
_scope?: Scope,
|
|
54
|
+
) =>
|
|
55
|
+
Layer.succeed(
|
|
56
|
+
this.forScope<Scope>(),
|
|
57
|
+
make(storageActionWriter) as unknown as Service<Scope>,
|
|
58
|
+
);
|
|
59
|
+
}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import type * as IdScope from "@confect/core/IdScope";
|
|
2
|
+
import type { StorageReader as ConvexStorageReader } from "convex/server";
|
|
3
|
+
import type { GenericId } from "convex/values";
|
|
4
|
+
import * as Context from "effect/Context";
|
|
5
|
+
import { flow, pipe } from "effect/Function";
|
|
6
|
+
import * as Effect from "effect/Effect";
|
|
7
|
+
import * as Layer from "effect/Layer";
|
|
8
|
+
import * as Option from "effect/Option";
|
|
9
|
+
import * as Schema from "effect/Schema";
|
|
10
|
+
import { BlobNotFoundError } from "./BlobNotFoundError.js";
|
|
11
|
+
import type * as ScopedId from "@confect/core/GenericId";
|
|
12
|
+
|
|
13
|
+
export type Service<Scope extends IdScope.IdScope = IdScope.App> = {
|
|
14
|
+
getUrl: (
|
|
15
|
+
id: ScopedId.GenericId<"_storage", Scope>,
|
|
16
|
+
) => ReturnType<ReturnType<typeof make>["getUrl"]>;
|
|
17
|
+
};
|
|
18
|
+
export type ForScope<Scope extends IdScope.IdScope> = Scope extends IdScope.App
|
|
19
|
+
? StorageReader
|
|
20
|
+
: { readonly "~ScopedStorageReader": Scope };
|
|
21
|
+
|
|
22
|
+
const make = (storageReader: ConvexStorageReader) => ({
|
|
23
|
+
getUrl: (storageId: GenericId<"_storage">) =>
|
|
24
|
+
Effect.promise(() => storageReader.getUrl(storageId)).pipe(
|
|
25
|
+
Effect.andThen(
|
|
26
|
+
flow(
|
|
27
|
+
Option.fromNullishOr,
|
|
28
|
+
Option.match({
|
|
29
|
+
onNone: () => Effect.fail(new BlobNotFoundError({ id: storageId })),
|
|
30
|
+
onSome: (doc) =>
|
|
31
|
+
pipe(
|
|
32
|
+
doc,
|
|
33
|
+
Schema.decodeEffect(Schema.URLFromString),
|
|
34
|
+
Effect.catchTag("SchemaError", Effect.die),
|
|
35
|
+
),
|
|
36
|
+
}),
|
|
37
|
+
),
|
|
38
|
+
),
|
|
39
|
+
),
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
export class StorageReader extends Context.Service<
|
|
43
|
+
StorageReader,
|
|
44
|
+
ReturnType<typeof make>
|
|
45
|
+
>()("@confect/server/StorageReader") {
|
|
46
|
+
static readonly forScope = <
|
|
47
|
+
Scope extends IdScope.IdScope = IdScope.App,
|
|
48
|
+
>(): Context.Service<ForScope<Scope>, Service<Scope>> =>
|
|
49
|
+
Context.Service("@confect/server/StorageReader");
|
|
50
|
+
|
|
51
|
+
static readonly layer = <Scope extends IdScope.IdScope = IdScope.App>(
|
|
52
|
+
storageReader: ConvexStorageReader,
|
|
53
|
+
_scope?: Scope,
|
|
54
|
+
) =>
|
|
55
|
+
Layer.succeed(
|
|
56
|
+
this.forScope<Scope>(),
|
|
57
|
+
make(storageReader) as unknown as Service<Scope>,
|
|
58
|
+
);
|
|
59
|
+
}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import type * as IdScope from "@confect/core/IdScope";
|
|
2
|
+
import type { StorageWriter as ConvexStorageWriter } from "convex/server";
|
|
3
|
+
import type { GenericId } from "convex/values";
|
|
4
|
+
import * as Context from "effect/Context";
|
|
5
|
+
import { pipe } from "effect/Function";
|
|
6
|
+
import * as Effect from "effect/Effect";
|
|
7
|
+
import * as Layer from "effect/Layer";
|
|
8
|
+
import * as Schema from "effect/Schema";
|
|
9
|
+
import { BlobNotFoundError } from "./BlobNotFoundError.js";
|
|
10
|
+
import type * as ScopedId from "@confect/core/GenericId";
|
|
11
|
+
|
|
12
|
+
export type Service<Scope extends IdScope.IdScope = IdScope.App> = {
|
|
13
|
+
generateUploadUrl: ReturnType<typeof make>["generateUploadUrl"];
|
|
14
|
+
delete: (
|
|
15
|
+
id: ScopedId.GenericId<"_storage", Scope>,
|
|
16
|
+
) => ReturnType<ReturnType<typeof make>["delete"]>;
|
|
17
|
+
};
|
|
18
|
+
export type ForScope<Scope extends IdScope.IdScope> = Scope extends IdScope.App
|
|
19
|
+
? StorageWriter
|
|
20
|
+
: { readonly "~ScopedStorageWriter": Scope };
|
|
21
|
+
|
|
22
|
+
const make = (storageWriter: ConvexStorageWriter) => ({
|
|
23
|
+
generateUploadUrl: Effect.promise(() =>
|
|
24
|
+
storageWriter.generateUploadUrl(),
|
|
25
|
+
).pipe(
|
|
26
|
+
Effect.andThen((url) =>
|
|
27
|
+
pipe(
|
|
28
|
+
url,
|
|
29
|
+
Schema.decodeEffect(Schema.URLFromString),
|
|
30
|
+
Effect.catchTag("SchemaError", Effect.die),
|
|
31
|
+
),
|
|
32
|
+
),
|
|
33
|
+
),
|
|
34
|
+
delete: (storageId: GenericId<"_storage">) =>
|
|
35
|
+
Effect.tryPromise({
|
|
36
|
+
try: () => storageWriter.delete(storageId),
|
|
37
|
+
catch: () => new BlobNotFoundError({ id: storageId }),
|
|
38
|
+
}),
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
export class StorageWriter extends Context.Service<
|
|
42
|
+
StorageWriter,
|
|
43
|
+
ReturnType<typeof make>
|
|
44
|
+
>()("@confect/server/StorageWriter") {
|
|
45
|
+
static readonly forScope = <
|
|
46
|
+
Scope extends IdScope.IdScope = IdScope.App,
|
|
47
|
+
>(): Context.Service<ForScope<Scope>, Service<Scope>> =>
|
|
48
|
+
Context.Service("@confect/server/StorageWriter");
|
|
49
|
+
|
|
50
|
+
static readonly layer = <Scope extends IdScope.IdScope = IdScope.App>(
|
|
51
|
+
storageWriter: ConvexStorageWriter,
|
|
52
|
+
_scope?: Scope,
|
|
53
|
+
) =>
|
|
54
|
+
Layer.succeed(
|
|
55
|
+
this.forScope<Scope>(),
|
|
56
|
+
make(storageWriter) as unknown as Service<Scope>,
|
|
57
|
+
);
|
|
58
|
+
}
|
package/src/Table.ts
ADDED
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
import type * as IdScope from "@confect/core/IdScope";
|
|
2
|
+
import { compileTableSchema } from "@confect/core/SchemaToValidator";
|
|
3
|
+
import * as Table_ from "@confect/core/Table";
|
|
4
|
+
import * as Schema from "effect/Schema";
|
|
5
|
+
import { defineTable, type TableDefinition } from "convex/server";
|
|
6
|
+
|
|
7
|
+
export {
|
|
8
|
+
TypeId,
|
|
9
|
+
isTable,
|
|
10
|
+
isUnnamedTable,
|
|
11
|
+
make,
|
|
12
|
+
type Table,
|
|
13
|
+
type Any,
|
|
14
|
+
type AnyWithProps,
|
|
15
|
+
type UnnamedTable,
|
|
16
|
+
type UnnamedAny,
|
|
17
|
+
type UnnamedAnyWithProps,
|
|
18
|
+
type Name,
|
|
19
|
+
type TableSchema,
|
|
20
|
+
type TableValidator,
|
|
21
|
+
type Indexes,
|
|
22
|
+
type SearchIndexes,
|
|
23
|
+
type VectorIndexes,
|
|
24
|
+
type Doc,
|
|
25
|
+
type Fields,
|
|
26
|
+
type Scope,
|
|
27
|
+
type WithName,
|
|
28
|
+
type TablesRecord,
|
|
29
|
+
} from "@confect/core/Table";
|
|
30
|
+
|
|
31
|
+
// -----------------------------------------------------------------------------
|
|
32
|
+
// tableDefinition
|
|
33
|
+
// -----------------------------------------------------------------------------
|
|
34
|
+
//
|
|
35
|
+
// The deploy-time Convex `TableDefinition` is the part of a table that
|
|
36
|
+
// belongs on the server: it value-imports `defineTable` from `convex/server`.
|
|
37
|
+
// Specs and generated refs reach `Fields`/`Doc` through `@confect/core`,
|
|
38
|
+
// so this helper is only called from `_generated/convexSchema.ts`.
|
|
39
|
+
|
|
40
|
+
const tableDefinitionCache = new WeakMap<
|
|
41
|
+
Table_.AnyWithProps,
|
|
42
|
+
TableDefinition<any, any, any, any>
|
|
43
|
+
>();
|
|
44
|
+
|
|
45
|
+
export const tableDefinition = <Table extends Table_.AnyWithProps>(
|
|
46
|
+
table: Table,
|
|
47
|
+
): TableDefinition<
|
|
48
|
+
Table_.TableValidator<Table>,
|
|
49
|
+
Table_.Indexes<Table>,
|
|
50
|
+
Table_.SearchIndexes<Table>,
|
|
51
|
+
Table_.VectorIndexes<Table>
|
|
52
|
+
> => {
|
|
53
|
+
const cached = tableDefinitionCache.get(table);
|
|
54
|
+
if (cached !== undefined) {
|
|
55
|
+
return cached as TableDefinition<
|
|
56
|
+
Table_.TableValidator<Table>,
|
|
57
|
+
Table_.Indexes<Table>,
|
|
58
|
+
Table_.SearchIndexes<Table>,
|
|
59
|
+
Table_.VectorIndexes<Table>
|
|
60
|
+
>;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
let definition: TableDefinition<any, any, any, any> = defineTable(
|
|
64
|
+
compileTableSchema(table.Fields, table.scope),
|
|
65
|
+
);
|
|
66
|
+
for (const [name, indexFields] of Object.entries(
|
|
67
|
+
table.indexes as Record<string, any>,
|
|
68
|
+
)) {
|
|
69
|
+
definition = definition.index(name, indexFields);
|
|
70
|
+
}
|
|
71
|
+
for (const [name, config] of Object.entries(
|
|
72
|
+
table.searchIndexes as Record<string, any>,
|
|
73
|
+
)) {
|
|
74
|
+
definition = definition.searchIndex(name, config);
|
|
75
|
+
}
|
|
76
|
+
for (const [name, config] of Object.entries(
|
|
77
|
+
table.vectorIndexes as Record<string, any>,
|
|
78
|
+
)) {
|
|
79
|
+
definition = definition.vectorIndex(name, config);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
tableDefinitionCache.set(table, definition);
|
|
83
|
+
return definition as TableDefinition<
|
|
84
|
+
Table_.TableValidator<Table>,
|
|
85
|
+
Table_.Indexes<Table>,
|
|
86
|
+
Table_.SearchIndexes<Table>,
|
|
87
|
+
Table_.VectorIndexes<Table>
|
|
88
|
+
>;
|
|
89
|
+
};
|
|
90
|
+
|
|
91
|
+
// -----------------------------------------------------------------------------
|
|
92
|
+
// System tables
|
|
93
|
+
// -----------------------------------------------------------------------------
|
|
94
|
+
|
|
95
|
+
export const scheduledFunctionsTable = Table_.make(() =>
|
|
96
|
+
Schema.Struct({
|
|
97
|
+
name: Schema.String,
|
|
98
|
+
args: Schema.Array(Schema.Any),
|
|
99
|
+
scheduledTime: Schema.Finite,
|
|
100
|
+
completedTime: Schema.optionalKey(Schema.Finite),
|
|
101
|
+
state: Schema.Union([
|
|
102
|
+
Schema.Struct({ kind: Schema.Literal("pending") }),
|
|
103
|
+
Schema.Struct({ kind: Schema.Literal("inProgress") }),
|
|
104
|
+
Schema.Struct({ kind: Schema.Literal("success") }),
|
|
105
|
+
Schema.Struct({
|
|
106
|
+
kind: Schema.Literal("failed"),
|
|
107
|
+
error: Schema.String,
|
|
108
|
+
}),
|
|
109
|
+
Schema.Struct({ kind: Schema.Literal("canceled") }),
|
|
110
|
+
]),
|
|
111
|
+
}),
|
|
112
|
+
)("_scheduled_functions");
|
|
113
|
+
|
|
114
|
+
export const storageTable = Table_.make(() =>
|
|
115
|
+
Schema.Struct({
|
|
116
|
+
sha256: Schema.String,
|
|
117
|
+
size: Schema.Finite,
|
|
118
|
+
contentType: Schema.optionalKey(Schema.String),
|
|
119
|
+
}),
|
|
120
|
+
)("_storage");
|
|
121
|
+
|
|
122
|
+
export const systemTables = {
|
|
123
|
+
_scheduled_functions: scheduledFunctionsTable,
|
|
124
|
+
_storage: storageTable,
|
|
125
|
+
} as const;
|
|
126
|
+
|
|
127
|
+
const makeSystemTables = <const Scope_ extends IdScope.IdScope>(
|
|
128
|
+
scope: Scope_,
|
|
129
|
+
) => ({
|
|
130
|
+
_scheduled_functions: Table_.make(() => scheduledFunctionsTable.Fields)(
|
|
131
|
+
"_scheduled_functions",
|
|
132
|
+
scope,
|
|
133
|
+
),
|
|
134
|
+
_storage: Table_.make(() => storageTable.Fields)("_storage", scope),
|
|
135
|
+
});
|
|
136
|
+
|
|
137
|
+
const systemTablesByScope = new Map<
|
|
138
|
+
IdScope.IdScope,
|
|
139
|
+
Record<keyof typeof systemTables, Table_.AnyWithProps>
|
|
140
|
+
>();
|
|
141
|
+
|
|
142
|
+
export const systemTablesForScope = <const Scope_ extends IdScope.IdScope>(
|
|
143
|
+
scope: Scope_,
|
|
144
|
+
): ReturnType<typeof makeSystemTables<Scope_>> => {
|
|
145
|
+
const cached = systemTablesByScope.get(scope);
|
|
146
|
+
if (cached !== undefined) {
|
|
147
|
+
// Each cache key is the scope used to construct both tables.
|
|
148
|
+
return cached as ReturnType<typeof makeSystemTables<Scope_>>;
|
|
149
|
+
}
|
|
150
|
+
const tables = makeSystemTables(scope);
|
|
151
|
+
systemTablesByScope.set(scope, tables);
|
|
152
|
+
return tables;
|
|
153
|
+
};
|
|
154
|
+
|
|
155
|
+
export type SystemTables<Scope_ extends IdScope.IdScope = IdScope.App> =
|
|
156
|
+
ReturnType<typeof systemTablesForScope<Scope_>>[keyof typeof systemTables];
|
package/src/TableInfo.ts
ADDED
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import type * as IdScope from "@confect/core/IdScope";
|
|
2
|
+
import type {
|
|
3
|
+
GenericDocument,
|
|
4
|
+
GenericFieldPaths,
|
|
5
|
+
GenericTableIndexes,
|
|
6
|
+
GenericTableSearchIndexes,
|
|
7
|
+
GenericTableVectorIndexes,
|
|
8
|
+
IdField,
|
|
9
|
+
SystemFields,
|
|
10
|
+
SystemIndexes,
|
|
11
|
+
} from "convex/server";
|
|
12
|
+
import type { GenericValidator } from "convex/values";
|
|
13
|
+
import type { Schema, Types } from "effect";
|
|
14
|
+
import type { WithSystemFields } from "@confect/core/SystemFields";
|
|
15
|
+
import type * as Document_ from "./Document.js";
|
|
16
|
+
import type * as Table from "./Table.js";
|
|
17
|
+
|
|
18
|
+
export declare const TypeId: "~@confect/server/TableInfo";
|
|
19
|
+
export type TypeId = typeof TypeId;
|
|
20
|
+
|
|
21
|
+
export type TableInfo<Table_ extends Table.AnyWithProps> =
|
|
22
|
+
Table_ extends Table.Table<
|
|
23
|
+
infer TableName,
|
|
24
|
+
infer TableSchema_,
|
|
25
|
+
infer TableValidator,
|
|
26
|
+
infer Indexes,
|
|
27
|
+
infer SearchIndexes,
|
|
28
|
+
infer VectorIndexes,
|
|
29
|
+
infer Scope
|
|
30
|
+
>
|
|
31
|
+
? {
|
|
32
|
+
readonly [TypeId]: TypeId;
|
|
33
|
+
readonly document: WithSystemFields<
|
|
34
|
+
TableName,
|
|
35
|
+
Schema.Schema.Type<TableSchema_>,
|
|
36
|
+
Scope
|
|
37
|
+
>;
|
|
38
|
+
readonly encodedDocument: WithSystemFields<
|
|
39
|
+
TableName,
|
|
40
|
+
Schema.Codec.Encoded<TableSchema_>,
|
|
41
|
+
Scope
|
|
42
|
+
>;
|
|
43
|
+
readonly convexDocument: ExtractConvexDocument<
|
|
44
|
+
TableName,
|
|
45
|
+
TableValidator,
|
|
46
|
+
Scope
|
|
47
|
+
>;
|
|
48
|
+
readonly fieldPaths:
|
|
49
|
+
| keyof IdField<TableName>
|
|
50
|
+
| ExtractFieldPaths<TableValidator>;
|
|
51
|
+
readonly indexes: Types.Simplify<Indexes & SystemIndexes>;
|
|
52
|
+
readonly searchIndexes: SearchIndexes;
|
|
53
|
+
readonly vectorIndexes: VectorIndexes;
|
|
54
|
+
}
|
|
55
|
+
: never;
|
|
56
|
+
|
|
57
|
+
export interface Any {
|
|
58
|
+
readonly [TypeId]: TypeId;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
export interface AnyWithProps extends Any {
|
|
62
|
+
readonly document: Document_.Any;
|
|
63
|
+
readonly encodedDocument: Document_.AnyEncoded;
|
|
64
|
+
readonly convexDocument: GenericDocument;
|
|
65
|
+
readonly fieldPaths: GenericFieldPaths;
|
|
66
|
+
readonly indexes: GenericTableIndexes;
|
|
67
|
+
readonly searchIndexes: GenericTableSearchIndexes;
|
|
68
|
+
readonly vectorIndexes: GenericTableVectorIndexes;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
export type ConvexTableInfo<TableInfo_ extends AnyWithProps> = {
|
|
72
|
+
document: TableInfo_["convexDocument"];
|
|
73
|
+
fieldPaths: TableInfo_["fieldPaths"];
|
|
74
|
+
indexes: TableInfo_["indexes"];
|
|
75
|
+
searchIndexes: TableInfo_["searchIndexes"];
|
|
76
|
+
vectorIndexes: TableInfo_["vectorIndexes"];
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
export type TableSchema<TableInfo_ extends AnyWithProps> = Schema.Codec<
|
|
80
|
+
TableInfo_["document"],
|
|
81
|
+
TableInfo_["encodedDocument"]
|
|
82
|
+
>;
|
|
83
|
+
|
|
84
|
+
export type Document<TableInfo_ extends AnyWithProps> = TableInfo_["document"];
|
|
85
|
+
|
|
86
|
+
// Vendored types from convex-js, partially modified.
|
|
87
|
+
// See https://github.com/get-convex/convex-js/pull/14
|
|
88
|
+
|
|
89
|
+
type ExtractFieldPaths<TableValidator extends GenericValidator> =
|
|
90
|
+
| TableValidator["fieldPaths"]
|
|
91
|
+
| keyof SystemFields;
|
|
92
|
+
|
|
93
|
+
type ExtractConvexDocument<
|
|
94
|
+
TableName extends string,
|
|
95
|
+
TableValidator extends GenericValidator,
|
|
96
|
+
Scope extends IdScope.IdScope = IdScope.App,
|
|
97
|
+
> =
|
|
98
|
+
WithSystemFields<
|
|
99
|
+
TableName,
|
|
100
|
+
TableValidator["type"],
|
|
101
|
+
Scope
|
|
102
|
+
> extends GenericDocument
|
|
103
|
+
? WithSystemFields<TableName, TableValidator["type"], Scope>
|
|
104
|
+
: never;
|
|
105
|
+
|
|
106
|
+
// End of vendored types from convex-js, partially modified.
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { QueryMeta } from "convex/server";
|
|
2
|
+
import * as Context from "effect/Context";
|
|
3
|
+
import * as Effect from "effect/Effect";
|
|
4
|
+
import * as Layer from "effect/Layer";
|
|
5
|
+
|
|
6
|
+
export type { TransactionMetric, TransactionMetrics } from "convex/server";
|
|
7
|
+
|
|
8
|
+
const make = (meta: Pick<QueryMeta, "getTransactionMetrics">) => ({
|
|
9
|
+
getMetrics: Effect.fn("TransactionMetadata.getMetrics")(() =>
|
|
10
|
+
Effect.promise(() => meta.getTransactionMetrics()),
|
|
11
|
+
),
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
export class TransactionMetadata extends Context.Service<
|
|
15
|
+
TransactionMetadata,
|
|
16
|
+
ReturnType<typeof make>
|
|
17
|
+
>()("@confect/server/TransactionMetadata") {}
|
|
18
|
+
|
|
19
|
+
export const layer = (meta: Pick<QueryMeta, "getTransactionMetrics">) =>
|
|
20
|
+
Layer.succeed(TransactionMetadata, make(meta));
|