@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.
- package/README.md +65 -20
- 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/add.js +29 -12
- package/dist/commands/dev.js +48 -44
- package/dist/commands/reshape.d.ts +2 -0
- package/dist/commands/reshape.js +21 -0
- package/dist/context.d.ts +5 -3
- package/dist/context.js +4 -2
- package/dist/corpus.d.ts +432 -0
- package/dist/corpus.js +348 -0
- package/dist/data.d.ts +13 -6
- package/dist/data.js +27 -15
- package/dist/datasets.d.ts +4 -1
- package/dist/datasets.js +48 -8
- package/dist/dev/host.js +6 -9
- package/dist/host.d.ts +17 -2
- package/dist/host.js +26 -2
- package/dist/index.d.ts +3 -3
- package/dist/index.js +2 -2
- package/dist/mount.d.ts +11 -4
- package/dist/mount.js +15 -9
- package/dist/papers.js +3 -2
- package/dist/parity.d.ts +25 -0
- package/dist/parity.js +70 -0
- package/dist/playwright.d.ts +2 -2
- package/dist/playwright.js +30 -8
- package/dist/project-id.d.ts +4 -0
- package/dist/project-id.js +7 -0
- package/dist/react.d.ts +32 -42
- package/dist/react.js +121 -118
- package/dist/schema.d.ts +19 -34
- package/dist/schema.js +47 -31
- package/dist/testing.d.ts +26 -11
- package/dist/testing.js +64 -26
- package/dist/types.d.ts +85 -26
- package/dist/urls.d.ts +35 -0
- package/dist/urls.js +58 -0
- package/dist/vite-config.js +2 -12
- package/dist/vite.d.ts +11 -2
- package/dist/vite.js +79 -25
- package/dist/zod.d.ts +2 -0
- package/dist/zod.js +4 -0
- package/package.json +19 -12
- package/schema/corpus.schema.json +3949 -29
- package/schema/project-id.schema.json +6 -0
- package/schema/research.schema.json +130 -2
- 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
|
@@ -14,7 +14,8 @@
|
|
|
14
14
|
},
|
|
15
15
|
"additionalProperties": {
|
|
16
16
|
"type": "string",
|
|
17
|
-
"pattern": "^(?!\\/)(?!.*\\.\\.)
|
|
17
|
+
"pattern": "^(?!\\/)(?!.*\\.\\.)(?=.)[^*?[\\]{}()!]*(?:\\*[^*?[\\]{}()!]*)?$",
|
|
18
|
+
"description": "a glob that is relative, has no .., has at most one *, and has none of ?[]{}()!"
|
|
18
19
|
}
|
|
19
20
|
},
|
|
20
21
|
"private": {
|
|
@@ -25,7 +26,8 @@
|
|
|
25
26
|
},
|
|
26
27
|
"additionalProperties": {
|
|
27
28
|
"type": "string",
|
|
28
|
-
"pattern": "^(?!\\/)(?!.*\\.\\.)
|
|
29
|
+
"pattern": "^(?!\\/)(?!.*\\.\\.)(?=.)[^*?[\\]{}()!]*\\*[^*?[\\]{}()!]*$",
|
|
30
|
+
"description": "a glob that is relative, has no .., has exactly one *, and has none of ?[]{}()!"
|
|
29
31
|
}
|
|
30
32
|
},
|
|
31
33
|
"roles": {
|
|
@@ -64,6 +66,132 @@
|
|
|
64
66
|
],
|
|
65
67
|
"additionalProperties": false
|
|
66
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
|
+
}
|
|
67
195
|
}
|
|
68
196
|
},
|
|
69
197
|
"required": [
|
package/dist/document-store.d.ts
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import type { Doc } from './types.js';
|
|
2
|
-
/**
|
|
3
|
-
* The project's document store as service-api-research answers it: the same
|
|
4
|
-
* routes, envelope, id grammar, size limit and conditions, held in memory. The
|
|
5
|
-
* dev host and the test host serve their documents from it.
|
|
6
|
-
*/
|
|
7
|
-
export declare function documentStore(seed?: Record<string, {
|
|
8
|
-
body: unknown;
|
|
9
|
-
writer?: string;
|
|
10
|
-
}>, seedWriter?: string): {
|
|
11
|
-
/** Answers a request for `/documents[/id]`; `writer` is the session's person. */
|
|
12
|
-
handle(request: Request, writer: string): Promise<Response>;
|
|
13
|
-
all: () => Doc<unknown>[];
|
|
14
|
-
};
|
package/dist/document-store.js
DELETED
|
@@ -1,78 +0,0 @@
|
|
|
1
|
-
import { idPattern, prefixPattern, documentId } from './documents.js';
|
|
2
|
-
const limit = 256 * 1024;
|
|
3
|
-
const json = (status, value, revision) => new Response(JSON.stringify(value), {
|
|
4
|
-
status,
|
|
5
|
-
headers: {
|
|
6
|
-
'Content-Type': 'application/json',
|
|
7
|
-
'Cache-Control': 'private, no-cache',
|
|
8
|
-
...(revision === undefined ? {} : { ETag: `"${revision}"` }),
|
|
9
|
-
},
|
|
10
|
-
});
|
|
11
|
-
const refuse = (status, why) => new Response(why, { status, headers: { 'Content-Type': 'text/plain' } });
|
|
12
|
-
/**
|
|
13
|
-
* The project's document store as service-api-research answers it: the same
|
|
14
|
-
* routes, envelope, id grammar, size limit and conditions, held in memory. The
|
|
15
|
-
* dev host and the test host serve their documents from it.
|
|
16
|
-
*/
|
|
17
|
-
export function documentStore(seed = {}, seedWriter = 'test') {
|
|
18
|
-
const docs = new Map();
|
|
19
|
-
let revision = 0;
|
|
20
|
-
for (const [id, { body, writer = seedWriter }] of Object.entries(seed))
|
|
21
|
-
docs.set(documentId(id), { id, writer, revision: ++revision, body });
|
|
22
|
-
/** Every document, sorted by id. */
|
|
23
|
-
const all = () => [...docs.values()].sort((a, b) => (a.id < b.id ? -1 : a.id > b.id ? 1 : 0));
|
|
24
|
-
async function put(request, id, writer) {
|
|
25
|
-
if (!idPattern.test(id))
|
|
26
|
-
return refuse(400, `${id}: not a document id`);
|
|
27
|
-
if (!request.headers.get('Content-Type')?.startsWith('application/json'))
|
|
28
|
-
return refuse(415, 'the body is not application/json');
|
|
29
|
-
const match = request.headers.get('If-Match');
|
|
30
|
-
const none = request.headers.get('If-None-Match');
|
|
31
|
-
if ((match !== null && !/^"\d+"$/.test(match)) ||
|
|
32
|
-
(none !== null && none !== '*'))
|
|
33
|
-
return refuse(400, 'a condition header is malformed');
|
|
34
|
-
const text = await request.text();
|
|
35
|
-
if (new TextEncoder().encode(text).length > limit)
|
|
36
|
-
return refuse(413, `the body is over ${limit} bytes`);
|
|
37
|
-
let body;
|
|
38
|
-
try {
|
|
39
|
-
body = JSON.parse(text);
|
|
40
|
-
}
|
|
41
|
-
catch {
|
|
42
|
-
return refuse(400, 'the body is not valid JSON');
|
|
43
|
-
}
|
|
44
|
-
const held = docs.get(id);
|
|
45
|
-
if ((none !== null && held) ||
|
|
46
|
-
(match !== null && held?.revision !== Number(match.slice(1, -1))))
|
|
47
|
-
return refuse(412, 'a condition does not hold');
|
|
48
|
-
const doc = { id, writer, revision: ++revision, body };
|
|
49
|
-
docs.set(id, doc);
|
|
50
|
-
return json(held ? 200 : 201, doc, doc.revision);
|
|
51
|
-
}
|
|
52
|
-
return {
|
|
53
|
-
/** Answers a request for `/documents[/id]`; `writer` is the session's person. */
|
|
54
|
-
async handle(request, writer) {
|
|
55
|
-
const { pathname, searchParams } = new URL(request.url);
|
|
56
|
-
const id = pathname.match(/\/documents(?:\/([^/]*))?$/)?.[1];
|
|
57
|
-
if (request.method === 'PUT' && id !== undefined)
|
|
58
|
-
return put(request, id, writer);
|
|
59
|
-
if (request.method !== 'GET')
|
|
60
|
-
return refuse(405, 'method not allowed');
|
|
61
|
-
if (id === undefined) {
|
|
62
|
-
const prefix = searchParams.get('prefix') ?? '';
|
|
63
|
-
if (!prefixPattern.test(prefix))
|
|
64
|
-
return refuse(400, `${prefix}: not a document prefix`);
|
|
65
|
-
return json(200, {
|
|
66
|
-
items: all().filter((doc) => doc.id.startsWith(prefix)),
|
|
67
|
-
});
|
|
68
|
-
}
|
|
69
|
-
if (!idPattern.test(id))
|
|
70
|
-
return refuse(400, `${id}: not a document id`);
|
|
71
|
-
const doc = docs.get(id);
|
|
72
|
-
return doc
|
|
73
|
-
? json(200, doc, doc.revision)
|
|
74
|
-
: refuse(404, 'no such document');
|
|
75
|
-
},
|
|
76
|
-
all,
|
|
77
|
-
};
|
|
78
|
-
}
|
package/dist/documents.d.ts
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
/** A document request the host answered with a status the library does not read as data. */
|
|
2
|
-
export declare class DocumentError extends Error {
|
|
3
|
-
/** The HTTP status: 412 when a condition did not hold, 413 over the size limit. */
|
|
4
|
-
status: number;
|
|
5
|
-
constructor(status: number, message: string);
|
|
6
|
-
}
|
|
7
|
-
export declare const idPattern: RegExp;
|
|
8
|
-
export declare const prefixPattern: RegExp;
|
|
9
|
-
export declare function documentId(id: string): string;
|
|
10
|
-
export declare function documentPrefix(prefix: string): string;
|
package/dist/documents.js
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
/** A document request the host answered with a status the library does not read as data. */
|
|
2
|
-
export class DocumentError extends Error {
|
|
3
|
-
/** The HTTP status: 412 when a condition did not hold, 413 over the size limit. */
|
|
4
|
-
status;
|
|
5
|
-
constructor(status, message) {
|
|
6
|
-
super(message);
|
|
7
|
-
this.name = 'DocumentError';
|
|
8
|
-
this.status = status;
|
|
9
|
-
}
|
|
10
|
-
}
|
|
11
|
-
export const idPattern = /^[A-Za-z0-9][A-Za-z0-9._-]{0,127}$/;
|
|
12
|
-
export const prefixPattern = /^[A-Za-z0-9._-]*$/;
|
|
13
|
-
export function documentId(id) {
|
|
14
|
-
if (!idPattern.test(id))
|
|
15
|
-
throw new Error(`document id "${id}": must match ${idPattern}`);
|
|
16
|
-
return id;
|
|
17
|
-
}
|
|
18
|
-
export function documentPrefix(prefix) {
|
|
19
|
-
if (!prefixPattern.test(prefix))
|
|
20
|
-
throw new Error(`document prefix "${prefix}": must match ${prefixPattern}`);
|
|
21
|
-
return prefix;
|
|
22
|
-
}
|