docs(api): add creator query normalization docs with before/after examples#238
Conversation
…mples (accesslayerorg#211) Adds docs/api/creator-query-normalization.md covering normalization rules for creatorId, creatorAddress, and username query params, with before/after tables and a link to the Zod validation layer. Links the doc from public-query-parse.utils.ts JSDoc comment. Closes accesslayerorg#211
|
@Spagero763 Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits. You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀 |
There was a problem hiding this comment.
Pull request overview
Adds dedicated documentation describing how creator-identifying query parameters should be normalized/validated, and links that doc from the shared query-parse helper.
Changes:
- Add
docs/api/creator-query-normalization.mddescribing expected normalization rules with examples. - Add a cross-reference link to the new doc in
parsePublicQueryJSDoc.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 6 comments.
| File | Description |
|---|---|
| src/utils/public-query-parse.utils.ts | Adds a JSDoc pointer to the new creator query normalization reference doc. |
| docs/api/creator-query-normalization.md | New reference page for creator query normalization + validation integration examples. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| | Raw query string | Normalized value used in query | | ||
| | :------------------------ | :----------------------------------- | | ||
| | `creatorId=ABC-123` | rejected — not a valid UUID | | ||
| | `creatorId= 3f6a1b2c-… ` | `3f6a1b2c-…` (whitespace stripped) | | ||
| | `creatorId=3F6A1B2C-…` | `3f6a1b2c-…` (lowercased) | | ||
| | `creatorId=3f6a1b2c-…` | `3f6a1b2c-…` (unchanged, valid UUID) | |
There was a problem hiding this comment.
Same table formatting issue as above: these before/after examples use || at the start of each row, which adds an unintended empty column in rendered Markdown. Use a single leading | for each row.
| | Raw query string | Normalized value used in query | | ||
| | :-------------------------- | :---------------------------------------------- | | ||
| | `creatorAddress= GABC…XYZ ` | `GABC…XYZ` (whitespace stripped) | | ||
| | `creatorAddress=gabc…xyz` | rejected — lowercase Stellar address is invalid | | ||
| | `creatorAddress=GABC…XYZ` | `GABC…XYZ` (unchanged, valid address) | | ||
| | `creatorAddress=SHORTKEY` | rejected — not 56 characters | | ||
|
|
There was a problem hiding this comment.
Same table formatting issue as above: this table uses || at the start of rows/headers, which renders an extra blank first column. Switch to a single leading | for proper GitHub Markdown tables.
| | Raw query string | Normalized value used in query | | ||
| | :--------------------- | :----------------------------- | | ||
| | `username=Alice` | `alice` | | ||
| | `username= Alice ` | `alice` (trimmed + lowercased) | | ||
| | `username=MUSIC_MAKER` | `music_maker` | | ||
| | `username=` | _(parameter ignored)_ | | ||
|
|
There was a problem hiding this comment.
Same table formatting issue as above: this table’s rows start with ||, which creates an extra empty column when rendered. Use a single leading | for each row to match standard GitHub Markdown table syntax.
| This document describes how raw query parameters for creator lookup endpoints are | ||
| normalized before use. See [`src/utils/public-query-parse.utils.ts`](../../src/utils/public-query-parse.utils.ts) | ||
| for the generic Zod-based validation layer that wraps these parameters. | ||
|
|
||
| ## Overview | ||
|
|
||
| Creator lookup endpoints accept three optional identifier fields. Each field is | ||
| read directly from `req.query` by | ||
| [`parseCreatorPublicQuery`](../../src/utils/creator-public-query.util.ts) and | ||
| forwarded to the service layer as-is. No coercion, trimming, or case-folding is | ||
| applied at the utility level — normalization is the caller's responsibility. |
There was a problem hiding this comment.
This states the creator lookup endpoints read req.query via parseCreatorPublicQuery, but parseCreatorPublicQuery is not referenced anywhere in src/ (it’s currently only defined in src/utils/creator-public-query.util.ts). Either update the docs to describe the actual current call path/schemas that normalize these params, or clarify that this utility (and these query keys) are not wired into any endpoint yet.
| This document describes how raw query parameters for creator lookup endpoints are | |
| normalized before use. See [`src/utils/public-query-parse.utils.ts`](../../src/utils/public-query-parse.utils.ts) | |
| for the generic Zod-based validation layer that wraps these parameters. | |
| ## Overview | |
| Creator lookup endpoints accept three optional identifier fields. Each field is | |
| read directly from `req.query` by | |
| [`parseCreatorPublicQuery`](../../src/utils/creator-public-query.util.ts) and | |
| forwarded to the service layer as-is. No coercion, trimming, or case-folding is | |
| applied at the utility level — normalization is the caller's responsibility. | |
| This document describes the creator-related public query keys currently defined | |
| in the codebase and how they are intended to be normalized before use. See | |
| [`src/utils/public-query-parse.utils.ts`](../../src/utils/public-query-parse.utils.ts) | |
| for the generic Zod-based validation layer that wraps public query parameters. | |
| ## Overview | |
| The creator-specific helper | |
| [`parseCreatorPublicQuery`](../../src/utils/creator-public-query.util.ts) | |
| defines three optional identifier fields for creator lookups. However, this | |
| utility is not currently referenced by endpoint code in `src/`, so the fields | |
| below should be read as documented query definitions rather than a guaranteed | |
| live endpoint call path. Where these fields are used by callers, no coercion, | |
| trimming, or case-folding is applied at the utility level — normalization | |
| remains the caller's responsibility. |
| creatorId: z.string().uuid().optional(), | ||
| creatorAddress: z.string().length(56).startsWith('G').optional(), | ||
| username: z.string().trim().toLowerCase().optional(), |
There was a problem hiding this comment.
The example schema doesn’t match the normalization rules described above: creatorId isn’t trimmed/lowercased before UUID validation, creatorAddress isn’t trimmed, and username will return '' (not undefined) for username= after .trim(). Consider updating the example to show the same trim/case-folding/empty-string-to-absent behavior the doc specifies.
| creatorId: z.string().uuid().optional(), | |
| creatorAddress: z.string().length(56).startsWith('G').optional(), | |
| username: z.string().trim().toLowerCase().optional(), | |
| creatorId: z.string() | |
| .trim() | |
| .toLowerCase() | |
| .pipe(z.string().uuid()) | |
| .optional(), | |
| creatorAddress: z.string() | |
| .trim() | |
| .pipe(z.string().length(56).startsWith('G')) | |
| .optional(), | |
| username: z.string() | |
| .trim() | |
| .toLowerCase() | |
| .transform((value) => (value === '' ? undefined : value)) | |
| .optional(), |
| | Query key | Constant | Typical format | | ||
| | :--------------- | :------------------------------------------ | :---------------------- | | ||
| | `creatorId` | `CREATOR_PUBLIC_QUERY_KEYS.CREATOR_ID` | UUID v4 string | | ||
| | `creatorAddress` | `CREATOR_PUBLIC_QUERY_KEYS.CREATOR_ADDRESS` | Stellar public key (G…) | | ||
| | `username` | `CREATOR_PUBLIC_QUERY_KEYS.USERNAME` | Lowercase handle | |
There was a problem hiding this comment.
Markdown tables here start with || instead of |, which renders an extra empty first column in GitHub Markdown. Update the table rows/header separators to use a single leading | so the table columns align as intended.
Summary
docs/api/creator-query-normalization.md— a dedicated reference page for howcreatorId,creatorAddress, andusernamequery params are normalized before use in creator lookup endpointsparsePublicQuery+ Zod enforce these rules at the route layerparsePublicQueryJSDoc comment insrc/utils/public-query-parse.utils.tsso readers navigating the code can find the docBefore / after preview
usernameAlicealiceusernameAlicealicecreatorId3F6A1B2C-…3f6a1b2c-…creatorAddressGABC…XYZGABC…XYZTest plan
pnpm lintpasses (only a.tscomment change, linted by lint-staged)pnpm buildpasses (no code logic changed)Closes #211