-
Notifications
You must be signed in to change notification settings - Fork 19
Self-contained sync rules and sync streams sections #655
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,9 +1,9 @@ | ||
| --- | ||
| allowed-tools: Read, Bash(npx mintlify *), Bash(PATH=* npx mintlify *), Bash(vale *), Bash(git diff *), Bash(git status *) | ||
| description: Run Vale and Mintlify broken-link checks for documentation changes and report failures. | ||
| allowed-tools: Read, Bash(pnpm check:links), Bash(PATH=* pnpm check:links), Bash(vale *), Bash(git diff *), Bash(git status *) | ||
| description: Run Vale and the link check for documentation changes and report failures. | ||
| --- | ||
|
|
||
| 1. Read the canonical [Verification](../CLAUDE.md#verification) section for commands, supported Node versions, and vocabulary rules. | ||
| 1. Read the canonical [Verification](../CLAUDE.md#verification) section for commands and vocabulary rules. | ||
| 2. Use the requested file scope. Otherwise, identify changed MDX pages with `git diff main --name-only --diff-filter=ACMR -- '*.mdx'` and `git status --short`, including untracked pages. | ||
| 3. Run `vale <file>` for each page and `npx mintlify broken-links` for the site. Use the canonical Node fallback if needed. | ||
| 3. Run `vale <file>` for each page and `pnpm check:links` once for the site. | ||
| 4. Report findings by file, suggested fixes, and totals for errors, warnings, and suggestions. Report failed or unavailable checks separately from content findings. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,187 @@ | ||
| #!/usr/bin/env node | ||
| /** | ||
| * Snippet-aware link check. | ||
| * | ||
| * Runs `mintlify broken-links --check-anchors --check-snippets`, then re-validates | ||
| * every reported `#anchor` against the headings of the target page *including* | ||
| * headings that come from snippets the page imports. The Mintlify checker only | ||
| * reads page files, so a page whose body lives in a snippet (for example the pages | ||
| * shared between the Sync Streams and Sync Rules sections, see snippets/sync-shared/) | ||
| * would otherwise fail for every inbound anchor link. | ||
| * | ||
| * Reported links without a fragment, and anchors that still cannot be found, are | ||
| * printed in the Mintlify format and make the script exit with status 1. | ||
| */ | ||
| import { spawnSync } from 'node:child_process'; | ||
| import { existsSync, readFileSync } from 'node:fs'; | ||
| import path from 'node:path'; | ||
|
|
||
| const nodeMajor = Number(process.versions.node.split('.')[0]); | ||
| if (nodeMajor < 20 || nodeMajor > 24) { | ||
| console.error( | ||
| `The Mintlify CLI supports Node 20.17 to 24, but this is Node ${process.versions.node}.\n` + | ||
| 'Run `nvm use` (the repo pins Node 24 in .nvmrc) or prefix the command with ' + | ||
| 'PATH="/opt/homebrew/opt/node@24/bin:$PATH".', | ||
| ); | ||
| process.exit(1); | ||
| } | ||
|
|
||
| const root = process.cwd(); | ||
| const localBin = path.join(root, 'node_modules', '.bin', 'mintlify'); | ||
| const bin = existsSync(localBin) ? localBin : 'mintlify'; | ||
|
|
||
| const run = spawnSync(bin, ['broken-links', '--check-anchors', '--check-snippets'], { | ||
| cwd: root, | ||
| encoding: 'utf8', | ||
| maxBuffer: 64 * 1024 * 1024, | ||
| }); | ||
| if (run.error) { | ||
| console.error(`Could not run ${bin}: ${run.error.message}`); | ||
| process.exit(1); | ||
| } | ||
|
|
||
| const output = ((run.stdout ?? '') + (run.stderr ?? '')) | ||
| .replace(/\x1B\[[0-9;?]*[A-Za-z]/g, '') | ||
| .replace(/\r/g, ''); | ||
|
|
||
| // Parse blocks of "<file>\n ⎿ <link>\n ⎿ <link>". | ||
| const flagged = []; | ||
| let currentFile = null; | ||
| for (const rawLine of output.split('\n')) { | ||
| const line = rawLine.trim(); | ||
| if (!line) continue; | ||
| if (/checking for broken links/.test(line)) continue; | ||
| if (/^found \d+ broken link/.test(line)) continue; | ||
| if (/^success/i.test(line)) continue; | ||
| const link = line.match(/^⎿\s*(\S.*)$/); | ||
| if (link) { | ||
| if (currentFile) flagged.push({ file: currentFile, link: link[1].trim() }); | ||
| continue; | ||
| } | ||
| currentFile = line; | ||
| } | ||
|
|
||
| if (run.status === 0 && flagged.length === 0) { | ||
| console.log('success no broken links found'); | ||
| process.exit(0); | ||
| } | ||
| if (flagged.length === 0) { | ||
| // Non-zero exit without a parsable report: show what Mintlify printed. | ||
| console.log(output.trim()); | ||
| process.exit(run.status ?? 1); | ||
| } | ||
|
|
||
| function pageFile(urlPath) { | ||
| const p = urlPath.replace(/^\//, '').replace(/\/$/, ''); | ||
| for (const candidate of [`${p}.mdx`, `${p}.md`, `${p}/index.mdx`, `${p}/index.md`]) { | ||
| if (existsSync(path.join(root, candidate))) return candidate; | ||
| } | ||
| return null; | ||
| } | ||
|
|
||
| function snippetFile(spec) { | ||
| const rel = spec.startsWith('/') ? spec.slice(1) : path.posix.join('snippets', spec); | ||
| return existsSync(path.join(root, rel)) ? rel : null; | ||
| } | ||
|
|
||
| // Page source plus the source of every snippet it imports, recursively. | ||
| function collectSource(file, seen = new Set()) { | ||
| if (seen.has(file)) return ''; | ||
| seen.add(file); | ||
| const src = readFileSync(path.join(root, file), 'utf8').replace(/^---\n[\s\S]*?\n---\n/, ''); | ||
| let out = src; | ||
| for (const m of src.matchAll(/^import\s+\w+\s+from\s+['"]([^'"]+)['"]/gm)) { | ||
| const f = snippetFile(m[1]); | ||
| if (f) out += `\n${collectSource(f, seen)}`; | ||
| } | ||
| for (const m of src.matchAll(/<Snippet\s+file=["']([^"']+)["']/g)) { | ||
| const f = snippetFile(m[1]); | ||
| if (f) out += `\n${collectSource(f, seen)}`; | ||
| } | ||
| return out; | ||
| } | ||
|
|
||
| // Mintlify slugs: inline JSX, backticks, emphasis, and punctuation such as | ||
| // parentheses are dropped; underscores are kept; spaces become hyphens. Several | ||
| // candidates are produced so that the check stays lenient about edge cases the | ||
| // Mintlify checker has already accepted elsewhere. | ||
| function slugCandidates(text) { | ||
| const base = text | ||
| .replace(/<[^>]*>/g, ' ') | ||
| .replace(/\[([^\]]*)\]\([^)]*\)/g, '$1') | ||
| .replace(/[`*]/g, '') | ||
| .trim() | ||
| .toLowerCase(); | ||
| const strict = base.replace(/[^a-z0-9\s_-]/g, '').trim().replace(/\s+/g, '-'); | ||
| const keepPunctuation = base.replace(/[^a-z0-9\s_/:-]/g, '').trim().replace(/\s+/g, '-'); | ||
| return new Set([strict, keepPunctuation, strict.replace(/-+/g, '-'), keepPunctuation.replace(/-+/g, '-')]); | ||
| } | ||
|
|
||
| const anchorCache = new Map(); | ||
| function anchorsFor(file) { | ||
| if (anchorCache.has(file)) return anchorCache.get(file); | ||
| const src = collectSource(file).replace(/```[\s\S]*?```/g, ''); | ||
| const anchors = new Set(); | ||
| for (const m of src.matchAll(/^#{1,6}\s+(.+?)\s*$/gm)) { | ||
| let heading = m[1]; | ||
| const explicit = heading.match(/\{#([^}]+)\}\s*$/); | ||
| if (explicit) { | ||
| anchors.add(explicit[1]); | ||
| heading = heading.replace(/\{#[^}]+\}\s*$/, ''); | ||
| } | ||
| for (const slug of slugCandidates(heading)) anchors.add(slug); | ||
| } | ||
| for (const m of src.matchAll(/<Accordion\b[^>]*\btitle=["']([^"']+)["']/g)) { | ||
| for (const slug of slugCandidates(m[1])) anchors.add(slug); | ||
| } | ||
| for (const m of src.matchAll(/\bid=["']([^"']+)["']/g)) anchors.add(m[1]); | ||
| for (const m of src.matchAll(/<(?:ResponseField|ParamField)\b[^>]*\bname=["']([^"']+)["']/g)) { | ||
| anchors.add(`param-${m[1].replace(/_/g, '-')}`); | ||
| } | ||
| anchorCache.set(file, anchors); | ||
| return anchors; | ||
| } | ||
|
|
||
| const unresolved = []; | ||
| for (const item of flagged) { | ||
| const hash = item.link.indexOf('#'); | ||
| if (hash < 0) { | ||
| unresolved.push(item); // a path problem, not an anchor problem | ||
| continue; | ||
| } | ||
| const target = item.link.slice(0, hash).split('?')[0]; | ||
| let anchor = item.link.slice(hash + 1); | ||
| try { | ||
| anchor = decodeURIComponent(anchor); | ||
| } catch { | ||
| // keep the raw fragment | ||
| } | ||
| const file = target === '' ? item.file : pageFile(target); | ||
| if (!file) { | ||
| unresolved.push(item); | ||
| continue; | ||
| } | ||
| const anchors = anchorsFor(file); | ||
| const withoutSuffix = anchor.replace(/-\d+$/, ''); | ||
| if (anchors.has(anchor) || (withoutSuffix !== anchor && anchors.has(withoutSuffix))) continue; | ||
| unresolved.push(item); | ||
| } | ||
|
|
||
| const plural = (n, word) => `${n} ${word}${n === 1 ? '' : 's'}`; | ||
| if (unresolved.length === 0) { | ||
| console.log(`success no broken links found (${plural(flagged.length, 'anchor')} resolved through imported snippets)`); | ||
| process.exit(0); | ||
| } | ||
|
|
||
| const byFile = new Map(); | ||
| for (const item of unresolved) { | ||
| if (!byFile.has(item.file)) byFile.set(item.file, []); | ||
| byFile.get(item.file).push(item.link); | ||
| } | ||
| console.log(`found ${plural(unresolved.length, 'broken link')} in ${plural(byFile.size, 'file')}\n`); | ||
| for (const [file, links] of byFile) { | ||
| console.log(file); | ||
| for (const link of links) console.log(` ⎿ ${link}`); | ||
| console.log(); | ||
| } | ||
| process.exit(1); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| {/* Shared body: rendered by sync/advanced/case-sensitivity.mdx (Sync Streams section) and sync/rules/case-sensitivity.mdx (Sync Rules (Legacy) section). Keep the content valid for both engines. */} | ||
|
|
||
| ### Case in Sync Rules | ||
|
|
||
| PowerSync converts all table/collection and column/field names to lower-case by default in Sync Rule queries (this is how Postgres also behaves). To preserve the case, surround the names with double quotes, for example: | ||
|
|
||
| ```sql | ||
| SELECT "ID" as id, "Description", "ListID" FROM "TODOs" WHERE "TODOs"."ListID" = bucket.list_id | ||
| ``` | ||
|
|
||
| When using `SELECT *`, the original case is preserved for the returned columns/fields. | ||
|
|
||
| ### Client-Side Case | ||
|
|
||
| On the client side, the case of table and column names in the [client-side schema](/intro/setup-guide#define-your-client-side-schema) must match the case produced by Sync Rules exactly. For the above example, use the following in Dart: | ||
|
|
||
| ```dart | ||
| Table('TODOs', [ | ||
| Column.text('Description'), | ||
| Column.text('ListID') | ||
| ]) | ||
| ``` | ||
|
|
||
| SQLite itself is case-insensitive. When querying and modifying the data on the client, any case may be used. For example, the above table may be queried using `SELECT description FROM todos WHERE listid = ?`. | ||
|
|
||
| Operations (`PUT`/`PATCH`/`DELETE`) are stored in the upload queue using the case as defined in the schema above for table and column names, not the case used in queries. | ||
|
|
||
| As another example, in this Sync Rule query: | ||
|
|
||
| ```sql | ||
| SELECT ID, todo_description as Description FROM todo_items as TODOs | ||
| ``` | ||
|
|
||
| Each identifier in the example is unquoted and converted to lower case. That means the client-side schema would be: | ||
|
|
||
| ```dart | ||
| Table('todos', [ | ||
| Column.text('description') | ||
| ]) | ||
| ``` | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This snippet now renders on the Sync Streams page (
sync/advanced/case-sensitivity.mdx) as well as the Sync Rules page, but the heading and prose still frame case-folding as a Sync Rules-only behavior: "Case in Sync Rules" here, "Sync Rule queries" on line 5, "case produced by Sync Rules" on line 15, and "this Sync Rule query" on line 28. A Sync Streams reader will see this unchanged and be pointed at a concept ("Sync Rules") that doesn't apply to them. Reword these to be engine-neutral (e.g. "Case in Sync Queries" / "sync queries") so the shared body actually reads as valid for both engines.