Skip to content

feat(dotnet)!: redesign the client API for Dax.Formatter 2.0 - #62

Draft
albertospelta wants to merge 29 commits into
masterfrom
feat/dotnet-client-v2
Draft

albertospelta wants to merge 29 commits into
masterfrom
feat/dotnet-client-v2

Conversation

@albertospelta

@albertospelta albertospelta commented Nov 22, 2026 •

Copy link
Copy Markdown
Member

Dax.Formatter 2.0 is a client written from scratch, published first as
2.0.0-beta.1. It breaks the 1.x API: the 1.x sources, the interface and
the sample project are removed.

  • DaxFormatterClient formats one text with FormatAsync, or thousands in
    one call with FormatBatchAsync, on strings or on the caller's objects
    through a selector. Results come in input order and carry the item,
    the original and formatted text and the syntax errors.
  • A large call is split into requests of at most 250 texts and 250,000
    characters, sent two at a time by default, with a timeout, retries
    and progress reports. Blank texts are not sent.
  • DaxKind.Expression formats the DAX of model objects, user-defined
    functions included: the client adds and removes the header the
    service needs and maps error positions back to the caller's text.
  • A syntax error is a result; a failure of the service throws
    DaxFormatterException with its reason, status code, request and
    operation ids, and the indexes of the texts of the failed request.
  • DaxModelInfo describes the model with enums that mirror the TOM
    server enums. The wire format and the server name hash are the same
    as in 1.x.
  • The client sends the User-Agent, DaxFormatter-Request-Id and
    DaxFormatter-Operation-Id headers, and accepts an HttpClient, so
    AddHttpClient() works.
  • The package targets netstandard2.0 and net10.0; its only dependency
    is System.Text.Json on netstandard2.0.
  • dotnet/version.json holds a version written by hand.
  • ADR-0005, ADR-0006 and ADR-0007 record the redesign, the versioning
    and how the API grows; docs/design/client-api.md describes the client
    for the ports to other languages.
  • The package readme is short; ReadmeTests keeps its code equal to code
    that compiles and runs, and PublicApiTests pins the public surface.
    Live tests run only when DAXFORMATTER_LIVE_TESTS is set.

Fixes #40
Fixes #6

- ADR-0005: the public API of a client no longer mirrors the REST
  contract; it has kinds of text, outcomes as values and splitting
  inside the client, so that it can be ported to other languages
- ADR-0006: the Dax.Formatter package version is written by hand as
  three numbers in version.json, and NBGV only stamps it; this replaces
  one rule of ADR-0004, which stays accepted
- delete the 1.x client, its request and response models, its JSON
  converters and its tests: version 2.0 is written from scratch
- delete dotnet/samples: the examples move to the package readme,
  where the tests check them
- target netstandard2.0 and net10.0 in the library, net472 and net10.0
  in the tests; net8.0 applications use the netstandard2.0 assembly
- generate the XML documentation file, enable package validation and
  mark the net10.0 assembly as compatible with native AOT
- add the options of the client and of a call, the kinds of text, the
  line, spacing and separator styles, and the optional description of
  the model with the known server types
- add the result of a text, with the caller's item in its generic
  form, the syntax error with value equality, the progress value and
  the one exception of the client with its failure reason
- add the polyfills that netstandard2.0 needs for nullable attributes
  and for the argument guards of .NET
- copy and check the options of the client and of a call into
  immutable settings; the names of the server and of the database are
  kept only as SHA-256 hashes
- resolve the caller identity from the options or the entry assembly,
  and build the User-Agent value from HTTP tokens
- add the request and response bodies with source-generated JSON, so
  that the net10.0 assembly needs no reflection
- send serverMode, serverEdition and serverLocation as strings, as the
  TypeScript port does
- embed the fixtures of the wire format in the tests, starting with
  the name hashes
- recognize the body of a user-defined function by its parameter list
  followed by the arrow, with a scanner that knows where strings,
  names and comments start and end
- send an expression under a header line, FUNCTION x = for a function
  body and [x] := for anything else, and remove the header from the
  answer with the indentation that the service adds under a function
- leave alone the lines that start inside a string or a block comment,
  which the service returns as they were sent
- turn the position of a syntax error into a line and a UTF-16 index
  in the text of the caller: tab stops of 8, carriage returns without
  width, end of input at the end of the last line
- add fixtures with the answers recorded from the service
- send one attempt with the headers User-Agent, DaxFormatter-Request-Id
  and DaxFormatter-Operation-Id, without Accept-Encoding, to the
  endpoint that takes several texts
- end an attempt after the request timeout, and tell a timeout from a
  cancellation by the caller
- treat status 204, a body that is not the documented JSON and a wrong
  number of results as an invalid response
- retry timeouts, network errors and the statuses 408, 429, 500, 502,
  503 and 504 with a growing wait, honor Retry-After, and reuse the
  body and the request id in every attempt
- share one HttpClient among the clients that are not given one
- plan the requests of a call by number of texts and by characters;
  a text longer than the limit travels alone and a blank text is not
  sent
- run the requests with a few workers that write each result at the
  index of its text; the first request that fails stops the others
- report progress as a count of texts that never decreases
- add DaxFormatterClient with FormatAsync for one text and
  FormatBatchAsync for texts or for items with a text selector; the
  results come back in the order of the input, each with its item
- check the arguments before the first request and create nothing in
  the constructor, so that a class can derive from the client
- test the client offline against a fake HTTP handler that records the
  requests, with a recorded wait in place of the retry delay
- pin the public surface in an approved file, on both target
  frameworks, and the overload each kind of call binds to

Closes #40
Closes #6
- follow the sections of the NuGet readme guidance: getting started,
  usage with one snippet for each operation, migration from 1.x,
  limits of the service, further documentation and feedback
- keep every C# block equal to a region of a compiled test file, whose
  tests run the code against a fake of the service
- skip the tests that call the service unless DAXFORMATTER_LIVE_TESTS
  is set, so that CI stays offline
- check the recorded answers of the fixtures against the service, the
  formatting of a function, the three known limits of the service and
  a call that needs several requests
- write the full version by hand: the git height is now only the
  fourth number of the file version
- add client-api.md, the model of a client that the other languages
  will port, with the three limits of the service
- separate in rest-api.md the contract of the service from what the
  clients do, and add the new headers, the string enums and how the
  service reports positions
- update the architecture for the offline tests and the version
  written by hand
- close B-10, B-12 and B-13 in the backlog, reword B-4, B-5, B-8, B-11
  and B-16, and add B-17 to B-22
- update dotnet/AGENTS.md: no sample, offline tests, how to run the
  live ones, the version rules
- drop the fourth number of the informational version, which counts
  commits since the version is written by hand, and its commit id
- chain the public constructors instead of repeating their arguments
- read the library version from the constant that the build generates,
  not from the assembly attribute
- let the plan of a call write the texts of a request under their
  headers, so that the run only schedules
- share the answers of the fake service between the echo and the
  readme fakes, and hold answers until enough requests arrived with
  one responder
- test the progress lock from several threads: the old test ran its
  requests one after the other and passed without the lock
- let a cancellation thrown by the progress receiver of the caller
  reach the caller, instead of failing the call with an unknown reason
- name the request timeout in the message only when its own timer
  ended the attempt, not the timeout of the HttpClient of the caller
- read a response without content as an invalid response on .NET
  Framework, where it was a null reference
- skip a UTF-8 byte order mark before the JSON of an answer
- use the default handler where sockets are not supported, as in a
  browser, where the shared HttpClient could not be created
- throw for a cancelled token also when a batch has no texts
- record in the fake handler whether a request refuses Expect
  100-continue, so that the test can fail without that line
- register the client with a factory: AddHttpClient cannot choose
  between the two constructors that take an HttpClient
- say that on .NET Framework the shared HttpClient has the connection
  limit of ServicePointManager, 2 by default
- say that a literal null as second argument of FormatBatchAsync is
  ambiguous, and what to write in its place
The readme showed the batch call only with measures, which suggested
one call for each type of object.

- add a sample that formats measures and functions in one call, with
  items that carry the function that writes the result back
- compile and run the sample in the readme tests
The readme is for package users: the migration from 1.x, the limits of
the service and the links to the design documents don't belong there.

- remove the sections on migrating from 1.x and on the service limits
- keep only the SQLBI Docs link in the additional documentation
- drop the mentions of those sections from B-22 and ADR-0005
Two public constructors took an HttpClient, so IHttpClientFactory could
not pick one and services.AddHttpClient<DaxFormatterClient>() threw.

- replace them with DaxFormatterClient(HttpClient, options = null),
  where null means the default options; every existing call compiles
- test the typed-client registration, with the options taken from the
  container, through Microsoft.Extensions.Http in the test project only
- show the plain registration in the package readme
…quest

The indexes of the texts of a failed request were only in the message,
and the message counted the blank texts between them, which are never
sent. The id of the call went to the service but not to the caller.

- add OperationId and TextIndexes to DaxFormatterException, set by the
  client from the request that failed; TextIndexes is empty otherwise
- widen the full constructor, which copies the indexes
- keep the real indexes of its texts in each request
A caller that switches on DaxFormatterFailureReason must not break when
a minor version adds a reason: the remarks say to handle an unknown
value as Unknown.
Version 2.0 fixes the shape of the public API until 3.0, so the paths
for the features in view are written down before it ships.

- add ADR-0007: the batch takes the caller's items with a selector and
  returns a list in input order; the patterns not taken, with their
  pros and cons; how each later feature is added without breaking
- say in client-api.md that enums can gain values, that the column
  index follows the string unit of each language, and what the
  exception reports about a failed request
- add B-23, package validation once 2.0.0 is published
…ent types

The tuple of the sample had no name for the object, so the sample could
not say which one has a syntax error, and C# guidance prefers a named
type once the shape travels between methods.

- declare sealed record ModelExpression(Name, Expression, Update)
- report the name of an object whose text has a syntax error
- say that an object with several DAX texts adds one item for each
- add IsExternalInit to the tests, which records need on net472
- DaxModelInfo takes DaxServerType, DaxServerMode, DaxServerEdition
  and DaxServerLocation instead of strings, as in 1.x and in the
  TypeScript port; DaxServerTypes is gone.
- Mode, edition and location have the names and values of the
  Analysis Services enums, StandardDeveloper editions included, so a
  caller converts a value of those libraries by its name.
- The wire format doesn't change: the client sends the strings of
  the service, and rejects a value outside its enum.
- ADR-0005 and the REST API document say so.
The service counts distinct servers and databases by their hash
across every client and version, so the hash of 2.0 must equal the
one of 1.x. The fixture already holds the 1.x test vectors.
- rest-api.md says only that the hash is the one of 1.x.
- B-24: the hash depends on the case of the name.
- version.json holds 2.0.0-beta.1: the first release of 2.0 is a
  preview.
- The package description is one line.
- The readme keeps only installing, formatting a query and the
  measures of a model, the description of the model, the formatting
  options and the errors; it asks callers to fill ModelInfo.
- The readme samples follow it; the polyfill that only the removed
  record sample needed is gone.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add configurable timeout and batching support for large requests Remove the unused DaxFormatterSeparatorStyle enum

1 participant