@oddstate/core 0.1.0 → 0.2.0

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,103 +1,111 @@
1
1
  # Oddstate core
2
2
 
3
- `@oddstate/core` is an ESM library that provides synchronous access to a snapshot
4
- of the Oddstate corpus. It requires Node.js 24 or newer for Node consumers.
5
- Build it from the repository root with `pnpm --filter @oddstate/core build`.
3
+ Use `@oddstate/core` when you want Oddstate’s case records or fixture data in
4
+ JavaScript or TypeScript. The library reads from a bundled snapshot. Lookups are
5
+ synchronous and work offline.
6
+
7
+ Browse the cases and guides on the [Oddstate website](https://oddstate.dev).
8
+
9
+ Install it in a Node.js 24+ project that uses ES modules.
10
+
11
+ ```sh
12
+ npm install @oddstate/core
13
+ ```
14
+
15
+ ## From a question to a test input
16
+
17
+ A search returns short summaries. Open a case for the explanation, the evidence
18
+ from its recorded run, and the list of fixtures you can reuse.
6
19
 
7
20
  ```ts
8
21
  import { getCase, getFixture, searchCases } from "@oddstate/core";
9
22
 
10
23
  const results = searchCases("date UTC", { category: "dates-and-times" });
11
- const edgeCase = getCase("date-only-utc");
12
- const evidence = edgeCase?.verification.evidence;
13
- const fixture = getFixture("date-only-utc", "date-inputs");
24
+ const example = getCase("date-only-utc");
25
+ const evidence = example?.verification.evidence;
26
+ const input = getFixture("date-only-utc", "date-inputs");
14
27
  ```
15
28
 
16
- ## API
29
+ If a lookup returns `undefined`, check the case or fixture ID. IDs are exact
30
+ and case-sensitive. The fixture’s `file` field gives its original filename.
31
+ Its `content` is a string for JSON and text, with the original whitespace
32
+ preserved. Binary fixtures return a `Uint8Array`. Each call gives you results
33
+ you can modify independently.
34
+
35
+ ## API at a glance
17
36
 
18
- | Function | Result |
19
- | ------------------------------- | --------------------------------------------------------------- |
20
- | `getCase(id)` | Full case metadata and `markdown`, or `undefined`. |
21
- | `listCategories()` | Categories in registry order. |
22
- | `listCases(filters?)` | Case summaries ordered by ID. |
23
- | `searchCases(query, filters?)` | Case summaries in relevance order. |
24
- | `getRelatedCases(id)` | Directly related case summaries in the declared order, or `[]`. |
25
- | `getFixture(caseId, fixtureId)` | A fixture descriptor with its `content`, or `undefined`. |
37
+ | Function | What it returns |
38
+ | ------------------------------- | ----------------------------------------------------------------- |
39
+ | `listCategories()` | Categories in registry order. |
40
+ | `listCases(filters?)` | Summaries in case ID order. |
41
+ | `searchCases(query, filters?)` | Summaries in relevance order. |
42
+ | `getCase(id)` | Case metadata and Markdown, or `undefined`. |
43
+ | `getRelatedCases(id)` | Directly related summaries in the case’s declared order, or `[]`. |
44
+ | `getFixture(caseId, fixtureId)` | The fixture descriptor and its content, or `undefined`. |
26
45
 
27
- Summaries include `id`, `title`, `summary` and `category`. Use the full case for
28
- references, fixture descriptors, compatibility prerequisites and recorded
29
- verification evidence. Case and fixture IDs are exact and case-sensitive. A
30
- fixture's `file` is its original filename. JSON and text fixture contents are
31
- strings with the original whitespace. Binary fixtures return `Uint8Array`.
32
- Results can be modified independently of subsequent calls.
46
+ A summary includes `id`, `title`, `summary`, and `category`. The full case
47
+ adds references, related cases, compatibility, and verification evidence.
33
48
 
34
- `listCases` and `searchCases` accept `category` and `nodeMajor` filters and apply
35
- both when supplied. `nodeMajor` selects cases whose supported verification
36
- floor is at or below the supplied major. `verification.evidence` identifies
37
- the Node version and environment of the recorded run. A `nodeMajor` outside
38
- the positive safe integer range throws `RangeError`. An unknown category yields
39
- an empty list.
49
+ `listCases` and `searchCases` accept both `category` and `nodeMajor`. The Node
50
+ filter includes cases whose minimum verification major is at or below the
51
+ requested major. Check `verification.evidence` for the exact Node version and
52
+ environment used in the recorded run. An unknown category returns `[]`.
53
+ A `nodeMajor` value outside the positive safe integer range throws a
54
+ `RangeError`.
40
55
 
41
- ## Search
56
+ ## Search in a browser
42
57
 
43
- Use the browser-focused entry point when you only need search.
58
+ Import the search entry point when your UI only needs to show matching cases.
59
+ It bundles summaries and search terms. Full explanations, evidence, and
60
+ fixture bytes are available through the main entry point.
44
61
 
45
62
  ```ts
46
63
  import { searchCases } from "@oddstate/core/search";
47
64
 
48
- const results = searchCases("date UTC", { category: "dates-and-times" });
65
+ const results = searchCases("TextDecoder split chunks");
49
66
  ```
50
67
 
51
- This entry loads case summaries, the Node major filter and generated search
52
- terms. Whole case records, Markdown source, verification evidence and fixture
53
- payloads stay in the full core entry. The full entry builds its search index on
54
- the first search.
55
-
56
- Search first looks for every distinct query word across the case ID, title,
57
- summary, Markdown and fixture IDs. It compares lowercase, NFC-normalised
58
- whole words. Punctuation separates words, with code points such as `U+FFFD`
59
- kept together. The strongest field for each word contributes 3 points for the
60
- case ID or title, 2 for the summary, and 1 for Markdown or a fixture ID.
61
-
62
- When no case matches exactly within the selected filters, search drops common
63
- question and connecting words and folds simple plurals and common spellings
64
- such as `normalization` and `normalisation`. A partial result may miss one
65
- word if at least two words match and one appears in a case ID, title or
66
- summary. Results are ordered by the number of matched words, then field
67
- score, then ascending case ID. A query without searchable words or matches
68
- returns `[]`. Search does not use fuzzy spelling correction or semantic
69
- matching.
70
-
71
- ## Build and package boundaries
72
-
73
- The build uses the repository's existing loader and verifier to check every
74
- case in the current environment before generating the JavaScript snapshots in
75
- `dist`. The snapshots carry forward the evidence stored in case metadata.
76
- Full core embeds Markdown, original JSON and text, and base64-encoded binary
77
- bytes. Runtime imports stay inside the built package and work independently of
78
- the application's directory and framework.
79
- The library targets ES2022 and uses the standard `structuredClone` and `atob`
80
- APIs. The package includes its own TypeScript declarations for both entry
81
- points and has no runtime dependencies.
82
-
83
- `pnpm --filter @oddstate/core test` builds the package, type-checks consumers
84
- against its exported declarations, and exercises the distribution through its
85
- package entry point. The workspace release smoke test installs the actual
86
- tarballs in a fresh npm project and checks strict TypeScript consumers.
87
-
88
- ## Browser bundle measurement
89
-
90
- Build core, then run `node scripts/measure-search-bundle.mts` from the workspace
91
- root. The script compares the full and browser entries on two seeded synthetic
92
- corpora using the installed Webpack and SWC versions. It runs both generated
93
- bundles without Node globals and compares their search results. To measure a
94
- previous implementation, pass `--before-dist <path>` with its built core
95
- directory.
96
-
97
- | Cases | Binary bytes per case | Previous gzip bytes | Browser entry gzip bytes |
98
- | ----: | --------------------: | ------------------: | -----------------------: |
99
- | 3,000 | 1,024 | 3,281,129 | 91,862 |
100
- | 1,000 | 16,384 | 17,381,848 | 33,442 |
101
-
102
- Measurements used the pre-hardening core, Webpack 5.98.0 and Next's bundled SWC
103
- on Node 24.22.3. They measure bundle size and result equivalence in a JS context.
68
+ Search looks for each distinct query word in the case ID, title, summary,
69
+ Markdown, and fixture IDs. It compares lowercase, NFC-normalized whole words.
70
+ Punctuation separates words, with code points like `U+FFFD` kept together.
71
+ For each word, the strongest field wins. IDs and titles score 3 points,
72
+ summaries 2, and Markdown and fixture IDs 1.
73
+
74
+ If there are no exact matches within the filters, search drops common
75
+ connecting words and folds simple plurals and spelling variants. A partial
76
+ match can miss one word when at least two words match and one appears in the
77
+ ID, title, or summary. Results sort by matched words, then score, then case ID.
78
+ Empty or unmatched queries return `[]`.
79
+
80
+ ## Build and verify from a checkout
81
+
82
+ Run these commands from the repository root.
83
+
84
+ ```sh
85
+ pnpm --filter @oddstate/core build
86
+ pnpm --filter @oddstate/core test
87
+ ```
88
+
89
+ The build verifies the corpus and generates the snapshots in `dist/`.
90
+ Those snapshots retain the evidence recorded in the case metadata. Both
91
+ entry points ship TypeScript declarations and use standard ES2022 APIs.
92
+ The package has zero runtime dependencies.
93
+
94
+ The package tests exercise the built entry points. The release smoke test
95
+ installs the actual tarballs in a fresh npm project and checks strict
96
+ TypeScript consumers.
97
+
98
+ ### Measure the browser bundle
99
+
100
+ After building core, run `node scripts/measure-search-bundle.mts` from the
101
+ repository root. It bundles the full and search entries with two synthetic
102
+ corpora, runs them without Node globals, and compares their results. Pass
103
+ `--before-dist <path>` with an earlier build to compare bundle sizes.
104
+
105
+ | Cases | Binary bytes per case | Previous gzip bytes | Browser search gzip bytes |
106
+ | ----: | --------------------: | ------------------: | ------------------------: |
107
+ | 3,000 | 1,024 | 3,281,129 | 91,862 |
108
+ | 1,000 | 16,384 | 17,381,848 | 33,442 |
109
+
110
+ These measurements used the pre-hardening core, Webpack 5.98.0, Next’s
111
+ bundled SWC, and Node.js 24.22.3.