@vaiftech/react 1.0.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024-2026 VAIF Technologies
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,230 @@
1
+ # @vaif/react
2
+
3
+ React hooks for VAIF Studio - a Backend-as-a-Service platform.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ npm install @vaif/react @vaif/client
9
+ # or
10
+ pnpm add @vaif/react @vaif/client
11
+ # or
12
+ yarn add @vaif/react @vaif/client
13
+ ```
14
+
15
+ ## Quick Start
16
+
17
+ ```tsx
18
+ import { VaifProvider } from '@vaif/react';
19
+ import { createVaifClient } from '@vaif/client';
20
+
21
+ const client = createVaifClient({
22
+ baseUrl: 'https://api.myproject.vaif.io',
23
+ apiKey: 'vaif_pk_xxx',
24
+ });
25
+
26
+ function App() {
27
+ return (
28
+ <VaifProvider client={client}>
29
+ <MyComponent />
30
+ </VaifProvider>
31
+ );
32
+ }
33
+ ```
34
+
35
+ ## Hooks
36
+
37
+ ### Authentication
38
+
39
+ ```tsx
40
+ import { useAuth, useUser, useSession } from '@vaif/react';
41
+
42
+ function AuthComponent() {
43
+ const { user, isLoading, signIn, signUp, signOut } = useAuth();
44
+
45
+ if (isLoading) return <div>Loading...</div>;
46
+
47
+ if (!user) {
48
+ return (
49
+ <button onClick={() => signIn({ email, password })}>
50
+ Sign In
51
+ </button>
52
+ );
53
+ }
54
+
55
+ return (
56
+ <div>
57
+ <p>Welcome, {user.email}</p>
58
+ <button onClick={signOut}>Sign Out</button>
59
+ </div>
60
+ );
61
+ }
62
+
63
+ // Just the user
64
+ function Profile() {
65
+ const { user, isLoading } = useUser();
66
+ return user ? <p>{user.email}</p> : null;
67
+ }
68
+
69
+ // Session management
70
+ function SessionInfo() {
71
+ const { session, refresh } = useSession();
72
+ return <p>Expires: {session?.expiresAt}</p>;
73
+ }
74
+ ```
75
+
76
+ ### Data Fetching
77
+
78
+ ```tsx
79
+ import { useQuery, useMutation } from '@vaif/react';
80
+
81
+ interface Post {
82
+ id: string;
83
+ title: string;
84
+ content: string;
85
+ }
86
+
87
+ function PostList() {
88
+ const { data: posts, isLoading, error, refetch } = useQuery<Post>('posts', {
89
+ filters: [{ field: 'published', operator: 'eq', value: true }],
90
+ orderBy: [{ field: 'createdAt', direction: 'desc' }],
91
+ limit: 10,
92
+ });
93
+
94
+ if (isLoading) return <div>Loading...</div>;
95
+ if (error) return <div>Error: {error.message}</div>;
96
+
97
+ return (
98
+ <ul>
99
+ {posts?.map(post => (
100
+ <li key={post.id}>{post.title}</li>
101
+ ))}
102
+ </ul>
103
+ );
104
+ }
105
+
106
+ function CreatePost() {
107
+ const { create, isCreating } = useMutation<Post>('posts');
108
+
109
+ const handleSubmit = async (data: Omit<Post, 'id'>) => {
110
+ const newPost = await create(data);
111
+ console.log('Created:', newPost);
112
+ };
113
+
114
+ return (
115
+ <button onClick={() => handleSubmit({ title: 'New', content: '...' })} disabled={isCreating}>
116
+ {isCreating ? 'Creating...' : 'Create Post'}
117
+ </button>
118
+ );
119
+ }
120
+ ```
121
+
122
+ ### Realtime
123
+
124
+ ```tsx
125
+ import { useRealtime, useRealtimeQuery } from '@vaif/react';
126
+
127
+ // Subscribe to changes
128
+ function MessageListener() {
129
+ useRealtime<Message>('messages', {
130
+ event: 'INSERT',
131
+ onInsert: (message) => {
132
+ console.log('New message:', message);
133
+ },
134
+ });
135
+
136
+ return null;
137
+ }
138
+
139
+ // Query with automatic realtime updates
140
+ function LiveMessages() {
141
+ const { data: messages } = useRealtimeQuery<Message>('messages', {
142
+ orderBy: [{ field: 'createdAt', direction: 'desc' }],
143
+ limit: 50,
144
+ });
145
+
146
+ return (
147
+ <ul>
148
+ {messages?.map(msg => (
149
+ <li key={msg.id}>{msg.content}</li>
150
+ ))}
151
+ </ul>
152
+ );
153
+ }
154
+ ```
155
+
156
+ ### Storage
157
+
158
+ ```tsx
159
+ import { useUpload, useDownload, useFile, usePublicUrl } from '@vaif/react';
160
+
161
+ function FileUpload() {
162
+ const { upload, progress, isUploading, error } = useUpload();
163
+
164
+ const handleUpload = async (file: File) => {
165
+ const result = await upload(file, `uploads/${file.name}`);
166
+ console.log('Uploaded:', result?.url);
167
+ };
168
+
169
+ return (
170
+ <div>
171
+ <input type="file" onChange={(e) => handleUpload(e.target.files![0])} />
172
+ {isUploading && <progress value={progress} max={100} />}
173
+ {error && <p>Error: {error.message}</p>}
174
+ </div>
175
+ );
176
+ }
177
+
178
+ function FileDisplay({ path }: { path: string }) {
179
+ const url = usePublicUrl(path);
180
+ return url ? <img src={url} alt="" /> : null;
181
+ }
182
+ ```
183
+
184
+ ### Edge Functions
185
+
186
+ ```tsx
187
+ import { useFunction } from '@vaif/react';
188
+
189
+ function SendEmail() {
190
+ const { invoke, isInvoking, error, result } = useFunction('send-email');
191
+
192
+ const handleSend = async () => {
193
+ await invoke({
194
+ to: 'user@example.com',
195
+ subject: 'Hello',
196
+ });
197
+ };
198
+
199
+ return (
200
+ <button onClick={handleSend} disabled={isInvoking}>
201
+ {isInvoking ? 'Sending...' : 'Send Email'}
202
+ </button>
203
+ );
204
+ }
205
+ ```
206
+
207
+ ## TypeScript Support
208
+
209
+ All hooks support TypeScript generics for full type safety:
210
+
211
+ ```tsx
212
+ interface User {
213
+ id: string;
214
+ email: string;
215
+ name: string;
216
+ }
217
+
218
+ const { data } = useQuery<User>('users');
219
+ // data is User[] | undefined
220
+ ```
221
+
222
+ ## Related Packages
223
+
224
+ - [@vaif/client](https://www.npmjs.com/package/@vaif/client) - Core client SDK
225
+ - [@vaif/sdk-expo](https://www.npmjs.com/package/@vaif/sdk-expo) - React Native/Expo SDK
226
+ - [@vaif/cli](https://www.npmjs.com/package/@vaif/cli) - CLI tools
227
+
228
+ ## License
229
+
230
+ MIT