@metacensus/library-research 0.13.0 → 0.15.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.
Files changed (46) hide show
  1. package/README.md +43 -11
  2. package/dist/commands/add.js +29 -12
  3. package/dist/commands/check.js +1 -1
  4. package/dist/commands/dev.js +24 -13
  5. package/dist/commands/reshape.d.ts +2 -0
  6. package/dist/commands/reshape.js +21 -0
  7. package/dist/context.d.ts +3 -1
  8. package/dist/context.js +2 -0
  9. package/dist/corpus.d.ts +432 -0
  10. package/dist/corpus.js +348 -0
  11. package/dist/data.d.ts +16 -12
  12. package/dist/data.js +38 -26
  13. package/dist/datasets.d.ts +8 -0
  14. package/dist/{roles.js → datasets.js} +35 -29
  15. package/dist/dev/host.d.ts +7 -1
  16. package/dist/dev/host.js +15 -13
  17. package/dist/host.d.ts +3 -1
  18. package/dist/host.js +6 -2
  19. package/dist/index.d.ts +3 -2
  20. package/dist/index.js +2 -1
  21. package/dist/mount.d.ts +7 -3
  22. package/dist/mount.js +7 -7
  23. package/dist/papers.js +3 -2
  24. package/dist/playwright.d.ts +1 -1
  25. package/dist/playwright.js +24 -6
  26. package/dist/project-id.d.ts +4 -0
  27. package/dist/project-id.js +7 -0
  28. package/dist/react.d.ts +18 -18
  29. package/dist/react.js +60 -37
  30. package/dist/reader.d.ts +18 -4
  31. package/dist/reader.js +25 -2
  32. package/dist/schema.d.ts +10 -35
  33. package/dist/schema.js +57 -34
  34. package/dist/testing.d.ts +11 -6
  35. package/dist/testing.js +12 -10
  36. package/dist/types.d.ts +62 -13
  37. package/dist/vite-config.js +2 -12
  38. package/dist/vite.d.ts +10 -2
  39. package/dist/vite.js +71 -19
  40. package/dist/zod.d.ts +2 -0
  41. package/dist/zod.js +4 -0
  42. package/package.json +14 -14
  43. package/schema/corpus.schema.json +3949 -29
  44. package/schema/project-id.schema.json +6 -0
  45. package/schema/research.schema.json +33 -7
  46. package/dist/roles.d.ts +0 -7
package/README.md CHANGED
@@ -7,8 +7,8 @@ The research-project contract and its tools
7
7
  A project is this layout, each path fixed, which `npx @metacensus/library-research init` writes into an empty repository:
8
8
 
9
9
  ```
10
- research.json title, data roles and private roles
11
- corpus.json sha → paper
10
+ research.json title, datasets, private datasets, roles and test people
11
+ corpus.json works by DOI or citation key: CSL-JSON, editions, papers by sha
12
12
  papers/<sha>.<kind> through LFS
13
13
  ui/package.json depends on @metacensus/library-research, which brings @playwright/test; scripts dev, check and test
14
14
  ui/tsconfig.json extends @metacensus/library-research/tsconfig.json
@@ -25,31 +25,61 @@ From `ui/`:
25
25
  | --------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
26
26
  | `npm run dev -- [--reader NAME] [--port N]` | serves the project at `/<path>/` and `ui/local/`'s at `/local/<path>/`, live from the files, as reader `NAME` (else `local`) to a context that names none, under the host's CSP |
27
27
  | `npm run check` | gates the project, one line per failure, as a host's build does |
28
- | `npx playwright test` | runs `browser/` in Chromium on a dev server; a CSP or axe violation fails its spec unless `violations` lists it |
28
+ | `npx playwright test` | runs `browser/` in Chromium on a dev server; a CSP, WCAG 2.2, console-error or other-origin violation fails its spec unless `violations` lists it |
29
29
  | `npx library-research add <file> [--title T] [--citation C] [--open]` | adds a paper to `papers/` and `corpus.json` |
30
+ | `npx library-research reshape` | rewrites a legacy `corpus.json`, one sha per paper, as works under placeholder keys, and prints what waits on a person |
30
31
  | `npx library-research candidate` | runs `check`, then tags a clean `HEAD` on `origin/main` as `<id>-YYYY-MM-DD[.N]`, pushes it, and prints the service's `make pin` line |
31
32
 
32
33
  ## Rendering
33
34
 
34
35
  A project renders in the browser only: the host is one single-page app and each project is a route of it, with no static build. A project never calls React's `lazy()`, and `check` fails on it; the PDF reader and charting come from `@metacensus/library-ui`.
35
36
 
36
- ## Data roles
37
+ ## Datasets
37
38
 
38
- Each key of research.json's `data` is a role, and `ui/roles.ts` exports `roles`, one Zod schema per role over the role's whole value; a glob role's is a `z.record` keyed by what its wildcard matched. The UI parses with it and `check` fails, one line per record file, on data that does not. A role with no schema fails, and `corpus.json` is no role: library-research's `Corpus` parses it.
39
+ Each key of research.json's `data` is a dataset, and `ui/datasets.ts` exports `datasets`, one Zod schema per dataset over the dataset's whole value; a glob dataset's is a `z.record` keyed by what its wildcard matched. The UI parses with it and `check` fails, one line per record file, on data that does not. A dataset with no schema fails, and `corpus.json` is no dataset: library-research's `Corpus` parses it.
40
+
41
+ `defineProject` takes `datasets` as its third argument, and `useData('items')` and `useDatas(['items', 'decisions'])` return what each name's schema parses, with no parser at the call. A project registers the types by augmenting `Register` beside its `defineProject`:
42
+
43
+ ```ts
44
+ // ui/datasets.ts
45
+ export const roles = ['author', 'leader'] as const
46
+ export const datasets = { items: z.record(z.string(), Item) /* … */ }
47
+
48
+ // ui/index.tsx
49
+ declare module '@metacensus/library-research' {
50
+ interface Register {
51
+ datasets: typeof datasets
52
+ roles: (typeof roles)[number]
53
+ }
54
+ }
55
+ ```
56
+
57
+ An undeclared name or a wrong result type then fails to compile. `roles` is the tuple research.json's `roles` copies: `check` fails when they differ.
58
+
59
+ A glob in `data` is relative, holds no `..`, at most one `*` and none of `?[]{}()!`; the grammar is in `schema/research.schema.json`.
39
60
 
40
61
  ## Private data
41
62
 
42
- `research.json`'s `private` maps a role to a glob holding exactly one `*`, such as `{ "private": { "ask": "research_notes/coauthors/*/questions.json" } }`. What the `*` matches is the page key, and the build emits each match at `/projects/<id>/private/<page>/<role>.json`, never among the shared `data/` files. A host serves that path only to the people who hold the page. A page key matches `^[a-z0-9][a-z0-9-]*$` and a role is in `data` or `private`, not both; `check` fails otherwise, naming the role.
63
+ `research.json`'s `private` maps a dataset to a glob holding exactly one `*` and otherwise the `data` grammar, such as `{ "private": { "ask": "research_notes/coauthors/*/questions.json" } }`. What the `*` matches is the page key, and the build emits each match at `/projects/<id>/private/<page>/<dataset>.json`, never among the shared `data/` files. A host serves that path only to the people who hold the page. A page key matches `^[a-z0-9][a-z0-9-]*$` and a dataset is in `data` or `private`, not both; `check` fails otherwise, naming the dataset.
64
+
65
+ `usePrivate(dataset)` returns `{ page: parsed }` for the pages the host names for the person the project is viewed as: none, one or several, and a page not yet built is left out. `Object.values(usePrivate('ask'))` is that person's questions. The dataset's schema in `ui/datasets.ts` parses one page's file, and `load` returns the dataset as `{ page: parsed }`. A host's `private(dataset)` returns the page-to-URL map.
66
+
67
+ In `dev` and `testHost`, a reader holds the pages [`people`](#people) gives them, and `testHost`'s `private: { dataset: { page: json } }` holds each page's JSON.
43
68
 
44
- `usePrivate(role, parse)` returns `{ page: parsed }` for the pages the host names for the person the project is viewed as: none, one or several, and a page not yet built is left out. `Object.values(usePrivate('ask', parse))` is that person's questions. The role's schema in `ui/roles.ts` parses one page's file, and `load` returns the role as `{ page: parsed }`. A host's `private(role)` returns the page-to-URL map.
69
+ Node loads `ui/datasets.ts` by stripping its types: no `enum` or namespace, relative imports end in `.ts`, and `ui/package.json` says `"type": "module"`. Dev tooling reads a project's datasets through `load` from `@metacensus/library-research/datasets`, which takes the folder holding research.json and returns each dataset parsed, with `corpus`.
45
70
 
46
- In `dev` and `testHost`, `research.json`'s optional `people` maps a reader to their pages, as a project's `people` does in production's people.json: `{ "people": { "dan.hertz": ["hertz"] } }`. `dev --reader dan.hertz` holds `hertz`'s page and another page answers 403; a reader `people` omits holds the page named as them, so `dev --reader hertz` holds `hertz`. `testHost`'s `private: { role: { page: json } }` gives the reader their pages, and its `people` option takes `research.people`. Production ignores `people`.
71
+ ## People
47
72
 
48
- Node loads `ui/roles.ts` by stripping its types: no `enum` or namespace, relative imports end in `.ts`, and `ui/package.json` says `"type": "module"`. Dev tooling reads a project's roles through `load` from `@metacensus/library-research/roles`, which takes the folder holding research.json and returns each role parsed, with `corpus`.
73
+ `research.json`'s optional `roles` lists the roles a person of the project holds one of, each matching `^[a-z][a-z0-9-]*$`, none repeated: `{ "roles": ["author", "leader"] }`.
74
+
75
+ - `useReader()` returns the host's `reader`, the person the project is viewed as: `{ username, name, role, self }`. `role` is one of `roles` (`Register`'s union where the project declares it), or null in a project that declares none. `self` is false while the host views the project as a person other than the one signed in.
76
+ - `useMembers()` returns the host's `members`, every person of the project, each `{ username, name, role }`.
77
+
78
+ In `dev` and `testHost`, `research.json`'s optional `people` stands in for production's people.json: it maps a username to `{ name, role, pages }`, `role` and `pages` optional, as `{ "people": { "dan.hertz": { "name": "Hertz", "role": "author", "pages": ["hertz"] } } }`. Every entry is a member. `dev --reader dan.hertz` and `testHost`'s `reader: 'dan.hertz'` serve that person as `reader` with `self` true, holding `hertz`'s page; another page answers 403. In a project that declares `roles`, a reader `people` omits is refused, naming them: by `testHost`, by `dev` before it serves when `--reader` names them, and by a `dev` page read as them, the default `local` included; in one that declares none, such a reader is served with their username as `name`, no role and no pages, and is no member. `check` fails, naming the person, on a role not in `roles`, on a person with no role where the project declares roles, and on a person with a role where it declares none. Production ignores `people`.
49
79
 
50
80
  ## Routes
51
81
 
52
- A project default-exports `defineProject('<path>', routes)`: its first URL segment, matching `^[a-z0-9][a-z0-9-]*$` and not `projects`, `local` or `pdfjs` (dev and the host reserve them), and its routes created against the `parent` it is handed, a route at that path; the host owns the router. `Register` types the project's own links. A link names its path in full and passes `from="/<path>"`, so a wrong path fails to compile:
82
+ A project default-exports `defineProject('<path>', routes, datasets)`: its first URL segment, a project id matching `^[a-z0-9][a-z0-9-]*$` (`projectIdPattern` from `@metacensus/library-research/host`, and `schema/project-id.schema.json`) and not `projects`, `local` or `pdfjs` (dev and the host reserve them), and its routes created against the `parent` it is handed, a route at that path; the host owns the router. `Register` types the project's own links. A link names its path in full and passes `from="/<path>"`, so a wrong path fails to compile:
53
83
 
54
84
  ```tsx
55
85
  const dpyd = defineProject('dpyd', (parent) => [
@@ -66,6 +96,8 @@ declare module '@tanstack/react-router' {
66
96
 
67
97
  A host mounts each project with `mount(parent, project, options)` from `@metacensus/library-research/host`: it creates the route at the path the project names, with `options` as the route's options, adds the project's routes, and returns it. Two projects at one path are refused by TanStack's duplicate-route-id check, in development builds only.
68
98
 
99
+ A host builds with `research({ projects })` and `tailwind({ projects })` from `@metacensus/library-research/vite`, `projects` mapping each project's id to its directory: `plugins: [react(), research({ projects }), tailwind({ projects })]`. It builds with library-research's `tailwindcss` and `@tailwindcss/vite`, and carries neither of its own. The host's stylesheet opens with `@layer theme, base, mc, components, utilities;`, then `@import "tailwindcss";` and `@import "@metacensus/library-ui/theme.css";`; each project's `ui/` becomes a source of the stylesheet a module or `index.html` loads, not of one reached through a nested CSS `@import`. A project's stylesheets `@apply` Tailwind's and library-ui's utilities as they are.
100
+
69
101
  `options` takes `frame(useHost)`, spread in: it provides the `Host` that `useHost` returns, shows a resettable error and an announced loading state. A host sets no `defaultPendingComponent` or `defaultErrorComponent` on its router, which would override the frame's for a project's routes. A host serves `@metacensus/library-research/csp.json` as its Content-Security-Policy (directive → sources, adding its own origins and nonces) and `pdfAssets`, `/pdfjs/`, for `configurePdf({ assets })`.
70
102
 
71
103
  ## Saving
@@ -83,7 +115,7 @@ A project saves JSON documents through its host, as it reads data.
83
115
 
84
116
  ## Testing
85
117
 
86
- `testHost(project, { data, private, documents, reader, url, sessionLost })` from `@metacensus/library-research/testing` returns `{ element, router, documents }`: the project in the frame and mount a real host uses, at its path, `data` giving each role's JSON, `reader` the username (default `test`), `documents` the project's saved documents as `{ id: { body, writer? } }`, `url` the path below the project (default `/`). Render `element` with any DOM renderer; `router.state.location` says where the project navigated, and `documents()` what it saved. `init` scaffolds `ui/index.test.tsx` on vitest, jsdom and Testing Library, which a project installs itself.
118
+ `testHost(project, { data, private, documents, people, roles, reader, self, url, sessionLost })` from `@metacensus/library-research/testing` returns `{ element, router, documents }`: the project in the frame and mount a real host uses, at its path, `data` giving each dataset's JSON, `people` and `roles` as research.json's, `reader` the username (default `test`) and the writer of every save, `self` false to view the project as `reader` while signed in as another (default true; `testHost` holds the one identity, so saves are still `reader`'s), `documents` the project's saved documents as `{ id: { body, writer? } }`, `url` the path below the project (default `/`). Render `element` with any DOM renderer; `router.state.location` says where the project navigated, and `documents()` what it saved. `membersOf(research.people)` and `readerOf(research, username, self)` from `./testing` build the `members` and `reader` `testHost` serves, so a fixture reads them from research.json rather than copying them. `init` scaffolds `ui/index.test.tsx` on vitest, jsdom and Testing Library, which a project installs itself.
87
119
 
88
120
  ```tsx
89
121
  render(
@@ -2,10 +2,10 @@ import { createHash } from 'node:crypto';
2
2
  import { existsSync, mkdirSync, readFileSync, writeFileSync } from 'node:fs';
3
3
  import { join } from 'node:path';
4
4
  import { parseArgs } from 'node:util';
5
+ import { kinds, papers, placeholderOf, workOf } from '../corpus.js';
6
+ import { readCorpus, writeCorpus } from '../data.js';
5
7
  import { git, kindOf, paperPath } from '../papers.js';
6
- import { readCorpus } from '../data.js';
7
8
  import { findRoot } from '../root.js';
8
- import { Corpus, kinds } from '../schema.js';
9
9
  export default function add(args) {
10
10
  const { positionals, values } = parseArgs({
11
11
  args,
@@ -29,19 +29,36 @@ export default function add(args) {
29
29
  if (git(root, 'check-attr', 'filter', '--', path) !== `${path}: filter: lfs\n`)
30
30
  throw new Error(`.gitattributes: papers/** doesn't go through LFS; run git lfs track 'papers/**'`);
31
31
  const corpus = readCorpus(root);
32
- const listed = corpus[sha]?.kind;
33
- if (listed && listed !== kind)
34
- throw new Error(`${file}: already listed as ${paperPath(sha, listed)}`);
32
+ const listed = papers(corpus).get(sha);
33
+ if (listed && listed.paper.kind !== kind)
34
+ throw new Error(`${file}: already listed as ${paperPath(sha, listed.paper.kind)}`);
35
+ if (listed) {
36
+ const { work, paper } = listed;
37
+ const pending = new Set(work.pending);
38
+ if (values.title !== undefined) {
39
+ work.csl.title = values.title;
40
+ pending.delete('title');
41
+ }
42
+ if (values.citation !== undefined) {
43
+ work.csl.note = values.citation;
44
+ pending.add('note');
45
+ }
46
+ if (values.open)
47
+ paper.open = true;
48
+ work.pending = [...pending];
49
+ if (!pending.size)
50
+ delete work.pending;
51
+ }
52
+ else {
53
+ const key = placeholderOf(sha);
54
+ if (corpus[key])
55
+ throw new Error(`${key}: already a work, and ${sha} shares its key`);
56
+ corpus[key] = workOf(sha, { kind, ...values });
57
+ }
35
58
  mkdirSync(join(root, 'papers'), { recursive: true });
36
59
  if (!existsSync(join(root, path)))
37
60
  writeFileSync(join(root, path), bytes);
38
- writeCorpus(root, { ...corpus, [sha]: { ...corpus[sha], kind, ...values } });
61
+ writeCorpus(root, corpus);
39
62
  git(root, 'add', '--', path, 'corpus.json');
40
63
  console.log(path);
41
64
  }
42
- function writeCorpus(root, corpus) {
43
- const lines = Object.entries(Corpus.parse(corpus))
44
- .sort(([a], [b]) => a.localeCompare(b))
45
- .map(([sha, paper]) => ` "${sha}": ${JSON.stringify(paper)}`);
46
- writeFileSync(join(root, 'corpus.json'), `{\n${lines.join(',\n')}\n}\n`);
47
- }
@@ -6,7 +6,7 @@ import { join, sep } from 'node:path';
6
6
  import { parseArgs, stripVTControlCharacters } from 'node:util';
7
7
  import { build, mergeConfig } from 'vite';
8
8
  import { checkPapers } from '../papers.js';
9
- import { load } from '../roles.js';
9
+ import { load } from '../datasets.js';
10
10
  import { findRoot } from '../root.js';
11
11
  import { hostConfig } from '../vite-config.js';
12
12
  const tsc = createRequire(import.meta.url).resolve('typescript/bin/tsc');
@@ -5,11 +5,12 @@ import { extname, join } from 'node:path';
5
5
  import { fileURLToPath } from 'node:url';
6
6
  import { parseArgs } from 'node:util';
7
7
  import { createServer, mergeConfig } from 'vite';
8
+ import { papers as held } from '../corpus.js';
8
9
  import { documentStore } from '../document-store.js';
9
10
  import { paperPath } from '../papers.js';
10
11
  import { project, read, readCorpus } from '../data.js';
11
12
  import { pdfAssets } from '../pdf.js';
12
- import { pagesOf, readerCookie } from '../reader.js';
13
+ import { pagesOf, readerCookie, readerOf } from '../reader.js';
13
14
  import { findRoot } from '../root.js';
14
15
  import { kinds } from '../schema.js';
15
16
  import { hostConfig } from '../vite-config.js';
@@ -51,7 +52,7 @@ export default async function dev(args) {
51
52
  const { values } = parseArgs({
52
53
  args,
53
54
  options: {
54
- reader: { type: 'string', default: 'local' },
55
+ reader: { type: 'string' },
55
56
  port: { type: 'string' },
56
57
  },
57
58
  });
@@ -69,9 +70,15 @@ export default async function dev(args) {
69
70
  if (local)
70
71
  console.log(`${url}local/`);
71
72
  }
72
- function devHost(root, reader) {
73
+ function devHost(root, named) {
74
+ const reader = named ?? 'local';
73
75
  const real = realpathSync(root);
74
- const { people } = project(root);
76
+ const { people, roles } = project(root);
77
+ // Refuses, before serving, a --reader the project's people cannot serve; the
78
+ // default is refused where a page reads as it, so contexts that each name a
79
+ // reader still start.
80
+ if (named !== undefined)
81
+ readerOf({ people, roles }, named, true);
75
82
  const store = documentStore();
76
83
  return {
77
84
  name: 'research:dev',
@@ -81,10 +88,14 @@ function devHost(root, reader) {
81
88
  resolveId: (id) => ([entry, css].includes(id) ? '\0' + id : undefined),
82
89
  load(id) {
83
90
  if (id === '\0' + css)
84
- return '@layer reset, mc;\n@layer reset {\n @tailwind base;\n}\n@tailwind components;\n@tailwind utilities;\n';
91
+ return [
92
+ '@layer theme, base, mc, components, utilities;',
93
+ `@import 'tailwindcss';`,
94
+ `@import '@metacensus/library-ui/theme.css';`,
95
+ ].join('\n');
85
96
  if (id === '\0' + entry)
86
97
  return [
87
- // First, so `reset` is ordered below library-ui's `mc`, as the host orders them.
98
+ // First, so its layer line sets the order before library-ui's CSS declares `mc`.
88
99
  `import '${css}'`,
89
100
  `import '@metacensus/library-ui/fonts.css'`,
90
101
  `import '@metacensus/library-ui/tokens.css'`,
@@ -92,7 +103,7 @@ function devHost(root, reader) {
92
103
  `import { configurePdf } from '@metacensus/library-ui/pdf'`,
93
104
  `import { start } from ${JSON.stringify(host)}`,
94
105
  `configurePdf({ assets: ${JSON.stringify(pdfAssets)} })`,
95
- `start(${JSON.stringify(reader)}, ${JSON.stringify(people)})`,
106
+ `start(${JSON.stringify(reader)}, ${JSON.stringify({ people, roles })})`,
96
107
  ].join('\n');
97
108
  },
98
109
  configureServer(server) {
@@ -119,7 +130,7 @@ function devHost(root, reader) {
119
130
  if ([data, documents, privates].some((route) => route.test(path ?? '')) &&
120
131
  named === '')
121
132
  return reply(res, 401, { 'Content-Type': 'text/plain' }, 'signed out');
122
- const [, page, role = ''] = path?.match(privates) ?? [];
133
+ const [, page, dataset = ''] = path?.match(privates) ?? [];
123
134
  if (documents.test(path ?? '') || page) {
124
135
  // A cookie that does not decode names no reader.
125
136
  let who = reader;
@@ -142,9 +153,9 @@ function devHost(root, reader) {
142
153
  }
143
154
  if (!pagesOf(people, who).includes(wanted))
144
155
  return reply(res, 403, { 'Content-Type': 'text/plain' }, 'not yours');
145
- const file = privateFile(root, wanted, role);
156
+ const file = privateFile(root, wanted, dataset);
146
157
  if (!file)
147
- return notFound(res, `project has no private role "${role}" page "${page}"`);
158
+ return notFound(res, `project has no private dataset "${dataset}" page "${page}"`);
148
159
  return send(req, res, Buffer.from(JSON.stringify(read(root, file))), 'application/json');
149
160
  }
150
161
  const asset = path?.startsWith(pdfAssets) && path.slice(pdfAssets.length);
@@ -158,7 +169,7 @@ function devHost(root, reader) {
158
169
  const sha = path?.match(papers)?.[1];
159
170
  if (!sha)
160
171
  return next();
161
- const kind = readCorpus(root)[sha]?.kind;
172
+ const kind = held(readCorpus(root)).get(sha)?.paper.kind;
162
173
  if (!kind)
163
174
  return notFound(res, `${sha}: not in corpus.json`);
164
175
  const file = paperPath(sha, kind);
@@ -183,9 +194,9 @@ function devHost(root, reader) {
183
194
  },
184
195
  };
185
196
  }
186
- function privateFile(root, page, role) {
197
+ function privateFile(root, page, dataset) {
187
198
  try {
188
- return project(root).pages[role]?.()[page];
199
+ return project(root).pages[dataset]?.()[page];
189
200
  }
190
201
  catch (error) {
191
202
  if (error.message.endsWith(': matches no file'))
@@ -0,0 +1,2 @@
1
+ /** Rewrites a legacy corpus.json in the new shape, leaving one already in it, and prints what waits on a person. */
2
+ export default function reshape(args: string[]): void;
@@ -0,0 +1,21 @@
1
+ import { parseArgs } from 'node:util';
2
+ import * as loader from '../corpus.js';
3
+ import { read, readCorpus, writeCorpus } from '../data.js';
4
+ import { findRoot } from '../root.js';
5
+ /** Rewrites a legacy corpus.json in the new shape, leaving one already in it, and prints what waits on a person. */
6
+ export default function reshape(args) {
7
+ parseArgs({ args });
8
+ const root = findRoot(process.cwd());
9
+ let corpus;
10
+ try {
11
+ corpus = readCorpus(root);
12
+ }
13
+ catch (error) {
14
+ const legacy = loader.LegacyCorpus.safeParse(read(root, 'corpus.json'));
15
+ if (!legacy.success)
16
+ throw error;
17
+ corpus = loader.reshape(legacy.data).corpus;
18
+ writeCorpus(root, corpus);
19
+ }
20
+ console.log(JSON.stringify(loader.pending(corpus), null, 2));
21
+ }
package/dist/context.d.ts CHANGED
@@ -1,4 +1,6 @@
1
- import type { Host } from './types.js';
1
+ import type { Host, Schema } from './types.js';
2
2
  export declare const HostContext: import("react").Context<Host | null>;
3
3
  /** Where the document hooks fetch from; the test host sets its in-memory store, a host leaves the global. */
4
4
  export declare const FetchContext: import("react").Context<typeof fetch | null>;
5
+ /** The schemas `defineProject` was given, which `useData` and `usePrivate` look a dataset up in. */
6
+ export declare const DatasetsContext: import("react").Context<Record<string, Schema>>;
package/dist/context.js CHANGED
@@ -2,3 +2,5 @@ import { createContext } from 'react';
2
2
  export const HostContext = createContext(null);
3
3
  /** Where the document hooks fetch from; the test host sets its in-memory store, a host leaves the global. */
4
4
  export const FetchContext = createContext(null);
5
+ /** The schemas `defineProject` was given, which `useData` and `usePrivate` look a dataset up in. */
6
+ export const DatasetsContext = createContext({});