pocketbase-react 0.1.27 → 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 +3050 -5403
- package/dist/pocketbase-react.min.js +1 -28
- package/es/context/Pocketbase.d.ts +3 -3
- package/es/context/Pocketbase.js +1 -1
- package/es/context/auth.d.ts +12 -20
- package/es/context/auth.js +13 -13
- package/es/context/client.d.ts +3 -3
- package/es/context/content.d.ts +8 -8
- package/es/context/content.js +8 -6
- package/es/hooks/useAppContent.d.ts +6 -6
- package/es/hooks/useAppContent.js +9 -3
- package/es/hooks/useAuth.d.ts +2 -2
- package/es/hooks/useAuth.js +3 -3
- package/es/hooks/useClientContext.d.ts +1 -1
- package/es/store/reducers/index.d.ts +6 -3
- package/es/store/reducers/records.d.ts +1 -1
- package/es/store/reducers/subscriptions.d.ts +1 -1
- package/es/store/store.d.ts +6 -14
- package/es/store/store.js +6 -8
- package/es/store/types/index.d.ts +2 -2
- package/lib/context/Pocketbase.js +6 -7
- package/lib/context/auth.js +17 -18
- package/lib/context/client.js +4 -5
- package/lib/context/content.js +13 -12
- 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/Pocketbase.tsx +1 -1
- package/src/context/auth.tsx +19 -24
- package/src/context/client.tsx +1 -1
- package/src/context/content.tsx +20 -9
- 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/es/store/store.d.ts
CHANGED
|
@@ -1,6 +1,3 @@
|
|
|
1
|
-
/// <reference types="redux-persist/types/persistReducer" />
|
|
2
|
-
/// <reference types="redux-persist/types/types" />
|
|
3
|
-
/// <reference types="redux-persist" />
|
|
4
1
|
import { TypedUseSelectorHook } from 'react-redux';
|
|
5
2
|
import { RecordAction } from './reducers/records';
|
|
6
3
|
interface Storage {
|
|
@@ -12,17 +9,12 @@ export declare const persistConfig: {
|
|
|
12
9
|
key: string;
|
|
13
10
|
storage: Storage;
|
|
14
11
|
};
|
|
15
|
-
declare const store: import("@reduxjs/toolkit").EnhancedStore<import("redux").
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
withExtraArgument<ExtraThunkArg, State = any, BasicAction extends import("redux").Action<any> = import("redux").AnyAction>(extraArgument: ExtraThunkArg): import("redux-thunk").ThunkMiddleware<State, BasicAction, ExtraThunkArg>;
|
|
22
|
-
})[]>;
|
|
23
|
-
declare type AppDispatch = typeof store.dispatch<RecordAction>;
|
|
24
|
-
declare const useAppDispatch: import("redux").Dispatch<RecordAction | import("./reducers/subscriptions").SubscriptionAction>;
|
|
25
|
-
declare type RootState = ReturnType<typeof store.getState>;
|
|
12
|
+
declare const store: import("@reduxjs/toolkit").EnhancedStore<any, RecordAction | import("./reducers/subscriptions").SubscriptionAction, import("@reduxjs/toolkit").Tuple<[import("redux").StoreEnhancer<{
|
|
13
|
+
dispatch: import("redux-thunk").ThunkDispatch<any, undefined, import("redux").UnknownAction> & import("redux-thunk").ThunkDispatch<any, undefined, import("redux").AnyAction>;
|
|
14
|
+
}>, import("redux").StoreEnhancer]>>;
|
|
15
|
+
type AppDispatch = typeof store.dispatch;
|
|
16
|
+
declare const useAppDispatch: () => import("redux-thunk").ThunkDispatch<any, undefined, import("redux").UnknownAction> & import("redux-thunk").ThunkDispatch<any, undefined, import("redux").AnyAction> & import("redux").Dispatch<RecordAction | import("./reducers/subscriptions").SubscriptionAction>;
|
|
17
|
+
type RootState = ReturnType<typeof store.getState>;
|
|
26
18
|
declare const useAppSelector: TypedUseSelectorHook<RootState>;
|
|
27
19
|
declare const persistor: import("redux-persist").Persistor;
|
|
28
20
|
export { AppDispatch, RootState, useAppDispatch, useAppSelector, store, persistor };
|
package/es/store/store.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { configureStore } from '@reduxjs/toolkit';
|
|
2
2
|
import { persistStore, persistReducer } from 'redux-persist';
|
|
3
3
|
import { 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 { StorageService } from '../service/Storage';
|
|
7
7
|
const CustomStorage = {
|
|
8
8
|
getItem: async (key, ..._args) => {
|
|
@@ -19,14 +19,12 @@ export const persistConfig = {
|
|
|
19
19
|
key: 'root',
|
|
20
20
|
storage: CustomStorage
|
|
21
21
|
};
|
|
22
|
-
const reducer = combineReducers({
|
|
23
|
-
reducer: persistReducer(persistConfig, appReducer)
|
|
24
|
-
});
|
|
25
22
|
const store = configureStore({
|
|
26
|
-
|
|
27
|
-
|
|
23
|
+
// @ts-ignore - persistReducer typing incompatibility with RTK configureStore
|
|
24
|
+
reducer: persistReducer(persistConfig, appReducer),
|
|
25
|
+
middleware: getDefaultMiddleware => getDefaultMiddleware().concat(thunk)
|
|
28
26
|
});
|
|
29
|
-
const useAppDispatch = store.dispatch;
|
|
27
|
+
const useAppDispatch = () => store.dispatch;
|
|
30
28
|
const useAppSelector = useSelector;
|
|
31
29
|
const persistor = persistStore(store);
|
|
32
30
|
export { useAppDispatch, useAppSelector, store, persistor };
|
|
@@ -4,8 +4,8 @@ export declare const ADD_RECORDS = "ADD_RECORDS";
|
|
|
4
4
|
export declare const UPDATE_RECORD = "UPDATE_RECORD";
|
|
5
5
|
export declare const DELETE_RECORD = "DELETE_RECORD";
|
|
6
6
|
export declare const DELETE_RECORDS = "DELETE_RECORDS";
|
|
7
|
-
export
|
|
7
|
+
export type RecordTypes = typeof SET_RECORDS | typeof ADD_RECORD | typeof ADD_RECORDS | typeof UPDATE_RECORD | typeof DELETE_RECORD | typeof DELETE_RECORDS;
|
|
8
8
|
export declare const SET_SUBSCRIPTIONS = "SET_SUBSCRIPTIONS";
|
|
9
9
|
export declare const ADD_SUBSCRIPTION = "ADD_SUBSCRIPTION";
|
|
10
10
|
export declare const DELETE_SUBSCRIPTION = "DELETE_SUBSCRIPTION";
|
|
11
|
-
export
|
|
11
|
+
export type SubscriptionsTypes = typeof SET_SUBSCRIPTIONS | typeof ADD_SUBSCRIPTION | typeof DELETE_SUBSCRIPTION;
|
|
@@ -3,8 +3,9 @@
|
|
|
3
3
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
4
|
exports.__esModule = true;
|
|
5
5
|
exports.PocketbaseContext = exports.Pocketbase = void 0;
|
|
6
|
-
var
|
|
7
|
-
var
|
|
6
|
+
var _react = _interopRequireWildcard(require("react"));
|
|
7
|
+
var React = _react;
|
|
8
|
+
var _pocketbase = _interopRequireDefault(require("pocketbase"));
|
|
8
9
|
var _reactRedux = require("react-redux");
|
|
9
10
|
var _react2 = require("redux-persist/integration/react");
|
|
10
11
|
var _store = require("../store/store");
|
|
@@ -12,14 +13,12 @@ var _client = require("./client");
|
|
|
12
13
|
var _content = require("./content");
|
|
13
14
|
var _auth = require("./auth");
|
|
14
15
|
var _Storage = require("../service/Storage");
|
|
15
|
-
function
|
|
16
|
-
|
|
17
|
-
const PocketbaseContext = (0, React.createContext)(null);
|
|
18
|
-
exports.PocketbaseContext = PocketbaseContext;
|
|
16
|
+
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); }
|
|
17
|
+
const PocketbaseContext = exports.PocketbaseContext = (0, _react.createContext)(null);
|
|
19
18
|
const Pocketbase = props => {
|
|
20
19
|
const [client, setClient] = React.useState(null);
|
|
21
20
|
const [initialCollections, setInitialCollections] = React.useState();
|
|
22
|
-
(0,
|
|
21
|
+
(0, _react.useEffect)(() => {
|
|
23
22
|
const client = new _pocketbase.default(props.serverURL);
|
|
24
23
|
client.authStore.onChange(async () => {
|
|
25
24
|
await _Storage.StorageService.set(_Storage.StorageService.Constants.COOKIE, client.authStore.exportToCookie());
|
package/lib/context/auth.js
CHANGED
|
@@ -2,31 +2,30 @@
|
|
|
2
2
|
|
|
3
3
|
exports.__esModule = true;
|
|
4
4
|
exports.AuthProvider = exports.AuthContext = void 0;
|
|
5
|
-
var
|
|
5
|
+
var _react = _interopRequireWildcard(require("react"));
|
|
6
|
+
var React = _react;
|
|
6
7
|
var _useClientContext = require("../hooks/useClientContext");
|
|
7
8
|
var _Storage = require("../service/Storage");
|
|
8
|
-
function
|
|
9
|
-
|
|
10
|
-
const AuthContext = (0, React.createContext)({});
|
|
11
|
-
exports.AuthContext = AuthContext;
|
|
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); }
|
|
10
|
+
const AuthContext = exports.AuthContext = (0, _react.createContext)({});
|
|
12
11
|
const AuthProvider = props => {
|
|
13
12
|
const client = (0, _useClientContext.useClientContext)();
|
|
14
13
|
const [authProviders, setAuthProviders] = React.useState();
|
|
15
14
|
const actions = {
|
|
16
15
|
registerWithEmail: async (email, password) => {
|
|
17
|
-
await (client == null ? void 0 : client.users.create({
|
|
16
|
+
await (client == null ? void 0 : client.collection('users').create({
|
|
18
17
|
email: email,
|
|
19
18
|
password: password,
|
|
20
19
|
passwordConfirm: password
|
|
21
20
|
}));
|
|
22
21
|
},
|
|
23
22
|
signInWithEmail: async (email, password) => {
|
|
24
|
-
await (client == null ? void 0 : client.users.
|
|
23
|
+
await (client == null ? void 0 : client.collection('users').authWithPassword(email, password));
|
|
25
24
|
},
|
|
26
25
|
signInWithProvider: async provider => {
|
|
27
26
|
const authProvider = authProviders == null ? void 0 : authProviders.find(p => p.name === provider);
|
|
28
27
|
const redirectURL = typeof document !== 'undefined' ? props.webRedirectUrl : props.mobileRedirectUrl;
|
|
29
|
-
const url = (authProvider == null ? void 0 : authProvider.
|
|
28
|
+
const url = (authProvider == null ? void 0 : authProvider.authURL) + redirectURL;
|
|
30
29
|
await _Storage.StorageService.set('provider', JSON.stringify(authProviders));
|
|
31
30
|
await props.openURL(url);
|
|
32
31
|
},
|
|
@@ -39,33 +38,33 @@ const AuthProvider = props => {
|
|
|
39
38
|
const providers = JSON.parse(providersString);
|
|
40
39
|
const authProvider = providers == null ? void 0 : providers.find(p => p.state === state);
|
|
41
40
|
if (authProvider && code) {
|
|
42
|
-
await (client == null ? void 0 : client.users.
|
|
41
|
+
await (client == null ? void 0 : client.collection('users').authWithOAuth2Code(authProvider.name, code, authProvider.codeVerifier, typeof document !== 'undefined' ? props.webRedirectUrl : props.mobileRedirectUrl));
|
|
43
42
|
}
|
|
44
43
|
}
|
|
45
44
|
},
|
|
46
45
|
signOut: () => {
|
|
47
|
-
client == null
|
|
46
|
+
client == null || client.authStore.clear();
|
|
48
47
|
},
|
|
49
48
|
sendPasswordResetEmail: async email => {
|
|
50
|
-
await (client == null ? void 0 : client.users.requestPasswordReset(email));
|
|
49
|
+
await (client == null ? void 0 : client.collection('users').requestPasswordReset(email));
|
|
51
50
|
},
|
|
52
51
|
sendEmailVerification: async email => {
|
|
53
|
-
await (client == null ? void 0 : client.users.requestVerification(email));
|
|
52
|
+
await (client == null ? void 0 : client.collection('users').requestVerification(email));
|
|
54
53
|
},
|
|
55
54
|
updateProfile: async (id, record) => {
|
|
56
|
-
await (client == null ? void 0 : client.
|
|
55
|
+
await (client == null ? void 0 : client.collection('profiles').update(id, record));
|
|
57
56
|
},
|
|
58
57
|
updateEmail: async email => {
|
|
59
|
-
await (client == null ? void 0 : client.users.requestEmailChange(email));
|
|
58
|
+
await (client == null ? void 0 : client.collection('users').requestEmailChange(email));
|
|
60
59
|
},
|
|
61
60
|
deleteUser: async id => {
|
|
62
|
-
await (client == null ? void 0 : client.users.delete(id));
|
|
61
|
+
await (client == null ? void 0 : client.collection('users').delete(id));
|
|
63
62
|
}
|
|
64
63
|
};
|
|
65
64
|
React.useEffect(() => {
|
|
66
|
-
(async () => {
|
|
67
|
-
const methods = await (client == null ? void 0 : client.users.listAuthMethods());
|
|
68
|
-
setAuthProviders(methods == null ? void 0 :
|
|
65
|
+
(async (_methods$oauth2$provi, _methods$oauth) => {
|
|
66
|
+
const methods = await (client == null ? void 0 : client.collection('users').listAuthMethods());
|
|
67
|
+
setAuthProviders((_methods$oauth2$provi = methods == null || (_methods$oauth = methods.oauth2) == null ? void 0 : _methods$oauth.providers) != null ? _methods$oauth2$provi : []);
|
|
69
68
|
})();
|
|
70
69
|
}, [props.webRedirectUrl, props.mobileRedirectUrl]);
|
|
71
70
|
return /*#__PURE__*/React.createElement(AuthContext.Provider, {
|
package/lib/context/client.js
CHANGED
|
@@ -2,11 +2,10 @@
|
|
|
2
2
|
|
|
3
3
|
exports.__esModule = true;
|
|
4
4
|
exports.ClientProvider = exports.ClientContext = void 0;
|
|
5
|
-
var
|
|
6
|
-
|
|
7
|
-
function _interopRequireWildcard(
|
|
8
|
-
const ClientContext = (0,
|
|
9
|
-
exports.ClientContext = ClientContext;
|
|
5
|
+
var _react = _interopRequireWildcard(require("react"));
|
|
6
|
+
var React = _react;
|
|
7
|
+
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
|
+
const ClientContext = exports.ClientContext = (0, _react.createContext)(null);
|
|
10
9
|
const ClientProvider = props => {
|
|
11
10
|
return /*#__PURE__*/React.createElement(ClientContext.Provider, {
|
|
12
11
|
value: props.client
|
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,21 +52,23 @@ const ContentProvider = props => {
|
|
|
53
52
|
}
|
|
54
53
|
},
|
|
55
54
|
fetch: async collectionName => {
|
|
56
|
-
await (client == null ? void 0 : client.
|
|
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
|
},
|
|
60
61
|
create: async (collectionName, record) => {
|
|
61
|
-
return await (client == null ? void 0 : client.
|
|
62
|
+
return await (client == null ? void 0 : client.collection(collectionName).create(record).catch(tempErrorHandler));
|
|
62
63
|
},
|
|
63
64
|
update: async (collectionName, recordId, record) => {
|
|
64
|
-
return await (client == null ? void 0 : client.
|
|
65
|
+
return await (client == null ? void 0 : client.collection(collectionName).update(recordId, record).catch(tempErrorHandler));
|
|
65
66
|
},
|
|
66
67
|
delete: async (collectionName, recordId) => {
|
|
67
|
-
return await (client == null ? void 0 : client.
|
|
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
|
-
"
|
|
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
|
-
"
|
|
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
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
2
|
import { createContext, useEffect } from 'react';
|
|
3
|
-
import PocketBase
|
|
3
|
+
import PocketBase from 'pocketbase';
|
|
4
4
|
import { Provider } from 'react-redux';
|
|
5
5
|
import { PersistGate } from 'redux-persist/integration/react';
|
|
6
6
|
import { store, persistor } from '../store/store';
|