@confect/server 6.0.0 → 7.0.0
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 +128 -1
- package/dist/ActionRunner.d.ts +3 -5
- package/dist/ActionRunner.d.ts.map +1 -1
- package/dist/ActionRunner.js.map +1 -1
- package/dist/DatabaseReader.d.ts +1 -1
- package/dist/Handler.d.ts +1 -1
- package/dist/Handler.d.ts.map +1 -1
- package/dist/Handler.js.map +1 -1
- package/dist/MutationRunner.d.ts +5 -16
- package/dist/MutationRunner.d.ts.map +1 -1
- package/dist/MutationRunner.js +2 -12
- package/dist/MutationRunner.js.map +1 -1
- package/dist/QueryRunner.d.ts +3 -5
- package/dist/QueryRunner.d.ts.map +1 -1
- package/dist/QueryRunner.js.map +1 -1
- package/dist/RegisteredConvexFunction.d.ts +6 -6
- package/dist/RegisteredConvexFunction.d.ts.map +1 -1
- package/dist/RegisteredConvexFunction.js +18 -8
- package/dist/RegisteredConvexFunction.js.map +1 -1
- package/dist/RegisteredFunction.d.ts +24 -5
- package/dist/RegisteredFunction.d.ts.map +1 -1
- package/dist/RegisteredFunction.js +34 -5
- package/dist/RegisteredFunction.js.map +1 -1
- package/dist/RegisteredNodeFunction.js +3 -1
- package/dist/RegisteredNodeFunction.js.map +1 -1
- package/package.json +5 -5
- package/src/ActionRunner.ts +5 -1
- package/src/Handler.ts +5 -1
- package/src/MutationRunner.ts +6 -16
- package/src/QueryRunner.ts +5 -1
- package/src/RegisteredConvexFunction.ts +95 -79
- package/src/RegisteredFunction.ts +67 -22
- package/src/RegisteredNodeFunction.ts +4 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,132 @@
|
|
|
1
1
|
# @confect/server
|
|
2
2
|
|
|
3
|
+
## 7.0.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- 90094d0: Add typed errors to Confect functions (queries, mutations, and actions). Declare an optional `error` schema in `FunctionSpec` and recover it as a typed value at every call site—`useQuery`, `useMutation`, `useAction`, `HttpClient`, `WebSocketClient`, and `TestConfect`—without paying for it on functions that don't fail.
|
|
8
|
+
|
|
9
|
+
Typed errors travel across the function boundary as Convex's native [`ConvexError`](https://docs.convex.dev/functions/error-handling/application-errors#throwing-application-errors): the encoded error sits in `ConvexError.data`, leaving the `returns` channel unsullied and preserving native Convex semantics for non-Confect callers of the same API.
|
|
10
|
+
|
|
11
|
+
### Authoring a function with typed errors
|
|
12
|
+
|
|
13
|
+
`FunctionSpec` constructors now accept an optional `error` schema. To support multiple error shapes, combine them with `Schema.Union`.
|
|
14
|
+
|
|
15
|
+
```ts
|
|
16
|
+
import { FunctionSpec, GenericId, GroupSpec } from "@confect/core";
|
|
17
|
+
import { Schema } from "effect";
|
|
18
|
+
|
|
19
|
+
export class NoteNotFound extends Schema.TaggedError<NoteNotFound>()(
|
|
20
|
+
"NoteNotFound",
|
|
21
|
+
{ noteId: GenericId.GenericId("notes") },
|
|
22
|
+
) {}
|
|
23
|
+
|
|
24
|
+
export const notes = GroupSpec.make("notes").addFunction(
|
|
25
|
+
FunctionSpec.publicQuery({
|
|
26
|
+
name: "getOrFail",
|
|
27
|
+
args: Schema.Struct({ noteId: GenericId.GenericId("notes") }),
|
|
28
|
+
returns: Notes.Doc,
|
|
29
|
+
error: NoteNotFound,
|
|
30
|
+
}),
|
|
31
|
+
);
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
The `FunctionImpl` for that ref can now `Effect.fail` (or `mapError` to) any value matching the declared schema. Whichever invocation path the caller takes—`useQuery`/`useMutation`/`useAction`, `HttpClient`, `WebSocketClient`, or `TestConfect`—Confect encodes the failure, transports it via `ConvexError`, and surfaces the decoded value in the appropriate channel for that call site.
|
|
35
|
+
|
|
36
|
+
```ts
|
|
37
|
+
import { FunctionImpl } from "@confect/server";
|
|
38
|
+
import { Effect } from "effect";
|
|
39
|
+
import api from "../_generated/api";
|
|
40
|
+
import { DatabaseReader } from "../_generated/services";
|
|
41
|
+
import { NoteNotFound } from "./notes.spec";
|
|
42
|
+
|
|
43
|
+
const getOrFail = FunctionImpl.make(api, "notes", "getOrFail", ({ noteId }) =>
|
|
44
|
+
Effect.gen(function* () {
|
|
45
|
+
const reader = yield* DatabaseReader;
|
|
46
|
+
return yield* reader
|
|
47
|
+
.table("notes")
|
|
48
|
+
.get(noteId)
|
|
49
|
+
.pipe(Effect.mapError(() => new NoteNotFound({ noteId })));
|
|
50
|
+
}),
|
|
51
|
+
);
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
### Consuming a typed error
|
|
55
|
+
|
|
56
|
+
`@confect/js` (`HttpClient`, `WebSocketClient`) and `@confect/test` (`TestConfect`) surface the decoded error in the `Effect` error channel alongside the existing `HttpClientError`/`WebSocketClientError`/`ParseError`:
|
|
57
|
+
|
|
58
|
+
```ts
|
|
59
|
+
HttpClient.query(refs.public.notes.getOrFail, { noteId });
|
|
60
|
+
// Effect.Effect<Note, NoteNotFound | HttpClientError | ParseError>
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
### `@confect/react`—breaking changes
|
|
64
|
+
|
|
65
|
+
`useQuery`, `useMutation`, and `useAction` now expose typed errors, and `useQuery` returns a tagged result type instead of `Returns | undefined`.
|
|
66
|
+
|
|
67
|
+
**`useQuery` now returns `QueryResult<A, E>`.** Loading and (when an `error` schema is declared) failure are reified as variants alongside success. Match on the result with `QueryResult.match`:
|
|
68
|
+
|
|
69
|
+
Before:
|
|
70
|
+
|
|
71
|
+
```tsx
|
|
72
|
+
const notes = useQuery(refs.public.notes.list, {});
|
|
73
|
+
if (notes === undefined) return <p>Loading…</p>;
|
|
74
|
+
return <NoteList notes={notes} />;
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
After:
|
|
78
|
+
|
|
79
|
+
```tsx
|
|
80
|
+
import { QueryResult, useQuery } from "@confect/react";
|
|
81
|
+
|
|
82
|
+
const notes = useQuery(refs.public.notes.list, {});
|
|
83
|
+
return QueryResult.match(notes, {
|
|
84
|
+
onLoading: (skipped) => (skipped ? null : <p>Loading…</p>),
|
|
85
|
+
onSuccess: (notes) => <NoteList notes={notes} />,
|
|
86
|
+
});
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
The `Loading` variant carries a `skipped: boolean` flag, exposed as the argument to `onLoading`. It distinguishes a query that is genuinely in flight (`skipped: false`) from one that is sitting idle because `"skip"` was passed as its args (`skipped: true`)—a distinction `convex/react`'s plain `undefined` return value cannot make. Use it to render a loading indicator only when work is actually happening, and an empty/placeholder state otherwise.
|
|
90
|
+
|
|
91
|
+
When the ref declares an `error` schema, `onFailure` becomes required and receives the decoded typed error:
|
|
92
|
+
|
|
93
|
+
```tsx
|
|
94
|
+
const lookup = useQuery(refs.public.notes.getOrFail, { noteId });
|
|
95
|
+
QueryResult.match(lookup, {
|
|
96
|
+
onLoading: (skipped) => (skipped ? null : "Looking up…"),
|
|
97
|
+
onSuccess: (note) => `Found: ${note.text}`,
|
|
98
|
+
onFailure: (error) => `Note ${error.noteId} not found.`,
|
|
99
|
+
});
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
`QueryResult` is a Confect-native type exported from `@confect/react`.
|
|
103
|
+
|
|
104
|
+
**`useMutation` and `useAction` return `Promise<Either<A, E>>` when the ref declares an `error` schema.** Refs without an `error` schema continue to resolve to `Promise<A>`, matching the prior shape and `convex/react`'s behavior.
|
|
105
|
+
|
|
106
|
+
```ts
|
|
107
|
+
const deleteOrFail = useMutation(refs.public.notes.deleteOrFail);
|
|
108
|
+
const result = await deleteOrFail({ noteId });
|
|
109
|
+
// Either.Either<null, NoteNotFound | Forbidden>
|
|
110
|
+
Either.match(result, {
|
|
111
|
+
onLeft: (error) => /* typed error */,
|
|
112
|
+
onRight: (value) => /* success */,
|
|
113
|
+
});
|
|
114
|
+
|
|
115
|
+
const deleteNote = useMutation(refs.public.notes.delete_); // no `error` schema
|
|
116
|
+
await deleteNote({ noteId }); // Promise<null>, as before
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
Unspecified failures continue to reject the promise.
|
|
120
|
+
|
|
121
|
+
### Migration
|
|
122
|
+
- For each `useQuery` call site, replace `result === undefined` checks and direct property access with `QueryResult.match` (or the lower-level `QueryResult.isLoading`/`isSuccess`/`isFailure` predicates).
|
|
123
|
+
- For each `useMutation`/`useAction` call site whose ref now declares an `error` schema, unwrap the resolved `Either` (e.g. with `Either.match`); call sites against refs without an `error` schema need no change.
|
|
124
|
+
|
|
125
|
+
### Patch Changes
|
|
126
|
+
|
|
127
|
+
- Updated dependencies [90094d0]
|
|
128
|
+
- @confect/core@7.0.0
|
|
129
|
+
|
|
3
130
|
## 6.0.0
|
|
4
131
|
|
|
5
132
|
### Major Changes
|
|
@@ -43,7 +170,7 @@
|
|
|
43
170
|
|
|
44
171
|
### Minor Changes
|
|
45
172
|
|
|
46
|
-
- 641fd99: Add optional `filter` parameter to `OrderedQuery.paginate`. This allows applying a Convex filter directly at the pagination level
|
|
173
|
+
- 641fd99: Add optional `filter` parameter to `OrderedQuery.paginate`. This allows applying a Convex filter directly at the pagination level—the one scenario where `.filter()` is recommended over index-based filtering. The filter callback receives a `FilterBuilder` and is applied to the underlying query before paginating.
|
|
47
174
|
|
|
48
175
|
### Patch Changes
|
|
49
176
|
|
package/dist/ActionRunner.d.ts
CHANGED
|
@@ -1,16 +1,14 @@
|
|
|
1
|
-
import { Context, Layer } from "effect";
|
|
1
|
+
import { Context, Effect, Layer, ParseResult } from "effect";
|
|
2
2
|
import * as Ref$1 from "@confect/core/Ref";
|
|
3
3
|
import { GenericActionCtx } from "convex/server";
|
|
4
|
-
import * as effect_ParseResult0 from "effect/ParseResult";
|
|
5
|
-
import * as effect_Effect0 from "effect/Effect";
|
|
6
4
|
|
|
7
5
|
//#region src/ActionRunner.d.ts
|
|
8
6
|
declare namespace ActionRunner_d_exports {
|
|
9
7
|
export { ActionRunner, layer };
|
|
10
8
|
}
|
|
11
|
-
declare const ActionRunner: Context.Tag<(<Action extends Ref$1.AnyAction>(action: Action, ...args: Ref$1.OptionalArgs<Action>) =>
|
|
9
|
+
declare const ActionRunner: Context.Tag<(<Action extends Ref$1.AnyAction>(action: Action, ...args: Ref$1.OptionalArgs<Action>) => Effect.Effect<Ref$1.Returns<Action>, Ref$1.Error<Action> | ParseResult.ParseError>), <Action extends Ref$1.AnyAction>(action: Action, ...args: Ref$1.OptionalArgs<Action>) => Effect.Effect<Ref$1.Returns<Action>, Ref$1.Error<Action> | ParseResult.ParseError>>;
|
|
12
10
|
type ActionRunner = typeof ActionRunner.Identifier;
|
|
13
|
-
declare const layer: (runAction: GenericActionCtx<any>["runAction"]) => Layer.Layer<(<Action extends Ref$1.AnyAction>(action: Action, ...args: Ref$1.OptionalArgs<Action>) =>
|
|
11
|
+
declare const layer: (runAction: GenericActionCtx<any>["runAction"]) => Layer.Layer<(<Action extends Ref$1.AnyAction>(action: Action, ...args: Ref$1.OptionalArgs<Action>) => Effect.Effect<Ref$1.Returns<Action>, Ref$1.Error<Action> | ParseResult.ParseError>), never, never>;
|
|
14
12
|
//#endregion
|
|
15
13
|
export { ActionRunner, ActionRunner_d_exports, layer };
|
|
16
14
|
//# sourceMappingURL=ActionRunner.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ActionRunner.d.ts","names":[],"sources":["../src/ActionRunner.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"ActionRunner.d.ts","names":[],"sources":["../src/ActionRunner.ts"],"mappings":";;;;;;;;cAqBa,YAAA,EAAY,OAAA,CAAA,GAAA,kBAdP,KAAA,CAAI,SAAA,EAAS,MAAA,EACnB,MAAA,KAAM,IAAA,EACL,KAAA,CAAI,YAAA,CAAa,MAAA,MACzB,MAAA,CAAO,MAAA,CACR,KAAA,CAAI,OAAA,CAAQ,MAAA,GACZ,KAAA,CAAI,KAAA,CAAM,MAAA,IAAU,WAAA,CAAY,UAAA,oBALlB,KAAA,CAAI,SAAA,EAAS,MAAA,EACnB,MAAA,KAAM,IAAA,EACL,KAAA,CAAI,YAAA,CAAa,MAAA,MACzB,MAAA,CAAO,MAAA,CACR,KAAA,CAAI,OAAA,CAAQ,MAAA,GACZ,KAAA,CAAI,KAAA,CAAM,MAAA,IAAU,WAAA,CAAY,UAAA;AAAA,KAYxB,YAAA,UAAsB,YAAA,CAAa,UAAA;AAAA,cAElC,KAAA,GAAS,SAAA,EAAW,gBAAA,uBAAkC,KAAA,CAAA,KAAA,kBAnBjD,KAAA,CAAI,SAAA,EAAS,MAAA,EACnB,MAAA,KAAM,IAAA,EACL,KAAA,CAAI,YAAA,CAAa,MAAA,MACzB,MAAA,CAAO,MAAA,CACR,KAAA,CAAI,OAAA,CAAQ,MAAA,GACZ,KAAA,CAAI,KAAA,CAAM,MAAA,IAAU,WAAA,CAAY,UAAA"}
|
package/dist/ActionRunner.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ActionRunner.js","names":["Ref"],"sources":["../src/ActionRunner.ts"],"sourcesContent":["import * as Ref from \"@confect/core/Ref\";\nimport { type GenericActionCtx } from \"convex/server\";\nimport { Context, Layer } from \"effect\";\n\nconst make =\n (runAction: GenericActionCtx<any>[\"runAction\"]) =>\n <Action extends Ref.AnyAction>(\n action: Action,\n ...args: Ref.OptionalArgs<Action>\n ) =>\n Ref.runWithCodec(\n action,\n (args[0] ?? {}) as Ref.Args<Action>,\n (functionReference, encodedArgs) =>\n runAction(functionReference, encodedArgs),\n );\n\nexport const ActionRunner = Context.GenericTag<ReturnType<typeof make>>(\n \"@confect/server/ActionRunner\",\n);\nexport type ActionRunner = typeof ActionRunner.Identifier;\n\nexport const layer = (runAction: GenericActionCtx<any>[\"runAction\"]) =>\n Layer.succeed(ActionRunner, make(runAction));\n"],"mappings":";;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"ActionRunner.js","names":["Ref"],"sources":["../src/ActionRunner.ts"],"sourcesContent":["import * as Ref from \"@confect/core/Ref\";\nimport { type GenericActionCtx } from \"convex/server\";\nimport type { ParseResult, Effect } from \"effect\";\nimport { Context, Layer } from \"effect\";\n\nconst make =\n (runAction: GenericActionCtx<any>[\"runAction\"]) =>\n <Action extends Ref.AnyAction>(\n action: Action,\n ...args: Ref.OptionalArgs<Action>\n ): Effect.Effect<\n Ref.Returns<Action>,\n Ref.Error<Action> | ParseResult.ParseError\n > =>\n Ref.runWithCodec(\n action,\n (args[0] ?? {}) as Ref.Args<Action>,\n (functionReference, encodedArgs) =>\n runAction(functionReference, encodedArgs),\n );\n\nexport const ActionRunner = Context.GenericTag<ReturnType<typeof make>>(\n \"@confect/server/ActionRunner\",\n);\nexport type ActionRunner = typeof ActionRunner.Identifier;\n\nexport const layer = (runAction: GenericActionCtx<any>[\"runAction\"]) =>\n Layer.succeed(ActionRunner, make(runAction));\n"],"mappings":";;;;;;;;;;AAKA,MAAM,QACH,eAEC,QACA,GAAG,SAKHA,MAAI,aACF,QACC,KAAK,MAAM,EAAE,GACb,mBAAmB,gBAClB,UAAU,mBAAmB,YAAY,CAC5C;AAEL,MAAa,eAAe,QAAQ,WAClC,+BACD;AAGD,MAAa,SAAS,cACpB,MAAM,QAAQ,cAAc,KAAK,UAAU,CAAC"}
|
package/dist/DatabaseReader.d.ts
CHANGED
|
@@ -9,8 +9,8 @@ import { Context, Layer } from "effect";
|
|
|
9
9
|
import * as convex_server0 from "convex/server";
|
|
10
10
|
import { GenericDatabaseReader } from "convex/server";
|
|
11
11
|
import * as convex_values0 from "convex/values";
|
|
12
|
-
import * as effect_Effect0 from "effect/Effect";
|
|
13
12
|
import * as _confect_core_Types0 from "@confect/core/Types";
|
|
13
|
+
import * as effect_Effect0 from "effect/Effect";
|
|
14
14
|
|
|
15
15
|
//#region src/DatabaseReader.d.ts
|
|
16
16
|
declare namespace DatabaseReader_d_exports {
|
package/dist/Handler.d.ts
CHANGED
|
@@ -32,7 +32,7 @@ type ConfectProvenanceMutation<DatabaseSchema_ extends AnyWithProps, FunctionSpe
|
|
|
32
32
|
type ActionServices<DatabaseSchema_ extends AnyWithProps> = Scheduler | Auth | StorageReader | StorageWriter | StorageActionWriter | QueryRunner | MutationRunner | ActionRunner | VectorSearch<FromSchema<DatabaseSchema_>> | ActionCtx<ToConvex<FromSchema<DatabaseSchema_>>>;
|
|
33
33
|
type ConvexRuntimeAction<DatabaseSchema_ extends AnyWithProps, FunctionSpec_ extends FunctionSpec.AnyWithPropsWithFunctionType<RuntimeAndFunctionType.AnyAction>> = Base<FunctionSpec_, ActionServices<DatabaseSchema_>>;
|
|
34
34
|
type NodeRuntimeAction<DatabaseSchema_ extends AnyWithProps, FunctionSpec_ extends FunctionSpec.AnyWithPropsWithFunctionType<RuntimeAndFunctionType.NodeAction>> = Base<FunctionSpec_, ActionServices<DatabaseSchema_> | NodeContext.NodeContext>;
|
|
35
|
-
type Base<FunctionSpec_ extends FunctionSpec.AnyWithProps, R> = (args: FunctionSpec.Args<FunctionSpec_>) => Effect.Effect<FunctionSpec.Returns<FunctionSpec_>,
|
|
35
|
+
type Base<FunctionSpec_ extends FunctionSpec.AnyWithProps, R> = (args: FunctionSpec.Args<FunctionSpec_>) => Effect.Effect<FunctionSpec.Returns<FunctionSpec_>, FunctionSpec.Error<FunctionSpec_>, R>;
|
|
36
36
|
type Any = AnyConfectProvenance | AnyConvexProvenance;
|
|
37
37
|
type AnyConfectProvenance = Base<FunctionSpec.AnyConfect, any>;
|
|
38
38
|
type AnyConvexProvenance = Any$1;
|
package/dist/Handler.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Handler.d.ts","names":[],"sources":["../src/Handler.ts"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;KAsBY,OAAA,yBACc,YAAA,wBACF,YAAA,CAAa,YAAA,IAEnC,aAAA,SAAsB,YAAA,CAAa,sBAAA,CACjC,aAAA,EACA,kBAAA,CAAmB,SAAA,IAEjB,uBAAA,CAAwB,aAAA,IACxB,aAAA,SAAsB,YAAA,CAAa,sBAAA,CAC/B,aAAA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AuB,UAAA,KACjE,IAAA,CACF,aAAA,EACA,cAAA,CAAe,eAAA,IAAmB,WAAA,CAAY,WAAA;AAAA,KAG3C,IAAA,uBAA2B,YAAA,CAAa,YAAA,QAC3C,IAAA,EAAM,YAAA,CAAa,IAAA,CAAK,aAAA,MACrB,MAAA,CAAO,MAAA,CACV,YAAA,CAAa,OAAA,CAAQ,aAAA,GACrB,YAAA,CAAa,KAAA,CAAM,aAAA,GACnB,CAAA;AAAA,KAGU,GAAA,GAAM,oBAAA,GAAuB,mBAAA;AAAA,KAE7B,oBAAA,GAAuB,IAAA,CAAK,YAAA,CAAa,UAAA;AAAA,KAEzC,mBAAA,GAAsB,KAAA;AAAA,KAEtB,QAAA,yBACc,YAAA,wBACF,YAAA,CAAa,YAAA,iCAEjC,OAAA,CACF,eAAA,EACA,YAAA,CAAa,QAAA,CAAS,aAAA,EAAe,YAAA"}
|
package/dist/Handler.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Handler.js","names":[],"sources":["../src/Handler.ts"],"sourcesContent":["import type { FunctionSpec, RuntimeAndFunctionType } from \"@confect/core\";\nimport type * as FunctionProvenance from \"@confect/core/FunctionProvenance\";\nimport type { NodeContext } from \"@effect/platform-node\";\nimport type { Effect } from \"effect\";\nimport type * as ActionCtx from \"./ActionCtx\";\nimport type * as ActionRunner from \"./ActionRunner\";\nimport type * as Auth from \"./Auth\";\nimport type * as DatabaseReader from \"./DatabaseReader\";\nimport type * as DatabaseSchema from \"./DatabaseSchema\";\nimport type * as DatabaseWriter from \"./DatabaseWriter\";\nimport type * as DataModel from \"./DataModel\";\nimport type * as MutationCtx from \"./MutationCtx\";\nimport type * as MutationRunner from \"./MutationRunner\";\nimport type * as QueryCtx from \"./QueryCtx\";\nimport type * as QueryRunner from \"./QueryRunner\";\nimport type * as RegisteredFunction from \"./RegisteredFunction\";\nimport type * as Scheduler from \"./Scheduler\";\nimport type { StorageActionWriter } from \"./StorageActionWriter\";\nimport type { StorageReader } from \"./StorageReader\";\nimport type { StorageWriter } from \"./StorageWriter\";\nimport type * as VectorSearch from \"./VectorSearch\";\n\nexport type Handler<\n DatabaseSchema_ extends DatabaseSchema.AnyWithProps,\n FunctionSpec_ extends FunctionSpec.AnyWithProps,\n> =\n FunctionSpec_ extends FunctionSpec.WithFunctionProvenance<\n FunctionSpec_,\n FunctionProvenance.AnyConvex\n >\n ? ConvexProvenanceHandler<FunctionSpec_>\n : FunctionSpec_ extends FunctionSpec.WithFunctionProvenance<\n FunctionSpec_,\n FunctionProvenance.AnyConfect\n >\n ? ConfectProvenanceHandler<DatabaseSchema_, FunctionSpec_>\n : never;\n\ntype ConvexProvenanceHandler<\n FunctionSpec_ extends\n FunctionSpec.AnyWithPropsWithFunctionProvenance<FunctionProvenance.AnyConvex>,\n> = RegisteredFunction.ConvexRegisteredFunction<FunctionSpec_>;\n\ntype ConfectProvenanceHandler<\n DatabaseSchema_ extends DatabaseSchema.AnyWithProps,\n FunctionSpec_ extends\n FunctionSpec.AnyWithPropsWithFunctionProvenance<FunctionProvenance.AnyConfect>,\n> =\n FunctionSpec_ extends FunctionSpec.WithFunctionType<FunctionSpec_, \"query\">\n ? ConfectProvenanceQuery<DatabaseSchema_, FunctionSpec_>\n : FunctionSpec_ extends FunctionSpec.WithFunctionType<\n FunctionSpec_,\n \"mutation\"\n >\n ? ConfectProvenanceMutation<DatabaseSchema_, FunctionSpec_>\n : FunctionSpec_ extends FunctionSpec.WithRuntimeAndFunctionType<\n FunctionSpec_,\n RuntimeAndFunctionType.ConvexAction\n >\n ? ConvexRuntimeAction<DatabaseSchema_, FunctionSpec_>\n : FunctionSpec_ extends FunctionSpec.WithRuntimeAndFunctionType<\n FunctionSpec_,\n RuntimeAndFunctionType.NodeAction\n >\n ? NodeRuntimeAction<DatabaseSchema_, FunctionSpec_>\n : never;\n\nexport type ConfectProvenanceQuery<\n DatabaseSchema_ extends DatabaseSchema.AnyWithProps,\n FunctionSpec_ extends\n FunctionSpec.AnyWithPropsWithFunctionType<RuntimeAndFunctionType.AnyQuery>,\n> = Base<\n FunctionSpec_,\n | DatabaseReader.DatabaseReader<DatabaseSchema_>\n | Auth.Auth\n | StorageReader\n | QueryRunner.QueryRunner\n | QueryCtx.QueryCtx<DataModel.ToConvex<DataModel.FromSchema<DatabaseSchema_>>>\n>;\n\nexport type ConfectProvenanceMutation<\n DatabaseSchema_ extends DatabaseSchema.AnyWithProps,\n FunctionSpec_ extends\n FunctionSpec.AnyWithPropsWithFunctionType<RuntimeAndFunctionType.AnyMutation>,\n> = Base<\n FunctionSpec_,\n | DatabaseReader.DatabaseReader<DatabaseSchema_>\n | DatabaseWriter.DatabaseWriter<DatabaseSchema_>\n | Auth.Auth\n | Scheduler.Scheduler\n | StorageReader\n | StorageWriter\n | QueryRunner.QueryRunner\n | MutationRunner.MutationRunner\n | MutationCtx.MutationCtx<\n DataModel.ToConvex<DataModel.FromSchema<DatabaseSchema_>>\n >\n>;\n\ntype ActionServices<DatabaseSchema_ extends DatabaseSchema.AnyWithProps> =\n | Scheduler.Scheduler\n | Auth.Auth\n | StorageReader\n | StorageWriter\n | StorageActionWriter\n | QueryRunner.QueryRunner\n | MutationRunner.MutationRunner\n | ActionRunner.ActionRunner\n | VectorSearch.VectorSearch<DataModel.FromSchema<DatabaseSchema_>>\n | ActionCtx.ActionCtx<\n DataModel.ToConvex<DataModel.FromSchema<DatabaseSchema_>>\n >;\n\nexport type ConvexRuntimeAction<\n DatabaseSchema_ extends DatabaseSchema.AnyWithProps,\n FunctionSpec_ extends\n FunctionSpec.AnyWithPropsWithFunctionType<RuntimeAndFunctionType.AnyAction>,\n> = Base<FunctionSpec_, ActionServices<DatabaseSchema_>>;\n\nexport type NodeRuntimeAction<\n DatabaseSchema_ extends DatabaseSchema.AnyWithProps,\n FunctionSpec_ extends\n FunctionSpec.AnyWithPropsWithFunctionType<RuntimeAndFunctionType.NodeAction>,\n> = Base<\n FunctionSpec_,\n ActionServices<DatabaseSchema_> | NodeContext.NodeContext\n>;\n\ntype Base<FunctionSpec_ extends FunctionSpec.AnyWithProps, R> = (\n args: FunctionSpec.Args<FunctionSpec_>,\n) => Effect.Effect
|
|
1
|
+
{"version":3,"file":"Handler.js","names":[],"sources":["../src/Handler.ts"],"sourcesContent":["import type { FunctionSpec, RuntimeAndFunctionType } from \"@confect/core\";\nimport type * as FunctionProvenance from \"@confect/core/FunctionProvenance\";\nimport type { NodeContext } from \"@effect/platform-node\";\nimport type { Effect } from \"effect\";\nimport type * as ActionCtx from \"./ActionCtx\";\nimport type * as ActionRunner from \"./ActionRunner\";\nimport type * as Auth from \"./Auth\";\nimport type * as DatabaseReader from \"./DatabaseReader\";\nimport type * as DatabaseSchema from \"./DatabaseSchema\";\nimport type * as DatabaseWriter from \"./DatabaseWriter\";\nimport type * as DataModel from \"./DataModel\";\nimport type * as MutationCtx from \"./MutationCtx\";\nimport type * as MutationRunner from \"./MutationRunner\";\nimport type * as QueryCtx from \"./QueryCtx\";\nimport type * as QueryRunner from \"./QueryRunner\";\nimport type * as RegisteredFunction from \"./RegisteredFunction\";\nimport type * as Scheduler from \"./Scheduler\";\nimport type { StorageActionWriter } from \"./StorageActionWriter\";\nimport type { StorageReader } from \"./StorageReader\";\nimport type { StorageWriter } from \"./StorageWriter\";\nimport type * as VectorSearch from \"./VectorSearch\";\n\nexport type Handler<\n DatabaseSchema_ extends DatabaseSchema.AnyWithProps,\n FunctionSpec_ extends FunctionSpec.AnyWithProps,\n> =\n FunctionSpec_ extends FunctionSpec.WithFunctionProvenance<\n FunctionSpec_,\n FunctionProvenance.AnyConvex\n >\n ? ConvexProvenanceHandler<FunctionSpec_>\n : FunctionSpec_ extends FunctionSpec.WithFunctionProvenance<\n FunctionSpec_,\n FunctionProvenance.AnyConfect\n >\n ? ConfectProvenanceHandler<DatabaseSchema_, FunctionSpec_>\n : never;\n\ntype ConvexProvenanceHandler<\n FunctionSpec_ extends\n FunctionSpec.AnyWithPropsWithFunctionProvenance<FunctionProvenance.AnyConvex>,\n> = RegisteredFunction.ConvexRegisteredFunction<FunctionSpec_>;\n\ntype ConfectProvenanceHandler<\n DatabaseSchema_ extends DatabaseSchema.AnyWithProps,\n FunctionSpec_ extends\n FunctionSpec.AnyWithPropsWithFunctionProvenance<FunctionProvenance.AnyConfect>,\n> =\n FunctionSpec_ extends FunctionSpec.WithFunctionType<FunctionSpec_, \"query\">\n ? ConfectProvenanceQuery<DatabaseSchema_, FunctionSpec_>\n : FunctionSpec_ extends FunctionSpec.WithFunctionType<\n FunctionSpec_,\n \"mutation\"\n >\n ? ConfectProvenanceMutation<DatabaseSchema_, FunctionSpec_>\n : FunctionSpec_ extends FunctionSpec.WithRuntimeAndFunctionType<\n FunctionSpec_,\n RuntimeAndFunctionType.ConvexAction\n >\n ? ConvexRuntimeAction<DatabaseSchema_, FunctionSpec_>\n : FunctionSpec_ extends FunctionSpec.WithRuntimeAndFunctionType<\n FunctionSpec_,\n RuntimeAndFunctionType.NodeAction\n >\n ? NodeRuntimeAction<DatabaseSchema_, FunctionSpec_>\n : never;\n\nexport type ConfectProvenanceQuery<\n DatabaseSchema_ extends DatabaseSchema.AnyWithProps,\n FunctionSpec_ extends\n FunctionSpec.AnyWithPropsWithFunctionType<RuntimeAndFunctionType.AnyQuery>,\n> = Base<\n FunctionSpec_,\n | DatabaseReader.DatabaseReader<DatabaseSchema_>\n | Auth.Auth\n | StorageReader\n | QueryRunner.QueryRunner\n | QueryCtx.QueryCtx<DataModel.ToConvex<DataModel.FromSchema<DatabaseSchema_>>>\n>;\n\nexport type ConfectProvenanceMutation<\n DatabaseSchema_ extends DatabaseSchema.AnyWithProps,\n FunctionSpec_ extends\n FunctionSpec.AnyWithPropsWithFunctionType<RuntimeAndFunctionType.AnyMutation>,\n> = Base<\n FunctionSpec_,\n | DatabaseReader.DatabaseReader<DatabaseSchema_>\n | DatabaseWriter.DatabaseWriter<DatabaseSchema_>\n | Auth.Auth\n | Scheduler.Scheduler\n | StorageReader\n | StorageWriter\n | QueryRunner.QueryRunner\n | MutationRunner.MutationRunner\n | MutationCtx.MutationCtx<\n DataModel.ToConvex<DataModel.FromSchema<DatabaseSchema_>>\n >\n>;\n\ntype ActionServices<DatabaseSchema_ extends DatabaseSchema.AnyWithProps> =\n | Scheduler.Scheduler\n | Auth.Auth\n | StorageReader\n | StorageWriter\n | StorageActionWriter\n | QueryRunner.QueryRunner\n | MutationRunner.MutationRunner\n | ActionRunner.ActionRunner\n | VectorSearch.VectorSearch<DataModel.FromSchema<DatabaseSchema_>>\n | ActionCtx.ActionCtx<\n DataModel.ToConvex<DataModel.FromSchema<DatabaseSchema_>>\n >;\n\nexport type ConvexRuntimeAction<\n DatabaseSchema_ extends DatabaseSchema.AnyWithProps,\n FunctionSpec_ extends\n FunctionSpec.AnyWithPropsWithFunctionType<RuntimeAndFunctionType.AnyAction>,\n> = Base<FunctionSpec_, ActionServices<DatabaseSchema_>>;\n\nexport type NodeRuntimeAction<\n DatabaseSchema_ extends DatabaseSchema.AnyWithProps,\n FunctionSpec_ extends\n FunctionSpec.AnyWithPropsWithFunctionType<RuntimeAndFunctionType.NodeAction>,\n> = Base<\n FunctionSpec_,\n ActionServices<DatabaseSchema_> | NodeContext.NodeContext\n>;\n\ntype Base<FunctionSpec_ extends FunctionSpec.AnyWithProps, R> = (\n args: FunctionSpec.Args<FunctionSpec_>,\n) => Effect.Effect<\n FunctionSpec.Returns<FunctionSpec_>,\n FunctionSpec.Error<FunctionSpec_>,\n R\n>;\n\nexport type Any = AnyConfectProvenance | AnyConvexProvenance;\n\nexport type AnyConfectProvenance = Base<FunctionSpec.AnyConfect, any>;\n\nexport type AnyConvexProvenance = RegisteredFunction.Any;\n\nexport type WithName<\n DatabaseSchema_ extends DatabaseSchema.AnyWithProps,\n FunctionSpec_ extends FunctionSpec.AnyWithProps,\n FunctionName extends string,\n> = Handler<\n DatabaseSchema_,\n FunctionSpec.WithName<FunctionSpec_, FunctionName>\n>;\n"],"mappings":""}
|
package/dist/MutationRunner.d.ts
CHANGED
|
@@ -1,25 +1,14 @@
|
|
|
1
|
-
import { Context, Layer,
|
|
1
|
+
import { Context, Effect, Layer, ParseResult } from "effect";
|
|
2
2
|
import * as Ref$1 from "@confect/core/Ref";
|
|
3
3
|
import { GenericMutationCtx } from "convex/server";
|
|
4
|
-
import * as effect_ParseResult0 from "effect/ParseResult";
|
|
5
|
-
import * as effect_Effect0 from "effect/Effect";
|
|
6
4
|
|
|
7
5
|
//#region src/MutationRunner.d.ts
|
|
8
6
|
declare namespace MutationRunner_d_exports {
|
|
9
|
-
export {
|
|
7
|
+
export { MutationRunner, layer };
|
|
10
8
|
}
|
|
11
|
-
declare const MutationRunner: Context.Tag<(<Mutation extends Ref$1.AnyMutation>(mutation: Mutation, ...args: Ref$1.OptionalArgs<Mutation>) =>
|
|
9
|
+
declare const MutationRunner: Context.Tag<(<Mutation extends Ref$1.AnyMutation>(mutation: Mutation, ...args: Ref$1.OptionalArgs<Mutation>) => Effect.Effect<Ref$1.Returns<Mutation>, Ref$1.Error<Mutation> | ParseResult.ParseError>), <Mutation extends Ref$1.AnyMutation>(mutation: Mutation, ...args: Ref$1.OptionalArgs<Mutation>) => Effect.Effect<Ref$1.Returns<Mutation>, Ref$1.Error<Mutation> | ParseResult.ParseError>>;
|
|
12
10
|
type MutationRunner = typeof MutationRunner.Identifier;
|
|
13
|
-
declare const layer: (runMutation: GenericMutationCtx<any>["runMutation"]) => Layer.Layer<(<Mutation extends Ref$1.AnyMutation>(mutation: Mutation, ...args: Ref$1.OptionalArgs<Mutation>) =>
|
|
14
|
-
declare const MutationRollback_base: Schema.TaggedErrorClass<MutationRollback, "MutationRollback", {
|
|
15
|
-
readonly _tag: Schema.tag<"MutationRollback">;
|
|
16
|
-
} & {
|
|
17
|
-
mutationName: typeof Schema.String;
|
|
18
|
-
error: typeof Schema.Unknown;
|
|
19
|
-
}>;
|
|
20
|
-
declare class MutationRollback extends MutationRollback_base {
|
|
21
|
-
get message(): string;
|
|
22
|
-
}
|
|
11
|
+
declare const layer: (runMutation: GenericMutationCtx<any>["runMutation"]) => Layer.Layer<(<Mutation extends Ref$1.AnyMutation>(mutation: Mutation, ...args: Ref$1.OptionalArgs<Mutation>) => Effect.Effect<Ref$1.Returns<Mutation>, Ref$1.Error<Mutation> | ParseResult.ParseError>), never, never>;
|
|
23
12
|
//#endregion
|
|
24
|
-
export {
|
|
13
|
+
export { MutationRunner, MutationRunner_d_exports, layer };
|
|
25
14
|
//# sourceMappingURL=MutationRunner.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MutationRunner.d.ts","names":[],"sources":["../src/MutationRunner.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"MutationRunner.d.ts","names":[],"sources":["../src/MutationRunner.ts"],"mappings":";;;;;;;;cAqBa,cAAA,EAAc,OAAA,CAAA,GAAA,oBAdP,KAAA,CAAI,WAAA,EAAW,QAAA,EACrB,QAAA,KAAQ,IAAA,EACT,KAAA,CAAI,YAAA,CAAa,QAAA,MACzB,MAAA,CAAO,MAAA,CACR,KAAA,CAAI,OAAA,CAAQ,QAAA,GACZ,KAAA,CAAI,KAAA,CAAM,QAAA,IAAY,WAAA,CAAY,UAAA,sBALlB,KAAA,CAAI,WAAA,EAAW,QAAA,EACrB,QAAA,KAAQ,IAAA,EACT,KAAA,CAAI,YAAA,CAAa,QAAA,MACzB,MAAA,CAAO,MAAA,CACR,KAAA,CAAI,OAAA,CAAQ,QAAA,GACZ,KAAA,CAAI,KAAA,CAAM,QAAA,IAAY,WAAA,CAAY,UAAA;AAAA,KAY1B,cAAA,UAAwB,cAAA,CAAe,UAAA;AAAA,cAEtC,KAAA,GAAS,WAAA,EAAa,kBAAA,yBAAsC,KAAA,CAAA,KAAA,oBAnBrD,KAAA,CAAI,WAAA,EAAW,QAAA,EACrB,QAAA,KAAQ,IAAA,EACT,KAAA,CAAI,YAAA,CAAa,QAAA,MACzB,MAAA,CAAO,MAAA,CACR,KAAA,CAAI,OAAA,CAAQ,QAAA,GACZ,KAAA,CAAI,KAAA,CAAM,QAAA,IAAY,WAAA,CAAY,UAAA"}
|
package/dist/MutationRunner.js
CHANGED
|
@@ -1,27 +1,17 @@
|
|
|
1
1
|
import { __exportAll } from "./_virtual/_rolldown/runtime.js";
|
|
2
|
-
import { Context, Layer
|
|
2
|
+
import { Context, Layer } from "effect";
|
|
3
3
|
import * as Ref$1 from "@confect/core/Ref";
|
|
4
4
|
import "convex/server";
|
|
5
5
|
|
|
6
6
|
//#region src/MutationRunner.ts
|
|
7
7
|
var MutationRunner_exports = /* @__PURE__ */ __exportAll({
|
|
8
|
-
MutationRollback: () => MutationRollback,
|
|
9
8
|
MutationRunner: () => MutationRunner,
|
|
10
9
|
layer: () => layer
|
|
11
10
|
});
|
|
12
11
|
const make = (runMutation) => (mutation, ...args) => Ref$1.runWithCodec(mutation, args[0] ?? {}, (functionReference, encodedArgs) => runMutation(functionReference, encodedArgs));
|
|
13
12
|
const MutationRunner = Context.GenericTag("@confect/server/MutationRunner");
|
|
14
13
|
const layer = (runMutation) => Layer.succeed(MutationRunner, make(runMutation));
|
|
15
|
-
var MutationRollback = class extends Schema.TaggedError()("MutationRollback", {
|
|
16
|
-
mutationName: Schema.String,
|
|
17
|
-
error: Schema.Unknown
|
|
18
|
-
}) {
|
|
19
|
-
/* v8 ignore start */
|
|
20
|
-
get message() {
|
|
21
|
-
return `Mutation ${this.mutationName} failed and was rolled back.\n\n${this.error}`;
|
|
22
|
-
}
|
|
23
|
-
};
|
|
24
14
|
|
|
25
15
|
//#endregion
|
|
26
|
-
export {
|
|
16
|
+
export { MutationRunner, MutationRunner_exports, layer };
|
|
27
17
|
//# sourceMappingURL=MutationRunner.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MutationRunner.js","names":["Ref"],"sources":["../src/MutationRunner.ts"],"sourcesContent":["import * as Ref from \"@confect/core/Ref\";\nimport { type GenericMutationCtx } from \"convex/server\";\nimport { Context, Layer
|
|
1
|
+
{"version":3,"file":"MutationRunner.js","names":["Ref"],"sources":["../src/MutationRunner.ts"],"sourcesContent":["import * as Ref from \"@confect/core/Ref\";\nimport { type GenericMutationCtx } from \"convex/server\";\nimport type { ParseResult, Effect } from \"effect\";\nimport { Context, Layer } from \"effect\";\n\nconst make =\n (runMutation: GenericMutationCtx<any>[\"runMutation\"]) =>\n <Mutation extends Ref.AnyMutation>(\n mutation: Mutation,\n ...args: Ref.OptionalArgs<Mutation>\n ): Effect.Effect<\n Ref.Returns<Mutation>,\n Ref.Error<Mutation> | ParseResult.ParseError\n > =>\n Ref.runWithCodec(\n mutation,\n (args[0] ?? {}) as Ref.Args<Mutation>,\n (functionReference, encodedArgs) =>\n runMutation(functionReference, encodedArgs),\n );\n\nexport const MutationRunner = Context.GenericTag<ReturnType<typeof make>>(\n \"@confect/server/MutationRunner\",\n);\nexport type MutationRunner = typeof MutationRunner.Identifier;\n\nexport const layer = (runMutation: GenericMutationCtx<any>[\"runMutation\"]) =>\n Layer.succeed(MutationRunner, make(runMutation));\n"],"mappings":";;;;;;;;;;AAKA,MAAM,QACH,iBAEC,UACA,GAAG,SAKHA,MAAI,aACF,UACC,KAAK,MAAM,EAAE,GACb,mBAAmB,gBAClB,YAAY,mBAAmB,YAAY,CAC9C;AAEL,MAAa,iBAAiB,QAAQ,WACpC,iCACD;AAGD,MAAa,SAAS,gBACpB,MAAM,QAAQ,gBAAgB,KAAK,YAAY,CAAC"}
|
package/dist/QueryRunner.d.ts
CHANGED
|
@@ -1,16 +1,14 @@
|
|
|
1
|
-
import { Context, Layer } from "effect";
|
|
1
|
+
import { Context, Effect, Layer, ParseResult } from "effect";
|
|
2
2
|
import * as Ref$1 from "@confect/core/Ref";
|
|
3
3
|
import { GenericQueryCtx } from "convex/server";
|
|
4
|
-
import * as effect_ParseResult0 from "effect/ParseResult";
|
|
5
|
-
import * as effect_Effect0 from "effect/Effect";
|
|
6
4
|
|
|
7
5
|
//#region src/QueryRunner.d.ts
|
|
8
6
|
declare namespace QueryRunner_d_exports {
|
|
9
7
|
export { QueryRunner, layer };
|
|
10
8
|
}
|
|
11
|
-
declare const QueryRunner: Context.Tag<(<Query extends Ref$1.AnyQuery>(query: Query, ...args: Ref$1.OptionalArgs<Query>) =>
|
|
9
|
+
declare const QueryRunner: Context.Tag<(<Query extends Ref$1.AnyQuery>(query: Query, ...args: Ref$1.OptionalArgs<Query>) => Effect.Effect<Ref$1.Returns<Query>, Ref$1.Error<Query> | ParseResult.ParseError>), <Query extends Ref$1.AnyQuery>(query: Query, ...args: Ref$1.OptionalArgs<Query>) => Effect.Effect<Ref$1.Returns<Query>, Ref$1.Error<Query> | ParseResult.ParseError>>;
|
|
12
10
|
type QueryRunner = typeof QueryRunner.Identifier;
|
|
13
|
-
declare const layer: (runQuery: GenericQueryCtx<any>["runQuery"]) => Layer.Layer<(<Query extends Ref$1.AnyQuery>(query: Query, ...args: Ref$1.OptionalArgs<Query>) =>
|
|
11
|
+
declare const layer: (runQuery: GenericQueryCtx<any>["runQuery"]) => Layer.Layer<(<Query extends Ref$1.AnyQuery>(query: Query, ...args: Ref$1.OptionalArgs<Query>) => Effect.Effect<Ref$1.Returns<Query>, Ref$1.Error<Query> | ParseResult.ParseError>), never, never>;
|
|
14
12
|
//#endregion
|
|
15
13
|
export { QueryRunner, QueryRunner_d_exports, layer };
|
|
16
14
|
//# sourceMappingURL=QueryRunner.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"QueryRunner.d.ts","names":[],"sources":["../src/QueryRunner.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"QueryRunner.d.ts","names":[],"sources":["../src/QueryRunner.ts"],"mappings":";;;;;;;;cAqBa,WAAA,EAAW,OAAA,CAAA,GAAA,iBAdP,KAAA,CAAI,QAAA,EAAQ,KAAA,EAClB,KAAA,KAAK,IAAA,EACH,KAAA,CAAI,YAAA,CAAa,KAAA,MACzB,MAAA,CAAO,MAAA,CACR,KAAA,CAAI,OAAA,CAAQ,KAAA,GACZ,KAAA,CAAI,KAAA,CAAM,KAAA,IAAS,WAAA,CAAY,UAAA,mBALlB,KAAA,CAAI,QAAA,EAAQ,KAAA,EAClB,KAAA,KAAK,IAAA,EACH,KAAA,CAAI,YAAA,CAAa,KAAA,MACzB,MAAA,CAAO,MAAA,CACR,KAAA,CAAI,OAAA,CAAQ,KAAA,GACZ,KAAA,CAAI,KAAA,CAAM,KAAA,IAAS,WAAA,CAAY,UAAA;AAAA,KAYvB,WAAA,UAAqB,WAAA,CAAY,UAAA;AAAA,cAEhC,KAAA,GAAS,QAAA,EAAU,eAAA,sBAAgC,KAAA,CAAA,KAAA,iBAnB/C,KAAA,CAAI,QAAA,EAAQ,KAAA,EAClB,KAAA,KAAK,IAAA,EACH,KAAA,CAAI,YAAA,CAAa,KAAA,MACzB,MAAA,CAAO,MAAA,CACR,KAAA,CAAI,OAAA,CAAQ,KAAA,GACZ,KAAA,CAAI,KAAA,CAAM,KAAA,IAAS,WAAA,CAAY,UAAA"}
|
package/dist/QueryRunner.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"QueryRunner.js","names":["Ref"],"sources":["../src/QueryRunner.ts"],"sourcesContent":["import * as Ref from \"@confect/core/Ref\";\nimport { type GenericQueryCtx } from \"convex/server\";\nimport { Context, Layer } from \"effect\";\n\nconst make =\n (runQuery: GenericQueryCtx<any>[\"runQuery\"]) =>\n <Query extends Ref.AnyQuery>(\n query: Query,\n ...args: Ref.OptionalArgs<Query>\n ) =>\n Ref.runWithCodec(\n query,\n (args[0] ?? {}) as Ref.Args<Query>,\n (functionReference, encodedArgs) =>\n runQuery(functionReference, encodedArgs),\n );\n\nexport const QueryRunner = Context.GenericTag<ReturnType<typeof make>>(\n \"@confect/server/QueryRunner\",\n);\nexport type QueryRunner = typeof QueryRunner.Identifier;\n\nexport const layer = (runQuery: GenericQueryCtx<any>[\"runQuery\"]) =>\n Layer.succeed(QueryRunner, make(runQuery));\n"],"mappings":";;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"QueryRunner.js","names":["Ref"],"sources":["../src/QueryRunner.ts"],"sourcesContent":["import * as Ref from \"@confect/core/Ref\";\nimport { type GenericQueryCtx } from \"convex/server\";\nimport type { ParseResult, Effect } from \"effect\";\nimport { Context, Layer } from \"effect\";\n\nconst make =\n (runQuery: GenericQueryCtx<any>[\"runQuery\"]) =>\n <Query extends Ref.AnyQuery>(\n query: Query,\n ...args: Ref.OptionalArgs<Query>\n ): Effect.Effect<\n Ref.Returns<Query>,\n Ref.Error<Query> | ParseResult.ParseError\n > =>\n Ref.runWithCodec(\n query,\n (args[0] ?? {}) as Ref.Args<Query>,\n (functionReference, encodedArgs) =>\n runQuery(functionReference, encodedArgs),\n );\n\nexport const QueryRunner = Context.GenericTag<ReturnType<typeof make>>(\n \"@confect/server/QueryRunner\",\n);\nexport type QueryRunner = typeof QueryRunner.Identifier;\n\nexport const layer = (runQuery: GenericQueryCtx<any>[\"runQuery\"]) =>\n Layer.succeed(QueryRunner, make(runQuery));\n"],"mappings":";;;;;;;;;;AAKA,MAAM,QACH,cAEC,OACA,GAAG,SAKHA,MAAI,aACF,OACC,KAAK,MAAM,EAAE,GACb,mBAAmB,gBAClB,SAAS,mBAAmB,YAAY,CAC3C;AAEL,MAAa,cAAc,QAAQ,WACjC,8BACD;AAGD,MAAa,SAAS,aACpB,MAAM,QAAQ,aAAa,KAAK,SAAS,CAAC"}
|
|
@@ -22,8 +22,8 @@ import * as _confect_core_Ref0 from "@confect/core/Ref";
|
|
|
22
22
|
import * as convex_server0 from "convex/server";
|
|
23
23
|
import { GenericMutationCtx } from "convex/server";
|
|
24
24
|
import * as convex_values0 from "convex/values";
|
|
25
|
-
import * as effect_ParseResult0 from "effect/ParseResult";
|
|
26
25
|
import * as _confect_core_Types0 from "@confect/core/Types";
|
|
26
|
+
import * as effect_ParseResult0 from "effect/ParseResult";
|
|
27
27
|
import * as effect_Duration0 from "effect/Duration";
|
|
28
28
|
import * as effect_DateTime0 from "effect/DateTime";
|
|
29
29
|
|
|
@@ -35,10 +35,7 @@ declare const make: <Api_ extends AnyWithPropsWithRuntime<"Convex">>(api: Api_,
|
|
|
35
35
|
functionSpec,
|
|
36
36
|
handler
|
|
37
37
|
}: AnyWithProps$1) => Any;
|
|
38
|
-
declare const mutationLayer: <Schema extends AnyWithProps>(schema: Schema, ctx: GenericMutationCtx<ToConvex<FromSchema<Schema>>>) => Layer.Layer<{
|
|
39
|
-
runAfter: <Ref_ extends _confect_core_Ref0.AnyMutation | _confect_core_Ref0.AnyAction>(delay: effect_Duration0.Duration, ref: Ref_, ...args: _confect_core_Ref0.OptionalArgs<Ref_>) => Effect.Effect<convex_values0.GenericId<"_scheduled_functions">, never, never>;
|
|
40
|
-
runAt: <Ref_ extends _confect_core_Ref0.AnyMutation | _confect_core_Ref0.AnyAction>(dateTime: effect_DateTime0.DateTime, ref: Ref_, ...args: _confect_core_Ref0.OptionalArgs<Ref_>) => Effect.Effect<convex_values0.GenericId<"_scheduled_functions">, never, never>;
|
|
41
|
-
} | Auth$1 | StorageReader$1 | StorageWriter$1 | (<Query extends _confect_core_Ref0.AnyQuery>(query: Query, ...args: _confect_core_Ref0.OptionalArgs<Query>) => Effect.Effect<_confect_core_Ref0.Returns<Query>, effect_ParseResult0.ParseError, never>) | (<Mutation extends _confect_core_Ref0.AnyMutation>(mutation: Mutation, ...args: _confect_core_Ref0.OptionalArgs<Mutation>) => Effect.Effect<_confect_core_Ref0.Returns<Mutation>, effect_ParseResult0.ParseError, never>) | GenericMutationCtx<ToConvex<FromSchema<Schema>>> | {
|
|
38
|
+
declare const mutationLayer: <Schema extends AnyWithProps>(schema: Schema, ctx: GenericMutationCtx<ToConvex<FromSchema<Schema>>>) => Layer.Layer<Auth$1 | StorageReader$1 | StorageWriter$1 | (<Query extends _confect_core_Ref0.AnyQuery>(query: Query, ...args: _confect_core_Ref0.OptionalArgs<Query>) => Effect.Effect<_confect_core_Ref0.Returns<Query>, _confect_core_Ref0.Error<Query> | effect_ParseResult0.ParseError>) | GenericMutationCtx<ToConvex<FromSchema<Schema>>> | {
|
|
42
39
|
table: <const TableName extends Name<IncludeSystemTables<Tables<Schema>>>>(tableName: TableName) => {
|
|
43
40
|
readonly get: {
|
|
44
41
|
(id: convex_values0.GenericId<TableName>): Effect.Effect<TableInfo<WithName<IncludeSystemTables<Tables<Schema>>, TableName>>["document"], DocumentDecodeError | GetByIdFailure, never>;
|
|
@@ -57,7 +54,10 @@ declare const mutationLayer: <Schema extends AnyWithProps>(schema: Schema, ctx:
|
|
|
57
54
|
replace: (id: convex_values0.GenericId<TableName>, value: convex_server0.Expand<convex_server0.BetterOmit<DocumentByName<FromSchema<Schema>, TableName>, "_id" | "_creationTime">>) => Effect.Effect<void, DocumentEncodeError, never>;
|
|
58
55
|
delete: (id: convex_values0.GenericId<TableName>) => Effect.Effect<void, never, never>;
|
|
59
56
|
};
|
|
60
|
-
}
|
|
57
|
+
} | {
|
|
58
|
+
runAfter: <Ref_ extends _confect_core_Ref0.AnyMutation | _confect_core_Ref0.AnyAction>(delay: effect_Duration0.Duration, ref: Ref_, ...args: _confect_core_Ref0.OptionalArgs<Ref_>) => Effect.Effect<convex_values0.GenericId<"_scheduled_functions">, never, never>;
|
|
59
|
+
runAt: <Ref_ extends _confect_core_Ref0.AnyMutation | _confect_core_Ref0.AnyAction>(dateTime: effect_DateTime0.DateTime, ref: Ref_, ...args: _confect_core_Ref0.OptionalArgs<Ref_>) => Effect.Effect<convex_values0.GenericId<"_scheduled_functions">, never, never>;
|
|
60
|
+
} | (<Mutation extends _confect_core_Ref0.AnyMutation>(mutation: Mutation, ...args: _confect_core_Ref0.OptionalArgs<Mutation>) => Effect.Effect<_confect_core_Ref0.Returns<Mutation>, _confect_core_Ref0.Error<Mutation> | effect_ParseResult0.ParseError>), never, never>;
|
|
61
61
|
type MutationServices<Schema extends AnyWithProps> = DatabaseReader<Schema> | DatabaseWriter<Schema> | Auth$1 | Scheduler$1 | StorageReader$1 | StorageWriter$1 | QueryRunner | MutationRunner | MutationCtx<ToConvex<FromSchema<Schema>>>;
|
|
62
62
|
//#endregion
|
|
63
63
|
export { MutationServices, RegisteredConvexFunction_d_exports, make, mutationLayer };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"RegisteredConvexFunction.d.ts","names":[],"sources":["../src/RegisteredConvexFunction.ts"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"RegisteredConvexFunction.d.ts","names":[],"sources":["../src/RegisteredConvexFunction.ts"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;cAiCa,IAAA,gBAAqB,uBAAA,YAChC,GAAA,EAAK,IAAA;EACL,YAAA;EAAA;AAAA,GAA2B,cAAA,KAC1B,GAAA;AAAA,cAiLU,aAAA,kBAAgC,YAAA,EAC3C,MAAA,EAAQ,MAAA,EACR,GAAA,EAAK,kBAAA,CAAmB,QAAA,CAAmB,UAAA,CAAqB,MAAA,QAAS,KAAA,CAAA,KAAA,CAAA,MAAA,GAAA,eAAA,GAAA,eAAA,mBAAA,kBAAA,CAAA,QAAA,EAAA,KAAA,EAAA,KAAA,KAAA,IAAA,EAAA,kBAAA,CAAA,YAAA,CAAA,KAAA,MAAA,MAAA,CAAA,MAAA,CAAA,kBAAA,CAAA,OAAA,CAAA,KAAA,GAAA,kBAAA,CAAA,KAAA,CAAA,KAAA,IAAA,mBAAA,CAAA,UAAA,KAAA,kBAAA,CAAA,QAAA,CAAA,UAAA,CAAA,MAAA;;;;;;;;;;;;;;;;;;;;;;;KAoB/D,gBAAA,gBAAgC,YAAA,IACxC,cAAA,CAA8B,MAAA,IAC9B,cAAA,CAA8B,MAAA,IAC9B,MAAA,GACA,WAAA,GACA,eAAA,GACA,eAAA,GACA,WAAA,GACA,cAAA,GACA,WAAA,CAAwB,QAAA,CAAmB,UAAA,CAAqB,MAAA"}
|
|
@@ -11,7 +11,7 @@ import { StorageReader as StorageReader$1 } from "./StorageReader.js";
|
|
|
11
11
|
import { StorageWriter as StorageWriter$1 } from "./StorageWriter.js";
|
|
12
12
|
import { MutationCtx } from "./MutationCtx.js";
|
|
13
13
|
import { QueryCtx } from "./QueryCtx.js";
|
|
14
|
-
import { actionFunctionBase, actionLayer } from "./RegisteredFunction.js";
|
|
14
|
+
import { actionFunctionBase, actionLayer, runHandlerPromise } from "./RegisteredFunction.js";
|
|
15
15
|
import { Clock, Effect, Layer, Match, Schema, pipe } from "effect";
|
|
16
16
|
import { actionGeneric, internalActionGeneric, internalMutationGeneric, internalQueryGeneric, mutationGeneric, queryGeneric } from "convex/server";
|
|
17
17
|
|
|
@@ -23,21 +23,26 @@ var RegisteredConvexFunction_exports = /* @__PURE__ */ __exportAll({
|
|
|
23
23
|
const make = (api, { functionSpec, handler }) => Match.value(functionSpec.functionProvenance).pipe(Match.tag("Convex", () => handler), Match.tag("Confect", () => {
|
|
24
24
|
const { functionVisibility, functionProvenance } = functionSpec;
|
|
25
25
|
return Match.value(functionSpec.runtimeAndFunctionType.functionType).pipe(Match.when("query", () => {
|
|
26
|
-
return Match.value(functionVisibility).pipe(Match.when("public", () => queryGeneric), Match.when("internal", () => internalQueryGeneric), Match.exhaustive)(queryFunction(
|
|
26
|
+
return Match.value(functionVisibility).pipe(Match.when("public", () => queryGeneric), Match.when("internal", () => internalQueryGeneric), Match.exhaustive)(queryFunction({
|
|
27
|
+
databaseSchema: api.databaseSchema,
|
|
27
28
|
args: functionProvenance.args,
|
|
28
29
|
returns: functionProvenance.returns,
|
|
30
|
+
error: functionProvenance.error,
|
|
29
31
|
handler
|
|
30
32
|
}));
|
|
31
33
|
}), Match.when("mutation", () => {
|
|
32
|
-
return Match.value(functionVisibility).pipe(Match.when("public", () => mutationGeneric), Match.when("internal", () => internalMutationGeneric), Match.exhaustive)(mutationFunction(
|
|
34
|
+
return Match.value(functionVisibility).pipe(Match.when("public", () => mutationGeneric), Match.when("internal", () => internalMutationGeneric), Match.exhaustive)(mutationFunction({
|
|
35
|
+
databaseSchema: api.databaseSchema,
|
|
33
36
|
args: functionProvenance.args,
|
|
34
37
|
returns: functionProvenance.returns,
|
|
38
|
+
error: functionProvenance.error,
|
|
35
39
|
handler
|
|
36
40
|
}));
|
|
37
41
|
}), Match.when("action", () => {
|
|
38
42
|
return Match.value(functionVisibility).pipe(Match.when("public", () => actionGeneric), Match.when("internal", () => internalActionGeneric), Match.exhaustive)(convexActionFunction(api.databaseSchema, {
|
|
39
43
|
args: functionProvenance.args,
|
|
40
44
|
returns: functionProvenance.returns,
|
|
45
|
+
error: functionProvenance.error,
|
|
41
46
|
handler
|
|
42
47
|
}));
|
|
43
48
|
}), Match.exhaustive);
|
|
@@ -64,20 +69,25 @@ const withStubbedDateNow = async (queryHandler) => {
|
|
|
64
69
|
Date.now = realDateNow;
|
|
65
70
|
}
|
|
66
71
|
};
|
|
67
|
-
const queryFunction = (databaseSchema,
|
|
72
|
+
const queryFunction = ({ databaseSchema, args, returns, error, handler }) => ({
|
|
68
73
|
args: compileArgsSchema(args),
|
|
69
74
|
returns: compileReturnsSchema(returns),
|
|
70
|
-
handler: (ctx, actualArgs) => withStubbedDateNow((clock) =>
|
|
75
|
+
handler: (ctx, actualArgs) => withStubbedDateNow((clock) => Effect.gen(function* () {
|
|
76
|
+
return yield* pipe(yield* handler(yield* pipe(actualArgs, Schema.decode(args), Effect.orDie)).pipe(Effect.provide(Layer.mergeAll(layer$1(databaseSchema, ctx.db), layer(ctx.auth), StorageReader$1.layer(ctx.storage), layer$4(ctx.runQuery), Layer.succeed(QueryCtx(), ctx), Layer.setConfigProvider(make$1())))), Schema.encode(returns), Effect.orDie);
|
|
77
|
+
}).pipe(Effect.withClock(clock), runHandlerPromise(error)))
|
|
71
78
|
});
|
|
72
79
|
const mutationLayer = (schema, ctx) => Layer.mergeAll(layer$1(schema, ctx.db), layer$2(schema, ctx.db), layer(ctx.auth), layer$5(ctx.scheduler), StorageReader$1.layer(ctx.storage), StorageWriter$1.layer(ctx.storage), layer$4(ctx.runQuery), layer$3(ctx.runMutation), Layer.succeed(MutationCtx(), ctx), Layer.setConfigProvider(make$1()));
|
|
73
|
-
const mutationFunction = (
|
|
80
|
+
const mutationFunction = ({ databaseSchema, args, returns, error, handler }) => ({
|
|
74
81
|
args: compileArgsSchema(args),
|
|
75
82
|
returns: compileReturnsSchema(returns),
|
|
76
|
-
handler: (ctx, actualArgs) =>
|
|
83
|
+
handler: (ctx, actualArgs) => Effect.gen(function* () {
|
|
84
|
+
return yield* pipe(yield* handler(yield* pipe(actualArgs, Schema.decode(args), Effect.orDie)).pipe(Effect.provide(mutationLayer(databaseSchema, ctx))), Schema.encode(returns), Effect.orDie);
|
|
85
|
+
}).pipe(runHandlerPromise(error))
|
|
77
86
|
});
|
|
78
|
-
const convexActionFunction = (schema, { args, returns, handler }) => actionFunctionBase({
|
|
87
|
+
const convexActionFunction = (schema, { args, returns, error, handler }) => actionFunctionBase({
|
|
79
88
|
args,
|
|
80
89
|
returns,
|
|
90
|
+
error,
|
|
81
91
|
handler,
|
|
82
92
|
createLayer: (ctx) => Layer.mergeAll(actionLayer(schema, ctx), Layer.setConfigProvider(make$1()))
|
|
83
93
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"RegisteredConvexFunction.js","names":["SchemaToValidator.compileArgsSchema","SchemaToValidator.compileReturnsSchema","DatabaseReader.layer","Auth.layer","StorageReader","QueryRunner.layer","QueryCtx.QueryCtx","ConvexConfigProvider.make","DatabaseWriter.layer","Scheduler.layer","StorageWriter","MutationRunner.layer","MutationCtx.MutationCtx","RegisteredFunction.actionFunctionBase","RegisteredFunction.actionLayer"],"sources":["../src/RegisteredConvexFunction.ts"],"sourcesContent":["import type * as FunctionSpec from \"@confect/core/FunctionSpec\";\nimport {\n actionGeneric,\n type DefaultFunctionArgs,\n type GenericMutationCtx,\n type GenericQueryCtx,\n internalActionGeneric,\n internalMutationGeneric,\n internalQueryGeneric,\n mutationGeneric,\n queryGeneric,\n} from \"convex/server\";\nimport { Clock, Effect, Layer, Match, pipe, Schema } from \"effect\";\nimport type * as Api from \"./Api\";\nimport * as Auth from \"./Auth\";\nimport * as ConvexConfigProvider from \"./ConvexConfigProvider\";\nimport * as DatabaseReader from \"./DatabaseReader\";\nimport type * as DatabaseSchema from \"./DatabaseSchema\";\nimport * as DatabaseWriter from \"./DatabaseWriter\";\nimport type * as DataModel from \"./DataModel\";\nimport type * as Handler from \"./Handler\";\nimport * as MutationCtx from \"./MutationCtx\";\nimport * as MutationRunner from \"./MutationRunner\";\nimport * as QueryCtx from \"./QueryCtx\";\nimport * as QueryRunner from \"./QueryRunner\";\nimport * as RegisteredFunction from \"./RegisteredFunction\";\nimport type * as RegistryItem from \"./RegistryItem\";\nimport * as Scheduler from \"./Scheduler\";\nimport * as SchemaToValidator from \"./SchemaToValidator\";\nimport { StorageReader } from \"./StorageReader\";\nimport { StorageWriter } from \"./StorageWriter\";\n\nexport const make = <Api_ extends Api.AnyWithPropsWithRuntime<\"Convex\">>(\n api: Api_,\n { functionSpec, handler }: RegistryItem.AnyWithProps,\n): RegisteredFunction.Any =>\n Match.value(functionSpec.functionProvenance).pipe(\n Match.tag(\"Convex\", () => handler as RegisteredFunction.Any),\n Match.tag(\"Confect\", () => {\n const { functionVisibility, functionProvenance } =\n functionSpec as FunctionSpec.AnyConfect;\n\n return Match.value(functionSpec.runtimeAndFunctionType.functionType).pipe(\n Match.when(\"query\", () => {\n const genericFunction = Match.value(functionVisibility).pipe(\n Match.when(\"public\", () => queryGeneric),\n Match.when(\"internal\", () => internalQueryGeneric),\n Match.exhaustive,\n );\n\n return genericFunction(\n queryFunction(api.databaseSchema, {\n args: functionProvenance.args,\n returns: functionProvenance.returns,\n handler: handler as Handler.AnyConfectProvenance,\n }),\n );\n }),\n Match.when(\"mutation\", () => {\n const genericFunction = Match.value(functionVisibility).pipe(\n Match.when(\"public\", () => mutationGeneric),\n Match.when(\"internal\", () => internalMutationGeneric),\n Match.exhaustive,\n );\n\n return genericFunction(\n mutationFunction(api.databaseSchema, {\n args: functionProvenance.args,\n returns: functionProvenance.returns,\n handler: handler as Handler.AnyConfectProvenance,\n }),\n );\n }),\n Match.when(\"action\", () => {\n const genericFunction = Match.value(functionVisibility).pipe(\n Match.when(\"public\", () => actionGeneric),\n Match.when(\"internal\", () => internalActionGeneric),\n Match.exhaustive,\n );\n\n return genericFunction(\n convexActionFunction(api.databaseSchema, {\n args: functionProvenance.args,\n returns: functionProvenance.returns,\n handler: handler as Handler.AnyConfectProvenance,\n }),\n );\n }),\n Match.exhaustive,\n );\n }),\n Match.exhaustive,\n );\n\n// Convex's query cache is invalidated by any Date.now() call during handler\n// execution. Effect's unsafeFork calls Date.now() when constructing a\n// FiberId.Runtime, which trips the cache for every confect-wrapped query. We\n// stub Date.now to 0 for the span of the handler; queries are forbidden from\n// relying on real time for correctness anyway.\n//\n// Users who explicitly want the real timestamp can still reach it via Effect's\n// Clock service (Clock.currentTimeMillis / Clock.currentTimeNanos). We provide\n// a Clock layer whose methods close over the *original* Date.now, so opting in\n// to Clock is an opt-in to worse caching — but caching is not broken by default.\nconst unpatchedClock = (realDateNow: () => number): Clock.Clock => {\n const bigint1e6 = BigInt(1_000_000);\n const unsafeCurrentTimeMillis = () => realDateNow();\n const unsafeCurrentTimeNanos = () => BigInt(realDateNow()) * bigint1e6;\n const defaultClock = Clock.make();\n return {\n ...defaultClock,\n unsafeCurrentTimeMillis,\n unsafeCurrentTimeNanos,\n currentTimeMillis: Effect.sync(unsafeCurrentTimeMillis),\n currentTimeNanos: Effect.sync(unsafeCurrentTimeNanos),\n };\n};\n\nconst withStubbedDateNow = async <T>(\n queryHandler: (clock: Clock.Clock) => Promise<T>,\n): Promise<T> => {\n const realDateNow = Date.now;\n const clock = unpatchedClock(realDateNow);\n Date.now = () => 0;\n try {\n return await queryHandler(clock);\n } finally {\n Date.now = realDateNow;\n }\n};\n\nconst queryFunction = <\n DatabaseSchema_ extends DatabaseSchema.AnyWithProps,\n Args,\n ConvexArgs extends DefaultFunctionArgs,\n Returns,\n ConvexReturns,\n E,\n>(\n databaseSchema: DatabaseSchema_,\n {\n args,\n returns,\n handler,\n }: {\n args: Schema.Schema<Args, ConvexArgs>;\n returns: Schema.Schema<Returns, ConvexReturns>;\n handler: (\n a: Args,\n ) => Effect.Effect<\n Returns,\n E,\n | DatabaseReader.DatabaseReader<DatabaseSchema_>\n | Auth.Auth\n | StorageReader\n | QueryRunner.QueryRunner\n | QueryCtx.QueryCtx<\n DataModel.ToConvex<DataModel.FromSchema<DatabaseSchema_>>\n >\n >;\n },\n) => ({\n args: SchemaToValidator.compileArgsSchema(args),\n returns: SchemaToValidator.compileReturnsSchema(returns),\n handler: (\n ctx: GenericQueryCtx<\n DataModel.ToConvex<DataModel.FromSchema<DatabaseSchema_>>\n >,\n actualArgs: ConvexArgs,\n ): Promise<ConvexReturns> =>\n withStubbedDateNow((clock) =>\n pipe(\n actualArgs,\n Schema.decode(args),\n Effect.orDie,\n Effect.andThen((decodedArgs) =>\n pipe(\n handler(decodedArgs),\n Effect.provide(\n Layer.mergeAll(\n DatabaseReader.layer(databaseSchema, ctx.db),\n Auth.layer(ctx.auth),\n StorageReader.layer(ctx.storage),\n QueryRunner.layer(ctx.runQuery),\n Layer.succeed(\n QueryCtx.QueryCtx<\n DataModel.ToConvex<DataModel.FromSchema<DatabaseSchema_>>\n >(),\n ctx,\n ),\n Layer.setConfigProvider(ConvexConfigProvider.make()),\n ),\n ),\n ),\n ),\n Effect.andThen((convexReturns) =>\n Schema.encodeUnknown(returns)(convexReturns),\n ),\n Effect.withClock(clock),\n Effect.runPromise,\n ),\n ),\n});\n\nexport const mutationLayer = <Schema extends DatabaseSchema.AnyWithProps>(\n schema: Schema,\n ctx: GenericMutationCtx<DataModel.ToConvex<DataModel.FromSchema<Schema>>>,\n) =>\n Layer.mergeAll(\n DatabaseReader.layer(schema, ctx.db),\n DatabaseWriter.layer(schema, ctx.db),\n Auth.layer(ctx.auth),\n Scheduler.layer(ctx.scheduler),\n StorageReader.layer(ctx.storage),\n StorageWriter.layer(ctx.storage),\n QueryRunner.layer(ctx.runQuery),\n MutationRunner.layer(ctx.runMutation),\n Layer.succeed(\n MutationCtx.MutationCtx<\n DataModel.ToConvex<DataModel.FromSchema<Schema>>\n >(),\n ctx,\n ),\n Layer.setConfigProvider(ConvexConfigProvider.make()),\n );\n\nexport type MutationServices<Schema extends DatabaseSchema.AnyWithProps> =\n | DatabaseReader.DatabaseReader<Schema>\n | DatabaseWriter.DatabaseWriter<Schema>\n | Auth.Auth\n | Scheduler.Scheduler\n | StorageReader\n | StorageWriter\n | QueryRunner.QueryRunner\n | MutationRunner.MutationRunner\n | MutationCtx.MutationCtx<DataModel.ToConvex<DataModel.FromSchema<Schema>>>;\n\nconst mutationFunction = <\n Schema extends DatabaseSchema.AnyWithProps,\n Args,\n ConvexArgs extends DefaultFunctionArgs,\n Returns,\n ConvexReturns,\n E,\n>(\n schema: Schema,\n {\n args,\n returns,\n handler,\n }: {\n args: Schema.Schema<Args, ConvexArgs>;\n returns: Schema.Schema<Returns, ConvexReturns>;\n handler: (a: Args) => Effect.Effect<Returns, E, MutationServices<Schema>>;\n },\n) => ({\n args: SchemaToValidator.compileArgsSchema(args),\n returns: SchemaToValidator.compileReturnsSchema(returns),\n handler: (\n ctx: GenericMutationCtx<DataModel.ToConvex<DataModel.FromSchema<Schema>>>,\n actualArgs: ConvexArgs,\n ): Promise<ConvexReturns> =>\n pipe(\n actualArgs,\n Schema.decode(args),\n Effect.orDie,\n Effect.andThen((decodedArgs) =>\n handler(decodedArgs).pipe(Effect.provide(mutationLayer(schema, ctx))),\n ),\n Effect.andThen((convexReturns) =>\n Schema.encodeUnknown(returns)(convexReturns),\n ),\n Effect.runPromise,\n ),\n});\n\nconst convexActionFunction = <\n DatabaseSchema_ extends DatabaseSchema.AnyWithProps,\n Args,\n ConvexArgs extends DefaultFunctionArgs,\n Returns,\n ConvexReturns,\n E,\n>(\n schema: DatabaseSchema_,\n {\n args,\n returns,\n handler,\n }: {\n args: Schema.Schema<Args, ConvexArgs>;\n returns: Schema.Schema<Returns, ConvexReturns>;\n handler: (\n a: Args,\n ) => Effect.Effect<\n Returns,\n E,\n RegisteredFunction.ActionServices<DatabaseSchema_>\n >;\n },\n) =>\n RegisteredFunction.actionFunctionBase({\n args,\n returns,\n handler,\n createLayer: (ctx) =>\n Layer.mergeAll(\n RegisteredFunction.actionLayer(schema, ctx),\n Layer.setConfigProvider(ConvexConfigProvider.make()),\n ),\n });\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAgCA,MAAa,QACX,KACA,EAAE,cAAc,cAEhB,MAAM,MAAM,aAAa,mBAAmB,CAAC,KAC3C,MAAM,IAAI,gBAAgB,QAAkC,EAC5D,MAAM,IAAI,iBAAiB;CACzB,MAAM,EAAE,oBAAoB,uBAC1B;AAEF,QAAO,MAAM,MAAM,aAAa,uBAAuB,aAAa,CAAC,KACnE,MAAM,KAAK,eAAe;AAOxB,SANwB,MAAM,MAAM,mBAAmB,CAAC,KACtD,MAAM,KAAK,gBAAgB,aAAa,EACxC,MAAM,KAAK,kBAAkB,qBAAqB,EAClD,MAAM,WACP,CAGC,cAAc,IAAI,gBAAgB;GAChC,MAAM,mBAAmB;GACzB,SAAS,mBAAmB;GACnB;GACV,CAAC,CACH;GACD,EACF,MAAM,KAAK,kBAAkB;AAO3B,SANwB,MAAM,MAAM,mBAAmB,CAAC,KACtD,MAAM,KAAK,gBAAgB,gBAAgB,EAC3C,MAAM,KAAK,kBAAkB,wBAAwB,EACrD,MAAM,WACP,CAGC,iBAAiB,IAAI,gBAAgB;GACnC,MAAM,mBAAmB;GACzB,SAAS,mBAAmB;GACnB;GACV,CAAC,CACH;GACD,EACF,MAAM,KAAK,gBAAgB;AAOzB,SANwB,MAAM,MAAM,mBAAmB,CAAC,KACtD,MAAM,KAAK,gBAAgB,cAAc,EACzC,MAAM,KAAK,kBAAkB,sBAAsB,EACnD,MAAM,WACP,CAGC,qBAAqB,IAAI,gBAAgB;GACvC,MAAM,mB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,EAC9BL,gBAAc,MAAM,IAAI,QAAQ,EAChCM,gBAAc,MAAM,IAAI,QAAQ,EAChCL,QAAkB,IAAI,SAAS,EAC/BM,QAAqB,IAAI,YAAY,EACrC,MAAM,QACJC,aAEG,EACH,IACD,EACD,MAAM,kBAAkBL,QAA2B,CAAC,CACrD;AAaH,MAAM,oBAQJ,QACA,EACE,MACA,SACA,eAME;CACJ,MAAMP,kBAAoC,KAAK;CAC/C,SAASC,qBAAuC,QAAQ;CACxD,UACE,KACA,eAEA,KACE,YACA,OAAO,OAAO,KAAK,EACnB,OAAO,OACP,OAAO,SAAS,gBACd,QAAQ,YAAY,CAAC,KAAK,OAAO,QAAQ,cAAc,QAAQ,IAAI,CAAC,CAAC,CACtE,EACD,OAAO,SAAS,kBACd,OAAO,cAAc,QAAQ,CAAC,cAAc,CAC7C,EACD,OAAO,WACR;CACJ;AAED,MAAM,wBAQJ,QACA,EACE,MACA,SACA,cAaFY,mBAAsC;CACpC;CACA;CACA;CACA,cAAc,QACZ,MAAM,SACJC,YAA+B,QAAQ,IAAI,EAC3C,MAAM,kBAAkBP,QAA2B,CAAC,CACrD;CACJ,CAAC"}
|
|
1
|
+
{"version":3,"file":"RegisteredConvexFunction.js","names":["SchemaToValidator.compileArgsSchema","SchemaToValidator.compileReturnsSchema","DatabaseReader.layer","Auth.layer","StorageReader","QueryRunner.layer","QueryCtx.QueryCtx","ConvexConfigProvider.make","RegisteredFunction.runHandlerPromise","DatabaseWriter.layer","Scheduler.layer","StorageWriter","MutationRunner.layer","MutationCtx.MutationCtx","RegisteredFunction.actionFunctionBase","RegisteredFunction.actionLayer"],"sources":["../src/RegisteredConvexFunction.ts"],"sourcesContent":["import type * as FunctionSpec from \"@confect/core/FunctionSpec\";\nimport {\n actionGeneric,\n type DefaultFunctionArgs,\n type GenericMutationCtx,\n type GenericQueryCtx,\n internalActionGeneric,\n internalMutationGeneric,\n internalQueryGeneric,\n mutationGeneric,\n queryGeneric,\n} from \"convex/server\";\nimport type { Value } from \"convex/values\";\nimport { Clock, Effect, Layer, Match, pipe, Schema } from \"effect\";\nimport type * as Api from \"./Api\";\nimport * as Auth from \"./Auth\";\nimport * as ConvexConfigProvider from \"./ConvexConfigProvider\";\nimport * as DatabaseReader from \"./DatabaseReader\";\nimport type * as DatabaseSchema from \"./DatabaseSchema\";\nimport * as DatabaseWriter from \"./DatabaseWriter\";\nimport type * as DataModel from \"./DataModel\";\nimport type * as Handler from \"./Handler\";\nimport * as MutationCtx from \"./MutationCtx\";\nimport * as MutationRunner from \"./MutationRunner\";\nimport * as QueryCtx from \"./QueryCtx\";\nimport * as QueryRunner from \"./QueryRunner\";\nimport * as RegisteredFunction from \"./RegisteredFunction\";\nimport type * as RegistryItem from \"./RegistryItem\";\nimport * as Scheduler from \"./Scheduler\";\nimport * as SchemaToValidator from \"./SchemaToValidator\";\nimport { StorageReader } from \"./StorageReader\";\nimport { StorageWriter } from \"./StorageWriter\";\n\nexport const make = <Api_ extends Api.AnyWithPropsWithRuntime<\"Convex\">>(\n api: Api_,\n { functionSpec, handler }: RegistryItem.AnyWithProps,\n): RegisteredFunction.Any =>\n Match.value(functionSpec.functionProvenance).pipe(\n Match.tag(\"Convex\", () => handler as RegisteredFunction.Any),\n Match.tag(\"Confect\", () => {\n const { functionVisibility, functionProvenance } =\n functionSpec as FunctionSpec.AnyConfect;\n\n return Match.value(functionSpec.runtimeAndFunctionType.functionType).pipe(\n Match.when(\"query\", () => {\n const genericFunction = Match.value(functionVisibility).pipe(\n Match.when(\"public\", () => queryGeneric),\n Match.when(\"internal\", () => internalQueryGeneric),\n Match.exhaustive,\n );\n\n return genericFunction(\n queryFunction({\n databaseSchema: api.databaseSchema,\n args: functionProvenance.args,\n returns: functionProvenance.returns,\n error: functionProvenance.error,\n handler: handler as Handler.AnyConfectProvenance,\n }),\n );\n }),\n Match.when(\"mutation\", () => {\n const genericFunction = Match.value(functionVisibility).pipe(\n Match.when(\"public\", () => mutationGeneric),\n Match.when(\"internal\", () => internalMutationGeneric),\n Match.exhaustive,\n );\n\n return genericFunction(\n mutationFunction({\n databaseSchema: api.databaseSchema,\n args: functionProvenance.args,\n returns: functionProvenance.returns,\n error: functionProvenance.error,\n handler: handler as Handler.AnyConfectProvenance,\n }),\n );\n }),\n Match.when(\"action\", () => {\n const genericFunction = Match.value(functionVisibility).pipe(\n Match.when(\"public\", () => actionGeneric),\n Match.when(\"internal\", () => internalActionGeneric),\n Match.exhaustive,\n );\n\n return genericFunction(\n convexActionFunction(api.databaseSchema, {\n args: functionProvenance.args,\n returns: functionProvenance.returns,\n error: functionProvenance.error,\n handler: handler as Handler.AnyConfectProvenance,\n }),\n );\n }),\n Match.exhaustive,\n );\n }),\n Match.exhaustive,\n );\n\n// Convex's query cache is invalidated by any Date.now() call during handler\n// execution. Effect's unsafeFork calls Date.now() when constructing a\n// FiberId.Runtime, which trips the cache for every confect-wrapped query. We\n// stub Date.now to 0 for the span of the handler; queries are forbidden from\n// relying on real time for correctness anyway.\n//\n// Users who explicitly want the real timestamp can still reach it via Effect's\n// Clock service (Clock.currentTimeMillis/Clock.currentTimeNanos). We provide\n// a Clock layer whose methods close over the *original* Date.now, so opting in\n// to Clock is an opt-in to worse caching—but caching is not broken by default.\nconst unpatchedClock = (realDateNow: () => number): Clock.Clock => {\n const bigint1e6 = BigInt(1_000_000);\n const unsafeCurrentTimeMillis = () => realDateNow();\n const unsafeCurrentTimeNanos = () => BigInt(realDateNow()) * bigint1e6;\n const defaultClock = Clock.make();\n return {\n ...defaultClock,\n unsafeCurrentTimeMillis,\n unsafeCurrentTimeNanos,\n currentTimeMillis: Effect.sync(unsafeCurrentTimeMillis),\n currentTimeNanos: Effect.sync(unsafeCurrentTimeNanos),\n };\n};\n\nconst withStubbedDateNow = async <T>(\n queryHandler: (clock: Clock.Clock) => Promise<T>,\n): Promise<T> => {\n const realDateNow = Date.now;\n const clock = unpatchedClock(realDateNow);\n Date.now = () => 0;\n try {\n return await queryHandler(clock);\n } finally {\n Date.now = realDateNow;\n }\n};\n\nconst queryFunction = <\n DatabaseSchema_ extends DatabaseSchema.AnyWithProps,\n Args,\n ConvexArgs extends DefaultFunctionArgs,\n Returns,\n ConvexReturns,\n E,\n>({\n databaseSchema,\n args,\n returns,\n error,\n handler,\n}: {\n databaseSchema: DatabaseSchema_;\n args: Schema.Schema<Args, ConvexArgs>;\n returns: Schema.Schema<Returns, ConvexReturns>;\n error: Schema.Schema<Error, Value> | undefined;\n handler: (\n a: Args,\n ) => Effect.Effect<\n Returns,\n E,\n | DatabaseReader.DatabaseReader<DatabaseSchema_>\n | Auth.Auth\n | StorageReader\n | QueryRunner.QueryRunner\n | QueryCtx.QueryCtx<\n DataModel.ToConvex<DataModel.FromSchema<DatabaseSchema_>>\n >\n >;\n}) => ({\n args: SchemaToValidator.compileArgsSchema(args),\n returns: SchemaToValidator.compileReturnsSchema(returns),\n handler: (\n ctx: GenericQueryCtx<\n DataModel.ToConvex<DataModel.FromSchema<DatabaseSchema_>>\n >,\n actualArgs: ConvexArgs,\n ): Promise<ConvexReturns> =>\n withStubbedDateNow((clock) =>\n Effect.gen(function* () {\n const decodedArgs = yield* pipe(\n actualArgs,\n Schema.decode(args),\n Effect.orDie,\n );\n const decodedReturns = yield* handler(decodedArgs).pipe(\n Effect.provide(\n Layer.mergeAll(\n DatabaseReader.layer(databaseSchema, ctx.db),\n Auth.layer(ctx.auth),\n StorageReader.layer(ctx.storage),\n QueryRunner.layer(ctx.runQuery),\n Layer.succeed(\n QueryCtx.QueryCtx<\n DataModel.ToConvex<DataModel.FromSchema<DatabaseSchema_>>\n >(),\n ctx,\n ),\n Layer.setConfigProvider(ConvexConfigProvider.make()),\n ),\n ),\n );\n return yield* pipe(\n decodedReturns,\n Schema.encode(returns),\n Effect.orDie,\n );\n }).pipe(\n Effect.withClock(clock),\n RegisteredFunction.runHandlerPromise(error),\n ),\n ),\n});\n\nexport const mutationLayer = <Schema extends DatabaseSchema.AnyWithProps>(\n schema: Schema,\n ctx: GenericMutationCtx<DataModel.ToConvex<DataModel.FromSchema<Schema>>>,\n) =>\n Layer.mergeAll(\n DatabaseReader.layer(schema, ctx.db),\n DatabaseWriter.layer(schema, ctx.db),\n Auth.layer(ctx.auth),\n Scheduler.layer(ctx.scheduler),\n StorageReader.layer(ctx.storage),\n StorageWriter.layer(ctx.storage),\n QueryRunner.layer(ctx.runQuery),\n MutationRunner.layer(ctx.runMutation),\n Layer.succeed(\n MutationCtx.MutationCtx<\n DataModel.ToConvex<DataModel.FromSchema<Schema>>\n >(),\n ctx,\n ),\n Layer.setConfigProvider(ConvexConfigProvider.make()),\n );\n\nexport type MutationServices<Schema extends DatabaseSchema.AnyWithProps> =\n | DatabaseReader.DatabaseReader<Schema>\n | DatabaseWriter.DatabaseWriter<Schema>\n | Auth.Auth\n | Scheduler.Scheduler\n | StorageReader\n | StorageWriter\n | QueryRunner.QueryRunner\n | MutationRunner.MutationRunner\n | MutationCtx.MutationCtx<DataModel.ToConvex<DataModel.FromSchema<Schema>>>;\n\nconst mutationFunction = <\n DatabaseSchema_ extends DatabaseSchema.AnyWithProps,\n Args,\n ConvexArgs extends DefaultFunctionArgs,\n Returns,\n ConvexReturns,\n E,\n>({\n databaseSchema,\n args,\n returns,\n error,\n handler,\n}: {\n databaseSchema: DatabaseSchema_;\n args: Schema.Schema<Args, ConvexArgs>;\n returns: Schema.Schema<Returns, ConvexReturns>;\n error: Schema.Schema<Error, Value> | undefined;\n handler: (\n a: Args,\n ) => Effect.Effect<Returns, E, MutationServices<DatabaseSchema_>>;\n}) => ({\n args: SchemaToValidator.compileArgsSchema(args),\n returns: SchemaToValidator.compileReturnsSchema(returns),\n handler: (\n ctx: GenericMutationCtx<\n DataModel.ToConvex<DataModel.FromSchema<DatabaseSchema_>>\n >,\n actualArgs: ConvexArgs,\n ): Promise<ConvexReturns> =>\n Effect.gen(function* () {\n const decodedArgs = yield* pipe(\n actualArgs,\n Schema.decode(args),\n Effect.orDie,\n );\n const decodedReturns = yield* handler(decodedArgs).pipe(\n Effect.provide(mutationLayer(databaseSchema, ctx)),\n );\n return yield* pipe(decodedReturns, Schema.encode(returns), Effect.orDie);\n }).pipe(RegisteredFunction.runHandlerPromise(error)),\n});\n\nconst convexActionFunction = <\n DatabaseSchema_ extends DatabaseSchema.AnyWithProps,\n Args,\n ConvexArgs extends DefaultFunctionArgs,\n Returns,\n ConvexReturns,\n E,\n>(\n schema: DatabaseSchema_,\n {\n args,\n returns,\n error,\n handler,\n }: {\n args: Schema.Schema<Args, ConvexArgs>;\n returns: Schema.Schema<Returns, ConvexReturns>;\n error: Schema.Schema.AnyNoContext | undefined;\n handler: (\n a: Args,\n ) => Effect.Effect<\n Returns,\n E,\n RegisteredFunction.ActionServices<DatabaseSchema_>\n >;\n },\n) =>\n RegisteredFunction.actionFunctionBase({\n args,\n returns,\n error,\n handler,\n createLayer: (ctx) =>\n Layer.mergeAll(\n RegisteredFunction.actionLayer(schema, ctx),\n Layer.setConfigProvider(ConvexConfigProvider.make()),\n ),\n });\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAiCA,MAAa,QACX,KACA,EAAE,cAAc,cAEhB,MAAM,MAAM,aAAa,mBAAmB,CAAC,KAC3C,MAAM,IAAI,gBAAgB,QAAkC,EAC5D,MAAM,IAAI,iBAAiB;CACzB,MAAM,EAAE,oBAAoB,uBAC1B;AAEF,QAAO,MAAM,MAAM,aAAa,uBAAuB,aAAa,CAAC,KACnE,MAAM,KAAK,eAAe;AAOxB,SANwB,MAAM,MAAM,mBAAmB,CAAC,KACtD,MAAM,KAAK,gBAAgB,aAAa,EACxC,MAAM,KAAK,kBAAkB,qBAAqB,EAClD,MAAM,WACP,CAGC,cAAc;GACZ,gBAAgB,IAAI;GACpB,MAAM,mBAAmB;GACzB,SAAS,mBAAmB;GAC5B,OAAO,mBAAmB;GACjB;GACV,CAAC,CACH;GACD,EACF,MAAM,KAAK,kBAAkB;AAO3B,SANwB,MAAM,MAAM,mBAAmB,CAAC,KACtD,MAAM,KAAK,gBAAgB,gBAA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