Skip to content

[DEV-1824] Document the data source order contract and fix contradicting examples - #292

Open
galisufyan-327 wants to merge 5 commits into
masterfrom
fix/DEV-1824-ds-order-contract
Open

[DEV-1824] Document the data source order contract and fix contradicting examples#292
galisufyan-327 wants to merge 5 commits into
masterfrom
fix/DEV-1824-ds-order-contract

Conversation

@galisufyan-327

@galisufyan-327 galisufyan-327 commented Aug 21, 2026

Copy link
Copy Markdown
Contributor

Product areas affected

Developer documentation — data sources (docs/API/fliplet-datasources.md, docs/API/datasources/joins.md, docs/REST-API/fliplet-datasources.md, docs/coding-standards.md, docs/code-api-patterns.md) and the regenerated .well-known/llms-full.txt.

What does this PR do?

States the data source order contract for POST /v1/data-sources/:id/data/query, and removes the examples that contradicted it.

These docs are fetched at runtime by the V3 AI builder and override its own system prompt, so a wrong example here actively teaches the wrong shape. Before this PR the contract existed only as a code comment inside a fence, while eight-plus examples across the corpus showed forms the API rejects.

The contract, now stated as a table in ## Sorting and Ordering:

  • order is an array of arrays — never flat.
  • Only id, order, createdAt, deletedAt, updatedAt may appear unprefixed.
  • Every other column must be data.<ColumnName>.
  • The name after data. must match the declared column verbatim, spaces included.

Changes:

  • API/fliplet-datasources.md — contract table, a warning explaining the single-character error a flat array produces, an info block on undeclared columns, the corpus's first multi-word column example (data.Start Time UTC), and a WRONG/RIGHT block. Five unprefixed Name examples fixed to data.Name. The one oversized js fence was split into four independently runnable fences.
  • API/datasources/joins.md — scoped, not "fixed". See below.
  • REST-API/fliplet-datasources.md — dead anchor #sort--order-the-results#sorting-and-ordering, plus the same rules in JSON form.
  • coding-standards.md, code-api-patterns.md — corrected/annotated examples.

JIRA ticket

DEV-1824

Result

Verified against the API implementation (routes/v1/data-sources.js) rather than against the existing prose — every quoted error string matches byte-for-byte, and each documented failure mode was traced to the line that produces it.

Corpus state after the change:

  • No copyable flat top-level order example remains. Surviving flat examples are either inside a join: block (where flat is correct) or explicitly labelled WRONG.
  • No nested order: [['X', …]] with an unprefixed data column remains, except WRONG-labelled examples and API/core/analytics.md (a different endpoint, where the column is an attributes alias).

Docs CI (the exact gate in .github/workflows/docs-validate.yml):

npm run test:unit   → # tests 163 / # pass 163 / # fail 0
npm run check:docs  → exit 0, 203 docs indexed, strict

llms-full.txt is a faithful regeneration — re-running the generator leaves it byte-identical.

Checklist

  • Added automated test coverage as appropriate for this change.

Documentation-only; no runtime surface and no test seam to add. Verification is the CI gate above plus corpus-wide greps proving no contradicting example survives.

Deployment instructions

None beyond the normal docs deploy. No frontmatter description: or title: changed, so the search index entries are unchanged; llms-full.txt is regenerated and committed in-tree, so the freshness check is satisfied.

Companion Studio PR (Fliplet/fliplet-studio#8868) states the same contract in the builder prompt. Since these docs override the prompt, both should land together.

Author concerns

1. joins.md was deliberately NOT converted to the nested shape. The original plan called those flat examples the same defect class. They are not: a join-level order is a different parameter, sorted in memory after fetch (_.get(entry, order[0]), order[1] === 'DESC'), and it never reaches the allowedOrderColumns validator. Nesting it would have made order[0] an array and order[1] undefined, silently breaking join ordering and publishing a false doc. The examples are scoped instead, and the bare-string form (coerced to ASC) is now documented too.

2. The data. prefix is not exclusive to order, and saying so was a real bug in an earlier revision of this branch. where keys and attributes entries take bare names, but join on keys and aggregate paths do require the prefix. An earlier draft told readers not to generalize the prefix beyond order — which would have led an agent to write bare on keys and get a silently empty join (or, on a required join, a dropped row). All three sites now say only what is true, and the corpus was grepped to confirm no fourth site survives.

3. Pre-existing fence defects remain. API/fliplet-datasources.md has 11 fences that redeclare const connection, all pre-existing and untouched here. This branch removed one such fence and introduced none (12 → 11). Fixing the rest is out of scope.

4. One over-broad edge-case description. The docs say a prefixed one-character name that is "not a letter, digit, space, underscore or hyphen" produces the one-character error. The validator regex is /^[A-z0-9 _-]*$/, whose A-z span also admits [ \ ] ^ `. The data.@ example given is correct; only the class description is marginally wider than the regex.

galisufyan-327 and others added 5 commits August 21, 2026 18:10
…xamples

`POST /v1/data-sources/:id/data/query` validates `order` before running the
query, but the rules lived nowhere in the docs: the array-of-arrays shape was
only shown by example, and the five-column unprefixed allowlist existed solely
as a comment inside a code fence. Meanwhile several examples sorted by a data
column with no `data.` prefix, which the API rejects with 400.

- API/fliplet-datasources.md: `## Sorting and Ordering` now states the four
  rules in a table, warns that a flat array reports a single-character column
  name, and carries a Common mistakes block. Adds the first multi-word column
  example in the corpus (`data.Start Time UTC`), since the verbatim-with-spaces
  rule previously had no positive evidence to copy. Prefixes the five `Name`
  sorts that were missing `data.`.
- API/datasources/joins.md: scopes the join-level `order`, which is a single
  flat `[column, direction]` pair sorted in memory after the fetch and is NOT
  the top-level nested shape. Left flat, because flat is what the join code
  reads; the two shapes are now explicitly told apart.
- REST-API/fliplet-datasources.md: the `order` bullet pointed at a dead anchor,
  so an agent following it landed on the page top. Points at the real heading
  and restates the rules in JSON form next to the endpoint.
- coding-standards.md, code-api-patterns.md: prefix the data column, point at
  the rule.

Regenerates .well-known/llms-full.txt from source. No frontmatter changed.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Review follow-ups on the previous commit. Every claim below was re-checked in
`routes/v1/data-sources.js` before rewording.

- API/fliplet-datasources.md: the intro promised "four rules" above a five-row
  table. Scoped to "the shape or column rules" instead, which also fixes the
  wider problem — the 400 framing covered the Direction row, but `direction` is
  never validated (`sortDirection = direction || 'ASC'` is interpolated raw into
  the SQL literal), so a bad direction surfaces as a database error, not a 400.
  Direction is now presented as a convention.
- API/fliplet-datasources.md: the contract's example block declared `connection`
  four times in one fence, so pasting it whole threw a redeclaration
  SyntaxError. Split into four fences, each independently runnable.
- API/fliplet-datasources.md, REST-API/fliplet-datasources.md: "a one-character
  column name always means the shape is flat" was false — a declared
  one-character column used unprefixed reports the same error. Softened, with
  the second cause named.
- API/fliplet-datasources.md: the undeclared-column error is conditional. The
  check only runs when the data source declares columns; with none declared the
  sort silently yields NULLs. Qualified.
- API/datasources/joins.md: a join `order` also accepts a bare string, coerced
  to `[order, 'ASC']`. Added.
- API/fliplet-datasources.md, REST-API/fliplet-datasources.md,
  coding-standards.md: state that the `data.` prefix is specific to `order`.
  `where` keys are nested under `data` by the API and `attributes` are picked
  off `entry.data`, so both take unprefixed column names — without saying so,
  a reader could over-generalize the prefix and break working queries.

Regenerates .well-known/llms-full.txt from source. No frontmatter changed.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
The prefix note said the data. prefix was specific to order and told readers
not to generalize it. Join `on` keys and aggregate field paths address the raw
entry row, so they require the prefix; dropping it there fails silently.

Also correct the direction row (an invalid direction is still a 400, only the
message differs), note that the direction must be a literal because it reaches
the query unescaped, and soften the "only other way" claim about one-character
column names in the error.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
The `data.` prefix also applies to join `on` keys/values and `aggregate`
field paths, which read the raw entry row. Keep only the accurate half:
`where` and `attributes` take unprefixed column names.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
The direction row described how the API handles the value, not just what
to write. Keep the actionable half — write a literal, never build it from
user input, ASC is the default — and drop the implementation detail.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@cloudflare-workers-and-pages

Copy link
Copy Markdown

Deploying fliplet-cli with  Cloudflare Pages  Cloudflare Pages

Latest commit: 30753bf
Status: ✅  Deploy successful!
Preview URL: https://72284a0f.fliplet-cli.pages.dev
Branch Preview URL: https://fix-dev-1824-ds-order-contra.fliplet-cli.pages.dev

View logs

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.

1 participant