docs: backfill TOC + decision trees, fix review findings

- Add ## Contents and ## Decision Tree to all 10 existing pattern files
- Fix embed_as/1 semantics inversion in types.md (:self → :dump)
- Fix fabricated __meta__.changes reference in changesets.md
- Fix default primary key type (:integer → :id) in schemas.md
- Combine @impl subsections into single "Minimal Callback Annotation"
This commit is contained in:
2026-05-01 22:13:35 -07:00
parent b33accf37c
commit 10218813d3
13 changed files with 356 additions and 87 deletions
+26
View File
@@ -2,6 +2,19 @@
Patterns extracted from the Elixir standard library source code.
## Contents
1. [Public Type with @typedoc](#1-public-type-with-typedoc)
2. [Private Types with @typep](#2-private-types-with-typep)
3. [@opaque Types (Protocol t())](#3-opaque-types-protocol-t)
4. [Union Types in @spec Return Values](#4-union-types-in-spec-return-values)
5. [`when` Constraints in Specs](#5-when-constraints-in-specs)
6. [Map Types with required/optional Keys](#6-map-types-with-requiredoptional-keys)
7. [Keyword List Types for Options](#7-keyword-list-types-for-options)
8. [Parameterized Types (t/1)](#8-parameterized-types-t1)
9. [Named Parameters in Specs (:: annotation)](#9-named-parameters-in-specs--annotation)
10. [@typedoc since: Annotation](#10-typedoc-since-annotation)
---
## 1. Public Type with @typedoc
@@ -798,4 +811,17 @@ end
**Why:** `since:` annotations are for library consumers checking compatibility across versions. Application code doesn't have "consumers" checking which version introduced a type — it's all deployed together.
## Decision Tree
- If you are defining a public `@type` that appears in any `@spec` or callback → [Public Type with @typedoc](#1-public-type-with-typedoc)
- If a type is used only internally for recursion or DRYing up repeated expressions → [Private Types with @typep](#2-private-types-with-typep)
- If you want to hide internal representation and force consumers to use accessor functions → [@opaque Types](#3-opaque-types-protocol-t)
- If a function can return multiple distinct shapes (tagged tuples, atoms) → [Union Types in @spec Return Values](#4-union-types-in-spec-return-values)
- If the return type depends on the input type (generic/polymorphic function) → [`when` Constraints in Specs](#5-when-constraints-in-specs)
- If you accept a map with a mix of mandatory and optional keys → [Map Types with required/optional Keys](#6-map-types-with-requiredoptional-keys)
- If a function accepts a keyword list of options and you want to document valid keys → [Keyword List Types for Options](#7-keyword-list-types-for-options)
- If you define a container type and want specs to express what element type is inside → [Parameterized Types (t/1)](#8-parameterized-types-t1)
- If a parameter's type alone does not convey its purpose → [Named Parameters in Specs](#9-named-parameters-in-specs--annotation)
- If you are adding a new public type to an existing library post-1.0 → [@typedoc since: Annotation](#10-typedoc-since-annotation)
<!-- PATTERN_COMPLETE -->