@gaganref/confect-server 10.3.1-fork.26 → 10.3.1-fork.27
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/ActionRunner.js +2 -2
- package/dist/AiGatewayDecisionClient.js +1 -1
- package/dist/AiGatewayLanguageClient.js +1 -1
- package/dist/Auth.js +1 -1
- package/dist/Callback.js +3 -3
- package/dist/ConvexConfigProvider.js +2 -2
- package/dist/ConvexFunctionDefinitions.js +2 -2
- package/dist/ConvexLogger.js +1 -1
- package/dist/CronJobs.js +6 -6
- package/dist/DatabaseSchema.js +2 -2
- package/dist/DatabaseWriter.js +3 -3
- package/dist/ExecutionMetadata.js +1 -1
- package/dist/FunctionImpl.js +2 -2
- package/dist/FunctionRegistryItem.js +1 -1
- package/dist/GroupImpl.js +5 -5
- package/dist/Handler.d.ts +7 -3
- package/dist/Handler.d.ts.map +1 -1
- package/dist/Handler.js.map +1 -1
- package/dist/HttpRouter.js +2 -2
- package/dist/MiddlewareImpl.js +1 -1
- package/dist/MutationRunner.js +2 -2
- package/dist/MutationTransactionContext.js +2 -2
- package/dist/QueryInitializer.js +2 -2
- package/dist/QueryRunner.js +2 -2
- package/dist/QueryStream.js +3 -3
- package/dist/QueryStreamCursor.js +1 -1
- package/dist/QueryStreamIndexPrefix.js +1 -1
- package/dist/QueryStreamIndexRange.js +2 -2
- package/dist/QueryStreamKey.js +1 -1
- package/dist/QueryStreamKeyBounds.js +2 -2
- package/dist/QueryStreamKeyLayout.js +2 -2
- package/dist/QueryStreamKeyValues.js +1 -1
- package/dist/QueryStreamPagination.js +1 -1
- package/dist/QueryStreamReadBudget.js +2 -2
- package/dist/QueryTransactionContext.js +2 -2
- package/dist/RegisteredConvexFunction.js +19 -19
- package/dist/RegisteredConvexFunction.js.map +1 -1
- package/dist/RegisteredFunction.d.ts.map +1 -1
- package/dist/RegisteredFunction.js +55 -13
- package/dist/RegisteredFunction.js.map +1 -1
- package/dist/RegisteredNodeFunction.js +1 -1
- package/dist/RegistryItems.js +1 -1
- package/dist/RequestMetadata.js +1 -1
- package/dist/Scheduler.js +2 -2
- package/dist/Storage.js +1 -1
- package/dist/StorageActionWriter.js +1 -1
- package/dist/StorageReader.js +1 -1
- package/dist/StorageWriter.js +1 -1
- package/dist/TransactionMetadata.js +1 -1
- package/dist/VectorSearch.js +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +10 -9
- package/dist/internal/AiGatewayDecisionClient.js +1 -1
- package/dist/internal/AiGatewayLanguageClient.js +1 -1
- package/dist/internal/AiGatewayServiceToken.js +1 -1
- package/dist/internal/DocumentPatch.js +1 -1
- package/package.json +2 -2
- package/src/ActionCall.ts +82 -0
- package/src/Handler.ts +20 -5
- package/src/RegisteredFunction.ts +54 -1
- package/src/index.ts +1 -0
package/dist/index.js
CHANGED
|
@@ -1,5 +1,14 @@
|
|
|
1
1
|
import { ActionCtx_exports } from "./ActionCtx.js";
|
|
2
2
|
import { ActionRunner_exports } from "./ActionRunner.js";
|
|
3
|
+
import { Registry_exports } from "./Registry.js";
|
|
4
|
+
import { MiddlewareRegistryItem_exports } from "./MiddlewareRegistryItem.js";
|
|
5
|
+
import { MiddlewareImpl_exports } from "./MiddlewareImpl.js";
|
|
6
|
+
import { MutationTransactionContext_exports } from "./MutationTransactionContext.js";
|
|
7
|
+
import { MutationRunner_exports } from "./MutationRunner.js";
|
|
8
|
+
import { QueryTransactionContext_exports } from "./QueryTransactionContext.js";
|
|
9
|
+
import { QueryRunner_exports } from "./QueryRunner.js";
|
|
10
|
+
import { Scheduler_exports } from "./Scheduler.js";
|
|
11
|
+
import { ActionCall_exports } from "./ActionCall.js";
|
|
3
12
|
import { AiGatewayDecisionClient_exports } from "./AiGatewayDecisionClient.js";
|
|
4
13
|
import { AiGatewayDecisionModel_exports } from "./AiGatewayDecisionModel.js";
|
|
5
14
|
import { AiGatewayLanguageClient_exports } from "./AiGatewayLanguageClient.js";
|
|
@@ -8,8 +17,6 @@ import { Auth_exports } from "./Auth.js";
|
|
|
8
17
|
import { BlobNotFoundError_exports } from "./BlobNotFoundError.js";
|
|
9
18
|
import { Callback_exports } from "./Callback.js";
|
|
10
19
|
import { ConvexConfigProvider_exports } from "./ConvexConfigProvider.js";
|
|
11
|
-
import { Registry_exports } from "./Registry.js";
|
|
12
|
-
import { MiddlewareRegistryItem_exports } from "./MiddlewareRegistryItem.js";
|
|
13
20
|
import { FunctionRegistryItem_exports } from "./FunctionRegistryItem.js";
|
|
14
21
|
import { DatabaseSchema_exports } from "./DatabaseSchema.js";
|
|
15
22
|
import { Document_exports } from "./Document.js";
|
|
@@ -31,13 +38,8 @@ import { ExecutionMetadata_exports } from "./ExecutionMetadata.js";
|
|
|
31
38
|
import { RequestMetadata_exports } from "./RequestMetadata.js";
|
|
32
39
|
import { TransactionMetadata_exports } from "./TransactionMetadata.js";
|
|
33
40
|
import { MutationCtx_exports } from "./MutationCtx.js";
|
|
34
|
-
import { MutationTransactionContext_exports } from "./MutationTransactionContext.js";
|
|
35
|
-
import { MutationRunner_exports } from "./MutationRunner.js";
|
|
36
41
|
import { QueryCtx_exports } from "./QueryCtx.js";
|
|
37
|
-
import { QueryTransactionContext_exports } from "./QueryTransactionContext.js";
|
|
38
|
-
import { QueryRunner_exports } from "./QueryRunner.js";
|
|
39
42
|
import { ConvexLogger_exports } from "./ConvexLogger.js";
|
|
40
|
-
import { Scheduler_exports } from "./Scheduler.js";
|
|
41
43
|
import { StorageActionWriter_exports } from "./StorageActionWriter.js";
|
|
42
44
|
import { StorageReader_exports } from "./StorageReader.js";
|
|
43
45
|
import { StorageWriter_exports } from "./StorageWriter.js";
|
|
@@ -55,8 +57,7 @@ import { RegistryItems_exports } from "./RegistryItems.js";
|
|
|
55
57
|
import { GroupImpl_exports } from "./GroupImpl.js";
|
|
56
58
|
import { Handler_exports } from "./Handler.js";
|
|
57
59
|
import { HttpRouter_exports } from "./HttpRouter.js";
|
|
58
|
-
import { MiddlewareImpl_exports } from "./MiddlewareImpl.js";
|
|
59
60
|
import { OfficialComponent_exports } from "./OfficialComponent.js";
|
|
60
61
|
import { RegisteredFunctions_exports } from "./RegisteredFunctions.js";
|
|
61
62
|
import { TableInfo_exports } from "./TableInfo.js";
|
|
62
|
-
export { ActionCtx_exports as ActionCtx, ActionRunner_exports as ActionRunner, AiGatewayDecisionClient_exports as AiGatewayDecisionClient, AiGatewayDecisionModel_exports as AiGatewayDecisionModel, AiGatewayLanguageClient_exports as AiGatewayLanguageClient, AiGatewayLanguageModel_exports as AiGatewayLanguageModel, Auth_exports as Auth, BlobNotFoundError_exports as BlobNotFoundError, Callback_exports as Callback, ConvexConfigProvider_exports as ConvexConfigProvider, ConvexFunctionDefinitions_exports as ConvexFunctionDefinitions, ConvexLogger_exports as ConvexLogger, CronJob_exports as CronJob, CronJobs_exports as CronJobs, DataModel_exports as DataModel, DatabaseReader_exports as DatabaseReader, DatabaseSchema_exports as DatabaseSchema, DatabaseWriter_exports as DatabaseWriter, Document_exports as Document, ExecutionMetadata_exports as ExecutionMetadata, FunctionImpl_exports as FunctionImpl, FunctionRegistryItem_exports as FunctionRegistryItem, GroupImpl_exports as GroupImpl, Handler_exports as Handler, HttpRouter_exports as HttpRouter, MiddlewareImpl_exports as MiddlewareImpl, MiddlewareRegistryItem_exports as MiddlewareRegistryItem, MutationCtx_exports as MutationCtx, MutationRunner_exports as MutationRunner, MutationTransactionContext_exports as MutationTransactionContext, OfficialComponent_exports as OfficialComponent, OrderedQuery_exports as OrderedQuery, QueryCtx_exports as QueryCtx, QueryInitializer_exports as QueryInitializer, QueryRunner_exports as QueryRunner, QueryStream_exports as QueryStream, QueryStreamCursor_exports as QueryStreamCursor, QueryStreamIndexRange_exports as QueryStreamIndexRange, QueryStreamKeyBounds_exports as QueryStreamKeyBounds, QueryStreamKeyLabels_exports as QueryStreamKeyLabels, QueryStreamKeyLayout_exports as QueryStreamKeyLayout, QueryStreamKeyValues_exports as QueryStreamKeyValues, QueryStreamOrderDirection_exports as QueryStreamOrderDirection, QueryStreamReadBudget_exports as QueryStreamReadBudget, QueryTransactionContext_exports as QueryTransactionContext, RegisteredConvexFunction_exports as RegisteredConvexFunction, RegisteredFunction_exports as RegisteredFunction, RegisteredFunctions_exports as RegisteredFunctions, Registry_exports as Registry, RegistryItems_exports as RegistryItems, RequestMetadata_exports as RequestMetadata, ResolvedMiddleware_exports as ResolvedMiddleware, Scheduler_exports as Scheduler, Storage_exports as Storage, StorageActionWriter_exports as StorageActionWriter, StorageReader_exports as StorageReader, StorageWriter_exports as StorageWriter, Table_exports as Table, TableInfo_exports as TableInfo, TransactionMetadata_exports as TransactionMetadata, VectorSearch_exports as VectorSearch };
|
|
63
|
+
export { ActionCall_exports as ActionCall, ActionCtx_exports as ActionCtx, ActionRunner_exports as ActionRunner, AiGatewayDecisionClient_exports as AiGatewayDecisionClient, AiGatewayDecisionModel_exports as AiGatewayDecisionModel, AiGatewayLanguageClient_exports as AiGatewayLanguageClient, AiGatewayLanguageModel_exports as AiGatewayLanguageModel, Auth_exports as Auth, BlobNotFoundError_exports as BlobNotFoundError, Callback_exports as Callback, ConvexConfigProvider_exports as ConvexConfigProvider, ConvexFunctionDefinitions_exports as ConvexFunctionDefinitions, ConvexLogger_exports as ConvexLogger, CronJob_exports as CronJob, CronJobs_exports as CronJobs, DataModel_exports as DataModel, DatabaseReader_exports as DatabaseReader, DatabaseSchema_exports as DatabaseSchema, DatabaseWriter_exports as DatabaseWriter, Document_exports as Document, ExecutionMetadata_exports as ExecutionMetadata, FunctionImpl_exports as FunctionImpl, FunctionRegistryItem_exports as FunctionRegistryItem, GroupImpl_exports as GroupImpl, Handler_exports as Handler, HttpRouter_exports as HttpRouter, MiddlewareImpl_exports as MiddlewareImpl, MiddlewareRegistryItem_exports as MiddlewareRegistryItem, MutationCtx_exports as MutationCtx, MutationRunner_exports as MutationRunner, MutationTransactionContext_exports as MutationTransactionContext, OfficialComponent_exports as OfficialComponent, OrderedQuery_exports as OrderedQuery, QueryCtx_exports as QueryCtx, QueryInitializer_exports as QueryInitializer, QueryRunner_exports as QueryRunner, QueryStream_exports as QueryStream, QueryStreamCursor_exports as QueryStreamCursor, QueryStreamIndexRange_exports as QueryStreamIndexRange, QueryStreamKeyBounds_exports as QueryStreamKeyBounds, QueryStreamKeyLabels_exports as QueryStreamKeyLabels, QueryStreamKeyLayout_exports as QueryStreamKeyLayout, QueryStreamKeyValues_exports as QueryStreamKeyValues, QueryStreamOrderDirection_exports as QueryStreamOrderDirection, QueryStreamReadBudget_exports as QueryStreamReadBudget, QueryTransactionContext_exports as QueryTransactionContext, RegisteredConvexFunction_exports as RegisteredConvexFunction, RegisteredFunction_exports as RegisteredFunction, RegisteredFunctions_exports as RegisteredFunctions, Registry_exports as Registry, RegistryItems_exports as RegistryItems, RequestMetadata_exports as RequestMetadata, ResolvedMiddleware_exports as ResolvedMiddleware, Scheduler_exports as Scheduler, Storage_exports as Storage, StorageActionWriter_exports as StorageActionWriter, StorageReader_exports as StorageReader, StorageWriter_exports as StorageWriter, Table_exports as Table, TableInfo_exports as TableInfo, TransactionMetadata_exports as TransactionMetadata, VectorSearch_exports as VectorSearch };
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { AiGatewayServiceToken, transformClientRequest } from "./AiGatewayServiceToken.js";
|
|
2
2
|
import { AI_GATEWAY_API_URL } from "./constants.js";
|
|
3
|
-
import * as Layer from "effect/Layer";
|
|
4
3
|
import * as Effect from "effect/Effect";
|
|
4
|
+
import * as Layer from "effect/Layer";
|
|
5
5
|
import * as OpenRouterClient from "@effect/ai-openrouter/OpenRouterClient";
|
|
6
6
|
//#region src/internal/AiGatewayDecisionClient.ts
|
|
7
7
|
const make = Effect.gen(function* () {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { AiGatewayServiceToken, transformClientRequest } from "./AiGatewayServiceToken.js";
|
|
2
2
|
import { AI_GATEWAY_API_URL } from "./constants.js";
|
|
3
|
-
import * as Layer from "effect/Layer";
|
|
4
3
|
import * as Effect from "effect/Effect";
|
|
4
|
+
import * as Layer from "effect/Layer";
|
|
5
5
|
import * as OpenAiClient from "@effect/ai-openai-compat/OpenAiClient";
|
|
6
6
|
//#region src/internal/AiGatewayLanguageClient.ts
|
|
7
7
|
const make = Effect.gen(function* () {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as Context from "effect/Context";
|
|
2
|
-
import * as Layer from "effect/Layer";
|
|
3
2
|
import * as Effect from "effect/Effect";
|
|
3
|
+
import * as Layer from "effect/Layer";
|
|
4
4
|
import { getServiceToken } from "convex/server";
|
|
5
5
|
import * as Schema from "effect/Schema";
|
|
6
6
|
import * as HttpClient from "effect/http/HttpClient";
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import * as Effect from "effect/Effect";
|
|
2
|
+
import * as Record from "effect/Record";
|
|
2
3
|
import * as Schema from "effect/Schema";
|
|
3
4
|
import { pipe } from "effect/Function";
|
|
4
5
|
import * as SchemaAST from "effect/SchemaAST";
|
|
5
|
-
import * as Record from "effect/Record";
|
|
6
6
|
//#region src/internal/DocumentPatch.ts
|
|
7
7
|
const patchEncoders = /* @__PURE__ */ new WeakMap();
|
|
8
8
|
/**
|
package/package.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gaganref/confect-server",
|
|
3
|
-
"version": "10.3.1-fork.
|
|
3
|
+
"version": "10.3.1-fork.27",
|
|
4
4
|
"dependencies": {
|
|
5
5
|
"@effect/ai-openai-compat": "4.0.4",
|
|
6
6
|
"@effect/ai-openrouter": "4.0.4"
|
|
7
7
|
},
|
|
8
8
|
"peerDependencies": {
|
|
9
|
-
"@confect/core": "npm:@gaganref/confect-core@10.3.1-fork.
|
|
9
|
+
"@confect/core": "npm:@gaganref/confect-core@10.3.1-fork.27",
|
|
10
10
|
"@effect/platform-node": "^4.0.0",
|
|
11
11
|
"convex": "^1.45.0",
|
|
12
12
|
"effect": "^4.0.4"
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import * as ActionCall from "@confect/core/ActionCall";
|
|
2
|
+
import * as Ref from "@confect/core/Ref";
|
|
3
|
+
import type { FunctionReference } from "convex/server";
|
|
4
|
+
import * as Context from "effect/Context";
|
|
5
|
+
import * as Data from "effect/Data";
|
|
6
|
+
import * as Effect from "effect/Effect";
|
|
7
|
+
import * as ActionCtx from "./ActionCtx.js";
|
|
8
|
+
import * as ActionRunner from "./ActionRunner.js";
|
|
9
|
+
import type * as DatabaseSchema from "./DatabaseSchema.js";
|
|
10
|
+
import type * as DataModel from "./DataModel.js";
|
|
11
|
+
import type * as Handler from "./Handler.js";
|
|
12
|
+
import * as MiddlewareImpl from "./MiddlewareImpl.js";
|
|
13
|
+
import * as MutationRunner from "./MutationRunner.js";
|
|
14
|
+
import * as QueryRunner from "./QueryRunner.js";
|
|
15
|
+
import * as Scheduler from "./Scheduler.js";
|
|
16
|
+
|
|
17
|
+
export class ActionCallAlreadyUsed extends Data.TaggedError(
|
|
18
|
+
"ActionCallAlreadyUsed",
|
|
19
|
+
)<{}> {}
|
|
20
|
+
export class ActionCallNotUsed extends Data.TaggedError(
|
|
21
|
+
"ActionCallNotUsed",
|
|
22
|
+
)<{}> {}
|
|
23
|
+
export class MissingFunctionType extends Data.TaggedError(
|
|
24
|
+
"MissingFunctionType",
|
|
25
|
+
)<{}> {}
|
|
26
|
+
export class NestedActionNotAllowed extends Data.TaggedError(
|
|
27
|
+
"NestedActionNotAllowed",
|
|
28
|
+
)<{}> {}
|
|
29
|
+
|
|
30
|
+
export class SchedulingNotAllowed extends Data.TaggedError(
|
|
31
|
+
"SchedulingNotAllowed",
|
|
32
|
+
)<{}> {}
|
|
33
|
+
|
|
34
|
+
export const layer = <S extends DatabaseSchema.AnyWithProps>(schema: S) =>
|
|
35
|
+
MiddlewareImpl.make(schema, ActionCall.Middleware, (effect) =>
|
|
36
|
+
Effect.gen(function* () {
|
|
37
|
+
const ctx = yield* ActionCtx.ActionCtx<
|
|
38
|
+
DataModel.ToConvex<DataModel.FromSchema<S>>,
|
|
39
|
+
DatabaseSchema.Scope<S>
|
|
40
|
+
>();
|
|
41
|
+
let claimed = false;
|
|
42
|
+
const call: ActionCall.Call = <
|
|
43
|
+
Target extends Ref.AnyQuery | Ref.AnyMutation,
|
|
44
|
+
>(
|
|
45
|
+
ref: Target,
|
|
46
|
+
...args: Ref.OptionalArgs<NoInfer<Target>>
|
|
47
|
+
) =>
|
|
48
|
+
Effect.suspend(() => {
|
|
49
|
+
if (claimed) return Effect.die(new ActionCallAlreadyUsed());
|
|
50
|
+
claimed = true;
|
|
51
|
+
if (ref.functionType !== "query" && ref.functionType !== "mutation")
|
|
52
|
+
return Effect.die(new MissingFunctionType());
|
|
53
|
+
return Ref.runWithCodec(
|
|
54
|
+
ref,
|
|
55
|
+
(args[0] ?? {}) as Ref.Args<Target>,
|
|
56
|
+
(native, encoded) =>
|
|
57
|
+
ref.functionType === "query"
|
|
58
|
+
? ctx.runQuery(
|
|
59
|
+
native as FunctionReference<"query">,
|
|
60
|
+
encoded as never,
|
|
61
|
+
)
|
|
62
|
+
: ctx.runMutation(
|
|
63
|
+
native as FunctionReference<"mutation">,
|
|
64
|
+
encoded as never,
|
|
65
|
+
),
|
|
66
|
+
);
|
|
67
|
+
});
|
|
68
|
+
return yield* effect.pipe(
|
|
69
|
+
Effect.provideService(ActionCall.ActionCall, call),
|
|
70
|
+
Effect.updateContext(
|
|
71
|
+
(context: Context.Context<Handler.ActionServices<S>>) =>
|
|
72
|
+
Context.omit(
|
|
73
|
+
QueryRunner.QueryRunner,
|
|
74
|
+
MutationRunner.MutationRunner,
|
|
75
|
+
ActionRunner.ActionRunner,
|
|
76
|
+
ActionCtx.ActionCtx(),
|
|
77
|
+
Scheduler.Scheduler,
|
|
78
|
+
)(context),
|
|
79
|
+
),
|
|
80
|
+
);
|
|
81
|
+
}),
|
|
82
|
+
);
|
package/src/Handler.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
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";
|
|
@@ -114,9 +115,7 @@ export type MutationServices<
|
|
|
114
115
|
/**
|
|
115
116
|
* Shared by both action runtimes.
|
|
116
117
|
*/
|
|
117
|
-
|
|
118
|
-
DatabaseSchema_ extends DatabaseSchema.AnyWithProps,
|
|
119
|
-
> =
|
|
118
|
+
type RawActionServices<DatabaseSchema_ extends DatabaseSchema.AnyWithProps> =
|
|
120
119
|
| Scheduler.ForScope<DatabaseSchema.Scope<DatabaseSchema_>>
|
|
121
120
|
| (DatabaseSchema_["target"]["kind"] extends "component" ? never : Auth.Auth)
|
|
122
121
|
| StorageReader.ForScope<DatabaseSchema.Scope<DatabaseSchema_>>
|
|
@@ -134,6 +133,22 @@ export type ActionServices<
|
|
|
134
133
|
DatabaseSchema.Scope<DatabaseSchema_>
|
|
135
134
|
>;
|
|
136
135
|
|
|
136
|
+
export type ActionServices<S extends DatabaseSchema.AnyWithProps, R = never> = [
|
|
137
|
+
Extract<R, ActionCall>,
|
|
138
|
+
] extends [never]
|
|
139
|
+
? RawActionServices<S>
|
|
140
|
+
: Exclude<
|
|
141
|
+
RawActionServices<S>,
|
|
142
|
+
| Scheduler.ForScope<DatabaseSchema.Scope<S>>
|
|
143
|
+
| QueryRunner.QueryRunner
|
|
144
|
+
| MutationRunner.MutationRunner
|
|
145
|
+
| ActionRunner.ActionRunner
|
|
146
|
+
| ActionCtx.ActionCtx<
|
|
147
|
+
DataModel.ToConvex<DataModel.FromSchema<S>>,
|
|
148
|
+
DatabaseSchema.Scope<S>
|
|
149
|
+
>
|
|
150
|
+
>;
|
|
151
|
+
|
|
137
152
|
export type ConfectProvenanceQuery<
|
|
138
153
|
DatabaseSchema_ extends DatabaseSchema.AnyWithProps,
|
|
139
154
|
FunctionSpec_ extends
|
|
@@ -153,7 +168,7 @@ export type ConvexRuntimeAction<
|
|
|
153
168
|
FunctionSpec_ extends
|
|
154
169
|
FunctionSpec.AnyWithPropsWithFunctionType<RuntimeAndFunctionType.AnyAction>,
|
|
155
170
|
R = never,
|
|
156
|
-
> = Base<FunctionSpec_, ActionServices<DatabaseSchema_> | R>;
|
|
171
|
+
> = Base<FunctionSpec_, ActionServices<DatabaseSchema_, R> | R>;
|
|
157
172
|
|
|
158
173
|
export type NodeRuntimeAction<
|
|
159
174
|
DatabaseSchema_ extends DatabaseSchema.AnyWithProps,
|
|
@@ -162,7 +177,7 @@ export type NodeRuntimeAction<
|
|
|
162
177
|
R = never,
|
|
163
178
|
> = Base<
|
|
164
179
|
FunctionSpec_,
|
|
165
|
-
ActionServices<DatabaseSchema_> | NodeServices.NodeServices | R
|
|
180
|
+
ActionServices<DatabaseSchema_, R> | NodeServices.NodeServices | R
|
|
166
181
|
>;
|
|
167
182
|
|
|
168
183
|
type Base<FunctionSpec_ extends FunctionSpec.AnyWithProps, R> = (
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import * as ActionCallSpec from "@confect/core/ActionCall";
|
|
2
|
+
import * as ActionCall from "./ActionCall.js";
|
|
1
3
|
import type { FunctionSpec, RuntimeAndFunctionType } from "@confect/core";
|
|
2
4
|
import * as IdScope from "@confect/core/IdScope";
|
|
3
5
|
import type * as FunctionProvenance from "@confect/core/FunctionProvenance";
|
|
@@ -299,6 +301,12 @@ export const actionFunctionBase = <
|
|
|
299
301
|
Schema.decodeUnknownEffect(args),
|
|
300
302
|
Effect.catchTag("SchemaError", Effect.die),
|
|
301
303
|
);
|
|
304
|
+
const restricted = resolvedMiddlewares.some(
|
|
305
|
+
({ middlewareSpec }) =>
|
|
306
|
+
middlewareSpec.key === ActionCallSpec.Middleware.key,
|
|
307
|
+
)
|
|
308
|
+
? restrict(ctx)
|
|
309
|
+
: undefined;
|
|
302
310
|
// oxlint-disable-next-line effecttsgo/any-unknown-in-error-context -- Middleware errors are intentionally erased here and validated by runHandlerPromise against the combined error schema below.
|
|
303
311
|
const decodedReturns = yield* applyMiddleware(
|
|
304
312
|
handler(decodedArgs),
|
|
@@ -309,7 +317,8 @@ export const actionFunctionBase = <
|
|
|
309
317
|
functionVisibility,
|
|
310
318
|
args: decodedArgs,
|
|
311
319
|
},
|
|
312
|
-
).pipe(Effect.provide(createLayer(ctx)));
|
|
320
|
+
).pipe(Effect.provide(createLayer(restricted?.ctx ?? ctx)));
|
|
321
|
+
if (restricted !== undefined) yield* restricted.check;
|
|
313
322
|
return yield* pipe(
|
|
314
323
|
decodedReturns,
|
|
315
324
|
Schema.encodeEffect(returns),
|
|
@@ -389,3 +398,47 @@ export const storageLayer = <Scope extends IdScope.IdScope>(
|
|
|
389
398
|
Storage.layer(reader) as Layer.Layer<
|
|
390
399
|
Storage.Storage | StorageReader.ForScope<Scope>
|
|
391
400
|
>;
|
|
401
|
+
|
|
402
|
+
/**
|
|
403
|
+
* Shares one dispatch budget across the entire middleware chain.
|
|
404
|
+
*/
|
|
405
|
+
const restrict = <Model extends GenericDataModel>(
|
|
406
|
+
ctx: GenericActionCtx<Model>,
|
|
407
|
+
) => {
|
|
408
|
+
let dispatched = false;
|
|
409
|
+
const claim = () => {
|
|
410
|
+
if (dispatched) throw new ActionCall.ActionCallAlreadyUsed();
|
|
411
|
+
dispatched = true;
|
|
412
|
+
};
|
|
413
|
+
const restricted: GenericActionCtx<Model> = {
|
|
414
|
+
...ctx,
|
|
415
|
+
scheduler: {
|
|
416
|
+
runAfter: () => {
|
|
417
|
+
throw new ActionCall.SchedulingNotAllowed();
|
|
418
|
+
},
|
|
419
|
+
runAt: () => {
|
|
420
|
+
throw new ActionCall.SchedulingNotAllowed();
|
|
421
|
+
},
|
|
422
|
+
cancel: () => {
|
|
423
|
+
throw new ActionCall.SchedulingNotAllowed();
|
|
424
|
+
},
|
|
425
|
+
},
|
|
426
|
+
runQuery: (...args) => {
|
|
427
|
+
claim();
|
|
428
|
+
return ctx.runQuery(...args);
|
|
429
|
+
},
|
|
430
|
+
runMutation: (...args) => {
|
|
431
|
+
claim();
|
|
432
|
+
return ctx.runMutation(...args);
|
|
433
|
+
},
|
|
434
|
+
runAction: () => {
|
|
435
|
+
throw new ActionCall.NestedActionNotAllowed();
|
|
436
|
+
},
|
|
437
|
+
};
|
|
438
|
+
return {
|
|
439
|
+
ctx: restricted,
|
|
440
|
+
check: Effect.suspend(() =>
|
|
441
|
+
dispatched ? Effect.void : Effect.die(new ActionCall.ActionCallNotUsed()),
|
|
442
|
+
),
|
|
443
|
+
};
|
|
444
|
+
};
|
package/src/index.ts
CHANGED