pocketbase-react 0.1.28 → 0.1.29
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/dist/pocketbase-react.js +3040 -5687
- package/dist/pocketbase-react.min.js +1 -28
- package/es/context/Pocketbase.d.ts +1 -1
- package/es/context/auth.d.ts +1 -9
- package/es/context/auth.js +5 -5
- package/es/context/client.d.ts +1 -1
- package/es/context/content.d.ts +1 -1
- package/es/context/content.js +5 -3
- package/es/hooks/useAppContent.js +9 -3
- package/es/hooks/useAuth.d.ts +2 -2
- package/es/hooks/useAuth.js +3 -3
- package/es/store/reducers/index.d.ts +5 -2
- package/es/store/store.d.ts +5 -13
- package/es/store/store.js +6 -8
- package/lib/context/Pocketbase.js +5 -6
- package/lib/context/auth.js +9 -10
- package/lib/context/client.js +4 -5
- package/lib/context/content.js +10 -9
- package/lib/hooks/useAppContent.js +9 -3
- package/lib/hooks/useAuth.js +3 -3
- package/lib/store/actions/index.js +1 -2
- package/lib/store/actions/records.js +1 -2
- package/lib/store/actions/subscriptions.js +1 -2
- package/lib/store/reducers/index.js +2 -3
- package/lib/store/reducers/records.js +1 -2
- package/lib/store/reducers/subscriptions.js +1 -2
- package/lib/store/store.js +9 -16
- package/lib/store/types/index.js +9 -18
- package/package.json +27 -23
- package/src/context/auth.tsx +4 -12
- package/src/context/content.tsx +6 -5
- package/src/hooks/useAppContent.ts +3 -3
- package/src/hooks/useAuth.ts +4 -5
- package/src/store/store.tsx +6 -9
- package/CHANGELOG.md +0 -48
package/lib/context/content.js
CHANGED
|
@@ -3,21 +3,20 @@
|
|
|
3
3
|
exports.__esModule = true;
|
|
4
4
|
exports.ContentProvider = exports.ContentContext = void 0;
|
|
5
5
|
var store = _interopRequireWildcard(require("../store/store"));
|
|
6
|
-
var
|
|
6
|
+
var _react = _interopRequireWildcard(require("react"));
|
|
7
|
+
var React = _react;
|
|
7
8
|
var _useClientContext = require("../hooks/useClientContext");
|
|
8
9
|
var _actions = require("../store/actions");
|
|
9
|
-
function
|
|
10
|
-
|
|
11
|
-
const ContentContext = (0, React.createContext)({});
|
|
12
|
-
exports.ContentContext = ContentContext;
|
|
10
|
+
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (const _t in e) "default" !== _t && {}.hasOwnProperty.call(e, _t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, _t)) && (i.get || i.set) ? o(f, _t, i) : f[_t] = e[_t]); return f; })(e, t); }
|
|
11
|
+
const ContentContext = exports.ContentContext = (0, _react.createContext)({});
|
|
13
12
|
const ContentProvider = props => {
|
|
14
13
|
const client = (0, _useClientContext.useClientContext)();
|
|
15
|
-
const dispatch = store.useAppDispatch;
|
|
14
|
+
const dispatch = store.useAppDispatch();
|
|
16
15
|
function tempErrorHandler(error) {
|
|
17
16
|
var _error$originalError;
|
|
18
17
|
// TODO: Handle error
|
|
19
18
|
// IDEA: Create new ErrorContext and Update it with error
|
|
20
|
-
if ((error == null
|
|
19
|
+
if ((error == null || (_error$originalError = error.originalError) == null ? void 0 : _error$originalError.name) !== 'AbortError') {
|
|
21
20
|
console.log('Error in content provider', JSON.stringify(error));
|
|
22
21
|
}
|
|
23
22
|
}
|
|
@@ -53,7 +52,9 @@ const ContentProvider = props => {
|
|
|
53
52
|
}
|
|
54
53
|
},
|
|
55
54
|
fetch: async collectionName => {
|
|
56
|
-
await (client == null ? void 0 : client.collection(collectionName).getFullList(
|
|
55
|
+
await (client == null ? void 0 : client.collection(collectionName).getFullList({
|
|
56
|
+
batch: 200
|
|
57
|
+
}).then(records => {
|
|
57
58
|
dispatch(_actions.recordsAction.setRecords(collectionName, records));
|
|
58
59
|
}).catch(tempErrorHandler));
|
|
59
60
|
},
|
|
@@ -67,7 +68,7 @@ const ContentProvider = props => {
|
|
|
67
68
|
return await (client == null ? void 0 : client.collection(collectionName).delete(recordId).catch(tempErrorHandler));
|
|
68
69
|
}
|
|
69
70
|
};
|
|
70
|
-
(0,
|
|
71
|
+
(0, _react.useEffect)(() => {
|
|
71
72
|
if (props.collections) {
|
|
72
73
|
props.collections.forEach(async collectionName => {
|
|
73
74
|
await actions.fetch(collectionName);
|
|
@@ -6,8 +6,14 @@ var _react = require("react");
|
|
|
6
6
|
var _context = require("../context");
|
|
7
7
|
var _store = require("../store");
|
|
8
8
|
function useAppContent(collectionName, initialFetch = false) {
|
|
9
|
-
const records = (0, _store.useAppSelector)(state =>
|
|
10
|
-
|
|
9
|
+
const records = (0, _store.useAppSelector)(state => {
|
|
10
|
+
var _collectionName, _records;
|
|
11
|
+
return (_collectionName = ((_records = state.records) != null ? _records : {})[collectionName]) != null ? _collectionName : [];
|
|
12
|
+
});
|
|
13
|
+
const subscriptions = (0, _store.useAppSelector)(state => {
|
|
14
|
+
var _subscriptions;
|
|
15
|
+
return (_subscriptions = state.subscriptions) != null ? _subscriptions : [];
|
|
16
|
+
});
|
|
11
17
|
const context = (0, _react.useContext)(_context.ContentContext);
|
|
12
18
|
(0, _react.useEffect)(() => {
|
|
13
19
|
if (initialFetch) {
|
|
@@ -18,7 +24,7 @@ function useAppContent(collectionName, initialFetch = false) {
|
|
|
18
24
|
}, [collectionName, initialFetch]);
|
|
19
25
|
const [isSubscribed, setIsSubscribed] = (0, _react.useState)(false);
|
|
20
26
|
(0, _react.useEffect)(() => {
|
|
21
|
-
setIsSubscribed(subscriptions.includes(collectionName));
|
|
27
|
+
setIsSubscribed((subscriptions != null ? subscriptions : []).includes(collectionName));
|
|
22
28
|
}, [subscriptions]);
|
|
23
29
|
const actions = {
|
|
24
30
|
subscribe: async () => await context.subscribe(collectionName),
|
package/lib/hooks/useAuth.js
CHANGED
|
@@ -11,13 +11,13 @@ function useAuth() {
|
|
|
11
11
|
const [isSignedIn, setIsSignedIn] = (0, _react.useState)(null);
|
|
12
12
|
const [user, setUser] = (0, _react.useState)(null);
|
|
13
13
|
function updateAuth() {
|
|
14
|
-
var _client$authStore$
|
|
14
|
+
var _client$authStore$rec;
|
|
15
15
|
setIsSignedIn((client == null ? void 0 : client.authStore.token) !== '');
|
|
16
|
-
setUser((_client$authStore$
|
|
16
|
+
setUser((_client$authStore$rec = client == null ? void 0 : client.authStore.record) != null ? _client$authStore$rec : null);
|
|
17
17
|
}
|
|
18
18
|
(0, _react.useEffect)(() => {
|
|
19
19
|
updateAuth();
|
|
20
|
-
client == null
|
|
20
|
+
client == null || client.authStore.onChange(() => {
|
|
21
21
|
updateAuth();
|
|
22
22
|
});
|
|
23
23
|
}, []);
|
|
@@ -6,5 +6,4 @@ var recordsAction = _interopRequireWildcard(require("./records"));
|
|
|
6
6
|
exports.recordsAction = recordsAction;
|
|
7
7
|
var subscriptionsAction = _interopRequireWildcard(require("./subscriptions"));
|
|
8
8
|
exports.subscriptionsAction = subscriptionsAction;
|
|
9
|
-
function
|
|
10
|
-
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
9
|
+
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (const _t in e) "default" !== _t && {}.hasOwnProperty.call(e, _t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, _t)) && (i.get || i.set) ? o(f, _t, i) : f[_t] = e[_t]); return f; })(e, t); }
|
|
@@ -3,8 +3,7 @@
|
|
|
3
3
|
exports.__esModule = true;
|
|
4
4
|
exports.updateRecord = exports.setRecords = exports.deleteRecords = exports.deleteRecord = exports.addRecords = exports.addRecord = void 0;
|
|
5
5
|
var ReduxType = _interopRequireWildcard(require("../types"));
|
|
6
|
-
function
|
|
7
|
-
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
6
|
+
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (const _t in e) "default" !== _t && {}.hasOwnProperty.call(e, _t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, _t)) && (i.get || i.set) ? o(f, _t, i) : f[_t] = e[_t]); return f; })(e, t); }
|
|
8
7
|
const setRecords = (key, payload) => ({
|
|
9
8
|
type: ReduxType.SET_RECORDS,
|
|
10
9
|
key,
|
|
@@ -3,8 +3,7 @@
|
|
|
3
3
|
exports.__esModule = true;
|
|
4
4
|
exports.setSubscriptions = exports.deleteSubscription = exports.addSubscription = void 0;
|
|
5
5
|
var ReduxType = _interopRequireWildcard(require("../types"));
|
|
6
|
-
function
|
|
7
|
-
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
6
|
+
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (const _t in e) "default" !== _t && {}.hasOwnProperty.call(e, _t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, _t)) && (i.get || i.set) ? o(f, _t, i) : f[_t] = e[_t]); return f; })(e, t); }
|
|
8
7
|
const setSubscriptions = payload => ({
|
|
9
8
|
type: ReduxType.SET_SUBSCRIPTIONS,
|
|
10
9
|
payload
|
|
@@ -5,8 +5,7 @@ exports.appReducer = void 0;
|
|
|
5
5
|
var _redux = require("redux");
|
|
6
6
|
var _records = require("./records");
|
|
7
7
|
var _subscriptions = require("./subscriptions");
|
|
8
|
-
const appReducer = (0, _redux.combineReducers)({
|
|
8
|
+
const appReducer = exports.appReducer = (0, _redux.combineReducers)({
|
|
9
9
|
records: _records.records,
|
|
10
10
|
subscriptions: _subscriptions.subscriptions
|
|
11
|
-
});
|
|
12
|
-
exports.appReducer = appReducer;
|
|
11
|
+
});
|
|
@@ -5,8 +5,7 @@ exports.__esModule = true;
|
|
|
5
5
|
exports.records = void 0;
|
|
6
6
|
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
|
|
7
7
|
var ReduxType = _interopRequireWildcard(require("../types"));
|
|
8
|
-
function
|
|
9
|
-
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
8
|
+
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (const _t in e) "default" !== _t && {}.hasOwnProperty.call(e, _t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, _t)) && (i.get || i.set) ? o(f, _t, i) : f[_t] = e[_t]); return f; })(e, t); }
|
|
10
9
|
function appendRecord(record, records) {
|
|
11
10
|
return [...records, record];
|
|
12
11
|
}
|
|
@@ -3,8 +3,7 @@
|
|
|
3
3
|
exports.__esModule = true;
|
|
4
4
|
exports.subscriptions = void 0;
|
|
5
5
|
var ReduxType = _interopRequireWildcard(require("../types"));
|
|
6
|
-
function
|
|
7
|
-
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
6
|
+
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (const _t in e) "default" !== _t && {}.hasOwnProperty.call(e, _t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, _t)) && (i.get || i.set) ? o(f, _t, i) : f[_t] = e[_t]); return f; })(e, t); }
|
|
8
7
|
function appendSubscription(subscription, subscriptions) {
|
|
9
8
|
return subscriptions.includes(subscription) ? subscriptions : [...subscriptions, subscription];
|
|
10
9
|
}
|
package/lib/store/store.js
CHANGED
|
@@ -1,13 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
3
|
exports.__esModule = true;
|
|
5
4
|
exports.useAppSelector = exports.useAppDispatch = exports.store = exports.persistor = exports.persistConfig = void 0;
|
|
6
5
|
var _toolkit = require("@reduxjs/toolkit");
|
|
7
6
|
var _reduxPersist = require("redux-persist");
|
|
8
7
|
var _reactRedux = require("react-redux");
|
|
9
8
|
var _reducers = require("./reducers");
|
|
10
|
-
var _reduxThunk =
|
|
9
|
+
var _reduxThunk = require("redux-thunk");
|
|
11
10
|
var _Storage = require("../service/Storage");
|
|
12
11
|
const CustomStorage = {
|
|
13
12
|
getItem: async (key, ..._args) => {
|
|
@@ -20,22 +19,16 @@ const CustomStorage = {
|
|
|
20
19
|
return await _Storage.StorageService.remove(key);
|
|
21
20
|
}
|
|
22
21
|
};
|
|
23
|
-
const persistConfig = {
|
|
22
|
+
const persistConfig = exports.persistConfig = {
|
|
24
23
|
key: 'root',
|
|
25
24
|
storage: CustomStorage
|
|
26
25
|
};
|
|
27
|
-
exports.
|
|
28
|
-
|
|
29
|
-
reducer: (0, _reduxPersist.persistReducer)(persistConfig, _reducers.appReducer)
|
|
26
|
+
const store = exports.store = (0, _toolkit.configureStore)({
|
|
27
|
+
// @ts-ignore - persistReducer typing incompatibility with RTK configureStore
|
|
28
|
+
reducer: (0, _reduxPersist.persistReducer)(persistConfig, _reducers.appReducer),
|
|
29
|
+
middleware: getDefaultMiddleware => getDefaultMiddleware().concat(_reduxThunk.thunk)
|
|
30
30
|
});
|
|
31
|
-
const
|
|
32
|
-
reducer,
|
|
33
|
-
middleware: [_reduxThunk.default]
|
|
34
|
-
});
|
|
35
|
-
exports.store = store;
|
|
36
|
-
const useAppDispatch = store.dispatch;
|
|
31
|
+
const useAppDispatch = () => store.dispatch;
|
|
37
32
|
exports.useAppDispatch = useAppDispatch;
|
|
38
|
-
const useAppSelector = _reactRedux.useSelector;
|
|
39
|
-
exports.
|
|
40
|
-
const persistor = (0, _reduxPersist.persistStore)(store);
|
|
41
|
-
exports.persistor = persistor;
|
|
33
|
+
const useAppSelector = exports.useAppSelector = _reactRedux.useSelector;
|
|
34
|
+
const persistor = exports.persistor = (0, _reduxPersist.persistStore)(store);
|
package/lib/store/types/index.js
CHANGED
|
@@ -2,21 +2,12 @@
|
|
|
2
2
|
|
|
3
3
|
exports.__esModule = true;
|
|
4
4
|
exports.UPDATE_RECORD = exports.SET_SUBSCRIPTIONS = exports.SET_RECORDS = exports.DELETE_SUBSCRIPTION = exports.DELETE_RECORDS = exports.DELETE_RECORD = exports.ADD_SUBSCRIPTION = exports.ADD_RECORDS = exports.ADD_RECORD = void 0;
|
|
5
|
-
const SET_RECORDS = 'SET_RECORDS';
|
|
6
|
-
exports.
|
|
7
|
-
const
|
|
8
|
-
exports.
|
|
9
|
-
const
|
|
10
|
-
exports.
|
|
11
|
-
const
|
|
12
|
-
exports.
|
|
13
|
-
const
|
|
14
|
-
exports.DELETE_RECORD = DELETE_RECORD;
|
|
15
|
-
const DELETE_RECORDS = 'DELETE_RECORDS';
|
|
16
|
-
exports.DELETE_RECORDS = DELETE_RECORDS;
|
|
17
|
-
const SET_SUBSCRIPTIONS = 'SET_SUBSCRIPTIONS';
|
|
18
|
-
exports.SET_SUBSCRIPTIONS = SET_SUBSCRIPTIONS;
|
|
19
|
-
const ADD_SUBSCRIPTION = 'ADD_SUBSCRIPTION';
|
|
20
|
-
exports.ADD_SUBSCRIPTION = ADD_SUBSCRIPTION;
|
|
21
|
-
const DELETE_SUBSCRIPTION = 'DELETE_SUBSCRIPTION';
|
|
22
|
-
exports.DELETE_SUBSCRIPTION = DELETE_SUBSCRIPTION;
|
|
5
|
+
const SET_RECORDS = exports.SET_RECORDS = 'SET_RECORDS';
|
|
6
|
+
const ADD_RECORD = exports.ADD_RECORD = 'ADD_RECORD';
|
|
7
|
+
const ADD_RECORDS = exports.ADD_RECORDS = 'ADD_RECORDS';
|
|
8
|
+
const UPDATE_RECORD = exports.UPDATE_RECORD = 'UPDATE_RECORD';
|
|
9
|
+
const DELETE_RECORD = exports.DELETE_RECORD = 'DELETE_RECORD';
|
|
10
|
+
const DELETE_RECORDS = exports.DELETE_RECORDS = 'DELETE_RECORDS';
|
|
11
|
+
const SET_SUBSCRIPTIONS = exports.SET_SUBSCRIPTIONS = 'SET_SUBSCRIPTIONS';
|
|
12
|
+
const ADD_SUBSCRIPTION = exports.ADD_SUBSCRIPTION = 'ADD_SUBSCRIPTION';
|
|
13
|
+
const DELETE_SUBSCRIPTION = exports.DELETE_SUBSCRIPTION = 'DELETE_SUBSCRIPTION';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pocketbase-react",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.29",
|
|
4
4
|
"description": "Unofficial React SDK (React, React Native, Expo) for interacting with the PocketBase JS SDK",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"pocketbase",
|
|
@@ -45,32 +45,36 @@
|
|
|
45
45
|
"prepublishOnly": "npm run build"
|
|
46
46
|
},
|
|
47
47
|
"peerDependencies": {
|
|
48
|
-
"pocketbase": "0.
|
|
48
|
+
"pocketbase": "0.25.1"
|
|
49
49
|
},
|
|
50
50
|
"devDependencies": {
|
|
51
|
-
"@babel/cli": "^7.
|
|
52
|
-
"@babel/core": "^7.
|
|
53
|
-
"@babel/plugin-proposal-
|
|
54
|
-
"@babel/plugin-
|
|
55
|
-
"@babel/plugin-
|
|
56
|
-
"@babel/
|
|
57
|
-
"@babel/
|
|
58
|
-
"@
|
|
59
|
-
"@
|
|
60
|
-
"@
|
|
61
|
-
"@rollup/plugin-
|
|
62
|
-
"
|
|
63
|
-
"
|
|
64
|
-
"rollup": "^
|
|
65
|
-
"rollup
|
|
66
|
-
"
|
|
51
|
+
"@babel/cli": "^7.28.6",
|
|
52
|
+
"@babel/core": "^7.29.0",
|
|
53
|
+
"@babel/plugin-proposal-class-properties": "^7.18.6",
|
|
54
|
+
"@babel/plugin-proposal-decorators": "^7.29.0",
|
|
55
|
+
"@babel/plugin-proposal-private-methods": "^7.18.6",
|
|
56
|
+
"@babel/plugin-proposal-private-property-in-object": "^7.21.11",
|
|
57
|
+
"@babel/plugin-transform-react-jsx": "^7.28.6",
|
|
58
|
+
"@babel/plugin-transform-runtime": "^7.29.0",
|
|
59
|
+
"@babel/preset-env": "^7.29.0",
|
|
60
|
+
"@babel/preset-typescript": "^7.28.5",
|
|
61
|
+
"@rollup/plugin-babel": "^6.1.0",
|
|
62
|
+
"@rollup/plugin-commonjs": "^29.0.0",
|
|
63
|
+
"@rollup/plugin-node-resolve": "^16.0.3",
|
|
64
|
+
"@rollup/plugin-replace": "^6.0.3",
|
|
65
|
+
"@rollup/plugin-terser": "^0.4.4",
|
|
66
|
+
"@types/react": "^19.0.0",
|
|
67
|
+
"cross-env": "^10.1.0",
|
|
68
|
+
"react": "19.2.4",
|
|
69
|
+
"rollup": "^4.57.1",
|
|
70
|
+
"typescript": "^5.9.3"
|
|
67
71
|
},
|
|
68
72
|
"dependencies": {
|
|
69
|
-
"@react-native-async-storage/async-storage": "^
|
|
70
|
-
"@reduxjs/toolkit": "^
|
|
71
|
-
"pocketbase": "0.8
|
|
72
|
-
"react-redux": "^
|
|
73
|
-
"redux": "^
|
|
73
|
+
"@react-native-async-storage/async-storage": "^2.2.0",
|
|
74
|
+
"@reduxjs/toolkit": "^2.11.2",
|
|
75
|
+
"pocketbase": "0.26.8",
|
|
76
|
+
"react-redux": "^9.2.0",
|
|
77
|
+
"redux": "^5.0.1",
|
|
74
78
|
"redux-persist": "^6.0.0"
|
|
75
79
|
}
|
|
76
80
|
}
|
package/src/context/auth.tsx
CHANGED
|
@@ -1,17 +1,9 @@
|
|
|
1
|
-
import { Collection } from 'pocketbase';
|
|
2
1
|
import * as React from 'react';
|
|
3
2
|
import { createContext } from 'react';
|
|
4
3
|
import { useClientContext } from '../hooks/useClientContext';
|
|
5
4
|
import { StorageService } from '../service/Storage';
|
|
5
|
+
import { AuthProviderInfo } from 'pocketbase';
|
|
6
6
|
|
|
7
|
-
export type AuthProviderInfo = {
|
|
8
|
-
name: string;
|
|
9
|
-
state: string;
|
|
10
|
-
codeVerifier: string;
|
|
11
|
-
codeChallenge: string;
|
|
12
|
-
codeChallengeMethod: string;
|
|
13
|
-
authUrl: string;
|
|
14
|
-
};
|
|
15
7
|
|
|
16
8
|
export type RegisterWithEmailType = (email: string, password: string) => Promise<void>;
|
|
17
9
|
export type SignInWithEmailType = (email: string, password: string) => Promise<void>;
|
|
@@ -65,7 +57,7 @@ export const AuthProvider = (props: AuthProviderProps) => {
|
|
|
65
57
|
const authProvider = authProviders?.find((p) => p.name === provider);
|
|
66
58
|
const redirectURL =
|
|
67
59
|
typeof document !== 'undefined' ? props.webRedirectUrl : props.mobileRedirectUrl;
|
|
68
|
-
const url = authProvider?.
|
|
60
|
+
const url = authProvider?.authURL + redirectURL;
|
|
69
61
|
await StorageService.set('provider', JSON.stringify(authProviders));
|
|
70
62
|
await props.openURL(url);
|
|
71
63
|
},
|
|
@@ -80,7 +72,7 @@ export const AuthProvider = (props: AuthProviderProps) => {
|
|
|
80
72
|
if (authProvider && code) {
|
|
81
73
|
await client
|
|
82
74
|
?.collection('users')
|
|
83
|
-
.
|
|
75
|
+
.authWithOAuth2Code(
|
|
84
76
|
authProvider.name,
|
|
85
77
|
code,
|
|
86
78
|
authProvider.codeVerifier,
|
|
@@ -112,7 +104,7 @@ export const AuthProvider = (props: AuthProviderProps) => {
|
|
|
112
104
|
React.useEffect(() => {
|
|
113
105
|
(async () => {
|
|
114
106
|
const methods = await client?.collection('users').listAuthMethods();
|
|
115
|
-
setAuthProviders(methods?.
|
|
107
|
+
setAuthProviders(methods?.oauth2?.providers ?? []);
|
|
116
108
|
})();
|
|
117
109
|
}, [props.webRedirectUrl, props.mobileRedirectUrl]);
|
|
118
110
|
|
package/src/context/content.tsx
CHANGED
|
@@ -5,6 +5,7 @@ import { useClientContext } from '../hooks/useClientContext';
|
|
|
5
5
|
import { Record } from '../interfaces/Record';
|
|
6
6
|
import { recordsAction } from '../store/actions';
|
|
7
7
|
import { subscriptionsAction } from '../store/actions';
|
|
8
|
+
import { RecordSubscription } from 'pocketbase';
|
|
8
9
|
|
|
9
10
|
type SubscribeType = (collectionName: string) => Promise<void>;
|
|
10
11
|
type UnsubscribeType = (collectionName?: string) => Promise<void>;
|
|
@@ -40,7 +41,7 @@ interface MessageData {
|
|
|
40
41
|
|
|
41
42
|
export const ContentProvider = (props: ContentProviderProps) => {
|
|
42
43
|
const client = useClientContext();
|
|
43
|
-
const dispatch = store.useAppDispatch;
|
|
44
|
+
const dispatch = store.useAppDispatch();
|
|
44
45
|
|
|
45
46
|
function tempErrorHandler(error: any) {
|
|
46
47
|
// TODO: Handle error
|
|
@@ -52,7 +53,7 @@ export const ContentProvider = (props: ContentProviderProps) => {
|
|
|
52
53
|
const actions: ContentActions = {
|
|
53
54
|
subscribe: async (collectionName: string) => {
|
|
54
55
|
await client?.realtime
|
|
55
|
-
.subscribe(collectionName, (event:
|
|
56
|
+
.subscribe(collectionName, (event: RecordSubscription<any>) => {
|
|
56
57
|
switch (event.action) {
|
|
57
58
|
case 'create':
|
|
58
59
|
dispatch(recordsAction.addRecord(collectionName, event.record));
|
|
@@ -92,9 +93,9 @@ export const ContentProvider = (props: ContentProviderProps) => {
|
|
|
92
93
|
fetch: async (collectionName: string) => {
|
|
93
94
|
await client
|
|
94
95
|
?.collection(collectionName)
|
|
95
|
-
.getFullList(200)
|
|
96
|
-
.then((records) => {
|
|
97
|
-
dispatch(recordsAction.setRecords(collectionName, records
|
|
96
|
+
.getFullList({ batch: 200 })
|
|
97
|
+
.then((records: Record[]) => {
|
|
98
|
+
dispatch(recordsAction.setRecords(collectionName, records));
|
|
98
99
|
})
|
|
99
100
|
.catch(tempErrorHandler);
|
|
100
101
|
},
|
|
@@ -23,8 +23,8 @@ export function useAppContent<T extends Record>(
|
|
|
23
23
|
collectionName: string,
|
|
24
24
|
initialFetch: boolean = false
|
|
25
25
|
): { records: T[]; actions: Actions; isSubscribed: boolean } {
|
|
26
|
-
const records = useAppSelector((state) => state.
|
|
27
|
-
const subscriptions = useAppSelector((state) => state.
|
|
26
|
+
const records = useAppSelector((state) => ((state as any).records ?? {})[collectionName] ?? []) as T[];
|
|
27
|
+
const subscriptions = useAppSelector((state) => ((state as any).subscriptions ?? []));
|
|
28
28
|
const context = useContext(ContentContext);
|
|
29
29
|
|
|
30
30
|
useEffect(() => {
|
|
@@ -38,7 +38,7 @@ export function useAppContent<T extends Record>(
|
|
|
38
38
|
const [isSubscribed, setIsSubscribed] = useState(false);
|
|
39
39
|
|
|
40
40
|
useEffect(() => {
|
|
41
|
-
setIsSubscribed(subscriptions.includes(collectionName));
|
|
41
|
+
setIsSubscribed((subscriptions ?? []).includes(collectionName));
|
|
42
42
|
}, [subscriptions]);
|
|
43
43
|
|
|
44
44
|
const actions: Actions = {
|
package/src/hooks/useAuth.ts
CHANGED
|
@@ -1,24 +1,23 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { RecordModel } from 'pocketbase';
|
|
2
2
|
import { useContext, useEffect, useState } from 'react';
|
|
3
3
|
import { AuthActions, AuthContext } from '../context/auth';
|
|
4
|
-
import { StorageService } from '../service/Storage';
|
|
5
4
|
import { useClientContext } from './useClientContext';
|
|
6
5
|
|
|
7
6
|
export interface AuthContextInterface {
|
|
8
7
|
actions: AuthActions;
|
|
9
8
|
isSignedIn: boolean | null;
|
|
10
|
-
user:
|
|
9
|
+
user: RecordModel | null;
|
|
11
10
|
}
|
|
12
11
|
|
|
13
12
|
export function useAuth(): AuthContextInterface {
|
|
14
13
|
const client = useClientContext();
|
|
15
14
|
const actions = useContext(AuthContext);
|
|
16
15
|
const [isSignedIn, setIsSignedIn] = useState<boolean | null>(null);
|
|
17
|
-
const [user, setUser] = useState<
|
|
16
|
+
const [user, setUser] = useState<RecordModel | null>(null);
|
|
18
17
|
|
|
19
18
|
function updateAuth() {
|
|
20
19
|
setIsSignedIn(client?.authStore.token !== '');
|
|
21
|
-
setUser(client?.authStore.
|
|
20
|
+
setUser(client?.authStore.record ?? null);
|
|
22
21
|
}
|
|
23
22
|
|
|
24
23
|
useEffect(() => {
|
package/src/store/store.tsx
CHANGED
|
@@ -2,7 +2,7 @@ import { combineReducers, configureStore } from '@reduxjs/toolkit';
|
|
|
2
2
|
import { persistStore, persistReducer } from 'redux-persist';
|
|
3
3
|
import { TypedUseSelectorHook, useSelector } from 'react-redux';
|
|
4
4
|
import { appReducer } from './reducers';
|
|
5
|
-
import thunk from 'redux-thunk';
|
|
5
|
+
import { thunk } from 'redux-thunk';
|
|
6
6
|
import { RecordAction } from './reducers/records';
|
|
7
7
|
import { StorageService } from '../service/Storage';
|
|
8
8
|
|
|
@@ -29,17 +29,14 @@ export const persistConfig = {
|
|
|
29
29
|
storage: CustomStorage,
|
|
30
30
|
};
|
|
31
31
|
|
|
32
|
-
const reducer = combineReducers({
|
|
33
|
-
reducer: persistReducer(persistConfig, appReducer),
|
|
34
|
-
});
|
|
35
|
-
|
|
36
32
|
const store = configureStore({
|
|
37
|
-
|
|
38
|
-
|
|
33
|
+
// @ts-ignore - persistReducer typing incompatibility with RTK configureStore
|
|
34
|
+
reducer: persistReducer(persistConfig, appReducer),
|
|
35
|
+
middleware: (getDefaultMiddleware) => getDefaultMiddleware().concat(thunk),
|
|
39
36
|
});
|
|
40
37
|
|
|
41
|
-
type AppDispatch = typeof store.dispatch
|
|
42
|
-
const useAppDispatch = store.dispatch;
|
|
38
|
+
type AppDispatch = typeof store.dispatch;
|
|
39
|
+
const useAppDispatch = () => store.dispatch;
|
|
43
40
|
type RootState = ReturnType<typeof store.getState>;
|
|
44
41
|
const useAppSelector: TypedUseSelectorHook<RootState> = useSelector;
|
|
45
42
|
|
package/CHANGELOG.md
DELETED
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
# Changelog
|
|
2
|
-
|
|
3
|
-
All notable changes to this project will be documented in this file.
|
|
4
|
-
|
|
5
|
-
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
|
6
|
-
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
7
|
-
|
|
8
|
-
## [Unreleased]
|
|
9
|
-
|
|
10
|
-
## [0.1.5] - 2022-10-10
|
|
11
|
-
|
|
12
|
-
### Changed
|
|
13
|
-
|
|
14
|
-
- SDK now uses custom @tobicrain/pocketbase javascript framework
|
|
15
|
-
|
|
16
|
-
## [0.1.4] - 2022-10-10
|
|
17
|
-
|
|
18
|
-
### Fixed
|
|
19
|
-
|
|
20
|
-
- SDK now runs on React and React Native
|
|
21
|
-
|
|
22
|
-
## [0.1.3] - 2022-10-06
|
|
23
|
-
|
|
24
|
-
### Changed
|
|
25
|
-
|
|
26
|
-
- Redux now toggles between localStorage / AsyncStorage
|
|
27
|
-
|
|
28
|
-
## [0.1.2] - 2022-10-05
|
|
29
|
-
|
|
30
|
-
### Changed
|
|
31
|
-
|
|
32
|
-
- Adjusted Rollup / Babel Config for use in React
|
|
33
|
-
|
|
34
|
-
## [0.1.1] - 2022-10-04
|
|
35
|
-
|
|
36
|
-
### Changed
|
|
37
|
-
|
|
38
|
-
- initialCollections now also "subscribe" instead of just "fetch" content once
|
|
39
|
-
|
|
40
|
-
## [0.1.0] - 2022-10-03
|
|
41
|
-
|
|
42
|
-
### Added
|
|
43
|
-
|
|
44
|
-
- Initial commit
|
|
45
|
-
|
|
46
|
-
### Changed
|
|
47
|
-
|
|
48
|
-
- Readme Instructions and so on
|