@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
@@ -0,0 +1,309 @@
1
+ import type { JSONSchema } from 'zod/v4/core';
2
+ export declare const collections: JSONSchema.JSONSchema;
3
+ export declare const writeRequest: JSONSchema.JSONSchema;
4
+ export declare const collectionName: {
5
+ readonly type: "string";
6
+ readonly pattern: "^[a-z][a-z0-9-]{0,63}$";
7
+ };
8
+ export declare const status: {
9
+ readonly unauthenticated: 401;
10
+ readonly forbidden: 403;
11
+ readonly invalid: 400;
12
+ readonly stale: 409;
13
+ readonly exists: 409;
14
+ readonly full: 507;
15
+ };
16
+ export declare const maxWriteBytes = 1048576;
17
+ export type Collections = components['schemas']['Collections'];
18
+ export interface paths {
19
+ "/api/projects/{project}/collections": {
20
+ parameters: {
21
+ query?: never;
22
+ header?: never;
23
+ path?: never;
24
+ cookie?: never;
25
+ };
26
+ get?: never;
27
+ put?: never;
28
+ post: operations["writeItems"];
29
+ delete?: never;
30
+ options?: never;
31
+ head?: never;
32
+ patch?: never;
33
+ trace?: never;
34
+ };
35
+ "/api/projects/{project}/collections/{collection}": {
36
+ parameters: {
37
+ query?: never;
38
+ header?: never;
39
+ path?: never;
40
+ cookie?: never;
41
+ };
42
+ get: operations["readItems"];
43
+ put?: never;
44
+ post?: never;
45
+ delete?: never;
46
+ options?: never;
47
+ head?: never;
48
+ patch?: never;
49
+ trace?: never;
50
+ };
51
+ }
52
+ export type webhooks = Record<string, never>;
53
+ export interface components {
54
+ schemas: {
55
+ WriteRequest: {
56
+ requestId: string;
57
+ items: components["schemas"]["WriteItem"][];
58
+ };
59
+ WriteItem: {
60
+ collection: components["schemas"]["CollectionName"];
61
+ id: components["schemas"]["ItemID"];
62
+ /** Format: int64 */
63
+ revision: number;
64
+ body: unknown;
65
+ };
66
+ CollectionName: string;
67
+ ItemID: string;
68
+ WriteResult: {
69
+ items: components["schemas"]["Item"][];
70
+ };
71
+ Item: {
72
+ collection: components["schemas"]["CollectionName"];
73
+ writer: string;
74
+ id: components["schemas"]["ItemID"];
75
+ /** Format: int64 */
76
+ revision: number;
77
+ /** Format: int64 */
78
+ sequence?: number;
79
+ body?: unknown;
80
+ };
81
+ Error: {
82
+ code: components["schemas"]["Outcome"];
83
+ conflicts?: components["schemas"]["Item"][];
84
+ };
85
+ /** @enum {string} */
86
+ Outcome: "ok" | "replayed" | "unauthenticated" | "forbidden" | "invalid" | "stale" | "exists" | "full";
87
+ ItemList: {
88
+ items: components["schemas"]["Item"][];
89
+ };
90
+ /**
91
+ * @description The collections section of a project's manifest, by collection name.
92
+ *
93
+ * Only 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`.
94
+ *
95
+ * A manifest that fails one of these checks is refused whole:
96
+ * - each role a grant names is one the project declares;
97
+ * - each gate's collection exists and is a `log`;
98
+ * - each `body` compiles as JSON Schema.
99
+ */
100
+ Collections: {
101
+ [key: string]: components["schemas"]["Collection"];
102
+ };
103
+ /**
104
+ * @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.
105
+ *
106
+ * A 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.
107
+ */
108
+ Collection: {
109
+ /**
110
+ * @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.
111
+ *
112
+ * `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.
113
+ * @enum {string}
114
+ */
115
+ mode: "document" | "log";
116
+ /** @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. */
117
+ body: Record<string, unknown>;
118
+ /** @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. */
119
+ read: components["schemas"]["ReadGrant"][];
120
+ /** @description The grants that allow a write. A write is refused `forbidden` for an item the person may not write. */
121
+ write: components["schemas"]["WriteGrant"][];
122
+ };
123
+ /** @description A rule allowing a read. It holds when each condition it names holds, and names at least one. */
124
+ ReadGrant: {
125
+ /**
126
+ * @description The reader wrote the item.
127
+ * @constant
128
+ */
129
+ own?: true;
130
+ roles?: components["schemas"]["GrantRoles"];
131
+ /**
132
+ * @description The person opens the project: a member, an admin or a super admin.
133
+ * @constant
134
+ */
135
+ members?: true;
136
+ after?: components["schemas"]["Gate"];
137
+ };
138
+ /** @description The person's role in the project is one of these. The roles are the ones the project's research.json declares. */
139
+ GrantRoles: string[];
140
+ /**
141
+ * @description Names one entry of a `log` collection in the same project: the entry with this `id` in this `collection`.
142
+ *
143
+ * The 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.
144
+ *
145
+ * A gate never closes: a log entry is never replaced or deleted, and the gate names only a log.
146
+ */
147
+ Gate: {
148
+ collection: components["schemas"]["CollectionName"];
149
+ id: components["schemas"]["ItemID"];
150
+ };
151
+ /** @description A rule allowing a write. It holds when each condition it names holds, and names at least one. */
152
+ WriteGrant: {
153
+ roles?: components["schemas"]["GrantRoles"];
154
+ /**
155
+ * @description The person opens the project: a member, an admin or a super admin.
156
+ * @constant
157
+ */
158
+ members?: true;
159
+ after?: components["schemas"]["Gate"];
160
+ };
161
+ };
162
+ responses: never;
163
+ parameters: {
164
+ ProjectID: string;
165
+ };
166
+ requestBodies: never;
167
+ headers: never;
168
+ pathItems: never;
169
+ }
170
+ export type $defs = Record<string, never>;
171
+ export interface operations {
172
+ writeItems: {
173
+ parameters: {
174
+ query?: never;
175
+ header?: never;
176
+ path: {
177
+ project: components["parameters"]["ProjectID"];
178
+ };
179
+ cookie?: never;
180
+ };
181
+ requestBody: {
182
+ content: {
183
+ "application/json": components["schemas"]["WriteRequest"];
184
+ };
185
+ };
186
+ responses: {
187
+ 200: {
188
+ headers: {
189
+ [name: string]: unknown;
190
+ };
191
+ content: {
192
+ "application/json": components["schemas"]["WriteResult"];
193
+ };
194
+ };
195
+ 201: {
196
+ headers: {
197
+ [name: string]: unknown;
198
+ };
199
+ content: {
200
+ "application/json": components["schemas"]["WriteResult"];
201
+ };
202
+ };
203
+ 400: {
204
+ headers: {
205
+ [name: string]: unknown;
206
+ };
207
+ content: {
208
+ "application/json": components["schemas"]["Error"];
209
+ };
210
+ };
211
+ 401: {
212
+ headers: {
213
+ [name: string]: unknown;
214
+ };
215
+ content: {
216
+ "application/json": components["schemas"]["Error"];
217
+ };
218
+ };
219
+ 403: {
220
+ headers: {
221
+ [name: string]: unknown;
222
+ };
223
+ content: {
224
+ "application/json": components["schemas"]["Error"];
225
+ };
226
+ };
227
+ 409: {
228
+ headers: {
229
+ [name: string]: unknown;
230
+ };
231
+ content: {
232
+ "application/json": components["schemas"]["Error"];
233
+ };
234
+ };
235
+ 413: {
236
+ headers: {
237
+ [name: string]: unknown;
238
+ };
239
+ content?: never;
240
+ };
241
+ 415: {
242
+ headers: {
243
+ [name: string]: unknown;
244
+ };
245
+ content?: never;
246
+ };
247
+ 507: {
248
+ headers: {
249
+ [name: string]: unknown;
250
+ };
251
+ content: {
252
+ "application/json": components["schemas"]["Error"];
253
+ };
254
+ };
255
+ };
256
+ };
257
+ readItems: {
258
+ parameters: {
259
+ query?: never;
260
+ header?: never;
261
+ path: {
262
+ project: components["parameters"]["ProjectID"];
263
+ collection: components["schemas"]["CollectionName"];
264
+ };
265
+ cookie?: never;
266
+ };
267
+ requestBody?: never;
268
+ responses: {
269
+ 200: {
270
+ headers: {
271
+ [name: string]: unknown;
272
+ };
273
+ content: {
274
+ "application/json": components["schemas"]["ItemList"];
275
+ };
276
+ };
277
+ 400: {
278
+ headers: {
279
+ [name: string]: unknown;
280
+ };
281
+ content: {
282
+ "application/json": components["schemas"]["Error"];
283
+ };
284
+ };
285
+ 401: {
286
+ headers: {
287
+ [name: string]: unknown;
288
+ };
289
+ content: {
290
+ "application/json": components["schemas"]["Error"];
291
+ };
292
+ };
293
+ 403: {
294
+ headers: {
295
+ [name: string]: unknown;
296
+ };
297
+ content: {
298
+ "application/json": components["schemas"]["Error"];
299
+ };
300
+ };
301
+ 404: {
302
+ headers: {
303
+ [name: string]: unknown;
304
+ };
305
+ content?: never;
306
+ };
307
+ };
308
+ };
309
+ }
@@ -0,0 +1,190 @@
1
+ export const collections = {
2
+ "type": "object",
3
+ "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",
4
+ "propertyNames": {
5
+ "type": "string",
6
+ "pattern": "^[a-z][a-z0-9-]{0,63}$"
7
+ },
8
+ "additionalProperties": {
9
+ "type": "object",
10
+ "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",
11
+ "additionalProperties": false,
12
+ "required": [
13
+ "mode",
14
+ "body",
15
+ "read",
16
+ "write"
17
+ ],
18
+ "properties": {
19
+ "mode": {
20
+ "type": "string",
21
+ "enum": [
22
+ "document",
23
+ "log"
24
+ ],
25
+ "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"
26
+ },
27
+ "body": {
28
+ "type": "object",
29
+ "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."
30
+ },
31
+ "read": {
32
+ "type": "array",
33
+ "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",
34
+ "items": {
35
+ "type": "object",
36
+ "description": "A rule allowing a read. It holds when each condition it names holds, and names at least one.",
37
+ "additionalProperties": false,
38
+ "minProperties": 1,
39
+ "properties": {
40
+ "own": {
41
+ "type": "boolean",
42
+ "const": true,
43
+ "description": "The reader wrote the item."
44
+ },
45
+ "roles": {
46
+ "type": "array",
47
+ "minItems": 1,
48
+ "description": "The person's role in the project is one of these. The roles are the ones the project's research.json declares.",
49
+ "items": {
50
+ "type": "string"
51
+ }
52
+ },
53
+ "members": {
54
+ "type": "boolean",
55
+ "const": true,
56
+ "description": "The person opens the project: a member, an admin or a super admin."
57
+ },
58
+ "after": {
59
+ "type": "object",
60
+ "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",
61
+ "additionalProperties": false,
62
+ "required": [
63
+ "collection",
64
+ "id"
65
+ ],
66
+ "properties": {
67
+ "collection": {
68
+ "type": "string",
69
+ "pattern": "^[a-z][a-z0-9-]{0,63}$"
70
+ },
71
+ "id": {
72
+ "type": "string",
73
+ "pattern": "^[A-Za-z0-9][A-Za-z0-9._:-]{0,199}$"
74
+ }
75
+ }
76
+ }
77
+ }
78
+ }
79
+ },
80
+ "write": {
81
+ "type": "array",
82
+ "description": "The grants that allow a write. A write is refused `forbidden` for an item the person may not write.",
83
+ "items": {
84
+ "type": "object",
85
+ "description": "A rule allowing a write. It holds when each condition it names holds, and names at least one.",
86
+ "additionalProperties": false,
87
+ "minProperties": 1,
88
+ "properties": {
89
+ "roles": {
90
+ "type": "array",
91
+ "minItems": 1,
92
+ "description": "The person's role in the project is one of these. The roles are the ones the project's research.json declares.",
93
+ "items": {
94
+ "type": "string"
95
+ }
96
+ },
97
+ "members": {
98
+ "type": "boolean",
99
+ "const": true,
100
+ "description": "The person opens the project: a member, an admin or a super admin."
101
+ },
102
+ "after": {
103
+ "type": "object",
104
+ "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",
105
+ "additionalProperties": false,
106
+ "required": [
107
+ "collection",
108
+ "id"
109
+ ],
110
+ "properties": {
111
+ "collection": {
112
+ "type": "string",
113
+ "pattern": "^[a-z][a-z0-9-]{0,63}$"
114
+ },
115
+ "id": {
116
+ "type": "string",
117
+ "pattern": "^[A-Za-z0-9][A-Za-z0-9._:-]{0,199}$"
118
+ }
119
+ }
120
+ }
121
+ }
122
+ }
123
+ }
124
+ }
125
+ }
126
+ };
127
+ export const writeRequest = {
128
+ "type": "object",
129
+ "additionalProperties": false,
130
+ "required": [
131
+ "requestId",
132
+ "items"
133
+ ],
134
+ "properties": {
135
+ "requestId": {
136
+ "type": "string",
137
+ "minLength": 1,
138
+ "maxLength": 128
139
+ },
140
+ "items": {
141
+ "type": "array",
142
+ "minItems": 1,
143
+ "maxItems": 100,
144
+ "items": {
145
+ "type": "object",
146
+ "additionalProperties": false,
147
+ "required": [
148
+ "collection",
149
+ "id",
150
+ "revision",
151
+ "body"
152
+ ],
153
+ "properties": {
154
+ "collection": {
155
+ "type": "string",
156
+ "pattern": "^[a-z][a-z0-9-]{0,63}$"
157
+ },
158
+ "id": {
159
+ "type": "string",
160
+ "pattern": "^[A-Za-z0-9][A-Za-z0-9._:-]{0,199}$"
161
+ },
162
+ "revision": {
163
+ "type": "integer",
164
+ "format": "int64",
165
+ "minimum": 0
166
+ },
167
+ "body": {
168
+ "x-go-type": "json.RawMessage",
169
+ "x-go-type-import": {
170
+ "path": "encoding/json"
171
+ }
172
+ }
173
+ }
174
+ }
175
+ }
176
+ }
177
+ };
178
+ export const collectionName = {
179
+ "type": "string",
180
+ "pattern": "^[a-z][a-z0-9-]{0,63}$"
181
+ };
182
+ export const status = {
183
+ "unauthenticated": 401,
184
+ "forbidden": 403,
185
+ "invalid": 400,
186
+ "stale": 409,
187
+ "exists": 409,
188
+ "full": 507
189
+ };
190
+ export const maxWriteBytes = 1048576;
@@ -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
- }