1 | import { Client, Databases, ID } from "[email protected]"; |
2 |
|
3 | |
4 | * @param document_id ID of the document to be created. Leave blank to generate a unique ID. |
5 | */ |
6 | type Appwrite = { |
7 | endpoint: string; |
8 | project: string; |
9 | key: string; |
10 | self_signed: boolean; |
11 | }; |
12 | export async function main( |
13 | auth: Appwrite, |
14 | database_id: string, |
15 | collection_id: string, |
16 | document_data: Record<string | number, any>, |
17 | document_id?: string, |
18 | document_permissions?: string[], |
19 | ) { |
20 | const client = new Client() |
21 | .setEndpoint(auth.endpoint) |
22 | .setProject(auth.project) |
23 | .setKey(auth.key); |
24 | const db = new Databases(client); |
25 |
|
26 | return await db.createDocument( |
27 | database_id, |
28 | collection_id, |
29 | document_id || ID.unique(), |
30 | document_data, |
31 | document_permissions, |
32 | ); |
33 | } |
34 |
|