amplifyquery 1.0.0 → 1.0.1

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 CHANGED
@@ -50,7 +50,67 @@ AmplifyQuery.configure({
50
50
  });
51
51
  ```
52
52
 
53
- ### 2. Service Creation
53
+ ### 2. Setup Provider (Important!)
54
+
55
+ Wrap your application with `AmplifyQueryProvider` at the root level. This provides the React Query client context to your components.
56
+
57
+ ```tsx
58
+ // App.tsx or your main application file
59
+ import React from "react";
60
+ import { AmplifyQueryProvider } from "amplifyquery"; // Or from 'amplifyquery/provider'
61
+ import YourApp from "./YourApp"; // Your main application component
62
+
63
+ function App() {
64
+ return (
65
+ <AmplifyQueryProvider>
66
+ <YourApp />
67
+ </AmplifyQueryProvider>
68
+ );
69
+ }
70
+
71
+ export default App;
72
+ ```
73
+
74
+ Alternatively, if you need to use a custom `QueryClient` instance:
75
+
76
+ ```tsx
77
+ // App.tsx or your main application file
78
+ import React from "react";
79
+ import { createCustomQueryProvider, getQueryClient } from "amplifyquery"; // Or from 'amplifyquery/provider'
80
+ import { QueryClient } from "@tanstack/react-query";
81
+ import YourApp from "./YourApp"; // Your main application component
82
+
83
+ // Create a custom client (optional)
84
+ const customQueryClient = new QueryClient({
85
+ defaultOptions: {
86
+ queries: {
87
+ // Your custom query client options
88
+ staleTime: 1000 * 60 * 10, // 10 minutes
89
+ },
90
+ },
91
+ });
92
+
93
+ // Create a provider with your custom client, or use the default
94
+ const MyCustomProvider = createCustomQueryProvider(customQueryClient);
95
+ // const MyDefaultProvider = createCustomQueryProvider(); // Uses the default client configured via AmplifyQuery.configure()
96
+
97
+ function App() {
98
+ return (
99
+ // Use your custom provider
100
+ <MyCustomProvider>
101
+ <YourApp />
102
+ </MyCustomProvider>
103
+ // Or, if using the default client with createCustomQueryProvider:
104
+ // <MyDefaultProvider>
105
+ // <YourApp />
106
+ // </MyDefaultProvider>
107
+ );
108
+ }
109
+
110
+ export default App;
111
+ ```
112
+
113
+ ### 3. Service Creation
54
114
 
55
115
  ```typescript
56
116
  import { AmplifyQuery } from "amplifyquery";
@@ -73,7 +133,7 @@ const UserSettingsService =
73
133
  AmplifyQuery.createSingletonService<UserSettingsModel>("UserSettings");
74
134
  ```
75
135
 
76
- ### 3. Data Fetching and Saving
136
+ ### 4. Data Fetching and Saving
77
137
 
78
138
  ```typescript
79
139
  // Fetch all items
@@ -104,7 +164,7 @@ await TodoService.update({
104
164
  await TodoService.delete("some-id");
105
165
  ```
106
166
 
107
- ### 4. Using React Hooks
167
+ ### 5. Using React Hooks
108
168
 
109
169
  ```tsx
110
170
  import React from "react";
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { getClient } from "./client";
2
- import { queryClient, createQueryKeys, invalidateModel, invalidateModelItem, invalidateModelByField, invalidateAll, ensureMutationsFlushed } from "./query";
2
+ import { queryClient, getQueryClient, createQueryKeys, invalidateModel, invalidateModelItem, invalidateModelByField, invalidateAll, ensureMutationsFlushed } from "./query";
3
3
  import { createAmplifyService } from "./service";
4
4
  import { createSingletonService } from "./singleton";
5
5
  import { AmplifyQueryConfig } from "./types";
@@ -29,8 +29,9 @@ import { createRelationalHook, setAppUrl, getAppUrl } from "./utils";
29
29
  */
30
30
  export declare function configure(config: AmplifyQueryConfig): void;
31
31
  export * from "./types";
32
- export { queryClient, invalidateModel, invalidateModelItem, invalidateModelByField, invalidateAll, ensureMutationsFlushed, createQueryKeys, };
32
+ export { queryClient, getQueryClient, invalidateModel, invalidateModelItem, invalidateModelByField, invalidateAll, ensureMutationsFlushed, createQueryKeys, };
33
33
  export { getClient };
34
+ export * from "./provider";
34
35
  export declare const Utils: {
35
36
  getUserId: () => Promise<string>;
36
37
  formatTimestamp: (date?: Date) => string;
@@ -130,4 +131,5 @@ export declare const AmplifyQuery: {
130
131
  getModelIds: {
131
132
  User: () => Promise<string>;
132
133
  };
134
+ getQueryClient: typeof getQueryClient;
133
135
  };
package/dist/index.js CHANGED
@@ -14,12 +14,13 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
14
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
- exports.AmplifyQuery = exports.getAppUrl = exports.setAppUrl = exports.Auth = exports.Storage = exports.Utils = exports.getClient = exports.createQueryKeys = exports.ensureMutationsFlushed = exports.invalidateAll = exports.invalidateModelByField = exports.invalidateModelItem = exports.invalidateModel = exports.queryClient = void 0;
17
+ exports.AmplifyQuery = exports.getAppUrl = exports.setAppUrl = exports.Auth = exports.Storage = exports.Utils = exports.getClient = exports.createQueryKeys = exports.ensureMutationsFlushed = exports.invalidateAll = exports.invalidateModelByField = exports.invalidateModelItem = exports.invalidateModel = exports.getQueryClient = exports.queryClient = void 0;
18
18
  exports.configure = configure;
19
19
  const client_1 = require("./client");
20
20
  Object.defineProperty(exports, "getClient", { enumerable: true, get: function () { return client_1.getClient; } });
21
21
  const query_1 = require("./query");
22
22
  Object.defineProperty(exports, "queryClient", { enumerable: true, get: function () { return query_1.queryClient; } });
23
+ Object.defineProperty(exports, "getQueryClient", { enumerable: true, get: function () { return query_1.getQueryClient; } });
23
24
  Object.defineProperty(exports, "createQueryKeys", { enumerable: true, get: function () { return query_1.createQueryKeys; } });
24
25
  Object.defineProperty(exports, "invalidateModel", { enumerable: true, get: function () { return query_1.invalidateModel; } });
25
26
  Object.defineProperty(exports, "invalidateModelItem", { enumerable: true, get: function () { return query_1.invalidateModelItem; } });
@@ -69,6 +70,8 @@ function configure(config) {
69
70
  }
70
71
  // Re-export types
71
72
  __exportStar(require("./types"), exports);
73
+ // Export provider
74
+ __exportStar(require("./provider"), exports);
72
75
  // Re-export utility services
73
76
  exports.Utils = utils_1.Utils;
74
77
  exports.Storage = utils_1.StorageService;
@@ -86,4 +89,5 @@ exports.AmplifyQuery = {
86
89
  Storage: utils_1.StorageService,
87
90
  Auth: utils_1.AuthService,
88
91
  getModelIds: singleton_1.getModelIds,
92
+ getQueryClient: query_1.getQueryClient,
89
93
  };
@@ -0,0 +1,59 @@
1
+ import * as React from "react";
2
+ import { QueryClient } from "@tanstack/react-query";
3
+ interface AmplifyQueryProviderProps {
4
+ children: React.ReactNode;
5
+ }
6
+ /**
7
+ * TanStack Query Provider for AmplifyQuery
8
+ *
9
+ * This component provides the QueryClient to the entire application.
10
+ * Use this at the root of your application to enable React Query.
11
+ *
12
+ * @example
13
+ * ```tsx
14
+ * import { AmplifyQueryProvider } from 'amplifyquery/provider';
15
+ *
16
+ * function App() {
17
+ * return (
18
+ * <AmplifyQueryProvider>
19
+ * <YourApp />
20
+ * </AmplifyQueryProvider>
21
+ * );
22
+ * }
23
+ * ```
24
+ */
25
+ export declare function AmplifyQueryProvider({ children, }: AmplifyQueryProviderProps): React.ReactElement;
26
+ /**
27
+ * Creates a custom QueryClient provider with configuration options
28
+ *
29
+ * @param customQueryClient Optional custom QueryClient instance
30
+ * @returns A provider component with the custom client
31
+ *
32
+ * @example
33
+ * ```tsx
34
+ * import { createCustomQueryProvider } from 'amplifyquery/provider';
35
+ * import { QueryClient } from '@tanstack/react-query';
36
+ *
37
+ * // Create a custom client with specific options
38
+ * const customClient = new QueryClient({
39
+ * defaultOptions: {
40
+ * queries: {
41
+ * staleTime: 1000 * 60 * 5,
42
+ * },
43
+ * },
44
+ * });
45
+ *
46
+ * // Create a provider with this client
47
+ * const CustomProvider = createCustomQueryProvider(customClient);
48
+ *
49
+ * function App() {
50
+ * return (
51
+ * <CustomProvider>
52
+ * <YourApp />
53
+ * </CustomProvider>
54
+ * );
55
+ * }
56
+ * ```
57
+ */
58
+ export declare function createCustomQueryProvider(customQueryClient?: QueryClient): ({ children }: AmplifyQueryProviderProps) => React.ReactElement;
59
+ export {};
@@ -0,0 +1,103 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.AmplifyQueryProvider = AmplifyQueryProvider;
37
+ exports.createCustomQueryProvider = createCustomQueryProvider;
38
+ const React = __importStar(require("react"));
39
+ const react_query_1 = require("@tanstack/react-query");
40
+ const query_1 = require("./query");
41
+ /**
42
+ * TanStack Query Provider for AmplifyQuery
43
+ *
44
+ * This component provides the QueryClient to the entire application.
45
+ * Use this at the root of your application to enable React Query.
46
+ *
47
+ * @example
48
+ * ```tsx
49
+ * import { AmplifyQueryProvider } from 'amplifyquery/provider';
50
+ *
51
+ * function App() {
52
+ * return (
53
+ * <AmplifyQueryProvider>
54
+ * <YourApp />
55
+ * </AmplifyQueryProvider>
56
+ * );
57
+ * }
58
+ * ```
59
+ */
60
+ function AmplifyQueryProvider({ children, }) {
61
+ // Get the shared query client instance
62
+ const queryClient = (0, query_1.getQueryClient)();
63
+ return (<react_query_1.QueryClientProvider client={queryClient}>{children}</react_query_1.QueryClientProvider>);
64
+ }
65
+ /**
66
+ * Creates a custom QueryClient provider with configuration options
67
+ *
68
+ * @param customQueryClient Optional custom QueryClient instance
69
+ * @returns A provider component with the custom client
70
+ *
71
+ * @example
72
+ * ```tsx
73
+ * import { createCustomQueryProvider } from 'amplifyquery/provider';
74
+ * import { QueryClient } from '@tanstack/react-query';
75
+ *
76
+ * // Create a custom client with specific options
77
+ * const customClient = new QueryClient({
78
+ * defaultOptions: {
79
+ * queries: {
80
+ * staleTime: 1000 * 60 * 5,
81
+ * },
82
+ * },
83
+ * });
84
+ *
85
+ * // Create a provider with this client
86
+ * const CustomProvider = createCustomQueryProvider(customClient);
87
+ *
88
+ * function App() {
89
+ * return (
90
+ * <CustomProvider>
91
+ * <YourApp />
92
+ * </CustomProvider>
93
+ * );
94
+ * }
95
+ * ```
96
+ */
97
+ function createCustomQueryProvider(customQueryClient) {
98
+ return ({ children }) => {
99
+ // Use custom client or get the default one
100
+ const client = customQueryClient || (0, query_1.getQueryClient)();
101
+ return (<react_query_1.QueryClientProvider client={client}>{children}</react_query_1.QueryClientProvider>);
102
+ };
103
+ }
package/dist/query.d.ts CHANGED
@@ -12,6 +12,11 @@ type ConfigOptions = {
12
12
  * TanStack Query client
13
13
  */
14
14
  export declare let queryClient: QueryClient;
15
+ /**
16
+ * Get the current query client instance
17
+ * @returns The QueryClient instance
18
+ */
19
+ export declare function getQueryClient(): QueryClient;
15
20
  /**
16
21
  * AmplifyQuery configuration
17
22
  * @param options Configuration options
package/dist/query.js CHANGED
@@ -10,6 +10,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
10
10
  };
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.queryClient = void 0;
13
+ exports.getQueryClient = getQueryClient;
13
14
  exports.configure = configure;
14
15
  exports.createQueryKeys = createQueryKeys;
15
16
  exports.invalidateModel = invalidateModel;
@@ -98,6 +99,13 @@ function createMmkvPersister() {
98
99
  * TanStack Query client
99
100
  */
100
101
  exports.queryClient = new react_query_1.QueryClient(config.queryClientConfig);
102
+ /**
103
+ * Get the current query client instance
104
+ * @returns The QueryClient instance
105
+ */
106
+ function getQueryClient() {
107
+ return exports.queryClient;
108
+ }
101
109
  /**
102
110
  * AmplifyQuery configuration
103
111
  * @param options Configuration options
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "amplifyquery",
3
- "version": "1.0.0",
3
+ "version": "1.0.1",
4
4
  "description": "Amplify+Query",
5
5
  "keywords": [
6
6
  "Amplify",