Skip to content

📝 capture PR #102 learnings in CONVENTIONS.md and DEVELOPMENT.md#108

Open
Valpertui wants to merge 2 commits into
mainfrom
valpertui/docs-conventions-update
Open

📝 capture PR #102 learnings in CONVENTIONS.md and DEVELOPMENT.md#108
Valpertui wants to merge 2 commits into
mainfrom
valpertui/docs-conventions-update

Conversation

@Valpertui
Copy link
Copy Markdown
Member

Motivation

PR #102 (the main-process RUM Operations APIs) surfaced a handful of recurring patterns that aren't yet written down anywhere in the repo. Capturing them now means the next contributor (human or agent) doesn't rediscover the same notes through code review.

This is a docs-only change. No behavior change, no API surface change.

Changes

docs/CONVENTIONS.md — five new subsections:

  • Public API JSDoc — JSDoc on src/index.ts exports carries the contract, not implementation reasoning. Cross-link to the README "feature" section for usage walkthroughs (@see README "Operation Monitoring" is the precedent we just established).
  • @deprecated aliases — when renaming a public API after it has shipped, keep the old name as a deprecated alias that warns once per method and forwards to the new one. Drop in the next major.
  • Public API checklist — six bullets (index.ts export, domain impl + tests, README usage, playground, e2e harness, dist/ rebuild before downstream typecheck). The dist-rebuild step is the easy one to forget — it's the most common cause of "Module has no exported member" after a public-API rename.
  • Defensive input validation — for public APIs that route into the event pipeline, type the validator parameters as unknown (not the strict shape the public function declares), narrow with isValidString / isIndexableObject from @datadog/browser-core, and pin the runtime contract with tests that bypass the type system (badValue as unknown as ExpectedType).
  • Derive types from generated schemas — when a domain-internal type needs to mirror a schema field's enum, derive it (NonNullable<RumVitalOperationStepEvent['vital']>['step_type']) instead of duplicating literals. Schema regenerations propagate automatically.
  • displayError vs displayWarn — drop-vs-emit semantics. displayError for "we're refusing to do what you asked"; displayWarn for "we're still emitting but flagging something suspicious".

docs/DEVELOPMENT.md — new "Auto-Generated Files" table:

Test instructions

Visual review of the diff. No runtime impact.

Checklist

  • Tested locally (playground) — N/A, docs-only
  • Added unit tests for this change. — N/A
  • Added e2e/integration tests for this change. — N/A
  • Updated related documentation.

CONVENTIONS.md:
- Public API JSDoc rules (contract only, no impl details — README is the
  place for usage walkthroughs).
- Deprecation alias pattern (warn-once + JSDoc tag + delegate).
- "Public API checklist" — every new export needs index.ts + impl + README
  + playground + e2e harness + dist rebuild before downstream typecheck.
- Defensive validation pattern: validators take `unknown` and use
  `isValidString` / `isIndexableObject` to defend against JS callers that
  bypass the TS types.
- Derive types from generated schemas, don't duplicate enum literals.
- displayError vs displayWarn split (drop-vs-emit semantics).

DEVELOPMENT.md:
- Auto-generated files table — CHANGELOG.md (generated by `yarn release`)
  joins src/rumEvent.types.ts on the "do not edit by hand" list.
@Valpertui Valpertui requested a review from a team as a code owner April 27, 2026 20:49
Comment thread docs/CONVENTIONS.md
Comment on lines +26 to +35
## Public API Checklist

When adding or renaming a top-level export from `src/index.ts`, every change below MUST land in the same PR:

- [ ] `src/index.ts` — export with full JSDoc (contract + `@experimental`/`@deprecated` if applicable).
- [ ] Domain implementation (`src/domain/.../*Collection.ts`) — actual behavior + unit tests.
- [ ] **`README.md`** — usage example under the matching `## API` subsection. Public docs live here; don't put walkthroughs in JSDoc.
- [ ] **Playground** — IPC handler + button so the new API is exercisable locally without writing a one-off Electron app.
- [ ] **e2e harness** (`e2e/app/src/main.ts`, `e2e/app/src/preload.ts`, `e2e/lib/mainPage.ts`) + at least one scenario in `e2e/scenarios/` exercising the API end-to-end against the local intake mock.
- [ ] If the public surface changes, **rebuild `dist/`** before typechecking the playground / e2e: they consume `@datadog/electron-sdk` via portal/yarn workspace and read from `dist/index.d.ts`. Stale dist is the most common cause of "Module has no exported member 'X'" after a rename.
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💬 suggestion: as it is more a workflow than a rule, it would probably be better in DEVELOPMENT.md

Comment thread docs/DEVELOPMENT.md
| File | Generated by | Editing it instead |
| ----------------------- | --------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------- |
| `CHANGELOG.md` | `yarn release` (see "Releasing" below) — sections built from commit subjects since the previous tag | Edit commit messages or the editor-prompt during the release; the changelog rebuilds from there |
| `src/rumEvent.types.ts` | `yarn json-schemas:generate` from `rum-events-format` schemas | Update the upstream schema in `rum-events-format`, then regenerate |
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💬 suggestion: ‏we already cover schema management in the previous section, maybe we could link the sections instead of duplicating the content

Comment thread docs/CONVENTIONS.md
Comment on lines 3 to +7
## Code Documentation

Update relevant code documentation (JSDoc comments, inline comments) when modifying function behavior. Keep documentation in sync with implementation.

### Public API JSDoc
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💬 suggestion: alternate structure

  ## Documentation Maintenance                                                                                       
  [existing 1-liner: keep code documentation in sync with implementation]                                            
                                                                                                                     
  ## Public API
  (all that is related to public API)                                                                                                      
  [intro: applies to src/index.ts exports]                                                                           
  ### JSDoc                                                                                                        
  ### Deprecated Aliases
  ### Defensive Input Validation 

 ...

  ## Logging Severity
 (we may want to enrich it with other severity)

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.

2 participants