@zeroin.earth/appwrite-graphql 0.14.8 → 0.14.9

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.d.mts CHANGED
@@ -5890,6 +5890,10 @@ declare function useFunction(): {
5890
5890
  executeFunction: _tanstack_react_query.UseMutationResult<Record<string, unknown>, Error, Props, unknown>;
5891
5891
  currentExecution: _tanstack_react_query.UseQueryResult<unknown, unknown>;
5892
5892
  };
5893
+ declare function useSuspenseFunction({ functionId, body, async, path, method, }: Props): {
5894
+ executeFunction: _tanstack_react_query.UseSuspenseQueryResult<Record<string, unknown>, Error>;
5895
+ currentExecution: _tanstack_react_query.UseQueryResult<unknown, unknown>;
5896
+ };
5893
5897
 
5894
5898
  type FragmentType<TDocumentType extends DocumentTypeDecoration<any, any>> = TDocumentType extends DocumentTypeDecoration<infer TType, any> ? [TType] extends [{
5895
5899
  ' $fragmentName'?: infer TKey;
@@ -5908,4 +5912,4 @@ declare const fragments: {
5908
5912
  Identity_ProviderFragment: _graphql_typed_document_node_core.TypedDocumentNode<Identity_ProviderFragmentFragment, unknown>;
5909
5913
  };
5910
5914
 
5911
- export { fragments, getFragmentData, useAccount, useAppwrite, useCollection, useCreateAnonymousSession, useCreateDocument, useCreateEmailToken, useCreateJWT, useCreateMagicURLToken, useCreateMfaAuthenticator, useCreateMfaChallenge, useCreateMfaRecoveryCodes, useCreatePhoneToken, useCreatePhoneVerification, useCreateSession, useDeleteDocument, useDeleteIdentity, useDeleteMfaAuthenticator, useDeleteSession, useDeleteSessions, useDocument, useFunction, useGetMfaRecoveryCodes, useGetPrefs, useGetSession, useListIdentities, useListMfaFactors, useListSessions, useLogin, useLogout, useLogs, useMutation, usePasswordRecovery, useQuery, useQueryClient, useResetPassword, useSignUp, useSuspenseCollection, useSuspenseCreateJWT, useUpdateDocument, useUpdateEmail, useUpdateMagicURLSession, useUpdateMfa, useUpdateMfaAuthenticator, useUpdateMfaChallenge, useUpdateMfaRecoveryCodes, useUpdateName, useUpdatePassword, useUpdatePhone, useUpdatePhoneSession, useUpdatePhoneVerification, useUpdatePrefs, useUpdateSession, useVerification };
5915
+ export { fragments, getFragmentData, useAccount, useAppwrite, useCollection, useCreateAnonymousSession, useCreateDocument, useCreateEmailToken, useCreateJWT, useCreateMagicURLToken, useCreateMfaAuthenticator, useCreateMfaChallenge, useCreateMfaRecoveryCodes, useCreatePhoneToken, useCreatePhoneVerification, useCreateSession, useDeleteDocument, useDeleteIdentity, useDeleteMfaAuthenticator, useDeleteSession, useDeleteSessions, useDocument, useFunction, useGetMfaRecoveryCodes, useGetPrefs, useGetSession, useListIdentities, useListMfaFactors, useListSessions, useLogin, useLogout, useLogs, useMutation, usePasswordRecovery, useQuery, useQueryClient, useResetPassword, useSignUp, useSuspenseCollection, useSuspenseCreateJWT, useSuspenseFunction, useUpdateDocument, useUpdateEmail, useUpdateMagicURLSession, useUpdateMfa, useUpdateMfaAuthenticator, useUpdateMfaChallenge, useUpdateMfaRecoveryCodes, useUpdateName, useUpdatePassword, useUpdatePhone, useUpdatePhoneSession, useUpdatePhoneVerification, useUpdatePrefs, useUpdateSession, useVerification };
package/dist/index.d.ts CHANGED
@@ -5890,6 +5890,10 @@ declare function useFunction(): {
5890
5890
  executeFunction: _tanstack_react_query.UseMutationResult<Record<string, unknown>, Error, Props, unknown>;
5891
5891
  currentExecution: _tanstack_react_query.UseQueryResult<unknown, unknown>;
5892
5892
  };
5893
+ declare function useSuspenseFunction({ functionId, body, async, path, method, }: Props): {
5894
+ executeFunction: _tanstack_react_query.UseSuspenseQueryResult<Record<string, unknown>, Error>;
5895
+ currentExecution: _tanstack_react_query.UseQueryResult<unknown, unknown>;
5896
+ };
5893
5897
 
5894
5898
  type FragmentType<TDocumentType extends DocumentTypeDecoration<any, any>> = TDocumentType extends DocumentTypeDecoration<infer TType, any> ? [TType] extends [{
5895
5899
  ' $fragmentName'?: infer TKey;
@@ -5908,4 +5912,4 @@ declare const fragments: {
5908
5912
  Identity_ProviderFragment: _graphql_typed_document_node_core.TypedDocumentNode<Identity_ProviderFragmentFragment, unknown>;
5909
5913
  };
5910
5914
 
5911
- export { fragments, getFragmentData, useAccount, useAppwrite, useCollection, useCreateAnonymousSession, useCreateDocument, useCreateEmailToken, useCreateJWT, useCreateMagicURLToken, useCreateMfaAuthenticator, useCreateMfaChallenge, useCreateMfaRecoveryCodes, useCreatePhoneToken, useCreatePhoneVerification, useCreateSession, useDeleteDocument, useDeleteIdentity, useDeleteMfaAuthenticator, useDeleteSession, useDeleteSessions, useDocument, useFunction, useGetMfaRecoveryCodes, useGetPrefs, useGetSession, useListIdentities, useListMfaFactors, useListSessions, useLogin, useLogout, useLogs, useMutation, usePasswordRecovery, useQuery, useQueryClient, useResetPassword, useSignUp, useSuspenseCollection, useSuspenseCreateJWT, useUpdateDocument, useUpdateEmail, useUpdateMagicURLSession, useUpdateMfa, useUpdateMfaAuthenticator, useUpdateMfaChallenge, useUpdateMfaRecoveryCodes, useUpdateName, useUpdatePassword, useUpdatePhone, useUpdatePhoneSession, useUpdatePhoneVerification, useUpdatePrefs, useUpdateSession, useVerification };
5915
+ export { fragments, getFragmentData, useAccount, useAppwrite, useCollection, useCreateAnonymousSession, useCreateDocument, useCreateEmailToken, useCreateJWT, useCreateMagicURLToken, useCreateMfaAuthenticator, useCreateMfaChallenge, useCreateMfaRecoveryCodes, useCreatePhoneToken, useCreatePhoneVerification, useCreateSession, useDeleteDocument, useDeleteIdentity, useDeleteMfaAuthenticator, useDeleteSession, useDeleteSessions, useDocument, useFunction, useGetMfaRecoveryCodes, useGetPrefs, useGetSession, useListIdentities, useListMfaFactors, useListSessions, useLogin, useLogout, useLogs, useMutation, usePasswordRecovery, useQuery, useQueryClient, useResetPassword, useSignUp, useSuspenseCollection, useSuspenseCreateJWT, useSuspenseFunction, useUpdateDocument, useUpdateEmail, useUpdateMagicURLSession, useUpdateMfa, useUpdateMfaAuthenticator, useUpdateMfaChallenge, useUpdateMfaRecoveryCodes, useUpdateName, useUpdatePassword, useUpdatePhone, useUpdatePhoneSession, useUpdatePhoneVerification, useUpdatePrefs, useUpdateSession, useVerification };
package/dist/index.js CHANGED
@@ -59,6 +59,7 @@ __export(src_exports, {
59
59
  useSignUp: () => useSignUp,
60
60
  useSuspenseCollection: () => useSuspenseCollection,
61
61
  useSuspenseCreateJWT: () => useSuspenseCreateJWT,
62
+ useSuspenseFunction: () => useSuspenseFunction,
62
63
  useUpdateDocument: () => useUpdateDocument,
63
64
  useUpdateEmail: () => useUpdateEmail,
64
65
  useUpdateMagicURLSession: () => useUpdateMagicURLSession,
@@ -2163,8 +2164,89 @@ function useFunction() {
2163
2164
  currentExecution: getExecution
2164
2165
  };
2165
2166
  }
2167
+ function useSuspenseFunction({
2168
+ functionId,
2169
+ body = {},
2170
+ async = false,
2171
+ path = "",
2172
+ method = "POST"
2173
+ }) {
2174
+ const { graphql: graphql2 } = useAppwrite();
2175
+ const [currentExecution, setCurrentExecution] = (0, import_react5.useState)(null);
2176
+ const [currentFunction, setCurrentFunction] = (0, import_react5.useState)(null);
2177
+ const executeFunction = useSuspenseQuery(
2178
+ {
2179
+ queryKey: ["appwrite", "functions", functionId],
2180
+ queryFn: async () => {
2181
+ setCurrentFunction(functionId);
2182
+ const { data } = await graphql2.mutation({
2183
+ query: createExecution,
2184
+ variables: {
2185
+ functionId,
2186
+ body: JSON.stringify(body),
2187
+ async,
2188
+ path,
2189
+ method
2190
+ // headers,
2191
+ }
2192
+ });
2193
+ let unsubscribe = null;
2194
+ const { _id, status, responseBody, errors } = data.functionsCreateExecution ?? {};
2195
+ if (status === "completed") {
2196
+ return JSON.parse(responseBody ?? "{}");
2197
+ }
2198
+ if (status === "failed" && errors) {
2199
+ throw new Error(errors);
2200
+ }
2201
+ setCurrentExecution(_id ?? null);
2202
+ const response = await new Promise((resolve, reject) => {
2203
+ unsubscribe = graphql2.client.subscribe(`executions.${_id}`, (event) => {
2204
+ switch (event.payload.status) {
2205
+ case "completed":
2206
+ setCurrentExecution(null);
2207
+ resolve(JSON.parse(event.payload.responseBody));
2208
+ break;
2209
+ case "failed":
2210
+ setCurrentExecution(null);
2211
+ reject(event.payload.errors);
2212
+ break;
2213
+ }
2214
+ return 1;
2215
+ });
2216
+ });
2217
+ unsubscribe?.();
2218
+ return response;
2219
+ }
2220
+ }
2221
+ );
2222
+ const getExecution = useQuery({
2223
+ queryKey: ["appwrite", "functions", currentFunction, currentExecution],
2224
+ queryFn: async () => {
2225
+ if (!currentExecution || !currentFunction) {
2226
+ return null;
2227
+ }
2228
+ const { data } = await graphql2.query({
2229
+ query: getFunctionExecution,
2230
+ variables: {
2231
+ functionId: currentFunction,
2232
+ executionId: currentExecution
2233
+ }
2234
+ });
2235
+ return data.functionsGetExecution ?? {};
2236
+ }
2237
+ });
2238
+ return {
2239
+ executeFunction,
2240
+ currentExecution: getExecution
2241
+ };
2242
+ }
2166
2243
 
2167
2244
  // src/account/fragments.ts
2245
+ var fragments_exports = {};
2246
+ __export(fragments_exports, {
2247
+ Account_UserFragment: () => Account_UserFragment,
2248
+ Identity_ProviderFragment: () => Identity_ProviderFragment
2249
+ });
2168
2250
  var Account_UserFragment = gql(
2169
2251
  /* GraphQL */
2170
2252
  `
@@ -2190,8 +2272,7 @@ var Identity_ProviderFragment = gql(
2190
2272
 
2191
2273
  // src/index.ts
2192
2274
  var fragments = {
2193
- Account_UserFragment,
2194
- Identity_ProviderFragment
2275
+ ...fragments_exports
2195
2276
  };
2196
2277
  // Annotate the CommonJS export names for ESM import in node:
2197
2278
  0 && (module.exports = {
@@ -2235,6 +2316,7 @@ var fragments = {
2235
2316
  useSignUp,
2236
2317
  useSuspenseCollection,
2237
2318
  useSuspenseCreateJWT,
2319
+ useSuspenseFunction,
2238
2320
  useUpdateDocument,
2239
2321
  useUpdateEmail,
2240
2322
  useUpdateMagicURLSession,