@metacensus/library-research 0.14.0 → 0.16.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 (53) hide show
  1. package/README.md +65 -20
  2. package/dist/collection-store.d.ts +31 -0
  3. package/dist/collection-store.js +174 -0
  4. package/dist/collections.gen.d.ts +309 -0
  5. package/dist/collections.gen.js +190 -0
  6. package/dist/commands/add.js +29 -12
  7. package/dist/commands/dev.js +48 -44
  8. package/dist/commands/reshape.d.ts +2 -0
  9. package/dist/commands/reshape.js +21 -0
  10. package/dist/context.d.ts +5 -3
  11. package/dist/context.js +4 -2
  12. package/dist/corpus.d.ts +432 -0
  13. package/dist/corpus.js +348 -0
  14. package/dist/data.d.ts +13 -6
  15. package/dist/data.js +27 -15
  16. package/dist/datasets.d.ts +4 -1
  17. package/dist/datasets.js +48 -8
  18. package/dist/dev/host.js +6 -9
  19. package/dist/host.d.ts +17 -2
  20. package/dist/host.js +26 -2
  21. package/dist/index.d.ts +3 -3
  22. package/dist/index.js +2 -2
  23. package/dist/mount.d.ts +11 -4
  24. package/dist/mount.js +15 -9
  25. package/dist/papers.js +3 -2
  26. package/dist/parity.d.ts +25 -0
  27. package/dist/parity.js +70 -0
  28. package/dist/playwright.d.ts +2 -2
  29. package/dist/playwright.js +30 -8
  30. package/dist/project-id.d.ts +4 -0
  31. package/dist/project-id.js +7 -0
  32. package/dist/react.d.ts +32 -42
  33. package/dist/react.js +121 -118
  34. package/dist/schema.d.ts +19 -34
  35. package/dist/schema.js +47 -31
  36. package/dist/testing.d.ts +26 -11
  37. package/dist/testing.js +64 -26
  38. package/dist/types.d.ts +85 -26
  39. package/dist/urls.d.ts +35 -0
  40. package/dist/urls.js +58 -0
  41. package/dist/vite-config.js +2 -12
  42. package/dist/vite.d.ts +11 -2
  43. package/dist/vite.js +79 -25
  44. package/dist/zod.d.ts +2 -0
  45. package/dist/zod.js +4 -0
  46. package/package.json +19 -12
  47. package/schema/corpus.schema.json +3949 -29
  48. package/schema/project-id.schema.json +6 -0
  49. package/schema/research.schema.json +130 -2
  50. package/dist/document-store.d.ts +0 -14
  51. package/dist/document-store.js +0 -78
  52. package/dist/documents.d.ts +0 -10
  53. package/dist/documents.js +0 -22
package/dist/testing.js CHANGED
@@ -1,39 +1,77 @@
1
1
  import { jsx as _jsx } from "react/jsx-runtime";
2
2
  import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
3
3
  import { createMemoryHistory, RouterProvider } from '@tanstack/react-router';
4
- import { FetchContext } from './context.js';
5
- import { documentStore } from './document-store.js';
4
+ import { collectionStore } from './collection-store.js';
5
+ import { createHost } from './host.js';
6
6
  import { membersOf, pagesOf, readerOf } from './reader.js';
7
7
  import { projectRouter } from './router.js';
8
+ import { match } from './urls.js';
9
+ export { parity } from './parity.js';
8
10
  export { membersOf, readerOf } from './reader.js';
9
- const origin = 'http://test.invalid';
11
+ const json = (value) => new Response(JSON.stringify(value), {
12
+ headers: { 'Content-Type': 'application/json' },
13
+ });
14
+ const refuse = (status) => new Response(null, { status });
10
15
  /**
11
16
  * A project rendered through the frame and the mount a real host uses, at the
12
- * path it names. Render `element` with any DOM renderer; `router` says where
13
- * the project navigated, and `documents()` what it saved, sorted by id.
17
+ * path it names, its store in memory. Render `element` with any DOM renderer;
18
+ * `router` says where the project navigated, `items()` each item's current
19
+ * revision in write order, and `host` is the `Host` the frame provides.
14
20
  */
15
- export function testHost(project, { data = {}, documents = {}, private: held = {}, people, roles, reader = 'test', self = true, url = '/', sessionLost = () => { }, } = {}) {
16
- const store = documentStore(documents, reader);
17
- const memory = (input, init) => store.handle(new Request(new URL(input instanceof Request ? input.url : input, origin), init), reader);
18
- const host = {
21
+ export function testHost(project, { data = {}, collections, items = [], private: held = {}, people, roles, reader = 'test', self = true, url = '/', sessionLost = () => { }, } = {}) {
22
+ const saved = collectionStore({
23
+ collections,
24
+ people: people ?? { [reader]: {} },
25
+ });
26
+ for (const [i, { writer = reader, ...item }] of items.entries()) {
27
+ const revision = saved
28
+ .items()
29
+ .find((held) => held.collection === item.collection &&
30
+ held.writer === writer &&
31
+ held.id === item.id)?.revision ?? 0;
32
+ const { outcome } = saved.write(writer, {
33
+ requestId: `seed-${i}`,
34
+ items: [{ ...item, revision }],
35
+ });
36
+ if (outcome !== 'ok')
37
+ throw new Error(`item "${item.id}" of "${item.collection}" seeded as "${writer}": ${outcome}`);
38
+ }
39
+ const pages = pagesOf(people, reader);
40
+ // Answers as dev does: a page the reader does not hold is 403, one not given is 404.
41
+ async function store(request) {
42
+ const route = match(request.url);
43
+ if (route?.project !== project.path)
44
+ return refuse(404);
45
+ switch (route.route) {
46
+ case 'data': {
47
+ const value = Object.hasOwn(data, route.dataset)
48
+ ? data[route.dataset]
49
+ : undefined;
50
+ return value === undefined ? refuse(404) : json(value);
51
+ }
52
+ case 'private': {
53
+ if (!pages.includes(route.page))
54
+ return refuse(403);
55
+ const page = held[route.dataset] ?? {};
56
+ return Object.hasOwn(page, route.page)
57
+ ? json(page[route.page])
58
+ : refuse(404);
59
+ }
60
+ case 'paper':
61
+ return refuse(404);
62
+ default:
63
+ return saved.handle(request, route, reader);
64
+ }
65
+ }
66
+ const host = createHost({
67
+ project: project.path,
19
68
  reader: readerOf({ people, roles }, reader, self),
20
69
  members: membersOf(people),
21
- data(dataset) {
22
- if (!Object.hasOwn(data, dataset) || data[dataset] === undefined)
23
- throw new Error(`testHost: no data for dataset "${dataset}"`);
24
- return `data:application/json,${encodeURIComponent(JSON.stringify(data[dataset]))}`;
25
- },
26
- private: (dataset) => Object.fromEntries(pagesOf(people, reader)
27
- .filter((page) => Object.hasOwn(held[dataset] ?? {}, page))
28
- .map((page) => [
29
- page,
30
- `data:application/json,${encodeURIComponent(JSON.stringify(held[dataset][page]))}`,
31
- ])),
32
- paper: (sha) => `/papers/${sha}`,
33
- document: (id) => `${origin}/documents/${id}`,
34
- documents: (prefix) => `${origin}/documents?prefix=${prefix}`,
70
+ pages,
71
+ store,
35
72
  sessionLost,
36
- };
73
+ origin: 'http://test.invalid',
74
+ });
37
75
  const router = projectRouter(project, () => host, createMemoryHistory({ initialEntries: [`/${project.path}${url}`] }));
38
76
  // react-router 1.170.46 reads this in Matches before router-core 1.171.39 sets it.
39
77
  // Delete once react-router and router-core are bumped to versions that agree.
@@ -45,6 +83,6 @@ export function testHost(project, { data = {}, documents = {}, private: held = {
45
83
  mutations: { gcTime: Infinity },
46
84
  },
47
85
  });
48
- const element = (_jsx(QueryClientProvider, { client: client, children: _jsx(FetchContext.Provider, { value: memory, children: _jsx(RouterProvider, { router: router }) }) }));
49
- return { element, router, documents: store.all };
86
+ const element = (_jsx(QueryClientProvider, { client: client, children: _jsx(RouterProvider, { router: router }) }));
87
+ return { element, router, host, items: saved.items };
50
88
  }
package/dist/types.d.ts CHANGED
@@ -1,9 +1,10 @@
1
1
  import type { z } from 'zod';
2
- import type { Corpus as CorpusSchema, kinds } from './schema.js';
2
+ import type { components } from './collections.gen.js';
3
+ import type * as corpus from './corpus.js';
3
4
  /**
4
5
  * What a host gives a project: `frame` provides it and `useHost` returns it.
5
- * The methods are called during render, so each must be cheap and return the
6
- * same URL for the same arguments.
6
+ * `createHost` builds it. The URL methods are called during render, so each
7
+ * must be cheap and return the same URL for the same arguments.
7
8
  */
8
9
  export interface Host {
9
10
  /** The person the project is viewed as, who may differ from the person signed in. */
@@ -16,44 +17,102 @@ export interface Host {
16
17
  private(dataset: string): Record<string, string>;
17
18
  /** The URL of the paper stored under `sha`, as the corpus names it. */
18
19
  paper(sha: string): string;
19
- /**
20
- * The URL of one document of this project: a GET reads it, a PUT writes it
21
- * as the signed-in person. `id` matches `^[A-Za-z0-9][A-Za-z0-9._-]{0,127}$`,
22
- * so the URL needs no encoding.
23
- */
24
- document(id: string): string;
25
- /** The URL a GET lists the project's documents at, those whose id starts with `prefix`, sorted by id. */
26
- documents(prefix: string): string;
20
+ /** The URL a POST writes items across the project's collections at, as the signed-in person; `useWrite` posts to it. */
21
+ collections(): string;
22
+ /** The URL a GET reads the items of one collection at, those the signed-in person may read; `useCollection` fetches it. */
23
+ collection(name: string): string;
24
+ /** The project's store: answers each URL this `Host` builds, but `paper`'s, as the signed-in person. Every hook fetches through it. */
25
+ store(request: Request): Promise<Response>;
27
26
  /** Called each time a data request is answered 401 or 403, so several times for one lost session. */
28
27
  sessionLost(): void;
29
28
  }
30
- /** A stored document: what the store records beside the project's `body`. */
31
- export interface Doc<T> {
32
- id: string;
33
- /** The person signed in when it was saved; never the person a reader views the project as. */
34
- writer: string;
35
- /** The project's write counter at the save, so it orders every save; `useSaveDocument`'s `when` takes it. */
36
- revision: number;
29
+ /**
30
+ * What a project declares of itself by augmenting this module:
31
+ * `datasets` and `collections`, the types of ui/datasets.ts's exports, and
32
+ * `roles`, research.json's roles as a union; `load` checks that ui/datasets.ts's
33
+ * `roles` tuple equals research.json's, and that each collection has
34
+ * research.json's `body` as its JSON Schema.
35
+ *
36
+ * @example
37
+ * declare module '@metacensus/library-research' {
38
+ * interface Register {
39
+ * datasets: typeof datasets
40
+ * collections: typeof collections
41
+ * roles: (typeof roles)[number]
42
+ * }
43
+ * }
44
+ */
45
+ export interface Register {
46
+ }
47
+ /** What parses a dataset's JSON: a Zod schema is one. */
48
+ export interface Schema {
49
+ parse(json: unknown): unknown;
50
+ }
51
+ /** The schemas of a project: those of `Register`'s `datasets`, else any by name. */
52
+ export type Schemas = Register extends {
53
+ datasets: infer D;
54
+ } ? D : Record<string, Schema>;
55
+ /** What a dataset's schema parses its JSON to. */
56
+ export type Data<K extends keyof Schemas> = Schemas[K] extends {
57
+ parse(json: unknown): infer T;
58
+ } ? T : unknown;
59
+ /** The schemas of a project's collections: those of `Register`'s `collections`, else any by name. */
60
+ export type CollectionSchemas = Register extends {
61
+ collections: infer C;
62
+ } ? C : Record<string, Schema>;
63
+ /** A collection's body type; `unknown` in a project whose `Register` holds no `collections`. */
64
+ export type Body<K extends keyof CollectionSchemas> = CollectionSchemas[K] extends {
65
+ parse(json: unknown): infer T;
66
+ } ? T : unknown;
67
+ /** One item of a collection, at the revision it holds, its body parsed. */
68
+ export type Item<T = unknown> = Omit<components['schemas']['Item'], 'body' | 'sequence'> & {
69
+ sequence: number;
37
70
  body: T;
71
+ };
72
+ /** One write across collections, atomic: each item's `body` typed by its `collection`. */
73
+ export interface WriteRequest {
74
+ /** Names the write: retrying it reuses the id, and a new write takes a new one, such as `crypto.randomUUID()`. */
75
+ requestId: string;
76
+ items: {
77
+ [K in keyof CollectionSchemas]: {
78
+ collection: K;
79
+ id: string;
80
+ /** The item's current revision, or `0` for a new item. */
81
+ revision: number;
82
+ body: Body<K>;
83
+ };
84
+ }[keyof CollectionSchemas][];
38
85
  }
86
+ /** What a write stored: each item, in the request's order, at the revision it now holds. */
87
+ export type WriteResult = components['schemas']['WriteResult'];
39
88
  /** A person of the project. */
40
89
  export interface Member {
41
90
  /** The name the host signs them in as. */
42
91
  username: string;
43
92
  /** The name a person reads. */
44
93
  name: string;
45
- /** One of research.json's `roles`; null only in a project that declares none. */
46
- role: string | null;
94
+ /** One of research.json's `roles`: `Register`'s where it declares them; null only in a project that declares none. */
95
+ role: Register extends {
96
+ roles: infer R;
97
+ } ? R : string | null;
47
98
  }
48
99
  /** The person a project is viewed as; `useReader` returns them. */
49
100
  export interface Reader extends Member {
50
101
  /** False while the host views the project as another person than the one signed in. */
51
102
  self: boolean;
52
103
  }
53
- /** A kind of record the schema allows, one of `kinds`' keys. */
54
- export type Kind = keyof typeof kinds;
55
- /** The parsed `corpus` dataset: every paper by sha. */
56
- export type Corpus = z.infer<typeof CorpusSchema>;
57
- /** One paper of the corpus. */
58
- export type Paper = Corpus[string];
104
+ /** A kind of file the schema allows, one of `kinds`' keys. */
105
+ export type Kind = keyof typeof corpus.kinds;
106
+ /** The parsed `corpus` dataset: every work by id. */
107
+ export type Corpus = z.infer<typeof corpus.Corpus>;
108
+ /** One work: its CSL-JSON, its editions, and the fields pending a person. */
109
+ export type Work = z.infer<typeof corpus.Work>;
110
+ /** One edition of a work, holding its files by sha. */
111
+ export type Edition = z.infer<typeof corpus.Edition>;
112
+ /** One held file of an edition. */
113
+ export type Paper = z.infer<typeof corpus.Paper>;
114
+ /** A work's CSL-JSON metadata. */
115
+ export type Csl = z.infer<typeof corpus.Csl>;
116
+ /** What waits on a person: a placeholder's `key`, or a pending CSL field. */
117
+ export type Judgment = ReturnType<typeof corpus.pending>[number];
59
118
  export type { AnyProject, Mount, Project, RouterOf } from './mount.js';
package/dist/urls.d.ts ADDED
@@ -0,0 +1,35 @@
1
+ /** Where a project's built files, data and private pages live. */
2
+ export declare const projectRoot: (project: string) => string;
3
+ export declare const urls: {
4
+ data: (project: string, dataset: string) => string;
5
+ private: (project: string, page: string, dataset: string) => string;
6
+ paper: (project: string, sha: string) => string;
7
+ collections: (project: string) => string;
8
+ collection: (project: string, collection: string) => string;
9
+ };
10
+ /** A URL `urls` builds, as the values it was built from. */
11
+ export type Route = {
12
+ route: 'data';
13
+ project: string;
14
+ dataset: string;
15
+ } | {
16
+ route: 'private';
17
+ project: string;
18
+ page: string;
19
+ dataset: string;
20
+ } | {
21
+ route: 'paper';
22
+ project: string;
23
+ sha: string;
24
+ } | {
25
+ route: 'collections';
26
+ project: string;
27
+ } | {
28
+ route: 'collection';
29
+ project: string;
30
+ collection: string;
31
+ };
32
+ /** Whether `path` lies under a route's root, where matching no route makes it a 404 rather than a file. */
33
+ export declare const routed: (path: string) => boolean;
34
+ /** The route `url`, a URL or a path, is; undefined when it is none, or a segment does not decode. */
35
+ export declare function match(url: string | URL): Route | undefined;
package/dist/urls.js ADDED
@@ -0,0 +1,58 @@
1
+ const e = encodeURIComponent;
2
+ // The API's paths the collection URLs fill in, so `tsc` fails when the spec renames one.
3
+ const api = {
4
+ collections: '/api/projects/{project}/collections',
5
+ collection: '/api/projects/{project}/collections/{collection}',
6
+ };
7
+ /** Where a project's built files, data and private pages live. */
8
+ export const projectRoot = (project) => `/projects/${e(project)}`;
9
+ export const urls = {
10
+ data: (project, dataset) => `${projectRoot(project)}/data/${e(dataset)}.json`,
11
+ private: (project, page, dataset) => `${projectRoot(project)}/private/${e(page)}/${e(dataset)}.json`,
12
+ paper: (project, sha) => `/api/papers/${e(project)}/${e(sha)}`,
13
+ collections: (project) => api.collections.replace('{project}', e(project)),
14
+ collection: (project, collection) => api.collection
15
+ .replace('{project}', e(project))
16
+ .replace('{collection}', e(collection)),
17
+ };
18
+ // Each route's path, its segments' names in order.
19
+ const paths = [
20
+ [
21
+ 'data',
22
+ /^\/projects\/([^/]*)\/data\/([^/]*)\.json$/,
23
+ ['project', 'dataset'],
24
+ ],
25
+ [
26
+ 'private',
27
+ /^\/projects\/([^/]*)\/private\/([^/]*)\/([^/]*)\.json$/,
28
+ ['project', 'page', 'dataset'],
29
+ ],
30
+ ['paper', /^\/api\/papers\/([^/]*)\/([^/]*)$/, ['project', 'sha']],
31
+ ['collections', /^\/api\/projects\/([^/]*)\/collections$/, ['project']],
32
+ [
33
+ 'collection',
34
+ /^\/api\/projects\/([^/]*)\/collections\/([^/]*)$/,
35
+ ['project', 'collection'],
36
+ ],
37
+ ];
38
+ /** Whether `path` lies under a route's root, where matching no route makes it a 404 rather than a file. */
39
+ export const routed = (path) => /^\/(projects|api\/projects|api\/papers)\//.test(path);
40
+ /** The route `url`, a URL or a path, is; undefined when it is none, or a segment does not decode. */
41
+ export function match(url) {
42
+ const { pathname } = new URL(url, 'http://host.invalid');
43
+ for (const [route, path, names] of paths) {
44
+ const found = pathname.match(path);
45
+ if (!found)
46
+ continue;
47
+ try {
48
+ const values = names.map((name, i) => [
49
+ name,
50
+ decodeURIComponent(found[i + 1]),
51
+ ]);
52
+ return { route, ...Object.fromEntries(values) };
53
+ }
54
+ catch {
55
+ return;
56
+ }
57
+ }
58
+ }
@@ -1,22 +1,12 @@
1
1
  import react from '@vitejs/plugin-react';
2
- import { createRequire } from 'node:module';
3
2
  import { join } from 'node:path';
4
- import tailwind from 'tailwindcss';
5
- import { research, tailwindContent } from './vite.js';
3
+ import { research, tailwind } from './vite.js';
6
4
  export function hostConfig(root) {
7
5
  const projects = { project: root };
8
- const preset = createRequire(import.meta.url)('@metacensus/library-ui/tailwind3');
9
6
  return {
10
7
  root: join(root, 'ui'),
11
8
  configFile: false,
12
- plugins: [react(), research({ projects })],
13
- css: {
14
- postcss: {
15
- plugins: [
16
- tailwind({ presets: [preset], content: tailwindContent(projects) }),
17
- ],
18
- },
19
- },
9
+ plugins: [react(), research({ projects }), tailwind({ projects })],
20
10
  // library-research's modules stay unbundled so the host and the project
21
11
  // share one copy; Vite reads no imports inside node_modules, so theirs are
22
12
  // listed.
package/dist/vite.d.ts CHANGED
@@ -11,5 +11,14 @@ import { type Plugin } from 'vite';
11
11
  export declare function research({ projects, }: {
12
12
  projects: Record<string, string>;
13
13
  }): Plugin[];
14
- /** The Tailwind `content` globs that scan each project's `ui/`, skipping its `node_modules`; spread into the host's config. */
15
- export declare function tailwindContent(projects: Record<string, string>): string[];
14
+ /**
15
+ * Tailwind 4 for a host, as a plugin because a project's path comes from the
16
+ * host's environment, which a stylesheet's literal `@source` cannot hold. A
17
+ * host stylesheet importing `tailwindcss` gains each project's `ui/` as a
18
+ * source and paints `body` with library-ui's ground and ink; a project
19
+ * stylesheet gains `@reference`s to Tailwind and library-ui's theme, so its
20
+ * `@apply` needs no boilerplate.
21
+ */
22
+ export declare function tailwind({ projects, }: {
23
+ projects: Record<string, string>;
24
+ }): Plugin[];
package/dist/vite.js CHANGED
@@ -1,11 +1,14 @@
1
1
  import { existsSync, readdirSync, readFileSync, realpathSync, statSync, } from 'node:fs';
2
2
  import { basename, dirname, join, relative, resolve, sep } from 'node:path';
3
+ import { fileURLToPath } from 'node:url';
3
4
  import { satisfies } from 'semver';
4
5
  import { isCSSRequest, preprocessCSS, searchForWorkspaceRoot, } from 'vite';
6
+ import tailwindcss from '@tailwindcss/vite';
5
7
  import { project, read } from './data.js';
6
- const prefix = 'projects';
7
- const dataPath = new RegExp(`^${prefix}/([^/]+)/data/([^/]+)\\.json$`);
8
- const privatePath = new RegExp(`^${prefix}/([^/]+)/private/([^/]+)/([^/]+)\\.json$`);
8
+ import { checkProjectId } from './project-id.js';
9
+ import { match, projectRoot, urls } from './urls.js';
10
+ /** Where a URL path's file is in the build output, which has no leading slash. */
11
+ const built = (path) => path.slice(1);
9
12
  const virtual = 'virtual:research-projects';
10
13
  const cssImport = /@(?:import|use|forward)\b/;
11
14
  const cssComposes = /\bcomposes\s*:[^;}]*?\bfrom\s+(['"])([^'"]+)\1/g;
@@ -42,7 +45,9 @@ export function research({ projects, }) {
42
45
  if (slugs.length > 1)
43
46
  throw new Error(`${owned.join(', ')}: mixes ${slugs.join(' and ')}`);
44
47
  const name = typeof pattern === 'string' ? pattern : pattern(info);
45
- return slugs[0] ? `${prefix}/${slugs[0]}/assets/${basename(name)}` : name;
48
+ return slugs[0]
49
+ ? `${built(projectRoot(slugs[0]))}/assets/${basename(name)}`
50
+ : name;
46
51
  };
47
52
  const sources = (asset) => asset.originalFileNames.map((file) => resolve(config.root, file));
48
53
  /**
@@ -66,6 +71,8 @@ export function research({ projects, }) {
66
71
  name: 'research',
67
72
  config(user) {
68
73
  const from = resolve(user.root ?? '');
74
+ for (const slug of Object.keys(projects))
75
+ checkProjectId(slug, 'project');
69
76
  dirs = Object.entries(projects).map(([slug, path]) => [
70
77
  slug,
71
78
  realpathSync(resolve(from, path)),
@@ -173,14 +180,14 @@ export function research({ projects, }) {
173
180
  for (const [dataset, json] of Object.entries(datasets))
174
181
  this.emitFile({
175
182
  type: 'asset',
176
- fileName: `${prefix}/${slug}/data/${dataset}.json`,
183
+ fileName: built(urls.data(slug, dataset)),
177
184
  source: JSON.stringify(json()),
178
185
  });
179
186
  for (const [dataset, held] of Object.entries(pages))
180
187
  for (const [page, file] of Object.entries(held()))
181
188
  this.emitFile({
182
189
  type: 'asset',
183
- fileName: `${prefix}/${slug}/private/${page}/${dataset}.json`,
190
+ fileName: built(urls.private(slug, page, dataset)),
184
191
  source: JSON.stringify(read(dir, file)),
185
192
  });
186
193
  }
@@ -252,8 +259,8 @@ export function research({ projects, }) {
252
259
  continue;
253
260
  const text = readFileSync(path, 'utf8');
254
261
  for (const [slug, mark] of marks)
255
- if (!inside(file, `${prefix}/${slug}`) && mark.test(text))
256
- this.error(`${file}: holds project ${slug}, outside ${prefix}/${slug}/`);
262
+ if (!inside(file, built(projectRoot(slug))) && mark.test(text))
263
+ this.error(`${file}: holds project ${slug}, outside ${built(projectRoot(slug))}/`);
257
264
  }
258
265
  },
259
266
  },
@@ -263,24 +270,24 @@ export function research({ projects, }) {
263
270
  configureServer(server) {
264
271
  server.middlewares.use((req, res, next) => {
265
272
  const path = req.url?.split('?')[0] ?? '';
266
- const local = path.startsWith(config.base)
267
- ? path.slice(config.base.length)
268
- : '';
269
- const [, slug, dataset = ''] = local.match(dataPath) ?? [];
270
- const [, pslug, page = '', pdataset = ''] = local.match(privatePath) ?? [];
271
- const dir = dirs.find(([s]) => s === (slug ?? pslug))?.[1];
273
+ const route = path.startsWith(config.base)
274
+ ? match(`/${path.slice(config.base.length)}`)
275
+ : undefined;
276
+ if (route?.route !== 'data' && route?.route !== 'private')
277
+ return next();
278
+ const dir = dirs.find(([s]) => s === route.project)?.[1];
272
279
  if (!dir)
273
280
  return next();
274
- if (pslug) {
281
+ const { project: slug, dataset } = route;
282
+ if (route.route === 'private') {
275
283
  // Gates nothing: the host's dev server decides who loads which page.
284
+ const { page } = route;
276
285
  const { pages } = project(dir);
277
- const held = Object.hasOwn(pages, pdataset)
278
- ? pages[pdataset]()
279
- : {};
286
+ const held = Object.hasOwn(pages, dataset) ? pages[dataset]() : {};
280
287
  const file = Object.hasOwn(held, page) ? held[page] : undefined;
281
288
  if (!file) {
282
289
  res.statusCode = 404;
283
- return res.end(`${pslug} has no private dataset "${pdataset}" page "${page}"`);
290
+ return res.end(`${slug} has no private dataset "${dataset}" page "${page}"`);
284
291
  }
285
292
  res.setHeader('Content-Type', 'application/json');
286
293
  return res.end(JSON.stringify(read(dir, file)));
@@ -297,10 +304,57 @@ export function research({ projects, }) {
297
304
  },
298
305
  ];
299
306
  }
300
- /** The Tailwind `content` globs that scan each project's `ui/`, skipping its `node_modules`; spread into the host's config. */
301
- export function tailwindContent(projects) {
302
- return Object.values(projects).flatMap((path) => [
303
- `${path}/ui/**/*.{ts,tsx}`,
304
- `!${path}/ui/node_modules/**`,
305
- ]);
307
+ /**
308
+ * Tailwind 4 for a host, as a plugin because a project's path comes from the
309
+ * host's environment, which a stylesheet's literal `@source` cannot hold. A
310
+ * host stylesheet importing `tailwindcss` gains each project's `ui/` as a
311
+ * source and paints `body` with library-ui's ground and ink; a project
312
+ * stylesheet gains `@reference`s to Tailwind and library-ui's theme, so its
313
+ * `@apply` needs no boilerplate.
314
+ */
315
+ export function tailwind({ projects, }) {
316
+ // tailwindcss resolves from library-research, so a project's stylesheet
317
+ // builds with the host's copy wherever the project sits.
318
+ const references = [
319
+ [
320
+ 'tailwindcss',
321
+ fileURLToPath(import.meta.resolve('tailwindcss/index.css')),
322
+ ],
323
+ ['@metacensus/library-ui/theme.css', '@metacensus/library-ui/theme.css'],
324
+ ];
325
+ let dirs = [];
326
+ return [
327
+ {
328
+ name: 'research:tailwind',
329
+ enforce: 'pre',
330
+ configResolved({ root }) {
331
+ dirs = Object.values(projects).map((path) => join(realpathSync(resolve(root, path)), 'ui'));
332
+ },
333
+ transform(code, id) {
334
+ if (!cssCode(id))
335
+ return;
336
+ const file = id.split('?')[0];
337
+ const uses = (target, rules = 'import|reference') => new RegExp(`@(?:${rules})\\s+(['"])${escape(target)}\\1`).test(code);
338
+ const project = dirs.find((dir) => inside(file, dir));
339
+ if (project) {
340
+ if (relative(project, file).split(sep).includes('node_modules'))
341
+ return;
342
+ const lines = references
343
+ .filter(([target]) => !uses(target))
344
+ .map(([, path]) => `@reference ${JSON.stringify(path)};\n`);
345
+ return lines.length
346
+ ? { code: lines.join('') + code, map: null }
347
+ : undefined;
348
+ }
349
+ if (uses('tailwindcss', 'import'))
350
+ return {
351
+ code: code +
352
+ dirs.map((dir) => `\n@source ${JSON.stringify(dir)};`).join('') +
353
+ '\n@layer base { body { background-color: var(--mc-ground); color: var(--mc-ink); } }',
354
+ map: null,
355
+ };
356
+ },
357
+ },
358
+ ...tailwindcss(),
359
+ ];
306
360
  }
package/dist/zod.d.ts ADDED
@@ -0,0 +1,2 @@
1
+ import { z } from 'zod';
2
+ export { z };
package/dist/zod.js ADDED
@@ -0,0 +1,4 @@
1
+ import { z } from 'zod';
2
+ // Before any schema is built: zod picks JIT at construction, and the host's CSP forbids eval.
3
+ z.config({ jitless: true });
4
+ export { z };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@metacensus/library-research",
3
- "version": "0.14.0",
3
+ "version": "0.16.0",
4
4
  "license": "AGPL-3.0-only",
5
5
  "repository": {
6
6
  "type": "git",
@@ -59,25 +59,26 @@
59
59
  "dependencies": {
60
60
  "@axe-core/playwright": "^4.14.0",
61
61
  "@playwright/test": "^1.65.1",
62
- "@types/react": "^18.3.31",
63
- "@types/react-dom": "^18.3.7",
62
+ "@tailwindcss/vite": "^4.3.5",
63
+ "@types/react": "^19.3.3",
64
+ "@types/react-dom": "^19.3.0",
64
65
  "@vitejs/plugin-react": "^6.3.0",
65
66
  "semver": "^7.8.6",
66
- "tailwindcss": "^3.4.19",
67
+ "tailwindcss": "^4.3.5",
67
68
  "typescript": "^6.0.3",
68
69
  "zod": "^4.6.7"
69
70
  },
70
71
  "peerDependencies": {
71
- "@metacensus/library-ui": ">=0.6.0 <1",
72
+ "@metacensus/library-ui": ">=0.22.0 <1",
72
73
  "@tanstack/react-query": "^5",
73
74
  "@tanstack/react-router": "^1",
74
- "react": "^18.3.1",
75
- "react-dom": "^18.3.1",
75
+ "react": "^19",
76
+ "react-dom": "^19",
76
77
  "vite": "~8.3.8"
77
78
  },
78
79
  "devDependencies": {
79
80
  "@eslint/js": "^9.39.5",
80
- "@metacensus/library-ui": "^0.12.0",
81
+ "@metacensus/library-ui": "^0.22.0",
81
82
  "@tanstack/react-query": "^5.108.0",
82
83
  "@tanstack/react-router": "^1.170.46",
83
84
  "@types/jsdom": "^30.0.0",
@@ -86,11 +87,17 @@
86
87
  "eslint": "^9.39.5",
87
88
  "eslint-plugin-react-hooks": "^7.1.1",
88
89
  "jsdom": "^31.0.1",
89
- "postcss": "^8.5.33",
90
+ "openapi-typescript": "^7.13.0",
90
91
  "prettier": "^3.10.1",
91
- "react": "^18.3.1",
92
- "react-dom": "^18.3.1",
92
+ "react": "^19.3.1",
93
+ "react-dom": "^19.3.1",
93
94
  "typescript-eslint": "^8.73.0",
94
- "vite": "~8.3.8"
95
+ "vite": "~8.3.8",
96
+ "yaml": "^2.9.1"
97
+ },
98
+ "overrides": {
99
+ "openapi-typescript": {
100
+ "typescript": "$typescript"
101
+ }
95
102
  }
96
103
  }