pocketbase-react 0.1.1 → 0.1.3

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.
Files changed (97) hide show
  1. package/CHANGELOG.md +3 -1
  2. package/README.md +15 -0
  3. package/dist/pocketbase-react.js +464 -0
  4. package/dist/pocketbase-react.min.js +1 -0
  5. package/{dist/esm → es}/context/Pocketbase.d.ts +1 -3
  6. package/es/context/Pocketbase.js +27 -0
  7. package/{dist/cjs → es}/context/client.d.ts +1 -1
  8. package/es/context/client.js +8 -0
  9. package/{dist/cjs → es}/context/content.d.ts +0 -0
  10. package/es/context/content.js +63 -0
  11. package/{dist/cjs → es}/context/index.d.ts +0 -0
  12. package/es/context/index.js +3 -0
  13. package/{dist/cjs → es}/hooks/index.d.ts +0 -0
  14. package/es/hooks/index.js +2 -0
  15. package/{dist/cjs → es}/hooks/useAppContent.d.ts +1 -1
  16. package/es/hooks/useAppContent.js +25 -0
  17. package/es/hooks/useClientContext.d.ts +2 -0
  18. package/es/hooks/useClientContext.js +7 -0
  19. package/{dist/cjs → es}/index.d.ts +0 -0
  20. package/{dist/esm/index.d.ts → es/index.js} +1 -1
  21. package/{dist/cjs → es}/interfaces/Record.d.ts +1 -1
  22. package/es/interfaces/Record.js +1 -0
  23. package/{dist/cjs → es}/interfaces/index.d.ts +0 -0
  24. package/es/interfaces/index.js +1 -0
  25. package/es/store/actions/index.d.ts +2 -0
  26. package/es/store/actions/index.js +2 -0
  27. package/es/store/actions/records.d.ts +9 -0
  28. package/es/store/actions/records.js +32 -0
  29. package/{dist/cjs → es}/store/index.d.ts +0 -0
  30. package/{dist/esm/store/index.d.ts → es/store/index.js} +1 -1
  31. package/{dist/cjs → es}/store/reducers/index.d.ts +2 -2
  32. package/es/store/reducers/index.js +5 -0
  33. package/{dist/cjs → es}/store/reducers/records.d.ts +2 -3
  34. package/es/store/reducers/records.js +56 -0
  35. package/{dist/cjs → es}/store/store.d.ts +0 -0
  36. package/es/store/store.js +44 -0
  37. package/{dist/cjs → es}/store/types/index.d.ts +0 -0
  38. package/es/store/types/index.js +6 -0
  39. package/lib/context/Pocketbase.js +35 -0
  40. package/lib/context/client.js +15 -0
  41. package/lib/context/content.js +70 -0
  42. package/lib/context/index.js +36 -0
  43. package/lib/hooks/index.js +25 -0
  44. package/lib/hooks/useAppContent.js +31 -0
  45. package/lib/hooks/useClientContext.js +11 -0
  46. package/lib/index.js +47 -0
  47. package/lib/interfaces/Record.js +1 -0
  48. package/lib/interfaces/index.js +14 -0
  49. package/lib/store/actions/index.js +8 -0
  50. package/lib/store/actions/records.js +43 -0
  51. package/lib/store/index.js +47 -0
  52. package/lib/store/reducers/index.js +10 -0
  53. package/lib/store/reducers/records.js +64 -0
  54. package/lib/store/store.js +53 -0
  55. package/lib/store/types/index.js +16 -0
  56. package/package.json +94 -35
  57. package/src/context/Pocketbase.tsx +42 -0
  58. package/src/context/client.tsx +14 -0
  59. package/src/context/content.tsx +88 -0
  60. package/{dist/esm/context/index.d.ts → src/context/index.ts} +0 -0
  61. package/src/hooks/index.ts +2 -0
  62. package/src/hooks/useAppContent.ts +28 -0
  63. package/src/hooks/useClientContext.ts +11 -0
  64. package/src/index.ts +4 -0
  65. package/src/interfaces/Record.ts +10 -0
  66. package/src/interfaces/index.ts +1 -0
  67. package/src/store/actions/index.tsx +3 -0
  68. package/src/store/actions/records.tsx +54 -0
  69. package/src/store/index.ts +4 -0
  70. package/src/store/reducers/index.tsx +12 -0
  71. package/src/store/reducers/records.tsx +78 -0
  72. package/src/store/store.tsx +65 -0
  73. package/src/store/types/index.ts +14 -0
  74. package/dist/cjs/EventSource.d.ts +0 -1
  75. package/dist/cjs/context/Pocketbase.d.ts +0 -15
  76. package/dist/cjs/hooks/useClientContext.d.ts +0 -2
  77. package/dist/cjs/index.js +0 -3478
  78. package/dist/cjs/index.js.map +0 -1
  79. package/dist/cjs/store/actions/index.d.ts +0 -2
  80. package/dist/cjs/store/actions/records.d.ts +0 -11
  81. package/dist/esm/EventSource.d.ts +0 -1
  82. package/dist/esm/context/client.d.ts +0 -8
  83. package/dist/esm/context/content.d.ts +0 -16
  84. package/dist/esm/hooks/index.d.ts +0 -2
  85. package/dist/esm/hooks/useAppContent.d.ts +0 -12
  86. package/dist/esm/hooks/useClientContext.d.ts +0 -2
  87. package/dist/esm/index.js +0 -3433
  88. package/dist/esm/index.js.map +0 -1
  89. package/dist/esm/interfaces/Record.d.ts +0 -10
  90. package/dist/esm/interfaces/index.d.ts +0 -1
  91. package/dist/esm/store/actions/index.d.ts +0 -2
  92. package/dist/esm/store/actions/records.d.ts +0 -11
  93. package/dist/esm/store/reducers/index.d.ts +0 -8
  94. package/dist/esm/store/reducers/records.d.ts +0 -12
  95. package/dist/esm/store/store.d.ts +0 -27
  96. package/dist/esm/store/types/index.d.ts +0 -7
  97. package/dist/index.d.ts +0 -128
@@ -0,0 +1,25 @@
1
+ import { useContext, useEffect } from 'react';
2
+ import * as store from '../store';
3
+ import { ContentContext } from '../context';
4
+ export function useAppContent(collectionName, initialFetch = false) {
5
+ var _store$useAppSelector;
6
+ const records = (_store$useAppSelector = store.useAppSelector(state => state.reducer.records[collectionName])) != null ? _store$useAppSelector : [];
7
+ const context = useContext(ContentContext);
8
+ useEffect(() => {
9
+ if (initialFetch) {
10
+ context == null ? void 0 : context.fetch(collectionName);
11
+ }
12
+ }, [collectionName, initialFetch]);
13
+ const actions = {
14
+ subscribe: async () => await (context == null ? void 0 : context.subscribe(collectionName)),
15
+ unsubscribe: () => context == null ? void 0 : context.unsubscribe(collectionName),
16
+ refetch: async () => await (context == null ? void 0 : context.fetch(collectionName)),
17
+ create: async record => await (context == null ? void 0 : context.create(collectionName, record)),
18
+ update: async (id, record) => await (context == null ? void 0 : context.update(collectionName, id, record)),
19
+ delete: async id => await (context == null ? void 0 : context.delete(collectionName, id))
20
+ };
21
+ return {
22
+ records,
23
+ actions
24
+ };
25
+ }
@@ -0,0 +1,2 @@
1
+ declare const useClientContext: () => import("pocketbase").default | null;
2
+ export { useClientContext };
@@ -0,0 +1,7 @@
1
+ import { useContext } from 'react';
2
+ import { ClientContext } from '../context';
3
+ const useClientContext = () => {
4
+ const context = useContext(ClientContext);
5
+ return context;
6
+ };
7
+ export { useClientContext };
File without changes
@@ -1,4 +1,4 @@
1
1
  export * from './hooks';
2
2
  export * from './interfaces';
3
3
  export * from './context';
4
- export * from './store';
4
+ export * from './store';
@@ -1,4 +1,4 @@
1
- export default interface Record {
1
+ export interface Record {
2
2
  id?: string;
3
3
  created?: string;
4
4
  updated?: string;
@@ -0,0 +1 @@
1
+ export {};
File without changes
@@ -0,0 +1 @@
1
+ export * from './Record';
@@ -0,0 +1,2 @@
1
+ import * as recordsAction from './records';
2
+ export { recordsAction };
@@ -0,0 +1,2 @@
1
+ import * as recordsAction from './records';
2
+ export { recordsAction };
@@ -0,0 +1,9 @@
1
+ import { Record } from '../../interfaces/Record';
2
+ import { RecordAction } from '../reducers/records';
3
+ declare const setRecords: (key: string, payload: Record[]) => RecordAction;
4
+ declare const addRecord: (key: string, payload: Record) => RecordAction;
5
+ declare const addRecords: (key: string, payload: Record[]) => RecordAction;
6
+ declare const deleteRecord: (key: string, payload: Record) => RecordAction;
7
+ declare const deleteRecords: (key: string, payload: Record[]) => RecordAction;
8
+ declare const updateRecord: (key: string, payload: Record) => RecordAction;
9
+ export { setRecords, addRecord, addRecords, deleteRecord, deleteRecords, updateRecord, };
@@ -0,0 +1,32 @@
1
+ import * as ReduxType from '../types';
2
+ const setRecords = (key, payload) => ({
3
+ type: ReduxType.SET_RECORDS,
4
+ key,
5
+ payload
6
+ });
7
+ const addRecord = (key, payload) => ({
8
+ type: ReduxType.ADD_RECORD,
9
+ key,
10
+ payload
11
+ });
12
+ const addRecords = (key, payload) => ({
13
+ type: ReduxType.ADD_RECORDS,
14
+ key,
15
+ payload
16
+ });
17
+ const deleteRecord = (key, payload) => ({
18
+ type: ReduxType.DELETE_RECORD,
19
+ key,
20
+ payload
21
+ });
22
+ const deleteRecords = (key, payload) => ({
23
+ type: ReduxType.DELETE_RECORDS,
24
+ key,
25
+ payload
26
+ });
27
+ const updateRecord = (key, payload) => ({
28
+ type: ReduxType.UPDATE_RECORD,
29
+ key,
30
+ payload
31
+ });
32
+ export { setRecords, addRecord, addRecords, deleteRecord, deleteRecords, updateRecord };
File without changes
@@ -1,4 +1,4 @@
1
1
  export * from './actions';
2
2
  export * from './reducers';
3
3
  export * from './types';
4
- export * from './store';
4
+ export * from './store';
@@ -1,8 +1,8 @@
1
- declare const appReducer: import("redux").Reducer<import("redux").CombinedState<{
1
+ export declare const appReducer: import("redux").Reducer<import("redux").CombinedState<{
2
2
  records: import("./records").ReduxRecord;
3
3
  }>, import("./records").RecordAction>;
4
4
  interface AppReducer {
5
5
  records: ReturnType<typeof appReducer>;
6
6
  }
7
7
  export declare type State = AppReducer;
8
- export default appReducer;
8
+ export {};
@@ -0,0 +1,5 @@
1
+ import { combineReducers } from 'redux';
2
+ import { records } from './records';
3
+ export const appReducer = combineReducers({
4
+ records: records
5
+ });
@@ -1,4 +1,4 @@
1
- import Record from '../../interfaces/Record';
1
+ import { Record } from '../../interfaces/Record';
2
2
  import * as ReduxType from '../types';
3
3
  export interface ReduxRecord {
4
4
  [key: string]: Record[];
@@ -8,5 +8,4 @@ export declare type RecordAction = {
8
8
  key: string;
9
9
  payload: null | Record | Record[];
10
10
  };
11
- declare const _default: (state: ReduxRecord | undefined, action: RecordAction) => ReduxRecord;
12
- export default _default;
11
+ export declare const records: (state: ReduxRecord | undefined, action: RecordAction) => ReduxRecord;
@@ -0,0 +1,56 @@
1
+ import _extends from "@babel/runtime/helpers/esm/extends";
2
+ import * as ReduxType from '../types';
3
+ function appendRecord(record, records) {
4
+ return [...records, record];
5
+ }
6
+ function appendRecords(recordsToAppend, records) {
7
+ return [...records, ...recordsToAppend];
8
+ }
9
+ function updateRecord(record, records) {
10
+ return records.map(r => {
11
+ if (r.id === record.id) {
12
+ return record;
13
+ }
14
+ return r;
15
+ });
16
+ }
17
+ function deleteRecord(record, records) {
18
+ return records.filter(r => r.id !== record.id);
19
+ }
20
+ function deleteRecords(recordsToDelete, records) {
21
+ return records.filter(r => !recordsToDelete.includes(r));
22
+ }
23
+ export const records = (state = {}, action) => {
24
+ var _state$action$key;
25
+ const list = (_state$action$key = state[action.key]) != null ? _state$action$key : [];
26
+ switch (action.type) {
27
+ case ReduxType.SET_RECORDS:
28
+ if (Array.isArray(action.payload)) {
29
+ return _extends({}, state, {
30
+ [action.key]: action.payload
31
+ });
32
+ }
33
+ case ReduxType.ADD_RECORD:
34
+ return _extends({}, state, {
35
+ [action.key]: appendRecord(action.payload, list)
36
+ });
37
+ case ReduxType.ADD_RECORDS:
38
+ return _extends({}, state, {
39
+ [action.key]: appendRecords(action.payload, list)
40
+ });
41
+ case ReduxType.DELETE_RECORD:
42
+ return _extends({}, state, {
43
+ [action.key]: deleteRecord(action.payload, list)
44
+ });
45
+ case ReduxType.DELETE_RECORDS:
46
+ return _extends({}, state, {
47
+ [action.key]: deleteRecords(action.payload, list)
48
+ });
49
+ case ReduxType.UPDATE_RECORD:
50
+ return _extends({}, state, {
51
+ [action.key]: updateRecord(action.payload, list)
52
+ });
53
+ default:
54
+ return state;
55
+ }
56
+ };
File without changes
@@ -0,0 +1,44 @@
1
+ import { combineReducers, configureStore } from '@reduxjs/toolkit';
2
+ import { persistStore, persistReducer } from 'redux-persist';
3
+ import { useSelector } from 'react-redux';
4
+ import { appReducer } from './reducers';
5
+ import thunk from 'redux-thunk';
6
+ import AsyncStorage from '@react-native-async-storage/async-storage';
7
+ const CustomStorage = {
8
+ getItem: async (_key, ..._args) => {
9
+ if (typeof document !== 'undefined') {
10
+ return localStorage.getItem(_key);
11
+ } else if (typeof navigator !== 'undefined' && navigator.product === 'ReactNative') {
12
+ return await AsyncStorage.getItem(_key);
13
+ }
14
+ },
15
+ setItem: async (_key, _value, ..._args) => {
16
+ if (typeof document !== 'undefined') {
17
+ return localStorage.setItem(_key, _value);
18
+ } else if (typeof navigator !== 'undefined' && navigator.product === 'ReactNative') {
19
+ return await AsyncStorage.setItem(_key, _value);
20
+ }
21
+ },
22
+ removeItem: async (_key, ..._args) => {
23
+ if (typeof document !== 'undefined') {
24
+ return localStorage.removeItem(_key);
25
+ } else if (typeof navigator !== 'undefined' && navigator.product === 'ReactNative') {
26
+ return await AsyncStorage.removeItem(_key);
27
+ }
28
+ }
29
+ };
30
+ export const persistConfig = {
31
+ key: 'root',
32
+ storage: CustomStorage
33
+ };
34
+ const reducer = combineReducers({
35
+ reducer: persistReducer(persistConfig, appReducer)
36
+ });
37
+ const store = configureStore({
38
+ reducer,
39
+ middleware: [thunk]
40
+ });
41
+ const useAppDispatch = store.dispatch;
42
+ const useAppSelector = useSelector;
43
+ const persistor = persistStore(store);
44
+ export { useAppDispatch, useAppSelector, store, persistor };
File without changes
@@ -0,0 +1,6 @@
1
+ export const SET_RECORDS = 'SET_RECORDS';
2
+ export const ADD_RECORD = 'ADD_RECORD';
3
+ export const ADD_RECORDS = 'ADD_RECORDS';
4
+ export const UPDATE_RECORD = 'UPDATE_RECORD';
5
+ export const DELETE_RECORD = 'DELETE_RECORD';
6
+ export const DELETE_RECORDS = 'DELETE_RECORDS';
@@ -0,0 +1,35 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+ exports.__esModule = true;
5
+ exports.PocketbaseContext = exports.Pocketbase = void 0;
6
+ var React = _interopRequireWildcard(require("react"));
7
+ var _pocketbase = _interopRequireDefault(require("pocketbase"));
8
+ var _reactRedux = require("react-redux");
9
+ var _react2 = require("redux-persist/integration/react");
10
+ var store = _interopRequireWildcard(require("../store/store"));
11
+ var _client = require("./client");
12
+ var _content = require("./content");
13
+ function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
14
+ 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; }
15
+ const PocketbaseContext = (0, React.createContext)(null);
16
+ exports.PocketbaseContext = PocketbaseContext;
17
+ const Pocketbase = props => {
18
+ const [client, setClient] = React.useState(null);
19
+ (0, React.useEffect)(() => {
20
+ const client = new _pocketbase.default(props.serverURL);
21
+ client.admins.authViaEmail(props.credentials.username, props.credentials.password).then(() => {
22
+ setClient(client);
23
+ });
24
+ }, [props.serverURL]);
25
+ return client ? /*#__PURE__*/React.createElement(_client.ClientProvider, {
26
+ client: client
27
+ }, /*#__PURE__*/React.createElement(_reactRedux.Provider, {
28
+ store: store.store
29
+ }, /*#__PURE__*/React.createElement(_react2.PersistGate, {
30
+ persistor: store.persistor
31
+ }, /*#__PURE__*/React.createElement(_content.ContentProvider, {
32
+ collections: props.initialCollections
33
+ }, props.children)))) : null;
34
+ };
35
+ exports.Pocketbase = Pocketbase;
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+
3
+ exports.__esModule = true;
4
+ exports.ClientProvider = exports.ClientContext = void 0;
5
+ var React = _interopRequireWildcard(require("react"));
6
+ function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
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; }
8
+ const ClientContext = (0, React.createContext)(null);
9
+ exports.ClientContext = ClientContext;
10
+ const ClientProvider = props => {
11
+ return /*#__PURE__*/React.createElement(ClientContext.Provider, {
12
+ value: props.client
13
+ }, props.children);
14
+ };
15
+ exports.ClientProvider = ClientProvider;
@@ -0,0 +1,70 @@
1
+ "use strict";
2
+
3
+ exports.__esModule = true;
4
+ exports.ContentProvider = exports.ContentContext = void 0;
5
+ var store = _interopRequireWildcard(require("../store/store"));
6
+ var React = _interopRequireWildcard(require("react"));
7
+ var _useClientContext = require("../hooks/useClientContext");
8
+ var _actions = require("../store/actions");
9
+ function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
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; }
11
+ const ContentContext = (0, React.createContext)(null);
12
+ exports.ContentContext = ContentContext;
13
+ const ContentProvider = props => {
14
+ const client = (0, _useClientContext.useClientContext)();
15
+ const dispatch = store.useAppDispatch;
16
+ const [collections, _] = React.useState(props.collections || []);
17
+ const actions = {
18
+ subscribe: async collectionName => {
19
+ // save local that collectionName should be subscribed
20
+ await (client == null ? void 0 : client.realtime.subscribe(collectionName, event => {
21
+ switch (event.action) {
22
+ case 'create':
23
+ dispatch(_actions.recordsAction.addRecord(collectionName, event.record));
24
+ break;
25
+ case 'update':
26
+ dispatch(_actions.recordsAction.updateRecord(collectionName, event.record));
27
+ break;
28
+ case 'delete':
29
+ dispatch(_actions.recordsAction.deleteRecord(collectionName, event.record));
30
+ break;
31
+ default:
32
+ break;
33
+ }
34
+ }));
35
+ },
36
+ unsubscribe: collectionName => {
37
+ if (collectionName) {
38
+ client == null ? void 0 : client.realtime.unsubscribe(collectionName);
39
+ } else {
40
+ client == null ? void 0 : client.realtime.unsubscribe();
41
+ }
42
+ },
43
+ fetch: async collectionName => {
44
+ const records = await (client == null ? void 0 : client.records.getFullList(collectionName, 200));
45
+ dispatch(_actions.recordsAction.setRecords(collectionName, records));
46
+ },
47
+ create: async (collectionName, record) => {
48
+ await (client == null ? void 0 : client.records.create(collectionName, record));
49
+ },
50
+ update: async (collectionName, recordId, record) => {
51
+ await (client == null ? void 0 : client.records.update(collectionName, recordId, record));
52
+ },
53
+ delete: async (collectionName, recordId) => {
54
+ await (client == null ? void 0 : client.records.delete(collectionName, recordId));
55
+ }
56
+ };
57
+ (0, React.useEffect)(() => {
58
+ if (collections) {
59
+ collections.forEach(collectionName => {
60
+ actions.fetch(collectionName);
61
+ actions.subscribe(collectionName);
62
+ });
63
+ }
64
+ return () => actions.unsubscribe();
65
+ }, [collections]);
66
+ return /*#__PURE__*/React.createElement(ContentContext.Provider, {
67
+ value: actions
68
+ }, props.children);
69
+ };
70
+ exports.ContentProvider = ContentProvider;
@@ -0,0 +1,36 @@
1
+ "use strict";
2
+
3
+ exports.__esModule = true;
4
+ var _content = require("./content");
5
+ Object.keys(_content).forEach(function (key) {
6
+ if (key === "default" || key === "__esModule") return;
7
+ if (key in exports && exports[key] === _content[key]) return;
8
+ Object.defineProperty(exports, key, {
9
+ enumerable: true,
10
+ get: function () {
11
+ return _content[key];
12
+ }
13
+ });
14
+ });
15
+ var _client = require("./client");
16
+ Object.keys(_client).forEach(function (key) {
17
+ if (key === "default" || key === "__esModule") return;
18
+ if (key in exports && exports[key] === _client[key]) return;
19
+ Object.defineProperty(exports, key, {
20
+ enumerable: true,
21
+ get: function () {
22
+ return _client[key];
23
+ }
24
+ });
25
+ });
26
+ var _Pocketbase = require("./Pocketbase");
27
+ Object.keys(_Pocketbase).forEach(function (key) {
28
+ if (key === "default" || key === "__esModule") return;
29
+ if (key in exports && exports[key] === _Pocketbase[key]) return;
30
+ Object.defineProperty(exports, key, {
31
+ enumerable: true,
32
+ get: function () {
33
+ return _Pocketbase[key];
34
+ }
35
+ });
36
+ });
@@ -0,0 +1,25 @@
1
+ "use strict";
2
+
3
+ exports.__esModule = true;
4
+ var _useAppContent = require("./useAppContent");
5
+ Object.keys(_useAppContent).forEach(function (key) {
6
+ if (key === "default" || key === "__esModule") return;
7
+ if (key in exports && exports[key] === _useAppContent[key]) return;
8
+ Object.defineProperty(exports, key, {
9
+ enumerable: true,
10
+ get: function () {
11
+ return _useAppContent[key];
12
+ }
13
+ });
14
+ });
15
+ var _useClientContext = require("./useClientContext");
16
+ Object.keys(_useClientContext).forEach(function (key) {
17
+ if (key === "default" || key === "__esModule") return;
18
+ if (key in exports && exports[key] === _useClientContext[key]) return;
19
+ Object.defineProperty(exports, key, {
20
+ enumerable: true,
21
+ get: function () {
22
+ return _useClientContext[key];
23
+ }
24
+ });
25
+ });
@@ -0,0 +1,31 @@
1
+ "use strict";
2
+
3
+ exports.__esModule = true;
4
+ exports.useAppContent = useAppContent;
5
+ var _react = require("react");
6
+ var store = _interopRequireWildcard(require("../store"));
7
+ var _context = require("../context");
8
+ function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
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; }
10
+ function useAppContent(collectionName, initialFetch = false) {
11
+ var _store$useAppSelector;
12
+ const records = (_store$useAppSelector = store.useAppSelector(state => state.reducer.records[collectionName])) != null ? _store$useAppSelector : [];
13
+ const context = (0, _react.useContext)(_context.ContentContext);
14
+ (0, _react.useEffect)(() => {
15
+ if (initialFetch) {
16
+ context == null ? void 0 : context.fetch(collectionName);
17
+ }
18
+ }, [collectionName, initialFetch]);
19
+ const actions = {
20
+ subscribe: async () => await (context == null ? void 0 : context.subscribe(collectionName)),
21
+ unsubscribe: () => context == null ? void 0 : context.unsubscribe(collectionName),
22
+ refetch: async () => await (context == null ? void 0 : context.fetch(collectionName)),
23
+ create: async record => await (context == null ? void 0 : context.create(collectionName, record)),
24
+ update: async (id, record) => await (context == null ? void 0 : context.update(collectionName, id, record)),
25
+ delete: async id => await (context == null ? void 0 : context.delete(collectionName, id))
26
+ };
27
+ return {
28
+ records,
29
+ actions
30
+ };
31
+ }
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+
3
+ exports.__esModule = true;
4
+ exports.useClientContext = void 0;
5
+ var _react = require("react");
6
+ var _context = require("../context");
7
+ const useClientContext = () => {
8
+ const context = (0, _react.useContext)(_context.ClientContext);
9
+ return context;
10
+ };
11
+ exports.useClientContext = useClientContext;
package/lib/index.js ADDED
@@ -0,0 +1,47 @@
1
+ "use strict";
2
+
3
+ exports.__esModule = true;
4
+ var _hooks = require("./hooks");
5
+ Object.keys(_hooks).forEach(function (key) {
6
+ if (key === "default" || key === "__esModule") return;
7
+ if (key in exports && exports[key] === _hooks[key]) return;
8
+ Object.defineProperty(exports, key, {
9
+ enumerable: true,
10
+ get: function () {
11
+ return _hooks[key];
12
+ }
13
+ });
14
+ });
15
+ var _interfaces = require("./interfaces");
16
+ Object.keys(_interfaces).forEach(function (key) {
17
+ if (key === "default" || key === "__esModule") return;
18
+ if (key in exports && exports[key] === _interfaces[key]) return;
19
+ Object.defineProperty(exports, key, {
20
+ enumerable: true,
21
+ get: function () {
22
+ return _interfaces[key];
23
+ }
24
+ });
25
+ });
26
+ var _context = require("./context");
27
+ Object.keys(_context).forEach(function (key) {
28
+ if (key === "default" || key === "__esModule") return;
29
+ if (key in exports && exports[key] === _context[key]) return;
30
+ Object.defineProperty(exports, key, {
31
+ enumerable: true,
32
+ get: function () {
33
+ return _context[key];
34
+ }
35
+ });
36
+ });
37
+ var _store = require("./store");
38
+ Object.keys(_store).forEach(function (key) {
39
+ if (key === "default" || key === "__esModule") return;
40
+ if (key in exports && exports[key] === _store[key]) return;
41
+ Object.defineProperty(exports, key, {
42
+ enumerable: true,
43
+ get: function () {
44
+ return _store[key];
45
+ }
46
+ });
47
+ });
@@ -0,0 +1 @@
1
+ "use strict";
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+
3
+ exports.__esModule = true;
4
+ var _Record = require("./Record");
5
+ Object.keys(_Record).forEach(function (key) {
6
+ if (key === "default" || key === "__esModule") return;
7
+ if (key in exports && exports[key] === _Record[key]) return;
8
+ Object.defineProperty(exports, key, {
9
+ enumerable: true,
10
+ get: function () {
11
+ return _Record[key];
12
+ }
13
+ });
14
+ });
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+
3
+ exports.__esModule = true;
4
+ exports.recordsAction = void 0;
5
+ var recordsAction = _interopRequireWildcard(require("./records"));
6
+ exports.recordsAction = recordsAction;
7
+ function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
8
+ 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; }
@@ -0,0 +1,43 @@
1
+ "use strict";
2
+
3
+ exports.__esModule = true;
4
+ exports.updateRecord = exports.setRecords = exports.deleteRecords = exports.deleteRecord = exports.addRecords = exports.addRecord = void 0;
5
+ var ReduxType = _interopRequireWildcard(require("../types"));
6
+ function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
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; }
8
+ const setRecords = (key, payload) => ({
9
+ type: ReduxType.SET_RECORDS,
10
+ key,
11
+ payload
12
+ });
13
+ exports.setRecords = setRecords;
14
+ const addRecord = (key, payload) => ({
15
+ type: ReduxType.ADD_RECORD,
16
+ key,
17
+ payload
18
+ });
19
+ exports.addRecord = addRecord;
20
+ const addRecords = (key, payload) => ({
21
+ type: ReduxType.ADD_RECORDS,
22
+ key,
23
+ payload
24
+ });
25
+ exports.addRecords = addRecords;
26
+ const deleteRecord = (key, payload) => ({
27
+ type: ReduxType.DELETE_RECORD,
28
+ key,
29
+ payload
30
+ });
31
+ exports.deleteRecord = deleteRecord;
32
+ const deleteRecords = (key, payload) => ({
33
+ type: ReduxType.DELETE_RECORDS,
34
+ key,
35
+ payload
36
+ });
37
+ exports.deleteRecords = deleteRecords;
38
+ const updateRecord = (key, payload) => ({
39
+ type: ReduxType.UPDATE_RECORD,
40
+ key,
41
+ payload
42
+ });
43
+ exports.updateRecord = updateRecord;