@confect/server 6.0.0 → 8.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 +157 -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/DatabaseSchema.d.ts +5 -10
- package/dist/DatabaseSchema.d.ts.map +1 -1
- package/dist/DatabaseSchema.js +5 -6
- package/dist/DatabaseSchema.js.map +1 -1
- package/dist/Document.d.ts.map +1 -1
- package/dist/Document.js +35 -23
- package/dist/Document.js.map +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 +36 -15
- 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/dist/SchemaToValidator.d.ts +8 -8
- package/dist/StorageActionWriter.d.ts +1 -1
- package/package.json +22 -18
- package/src/ActionRunner.ts +5 -1
- package/src/DatabaseSchema.ts +7 -10
- package/src/Document.ts +90 -58
- package/src/Handler.ts +5 -1
- package/src/MutationRunner.ts +6 -16
- package/src/QueryRunner.ts +5 -1
- package/src/RegisteredConvexFunction.ts +111 -94
- package/src/RegisteredFunction.ts +67 -22
- package/src/RegisteredNodeFunction.ts +4 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,161 @@
|
|
|
1
1
|
# @confect/server
|
|
2
2
|
|
|
3
|
+
## 8.0.0
|
|
4
|
+
|
|
5
|
+
### Major Changes
|
|
6
|
+
|
|
7
|
+
- 87b7207: Renamed `DatabaseSchema.isSchema` to `DatabaseSchema.isDatabaseSchema` for consistency with the `is<TypeName>` predicate convention used elsewhere (e.g. `Spec.isSpec`). `TypeId` and `Any` are now defined in `@confect/core/DatabaseSchema` and re-exported from `@confect/server`; the underlying brand string is unchanged, so existing schema values continue to be recognized. Migration: replace `DatabaseSchema.isSchema(x)` with `DatabaseSchema.isDatabaseSchema(x)`.
|
|
8
|
+
|
|
9
|
+
Internally, this removes a cyclic workspace dependency between `@confect/cli` and `@confect/server` that triggered a pnpm install warning. `@confect/cli` no longer peer-depends on `@confect/server`.
|
|
10
|
+
|
|
11
|
+
### Minor Changes
|
|
12
|
+
|
|
13
|
+
- 4bb2722: Bump Effect ecosystem to latest. `@effect/platform` is now `^0.96.1` and `@effect/platform-node` is now `^0.106.0` in `@confect/server`'s peer dependencies; `effect` peer is now `^3.21.2` across packages. Consumers must upgrade `@effect/platform`, `@effect/platform-node`, and `effect` in lockstep when bumping `@confect/server`.
|
|
14
|
+
|
|
15
|
+
### Patch Changes
|
|
16
|
+
|
|
17
|
+
- f308edd: Fix Convex query cache invalidation when handlers use `Effect.log`, `Effect.withSpan`, or other Effect features that read the clock through its `unsafe*` methods.
|
|
18
|
+
|
|
19
|
+
The `Clock` provided to confect-wrapped handlers previously implemented `unsafeCurrentTimeMillis`/`unsafeCurrentTimeNanos` by calling the real `Date.now`, so Effect internals (logging, span events, the default scheduler) would read real time during handler execution and invalidate Convex's per-query cache. Those unsafe methods now return constants (`0`/`0n`), making the only opt-in to cache invalidation the user-facing `Clock.currentTimeMillis`/`Clock.currentTimeNanos` effects, as originally intended.
|
|
20
|
+
|
|
21
|
+
- a02ef8a: Memoize `Document.decode` and `Document.encode` parsers in module-scoped `WeakMap` caches. Decoders are keyed by table schema and table name so shared schemas across tables get the correct `extendWithSystemFields` parser; encoders are keyed by schema only.
|
|
22
|
+
- 40c1cff: Switch sibling `@confect/*` peer-dependency specifiers from `workspace:*` to `workspace:^`. Published peer ranges are now caret-based (e.g. `^7.0.0`) instead of exact-pinned, so non-major upgrades of one `@confect/*` package no longer fall out of range for its peer dependents.
|
|
23
|
+
|
|
24
|
+
Paired with the Changesets `onlyUpdatePeerDependentsWhenOutOfRange` flag, this prevents the entire `@confect/*` family from being promoted to a major bump on every release when only minor/patch changes are present.
|
|
25
|
+
|
|
26
|
+
`@confect/cli` additionally moves `@effect/platform` from `peerDependencies` to `dependencies`, since the CLI consumes it as an internal implementation detail (for `FileSystem`/`Path`) rather than exposing it in its public API. Consumers no longer need to install `@effect/platform` themselves to use the CLI.
|
|
27
|
+
|
|
28
|
+
- Updated dependencies [4bb2722]
|
|
29
|
+
- Updated dependencies [40c1cff]
|
|
30
|
+
- @confect/core@8.0.0
|
|
31
|
+
|
|
32
|
+
## 7.0.0
|
|
33
|
+
|
|
34
|
+
### Minor Changes
|
|
35
|
+
|
|
36
|
+
- 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.
|
|
37
|
+
|
|
38
|
+
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.
|
|
39
|
+
|
|
40
|
+
### Authoring a function with typed errors
|
|
41
|
+
|
|
42
|
+
`FunctionSpec` constructors now accept an optional `error` schema. To support multiple error shapes, combine them with `Schema.Union`.
|
|
43
|
+
|
|
44
|
+
```ts
|
|
45
|
+
import { FunctionSpec, GenericId, GroupSpec } from "@confect/core";
|
|
46
|
+
import { Schema } from "effect";
|
|
47
|
+
|
|
48
|
+
export class NoteNotFound extends Schema.TaggedError<NoteNotFound>()(
|
|
49
|
+
"NoteNotFound",
|
|
50
|
+
{ noteId: GenericId.GenericId("notes") },
|
|
51
|
+
) {}
|
|
52
|
+
|
|
53
|
+
export const notes = GroupSpec.make("notes").addFunction(
|
|
54
|
+
FunctionSpec.publicQuery({
|
|
55
|
+
name: "getOrFail",
|
|
56
|
+
args: Schema.Struct({ noteId: GenericId.GenericId("notes") }),
|
|
57
|
+
returns: Notes.Doc,
|
|
58
|
+
error: NoteNotFound,
|
|
59
|
+
}),
|
|
60
|
+
);
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
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.
|
|
64
|
+
|
|
65
|
+
```ts
|
|
66
|
+
import { FunctionImpl } from "@confect/server";
|
|
67
|
+
import { Effect } from "effect";
|
|
68
|
+
import api from "../_generated/api";
|
|
69
|
+
import { DatabaseReader } from "../_generated/services";
|
|
70
|
+
import { NoteNotFound } from "./notes.spec";
|
|
71
|
+
|
|
72
|
+
const getOrFail = FunctionImpl.make(api, "notes", "getOrFail", ({ noteId }) =>
|
|
73
|
+
Effect.gen(function* () {
|
|
74
|
+
const reader = yield* DatabaseReader;
|
|
75
|
+
return yield* reader
|
|
76
|
+
.table("notes")
|
|
77
|
+
.get(noteId)
|
|
78
|
+
.pipe(Effect.mapError(() => new NoteNotFound({ noteId })));
|
|
79
|
+
}),
|
|
80
|
+
);
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
### Consuming a typed error
|
|
84
|
+
|
|
85
|
+
`@confect/js` (`HttpClient`, `WebSocketClient`) and `@confect/test` (`TestConfect`) surface the decoded error in the `Effect` error channel alongside the existing `HttpClientError`/`WebSocketClientError`/`ParseError`:
|
|
86
|
+
|
|
87
|
+
```ts
|
|
88
|
+
HttpClient.query(refs.public.notes.getOrFail, { noteId });
|
|
89
|
+
// Effect.Effect<Note, NoteNotFound | HttpClientError | ParseError>
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
### `@confect/react`—breaking changes
|
|
93
|
+
|
|
94
|
+
`useQuery`, `useMutation`, and `useAction` now expose typed errors, and `useQuery` returns a tagged result type instead of `Returns | undefined`.
|
|
95
|
+
|
|
96
|
+
**`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`:
|
|
97
|
+
|
|
98
|
+
Before:
|
|
99
|
+
|
|
100
|
+
```tsx
|
|
101
|
+
const notes = useQuery(refs.public.notes.list, {});
|
|
102
|
+
if (notes === undefined) return <p>Loading…</p>;
|
|
103
|
+
return <NoteList notes={notes} />;
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
After:
|
|
107
|
+
|
|
108
|
+
```tsx
|
|
109
|
+
import { QueryResult, useQuery } from "@confect/react";
|
|
110
|
+
|
|
111
|
+
const notes = useQuery(refs.public.notes.list, {});
|
|
112
|
+
return QueryResult.match(notes, {
|
|
113
|
+
onLoading: (skipped) => (skipped ? null : <p>Loading…</p>),
|
|
114
|
+
onSuccess: (notes) => <NoteList notes={notes} />,
|
|
115
|
+
});
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
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.
|
|
119
|
+
|
|
120
|
+
When the ref declares an `error` schema, `onFailure` becomes required and receives the decoded typed error:
|
|
121
|
+
|
|
122
|
+
```tsx
|
|
123
|
+
const lookup = useQuery(refs.public.notes.getOrFail, { noteId });
|
|
124
|
+
QueryResult.match(lookup, {
|
|
125
|
+
onLoading: (skipped) => (skipped ? null : "Looking up…"),
|
|
126
|
+
onSuccess: (note) => `Found: ${note.text}`,
|
|
127
|
+
onFailure: (error) => `Note ${error.noteId} not found.`,
|
|
128
|
+
});
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
`QueryResult` is a Confect-native type exported from `@confect/react`.
|
|
132
|
+
|
|
133
|
+
**`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.
|
|
134
|
+
|
|
135
|
+
```ts
|
|
136
|
+
const deleteOrFail = useMutation(refs.public.notes.deleteOrFail);
|
|
137
|
+
const result = await deleteOrFail({ noteId });
|
|
138
|
+
// Either.Either<null, NoteNotFound | Forbidden>
|
|
139
|
+
Either.match(result, {
|
|
140
|
+
onLeft: (error) => /* typed error */,
|
|
141
|
+
onRight: (value) => /* success */,
|
|
142
|
+
});
|
|
143
|
+
|
|
144
|
+
const deleteNote = useMutation(refs.public.notes.delete_); // no `error` schema
|
|
145
|
+
await deleteNote({ noteId }); // Promise<null>, as before
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
Unspecified failures continue to reject the promise.
|
|
149
|
+
|
|
150
|
+
### Migration
|
|
151
|
+
- 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).
|
|
152
|
+
- 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.
|
|
153
|
+
|
|
154
|
+
### Patch Changes
|
|
155
|
+
|
|
156
|
+
- Updated dependencies [90094d0]
|
|
157
|
+
- @confect/core@7.0.0
|
|
158
|
+
|
|
3
159
|
## 6.0.0
|
|
4
160
|
|
|
5
161
|
### Major Changes
|
|
@@ -43,7 +199,7 @@
|
|
|
43
199
|
|
|
44
200
|
### Minor Changes
|
|
45
201
|
|
|
46
|
-
- 641fd99: Add optional `filter` parameter to `OrderedQuery.paginate`. This allows applying a Convex filter directly at the pagination level
|
|
202
|
+
- 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
203
|
|
|
48
204
|
### Patch Changes
|
|
49
205
|
|
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/DatabaseSchema.d.ts
CHANGED
|
@@ -1,20 +1,18 @@
|
|
|
1
1
|
import { AnyWithProps as AnyWithProps$1, Name, SystemTables, Table, TablesRecord, WithName } from "./Table.js";
|
|
2
2
|
import { Expand, GenericSchema, SchemaDefinition } from "convex/server";
|
|
3
3
|
import * as convex_values0 from "convex/values";
|
|
4
|
+
import { Any, TypeId, TypeId as TypeId$1, isDatabaseSchema } from "@confect/core/DatabaseSchema";
|
|
4
5
|
import * as effect_Schema0 from "effect/Schema";
|
|
5
6
|
|
|
6
7
|
//#region src/DatabaseSchema.d.ts
|
|
7
8
|
declare namespace DatabaseSchema_d_exports {
|
|
8
|
-
export { Any, AnyWithProps, ConvexDatabaseSchemaFromTables, DatabaseSchema, ExtendWithSystemTables, IncludeSystemTables, TableNames, TableWithName, Tables, TypeId, extendWithSystemTables,
|
|
9
|
+
export { Any, AnyWithProps, ConvexDatabaseSchemaFromTables, DatabaseSchema, ExtendWithSystemTables, IncludeSystemTables, TableNames, TableWithName, Tables, TypeId, extendWithSystemTables, isDatabaseSchema, make, systemSchema };
|
|
9
10
|
}
|
|
10
|
-
declare const TypeId = "@confect/server/DatabaseSchema";
|
|
11
|
-
type TypeId = typeof TypeId;
|
|
12
|
-
declare const isSchema: (u: unknown) => u is Any;
|
|
13
11
|
/**
|
|
14
12
|
* A schema definition tracks the schema and its Convex schema definition.
|
|
15
13
|
*/
|
|
16
14
|
interface DatabaseSchema<Tables_ extends AnyWithProps$1 = never> {
|
|
17
|
-
readonly [TypeId]: TypeId;
|
|
15
|
+
readonly [TypeId$1]: TypeId$1;
|
|
18
16
|
readonly tables: TablesRecord<Tables_>;
|
|
19
17
|
readonly convexSchemaDefinition: SchemaDefinition<ConvexDatabaseSchemaFromTables<Tables_>, true>;
|
|
20
18
|
/**
|
|
@@ -22,11 +20,8 @@ interface DatabaseSchema<Tables_ extends AnyWithProps$1 = never> {
|
|
|
22
20
|
*/
|
|
23
21
|
addTable<TableDef extends AnyWithProps$1>(table: TableDef): DatabaseSchema<Tables_ | TableDef>;
|
|
24
22
|
}
|
|
25
|
-
interface Any {
|
|
26
|
-
readonly [TypeId]: TypeId;
|
|
27
|
-
}
|
|
28
23
|
interface AnyWithProps {
|
|
29
|
-
readonly [TypeId]: TypeId;
|
|
24
|
+
readonly [TypeId$1]: TypeId$1;
|
|
30
25
|
readonly tables: Record<string, AnyWithProps$1>;
|
|
31
26
|
readonly convexSchemaDefinition: SchemaDefinition<GenericSchema, true>;
|
|
32
27
|
addTable<TableDef extends AnyWithProps$1>(table: TableDef): AnyWithProps;
|
|
@@ -135,5 +130,5 @@ declare const extendWithSystemTables: <Tables_ extends AnyWithProps$1>(tables: T
|
|
|
135
130
|
type ExtendWithSystemTables<Tables_ extends AnyWithProps$1> = TablesRecord<Tables_ | SystemTables>;
|
|
136
131
|
type IncludeSystemTables<Tables_ extends AnyWithProps$1> = Tables_ | SystemTables extends infer T ? T extends AnyWithProps$1 ? T : never : never;
|
|
137
132
|
//#endregion
|
|
138
|
-
export { Any, AnyWithProps, ConvexDatabaseSchemaFromTables, DatabaseSchema, DatabaseSchema_d_exports, ExtendWithSystemTables, IncludeSystemTables, TableNames, TableWithName, Tables, TypeId, extendWithSystemTables,
|
|
133
|
+
export { type Any, AnyWithProps, ConvexDatabaseSchemaFromTables, DatabaseSchema, DatabaseSchema_d_exports, ExtendWithSystemTables, IncludeSystemTables, TableNames, TableWithName, Tables, TypeId, extendWithSystemTables, isDatabaseSchema, make, systemSchema };
|
|
139
134
|
//# sourceMappingURL=DatabaseSchema.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DatabaseSchema.d.ts","names":[],"sources":["../src/DatabaseSchema.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"DatabaseSchema.d.ts","names":[],"sources":["../src/DatabaseSchema.ts"],"mappings":";;;;;;;;;;;;;UAkBiB,cAAA,iBAA+B,cAAA;EAAA,UACpC,QAAA,GAAS,QAAA;EAAA,SACV,MAAA,EAAQ,YAAA,CAAmB,OAAA;EAAA,SAC3B,sBAAA,EAAwB,gBAAA,CAC/B,8BAAA,CAA+B,OAAA;;;;EAOjC,QAAA,kBAA0B,cAAA,EACxB,KAAA,EAAO,QAAA,GACN,cAAA,CAAe,OAAA,GAAU,QAAA;AAAA;AAAA,UAGb,YAAA;EAAA,UACL,QAAA,GAAS,QAAA;EAAA,SACV,MAAA,EAAQ,MAAA,SAAe,cAAA;EAAA,SACvB,sBAAA,EAAwB,gBAAA,CAAiB,aAAA;EAClD,QAAA,kBAA0B,cAAA,EAAoB,KAAA,EAAO,QAAA,GAAW,YAAA;AAAA;AAAA,KAGtD,MAAA,yBAA+B,YAAA,IACzC,eAAA,SAAwB,cAAA,kBAAgC,OAAA;AAAA,KAE9C,UAAA,yBAAmC,YAAA,IAAgB,IAAA,CAC7D,MAAA,CAAO,eAAA;AAAA,KAIG,aAAA,yBACc,YAAA,oBACN,UAAA,CAAW,eAAA,KAC3B,OAAA,CAAQ,MAAA,CAAO,eAAA;EAAA,SAA6B,IAAA,EAAM,SAAA;AAAA;;;;cAyCzC,IAAA,QAAW,cAAA;AAAA,KAMZ,8BAAA,iBAA+C,cAAA,IACzD,MAAA,iBACgB,IAAA,CAAW,OAAA,aAAoB,QAAA,CAC3C,OAAA,EACA,SAAA;AAAA,cAMO,YAAA,EAAY,cAAA,CAAA,KAAA,wCAAA,MAAA;eAEM,cAAA,CAAA,MAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;QAFN,cAAA,CAAA,OAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAAA,cAAA,CAAA,MAAA;;;;;;;;;;;;;;cAIZ,sBAAA,mBAA0C,cAAA,EACrD,MAAA,EAAQ,YAAA,CAAmB,OAAA,MAC1B,sBAAA,CAAuB,OAAA;AAAA,KAMd,sBAAA,iBAAuC,cAAA,IACjD,YAAA,CAAmB,OAAA,GAAU,YAAA;AAAA,KAEnB,mBAAA,iBAAoC,cAAA,IAC5C,OAAA,GACA,YAAA,mBACA,CAAA,SAAU,cAAA,GACR,CAAA"}
|
package/dist/DatabaseSchema.js
CHANGED
|
@@ -1,20 +1,19 @@
|
|
|
1
1
|
import { __exportAll } from "./_virtual/_rolldown/runtime.js";
|
|
2
2
|
import { scheduledFunctionsTable, storageTable, systemTables } from "./Table.js";
|
|
3
|
-
import { Array,
|
|
3
|
+
import { Array, Record, pipe } from "effect";
|
|
4
4
|
import { defineSchema } from "convex/server";
|
|
5
|
+
import { TypeId, TypeId as TypeId$1, isDatabaseSchema } from "@confect/core/DatabaseSchema";
|
|
5
6
|
|
|
6
7
|
//#region src/DatabaseSchema.ts
|
|
7
8
|
var DatabaseSchema_exports = /* @__PURE__ */ __exportAll({
|
|
8
9
|
TypeId: () => TypeId,
|
|
9
10
|
extendWithSystemTables: () => extendWithSystemTables,
|
|
10
|
-
|
|
11
|
+
isDatabaseSchema: () => isDatabaseSchema,
|
|
11
12
|
make: () => make,
|
|
12
13
|
systemSchema: () => systemSchema
|
|
13
14
|
});
|
|
14
|
-
const TypeId = "@confect/server/DatabaseSchema";
|
|
15
|
-
const isSchema = (u) => Predicate.hasProperty(u, TypeId);
|
|
16
15
|
const Proto = {
|
|
17
|
-
[TypeId]: TypeId,
|
|
16
|
+
[TypeId$1]: TypeId$1,
|
|
18
17
|
addTable(table) {
|
|
19
18
|
const newTablesArray = [...Object.values(this.tables), table];
|
|
20
19
|
return makeProto({
|
|
@@ -41,5 +40,5 @@ const extendWithSystemTables = (tables) => ({
|
|
|
41
40
|
});
|
|
42
41
|
|
|
43
42
|
//#endregion
|
|
44
|
-
export { DatabaseSchema_exports, TypeId, extendWithSystemTables,
|
|
43
|
+
export { DatabaseSchema_exports, TypeId, extendWithSystemTables, isDatabaseSchema, make, systemSchema };
|
|
45
44
|
//# sourceMappingURL=DatabaseSchema.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DatabaseSchema.js","names":["defineConvexSchema","Table.scheduledFunctionsTable","Table.storageTable","Table.systemTables"],"sources":["../src/DatabaseSchema.ts"],"sourcesContent":["import type { Expand, GenericSchema } from \"convex/server\";\nimport {\n defineSchema as defineConvexSchema,\n type SchemaDefinition,\n} from \"convex/server\";\nimport { Array, pipe,
|
|
1
|
+
{"version":3,"file":"DatabaseSchema.js","names":["TypeId","defineConvexSchema","Table.scheduledFunctionsTable","Table.storageTable","Table.systemTables"],"sources":["../src/DatabaseSchema.ts"],"sourcesContent":["import type { Expand, GenericSchema } from \"convex/server\";\nimport {\n defineSchema as defineConvexSchema,\n type SchemaDefinition,\n} from \"convex/server\";\nimport { Array, pipe, Record } from \"effect\";\nimport * as Table from \"./Table\";\nimport { TypeId } from \"@confect/core/DatabaseSchema\";\n\nexport {\n type Any,\n isDatabaseSchema,\n TypeId,\n} from \"@confect/core/DatabaseSchema\";\n\n/**\n * A schema definition tracks the schema and its Convex schema definition.\n */\nexport interface DatabaseSchema<Tables_ extends Table.AnyWithProps = never> {\n readonly [TypeId]: TypeId;\n readonly tables: Table.TablesRecord<Tables_>;\n readonly convexSchemaDefinition: SchemaDefinition<\n ConvexDatabaseSchemaFromTables<Tables_>,\n true\n >;\n\n /**\n * Add a table definition to the schema.\n */\n addTable<TableDef extends Table.AnyWithProps>(\n table: TableDef,\n ): DatabaseSchema<Tables_ | TableDef>;\n}\n\nexport interface AnyWithProps {\n readonly [TypeId]: TypeId;\n readonly tables: Record<string, Table.AnyWithProps>;\n readonly convexSchemaDefinition: SchemaDefinition<GenericSchema, true>;\n addTable<TableDef extends Table.AnyWithProps>(table: TableDef): AnyWithProps;\n}\n\nexport type Tables<DatabaseSchema_ extends AnyWithProps> =\n DatabaseSchema_ extends DatabaseSchema<infer Tables_> ? Tables_ : never;\n\nexport type TableNames<DatabaseSchema_ extends AnyWithProps> = Table.Name<\n Tables<DatabaseSchema_>\n> &\n string;\n\nexport type TableWithName<\n DatabaseSchema_ extends AnyWithProps,\n TableName extends TableNames<DatabaseSchema_>,\n> = Extract<Tables<DatabaseSchema_>, { readonly name: TableName }>;\n\nconst Proto = {\n [TypeId]: TypeId,\n\n addTable<TableDef extends Table.AnyWithProps>(\n this: DatabaseSchema<Table.AnyWithProps>,\n table: TableDef,\n ) {\n const tablesArray = Object.values(this.tables) as Table.AnyWithProps[];\n const newTablesArray = [...tablesArray, table];\n\n return makeProto({\n tables: Record.set(this.tables, table.name, table),\n convexSchemaDefinition: pipe(\n newTablesArray,\n Array.map(\n ({ name, tableDefinition }) => [name, tableDefinition] as const,\n ),\n Record.fromEntries,\n defineConvexSchema,\n ),\n });\n },\n};\n\nconst makeProto = <Tables_ extends Table.AnyWithProps>({\n tables,\n convexSchemaDefinition,\n}: {\n tables: Record.ReadonlyRecord<string, Tables_>;\n convexSchemaDefinition: SchemaDefinition<GenericSchema, true>;\n}): DatabaseSchema<Tables_> =>\n Object.assign(Object.create(Proto), {\n tables,\n convexSchemaDefinition,\n });\n\n/**\n * Create an empty schema definition. Add tables incrementally via `addTable`.\n */\nexport const make = (): DatabaseSchema<never> =>\n makeProto({\n tables: Record.empty(),\n convexSchemaDefinition: defineConvexSchema({}),\n });\n\nexport type ConvexDatabaseSchemaFromTables<Tables_ extends Table.AnyWithProps> =\n Expand<{\n [TableName in Table.Name<Tables_> & string]: Table.WithName<\n Tables_,\n TableName\n >[\"tableDefinition\"];\n }>;\n\n// System tables\n\nexport const systemSchema = make()\n .addTable(Table.scheduledFunctionsTable)\n .addTable(Table.storageTable);\n\nexport const extendWithSystemTables = <Tables_ extends Table.AnyWithProps>(\n tables: Table.TablesRecord<Tables_>,\n): ExtendWithSystemTables<Tables_> =>\n ({\n ...tables,\n ...Table.systemTables,\n }) as ExtendWithSystemTables<Tables_>;\n\nexport type ExtendWithSystemTables<Tables_ extends Table.AnyWithProps> =\n Table.TablesRecord<Tables_ | Table.SystemTables>;\n\nexport type IncludeSystemTables<Tables_ extends Table.AnyWithProps> =\n | Tables_\n | Table.SystemTables extends infer T\n ? T extends Table.AnyWithProps\n ? T\n : never\n : never;\n"],"mappings":";;;;;;;;;;;;;;AAsDA,MAAM,QAAQ;EACXA,WAASA;CAEV,SAEE,OACA;EAEA,MAAM,iBAAiB,CAAC,GADJ,OAAO,OAAO,KAAK,OAAO,EACN,MAAM;AAE9C,SAAO,UAAU;GACf,QAAQ,OAAO,IAAI,KAAK,QAAQ,MAAM,MAAM,MAAM;GAClD,wBAAwB,KACtB,gBACA,MAAM,KACH,EAAE,MAAM,sBAAsB,CAAC,MAAM,gBAAgB,CACvD,EACD,OAAO,aACPC,aACD;GACF,CAAC;;CAEL;AAED,MAAM,aAAiD,EACrD,QACA,6BAKA,OAAO,OAAO,OAAO,OAAO,MAAM,EAAE;CAClC;CACA;CACD,CAAC;;;;AAKJ,MAAa,aACX,UAAU;CACR,QAAQ,OAAO,OAAO;CACtB,wBAAwBA,aAAmB,EAAE,CAAC;CAC/C,CAAC;AAYJ,MAAa,eAAe,MAAM,CAC/B,SAASC,wBAA8B,CACvC,SAASC,aAAmB;AAE/B,MAAa,0BACX,YAEC;CACC,GAAG;CACH,GAAGC;CACJ"}
|
package/dist/Document.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Document.d.ts","names":[],"sources":["../src/Document.ts"],"mappings":";;;;;;;;;;KAOY,mBAAA,QAA2B,IAAA,CAAK,GAAA;AAAA,KAEhC,GAAA;AAAA,KACA,UAAA,GAAa,cAAA,SAAuB,aAAA;AAAA,
|
|
1
|
+
{"version":3,"file":"Document.d.ts","names":[],"sources":["../src/Document.ts"],"mappings":";;;;;;;;;;KAOY,mBAAA,QAA2B,IAAA,CAAK,GAAA;AAAA,KAEhC,GAAA;AAAA,KACA,UAAA,GAAa,cAAA,SAAuB,aAAA;AAAA,cAiCnC,MAAA,uBAEU,YAAA,oBACD,UAAA,CAAqB,UAAA,GAAW,SAAA,EAEvC,SAAA,EAAS,WAAA,EACP,WAAA,CACX,kBAAA,CAA6B,UAAA,EAAY,SAAA,QAG3C,IAAA,EAAM,kBAAA,CAA6B,UAAA,EAAY,SAAA,wBAC5C,MAAA,CAAO,MAAA,CACV,kBAAA,CAA6B,UAAA,EAAY,SAAA,eACzC,mBAAA,0BAGmB,YAAA,oBACD,UAAA,CAAqB,UAAA,GAAW,IAAA,EAE5C,kBAAA,CAA6B,UAAA,EAAY,SAAA,qBAA4B,SAAA,EAChE,SAAA,EAAS,WAAA,EACP,WAAA,CACX,kBAAA,CAA6B,UAAA,EAAY,SAAA,OAExC,MAAA,CAAO,MAAA,CACV,kBAAA,CAA6B,UAAA,EAAY,SAAA,eACzC,mBAAA;AAAA,cAsDS,MAAA,uBAEU,YAAA,oBACD,UAAA,CAAqB,UAAA,GAAW,SAAA,EAEvC,SAAA,EAAS,WAAA,EACP,WAAA,CACX,kBAAA,CAA6B,UAAA,EAAY,SAAA,QAG3C,IAAA,EAAM,kBAAA,CAA6B,UAAA,EAAY,SAAA,kBAC5C,MAAA,CAAO,MAAA,CACV,kBAAA,CAA6B,UAAA,EAAY,SAAA,sBACzC,mBAAA,0BAGmB,YAAA,oBACD,UAAA,CAAqB,UAAA,GAAW,IAAA,EAE5C,kBAAA,CAA6B,UAAA,EAAY,SAAA,eAAsB,SAAA,EAC1D,SAAA,EAAS,WAAA,EACP,WAAA,CACX,kBAAA,CAA6B,UAAA,EAAY,SAAA,OAExC,MAAA,CAAO,MAAA,CACV,kBAAA,CAA6B,UAAA,EAAY,SAAA,sBACzC,mBAAA;AAAA,cAwCF,wBAAA;;;;;;;cAEW,mBAAA,SAA4B,wBAAA;EAAA,IAQ1B,OAAA,CAAA;AAAA;AAAA,cAOd,wBAAA;;;;;;;cAEY,mBAAA,SAA4B,wBAAA;EAAA,IAQ1B,OAAA,CAAA;AAAA;AAAA,cASF,oBAAA;EAAwB,EAAA;EAAA,SAAA;EAAA;AAAA;EAKnC,EAAA;EACA,SAAA;EACA,OAAA;AAAA"}
|
package/dist/Document.js
CHANGED
|
@@ -10,29 +10,41 @@ var Document_exports = /* @__PURE__ */ __exportAll({
|
|
|
10
10
|
documentErrorMessage: () => documentErrorMessage,
|
|
11
11
|
encode: () => encode
|
|
12
12
|
});
|
|
13
|
-
const
|
|
14
|
-
|
|
15
|
-
const
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
return
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
}));
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
13
|
+
const decoderCache = /* @__PURE__ */ new WeakMap();
|
|
14
|
+
const getDecoder = (tableName, tableSchema) => {
|
|
15
|
+
const byTable = decoderCache.get(tableSchema) ?? (() => {
|
|
16
|
+
const map = /* @__PURE__ */ new Map();
|
|
17
|
+
decoderCache.set(tableSchema, map);
|
|
18
|
+
return map;
|
|
19
|
+
})();
|
|
20
|
+
return byTable.get(tableName) ?? (() => {
|
|
21
|
+
const decoder = Schema.decode(SystemFields.extendWithSystemFields(tableName, tableSchema));
|
|
22
|
+
byTable.set(tableName, decoder);
|
|
23
|
+
return decoder;
|
|
24
|
+
})();
|
|
25
|
+
};
|
|
26
|
+
const decode = Function.dual(3, (self, tableName, tableSchema) => pipe(self, getDecoder(tableName, tableSchema), Effect.catchIf(ParseResult.isParseError, (parseError) => Effect.gen(function* () {
|
|
27
|
+
const formattedParseError = yield* ParseResult.TreeFormatter.formatError(parseError);
|
|
28
|
+
return yield* new DocumentDecodeError({
|
|
29
|
+
tableName,
|
|
30
|
+
id: self._id,
|
|
31
|
+
parseError: formattedParseError
|
|
32
|
+
});
|
|
33
|
+
})), Effect.map((decodedDoc) => decodedDoc)));
|
|
34
|
+
const encoderCache = /* @__PURE__ */ new WeakMap();
|
|
35
|
+
const getEncoder = (tableSchema) => encoderCache.get(tableSchema) ?? (() => {
|
|
36
|
+
const encoder = Schema.encode(tableSchema);
|
|
37
|
+
encoderCache.set(tableSchema, encoder);
|
|
38
|
+
return encoder;
|
|
39
|
+
})();
|
|
40
|
+
const encode = Function.dual(3, (self, tableName, tableSchema) => pipe(self, getEncoder(tableSchema), Effect.catchIf(ParseResult.isParseError, (parseError) => Effect.gen(function* () {
|
|
41
|
+
const formattedParseError = yield* ParseResult.TreeFormatter.formatError(parseError);
|
|
42
|
+
return yield* new DocumentEncodeError({
|
|
43
|
+
tableName,
|
|
44
|
+
id: self._id,
|
|
45
|
+
parseError: formattedParseError
|
|
46
|
+
});
|
|
47
|
+
})), Effect.map((encodedDoc) => encodedDoc)));
|
|
36
48
|
var DocumentDecodeError = class extends Schema.TaggedError()("DocumentDecodeError", {
|
|
37
49
|
tableName: Schema.String,
|
|
38
50
|
id: Schema.String,
|
package/dist/Document.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Document.js","names":[],"sources":["../src/Document.ts"],"sourcesContent":["import { Effect, Function, ParseResult, pipe, Schema } from \"effect\";\nimport type { ReadonlyRecord } from \"effect/Record\";\nimport
|
|
1
|
+
{"version":3,"file":"Document.js","names":[],"sources":["../src/Document.ts"],"sourcesContent":["import * as SystemFields from \"@confect/core/SystemFields\";\nimport { Effect, Function, ParseResult, pipe, Schema } from \"effect\";\nimport type { ReadonlyRecord } from \"effect/Record\";\nimport type * as DataModel from \"./DataModel\";\nimport type { ReadonlyValue } from \"./SchemaToValidator\";\nimport type * as TableInfo from \"./TableInfo\";\n\nexport type WithoutSystemFields<Doc> = Omit<Doc, \"_creationTime\" | \"_id\">;\n\nexport type Any = any;\nexport type AnyEncoded = ReadonlyRecord<string, ReadonlyValue>;\n\ntype Decode = (doc: unknown) => Effect.Effect<unknown, ParseResult.ParseError>;\n\nconst decoderCache = new WeakMap<\n Schema.Schema.AnyNoContext,\n Map<string, Decode>\n>();\n\nconst getDecoder = (\n tableName: string,\n tableSchema: Schema.Schema.AnyNoContext,\n): Decode => {\n const byTable =\n decoderCache.get(tableSchema) ??\n (() => {\n const map = new Map<string, Decode>();\n decoderCache.set(tableSchema, map);\n return map;\n })();\n\n return (\n byTable.get(tableName) ??\n (() => {\n const decoder = Schema.decode(\n SystemFields.extendWithSystemFields(tableName, tableSchema),\n ) as Decode;\n byTable.set(tableName, decoder);\n return decoder;\n })()\n );\n};\n\nexport const decode = Function.dual<\n <\n DataModel_ extends DataModel.AnyWithProps,\n TableName extends DataModel.TableNames<DataModel_>,\n >(\n tableName: TableName,\n tableSchema: TableInfo.TableSchema<\n DataModel.TableInfoWithName_<DataModel_, TableName>\n >,\n ) => (\n self: DataModel.TableInfoWithName_<DataModel_, TableName>[\"convexDocument\"],\n ) => Effect.Effect<\n DataModel.TableInfoWithName_<DataModel_, TableName>[\"document\"],\n DocumentDecodeError\n >,\n <\n DataModel_ extends DataModel.AnyWithProps,\n TableName extends DataModel.TableNames<DataModel_>,\n >(\n self: DataModel.TableInfoWithName_<DataModel_, TableName>[\"convexDocument\"],\n tableName: TableName,\n tableSchema: TableInfo.TableSchema<\n DataModel.TableInfoWithName_<DataModel_, TableName>\n >,\n ) => Effect.Effect<\n DataModel.TableInfoWithName_<DataModel_, TableName>[\"document\"],\n DocumentDecodeError\n >\n>(\n 3,\n <\n DataModel_ extends DataModel.AnyWithProps,\n TableName extends DataModel.TableNames<DataModel_>,\n >(\n self: DataModel.TableInfoWithName_<DataModel_, TableName>[\"convexDocument\"],\n tableName: TableName,\n tableSchema: TableInfo.TableSchema<\n DataModel.TableInfoWithName_<DataModel_, TableName>\n >,\n ): Effect.Effect<\n DataModel.TableInfoWithName_<DataModel_, TableName>[\"document\"],\n DocumentDecodeError\n > =>\n pipe(\n self,\n getDecoder(tableName, tableSchema),\n Effect.catchIf(ParseResult.isParseError, (parseError) =>\n Effect.gen(function* () {\n const formattedParseError =\n yield* ParseResult.TreeFormatter.formatError(parseError);\n\n return yield* new DocumentDecodeError({\n tableName,\n id: self._id,\n parseError: formattedParseError,\n });\n }),\n ),\n Effect.map(\n (decodedDoc) =>\n decodedDoc as DataModel.TableInfoWithName_<\n DataModel_,\n TableName\n >[\"document\"],\n ),\n ),\n);\n\ntype Encode = (doc: unknown) => Effect.Effect<unknown, ParseResult.ParseError>;\n\nconst encoderCache = new WeakMap<Schema.Schema.AnyNoContext, Encode>();\n\nconst getEncoder = (tableSchema: Schema.Schema.AnyNoContext): Encode =>\n encoderCache.get(tableSchema) ??\n (() => {\n const encoder = Schema.encode(tableSchema) as Encode;\n encoderCache.set(tableSchema, encoder);\n return encoder;\n })();\n\nexport const encode = Function.dual<\n <\n DataModel_ extends DataModel.AnyWithProps,\n TableName extends DataModel.TableNames<DataModel_>,\n >(\n tableName: TableName,\n tableSchema: TableInfo.TableSchema<\n DataModel.TableInfoWithName_<DataModel_, TableName>\n >,\n ) => (\n self: DataModel.TableInfoWithName_<DataModel_, TableName>[\"document\"],\n ) => Effect.Effect<\n DataModel.TableInfoWithName_<DataModel_, TableName>[\"encodedDocument\"],\n DocumentEncodeError\n >,\n <\n DataModel_ extends DataModel.AnyWithProps,\n TableName extends DataModel.TableNames<DataModel_>,\n >(\n self: DataModel.TableInfoWithName_<DataModel_, TableName>[\"document\"],\n tableName: TableName,\n tableSchema: TableInfo.TableSchema<\n DataModel.TableInfoWithName_<DataModel_, TableName>\n >,\n ) => Effect.Effect<\n DataModel.TableInfoWithName_<DataModel_, TableName>[\"encodedDocument\"],\n DocumentEncodeError\n >\n>(\n 3,\n <\n DataModel_ extends DataModel.AnyWithProps,\n TableName extends DataModel.TableNames<DataModel_>,\n >(\n self: DataModel.TableInfoWithName_<DataModel_, TableName>[\"document\"],\n tableName: TableName,\n tableSchema: TableInfo.TableSchema<\n DataModel.TableInfoWithName_<DataModel_, TableName>\n >,\n ): Effect.Effect<\n DataModel.TableInfoWithName_<DataModel_, TableName>[\"encodedDocument\"],\n DocumentEncodeError\n > =>\n pipe(\n self,\n getEncoder(tableSchema),\n Effect.catchIf(ParseResult.isParseError, (parseError) =>\n Effect.gen(function* () {\n const formattedParseError =\n yield* ParseResult.TreeFormatter.formatError(parseError);\n\n return yield* new DocumentEncodeError({\n tableName,\n id: self._id,\n parseError: formattedParseError,\n });\n }),\n ),\n Effect.map(\n (encodedDoc) =>\n encodedDoc as DataModel.TableInfoWithName_<\n DataModel_,\n TableName\n >[\"encodedDocument\"],\n ),\n ),\n);\n\nexport class DocumentDecodeError extends Schema.TaggedError<DocumentDecodeError>()(\n \"DocumentDecodeError\",\n {\n tableName: Schema.String,\n id: Schema.String,\n parseError: Schema.String,\n },\n) {\n override get message(): string {\n return documentErrorMessage({\n id: this.id,\n tableName: this.tableName,\n message: `could not be decoded:\\n\\n${this.parseError}`,\n });\n }\n}\n\nexport class DocumentEncodeError extends Schema.TaggedError<DocumentEncodeError>()(\n \"DocumentEncodeError\",\n {\n tableName: Schema.String,\n id: Schema.String,\n parseError: Schema.String,\n },\n) {\n override get message(): string {\n return documentErrorMessage({\n id: this.id,\n tableName: this.tableName,\n message: `could not be encoded:\\n\\n${this.parseError}`,\n });\n }\n}\n\nexport const documentErrorMessage = ({\n id,\n tableName,\n message,\n}: {\n id: string;\n tableName: string;\n message: string;\n}) => `Document with ID '${id}' in table '${tableName}' ${message}`;\n"],"mappings":";;;;;;;;;;;;AAcA,MAAM,+BAAe,IAAI,SAGtB;AAEH,MAAM,cACJ,WACA,gBACW;CACX,MAAM,UACJ,aAAa,IAAI,YAAY,WACtB;EACL,MAAM,sBAAM,IAAI,KAAqB;AACrC,eAAa,IAAI,aAAa,IAAI;AAClC,SAAO;KACL;AAEN,QACE,QAAQ,IAAI,UAAU,WACf;EACL,MAAM,UAAU,OAAO,OACrB,aAAa,uBAAuB,WAAW,YAAY,CAC5D;AACD,UAAQ,IAAI,WAAW,QAAQ;AAC/B,SAAO;KACL;;AAIR,MAAa,SAAS,SAAS,KA6B7B,IAKE,MACA,WACA,gBAOA,KACE,MACA,WAAW,WAAW,YAAY,EAClC,OAAO,QAAQ,YAAY,eAAe,eACxC,OAAO,IAAI,aAAa;CACtB,MAAM,sBACJ,OAAO,YAAY,cAAc,YAAY,WAAW;AAE1D,QAAO,OAAO,IAAI,oBAAoB;EACpC;EACA,IAAI,KAAK;EACT,YAAY;EACb,CAAC;EACF,CACH,EACD,OAAO,KACJ,eACC,WAIH,CACF,CACJ;AAID,MAAM,+BAAe,IAAI,SAA6C;AAEtE,MAAM,cAAc,gBAClB,aAAa,IAAI,YAAY,WACtB;CACL,MAAM,UAAU,OAAO,OAAO,YAAY;AAC1C,cAAa,IAAI,aAAa,QAAQ;AACtC,QAAO;IACL;AAEN,MAAa,SAAS,SAAS,KA6B7B,IAKE,MACA,WACA,gBAOA,KACE,MACA,WAAW,YAAY,EACvB,OAAO,QAAQ,YAAY,eAAe,eACxC,OAAO,IAAI,aAAa;CACtB,MAAM,sBACJ,OAAO,YAAY,cAAc,YAAY,WAAW;AAE1D,QAAO,OAAO,IAAI,oBAAoB;EACpC;EACA,IAAI,KAAK;EACT,YAAY;EACb,CAAC;EACF,CACH,EACD,OAAO,KACJ,eACC,WAIH,CACF,CACJ;AAED,IAAa,sBAAb,cAAyC,OAAO,aAAkC,CAChF,uBACA;CACE,WAAW,OAAO;CAClB,IAAI,OAAO;CACX,YAAY,OAAO;CACpB,CACF,CAAC;CACA,IAAa,UAAkB;AAC7B,SAAO,qBAAqB;GAC1B,IAAI,KAAK;GACT,WAAW,KAAK;GAChB,SAAS,4BAA4B,KAAK;GAC3C,CAAC;;;AAIN,IAAa,sBAAb,cAAyC,OAAO,aAAkC,CAChF,uBACA;CACE,WAAW,OAAO;CAClB,IAAI,OAAO;CACX,YAAY,OAAO;CACpB,CACF,CAAC;CACA,IAAa,UAAkB;AAC7B,SAAO,qBAAqB;GAC1B,IAAI,KAAK;GACT,WAAW,KAAK;GAChB,SAAS,4BAA4B,KAAK;GAC3C,CAAC;;;AAIN,MAAa,wBAAwB,EACnC,IACA,WACA,cAKI,qBAAqB,GAAG,cAAc,UAAU,IAAI"}
|
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,EACA,kBAAA,CAAmB,UAAA,IAErB,wBAAA,CAAyB,eAAA,EAAiB,aAAA;AAAA,KAG7C,uBAAA,uBAED,YAAA,CAAa,kCAAA,CAAmC,kBAAA,CAAmB,SAAA,KACnE,wBAAA,CAA4C,aAAA;AAAA,KAE3C,wBAAA,yBACqB,YAAA,wBAEtB,YAAA,CAAa,kCAAA,CAAmC,kBAAA,CAAmB,UAAA,KAErE,aAAA,SAAsB,YAAA,CAAa,gBAAA,CAAiB,aAAA,aAChD,sBAAA,CAAuB,eAAA,EAAiB,aAAA,IACxC,aAAA,SAAsB,YAAA,CAAa,gBAAA,CAC/B,aAAA,gBAGF,yBAAA,CAA0B,eAAA,EAAiB,aAAA,IAC3C,aAAA,SAAsB,YAAA,CAAa,0BAAA,CAC/B,aAAA,EACA,sBAAA,CAAuB,YAAA,IAEzB,mBAAA,CAAoB,eAAA,EAAiB,aAAA,IACrC,aAAA,SAAsB,YAAA,CAAa,0BAAA,CAC/B,aAAA,EACA,sBAAA,CAAuB,UAAA,IAEzB,iBAAA,CAAkB,eAAA,EAAiB,aAAA;AAAA,KAGnC,sBAAA,yBACc,YAAA,wBAEtB,YAAA,CAAa,4BAAA,CAA6B,sBAAA,CAAuB,QAAA,KACjE,IAAA,CACF,aAAA,EACE,cAAA,CAA8B,eAAA,IAC9B,IAAA,GACA,aAAA,GACA,WAAA,GACA,QAAA,CAAkB,QAAA,CAAmB,UAAA,CAAqB,eAAA;AAAA,KAGlD,yBAAA,yBACc,YAAA,wBAEtB,YAAA,CAAa,4BAAA,CAA6B,sBAAA,CAAuB,WAAA,KACjE,IAAA,CACF,aAAA,EACE,cAAA,CAA8B,eAAA,IAC9B,cAAA,CAA8B,eAAA,IAC9B,IAAA,GACA,SAAA,GACA,aAAA,GACA,aAAA,GACA,WAAA,GACA,cAAA,GACA,WAAA,CACE,QAAA,CAAmB,UAAA,CAAqB,eAAA;AAAA,KAIzC,cAAA,yBAAuC,YAAA,IACxC,SAAA,GACA,IAAA,GACA,aAAA,GACA,aAAA,GACA,mBAAA,GACA,WAAA,GACA,cAAA,GACA,YAAA,GACA,YAAA,CAA0B,UAAA,CAAqB,eAAA,KAC/C,SAAA,CACE,QAAA,CAAmB,UAAA,CAAqB,eAAA;AAAA,KAGlC,mBAAA,yBACc,YAAA,wBAEtB,YAAA,CAAa,4BAAA,CAA6B,sBAAA,CAAuB,SAAA,KACjE,IAAA,CAAK,aAAA,EAAe,cAAA,CAAe,eAAA;AAAA,KAE3B,iBAAA,yBACc,YAAA,wBAEtB,YAAA,CAAa,4BAAA,CAA6B,sBAAA,CAAuB,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,
|
|
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,EACA,kBAAA,CAAmB,UAAA,IAErB,wBAAA,CAAyB,eAAA,EAAiB,aAAA;AAAA,KAG7C,uBAAA,uBAED,YAAA,CAAa,kCAAA,CAAmC,kBAAA,CAAmB,SAAA,KACnE,wBAAA,CAA4C,aAAA;AAAA,KAE3C,wBAAA,yBACqB,YAAA,wBAEtB,YAAA,CAAa,kCAAA,CAAmC,kBAAA,CAAmB,UAAA,KAErE,aAAA,SAAsB,YAAA,CAAa,gBAAA,CAAiB,aAAA,aAChD,sBAAA,CAAuB,eAAA,EAAiB,aAAA,IACxC,aAAA,SAAsB,YAAA,CAAa,gBAAA,CAC/B,aAAA,gBAGF,yBAAA,CAA0B,eAAA,EAAiB,aAAA,IAC3C,aAAA,SAAsB,YAAA,CAAa,0BAAA,CAC/B,aAAA,EACA,sBAAA,CAAuB,YAAA,IAEzB,mBAAA,CAAoB,eAAA,EAAiB,aAAA,IACrC,aAAA,SAAsB,YAAA,CAAa,0BAAA,CAC/B,aAAA,EACA,sBAAA,CAAuB,UAAA,IAEzB,iBAAA,CAAkB,eAAA,EAAiB,aAAA;AAAA,KAGnC,sBAAA,yBACc,YAAA,wBAEtB,YAAA,CAAa,4BAAA,CAA6B,sBAAA,CAAuB,QAAA,KACjE,IAAA,CACF,aAAA,EACE,cAAA,CAA8B,eAAA,IAC9B,IAAA,GACA,aAAA,GACA,WAAA,GACA,QAAA,CAAkB,QAAA,CAAmB,UAAA,CAAqB,eAAA;AAAA,KAGlD,yBAAA,yBACc,YAAA,wBAEtB,YAAA,CAAa,4BAAA,CAA6B,sBAAA,CAAuB,WAAA,KACjE,IAAA,CACF,aAAA,EACE,cAAA,CAA8B,eAAA,IAC9B,cAAA,CAA8B,eAAA,IAC9B,IAAA,GACA,SAAA,GACA,aAAA,GACA,aAAA,GACA,WAAA,GACA,cAAA,GACA,WAAA,CACE,QAAA,CAAmB,UAAA,CAAqB,eAAA;AAAA,KAIzC,cAAA,yBAAuC,YAAA,IACxC,SAAA,GACA,IAAA,GACA,aAAA,GACA,aAAA,GACA,mBAAA,GACA,WAAA,GACA,cAAA,GACA,YAAA,GACA,YAAA,CAA0B,UAAA,CAAqB,eAAA,KAC/C,SAAA,CACE,QAAA,CAAmB,UAAA,CAAqB,eAAA;AAAA,KAGlC,mBAAA,yBACc,YAAA,wBAEtB,YAAA,CAAa,4BAAA,CAA6B,sBAAA,CAAuB,SAAA,KACjE,IAAA,CAAK,aAAA,EAAe,cAAA,CAAe,eAAA;AAAA,KAE3B,iBAAA,yBACc,YAAA,wBAEtB,YAAA,CAAa,4BAAA,CAA6B,sBAAA,CAAuB,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"}
|