@browsercore/dev 0.2.0 → 0.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,7 +1,7 @@
1
1
  # @browsercore/dev
2
2
 
3
3
  [![npm version](https://img.shields.io/npm/v/@browsercore/dev.svg)](https://www.npmjs.com/package/@browsercore/dev)
4
- [![coverage](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/jverneuer/browsercore-dev/coverage/coverage/badge.json)](https://github.com/jverneuer/browsercore-dev/blob/main/COVERAGE.md)
4
+ [![coverage](https://img.shields.io/endpoint?url=https://jverneuer.github.io/browsercore-dev/badge.json)](https://github.com/jverneuer/browsercore-dev/blob/main/COVERAGE.md)
5
5
  [![license](https://img.shields.io/npm/l/@browsercore/dev.svg)](LICENSE)
6
6
 
7
7
  Shared build, lint, test, and coverage tooling for every `@browsercore/*` package. One published package is the single source of truth; consumers extend it live via npm.
@@ -9,20 +9,27 @@
9
9
  * Distributed as the `coverage-md` bin of @browsercore/dev, replacing the
10
10
  * per-repo scripts/coverage-md.mjs copies.
11
11
  *
12
- * Dependency-free: only node:fs + node:path. Safe in CI with no install step.
12
+ * The bin is a thin I/O wrapper: all rendering logic and the boundary
13
+ * validation schema live in the compiled output (`dist/coverage-md.js`);
14
+ * this file reads JSON, validates it, renders, and writes results.
13
15
  */
14
16
  import { readFileSync, writeFileSync } from "node:fs";
15
17
  import { join, relative } from "node:path";
18
+ import {
19
+ renderCoverageMarkdown,
20
+ renderBadge,
21
+ CoverageSummarySchema,
22
+ } from "../dist/coverage-md.js";
16
23
 
17
24
  const pkgRoot = process.cwd();
18
25
  const summaryPath = join(pkgRoot, "coverage", "coverage-summary.json");
19
26
  const outPath = join(pkgRoot, "COVERAGE.md");
20
- const badgePath = join(pkgRoot, "coverage", "badge.json");
27
+ const badgePath = join(pkgRoot, ".github", "coverage-badge.json");
21
28
 
22
- /** @type {Record<string, { lines:{total:number,covered:number,pct:number}, statements:{total:number,covered:number,pct:number}, functions:{total:number,covered:number,pct:number}, branches:{total:number,covered:number,pct:number} }>} */
23
- let data;
29
+ /** @type {unknown} */
30
+ let raw;
24
31
  try {
25
- data = JSON.parse(readFileSync(summaryPath, "utf-8"));
32
+ raw = readFileSync(summaryPath, "utf-8");
26
33
  } catch {
27
34
  console.error(
28
35
  `[coverage-md] Could not read ${summaryPath}. ` +
@@ -31,23 +38,9 @@ try {
31
38
  process.exit(1);
32
39
  }
33
40
 
34
- const total = data.total;
35
- /**
36
- * @typedef {Object} Metric
37
- * @property {string} label
38
- * @property {keyof typeof total} key
39
- */
40
- /** @type {Metric[]} */
41
- const metrics = [
42
- { label: "Statements", key: "statements" },
43
- { label: "Branches", key: "branches" },
44
- { label: "Functions", key: "functions" },
45
- { label: "Lines", key: "lines" },
46
- ];
47
- /** @param {{pct:number,covered:number,total:number}} m */
48
- const render = (m) => `${m.pct}% (${m.covered}/${m.total})`;
41
+ const parsed = CoverageSummarySchema.parse(JSON.parse(raw));
49
42
 
50
- const fileEntries = Object.entries(data)
43
+ const fileEntries = Object.entries(parsed)
51
44
  .filter(([key]) => key !== "total")
52
45
  .map(([file, m]) => {
53
46
  // coverage-summary.json keys are absolute paths; show repo-relative.
@@ -56,44 +49,10 @@ const fileEntries = Object.entries(data)
56
49
  })
57
50
  .sort((a, b) => a.file.localeCompare(b.file));
58
51
 
59
- const lines = [];
60
- lines.push(`# Coverage report`);
61
- lines.push("");
62
- lines.push(`Generated from \`coverage-summary.json\` by \`coverage-md\` (@browsercore/dev).`);
63
- lines.push("");
64
- lines.push(`## Total`);
65
- lines.push("");
66
- lines.push(`| Metric | Coverage |`);
67
- lines.push(`| --- | --- |`);
68
- for (const { label, key } of metrics) {
69
- lines.push(`| ${label} | ${render(total[key])} |`);
70
- }
71
- lines.push("");
72
- lines.push(`## Per-file`);
73
- lines.push("");
74
- const header = `| File | ${metrics.map((m) => m.label).join(" | ")} |`;
75
- const sep = `| --- | ${metrics.map(() => "---").join(" | ")} |`;
76
- lines.push(header);
77
- lines.push(sep);
78
- for (const { file, m } of fileEntries) {
79
- lines.push(`| \`${file}\` | ${metrics.map((met) => render(m[met.key])).join(" | ")} |`);
80
- }
81
- lines.push("");
82
-
83
- writeFileSync(outPath, lines.join("\n"));
52
+ const md = renderCoverageMarkdown(parsed, fileEntries);
53
+ writeFileSync(outPath, md);
84
54
  console.log(`[coverage-md] wrote ${relative(process.cwd(), outPath)}`);
85
55
 
86
- // shields.io endpoint badge: a single coverage figure (statements %) for the
87
- // README badge. Color tiers mirror shields.io conventions.
88
- const pct = total.statements.pct;
89
- const badgeColor =
90
- pct >= 90 ? "brightgreen" : pct >= 75 ? "green" : pct >= 50 ? "yellow" : "red";
91
- const badge = {
92
- schemaVersion: 1,
93
- label: "coverage",
94
- message: `${pct}%`,
95
- color: badgeColor,
96
- namedLogo: "vitest",
97
- };
56
+ const badge = renderBadge(parsed.total.statements.pct);
98
57
  writeFileSync(badgePath, JSON.stringify(badge));
99
58
  console.log(`[coverage-md] wrote ${relative(process.cwd(), badgePath)}`);
@@ -1,32 +1,202 @@
1
1
  /**
2
- * Pure rendering logic for the coverage-md bin, extracted from bin/coverage-md.mjs
3
- * so it can be unit-tested without touching the filesystem. The bin imports these
4
- * helpers and handles I/O; everything here is deterministic given a coverage summary.
5
- */
6
- export interface MetricTotals {
7
- total: number;
8
- covered: number;
9
- pct: number;
10
- }
11
- export interface CoverageSummary {
12
- total: {
13
- statements: MetricTotals;
14
- branches: MetricTotals;
15
- functions: MetricTotals;
16
- lines: MetricTotals;
17
- };
18
- }
2
+ * Pure rendering logic for the coverage-md bin.
3
+ *
4
+ * Extracted from `bin/coverage-md.mjs` so it can be unit-tested without
5
+ * touching the filesystem. The bin imports these helpers and handles I/O;
6
+ * everything here is deterministic given a coverage summary.
7
+ *
8
+ * @module
9
+ * @since 0.1.0
10
+ */
11
+ import { z } from "zod";
12
+ /**
13
+ * Schema for a single metric's totals (statements, branches, functions, lines).
14
+ *
15
+ * @since 0.3.0
16
+ */
17
+ declare const metricTotalsSchema: z.ZodObject<{
18
+ total: z.ZodNumber;
19
+ covered: z.ZodNumber;
20
+ pct: z.ZodNumber;
21
+ }, z.core.$strip>;
22
+ /**
23
+ * Totals for a single metric (statements, branches, functions, lines).
24
+ *
25
+ * Derived from {@link metricTotalsSchema} so the type and its validator stay
26
+ * in sync.
27
+ *
28
+ * @since 0.1.0
29
+ */
30
+ export type MetricTotals = z.infer<typeof metricTotalsSchema>;
31
+ /**
32
+ * The shape of v8's `coverage-summary.json` file.
33
+ *
34
+ * `total` holds the aggregate; every other key is an absolute file path with
35
+ * the same per-metric shape. The `.catchall` validates every entry (total and
36
+ * per-file) against {@link fileCoverageSchema} without stripping the arbitrary
37
+ * file-path keys the bin iterates over.
38
+ *
39
+ * This is the single source of truth for the coverage shape: the
40
+ * {@link CoverageSummary} type is derived from it via `z.infer`, so the
41
+ * validated runtime shape and the static type can never drift.
42
+ *
43
+ * @since 0.3.0
44
+ */
45
+ export declare const CoverageSummarySchema: z.ZodObject<{
46
+ total: z.ZodObject<{
47
+ statements: z.ZodObject<{
48
+ total: z.ZodNumber;
49
+ covered: z.ZodNumber;
50
+ pct: z.ZodNumber;
51
+ }, z.core.$strip>;
52
+ branches: z.ZodObject<{
53
+ total: z.ZodNumber;
54
+ covered: z.ZodNumber;
55
+ pct: z.ZodNumber;
56
+ }, z.core.$strip>;
57
+ functions: z.ZodObject<{
58
+ total: z.ZodNumber;
59
+ covered: z.ZodNumber;
60
+ pct: z.ZodNumber;
61
+ }, z.core.$strip>;
62
+ lines: z.ZodObject<{
63
+ total: z.ZodNumber;
64
+ covered: z.ZodNumber;
65
+ pct: z.ZodNumber;
66
+ }, z.core.$strip>;
67
+ }, z.core.$strip>;
68
+ }, z.core.$catchall<z.ZodObject<{
69
+ statements: z.ZodObject<{
70
+ total: z.ZodNumber;
71
+ covered: z.ZodNumber;
72
+ pct: z.ZodNumber;
73
+ }, z.core.$strip>;
74
+ branches: z.ZodObject<{
75
+ total: z.ZodNumber;
76
+ covered: z.ZodNumber;
77
+ pct: z.ZodNumber;
78
+ }, z.core.$strip>;
79
+ functions: z.ZodObject<{
80
+ total: z.ZodNumber;
81
+ covered: z.ZodNumber;
82
+ pct: z.ZodNumber;
83
+ }, z.core.$strip>;
84
+ lines: z.ZodObject<{
85
+ total: z.ZodNumber;
86
+ covered: z.ZodNumber;
87
+ pct: z.ZodNumber;
88
+ }, z.core.$strip>;
89
+ }, z.core.$strip>>>;
90
+ /**
91
+ * The shape of v8's `coverage-summary.json` file.
92
+ *
93
+ * `total` holds the aggregate; every other key is an absolute file path with
94
+ * the same per-metric shape.
95
+ *
96
+ * Derived from {@link CoverageSummarySchema} so the type and its validator stay
97
+ * in sync.
98
+ *
99
+ * @since 0.1.0
100
+ */
101
+ export type CoverageSummary = z.infer<typeof CoverageSummarySchema>;
102
+ /**
103
+ * A single coverage metric with a human-readable label and its key in
104
+ * {@link CoverageSummary}.
105
+ *
106
+ * @since 0.1.0
107
+ */
19
108
  export interface Metric {
109
+ /** Human-readable label (e.g. `"Statements"`). */
20
110
  label: string;
111
+ /** Key into {@link CoverageSummary.total} (e.g. `"statements"`). */
21
112
  key: keyof CoverageSummary["total"];
22
113
  }
114
+ /**
115
+ * The canonical ordered list of coverage metrics.
116
+ *
117
+ * Used by both the markdown renderer and the badge renderer so they stay in sync.
118
+ *
119
+ * @since 0.1.0
120
+ */
23
121
  export declare const METRICS: Metric[];
122
+ /**
123
+ * Render a single metric as a human-readable string.
124
+ *
125
+ * @param m The metric totals to render.
126
+ * @returns A string like `"85% (17/20)"`.
127
+ *
128
+ * @example
129
+ * ```ts
130
+ * renderMetric({ total: 20, covered: 17, pct: 85 });
131
+ * // => "85% (17/20)"
132
+ * ```
133
+ *
134
+ * @since 0.1.0
135
+ */
24
136
  export declare const renderMetric: (m: MetricTotals) => string;
137
+ /**
138
+ * Map a coverage percentage to a badge color.
139
+ *
140
+ * Follows the Shields.io color scheme:
141
+ * - `≥ 90%` → `brightgreen`
142
+ * - `≥ 75%` → `green`
143
+ * - `≥ 50%` → `yellow`
144
+ * - `< 50%` → `red`
145
+ *
146
+ * @param pct Coverage percentage (0–100).
147
+ * @returns The Shields.io color name.
148
+ *
149
+ * @example
150
+ * ```ts
151
+ * badgeColor(95); // => "brightgreen"
152
+ * badgeColor(60); // => "yellow"
153
+ * badgeColor(30); // => "red"
154
+ * ```
155
+ *
156
+ * @since 0.1.0
157
+ */
25
158
  export declare const badgeColor: (pct: number) => string;
159
+ /**
160
+ * Render a full coverage report as a Markdown string.
161
+ *
162
+ * Produces a document with a total section and a per-file section, each as
163
+ * a table with columns for statements, branches, functions, and lines.
164
+ *
165
+ * @param data The aggregate coverage summary.
166
+ * @param fileEntries Per-file breakdown (file path + metric totals).
167
+ * @returns A complete Markdown document.
168
+ *
169
+ * @example
170
+ * ```ts
171
+ * const md = renderCoverageMarkdown(summary, [
172
+ * { file: "src/index.ts", m: { statements: { total: 10, covered: 8, pct: 80 }, ... } }
173
+ * ]);
174
+ * ```
175
+ *
176
+ * @since 0.1.0
177
+ */
26
178
  export declare const renderCoverageMarkdown: (data: CoverageSummary, fileEntries: Array<{
27
179
  file: string;
28
180
  m: CoverageSummary["total"];
29
181
  }>) => string;
182
+ /**
183
+ * Render a Shields.io-compatible coverage badge JSON object.
184
+ *
185
+ * The returned object can be written to a JSON file and served as a badge
186
+ * endpoint, or consumed directly by Shields.io's endpoint badge format.
187
+ *
188
+ * @param statementsPct The statements coverage percentage (0–100).
189
+ * @returns A badge object with `schemaVersion`, `label`, `message`, `color`, and `namedLogo`.
190
+ *
191
+ * @example
192
+ * ```ts
193
+ * renderBadge(87);
194
+ * // => { schemaVersion: 1, label: "coverage", message: "87%", color: "green", namedLogo: "vitest" }
195
+ * ```
196
+ *
197
+ * @see {@link https://shields.io/badges Shields.io badge format}
198
+ * @since 0.1.0
199
+ */
30
200
  export declare const renderBadge: (statementsPct: number) => {
31
201
  schemaVersion: number;
32
202
  label: string;
@@ -34,4 +204,5 @@ export declare const renderBadge: (statementsPct: number) => {
34
204
  color: string;
35
205
  namedLogo: string;
36
206
  };
207
+ export {};
37
208
  //# sourceMappingURL=coverage-md.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"coverage-md.d.ts","sourceRoot":"","sources":["../src/coverage-md.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,MAAM,WAAW,YAAY;IACzB,KAAK,EAAE,MAAM,CAAC;IACd,OAAO,EAAE,MAAM,CAAC;IAChB,GAAG,EAAE,MAAM,CAAC;CACf;AAED,MAAM,WAAW,eAAe;IAC5B,KAAK,EAAE;QACH,UAAU,EAAE,YAAY,CAAC;QACzB,QAAQ,EAAE,YAAY,CAAC;QACvB,SAAS,EAAE,YAAY,CAAC;QACxB,KAAK,EAAE,YAAY,CAAC;KACvB,CAAC;CACL;AAED,MAAM,WAAW,MAAM;IACnB,KAAK,EAAE,MAAM,CAAC;IACd,GAAG,EAAE,MAAM,eAAe,CAAC,OAAO,CAAC,CAAC;CACvC;AAED,eAAO,MAAM,OAAO,EAAE,MAAM,EAK3B,CAAC;AAEF,eAAO,MAAM,YAAY,MAAO,YAAY,KAAG,MAA+C,CAAC;AAE/F,eAAO,MAAM,UAAU,QAAS,MAAM,KAAG,MACyC,CAAC;AAEnF,eAAO,MAAM,sBAAsB,SACzB,eAAe,eACR,KAAK,CAAC;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,CAAC,EAAE,eAAe,CAAC,OAAO,CAAC,CAAA;CAAE,CAAC,KAClE,MA4BF,CAAC;AAEF,eAAO,MAAM,WAAW,kBACL,MAAM,KACtB;IAAE,aAAa,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,CAAC;IAAC,SAAS,EAAE,MAAM,CAAA;CAM1F,CAAC"}
1
+ {"version":3,"file":"coverage-md.d.ts","sourceRoot":"","sources":["../src/coverage-md.ts"],"names":[],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CAAC;IAAC,SAAS,EAAE,MAAM,CAAA;CAM1F,CAAC"}
@@ -1,7 +1,63 @@
1
1
  /**
2
- * Pure rendering logic for the coverage-md bin, extracted from bin/coverage-md.mjs
3
- * so it can be unit-tested without touching the filesystem. The bin imports these
4
- * helpers and handles I/O; everything here is deterministic given a coverage summary.
2
+ * Pure rendering logic for the coverage-md bin.
3
+ *
4
+ * Extracted from `bin/coverage-md.mjs` so it can be unit-tested without
5
+ * touching the filesystem. The bin imports these helpers and handles I/O;
6
+ * everything here is deterministic given a coverage summary.
7
+ *
8
+ * @module
9
+ * @since 0.1.0
10
+ */
11
+ import { z } from "zod";
12
+ /**
13
+ * Schema for a single metric's totals (statements, branches, functions, lines).
14
+ *
15
+ * @since 0.3.0
16
+ */
17
+ const metricTotalsSchema = z.object({
18
+ /** Total number of trackable items. */
19
+ total: z.number(),
20
+ /** Number of items that were covered. */
21
+ covered: z.number(),
22
+ /** Coverage percentage (0–100). */
23
+ pct: z.number(),
24
+ });
25
+ /**
26
+ * Schema for one file's coverage entry (or the aggregate `total` entry).
27
+ *
28
+ * @since 0.3.0
29
+ */
30
+ const fileCoverageSchema = z.object({
31
+ statements: metricTotalsSchema,
32
+ branches: metricTotalsSchema,
33
+ functions: metricTotalsSchema,
34
+ lines: metricTotalsSchema,
35
+ });
36
+ /**
37
+ * The shape of v8's `coverage-summary.json` file.
38
+ *
39
+ * `total` holds the aggregate; every other key is an absolute file path with
40
+ * the same per-metric shape. The `.catchall` validates every entry (total and
41
+ * per-file) against {@link fileCoverageSchema} without stripping the arbitrary
42
+ * file-path keys the bin iterates over.
43
+ *
44
+ * This is the single source of truth for the coverage shape: the
45
+ * {@link CoverageSummary} type is derived from it via `z.infer`, so the
46
+ * validated runtime shape and the static type can never drift.
47
+ *
48
+ * @since 0.3.0
49
+ */
50
+ export const CoverageSummarySchema = z
51
+ .object({
52
+ total: fileCoverageSchema,
53
+ })
54
+ .catchall(fileCoverageSchema);
55
+ /**
56
+ * The canonical ordered list of coverage metrics.
57
+ *
58
+ * Used by both the markdown renderer and the badge renderer so they stay in sync.
59
+ *
60
+ * @since 0.1.0
5
61
  */
6
62
  export const METRICS = [
7
63
  { label: "Statements", key: "statements" },
@@ -9,8 +65,62 @@ export const METRICS = [
9
65
  { label: "Functions", key: "functions" },
10
66
  { label: "Lines", key: "lines" },
11
67
  ];
68
+ /**
69
+ * Render a single metric as a human-readable string.
70
+ *
71
+ * @param m The metric totals to render.
72
+ * @returns A string like `"85% (17/20)"`.
73
+ *
74
+ * @example
75
+ * ```ts
76
+ * renderMetric({ total: 20, covered: 17, pct: 85 });
77
+ * // => "85% (17/20)"
78
+ * ```
79
+ *
80
+ * @since 0.1.0
81
+ */
12
82
  export const renderMetric = (m) => `${m.pct}% (${m.covered}/${m.total})`;
83
+ /**
84
+ * Map a coverage percentage to a badge color.
85
+ *
86
+ * Follows the Shields.io color scheme:
87
+ * - `≥ 90%` → `brightgreen`
88
+ * - `≥ 75%` → `green`
89
+ * - `≥ 50%` → `yellow`
90
+ * - `< 50%` → `red`
91
+ *
92
+ * @param pct Coverage percentage (0–100).
93
+ * @returns The Shields.io color name.
94
+ *
95
+ * @example
96
+ * ```ts
97
+ * badgeColor(95); // => "brightgreen"
98
+ * badgeColor(60); // => "yellow"
99
+ * badgeColor(30); // => "red"
100
+ * ```
101
+ *
102
+ * @since 0.1.0
103
+ */
13
104
  export const badgeColor = (pct) => pct >= 90 ? "brightgreen" : pct >= 75 ? "green" : pct >= 50 ? "yellow" : "red";
105
+ /**
106
+ * Render a full coverage report as a Markdown string.
107
+ *
108
+ * Produces a document with a total section and a per-file section, each as
109
+ * a table with columns for statements, branches, functions, and lines.
110
+ *
111
+ * @param data The aggregate coverage summary.
112
+ * @param fileEntries Per-file breakdown (file path + metric totals).
113
+ * @returns A complete Markdown document.
114
+ *
115
+ * @example
116
+ * ```ts
117
+ * const md = renderCoverageMarkdown(summary, [
118
+ * { file: "src/index.ts", m: { statements: { total: 10, covered: 8, pct: 80 }, ... } }
119
+ * ]);
120
+ * ```
121
+ *
122
+ * @since 0.1.0
123
+ */
14
124
  export const renderCoverageMarkdown = (data, fileEntries) => {
15
125
  const total = data.total;
16
126
  const totalRows = METRICS.map(({ label, key }) => `| ${label} | ${renderMetric(total[key])} |`);
@@ -36,6 +146,24 @@ export const renderCoverageMarkdown = (data, fileEntries) => {
36
146
  "",
37
147
  ].join("\n");
38
148
  };
149
+ /**
150
+ * Render a Shields.io-compatible coverage badge JSON object.
151
+ *
152
+ * The returned object can be written to a JSON file and served as a badge
153
+ * endpoint, or consumed directly by Shields.io's endpoint badge format.
154
+ *
155
+ * @param statementsPct The statements coverage percentage (0–100).
156
+ * @returns A badge object with `schemaVersion`, `label`, `message`, `color`, and `namedLogo`.
157
+ *
158
+ * @example
159
+ * ```ts
160
+ * renderBadge(87);
161
+ * // => { schemaVersion: 1, label: "coverage", message: "87%", color: "green", namedLogo: "vitest" }
162
+ * ```
163
+ *
164
+ * @see {@link https://shields.io/badges Shields.io badge format}
165
+ * @since 0.1.0
166
+ */
39
167
  export const renderBadge = (statementsPct) => ({
40
168
  schemaVersion: 1,
41
169
  label: "coverage",
@@ -1 +1 @@
1
- {"version":3,"file":"coverage-md.js","sourceRoot":"","sources":["../src/coverage-md.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAsBH,MAAM,CAAC,MAAM,OAAO,GAAa;IAC7B,EAAE,KAAK,EAAE,YAAY,EAAE,GAAG,EAAE,YAAY,EAAE;IAC1C,EAAE,KAAK,EAAE,UAAU,EAAE,GAAG,EAAE,UAAU,EAAE;IACtC,EAAE,KAAK,EAAE,WAAW,EAAE,GAAG,EAAE,WAAW,EAAE;IACxC,EAAE,KAAK,EAAE,OAAO,EAAE,GAAG,EAAE,OAAO,EAAE;CACnC,CAAC;AAEF,MAAM,CAAC,MAAM,YAAY,GAAG,CAAC,CAAe,EAAU,EAAE,CAAC,GAAG,CAAC,CAAC,GAAG,MAAM,CAAC,CAAC,OAAO,IAAI,CAAC,CAAC,K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IACvE,MAAM,GAAG,GAAG,WAAW,OAAO,CAAC,GAAG,CAAC,GAAG,EAAE,CAAC,KAAK,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC;IAChE,MAAM,QAAQ,GAAa,WAAW,CAAC,GAAG,CACtC,CAAC,EAAE,IAAI,EAAE,CAAC,EAAE,EAAE,EAAE,CAAC,OAAO,IAAI,QAAQ,OAAO,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,YAAY,CAAC,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,CACrG,CAAC;IAEF,OAAO;QACH,mBAAmB;QACnB,EAAE;QACF,6EAA6E;QAC7E,EAAE;QACF,UAAU;QACV,EAAE;QACF,uBAAuB;QACvB,eAAe;QACf,GAAG,SAAS;QACZ,EAAE;QACF,aAAa;QACb,EAAE;QACF,MAAM;QACN,GAAG;QACH,GAAG,QAAQ;QACX,EAAE;KACL,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AACjB,CAAC,CAAC;AAEF;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAM,CAAC,MAAM,WAAW,GAAG,CACvB,aAAqB,EACsE,EAAE,CAAC,CAAC;IAC/F,aAAa,EAAE,CAAC;IAChB,KAAK,EAAE,UAAU;IACjB,OAAO,EAAE,GAAG,aAAa,GAAG;IAC5B,KAAK,EAAE,UAAU,CAAC,aAAa,CAAC;IAChC,SAAS,EAAE,QAAQ;CACtB,CAAC,CAAC"}
package/dist/index.d.ts CHANGED
@@ -1,9 +1,12 @@
1
1
  /**
2
2
  * Public entrypoint for @browsercore/dev.
3
3
  *
4
- * Re-exports the convenience helpers; consumers normally import the subpath
4
+ * Re-exports the convenience helpers. Consumers normally import the subpath
5
5
  * directly (`@browsercore/dev/vitest`, `@browsercore/dev/oxlint`), but the root
6
6
  * export is here for `import { definePackageConfig, oxlintBase } from "@browsercore/dev"`.
7
+ *
8
+ * @module
9
+ * @since 0.1.0
7
10
  */
8
11
  export { definePackageConfig } from "./vitest.js";
9
12
  export { default as oxlintBase } from "./oxlint.js";
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,OAAO,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAC;AAClD,OAAO,EAAE,OAAO,IAAI,UAAU,EAAE,MAAM,aAAa,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAC;AAClD,OAAO,EAAE,OAAO,IAAI,UAAU,EAAE,MAAM,aAAa,CAAC"}
package/dist/index.js CHANGED
@@ -1,9 +1,12 @@
1
1
  /**
2
2
  * Public entrypoint for @browsercore/dev.
3
3
  *
4
- * Re-exports the convenience helpers; consumers normally import the subpath
4
+ * Re-exports the convenience helpers. Consumers normally import the subpath
5
5
  * directly (`@browsercore/dev/vitest`, `@browsercore/dev/oxlint`), but the root
6
6
  * export is here for `import { definePackageConfig, oxlintBase } from "@browsercore/dev"`.
7
+ *
8
+ * @module
9
+ * @since 0.1.0
7
10
  */
8
11
  export { definePackageConfig } from "./vitest.js";
9
12
  export { default as oxlintBase } from "./oxlint.js";
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,OAAO,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAC;AAClD,OAAO,EAAE,OAAO,IAAI,UAAU,EAAE,MAAM,aAAa,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAC;AAClD,OAAO,EAAE,OAAO,IAAI,UAAU,EAAE,MAAM,aAAa,CAAC"}
package/dist/oxlint.d.ts CHANGED
@@ -2,18 +2,28 @@ import type { OxlintConfig } from "oxlint";
2
2
  /**
3
3
  * Base oxlint config shared by every @browsercore/* package.
4
4
  *
5
- * Consumers extend it in an `oxlint.config.ts` (which replaces `.oxlintrc.json`):
5
+ * Consumers extend it in an `oxlint.config.ts` (which replaces `.oxlintrc.json`).
6
6
  *
7
+ * @remarks
8
+ * Why a TS import rather than `.oxlintrc.json` `extends`: oxlint's JSON
9
+ * `extends` resolves only relative file paths, not `node_modules` (see
10
+ * oxc-project/oxc#15538). The `oxlint.config.ts` form imports the config object
11
+ * directly, which does resolve through `node_modules`.
12
+ *
13
+ * @example
7
14
  * ```ts
15
+ * // oxlint.config.ts in a @browsercore/* package
8
16
  * import { defineConfig } from "oxlint";
9
17
  * import base from "@browsercore/dev/oxlint";
10
18
  * export default defineConfig({ extends: [base] });
11
19
  * ```
12
20
  *
13
- * Why a TS import rather than `.oxlintrc.json` `extends`: oxlint's JSON
14
- * `extends` resolves only relative file paths, not `node_modules` (see
15
- * oxc-project/oxc#15538). The `oxlint.config.ts` form imports the config object
16
- * directly, which does resolve through `node_modules`.
21
+ * @defaultValue
22
+ * Enables `typescript`, `unicorn`, `import`, `promise`, and `node` plugins with
23
+ * `correctness`, `suspicious`, and `pedantic` set to `"error"`.
24
+ *
25
+ * @see {@link https://oxc.rs/docs/guide/linting/ oxlint documentation}
26
+ * @since 0.1.0
17
27
  */
18
28
  declare const base: OxlintConfig;
19
29
  export default base;
@@ -1 +1 @@
1
- {"version":3,"file":"oxlint.d.ts","sourceRoot":"","sources":["../src/oxlint.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAC;AAE3C;;;;;;;;;;;;;;;GAeG;AACH,QAAA,MAAM,IAAI,EAAE,YAwDX,CAAC;eAEa,IAAI"}
1
+ {"version":3,"file":"oxlint.d.ts","sourceRoot":"","sources":["../src/oxlint.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAC;AAE3C;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,QAAA,MAAM,IAAI,EAAE,YAwDX,CAAC;eAEa,IAAI"}
package/dist/oxlint.js CHANGED
@@ -1,18 +1,28 @@
1
1
  /**
2
2
  * Base oxlint config shared by every @browsercore/* package.
3
3
  *
4
- * Consumers extend it in an `oxlint.config.ts` (which replaces `.oxlintrc.json`):
4
+ * Consumers extend it in an `oxlint.config.ts` (which replaces `.oxlintrc.json`).
5
5
  *
6
+ * @remarks
7
+ * Why a TS import rather than `.oxlintrc.json` `extends`: oxlint's JSON
8
+ * `extends` resolves only relative file paths, not `node_modules` (see
9
+ * oxc-project/oxc#15538). The `oxlint.config.ts` form imports the config object
10
+ * directly, which does resolve through `node_modules`.
11
+ *
12
+ * @example
6
13
  * ```ts
14
+ * // oxlint.config.ts in a @browsercore/* package
7
15
  * import { defineConfig } from "oxlint";
8
16
  * import base from "@browsercore/dev/oxlint";
9
17
  * export default defineConfig({ extends: [base] });
10
18
  * ```
11
19
  *
12
- * Why a TS import rather than `.oxlintrc.json` `extends`: oxlint's JSON
13
- * `extends` resolves only relative file paths, not `node_modules` (see
14
- * oxc-project/oxc#15538). The `oxlint.config.ts` form imports the config object
15
- * directly, which does resolve through `node_modules`.
20
+ * @defaultValue
21
+ * Enables `typescript`, `unicorn`, `import`, `promise`, and `node` plugins with
22
+ * `correctness`, `suspicious`, and `pedantic` set to `"error"`.
23
+ *
24
+ * @see {@link https://oxc.rs/docs/guide/linting/ oxlint documentation}
25
+ * @since 0.1.0
16
26
  */
17
27
  const base = {
18
28
  plugins: ["typescript", "unicorn", "import", "promise", "node"],
@@ -1 +1 @@
1
- {"version":3,"file":"oxlint.js","sourceRoot":"","sources":["../src/oxlint.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;;;;;;GAeG;AACH,MAAM,IAAI,GA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E,OAAO;QACpC,iCAAiC,EAAE,OAAO;QAC1C,yBAAyB,EAAE,KAAK;QAChC,yBAAyB,EAAE,OAAO;QAClC,uBAAuB,EAAE,KAAK;QAC9B,0EAA0E;QAC1E,oEAAoE;QACpE,6BAA6B,EAAE,KAAK;QACpC,oBAAoB,EAAE,KAAK;QAC3B,WAAW,EAAE,KAAK;QAClB,wBAAwB,EAAE,KAAK;QAC/B,iBAAiB,EAAE,OAAO;QAC1B,sBAAsB,EAAE,OAAO;QAC/B,uBAAuB,EAAE,OAAO;QAChC,wBAAwB,EAAE,OAAO;QACjC,oBAAoB,EAAE,MAAM;QAC5B,qCAAqC,EAAE,KAAK;QAC5C,0CAA0C,EAAE,KAAK;QACjD,sBAAsB,EAAE,KAAK;QAC7B,iCAAiC,EAAE,KAAK;KAC3C;IACD,cAAc,EAAE,CAAC,MAAM,EAAE,UAAU,EAAE,cAAc,EAAE,aAAa,CAAC;CACtE,CAAC;AAEF,eAAe,IAAI,CAAC"}
package/dist/vitest.d.ts CHANGED
@@ -1,8 +1,23 @@
1
+ /**
2
+ * Options for configuring a package's vitest setup.
3
+ *
4
+ * @since 0.1.0
5
+ */
1
6
  type PackageOptions = {
7
+ /** Display name for the test run (shown in reporters). */
2
8
  name: string;
3
- /** Test files to run; defaults to the `tests/` directory. */
9
+ /**
10
+ * Test files to run.
11
+ *
12
+ * @defaultValue <code>["tests&#47;**&#47;*.test.ts"]</code>
13
+ */
4
14
  include?: string[];
5
- /** Overrides merged into the `coverage` block (e.g. extra `exclude`). */
15
+ /**
16
+ * Overrides merged into the <code>coverage</code> block.
17
+ *
18
+ * Use this to add extra <code>exclude</code> patterns — they are appended to the
19
+ * default excludes (<code>**&#47;index.ts</code>, <code>tests&#47;**</code>, <code>node_modules&#47;**</code>).
20
+ */
6
21
  coverage?: {
7
22
  exclude?: string[];
8
23
  [key: string]: unknown;
@@ -16,12 +31,29 @@ type PackageOptions = {
16
31
  * `json-summary` — the last is what the coverage gate reads), the same v8
17
32
  * coverage over `src/` (all `.ts` files), the same 30s timeouts, and `globals: false`.
18
33
  *
19
- * Consumers opt in with just their name:
34
+ * @param options Configuration options for the package.
35
+ * @param options.name Display name for the test run.
36
+ * @param options.include Glob patterns for test files.
37
+ * @param options.coverage Optional coverage overrides.
38
+ * @returns A fully-formed vitest config object.
20
39
  *
40
+ * @example
21
41
  * ```ts
42
+ * // vitest.config.ts in a @browsercore/* package
22
43
  * import { definePackageConfig } from "@browsercore/dev/vitest";
23
44
  * export default definePackageConfig({ name: "crypto" });
24
45
  * ```
46
+ *
47
+ * @example
48
+ * ```ts
49
+ * // With custom coverage excludes
50
+ * export default definePackageConfig({
51
+ * name: "tls",
52
+ * coverage: { exclude: ["**&#47;handshake-driver.ts"] }
53
+ * });
54
+ * ```
55
+ *
56
+ * @since 0.1.0
25
57
  */
26
58
  export declare function definePackageConfig(options: PackageOptions): import("vite").UserConfig;
27
59
  export {};
@@ -1 +1 @@
1
- {"version":3,"file":"vitest.d.ts","sourceRoot":"","sources":["../src/vitest.ts"],"names":[],"mappings":"AAEA,KAAK,cAAc,GAAG;IAClB,IAAI,EAAE,MAAM,CAAC;IACb,6DAA6D;IAC7D,OAAO,CAAC,EAAE,MAAM,EAAE,CAAC;IACnB,yEAAyE;IACzE,QAAQ,CAAC,EAAE;QACP,OAAO,CAAC,EAAE,MAAM,EAAE,CAAC;QACnB,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;KAC1B,CAAC;CACL,CAAC;AAEF;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,mBAAmB,CAAC,OAAO,EAAE,cAAc,6BA8B1D"}
1
+ {"version":3,"file":"vitest.d.ts","sourceRoot":"","sources":["../src/vitest.ts"],"names":[],"mappings":"AAEA;;;;GAIG;AACH,KAAK,cAAc,GAAG;IAClB,0DAA0D;IAC1D,IAAI,EAAE,MAAM,CAAC;IACb;;;;OAIG;IACH,OAAO,CAAC,EAAE,MAAM,EAAE,CAAC;IACnB;;;;;OAKG;IACH,QAAQ,CAAC,EAAE;QACP,OAAO,CAAC,EAAE,MAAM,EAAE,CAAC;QACnB,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;KAC1B,CAAC;CACL,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AACH,wBAAgB,mBAAmB,CAAC,OAAO,EAAE,cAAc,6BA8B1D"}
package/dist/vitest.js CHANGED
@@ -7,12 +7,29 @@ import { defineConfig } from "vitest/config";
7
7
  * `json-summary` — the last is what the coverage gate reads), the same v8
8
8
  * coverage over `src/` (all `.ts` files), the same 30s timeouts, and `globals: false`.
9
9
  *
10
- * Consumers opt in with just their name:
10
+ * @param options Configuration options for the package.
11
+ * @param options.name Display name for the test run.
12
+ * @param options.include Glob patterns for test files.
13
+ * @param options.coverage Optional coverage overrides.
14
+ * @returns A fully-formed vitest config object.
11
15
  *
16
+ * @example
12
17
  * ```ts
18
+ * // vitest.config.ts in a @browsercore/* package
13
19
  * import { definePackageConfig } from "@browsercore/dev/vitest";
14
20
  * export default definePackageConfig({ name: "crypto" });
15
21
  * ```
22
+ *
23
+ * @example
24
+ * ```ts
25
+ * // With custom coverage excludes
26
+ * export default definePackageConfig({
27
+ * name: "tls",
28
+ * coverage: { exclude: ["**&#47;handshake-driver.ts"] }
29
+ * });
30
+ * ```
31
+ *
32
+ * @since 0.1.0
16
33
  */
17
34
  export function definePackageConfig(options) {
18
35
  return defineConfig({
@@ -29,7 +46,7 @@ export function definePackageConfig(options) {
29
46
  include: ["src/**/*.ts"],
30
47
  reporter: ["text", "html", "json-summary"],
31
48
  // Pure-reexport entrypoints can't be observed by V8's coverage
32
- // instrumentation: `export { … } from` compiles to no executable
49
+ // instrumentation: 'export { … } from' compiles to no executable
33
50
  // lines, so a file that only re-exports reports 0% even when every
34
51
  // re-exported symbol is exercised by tests. The symbols remain
35
52
  // fully covered at their origin modules. Append (don't replace)
@@ -1 +1 @@
1
- {"version":3,"file":"vitest.js","sourceRoot":"","sources":["../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E,MAAM;YACnB,OAAO,EAAE,KAAK;YACd,WAAW,EAAE,MAAM;YACnB,WAAW,EAAE,MAAM;YACnB,QAAQ,EAAE;gBACN,QAAQ,EAAE,IAAI;gBACd,OAAO,EAAE,CAAC,aAAa,CAAC;gBACxB,QAAQ,EAAE,CAAC,MAAM,EAAE,MAAM,EAAE,cAAc,CAAC;gBAC1C,+DAA+D;gBAC/D,iEAAiE;gBACjE,mEAAmE;gBACnE,+DAA+D;gBAC/D,gEAAgE;gBAChE,4DAA4D;gBAC5D,GAAG,OAAO,CAAC,QAAQ;gBACnB,OAAO,EAAE;oBACL,aAAa;oBACb,UAAU;oBACV,iBAAiB;oBACjB,GAAG,CAAC,OAAO,CAAC,QAAQ,EAAE,OAAO,IAAI,EAAE,CAAC;iBACvC;aACJ;SACJ;KACJ,CAAC,CAAC;AACP,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@browsercore/dev",
3
- "version": "0.2.0",
3
+ "version": "0.2.1",
4
4
  "description": "Shared build, lint, test, and coverage tooling for the @browsercore/* packages.",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -52,7 +52,17 @@
52
52
  "test": "vitest run",
53
53
  "lint": "oxlint --type-aware src/",
54
54
  "clean": "rm -rf dist coverage",
55
- "prepublishOnly": "npm run clean && npm run build"
55
+ "prepublishOnly": "npm run clean && npm run build",
56
+ "graph": "npx tsx scripts/resolve-graph.ts",
57
+ "memory:brief": "npx tsx scripts/memory-session.ts brief",
58
+ "memory:search": "npx tsx scripts/memory-query.ts search",
59
+ "memory:questions": "npx tsx scripts/memory-query.ts questions",
60
+ "memory:facts": "npx tsx scripts/memory-query.ts facts"
61
+ },
62
+ "dependencies": {
63
+ "@tursodatabase/database": "^0.2.0",
64
+ "@xenova/transformers": "^2.17.2",
65
+ "zod": "^4.4.3"
56
66
  },
57
67
  "peerDependencies": {
58
68
  "oxlint": "^1.76.0",
@@ -1,205 +0,0 @@
1
- # TypeScript Coding Standards
2
-
3
- These rules are the standard for this codebase and **every** sub-package. Every PR,
4
- every AI-generated snippet, and every hand-written file follows them. They exist so
5
- the intended behavior lives in the types — never in tribal knowledge or hidden assumptions.
6
-
7
- > Design for AI modification: before committing, ask *"Could another developer or an
8
- > LLM understand the intended behavior without asking me?"* If not — add types, split
9
- > functions, clarify states, rename.
10
-
11
- ---
12
-
13
- ## 1. Strict compiler — never relax it
14
-
15
- Every `tsconfig.json` inherits `tsconfig.base.json`, which carries:
16
-
17
- ```json
18
- {
19
- "strict": true,
20
- "noUncheckedIndexedAccess": true,
21
- "exactOptionalPropertyTypes": true
22
- }
23
- ```
24
-
25
- - `noUncheckedIndexedAccess` → `arr[i]` is `T | undefined`.
26
- - `exactOptionalPropertyTypes` → `?` means absent-or-present, not present-and-undefined.
27
-
28
- Ambiguity creates bugs and forces LLMs to guess. **Never** override these to `false`
29
- in a sub-package to dodge an error. Fix the error instead.
30
-
31
- ## 2. Every important data structure has a type
32
-
33
- If data crosses a module boundary, it has an explicit type. No anonymous object
34
- literals escaping a function.
35
-
36
- ```ts
37
- // Bad
38
- const frame = { type: 0x1, streamId: 3, data: buf };
39
-
40
- // Good
41
- interface HeadersFrame {
42
- readonly type: FrameType.HEADERS;
43
- readonly streamId: StreamId;
44
- readonly data: Uint8Array;
45
- }
46
- ```
47
-
48
- ## 3. Never `any`
49
-
50
- Unknown external data is `unknown`, then validated. `any` is a build failure.
51
-
52
- ```ts
53
- function parseFrame(raw: Uint8Array): Frame {
54
- const unknown = decodeUnknown(raw); // unknown
55
- return FrameSchema.parse(unknown); // validated → typed
56
- }
57
- ```
58
-
59
- ## 4. Interfaces for domain objects, type aliases for states/constraints
60
-
61
- - Interfaces for real entities (`TlsConnection`, `Http2Stream`, `Cookie`).
62
- - Type aliases for states/constraints (`RunStatus`, `CipherSuite`).
63
- - If values come from a known set, encode the set — never bare `string`.
64
-
65
- ## 5. Model states explicitly — make invalid states unrepresentable
66
-
67
- No "state via nullable-field combos." Use discriminated unions.
68
-
69
- ```ts
70
- // Bad — allows { state: "open", error: "failed" }
71
- interface Connection {
72
- state: string;
73
- stream?: Stream;
74
- error?: string;
75
- }
76
-
77
- // Good
78
- type ConnectionState =
79
- | { readonly state: "connecting" }
80
- | { readonly state: "open"; readonly stream: Stream }
81
- | { readonly state: "closed"; readonly reason: CloseReason };
82
- ```
83
-
84
- ## 6. Discriminated unions for every workflow/state
85
-
86
- The compiler + LLM reason about every case.
87
-
88
- ## 7. Functions declare input AND output types
89
-
90
- Public functions always define both sides — no inference-only signatures on exported APIs.
91
-
92
- ## 8. One function = one decision
93
-
94
- No `processHandshake()` that validates + persists + schedules + notifies. Split:
95
- `validate…`, `decodeStep`, `actuate`, `recordStep`.
96
-
97
- ## 9. No hidden behavior
98
-
99
- A function named `updateSettings` does not also flush a log. Every side effect is its
100
- own named call.
101
-
102
- ## 10. Name things explicitly
103
-
104
- `cipherSuite`, `observedRank`, `clientHello` — never `data`, `result`, `obj`.
105
- The name is the documentation.
106
-
107
- ## 11. Prefer immutable data + `readonly`
108
-
109
- ```ts
110
- const next = { ...prev, cipherSuite } as const;
111
- interface Connection { readonly id: ConnectionId; }
112
- ```
113
-
114
- No in-place mutation of shared state. `const` over `let`.
115
-
116
- ## 12. Validate external data immediately
117
-
118
- Everything from outside the boundary is `unknown`: sockets, files, captures, configs.
119
- Use **Zod** at every boundary:
120
-
121
- ```ts
122
- const frame = FrameSchema.parse(raw); // never `raw as Frame`
123
- ```
124
-
125
- ## 13. Types are contracts, not documentation
126
-
127
- ```ts
128
- // Bad // user id
129
- // id: string;
130
- // Good
131
- type UserId = string & { __brand: "UserId" };
132
- ```
133
-
134
- ## 14. Branded/opaque ID types — load-bearing
135
-
136
- Don't use bare `number`/`string` for IDs. This kills the "pass an X where a Y belongs"
137
- class of bug. The project uses these brands (defined per-package, see `types.ts`):
138
-
139
- ```ts
140
- type ConnectionId = string & { __brand: "ConnectionId" };
141
- type StreamId = number & { __brand: "StreamId" };
142
- type SessionId = string & { __brand: "SessionId" };
143
- ```
144
-
145
- ## 15. Exhaustive switches
146
-
147
- Every `switch` over a union hits `default: assertNever(x)`. Adding a state forces every
148
- handler to compile-error until handled.
149
-
150
- ```ts
151
- function assertNever(x: never): never {
152
- throw new Error(`Unexpected value: ${JSON.stringify(x)}`);
153
- }
154
- ```
155
-
156
- ## 16. Explicit, typed errors
157
-
158
- ```ts
159
- // Bad
160
- throw new Error("handshake failed");
161
- // Good
162
- throw new TlsHandshakeError("server_hello_parse", cause);
163
- ```
164
-
165
- Errors are part of the API. Define them in each package's `errors.ts`.
166
-
167
- ## 17. No magic strings
168
-
169
- `if (event === Event.COLD_START)` or a string-literal union — never bare `"cold_start"`.
170
-
171
- ## 18. Clear dependency boundaries
172
-
173
- Domain (pure protocol logic) knows nothing of AWS / HTTP / DDB / sockets. Infrastructure
174
- adapts. The protocol state machines stay I/O-free so they're unit-testable.
175
-
176
- **Within this repo**, the dependency graph flows upward only — never sideways or downward:
177
-
178
- ```
179
- @browsercore/fetch
180
- └─ @browsercore/http2 @browsercore/http1 @browsercore/cookies @browsercore/profiles
181
- └─ @browsercore/tls
182
- └─ @browsercore/crypto @browsercore/transport
183
- └─ node:net / node:crypto
184
- ```
185
-
186
- A package may only import from packages *below* it in this graph.
187
-
188
- ## 19. Documentation: why, not what
189
-
190
- Comments explain *why* ("crawl past our position so the competitor snapshot covers the
191
- neighborhood"), never *what* the code obviously does. Priority: Types > Names > Structure >
192
- Comments.
193
-
194
- ## 20. API contracts in one place
195
-
196
- Domain types live in each package's `types.ts`; wire schemas in `schemas.ts`. One source
197
- of truth, never duplicated shapes.
198
-
199
- ---
200
-
201
- ## The Golden Rule
202
-
203
- Every piece of important information exists as one of: **a type, a function signature,
204
- an explicit state model, a schema validation, or clear naming.** Never rely on tribal
205
- knowledge or hidden assumptions.