pocketbase-react 0.1.14 → 0.1.16

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 (62) hide show
  1. package/CHANGELOG.md +15 -3
  2. package/README.md +56 -16
  3. package/dist/pocketbase-react.js +85 -52
  4. package/dist/pocketbase-react.min.js +3 -3
  5. package/es/context/auth.d.ts +7 -1
  6. package/es/context/auth.js +6 -1
  7. package/es/context/content.d.ts +1 -4
  8. package/es/context/content.js +7 -21
  9. package/es/hooks/useAppContent.js +10 -24
  10. package/es/hooks/useAuth.d.ts +2 -4
  11. package/es/hooks/useAuth.js +1 -4
  12. package/es/service/Authentication.d.ts +1 -1
  13. package/es/service/Authentication.js +1 -1
  14. package/es/service/Storage.js +2 -2
  15. package/es/store/actions/index.d.ts +2 -1
  16. package/es/store/actions/index.js +2 -1
  17. package/es/store/actions/records.d.ts +1 -1
  18. package/es/store/actions/subscriptions.d.ts +5 -0
  19. package/es/store/actions/subscriptions.js +14 -0
  20. package/es/store/reducers/index.d.ts +2 -1
  21. package/es/store/reducers/index.js +3 -1
  22. package/es/store/reducers/records.d.ts +1 -1
  23. package/es/store/reducers/subscriptions.d.ts +9 -0
  24. package/es/store/reducers/subscriptions.js +30 -0
  25. package/es/store/store.d.ts +3 -2
  26. package/es/store/store.js +2 -2
  27. package/es/store/types/index.d.ts +5 -1
  28. package/es/store/types/index.js +4 -1
  29. package/lib/context/auth.js +6 -1
  30. package/lib/context/content.js +6 -21
  31. package/lib/hooks/useAppContent.js +10 -24
  32. package/lib/hooks/useAuth.js +1 -4
  33. package/lib/service/Authentication.js +1 -1
  34. package/lib/service/Storage.js +1 -1
  35. package/lib/store/actions/index.js +3 -1
  36. package/lib/store/actions/subscriptions.js +22 -0
  37. package/lib/store/reducers/index.js +3 -1
  38. package/lib/store/reducers/subscriptions.js +37 -0
  39. package/lib/store/store.js +2 -2
  40. package/lib/store/types/index.js +8 -2
  41. package/package.json +1 -1
  42. package/src/context/Pocketbase.tsx +5 -2
  43. package/src/context/auth.tsx +29 -9
  44. package/src/context/content.tsx +38 -57
  45. package/src/context/index.ts +1 -1
  46. package/src/hooks/index.ts +1 -1
  47. package/src/hooks/useAppContent.ts +19 -31
  48. package/src/hooks/useAuth.ts +3 -4
  49. package/src/hooks/useClientContext.ts +1 -2
  50. package/src/index.ts +1 -1
  51. package/src/interfaces/index.ts +1 -1
  52. package/src/service/Authentication.ts +12 -22
  53. package/src/service/Storage.ts +22 -21
  54. package/src/store/actions/index.tsx +2 -1
  55. package/src/store/actions/records.tsx +1 -8
  56. package/src/store/actions/subscriptions.tsx +22 -0
  57. package/src/store/index.ts +1 -1
  58. package/src/store/reducers/index.tsx +3 -1
  59. package/src/store/reducers/records.tsx +2 -2
  60. package/src/store/reducers/subscriptions.tsx +46 -0
  61. package/src/store/store.tsx +4 -7
  62. package/src/store/types/index.ts +10 -1
package/CHANGELOG.md CHANGED
@@ -1,4 +1,5 @@
1
1
  # Changelog
2
+
2
3
  All notable changes to this project will be documented in this file.
3
4
 
4
5
  The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
@@ -7,30 +8,41 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
7
8
  ## [Unreleased]
8
9
 
9
10
  ## [0.1.5] - 2022-10-10
11
+
10
12
  ### Changed
13
+
11
14
  - SDK now uses custom @tobicrain/pocketbase javascript framework
12
15
 
13
16
  ## [0.1.4] - 2022-10-10
17
+
14
18
  ### Fixed
19
+
15
20
  - SDK now runs on React and React Native
16
21
 
17
22
  ## [0.1.3] - 2022-10-06
23
+
18
24
  ### Changed
19
- - Redux now toggles between localStorage / AsyncStorage
20
25
 
26
+ - Redux now toggles between localStorage / AsyncStorage
21
27
 
22
28
  ## [0.1.2] - 2022-10-05
29
+
23
30
  ### Changed
24
- - Adjusted Rollup / Babel Config for use in React
25
31
 
32
+ - Adjusted Rollup / Babel Config for use in React
26
33
 
27
34
  ## [0.1.1] - 2022-10-04
35
+
28
36
  ### Changed
37
+
29
38
  - initialCollections now also "subscribe" instead of just "fetch" content once
30
39
 
31
40
  ## [0.1.0] - 2022-10-03
41
+
32
42
  ### Added
43
+
33
44
  - Initial commit
34
45
 
35
46
  ### Changed
36
- - Readme Instructions and so on
47
+
48
+ - Readme Instructions and so on
package/README.md CHANGED
@@ -1,21 +1,18 @@
1
- PocketBase React SDK
2
- ======================================================================
1
+ # PocketBase React SDK
2
+
3
3
  [![Npm package version](https://badgen.net/npm/v/pocketbase-react)](https://npmjs.com/package/pocketbase-react)
4
4
 
5
5
  Unofficial React SDK (React, React Native, Expo) for interacting with the [PocketBase JS SDK](https://github.com/pocketbase/js-sdk).
6
6
 
7
-
8
7
  - [Installation](#installation)
9
8
  - [Usage](#usage)
10
9
  - [Caveats](#caveats)
11
10
  - [Development](#development)
12
11
 
13
-
14
12
  ## Installation
15
13
 
16
14
  ### React, React Native or Expo
17
15
 
18
-
19
16
  ```sh
20
17
  # Using npm
21
18
  npm install pocketbase-react --save
@@ -23,13 +20,16 @@ npm install pocketbase-react --save
23
20
  #Using yarn
24
21
  yarn add pocketbase-react
25
22
  ```
23
+
26
24
  ```tsx
27
25
  import { Pocketbase } from 'pocketbase-react';
28
26
  ```
29
27
 
30
28
  ---
29
+
31
30
  > 🔧 React Native / Expo doesn't have native `EventSource` implementation, so in order to use the realtime service you'll need to load a `EventSource` polyfill.
32
31
  > I recommend [EventSource/eventsource](https://github.com/EventSource/eventsource)
32
+ >
33
33
  > ```sh
34
34
  > # Using npm
35
35
  > npm install eventsource --save
@@ -37,7 +37,8 @@ import { Pocketbase } from 'pocketbase-react';
37
37
  > # Using yarn
38
38
  > yarn add eventsource
39
39
  > ```
40
- > ```js
40
+ >
41
+ > ```js
41
42
  > // EventSource.ts
42
43
  > var Source = require('event-source');
43
44
  > global.EventSource = Source;
@@ -68,109 +69,148 @@ const mobileRedirectURL = "expo://..." // for example
68
69
  ```
69
70
 
70
71
  ## Caveats
72
+
71
73
  ```tsx
72
- import { useAppContent, useAuth } from "pocketbase-react";
74
+ import { useAppContent, useAuth } from 'pocketbase-react';
73
75
  ```
76
+
74
77
  ### Records
78
+
75
79
  Reading the records value directly accesses the Redux Store.
76
80
 
77
81
  The value will be changed automatically by the following actions:
82
+
78
83
  - [Initial Fetch](#initialfetch)
79
84
  - [Initial Collections](#usage)
80
85
  - [Subscribe](#subscribe)
81
86
  - [Refetch](#refetch)
82
87
 
83
88
  **Without** Initial Fetch
89
+
84
90
  ```tsx
85
91
  // Corresponds to the stored Redux value, simply reads without making further PocketBase requests
86
- const { records } = useAppContent("COLLECTION_NAME_01")
92
+ const { records } = useAppContent('COLLECTION_NAME_01');
87
93
  ```
94
+
88
95
  **With** Initial Fetch <a name="initialfetch"></a>
96
+
89
97
  ```tsx
90
98
  // When initializing, the desired table is queried once and updated in Redux, records corresponds to the stored Redux value
91
- const { records } = useAppContent("COLLECTION_NAME_01", true)
99
+ const { records } = useAppContent('COLLECTION_NAME_01', true);
92
100
  ```
93
101
 
94
102
  ### Actions
103
+
95
104
  ```tsx
96
- const { actions } = useAppContent("COLLECTION_NAME_01")
105
+ const { actions } = useAppContent('COLLECTION_NAME_01');
97
106
  ```
98
107
 
99
- > *All following actions are performed on the desired table, in this case -> COLLECTION_NAME_01*
108
+ > _All following actions are performed on the desired table, in this case -> COLLECTION_NAME_01_
100
109
  >
101
110
  > ⚠️ **All actions will not return anything, they will just modify the Redux value according to their intention**
102
111
 
103
112
  Subscribe <a name="subscribe"></a>
113
+
104
114
  ```tsx
105
115
  actions.subscribe();
106
116
  ```
117
+
107
118
  Unsubscribe
119
+
108
120
  ```tsx
109
121
  actions.unsubscribe();
110
122
  ```
123
+
111
124
  Refetch <a name="refetch"></a>
125
+
112
126
  ```tsx
113
127
  actions.refetch();
114
128
  ```
129
+
115
130
  Create
131
+
116
132
  ```tsx
117
133
  const object = {};
118
134
  actions.create(object);
119
135
  ```
136
+
120
137
  Update
138
+
121
139
  ```tsx
122
- const id = "SOME_ID";
140
+ const id = 'SOME_ID';
123
141
  const object = {};
124
142
  actions.update(id, object);
125
143
  ```
144
+
126
145
  DELETE
146
+
127
147
  ```tsx
128
- const id = "SOME_ID";
148
+ const id = 'SOME_ID';
129
149
  actions.delete(id);
130
150
  ```
131
151
 
132
152
  ### Auth
153
+
133
154
  ```tsx
134
- const { actions } = useAuth()
155
+ const { actions } = useAuth();
135
156
  ```
136
157
 
137
158
  Register with Email <a name="subscribe"></a>
159
+
138
160
  ```tsx
139
161
  await actions.registerWithEmail(email: string, password: string);
140
162
  ```
163
+
141
164
  Sign-In with Email
165
+
142
166
  ```tsx
143
167
  await actions.signInWithEmail(email: string, password: string);
144
168
  ```
169
+
145
170
  Sign-In with Provider
171
+
146
172
  ```tsx
147
173
  await actions.signInWithProvider(provider: string);
148
174
  ```
149
- Submit Provider Result
175
+
176
+ Submit Provider Result
177
+
150
178
  ```tsx
151
179
  await actions.submitProviderResult(url: string);
152
180
  ```
181
+
153
182
  Sign-Out
183
+
154
184
  ```tsx
155
185
  actions.signOut();
156
186
  ```
187
+
157
188
  Send password reset email
189
+
158
190
  ```tsx
159
191
  await actions.sendPasswordResetEmail(email: string);
160
192
  ```
193
+
161
194
  Send email verification
195
+
162
196
  ```tsx
163
197
  await actions.sendEmailVerification(email: string);
164
198
  ```
199
+
165
200
  Update profile
201
+
166
202
  ```tsx
167
203
  await actions.updateProfile(id: string, record: {});
168
204
  ```
205
+
169
206
  Update profile
207
+
170
208
  ```tsx
171
209
  await actions.updateEmail(email: string);
172
210
  ```
211
+
173
212
  Delete user
213
+
174
214
  ```tsx
175
215
  await actions.deleteUser(id: string);
176
- ```
216
+ ```
@@ -2761,6 +2761,9 @@
2761
2761
  const UPDATE_RECORD = 'UPDATE_RECORD';
2762
2762
  const DELETE_RECORD = 'DELETE_RECORD';
2763
2763
  const DELETE_RECORDS = 'DELETE_RECORDS';
2764
+ const SET_SUBSCRIPTIONS = 'SET_SUBSCRIPTIONS';
2765
+ const ADD_SUBSCRIPTION = 'ADD_SUBSCRIPTION';
2766
+ const DELETE_SUBSCRIPTION = 'DELETE_SUBSCRIPTION';
2764
2767
 
2765
2768
  const setRecords = (key, payload) => ({
2766
2769
  type: SET_RECORDS,
@@ -2803,6 +2806,26 @@
2803
2806
  updateRecord: updateRecord$1
2804
2807
  });
2805
2808
 
2809
+ const setSubscriptions = payload => ({
2810
+ type: SET_SUBSCRIPTIONS,
2811
+ payload
2812
+ });
2813
+ const addSubscription = payload => ({
2814
+ type: ADD_SUBSCRIPTION,
2815
+ payload
2816
+ });
2817
+ const deleteSubscription$1 = payload => ({
2818
+ type: DELETE_SUBSCRIPTION,
2819
+ payload
2820
+ });
2821
+
2822
+ var subscriptions$1 = /*#__PURE__*/Object.freeze({
2823
+ __proto__: null,
2824
+ setSubscriptions: setSubscriptions,
2825
+ addSubscription: addSubscription,
2826
+ deleteSubscription: deleteSubscription$1
2827
+ });
2828
+
2806
2829
  function _defineProperty$4(obj, key, value) {
2807
2830
  if (key in obj) {
2808
2831
  Object.defineProperty(obj, key, {
@@ -3529,8 +3552,39 @@
3529
3552
  }
3530
3553
  };
3531
3554
 
3555
+ function appendSubscription(subscription, subscriptions) {
3556
+ return [...subscriptions, subscription];
3557
+ }
3558
+ function deleteSubscription(subscription, subscriptions) {
3559
+ return subscriptions.filter(sub => sub !== subscription);
3560
+ }
3561
+ const subscriptions = (state = {
3562
+ subscriptions: []
3563
+ }, action) => {
3564
+ const list = state.subscriptions;
3565
+ switch (action.type) {
3566
+ case SET_SUBSCRIPTIONS:
3567
+ if (Array.isArray(action.payload)) {
3568
+ return {
3569
+ subscriptions: action.payload
3570
+ };
3571
+ }
3572
+ case ADD_SUBSCRIPTION:
3573
+ return {
3574
+ subscriptions: appendSubscription(action.payload, list)
3575
+ };
3576
+ case DELETE_SUBSCRIPTION:
3577
+ return {
3578
+ subscriptions: deleteSubscription(action.payload, list)
3579
+ };
3580
+ default:
3581
+ return state;
3582
+ }
3583
+ };
3584
+
3532
3585
  const appReducer = combineReducers({
3533
- records: records
3586
+ records: records,
3587
+ subscriptions: subscriptions
3534
3588
  });
3535
3589
 
3536
3590
  function n(n){for(var r=arguments.length,t=Array(r>1?r-1:0),e=1;e<r;e++)t[e-1]=arguments[e];{var i=Y[n],o=i?"function"==typeof i?i.apply(null,t):i:"unknown error nr: "+n;throw Error("[Immer] "+o)}}function r(n){return !!n&&!!n[Q]}function t(n){return !!n&&(function(n){if(!n||"object"!=typeof n)return !1;var r=Object.getPrototypeOf(n);if(null===r)return !0;var t=Object.hasOwnProperty.call(r,"constructor")&&r.constructor;return t===Object||"function"==typeof t&&Function.toString.call(t)===Z}(n)||Array.isArray(n)||!!n[L]||!!n.constructor[L]||s(n)||v(n))}function i(n,r,t){void 0===t&&(t=!1),0===o(n)?(t?Object.keys:nn)(n).forEach((function(e){t&&"symbol"==typeof e||r(e,n[e],n);})):n.forEach((function(t,e){return r(e,t,n)}));}function o(n){var r=n[Q];return r?r.i>3?r.i-4:r.i:Array.isArray(n)?1:s(n)?2:v(n)?3:0}function u(n,r){return 2===o(n)?n.has(r):Object.prototype.hasOwnProperty.call(n,r)}function a(n,r){return 2===o(n)?n.get(r):n[r]}function f(n,r,t){var e=o(n);2===e?n.set(r,t):3===e?(n.delete(r),n.add(t)):n[r]=t;}function c(n,r){return n===r?0!==n||1/n==1/r:n!=n&&r!=r}function s(n){return X&&n instanceof Map}function v(n){return q&&n instanceof Set}function p(n){return n.o||n.t}function l(n){if(Array.isArray(n))return Array.prototype.slice.call(n);var r=rn(n);delete r[Q];for(var t=nn(r),e=0;e<t.length;e++){var i=t[e],o=r[i];!1===o.writable&&(o.writable=!0,o.configurable=!0),(o.get||o.set)&&(r[i]={configurable:!0,writable:!0,enumerable:o.enumerable,value:n[i]});}return Object.create(Object.getPrototypeOf(n),r)}function d(n,e){return void 0===e&&(e=!1),y(n)||r(n)||!t(n)?n:(o(n)>1&&(n.set=n.add=n.clear=n.delete=h),Object.freeze(n),e&&i(n,(function(n,r){return d(r,!0)}),!0),n)}function h(){n(2);}function y(n){return null==n||"object"!=typeof n||Object.isFrozen(n)}function b(r){var t=tn[r];return t||n(18,r),t}function m(n,r){tn[n]||(tn[n]=r);}function _(){return U||n(0),U}function j(n,r){r&&(b("Patches"),n.u=[],n.s=[],n.v=r);}function O(n){g(n),n.p.forEach(S),n.p=null;}function g(n){n===U&&(U=n.l);}function w(n){return U={p:[],l:U,h:n,m:!0,_:0}}function S(n){var r=n[Q];0===r.i||1===r.i?r.j():r.O=!0;}function P(r,e){e._=e.p.length;var i=e.p[0],o=void 0!==r&&r!==i;return e.h.g||b("ES5").S(e,r,o),o?(i[Q].P&&(O(e),n(4)),t(r)&&(r=M(e,r),e.l||x(e,r)),e.u&&b("Patches").M(i[Q].t,r,e.u,e.s)):r=M(e,i,[]),O(e),e.u&&e.v(e.u,e.s),r!==H?r:void 0}function M(n,r,t){if(y(r))return r;var e=r[Q];if(!e)return i(r,(function(i,o){return A(n,e,r,i,o,t)}),!0),r;if(e.A!==n)return r;if(!e.P)return x(n,e.t,!0),e.t;if(!e.I){e.I=!0,e.A._--;var o=4===e.i||5===e.i?e.o=l(e.k):e.o;i(3===e.i?new Set(o):o,(function(r,i){return A(n,e,o,r,i,t)})),x(n,o,!1),t&&n.u&&b("Patches").R(e,t,n.u,n.s);}return e.o}function A(e,i,o,a,c,s){if(c===o&&n(5),r(c)){var v=M(e,c,s&&i&&3!==i.i&&!u(i.D,a)?s.concat(a):void 0);if(f(o,a,v),!r(v))return;e.m=!1;}if(t(c)&&!y(c)){if(!e.h.F&&e._<1)return;M(e,c),i&&i.A.l||x(e,c);}}function x(n,r,t){void 0===t&&(t=!1),n.h.F&&n.m&&d(r,t);}function z(n,r){var t=n[Q];return (t?p(t):n)[r]}function I(n,r){if(r in n)for(var t=Object.getPrototypeOf(n);t;){var e=Object.getOwnPropertyDescriptor(t,r);if(e)return e;t=Object.getPrototypeOf(t);}}function k(n){n.P||(n.P=!0,n.l&&k(n.l));}function E(n){n.o||(n.o=l(n.t));}function R(n,r,t){var e=s(r)?b("MapSet").N(r,t):v(r)?b("MapSet").T(r,t):n.g?function(n,r){var t=Array.isArray(n),e={i:t?1:0,A:r?r.A:_(),P:!1,I:!1,D:{},l:r,t:n,k:null,o:null,j:null,C:!1},i=e,o=en;t&&(i=[e],o=on);var u=Proxy.revocable(i,o),a=u.revoke,f=u.proxy;return e.k=f,e.j=a,f}(r,t):b("ES5").J(r,t);return (t?t.A:_()).p.push(e),e}function D(e){return r(e)||n(22,e),function n(r){if(!t(r))return r;var e,u=r[Q],c=o(r);if(u){if(!u.P&&(u.i<4||!b("ES5").K(u)))return u.t;u.I=!0,e=F(r,c),u.I=!1;}else e=F(r,c);return i(e,(function(r,t){u&&a(u.t,r)===t||f(e,r,n(t));})),3===c?new Set(e):e}(e)}function F(n,r){switch(r){case 2:return new Map(n);case 3:return Array.from(n)}return l(n)}function N(){function t(n,r){var t=s[n];return t?t.enumerable=r:s[n]=t={configurable:!0,enumerable:r,get:function(){var r=this[Q];return f(r),en.get(r,n)},set:function(r){var t=this[Q];f(t),en.set(t,n,r);}},t}function e(n){for(var r=n.length-1;r>=0;r--){var t=n[r][Q];if(!t.P)switch(t.i){case 5:a(t)&&k(t);break;case 4:o(t)&&k(t);}}}function o(n){for(var r=n.t,t=n.k,e=nn(t),i=e.length-1;i>=0;i--){var o=e[i];if(o!==Q){var a=r[o];if(void 0===a&&!u(r,o))return !0;var f=t[o],s=f&&f[Q];if(s?s.t!==a:!c(f,a))return !0}}var v=!!r[Q];return e.length!==nn(r).length+(v?0:1)}function a(n){var r=n.k;if(r.length!==n.t.length)return !0;var t=Object.getOwnPropertyDescriptor(r,r.length-1);if(t&&!t.get)return !0;for(var e=0;e<r.length;e++)if(!r.hasOwnProperty(e))return !0;return !1}function f(r){r.O&&n(3,JSON.stringify(p(r)));}var s={};m("ES5",{J:function(n,r){var e=Array.isArray(n),i=function(n,r){if(n){for(var e=Array(r.length),i=0;i<r.length;i++)Object.defineProperty(e,""+i,t(i,!0));return e}var o=rn(r);delete o[Q];for(var u=nn(o),a=0;a<u.length;a++){var f=u[a];o[f]=t(f,n||!!o[f].enumerable);}return Object.create(Object.getPrototypeOf(r),o)}(e,n),o={i:e?5:4,A:r?r.A:_(),P:!1,I:!1,D:{},l:r,t:n,k:i,o:null,O:!1,C:!1};return Object.defineProperty(i,Q,{value:o,writable:!0}),i},S:function(n,t,o){o?r(t)&&t[Q].A===n&&e(n.p):(n.u&&function n(r){if(r&&"object"==typeof r){var t=r[Q];if(t){var e=t.t,o=t.k,f=t.D,c=t.i;if(4===c)i(o,(function(r){r!==Q&&(void 0!==e[r]||u(e,r)?f[r]||n(o[r]):(f[r]=!0,k(t)));})),i(e,(function(n){void 0!==o[n]||u(o,n)||(f[n]=!1,k(t));}));else if(5===c){if(a(t)&&(k(t),f.length=!0),o.length<e.length)for(var s=o.length;s<e.length;s++)f[s]=!1;else for(var v=e.length;v<o.length;v++)f[v]=!0;for(var p=Math.min(o.length,e.length),l=0;l<p;l++)o.hasOwnProperty(l)||(f[l]=!0),void 0===f[l]&&n(o[l]);}}}}(n.p[0]),e(n.p));},K:function(n){return 4===n.i?o(n):a(n)}});}var G,U,W="undefined"!=typeof Symbol&&"symbol"==typeof Symbol("x"),X="undefined"!=typeof Map,q="undefined"!=typeof Set,B="undefined"!=typeof Proxy&&void 0!==Proxy.revocable&&"undefined"!=typeof Reflect,H=W?Symbol.for("immer-nothing"):((G={})["immer-nothing"]=!0,G),L=W?Symbol.for("immer-draftable"):"__$immer_draftable",Q=W?Symbol.for("immer-state"):"__$immer_state",Y={0:"Illegal state",1:"Immer drafts cannot have computed properties",2:"This object has been frozen and should not be mutated",3:function(n){return "Cannot use a proxy that has been revoked. Did you pass an object from inside an immer function to an async process? "+n},4:"An immer producer returned a new value *and* modified its draft. Either return a new value *or* modify the draft.",5:"Immer forbids circular references",6:"The first or second argument to `produce` must be a function",7:"The third argument to `produce` must be a function or undefined",8:"First argument to `createDraft` must be a plain object, an array, or an immerable object",9:"First argument to `finishDraft` must be a draft returned by `createDraft`",10:"The given draft is already finalized",11:"Object.defineProperty() cannot be used on an Immer draft",12:"Object.setPrototypeOf() cannot be used on an Immer draft",13:"Immer only supports deleting array indices",14:"Immer only supports setting array indices and the 'length' property",15:function(n){return "Cannot apply patch, path doesn't resolve: "+n},16:'Sets cannot have "replace" patches.',17:function(n){return "Unsupported patch operation: "+n},18:function(n){return "The plugin for '"+n+"' has not been loaded into Immer. To enable the plugin, import and call `enable"+n+"()` when initializing your application."},20:"Cannot use proxies if Proxy, Proxy.revocable or Reflect are not available",21:function(n){return "produce can only be called on things that are draftable: plain objects, arrays, Map, Set or classes that are marked with '[immerable]: true'. Got '"+n+"'"},22:function(n){return "'current' expects a draft, got: "+n},23:function(n){return "'original' expects a draft, got: "+n},24:"Patching reserved attributes like __proto__, prototype and constructor is not allowed"},Z=""+Object.prototype.constructor,nn="undefined"!=typeof Reflect&&Reflect.ownKeys?Reflect.ownKeys:void 0!==Object.getOwnPropertySymbols?function(n){return Object.getOwnPropertyNames(n).concat(Object.getOwnPropertySymbols(n))}:Object.getOwnPropertyNames,rn=Object.getOwnPropertyDescriptors||function(n){var r={};return nn(n).forEach((function(t){r[t]=Object.getOwnPropertyDescriptor(n,t);})),r},tn={},en={get:function(n,r){if(r===Q)return n;var e=p(n);if(!u(e,r))return function(n,r,t){var e,i=I(r,t);return i?"value"in i?i.value:null===(e=i.get)||void 0===e?void 0:e.call(n.k):void 0}(n,e,r);var i=e[r];return n.I||!t(i)?i:i===z(n.t,r)?(E(n),n.o[r]=R(n.A.h,i,n)):i},has:function(n,r){return r in p(n)},ownKeys:function(n){return Reflect.ownKeys(p(n))},set:function(n,r,t){var e=I(p(n),r);if(null==e?void 0:e.set)return e.set.call(n.k,t),!0;if(!n.P){var i=z(p(n),r),o=null==i?void 0:i[Q];if(o&&o.t===t)return n.o[r]=t,n.D[r]=!1,!0;if(c(t,i)&&(void 0!==t||u(n.t,r)))return !0;E(n),k(n);}return n.o[r]===t&&"number"!=typeof t&&(void 0!==t||r in n.o)||(n.o[r]=t,n.D[r]=!0,!0)},deleteProperty:function(n,r){return void 0!==z(n.t,r)||r in n.t?(n.D[r]=!1,E(n),k(n)):delete n.D[r],n.o&&delete n.o[r],!0},getOwnPropertyDescriptor:function(n,r){var t=p(n),e=Reflect.getOwnPropertyDescriptor(t,r);return e?{writable:!0,configurable:1!==n.i||"length"!==r,enumerable:e.enumerable,value:t[r]}:e},defineProperty:function(){n(11);},getPrototypeOf:function(n){return Object.getPrototypeOf(n.t)},setPrototypeOf:function(){n(12);}},on={};i(en,(function(n,r){on[n]=function(){return arguments[0]=arguments[0][0],r.apply(this,arguments)};})),on.deleteProperty=function(r,t){return isNaN(parseInt(t))&&n(13),on.set.call(this,r,t,void 0)},on.set=function(r,t,e){return "length"!==t&&isNaN(parseInt(t))&&n(14),en.set.call(this,r[0],t,e,r[0])};var un=function(){function e(r){var e=this;this.g=B,this.F=!0,this.produce=function(r,i,o){if("function"==typeof r&&"function"!=typeof i){var u=i;i=r;var a=e;return function(n){var r=this;void 0===n&&(n=u);for(var t=arguments.length,e=Array(t>1?t-1:0),o=1;o<t;o++)e[o-1]=arguments[o];return a.produce(n,(function(n){var t;return (t=i).call.apply(t,[r,n].concat(e))}))}}var f;if("function"!=typeof i&&n(6),void 0!==o&&"function"!=typeof o&&n(7),t(r)){var c=w(e),s=R(e,r,void 0),v=!0;try{f=i(s),v=!1;}finally{v?O(c):g(c);}return "undefined"!=typeof Promise&&f instanceof Promise?f.then((function(n){return j(c,o),P(n,c)}),(function(n){throw O(c),n})):(j(c,o),P(f,c))}if(!r||"object"!=typeof r){if(void 0===(f=i(r))&&(f=r),f===H&&(f=void 0),e.F&&d(f,!0),o){var p=[],l=[];b("Patches").M(r,f,p,l),o(p,l);}return f}n(21,r);},this.produceWithPatches=function(n,r){if("function"==typeof n)return function(r){for(var t=arguments.length,i=Array(t>1?t-1:0),o=1;o<t;o++)i[o-1]=arguments[o];return e.produceWithPatches(r,(function(r){return n.apply(void 0,[r].concat(i))}))};var t,i,o=e.produce(n,r,(function(n,r){t=n,i=r;}));return "undefined"!=typeof Promise&&o instanceof Promise?o.then((function(n){return [n,t,i]})):[o,t,i]},"boolean"==typeof(null==r?void 0:r.useProxies)&&this.setUseProxies(r.useProxies),"boolean"==typeof(null==r?void 0:r.autoFreeze)&&this.setAutoFreeze(r.autoFreeze);}var i=e.prototype;return i.createDraft=function(e){t(e)||n(8),r(e)&&(e=D(e));var i=w(this),o=R(this,e,void 0);return o[Q].C=!0,g(i),o},i.finishDraft=function(r,t){var e=r&&r[Q];(e&&e.C||n(9),e.I&&n(10));var i=e.A;return j(i,t),P(void 0,i)},i.setAutoFreeze=function(n){this.F=n;},i.setUseProxies=function(r){r&&!B&&n(20),this.g=r;},i.applyPatches=function(n,t){var e;for(e=t.length-1;e>=0;e--){var i=t[e];if(0===i.path.length&&"replace"===i.op){n=i.value;break}}e>-1&&(t=t.slice(e+1));var o=b("Patches").$;return r(n)?o(n,t):this.produce(n,(function(n){return o(n,t)}))},e}(),an=new un;an.produce;an.produceWithPatches.bind(an);an.setAutoFreeze.bind(an);an.setUseProxies.bind(an);an.applyPatches.bind(an);an.createDraft.bind(an);an.finishDraft.bind(an);
@@ -5945,7 +5999,7 @@
5945
5999
  }
5946
6000
  }
5947
6001
  StorageService.Constants = {
5948
- SUBSCRIBED: "subscribed"
6002
+ SUBSCRIBED: 'subscribed'
5949
6003
  };
5950
6004
 
5951
6005
  const CustomStorage = {
@@ -5953,10 +6007,10 @@
5953
6007
  return await StorageService.get(key);
5954
6008
  },
5955
6009
  setItem: async (key, value, ..._args) => {
5956
- return StorageService.set(key, value);
6010
+ return await StorageService.set(key, value);
5957
6011
  },
5958
6012
  removeItem: async (key, ..._args) => {
5959
- return StorageService.remove(key);
6013
+ return await StorageService.remove(key);
5960
6014
  }
5961
6015
  };
5962
6016
  const persistConfig = {
@@ -5985,9 +6039,6 @@
5985
6039
  const dispatch = useAppDispatch;
5986
6040
  const actions = {
5987
6041
  subscribe: async collectionName => {
5988
- var _await$StorageService;
5989
- const subscribedCollectionsString = (_await$StorageService = await StorageService.get(StorageService.Constants.SUBSCRIBED)) != null ? _await$StorageService : JSON.stringify([]);
5990
- var subscribedCollections = JSON.parse(subscribedCollectionsString);
5991
6042
  await (client == null ? void 0 : client.realtime.subscribe(collectionName, event => {
5992
6043
  switch (event.action) {
5993
6044
  case 'create':
@@ -6001,30 +6052,21 @@
6001
6052
  break;
6002
6053
  }
6003
6054
  }).then(() => {
6004
- if (!subscribedCollections.includes(collectionName)) {
6005
- subscribedCollections.push(collectionName);
6006
- }
6055
+ dispatch(addSubscription(collectionName));
6007
6056
  }).catch(_error => {
6008
- subscribedCollections = subscribedCollections.filter(collection => collection !== collectionName);
6057
+ dispatch(deleteSubscription$1(collectionName));
6009
6058
  }));
6010
- await StorageService.set(StorageService.Constants.SUBSCRIBED, JSON.stringify(subscribedCollections));
6011
6059
  },
6012
6060
  unsubscribe: async collectionName => {
6013
- var _await$StorageService2;
6014
- const subscribedCollectionsString = (_await$StorageService2 = await StorageService.get(StorageService.Constants.SUBSCRIBED)) != null ? _await$StorageService2 : JSON.stringify([]);
6015
- var subscribedCollections = JSON.parse(subscribedCollectionsString);
6016
6061
  if (collectionName) {
6017
6062
  await (client == null ? void 0 : client.realtime.unsubscribe(collectionName).then(() => {
6018
- subscribedCollections = subscribedCollections.filter(collection => collection !== collectionName);
6019
- }).catch(_error => {
6020
- subscribedCollections = subscribedCollections.filter(collection => collection !== collectionName);
6021
- }));
6063
+ dispatch(deleteSubscription$1(collectionName));
6064
+ }).catch(_error => {}));
6022
6065
  } else {
6023
6066
  await (client == null ? void 0 : client.realtime.unsubscribe().then(() => {
6024
- subscribedCollections = [];
6067
+ dispatch(setSubscriptions([]));
6025
6068
  }).catch(_error => {}));
6026
6069
  }
6027
- await StorageService.set(StorageService.Constants.SUBSCRIBED, JSON.stringify(subscribedCollections));
6028
6070
  },
6029
6071
  fetch: async collectionName => {
6030
6072
  const records = await (client == null ? void 0 : client.records.getFullList(collectionName, 200).catch(_error => {}));
@@ -6054,9 +6096,7 @@
6054
6096
  };
6055
6097
  }, [props.collections]);
6056
6098
  return /*#__PURE__*/react.createElement(ContentContext.Provider, {
6057
- value: {
6058
- actions
6059
- }
6099
+ value: actions
6060
6100
  }, props.children);
6061
6101
  };
6062
6102
 
@@ -6069,6 +6109,7 @@
6069
6109
 
6070
6110
  const AuthContext = react.createContext({});
6071
6111
  const AuthProvider = props => {
6112
+ var _client$authStore$mod;
6072
6113
  const client = useClientContext();
6073
6114
  const [authProviders, setAuthProviders] = react.useState();
6074
6115
  const actions = {
@@ -6127,7 +6168,11 @@
6127
6168
  })();
6128
6169
  }, [props.webRedirectUrl, props.mobileRedirectUrl]);
6129
6170
  return /*#__PURE__*/react.createElement(AuthContext.Provider, {
6130
- value: actions
6171
+ value: {
6172
+ actions: actions,
6173
+ isSignedIn: (client == null ? void 0 : client.authStore.isValid) || false,
6174
+ user: (_client$authStore$mod = client == null ? void 0 : client.authStore.model) != null ? _client$authStore$mod : null
6175
+ }
6131
6176
  }, props.children);
6132
6177
  };
6133
6178
 
@@ -6256,37 +6301,24 @@
6256
6301
  function useAppContent(collectionName, initialFetch = false) {
6257
6302
  var _store$useAppSelector;
6258
6303
  const records = (_store$useAppSelector = useAppSelector(state => state.reducer.records[collectionName])) != null ? _store$useAppSelector : [];
6304
+ const subscriptions = useAppSelector(state => state.reducer.subscriptions).subscriptions;
6259
6305
  const context = react.useContext(ContentContext);
6260
6306
  react.useEffect(() => {
6261
6307
  if (initialFetch) {
6262
- context.actions.fetch(collectionName);
6308
+ context.fetch(collectionName);
6263
6309
  }
6264
6310
  }, [collectionName, initialFetch]);
6265
6311
  const [isSubscribed, setIsSubscribed] = react.useState(false);
6266
- async function refetchSubscribeState() {
6267
- var _await$StorageService;
6268
- const subscribedCollectionsString = (_await$StorageService = await StorageService.get(StorageService.Constants.SUBSCRIBED)) != null ? _await$StorageService : JSON.stringify([]);
6269
- var subscribedCollections = JSON.parse(subscribedCollectionsString);
6270
- setIsSubscribed(subscribedCollections.includes(collectionName));
6271
- }
6272
6312
  react.useEffect(() => {
6273
- (async () => {
6274
- await refetchSubscribeState();
6275
- })();
6276
- }, []);
6313
+ setIsSubscribed(subscriptions.includes(collectionName));
6314
+ }, [subscriptions]);
6277
6315
  const actions = {
6278
- subscribe: async () => {
6279
- await context.actions.subscribe(collectionName);
6280
- await refetchSubscribeState();
6281
- },
6282
- unsubscribe: async () => {
6283
- context.actions.unsubscribe(collectionName);
6284
- await refetchSubscribeState();
6285
- },
6286
- fetch: async () => await context.actions.fetch(collectionName),
6287
- create: async record => await context.actions.create(collectionName, record),
6288
- update: async (id, record) => await context.actions.update(collectionName, id, record),
6289
- delete: async id => await context.actions.delete(collectionName, id)
6316
+ subscribe: async () => await context.subscribe(collectionName),
6317
+ unsubscribe: async () => await context.unsubscribe(collectionName),
6318
+ fetch: async () => await context.fetch(collectionName),
6319
+ create: async record => await context.create(collectionName, record),
6320
+ update: async (id, record) => await context.update(collectionName, id, record),
6321
+ delete: async id => await context.delete(collectionName, id)
6290
6322
  };
6291
6323
  return {
6292
6324
  records,
@@ -6296,14 +6328,12 @@
6296
6328
  }
6297
6329
 
6298
6330
  function useAuth() {
6299
- const actions = react.useContext(AuthContext);
6300
- return {
6301
- actions
6302
- };
6331
+ return react.useContext(AuthContext);
6303
6332
  }
6304
6333
 
6305
6334
  exports.ADD_RECORD = ADD_RECORD;
6306
6335
  exports.ADD_RECORDS = ADD_RECORDS;
6336
+ exports.ADD_SUBSCRIPTION = ADD_SUBSCRIPTION;
6307
6337
  exports.AuthContext = AuthContext;
6308
6338
  exports.AuthProvider = AuthProvider;
6309
6339
  exports.ClientContext = ClientContext;
@@ -6312,15 +6342,18 @@
6312
6342
  exports.ContentProvider = ContentProvider;
6313
6343
  exports.DELETE_RECORD = DELETE_RECORD;
6314
6344
  exports.DELETE_RECORDS = DELETE_RECORDS;
6345
+ exports.DELETE_SUBSCRIPTION = DELETE_SUBSCRIPTION;
6315
6346
  exports.Pocketbase = Pocketbase;
6316
6347
  exports.PocketbaseContext = PocketbaseContext;
6317
6348
  exports.SET_RECORDS = SET_RECORDS;
6349
+ exports.SET_SUBSCRIPTIONS = SET_SUBSCRIPTIONS;
6318
6350
  exports.UPDATE_RECORD = UPDATE_RECORD;
6319
6351
  exports.appReducer = appReducer;
6320
6352
  exports.persistConfig = persistConfig;
6321
6353
  exports.persistor = persistor;
6322
6354
  exports.recordsAction = records$1;
6323
6355
  exports.store = store;
6356
+ exports.subscriptionsAction = subscriptions$1;
6324
6357
  exports.useAppContent = useAppContent;
6325
6358
  exports.useAppDispatch = useAppDispatch;
6326
6359
  exports.useAppSelector = useAppSelector;