Automatic Dart client code generation for NpgsqlRest, targeting Flutter projects.
Generates plain Dart modules that call NpgsqlRest endpoints using package:http — no other dependencies, works on all Flutter targets (mobile, desktop, web).
For every endpoint the generator emits:
- A request class with a
toJson()method (one field per routine parameter, optional-named constructor parameters). - A response class with a
fromJson()factory (one field per column), or a plain Dart type for scalar responses. - An async function wrapping the HTTP call: query-string, path and JSON-body parameters handled automatically.
- Optional
ApiResult<T>/ApiErrorwrappers carrying the HTTP status code and problem-details errors (IncludeStatusCode). - Multipart upload functions for upload endpoints (
http.MultipartRequest, files sent as form fieldfile, optionalprogresscallback reporting uploaded bytes, optional XSRF token header). - Server-sent events support for SSE endpoints: a
create{Name}EventSourcefactory returning anSseSubscription(built on streamedpackage:httpresponses — no extra dependency), and SSE-aware functions acceptingonMessage,id,closeAfterMsandawaitConnectionMs, attaching the execution-id header to the triggering request. - Raw responses for proxies:
proxy_outand void proxy pass-through endpoints returnFuture<http.Response>directly. - Optional per-call
parseUrl/parseRequesthooks (IncludeParseUrlParam/IncludeParseRequestParam) to rewrite the URI or request before sending.
Testing: generated modules expose a top-level http.Client? httpClient variable — assign a MockClient from package:http/testing.dart to intercept requests in tests.
All model fields are nullable (T?).
numeric/moneymap todouble— arbitrary precision beyond IEEE 754 is lost (the JSON wire format already carries a JSON number).- Dart
inton the web (dart2js) is limited to 2^53;bigintvalues beyond that lose precision on Flutter Web. - Multi-dimensional PostgreSQL arrays are typed as one-dimensional
List<T>(PostgreSQL's type system does not expose array dimensionality).
Per-endpoint overrides in routine comments:
dartclient = off— exclude the endpoint from generation.dartclient_module=name— group the endpoint into module filename(falls back totsclient_module, so SQL-file directory grouping applies to both generators).dartclient_status_code=true— wrap this endpoint's response inApiResult<T>.dartclient_events=false— generate a plain function for an SSE endpoint (no event-source parameters).dartclient_parse_url=true/dartclient_parse_request=true— add the per-call rewrite hooks to this endpoint.dartclient_export_url=true— emit a{name}Url()URL-builder function.dartclient_url_only=true— emit only the URL-builder function.
