@confect/core 10.0.0-next.8 → 10.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 +966 -46
- package/README.md +3 -1
- package/dist/FunctionProvenance.d.ts +166 -68
- package/dist/FunctionProvenance.d.ts.map +1 -1
- package/dist/FunctionProvenance.js +55 -13
- package/dist/FunctionProvenance.js.map +1 -1
- package/dist/FunctionSpec.d.ts +320 -138
- package/dist/FunctionSpec.d.ts.map +1 -1
- package/dist/FunctionSpec.js +56 -13
- package/dist/FunctionSpec.js.map +1 -1
- package/dist/GenericId.d.ts.map +1 -1
- package/dist/GenericId.js +1 -1
- package/dist/GroupPath.d.ts +6 -10
- package/dist/GroupPath.d.ts.map +1 -1
- package/dist/GroupPath.js.map +1 -1
- package/dist/GroupSpec.d.ts +25 -12
- package/dist/GroupSpec.d.ts.map +1 -1
- package/dist/GroupSpec.js +51 -14
- package/dist/GroupSpec.js.map +1 -1
- package/dist/Identifier.d.ts +6 -5
- package/dist/Identifier.d.ts.map +1 -1
- package/dist/Identifier.js +6 -5
- package/dist/Identifier.js.map +1 -1
- package/dist/Lazy.d.ts +11 -14
- package/dist/Lazy.d.ts.map +1 -1
- package/dist/Lazy.js +11 -14
- package/dist/Lazy.js.map +1 -1
- package/dist/MiddlewareAttachment.d.ts +171 -0
- package/dist/MiddlewareAttachment.d.ts.map +1 -0
- package/dist/MiddlewareAttachment.js +48 -0
- package/dist/MiddlewareAttachment.js.map +1 -0
- package/dist/MiddlewareSpec.d.ts +198 -0
- package/dist/MiddlewareSpec.d.ts.map +1 -0
- package/dist/MiddlewareSpec.js +60 -0
- package/dist/MiddlewareSpec.js.map +1 -0
- package/dist/PaginationError.d.ts +20 -0
- package/dist/PaginationError.d.ts.map +1 -0
- package/dist/PaginationError.js +31 -0
- package/dist/PaginationError.js.map +1 -0
- package/dist/PaginationOptions.d.ts +23 -0
- package/dist/PaginationOptions.d.ts.map +1 -0
- package/dist/PaginationOptions.js +29 -0
- package/dist/PaginationOptions.js.map +1 -0
- package/dist/PaginationResult.d.ts +1 -0
- package/dist/PaginationResult.d.ts.map +1 -1
- package/dist/PaginationResult.js.map +1 -1
- package/dist/Ref.d.ts +135 -47
- package/dist/Ref.d.ts.map +1 -1
- package/dist/Ref.js +104 -46
- package/dist/Ref.js.map +1 -1
- package/dist/Refs.d.ts +10 -5
- package/dist/Refs.d.ts.map +1 -1
- package/dist/Refs.js +5 -4
- package/dist/Refs.js.map +1 -1
- package/dist/SchemaToValidator.d.ts +99 -0
- package/dist/SchemaToValidator.d.ts.map +1 -0
- package/dist/SchemaToValidator.js +158 -0
- package/dist/SchemaToValidator.js.map +1 -0
- package/dist/Spec.d.ts +16 -12
- package/dist/Spec.d.ts.map +1 -1
- package/dist/Spec.js +14 -9
- package/dist/Spec.js.map +1 -1
- package/dist/SystemFields.d.ts +16 -15
- package/dist/SystemFields.d.ts.map +1 -1
- package/dist/SystemFields.js +16 -15
- package/dist/SystemFields.js.map +1 -1
- package/dist/Table.d.ts +75 -0
- package/dist/Table.d.ts.map +1 -0
- package/dist/Table.js +77 -0
- package/dist/Table.js.map +1 -0
- package/dist/Types.d.ts +8 -2
- package/dist/Types.d.ts.map +1 -1
- package/dist/Types.js.map +1 -1
- package/dist/UserIdentity.d.ts.map +1 -1
- package/dist/index.d.ts +6 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +9 -4
- package/package.json +17 -15
- package/src/FunctionProvenance.ts +197 -34
- package/src/FunctionSpec.ts +332 -86
- package/src/GroupPath.ts +6 -12
- package/src/GroupSpec.ts +184 -25
- package/src/Identifier.ts +6 -5
- package/src/Lazy.ts +11 -14
- package/src/MiddlewareAttachment.ts +106 -0
- package/src/MiddlewareSpec.ts +392 -0
- package/src/PaginationError.ts +78 -0
- package/src/PaginationOptions.ts +23 -0
- package/src/PaginationResult.ts +4 -0
- package/src/Ref.ts +468 -236
- package/src/Refs.ts +43 -18
- package/src/SchemaToValidator.ts +612 -0
- package/src/Spec.ts +50 -39
- package/src/SystemFields.ts +32 -36
- package/src/Table.ts +427 -0
- package/src/Types.ts +9 -3
- package/src/index.ts +6 -1
- package/dist/Registry.d.ts +0 -24
- package/dist/Registry.d.ts.map +0 -1
- package/dist/Registry.js +0 -19
- package/dist/Registry.js.map +0 -1
- package/dist/tsconfig.src.tsbuildinfo +0 -1
- package/src/Registry.ts +0 -30
|
@@ -1,89 +1,252 @@
|
|
|
1
1
|
import type { DefaultFunctionArgs } from "convex/server";
|
|
2
|
-
import type { Schema } from "effect";
|
|
3
2
|
import * as Data from "effect/Data";
|
|
3
|
+
import * as Schema from "effect/Schema";
|
|
4
4
|
import * as Lazy from "./Lazy";
|
|
5
|
+
import * as PaginationOptions from "./PaginationOptions";
|
|
6
|
+
import * as PaginationResult from "./PaginationResult";
|
|
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
|
+
export type ArgsFields = {
|
|
14
|
+
readonly [key: PropertyKey]: Schema.ConstraintCodec<any, any>;
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* A struct-shaped Confect args schema that keeps its exact field map while
|
|
19
|
+
* erasing the rest of `Schema.Struct`'s large implementation type. Decoded and
|
|
20
|
+
* encoded args are derived directly from `ArgsFields_`; keeping the runtime
|
|
21
|
+
* codec structural prevents every ref lookup from expanding the full Effect
|
|
22
|
+
* schema type.
|
|
23
|
+
*/
|
|
24
|
+
export interface ArgsSchema<
|
|
25
|
+
ArgsFields_ extends ArgsFields,
|
|
26
|
+
> extends Schema.Codec<any, any> {
|
|
27
|
+
readonly fields: ArgsFields_;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Erased structural view used after the exact field map is no longer needed.
|
|
32
|
+
*/
|
|
33
|
+
export type AnyArgsSchema = ArgsSchema<ArgsFields>;
|
|
5
34
|
|
|
6
35
|
export type FunctionProvenance = Data.TaggedEnum<{
|
|
7
36
|
Confect: {
|
|
8
|
-
args:
|
|
37
|
+
args: AnyArgsSchema;
|
|
9
38
|
returns: Schema.Codec<any, any>;
|
|
10
39
|
error?: Schema.Codec<any, any>;
|
|
40
|
+
kind: ConfectKind;
|
|
11
41
|
};
|
|
12
42
|
Convex: {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
/** @internal */
|
|
16
|
-
_returns: any;
|
|
43
|
+
"~args": DefaultFunctionArgs;
|
|
44
|
+
"~returns": any;
|
|
17
45
|
};
|
|
18
46
|
}>;
|
|
19
47
|
|
|
48
|
+
/**
|
|
49
|
+
* The declaration shape of a Confect function—orthogonal to both the provenance
|
|
50
|
+
* origin (Confect vs Convex) and the function type (query/mutation/action). A
|
|
51
|
+
* `Standard` function declares its args fields and returns schema directly; a
|
|
52
|
+
* `Paginated` function declares user-args fields and an item schema from which
|
|
53
|
+
* the Convex-facing `args`/`returns` are composed.
|
|
54
|
+
*/
|
|
55
|
+
export type ConfectKind = Standard | Paginated;
|
|
56
|
+
|
|
57
|
+
export interface Standard {
|
|
58
|
+
readonly _tag: "Standard";
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
export interface Paginated<
|
|
62
|
+
UserArgsFields_ extends ArgsFields = ArgsFields,
|
|
63
|
+
Item extends Schema.Codec<any, any> = Schema.Codec<any, any>,
|
|
64
|
+
> {
|
|
65
|
+
readonly _tag: "Paginated";
|
|
66
|
+
/**
|
|
67
|
+
* User-declared args—no `paginationOpts`.
|
|
68
|
+
*/
|
|
69
|
+
readonly userArgs: ArgsSchema<UserArgsFields_>;
|
|
70
|
+
/**
|
|
71
|
+
* Page element schema.
|
|
72
|
+
*/
|
|
73
|
+
readonly item: Item;
|
|
74
|
+
/**
|
|
75
|
+
* Mutable array of items—the page decode target.
|
|
76
|
+
*/
|
|
77
|
+
readonly page: Schema.Codec<any, any>;
|
|
78
|
+
}
|
|
79
|
+
|
|
20
80
|
export interface Confect<
|
|
21
|
-
|
|
81
|
+
ArgsFields_ extends ArgsFields,
|
|
22
82
|
Returns extends Schema.Codec<any, any>,
|
|
23
83
|
Error extends Schema.Codec<any, any> = never,
|
|
84
|
+
Kind extends ConfectKind = ConfectKind,
|
|
24
85
|
> {
|
|
25
86
|
readonly _tag: "Confect";
|
|
26
|
-
readonly
|
|
87
|
+
readonly "~ArgsFields": ArgsFields_;
|
|
88
|
+
readonly args: ArgsSchema<ArgsFields_>;
|
|
27
89
|
readonly returns: Returns;
|
|
28
90
|
readonly error?: Error;
|
|
91
|
+
readonly kind: Kind;
|
|
29
92
|
}
|
|
30
93
|
|
|
31
|
-
export interface AnyConfect
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
Schema.Codec<any, any
|
|
35
|
-
|
|
94
|
+
export interface AnyConfect {
|
|
95
|
+
readonly _tag: "Confect";
|
|
96
|
+
readonly args: AnyArgsSchema;
|
|
97
|
+
readonly returns: Schema.Codec<any, any>;
|
|
98
|
+
readonly error?: Schema.Codec<any, any>;
|
|
99
|
+
readonly kind: ConfectKind;
|
|
100
|
+
}
|
|
36
101
|
|
|
37
102
|
export interface Convex<Args extends DefaultFunctionArgs, Returns> {
|
|
38
103
|
readonly _tag: "Convex";
|
|
39
|
-
readonly
|
|
40
|
-
readonly
|
|
104
|
+
readonly "~args": Args;
|
|
105
|
+
readonly "~returns": Returns;
|
|
41
106
|
}
|
|
42
107
|
|
|
43
108
|
export interface AnyConvex extends Convex<DefaultFunctionArgs, any> {}
|
|
44
109
|
|
|
45
110
|
export const FunctionProvenance = Data.taggedEnum<FunctionProvenance>();
|
|
46
111
|
|
|
112
|
+
const Standard: Standard = { _tag: "Standard" };
|
|
113
|
+
|
|
47
114
|
/**
|
|
48
|
-
* Build a `Confect` provenance from lazy schema thunks. `args`,
|
|
49
|
-
* and `error` are exposed as sync lazy memoised getters (via
|
|
50
|
-
* that only evaluate their thunk on first access,
|
|
51
|
-
* defers `Fields`/`Doc
|
|
52
|
-
* `_generated/spec.ts` cheap
|
|
53
|
-
* work runs at module load; it is
|
|
54
|
-
* actually compiles validators or runs a
|
|
115
|
+
* Build a `Confect` provenance from lazy args-fields and schema thunks. `args`,
|
|
116
|
+
* `returns`, and `error` are exposed as sync lazy memoised getters (via
|
|
117
|
+
* {@link Lazy.defineProperty}) that only evaluate their thunk on first access,
|
|
118
|
+
* mirroring how `Table` defers `Fields`/`Doc`. This keeps importing the
|
|
119
|
+
* assembled `_generated/spec.ts` cheap—no
|
|
120
|
+
* `Schema.Struct(...)`/`Schema.Array(...)` work runs at module load; it is
|
|
121
|
+
* deferred to the first invocation that actually compiles validators or runs a
|
|
122
|
+
* codec.
|
|
55
123
|
*
|
|
56
124
|
* The object is built by hand rather than through `FunctionProvenance.Confect`
|
|
57
125
|
* because the `Data` constructor copies its input with `Object.assign`, which
|
|
58
|
-
* would force the getters at construction time and defeat the laziness.
|
|
59
|
-
*
|
|
60
|
-
*
|
|
126
|
+
* would force the getters at construction time and defeat the laziness. `error`
|
|
127
|
+
* is only installed when an `errorThunk` is provided, so its absence is
|
|
128
|
+
* observable via `"error" in provenance` without forcing anything; nothing
|
|
61
129
|
* relies on `Data`'s structural `Equal`/`Hash` for provenance values.
|
|
62
130
|
*/
|
|
63
131
|
export const Confect = <
|
|
64
|
-
|
|
132
|
+
const ArgsFields_ extends ArgsFields,
|
|
65
133
|
Returns extends Schema.Codec<any, any>,
|
|
66
134
|
Error extends Schema.Codec<any, any> = never,
|
|
67
135
|
>(
|
|
68
|
-
args: () =>
|
|
136
|
+
args: () => ArgsFields_,
|
|
69
137
|
returns: () => Returns,
|
|
70
138
|
error?: () => Error,
|
|
71
|
-
): Confect<
|
|
72
|
-
const provenance = { _tag: "Confect" as const };
|
|
139
|
+
): Confect<ArgsFields_, Returns, Error, Standard> => {
|
|
140
|
+
const provenance = { _tag: "Confect" as const, kind: Standard };
|
|
73
141
|
|
|
74
|
-
Lazy.defineProperty(provenance, "args", args);
|
|
142
|
+
Lazy.defineProperty(provenance, "args", () => Schema.Struct(args()));
|
|
75
143
|
Lazy.defineProperty(provenance, "returns", returns);
|
|
76
144
|
if (error !== undefined) {
|
|
77
145
|
Lazy.defineProperty(provenance, "error", error);
|
|
78
146
|
}
|
|
79
147
|
|
|
80
|
-
return provenance as Confect<
|
|
148
|
+
return provenance as Confect<ArgsFields_, Returns, Error, Standard>;
|
|
149
|
+
};
|
|
150
|
+
|
|
151
|
+
/**
|
|
152
|
+
* The composed args schema of a paginated query: the user-declared fields plus
|
|
153
|
+
* the `paginationOpts` field managed by Convex's pagination protocol.
|
|
154
|
+
*
|
|
155
|
+
* The fields-first representation keeps the user-declared map available for
|
|
156
|
+
* type-level composition without reconstructing it from an erased schema.
|
|
157
|
+
*/
|
|
158
|
+
export type PaginatedArgsFields<UserArgsFields extends ArgsFields> =
|
|
159
|
+
UserArgsFields & {
|
|
160
|
+
readonly paginationOpts: typeof PaginationOptions.PaginationOptions;
|
|
161
|
+
};
|
|
162
|
+
|
|
163
|
+
export type PaginatedArgs<UserArgsFields extends ArgsFields> = Schema.Struct<
|
|
164
|
+
PaginatedArgsFields<UserArgsFields>
|
|
165
|
+
>;
|
|
166
|
+
|
|
167
|
+
/**
|
|
168
|
+
* The composed returns schema of a paginated query: a `PaginationResult` of the
|
|
169
|
+
* item schema. Same deferred-conditional device as {@link PaginatedArgs}.
|
|
170
|
+
*/
|
|
171
|
+
export type PaginatedReturns<Item extends Schema.Codec<any, any>> =
|
|
172
|
+
PaginationResult.PaginationResult<Item> extends infer ComposedReturns extends
|
|
173
|
+
Schema.Codec<any, any>
|
|
174
|
+
? ComposedReturns
|
|
175
|
+
: never;
|
|
176
|
+
|
|
177
|
+
export interface ConfectPaginated<
|
|
178
|
+
UserArgsFields extends ArgsFields,
|
|
179
|
+
Item extends Schema.Codec<any, any>,
|
|
180
|
+
Error extends Schema.Codec<any, any> = never,
|
|
181
|
+
> extends Confect<
|
|
182
|
+
PaginatedArgsFields<UserArgsFields>,
|
|
183
|
+
PaginatedReturns<Item>,
|
|
184
|
+
Error,
|
|
185
|
+
Paginated<UserArgsFields, Item>
|
|
186
|
+
> {}
|
|
187
|
+
|
|
188
|
+
export interface AnyConfectPaginated extends AnyConfect {
|
|
189
|
+
readonly kind: Paginated;
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
/**
|
|
193
|
+
* Build the provenance of a paginated query from lazy schema thunks, with the
|
|
194
|
+
* same laziness contract as {@link Confect}. The user-facing schemas live on the
|
|
195
|
+
* `Paginated` kind (`kind.userArgs`, `kind.item`, `kind.page`)—the kind
|
|
196
|
+
* container is built eagerly (it is cheap) while the schemas inside it stay
|
|
197
|
+
* lazy. The composed Convex-facing `args`/`returns` are derived lazily from
|
|
198
|
+
* them: `args` spreads the user fields plus `paginationOpts`, and `returns`
|
|
199
|
+
* wraps the item in `PaginationResult`. Composition living here means the
|
|
200
|
+
* composed schemas can never drift from the stored user schemas.
|
|
201
|
+
*/
|
|
202
|
+
export const ConfectPaginated = <
|
|
203
|
+
const UserArgsFields_ extends ArgsFields,
|
|
204
|
+
Item extends Schema.Codec<any, any>,
|
|
205
|
+
Error extends Schema.Codec<any, any> = never,
|
|
206
|
+
>(
|
|
207
|
+
userArgs: () => UserArgsFields_,
|
|
208
|
+
item: () => Item,
|
|
209
|
+
error?: () => Error,
|
|
210
|
+
): ConfectPaginated<UserArgsFields_, Item, Error> => {
|
|
211
|
+
const kind = { _tag: "Paginated" as const };
|
|
212
|
+
const paginatedKind = kind as Paginated<UserArgsFields_, Item>;
|
|
213
|
+
|
|
214
|
+
Lazy.defineProperty(kind, "userArgs", () => Schema.Struct(userArgs()));
|
|
215
|
+
Lazy.defineProperty(kind, "item", item);
|
|
216
|
+
Lazy.defineProperty(kind, "page", () =>
|
|
217
|
+
Schema.mutable(Schema.Array(paginatedKind.item)),
|
|
218
|
+
);
|
|
219
|
+
|
|
220
|
+
const provenance = { _tag: "Confect" as const, kind: paginatedKind };
|
|
221
|
+
const self = provenance as ConfectPaginated<UserArgsFields_, Item, Error>;
|
|
222
|
+
|
|
223
|
+
Lazy.defineProperty(provenance, "args", () => {
|
|
224
|
+
const fields = paginatedKind.userArgs.fields;
|
|
225
|
+
if ("paginationOpts" in fields) {
|
|
226
|
+
throw new globalThis.Error(
|
|
227
|
+
"A paginated query's args schema must not declare `paginationOpts`—" +
|
|
228
|
+
"it is added automatically from the `PaginationOptions` schema",
|
|
229
|
+
);
|
|
230
|
+
}
|
|
231
|
+
return Schema.Struct({
|
|
232
|
+
...fields,
|
|
233
|
+
paginationOpts: PaginationOptions.PaginationOptions,
|
|
234
|
+
});
|
|
235
|
+
});
|
|
236
|
+
Lazy.defineProperty(provenance, "returns", () =>
|
|
237
|
+
PaginationResult.PaginationResult(paginatedKind.item),
|
|
238
|
+
);
|
|
239
|
+
if (error !== undefined) {
|
|
240
|
+
Lazy.defineProperty(provenance, "error", error);
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
return self;
|
|
81
244
|
};
|
|
82
245
|
|
|
83
|
-
export const Convex = <
|
|
246
|
+
export const Convex = <Args extends DefaultFunctionArgs, Returns>() =>
|
|
84
247
|
FunctionProvenance.Convex(
|
|
85
248
|
{} as {
|
|
86
|
-
|
|
87
|
-
|
|
249
|
+
"~args": Args;
|
|
250
|
+
"~returns": Returns;
|
|
88
251
|
},
|
|
89
252
|
);
|