@oaiz/sdk 0.0.0-stage → 0.1.4128
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/LICENSE +21 -0
- package/README.md +484 -2
- package/dist/index.d.ts +2669 -0
- package/dist/index.js +3706 -0
- package/dist/test.d.mts +63 -0
- package/dist/test.mjs +2495 -0
- package/package.json +61 -4
package/dist/test.d.mts
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { Plugin } from "vite";
|
|
2
|
+
interface OaizTestOptions {
|
|
3
|
+
/** The app's tests folder, relative to the Vite root: `databases/` and `members.json`. */
|
|
4
|
+
directory?: string;
|
|
5
|
+
}
|
|
6
|
+
/**
|
|
7
|
+
* Serves OAIZ sign-in, row requests and function calls under `/__oaiz-test/` from local test
|
|
8
|
+
* databases, on the dev server of `vite --mode oaiz-test` only. The folder is read on the first
|
|
9
|
+
* such request and again on every reset request.
|
|
10
|
+
*/
|
|
11
|
+
export declare function oaizTest({ directory }?: OaizTestOptions): Plugin;
|
|
12
|
+
interface OaizTestServerOptions {
|
|
13
|
+
/**
|
|
14
|
+
* The app's tests folder: `databases/<id>.sql` is the schema of the database with that id,
|
|
15
|
+
* `databases/<id>.seed.sql` its seed, and `members.json` who can sign in.
|
|
16
|
+
*/
|
|
17
|
+
directory: string;
|
|
18
|
+
}
|
|
19
|
+
/** Answers an app's OAIZ requests under `/__oaiz-test/` from one local test database per id. */
|
|
20
|
+
interface OaizTestServer {
|
|
21
|
+
handle(request: Request): Promise<Response>;
|
|
22
|
+
/** An access token that signs memberId in to the app clientId. */
|
|
23
|
+
issueToken(memberId: string, clientId: string): string;
|
|
24
|
+
/**
|
|
25
|
+
* Reads the folder again, then empties every open database and runs its seed. A database whose
|
|
26
|
+
* schema file changed is built again; one whose schema file is gone is closed.
|
|
27
|
+
*/
|
|
28
|
+
reset(): Promise<void>;
|
|
29
|
+
close(): Promise<void>;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Reads the folder and signs in its members. A database is built from its schema and seeded on its
|
|
33
|
+
* first request, so a test that reads one of an app's databases runs one PGlite.
|
|
34
|
+
*/
|
|
35
|
+
export declare function createTestServer(options: OaizTestServerOptions): Promise<OaizTestServer>;
|
|
36
|
+
/** A team of the test organisation. */
|
|
37
|
+
interface OaizTestTeam {
|
|
38
|
+
id: string;
|
|
39
|
+
name: string;
|
|
40
|
+
}
|
|
41
|
+
/** A member of the test organisation who can sign in to the app. */
|
|
42
|
+
interface OaizTestMember {
|
|
43
|
+
id: string;
|
|
44
|
+
name: string;
|
|
45
|
+
/** An address on `example.test`, never a real one. */
|
|
46
|
+
email: string;
|
|
47
|
+
/** The ids of the member's teams. */
|
|
48
|
+
teams?: string[];
|
|
49
|
+
/** The member's organisation role; `member` when omitted. */
|
|
50
|
+
role?: "member" | "administrator";
|
|
51
|
+
}
|
|
52
|
+
/** The grant the app has on one database. */
|
|
53
|
+
type OaizTestGrant = "view" | "edit";
|
|
54
|
+
/**
|
|
55
|
+
* `tests/members.json`: who can sign in, and the app's grant on each database. A database the
|
|
56
|
+
* grants leave out gets `edit`.
|
|
57
|
+
*/
|
|
58
|
+
interface OaizTestMembers {
|
|
59
|
+
teams: OaizTestTeam[];
|
|
60
|
+
members: OaizTestMember[];
|
|
61
|
+
grants: Record<string, OaizTestGrant>;
|
|
62
|
+
}
|
|
63
|
+
export type { OaizTestGrant, OaizTestMember, OaizTestMembers, OaizTestOptions, OaizTestServer, OaizTestServerOptions, OaizTestTeam };
|