@gaganref/confect-server 10.3.1-fork.4 → 10.3.1-fork.41
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/dist/ActionCall.d.ts +30 -0
- package/dist/ActionCall.d.ts.map +1 -0
- package/dist/ActionCall.js +41 -0
- package/dist/ActionCall.js.map +1 -0
- package/dist/ActionCtx.d.ts +1 -1
- package/dist/ActionCtx.d.ts.map +1 -1
- package/dist/ActionCtx.js.map +1 -1
- package/dist/ActionRunner.js +2 -2
- package/dist/AiGatewayDecisionClient.d.ts +2 -2
- package/dist/AiGatewayDecisionClient.d.ts.map +1 -1
- package/dist/AiGatewayDecisionClient.js +1 -1
- package/dist/AiGatewayDecisionClient.js.map +1 -1
- package/dist/AiGatewayLanguageClient.d.ts +2 -2
- package/dist/AiGatewayLanguageClient.d.ts.map +1 -1
- package/dist/AiGatewayLanguageClient.js +1 -1
- package/dist/AiGatewayLanguageClient.js.map +1 -1
- package/dist/Auth.d.ts +14 -2
- package/dist/Auth.d.ts.map +1 -1
- package/dist/Auth.js +13 -3
- package/dist/Auth.js.map +1 -1
- package/dist/Callback.js +3 -3
- package/dist/ComponentCtx.d.ts +1 -1
- package/dist/ComponentCtx.d.ts.map +1 -1
- package/dist/ConvexConfigProvider.js +2 -2
- package/dist/ConvexFunctionDefinitions.d.ts +4 -4
- package/dist/ConvexFunctionDefinitions.d.ts.map +1 -1
- package/dist/ConvexFunctionDefinitions.js +4 -4
- package/dist/ConvexFunctionDefinitions.js.map +1 -1
- package/dist/ConvexLogger.js +1 -1
- package/dist/CronJobs.d.ts +1 -1
- package/dist/CronJobs.d.ts.map +1 -1
- package/dist/CronJobs.js +6 -6
- package/dist/CronJobs.js.map +1 -1
- package/dist/DataModel.d.ts +3 -3
- package/dist/DataModel.d.ts.map +1 -1
- package/dist/DataModel.js.map +1 -1
- package/dist/DatabaseReader.d.ts +4 -4
- package/dist/DatabaseReader.d.ts.map +1 -1
- package/dist/DatabaseReader.js.map +1 -1
- package/dist/DatabaseSchema.d.ts +1 -1
- package/dist/DatabaseSchema.d.ts.map +1 -1
- package/dist/DatabaseSchema.js +2 -2
- package/dist/DatabaseSchema.js.map +1 -1
- package/dist/DatabaseWriter.d.ts +41 -7
- package/dist/DatabaseWriter.d.ts.map +1 -1
- package/dist/DatabaseWriter.js +55 -8
- package/dist/DatabaseWriter.js.map +1 -1
- package/dist/Document.d.ts +4 -4
- package/dist/Document.d.ts.map +1 -1
- package/dist/Document.js.map +1 -1
- package/dist/ExecutionMetadata.js +1 -1
- package/dist/FunctionImpl.d.ts +2 -2
- package/dist/FunctionImpl.d.ts.map +1 -1
- package/dist/FunctionImpl.js +2 -2
- package/dist/FunctionImpl.js.map +1 -1
- package/dist/FunctionRegistryItem.d.ts +1 -1
- package/dist/FunctionRegistryItem.d.ts.map +1 -1
- package/dist/FunctionRegistryItem.js +1 -1
- package/dist/FunctionRegistryItem.js.map +1 -1
- package/dist/GroupImpl.d.ts +24 -5
- package/dist/GroupImpl.d.ts.map +1 -1
- package/dist/GroupImpl.js +21 -22
- package/dist/GroupImpl.js.map +1 -1
- package/dist/GroupRegistry.d.ts +3 -2
- package/dist/GroupRegistry.d.ts.map +1 -1
- package/dist/GroupRegistry.js +10 -3
- package/dist/GroupRegistry.js.map +1 -1
- package/dist/Handler.d.ts +31 -27
- package/dist/Handler.d.ts.map +1 -1
- package/dist/Handler.js.map +1 -1
- package/dist/HttpRouter.d.ts +15 -13
- package/dist/HttpRouter.d.ts.map +1 -1
- package/dist/HttpRouter.js +16 -7
- package/dist/HttpRouter.js.map +1 -1
- package/dist/MiddlewareImpl.d.ts +14 -14
- package/dist/MiddlewareImpl.d.ts.map +1 -1
- package/dist/MiddlewareImpl.js +1 -1
- package/dist/MiddlewareImpl.js.map +1 -1
- package/dist/MutationCtx.d.ts +1 -1
- package/dist/MutationCtx.d.ts.map +1 -1
- package/dist/MutationCtx.js.map +1 -1
- package/dist/MutationRunner.d.ts +1 -1
- package/dist/MutationRunner.d.ts.map +1 -1
- package/dist/MutationRunner.js +2 -2
- package/dist/MutationRunner.js.map +1 -1
- package/dist/MutationTransactionContext.d.ts +2 -2
- package/dist/MutationTransactionContext.d.ts.map +1 -1
- package/dist/MutationTransactionContext.js +2 -2
- package/dist/MutationTransactionContext.js.map +1 -1
- package/dist/OfficialComponent.d.ts +50 -0
- package/dist/OfficialComponent.d.ts.map +1 -0
- package/dist/OfficialComponent.js +70 -0
- package/dist/OfficialComponent.js.map +1 -0
- package/dist/OrderedQuery.d.ts +4 -4
- package/dist/OrderedQuery.d.ts.map +1 -1
- package/dist/OrderedQuery.js.map +1 -1
- package/dist/QueryCtx.d.ts +1 -1
- package/dist/QueryCtx.d.ts.map +1 -1
- package/dist/QueryCtx.js.map +1 -1
- package/dist/QueryInitializer.d.ts +10 -10
- package/dist/QueryInitializer.d.ts.map +1 -1
- package/dist/QueryInitializer.js +2 -2
- package/dist/QueryInitializer.js.map +1 -1
- package/dist/QueryRunner.d.ts +2 -2
- package/dist/QueryRunner.d.ts.map +1 -1
- package/dist/QueryRunner.js +2 -2
- package/dist/QueryRunner.js.map +1 -1
- package/dist/QueryStream.d.ts +131 -23
- package/dist/QueryStream.d.ts.map +1 -1
- package/dist/QueryStream.js +142 -40
- package/dist/QueryStream.js.map +1 -1
- package/dist/QueryStreamCursor.d.ts +2 -2
- package/dist/QueryStreamCursor.d.ts.map +1 -1
- package/dist/QueryStreamCursor.js +1 -1
- package/dist/QueryStreamCursor.js.map +1 -1
- package/dist/QueryStreamIndexPrefix.d.ts +2 -2
- package/dist/QueryStreamIndexPrefix.d.ts.map +1 -1
- package/dist/QueryStreamIndexPrefix.js +1 -1
- package/dist/QueryStreamIndexPrefix.js.map +1 -1
- package/dist/QueryStreamIndexRange.d.ts +4 -4
- package/dist/QueryStreamIndexRange.d.ts.map +1 -1
- package/dist/QueryStreamIndexRange.js +2 -2
- package/dist/QueryStreamIndexRange.js.map +1 -1
- package/dist/QueryStreamKey.d.ts +2 -2
- package/dist/QueryStreamKey.d.ts.map +1 -1
- package/dist/QueryStreamKey.js +1 -1
- package/dist/QueryStreamKey.js.map +1 -1
- package/dist/QueryStreamKeyBounds.d.ts +3 -3
- package/dist/QueryStreamKeyBounds.d.ts.map +1 -1
- package/dist/QueryStreamKeyBounds.js +2 -2
- package/dist/QueryStreamKeyBounds.js.map +1 -1
- package/dist/QueryStreamKeyLayout.d.ts +1 -1
- package/dist/QueryStreamKeyLayout.d.ts.map +1 -1
- package/dist/QueryStreamKeyLayout.js +2 -2
- package/dist/QueryStreamKeyLayout.js.map +1 -1
- package/dist/QueryStreamKeyValues.d.ts +1 -1
- package/dist/QueryStreamKeyValues.d.ts.map +1 -1
- package/dist/QueryStreamKeyValues.js +1 -1
- package/dist/QueryStreamKeyValues.js.map +1 -1
- package/dist/QueryStreamPagination.d.ts +1 -1
- package/dist/QueryStreamPagination.d.ts.map +1 -1
- package/dist/QueryStreamPagination.js +1 -1
- package/dist/QueryStreamPagination.js.map +1 -1
- package/dist/QueryStreamReadBudget.d.ts +3 -2
- package/dist/QueryStreamReadBudget.d.ts.map +1 -1
- package/dist/QueryStreamReadBudget.js +7 -4
- package/dist/QueryStreamReadBudget.js.map +1 -1
- package/dist/QueryTransactionContext.js +2 -2
- package/dist/RegisteredConvexFunction.d.ts +27 -24
- package/dist/RegisteredConvexFunction.d.ts.map +1 -1
- package/dist/RegisteredConvexFunction.js +39 -26
- package/dist/RegisteredConvexFunction.js.map +1 -1
- package/dist/RegisteredFunction.d.ts +51 -47
- package/dist/RegisteredFunction.d.ts.map +1 -1
- package/dist/RegisteredFunction.js +126 -37
- package/dist/RegisteredFunction.js.map +1 -1
- package/dist/RegisteredFunctions.d.ts +3 -3
- package/dist/RegisteredFunctions.d.ts.map +1 -1
- package/dist/RegisteredFunctions.js.map +1 -1
- package/dist/RegisteredNodeFunction.d.ts +7 -7
- package/dist/RegisteredNodeFunction.d.ts.map +1 -1
- package/dist/RegisteredNodeFunction.js +8 -6
- package/dist/RegisteredNodeFunction.js.map +1 -1
- package/dist/Registry.d.ts +1 -1
- package/dist/Registry.d.ts.map +1 -1
- package/dist/Registry.js.map +1 -1
- package/dist/RegistryItems.d.ts +7 -0
- package/dist/RegistryItems.d.ts.map +1 -1
- package/dist/RegistryItems.js +8 -3
- package/dist/RegistryItems.js.map +1 -1
- package/dist/RequestMetadata.js +1 -1
- package/dist/ResolvedMiddleware.d.ts +2 -2
- package/dist/ResolvedMiddleware.d.ts.map +1 -1
- package/dist/ResolvedMiddleware.js.map +1 -1
- package/dist/Scheduler.js +2 -2
- package/dist/Storage.d.ts +6 -6
- package/dist/Storage.d.ts.map +1 -1
- package/dist/Storage.js +1 -1
- package/dist/Storage.js.map +1 -1
- package/dist/StorageActionWriter.d.ts +1 -1
- package/dist/StorageActionWriter.d.ts.map +1 -1
- package/dist/StorageActionWriter.js +1 -1
- package/dist/StorageActionWriter.js.map +1 -1
- package/dist/StorageReader.d.ts +1 -1
- package/dist/StorageReader.d.ts.map +1 -1
- package/dist/StorageReader.js +1 -1
- package/dist/StorageReader.js.map +1 -1
- package/dist/StorageWriter.d.ts +1 -1
- package/dist/StorageWriter.d.ts.map +1 -1
- package/dist/StorageWriter.js +1 -1
- package/dist/StorageWriter.js.map +1 -1
- package/dist/TableInfo.d.ts +2 -2
- package/dist/TableInfo.d.ts.map +1 -1
- package/dist/TableInfo.js.map +1 -1
- package/dist/TransactionMetadata.js +1 -1
- package/dist/VectorSearch.d.ts +1 -1
- package/dist/VectorSearch.d.ts.map +1 -1
- package/dist/VectorSearch.js +1 -1
- package/dist/VectorSearch.js.map +1 -1
- package/dist/index.d.ts +62 -60
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +20 -18
- package/dist/internal/AiGatewayDecisionClient.d.ts +1 -1
- package/dist/internal/AiGatewayDecisionClient.d.ts.map +1 -1
- package/dist/internal/AiGatewayDecisionClient.js +1 -1
- package/dist/internal/AiGatewayDecisionClient.js.map +1 -1
- package/dist/internal/AiGatewayLanguageClient.d.ts +1 -1
- package/dist/internal/AiGatewayLanguageClient.d.ts.map +1 -1
- package/dist/internal/AiGatewayLanguageClient.js +1 -1
- package/dist/internal/AiGatewayLanguageClient.js.map +1 -1
- package/dist/internal/AiGatewayServiceToken.js +1 -1
- package/dist/internal/DocumentPatch.d.ts +16 -0
- package/dist/internal/DocumentPatch.d.ts.map +1 -0
- package/dist/internal/DocumentPatch.js +36 -0
- package/dist/internal/DocumentPatch.js.map +1 -0
- package/dist/internal/observability.d.ts +5 -0
- package/dist/internal/observability.d.ts.map +1 -0
- package/dist/internal/observability.js +21 -0
- package/dist/internal/observability.js.map +1 -0
- package/dist/node.d.ts +1 -1
- package/dist/node.d.ts.map +1 -1
- package/package.json +5 -5
- package/src/ActionCall.ts +82 -0
- package/src/ActionCtx.ts +1 -1
- package/src/AiGatewayDecisionClient.ts +3 -3
- package/src/AiGatewayLanguageClient.ts +3 -3
- package/src/Auth.ts +24 -2
- package/src/ComponentCtx.ts +1 -1
- package/src/ConvexFunctionDefinitions.ts +10 -9
- package/src/CronJobs.ts +1 -1
- package/src/DataModel.ts +3 -3
- package/src/DatabaseReader.ts +4 -4
- package/src/DatabaseSchema.ts +1 -1
- package/src/DatabaseWriter.ts +189 -31
- package/src/Document.ts +4 -4
- package/src/FunctionImpl.ts +5 -5
- package/src/FunctionRegistryItem.ts +1 -1
- package/src/GroupImpl.ts +66 -13
- package/src/GroupRegistry.ts +11 -7
- package/src/Handler.ts +44 -28
- package/src/HttpRouter.ts +71 -21
- package/src/MiddlewareImpl.ts +17 -17
- package/src/MutationCtx.ts +1 -1
- package/src/MutationRunner.ts +1 -1
- package/src/MutationTransactionContext.ts +2 -2
- package/src/OfficialComponent.ts +151 -0
- package/src/OrderedQuery.ts +4 -4
- package/src/QueryCtx.ts +1 -1
- package/src/QueryInitializer.ts +9 -9
- package/src/QueryRunner.ts +2 -2
- package/src/QueryStream.ts +406 -76
- package/src/QueryStreamCursor.ts +3 -3
- package/src/QueryStreamIndexPrefix.ts +2 -2
- package/src/QueryStreamIndexRange.ts +4 -4
- package/src/QueryStreamKey.ts +2 -2
- package/src/QueryStreamKeyBounds.ts +3 -3
- package/src/QueryStreamKeyLayout.ts +1 -1
- package/src/QueryStreamKeyValues.ts +1 -1
- package/src/QueryStreamPagination.ts +2 -2
- package/src/QueryStreamReadBudget.ts +19 -6
- package/src/RegisteredConvexFunction.ts +38 -21
- package/src/RegisteredFunction.ts +209 -60
- package/src/RegisteredFunctions.ts +4 -4
- package/src/RegisteredNodeFunction.ts +15 -9
- package/src/Registry.ts +1 -1
- package/src/RegistryItems.ts +33 -2
- package/src/ResolvedMiddleware.ts +2 -2
- package/src/Storage.ts +3 -3
- package/src/StorageActionWriter.ts +1 -1
- package/src/StorageReader.ts +1 -1
- package/src/StorageWriter.ts +1 -1
- package/src/TableInfo.ts +2 -2
- package/src/VectorSearch.ts +1 -1
- package/src/index.ts +62 -60
- package/src/internal/AiGatewayDecisionClient.ts +2 -2
- package/src/internal/AiGatewayLanguageClient.ts +2 -2
- package/src/internal/DocumentPatch.ts +87 -0
- package/src/internal/observability.ts +27 -0
- package/src/node.ts +1 -1
package/src/GroupImpl.ts
CHANGED
|
@@ -1,17 +1,18 @@
|
|
|
1
1
|
import type * as GroupSpec from "@confect/core/GroupSpec";
|
|
2
2
|
import type * as MiddlewareSpec from "@confect/core/MiddlewareSpec";
|
|
3
|
-
import * as Registry from "./Registry";
|
|
4
|
-
import * as RegistryItems from "./RegistryItems";
|
|
3
|
+
import * as Registry from "./Registry.js";
|
|
4
|
+
import * as RegistryItems from "./RegistryItems.js";
|
|
5
5
|
import * as Array from "effect/Array";
|
|
6
6
|
import * as Context from "effect/Context";
|
|
7
7
|
import * as Effect from "effect/Effect";
|
|
8
|
+
import * as Data from "effect/Data";
|
|
8
9
|
import * as Layer from "effect/Layer";
|
|
9
10
|
import * as Option from "effect/Option";
|
|
10
11
|
import * as Predicate from "effect/Predicate";
|
|
11
12
|
import * as Ref from "effect/Ref";
|
|
12
|
-
import type * as DatabaseSchema from "./DatabaseSchema";
|
|
13
|
-
import type * as FunctionImpl from "./FunctionImpl";
|
|
14
|
-
import type * as MiddlewareImpl from "./MiddlewareImpl";
|
|
13
|
+
import type * as DatabaseSchema from "./DatabaseSchema.js";
|
|
14
|
+
import type * as FunctionImpl from "./FunctionImpl.js";
|
|
15
|
+
import type * as MiddlewareImpl from "./MiddlewareImpl.js";
|
|
15
16
|
|
|
16
17
|
export const TypeId = "~@confect/server/GroupImpl";
|
|
17
18
|
export type TypeId = typeof TypeId;
|
|
@@ -111,10 +112,20 @@ export const make = <
|
|
|
111
112
|
FunctionImpl.FromGroupSpec<Group> | MiddlewareImpl.FromGroupSpec<Group>
|
|
112
113
|
>;
|
|
113
114
|
|
|
114
|
-
const
|
|
115
|
-
context
|
|
116
|
-
|
|
117
|
-
|
|
115
|
+
const findGroupImpl = <S>(context: Context.Context<S>): Option.Option<Any> =>
|
|
116
|
+
Array.findFirst(context.mapUnsafe.values(), isGroupImpl);
|
|
117
|
+
|
|
118
|
+
export class MissingRequiredMiddlewareError extends Data.TaggedError(
|
|
119
|
+
"MissingRequiredMiddlewareError",
|
|
120
|
+
)<{
|
|
121
|
+
readonly missing: ReadonlyArray<RegistryItems.MissingMiddleware>;
|
|
122
|
+
}> {
|
|
123
|
+
override get message(): string {
|
|
124
|
+
return `GroupImpl.finalize: ${this.missing.map(({ functionName, middlewareKey }) => `${functionName} requires middleware "${middlewareKey}"`).join("\n")}`;
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
type Finalizable = Layer.Layer<AnyUnfinalized> | Layer.Layer<AnyFinalized>;
|
|
118
129
|
|
|
119
130
|
/**
|
|
120
131
|
* Mark a `GroupImpl` layer as fully implemented. The parameter type defaults
|
|
@@ -127,20 +138,52 @@ const findUnfinalizedGroupImpl = <S>(
|
|
|
127
138
|
* registered into this group's scope are snapshotted onto the produced service
|
|
128
139
|
* value's `registeredFunctionNames` field, so consumers can verify impl
|
|
129
140
|
* completeness against a `GroupSpec`'s expected functions without having to
|
|
130
|
-
* inspect the `Registry` themselves.
|
|
141
|
+
* inspect the `Registry` themselves. Pass `{ required }` to check every
|
|
142
|
+
* registered function's middleware at layer build, including internal
|
|
143
|
+
* functions. This form also accepts a finalized layer so generated registration
|
|
144
|
+
* can enforce the backend declaration without changing authored impls. Pass
|
|
145
|
+
* `groupPath` to qualify uncovered function names in the diagnostic.
|
|
131
146
|
*/
|
|
132
|
-
export
|
|
147
|
+
export function finalize(options: {
|
|
148
|
+
readonly groupPath?: string;
|
|
149
|
+
readonly required: ReadonlyArray<
|
|
150
|
+
Pick<MiddlewareSpec.AnyMiddlewareSpec, "key">
|
|
151
|
+
>;
|
|
152
|
+
}): (group: Finalizable) => Layer.Layer<GroupImpl<"Finalized">>;
|
|
153
|
+
export function finalize(
|
|
133
154
|
group: Layer.Layer<GroupImpl<"Unfinalized">>,
|
|
155
|
+
): Layer.Layer<GroupImpl<"Finalized">>;
|
|
156
|
+
export function finalize(
|
|
157
|
+
input:
|
|
158
|
+
| Finalizable
|
|
159
|
+
| {
|
|
160
|
+
readonly groupPath?: string;
|
|
161
|
+
readonly required: ReadonlyArray<
|
|
162
|
+
Pick<MiddlewareSpec.AnyMiddlewareSpec, "key">
|
|
163
|
+
>;
|
|
164
|
+
},
|
|
165
|
+
):
|
|
166
|
+
| Layer.Layer<GroupImpl<"Finalized">>
|
|
167
|
+
| ((group: Finalizable) => Layer.Layer<GroupImpl<"Finalized">>) {
|
|
168
|
+
return "required" in input
|
|
169
|
+
? (group) => finalizeWith(group, input.required, input.groupPath)
|
|
170
|
+
: finalizeWith(input, []);
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
const finalizeWith = (
|
|
174
|
+
group: Layer.Layer<never>,
|
|
175
|
+
required: ReadonlyArray<Pick<MiddlewareSpec.AnyMiddlewareSpec, "key">>,
|
|
176
|
+
groupPath = "",
|
|
134
177
|
): Layer.Layer<GroupImpl<"Finalized">> =>
|
|
135
178
|
Layer.flatMap(group, (context): Layer.Layer<GroupImpl<"Finalized">> =>
|
|
136
|
-
|
|
179
|
+
findGroupImpl(context).pipe(
|
|
137
180
|
Option.match({
|
|
138
181
|
onNone: () =>
|
|
139
182
|
Layer.effect(
|
|
140
183
|
GroupImpl<"Finalized">({ finalizationStatus: "Finalized" }),
|
|
141
184
|
Effect.die(
|
|
142
185
|
new Error(
|
|
143
|
-
"GroupImpl.finalize: no
|
|
186
|
+
"GroupImpl.finalize: no GroupImpl service was found in the layer's context.",
|
|
144
187
|
),
|
|
145
188
|
),
|
|
146
189
|
),
|
|
@@ -150,6 +193,16 @@ export const finalize = (
|
|
|
150
193
|
Effect.gen(function* () {
|
|
151
194
|
const registry = yield* Registry.Registry;
|
|
152
195
|
const items = yield* Ref.get(registry);
|
|
196
|
+
const missing = RegistryItems.missingRequired(
|
|
197
|
+
items,
|
|
198
|
+
required,
|
|
199
|
+
groupPath,
|
|
200
|
+
);
|
|
201
|
+
if (missing.length > 0) {
|
|
202
|
+
return yield* Effect.die(
|
|
203
|
+
new MissingRequiredMiddlewareError({ missing }),
|
|
204
|
+
);
|
|
205
|
+
}
|
|
153
206
|
return {
|
|
154
207
|
[TypeId]: TypeId,
|
|
155
208
|
finalizationStatus: "Finalized" as const,
|
package/src/GroupRegistry.ts
CHANGED
|
@@ -1,17 +1,21 @@
|
|
|
1
|
+
import * as RegisteredFunction from "./RegisteredFunction.js";
|
|
1
2
|
import * as Effect from "effect/Effect";
|
|
2
3
|
import type * as Layer from "effect/Layer";
|
|
3
4
|
import * as Ref from "effect/Ref";
|
|
4
|
-
import * as Registry from "./Registry";
|
|
5
|
-
import type * as RegistryItems from "./RegistryItems";
|
|
6
|
-
import type * as GroupImpl from "./GroupImpl";
|
|
7
|
-
import * as MiddlewareRegistryItem from "./MiddlewareRegistryItem";
|
|
5
|
+
import * as Registry from "./Registry.js";
|
|
6
|
+
import type * as RegistryItems from "./RegistryItems.js";
|
|
7
|
+
import type * as GroupImpl from "./GroupImpl.js";
|
|
8
|
+
import * as MiddlewareRegistryItem from "./MiddlewareRegistryItem.js";
|
|
8
9
|
|
|
9
10
|
export const make = (
|
|
10
11
|
groupLayer: Layer.Layer<GroupImpl.GroupImpl<"Finalized">>,
|
|
11
12
|
) => {
|
|
12
|
-
const registryItems = Effect.gen(function* () {
|
|
13
|
+
const { registryItems, observability } = Effect.gen(function* () {
|
|
13
14
|
const registry = yield* Registry.Registry;
|
|
14
|
-
return
|
|
15
|
+
return {
|
|
16
|
+
registryItems: yield* Ref.get(registry),
|
|
17
|
+
observability: yield* RegisteredFunction.Observability,
|
|
18
|
+
};
|
|
15
19
|
}).pipe(
|
|
16
20
|
Effect.provide(groupLayer),
|
|
17
21
|
Effect.provideService(
|
|
@@ -21,7 +25,7 @@ export const make = (
|
|
|
21
25
|
Effect.runSync,
|
|
22
26
|
);
|
|
23
27
|
|
|
24
|
-
return partitionRegistryItems(registryItems);
|
|
28
|
+
return { ...partitionRegistryItems(registryItems), observability };
|
|
25
29
|
};
|
|
26
30
|
|
|
27
31
|
const partitionRegistryItems = (registryItems: RegistryItems.RegistryItems) => {
|
package/src/Handler.ts
CHANGED
|
@@ -1,30 +1,31 @@
|
|
|
1
|
+
import type { ActionCall } from "@confect/core/ActionCall";
|
|
1
2
|
import type { FunctionSpec, RuntimeAndFunctionType } from "@confect/core";
|
|
2
3
|
import type * as FunctionProvenance from "@confect/core/FunctionProvenance";
|
|
3
4
|
import type * as NodeServices from "@effect/platform-node/NodeServices";
|
|
4
5
|
import type { Effect } from "effect";
|
|
5
|
-
import type * as ActionCtx from "./ActionCtx";
|
|
6
|
-
import type * as ActionRunner from "./ActionRunner";
|
|
7
|
-
import type * as Auth from "./Auth";
|
|
8
|
-
import type * as DatabaseReader from "./DatabaseReader";
|
|
9
|
-
import type * as DatabaseSchema from "./DatabaseSchema";
|
|
10
|
-
import type * as DatabaseWriter from "./DatabaseWriter";
|
|
11
|
-
import type * as DataModel from "./DataModel";
|
|
12
|
-
import type { ExecutionMetadata } from "./ExecutionMetadata";
|
|
13
|
-
import type { RequestMetadata } from "./RequestMetadata";
|
|
14
|
-
import type { TransactionMetadata } from "./TransactionMetadata";
|
|
15
|
-
import type * as MutationCtx from "./MutationCtx";
|
|
16
|
-
import type * as MutationRunner from "./MutationRunner";
|
|
17
|
-
import type { MutationTransactionContext } from "./MutationTransactionContext";
|
|
18
|
-
import type * as QueryCtx from "./QueryCtx";
|
|
19
|
-
import type * as QueryRunner from "./QueryRunner";
|
|
20
|
-
import type { QueryTransactionContext } from "./QueryTransactionContext";
|
|
21
|
-
import type * as RegisteredFunction from "./RegisteredFunction";
|
|
22
|
-
import type * as Scheduler from "./Scheduler";
|
|
23
|
-
import type { Storage } from "./Storage";
|
|
24
|
-
import type * as StorageActionWriter from "./StorageActionWriter";
|
|
25
|
-
import type * as StorageReader from "./StorageReader";
|
|
26
|
-
import type * as StorageWriter from "./StorageWriter";
|
|
27
|
-
import type * as VectorSearch from "./VectorSearch";
|
|
6
|
+
import type * as ActionCtx from "./ActionCtx.js";
|
|
7
|
+
import type * as ActionRunner from "./ActionRunner.js";
|
|
8
|
+
import type * as Auth from "./Auth.js";
|
|
9
|
+
import type * as DatabaseReader from "./DatabaseReader.js";
|
|
10
|
+
import type * as DatabaseSchema from "./DatabaseSchema.js";
|
|
11
|
+
import type * as DatabaseWriter from "./DatabaseWriter.js";
|
|
12
|
+
import type * as DataModel from "./DataModel.js";
|
|
13
|
+
import type { ExecutionMetadata } from "./ExecutionMetadata.js";
|
|
14
|
+
import type { RequestMetadata } from "./RequestMetadata.js";
|
|
15
|
+
import type { TransactionMetadata } from "./TransactionMetadata.js";
|
|
16
|
+
import type * as MutationCtx from "./MutationCtx.js";
|
|
17
|
+
import type * as MutationRunner from "./MutationRunner.js";
|
|
18
|
+
import type { MutationTransactionContext } from "./MutationTransactionContext.js";
|
|
19
|
+
import type * as QueryCtx from "./QueryCtx.js";
|
|
20
|
+
import type * as QueryRunner from "./QueryRunner.js";
|
|
21
|
+
import type { QueryTransactionContext } from "./QueryTransactionContext.js";
|
|
22
|
+
import type * as RegisteredFunction from "./RegisteredFunction.js";
|
|
23
|
+
import type * as Scheduler from "./Scheduler.js";
|
|
24
|
+
import type { Storage } from "./Storage.js";
|
|
25
|
+
import type * as StorageActionWriter from "./StorageActionWriter.js";
|
|
26
|
+
import type * as StorageReader from "./StorageReader.js";
|
|
27
|
+
import type * as StorageWriter from "./StorageWriter.js";
|
|
28
|
+
import type * as VectorSearch from "./VectorSearch.js";
|
|
28
29
|
|
|
29
30
|
export type Handler<
|
|
30
31
|
DatabaseSchema_ extends DatabaseSchema.AnyWithProps,
|
|
@@ -94,6 +95,7 @@ export type MutationServices<
|
|
|
94
95
|
> =
|
|
95
96
|
| DatabaseReader.DatabaseReader<DatabaseSchema_>
|
|
96
97
|
| DatabaseWriter.DatabaseWriter<DatabaseSchema_>
|
|
98
|
+
| Auth.MutationAuth
|
|
97
99
|
| (DatabaseSchema_["target"]["kind"] extends "component" ? never : Auth.Auth)
|
|
98
100
|
| Scheduler.ForScope<DatabaseSchema.Scope<DatabaseSchema_>>
|
|
99
101
|
| StorageReader.ForScope<DatabaseSchema.Scope<DatabaseSchema_>>
|
|
@@ -114,9 +116,7 @@ export type MutationServices<
|
|
|
114
116
|
/**
|
|
115
117
|
* Shared by both action runtimes.
|
|
116
118
|
*/
|
|
117
|
-
|
|
118
|
-
DatabaseSchema_ extends DatabaseSchema.AnyWithProps,
|
|
119
|
-
> =
|
|
119
|
+
type RawActionServices<DatabaseSchema_ extends DatabaseSchema.AnyWithProps> =
|
|
120
120
|
| Scheduler.ForScope<DatabaseSchema.Scope<DatabaseSchema_>>
|
|
121
121
|
| (DatabaseSchema_["target"]["kind"] extends "component" ? never : Auth.Auth)
|
|
122
122
|
| StorageReader.ForScope<DatabaseSchema.Scope<DatabaseSchema_>>
|
|
@@ -134,6 +134,22 @@ export type ActionServices<
|
|
|
134
134
|
DatabaseSchema.Scope<DatabaseSchema_>
|
|
135
135
|
>;
|
|
136
136
|
|
|
137
|
+
export type ActionServices<S extends DatabaseSchema.AnyWithProps, R = never> = [
|
|
138
|
+
Extract<R, ActionCall>,
|
|
139
|
+
] extends [never]
|
|
140
|
+
? RawActionServices<S>
|
|
141
|
+
: Exclude<
|
|
142
|
+
RawActionServices<S>,
|
|
143
|
+
| Scheduler.ForScope<DatabaseSchema.Scope<S>>
|
|
144
|
+
| QueryRunner.QueryRunner
|
|
145
|
+
| MutationRunner.MutationRunner
|
|
146
|
+
| ActionRunner.ActionRunner
|
|
147
|
+
| ActionCtx.ActionCtx<
|
|
148
|
+
DataModel.ToConvex<DataModel.FromSchema<S>>,
|
|
149
|
+
DatabaseSchema.Scope<S>
|
|
150
|
+
>
|
|
151
|
+
>;
|
|
152
|
+
|
|
137
153
|
export type ConfectProvenanceQuery<
|
|
138
154
|
DatabaseSchema_ extends DatabaseSchema.AnyWithProps,
|
|
139
155
|
FunctionSpec_ extends
|
|
@@ -153,7 +169,7 @@ export type ConvexRuntimeAction<
|
|
|
153
169
|
FunctionSpec_ extends
|
|
154
170
|
FunctionSpec.AnyWithPropsWithFunctionType<RuntimeAndFunctionType.AnyAction>,
|
|
155
171
|
R = never,
|
|
156
|
-
> = Base<FunctionSpec_, ActionServices<DatabaseSchema_> | R>;
|
|
172
|
+
> = Base<FunctionSpec_, ActionServices<DatabaseSchema_, R> | R>;
|
|
157
173
|
|
|
158
174
|
export type NodeRuntimeAction<
|
|
159
175
|
DatabaseSchema_ extends DatabaseSchema.AnyWithProps,
|
|
@@ -162,7 +178,7 @@ export type NodeRuntimeAction<
|
|
|
162
178
|
R = never,
|
|
163
179
|
> = Base<
|
|
164
180
|
FunctionSpec_,
|
|
165
|
-
ActionServices<DatabaseSchema_> | NodeServices.NodeServices | R
|
|
181
|
+
ActionServices<DatabaseSchema_, R> | NodeServices.NodeServices | R
|
|
166
182
|
>;
|
|
167
183
|
|
|
168
184
|
type Base<FunctionSpec_ extends FunctionSpec.AnyWithProps, R> = (
|
package/src/HttpRouter.ts
CHANGED
|
@@ -24,24 +24,27 @@ import type * as HttpApiGroup from "effect/http-api/HttpApiGroup";
|
|
|
24
24
|
import type * as Etag from "effect/http/Etag";
|
|
25
25
|
import type * as HttpPlatform from "effect/http/HttpPlatform";
|
|
26
26
|
import * as HttpRouter from "effect/http/HttpRouter";
|
|
27
|
+
import * as HttpMiddleware from "effect/http/HttpMiddleware";
|
|
28
|
+
import type * as HttpServerRequest from "effect/http/HttpServerRequest";
|
|
27
29
|
import * as HttpServer from "effect/http/HttpServer";
|
|
28
|
-
import type * as ActionRunner from "./ActionRunner";
|
|
29
|
-
import type * as Auth from "./Auth";
|
|
30
|
-
import type { ExecutionMetadata } from "./ExecutionMetadata";
|
|
31
|
-
import type { RequestMetadata } from "./RequestMetadata";
|
|
32
|
-
import type * as DatabaseSchema from "./DatabaseSchema";
|
|
33
|
-
import type * as DataModel from "./DataModel";
|
|
34
|
-
import type * as Handler from "./Handler";
|
|
35
|
-
import * as ConvexConfigProvider from "./ConvexConfigProvider";
|
|
36
|
-
import * as
|
|
37
|
-
import
|
|
38
|
-
import type * as
|
|
39
|
-
import * as
|
|
40
|
-
import
|
|
41
|
-
import type
|
|
42
|
-
import type {
|
|
43
|
-
import type {
|
|
44
|
-
import type {
|
|
30
|
+
import type * as ActionRunner from "./ActionRunner.js";
|
|
31
|
+
import type * as Auth from "./Auth.js";
|
|
32
|
+
import type { ExecutionMetadata } from "./ExecutionMetadata.js";
|
|
33
|
+
import type { RequestMetadata } from "./RequestMetadata.js";
|
|
34
|
+
import type * as DatabaseSchema from "./DatabaseSchema.js";
|
|
35
|
+
import type * as DataModel from "./DataModel.js";
|
|
36
|
+
import type * as Handler from "./Handler.js";
|
|
37
|
+
import * as ConvexConfigProvider from "./ConvexConfigProvider.js";
|
|
38
|
+
import * as ObservabilityRuntime from "./internal/observability.js";
|
|
39
|
+
import * as ConvexLogger from "./ConvexLogger.js";
|
|
40
|
+
import type * as MutationRunner from "./MutationRunner.js";
|
|
41
|
+
import type * as QueryRunner from "./QueryRunner.js";
|
|
42
|
+
import * as RegisteredFunction from "./RegisteredFunction.js";
|
|
43
|
+
import type * as Scheduler from "./Scheduler.js";
|
|
44
|
+
import type { Storage } from "./Storage.js";
|
|
45
|
+
import type { StorageActionWriter } from "./StorageActionWriter.js";
|
|
46
|
+
import type { StorageReader } from "./StorageReader.js";
|
|
47
|
+
import type { StorageWriter } from "./StorageWriter.js";
|
|
45
48
|
|
|
46
49
|
/**
|
|
47
50
|
* The Confect services available to HTTP route handlers and middleware,
|
|
@@ -116,9 +119,17 @@ export type Routes<Services_ = Services> = Layer.Layer<
|
|
|
116
119
|
*/
|
|
117
120
|
export const make = <Id extends string, Groups extends HttpApiGroup.Constraint>(
|
|
118
121
|
routes: Routes,
|
|
119
|
-
options?: {
|
|
122
|
+
options?: {
|
|
123
|
+
readonly observability?: Layer.Layer<never> | undefined;
|
|
124
|
+
readonly api?: HttpApi.HttpApi<Id, Groups> | undefined;
|
|
125
|
+
},
|
|
120
126
|
): ConvexHttpRouter =>
|
|
121
|
-
makeWithLayer(
|
|
127
|
+
makeWithLayer(
|
|
128
|
+
routes,
|
|
129
|
+
RegisteredFunction.baseActionLayer,
|
|
130
|
+
options?.api,
|
|
131
|
+
options?.observability,
|
|
132
|
+
);
|
|
122
133
|
|
|
123
134
|
/**
|
|
124
135
|
* Derive HTTP capabilities and ID scopes from the generated database schema.
|
|
@@ -131,7 +142,10 @@ export const forSchema =
|
|
|
131
142
|
) =>
|
|
132
143
|
<Id extends string, Groups extends HttpApiGroup.Constraint>(
|
|
133
144
|
routes: Routes<Handler.ActionServices<DatabaseSchema_>>,
|
|
134
|
-
options?: {
|
|
145
|
+
options?: {
|
|
146
|
+
readonly observability?: Layer.Layer<never> | undefined;
|
|
147
|
+
readonly api?: HttpApi.HttpApi<Id, Groups> | undefined;
|
|
148
|
+
},
|
|
135
149
|
): ConvexHttpRouter =>
|
|
136
150
|
makeWithLayer<
|
|
137
151
|
Handler.ActionServices<DatabaseSchema_>,
|
|
@@ -148,6 +162,8 @@ export const forSchema =
|
|
|
148
162
|
),
|
|
149
163
|
(ctx) => RegisteredFunction.actionLayer(schema, ctx),
|
|
150
164
|
options?.api,
|
|
165
|
+
options?.observability,
|
|
166
|
+
schema.target.kind === "component",
|
|
151
167
|
);
|
|
152
168
|
|
|
153
169
|
// Convex uses a component-relative path to select its HTTP action but passes
|
|
@@ -175,15 +191,38 @@ const makeWithLayer = <
|
|
|
175
191
|
routes: Routes<Services_>,
|
|
176
192
|
layer: (ctx: GenericActionCtx<DataModel_>) => Layer.Layer<Services_>,
|
|
177
193
|
api: HttpApi.HttpApi<Id, Groups> | undefined,
|
|
194
|
+
observability?: Layer.Layer<never>,
|
|
195
|
+
siteRelative = false,
|
|
178
196
|
): ConvexHttpRouter => {
|
|
179
197
|
applyMonkeyPatches();
|
|
180
198
|
|
|
199
|
+
const spanName = Layer.effect(
|
|
200
|
+
HttpMiddleware.SpanNameGenerator,
|
|
201
|
+
Effect.gen(function* () {
|
|
202
|
+
const prefix = siteRelative
|
|
203
|
+
? (yield* Config.schema(
|
|
204
|
+
Schema.URLFromString,
|
|
205
|
+
"CONVEX_SITE_URL",
|
|
206
|
+
)).pathname.replace(/\/$/, "")
|
|
207
|
+
: "";
|
|
208
|
+
return (request: HttpServerRequest.HttpServerRequest) =>
|
|
209
|
+
convexHttpRouter.lookup(
|
|
210
|
+
new URL(request.originalUrl).pathname.slice(prefix.length) || "/",
|
|
211
|
+
request.method as (typeof ROUTABLE_HTTP_METHODS)[number],
|
|
212
|
+
)?.[2] ?? "/*";
|
|
213
|
+
}).pipe(Effect.orDie),
|
|
214
|
+
);
|
|
215
|
+
|
|
181
216
|
// Provided (not just merged) so that route layers' own construction—e.g.
|
|
182
217
|
// a `Layer.unwrap` reading `Config`—resolves configuration through the
|
|
183
218
|
// Convex-aware provider; merged so that request fibers—endpoint handlers
|
|
184
219
|
// and middleware—do too.
|
|
185
220
|
const AppLayer = routes.pipe(
|
|
186
|
-
Layer.provideMerge(
|
|
221
|
+
Layer.provideMerge(
|
|
222
|
+
observability === undefined
|
|
223
|
+
? ConvexLogger.layer
|
|
224
|
+
: Layer.merge(ObservabilityRuntime.memoized(observability), spanName),
|
|
225
|
+
),
|
|
187
226
|
Layer.provideMerge(ConvexConfigProvider.layer),
|
|
188
227
|
Layer.provide(HttpServer.layerServices),
|
|
189
228
|
);
|
|
@@ -193,6 +232,17 @@ const makeWithLayer = <
|
|
|
193
232
|
// exposes as a per-request context argument.
|
|
194
233
|
const { handler } = HttpRouter.toWebHandler(AppLayer, {
|
|
195
234
|
disableLogger: true,
|
|
235
|
+
/* oxlint-disable effecttsgo/any-unknown-in-error-context -- Keep Effect's erased HTTP boundary errors intact. */
|
|
236
|
+
...(observability === undefined
|
|
237
|
+
? {}
|
|
238
|
+
: {
|
|
239
|
+
middleware: (effect) =>
|
|
240
|
+
Effect.andThen(
|
|
241
|
+
Effect.annotateCurrentSpan("kind", "httpAction"),
|
|
242
|
+
effect,
|
|
243
|
+
),
|
|
244
|
+
}),
|
|
245
|
+
/* oxlint-enable effecttsgo/any-unknown-in-error-context */
|
|
196
246
|
});
|
|
197
247
|
|
|
198
248
|
const httpAction = httpActionGeneric((ctx, request): Promise<Response> => {
|
package/src/MiddlewareImpl.ts
CHANGED
|
@@ -1,28 +1,28 @@
|
|
|
1
1
|
import type * as FunctionSpec from "@confect/core/FunctionSpec";
|
|
2
2
|
import type * as GroupSpec from "@confect/core/GroupSpec";
|
|
3
3
|
import * as MiddlewareSpec from "@confect/core/MiddlewareSpec";
|
|
4
|
-
import * as Registry from "./Registry";
|
|
4
|
+
import * as Registry from "./Registry.js";
|
|
5
5
|
import type { FunctionType } from "convex/server";
|
|
6
6
|
import * as Context from "effect/Context";
|
|
7
7
|
import * as Effect from "effect/Effect";
|
|
8
8
|
import * as Layer from "effect/Layer";
|
|
9
9
|
import * as Ref from "effect/Ref";
|
|
10
|
-
import type * as Auth from "./Auth";
|
|
11
|
-
import type * as DatabaseReader from "./DatabaseReader";
|
|
12
|
-
import type * as DatabaseSchema from "./DatabaseSchema";
|
|
13
|
-
import type * as Handler from "./Handler";
|
|
14
|
-
import type { ExecutionMetadata } from "./ExecutionMetadata";
|
|
15
|
-
import type { RequestMetadata } from "./RequestMetadata";
|
|
16
|
-
import type { TransactionMetadata } from "./TransactionMetadata";
|
|
17
|
-
import type * as MutationRunner from "./MutationRunner";
|
|
18
|
-
import type * as QueryRunner from "./QueryRunner";
|
|
19
|
-
import type { QueryTransactionContext } from "./QueryTransactionContext";
|
|
20
|
-
import type * as Scheduler from "./Scheduler";
|
|
21
|
-
import type { Storage } from "./Storage";
|
|
22
|
-
import type * as StorageReader from "./StorageReader";
|
|
23
|
-
import type * as StorageWriter from "./StorageWriter";
|
|
24
|
-
import * as MiddlewareRegistryItem from "./MiddlewareRegistryItem";
|
|
25
|
-
import { setNestedProperty } from "./internal/utils";
|
|
10
|
+
import type * as Auth from "./Auth.js";
|
|
11
|
+
import type * as DatabaseReader from "./DatabaseReader.js";
|
|
12
|
+
import type * as DatabaseSchema from "./DatabaseSchema.js";
|
|
13
|
+
import type * as Handler from "./Handler.js";
|
|
14
|
+
import type { ExecutionMetadata } from "./ExecutionMetadata.js";
|
|
15
|
+
import type { RequestMetadata } from "./RequestMetadata.js";
|
|
16
|
+
import type { TransactionMetadata } from "./TransactionMetadata.js";
|
|
17
|
+
import type * as MutationRunner from "./MutationRunner.js";
|
|
18
|
+
import type * as QueryRunner from "./QueryRunner.js";
|
|
19
|
+
import type { QueryTransactionContext } from "./QueryTransactionContext.js";
|
|
20
|
+
import type * as Scheduler from "./Scheduler.js";
|
|
21
|
+
import type { Storage } from "./Storage.js";
|
|
22
|
+
import type * as StorageReader from "./StorageReader.js";
|
|
23
|
+
import type * as StorageWriter from "./StorageWriter.js";
|
|
24
|
+
import * as MiddlewareRegistryItem from "./MiddlewareRegistryItem.js";
|
|
25
|
+
import { setNestedProperty } from "./internal/utils.js";
|
|
26
26
|
|
|
27
27
|
/**
|
|
28
28
|
* Marker service produced by providing a middleware's implementation to a
|
package/src/MutationCtx.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type * as IdScope from "@confect/core/IdScope";
|
|
2
2
|
import type { GenericDataModel, GenericMutationCtx } from "convex/server";
|
|
3
3
|
import * as Context from "effect/Context";
|
|
4
|
-
import type * as ComponentCtx from "./ComponentCtx";
|
|
4
|
+
import type * as ComponentCtx from "./ComponentCtx.js";
|
|
5
5
|
import * as Layer from "effect/Layer";
|
|
6
6
|
|
|
7
7
|
export type MutationCtxTag<
|
package/src/MutationRunner.ts
CHANGED
|
@@ -4,7 +4,7 @@ import * as Context from "effect/Context";
|
|
|
4
4
|
import * as Effect from "effect/Effect";
|
|
5
5
|
import * as Layer from "effect/Layer";
|
|
6
6
|
import type * as Schema from "effect/Schema";
|
|
7
|
-
import * as MutationTransactionContext from "./MutationTransactionContext";
|
|
7
|
+
import * as MutationTransactionContext from "./MutationTransactionContext.js";
|
|
8
8
|
|
|
9
9
|
export type Options = MutationTransactionContext.MutationOptions;
|
|
10
10
|
|
|
@@ -7,10 +7,10 @@ import type {
|
|
|
7
7
|
import * as Context from "effect/Context";
|
|
8
8
|
import * as Effect from "effect/Effect";
|
|
9
9
|
import * as Layer from "effect/Layer";
|
|
10
|
-
import type { Options as MutationOptions } from "./QueryTransactionContext";
|
|
10
|
+
import type { Options as MutationOptions } from "./QueryTransactionContext.js";
|
|
11
11
|
|
|
12
12
|
export type { TransactionLimits } from "convex/server";
|
|
13
|
-
export type { Options as MutationOptions } from "./QueryTransactionContext";
|
|
13
|
+
export type { Options as MutationOptions } from "./QueryTransactionContext.js";
|
|
14
14
|
export type QueryOptions = AdvancedRunQueryOptions;
|
|
15
15
|
|
|
16
16
|
const make = (
|
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
import * as Ref from "@confect/core/Ref";
|
|
2
|
+
import type {
|
|
3
|
+
DefaultFunctionArgs,
|
|
4
|
+
GenericActionCtx,
|
|
5
|
+
GenericDataModel,
|
|
6
|
+
GenericMutationCtx,
|
|
7
|
+
GenericQueryCtx,
|
|
8
|
+
} from "convex/server";
|
|
9
|
+
import * as Effect from "effect/Effect";
|
|
10
|
+
import * as Option from "effect/Option";
|
|
11
|
+
import * as Schema from "effect/Schema";
|
|
12
|
+
import * as ActionCtx from "./ActionCtx.js";
|
|
13
|
+
import type * as ActionRunner from "./ActionRunner.js";
|
|
14
|
+
import * as MutationCtx from "./MutationCtx.js";
|
|
15
|
+
import type * as MutationRunner from "./MutationRunner.js";
|
|
16
|
+
import * as QueryCtx from "./QueryCtx.js";
|
|
17
|
+
import type * as QueryRunner from "./QueryRunner.js";
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* An official component's method rejected. `cause` is the rejection as thrown.
|
|
21
|
+
*/
|
|
22
|
+
export class ComponentCallFailed extends Schema.TaggedError<ComponentCallFailed>()(
|
|
23
|
+
"ComponentCallFailed",
|
|
24
|
+
{ component: Schema.String, method: Schema.String, cause: Schema.Defect() },
|
|
25
|
+
) {}
|
|
26
|
+
|
|
27
|
+
declare const unsupported: unique symbol;
|
|
28
|
+
type Unsupported = typeof unsupported;
|
|
29
|
+
type Needs<Param> = [GenericActionCtx<GenericDataModel>] extends [Param]
|
|
30
|
+
? [GenericMutationCtx<GenericDataModel>] extends [Param]
|
|
31
|
+
? [GenericQueryCtx<GenericDataModel>] extends [Param]
|
|
32
|
+
? QueryRunner.QueryRunner
|
|
33
|
+
: MutationRunner.MutationRunner
|
|
34
|
+
: [GenericQueryCtx<GenericDataModel>] extends [Param]
|
|
35
|
+
? Unsupported
|
|
36
|
+
: ActionRunner.ActionRunner
|
|
37
|
+
: Unsupported;
|
|
38
|
+
|
|
39
|
+
type Method<Official> = {
|
|
40
|
+
[K in keyof Official & string]: Official[K] extends (
|
|
41
|
+
ctx: infer Ctx,
|
|
42
|
+
...args: infer _Args
|
|
43
|
+
) => Promise<unknown>
|
|
44
|
+
? Needs<Ctx> extends Unsupported
|
|
45
|
+
? never
|
|
46
|
+
: K
|
|
47
|
+
: never;
|
|
48
|
+
}[keyof Official & string];
|
|
49
|
+
|
|
50
|
+
type Call<F> = F extends (
|
|
51
|
+
ctx: infer Ctx,
|
|
52
|
+
...args: infer Args
|
|
53
|
+
) => Promise<infer A>
|
|
54
|
+
? (...args: Args) => Effect.Effect<A, never, Needs<Ctx>>
|
|
55
|
+
: never;
|
|
56
|
+
|
|
57
|
+
type Lifted<Official> = <M extends Method<Official>>(
|
|
58
|
+
method: M,
|
|
59
|
+
...args: Parameters<Call<Official[M]>>
|
|
60
|
+
) => ReturnType<Call<Official[M]>>;
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* Lift official promise methods, deriving each capability from its ctx
|
|
64
|
+
* parameter. A rejection is caller misuse, a limit or a platform fault rather
|
|
65
|
+
* than a domain fact, so it dies.
|
|
66
|
+
*/
|
|
67
|
+
export const make = <Official extends object>(
|
|
68
|
+
component: string,
|
|
69
|
+
official: Official,
|
|
70
|
+
): Lifted<Official> => {
|
|
71
|
+
const context = Effect.gen(function* () {
|
|
72
|
+
const action = yield* Effect.serviceOption(
|
|
73
|
+
ActionCtx.ActionCtx<GenericDataModel>(),
|
|
74
|
+
);
|
|
75
|
+
if (Option.isSome(action)) return action.value;
|
|
76
|
+
const mutation = yield* Effect.serviceOption(
|
|
77
|
+
MutationCtx.MutationCtx<GenericDataModel>(),
|
|
78
|
+
);
|
|
79
|
+
if (Option.isSome(mutation)) return mutation.value;
|
|
80
|
+
const query = yield* Effect.serviceOption(
|
|
81
|
+
QueryCtx.QueryCtx<GenericDataModel>(),
|
|
82
|
+
);
|
|
83
|
+
if (Option.isSome(query)) return query.value;
|
|
84
|
+
return yield* Effect.die(
|
|
85
|
+
new Error(`${component} called outside a Confect handler`),
|
|
86
|
+
);
|
|
87
|
+
});
|
|
88
|
+
const call = Effect.fn(`${component}.call`)(function* (
|
|
89
|
+
method: Method<Official>,
|
|
90
|
+
...args: unknown[]
|
|
91
|
+
) {
|
|
92
|
+
const ctx = yield* context;
|
|
93
|
+
// Method selects promise methods whose first argument accepts a native handler context.
|
|
94
|
+
const invoke = official[method] as (
|
|
95
|
+
native: typeof ctx,
|
|
96
|
+
...args: unknown[]
|
|
97
|
+
) => Promise<unknown>;
|
|
98
|
+
return yield* Effect.tryPromise({
|
|
99
|
+
try: () => invoke.call(official, ctx, ...args),
|
|
100
|
+
catch: (cause) => ComponentCallFailed.make({ component, method, cause }),
|
|
101
|
+
}).pipe(Effect.orDie);
|
|
102
|
+
});
|
|
103
|
+
// Confect installs the native ctx with the runner capability inferred by Needs.
|
|
104
|
+
return call as unknown as Lifted<Official>;
|
|
105
|
+
};
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* A function reference with its encoded arguments, ready for an official method
|
|
109
|
+
* that takes both.
|
|
110
|
+
*/
|
|
111
|
+
export interface Fn<R extends Ref.Any> {
|
|
112
|
+
readonly reference: Ref.FunctionReference<R>;
|
|
113
|
+
readonly args: DefaultFunctionArgs;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
/**
|
|
117
|
+
* Encode a ref's arguments through its codecs to the wire record an official
|
|
118
|
+
* method expects.
|
|
119
|
+
*/
|
|
120
|
+
export const encodeCall = <R extends Ref.Any>(
|
|
121
|
+
ref: R,
|
|
122
|
+
args: NoInfer<Ref.Args<R>>,
|
|
123
|
+
): Effect.Effect<Fn<R>> =>
|
|
124
|
+
Ref.encodeArgs(ref, args).pipe(
|
|
125
|
+
Effect.flatMap(
|
|
126
|
+
Schema.decodeUnknownEffect(Schema.Record(Schema.String, Schema.Unknown)),
|
|
127
|
+
),
|
|
128
|
+
Effect.map((encoded) => ({
|
|
129
|
+
reference: Ref.getFunctionReference(ref),
|
|
130
|
+
args: encoded,
|
|
131
|
+
})),
|
|
132
|
+
Effect.orDie,
|
|
133
|
+
);
|
|
134
|
+
|
|
135
|
+
/**
|
|
136
|
+
* Encode a callback's real field without fabricating the rest of its arguments.
|
|
137
|
+
*/
|
|
138
|
+
export const encodeField = <
|
|
139
|
+
R extends Ref.AnyConfect,
|
|
140
|
+
K extends keyof Ref.Args<R> & keyof Ref.ArgsFields<R>,
|
|
141
|
+
>(
|
|
142
|
+
ref: R,
|
|
143
|
+
key: K,
|
|
144
|
+
value: NoInfer<Ref.Args<R>[K]>,
|
|
145
|
+
): Effect.Effect<unknown> => {
|
|
146
|
+
const fields = ref.args.fields as Record<
|
|
147
|
+
keyof Ref.ArgsFields<R>,
|
|
148
|
+
Schema.Codec<unknown, unknown>
|
|
149
|
+
>;
|
|
150
|
+
return Schema.encodeUnknownEffect(fields[key])(value).pipe(Effect.orDie);
|
|
151
|
+
};
|
package/src/OrderedQuery.ts
CHANGED
|
@@ -10,10 +10,10 @@ import { identity, pipe } from "effect/Function";
|
|
|
10
10
|
import type { Option } from "effect";
|
|
11
11
|
import * as Effect from "effect/Effect";
|
|
12
12
|
import * as Stream from "effect/Stream";
|
|
13
|
-
import type * as DatabaseSchema from "./DatabaseSchema";
|
|
14
|
-
import * as Document from "./Document";
|
|
15
|
-
import type * as TableInfo from "./TableInfo";
|
|
16
|
-
import type * as Table from "./Table";
|
|
13
|
+
import type * as DatabaseSchema from "./DatabaseSchema.js";
|
|
14
|
+
import * as Document from "./Document.js";
|
|
15
|
+
import type * as TableInfo from "./TableInfo.js";
|
|
16
|
+
import type * as Table from "./Table.js";
|
|
17
17
|
|
|
18
18
|
type NativePaginate<TableInfo_ extends TableInfo.AnyWithProps, Doc> = (
|
|
19
19
|
options: PaginationOptions,
|