@oddstate/core 0.0.0-stage → 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/LICENSE +21 -0
- package/NOTICE.md +18 -0
- package/README.md +110 -2
- package/dist/corpus-data.d.ts +17 -0
- package/dist/corpus-data.js +2 -0
- package/dist/index.d.ts +49 -0
- package/dist/index.js +94 -0
- package/dist/search-data.d.ts +4 -0
- package/dist/search-data.js +2 -0
- package/dist/search-engine.d.ts +16 -0
- package/dist/search-engine.js +143 -0
- package/dist/search.d.ts +10 -0
- package/dist/search.js +17 -0
- package/dist/types.d.ts +45 -0
- package/dist/types.js +1 -0
- package/licenses/CC-BY-4.0.txt +396 -0
- package/licenses/CC0-1.0.txt +121 -0
- package/package.json +36 -3
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Oddstate contributors
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/NOTICE.md
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
# Oddstate licenses
|
|
2
|
+
|
|
3
|
+
- [MIT](LICENSE) covers original source code, reproducers, code examples,
|
|
4
|
+
development documentation and skill instructions and scripts.
|
|
5
|
+
- [CC BY 4.0](licenses/CC-BY-4.0.txt) covers original educational prose in corpus
|
|
6
|
+
cases, their descriptive metadata and guides. Attribute this material to
|
|
7
|
+
Oddstate contributors and link to the [project](https://github.com/IshitRaj/oddstate).
|
|
8
|
+
- [CC0 1.0](licenses/CC0-1.0.txt) applies to original reusable corpus fixtures.
|
|
9
|
+
|
|
10
|
+
Core and the agent skill include corpus material alongside MIT-licensed code.
|
|
11
|
+
The CLI package contains MIT-licensed code and obtains corpus material from
|
|
12
|
+
core. Citations identify external sources. Upstream material remains subject to its
|
|
13
|
+
own terms.
|
|
14
|
+
|
|
15
|
+
Geist and Geist Mono retain their upstream SIL Open Font License 1.1 notices in
|
|
16
|
+
the website's `apps/web/src/fonts` directory. Oddstate's names and marks,
|
|
17
|
+
website artwork, and third-party dependencies and assets are outside the
|
|
18
|
+
project license grants above. Dependencies retain their own license terms.
|
package/README.md
CHANGED
|
@@ -1,3 +1,111 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Oddstate core
|
|
2
2
|
|
|
3
|
-
|
|
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.
|
|
19
|
+
|
|
20
|
+
```ts
|
|
21
|
+
import { getCase, getFixture, searchCases } from "@oddstate/core";
|
|
22
|
+
|
|
23
|
+
const results = searchCases("date UTC", { category: "dates-and-times" });
|
|
24
|
+
const example = getCase("date-only-utc");
|
|
25
|
+
const evidence = example?.verification.evidence;
|
|
26
|
+
const input = getFixture("date-only-utc", "date-inputs");
|
|
27
|
+
```
|
|
28
|
+
|
|
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
|
|
36
|
+
|
|
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`. |
|
|
45
|
+
|
|
46
|
+
A summary includes `id`, `title`, `summary`, and `category`. The full case
|
|
47
|
+
adds references, related cases, compatibility, and verification evidence.
|
|
48
|
+
|
|
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`.
|
|
55
|
+
|
|
56
|
+
## Search in a browser
|
|
57
|
+
|
|
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.
|
|
61
|
+
|
|
62
|
+
```ts
|
|
63
|
+
import { searchCases } from "@oddstate/core/search";
|
|
64
|
+
|
|
65
|
+
const results = searchCases("TextDecoder split chunks");
|
|
66
|
+
```
|
|
67
|
+
|
|
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.
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { CaseMetadata, Category } from "./types.js";
|
|
2
|
+
|
|
3
|
+
export interface CaseSnapshot {
|
|
4
|
+
metadata: CaseMetadata;
|
|
5
|
+
markdown: string;
|
|
6
|
+
// Binary fixture entries contain base64. JSON and text entries contain source text.
|
|
7
|
+
fixtureContents: Record<string, string>;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export interface CorpusSnapshot {
|
|
11
|
+
categories: Category[];
|
|
12
|
+
// The loader produces global ID order, regardless of category directory order.
|
|
13
|
+
cases: CaseSnapshot[];
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
// The repository build script writes the JavaScript module into dist.
|
|
17
|
+
export const corpus: CorpusSnapshot;
|