react-firebase-ql 2.0.9 → 2.1.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.
@@ -0,0 +1,4 @@
1
+ export { useAuth } from '../client/useAuth';
2
+ export { useCount } from '../client/useCounter';
3
+ export { useFetch } from '../client/useFetch';
4
+ export { useStream } from '../client/useStream';
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.useStream = exports.useFetch = exports.useCount = exports.useAuth = void 0;
4
+ var useAuth_1 = require("../client/useAuth");
5
+ Object.defineProperty(exports, "useAuth", { enumerable: true, get: function () { return useAuth_1.useAuth; } });
6
+ var useCounter_1 = require("../client/useCounter");
7
+ Object.defineProperty(exports, "useCount", { enumerable: true, get: function () { return useCounter_1.useCount; } });
8
+ var useFetch_1 = require("../client/useFetch");
9
+ Object.defineProperty(exports, "useFetch", { enumerable: true, get: function () { return useFetch_1.useFetch; } });
10
+ var useStream_1 = require("../client/useStream");
11
+ Object.defineProperty(exports, "useStream", { enumerable: true, get: function () { return useStream_1.useStream; } });
12
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/client/index.ts"],"names":[],"mappings":";;;AACA,6CAA4C;AAAnC,kGAAA,OAAO,OAAA;AAChB,mDAAgD;AAAvC,sGAAA,QAAQ,OAAA;AACjB,+CAA8C;AAArC,oGAAA,QAAQ,OAAA;AACjB,iDAAgD;AAAvC,sGAAA,SAAS,OAAA"}
@@ -0,0 +1,2 @@
1
+ import { Auth, User } from 'firebase/auth';
2
+ export declare function useAuth(auth: Auth, callback: (user: User | null) => void): void;
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+ 'use client';
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.useAuth = useAuth;
5
+ const react_1 = require("react");
6
+ const auth_1 = require("firebase/auth");
7
+ function useAuth(auth, callback) {
8
+ (0, react_1.useEffect)(() => {
9
+ const unsubscribe = (0, auth_1.onAuthStateChanged)(auth, async (authUser) => {
10
+ callback(authUser);
11
+ });
12
+ return () => unsubscribe();
13
+ }, []);
14
+ }
15
+ //# sourceMappingURL=useAuth.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useAuth.js","sourceRoot":"","sources":["../../src/client/useAuth.ts"],"names":[],"mappings":";AAAA,YAAY,CAAC;;AAKb,0BAQC;AAZD,iCAAkC;AAClC,wCAA+D;AAG/D,SAAgB,OAAO,CAAC,IAAU,EAAE,QAAmC;IACrE,IAAA,iBAAS,EAAC,GAAG,EAAE;QACb,MAAM,WAAW,GAAG,IAAA,yBAAkB,EAAC,IAAI,EAAE,KAAK,EAAE,QAAQ,EAAE,EAAE;YAC/D,QAAQ,CAAC,QAAQ,CAAC,CAAA;QACnB,CAAC,CAAC,CAAC;QAEH,OAAO,GAAG,EAAE,CAAC,WAAW,EAAE,CAAC;IAC7B,CAAC,EAAE,EAAE,CAAC,CAAC;AACT,CAAC"}
@@ -0,0 +1,6 @@
1
+ import { BaseModel, whereClause } from "firebase-client-ql";
2
+ import { Dispatch, SetStateAction } from "react";
3
+ export declare const useCount: <T extends BaseModel>(param: {
4
+ model: T | any;
5
+ where?: whereClause[];
6
+ }) => [number, boolean, Dispatch<SetStateAction<boolean>>];
@@ -0,0 +1,34 @@
1
+ "use strict";
2
+ 'use client';
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.useCount = void 0;
5
+ const firebase_client_ql_1 = require("firebase-client-ql");
6
+ const react_1 = require("react");
7
+ const useCount = (param) => {
8
+ const [data, setData] = (0, react_1.useState)(0);
9
+ const [loading, setLoading] = (0, react_1.useState)(true);
10
+ const fetcher = (0, react_1.useCallback)(async () => {
11
+ if (!param.where)
12
+ return;
13
+ try {
14
+ const model = param.model;
15
+ const found = await model.countData(param.where);
16
+ setData(found);
17
+ }
18
+ catch (error) {
19
+ (0, firebase_client_ql_1.errorLogger)("useCount: ", error);
20
+ }
21
+ finally {
22
+ setLoading(false);
23
+ }
24
+ }, [
25
+ JSON.stringify(param.where),
26
+ loading
27
+ ]);
28
+ (0, react_1.useEffect)(() => {
29
+ fetcher();
30
+ }, [fetcher]);
31
+ return [data, loading, setLoading];
32
+ };
33
+ exports.useCount = useCount;
34
+ //# sourceMappingURL=useCounter.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useCounter.js","sourceRoot":"","sources":["../../src/client/useCounter.ts"],"names":[],"mappings":";AAAA,YAAY,CAAA;;;AAEZ,2DAAyE;AACzE,iCAAkF;AAI3E,MAAM,QAAQ,GAAG,CAAuB,KAG9C,EAAwD,EAAE;IAEvD,MAAM,CAAC,IAAI,EAAE,OAAO,CAAC,GAAG,IAAA,gBAAQ,EAAS,CAAC,CAAC,CAAC;IAC5C,MAAM,CAAC,OAAO,EAAE,UAAU,CAAC,GAAG,IAAA,gBAAQ,EAAC,IAAI,CAAC,CAAC;IAE7C,MAAM,OAAO,GAAG,IAAA,mBAAW,EAAC,KAAK,IAAI,EAAE;QACnC,IAAK,CAAC,KAAK,CAAC,KAAK;YAAE,OAAO;QAE1B,IAAI,CAAC;YACD,MAAM,KAAK,GAAG,KAAK,CAAC,KAAK,CAAC;YAC1B,MAAM,KAAK,GAAG,MAAM,KAAK,CAAC,SAAS,CAAC,KAAK,CAAC,KAAK,CAAC,CAAA;YAChD,OAAO,CAAC,KAAK,CAAC,CAAC;QACnB,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACb,IAAA,gCAAW,EAAC,YAAY,EAAE,KAAK,CAAC,CAAC;QACrC,CAAC;gBAAS,CAAC;YACP,UAAU,CAAC,KAAK,CAAC,CAAC;QACtB,CAAC;IACL,CAAC,EAAE;QACC,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,KAAK,CAAC;QAC3B,OAAO;KACV,CAAC,CAAC;IAEH,IAAA,iBAAS,EAAC,GAAG,EAAE;QACX,OAAO,EAAE,CAAC;IACd,CAAC,EAAE,CAAC,OAAO,CAAC,CAAC,CAAC;IAEd,OAAO,CAAC,IAAI,EAAE,OAAO,EAAE,UAAU,CAAC,CAAC;AACvC,CAAC,CAAA;AA9BY,QAAA,QAAQ,YA8BpB"}
@@ -0,0 +1,15 @@
1
+ import { BaseModel, whereClause } from "firebase-client-ql";
2
+ import { Dispatch, SetStateAction } from "react";
3
+ export declare const useFetch: <T extends BaseModel>(param: {
4
+ model: T | any;
5
+ where?: whereClause[];
6
+ reference?: string;
7
+ filter?: {
8
+ orderBy?: {
9
+ parameter: string;
10
+ direction?: "asc" | "desc";
11
+ };
12
+ offset?: string;
13
+ limit?: number;
14
+ };
15
+ }) => [typeof param.model.data, boolean, Dispatch<SetStateAction<boolean>>];
@@ -0,0 +1,49 @@
1
+ "use strict";
2
+ 'use client';
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.useFetch = void 0;
5
+ const firebase_client_ql_1 = require("firebase-client-ql");
6
+ const react_1 = require("react");
7
+ const useFetch = (param) => {
8
+ const [data, setData] = (0, react_1.useState)();
9
+ const [loading, setLoading] = (0, react_1.useState)(true);
10
+ const fetcher = (0, react_1.useCallback)(async () => {
11
+ var _a, _b, _c, _d;
12
+ if (!param.reference && !param.where)
13
+ return;
14
+ try {
15
+ const model = param.model;
16
+ if (param.reference) {
17
+ const found = await model.find(param.reference);
18
+ if (found)
19
+ setData(model.data);
20
+ }
21
+ else if (param.where) {
22
+ const found = await model.findWhere({
23
+ wh: param.where,
24
+ lim: (_b = (_a = param.filter) === null || _a === void 0 ? void 0 : _a.limit) !== null && _b !== void 0 ? _b : 100,
25
+ order: (_c = param.filter) === null || _c === void 0 ? void 0 : _c.orderBy,
26
+ offset: (_d = param.filter) === null || _d === void 0 ? void 0 : _d.offset
27
+ });
28
+ setData(found);
29
+ }
30
+ }
31
+ catch (error) {
32
+ (0, firebase_client_ql_1.errorLogger)("useFetch: ", error);
33
+ }
34
+ finally {
35
+ setLoading(false);
36
+ }
37
+ }, [
38
+ param.reference,
39
+ JSON.stringify(param.where),
40
+ JSON.stringify(param.filter),
41
+ loading
42
+ ]);
43
+ (0, react_1.useEffect)(() => {
44
+ fetcher();
45
+ }, [fetcher]);
46
+ return [data, loading, setLoading];
47
+ };
48
+ exports.useFetch = useFetch;
49
+ //# sourceMappingURL=useFetch.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useFetch.js","sourceRoot":"","sources":["../../src/client/useFetch.ts"],"names":[],"mappings":";AAAA,YAAY,CAAA;;;AAEZ,2DAAwE;AACxE,iCAAkF;AAI3E,MAAM,QAAQ,GAAG,CAAuB,KAS9C,EAAyE,EAAE;IAExE,MAAM,CAAC,IAAI,EAAE,OAAO,CAAC,GAAG,IAAA,gBAAQ,GAAW,CAAC;IAC5C,MAAM,CAAC,OAAO,EAAE,UAAU,CAAC,GAAG,IAAA,gBAAQ,EAAC,IAAI,CAAC,CAAC;IAE7C,MAAM,OAAO,GAAG,IAAA,mBAAW,EAAC,KAAK,IAAI,EAAE;;QACnC,IAAI,CAAC,KAAK,CAAC,SAAS,IAAI,CAAC,KAAK,CAAC,KAAK;YAAE,OAAO;QAE7C,IAAI,CAAC;YACD,MAAM,KAAK,GAAG,KAAK,CAAC,KAAK,CAAC;YAE1B,IAAI,KAAK,CAAC,SAAS,EAAE,CAAC;gBAClB,MAAM,KAAK,GAAG,MAAM,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC;gBAChD,IAAI,KAAK;oBAAE,OAAO,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;YACnC,CAAC;iBAAM,IAAI,KAAK,CAAC,KAAK,EAAE,CAAC;gBACrB,MAAM,KAAK,GAAG,MAAM,KAAK,CAAC,SAAS,CAAC;oBAChC,EAAE,EAAE,KAAK,CAAC,KAAK;oBACf,GAAG,EAAE,MAAA,MAAA,KAAK,CAAC,MAAM,0CAAE,KAAK,mCAAI,GAAG;oBAC/B,KAAK,EAAE,MAAA,KAAK,CAAC,MAAM,0CAAE,OAAO;oBAC5B,MAAM,EAAE,MAAA,KAAK,CAAC,MAAM,0CAAE,MAAM;iBAC/B,CAAC,CAAC;gBACH,OAAO,CAAC,KAAK,CAAC,CAAC;YACnB,CAAC;QACL,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACb,IAAA,gCAAW,EAAC,YAAY,EAAE,KAAK,CAAC,CAAC;QACrC,CAAC;gBAAS,CAAC;YACP,UAAU,CAAC,KAAK,CAAC,CAAC;QACtB,CAAC;IACL,CAAC,EAAE;QACC,KAAK,CAAC,SAAS;QACf,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,KAAK,CAAC;QAC3B,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,MAAM,CAAC;QAC5B,OAAO;KACV,CAAC,CAAC;IAEH,IAAA,iBAAS,EAAC,GAAG,EAAE;QACX,OAAO,EAAE,CAAC;IACd,CAAC,EAAE,CAAC,OAAO,CAAC,CAAC,CAAC;IAEd,OAAO,CAAC,IAAI,EAAE,OAAO,EAAE,UAAU,CAAC,CAAC;AACvC,CAAC,CAAA;AAjDY,QAAA,QAAQ,YAiDpB"}
@@ -0,0 +1,13 @@
1
+ import { BaseModel, whereClause } from 'firebase-client-ql';
2
+ export declare const useStream: <T extends BaseModel>(param: {
3
+ model: T | any;
4
+ where?: whereClause[];
5
+ reference?: string;
6
+ filter?: {
7
+ orderBy?: {
8
+ parameter: string;
9
+ direction?: "asc" | "desc";
10
+ };
11
+ offset?: string;
12
+ };
13
+ }, callback: (data: any) => void) => void;
@@ -0,0 +1,41 @@
1
+ "use strict";
2
+ 'use client';
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.useStream = void 0;
5
+ const firebase_client_ql_1 = require("firebase-client-ql");
6
+ const react_1 = require("react");
7
+ const useStream = (param, callback) => {
8
+ (0, react_1.useEffect)(() => {
9
+ let unsubscribe;
10
+ try {
11
+ const { model, reference, where, filter } = param;
12
+ if (reference) {
13
+ unsubscribe = model.stream((data) => {
14
+ if (data)
15
+ callback(data);
16
+ }, reference);
17
+ }
18
+ else if (where) {
19
+ const allInvalid = where.every((item) => item.value === undefined);
20
+ if (allInvalid) {
21
+ callback([]);
22
+ return;
23
+ }
24
+ unsubscribe = model.streamWhere(where, (data) => {
25
+ if (data)
26
+ callback(data);
27
+ }, 100, filter === null || filter === void 0 ? void 0 : filter.orderBy, filter === null || filter === void 0 ? void 0 : filter.offset);
28
+ }
29
+ }
30
+ catch (error) {
31
+ (0, firebase_client_ql_1.errorLogger)('useStream error:', error);
32
+ }
33
+ return () => {
34
+ if (typeof unsubscribe === 'function') {
35
+ unsubscribe();
36
+ }
37
+ };
38
+ }, [JSON.stringify(param.where), JSON.stringify(param.filter), param.reference]);
39
+ };
40
+ exports.useStream = useStream;
41
+ //# sourceMappingURL=useStream.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useStream.js","sourceRoot":"","sources":["../../src/client/useStream.ts"],"names":[],"mappings":";AAAA,YAAY,CAAC;;;AAEb,2DAAyE;AACzE,iCAAkC;AAG3B,MAAM,SAAS,GAAG,CACvB,KAQC,EACD,QAA6B,EACvB,EAAE;IACR,IAAA,iBAAS,EAAC,GAAG,EAAE;QACb,IAAI,WAAqC,CAAC;QAE1C,IAAI,CAAC;YACH,MAAM,EAAC,KAAK,EAAE,SAAS,EAAE,KAAK,EAAE,MAAM,EAAE,GAAG,KAAK,CAAC;YAEjD,IAAI,SAAS,EAAE,CAAC;gBACd,WAAW,GAAG,KAAK,CAAC,MAAM,CAAC,CAAC,IAAS,EAAE,EAAE;oBACvC,IAAI,IAAI;wBAAE,QAAQ,CAAC,IAAI,CAAC,CAAC;gBAC3B,CAAC,EAAE,SAAS,CAAC,CAAC;YAChB,CAAC;iBAAM,IAAI,KAAK,EAAE,CAAC;gBACjB,MAAM,UAAU,GAAG,KAAK,CAAC,KAAK,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,KAAK,KAAK,SAAS,CAAC,CAAC;gBACnE,IAAI,UAAU,EAAE,CAAC;oBACf,QAAQ,CAAC,EAAE,CAAC,CAAC;oBACb,OAAO;gBACT,CAAC;gBAED,WAAW,GAAG,KAAK,CAAC,WAAW,CAC7B,KAAK,EACL,CAAC,IAAS,EAAE,EAAE;oBACZ,IAAI,IAAI;wBAAE,QAAQ,CAAC,IAAI,CAAC,CAAC;gBAC3B,CAAC,EACD,GAAG,EACH,MAAM,aAAN,MAAM,uBAAN,MAAM,CAAE,OAAO,EACf,MAAM,aAAN,MAAM,uBAAN,MAAM,CAAE,MAAM,CACf,CAAC;YACJ,CAAC;QACH,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,IAAA,gCAAW,EAAC,kBAAkB,EAAE,KAAK,CAAC,CAAC;QACzC,CAAC;QAGD,OAAO,GAAG,EAAE;YACV,IAAI,OAAO,WAAW,KAAK,UAAU,EAAE,CAAC;gBACtC,WAAW,EAAE,CAAC;YAChB,CAAC;QACH,CAAC,CAAC;IACJ,CAAC,EAAE,CAAC,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,KAAK,CAAC,EAAE,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,MAAM,CAAC,EAAE,KAAK,CAAC,SAAS,CAAC,CAAC,CAAC;AACnF,CAAC,CAAC;AAlDW,QAAA,SAAS,aAkDpB"}
package/dist/index.d.ts CHANGED
@@ -1,39 +1 @@
1
- import { Auth, User } from 'firebase/auth';
2
- import { BaseModel, whereClause } from 'firebase-client-ql';
3
- import { Dispatch, SetStateAction } from 'react';
4
-
5
- declare function useAuth(auth: Auth, callback: (user: User | null) => void): void;
6
-
7
- declare const useCount: <T extends BaseModel>(param: {
8
- model: T | any;
9
- where?: whereClause[];
10
- }) => [number, boolean, Dispatch<SetStateAction<boolean>>];
11
-
12
- declare const useFetch: <T extends BaseModel>(param: {
13
- model: T | any;
14
- where?: whereClause[];
15
- reference?: string;
16
- filter?: {
17
- orderBy?: {
18
- parameter: string;
19
- direction?: "asc" | "desc";
20
- };
21
- offset?: string;
22
- limit?: number;
23
- };
24
- }) => [typeof param.model.data, boolean, Dispatch<SetStateAction<boolean>>];
25
-
26
- declare const useStream: <T extends BaseModel>(param: {
27
- model: T | any;
28
- where?: whereClause[];
29
- reference?: string;
30
- filter?: {
31
- orderBy?: {
32
- parameter: string;
33
- direction?: "asc" | "desc";
34
- };
35
- offset?: string;
36
- };
37
- }, callback: (data: any) => void) => void;
38
-
39
- export { useAuth, useCount, useFetch, useStream };
1
+ export * from './client';