dartvex_codegen 0.4.2
dartvex_codegen: ^0.4.2 copied to clipboard
CLI code generator for Convex backends. Generates type-safe Dart bindings from the validators in your Convex function spec.
Changelog #
All notable changes to this project will be documented in this file.
The format is based on Keep a Changelog, and this project adheres to Semantic Versioning.
[Unreleased] #
0.4.2 - 2026-11-20 #
Changed #
- Documentation: "The Dartvex ecosystem" table lists
dartvex_auth2_convex, the Convex Auth (@convex-dev/authv2) adapter, published as 0.1.0. - Dev dependency on
dartvexraised to ^0.4.2 (tests only).
0.4.0 - 2026-11-20 #
Added #
- Generated
TypedQuerySuccessandTypedQueryErrorcarryfromCache, forwarded from the coreQuerySuccess.fromCache/QueryError.fromCache: the cached seed a new subscription replays before the server answers. A value the bindings fail to decode keeps the flag of the result it came from. Breaking (regenerated bindings): they requiredartvex^0.4.0, which adds those fields.
Changed #
- A union nested in a union is flattened:
v.union(v.union(a, b), c)generates the same type asv.union(a, b, c), with one case per leaf instead of an intermediate union type. Two nested unions in the same union used to be rejected as an ambiguous union, which made generation fail on validators composed from shared pieces, such as the sign-in results of@convex-dev/authv2. Breaking (regenerated bindings): a union with a single nested union, which already generated, loses its intermediate type.
Fixed #
- The generator checks that every file it reads, writes or deletes is really inside the output directory once symbolic links are followed. A manifest, a generated file or a parent directory that is a symbolic link leading elsewhere is refused before anything is modified; the path check was textual only. The output directory itself may still be a link.
0.3.0 - 2026-11-05 #
Added #
- Supports the convex 1.43+/1.49 validator kinds:
v.commitTs()maps toObject(expectCommitTs: aBigIntcommit timestamp, orConvexCommitTsPlaceholder.instancewhen a mutation returns a field it wrote withdb.vars.commitTsbefore committing; Convex types itbigint | CommitTsPlaceholder) andv.function()handles map toString, instead of degrading todynamicwith an "Unknown Convex type" warning. Breaking (regenerated bindings): fields of these kinds change fromdynamictoObject/String. Breaking (library API): the exported sealedConvexTypegains theConvexCommitTsTypeandConvexFunctionHandleTypesubclasses, so exhaustive switches overConvexTypeneed new cases. - Generated mutation methods take an optional
OptimisticUpdate? optimisticUpdateand forward it toConvexFunctionCaller.mutate(positionally, matchingConvexClient.mutate). Breaking: regenerated bindings requiredartvex^0.3.0, whoseConvexFunctionCaller.mutateaccepts it; customConvexFunctionCallerimplementations must add the parameter. TypedQuerySuccessnow carrieshasPendingWritesandlogLinesfrom the underlyingQuerySuccess.- Top-level
dartvex_codegen --help(or-h,help) lists thegenerateandscrubcommands and exits 0. ProcessRunnerExceptionhas anexitCode, and itstoString()includes the last lines of the captured Convex CLI output.FileEmitter.emitaccepts anonWarningcallback.
Fixed #
- Generated
TypedConvexPaginatedResultexposeshasPendingWrites. - Watch mode on Linux watches source directories reached through symlinks, without following cycles.
--watch --projectnow sees changes in nested directories on Linux, whereDirectory.watch(recursive: true)only watches the top level; every directory exceptnode_modules,.git,.dart_tool, and the output directory is watched individually.--watch --projectre-reads the deployed function spec 2, 5, and 10 seconds after each change, so aconvex devpush that finishes after the first regeneration no longer leaves stale bindings. Unchanged specs are not rewritten.- Watch mode arms its filesystem watches before the initial generation (so
edits made during it are not lost), keeps watching when the initial
generation fails, and survives atomic replaces of a
--spec-file(it watches the parent directory). A truncated, empty spec file is skipped silently. A watch error or a removed watched directory now exits non-zero with a concise message instead of hanging or crashing with an unhandled error. - Generated union case classes no longer collide with nested types named
from the same prefix (an object member's
valuefield or a record member's values), which produced duplicate declarations that did not compile. Case class names are unchanged; the nested type gets a numeric suffix. - Unions of distinct literals with the same runtime type plus another member
(
v.union(v.literal('auto'), v.literal('none'), v.number())) no longer fail as "Ambiguous union". - An argument named like the return type (for example
result) no longer aborts generation with a spurious "Name collision": table names are now collected without mapping types. _id/_creationTimenext to user fieldsid/creationTimeno longer abort generation; the system fields are generated assystemIdandsystemCreationTime.- A system table whose ID class collides with a user table's (
_storageandstorage) no longer aborts generation; the system table's class gets aSystemprefix (SystemStorageId). - Field and function names
toString,hashCode,runtimeType, andnoSuchMethodget aValuesuffix instead of producing invalid record fields or overrides. - Non-object top-level
argsvalidators (unions, records) generate an untypedMap<String, dynamic>argument with a warning instead of crashing the run with an uncaughtStateError. - Records keyed by
v.id(...), string literals, or unions of those keep their value type (Map<String, V>) instead of degrading toMap<String, dynamic>with a misleading "keys are not strings" warning. Breaking (regenerated bindings): such fields change type. - Breaking (behavior): decode failures in generated subscriptions
become
TypedQueryErrorevents instead of stream errors.TypedConvexPaginatedQueryreports undecodable items asConvexPaginationStatus.errorinstead of throwing fromcurrent/itemsor erroring the stream. TypedConvexPaginatedQuery.streamreturns the same stream on every access (aStreamBuilderno longer resubscribes on rebuild), andcurrent/itemsdecode each snapshot once. Breaking:itemsis now an unmodifiable list.- Failing
convex function-specruns show the CLI's own error output (for exampleNo CONVEX_DEPLOYMENT set) instead of only "failed in scrubandgenerate --spec-fileaccept the same noisy runner output (for example yarn v1 banners) that--projectalready tolerates.- A corrupted or merge-conflicted generator manifest no longer breaks every
run with an opaque
FormatException; it is ignored with a warning and rewritten. The manifest is now written atomically. - Unknown types inside internal functions, which are never generated, no longer produce warnings.
- Warnings and watch-mode errors go to stderr, so
--dry-runoutput stays clean. Unknown commands print usage to stderr. --watch --projectmatches the output directory however a symlink spells it (macOS/varvs/private/var, or a relative--outputresolved against the real current directory while--projectnames a symlink), so writing the bindings no longer triggers another regeneration or, on Linux, a watch of the output directory. Ignored directory names (node_modules,.git,.dart_tool) only count below the project directory, so a project that itself lives under such a directory is still watched.
Changed #
- Generated subscriptions delegate to a new
typedQueryResulthelper in the generatedruntime.dart. - Package descriptions now say bindings are generated from the function spec validators rather than "from your Convex schema".
- The README documents watch-mode behavior, type-mapping rules, naming
rules, custom
ConvexFunctionCallerclients, and that the exported pipeline stages are not yet a stable API. - Removed the duplicate
test/update_goldens.dart; usedart run tool/update_goldens.dart. - README and example: the bindings come from the functions deployed to the
project's deployment (
convex function-spec), not from local sources; documents the generated result types and which clientsConvexApiaccepts, and the example shows the real generated shape.
0.2.0 - 2026-06-12 #
Added #
- Tolerates raw
convex function-specdumps: absent ornullargs/returnsparse as the Convexanytype (a returns-less function generatesFuture<dynamic>; an unvalidated-args function takes aMap<String, dynamic>argument) instead of aborting generation. - Unknown/future Convex type tags and non-scalar literal values (such as
$integer-encoded bigint literals) degrade todynamicwith a warning instead of crashing the run. - Spec parse errors now name the offending function and field path
(
messages.ts:list → args → field "filters"). dartvex_codegen scrubsubcommand andscrubFunctionSpec: replace the real deployment URL in a function-spec dump with a placeholder before the file is committed.- Typed paginated query bindings: a query taking
paginationOptsand returning aPaginationResultshape generates aTypedConvexPaginatedQuery<PageItem>wrapper (typed page items when areturns:validator exists,Map<String, dynamic>items otherwise), exposingitems,stream,status,isDone,loadMore, andcancel. - Generated files carry an
ignore_for_fileline under the generated-code header, so projects that do not exclude the generated directory from analysis do not fail on unused generated helpers or imports.
Fixed #
- Encoding an optional field with a nullable composite type (for example
v.optional(v.union(v.id('users'), v.null()))) generated Dart that did not compile; nullable encodes now bind through a promoting switch expression. - Generated locals no longer collide with user argument names: arguments named
raw,value,subscription, orquery(for examplekv.set(key, value)or a paginatedsearch(query)) previously generated code that failed to compile. - A paginated query with an argument that sanitizes to
pageSizefalls back to a plain query method with a warning instead of declaring the parameter twice. - Unions of only null members (including
v.literal(null)) map toNullinstead of rendering an empty Dart enum, and nested nullable unions no longer emit invalidT??annotations. - NUL characters in string literals are escaped as
\x00; Dart has no\0escape, so the previous output silently matched the digit'0'. - Generated typed query subscriptions now include
TypedQueryLoading<T>and handledartvexQueryLoadingevents, keeping generated switches exhaustive withdartvex0.2.x. - CLI generation failures now return non-zero exit codes and print concise errors instead of leaking raw uncaught stack traces to callers.
- Escapes literal-union enum
fromJsonerror messages so literal values with quotes, dollars, or newlines do not generate invalid Dart source. - Escapes generated imports, Convex function names, and table names embedded in Dart string literals, so unusual but valid identifiers containing quotes, dollars, or control characters do not produce analyzer-broken bindings.
- Deduplicates repeated literal union members before rendering enum decoders, so
redundant validators cannot generate duplicate Dart
switchcases. - Rejects unsafe generated file paths from malformed function specs or stale manifests instead of writing or deleting files outside the configured output directory.
- Fails code generation when a generated Dart file cannot be formatted instead of emitting invalid source with only a warning.
- Rejects Convex table names that would generate duplicate
ConvexTableIdsubclasses inschema.dart. - Rejects generated API member name collisions before writing invalid Dart.
- Preserves existing camelCase boundaries in generated method and field names.
- Rejects missing
--outputpaths before path normalization.
Changed #
- Widen the
dartvexdev-dependency to^0.2.0for golden fixture validation. - Breaking (noted after release): regenerated bindings changed in this
release: the sealed
TypedQueryResultgained aTypedQueryLoadingcase (exhaustiveswitches need a new branch), paginated queries generate typed wrappers, and the output requiresdartvex^0.2.0(QueryLoading,ConvexFunctionCaller.paginatedQuery). - Require Dart
^3.7.0, matching the minimum SDK required by thedart_styleformatter versions accepted by the CLI.
0.1.3 - 2026-04-30 #
Improved #
- Refreshed README metadata, logo links, installation snippets, and example commands for pub.dev.
0.1.2 - 2026-03-21 #
Improved #
- Added comprehensive dartdoc comments on all public API
- Added example file for pub.dev scoring