@confect/core 10.0.0-next.2 → 10.0.0-next.20

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.
Files changed (94) hide show
  1. package/CHANGELOG.md +518 -0
  2. package/README.md +3 -1
  3. package/dist/FunctionProvenance.d.ts +155 -65
  4. package/dist/FunctionProvenance.d.ts.map +1 -1
  5. package/dist/FunctionProvenance.js +51 -10
  6. package/dist/FunctionProvenance.js.map +1 -1
  7. package/dist/FunctionSpec.d.ts +314 -138
  8. package/dist/FunctionSpec.d.ts.map +1 -1
  9. package/dist/FunctionSpec.js +50 -13
  10. package/dist/FunctionSpec.js.map +1 -1
  11. package/dist/GenericId.d.ts.map +1 -1
  12. package/dist/GenericId.js +1 -1
  13. package/dist/GroupPath.d.ts +1 -4
  14. package/dist/GroupPath.d.ts.map +1 -1
  15. package/dist/GroupPath.js.map +1 -1
  16. package/dist/GroupSpec.d.ts +16 -10
  17. package/dist/GroupSpec.d.ts.map +1 -1
  18. package/dist/GroupSpec.js +34 -11
  19. package/dist/GroupSpec.js.map +1 -1
  20. package/dist/Identifier.d.ts.map +1 -1
  21. package/dist/Lazy.d.ts +2 -3
  22. package/dist/Lazy.d.ts.map +1 -1
  23. package/dist/Lazy.js +2 -3
  24. package/dist/Lazy.js.map +1 -1
  25. package/dist/MiddlewareSpec.d.ts +184 -0
  26. package/dist/MiddlewareSpec.d.ts.map +1 -0
  27. package/dist/MiddlewareSpec.js +55 -0
  28. package/dist/MiddlewareSpec.js.map +1 -0
  29. package/dist/PaginationError.d.ts +14 -0
  30. package/dist/PaginationError.d.ts.map +1 -0
  31. package/dist/PaginationError.js +25 -0
  32. package/dist/PaginationError.js.map +1 -0
  33. package/dist/PaginationOptions.d.ts +23 -0
  34. package/dist/PaginationOptions.d.ts.map +1 -0
  35. package/dist/PaginationOptions.js +29 -0
  36. package/dist/PaginationOptions.js.map +1 -0
  37. package/dist/PaginationResult.d.ts +1 -0
  38. package/dist/PaginationResult.d.ts.map +1 -1
  39. package/dist/PaginationResult.js.map +1 -1
  40. package/dist/Ref.d.ts +120 -39
  41. package/dist/Ref.d.ts.map +1 -1
  42. package/dist/Ref.js +94 -38
  43. package/dist/Ref.js.map +1 -1
  44. package/dist/Refs.d.ts +9 -4
  45. package/dist/Refs.d.ts.map +1 -1
  46. package/dist/Refs.js +3 -3
  47. package/dist/Refs.js.map +1 -1
  48. package/dist/SchemaToValidator.d.ts +99 -0
  49. package/dist/SchemaToValidator.d.ts.map +1 -0
  50. package/dist/SchemaToValidator.js +156 -0
  51. package/dist/SchemaToValidator.js.map +1 -0
  52. package/dist/Spec.d.ts +3 -2
  53. package/dist/Spec.d.ts.map +1 -1
  54. package/dist/Spec.js +1 -1
  55. package/dist/Spec.js.map +1 -1
  56. package/dist/SystemFields.d.ts +1 -1
  57. package/dist/SystemFields.d.ts.map +1 -1
  58. package/dist/SystemFields.js +2 -2
  59. package/dist/SystemFields.js.map +1 -1
  60. package/dist/Table.d.ts +74 -0
  61. package/dist/Table.d.ts.map +1 -0
  62. package/dist/Table.js +77 -0
  63. package/dist/Table.js.map +1 -0
  64. package/dist/Types.d.ts +8 -2
  65. package/dist/Types.d.ts.map +1 -1
  66. package/dist/Types.js.map +1 -1
  67. package/dist/UserIdentity.d.ts.map +1 -1
  68. package/dist/index.d.ts +5 -1
  69. package/dist/index.d.ts.map +1 -1
  70. package/dist/index.js +7 -3
  71. package/package.json +14 -13
  72. package/src/FunctionProvenance.ts +187 -31
  73. package/src/FunctionSpec.ts +313 -85
  74. package/src/GroupPath.ts +1 -6
  75. package/src/GroupSpec.ts +125 -18
  76. package/src/Lazy.ts +2 -3
  77. package/src/MiddlewareSpec.ts +356 -0
  78. package/src/PaginationError.ts +72 -0
  79. package/src/PaginationOptions.ts +23 -0
  80. package/src/PaginationResult.ts +4 -0
  81. package/src/Ref.ts +429 -208
  82. package/src/Refs.ts +41 -16
  83. package/src/SchemaToValidator.ts +601 -0
  84. package/src/Spec.ts +4 -4
  85. package/src/SystemFields.ts +3 -6
  86. package/src/Table.ts +426 -0
  87. package/src/Types.ts +9 -3
  88. package/src/index.ts +5 -1
  89. package/dist/Registry.d.ts +0 -24
  90. package/dist/Registry.d.ts.map +0 -1
  91. package/dist/Registry.js +0 -19
  92. package/dist/Registry.js.map +0 -1
  93. package/dist/tsconfig.src.tsbuildinfo +0 -1
  94. package/src/Registry.ts +0 -30
package/CHANGELOG.md CHANGED
@@ -1,5 +1,464 @@
1
1
  # @confect/core
2
2
 
3
+ ## 10.0.0-next.20
4
+
5
+ ## 10.0.0-next.19
6
+
7
+ ### Minor Changes
8
+
9
+ - 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.
10
+
11
+ ```ts
12
+ import * as Confect from "@confect/foldkit";
13
+ import * as Schema from "effect/Schema";
14
+ import * as Subscription from "foldkit/subscription";
15
+
16
+ const SaveNote = Confect.Command.mutation(
17
+ "SaveNote",
18
+ refs.public.notes.insert,
19
+ {
20
+ messages: [SucceededSaveNote, FailedSaveNote],
21
+ onSuccess: (noteId) => SucceededSaveNote({ noteId }),
22
+ onError: (error) => FailedSaveNote({ message: String(error) }),
23
+ },
24
+ );
25
+
26
+ const subscriptions = Subscription.make<
27
+ Model,
28
+ Message,
29
+ Confect.Client.Client
30
+ >()(() => ({
31
+ note: Confect.Subscription.reactiveQuery<Model>()(refs.public.notes.get, {
32
+ args: (model) => Option.map(model.noteId, (noteId) => ({ noteId })),
33
+ onSuccess: (note) => SucceededGetNote({ note }),
34
+ onError: (error) => FailedGetNote({ message: String(error) }),
35
+ }),
36
+ }));
37
+ ```
38
+
39
+ 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.
40
+
41
+ `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.
42
+
43
+ `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.
44
+
45
+ ```ts
46
+ const Notes = Confect.PaginatedQuery.make(refs.public.notes.paginate);
47
+
48
+ // Model: notes: Notes.schema
49
+ // Initial Model value: notes: Notes.idle
50
+ // Message: settlement: Notes.settlement
51
+ // update after matching Idle: Notes.init(idle, { channel }, { initialNumItems: 20 })
52
+
53
+ const subscriptions = Subscription.make<
54
+ Model,
55
+ Message,
56
+ Confect.Client.Client
57
+ >()(() => ({
58
+ notesPage: Confect.Subscription.paginatedQuery<Model>()(Notes, {
59
+ state: (model) => model.notes,
60
+ onSettled: (settlement) => SettledGetNotesPage({ settlement }),
61
+ }),
62
+ }));
63
+ ```
64
+
65
+ - 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.
66
+
67
+ ## 10.0.0-next.18
68
+
69
+ ### Minor Changes
70
+
71
+ - 91aebe4: Move `Table.make` to `@confect/core` so a spec that returns `notes.Doc` from `_generated/tables/notes` no longer ships `@confect/server` to the client.
72
+
73
+ ```ts confect/tables/notes.ts
74
+ import { Table } from "@confect/core";
75
+ import * as Schema from "effect/Schema";
76
+
77
+ export default Table.make(() =>
78
+ Schema.Struct({
79
+ text: Schema.String,
80
+ }),
81
+ );
82
+ ```
83
+
84
+ `confect codegen` now fails if any module a spec reaches value-imports `@confect/server`, including `confect/tables/` and `_generated/`. Type-only imports remain allowed.
85
+
86
+ ## 10.0.0-next.17
87
+
88
+ ### Minor Changes
89
+
90
+ - 126548a: Add middleware: reusable logic that runs around a group's function handlers, provides Effect services to them, and fails with typed errors that reach clients.
91
+
92
+ Middleware lives in a reserved `confect/middleware/` directory, one `<Name>.spec.ts`/`<Name>.impl.ts` pair per middleware. Confect no longer scans that directory for function groups, so a group can no longer be defined at `confect/middleware/...`.
93
+
94
+ Declare a middleware's client-safe interface with `MiddlewareSpec.MiddlewareSpec` — its `provides` service (type-level), its `error` schema, and the function types it may cover (`functionTypes`, one required boolean flag per function type, so every spec states its coverage outright) — and attach it in a group spec with `GroupSpec.middleware`:
95
+
96
+ ```ts confect/middleware/RequireUser.spec.ts
97
+ import { MiddlewareSpec } from "@confect/core";
98
+
99
+ export class CurrentUser extends Context.Service<
100
+ CurrentUser,
101
+ {
102
+ readonly user: User;
103
+ }
104
+ >()("confect/middleware/RequireUser.spec/CurrentUser") {}
105
+
106
+ export class NotSignedIn extends Schema.TaggedError<NotSignedIn>()(
107
+ "NotSignedIn",
108
+ {},
109
+ ) {}
110
+
111
+ export default class RequireUser extends MiddlewareSpec.MiddlewareSpec<
112
+ RequireUser,
113
+ {
114
+ provides: CurrentUser;
115
+ }
116
+ >()("RequireUser", {
117
+ error: () => NotSignedIn,
118
+ functionTypes: { query: true, mutation: true, action: false },
119
+ }) {}
120
+ ```
121
+
122
+ ```ts confect/notes.spec.ts
123
+ import RequireUser from "./middleware/RequireUser.spec";
124
+
125
+ export default GroupSpec.make()
126
+ .middleware(RequireUser)
127
+ .addFunction(FunctionSpec.publicMutation({ ... }));
128
+ ```
129
+
130
+ Handlers of covered functions can then consume the provided service — a handler requiring `CurrentUser` type-checks exactly when a middleware providing it is attached to the group. Implement the middleware server-side with `MiddlewareImpl.make` (one strategy for all declared function types), `MiddlewareImpl.makeByFunctionType` (one per function type — the recommended shape for database-touching middleware that also covers actions), or the `MiddlewareImpl.provides` shorthand, and provide it to the group's impl layer like any function implementation:
131
+
132
+ ```ts confect/middleware/RequireUser.impl.ts
133
+ import { MiddlewareImpl } from "@confect/server";
134
+
135
+ export default MiddlewareImpl.provides(
136
+ databaseSchema,
137
+ RequireUser,
138
+ CurrentUser,
139
+ Effect.gen(function* () {
140
+ // load the user; `return yield* new NotSignedIn()` short-circuits
141
+ return { user };
142
+ }),
143
+ );
144
+ ```
145
+
146
+ ```ts confect/notes.impl.ts
147
+ import RequireUser from "./middleware/RequireUser.impl";
148
+
149
+ export default GroupImpl.make(databaseSchema, group).pipe(
150
+ Layer.provide(createNote),
151
+ Layer.provide(RequireUser), // omitting this is a compile error at `GroupImpl.finalize`
152
+ GroupImpl.finalize,
153
+ );
154
+ ```
155
+
156
+ Middleware runs per invocation, after args are decoded and before the handler, in attachment order; a middleware failure short-circuits the rest of the chain. Its errors join the covered functions' error unions end to end: `useQuery`/`useMutation` and the `@confect/js` clients surface them as typed errors with no client-side changes.
157
+
158
+ Middleware can also attach to a single function with `.middleware()` on the function spec — it runs inside the group-attached chain, immediately around the handler, and its errors join only that function's error union:
159
+
160
+ ```ts
161
+ FunctionSpec.publicMutation({ name: "deleteAll", ... }).middleware(RequireAdmin);
162
+ ```
163
+
164
+ A middleware can depend on one that runs earlier in the chain by declaring `requires` in its `Config` type parameter — its implementation may then consume the required service (e.g. `RequireAdmin` reading the `CurrentUser` that `RequireUser` provides). Satisfaction is type-checked at `GroupSpec.middleware` for group attachments and at `GroupImpl.make` for whole groups.
165
+
166
+ Attaching the same middleware twice (including once at group level and once at function level), attaching one whose `functionTypes` don't cover a covered function's type, attaching any middleware to a plain-Convex function, or attaching to a group containing a matching-type plain-Convex function are all type errors. Middleware does not propagate to subgroups. `confect codegen` fails with an explicit error when a group's spec attaches a middleware its impl never provides.
167
+
168
+ Because every `*.spec.ts` is reachable from `_generated/refs.ts`, which clients import, a spec's whole import graph is bundled into the browser — so an implementation co-located with its declaration ships server logic (table names, index names, authorization checks) to users. `confect codegen` now fails when any module a spec reaches value-imports `@confect/server`, outside the `tables/` and `_generated/` directories that legitimately need it. Type-only imports are erased before bundling and remain allowed.
169
+
170
+ ### Patch Changes
171
+
172
+ - 8e4962e: Raise the required `effect` peer version to `^4.0.0-rc.111` (from `^4.0.0-rc.110`), and `@confect/server`'s optional `@effect/platform-node` peer version likewise.
173
+
174
+ No Confect API changed, and no call-site edits are needed. `rc.111` is a patch release of Effect with nothing removed or renamed, so upgrading is a matter of installing it alongside `@confect/*`.
175
+
176
+ ## 10.0.0-next.16
177
+
178
+ ### Major Changes
179
+
180
+ - Migrate to Effect v4. All `@confect/*` packages now require `effect@^4.0.0-beta.97`; `@effect/platform` and `@effect/cli` are no longer dependencies (their functionality moved into `effect` core and `effect/unstable/*`).
181
+
182
+ Breaking changes for users:
183
+
184
+ - **Schemas** follow Effect v4's Schema API: `Schema.Union([a, b])` (array form), `Schema.Literals([...])` for literal unions, `Schema.optionalKey` in place of `optionalWith({ exact: true })`, and checks like `Schema.String.check(Schema.isMaxLength(...))` in place of piped filters.
185
+ - **Option-returning functions** must use a codec with a serializable encoded form, such as `Schema.OptionFromNullOr(...)` — v4's `Schema.Option` encodes to an `Option` instance, which is not a Convex value.
186
+ - **Table schemas** may now be transformations (`Schema.decodeTo` chains, `Schema.encodeKeys`), branded structs, suspended schemas, or unions of these — Convex's system fields are carried through the whole encoding chain. Schemas that do not resolve to an object shape at every step (such as `Schema.Class`) are rejected with a descriptive error when the table is defined.
187
+ - **Clients**: decode failures surface as `SchemaError` rather than `ParseError` in `@confect/js` and `@confect/react`, and `@confect/react`'s `useMutation`/`useAction` handles with an `error` schema now resolve to `Result` (v4's replacement for `Either`).
188
+ - **HTTP** is now mounted through the renamed `HttpRouter` module (formerly `HttpApi`). `HttpRouter.make(routes)` takes a single route-registering `Layer` composed from Effect's own `effect/unstable/http` and `effect/unstable/httpapi` modules — `HttpApiBuilder.layer(api)` (with group handler layers supplied via `Layer.provide`; a missing group is a compile-time error), `HttpApiScalar.layer` for docs, `HttpRouter.add` for plain routes, and `HttpRouter.middleware(fn, { global: true })` for middleware, merged with `Layer.mergeAll`. The per-path-prefix record and its `api`/`apiLive`/`middleware`/`scalar` options are gone; Confect registers one catch-all Convex HTTP action at `/`, and plain Convex routes added to the returned router still take precedence. Handlers, middleware, and route-layer construction all run with Confect's Convex-aware `ConfigProvider` in context.
189
+ - **Node actions** use `effect/unstable/process` (`ChildProcessSpawner`) and `@effect/platform-node`'s `NodeServices` in place of `@effect/platform` `Command`/`NodeContext`.
190
+ - **Configuration**: Confect's Convex-aware `ConfigProvider` treats empty-string environment variables as missing values (matching Effect v4's built-in providers), so `Config.withDefault` and `Config.option` recover from them.
191
+ - **CLI**: a malformed `convex.json` now fails codegen with a descriptive error instead of being silently ignored.
192
+ - Confect queries no longer stub the global `Date.now`. Queries run with a `Clock` whose unsafe accessors return constants, so Effect-internal reads (log timestamps, spans) never evict a query from Convex's cache; explicit time reads — `Clock.currentTimeMillis`/`currentTimeNanos` or a raw `Date.now()` call — opt the query out and evict as they honestly should.
193
+
194
+ ### Patch Changes
195
+
196
+ - Raise the required `effect` peer version to `^4.0.0-beta.100` (from `^4.0.0-beta.99`).
197
+
198
+ This is a peer-range-only change with no consumer-visible API consequences. The `beta.100` release only touches `Cron` internals (month/weekday alias normalization, day/weekday rollover, and equality/hashing), CLI error message formatting (`InvalidValue` prefixes), and `Schema.toTaggedUnion` discriminants that Confect doesn't use.
199
+
200
+ - Raise the required `effect` peer version to `^4.0.0-beta.101` (from `^4.0.0-beta.100`).
201
+
202
+ This is a peer-range-only change with no consumer-visible API consequences. The `beta.101` release only touches fiber/concurrency internals (interrupt handling in concurrent traversal, stack frame annotations, `awaitAllChildren` linearization, `interruptibleMask` interrupt delivery), a `MutableList.filter` fix for empty buckets, a `Schema.Struct` required-readonly-field type display simplification, and an `HttpRouter.toWebHandler` middleware type-inference tightening that Confect doesn't need to accommodate.
203
+
204
+ - Raise the required `effect` peer version to `^4.0.0-beta.102` (from `^4.0.0-beta.101`), and `@confect/server`'s optional `@effect/platform-node` peer version likewise.
205
+ - Raise the required `effect` peer version to `^4.0.0-beta.105` (from `^4.0.0-beta.102`), and `@confect/server`'s optional `@effect/platform-node` peer version likewise.
206
+
207
+ `beta.103` separates wall-clock time from monotonic elapsed time: `Clock.Clock` now also requires `monotonicTimeNanos` and `monotonicTimeNanosUnsafe`, so a custom `Clock` provided to a Confect function has to supply both. Effects that measure elapsed time — `Effect.timed`, duration metrics, `Sink.withDuration` — read the monotonic accessors instead of the wall clock, and continue to report a zero duration inside queries and mutations, where Confect pins the unsafe accessors to constants to keep Convex's query cache from evicting on every logged span.
208
+
209
+ `beta.103` also moves synchronous Effect runs off `setImmediate`/`setTimeout` and onto the microtask queue, which Convex's query and mutation isolate permits. Confect no longer suppresses cooperative fiber yielding for the synchronous work it performs while your modules load — registration and schema-to-validator compilation — and relies on that scheduling instead. Neither the "Can't use `setTimeout` in queries and mutations" crash nor any other consumer-visible behavior changes, but this is the area to look at if module loading starts misbehaving.
210
+
211
+ `beta.104` renames Effect's schema error constructors to match their `Data` counterparts, which affects any error schema you declare for a Confect function:
212
+
213
+ **Before:**
214
+
215
+ ```ts
216
+ export class NoteNotFound extends Schema.TaggedErrorClass<NoteNotFound>()(
217
+ "NoteNotFound",
218
+ { noteId: Id("notes") },
219
+ ) {}
220
+ ```
221
+
222
+ **After:**
223
+
224
+ ```ts
225
+ export class NoteNotFound extends Schema.TaggedError<NoteNotFound>()(
226
+ "NoteNotFound",
227
+ { noteId: Id("notes") },
228
+ ) {}
229
+ ```
230
+
231
+ `Schema.ErrorClass` is likewise now `Schema.Error`; the schema for JavaScript `Error` instances that previously went by `Schema.Error` is now `Schema.ErrorInstance`, and `Schema.ErrorReviver` is now `Schema.ErrorInstanceReviver`. Confect's own error types — `DocumentDecodeError`, `BlobNotFoundError`, and the rest — are unchanged in name, shape, and message.
232
+
233
+ `beta.105` restructures how schema validation failures are reported, but not on the path Confect puts you on: decode and encode failures still surface as `Schema.SchemaError` with a formatted `message`, so error text from `@confect/js`, `@confect/react`, and document decoding is unchanged.
234
+
235
+ - Raise the required `effect` peer version to `^4.0.0-beta.106` (from `^4.0.0-beta.105`), and `@confect/server`'s optional `@effect/platform-node` peer version likewise.
236
+
237
+ `beta.106` is a patch-only Effect release. Nothing in Confect's own API changes, and your table, argument, and returns schemas still compile to the same Convex validators.
238
+
239
+ One Effect change needs a call-site edit if you derive property-test generators from those schemas: `Schema.toArbitrary` now returns a factory that takes the `fast-check` module instead of returning an arbitrary directly, and `Schema.toArbitraryLazy` and the `{ report: true }` option are gone.
240
+
241
+ **Before:**
242
+
243
+ ```ts
244
+ const NoteArbitrary = Schema.toArbitrary(Note);
245
+ ```
246
+
247
+ **After:**
248
+
249
+ ```ts
250
+ import * as FastCheck from "fast-check";
251
+
252
+ const NoteArbitrary = Schema.toArbitrary(Note)(FastCheck);
253
+ ```
254
+
255
+ HTTP actions written against `HttpRouter` also inherit Effect's stricter multipart handling: a request that exceeds the configured part count, part size, or field size limits now stops being parsed at the limit rather than being read to completion first.
256
+
257
+ - Raise the required `effect` peer version to `^4.0.0-beta.107` (from `^4.0.0-beta.106`), and `@confect/server`'s optional `@effect/platform-node` peer version likewise.
258
+
259
+ `beta.107` is a patch-only Effect release, so no Confect API changes and no call-site edits are needed — upgrade `effect` alongside `@confect/*` and everything you have written keeps compiling. Your table, argument, and returns schemas still produce the same Convex validators.
260
+
261
+ Two Effect fixes are worth knowing about if they touch your code. HTTP actions written with `HttpRouter` now collect uploaded file contents far faster on large multipart bodies, and a file part whose stream is cut short — because a parser limit was exceeded or the request body ended early — now fails instead of hanging. Separately, `Duration` values that are equal now hash equally, so a `Duration` used as a `HashMap` key or a `HashSet` member is found regardless of which constructor built it.
262
+
263
+ - Raise the required `effect` peer version to `^4.0.0-beta.98` (from `^4.0.0-beta.97`).
264
+
265
+ `effect`'s `SchemaError` is now exposed as its own public module (`effect/SchemaError`), which changes the import path TypeScript picks when Confect emits `.d.ts` declarations that reference `Schema.SchemaError` (for example in generated `services.d.ts`). Existing `Schema.SchemaError` / `Schema.isSchemaError` usage is unaffected — this is purely a declaration-emit detail that consumers relying on generated types may notice.
266
+
267
+ - Raise the required `effect` peer version to `^4.0.0-beta.99` (from `^4.0.0-beta.98`).
268
+
269
+ This is a peer-range-only change with no consumer-visible API consequences. The `beta.99` release only touches `Graph`, CLI (`Command`/`CliConfig`/wizard mode), `Tool` cloning, Redis script eval, and multipart parser internals that Confect doesn't use.
270
+
271
+ - Raise the required `effect` peer version to `^4.0.0-rc.108` (from `^4.0.0-beta.107`), and `@confect/server`'s optional `@effect/platform-node` peer version likewise. Effect v4 has left beta for release candidates, so `effect@rc` is now the tag to install alongside `@confect/*`.
272
+
273
+ No Confect API changed, and no call-site edits are needed for Confect itself. One Effect change can reach your code: the standalone `effect/SchemaError` module is gone, and `SchemaError` is now exported from `Schema`. Confect still fails decoding with the same error, so this only matters if you name the type when handling it.
274
+
275
+ Before:
276
+
277
+ ```ts
278
+ import type { SchemaError } from "effect/SchemaError";
279
+ ```
280
+
281
+ After:
282
+
283
+ ```ts
284
+ import type { SchemaError } from "effect/Schema";
285
+ ```
286
+
287
+ Also worth knowing if you serve an `HttpApi`: a query parameter declared as an array now decodes correctly when a request supplies exactly one value for it.
288
+
289
+ One internal change rides along. Queries and mutations that run long enough to trigger a cooperative fiber yield now take that yield from Effect's own scheduler, which `rc.108` made usable inside Convex's isolate for the first time. The underlying microtask primitive is identical, so behavior should not change — but it is the thing to look at if a long-running query or mutation regresses on this release.
290
+
291
+ - Raise the required `effect` peer version to `^4.0.0-rc.109` (from `^4.0.0-rc.108`), and `@confect/server`'s optional `@effect/platform-node` peer version likewise.
292
+
293
+ No Confect API changed, and no call-site edits are needed. `rc.109` is a patch release of Effect with nothing removed or renamed, so upgrading is a matter of installing it alongside `@confect/*`.
294
+
295
+ - 8e4962e: Raise the required `effect` peer version to `^4.0.0-rc.110` (from `^4.0.0-rc.109`), and `@confect/server`'s optional `@effect/platform-node` peer version likewise.
296
+
297
+ No Confect API changed, and no call-site edits are needed. `rc.110` is a patch release of Effect with nothing removed or renamed, so upgrading is a matter of installing it alongside `@confect/*`.
298
+
299
+ - 3f0255c: Build and test against `convex` 1.44.0. The published `convex` peer ranges are unchanged, so no consumer action is required.
300
+ - The schemas Confect uses for values Convex itself produces now reject `NaN` and `±Infinity`: `_creationTime`, a scheduled function's `scheduledTime` and `completedTime`, a stored file's `size`, and the fields of `PaginationOptions`. Convex cannot return a non-finite value for any of them, so this rules out states that were never reachable.
301
+
302
+ The Convex validators these compile to are unchanged — each is still `v.float64()` — so nothing changes about what your deployment accepts. Only Confect's decoding is narrower. Your own table schemas are untouched: `Schema.Number` still accepts non-finite values wherever you use it, which matters because Convex stores them.
303
+
304
+ - Sync with `main`: this prerelease line now includes all changes released in `@confect/*` 9.2.2–9.2.4 — see those versions' changelog entries.
305
+ - Sync with `main`: this prerelease line now includes all changes released in `@confect/*` 9.2.5 — see that version's changelog entries.
306
+ - Sync with `main`: this prerelease line now includes all changes released in `@confect/*` 9.3.0 — see that version's changelog entries.
307
+ - Sync with `main`: this prerelease line now includes all changes released in `@confect/*` 9.4.0 — see that version's changelog entries.
308
+
309
+ The `@effect/platform` and `@effect/cli` peer and dependency floors that 9.4.0 raises do not apply here: this line runs on Effect v4, where those packages are not dependencies at all.
310
+
311
+ - The published type declarations are now emitted by TypeScript 7 rather than TypeScript 6. No API changed, but the declaration text differs in places, so an inferred type printed in your editor or in a type error may read slightly differently than before.
312
+
313
+ ## 10.0.0-next.15
314
+
315
+ ### Patch Changes
316
+
317
+ - 8e4962e: Raise the required `effect` peer version to `^4.0.0-rc.109` (from `^4.0.0-rc.108`), and `@confect/server`'s optional `@effect/platform-node` peer version likewise.
318
+
319
+ No Confect API changed, and no call-site edits are needed. `rc.109` is a patch release of Effect with nothing removed or renamed, so upgrading is a matter of installing it alongside `@confect/*`.
320
+
321
+ ## 10.0.0-next.14
322
+
323
+ ### Patch Changes
324
+
325
+ - 9d51bd3: Raise the required `effect` peer version to `^4.0.0-rc.108` (from `^4.0.0-beta.107`), and `@confect/server`'s optional `@effect/platform-node` peer version likewise. Effect v4 has left beta for release candidates, so `effect@rc` is now the tag to install alongside `@confect/*`.
326
+
327
+ No Confect API changed, and no call-site edits are needed for Confect itself. One Effect change can reach your code: the standalone `effect/SchemaError` module is gone, and `SchemaError` is now exported from `Schema`. Confect still fails decoding with the same error, so this only matters if you name the type when handling it.
328
+
329
+ Before:
330
+
331
+ ```ts
332
+ import type { SchemaError } from "effect/SchemaError";
333
+ ```
334
+
335
+ After:
336
+
337
+ ```ts
338
+ import type { SchemaError } from "effect/Schema";
339
+ ```
340
+
341
+ Also worth knowing if you serve an `HttpApi`: a query parameter declared as an array now decodes correctly when a request supplies exactly one value for it.
342
+
343
+ One internal change rides along. Queries and mutations that run long enough to trigger a cooperative fiber yield now take that yield from Effect's own scheduler, which `rc.108` made usable inside Convex's isolate for the first time. The underlying microtask primitive is identical, so behavior should not change — but it is the thing to look at if a long-running query or mutation regresses on this release.
344
+
345
+ - aede323: The schemas Confect uses for values Convex itself produces now reject `NaN` and `±Infinity`: `_creationTime`, a scheduled function's `scheduledTime` and `completedTime`, a stored file's `size`, and the fields of `PaginationOptions`. Convex cannot return a non-finite value for any of them, so this rules out states that were never reachable.
346
+
347
+ The Convex validators these compile to are unchanged — each is still `v.float64()` — so nothing changes about what your deployment accepts. Only Confect's decoding is narrower. Your own table schemas are untouched: `Schema.Number` still accepts non-finite values wherever you use it, which matters because Convex stores them.
348
+
349
+ - a4054ab: The published type declarations are now emitted by TypeScript 7 rather than TypeScript 6. No API changed, but the declaration text differs in places, so an inferred type printed in your editor or in a type error may read slightly differently than before.
350
+
351
+ ## 10.0.0-next.13
352
+
353
+ ### Patch Changes
354
+
355
+ - 5a73763: Raise the required `effect` peer version to `^4.0.0-beta.107` (from `^4.0.0-beta.106`), and `@confect/server`'s optional `@effect/platform-node` peer version likewise.
356
+
357
+ `beta.107` is a patch-only Effect release, so no Confect API changes and no call-site edits are needed — upgrade `effect` alongside `@confect/*` and everything you have written keeps compiling. Your table, argument, and returns schemas still produce the same Convex validators.
358
+
359
+ Two Effect fixes are worth knowing about if they touch your code. HTTP actions written with `HttpRouter` now collect uploaded file contents far faster on large multipart bodies, and a file part whose stream is cut short — because a parser limit was exceeded or the request body ended early — now fails instead of hanging. Separately, `Duration` values that are equal now hash equally, so a `Duration` used as a `HashMap` key or a `HashSet` member is found regardless of which constructor built it.
360
+
361
+ ## 10.0.0-next.12
362
+
363
+ ### Patch Changes
364
+
365
+ - 661ee9b: Raise the required `effect` peer version to `^4.0.0-beta.106` (from `^4.0.0-beta.105`), and `@confect/server`'s optional `@effect/platform-node` peer version likewise.
366
+
367
+ `beta.106` is a patch-only Effect release. Nothing in Confect's own API changes, and your table, argument, and returns schemas still compile to the same Convex validators.
368
+
369
+ One Effect change needs a call-site edit if you derive property-test generators from those schemas: `Schema.toArbitrary` now returns a factory that takes the `fast-check` module instead of returning an arbitrary directly, and `Schema.toArbitraryLazy` and the `{ report: true }` option are gone.
370
+
371
+ **Before:**
372
+
373
+ ```ts
374
+ const NoteArbitrary = Schema.toArbitrary(Note);
375
+ ```
376
+
377
+ **After:**
378
+
379
+ ```ts
380
+ import * as FastCheck from "fast-check";
381
+
382
+ const NoteArbitrary = Schema.toArbitrary(Note)(FastCheck);
383
+ ```
384
+
385
+ HTTP actions written against `HttpRouter` also inherit Effect's stricter multipart handling: a request that exceeds the configured part count, part size, or field size limits now stops being parsed at the limit rather than being read to completion first.
386
+
387
+ ## 10.0.0-next.11
388
+
389
+ ### Patch Changes
390
+
391
+ - f782cdd: Raise the required `effect` peer version to `^4.0.0-beta.105` (from `^4.0.0-beta.102`), and `@confect/server`'s optional `@effect/platform-node` peer version likewise.
392
+
393
+ `beta.103` separates wall-clock time from monotonic elapsed time: `Clock.Clock` now also requires `monotonicTimeNanos` and `monotonicTimeNanosUnsafe`, so a custom `Clock` provided to a Confect function has to supply both. Effects that measure elapsed time — `Effect.timed`, duration metrics, `Sink.withDuration` — read the monotonic accessors instead of the wall clock, and continue to report a zero duration inside queries and mutations, where Confect pins the unsafe accessors to constants to keep Convex's query cache from evicting on every logged span.
394
+
395
+ `beta.103` also moves synchronous Effect runs off `setImmediate`/`setTimeout` and onto the microtask queue, which Convex's query and mutation isolate permits. Confect no longer suppresses cooperative fiber yielding for the synchronous work it performs while your modules load — registration and schema-to-validator compilation — and relies on that scheduling instead. Neither the "Can't use `setTimeout` in queries and mutations" crash nor any other consumer-visible behavior changes, but this is the area to look at if module loading starts misbehaving.
396
+
397
+ `beta.104` renames Effect's schema error constructors to match their `Data` counterparts, which affects any error schema you declare for a Confect function:
398
+
399
+ **Before:**
400
+
401
+ ```ts
402
+ export class NoteNotFound extends Schema.TaggedErrorClass<NoteNotFound>()(
403
+ "NoteNotFound",
404
+ { noteId: Id("notes") },
405
+ ) {}
406
+ ```
407
+
408
+ **After:**
409
+
410
+ ```ts
411
+ export class NoteNotFound extends Schema.TaggedError<NoteNotFound>()(
412
+ "NoteNotFound",
413
+ { noteId: Id("notes") },
414
+ ) {}
415
+ ```
416
+
417
+ `Schema.ErrorClass` is likewise now `Schema.Error`; the schema for JavaScript `Error` instances that previously went by `Schema.Error` is now `Schema.ErrorInstance`, and `Schema.ErrorReviver` is now `Schema.ErrorInstanceReviver`. Confect's own error types — `DocumentDecodeError`, `BlobNotFoundError`, and the rest — are unchanged in name, shape, and message.
418
+
419
+ `beta.105` restructures how schema validation failures are reported, but not on the path Confect puts you on: decode and encode failures still surface as `Schema.SchemaError` with a formatted `message`, so error text from `@confect/js`, `@confect/react`, and document decoding is unchanged.
420
+
421
+ - Sync with `main`: this prerelease line now includes all changes released in `@confect/*` 9.4.0 — see that version's changelog entries.
422
+
423
+ The `@effect/platform` and `@effect/cli` peer and dependency floors that 9.4.0 raises do not apply here: this line runs on Effect v4, where those packages are not dependencies at all.
424
+
425
+ ## 10.0.0-next.10
426
+
427
+ ### Patch Changes
428
+
429
+ - Sync with `main`: this prerelease line now includes all changes released in `@confect/*` 9.3.0 — see that version's changelog entries.
430
+
431
+ ## 10.0.0-next.9
432
+
433
+ ### Patch Changes
434
+
435
+ - 0dcc0fb: Raise the required `effect` peer version to `^4.0.0-beta.102` (from `^4.0.0-beta.101`), and `@confect/server`'s optional `@effect/platform-node` peer version likewise.
436
+ - 25e8d19: Sync with `main`: this prerelease line now includes all changes released in `@confect/*` 9.2.5 — see that version's changelog entries.
437
+
438
+ ## 10.0.0-next.8
439
+
440
+ ### Patch Changes
441
+
442
+ - 913d0e5: Raise the required `effect` peer version to `^4.0.0-beta.101` (from `^4.0.0-beta.100`).
443
+
444
+ This is a peer-range-only change with no consumer-visible API consequences. The `beta.101` release only touches fiber/concurrency internals (interrupt handling in concurrent traversal, stack frame annotations, `awaitAllChildren` linearization, `interruptibleMask` interrupt delivery), a `MutableList.filter` fix for empty buckets, a `Schema.Struct` required-readonly-field type display simplification, and an `HttpRouter.toWebHandler` middleware type-inference tightening that Confect doesn't need to accommodate.
445
+
446
+ ## 10.0.0-next.7
447
+
448
+ ## 10.0.0-next.6
449
+
450
+ ## 10.0.0-next.5
451
+
452
+ ## 10.0.0-next.4
453
+
454
+ ## 10.0.0-next.3
455
+
456
+ ### Patch Changes
457
+
458
+ - 5b63546: Raise the required `effect` peer version to `^4.0.0-beta.100` (from `^4.0.0-beta.99`).
459
+
460
+ This is a peer-range-only change with no consumer-visible API consequences. The `beta.100` release only touches `Cron` internals (month/weekday alias normalization, day/weekday rollover, and equality/hashing), CLI error message formatting (`InvalidValue` prefixes), and `Schema.toTaggedUnion` discriminants that Confect doesn't use.
461
+
3
462
  ## 10.0.0-next.2
4
463
 
5
464
  ### Patch Changes
@@ -35,6 +494,65 @@
35
494
  - **CLI**: a malformed `convex.json` now fails codegen with a descriptive error instead of being silently ignored.
36
495
  - Confect queries no longer stub the global `Date.now`. Queries run with a `Clock` whose unsafe accessors return constants, so Effect-internal reads (log timestamps, spans) never evict a query from Convex's cache; explicit time reads — `Clock.currentTimeMillis`/`currentTimeNanos` or a raw `Date.now()` call — opt the query out and evict as they honestly should.
37
496
 
497
+ ## 9.4.1
498
+
499
+ ### Patch Changes
500
+
501
+ - a4054ab: The published type declarations are now emitted by TypeScript 7 rather than TypeScript 6. No API changed, but the declaration text differs in places, so an inferred type printed in your editor or in a type error may read slightly differently than before.
502
+
503
+ ## 9.4.0
504
+
505
+ ## 9.3.0
506
+
507
+ ### Minor Changes
508
+
509
+ - 16b5ad6: Add first-class paginated queries: declare one with `FunctionSpec.publicPaginatedQuery` (or `internalPaginatedQuery`) and read it with the new `usePaginatedQuery` hook from `@confect/react`.
510
+
511
+ Pass an `item` schema — the type of one element in a page — in place of `returns`, plus an optional `args` struct for your own arguments. The handler receives `paginationOpts` alongside them and forwards it to `paginate`.
512
+
513
+ ```ts
514
+ // confect/notes.spec.ts
515
+ FunctionSpec.publicPaginatedQuery({
516
+ name: "listByAuthor",
517
+ args: () => Schema.Struct({ author: Schema.String }),
518
+ item: () => notes.Doc,
519
+ });
520
+
521
+ // confect/notes.impl.ts
522
+ ({ author, paginationOpts }) =>
523
+ Effect.gen(function* () {
524
+ const reader = yield* DatabaseReader;
525
+
526
+ return yield* reader
527
+ .table("notes")
528
+ .index("by_creation_time", "desc")
529
+ .paginate(paginationOpts, (q) => q.eq(q.field("author"), author));
530
+ }).pipe(Effect.orDie);
531
+ ```
532
+
533
+ Declaring `paginationOpts` in `args` yourself is a type and runtime error.
534
+
535
+ ```tsx
536
+ import { PaginatedQueryResult, usePaginatedQuery } from "@confect/react";
537
+
538
+ const notes = usePaginatedQuery(
539
+ refs.public.notes.listByAuthor,
540
+ { author },
541
+ { initialNumItems: 10 },
542
+ );
543
+
544
+ // `notes.results` holds the pages decoded through `item`.
545
+ if (PaginatedQueryResult.isCanLoadMore(notes)) {
546
+ notes.loadMore(10);
547
+ }
548
+ ```
549
+
550
+ The hook returns a `PaginatedQueryResult<Item, E>`. `LoadingFirstPage`, `LoadingMore`, `CanLoadMore`, and `Exhausted` all carry `results` and `isLoading`; `loadMore` lives only on `CanLoadMore`, the one state it can make progress from. A declared `error` schema surfaces as a `Failure` variant carrying the decoded error instead of throwing during render, and `Failure` carries `results` too, so the pages loaded before it can still be rendered. Without an `error` schema, `Failure` is absent from the type entirely.
551
+
552
+ `paginate` in `@confect/server` now accepts Convex's full `PaginationOptions`, so a handler's `paginationOpts` passes straight through. `@confect/react` now requires `convex` >= 1.36.0.
553
+
554
+ ## 9.2.5
555
+
38
556
  ## 9.2.4
39
557
 
40
558
  ## 9.2.3
package/README.md CHANGED
@@ -5,7 +5,9 @@ Confect is a framework that deeply integrates Effect with Convex. It's more than
5
5
  - Define your Convex database schema using Effect schemas.
6
6
  - Write Convex function args and returns validators using Effect's schema library.
7
7
  - Use Confect functions to automatically decode and encode your data according to your Effect schema definitions for end-to-end rich types, from client to function to database (and back).
8
- - Use Effect's HTTP API modules to define your HTTP API(s). Includes interactive OpenAPI documentation powered by [Scalar](https://github.com/scalar/scalar).
8
+ - Add reusable, type-safe middleware to function groups or individual functions to provide Effect services and run logic around handlers.
9
+ - Declare typed errors on functions and middleware using Effect schemas, then handle the decoded errors at every call site.
10
+ - Use Effect's native HTTP API modules to define your HTTP API.
9
11
  - Access Convex platform capabilities via Effect services.
10
12
 
11
13
  Want to learn more? Read the [docs](https://confect.dev)!