pocketbase-react 0.1.0 → 0.1.2

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