|
| 1 | +--- |
| 2 | +description: Documentation requirements when making breaking changes or adding features to public library interfaces in packages |
| 3 | +globs: 'packages/**/*.ts', 'packages/**/*.tsx', 'packages/**/*.js', 'packages/**/*.jsx' |
| 4 | +alwaysApply: false |
| 5 | +--- |
| 6 | + |
| 7 | +# Package Documentation Requirements |
| 8 | + |
| 9 | +When making changes to public library interfaces in `/packages`, you **must** update the corresponding documentation in `/docs`. |
| 10 | + |
| 11 | +## Documentation Structure |
| 12 | + |
| 13 | +The `/docs` folder is organized by package: |
| 14 | +- `docs/core/` - Documentation for `@data-client/core` and `@data-client/react` |
| 15 | +- `docs/rest/` - Documentation for `@data-client/rest` |
| 16 | +- `docs/graphql/` - Documentation for `@data-client/graphql` |
| 17 | + |
| 18 | +Each package documentation has subdirectories: |
| 19 | +- `api/` - API reference documentation (one file per public class/function/hook) |
| 20 | +- `guides/` - How-to guides and tutorials |
| 21 | +- `concepts/` - Conceptual documentation |
| 22 | +- `getting-started/` - Getting started guides |
| 23 | + |
| 24 | +## When to Update Documentation |
| 25 | + |
| 26 | +### Breaking Changes |
| 27 | + |
| 28 | +**Breaking changes** include: |
| 29 | +- Removing public APIs (classes, functions, methods, hooks, composables) |
| 30 | +- Changing function/method signatures (parameter types, return types, required vs optional) |
| 31 | +- Changing class/interface properties (removing, renaming, changing types) |
| 32 | +- Changing default behavior that affects existing code |
| 33 | +- Deprecating APIs (should be documented with migration path) |
| 34 | + |
| 35 | +**Required actions:** |
| 36 | +1. Update the relevant API documentation file in `docs/{package}/api/` |
| 37 | +2. Add migration notes or deprecation warnings |
| 38 | +3. Update any guides or examples that use the changed API |
| 39 | +4. Update TypeScript types/examples in documentation |
| 40 | + |
| 41 | +### New Features |
| 42 | + |
| 43 | +**New features** include: |
| 44 | +- Adding new public APIs (classes, functions, methods, hooks, composables) |
| 45 | +- Adding new options/parameters to existing APIs |
| 46 | +- Adding new configuration options |
| 47 | +- New capabilities or behaviors |
| 48 | + |
| 49 | +**Required actions:** |
| 50 | +1. Create or update the relevant API documentation file in `docs/{package}/api/` |
| 51 | +2. Add usage examples |
| 52 | +3. Update relevant guides if the feature affects common workflows |
| 53 | +4. Add to getting-started guides if it's a major feature |
| 54 | + |
| 55 | +## Documentation File Naming |
| 56 | + |
| 57 | +API documentation files should match the exported name: |
| 58 | +- `useSuspense.ts` → `docs/core/api/useSuspense.md` |
| 59 | +- `RestEndpoint.js` → `docs/rest/api/RestEndpoint.md` |
| 60 | +- `Controller.ts` → `docs/core/api/Controller.md` |
| 61 | +- `Entity.ts` → `docs/rest/api/Entity.md` (or `docs/core/api/Entity.md`) |
| 62 | + |
| 63 | +## Documentation Format |
| 64 | + |
| 65 | +All API documentation files should include: |
| 66 | + |
| 67 | +1. **Frontmatter** with metadata: |
| 68 | +```markdown |
| 69 | +--- |
| 70 | +title: API Name |
| 71 | +sidebar_label: Display Name |
| 72 | +--- |
| 73 | +``` |
| 74 | + |
| 75 | +2. **Description** - What the API does |
| 76 | + |
| 77 | +3. **Usage examples** - Code examples showing how to use it |
| 78 | + |
| 79 | +4. **Parameters/Options** - Document all parameters, options, and return types |
| 80 | + |
| 81 | +5. **Type information** - TypeScript types and examples |
| 82 | + |
| 83 | +6. **Related APIs** - Links to related documentation |
| 84 | + |
| 85 | +## Finding the Right Documentation File |
| 86 | + |
| 87 | +1. **Identify the package**: Check which package the code belongs to (`packages/core`, `packages/rest`, etc.) |
| 88 | +2. **Check exports**: Look at the package's `index.ts` or main entry point to see what's exported |
| 89 | +3. **Match the name**: Find the corresponding file in `docs/{package}/api/` |
| 90 | +4. **Check guides**: If it's a workflow change, also check `docs/{package}/guides/` |
| 91 | + |
| 92 | +## Examples |
| 93 | + |
| 94 | +### Example 1: Adding a new hook |
| 95 | +- **File**: `packages/react/src/hooks/useNewFeature.ts` |
| 96 | +- **Action**: Create `docs/core/api/useNewFeature.md` with usage examples and API reference |
| 97 | + |
| 98 | +### Example 2: Changing a method signature |
| 99 | +- **File**: `packages/rest/src/RestEndpoint.js` (changing `extend()` method) |
| 100 | +- **Action**: Update `docs/rest/api/RestEndpoint.md` with new signature, migration notes, and updated examples |
| 101 | + |
| 102 | +### Example 3: Deprecating an API |
| 103 | +- **File**: `packages/core/src/SomeClass.ts` (deprecating `oldMethod()`) |
| 104 | +- **Action**: |
| 105 | + - Update `docs/core/api/SomeClass.md` with deprecation notice |
| 106 | + - Document the replacement API |
| 107 | + - Add migration guide if needed |
| 108 | + |
| 109 | +### Example 4: Adding a new option |
| 110 | +- **File**: `packages/rest/src/RestEndpoint.js` (adding `newOption` parameter) |
| 111 | +- **Action**: Update `docs/rest/api/RestEndpoint.md` to document the new option with examples |
| 112 | + |
| 113 | +## Checklist |
| 114 | + |
| 115 | +Before completing changes to public APIs in `/packages`: |
| 116 | + |
| 117 | +- [ ] Identified all affected public APIs (exports from package entry points) |
| 118 | +- [ ] Located or created corresponding documentation files in `/docs/{package}/api/` |
| 119 | +- [ ] Updated API reference documentation with changes |
| 120 | +- [ ] Added/updated code examples |
| 121 | +- [ ] Updated related guides if workflow changed |
| 122 | +- [ ] Added migration notes for breaking changes |
| 123 | +- [ ] Updated TypeScript examples in documentation |
| 124 | +- [ ] Verified documentation builds correctly (if applicable) |
| 125 | + |
| 126 | +## Important Notes |
| 127 | + |
| 128 | +- **Public APIs** are anything exported from the package's main entry point (typically `index.ts` or `src/index.ts`) |
| 129 | +- **Internal/private APIs** (prefixed with `_`, not exported, or marked as `@internal`) don't require documentation updates |
| 130 | +- When in doubt, **err on the side of documenting** - it's better to have extra documentation than missing documentation |
| 131 | +- Documentation should be updated **in the same commit or PR** as the code changes |
0 commit comments