@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/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
|
-
}
|