@pisell/utils 1.0.26 → 1.0.28

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.
@@ -1,4 +1,4 @@
1
1
  var webHookApi = {
2
- warning_log: "https://open.feishu.cn/open-apis/bot/v2/hook/6f328eb8-782c-4305-a0b5-d14986a24a0d"
2
+ warning_log: "https://open.feishu.cn/open-apis/bot/v2/hook/887dfff9-2ccc-4513-87ff-a05d8cef953e"
3
3
  };
4
4
  export { webHookApi };
@@ -1,11 +1,11 @@
1
1
  import { FirebaseApp } from 'firebase/app';
2
2
  import { Auth } from 'firebase/auth';
3
- import { Database } from 'firebase/database';
3
+ import { ref, Database, goOnline, goOffline } from 'firebase/database';
4
4
  declare let firebaseApp: FirebaseApp;
5
5
  declare let auth: Auth;
6
6
  declare let database: Database;
7
7
  export declare const initFirebase: (config?: any) => void;
8
- export { database, firebaseApp, auth };
8
+ export { database, firebaseApp, auth, ref, goOnline, goOffline };
9
9
  export declare const getPath: (path: string) => string;
10
10
  export declare const setAuthStateChangeCallback: (callback: (user: any) => void) => void;
11
11
  export declare const signUp: (email: string, password: string) => Promise<import("firebase/auth").User>;
@@ -5,17 +5,19 @@ function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try
5
5
  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); }); }; }
6
6
  import { initializeApp } from 'firebase/app';
7
7
  import { getAuth, createUserWithEmailAndPassword, signInWithEmailAndPassword, signOut } from 'firebase/auth';
8
- import { getDatabase, ref, set, get, off, onValue, onChildChanged } from 'firebase/database';
8
+ import { getDatabase, ref, set, get, off, onValue, onChildChanged, goOnline, goOffline } from 'firebase/database';
9
9
  import { firebaseConfig } from "./config";
10
10
  import { isUndefined } from "../typeUtils";
11
11
  var isClient = typeof window != "undefined" && window.document;
12
12
 
13
13
  // 是否默认初始化firebase erp_admin默认不初始化
14
14
  var isDefaultInit = isUndefined((_window = window) === null || _window === void 0 ? void 0 : _window.__isDefaultInit) ? true : (_window2 = window) === null || _window2 === void 0 ? void 0 : _window2.__isDefaultInit;
15
+ var isInitialized = false;
15
16
  var firebaseApp = {};
16
17
  var auth = {};
17
18
  var database = {};
18
19
  export var initFirebase = function initFirebase(config) {
20
+ isInitialized = true;
19
21
  // 初始化 Firebase
20
22
  firebaseApp = initializeApp(config || firebaseConfig);
21
23
  // 获取 Firebase Auth 实例
@@ -30,7 +32,7 @@ if (isClient && window.__wxjs_environment !== "miniprogram" && isDefaultInit) {
30
32
  }
31
33
 
32
34
  // 导出 Firebase 配置,以便在需要时进行访问
33
- export { database, firebaseApp, auth };
35
+ export { database, firebaseApp, auth, ref, goOnline, goOffline };
34
36
 
35
37
  // 配置化 Firebase 路径
36
38
  export var getPath = function getPath(path) {
@@ -132,21 +134,24 @@ export var readData = /*#__PURE__*/function () {
132
134
  while (1) switch (_context4.prev = _context4.next) {
133
135
  case 0:
134
136
  _context4.prev = 0;
135
- _context4.next = 3;
137
+ if (!isInitialized) {
138
+ initFirebase();
139
+ }
140
+ _context4.next = 4;
136
141
  return get(ref(database, getPath(path)));
137
- case 3:
142
+ case 4:
138
143
  dataSnapshot = _context4.sent;
139
144
  return _context4.abrupt("return", dataSnapshot.val());
140
- case 7:
141
- _context4.prev = 7;
145
+ case 8:
146
+ _context4.prev = 8;
142
147
  _context4.t0 = _context4["catch"](0);
143
148
  console.error("Error reading data:", _context4.t0);
144
149
  throw _context4.t0;
145
- case 11:
150
+ case 12:
146
151
  case "end":
147
152
  return _context4.stop();
148
153
  }
149
- }, _callee4, null, [[0, 7]]);
154
+ }, _callee4, null, [[0, 8]]);
150
155
  }));
151
156
  return function readData(_x5) {
152
157
  return _ref4.apply(this, arguments);
@@ -160,17 +165,20 @@ export var writeData = /*#__PURE__*/function () {
160
165
  while (1) switch (_context5.prev = _context5.next) {
161
166
  case 0:
162
167
  _context5.prev = 0;
168
+ if (!isInitialized) {
169
+ initFirebase();
170
+ }
163
171
  return _context5.abrupt("return", set(ref(database, getPath(path)), data));
164
- case 4:
165
- _context5.prev = 4;
172
+ case 5:
173
+ _context5.prev = 5;
166
174
  _context5.t0 = _context5["catch"](0);
167
175
  console.error("Error writing data:", _context5.t0);
168
176
  throw _context5.t0;
169
- case 8:
177
+ case 9:
170
178
  case "end":
171
179
  return _context5.stop();
172
180
  }
173
- }, _callee5, null, [[0, 4]]);
181
+ }, _callee5, null, [[0, 5]]);
174
182
  }));
175
183
  return function writeData(_x6, _x7) {
176
184
  return _ref5.apply(this, arguments);
@@ -179,6 +187,13 @@ export var writeData = /*#__PURE__*/function () {
179
187
 
180
188
  // onValue 方法 实现监听
181
189
  export var onDataChange = function onDataChange(path, callback) {
190
+ try {
191
+ if (!isInitialized) {
192
+ initFirebase();
193
+ }
194
+ } catch (error) {
195
+ console.error('init error', error);
196
+ }
182
197
  var databaseRef = ref(database, getPath(path));
183
198
  var listener = onValue(databaseRef, callback);
184
199
 
@@ -188,6 +203,13 @@ export var onDataChange = function onDataChange(path, callback) {
188
203
 
189
204
  // onChildChanged 方法 实现监听变化的key
190
205
  export var onDataChanged = function onDataChanged(path, callback) {
206
+ try {
207
+ if (!isInitialized) {
208
+ initFirebase();
209
+ }
210
+ } catch (error) {
211
+ console.error('init error', error);
212
+ }
191
213
  var databaseRef = ref(database, getPath(path));
192
214
  var listener = onChildChanged(databaseRef, callback);
193
215
 
@@ -23,7 +23,7 @@ __export(constants_exports, {
23
23
  });
24
24
  module.exports = __toCommonJS(constants_exports);
25
25
  var webHookApi = {
26
- warning_log: "https://open.feishu.cn/open-apis/bot/v2/hook/6f328eb8-782c-4305-a0b5-d14986a24a0d"
26
+ warning_log: "https://open.feishu.cn/open-apis/bot/v2/hook/887dfff9-2ccc-4513-87ff-a05d8cef953e"
27
27
  };
28
28
  // Annotate the CommonJS export names for ESM import in node:
29
29
  0 && (module.exports = {
@@ -1,11 +1,11 @@
1
1
  import { FirebaseApp } from 'firebase/app';
2
2
  import { Auth } from 'firebase/auth';
3
- import { Database } from 'firebase/database';
3
+ import { ref, Database, goOnline, goOffline } from 'firebase/database';
4
4
  declare let firebaseApp: FirebaseApp;
5
5
  declare let auth: Auth;
6
6
  declare let database: Database;
7
7
  export declare const initFirebase: (config?: any) => void;
8
- export { database, firebaseApp, auth };
8
+ export { database, firebaseApp, auth, ref, goOnline, goOffline };
9
9
  export declare const getPath: (path: string) => string;
10
10
  export declare const setAuthStateChangeCallback: (callback: (user: any) => void) => void;
11
11
  export declare const signUp: (email: string, password: string) => Promise<import("firebase/auth").User>;
@@ -24,10 +24,13 @@ __export(firebase_exports, {
24
24
  default: () => firebase_default,
25
25
  firebaseApp: () => firebaseApp,
26
26
  getPath: () => getPath,
27
+ goOffline: () => import_database.goOffline,
28
+ goOnline: () => import_database.goOnline,
27
29
  initFirebase: () => initFirebase,
28
30
  onDataChange: () => onDataChange,
29
31
  onDataChanged: () => onDataChanged,
30
32
  readData: () => readData,
33
+ ref: () => import_database.ref,
31
34
  removeDataListener: () => removeDataListener,
32
35
  setAuthStateChangeCallback: () => setAuthStateChangeCallback,
33
36
  signInUser: () => signInUser,
@@ -43,10 +46,12 @@ var import_config = require("./config");
43
46
  var import_typeUtils = require("../typeUtils");
44
47
  var isClient = typeof window != "undefined" && window.document;
45
48
  var isDefaultInit = (0, import_typeUtils.isUndefined)(window == null ? void 0 : window.__isDefaultInit) ? true : window == null ? void 0 : window.__isDefaultInit;
49
+ var isInitialized = false;
46
50
  var firebaseApp = {};
47
51
  var auth = {};
48
52
  var database = {};
49
53
  var initFirebase = (config) => {
54
+ isInitialized = true;
50
55
  firebaseApp = (0, import_app.initializeApp)(config || import_config.firebaseConfig);
51
56
  auth = (0, import_auth.getAuth)(firebaseApp);
52
57
  database = (0, import_database.getDatabase)(firebaseApp);
@@ -96,6 +101,9 @@ var signOutUser = async () => {
96
101
  };
97
102
  var readData = async (path) => {
98
103
  try {
104
+ if (!isInitialized) {
105
+ initFirebase();
106
+ }
99
107
  const dataSnapshot = await (0, import_database.get)((0, import_database.ref)(database, getPath(path)));
100
108
  return dataSnapshot.val();
101
109
  } catch (error) {
@@ -105,6 +113,9 @@ var readData = async (path) => {
105
113
  };
106
114
  var writeData = async (path, data) => {
107
115
  try {
116
+ if (!isInitialized) {
117
+ initFirebase();
118
+ }
108
119
  return (0, import_database.set)((0, import_database.ref)(database, getPath(path)), data);
109
120
  } catch (error) {
110
121
  console.error("Error writing data:", error);
@@ -112,11 +123,25 @@ var writeData = async (path, data) => {
112
123
  }
113
124
  };
114
125
  var onDataChange = (path, callback) => {
126
+ try {
127
+ if (!isInitialized) {
128
+ initFirebase();
129
+ }
130
+ } catch (error) {
131
+ console.error("init error", error);
132
+ }
115
133
  const databaseRef = (0, import_database.ref)(database, getPath(path));
116
134
  const listener = (0, import_database.onValue)(databaseRef, callback);
117
135
  return listener;
118
136
  };
119
137
  var onDataChanged = (path, callback) => {
138
+ try {
139
+ if (!isInitialized) {
140
+ initFirebase();
141
+ }
142
+ } catch (error) {
143
+ console.error("init error", error);
144
+ }
120
145
  const databaseRef = (0, import_database.ref)(database, getPath(path));
121
146
  const listener = (0, import_database.onChildChanged)(databaseRef, callback);
122
147
  return listener;
@@ -139,10 +164,13 @@ var firebase_default = {
139
164
  database,
140
165
  firebaseApp,
141
166
  getPath,
167
+ goOffline,
168
+ goOnline,
142
169
  initFirebase,
143
170
  onDataChange,
144
171
  onDataChanged,
145
172
  readData,
173
+ ref,
146
174
  removeDataListener,
147
175
  setAuthStateChangeCallback,
148
176
  signInUser,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pisell/utils",
3
- "version": "1.0.26",
3
+ "version": "1.0.28",
4
4
  "sideEffects": false,
5
5
  "main": "./lib/index.js",
6
6
  "module": "./es/index.js",