@confect/core 10.0.0-next.18 → 10.0.0-next.19
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 +62 -0
- package/dist/FunctionProvenance.d.ts +64 -43
- package/dist/FunctionProvenance.d.ts.map +1 -1
- package/dist/FunctionProvenance.js +9 -9
- package/dist/FunctionProvenance.js.map +1 -1
- package/dist/FunctionSpec.d.ts +255 -143
- package/dist/FunctionSpec.d.ts.map +1 -1
- package/dist/FunctionSpec.js +24 -19
- package/dist/FunctionSpec.js.map +1 -1
- package/dist/PaginationError.d.ts +14 -0
- package/dist/PaginationError.d.ts.map +1 -0
- package/dist/PaginationError.js +25 -0
- package/dist/PaginationError.js.map +1 -0
- package/dist/Ref.d.ts +44 -8
- package/dist/Ref.d.ts.map +1 -1
- package/dist/Ref.js +3 -3
- package/dist/Ref.js.map +1 -1
- package/dist/Refs.d.ts +1 -1
- package/dist/Refs.d.ts.map +1 -1
- package/dist/Refs.js.map +1 -1
- package/dist/SchemaToValidator.js +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -1
- package/package.json +4 -4
- package/src/FunctionProvenance.ts +77 -64
- package/src/FunctionSpec.ts +192 -109
- package/src/PaginationError.ts +72 -0
- package/src/Ref.ts +85 -34
- package/src/Refs.ts +1 -0
- package/src/index.ts +1 -0
|
@@ -5,17 +5,41 @@ import * as Lazy from "./Lazy";
|
|
|
5
5
|
import * as PaginationOptions from "./PaginationOptions";
|
|
6
6
|
import * as PaginationResult from "./PaginationResult";
|
|
7
7
|
|
|
8
|
+
/**
|
|
9
|
+
* A field map accepted as Confect function args. Restricting each field to a
|
|
10
|
+
* context-free codec means the struct assembled from the fields can always be
|
|
11
|
+
* encoded and decoded synchronously at a Convex boundary.
|
|
12
|
+
*/
|
|
13
|
+
// eslint-disable-next-line import/namespace -- oxlint's namespace resolution misses type-only exports, and `Schema` is an interface/namespace
|
|
14
|
+
export type ArgsFields = {
|
|
15
|
+
readonly [key: PropertyKey]: Schema.ConstraintCodec<any, any>;
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* A struct-shaped Confect args schema that keeps its exact field map while
|
|
20
|
+
* erasing the rest of `Schema.Struct`'s large implementation type. Decoded and
|
|
21
|
+
* encoded args are derived directly from `ArgsFields_`; keeping the runtime
|
|
22
|
+
* codec structural prevents every ref lookup from expanding the full Effect
|
|
23
|
+
* schema type.
|
|
24
|
+
*/
|
|
25
|
+
export interface ArgsSchema<
|
|
26
|
+
ArgsFields_ extends ArgsFields,
|
|
27
|
+
> extends Schema.Codec<any, any> {
|
|
28
|
+
readonly fields: ArgsFields_;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/** Erased structural view used after the exact field map is no longer needed. */
|
|
32
|
+
export type AnyArgsSchema = ArgsSchema<ArgsFields>;
|
|
33
|
+
|
|
8
34
|
export type FunctionProvenance = Data.TaggedEnum<{
|
|
9
35
|
Confect: {
|
|
10
|
-
args:
|
|
36
|
+
args: AnyArgsSchema;
|
|
11
37
|
returns: Schema.Codec<any, any>;
|
|
12
38
|
error?: Schema.Codec<any, any>;
|
|
13
39
|
kind: ConfectKind;
|
|
14
40
|
};
|
|
15
41
|
Convex: {
|
|
16
|
-
/** @internal */
|
|
17
42
|
"~args": DefaultFunctionArgs;
|
|
18
|
-
/** @internal */
|
|
19
43
|
"~returns": any;
|
|
20
44
|
};
|
|
21
45
|
}>;
|
|
@@ -23,9 +47,10 @@ export type FunctionProvenance = Data.TaggedEnum<{
|
|
|
23
47
|
/**
|
|
24
48
|
* The declaration shape of a Confect function — orthogonal to both the
|
|
25
49
|
* provenance origin (Confect vs Convex) and the function type
|
|
26
|
-
* (query/mutation/action). A `Standard` function declares its
|
|
27
|
-
*
|
|
28
|
-
*
|
|
50
|
+
* (query/mutation/action). A `Standard` function declares its args fields and
|
|
51
|
+
* returns schema directly; a `Paginated` function declares user-args fields
|
|
52
|
+
* and an item schema from which the Convex-facing `args`/`returns` are
|
|
53
|
+
* composed.
|
|
29
54
|
*/
|
|
30
55
|
export type ConfectKind = Standard | Paginated;
|
|
31
56
|
|
|
@@ -34,12 +59,12 @@ export interface Standard {
|
|
|
34
59
|
}
|
|
35
60
|
|
|
36
61
|
export interface Paginated<
|
|
37
|
-
|
|
62
|
+
UserArgsFields_ extends ArgsFields = ArgsFields,
|
|
38
63
|
Item extends Schema.Codec<any, any> = Schema.Codec<any, any>,
|
|
39
64
|
> {
|
|
40
65
|
readonly _tag: "Paginated";
|
|
41
66
|
/** User-declared args — no `paginationOpts`. */
|
|
42
|
-
readonly userArgs:
|
|
67
|
+
readonly userArgs: ArgsSchema<UserArgsFields_>;
|
|
43
68
|
/** Page element schema. */
|
|
44
69
|
readonly item: Item;
|
|
45
70
|
/** Mutable array of items — the page decode target. */
|
|
@@ -47,23 +72,26 @@ export interface Paginated<
|
|
|
47
72
|
}
|
|
48
73
|
|
|
49
74
|
export interface Confect<
|
|
50
|
-
|
|
75
|
+
ArgsFields_ extends ArgsFields,
|
|
51
76
|
Returns extends Schema.Codec<any, any>,
|
|
52
77
|
Error extends Schema.Codec<any, any> = never,
|
|
53
78
|
Kind extends ConfectKind = ConfectKind,
|
|
54
79
|
> {
|
|
55
80
|
readonly _tag: "Confect";
|
|
56
|
-
readonly
|
|
81
|
+
readonly "~ArgsFields": ArgsFields_;
|
|
82
|
+
readonly args: ArgsSchema<ArgsFields_>;
|
|
57
83
|
readonly returns: Returns;
|
|
58
84
|
readonly error?: Error;
|
|
59
85
|
readonly kind: Kind;
|
|
60
86
|
}
|
|
61
87
|
|
|
62
|
-
export interface AnyConfect
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
Schema.Codec<any, any
|
|
66
|
-
|
|
88
|
+
export interface AnyConfect {
|
|
89
|
+
readonly _tag: "Confect";
|
|
90
|
+
readonly args: AnyArgsSchema;
|
|
91
|
+
readonly returns: Schema.Codec<any, any>;
|
|
92
|
+
readonly error?: Schema.Codec<any, any>;
|
|
93
|
+
readonly kind: ConfectKind;
|
|
94
|
+
}
|
|
67
95
|
|
|
68
96
|
export interface Convex<Args extends DefaultFunctionArgs, Returns> {
|
|
69
97
|
readonly _tag: "Convex";
|
|
@@ -78,13 +106,13 @@ export const FunctionProvenance = Data.taggedEnum<FunctionProvenance>();
|
|
|
78
106
|
const Standard: Standard = { _tag: "Standard" };
|
|
79
107
|
|
|
80
108
|
/**
|
|
81
|
-
* Build a `Confect` provenance from lazy schema thunks.
|
|
82
|
-
* and `error` are exposed as sync lazy memoised getters
|
|
83
|
-
* that only evaluate their thunk on first
|
|
84
|
-
* defers `Fields`/`Doc`. This keeps importing the
|
|
85
|
-
* `_generated/spec.ts` cheap — no `Schema.Struct(...)` /
|
|
86
|
-
* work runs at module load; it is deferred to the first
|
|
87
|
-
* actually compiles validators or runs a codec.
|
|
109
|
+
* Build a `Confect` provenance from lazy args-fields and schema thunks.
|
|
110
|
+
* `args`, `returns`, and `error` are exposed as sync lazy memoised getters
|
|
111
|
+
* (via {@link Lazy.defineProperty}) that only evaluate their thunk on first
|
|
112
|
+
* access, mirroring how `Table` defers `Fields`/`Doc`. This keeps importing the
|
|
113
|
+
* assembled `_generated/spec.ts` cheap — no `Schema.Struct(...)` /
|
|
114
|
+
* `Schema.Array(...)` work runs at module load; it is deferred to the first
|
|
115
|
+
* invocation that actually compiles validators or runs a codec.
|
|
88
116
|
*
|
|
89
117
|
* The object is built by hand rather than through `FunctionProvenance.Confect`
|
|
90
118
|
* because the `Data` constructor copies its input with `Object.assign`, which
|
|
@@ -94,53 +122,40 @@ const Standard: Standard = { _tag: "Standard" };
|
|
|
94
122
|
* relies on `Data`'s structural `Equal`/`Hash` for provenance values.
|
|
95
123
|
*/
|
|
96
124
|
export const Confect = <
|
|
97
|
-
|
|
125
|
+
const ArgsFields_ extends ArgsFields,
|
|
98
126
|
Returns extends Schema.Codec<any, any>,
|
|
99
127
|
Error extends Schema.Codec<any, any> = never,
|
|
100
128
|
>(
|
|
101
|
-
args: () =>
|
|
129
|
+
args: () => ArgsFields_,
|
|
102
130
|
returns: () => Returns,
|
|
103
131
|
error?: () => Error,
|
|
104
|
-
): Confect<
|
|
132
|
+
): Confect<ArgsFields_, Returns, Error, Standard> => {
|
|
105
133
|
const provenance = { _tag: "Confect" as const, kind: Standard };
|
|
106
134
|
|
|
107
|
-
Lazy.defineProperty(provenance, "args", args);
|
|
135
|
+
Lazy.defineProperty(provenance, "args", () => Schema.Struct(args()));
|
|
108
136
|
Lazy.defineProperty(provenance, "returns", returns);
|
|
109
137
|
if (error !== undefined) {
|
|
110
138
|
Lazy.defineProperty(provenance, "error", error);
|
|
111
139
|
}
|
|
112
140
|
|
|
113
|
-
return provenance as Confect<
|
|
141
|
+
return provenance as Confect<ArgsFields_, Returns, Error, Standard>;
|
|
114
142
|
};
|
|
115
143
|
|
|
116
|
-
/**
|
|
117
|
-
* Any struct-shaped, context-free schema usable as a paginated query's user
|
|
118
|
-
* args. A structural bound rather than `Schema.Struct<Schema.Struct.Fields>`
|
|
119
|
-
* because `Schema.Struct` is not covariant in its fields parameter — concrete
|
|
120
|
-
* structs do not extend `Schema.Struct<Schema.Struct.Fields>`.
|
|
121
|
-
*/
|
|
122
|
-
// eslint-disable-next-line import/namespace -- oxlint's namespace resolution misses type-only exports, and `Schema` is an interface/namespace
|
|
123
|
-
export interface AnyUserArgs extends Schema.Codec<any, any> {
|
|
124
|
-
readonly fields: Schema.Struct.Fields;
|
|
125
|
-
}
|
|
126
|
-
|
|
127
144
|
/**
|
|
128
145
|
* The composed args schema of a paginated query: the user-declared fields
|
|
129
146
|
* plus the `paginationOpts` field managed by Convex's pagination protocol.
|
|
130
147
|
*
|
|
131
|
-
* The
|
|
132
|
-
*
|
|
133
|
-
* `UserArgs` is an unresolved type parameter; for concrete user args it
|
|
134
|
-
* evaluates away entirely.
|
|
148
|
+
* The fields-first representation keeps the user-declared map available for
|
|
149
|
+
* type-level composition without reconstructing it from an erased schema.
|
|
135
150
|
*/
|
|
136
|
-
export type
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
151
|
+
export type PaginatedArgsFields<UserArgsFields extends ArgsFields> =
|
|
152
|
+
UserArgsFields & {
|
|
153
|
+
readonly paginationOpts: typeof PaginationOptions.PaginationOptions;
|
|
154
|
+
};
|
|
155
|
+
|
|
156
|
+
export type PaginatedArgs<UserArgsFields extends ArgsFields> = Schema.Struct<
|
|
157
|
+
PaginatedArgsFields<UserArgsFields>
|
|
158
|
+
>;
|
|
144
159
|
|
|
145
160
|
/**
|
|
146
161
|
* The composed returns schema of a paginated query: a `PaginationResult` of
|
|
@@ -153,21 +168,19 @@ export type PaginatedReturns<Item extends Schema.Codec<any, any>> =
|
|
|
153
168
|
: never;
|
|
154
169
|
|
|
155
170
|
export interface ConfectPaginated<
|
|
156
|
-
|
|
171
|
+
UserArgsFields extends ArgsFields,
|
|
157
172
|
Item extends Schema.Codec<any, any>,
|
|
158
173
|
Error extends Schema.Codec<any, any> = never,
|
|
159
174
|
> extends Confect<
|
|
160
|
-
|
|
175
|
+
PaginatedArgsFields<UserArgsFields>,
|
|
161
176
|
PaginatedReturns<Item>,
|
|
162
177
|
Error,
|
|
163
|
-
Paginated<
|
|
178
|
+
Paginated<UserArgsFields, Item>
|
|
164
179
|
> {}
|
|
165
180
|
|
|
166
|
-
export interface AnyConfectPaginated extends
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
Schema.Codec<any, any>
|
|
170
|
-
> {}
|
|
181
|
+
export interface AnyConfectPaginated extends AnyConfect {
|
|
182
|
+
readonly kind: Paginated;
|
|
183
|
+
}
|
|
171
184
|
|
|
172
185
|
/**
|
|
173
186
|
* Build the provenance of a paginated query from lazy schema thunks, with the
|
|
@@ -180,25 +193,25 @@ export interface AnyConfectPaginated extends ConfectPaginated<
|
|
|
180
193
|
* composed schemas can never drift from the stored user schemas.
|
|
181
194
|
*/
|
|
182
195
|
export const ConfectPaginated = <
|
|
183
|
-
|
|
196
|
+
const UserArgsFields_ extends ArgsFields,
|
|
184
197
|
Item extends Schema.Codec<any, any>,
|
|
185
198
|
Error extends Schema.Codec<any, any> = never,
|
|
186
199
|
>(
|
|
187
|
-
userArgs: () =>
|
|
200
|
+
userArgs: () => UserArgsFields_,
|
|
188
201
|
item: () => Item,
|
|
189
202
|
error?: () => Error,
|
|
190
|
-
): ConfectPaginated<
|
|
203
|
+
): ConfectPaginated<UserArgsFields_, Item, Error> => {
|
|
191
204
|
const kind = { _tag: "Paginated" as const };
|
|
192
|
-
const paginatedKind = kind as Paginated<
|
|
205
|
+
const paginatedKind = kind as Paginated<UserArgsFields_, Item>;
|
|
193
206
|
|
|
194
|
-
Lazy.defineProperty(kind, "userArgs", userArgs);
|
|
207
|
+
Lazy.defineProperty(kind, "userArgs", () => Schema.Struct(userArgs()));
|
|
195
208
|
Lazy.defineProperty(kind, "item", item);
|
|
196
209
|
Lazy.defineProperty(kind, "page", () =>
|
|
197
210
|
Schema.mutable(Schema.Array(paginatedKind.item)),
|
|
198
211
|
);
|
|
199
212
|
|
|
200
213
|
const provenance = { _tag: "Confect" as const, kind: paginatedKind };
|
|
201
|
-
const self = provenance as ConfectPaginated<
|
|
214
|
+
const self = provenance as ConfectPaginated<UserArgsFields_, Item, Error>;
|
|
202
215
|
|
|
203
216
|
Lazy.defineProperty(provenance, "args", () => {
|
|
204
217
|
const fields = paginatedKind.userArgs.fields;
|
package/src/FunctionSpec.ts
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import type {
|
|
2
|
+
DefaultFunctionArgs,
|
|
2
3
|
FunctionType,
|
|
3
4
|
FunctionVisibility,
|
|
4
5
|
RegisteredAction,
|
|
5
6
|
RegisteredMutation,
|
|
6
7
|
RegisteredQuery,
|
|
7
8
|
} from "convex/server";
|
|
8
|
-
import * as Schema from "effect/Schema";
|
|
9
|
+
import type * as Schema from "effect/Schema";
|
|
9
10
|
import * as Predicate from "effect/Predicate";
|
|
10
11
|
import * as FunctionProvenance from "./FunctionProvenance";
|
|
11
12
|
import { validateConfectFunctionIdentifier } from "./Identifier";
|
|
@@ -127,86 +128,122 @@ export type GetRuntimeAndFunctionType<FunctionSpec_ extends AnyWithProps> =
|
|
|
127
128
|
export type GetFunctionVisibility<FunctionSpec_ extends AnyWithProps> =
|
|
128
129
|
FunctionSpec_["functionVisibility"];
|
|
129
130
|
|
|
131
|
+
export type GetFunctionProvenance<FunctionSpec_ extends AnyWithProps> =
|
|
132
|
+
FunctionSpec_["functionProvenance"];
|
|
133
|
+
|
|
130
134
|
export type Name<FunctionSpec_ extends AnyWithProps> = FunctionSpec_["name"];
|
|
131
135
|
|
|
132
136
|
export type MiddlewareSpecs<FunctionSpec_ extends AnyWithProps> =
|
|
133
137
|
FunctionSpec_["middlewareSpecs"][number];
|
|
134
138
|
|
|
139
|
+
/** The field map declared by a Confect-provenance spec. */
|
|
140
|
+
export type ArgsFields<FunctionSpec_ extends AnyWithProps> =
|
|
141
|
+
FunctionSpec_ extends {
|
|
142
|
+
readonly functionProvenance: {
|
|
143
|
+
readonly _tag: "Confect";
|
|
144
|
+
readonly "~ArgsFields": infer ArgsFields_ extends
|
|
145
|
+
FunctionProvenance.ArgsFields;
|
|
146
|
+
};
|
|
147
|
+
}
|
|
148
|
+
? ArgsFields_
|
|
149
|
+
: FunctionSpec_ extends {
|
|
150
|
+
readonly functionProvenance: { readonly _tag: "Confect" };
|
|
151
|
+
}
|
|
152
|
+
? FunctionProvenance.ArgsFields
|
|
153
|
+
: never;
|
|
154
|
+
|
|
155
|
+
/** The args schema assembled from a Confect-provenance spec's field map. */
|
|
156
|
+
export type ArgsSchema<FunctionSpec_ extends AnyWithProps> =
|
|
157
|
+
FunctionSpec_ extends {
|
|
158
|
+
readonly functionProvenance: {
|
|
159
|
+
readonly _tag: "Confect";
|
|
160
|
+
readonly "~ArgsFields": infer ArgsFields_ extends
|
|
161
|
+
FunctionProvenance.ArgsFields;
|
|
162
|
+
};
|
|
163
|
+
}
|
|
164
|
+
? Schema.Struct<ArgsFields_>
|
|
165
|
+
: FunctionSpec_ extends {
|
|
166
|
+
readonly functionProvenance: {
|
|
167
|
+
readonly _tag: "Confect";
|
|
168
|
+
readonly args: infer ArgsSchema_ extends
|
|
169
|
+
FunctionProvenance.AnyArgsSchema;
|
|
170
|
+
};
|
|
171
|
+
}
|
|
172
|
+
? ArgsSchema_
|
|
173
|
+
: never;
|
|
174
|
+
|
|
175
|
+
export type ReturnsSchema<FunctionSpec_ extends AnyWithProps> =
|
|
176
|
+
FunctionSpec_ extends {
|
|
177
|
+
readonly functionProvenance: {
|
|
178
|
+
readonly _tag: "Confect";
|
|
179
|
+
readonly returns: infer ReturnsSchema_ extends Schema.Codec<any, any>;
|
|
180
|
+
};
|
|
181
|
+
}
|
|
182
|
+
? ReturnsSchema_
|
|
183
|
+
: never;
|
|
184
|
+
|
|
185
|
+
export type ErrorSchema<FunctionSpec_ extends AnyWithProps> =
|
|
186
|
+
FunctionSpec_ extends {
|
|
187
|
+
readonly functionProvenance: {
|
|
188
|
+
readonly _tag: "Confect";
|
|
189
|
+
readonly error?: infer ErrorSchema_ extends Schema.Codec<any, any>;
|
|
190
|
+
};
|
|
191
|
+
}
|
|
192
|
+
? ErrorSchema_
|
|
193
|
+
: never;
|
|
194
|
+
|
|
135
195
|
export type Args<FunctionSpec_ extends AnyWithProps> = FunctionSpec_ extends {
|
|
136
|
-
functionProvenance: {
|
|
137
|
-
_tag: "Confect";
|
|
138
|
-
args: infer ArgsSchema_ extends Schema.Codec<any, any>;
|
|
139
|
-
};
|
|
196
|
+
readonly functionProvenance: { readonly _tag: "Confect" };
|
|
140
197
|
}
|
|
141
|
-
?
|
|
142
|
-
: FunctionSpec_ extends
|
|
143
|
-
|
|
144
|
-
|
|
198
|
+
? ArgsSchema<FunctionSpec_>["Type"]
|
|
199
|
+
: GetFunctionProvenance<FunctionSpec_> extends FunctionProvenance.Convex<
|
|
200
|
+
infer Args_,
|
|
201
|
+
any
|
|
202
|
+
>
|
|
145
203
|
? Args_
|
|
146
204
|
: never;
|
|
147
205
|
|
|
148
206
|
export type Returns<FunctionSpec_ extends AnyWithProps> =
|
|
149
207
|
FunctionSpec_ extends {
|
|
150
|
-
functionProvenance: {
|
|
151
|
-
_tag: "Confect";
|
|
152
|
-
returns: infer ReturnsSchema_ extends Schema.Codec<any, any>;
|
|
153
|
-
};
|
|
208
|
+
readonly functionProvenance: { readonly _tag: "Confect" };
|
|
154
209
|
}
|
|
155
|
-
?
|
|
156
|
-
: FunctionSpec_ extends
|
|
157
|
-
|
|
158
|
-
|
|
210
|
+
? ReturnsSchema<FunctionSpec_>["Type"]
|
|
211
|
+
: GetFunctionProvenance<FunctionSpec_> extends FunctionProvenance.Convex<
|
|
212
|
+
any,
|
|
213
|
+
infer Returns_
|
|
214
|
+
>
|
|
159
215
|
? Awaited<Returns_>
|
|
160
216
|
: never;
|
|
161
217
|
|
|
162
218
|
export type EncodedArgs<FunctionSpec_ extends AnyWithProps> =
|
|
163
219
|
FunctionSpec_ extends {
|
|
164
|
-
functionProvenance: {
|
|
165
|
-
_tag: "Confect";
|
|
166
|
-
args: infer ArgsSchema_ extends Schema.Codec<any, any>;
|
|
167
|
-
};
|
|
220
|
+
readonly functionProvenance: { readonly _tag: "Confect" };
|
|
168
221
|
}
|
|
169
|
-
?
|
|
170
|
-
: FunctionSpec_ extends
|
|
171
|
-
|
|
172
|
-
|
|
222
|
+
? ArgsSchema<FunctionSpec_>["Encoded"]
|
|
223
|
+
: GetFunctionProvenance<FunctionSpec_> extends FunctionProvenance.Convex<
|
|
224
|
+
infer Args_,
|
|
225
|
+
any
|
|
226
|
+
>
|
|
173
227
|
? Args_
|
|
174
228
|
: never;
|
|
175
229
|
|
|
176
230
|
export type EncodedReturns<FunctionSpec_ extends AnyWithProps> =
|
|
177
231
|
FunctionSpec_ extends {
|
|
178
|
-
functionProvenance: {
|
|
179
|
-
_tag: "Confect";
|
|
180
|
-
returns: infer ReturnsSchema_ extends Schema.Codec<any, any>;
|
|
181
|
-
};
|
|
232
|
+
readonly functionProvenance: { readonly _tag: "Confect" };
|
|
182
233
|
}
|
|
183
|
-
?
|
|
184
|
-
: FunctionSpec_ extends
|
|
185
|
-
|
|
186
|
-
|
|
234
|
+
? ReturnsSchema<FunctionSpec_>["Encoded"]
|
|
235
|
+
: GetFunctionProvenance<FunctionSpec_> extends FunctionProvenance.Convex<
|
|
236
|
+
any,
|
|
237
|
+
infer Returns_
|
|
238
|
+
>
|
|
187
239
|
? Returns_
|
|
188
240
|
: never;
|
|
189
241
|
|
|
190
|
-
export type Error<FunctionSpec_ extends AnyWithProps> =
|
|
191
|
-
|
|
192
|
-
any,
|
|
193
|
-
any,
|
|
194
|
-
infer ErrorSchema_ extends Schema.Codec<any, any>
|
|
195
|
-
>;
|
|
196
|
-
}
|
|
197
|
-
? ErrorSchema_["Type"]
|
|
198
|
-
: never;
|
|
242
|
+
export type Error<FunctionSpec_ extends AnyWithProps> =
|
|
243
|
+
ErrorSchema<FunctionSpec_>["Type"];
|
|
199
244
|
|
|
200
245
|
export type EncodedError<FunctionSpec_ extends AnyWithProps> =
|
|
201
|
-
FunctionSpec_
|
|
202
|
-
functionProvenance: FunctionProvenance.Confect<
|
|
203
|
-
any,
|
|
204
|
-
any,
|
|
205
|
-
infer ErrorSchema_ extends Schema.Codec<any, any>
|
|
206
|
-
>;
|
|
207
|
-
}
|
|
208
|
-
? ErrorSchema_["Encoded"]
|
|
209
|
-
: never;
|
|
246
|
+
ErrorSchema<FunctionSpec_>["Encoded"];
|
|
210
247
|
|
|
211
248
|
export type WithName<
|
|
212
249
|
FunctionSpec_ extends AnyWithProps,
|
|
@@ -280,46 +317,68 @@ const Proto = {
|
|
|
280
317
|
},
|
|
281
318
|
};
|
|
282
319
|
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
320
|
+
interface Options {
|
|
321
|
+
readonly name: string;
|
|
322
|
+
readonly args?: () => FunctionProvenance.ArgsFields;
|
|
323
|
+
readonly returns: () => Schema.Codec<any, any>;
|
|
324
|
+
readonly error?: () => Schema.Codec<any, any>;
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
const make = <
|
|
328
|
+
RuntimeAndFunctionType_ extends RuntimeAndFunctionType.RuntimeAndFunctionType,
|
|
329
|
+
FunctionVisibility_ extends FunctionVisibility,
|
|
330
|
+
>(
|
|
331
|
+
runtimeAndFunctionType: RuntimeAndFunctionType_,
|
|
332
|
+
functionVisibility: FunctionVisibility_,
|
|
333
|
+
) => {
|
|
334
|
+
function makeSpec<
|
|
293
335
|
const Name_ extends string,
|
|
294
|
-
|
|
336
|
+
const ArgsFields_ extends FunctionProvenance.ArgsFields,
|
|
295
337
|
Returns_ extends Schema.Codec<any, any>,
|
|
296
338
|
Error_ extends Schema.Codec<any, any> = never,
|
|
297
|
-
>({
|
|
298
|
-
name,
|
|
299
|
-
args,
|
|
300
|
-
returns,
|
|
301
|
-
error,
|
|
302
|
-
}: {
|
|
339
|
+
>(options: {
|
|
303
340
|
name: Name_;
|
|
304
|
-
args: () =>
|
|
341
|
+
args: () => ArgsFields_;
|
|
305
342
|
returns: () => Returns_;
|
|
306
343
|
error?: () => Error_;
|
|
307
344
|
}): Builder<
|
|
308
345
|
RuntimeAndFunctionType_,
|
|
309
346
|
FunctionVisibility_,
|
|
310
347
|
Name_,
|
|
311
|
-
FunctionProvenance.Confect<
|
|
312
|
-
|
|
348
|
+
FunctionProvenance.Confect<ArgsFields_, Returns_, Error_>
|
|
349
|
+
>;
|
|
350
|
+
function makeSpec<
|
|
351
|
+
const Name_ extends string,
|
|
352
|
+
Returns_ extends Schema.Codec<any, any>,
|
|
353
|
+
Error_ extends Schema.Codec<any, any> = never,
|
|
354
|
+
>(options: {
|
|
355
|
+
name: Name_;
|
|
356
|
+
args?: never;
|
|
357
|
+
returns: () => Returns_;
|
|
358
|
+
error?: () => Error_;
|
|
359
|
+
}): Builder<
|
|
360
|
+
RuntimeAndFunctionType_,
|
|
361
|
+
FunctionVisibility_,
|
|
362
|
+
Name_,
|
|
363
|
+
FunctionProvenance.Confect<{}, Returns_, Error_>
|
|
364
|
+
>;
|
|
365
|
+
function makeSpec({ name, args, returns, error }: Options) {
|
|
313
366
|
validateConfectFunctionIdentifier(name);
|
|
314
367
|
|
|
315
368
|
return Object.assign(Object.create(Proto), {
|
|
316
369
|
runtimeAndFunctionType,
|
|
317
370
|
functionVisibility,
|
|
318
371
|
name,
|
|
319
|
-
functionProvenance:
|
|
372
|
+
functionProvenance:
|
|
373
|
+
args === undefined
|
|
374
|
+
? FunctionProvenance.Confect(() => ({}), returns, error)
|
|
375
|
+
: FunctionProvenance.Confect(args, returns, error),
|
|
320
376
|
middlewareSpecs: [],
|
|
321
377
|
});
|
|
322
|
-
}
|
|
378
|
+
}
|
|
379
|
+
|
|
380
|
+
return makeSpec;
|
|
381
|
+
};
|
|
323
382
|
|
|
324
383
|
/**
|
|
325
384
|
* `Schema.Struct` fields that must not declare `paginationOpts`. Used to
|
|
@@ -327,58 +386,74 @@ const make =
|
|
|
327
386
|
* constructors add themselves; the check reports at the `args` thunk with an
|
|
328
387
|
* unsatisfiable type when violated.
|
|
329
388
|
*/
|
|
330
|
-
type ForbidPaginationOpts<
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
389
|
+
type ForbidPaginationOpts<
|
|
390
|
+
UserArgsFields extends FunctionProvenance.ArgsFields,
|
|
391
|
+
> = "paginationOpts" extends keyof UserArgsFields
|
|
392
|
+
? { readonly paginationOpts: never }
|
|
393
|
+
: unknown;
|
|
394
|
+
|
|
395
|
+
interface PaginatedOptions {
|
|
396
|
+
readonly name: string;
|
|
397
|
+
readonly args?: () => FunctionProvenance.ArgsFields;
|
|
398
|
+
readonly item: () => Schema.Codec<any, any>;
|
|
399
|
+
readonly error?: () => Schema.Codec<any, any>;
|
|
400
|
+
}
|
|
334
401
|
|
|
335
|
-
const makePaginated =
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
) =>
|
|
344
|
-
<
|
|
402
|
+
const makePaginated = <
|
|
403
|
+
RuntimeAndFunctionType_ extends RuntimeAndFunctionType.RuntimeAndFunctionType,
|
|
404
|
+
FunctionVisibility_ extends FunctionVisibility,
|
|
405
|
+
>(
|
|
406
|
+
runtimeAndFunctionType: RuntimeAndFunctionType_,
|
|
407
|
+
functionVisibility: FunctionVisibility_,
|
|
408
|
+
) => {
|
|
409
|
+
function makeSpec<
|
|
345
410
|
const Name_ extends string,
|
|
411
|
+
const UserArgsFields_ extends FunctionProvenance.ArgsFields,
|
|
346
412
|
Item_ extends Schema.Codec<any, any>,
|
|
347
|
-
UserArgs_ extends FunctionProvenance.AnyUserArgs = Schema.Struct<{}>,
|
|
348
413
|
Error_ extends Schema.Codec<any, any> = never,
|
|
349
|
-
>({
|
|
350
|
-
name,
|
|
351
|
-
args,
|
|
352
|
-
item,
|
|
353
|
-
error,
|
|
354
|
-
}: {
|
|
414
|
+
>(options: {
|
|
355
415
|
name: Name_;
|
|
356
|
-
|
|
357
|
-
args?: (() => UserArgs_) & ForbidPaginationOpts<UserArgs_>;
|
|
358
|
-
/** The page element schema. */
|
|
416
|
+
args: () => UserArgsFields_ & ForbidPaginationOpts<UserArgsFields_>;
|
|
359
417
|
item: () => Item_;
|
|
360
418
|
error?: () => Error_;
|
|
361
419
|
}): Builder<
|
|
362
420
|
RuntimeAndFunctionType_,
|
|
363
421
|
FunctionVisibility_,
|
|
364
422
|
Name_,
|
|
365
|
-
FunctionProvenance.ConfectPaginated<
|
|
366
|
-
|
|
423
|
+
FunctionProvenance.ConfectPaginated<UserArgsFields_, Item_, Error_>
|
|
424
|
+
>;
|
|
425
|
+
function makeSpec<
|
|
426
|
+
const Name_ extends string,
|
|
427
|
+
Item_ extends Schema.Codec<any, any>,
|
|
428
|
+
Error_ extends Schema.Codec<any, any> = never,
|
|
429
|
+
>(options: {
|
|
430
|
+
name: Name_;
|
|
431
|
+
args?: never;
|
|
432
|
+
item: () => Item_;
|
|
433
|
+
error?: () => Error_;
|
|
434
|
+
}): Builder<
|
|
435
|
+
RuntimeAndFunctionType_,
|
|
436
|
+
FunctionVisibility_,
|
|
437
|
+
Name_,
|
|
438
|
+
FunctionProvenance.ConfectPaginated<{}, Item_, Error_>
|
|
439
|
+
>;
|
|
440
|
+
function makeSpec({ name, args, item, error }: PaginatedOptions) {
|
|
367
441
|
validateConfectFunctionIdentifier(name);
|
|
368
442
|
|
|
369
443
|
return Object.assign(Object.create(Proto), {
|
|
370
444
|
runtimeAndFunctionType,
|
|
371
445
|
functionVisibility,
|
|
372
446
|
name,
|
|
373
|
-
functionProvenance:
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
error,
|
|
378
|
-
),
|
|
447
|
+
functionProvenance:
|
|
448
|
+
args === undefined
|
|
449
|
+
? FunctionProvenance.ConfectPaginated(() => ({}), item, error)
|
|
450
|
+
: FunctionProvenance.ConfectPaginated(args, item, error),
|
|
379
451
|
middlewareSpecs: [],
|
|
380
452
|
});
|
|
381
|
-
}
|
|
453
|
+
}
|
|
454
|
+
|
|
455
|
+
return makeSpec;
|
|
456
|
+
};
|
|
382
457
|
|
|
383
458
|
export const publicQuery = make(RuntimeAndFunctionType.ConvexQuery, "public");
|
|
384
459
|
export const internalQuery = make(
|
|
@@ -429,11 +504,19 @@ type MatchingRegisteredFunction<
|
|
|
429
504
|
: never;
|
|
430
505
|
|
|
431
506
|
type ExtractArgs<F> =
|
|
432
|
-
F extends RegisteredQuery<any, infer A, any>
|
|
507
|
+
F extends RegisteredQuery<any, infer A extends DefaultFunctionArgs, any>
|
|
433
508
|
? A
|
|
434
|
-
: F extends RegisteredMutation<
|
|
509
|
+
: F extends RegisteredMutation<
|
|
510
|
+
any,
|
|
511
|
+
infer A extends DefaultFunctionArgs,
|
|
512
|
+
any
|
|
513
|
+
>
|
|
435
514
|
? A
|
|
436
|
-
: F extends RegisteredAction<
|
|
515
|
+
: F extends RegisteredAction<
|
|
516
|
+
any,
|
|
517
|
+
infer A extends DefaultFunctionArgs,
|
|
518
|
+
any
|
|
519
|
+
>
|
|
437
520
|
? A
|
|
438
521
|
: never;
|
|
439
522
|
|