@zeroin.earth/appwrite-graphql 0.13.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/dist/index.js ADDED
@@ -0,0 +1,808 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __export = (target, all) => {
6
+ for (var name in all)
7
+ __defProp(target, name, { get: all[name], enumerable: true });
8
+ };
9
+ var __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from === "object" || typeof from === "function") {
11
+ for (let key of __getOwnPropNames(from))
12
+ if (!__hasOwnProp.call(to, key) && key !== except)
13
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
+ }
15
+ return to;
16
+ };
17
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
+
19
+ // src/index.ts
20
+ var src_exports = {};
21
+ __export(src_exports, {
22
+ fragments: () => fragments,
23
+ getFragmentData: () => getFragmentData,
24
+ useAccount: () => useAccount,
25
+ useAppwrite: () => useAppwrite,
26
+ useCollection: () => useCollection,
27
+ useCreateDocument: () => useCreateDocument,
28
+ useDocument: () => useDocument,
29
+ useFunction: () => useFunction,
30
+ useLogin: () => useLogin,
31
+ useLogout: () => useLogout,
32
+ useMutation: () => useMutation,
33
+ usePasswordRecovery: () => usePasswordRecovery,
34
+ useQuery: () => useQuery,
35
+ useQueryClient: () => useQueryClient,
36
+ useResetPassword: () => useResetPassword,
37
+ useSignUp: () => useSignUp,
38
+ useVerification: () => useVerification
39
+ });
40
+ module.exports = __toCommonJS(src_exports);
41
+
42
+ // src/useAppwrite.ts
43
+ var import_react = require("react");
44
+ var import_appwrite = require("appwrite");
45
+ var import_graphql = require("graphql");
46
+ var import_jotai = require("jotai");
47
+ var client = new import_appwrite.Client();
48
+ var endpoint = process.env.APPWRITE_ENDPOINT ?? process.env.NEXT_PUBLIC_APPWRITE_URL ?? "http://localhost/v1";
49
+ var projectId = process.env.APPWRITE_PROJECT_ID ?? process.env.NEXT_PUBLIC_APPWRITE_PROJECT_ID ?? "[PROJECT_ID]";
50
+ client.setEndpoint(endpoint).setProject(projectId);
51
+ var account = new import_appwrite.Account(client);
52
+ var graphql = new import_appwrite.Graphql(client);
53
+ var AccountAtom = (0, import_jotai.atom)(account);
54
+ var GraphqlAtom = (0, import_jotai.atom)(graphql);
55
+ function useAppwrite() {
56
+ const [account2] = (0, import_jotai.useAtom)(AccountAtom);
57
+ const [graphqlAppwrite] = (0, import_jotai.useAtom)(GraphqlAtom);
58
+ const graphql2 = (0, import_react.useMemo)(
59
+ () => ({
60
+ client: graphqlAppwrite.client,
61
+ query: async ({
62
+ query,
63
+ variables
64
+ }) => {
65
+ const { data, errors } = await graphqlAppwrite.query({
66
+ query: (0, import_graphql.print)(query),
67
+ variables
68
+ });
69
+ return { data, errors };
70
+ },
71
+ mutation: async ({
72
+ query,
73
+ variables
74
+ }) => {
75
+ const { data, errors } = await graphqlAppwrite.mutation({
76
+ query: (0, import_graphql.print)(query),
77
+ variables
78
+ });
79
+ return { data, errors };
80
+ }
81
+ }),
82
+ [graphqlAppwrite]
83
+ );
84
+ return {
85
+ account: account2,
86
+ graphql: graphql2
87
+ };
88
+ }
89
+
90
+ // src/useMutation.ts
91
+ var import_react_query2 = require("@tanstack/react-query");
92
+
93
+ // src/useQueryClient.ts
94
+ var import_jotai3 = require("jotai");
95
+
96
+ // src/states/query.ts
97
+ var import_react_query = require("@tanstack/react-query");
98
+ var import_jotai2 = require("jotai");
99
+ var queryClient = new import_react_query.QueryClient();
100
+ var QueryAtom = (0, import_jotai2.atom)(queryClient);
101
+
102
+ // src/useQueryClient.ts
103
+ function useQueryClient() {
104
+ const [queryClient2] = (0, import_jotai3.useAtom)(QueryAtom);
105
+ return queryClient2;
106
+ }
107
+
108
+ // src/useMutation.ts
109
+ function useMutation(options) {
110
+ const queryClient2 = useQueryClient();
111
+ return (0, import_react_query2.useMutation)(options, queryClient2);
112
+ }
113
+
114
+ // src/useQuery.ts
115
+ var import_react_query3 = require("@tanstack/react-query");
116
+ function useQuery(options) {
117
+ const queryClient2 = useQueryClient();
118
+ return (0, import_react_query3.useQuery)(options, queryClient2);
119
+ }
120
+
121
+ // src/account/useAccount.ts
122
+ var import_react2 = require("react");
123
+ var import_immer = require("immer");
124
+
125
+ // src/__generated__/graphql.ts
126
+ var Account_UserFragmentFragmentDoc = { "kind": "Document", "definitions": [{ "kind": "FragmentDefinition", "name": { "kind": "Name", "value": "Account_UserFragment" }, "typeCondition": { "kind": "NamedType", "name": { "kind": "Name", "value": "User" } }, "selectionSet": { "kind": "SelectionSet", "selections": [{ "kind": "Field", "name": { "kind": "Name", "value": "name" } }, { "kind": "Field", "name": { "kind": "Name", "value": "email" } }, { "kind": "Field", "name": { "kind": "Name", "value": "prefs" }, "selectionSet": { "kind": "SelectionSet", "selections": [{ "kind": "Field", "name": { "kind": "Name", "value": "data" } }] } }] } }] };
127
+ var AccountGetDocument = { "kind": "Document", "definitions": [{ "kind": "OperationDefinition", "operation": "query", "name": { "kind": "Name", "value": "AccountGet" }, "selectionSet": { "kind": "SelectionSet", "selections": [{ "kind": "Field", "name": { "kind": "Name", "value": "accountGet" }, "selectionSet": { "kind": "SelectionSet", "selections": [{ "kind": "FragmentSpread", "name": { "kind": "Name", "value": "Account_UserFragment" } }] } }] } }, { "kind": "FragmentDefinition", "name": { "kind": "Name", "value": "Account_UserFragment" }, "typeCondition": { "kind": "NamedType", "name": { "kind": "Name", "value": "User" } }, "selectionSet": { "kind": "SelectionSet", "selections": [{ "kind": "Field", "name": { "kind": "Name", "value": "name" } }, { "kind": "Field", "name": { "kind": "Name", "value": "email" } }, { "kind": "Field", "name": { "kind": "Name", "value": "prefs" }, "selectionSet": { "kind": "SelectionSet", "selections": [{ "kind": "Field", "name": { "kind": "Name", "value": "data" } }] } }] } }] };
128
+ var CreateEmailSessionDocument = { "kind": "Document", "definitions": [{ "kind": "OperationDefinition", "operation": "mutation", "name": { "kind": "Name", "value": "CreateEmailSession" }, "variableDefinitions": [{ "kind": "VariableDefinition", "variable": { "kind": "Variable", "name": { "kind": "Name", "value": "email" } }, "type": { "kind": "NonNullType", "type": { "kind": "NamedType", "name": { "kind": "Name", "value": "String" } } } }, { "kind": "VariableDefinition", "variable": { "kind": "Variable", "name": { "kind": "Name", "value": "password" } }, "type": { "kind": "NonNullType", "type": { "kind": "NamedType", "name": { "kind": "Name", "value": "String" } } } }], "selectionSet": { "kind": "SelectionSet", "selections": [{ "kind": "Field", "name": { "kind": "Name", "value": "accountCreateEmailSession" }, "arguments": [{ "kind": "Argument", "name": { "kind": "Name", "value": "email" }, "value": { "kind": "Variable", "name": { "kind": "Name", "value": "email" } } }, { "kind": "Argument", "name": { "kind": "Name", "value": "password" }, "value": { "kind": "Variable", "name": { "kind": "Name", "value": "password" } } }], "selectionSet": { "kind": "SelectionSet", "selections": [{ "kind": "Field", "name": { "kind": "Name", "value": "userId" } }, { "kind": "Field", "name": { "kind": "Name", "value": "expire" } }, { "kind": "Field", "name": { "kind": "Name", "value": "current" } }] } }] } }] };
129
+ var DeleteSessionDocument = { "kind": "Document", "definitions": [{ "kind": "OperationDefinition", "operation": "mutation", "name": { "kind": "Name", "value": "DeleteSession" }, "variableDefinitions": [{ "kind": "VariableDefinition", "variable": { "kind": "Variable", "name": { "kind": "Name", "value": "sessionId" } }, "type": { "kind": "NonNullType", "type": { "kind": "NamedType", "name": { "kind": "Name", "value": "String" } } } }], "selectionSet": { "kind": "SelectionSet", "selections": [{ "kind": "Field", "name": { "kind": "Name", "value": "accountDeleteSession" }, "arguments": [{ "kind": "Argument", "name": { "kind": "Name", "value": "sessionId" }, "value": { "kind": "Variable", "name": { "kind": "Name", "value": "sessionId" } } }], "selectionSet": { "kind": "SelectionSet", "selections": [{ "kind": "Field", "name": { "kind": "Name", "value": "status" } }] } }] } }] };
130
+ var CreateRecoveryDocument = { "kind": "Document", "definitions": [{ "kind": "OperationDefinition", "operation": "mutation", "name": { "kind": "Name", "value": "CreateRecovery" }, "variableDefinitions": [{ "kind": "VariableDefinition", "variable": { "kind": "Variable", "name": { "kind": "Name", "value": "email" } }, "type": { "kind": "NonNullType", "type": { "kind": "NamedType", "name": { "kind": "Name", "value": "String" } } } }, { "kind": "VariableDefinition", "variable": { "kind": "Variable", "name": { "kind": "Name", "value": "url" } }, "type": { "kind": "NonNullType", "type": { "kind": "NamedType", "name": { "kind": "Name", "value": "String" } } } }], "selectionSet": { "kind": "SelectionSet", "selections": [{ "kind": "Field", "name": { "kind": "Name", "value": "accountCreateRecovery" }, "arguments": [{ "kind": "Argument", "name": { "kind": "Name", "value": "email" }, "value": { "kind": "Variable", "name": { "kind": "Name", "value": "email" } } }, { "kind": "Argument", "name": { "kind": "Name", "value": "url" }, "value": { "kind": "Variable", "name": { "kind": "Name", "value": "url" } } }], "selectionSet": { "kind": "SelectionSet", "selections": [{ "kind": "Field", "name": { "kind": "Name", "value": "expire" } }] } }] } }] };
131
+ var UpdateRecoveryDocument = { "kind": "Document", "definitions": [{ "kind": "OperationDefinition", "operation": "mutation", "name": { "kind": "Name", "value": "UpdateRecovery" }, "variableDefinitions": [{ "kind": "VariableDefinition", "variable": { "kind": "Variable", "name": { "kind": "Name", "value": "userId" } }, "type": { "kind": "NonNullType", "type": { "kind": "NamedType", "name": { "kind": "Name", "value": "String" } } } }, { "kind": "VariableDefinition", "variable": { "kind": "Variable", "name": { "kind": "Name", "value": "secret" } }, "type": { "kind": "NonNullType", "type": { "kind": "NamedType", "name": { "kind": "Name", "value": "String" } } } }, { "kind": "VariableDefinition", "variable": { "kind": "Variable", "name": { "kind": "Name", "value": "password" } }, "type": { "kind": "NonNullType", "type": { "kind": "NamedType", "name": { "kind": "Name", "value": "String" } } } }, { "kind": "VariableDefinition", "variable": { "kind": "Variable", "name": { "kind": "Name", "value": "passwordAgain" } }, "type": { "kind": "NonNullType", "type": { "kind": "NamedType", "name": { "kind": "Name", "value": "String" } } } }], "selectionSet": { "kind": "SelectionSet", "selections": [{ "kind": "Field", "name": { "kind": "Name", "value": "accountUpdateRecovery" }, "arguments": [{ "kind": "Argument", "name": { "kind": "Name", "value": "userId" }, "value": { "kind": "Variable", "name": { "kind": "Name", "value": "userId" } } }, { "kind": "Argument", "name": { "kind": "Name", "value": "secret" }, "value": { "kind": "Variable", "name": { "kind": "Name", "value": "secret" } } }, { "kind": "Argument", "name": { "kind": "Name", "value": "password" }, "value": { "kind": "Variable", "name": { "kind": "Name", "value": "password" } } }, { "kind": "Argument", "name": { "kind": "Name", "value": "passwordAgain" }, "value": { "kind": "Variable", "name": { "kind": "Name", "value": "passwordAgain" } } }], "selectionSet": { "kind": "SelectionSet", "selections": [{ "kind": "Field", "name": { "kind": "Name", "value": "expire" } }] } }] } }] };
132
+ var CreateAccountDocument = { "kind": "Document", "definitions": [{ "kind": "OperationDefinition", "operation": "mutation", "name": { "kind": "Name", "value": "CreateAccount" }, "variableDefinitions": [{ "kind": "VariableDefinition", "variable": { "kind": "Variable", "name": { "kind": "Name", "value": "userId" } }, "type": { "kind": "NonNullType", "type": { "kind": "NamedType", "name": { "kind": "Name", "value": "String" } } } }, { "kind": "VariableDefinition", "variable": { "kind": "Variable", "name": { "kind": "Name", "value": "name" } }, "type": { "kind": "NamedType", "name": { "kind": "Name", "value": "String" } } }, { "kind": "VariableDefinition", "variable": { "kind": "Variable", "name": { "kind": "Name", "value": "email" } }, "type": { "kind": "NonNullType", "type": { "kind": "NamedType", "name": { "kind": "Name", "value": "String" } } } }, { "kind": "VariableDefinition", "variable": { "kind": "Variable", "name": { "kind": "Name", "value": "password" } }, "type": { "kind": "NonNullType", "type": { "kind": "NamedType", "name": { "kind": "Name", "value": "String" } } } }], "selectionSet": { "kind": "SelectionSet", "selections": [{ "kind": "Field", "name": { "kind": "Name", "value": "accountCreate" }, "arguments": [{ "kind": "Argument", "name": { "kind": "Name", "value": "userId" }, "value": { "kind": "Variable", "name": { "kind": "Name", "value": "userId" } } }, { "kind": "Argument", "name": { "kind": "Name", "value": "name" }, "value": { "kind": "Variable", "name": { "kind": "Name", "value": "name" } } }, { "kind": "Argument", "name": { "kind": "Name", "value": "email" }, "value": { "kind": "Variable", "name": { "kind": "Name", "value": "email" } } }, { "kind": "Argument", "name": { "kind": "Name", "value": "password" }, "value": { "kind": "Variable", "name": { "kind": "Name", "value": "password" } } }], "selectionSet": { "kind": "SelectionSet", "selections": [{ "kind": "Field", "name": { "kind": "Name", "value": "name" } }, { "kind": "Field", "name": { "kind": "Name", "value": "email" } }] } }] } }] };
133
+ var VerifyEmailDocument = { "kind": "Document", "definitions": [{ "kind": "OperationDefinition", "operation": "mutation", "name": { "kind": "Name", "value": "VerifyEmail" }, "variableDefinitions": [{ "kind": "VariableDefinition", "variable": { "kind": "Variable", "name": { "kind": "Name", "value": "url" } }, "type": { "kind": "NonNullType", "type": { "kind": "NamedType", "name": { "kind": "Name", "value": "String" } } } }], "selectionSet": { "kind": "SelectionSet", "selections": [{ "kind": "Field", "name": { "kind": "Name", "value": "accountCreateVerification" }, "arguments": [{ "kind": "Argument", "name": { "kind": "Name", "value": "url" }, "value": { "kind": "Variable", "name": { "kind": "Name", "value": "url" } } }], "selectionSet": { "kind": "SelectionSet", "selections": [{ "kind": "Field", "name": { "kind": "Name", "value": "expire" } }] } }] } }] };
134
+ var UpdateVerificationDocument = { "kind": "Document", "definitions": [{ "kind": "OperationDefinition", "operation": "mutation", "name": { "kind": "Name", "value": "UpdateVerification" }, "variableDefinitions": [{ "kind": "VariableDefinition", "variable": { "kind": "Variable", "name": { "kind": "Name", "value": "userId" } }, "type": { "kind": "NonNullType", "type": { "kind": "NamedType", "name": { "kind": "Name", "value": "String" } } } }, { "kind": "VariableDefinition", "variable": { "kind": "Variable", "name": { "kind": "Name", "value": "secret" } }, "type": { "kind": "NonNullType", "type": { "kind": "NamedType", "name": { "kind": "Name", "value": "String" } } } }], "selectionSet": { "kind": "SelectionSet", "selections": [{ "kind": "Field", "name": { "kind": "Name", "value": "accountUpdateVerification" }, "arguments": [{ "kind": "Argument", "name": { "kind": "Name", "value": "userId" }, "value": { "kind": "Variable", "name": { "kind": "Name", "value": "userId" } } }, { "kind": "Argument", "name": { "kind": "Name", "value": "secret" }, "value": { "kind": "Variable", "name": { "kind": "Name", "value": "secret" } } }], "selectionSet": { "kind": "SelectionSet", "selections": [{ "kind": "Field", "name": { "kind": "Name", "value": "expire" } }] } }] } }] };
135
+ var ListDocumentsDocument = { "kind": "Document", "definitions": [{ "kind": "OperationDefinition", "operation": "query", "name": { "kind": "Name", "value": "ListDocuments" }, "variableDefinitions": [{ "kind": "VariableDefinition", "variable": { "kind": "Variable", "name": { "kind": "Name", "value": "databaseId" } }, "type": { "kind": "NonNullType", "type": { "kind": "NamedType", "name": { "kind": "Name", "value": "String" } } } }, { "kind": "VariableDefinition", "variable": { "kind": "Variable", "name": { "kind": "Name", "value": "collectionId" } }, "type": { "kind": "NonNullType", "type": { "kind": "NamedType", "name": { "kind": "Name", "value": "String" } } } }, { "kind": "VariableDefinition", "variable": { "kind": "Variable", "name": { "kind": "Name", "value": "queries" } }, "type": { "kind": "ListType", "type": { "kind": "NonNullType", "type": { "kind": "NamedType", "name": { "kind": "Name", "value": "String" } } } } }], "selectionSet": { "kind": "SelectionSet", "selections": [{ "kind": "Field", "name": { "kind": "Name", "value": "databasesListDocuments" }, "arguments": [{ "kind": "Argument", "name": { "kind": "Name", "value": "databaseId" }, "value": { "kind": "Variable", "name": { "kind": "Name", "value": "databaseId" } } }, { "kind": "Argument", "name": { "kind": "Name", "value": "collectionId" }, "value": { "kind": "Variable", "name": { "kind": "Name", "value": "collectionId" } } }, { "kind": "Argument", "name": { "kind": "Name", "value": "queries" }, "value": { "kind": "Variable", "name": { "kind": "Name", "value": "queries" } } }], "selectionSet": { "kind": "SelectionSet", "selections": [{ "kind": "Field", "name": { "kind": "Name", "value": "total" } }, { "kind": "Field", "name": { "kind": "Name", "value": "documents" }, "selectionSet": { "kind": "SelectionSet", "selections": [{ "kind": "Field", "name": { "kind": "Name", "value": "_id" } }, { "kind": "Field", "name": { "kind": "Name", "value": "data" } }] } }] } }] } }] };
136
+ var CreateDocumentDocument = { "kind": "Document", "definitions": [{ "kind": "OperationDefinition", "operation": "mutation", "name": { "kind": "Name", "value": "CreateDocument" }, "variableDefinitions": [{ "kind": "VariableDefinition", "variable": { "kind": "Variable", "name": { "kind": "Name", "value": "databaseId" } }, "type": { "kind": "NonNullType", "type": { "kind": "NamedType", "name": { "kind": "Name", "value": "String" } } } }, { "kind": "VariableDefinition", "variable": { "kind": "Variable", "name": { "kind": "Name", "value": "collectionId" } }, "type": { "kind": "NonNullType", "type": { "kind": "NamedType", "name": { "kind": "Name", "value": "String" } } } }, { "kind": "VariableDefinition", "variable": { "kind": "Variable", "name": { "kind": "Name", "value": "documentId" } }, "type": { "kind": "NonNullType", "type": { "kind": "NamedType", "name": { "kind": "Name", "value": "String" } } } }, { "kind": "VariableDefinition", "variable": { "kind": "Variable", "name": { "kind": "Name", "value": "data" } }, "type": { "kind": "NonNullType", "type": { "kind": "NamedType", "name": { "kind": "Name", "value": "JSON" } } } }, { "kind": "VariableDefinition", "variable": { "kind": "Variable", "name": { "kind": "Name", "value": "permissions" } }, "type": { "kind": "ListType", "type": { "kind": "NonNullType", "type": { "kind": "NamedType", "name": { "kind": "Name", "value": "String" } } } } }], "selectionSet": { "kind": "SelectionSet", "selections": [{ "kind": "Field", "name": { "kind": "Name", "value": "databasesCreateDocument" }, "arguments": [{ "kind": "Argument", "name": { "kind": "Name", "value": "databaseId" }, "value": { "kind": "Variable", "name": { "kind": "Name", "value": "databaseId" } } }, { "kind": "Argument", "name": { "kind": "Name", "value": "collectionId" }, "value": { "kind": "Variable", "name": { "kind": "Name", "value": "collectionId" } } }, { "kind": "Argument", "name": { "kind": "Name", "value": "documentId" }, "value": { "kind": "Variable", "name": { "kind": "Name", "value": "documentId" } } }, { "kind": "Argument", "name": { "kind": "Name", "value": "data" }, "value": { "kind": "Variable", "name": { "kind": "Name", "value": "data" } } }, { "kind": "Argument", "name": { "kind": "Name", "value": "permissions" }, "value": { "kind": "Variable", "name": { "kind": "Name", "value": "permissions" } } }], "selectionSet": { "kind": "SelectionSet", "selections": [{ "kind": "Field", "name": { "kind": "Name", "value": "_id" } }] } }] } }] };
137
+ var GetDocumentDocument = { "kind": "Document", "definitions": [{ "kind": "OperationDefinition", "operation": "query", "name": { "kind": "Name", "value": "GetDocument" }, "variableDefinitions": [{ "kind": "VariableDefinition", "variable": { "kind": "Variable", "name": { "kind": "Name", "value": "databaseId" } }, "type": { "kind": "NonNullType", "type": { "kind": "NamedType", "name": { "kind": "Name", "value": "String" } } } }, { "kind": "VariableDefinition", "variable": { "kind": "Variable", "name": { "kind": "Name", "value": "collectionId" } }, "type": { "kind": "NonNullType", "type": { "kind": "NamedType", "name": { "kind": "Name", "value": "String" } } } }, { "kind": "VariableDefinition", "variable": { "kind": "Variable", "name": { "kind": "Name", "value": "documentId" } }, "type": { "kind": "NonNullType", "type": { "kind": "NamedType", "name": { "kind": "Name", "value": "String" } } } }], "selectionSet": { "kind": "SelectionSet", "selections": [{ "kind": "Field", "name": { "kind": "Name", "value": "databasesGetDocument" }, "arguments": [{ "kind": "Argument", "name": { "kind": "Name", "value": "databaseId" }, "value": { "kind": "Variable", "name": { "kind": "Name", "value": "databaseId" } } }, { "kind": "Argument", "name": { "kind": "Name", "value": "collectionId" }, "value": { "kind": "Variable", "name": { "kind": "Name", "value": "collectionId" } } }, { "kind": "Argument", "name": { "kind": "Name", "value": "documentId" }, "value": { "kind": "Variable", "name": { "kind": "Name", "value": "documentId" } } }], "selectionSet": { "kind": "SelectionSet", "selections": [{ "kind": "Field", "name": { "kind": "Name", "value": "_id" } }, { "kind": "Field", "name": { "kind": "Name", "value": "data" } }] } }] } }] };
138
+ var CreateExecutionDocument = { "kind": "Document", "definitions": [{ "kind": "OperationDefinition", "operation": "mutation", "name": { "kind": "Name", "value": "CreateExecution" }, "variableDefinitions": [{ "kind": "VariableDefinition", "variable": { "kind": "Variable", "name": { "kind": "Name", "value": "functionId" } }, "type": { "kind": "NonNullType", "type": { "kind": "NamedType", "name": { "kind": "Name", "value": "String" } } } }, { "kind": "VariableDefinition", "variable": { "kind": "Variable", "name": { "kind": "Name", "value": "body" } }, "type": { "kind": "NamedType", "name": { "kind": "Name", "value": "String" } } }, { "kind": "VariableDefinition", "variable": { "kind": "Variable", "name": { "kind": "Name", "value": "async" } }, "type": { "kind": "NamedType", "name": { "kind": "Name", "value": "Boolean" } } }, { "kind": "VariableDefinition", "variable": { "kind": "Variable", "name": { "kind": "Name", "value": "path" } }, "type": { "kind": "NamedType", "name": { "kind": "Name", "value": "String" } } }, { "kind": "VariableDefinition", "variable": { "kind": "Variable", "name": { "kind": "Name", "value": "method" } }, "type": { "kind": "NamedType", "name": { "kind": "Name", "value": "String" } } }, { "kind": "VariableDefinition", "variable": { "kind": "Variable", "name": { "kind": "Name", "value": "headers" } }, "type": { "kind": "NamedType", "name": { "kind": "Name", "value": "JSON" } } }], "selectionSet": { "kind": "SelectionSet", "selections": [{ "kind": "Field", "name": { "kind": "Name", "value": "functionsCreateExecution" }, "arguments": [{ "kind": "Argument", "name": { "kind": "Name", "value": "functionId" }, "value": { "kind": "Variable", "name": { "kind": "Name", "value": "functionId" } } }, { "kind": "Argument", "name": { "kind": "Name", "value": "body" }, "value": { "kind": "Variable", "name": { "kind": "Name", "value": "body" } } }, { "kind": "Argument", "name": { "kind": "Name", "value": "async" }, "value": { "kind": "Variable", "name": { "kind": "Name", "value": "async" } } }, { "kind": "Argument", "name": { "kind": "Name", "value": "path" }, "value": { "kind": "Variable", "name": { "kind": "Name", "value": "path" } } }, { "kind": "Argument", "name": { "kind": "Name", "value": "method" }, "value": { "kind": "Variable", "name": { "kind": "Name", "value": "method" } } }, { "kind": "Argument", "name": { "kind": "Name", "value": "headers" }, "value": { "kind": "Variable", "name": { "kind": "Name", "value": "headers" } } }], "selectionSet": { "kind": "SelectionSet", "selections": [{ "kind": "Field", "name": { "kind": "Name", "value": "_id" } }, { "kind": "Field", "name": { "kind": "Name", "value": "status" } }, { "kind": "Field", "name": { "kind": "Name", "value": "responseStatusCode" } }, { "kind": "Field", "name": { "kind": "Name", "value": "responseBody" } }, { "kind": "Field", "name": { "kind": "Name", "value": "errors" } }, { "kind": "Field", "name": { "kind": "Name", "value": "duration" } }] } }] } }] };
139
+ var GetFunctionExecutionDocument = { "kind": "Document", "definitions": [{ "kind": "OperationDefinition", "operation": "query", "name": { "kind": "Name", "value": "GetFunctionExecution" }, "variableDefinitions": [{ "kind": "VariableDefinition", "variable": { "kind": "Variable", "name": { "kind": "Name", "value": "functionId" } }, "type": { "kind": "NonNullType", "type": { "kind": "NamedType", "name": { "kind": "Name", "value": "String" } } } }, { "kind": "VariableDefinition", "variable": { "kind": "Variable", "name": { "kind": "Name", "value": "executionId" } }, "type": { "kind": "NonNullType", "type": { "kind": "NamedType", "name": { "kind": "Name", "value": "String" } } } }], "selectionSet": { "kind": "SelectionSet", "selections": [{ "kind": "Field", "name": { "kind": "Name", "value": "functionsGetExecution" }, "arguments": [{ "kind": "Argument", "name": { "kind": "Name", "value": "functionId" }, "value": { "kind": "Variable", "name": { "kind": "Name", "value": "functionId" } } }, { "kind": "Argument", "name": { "kind": "Name", "value": "executionId" }, "value": { "kind": "Variable", "name": { "kind": "Name", "value": "executionId" } } }], "selectionSet": { "kind": "SelectionSet", "selections": [{ "kind": "Field", "name": { "kind": "Name", "value": "status" } }, { "kind": "Field", "name": { "kind": "Name", "value": "errors" } }, { "kind": "Field", "name": { "kind": "Name", "value": "duration" } }] } }] } }] };
140
+
141
+ // src/__generated__/gql.ts
142
+ var documents = {
143
+ "\n fragment Account_UserFragment on User {\n name\n email\n prefs {\n data\n }\n }\n": Account_UserFragmentFragmentDoc,
144
+ "\n query AccountGet {\n accountGet {\n ...Account_UserFragment\n }\n }\n": AccountGetDocument,
145
+ "\n mutation CreateEmailSession($email: String!, $password: String!) {\n accountCreateEmailSession(email: $email, password: $password) {\n userId\n expire\n current\n }\n }\n": CreateEmailSessionDocument,
146
+ "\n mutation DeleteSession($sessionId: String!) {\n accountDeleteSession(sessionId: $sessionId) {\n status\n }\n }\n": DeleteSessionDocument,
147
+ "\n mutation CreateRecovery($email: String!, $url: String!) {\n accountCreateRecovery(email: $email, url: $url) {\n expire\n }\n }\n": CreateRecoveryDocument,
148
+ "\n mutation UpdateRecovery(\n $userId: String!\n $secret: String!\n $password: String!\n $passwordAgain: String!\n ) {\n accountUpdateRecovery(\n userId: $userId\n secret: $secret\n password: $password\n passwordAgain: $passwordAgain\n ) {\n expire\n }\n }\n": UpdateRecoveryDocument,
149
+ "\n mutation CreateAccount($userId: String!, $name: String, $email: String!, $password: String!) {\n accountCreate(userId: $userId, name: $name, email: $email, password: $password) {\n name\n email\n }\n }\n": CreateAccountDocument,
150
+ "\n mutation VerifyEmail($url: String!) {\n accountCreateVerification(url: $url) {\n expire\n }\n }\n": VerifyEmailDocument,
151
+ "\n mutation UpdateVerification($userId: String!, $secret: String!) {\n accountUpdateVerification(userId: $userId, secret: $secret) {\n expire\n }\n }\n": UpdateVerificationDocument,
152
+ "\n query ListDocuments($databaseId: String!, $collectionId: String!, $queries: [String!]) {\n databasesListDocuments(\n databaseId: $databaseId\n collectionId: $collectionId\n queries: $queries\n ) {\n total\n documents {\n _id\n data\n }\n }\n }\n": ListDocumentsDocument,
153
+ "\n mutation CreateDocument(\n $databaseId: String!\n $collectionId: String!\n $documentId: String!\n $data: JSON!\n $permissions: [String!]\n ) {\n databasesCreateDocument(\n databaseId: $databaseId\n collectionId: $collectionId\n documentId: $documentId\n data: $data\n permissions: $permissions\n ) {\n _id\n }\n }\n": CreateDocumentDocument,
154
+ "\n query GetDocument($databaseId: String!, $collectionId: String!, $documentId: String!) {\n databasesGetDocument(\n databaseId: $databaseId\n collectionId: $collectionId\n documentId: $documentId\n ) {\n _id\n data\n }\n }\n": GetDocumentDocument,
155
+ "\n mutation CreateExecution(\n $functionId: String!\n $body: String\n $async: Boolean\n $path: String\n $method: String\n $headers: JSON\n ) {\n functionsCreateExecution(\n functionId: $functionId\n body: $body\n async: $async\n path: $path\n method: $method\n headers: $headers\n ) {\n _id\n status\n responseStatusCode\n responseBody\n errors\n duration\n }\n }\n": CreateExecutionDocument,
156
+ "\n query GetFunctionExecution($functionId: String!, $executionId: String!) {\n functionsGetExecution(functionId: $functionId, executionId: $executionId) {\n status\n errors\n duration\n }\n }\n": GetFunctionExecutionDocument
157
+ };
158
+ function gql(source) {
159
+ return documents[source] ?? {};
160
+ }
161
+
162
+ // src/account/useAccount.ts
163
+ var getAccount = gql(
164
+ /* GraphQL */
165
+ `
166
+ query AccountGet {
167
+ accountGet {
168
+ ...Account_UserFragment
169
+ }
170
+ }
171
+ `
172
+ );
173
+ function useAccount({
174
+ options
175
+ }) {
176
+ const { graphql: graphql2 } = useAppwrite();
177
+ const queryClient2 = useQueryClient();
178
+ const queryResult = useQuery({
179
+ queryKey: ["appwrite", "account"],
180
+ queryFn: async () => {
181
+ const { data, errors } = await graphql2.query({
182
+ query: getAccount
183
+ });
184
+ if (errors) {
185
+ throw errors;
186
+ }
187
+ return data.accountGet;
188
+ },
189
+ retry: false,
190
+ ...options
191
+ });
192
+ (0, import_react2.useEffect)(() => {
193
+ const unsubscribe = graphql2.client.subscribe(
194
+ "account",
195
+ (response) => {
196
+ const isUpdatingPreferences = response.events.some((event) => event.endsWith("prefs"));
197
+ if (isUpdatingPreferences) {
198
+ queryClient2.setQueryData(
199
+ ["appwrite", "account"],
200
+ (account2) => (0, import_immer.produce)(account2, (draft) => {
201
+ if (draft) {
202
+ draft.prefs = (0, import_immer.castDraft)(response.payload.prefs);
203
+ }
204
+ })
205
+ );
206
+ return;
207
+ }
208
+ queryClient2.setQueryData(
209
+ ["appwrite", "account"],
210
+ response.payload
211
+ );
212
+ }
213
+ );
214
+ return unsubscribe;
215
+ }, [graphql2.client, queryClient2]);
216
+ return queryResult;
217
+ }
218
+
219
+ // src/account/useLogin.ts
220
+ var createEmailSession = gql(
221
+ /* GraphQL */
222
+ `
223
+ mutation CreateEmailSession($email: String!, $password: String!) {
224
+ accountCreateEmailSession(email: $email, password: $password) {
225
+ userId
226
+ expire
227
+ current
228
+ }
229
+ }
230
+ `
231
+ );
232
+ function useLogin() {
233
+ const { account: account2, graphql: graphql2 } = useAppwrite();
234
+ const login = useMutation({
235
+ mutationFn: async ({ email, password }) => {
236
+ const { data, errors } = await graphql2.mutation({
237
+ query: createEmailSession,
238
+ variables: {
239
+ email,
240
+ password
241
+ }
242
+ });
243
+ if (errors) {
244
+ throw errors;
245
+ }
246
+ return data.accountCreateEmailSession ?? {};
247
+ }
248
+ });
249
+ const oAuthLogin = useMutation({
250
+ mutationFn: async ({ provider, success, failure }) => {
251
+ return account2.createOAuth2Session(provider, success, failure);
252
+ }
253
+ });
254
+ return {
255
+ login,
256
+ oAuthLogin
257
+ };
258
+ }
259
+
260
+ // src/__generated__/fragment-masking.ts
261
+ function getFragmentData(_documentNode, fragmentType) {
262
+ return fragmentType;
263
+ }
264
+
265
+ // src/account/useLogout.ts
266
+ var deleteSession = gql(
267
+ /* GraphQL */
268
+ `
269
+ mutation DeleteSession($sessionId: String!) {
270
+ accountDeleteSession(sessionId: $sessionId) {
271
+ status
272
+ }
273
+ }
274
+ `
275
+ );
276
+ function useLogout() {
277
+ const { graphql: graphql2 } = useAppwrite();
278
+ const queryClient2 = useQueryClient();
279
+ const logout = useMutation({
280
+ mutationFn: () => {
281
+ return graphql2.mutation({
282
+ query: deleteSession,
283
+ variables: {
284
+ sessionId: "current"
285
+ }
286
+ });
287
+ },
288
+ onSuccess: async () => {
289
+ queryClient2.setQueryData(["appwrite", "account"], null);
290
+ queryClient2.removeQueries({ queryKey: ["appwrite", "account"] });
291
+ }
292
+ });
293
+ return logout;
294
+ }
295
+
296
+ // src/account/usePasswordRecovery.ts
297
+ var createRecovery = gql(
298
+ /* GraphQL */
299
+ `
300
+ mutation CreateRecovery($email: String!, $url: String!) {
301
+ accountCreateRecovery(email: $email, url: $url) {
302
+ expire
303
+ }
304
+ }
305
+ `
306
+ );
307
+ function usePasswordRecovery() {
308
+ const { graphql: graphql2 } = useAppwrite();
309
+ const passwordRecovery = useMutation({
310
+ mutationFn: async ({ email, resetUrl }) => {
311
+ const { data, errors } = await graphql2.mutation({
312
+ query: createRecovery,
313
+ variables: {
314
+ email,
315
+ url: resetUrl
316
+ }
317
+ });
318
+ if (errors) {
319
+ throw errors;
320
+ }
321
+ return data.accountCreateRecovery ?? {};
322
+ },
323
+ onSuccess: async (_, variables) => {
324
+ localStorage.setItem("email", variables.email);
325
+ }
326
+ });
327
+ return passwordRecovery;
328
+ }
329
+
330
+ // src/account/useResetPassword.ts
331
+ var updateRecovery = gql(
332
+ /* GraphQL */
333
+ `
334
+ mutation UpdateRecovery(
335
+ $userId: String!
336
+ $secret: String!
337
+ $password: String!
338
+ $passwordAgain: String!
339
+ ) {
340
+ accountUpdateRecovery(
341
+ userId: $userId
342
+ secret: $secret
343
+ password: $password
344
+ passwordAgain: $passwordAgain
345
+ ) {
346
+ expire
347
+ }
348
+ }
349
+ `
350
+ );
351
+ function useResetPassword() {
352
+ const { graphql: graphql2 } = useAppwrite();
353
+ const passwordReset = useMutation({
354
+ mutationFn: async ({ userId, secret, password, confirmPassword }) => {
355
+ const { data, errors } = await graphql2.mutation({
356
+ query: updateRecovery,
357
+ variables: {
358
+ userId,
359
+ secret,
360
+ password,
361
+ passwordAgain: confirmPassword
362
+ }
363
+ });
364
+ if (errors) {
365
+ throw errors;
366
+ }
367
+ return data.accountUpdateRecovery ?? {};
368
+ }
369
+ });
370
+ return passwordReset;
371
+ }
372
+
373
+ // src/account/useSignUp.ts
374
+ var import_appwrite2 = require("appwrite");
375
+ var createAccount = gql(
376
+ /* GraphQL */
377
+ `
378
+ mutation CreateAccount($userId: String!, $name: String, $email: String!, $password: String!) {
379
+ accountCreate(userId: $userId, name: $name, email: $email, password: $password) {
380
+ name
381
+ email
382
+ }
383
+ }
384
+ `
385
+ );
386
+ var verify = gql(
387
+ /* GraphQL */
388
+ `
389
+ mutation VerifyEmail($url: String!) {
390
+ accountCreateVerification(url: $url) {
391
+ expire
392
+ }
393
+ }
394
+ `
395
+ );
396
+ function useSignUp() {
397
+ const { graphql: graphql2 } = useAppwrite();
398
+ const signUp = useMutation({
399
+ mutationFn: async ({ userId, email, password, name }) => {
400
+ const { data, errors } = await graphql2.mutation({
401
+ query: createAccount,
402
+ variables: {
403
+ userId: userId ?? import_appwrite2.ID.unique(),
404
+ name,
405
+ email,
406
+ password
407
+ }
408
+ });
409
+ if (errors) {
410
+ throw errors;
411
+ }
412
+ return data.accountCreate ?? {};
413
+ }
414
+ });
415
+ const verifyEmail = useMutation({
416
+ mutationFn: async ({ verifyUrl }) => {
417
+ const { data, errors } = await graphql2.mutation({
418
+ query: verify,
419
+ variables: {
420
+ url: verifyUrl
421
+ }
422
+ });
423
+ if (errors) {
424
+ throw errors;
425
+ }
426
+ return data.accountCreateVerification ?? {};
427
+ }
428
+ });
429
+ return { signUp, verifyEmail };
430
+ }
431
+
432
+ // src/account/useVerification.ts
433
+ var updateVerification = gql(
434
+ /* GraphQL */
435
+ `
436
+ mutation UpdateVerification($userId: String!, $secret: String!) {
437
+ accountUpdateVerification(userId: $userId, secret: $secret) {
438
+ expire
439
+ }
440
+ }
441
+ `
442
+ );
443
+ function useVerification() {
444
+ const { graphql: graphql2 } = useAppwrite();
445
+ const queryClient2 = useQueryClient();
446
+ const verify2 = useMutation({
447
+ mutationFn: async ({ userId, secret }) => {
448
+ if (!userId || !secret) {
449
+ throw new Error("Missing userId or secret");
450
+ }
451
+ const { data, errors } = await graphql2.mutation({
452
+ query: updateVerification,
453
+ variables: {
454
+ userId,
455
+ secret
456
+ }
457
+ });
458
+ if (errors) {
459
+ throw errors;
460
+ }
461
+ return data.accountUpdateVerification ?? {};
462
+ },
463
+ onSuccess: async () => {
464
+ queryClient2.setQueryData(["appwrite", "account"], null);
465
+ }
466
+ });
467
+ return verify2;
468
+ }
469
+
470
+ // src/databases/useCollection.ts
471
+ var import_react3 = require("react");
472
+ var listDocuments = gql(
473
+ /* GraphQL */
474
+ `
475
+ query ListDocuments($databaseId: String!, $collectionId: String!, $queries: [String!]) {
476
+ databasesListDocuments(
477
+ databaseId: $databaseId
478
+ collectionId: $collectionId
479
+ queries: $queries
480
+ ) {
481
+ total
482
+ documents {
483
+ _id
484
+ data
485
+ }
486
+ }
487
+ }
488
+ `
489
+ );
490
+ function useCollection({
491
+ databaseId,
492
+ collectionId,
493
+ queries,
494
+ options
495
+ }) {
496
+ const { graphql: graphql2 } = useAppwrite();
497
+ const queryClient2 = useQueryClient();
498
+ const collection = useQuery({
499
+ queryKey: ["appwrite", "databases", databaseId, collectionId, { queries }],
500
+ queryFn: async () => {
501
+ const { data, errors } = await graphql2.query({
502
+ query: listDocuments,
503
+ variables: {
504
+ databaseId,
505
+ collectionId,
506
+ queries
507
+ }
508
+ });
509
+ if (errors) {
510
+ throw errors;
511
+ }
512
+ const documents2 = data.databasesListDocuments?.documents?.map((document) => ({
513
+ ...document,
514
+ ...document ? JSON.parse(document.data) : {}
515
+ })) ?? [];
516
+ return {
517
+ total: data.databasesListDocuments?.total ?? 0,
518
+ documents: documents2
519
+ };
520
+ },
521
+ ...options
522
+ });
523
+ (0, import_react3.useEffect)(() => {
524
+ const unsubscribe = graphql2.client.subscribe(
525
+ `databases.${databaseId}.collections.${collectionId}.documents`,
526
+ (response) => {
527
+ const [, operation] = response.events[0].match(/\.(\w+)$/);
528
+ const document = response.payload;
529
+ switch (operation) {
530
+ case "create":
531
+ case "update":
532
+ case "delete":
533
+ queryClient2.setQueryData(
534
+ ["appwrite", "databases", databaseId, collectionId, "documents", document.$id],
535
+ document
536
+ );
537
+ queryClient2.invalidateQueries({
538
+ queryKey: ["appwrite", "databases", databaseId, collectionId, { queries }],
539
+ exact: true
540
+ });
541
+ break;
542
+ }
543
+ }
544
+ );
545
+ return unsubscribe;
546
+ }, [databaseId, collectionId, graphql2.client, queryClient2, queries]);
547
+ return {
548
+ ...collection,
549
+ documents: collection.data?.documents,
550
+ total: collection.data?.total
551
+ };
552
+ }
553
+
554
+ // src/databases/useCreateDocument.ts
555
+ var createDocument = gql(
556
+ /* GraphQL */
557
+ `
558
+ mutation CreateDocument(
559
+ $databaseId: String!
560
+ $collectionId: String!
561
+ $documentId: String!
562
+ $data: JSON!
563
+ $permissions: [String!]
564
+ ) {
565
+ databasesCreateDocument(
566
+ databaseId: $databaseId
567
+ collectionId: $collectionId
568
+ documentId: $documentId
569
+ data: $data
570
+ permissions: $permissions
571
+ ) {
572
+ _id
573
+ }
574
+ }
575
+ `
576
+ );
577
+ function useCreateDocument(databaseId, collectionId, documentId, data, permissions, options) {
578
+ const { graphql: graphql2 } = useAppwrite();
579
+ const mutationResult = useMutation({
580
+ mutationKey: ["appwrite", "databases", databaseId, collectionId, "documents", documentId],
581
+ mutationFn: async () => {
582
+ const { data: mutationData, errors } = await graphql2.mutation({
583
+ query: createDocument,
584
+ variables: {
585
+ databaseId,
586
+ collectionId,
587
+ documentId,
588
+ data,
589
+ permissions
590
+ }
591
+ });
592
+ if (errors) {
593
+ throw errors;
594
+ }
595
+ return mutationData.databasesCreateDocument?._id;
596
+ },
597
+ ...options
598
+ });
599
+ return mutationResult;
600
+ }
601
+
602
+ // src/databases/useDocument.ts
603
+ var import_react4 = require("react");
604
+ var getDocument = gql(
605
+ /* GraphQL */
606
+ `
607
+ query GetDocument($databaseId: String!, $collectionId: String!, $documentId: String!) {
608
+ databasesGetDocument(
609
+ databaseId: $databaseId
610
+ collectionId: $collectionId
611
+ documentId: $documentId
612
+ ) {
613
+ _id
614
+ data
615
+ }
616
+ }
617
+ `
618
+ );
619
+ function useDocument(databaseId, collectionId, documentId, options) {
620
+ const { graphql: graphql2 } = useAppwrite();
621
+ const queryClient2 = useQueryClient();
622
+ const queryResult = useQuery({
623
+ queryKey: ["appwrite", "databases", databaseId, collectionId, "documents", documentId],
624
+ queryFn: async () => {
625
+ const { data, errors } = await graphql2.query({
626
+ query: getDocument,
627
+ variables: {
628
+ databaseId,
629
+ collectionId,
630
+ documentId
631
+ }
632
+ });
633
+ if (errors) {
634
+ throw errors;
635
+ }
636
+ const document = {
637
+ ...data.databasesGetDocument,
638
+ ...data.databasesGetDocument ? JSON.parse(data.databasesGetDocument.data) : {}
639
+ };
640
+ return document;
641
+ },
642
+ ...options
643
+ });
644
+ (0, import_react4.useEffect)(() => {
645
+ const unsubscribe = graphql2.client.subscribe(
646
+ `databases.${databaseId}.collections.${collectionId}.documents.${documentId}`,
647
+ (response) => {
648
+ queryClient2.setQueryData(
649
+ ["appwrite", "databases", databaseId, collectionId, "documents", documentId],
650
+ response.payload
651
+ );
652
+ }
653
+ );
654
+ return unsubscribe;
655
+ }, [databaseId, collectionId, documentId, graphql2.client, queryClient2]);
656
+ return queryResult;
657
+ }
658
+
659
+ // src/functions/useFunction.ts
660
+ var import_react5 = require("react");
661
+ var createExecution = gql(
662
+ /* GraphQL */
663
+ `
664
+ mutation CreateExecution(
665
+ $functionId: String!
666
+ $body: String
667
+ $async: Boolean
668
+ $path: String
669
+ $method: String
670
+ $headers: JSON
671
+ ) {
672
+ functionsCreateExecution(
673
+ functionId: $functionId
674
+ body: $body
675
+ async: $async
676
+ path: $path
677
+ method: $method
678
+ headers: $headers
679
+ ) {
680
+ _id
681
+ status
682
+ responseStatusCode
683
+ responseBody
684
+ errors
685
+ duration
686
+ }
687
+ }
688
+ `
689
+ );
690
+ var getFunctionExecution = gql(
691
+ /* GraphQL */
692
+ `
693
+ query GetFunctionExecution($functionId: String!, $executionId: String!) {
694
+ functionsGetExecution(functionId: $functionId, executionId: $executionId) {
695
+ status
696
+ errors
697
+ duration
698
+ }
699
+ }
700
+ `
701
+ );
702
+ function useFunction() {
703
+ const { graphql: graphql2 } = useAppwrite();
704
+ const [currentExecution, setCurrentExecution] = (0, import_react5.useState)(null);
705
+ const [currentFunction, setCurrentFunction] = (0, import_react5.useState)(null);
706
+ const executeFunction = useMutation({
707
+ mutationFn: async ({ functionId, body, async, path, method, headers }) => {
708
+ setCurrentFunction(functionId);
709
+ const { data } = await graphql2.mutation({
710
+ query: createExecution,
711
+ variables: {
712
+ functionId,
713
+ body: JSON.stringify(body),
714
+ async,
715
+ path,
716
+ method,
717
+ headers
718
+ }
719
+ });
720
+ let unsubscribe = null;
721
+ const { _id, status, responseBody, errors } = data.functionsCreateExecution ?? {};
722
+ if (status === "completed") {
723
+ return JSON.parse(responseBody ?? "{}");
724
+ }
725
+ if (status === "failed" && errors) {
726
+ throw new Error(errors);
727
+ }
728
+ setCurrentExecution(_id ?? null);
729
+ const response = await new Promise((resolve, reject) => {
730
+ unsubscribe = graphql2.client.subscribe(`executions.${_id}`, (event) => {
731
+ switch (event.payload.status) {
732
+ case "completed":
733
+ setCurrentExecution(null);
734
+ resolve(JSON.parse(event.payload.responseBody));
735
+ break;
736
+ case "failed":
737
+ setCurrentExecution(null);
738
+ reject(event.payload.errors);
739
+ break;
740
+ }
741
+ return 1;
742
+ });
743
+ });
744
+ unsubscribe?.();
745
+ return response;
746
+ }
747
+ });
748
+ const getExecution = useQuery({
749
+ queryKey: ["appwrite", "functions", currentFunction, currentExecution],
750
+ queryFn: async () => {
751
+ if (!currentExecution || !currentFunction) {
752
+ return null;
753
+ }
754
+ const { data } = await graphql2.query({
755
+ query: getFunctionExecution,
756
+ variables: {
757
+ functionId: currentFunction,
758
+ executionId: currentExecution
759
+ }
760
+ });
761
+ return data.functionsGetExecution ?? {};
762
+ }
763
+ });
764
+ return {
765
+ executeFunction,
766
+ currentExecution: getExecution
767
+ };
768
+ }
769
+
770
+ // src/account/fragments.ts
771
+ var Account_UserFragment = gql(
772
+ /* GraphQL */
773
+ `
774
+ fragment Account_UserFragment on User {
775
+ name
776
+ email
777
+ prefs {
778
+ data
779
+ }
780
+ }
781
+ `
782
+ );
783
+
784
+ // src/index.ts
785
+ var fragments = {
786
+ Account_UserFragment
787
+ };
788
+ // Annotate the CommonJS export names for ESM import in node:
789
+ 0 && (module.exports = {
790
+ fragments,
791
+ getFragmentData,
792
+ useAccount,
793
+ useAppwrite,
794
+ useCollection,
795
+ useCreateDocument,
796
+ useDocument,
797
+ useFunction,
798
+ useLogin,
799
+ useLogout,
800
+ useMutation,
801
+ usePasswordRecovery,
802
+ useQuery,
803
+ useQueryClient,
804
+ useResetPassword,
805
+ useSignUp,
806
+ useVerification
807
+ });
808
+ //# sourceMappingURL=index.js.map