@metacensus/library-research 0.15.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.
- package/README.md +41 -19
- package/dist/collection-store.d.ts +31 -0
- package/dist/collection-store.js +174 -0
- package/dist/collections.gen.d.ts +309 -0
- package/dist/collections.gen.js +190 -0
- package/dist/commands/dev.js +40 -41
- package/dist/context.d.ts +2 -2
- package/dist/context.js +2 -2
- package/dist/corpus.d.ts +8 -8
- package/dist/data.d.ts +8 -0
- package/dist/data.js +2 -2
- package/dist/datasets.d.ts +3 -1
- package/dist/datasets.js +39 -6
- package/dist/dev/host.js +6 -9
- package/dist/host.d.ts +15 -2
- package/dist/host.js +23 -3
- package/dist/index.d.ts +2 -3
- package/dist/index.js +1 -2
- package/dist/mount.d.ts +8 -5
- package/dist/mount.js +12 -6
- package/dist/parity.d.ts +25 -0
- package/dist/parity.js +70 -0
- package/dist/playwright.d.ts +1 -1
- package/dist/playwright.js +6 -2
- package/dist/react.d.ts +20 -23
- package/dist/react.js +77 -89
- package/dist/schema.d.ts +15 -0
- package/dist/schema.js +20 -0
- package/dist/testing.d.ts +25 -10
- package/dist/testing.js +64 -26
- package/dist/types.d.ts +43 -22
- package/dist/urls.d.ts +35 -0
- package/dist/urls.js +58 -0
- package/dist/vite.d.ts +3 -2
- package/dist/vite.js +26 -22
- package/package.json +9 -2
- package/schema/research.schema.json +126 -0
- package/dist/document-store.d.ts +0 -14
- package/dist/document-store.js +0 -78
- package/dist/documents.d.ts +0 -10
- package/dist/documents.js +0 -22
package/dist/testing.d.ts
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import type { ReactElement } from 'react';
|
|
2
|
+
import type { Collections } from './collections.gen.js';
|
|
2
3
|
import { type People } from './reader.js';
|
|
3
4
|
import type { AnyProject } from './mount.js';
|
|
5
|
+
export { parity, type Exchange } from './parity.js';
|
|
4
6
|
export { membersOf, readerOf, type People } from './reader.js';
|
|
5
7
|
/** What `testHost` is given besides the project; every field is optional. */
|
|
6
8
|
export interface TestHostOptions {
|
|
@@ -8,18 +10,22 @@ export interface TestHostOptions {
|
|
|
8
10
|
data?: Record<string, unknown>;
|
|
9
11
|
/** Each private dataset's pages, `{ dataset: { page: JSON } }`; the reader sees those `people` gives them. */
|
|
10
12
|
private?: Record<string, Record<string, unknown>>;
|
|
11
|
-
/**
|
|
12
|
-
|
|
13
|
+
/** The project's collections, as research.json's `collections`. */
|
|
14
|
+
collections?: Collections;
|
|
15
|
+
/** The items the project starts with, written in order, each as its `writer`, the reader by default; a refused one throws, naming its outcome. */
|
|
16
|
+
items?: {
|
|
17
|
+
collection: string;
|
|
18
|
+
id: string;
|
|
13
19
|
body: unknown;
|
|
14
20
|
writer?: string;
|
|
15
|
-
}
|
|
16
|
-
/** The project's people, as research.json's `people`: each is a member, and `reader` holds their `pages
|
|
21
|
+
}[];
|
|
22
|
+
/** The project's people, as research.json's `people`: each is a member, and `reader` holds their `pages`; without them, the reader is the one member. */
|
|
17
23
|
people?: People;
|
|
18
24
|
/** The project's roles, as research.json's `roles`; with them, `reader` must be in `people`. */
|
|
19
25
|
roles?: string[];
|
|
20
|
-
/** The reader's username, and the writer of every
|
|
26
|
+
/** The reader's username, and the writer of every write: `testHost` holds this one identity. */
|
|
21
27
|
reader?: string;
|
|
22
|
-
/** False to view the project as `reader` while signed in as another;
|
|
28
|
+
/** False to view the project as `reader` while signed in as another; writes are still written as `reader`. */
|
|
23
29
|
self?: boolean;
|
|
24
30
|
/** The path below the project, with search and hash. */
|
|
25
31
|
url?: string;
|
|
@@ -28,11 +34,20 @@ export interface TestHostOptions {
|
|
|
28
34
|
}
|
|
29
35
|
/**
|
|
30
36
|
* A project rendered through the frame and the mount a real host uses, at the
|
|
31
|
-
* path it names. Render `element` with any DOM renderer;
|
|
32
|
-
* the project navigated,
|
|
37
|
+
* path it names, its store in memory. Render `element` with any DOM renderer;
|
|
38
|
+
* `router` says where the project navigated, `items()` each item's current
|
|
39
|
+
* revision in write order, and `host` is the `Host` the frame provides.
|
|
33
40
|
*/
|
|
34
|
-
export declare function testHost(project: AnyProject, { data,
|
|
41
|
+
export declare function testHost(project: AnyProject, { data, collections, items, private: held, people, roles, reader, self, url, sessionLost, }?: TestHostOptions): {
|
|
35
42
|
element: ReactElement<unknown, string | import("react").JSXElementConstructor<any>>;
|
|
36
43
|
router: import("@tanstack/router-core").RouterCore<import("@tanstack/router-core").Route<import("@tanstack/react-router").Register, any, "/", "/", string, "__root__", undefined, {}, {}, import("@tanstack/react-router").AnyContext, import("@tanstack/react-router").AnyContext, {}, undefined, readonly [import("@tanstack/react-router").AnyRoute], unknown, unknown, unknown, undefined>, "preserve", false, import("@tanstack/history").RouterHistory, Record<string, any>>;
|
|
37
|
-
|
|
44
|
+
host: import("./types.js").Host;
|
|
45
|
+
items: () => {
|
|
46
|
+
collection: import("./collections.gen.js").components["schemas"]["CollectionName"];
|
|
47
|
+
writer: string;
|
|
48
|
+
id: import("./collections.gen.js").components["schemas"]["ItemID"];
|
|
49
|
+
revision: number;
|
|
50
|
+
sequence?: number;
|
|
51
|
+
body?: unknown;
|
|
52
|
+
}[];
|
|
38
53
|
};
|
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 {
|
|
5
|
-
import {
|
|
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
|
|
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;
|
|
13
|
-
* the project navigated,
|
|
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 = {},
|
|
16
|
-
const
|
|
17
|
-
|
|
18
|
-
|
|
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
|
-
|
|
22
|
-
|
|
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(
|
|
49
|
-
return { element, router,
|
|
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 { components } from './collections.gen.js';
|
|
2
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
|
|
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,36 +17,27 @@ 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
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
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;
|
|
37
|
-
body: T;
|
|
38
|
-
}
|
|
39
29
|
/**
|
|
40
30
|
* What a project declares of itself by augmenting this module:
|
|
41
|
-
* `datasets`, the
|
|
42
|
-
* roles as a union; `load` checks that ui/datasets.ts's
|
|
43
|
-
* research.json's
|
|
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.
|
|
44
35
|
*
|
|
45
36
|
* @example
|
|
46
37
|
* declare module '@metacensus/library-research' {
|
|
47
38
|
* interface Register {
|
|
48
39
|
* datasets: typeof datasets
|
|
40
|
+
* collections: typeof collections
|
|
49
41
|
* roles: (typeof roles)[number]
|
|
50
42
|
* }
|
|
51
43
|
* }
|
|
@@ -64,6 +56,35 @@ export type Schemas = Register extends {
|
|
|
64
56
|
export type Data<K extends keyof Schemas> = Schemas[K] extends {
|
|
65
57
|
parse(json: unknown): infer T;
|
|
66
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;
|
|
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][];
|
|
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'];
|
|
67
88
|
/** A person of the project. */
|
|
68
89
|
export interface Member {
|
|
69
90
|
/** The name the host signs them in as. */
|
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
|
+
}
|
package/dist/vite.d.ts
CHANGED
|
@@ -15,8 +15,9 @@ export declare function research({ projects, }: {
|
|
|
15
15
|
* Tailwind 4 for a host, as a plugin because a project's path comes from the
|
|
16
16
|
* host's environment, which a stylesheet's literal `@source` cannot hold. A
|
|
17
17
|
* host stylesheet importing `tailwindcss` gains each project's `ui/` as a
|
|
18
|
-
* source
|
|
19
|
-
*
|
|
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.
|
|
20
21
|
*/
|
|
21
22
|
export declare function tailwind({ projects, }: {
|
|
22
23
|
projects: Record<string, string>;
|
package/dist/vite.js
CHANGED
|
@@ -6,9 +6,9 @@ import { isCSSRequest, preprocessCSS, searchForWorkspaceRoot, } from 'vite';
|
|
|
6
6
|
import tailwindcss from '@tailwindcss/vite';
|
|
7
7
|
import { project, read } from './data.js';
|
|
8
8
|
import { checkProjectId } from './project-id.js';
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
const
|
|
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);
|
|
12
12
|
const virtual = 'virtual:research-projects';
|
|
13
13
|
const cssImport = /@(?:import|use|forward)\b/;
|
|
14
14
|
const cssComposes = /\bcomposes\s*:[^;}]*?\bfrom\s+(['"])([^'"]+)\1/g;
|
|
@@ -45,7 +45,9 @@ export function research({ projects, }) {
|
|
|
45
45
|
if (slugs.length > 1)
|
|
46
46
|
throw new Error(`${owned.join(', ')}: mixes ${slugs.join(' and ')}`);
|
|
47
47
|
const name = typeof pattern === 'string' ? pattern : pattern(info);
|
|
48
|
-
return slugs[0]
|
|
48
|
+
return slugs[0]
|
|
49
|
+
? `${built(projectRoot(slugs[0]))}/assets/${basename(name)}`
|
|
50
|
+
: name;
|
|
49
51
|
};
|
|
50
52
|
const sources = (asset) => asset.originalFileNames.map((file) => resolve(config.root, file));
|
|
51
53
|
/**
|
|
@@ -178,14 +180,14 @@ export function research({ projects, }) {
|
|
|
178
180
|
for (const [dataset, json] of Object.entries(datasets))
|
|
179
181
|
this.emitFile({
|
|
180
182
|
type: 'asset',
|
|
181
|
-
fileName:
|
|
183
|
+
fileName: built(urls.data(slug, dataset)),
|
|
182
184
|
source: JSON.stringify(json()),
|
|
183
185
|
});
|
|
184
186
|
for (const [dataset, held] of Object.entries(pages))
|
|
185
187
|
for (const [page, file] of Object.entries(held()))
|
|
186
188
|
this.emitFile({
|
|
187
189
|
type: 'asset',
|
|
188
|
-
fileName:
|
|
190
|
+
fileName: built(urls.private(slug, page, dataset)),
|
|
189
191
|
source: JSON.stringify(read(dir, file)),
|
|
190
192
|
});
|
|
191
193
|
}
|
|
@@ -257,8 +259,8 @@ export function research({ projects, }) {
|
|
|
257
259
|
continue;
|
|
258
260
|
const text = readFileSync(path, 'utf8');
|
|
259
261
|
for (const [slug, mark] of marks)
|
|
260
|
-
if (!inside(file,
|
|
261
|
-
this.error(`${file}: holds project ${slug}, outside ${
|
|
262
|
+
if (!inside(file, built(projectRoot(slug))) && mark.test(text))
|
|
263
|
+
this.error(`${file}: holds project ${slug}, outside ${built(projectRoot(slug))}/`);
|
|
262
264
|
}
|
|
263
265
|
},
|
|
264
266
|
},
|
|
@@ -268,24 +270,24 @@ export function research({ projects, }) {
|
|
|
268
270
|
configureServer(server) {
|
|
269
271
|
server.middlewares.use((req, res, next) => {
|
|
270
272
|
const path = req.url?.split('?')[0] ?? '';
|
|
271
|
-
const
|
|
272
|
-
? path.slice(config.base.length)
|
|
273
|
-
:
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
const dir = dirs.find(([s]) => s ===
|
|
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];
|
|
277
279
|
if (!dir)
|
|
278
280
|
return next();
|
|
279
|
-
|
|
281
|
+
const { project: slug, dataset } = route;
|
|
282
|
+
if (route.route === 'private') {
|
|
280
283
|
// Gates nothing: the host's dev server decides who loads which page.
|
|
284
|
+
const { page } = route;
|
|
281
285
|
const { pages } = project(dir);
|
|
282
|
-
const held = Object.hasOwn(pages,
|
|
283
|
-
? pages[pdataset]()
|
|
284
|
-
: {};
|
|
286
|
+
const held = Object.hasOwn(pages, dataset) ? pages[dataset]() : {};
|
|
285
287
|
const file = Object.hasOwn(held, page) ? held[page] : undefined;
|
|
286
288
|
if (!file) {
|
|
287
289
|
res.statusCode = 404;
|
|
288
|
-
return res.end(`${
|
|
290
|
+
return res.end(`${slug} has no private dataset "${dataset}" page "${page}"`);
|
|
289
291
|
}
|
|
290
292
|
res.setHeader('Content-Type', 'application/json');
|
|
291
293
|
return res.end(JSON.stringify(read(dir, file)));
|
|
@@ -306,8 +308,9 @@ export function research({ projects, }) {
|
|
|
306
308
|
* Tailwind 4 for a host, as a plugin because a project's path comes from the
|
|
307
309
|
* host's environment, which a stylesheet's literal `@source` cannot hold. A
|
|
308
310
|
* host stylesheet importing `tailwindcss` gains each project's `ui/` as a
|
|
309
|
-
* source
|
|
310
|
-
*
|
|
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.
|
|
311
314
|
*/
|
|
312
315
|
export function tailwind({ projects, }) {
|
|
313
316
|
// tailwindcss resolves from library-research, so a project's stylesheet
|
|
@@ -346,7 +349,8 @@ export function tailwind({ projects, }) {
|
|
|
346
349
|
if (uses('tailwindcss', 'import'))
|
|
347
350
|
return {
|
|
348
351
|
code: code +
|
|
349
|
-
dirs.map((dir) => `\n@source ${JSON.stringify(dir)};`).join('')
|
|
352
|
+
dirs.map((dir) => `\n@source ${JSON.stringify(dir)};`).join('') +
|
|
353
|
+
'\n@layer base { body { background-color: var(--mc-ground); color: var(--mc-ink); } }',
|
|
350
354
|
map: null,
|
|
351
355
|
};
|
|
352
356
|
},
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@metacensus/library-research",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.16.0",
|
|
4
4
|
"license": "AGPL-3.0-only",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -87,10 +87,17 @@
|
|
|
87
87
|
"eslint": "^9.39.5",
|
|
88
88
|
"eslint-plugin-react-hooks": "^7.1.1",
|
|
89
89
|
"jsdom": "^31.0.1",
|
|
90
|
+
"openapi-typescript": "^7.13.0",
|
|
90
91
|
"prettier": "^3.10.1",
|
|
91
92
|
"react": "^19.3.1",
|
|
92
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
|
}
|
|
@@ -66,6 +66,132 @@
|
|
|
66
66
|
],
|
|
67
67
|
"additionalProperties": false
|
|
68
68
|
}
|
|
69
|
+
},
|
|
70
|
+
"collections": {
|
|
71
|
+
"type": "object",
|
|
72
|
+
"description": "The collections section of a project's manifest, by collection name.\n\nOnly the project's members are ever allowed: a person who is not a member is refused `forbidden`, and a request with no session is refused `unauthenticated`.\n\nA manifest that fails one of these checks is refused whole:\n- each role a grant names is one the project declares;\n- each gate's collection exists and is a `log`;\n- each `body` compiles as JSON Schema.\n",
|
|
73
|
+
"propertyNames": {
|
|
74
|
+
"type": "string",
|
|
75
|
+
"pattern": "^[a-z][a-z0-9-]{0,63}$"
|
|
76
|
+
},
|
|
77
|
+
"additionalProperties": {
|
|
78
|
+
"type": "object",
|
|
79
|
+
"description": "A set of items, each keyed by (writer, id) within the collection. Only an item's writer writes it, so no one can take an id another person is using.\n\nA collection allows a person when any one of its grants holds; an empty list allows no one. A grant holds when all of its conditions hold.\n",
|
|
80
|
+
"additionalProperties": false,
|
|
81
|
+
"required": [
|
|
82
|
+
"mode",
|
|
83
|
+
"body",
|
|
84
|
+
"read",
|
|
85
|
+
"write"
|
|
86
|
+
],
|
|
87
|
+
"properties": {
|
|
88
|
+
"mode": {
|
|
89
|
+
"type": "string",
|
|
90
|
+
"enum": [
|
|
91
|
+
"document",
|
|
92
|
+
"log"
|
|
93
|
+
],
|
|
94
|
+
"description": "`document`: a write names the item's expected revision, `0` for a new item, and is refused `stale` unless the item is at that revision. A read returns each item's current revision. Earlier revisions stay stored and count toward the quota, but are never served.\n\n`log`: an entry is written once, at expected revision `0`; any other expected revision is `stale`. A second write of the same (writer, id) is refused `exists`. A read returns every entry, so the log is its writer's history, and no entry is replaced or deleted.\n"
|
|
95
|
+
},
|
|
96
|
+
"body": {
|
|
97
|
+
"type": "object",
|
|
98
|
+
"description": "A JSON Schema, draft 2020-12, that every item body written to the collection must satisfy. It holds no external `$ref`, and `format` is an annotation only."
|
|
99
|
+
},
|
|
100
|
+
"read": {
|
|
101
|
+
"type": "array",
|
|
102
|
+
"description": "The grants that allow a read. A read returns, in the store's sequence order, the items the person may read, which are those for which some grant holds; a member is never refused a read, and may be served nothing.\n",
|
|
103
|
+
"items": {
|
|
104
|
+
"type": "object",
|
|
105
|
+
"description": "A rule allowing a read. It holds when each condition it names holds, and names at least one.",
|
|
106
|
+
"additionalProperties": false,
|
|
107
|
+
"minProperties": 1,
|
|
108
|
+
"properties": {
|
|
109
|
+
"own": {
|
|
110
|
+
"type": "boolean",
|
|
111
|
+
"const": true,
|
|
112
|
+
"description": "The reader wrote the item."
|
|
113
|
+
},
|
|
114
|
+
"roles": {
|
|
115
|
+
"type": "array",
|
|
116
|
+
"minItems": 1,
|
|
117
|
+
"description": "The person's role in the project is one of these. The roles are the ones the project's research.json declares.",
|
|
118
|
+
"items": {
|
|
119
|
+
"type": "string"
|
|
120
|
+
}
|
|
121
|
+
},
|
|
122
|
+
"members": {
|
|
123
|
+
"type": "boolean",
|
|
124
|
+
"const": true,
|
|
125
|
+
"description": "The person opens the project: a member, an admin or a super admin."
|
|
126
|
+
},
|
|
127
|
+
"after": {
|
|
128
|
+
"type": "object",
|
|
129
|
+
"description": "Names one entry of a `log` collection in the same project: the entry with this `id` in this `collection`.\n\nThe first entry with that id opens the gate, whoever wrote it, provided the collection's write grants allowed that writer. Until then every grant that names the gate fails.\n\nA gate never closes: a log entry is never replaced or deleted, and the gate names only a log.\n",
|
|
130
|
+
"additionalProperties": false,
|
|
131
|
+
"required": [
|
|
132
|
+
"collection",
|
|
133
|
+
"id"
|
|
134
|
+
],
|
|
135
|
+
"properties": {
|
|
136
|
+
"collection": {
|
|
137
|
+
"type": "string",
|
|
138
|
+
"pattern": "^[a-z][a-z0-9-]{0,63}$"
|
|
139
|
+
},
|
|
140
|
+
"id": {
|
|
141
|
+
"type": "string",
|
|
142
|
+
"pattern": "^[A-Za-z0-9][A-Za-z0-9._:-]{0,199}$"
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
},
|
|
149
|
+
"write": {
|
|
150
|
+
"type": "array",
|
|
151
|
+
"description": "The grants that allow a write. A write is refused `forbidden` for an item the person may not write.",
|
|
152
|
+
"items": {
|
|
153
|
+
"type": "object",
|
|
154
|
+
"description": "A rule allowing a write. It holds when each condition it names holds, and names at least one.",
|
|
155
|
+
"additionalProperties": false,
|
|
156
|
+
"minProperties": 1,
|
|
157
|
+
"properties": {
|
|
158
|
+
"roles": {
|
|
159
|
+
"type": "array",
|
|
160
|
+
"minItems": 1,
|
|
161
|
+
"description": "The person's role in the project is one of these. The roles are the ones the project's research.json declares.",
|
|
162
|
+
"items": {
|
|
163
|
+
"type": "string"
|
|
164
|
+
}
|
|
165
|
+
},
|
|
166
|
+
"members": {
|
|
167
|
+
"type": "boolean",
|
|
168
|
+
"const": true,
|
|
169
|
+
"description": "The person opens the project: a member, an admin or a super admin."
|
|
170
|
+
},
|
|
171
|
+
"after": {
|
|
172
|
+
"type": "object",
|
|
173
|
+
"description": "Names one entry of a `log` collection in the same project: the entry with this `id` in this `collection`.\n\nThe first entry with that id opens the gate, whoever wrote it, provided the collection's write grants allowed that writer. Until then every grant that names the gate fails.\n\nA gate never closes: a log entry is never replaced or deleted, and the gate names only a log.\n",
|
|
174
|
+
"additionalProperties": false,
|
|
175
|
+
"required": [
|
|
176
|
+
"collection",
|
|
177
|
+
"id"
|
|
178
|
+
],
|
|
179
|
+
"properties": {
|
|
180
|
+
"collection": {
|
|
181
|
+
"type": "string",
|
|
182
|
+
"pattern": "^[a-z][a-z0-9-]{0,63}$"
|
|
183
|
+
},
|
|
184
|
+
"id": {
|
|
185
|
+
"type": "string",
|
|
186
|
+
"pattern": "^[A-Za-z0-9][A-Za-z0-9._:-]{0,199}$"
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
}
|
|
69
195
|
}
|
|
70
196
|
},
|
|
71
197
|
"required": [
|