@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 CHANGED
@@ -1,5 +1,67 @@
1
1
  # @confect/core
2
2
 
3
+ ## 10.0.0-next.19
4
+
5
+ ### Minor Changes
6
+
7
+ - c1087eb: Add `@confect/foldkit` — client-side bindings for [Foldkit](https://foldkit.dev) apps. The package maps Confect's client surface onto Foldkit's integration seams: `Client.layer` provides the scoped WebSocket client and pagination-session allocator through an application's `resources`, `Subscription.reactiveQuery` builds a subscription entry that opens, re-opens, and closes a reactive query as `Option`-wrapped args derived from the Model change, and `Command.query` / `Command.mutation` / `Command.action` build Command definitions whose args are the ref's args and whose Messages are declared with the same `messages` field Foldkit's own `Command.define` takes. Every failure is folded into a Message via the required `onError` handler, so Command and Subscription error channels stay `never` as Foldkit requires.
8
+
9
+ ```ts
10
+ import * as Confect from "@confect/foldkit";
11
+ import * as Schema from "effect/Schema";
12
+ import * as Subscription from "foldkit/subscription";
13
+
14
+ const SaveNote = Confect.Command.mutation(
15
+ "SaveNote",
16
+ refs.public.notes.insert,
17
+ {
18
+ messages: [SucceededSaveNote, FailedSaveNote],
19
+ onSuccess: (noteId) => SucceededSaveNote({ noteId }),
20
+ onError: (error) => FailedSaveNote({ message: String(error) }),
21
+ },
22
+ );
23
+
24
+ const subscriptions = Subscription.make<
25
+ Model,
26
+ Message,
27
+ Confect.Client.Client
28
+ >()(() => ({
29
+ note: Confect.Subscription.reactiveQuery<Model>()(refs.public.notes.get, {
30
+ args: (model) => Option.map(model.noteId, (noteId) => ({ noteId })),
31
+ onSuccess: (note) => SucceededGetNote({ note }),
32
+ onError: (error) => FailedGetNote({ message: String(error) }),
33
+ }),
34
+ }));
35
+ ```
36
+
37
+ The Command factories accept Foldkit's `interrupt` option — `true` keys invocations by the Command name, `{ keyFields, toKey }` by a part derived from the ref's args — and the returned definition gains the `Interrupt` constructor for stopping in-flight invocations. Factory-built definitions instantiate Foldkit's own definition interfaces, so they are accepted wherever Foldkit accepts a Command definition — including Story/Scene `Command.resolve` and `expectExact` matchers. `Command.queryEffect`, `Command.mutationEffect`, and `Command.actionEffect` return execute bodies for hand-written `Command.define` calls (custom args schemas, multi-call Commands), and `Subscription.reactiveQueryStream` is the `dependenciesToStream` escape hatch for hand-written subscription entries.
38
+
39
+ `PaginatedQuery` navigates a paginated query one page at a time over Convex's cursor pagination. `PaginatedQuery.make(ref)` returns the Model and settlement schemas. Its states use Foldkit `AsyncData`'s vocabulary and semantics: `Idle`, `Loading`, `Refreshing`, `Success`, `Failure`, and `Stale`. Failed settlements preserve the complete error contract: declared function and middleware errors are wrapped as `FunctionError`, Convex's invalid-cursor pseudo-error is normalized to the new `@confect/core/PaginationError.InvalidCursor`, and `WebSocketClientError` and `SchemaError` are carried directly. `settle` accepts a request-bound `Result`, turns a failed refresh into `Stale`, automatically resets an invalid cursor, and ignores successes or failures from superseded requests. All machine operations (`init`, `reinitialize`, `reset`, `close`, `next`, `prev`, and `first`) remain pure.
40
+
41
+ `Subscription.paginatedQuery` keeps exactly one live, reactive page subscription in sync with the machine and emits one `onSettled` Message shape for either outcome. It allocates Convex's pagination `id` internally and returns it with the first settlement, so session allocation is not a separate Command or application Message. Installing that id is keep-alive-equivalent and does not restart the subscription. Query errors are emitted as values without closing the underlying Convex subscription, allowing a later successful result to recover naturally. Each request supports `maximumRowsRead` and `maximumBytesRead` and uses `initialNumItems` for the initial page and split heuristic. Page splits remain transparent, the last complete page stays visible during navigation and after refresh failure, and an empty terminal page automatically retreats to the preceding page.
42
+
43
+ ```ts
44
+ const Notes = Confect.PaginatedQuery.make(refs.public.notes.paginate);
45
+
46
+ // Model: notes: Notes.schema
47
+ // Initial Model value: notes: Notes.idle
48
+ // Message: settlement: Notes.settlement
49
+ // update after matching Idle: Notes.init(idle, { channel }, { initialNumItems: 20 })
50
+
51
+ const subscriptions = Subscription.make<
52
+ Model,
53
+ Message,
54
+ Confect.Client.Client
55
+ >()(() => ({
56
+ notesPage: Confect.Subscription.paginatedQuery<Model>()(Notes, {
57
+ state: (model) => model.notes,
58
+ onSettled: (settlement) => SettledGetNotesPage({ settlement }),
59
+ }),
60
+ }));
61
+ ```
62
+
63
+ - b34e029: Declare Confect function arguments as optional lazy `Schema.Struct` field maps instead of constructed struct schemas. Confect now derives and builds the struct schema itself, defaults omitted args to `{}`, matches Convex's object-only argument model, and preserves exact field types through function specs and refs.
64
+
3
65
  ## 10.0.0-next.18
4
66
 
5
67
  ### Minor Changes
@@ -3,43 +3,73 @@ import * as Data from "effect/Data";
3
3
  import * as Schema from "effect/Schema";
4
4
  import * as PaginationOptions from "./PaginationOptions";
5
5
  import * as PaginationResult from "./PaginationResult";
6
+ /**
7
+ * A field map accepted as Confect function args. Restricting each field to a
8
+ * context-free codec means the struct assembled from the fields can always be
9
+ * encoded and decoded synchronously at a Convex boundary.
10
+ */
11
+ export type ArgsFields = {
12
+ readonly [key: PropertyKey]: Schema.ConstraintCodec<any, any>;
13
+ };
14
+ /**
15
+ * A struct-shaped Confect args schema that keeps its exact field map while
16
+ * erasing the rest of `Schema.Struct`'s large implementation type. Decoded and
17
+ * encoded args are derived directly from `ArgsFields_`; keeping the runtime
18
+ * codec structural prevents every ref lookup from expanding the full Effect
19
+ * schema type.
20
+ */
21
+ export interface ArgsSchema<ArgsFields_ extends ArgsFields> extends Schema.Codec<any, any> {
22
+ readonly fields: ArgsFields_;
23
+ }
24
+ /** Erased structural view used after the exact field map is no longer needed. */
25
+ export type AnyArgsSchema = ArgsSchema<ArgsFields>;
6
26
  export type FunctionProvenance = Data.TaggedEnum<{
7
27
  Confect: {
8
- args: Schema.Codec<any, any>;
28
+ args: AnyArgsSchema;
9
29
  returns: Schema.Codec<any, any>;
10
30
  error?: Schema.Codec<any, any>;
11
31
  kind: ConfectKind;
12
32
  };
13
- Convex: {};
33
+ Convex: {
34
+ "~args": DefaultFunctionArgs;
35
+ "~returns": any;
36
+ };
14
37
  }>;
15
38
  /**
16
39
  * The declaration shape of a Confect function — orthogonal to both the
17
40
  * provenance origin (Confect vs Convex) and the function type
18
- * (query/mutation/action). A `Standard` function declares its `args` and
19
- * `returns` schemas directly; a `Paginated` function declares `userArgs` and
20
- * `item` schemas from which the Convex-facing `args`/`returns` are composed.
41
+ * (query/mutation/action). A `Standard` function declares its args fields and
42
+ * returns schema directly; a `Paginated` function declares user-args fields
43
+ * and an item schema from which the Convex-facing `args`/`returns` are
44
+ * composed.
21
45
  */
22
46
  export type ConfectKind = Standard | Paginated;
23
47
  export interface Standard {
24
48
  readonly _tag: "Standard";
25
49
  }
26
- export interface Paginated<UserArgs extends AnyUserArgs = AnyUserArgs, Item extends Schema.Codec<any, any> = Schema.Codec<any, any>> {
50
+ export interface Paginated<UserArgsFields_ extends ArgsFields = ArgsFields, Item extends Schema.Codec<any, any> = Schema.Codec<any, any>> {
27
51
  readonly _tag: "Paginated";
28
52
  /** User-declared args — no `paginationOpts`. */
29
- readonly userArgs: UserArgs;
53
+ readonly userArgs: ArgsSchema<UserArgsFields_>;
30
54
  /** Page element schema. */
31
55
  readonly item: Item;
32
56
  /** Mutable array of items — the page decode target. */
33
57
  readonly page: Schema.Codec<any, any>;
34
58
  }
35
- export interface Confect<Args extends Schema.Codec<any, any>, Returns extends Schema.Codec<any, any>, Error extends Schema.Codec<any, any> = never, Kind extends ConfectKind = ConfectKind> {
59
+ export interface Confect<ArgsFields_ extends ArgsFields, Returns extends Schema.Codec<any, any>, Error extends Schema.Codec<any, any> = never, Kind extends ConfectKind = ConfectKind> {
36
60
  readonly _tag: "Confect";
37
- readonly args: Args;
61
+ readonly "~ArgsFields": ArgsFields_;
62
+ readonly args: ArgsSchema<ArgsFields_>;
38
63
  readonly returns: Returns;
39
64
  readonly error?: Error;
40
65
  readonly kind: Kind;
41
66
  }
42
- export interface AnyConfect extends Confect<Schema.Codec<any, any>, Schema.Codec<any, any>, Schema.Codec<any, any>> {
67
+ export interface AnyConfect {
68
+ readonly _tag: "Confect";
69
+ readonly args: AnyArgsSchema;
70
+ readonly returns: Schema.Codec<any, any>;
71
+ readonly error?: Schema.Codec<any, any>;
72
+ readonly kind: ConfectKind;
43
73
  }
44
74
  export interface Convex<Args extends DefaultFunctionArgs, Returns> {
45
75
  readonly _tag: "Convex";
@@ -51,7 +81,7 @@ export interface AnyConvex extends Convex<DefaultFunctionArgs, any> {
51
81
  export declare const FunctionProvenance: {
52
82
  readonly $is: <Tag extends "Confect" | "Convex">(tag: Tag) => (u: unknown) => u is Extract<{
53
83
  readonly _tag: "Confect";
54
- readonly args: Schema.Codec<any, any>;
84
+ readonly args: AnyArgsSchema;
55
85
  readonly returns: Schema.Codec<any, any>;
56
86
  readonly error?: Schema.Codec<any, any>;
57
87
  readonly kind: ConfectKind;
@@ -67,7 +97,7 @@ export declare const FunctionProvenance: {
67
97
  readonly $match: {
68
98
  <Cases extends { readonly [Tag in "Confect" | "Convex"]: (args: Extract<{
69
99
  readonly _tag: "Confect";
70
- readonly args: Schema.Codec<any, any>;
100
+ readonly args: AnyArgsSchema;
71
101
  readonly returns: Schema.Codec<any, any>;
72
102
  readonly error?: Schema.Codec<any, any>;
73
103
  readonly kind: ConfectKind;
@@ -79,7 +109,7 @@ export declare const FunctionProvenance: {
79
109
  readonly _tag: Tag;
80
110
  }>) => any; }>(cases: Cases): (value: {
81
111
  readonly _tag: "Confect";
82
- readonly args: Schema.Codec<any, any>;
112
+ readonly args: AnyArgsSchema;
83
113
  readonly returns: Schema.Codec<any, any>;
84
114
  readonly error?: Schema.Codec<any, any>;
85
115
  readonly kind: ConfectKind;
@@ -90,7 +120,7 @@ export declare const FunctionProvenance: {
90
120
  }) => import("effect/Unify").Unify<ReturnType<Cases["Confect" | "Convex"]>>;
91
121
  <Cases extends { readonly [Tag in "Confect" | "Convex"]: (args: Extract<{
92
122
  readonly _tag: "Confect";
93
- readonly args: Schema.Codec<any, any>;
123
+ readonly args: AnyArgsSchema;
94
124
  readonly returns: Schema.Codec<any, any>;
95
125
  readonly error?: Schema.Codec<any, any>;
96
126
  readonly kind: ConfectKind;
@@ -102,7 +132,7 @@ export declare const FunctionProvenance: {
102
132
  readonly _tag: Tag;
103
133
  }>) => any; }>(value: {
104
134
  readonly _tag: "Confect";
105
- readonly args: Schema.Codec<any, any>;
135
+ readonly args: AnyArgsSchema;
106
136
  readonly returns: Schema.Codec<any, any>;
107
137
  readonly error?: Schema.Codec<any, any>;
108
138
  readonly kind: ConfectKind;
@@ -114,7 +144,7 @@ export declare const FunctionProvenance: {
114
144
  };
115
145
  readonly Confect: Data.TaggedEnum.ConstructorFrom<{
116
146
  readonly _tag: "Confect";
117
- readonly args: Schema.Codec<any, any>;
147
+ readonly args: AnyArgsSchema;
118
148
  readonly returns: Schema.Codec<any, any>;
119
149
  readonly error?: Schema.Codec<any, any>;
120
150
  readonly kind: ConfectKind;
@@ -126,13 +156,13 @@ export declare const FunctionProvenance: {
126
156
  }, "_tag">;
127
157
  };
128
158
  /**
129
- * Build a `Confect` provenance from lazy schema thunks. `args`, `returns`,
130
- * and `error` are exposed as sync lazy memoised getters (via {@link Lazy.defineProperty})
131
- * that only evaluate their thunk on first access, mirroring how `Table`
132
- * defers `Fields`/`Doc`. This keeps importing the assembled
133
- * `_generated/spec.ts` cheap — no `Schema.Struct(...)` / `Schema.Array(...)`
134
- * work runs at module load; it is deferred to the first invocation that
135
- * actually compiles validators or runs a codec.
159
+ * Build a `Confect` provenance from lazy args-fields and schema thunks.
160
+ * `args`, `returns`, and `error` are exposed as sync lazy memoised getters
161
+ * (via {@link Lazy.defineProperty}) that only evaluate their thunk on first
162
+ * access, mirroring how `Table` defers `Fields`/`Doc`. This keeps importing the
163
+ * assembled `_generated/spec.ts` cheap — no `Schema.Struct(...)` /
164
+ * `Schema.Array(...)` work runs at module load; it is deferred to the first
165
+ * invocation that actually compiles validators or runs a codec.
136
166
  *
137
167
  * The object is built by hand rather than through `FunctionProvenance.Confect`
138
168
  * because the `Data` constructor copies its input with `Object.assign`, which
@@ -141,36 +171,27 @@ export declare const FunctionProvenance: {
141
171
  * is observable via `"error" in provenance` without forcing anything; nothing
142
172
  * relies on `Data`'s structural `Equal`/`Hash` for provenance values.
143
173
  */
144
- export declare const Confect: <Args extends Schema.Codec<any, any>, Returns extends Schema.Codec<any, any>, Error extends Schema.Codec<any, any> = never>(args: () => Args, returns: () => Returns, error?: () => Error) => Confect<Args, Returns, Error, Standard>;
145
- /**
146
- * Any struct-shaped, context-free schema usable as a paginated query's user
147
- * args. A structural bound rather than `Schema.Struct<Schema.Struct.Fields>`
148
- * because `Schema.Struct` is not covariant in its fields parameter — concrete
149
- * structs do not extend `Schema.Struct<Schema.Struct.Fields>`.
150
- */
151
- export interface AnyUserArgs extends Schema.Codec<any, any> {
152
- readonly fields: Schema.Struct.Fields;
153
- }
174
+ export declare const Confect: <const ArgsFields_ extends ArgsFields, Returns extends Schema.Codec<any, any>, Error extends Schema.Codec<any, any> = never>(args: () => ArgsFields_, returns: () => Returns, error?: () => Error) => Confect<ArgsFields_, Returns, Error, Standard>;
154
175
  /**
155
176
  * The composed args schema of a paginated query: the user-declared fields
156
177
  * plus the `paginationOpts` field managed by Convex's pagination protocol.
157
178
  *
158
- * The `extends infer ... extends` conditional lets TypeScript accept the
159
- * composed struct where `Schema.Codec<any, any>` is required even while
160
- * `UserArgs` is an unresolved type parameter; for concrete user args it
161
- * evaluates away entirely.
179
+ * The fields-first representation keeps the user-declared map available for
180
+ * type-level composition without reconstructing it from an erased schema.
162
181
  */
163
- export type PaginatedArgs<UserArgs extends AnyUserArgs> = Schema.Struct<UserArgs["fields"] & {
164
- paginationOpts: typeof PaginationOptions.PaginationOptions;
165
- }> extends infer ComposedArgs extends Schema.Codec<any, any> ? ComposedArgs : never;
182
+ export type PaginatedArgsFields<UserArgsFields extends ArgsFields> = UserArgsFields & {
183
+ readonly paginationOpts: typeof PaginationOptions.PaginationOptions;
184
+ };
185
+ export type PaginatedArgs<UserArgsFields extends ArgsFields> = Schema.Struct<PaginatedArgsFields<UserArgsFields>>;
166
186
  /**
167
187
  * The composed returns schema of a paginated query: a `PaginationResult` of
168
188
  * the item schema. Same deferred-conditional device as {@link PaginatedArgs}.
169
189
  */
170
190
  export type PaginatedReturns<Item extends Schema.Codec<any, any>> = PaginationResult.PaginationResult<Item> extends infer ComposedReturns extends Schema.Codec<any, any> ? ComposedReturns : never;
171
- export interface ConfectPaginated<UserArgs extends AnyUserArgs, Item extends Schema.Codec<any, any>, Error extends Schema.Codec<any, any> = never> extends Confect<PaginatedArgs<UserArgs>, PaginatedReturns<Item>, Error, Paginated<UserArgs, Item>> {
191
+ export interface ConfectPaginated<UserArgsFields extends ArgsFields, Item extends Schema.Codec<any, any>, Error extends Schema.Codec<any, any> = never> extends Confect<PaginatedArgsFields<UserArgsFields>, PaginatedReturns<Item>, Error, Paginated<UserArgsFields, Item>> {
172
192
  }
173
- export interface AnyConfectPaginated extends ConfectPaginated<AnyUserArgs, Schema.Codec<any, any>, Schema.Codec<any, any>> {
193
+ export interface AnyConfectPaginated extends AnyConfect {
194
+ readonly kind: Paginated;
174
195
  }
175
196
  /**
176
197
  * Build the provenance of a paginated query from lazy schema thunks, with the
@@ -182,7 +203,7 @@ export interface AnyConfectPaginated extends ConfectPaginated<AnyUserArgs, Schem
182
203
  * wraps the item in `PaginationResult`. Composition living here means the
183
204
  * composed schemas can never drift from the stored user schemas.
184
205
  */
185
- export declare const ConfectPaginated: <UserArgs extends AnyUserArgs, Item extends Schema.Codec<any, any>, Error extends Schema.Codec<any, any> = never>(userArgs: () => UserArgs, item: () => Item, error?: () => Error) => ConfectPaginated<UserArgs, Item, Error>;
206
+ export declare const ConfectPaginated: <const UserArgsFields_ extends ArgsFields, Item extends Schema.Codec<any, any>, Error extends Schema.Codec<any, any> = never>(userArgs: () => UserArgsFields_, item: () => Item, error?: () => Error) => ConfectPaginated<UserArgsFields_, Item, Error>;
186
207
  export declare const Convex: <Args extends DefaultFunctionArgs, Returns>() => {
187
208
  readonly _tag: "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,CAAC,KAAK,CAAC,GAAG,EAAE,GAAG,CAAC,GACpB,eAAe,GACf,KAAK,CAAC;AAEZ,MAAM,WAAW,gBAAgB,CAC/B,cAAc,SAAS,UAAU,EACjC,IAAI,SAAS,MAAM,CAAC,KAAK,CAAC,GAAG,EAAE,GAAG,CAAC,EACnC,KAAK,SAAS,MAAM,CAAC,KAAK,CAAC,GAAG,EAAE,GAAG,CAAC,GAAG,KAAK,CAC5C,SAAQ,OAAO,CACf,mBAAmB,CAAC,cAAc,CAAC,EACnC,gBAAgB,CAAC,IAAI,CAAC,EACtB,KAAK,EACL,SAAS,CAAC,cAAc,EAAE,IAAI,CAAC,CAChC;CAAG;AAEJ,MAAM,WAAW,mBAAoB,SAAQ,UAAU;IACrD,QAAQ,CAAC,IAAI,EAAE,SAAS,CAAC;CAC1B;AAED;;;;;;;;;GASG;AACH,eAAO,MAAM,gBAAgB,GAC3B,KAAK,CAAC,eAAe,SAAS,UAAU,EACxC,IAAI,SAAS,MAAM,CAAC,KAAK,CAAC,GAAG,EAAE,GAAG,CAAC,EACnC,KAAK,SAAS,MAAM,CAAC,KAAK,CAAC,GAAG,EAAE,GAAG,CAAC,GAAG,KAAK,YAElC,MAAM,eAAe,QACzB,MAAM,IAAI,UACR,MAAM,KAAK,KAClB,gBAAgB,CAAC,eAAe,EAAE,IAAI,EAAE,KAAK,CAkC/C,CAAC;AAEF,eAAO,MAAM,MAAM,GAAI,IAAI,SAAS,mBAAmB,EAAE,OAAO;;sBArMnD,mBAAmB;yBAChB,GAAG;CA0MhB,CAAC"}
@@ -14,13 +14,13 @@ var FunctionProvenance_exports = /* @__PURE__ */ __exportAll({
14
14
  const FunctionProvenance = Data.taggedEnum();
15
15
  const Standard = { _tag: "Standard" };
16
16
  /**
17
- * Build a `Confect` provenance from lazy schema thunks. `args`, `returns`,
18
- * and `error` are exposed as sync lazy memoised getters (via {@link Lazy.defineProperty})
19
- * that only evaluate their thunk on first access, mirroring how `Table`
20
- * defers `Fields`/`Doc`. This keeps importing the assembled
21
- * `_generated/spec.ts` cheap — no `Schema.Struct(...)` / `Schema.Array(...)`
22
- * work runs at module load; it is deferred to the first invocation that
23
- * actually compiles validators or runs a codec.
17
+ * Build a `Confect` provenance from lazy args-fields and schema thunks.
18
+ * `args`, `returns`, and `error` are exposed as sync lazy memoised getters
19
+ * (via {@link Lazy.defineProperty}) that only evaluate their thunk on first
20
+ * access, mirroring how `Table` defers `Fields`/`Doc`. This keeps importing the
21
+ * assembled `_generated/spec.ts` cheap — no `Schema.Struct(...)` /
22
+ * `Schema.Array(...)` work runs at module load; it is deferred to the first
23
+ * invocation that actually compiles validators or runs a codec.
24
24
  *
25
25
  * The object is built by hand rather than through `FunctionProvenance.Confect`
26
26
  * because the `Data` constructor copies its input with `Object.assign`, which
@@ -34,7 +34,7 @@ const Confect = (args, returns, error) => {
34
34
  _tag: "Confect",
35
35
  kind: Standard
36
36
  };
37
- defineProperty(provenance, "args", args);
37
+ defineProperty(provenance, "args", () => Schema.Struct(args()));
38
38
  defineProperty(provenance, "returns", returns);
39
39
  if (error !== void 0) defineProperty(provenance, "error", error);
40
40
  return provenance;
@@ -52,7 +52,7 @@ const Confect = (args, returns, error) => {
52
52
  const ConfectPaginated = (userArgs, item, error) => {
53
53
  const kind = { _tag: "Paginated" };
54
54
  const paginatedKind = kind;
55
- defineProperty(kind, "userArgs", userArgs);
55
+ defineProperty(kind, "userArgs", () => Schema.Struct(userArgs()));
56
56
  defineProperty(kind, "item", item);
57
57
  defineProperty(kind, "page", () => Schema.mutable(Schema.Array(paginatedKind.item)));
58
58
  const provenance = {
@@ -1 +1 @@
1
- {"version":3,"file":"FunctionProvenance.js","names":["PaginationOptions.PaginationOptions","PaginationResult.PaginationResult"],"sources":["../src/FunctionProvenance.ts"],"sourcesContent":["import type { DefaultFunctionArgs } from \"convex/server\";\nimport * as Data from \"effect/Data\";\nimport * as Schema from \"effect/Schema\";\nimport * as Lazy from \"./Lazy\";\nimport * as PaginationOptions from \"./PaginationOptions\";\nimport * as PaginationResult from \"./PaginationResult\";\n\nexport type FunctionProvenance = Data.TaggedEnum<{\n Confect: {\n args: Schema.Codec<any, any>;\n returns: Schema.Codec<any, any>;\n error?: Schema.Codec<any, any>;\n kind: ConfectKind;\n };\n Convex: {\n /** @internal */\n \"~args\": DefaultFunctionArgs;\n /** @internal */\n \"~returns\": any;\n };\n}>;\n\n/**\n * The declaration shape of a Confect function — orthogonal to both the\n * provenance origin (Confect vs Convex) and the function type\n * (query/mutation/action). A `Standard` function declares its `args` and\n * `returns` schemas directly; a `Paginated` function declares `userArgs` and\n * `item` schemas from which the Convex-facing `args`/`returns` are composed.\n */\nexport type ConfectKind = Standard | Paginated;\n\nexport interface Standard {\n readonly _tag: \"Standard\";\n}\n\nexport interface Paginated<\n UserArgs extends AnyUserArgs = AnyUserArgs,\n Item extends Schema.Codec<any, any> = Schema.Codec<any, any>,\n> {\n readonly _tag: \"Paginated\";\n /** User-declared args — no `paginationOpts`. */\n readonly userArgs: UserArgs;\n /** Page element schema. */\n readonly item: Item;\n /** Mutable array of items — the page decode target. */\n readonly page: Schema.Codec<any, any>;\n}\n\nexport interface Confect<\n Args extends Schema.Codec<any, any>,\n Returns extends Schema.Codec<any, any>,\n Error extends Schema.Codec<any, any> = never,\n Kind extends ConfectKind = ConfectKind,\n> {\n readonly _tag: \"Confect\";\n readonly args: Args;\n readonly returns: Returns;\n readonly error?: Error;\n readonly kind: Kind;\n}\n\nexport interface AnyConfect extends Confect<\n Schema.Codec<any, any>,\n Schema.Codec<any, any>,\n Schema.Codec<any, any>\n> {}\n\nexport interface Convex<Args extends DefaultFunctionArgs, Returns> {\n readonly _tag: \"Convex\";\n readonly \"~args\": Args;\n readonly \"~returns\": Returns;\n}\n\nexport interface AnyConvex extends Convex<DefaultFunctionArgs, any> {}\n\nexport const FunctionProvenance = Data.taggedEnum<FunctionProvenance>();\n\nconst Standard: Standard = { _tag: \"Standard\" };\n\n/**\n * Build a `Confect` provenance from lazy schema thunks. `args`, `returns`,\n * and `error` are exposed as sync lazy memoised getters (via {@link Lazy.defineProperty})\n * that only evaluate their thunk on first access, mirroring how `Table`\n * defers `Fields`/`Doc`. This keeps importing the assembled\n * `_generated/spec.ts` cheap — no `Schema.Struct(...)` / `Schema.Array(...)`\n * work runs at module load; it is deferred to the first invocation that\n * actually compiles validators or runs a codec.\n *\n * The object is built by hand rather than through `FunctionProvenance.Confect`\n * because the `Data` constructor copies its input with `Object.assign`, which\n * would force the getters at construction time and defeat the laziness.\n * `error` is only installed when an `errorThunk` is provided, so its absence\n * is observable via `\"error\" in provenance` without forcing anything; nothing\n * relies on `Data`'s structural `Equal`/`Hash` for provenance values.\n */\nexport const Confect = <\n Args extends Schema.Codec<any, any>,\n Returns extends Schema.Codec<any, any>,\n Error extends Schema.Codec<any, any> = never,\n>(\n args: () => Args,\n returns: () => Returns,\n error?: () => Error,\n): Confect<Args, Returns, Error, Standard> => {\n const provenance = { _tag: \"Confect\" as const, kind: Standard };\n\n Lazy.defineProperty(provenance, \"args\", args);\n Lazy.defineProperty(provenance, \"returns\", returns);\n if (error !== undefined) {\n Lazy.defineProperty(provenance, \"error\", error);\n }\n\n return provenance as Confect<Args, Returns, Error, Standard>;\n};\n\n/**\n * Any struct-shaped, context-free schema usable as a paginated query's user\n * args. A structural bound rather than `Schema.Struct<Schema.Struct.Fields>`\n * because `Schema.Struct` is not covariant in its fields parameter — concrete\n * structs do not extend `Schema.Struct<Schema.Struct.Fields>`.\n */\n// eslint-disable-next-line import/namespace -- oxlint's namespace resolution misses type-only exports, and `Schema` is an interface/namespace\nexport interface AnyUserArgs extends Schema.Codec<any, any> {\n readonly fields: Schema.Struct.Fields;\n}\n\n/**\n * The composed args schema of a paginated query: the user-declared fields\n * plus the `paginationOpts` field managed by Convex's pagination protocol.\n *\n * The `extends infer ... extends` conditional lets TypeScript accept the\n * composed struct where `Schema.Codec<any, any>` is required even while\n * `UserArgs` is an unresolved type parameter; for concrete user args it\n * evaluates away entirely.\n */\nexport type PaginatedArgs<UserArgs extends AnyUserArgs> =\n Schema.Struct<\n UserArgs[\"fields\"] & {\n paginationOpts: typeof PaginationOptions.PaginationOptions;\n }\n > extends infer ComposedArgs extends Schema.Codec<any, any>\n ? ComposedArgs\n : never;\n\n/**\n * The composed returns schema of a paginated query: a `PaginationResult` of\n * the item schema. Same deferred-conditional device as {@link PaginatedArgs}.\n */\nexport type PaginatedReturns<Item extends Schema.Codec<any, any>> =\n PaginationResult.PaginationResult<Item> extends infer ComposedReturns extends\n Schema.Codec<any, any>\n ? ComposedReturns\n : never;\n\nexport interface ConfectPaginated<\n UserArgs extends AnyUserArgs,\n Item extends Schema.Codec<any, any>,\n Error extends Schema.Codec<any, any> = never,\n> extends Confect<\n PaginatedArgs<UserArgs>,\n PaginatedReturns<Item>,\n Error,\n Paginated<UserArgs, Item>\n> {}\n\nexport interface AnyConfectPaginated extends ConfectPaginated<\n AnyUserArgs,\n Schema.Codec<any, any>,\n Schema.Codec<any, any>\n> {}\n\n/**\n * Build the provenance of a paginated query from lazy schema thunks, with the\n * same laziness contract as {@link Confect}. The user-facing schemas live on\n * the `Paginated` kind (`kind.userArgs`, `kind.item`, `kind.page`) — the kind\n * container is built eagerly (it is cheap) while the schemas inside it stay\n * lazy. The composed Convex-facing `args`/`returns` are derived lazily from\n * them: `args` spreads the user fields plus `paginationOpts`, and `returns`\n * wraps the item in `PaginationResult`. Composition living here means the\n * composed schemas can never drift from the stored user schemas.\n */\nexport const ConfectPaginated = <\n UserArgs extends AnyUserArgs,\n Item extends Schema.Codec<any, any>,\n Error extends Schema.Codec<any, any> = never,\n>(\n userArgs: () => UserArgs,\n item: () => Item,\n error?: () => Error,\n): ConfectPaginated<UserArgs, Item, Error> => {\n const kind = { _tag: \"Paginated\" as const };\n const paginatedKind = kind as Paginated<UserArgs, Item>;\n\n Lazy.defineProperty(kind, \"userArgs\", userArgs);\n Lazy.defineProperty(kind, \"item\", item);\n Lazy.defineProperty(kind, \"page\", () =>\n Schema.mutable(Schema.Array(paginatedKind.item)),\n );\n\n const provenance = { _tag: \"Confect\" as const, kind: paginatedKind };\n const self = provenance as ConfectPaginated<UserArgs, Item, Error>;\n\n Lazy.defineProperty(provenance, \"args\", () => {\n const fields = paginatedKind.userArgs.fields;\n if (\"paginationOpts\" in fields) {\n throw new globalThis.Error(\n \"A paginated query's args schema must not declare `paginationOpts` — \" +\n \"it is added automatically from the `PaginationOptions` schema\",\n );\n }\n return Schema.Struct({\n ...fields,\n paginationOpts: PaginationOptions.PaginationOptions,\n });\n });\n Lazy.defineProperty(provenance, \"returns\", () =>\n PaginationResult.PaginationResult(paginatedKind.item),\n );\n if (error !== undefined) {\n Lazy.defineProperty(provenance, \"error\", error);\n }\n\n return self;\n};\n\nexport const Convex = <Args extends DefaultFunctionArgs, Returns>() =>\n FunctionProvenance.Convex(\n {} as {\n \"~args\": Args;\n \"~returns\": Returns;\n },\n );\n"],"mappings":";;;;;;;;;;;;;AA2EA,MAAa,qBAAqB,KAAK,WAA+B;AAEtE,MAAM,WAAqB,EAAE,MAAM,WAAW;;;;;;;;;;;;;;;;;AAkB9C,MAAa,WAKX,MACA,SACA,UAC4C;CAC5C,MAAM,aAAa;EAAE,MAAM;EAAoB,MAAM;CAAS;CAE9D,eAAoB,YAAY,QAAQ,IAAI;CAC5C,eAAoB,YAAY,WAAW,OAAO;CAClD,IAAI,UAAU,KAAA,GACZ,eAAoB,YAAY,SAAS,KAAK;CAGhD,OAAO;AACT;;;;;;;;;;;AAoEA,MAAa,oBAKX,UACA,MACA,UAC4C;CAC5C,MAAM,OAAO,EAAE,MAAM,YAAqB;CAC1C,MAAM,gBAAgB;CAEtB,eAAoB,MAAM,YAAY,QAAQ;CAC9C,eAAoB,MAAM,QAAQ,IAAI;CACtC,eAAoB,MAAM,cACxB,OAAO,QAAQ,OAAO,MAAM,cAAc,IAAI,CAAC,CACjD;CAEA,MAAM,aAAa;EAAE,MAAM;EAAoB,MAAM;CAAc;CACnE,MAAM,OAAO;CAEb,eAAoB,YAAY,cAAc;EAC5C,MAAM,SAAS,cAAc,SAAS;EACtC,IAAI,oBAAoB,QACtB,MAAM,IAAI,WAAW,MACnB,mIAEF;EAEF,OAAO,OAAO,OAAO;GACnB,GAAG;GACH,gBAAgBA;EAClB,CAAC;CACH,CAAC;CACD,eAAoB,YAAY,iBAC9BC,iBAAkC,cAAc,IAAI,CACtD;CACA,IAAI,UAAU,KAAA,GACZ,eAAoB,YAAY,SAAS,KAAK;CAGhD,OAAO;AACT;AAEA,MAAa,eACX,mBAAmB,OACjB,CAAC,CAIH"}
1
+ {"version":3,"file":"FunctionProvenance.js","names":["PaginationOptions.PaginationOptions","PaginationResult.PaginationResult"],"sources":["../src/FunctionProvenance.ts"],"sourcesContent":["import type { DefaultFunctionArgs } from \"convex/server\";\nimport * as Data from \"effect/Data\";\nimport * as Schema from \"effect/Schema\";\nimport * as Lazy from \"./Lazy\";\nimport * as PaginationOptions from \"./PaginationOptions\";\nimport * as PaginationResult from \"./PaginationResult\";\n\n/**\n * A field map accepted as Confect function args. Restricting each field to a\n * context-free codec means the struct assembled from the fields can always be\n * encoded and decoded synchronously at a Convex boundary.\n */\n// eslint-disable-next-line import/namespace -- oxlint's namespace resolution misses type-only exports, and `Schema` is an interface/namespace\nexport type ArgsFields = {\n readonly [key: PropertyKey]: Schema.ConstraintCodec<any, any>;\n};\n\n/**\n * A struct-shaped Confect args schema that keeps its exact field map while\n * erasing the rest of `Schema.Struct`'s large implementation type. Decoded and\n * encoded args are derived directly from `ArgsFields_`; keeping the runtime\n * codec structural prevents every ref lookup from expanding the full Effect\n * schema type.\n */\nexport interface ArgsSchema<\n ArgsFields_ extends ArgsFields,\n> extends Schema.Codec<any, any> {\n readonly fields: ArgsFields_;\n}\n\n/** Erased structural view used after the exact field map is no longer needed. */\nexport type AnyArgsSchema = ArgsSchema<ArgsFields>;\n\nexport type FunctionProvenance = Data.TaggedEnum<{\n Confect: {\n args: AnyArgsSchema;\n returns: Schema.Codec<any, any>;\n error?: Schema.Codec<any, any>;\n kind: ConfectKind;\n };\n Convex: {\n \"~args\": DefaultFunctionArgs;\n \"~returns\": any;\n };\n}>;\n\n/**\n * The declaration shape of a Confect function — orthogonal to both the\n * provenance origin (Confect vs Convex) and the function type\n * (query/mutation/action). A `Standard` function declares its args fields and\n * returns schema directly; a `Paginated` function declares user-args fields\n * and an item schema from which the Convex-facing `args`/`returns` are\n * composed.\n */\nexport type ConfectKind = Standard | Paginated;\n\nexport interface Standard {\n readonly _tag: \"Standard\";\n}\n\nexport interface Paginated<\n UserArgsFields_ extends ArgsFields = ArgsFields,\n Item extends Schema.Codec<any, any> = Schema.Codec<any, any>,\n> {\n readonly _tag: \"Paginated\";\n /** User-declared args — no `paginationOpts`. */\n readonly userArgs: ArgsSchema<UserArgsFields_>;\n /** Page element schema. */\n readonly item: Item;\n /** Mutable array of items — the page decode target. */\n readonly page: Schema.Codec<any, any>;\n}\n\nexport interface Confect<\n ArgsFields_ extends ArgsFields,\n Returns extends Schema.Codec<any, any>,\n Error extends Schema.Codec<any, any> = never,\n Kind extends ConfectKind = ConfectKind,\n> {\n readonly _tag: \"Confect\";\n readonly \"~ArgsFields\": ArgsFields_;\n readonly args: ArgsSchema<ArgsFields_>;\n readonly returns: Returns;\n readonly error?: Error;\n readonly kind: Kind;\n}\n\nexport interface AnyConfect {\n readonly _tag: \"Confect\";\n readonly args: AnyArgsSchema;\n readonly returns: Schema.Codec<any, any>;\n readonly error?: Schema.Codec<any, any>;\n readonly kind: ConfectKind;\n}\n\nexport interface Convex<Args extends DefaultFunctionArgs, Returns> {\n readonly _tag: \"Convex\";\n readonly \"~args\": Args;\n readonly \"~returns\": Returns;\n}\n\nexport interface AnyConvex extends Convex<DefaultFunctionArgs, any> {}\n\nexport const FunctionProvenance = Data.taggedEnum<FunctionProvenance>();\n\nconst Standard: Standard = { _tag: \"Standard\" };\n\n/**\n * Build a `Confect` provenance from lazy args-fields and schema thunks.\n * `args`, `returns`, and `error` are exposed as sync lazy memoised getters\n * (via {@link Lazy.defineProperty}) that only evaluate their thunk on first\n * access, mirroring how `Table` defers `Fields`/`Doc`. This keeps importing the\n * assembled `_generated/spec.ts` cheap — no `Schema.Struct(...)` /\n * `Schema.Array(...)` work runs at module load; it is deferred to the first\n * invocation that actually compiles validators or runs a codec.\n *\n * The object is built by hand rather than through `FunctionProvenance.Confect`\n * because the `Data` constructor copies its input with `Object.assign`, which\n * would force the getters at construction time and defeat the laziness.\n * `error` is only installed when an `errorThunk` is provided, so its absence\n * is observable via `\"error\" in provenance` without forcing anything; nothing\n * relies on `Data`'s structural `Equal`/`Hash` for provenance values.\n */\nexport const Confect = <\n const ArgsFields_ extends ArgsFields,\n Returns extends Schema.Codec<any, any>,\n Error extends Schema.Codec<any, any> = never,\n>(\n args: () => ArgsFields_,\n returns: () => Returns,\n error?: () => Error,\n): Confect<ArgsFields_, Returns, Error, Standard> => {\n const provenance = { _tag: \"Confect\" as const, kind: Standard };\n\n Lazy.defineProperty(provenance, \"args\", () => Schema.Struct(args()));\n Lazy.defineProperty(provenance, \"returns\", returns);\n if (error !== undefined) {\n Lazy.defineProperty(provenance, \"error\", error);\n }\n\n return provenance as Confect<ArgsFields_, Returns, Error, Standard>;\n};\n\n/**\n * The composed args schema of a paginated query: the user-declared fields\n * plus the `paginationOpts` field managed by Convex's pagination protocol.\n *\n * The fields-first representation keeps the user-declared map available for\n * type-level composition without reconstructing it from an erased schema.\n */\nexport type PaginatedArgsFields<UserArgsFields extends ArgsFields> =\n UserArgsFields & {\n readonly paginationOpts: typeof PaginationOptions.PaginationOptions;\n };\n\nexport type PaginatedArgs<UserArgsFields extends ArgsFields> = Schema.Struct<\n PaginatedArgsFields<UserArgsFields>\n>;\n\n/**\n * The composed returns schema of a paginated query: a `PaginationResult` of\n * the item schema. Same deferred-conditional device as {@link PaginatedArgs}.\n */\nexport type PaginatedReturns<Item extends Schema.Codec<any, any>> =\n PaginationResult.PaginationResult<Item> extends infer ComposedReturns extends\n Schema.Codec<any, any>\n ? ComposedReturns\n : never;\n\nexport interface ConfectPaginated<\n UserArgsFields extends ArgsFields,\n Item extends Schema.Codec<any, any>,\n Error extends Schema.Codec<any, any> = never,\n> extends Confect<\n PaginatedArgsFields<UserArgsFields>,\n PaginatedReturns<Item>,\n Error,\n Paginated<UserArgsFields, Item>\n> {}\n\nexport interface AnyConfectPaginated extends AnyConfect {\n readonly kind: Paginated;\n}\n\n/**\n * Build the provenance of a paginated query from lazy schema thunks, with the\n * same laziness contract as {@link Confect}. The user-facing schemas live on\n * the `Paginated` kind (`kind.userArgs`, `kind.item`, `kind.page`) — the kind\n * container is built eagerly (it is cheap) while the schemas inside it stay\n * lazy. The composed Convex-facing `args`/`returns` are derived lazily from\n * them: `args` spreads the user fields plus `paginationOpts`, and `returns`\n * wraps the item in `PaginationResult`. Composition living here means the\n * composed schemas can never drift from the stored user schemas.\n */\nexport const ConfectPaginated = <\n const UserArgsFields_ extends ArgsFields,\n Item extends Schema.Codec<any, any>,\n Error extends Schema.Codec<any, any> = never,\n>(\n userArgs: () => UserArgsFields_,\n item: () => Item,\n error?: () => Error,\n): ConfectPaginated<UserArgsFields_, Item, Error> => {\n const kind = { _tag: \"Paginated\" as const };\n const paginatedKind = kind as Paginated<UserArgsFields_, Item>;\n\n Lazy.defineProperty(kind, \"userArgs\", () => Schema.Struct(userArgs()));\n Lazy.defineProperty(kind, \"item\", item);\n Lazy.defineProperty(kind, \"page\", () =>\n Schema.mutable(Schema.Array(paginatedKind.item)),\n );\n\n const provenance = { _tag: \"Confect\" as const, kind: paginatedKind };\n const self = provenance as ConfectPaginated<UserArgsFields_, Item, Error>;\n\n Lazy.defineProperty(provenance, \"args\", () => {\n const fields = paginatedKind.userArgs.fields;\n if (\"paginationOpts\" in fields) {\n throw new globalThis.Error(\n \"A paginated query's args schema must not declare `paginationOpts` — \" +\n \"it is added automatically from the `PaginationOptions` schema\",\n );\n }\n return Schema.Struct({\n ...fields,\n paginationOpts: PaginationOptions.PaginationOptions,\n });\n });\n Lazy.defineProperty(provenance, \"returns\", () =>\n PaginationResult.PaginationResult(paginatedKind.item),\n );\n if (error !== undefined) {\n Lazy.defineProperty(provenance, \"error\", error);\n }\n\n return self;\n};\n\nexport const Convex = <Args extends DefaultFunctionArgs, Returns>() =>\n FunctionProvenance.Convex(\n {} as {\n \"~args\": Args;\n \"~returns\": Returns;\n },\n );\n"],"mappings":";;;;;;;;;;;;;AAuGA,MAAa,qBAAqB,KAAK,WAA+B;AAEtE,MAAM,WAAqB,EAAE,MAAM,WAAW;;;;;;;;;;;;;;;;;AAkB9C,MAAa,WAKX,MACA,SACA,UACmD;CACnD,MAAM,aAAa;EAAE,MAAM;EAAoB,MAAM;CAAS;CAE9D,eAAoB,YAAY,cAAc,OAAO,OAAO,KAAK,CAAC,CAAC;CACnE,eAAoB,YAAY,WAAW,OAAO;CAClD,IAAI,UAAU,KAAA,GACZ,eAAoB,YAAY,SAAS,KAAK;CAGhD,OAAO;AACT;;;;;;;;;;;AAqDA,MAAa,oBAKX,UACA,MACA,UACmD;CACnD,MAAM,OAAO,EAAE,MAAM,YAAqB;CAC1C,MAAM,gBAAgB;CAEtB,eAAoB,MAAM,kBAAkB,OAAO,OAAO,SAAS,CAAC,CAAC;CACrE,eAAoB,MAAM,QAAQ,IAAI;CACtC,eAAoB,MAAM,cACxB,OAAO,QAAQ,OAAO,MAAM,cAAc,IAAI,CAAC,CACjD;CAEA,MAAM,aAAa;EAAE,MAAM;EAAoB,MAAM;CAAc;CACnE,MAAM,OAAO;CAEb,eAAoB,YAAY,cAAc;EAC5C,MAAM,SAAS,cAAc,SAAS;EACtC,IAAI,oBAAoB,QACtB,MAAM,IAAI,WAAW,MACnB,mIAEF;EAEF,OAAO,OAAO,OAAO;GACnB,GAAG;GACH,gBAAgBA;EAClB,CAAC;CACH,CAAC;CACD,eAAoB,YAAY,iBAC9BC,iBAAkC,cAAc,IAAI,CACtD;CACA,IAAI,UAAU,KAAA,GACZ,eAAoB,YAAY,SAAS,KAAK;CAGhD,OAAO;AACT;AAEA,MAAa,eACX,mBAAmB,OACjB,CAAC,CAIH"}