eny-ai 1.0.0 → 2.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/V2_README.md +414 -0
- package/dist/chunk-2NUS77CI.js +195 -0
- package/dist/chunk-5KPALVCK.js +280 -0
- package/dist/{chunk-2WFUL4XJ.js → chunk-5PZUUNHS.js} +717 -751
- package/dist/{chunk-E4KJZEXX.js → chunk-AJH2I5ZI.js} +5 -0
- package/dist/chunk-LVJ3GJRQ.js +360 -0
- package/dist/{chunk-PNKVD2UK.js → chunk-MXA7TAAG.js} +11 -1
- package/dist/cli.js +5 -4
- package/dist/firebase.cjs +296 -0
- package/dist/firebase.d.cts +136 -0
- package/dist/firebase.d.ts +136 -0
- package/dist/firebase.js +17 -0
- package/dist/hooks.cjs +236 -0
- package/dist/hooks.d.cts +184 -0
- package/dist/hooks.d.ts +184 -0
- package/dist/hooks.js +31 -0
- package/dist/index.cjs +1622 -1092
- package/dist/index.d.cts +16 -195
- package/dist/index.d.ts +16 -195
- package/dist/index.js +68 -262
- package/dist/runtime.cjs +366 -0
- package/dist/runtime.d.cts +229 -0
- package/dist/runtime.d.ts +229 -0
- package/dist/runtime.js +25 -0
- package/dist/symbols.js +2 -2
- package/examples/app-simbolico-completo.tsx +249 -0
- package/examples/nextjs-integration.tsx +446 -0
- package/examples/v2-demo.tsx +377 -0
- package/package.json +23 -11
- package/dist/react/index.cjs +0 -342
- package/dist/react/index.d.cts +0 -751
- package/dist/react/index.d.ts +0 -751
- package/dist/react/index.js +0 -284
|
@@ -0,0 +1,280 @@
|
|
|
1
|
+
import {
|
|
2
|
+
__esm,
|
|
3
|
+
__export,
|
|
4
|
+
init_esm_shims
|
|
5
|
+
} from "./chunk-MXA7TAAG.js";
|
|
6
|
+
|
|
7
|
+
// src/firebase/index.ts
|
|
8
|
+
var firebase_exports = {};
|
|
9
|
+
__export(firebase_exports, {
|
|
10
|
+
ENYFirebase: () => ENYFirebase,
|
|
11
|
+
firebase: () => firebase,
|
|
12
|
+
useAuth: () => useAuth,
|
|
13
|
+
useFirebase: () => useFirebase,
|
|
14
|
+
useRealtimeData: () => useRealtimeData
|
|
15
|
+
});
|
|
16
|
+
import { initializeApp } from "firebase/app";
|
|
17
|
+
import { getAuth, signInWithEmailAndPassword, createUserWithEmailAndPassword, signOut, onAuthStateChanged } from "firebase/auth";
|
|
18
|
+
import { getDatabase, ref, set, get, update, remove, onValue, query, orderByChild, limitToFirst } from "firebase/database";
|
|
19
|
+
import React from "react";
|
|
20
|
+
function useFirebase() {
|
|
21
|
+
return firebase;
|
|
22
|
+
}
|
|
23
|
+
function useAuth(callback) {
|
|
24
|
+
const [user, setUser] = React.useState(null);
|
|
25
|
+
const [loading, setLoading] = React.useState(true);
|
|
26
|
+
React.useEffect(() => {
|
|
27
|
+
const unsubscribe = firebase.onAuthStateChange((u) => {
|
|
28
|
+
setUser(u);
|
|
29
|
+
setLoading(false);
|
|
30
|
+
callback?.(u);
|
|
31
|
+
});
|
|
32
|
+
return () => unsubscribe();
|
|
33
|
+
}, [callback]);
|
|
34
|
+
return { user, loading };
|
|
35
|
+
}
|
|
36
|
+
function useRealtimeData(path) {
|
|
37
|
+
const [data, setData] = React.useState(null);
|
|
38
|
+
const [loading, setLoading] = React.useState(true);
|
|
39
|
+
React.useEffect(() => {
|
|
40
|
+
const unsubscribe = firebase.watch(path, (d) => {
|
|
41
|
+
setData(d);
|
|
42
|
+
setLoading(false);
|
|
43
|
+
});
|
|
44
|
+
return () => unsubscribe();
|
|
45
|
+
}, [path]);
|
|
46
|
+
return { data, loading };
|
|
47
|
+
}
|
|
48
|
+
var ENYFirebase, firebase;
|
|
49
|
+
var init_firebase = __esm({
|
|
50
|
+
"src/firebase/index.ts"() {
|
|
51
|
+
init_esm_shims();
|
|
52
|
+
ENYFirebase = class {
|
|
53
|
+
constructor() {
|
|
54
|
+
this.app = null;
|
|
55
|
+
this.auth = null;
|
|
56
|
+
this.db = null;
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* ⚙️ - Inicializar Firebase
|
|
60
|
+
*/
|
|
61
|
+
initialize(config) {
|
|
62
|
+
this.app = initializeApp(config);
|
|
63
|
+
this.auth = getAuth(this.app);
|
|
64
|
+
this.db = getDatabase(this.app);
|
|
65
|
+
console.log("\u2705 Firebase inicializado");
|
|
66
|
+
}
|
|
67
|
+
// ═════════════════════════════════════════════════════════════════════════════
|
|
68
|
+
// MÉTODOS AUTENTICAÇÃO
|
|
69
|
+
// ═════════════════════════════════════════════════════════════════════════════
|
|
70
|
+
/**
|
|
71
|
+
* signin - Login com email/senha
|
|
72
|
+
* signin(email, password)
|
|
73
|
+
* Alias: 🔑(email, password)
|
|
74
|
+
*/
|
|
75
|
+
async signin(email, password) {
|
|
76
|
+
if (!this.auth) throw new Error("Firebase not initialized");
|
|
77
|
+
try {
|
|
78
|
+
const credential = await signInWithEmailAndPassword(this.auth, email, password);
|
|
79
|
+
console.log("\u2705 Login bem-sucedido:", email);
|
|
80
|
+
return {
|
|
81
|
+
user: credential.user,
|
|
82
|
+
success: true
|
|
83
|
+
};
|
|
84
|
+
} catch (error) {
|
|
85
|
+
console.error("\u274C Erro login:", error);
|
|
86
|
+
throw error;
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* signup - Criar conta
|
|
91
|
+
* signup(email, password)
|
|
92
|
+
* Alias: 📝(email, password)
|
|
93
|
+
*/
|
|
94
|
+
async signup(email, password) {
|
|
95
|
+
if (!this.auth) throw new Error("Firebase not initialized");
|
|
96
|
+
try {
|
|
97
|
+
const credential = await createUserWithEmailAndPassword(this.auth, email, password);
|
|
98
|
+
console.log("\u2705 Conta criada:", email);
|
|
99
|
+
return {
|
|
100
|
+
user: credential.user,
|
|
101
|
+
success: true
|
|
102
|
+
};
|
|
103
|
+
} catch (error) {
|
|
104
|
+
console.error("\u274C Erro criar conta:", error);
|
|
105
|
+
throw error;
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* signout - Logout
|
|
110
|
+
* signout()
|
|
111
|
+
* Alias: 🚪()
|
|
112
|
+
*/
|
|
113
|
+
async signout() {
|
|
114
|
+
if (!this.auth) throw new Error("Firebase not initialized");
|
|
115
|
+
try {
|
|
116
|
+
await signOut(this.auth);
|
|
117
|
+
console.log("\u{1F44B} Desconectado");
|
|
118
|
+
return { success: true };
|
|
119
|
+
} catch (error) {
|
|
120
|
+
console.error("\u274C Erro logout:", error);
|
|
121
|
+
throw error;
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* currentUser - Obter usuário atual
|
|
126
|
+
* Alias: 👤
|
|
127
|
+
*/
|
|
128
|
+
get currentUser() {
|
|
129
|
+
return this.auth?.currentUser || null;
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* onAuthStateChange - Observar estado autenticação
|
|
133
|
+
* onAuthStateChange((user) => {...})
|
|
134
|
+
* Alias: 👁((user) => {...})
|
|
135
|
+
*/
|
|
136
|
+
onAuthStateChange(callback) {
|
|
137
|
+
if (!this.auth) throw new Error("Firebase not initialized");
|
|
138
|
+
return onAuthStateChanged(this.auth, callback);
|
|
139
|
+
}
|
|
140
|
+
// ═════════════════════════════════════════════════════════════════════════════
|
|
141
|
+
// MÉTODOS DATABASE
|
|
142
|
+
// ═════════════════════════════════════════════════════════════════════════════
|
|
143
|
+
/**
|
|
144
|
+
* write - Escrever dados
|
|
145
|
+
* write('users/123', { name: 'João' })
|
|
146
|
+
* Alias: 📊(path, data)
|
|
147
|
+
*/
|
|
148
|
+
async write(path, data) {
|
|
149
|
+
if (!this.db) throw new Error("Firebase not initialized");
|
|
150
|
+
try {
|
|
151
|
+
const dbRef = ref(this.db, path);
|
|
152
|
+
await set(dbRef, data);
|
|
153
|
+
console.log("\u2705 Dados salvos:", path);
|
|
154
|
+
return { success: true };
|
|
155
|
+
} catch (error) {
|
|
156
|
+
console.error("\u274C Erro salvar:", error);
|
|
157
|
+
throw error;
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
/**
|
|
161
|
+
* read - Ler dados (uma vez)
|
|
162
|
+
* read('users/123')
|
|
163
|
+
* Alias: 🔍('users/123')
|
|
164
|
+
*/
|
|
165
|
+
async read(path) {
|
|
166
|
+
if (!this.db) throw new Error("Firebase not initialized");
|
|
167
|
+
try {
|
|
168
|
+
const dbRef = ref(this.db, path);
|
|
169
|
+
const snapshot = await get(dbRef);
|
|
170
|
+
console.log("\u2705 Dados lidos:", path);
|
|
171
|
+
return snapshot.val();
|
|
172
|
+
} catch (error) {
|
|
173
|
+
console.error("\u274C Erro ler:", error);
|
|
174
|
+
throw error;
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
/**
|
|
178
|
+
* watch - Observar dados em tempo real
|
|
179
|
+
* watch('users/123', (data) => {...})
|
|
180
|
+
* Alias: 📡('users/123', (data) => {...})
|
|
181
|
+
*/
|
|
182
|
+
watch(path, callback) {
|
|
183
|
+
if (!this.db) throw new Error("Firebase not initialized");
|
|
184
|
+
const dbRef = ref(this.db, path);
|
|
185
|
+
return onValue(dbRef, (snapshot) => {
|
|
186
|
+
callback(snapshot.val());
|
|
187
|
+
});
|
|
188
|
+
}
|
|
189
|
+
/**
|
|
190
|
+
* update - Atualizar dados específicos
|
|
191
|
+
* update('users/123', { name: 'João Silva' })
|
|
192
|
+
* Alias: ✏️('users/123', { name: 'João Silva' })
|
|
193
|
+
*/
|
|
194
|
+
async updateData(path, data) {
|
|
195
|
+
if (!this.db) throw new Error("Firebase not initialized");
|
|
196
|
+
try {
|
|
197
|
+
const dbRef = ref(this.db, path);
|
|
198
|
+
await update(dbRef, data);
|
|
199
|
+
console.log("\u2705 Dados atualizados:", path);
|
|
200
|
+
return { success: true };
|
|
201
|
+
} catch (error) {
|
|
202
|
+
console.error("\u274C Erro atualizar:", error);
|
|
203
|
+
throw error;
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
/**
|
|
207
|
+
* delete - Deletar dados
|
|
208
|
+
* delete('users/123')
|
|
209
|
+
* Alias: 🗑️('users/123')
|
|
210
|
+
*/
|
|
211
|
+
async delete(path) {
|
|
212
|
+
if (!this.db) throw new Error("Firebase not initialized");
|
|
213
|
+
try {
|
|
214
|
+
const dbRef = ref(this.db, path);
|
|
215
|
+
await remove(dbRef);
|
|
216
|
+
console.log("\u2705 Dados deletados:", path);
|
|
217
|
+
return { success: true };
|
|
218
|
+
} catch (error) {
|
|
219
|
+
console.error("\u274C Erro deletar:", error);
|
|
220
|
+
throw error;
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
/**
|
|
224
|
+
* query - Query com ordem/limite
|
|
225
|
+
* query('users', 'age', 10)
|
|
226
|
+
* Alias: 🔗('users', 'age', 10)
|
|
227
|
+
*/
|
|
228
|
+
async queryData(path, orderBy = "", limit = 0) {
|
|
229
|
+
if (!this.db) throw new Error("Firebase not initialized");
|
|
230
|
+
try {
|
|
231
|
+
const dbRef = ref(this.db, path);
|
|
232
|
+
let q = dbRef;
|
|
233
|
+
if (orderBy) {
|
|
234
|
+
q = query(dbRef, orderByChild(orderBy));
|
|
235
|
+
}
|
|
236
|
+
if (limit) {
|
|
237
|
+
q = query(dbRef, limitToFirst(limit));
|
|
238
|
+
}
|
|
239
|
+
const snapshot = await get(q);
|
|
240
|
+
return snapshot.val();
|
|
241
|
+
} catch (error) {
|
|
242
|
+
console.error("\u274C Erro query:", error);
|
|
243
|
+
throw error;
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
// ═════════════════════════════════════════════════════════════════════════════
|
|
247
|
+
// HELPERS
|
|
248
|
+
// ═════════════════════════════════════════════════════════════════════════════
|
|
249
|
+
/**
|
|
250
|
+
* 🔐 - Contexto de autenticação
|
|
251
|
+
*/
|
|
252
|
+
getAuth() {
|
|
253
|
+
return this.auth;
|
|
254
|
+
}
|
|
255
|
+
/**
|
|
256
|
+
* 📂 - Contexto de database
|
|
257
|
+
*/
|
|
258
|
+
getDatabase() {
|
|
259
|
+
return this.db;
|
|
260
|
+
}
|
|
261
|
+
/**
|
|
262
|
+
* Verificar se está autenticado
|
|
263
|
+
*/
|
|
264
|
+
isAuthenticated() {
|
|
265
|
+
return this.currentUser !== null;
|
|
266
|
+
}
|
|
267
|
+
};
|
|
268
|
+
firebase = new ENYFirebase();
|
|
269
|
+
}
|
|
270
|
+
});
|
|
271
|
+
|
|
272
|
+
export {
|
|
273
|
+
ENYFirebase,
|
|
274
|
+
firebase,
|
|
275
|
+
useFirebase,
|
|
276
|
+
useAuth,
|
|
277
|
+
useRealtimeData,
|
|
278
|
+
firebase_exports,
|
|
279
|
+
init_firebase
|
|
280
|
+
};
|