@pisell/utils 1.0.6 → 1.0.7
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/es/firebase/config/index.d.ts +20 -0
- package/es/firebase/config/index.js +13 -0
- package/es/firebase/index.d.ts +11 -0
- package/es/firebase/index.js +179 -0
- package/es/platform.js +1 -1
- package/lib/firebase/config/index.d.ts +20 -0
- package/lib/firebase/config/index.js +42 -0
- package/lib/firebase/index.d.ts +11 -0
- package/lib/firebase/index.js +128 -0
- package/lib/platform.js +1 -1
- package/package.json +3 -2
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
declare let firebaseConfig: {
|
|
2
|
+
apiKey: string;
|
|
3
|
+
authDomain: string;
|
|
4
|
+
projectId: string;
|
|
5
|
+
storageBucket: string;
|
|
6
|
+
messagingSenderId: string;
|
|
7
|
+
appId: string;
|
|
8
|
+
databaseURL: string;
|
|
9
|
+
};
|
|
10
|
+
declare type InjectedConfigType = {
|
|
11
|
+
apiKey: string;
|
|
12
|
+
authDomain: string;
|
|
13
|
+
projectId: string;
|
|
14
|
+
storageBucket: string;
|
|
15
|
+
messagingSenderId: string;
|
|
16
|
+
appId: string;
|
|
17
|
+
databaseURL: string;
|
|
18
|
+
};
|
|
19
|
+
export declare const injectConfig: (context: InjectedConfigType) => void;
|
|
20
|
+
export default firebaseConfig;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
var firebaseConfig = {
|
|
2
|
+
apiKey: 'AIzaSyDuOjRgJtahbsI84cJ0cxiGpTAUU4fcaos',
|
|
3
|
+
authDomain: 'wzwtest-65bf6.firebaseapp.com',
|
|
4
|
+
projectId: 'wzwtest-65bf6',
|
|
5
|
+
storageBucket: 'wzwtest-65bf6.appspot.com',
|
|
6
|
+
messagingSenderId: '798575306619',
|
|
7
|
+
appId: '1:798575306619:web:48bd1102aae4a727a0bfde',
|
|
8
|
+
databaseURL: 'https://wzwtest-65bf6-default-rtdb.asia-southeast1.firebasedatabase.app'
|
|
9
|
+
};
|
|
10
|
+
export var injectConfig = function injectConfig(context) {
|
|
11
|
+
firebaseConfig = context;
|
|
12
|
+
};
|
|
13
|
+
export default firebaseConfig;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
declare const firebaseApp: import("firebase/app").FirebaseApp;
|
|
2
|
+
export { firebaseApp };
|
|
3
|
+
export declare const getPath: (path: string) => string;
|
|
4
|
+
export declare const setAuthStateChangeCallback: (callback: (user: any) => void) => void;
|
|
5
|
+
export declare const signUp: (email: string, password: string) => Promise<import("firebase/auth").User>;
|
|
6
|
+
export declare const signInUser: (email: string, password: string) => Promise<import("firebase/auth").User>;
|
|
7
|
+
export declare const signOutUser: () => Promise<void>;
|
|
8
|
+
export declare const readData: (path: string) => Promise<any>;
|
|
9
|
+
export declare const writeData: (path: string, data: any) => Promise<void>;
|
|
10
|
+
export declare const onDataChange: (path: string, callback: (snapshot: any) => void) => import("firebase/database").Unsubscribe;
|
|
11
|
+
export declare const removeDataListener: (listener: any) => void;
|
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
|
|
2
|
+
function _regeneratorRuntime() { "use strict"; /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */ _regeneratorRuntime = function _regeneratorRuntime() { return exports; }; var exports = {}, Op = Object.prototype, hasOwn = Op.hasOwnProperty, defineProperty = Object.defineProperty || function (obj, key, desc) { obj[key] = desc.value; }, $Symbol = "function" == typeof Symbol ? Symbol : {}, iteratorSymbol = $Symbol.iterator || "@@iterator", asyncIteratorSymbol = $Symbol.asyncIterator || "@@asyncIterator", toStringTagSymbol = $Symbol.toStringTag || "@@toStringTag"; function define(obj, key, value) { return Object.defineProperty(obj, key, { value: value, enumerable: !0, configurable: !0, writable: !0 }), obj[key]; } try { define({}, ""); } catch (err) { define = function define(obj, key, value) { return obj[key] = value; }; } function wrap(innerFn, outerFn, self, tryLocsList) { var protoGenerator = outerFn && outerFn.prototype instanceof Generator ? outerFn : Generator, generator = Object.create(protoGenerator.prototype), context = new Context(tryLocsList || []); return defineProperty(generator, "_invoke", { value: makeInvokeMethod(innerFn, self, context) }), generator; } function tryCatch(fn, obj, arg) { try { return { type: "normal", arg: fn.call(obj, arg) }; } catch (err) { return { type: "throw", arg: err }; } } exports.wrap = wrap; var ContinueSentinel = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} var IteratorPrototype = {}; define(IteratorPrototype, iteratorSymbol, function () { return this; }); var getProto = Object.getPrototypeOf, NativeIteratorPrototype = getProto && getProto(getProto(values([]))); NativeIteratorPrototype && NativeIteratorPrototype !== Op && hasOwn.call(NativeIteratorPrototype, iteratorSymbol) && (IteratorPrototype = NativeIteratorPrototype); var Gp = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(IteratorPrototype); function defineIteratorMethods(prototype) { ["next", "throw", "return"].forEach(function (method) { define(prototype, method, function (arg) { return this._invoke(method, arg); }); }); } function AsyncIterator(generator, PromiseImpl) { function invoke(method, arg, resolve, reject) { var record = tryCatch(generator[method], generator, arg); if ("throw" !== record.type) { var result = record.arg, value = result.value; return value && "object" == _typeof(value) && hasOwn.call(value, "__await") ? PromiseImpl.resolve(value.__await).then(function (value) { invoke("next", value, resolve, reject); }, function (err) { invoke("throw", err, resolve, reject); }) : PromiseImpl.resolve(value).then(function (unwrapped) { result.value = unwrapped, resolve(result); }, function (error) { return invoke("throw", error, resolve, reject); }); } reject(record.arg); } var previousPromise; defineProperty(this, "_invoke", { value: function value(method, arg) { function callInvokeWithMethodAndArg() { return new PromiseImpl(function (resolve, reject) { invoke(method, arg, resolve, reject); }); } return previousPromise = previousPromise ? previousPromise.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg(); } }); } function makeInvokeMethod(innerFn, self, context) { var state = "suspendedStart"; return function (method, arg) { if ("executing" === state) throw new Error("Generator is already running"); if ("completed" === state) { if ("throw" === method) throw arg; return doneResult(); } for (context.method = method, context.arg = arg;;) { var delegate = context.delegate; if (delegate) { var delegateResult = maybeInvokeDelegate(delegate, context); if (delegateResult) { if (delegateResult === ContinueSentinel) continue; return delegateResult; } } if ("next" === context.method) context.sent = context._sent = context.arg;else if ("throw" === context.method) { if ("suspendedStart" === state) throw state = "completed", context.arg; context.dispatchException(context.arg); } else "return" === context.method && context.abrupt("return", context.arg); state = "executing"; var record = tryCatch(innerFn, self, context); if ("normal" === record.type) { if (state = context.done ? "completed" : "suspendedYield", record.arg === ContinueSentinel) continue; return { value: record.arg, done: context.done }; } "throw" === record.type && (state = "completed", context.method = "throw", context.arg = record.arg); } }; } function maybeInvokeDelegate(delegate, context) { var methodName = context.method, method = delegate.iterator[methodName]; if (undefined === method) return context.delegate = null, "throw" === methodName && delegate.iterator.return && (context.method = "return", context.arg = undefined, maybeInvokeDelegate(delegate, context), "throw" === context.method) || "return" !== methodName && (context.method = "throw", context.arg = new TypeError("The iterator does not provide a '" + methodName + "' method")), ContinueSentinel; var record = tryCatch(method, delegate.iterator, context.arg); if ("throw" === record.type) return context.method = "throw", context.arg = record.arg, context.delegate = null, ContinueSentinel; var info = record.arg; return info ? info.done ? (context[delegate.resultName] = info.value, context.next = delegate.nextLoc, "return" !== context.method && (context.method = "next", context.arg = undefined), context.delegate = null, ContinueSentinel) : info : (context.method = "throw", context.arg = new TypeError("iterator result is not an object"), context.delegate = null, ContinueSentinel); } function pushTryEntry(locs) { var entry = { tryLoc: locs[0] }; 1 in locs && (entry.catchLoc = locs[1]), 2 in locs && (entry.finallyLoc = locs[2], entry.afterLoc = locs[3]), this.tryEntries.push(entry); } function resetTryEntry(entry) { var record = entry.completion || {}; record.type = "normal", delete record.arg, entry.completion = record; } function Context(tryLocsList) { this.tryEntries = [{ tryLoc: "root" }], tryLocsList.forEach(pushTryEntry, this), this.reset(!0); } function values(iterable) { if (iterable) { var iteratorMethod = iterable[iteratorSymbol]; if (iteratorMethod) return iteratorMethod.call(iterable); if ("function" == typeof iterable.next) return iterable; if (!isNaN(iterable.length)) { var i = -1, next = function next() { for (; ++i < iterable.length;) if (hasOwn.call(iterable, i)) return next.value = iterable[i], next.done = !1, next; return next.value = undefined, next.done = !0, next; }; return next.next = next; } } return { next: doneResult }; } function doneResult() { return { value: undefined, done: !0 }; } return GeneratorFunction.prototype = GeneratorFunctionPrototype, defineProperty(Gp, "constructor", { value: GeneratorFunctionPrototype, configurable: !0 }), defineProperty(GeneratorFunctionPrototype, "constructor", { value: GeneratorFunction, configurable: !0 }), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, toStringTagSymbol, "GeneratorFunction"), exports.isGeneratorFunction = function (genFun) { var ctor = "function" == typeof genFun && genFun.constructor; return !!ctor && (ctor === GeneratorFunction || "GeneratorFunction" === (ctor.displayName || ctor.name)); }, exports.mark = function (genFun) { return Object.setPrototypeOf ? Object.setPrototypeOf(genFun, GeneratorFunctionPrototype) : (genFun.__proto__ = GeneratorFunctionPrototype, define(genFun, toStringTagSymbol, "GeneratorFunction")), genFun.prototype = Object.create(Gp), genFun; }, exports.awrap = function (arg) { return { __await: arg }; }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, asyncIteratorSymbol, function () { return this; }), exports.AsyncIterator = AsyncIterator, exports.async = function (innerFn, outerFn, self, tryLocsList, PromiseImpl) { void 0 === PromiseImpl && (PromiseImpl = Promise); var iter = new AsyncIterator(wrap(innerFn, outerFn, self, tryLocsList), PromiseImpl); return exports.isGeneratorFunction(outerFn) ? iter : iter.next().then(function (result) { return result.done ? result.value : iter.next(); }); }, defineIteratorMethods(Gp), define(Gp, toStringTagSymbol, "Generator"), define(Gp, iteratorSymbol, function () { return this; }), define(Gp, "toString", function () { return "[object Generator]"; }), exports.keys = function (val) { var object = Object(val), keys = []; for (var key in object) keys.push(key); return keys.reverse(), function next() { for (; keys.length;) { var key = keys.pop(); if (key in object) return next.value = key, next.done = !1, next; } return next.done = !0, next; }; }, exports.values = values, Context.prototype = { constructor: Context, reset: function reset(skipTempReset) { if (this.prev = 0, this.next = 0, this.sent = this._sent = undefined, this.done = !1, this.delegate = null, this.method = "next", this.arg = undefined, this.tryEntries.forEach(resetTryEntry), !skipTempReset) for (var name in this) "t" === name.charAt(0) && hasOwn.call(this, name) && !isNaN(+name.slice(1)) && (this[name] = undefined); }, stop: function stop() { this.done = !0; var rootRecord = this.tryEntries[0].completion; if ("throw" === rootRecord.type) throw rootRecord.arg; return this.rval; }, dispatchException: function dispatchException(exception) { if (this.done) throw exception; var context = this; function handle(loc, caught) { return record.type = "throw", record.arg = exception, context.next = loc, caught && (context.method = "next", context.arg = undefined), !!caught; } for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i], record = entry.completion; if ("root" === entry.tryLoc) return handle("end"); if (entry.tryLoc <= this.prev) { var hasCatch = hasOwn.call(entry, "catchLoc"), hasFinally = hasOwn.call(entry, "finallyLoc"); if (hasCatch && hasFinally) { if (this.prev < entry.catchLoc) return handle(entry.catchLoc, !0); if (this.prev < entry.finallyLoc) return handle(entry.finallyLoc); } else if (hasCatch) { if (this.prev < entry.catchLoc) return handle(entry.catchLoc, !0); } else { if (!hasFinally) throw new Error("try statement without catch or finally"); if (this.prev < entry.finallyLoc) return handle(entry.finallyLoc); } } } }, abrupt: function abrupt(type, arg) { for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i]; if (entry.tryLoc <= this.prev && hasOwn.call(entry, "finallyLoc") && this.prev < entry.finallyLoc) { var finallyEntry = entry; break; } } finallyEntry && ("break" === type || "continue" === type) && finallyEntry.tryLoc <= arg && arg <= finallyEntry.finallyLoc && (finallyEntry = null); var record = finallyEntry ? finallyEntry.completion : {}; return record.type = type, record.arg = arg, finallyEntry ? (this.method = "next", this.next = finallyEntry.finallyLoc, ContinueSentinel) : this.complete(record); }, complete: function complete(record, afterLoc) { if ("throw" === record.type) throw record.arg; return "break" === record.type || "continue" === record.type ? this.next = record.arg : "return" === record.type ? (this.rval = this.arg = record.arg, this.method = "return", this.next = "end") : "normal" === record.type && afterLoc && (this.next = afterLoc), ContinueSentinel; }, finish: function finish(finallyLoc) { for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i]; if (entry.finallyLoc === finallyLoc) return this.complete(entry.completion, entry.afterLoc), resetTryEntry(entry), ContinueSentinel; } }, catch: function _catch(tryLoc) { for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i]; if (entry.tryLoc === tryLoc) { var record = entry.completion; if ("throw" === record.type) { var thrown = record.arg; resetTryEntry(entry); } return thrown; } } throw new Error("illegal catch attempt"); }, delegateYield: function delegateYield(iterable, resultName, nextLoc) { return this.delegate = { iterator: values(iterable), resultName: resultName, nextLoc: nextLoc }, "next" === this.method && (this.arg = undefined), ContinueSentinel; } }, exports; }
|
|
3
|
+
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
|
|
4
|
+
function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
|
|
5
|
+
import { initializeApp } from 'firebase/app';
|
|
6
|
+
import { getAuth, createUserWithEmailAndPassword, signInWithEmailAndPassword, signOut } from 'firebase/auth';
|
|
7
|
+
import { getDatabase, ref, set, get, off, onValue } from 'firebase/database';
|
|
8
|
+
import firebaseConfig from "./config";
|
|
9
|
+
|
|
10
|
+
// 初始化 Firebase
|
|
11
|
+
var firebaseApp = initializeApp(firebaseConfig);
|
|
12
|
+
|
|
13
|
+
// 获取 Firebase Auth 实例
|
|
14
|
+
var auth = getAuth(firebaseApp);
|
|
15
|
+
|
|
16
|
+
// 获取 Firebase Database 实例
|
|
17
|
+
var database = getDatabase(firebaseApp);
|
|
18
|
+
|
|
19
|
+
// 导出 Firebase 配置,以便在需要时进行访问
|
|
20
|
+
export { firebaseApp };
|
|
21
|
+
|
|
22
|
+
// 配置化 Firebase 路径
|
|
23
|
+
export var getPath = function getPath(path) {
|
|
24
|
+
return path;
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
// 设置 Firebase 用户身份认证状态变更回调
|
|
28
|
+
export var setAuthStateChangeCallback = function setAuthStateChangeCallback(callback) {
|
|
29
|
+
auth.onAuthStateChanged(callback);
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
// 用户注册
|
|
33
|
+
export var signUp = /*#__PURE__*/function () {
|
|
34
|
+
var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(email, password) {
|
|
35
|
+
var userCredential;
|
|
36
|
+
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
37
|
+
while (1) switch (_context.prev = _context.next) {
|
|
38
|
+
case 0:
|
|
39
|
+
_context.prev = 0;
|
|
40
|
+
_context.next = 3;
|
|
41
|
+
return createUserWithEmailAndPassword(auth, email, password);
|
|
42
|
+
case 3:
|
|
43
|
+
userCredential = _context.sent;
|
|
44
|
+
return _context.abrupt("return", userCredential.user);
|
|
45
|
+
case 7:
|
|
46
|
+
_context.prev = 7;
|
|
47
|
+
_context.t0 = _context["catch"](0);
|
|
48
|
+
console.error('Error signing up:', _context.t0);
|
|
49
|
+
throw _context.t0;
|
|
50
|
+
case 11:
|
|
51
|
+
case "end":
|
|
52
|
+
return _context.stop();
|
|
53
|
+
}
|
|
54
|
+
}, _callee, null, [[0, 7]]);
|
|
55
|
+
}));
|
|
56
|
+
return function signUp(_x, _x2) {
|
|
57
|
+
return _ref.apply(this, arguments);
|
|
58
|
+
};
|
|
59
|
+
}();
|
|
60
|
+
|
|
61
|
+
// 用户登录
|
|
62
|
+
export var signInUser = /*#__PURE__*/function () {
|
|
63
|
+
var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(email, password) {
|
|
64
|
+
var userCredential;
|
|
65
|
+
return _regeneratorRuntime().wrap(function _callee2$(_context2) {
|
|
66
|
+
while (1) switch (_context2.prev = _context2.next) {
|
|
67
|
+
case 0:
|
|
68
|
+
_context2.prev = 0;
|
|
69
|
+
_context2.next = 3;
|
|
70
|
+
return signInWithEmailAndPassword(auth, email, password);
|
|
71
|
+
case 3:
|
|
72
|
+
userCredential = _context2.sent;
|
|
73
|
+
return _context2.abrupt("return", userCredential.user);
|
|
74
|
+
case 7:
|
|
75
|
+
_context2.prev = 7;
|
|
76
|
+
_context2.t0 = _context2["catch"](0);
|
|
77
|
+
console.error('Error signing in:', _context2.t0);
|
|
78
|
+
throw _context2.t0;
|
|
79
|
+
case 11:
|
|
80
|
+
case "end":
|
|
81
|
+
return _context2.stop();
|
|
82
|
+
}
|
|
83
|
+
}, _callee2, null, [[0, 7]]);
|
|
84
|
+
}));
|
|
85
|
+
return function signInUser(_x3, _x4) {
|
|
86
|
+
return _ref2.apply(this, arguments);
|
|
87
|
+
};
|
|
88
|
+
}();
|
|
89
|
+
|
|
90
|
+
// 用户登出
|
|
91
|
+
export var signOutUser = /*#__PURE__*/function () {
|
|
92
|
+
var _ref3 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3() {
|
|
93
|
+
return _regeneratorRuntime().wrap(function _callee3$(_context3) {
|
|
94
|
+
while (1) switch (_context3.prev = _context3.next) {
|
|
95
|
+
case 0:
|
|
96
|
+
_context3.prev = 0;
|
|
97
|
+
return _context3.abrupt("return", signOut(auth));
|
|
98
|
+
case 4:
|
|
99
|
+
_context3.prev = 4;
|
|
100
|
+
_context3.t0 = _context3["catch"](0);
|
|
101
|
+
console.error('Error signing out:', _context3.t0);
|
|
102
|
+
throw _context3.t0;
|
|
103
|
+
case 8:
|
|
104
|
+
case "end":
|
|
105
|
+
return _context3.stop();
|
|
106
|
+
}
|
|
107
|
+
}, _callee3, null, [[0, 4]]);
|
|
108
|
+
}));
|
|
109
|
+
return function signOutUser() {
|
|
110
|
+
return _ref3.apply(this, arguments);
|
|
111
|
+
};
|
|
112
|
+
}();
|
|
113
|
+
|
|
114
|
+
// 读取数据 单次数据
|
|
115
|
+
export var readData = /*#__PURE__*/function () {
|
|
116
|
+
var _ref4 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4(path) {
|
|
117
|
+
var dataSnapshot;
|
|
118
|
+
return _regeneratorRuntime().wrap(function _callee4$(_context4) {
|
|
119
|
+
while (1) switch (_context4.prev = _context4.next) {
|
|
120
|
+
case 0:
|
|
121
|
+
_context4.prev = 0;
|
|
122
|
+
_context4.next = 3;
|
|
123
|
+
return get(ref(database, getPath(path)));
|
|
124
|
+
case 3:
|
|
125
|
+
dataSnapshot = _context4.sent;
|
|
126
|
+
return _context4.abrupt("return", dataSnapshot.val());
|
|
127
|
+
case 7:
|
|
128
|
+
_context4.prev = 7;
|
|
129
|
+
_context4.t0 = _context4["catch"](0);
|
|
130
|
+
console.error('Error reading data:', _context4.t0);
|
|
131
|
+
throw _context4.t0;
|
|
132
|
+
case 11:
|
|
133
|
+
case "end":
|
|
134
|
+
return _context4.stop();
|
|
135
|
+
}
|
|
136
|
+
}, _callee4, null, [[0, 7]]);
|
|
137
|
+
}));
|
|
138
|
+
return function readData(_x5) {
|
|
139
|
+
return _ref4.apply(this, arguments);
|
|
140
|
+
};
|
|
141
|
+
}();
|
|
142
|
+
|
|
143
|
+
// 写入数据
|
|
144
|
+
export var writeData = /*#__PURE__*/function () {
|
|
145
|
+
var _ref5 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee5(path, data) {
|
|
146
|
+
return _regeneratorRuntime().wrap(function _callee5$(_context5) {
|
|
147
|
+
while (1) switch (_context5.prev = _context5.next) {
|
|
148
|
+
case 0:
|
|
149
|
+
_context5.prev = 0;
|
|
150
|
+
return _context5.abrupt("return", set(ref(database, getPath(path)), data));
|
|
151
|
+
case 4:
|
|
152
|
+
_context5.prev = 4;
|
|
153
|
+
_context5.t0 = _context5["catch"](0);
|
|
154
|
+
console.error('Error writing data:', _context5.t0);
|
|
155
|
+
throw _context5.t0;
|
|
156
|
+
case 8:
|
|
157
|
+
case "end":
|
|
158
|
+
return _context5.stop();
|
|
159
|
+
}
|
|
160
|
+
}, _callee5, null, [[0, 4]]);
|
|
161
|
+
}));
|
|
162
|
+
return function writeData(_x6, _x7) {
|
|
163
|
+
return _ref5.apply(this, arguments);
|
|
164
|
+
};
|
|
165
|
+
}();
|
|
166
|
+
|
|
167
|
+
// onValue 方法 实现监听
|
|
168
|
+
export var onDataChange = function onDataChange(path, callback) {
|
|
169
|
+
var databaseRef = ref(database, getPath(path));
|
|
170
|
+
var listener = onValue(databaseRef, callback);
|
|
171
|
+
|
|
172
|
+
// 返回实例,用于移除监听器
|
|
173
|
+
return listener;
|
|
174
|
+
};
|
|
175
|
+
|
|
176
|
+
// 移除监听器
|
|
177
|
+
export var removeDataListener = function removeDataListener(listener) {
|
|
178
|
+
off(listener); // 移除监听器
|
|
179
|
+
};
|
package/es/platform.js
CHANGED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
declare let firebaseConfig: {
|
|
2
|
+
apiKey: string;
|
|
3
|
+
authDomain: string;
|
|
4
|
+
projectId: string;
|
|
5
|
+
storageBucket: string;
|
|
6
|
+
messagingSenderId: string;
|
|
7
|
+
appId: string;
|
|
8
|
+
databaseURL: string;
|
|
9
|
+
};
|
|
10
|
+
declare type InjectedConfigType = {
|
|
11
|
+
apiKey: string;
|
|
12
|
+
authDomain: string;
|
|
13
|
+
projectId: string;
|
|
14
|
+
storageBucket: string;
|
|
15
|
+
messagingSenderId: string;
|
|
16
|
+
appId: string;
|
|
17
|
+
databaseURL: string;
|
|
18
|
+
};
|
|
19
|
+
export declare const injectConfig: (context: InjectedConfigType) => void;
|
|
20
|
+
export default firebaseConfig;
|
|
@@ -0,0 +1,42 @@
|
|
|
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/firebase/config/index.ts
|
|
20
|
+
var config_exports = {};
|
|
21
|
+
__export(config_exports, {
|
|
22
|
+
default: () => config_default,
|
|
23
|
+
injectConfig: () => injectConfig
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(config_exports);
|
|
26
|
+
var firebaseConfig = {
|
|
27
|
+
apiKey: "AIzaSyDuOjRgJtahbsI84cJ0cxiGpTAUU4fcaos",
|
|
28
|
+
authDomain: "wzwtest-65bf6.firebaseapp.com",
|
|
29
|
+
projectId: "wzwtest-65bf6",
|
|
30
|
+
storageBucket: "wzwtest-65bf6.appspot.com",
|
|
31
|
+
messagingSenderId: "798575306619",
|
|
32
|
+
appId: "1:798575306619:web:48bd1102aae4a727a0bfde",
|
|
33
|
+
databaseURL: "https://wzwtest-65bf6-default-rtdb.asia-southeast1.firebasedatabase.app"
|
|
34
|
+
};
|
|
35
|
+
var injectConfig = (context) => {
|
|
36
|
+
firebaseConfig = context;
|
|
37
|
+
};
|
|
38
|
+
var config_default = firebaseConfig;
|
|
39
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
40
|
+
0 && (module.exports = {
|
|
41
|
+
injectConfig
|
|
42
|
+
});
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
declare const firebaseApp: import("firebase/app").FirebaseApp;
|
|
2
|
+
export { firebaseApp };
|
|
3
|
+
export declare const getPath: (path: string) => string;
|
|
4
|
+
export declare const setAuthStateChangeCallback: (callback: (user: any) => void) => void;
|
|
5
|
+
export declare const signUp: (email: string, password: string) => Promise<import("firebase/auth").User>;
|
|
6
|
+
export declare const signInUser: (email: string, password: string) => Promise<import("firebase/auth").User>;
|
|
7
|
+
export declare const signOutUser: () => Promise<void>;
|
|
8
|
+
export declare const readData: (path: string) => Promise<any>;
|
|
9
|
+
export declare const writeData: (path: string, data: any) => Promise<void>;
|
|
10
|
+
export declare const onDataChange: (path: string, callback: (snapshot: any) => void) => import("firebase/database").Unsubscribe;
|
|
11
|
+
export declare const removeDataListener: (listener: any) => void;
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all)
|
|
9
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
+
};
|
|
11
|
+
var __copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
+
for (let key of __getOwnPropNames(from))
|
|
14
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
+
}
|
|
17
|
+
return to;
|
|
18
|
+
};
|
|
19
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
20
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
21
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
22
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
23
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
24
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
25
|
+
mod
|
|
26
|
+
));
|
|
27
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
28
|
+
|
|
29
|
+
// src/firebase/index.ts
|
|
30
|
+
var firebase_exports = {};
|
|
31
|
+
__export(firebase_exports, {
|
|
32
|
+
firebaseApp: () => firebaseApp,
|
|
33
|
+
getPath: () => getPath,
|
|
34
|
+
onDataChange: () => onDataChange,
|
|
35
|
+
readData: () => readData,
|
|
36
|
+
removeDataListener: () => removeDataListener,
|
|
37
|
+
setAuthStateChangeCallback: () => setAuthStateChangeCallback,
|
|
38
|
+
signInUser: () => signInUser,
|
|
39
|
+
signOutUser: () => signOutUser,
|
|
40
|
+
signUp: () => signUp,
|
|
41
|
+
writeData: () => writeData
|
|
42
|
+
});
|
|
43
|
+
module.exports = __toCommonJS(firebase_exports);
|
|
44
|
+
var import_app = require("firebase/app");
|
|
45
|
+
var import_auth = require("firebase/auth");
|
|
46
|
+
var import_database = require("firebase/database");
|
|
47
|
+
var import_config = __toESM(require("./config"));
|
|
48
|
+
var firebaseApp = (0, import_app.initializeApp)(import_config.default);
|
|
49
|
+
var auth = (0, import_auth.getAuth)(firebaseApp);
|
|
50
|
+
var database = (0, import_database.getDatabase)(firebaseApp);
|
|
51
|
+
var getPath = (path) => {
|
|
52
|
+
return path;
|
|
53
|
+
};
|
|
54
|
+
var setAuthStateChangeCallback = (callback) => {
|
|
55
|
+
auth.onAuthStateChanged(callback);
|
|
56
|
+
};
|
|
57
|
+
var signUp = async (email, password) => {
|
|
58
|
+
try {
|
|
59
|
+
const userCredential = await (0, import_auth.createUserWithEmailAndPassword)(
|
|
60
|
+
auth,
|
|
61
|
+
email,
|
|
62
|
+
password
|
|
63
|
+
);
|
|
64
|
+
return userCredential.user;
|
|
65
|
+
} catch (error) {
|
|
66
|
+
console.error("Error signing up:", error);
|
|
67
|
+
throw error;
|
|
68
|
+
}
|
|
69
|
+
};
|
|
70
|
+
var signInUser = async (email, password) => {
|
|
71
|
+
try {
|
|
72
|
+
const userCredential = await (0, import_auth.signInWithEmailAndPassword)(
|
|
73
|
+
auth,
|
|
74
|
+
email,
|
|
75
|
+
password
|
|
76
|
+
);
|
|
77
|
+
return userCredential.user;
|
|
78
|
+
} catch (error) {
|
|
79
|
+
console.error("Error signing in:", error);
|
|
80
|
+
throw error;
|
|
81
|
+
}
|
|
82
|
+
};
|
|
83
|
+
var signOutUser = async () => {
|
|
84
|
+
try {
|
|
85
|
+
return (0, import_auth.signOut)(auth);
|
|
86
|
+
} catch (error) {
|
|
87
|
+
console.error("Error signing out:", error);
|
|
88
|
+
throw error;
|
|
89
|
+
}
|
|
90
|
+
};
|
|
91
|
+
var readData = async (path) => {
|
|
92
|
+
try {
|
|
93
|
+
const dataSnapshot = await (0, import_database.get)((0, import_database.ref)(database, getPath(path)));
|
|
94
|
+
return dataSnapshot.val();
|
|
95
|
+
} catch (error) {
|
|
96
|
+
console.error("Error reading data:", error);
|
|
97
|
+
throw error;
|
|
98
|
+
}
|
|
99
|
+
};
|
|
100
|
+
var writeData = async (path, data) => {
|
|
101
|
+
try {
|
|
102
|
+
return (0, import_database.set)((0, import_database.ref)(database, getPath(path)), data);
|
|
103
|
+
} catch (error) {
|
|
104
|
+
console.error("Error writing data:", error);
|
|
105
|
+
throw error;
|
|
106
|
+
}
|
|
107
|
+
};
|
|
108
|
+
var onDataChange = (path, callback) => {
|
|
109
|
+
const databaseRef = (0, import_database.ref)(database, getPath(path));
|
|
110
|
+
const listener = (0, import_database.onValue)(databaseRef, callback);
|
|
111
|
+
return listener;
|
|
112
|
+
};
|
|
113
|
+
var removeDataListener = (listener) => {
|
|
114
|
+
(0, import_database.off)(listener);
|
|
115
|
+
};
|
|
116
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
117
|
+
0 && (module.exports = {
|
|
118
|
+
firebaseApp,
|
|
119
|
+
getPath,
|
|
120
|
+
onDataChange,
|
|
121
|
+
readData,
|
|
122
|
+
removeDataListener,
|
|
123
|
+
setAuthStateChangeCallback,
|
|
124
|
+
signInUser,
|
|
125
|
+
signOutUser,
|
|
126
|
+
signUp,
|
|
127
|
+
writeData
|
|
128
|
+
});
|
package/lib/platform.js
CHANGED
|
@@ -57,7 +57,7 @@ var isAndroid = () => {
|
|
|
57
57
|
return navigator.userAgent.toLowerCase().indexOf("android") !== -1;
|
|
58
58
|
};
|
|
59
59
|
var isIos = () => {
|
|
60
|
-
return /iphone|ipad|ipod/.test(navigator.userAgent.toLowerCase());
|
|
60
|
+
return /iphone|ipad|ipod|safari/.test(navigator.userAgent.toLowerCase());
|
|
61
61
|
};
|
|
62
62
|
// Annotate the CommonJS export names for ESM import in node:
|
|
63
63
|
0 && (module.exports = {
|
package/package.json
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pisell/utils",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.7",
|
|
4
4
|
"main": "./lib/index.js",
|
|
5
5
|
"module": "./es/index.js",
|
|
6
6
|
"types": "./lib/index.d.ts",
|
|
7
7
|
"typings": "./lib/index.d.ts",
|
|
8
8
|
"devDependencies": {
|
|
9
9
|
"father": "^4.1.0",
|
|
10
|
-
"dayjs": "^1.11.9"
|
|
10
|
+
"dayjs": "^1.11.9",
|
|
11
|
+
"firebase": "^10.5.0"
|
|
11
12
|
},
|
|
12
13
|
"files": [
|
|
13
14
|
"es",
|