@raphiniert/ra-data-postgrest 2.0.0 → 2.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,224 +1,232 @@
1
- # Change Log
2
-
3
- Find all notable changes of this project in this file.
4
-
5
- ## v2.0.0 - 2023-12-29
6
- ### Improvements
7
- - updated dependencies
8
-
9
- ### Fixes
10
- - [#113](https://github.com/raphiniert-com/ra-data-postgrest/pull/113) remove {} value wrapping for cs/cd @[ruslantalpa](https://github.com/ruslantalpa)
11
-
12
- ### Breaking changes
13
- - the fix in this version might break old versions, as the {} are removed. Thus, one needs to manually add the {} for cs/cd.
14
-
15
-
16
- ## v2.0.0-alpha.4 - 2023-10-23
17
- ### Improvements
18
- - updated dependencies
19
-
20
- ### New feature
21
- - [#100](https://github.com/raphiniert-com/ra-data-postgrest/pull/100) support "meta.columns" on all code paths (useful when the user does not have permissions on all the columns in which case doing select=* gives permissions errors) - @[ruslantalpa](https://github.com/ruslantalpa)
22
-
23
- ### Fixes
24
- - [#50](https://github.com/raphiniert-com/ra-data-postgrest/issues/50) and [#88](https://github.com/raphiniert-com/ra-data-postgrest/issues/88) solved by [#100](https://github.com/raphiniert-com/ra-data-postgrest/pull/100) including other fixes - @[ruslantalpa](https://github.com/ruslantalpa)
25
-
26
-
27
- ## v2.0.0-alpha.3 - 2023-06-16
28
- ### Improvements
29
- - updated dependencies
30
-
31
- ### New feature
32
- - [#82](https://github.com/raphiniert-com/ra-data-postgrest/pull/82), add logical operator filter parsing - @[jordiyapz](https://github.com/jordiyapz)
33
-
34
- ### Fixes
35
- - [#81](https://github.com/raphiniert-com/ra-data-postgrest/pull/81), use {} with cs and cd operators url - @[YannBeauxis](https://github.com/YannBeauxis)
36
-
37
- ### Breaking changes
38
- - Changed from from regular parameters to instantiate the dataProvider to a configuration interface/class. Thus, in future initalize the dataProvider by creating a structure which implements the interface:
39
-
40
- ```jsx
41
- import { fetchUtils } from 'react-admin';
42
- import postgrestRestProvider,
43
- { IDataProviderConfig,
44
- defaultPrimaryKeys,
45
- defaultSchema } from '@raphiniert/ra-data-postgrest';
46
-
47
- const config: IDataProviderConfig = {
48
- apiUrl: 'http://path.to.my.api/',
49
- httpClient: fetchUtils.fetchJson,
50
- defaultListOp: 'eq',
51
- primaryKeys: defaultPrimaryKeys,
52
- schema: defaultSchema
53
- }
54
-
55
- dp = postgrestRestProvider(config);
56
- ```
57
-
58
- ## v2.0.0-alpha.2 - 2023-04-24
59
- ### Improvements
60
- - updated dependencies
61
-
62
- ### New feature
63
- - [#49](https://github.com/raphiniert-com/ra-data-postgrest/issues/49), custom schema name can be used
64
-
65
- ## v2.0.0-alpha.1 - 2023-04-09
66
- ### Improvements
67
- - updated dependencies
68
- - updated `urlBuilder` and integrated URL encoding
69
-
70
- ### New feature
71
- - [#48](https://github.com/raphiniert-com/ra-data-postgrest/issues/48) solved by pull request [#55](https://github.com/raphiniert-com/ra-data-postgrest/pull/55), the create method should return the data returned by postgrest and not the posted data - @[christiaanwesterbeek](https://github.com/christiaanwesterbeek)
72
- - [#39](https://github.com/raphiniert-com/ra-data-postgrest/pull/39), allow passing extra headers via meta for react-admin hooks - @[christiaanwesterbeek](https://github.com/christiaanwesterbeek)
73
- - [#41](https://github.com/raphiniert-com/ra-data-postgrest/pull/41), allow columns filtering for getList and getManyReference - @[christiaanwesterbeek](https://github.com/christiaanwesterbeek)
74
- - added support of [#41](https://github.com/raphiniert-com/ra-data-postgrest/pull/41) for other functions, but `create` and `updateMany`
75
- - [#38](https://github.com/raphiniert-com/ra-data-postgrest/pull/38), Let the sort param in getList be optional - @[christiaanwesterbeek](https://github.com/christiaanwesterbeek)
76
-
77
-
78
- ## v1.2.1 - 2023-04-07
79
- - small fix in condition
80
- - fixed package name
81
-
82
- ## v2.0.0-alpha.0 - 2022-11-23
83
-
84
- - [#42](https://github.com/raphiniert-com/ra-data-postgrest/issues/42), started adding some unit tests - @[christiaanwesterbeek](https://github.com/christiaanwesterbeek)
85
- - dropped authProvider
86
- - code cleanup & restructuring
87
- - minor bugfixes - @[christiaanwesterbeek](https://github.com/christiaanwesterbeek)
88
- - added some notes to README.md
89
-
90
- ### Breaking changes
91
-
92
- - dropped authProvider as this should rather be an own package in case of a generic piece of software or application specific.
93
-
94
- ## v1.2.0 - 2022-08-23
95
-
96
- - [#33](https://github.com/raphiniert-com/ra-data-postgrest/pull/33), adding dependabot - @[promitheus7](https://github.com/promitheus7)
97
- - [#30](https://github.com/raphiniert-com/ra-data-postgrest/pull/30) and [#33](https://github.com/raphiniert-com/ra-data-postgrest/pull/33), updated dependency to compatible starting from `ra-core` 4.1.x - @[corrideat](https://github.com/corrideat), @[promitheus7](https://github.com/promitheus7)
98
-
99
- ## v1.1.9 - 2022-08-23
100
-
101
- - [#30](https://github.com/raphiniert-com/ra-data-postgrest/pull/30), updated ts and modified code, such that some package dependencies became unrequired - @[corrideat](https://github.com/corrideat)
102
-
103
- ## v1.1.8 - 2022-01-07
104
-
105
- - required re-release as I missed to transpile all and upload the features of 1.1.7 to npm.
106
-
107
- ## v1.1.7 - 2022-01-07
108
-
109
- ### Fixes
110
-
111
- - fixed bad behaivor with compound keys while using field named `id` [issue #27](https://github.com/raphiniert-com/ra-data-postgrest/issues/27) and [issue #19](https://github.com/raphiniert-com/ra-data-postgrest/pull/19) - @[kenfehling](https://github.com/kenfehling)
112
-
113
- ### New feature
114
-
115
- - [#26](https://github.com/raphiniert-com/ra-data-postgrest/pull/26), added rpc filter support, which is explained [here](https://github.com/raphiniert-com/ra-data-postgrest#special-filter-feature-rpc-functions) - @[TheRealAstroboy](https://github.com/TheRealAstroboy)
116
-
117
- ## v1.1.6 - 2021-01-16
118
-
119
- ### Fixes
120
-
121
- - [#24](https://github.com/raphiniert-com/ra-data-postgrest/pull/24), fixed eq. prefix for non-compound keys [issue #23](https://github.com/raphiniert-com/ra-data-postgrest/issues/23) - @[andymed-jlp](https://github.com/andymed-jlp)
122
-
123
- ## v1.1.5 - 2021-01-16
124
-
125
- ### Fixes
126
-
127
- - fixed query string generation of rpc endpoints [issue #22](https://github.com/raphiniert-com/ra-data-postgrest/issues/22)
128
-
129
- ### Breaking changes
130
-
131
- - Support was dropped for generating the query string given many ids in case of an rpc endpoint. If your application has some psql functions which parse the standard input, I recommend to rework your db design. If this change causes strong damage to your application, please contact me in order to find a proper generic solution. Query strings of single rpc calls now drop the operator (`eq.`) and are generated properly.
132
-
133
- ## v1.1.4 - 2021-01-16
134
-
135
- - deployment error
136
-
137
- ## v1.1.3 - 2020-11-30
138
-
139
- ### Fixes
140
-
141
- - [#20](https://github.com/raphiniert-com/ra-data-postgrest/pull/20), fixed small bug in update - @[mkkane](https://github.com/mkkane)
142
- - removed console log
143
-
144
- ## v1.1.2 - 2020-10-05
145
-
146
- ### Fixes
147
-
148
- - fixed the last fix of getMany and getManyReferecnce for compound keys :)
149
-
150
- ## v1.1.1 - 2020-09-28
151
-
152
- ### Fixes
153
-
154
- - fixed getMany and getManyReferecnce for compound keys
155
-
156
- ## v1.1.0 - 2020-09-16
157
-
158
- ### Fixes
159
-
160
- - removed requirement to define order key in react admin, when using compound keys: default was `id`, now it's the compound key
161
-
162
- ### Breaking changes
163
-
164
- - refactored compound primary keys:
165
- For single custom keys wrap an array as follows:
166
- ```jsx
167
- const dataProvider = postgrestRestProvider(
168
- API_URL,
169
- fetchUtils.fetchJson,
170
- 'eq',
171
- new Map([
172
- ['some_table', ['custom_id']], // <- instead of ['some_table','custom_id']
173
- ['another_table', ['first_column', 'second_column']],
174
- ])
175
- );
176
- ```
177
-
178
- ## v1.0.7 - 2020-08-23
179
-
180
- ### New feature
181
-
182
- - [#14](https://github.com/raphiniert-com/ra-data-postgrest/pull/14), added compound primary keys (see [README.md](https://github.com/raphiniert-com/ra-data-postgrest/blob/master/README.md#compound-primary-keys)) - @[programmarchy](https://github.com/programmarchy)
183
-
184
- ### Maintenance
185
-
186
- - `import React from 'react';` -> `import * as React from 'react';`
187
- - Some minor code cleanup
188
-
189
- ## v1.0.6 - 2020-06-15
190
-
191
- ### Fixes
192
-
193
- - Fixed wrong support statement concerning [postgrest starter kit](https://github.com/subzerocloud/postgrest-starter-kit) in readme
194
-
195
- ## v1.0.5 - 2020-06-15
196
-
197
- ### Fixes
198
-
199
- - [#13](https://github.com/raphiniert-com/ra-data-postgrest/pull/13), Remove console.log - @[jpagex](https://github.com/jpagex)
200
- - [#12](https://github.com/raphiniert-com/ra-data-postgrest/pull/12), Fixed limit parameter - @[jpagex](https://github.com/jpagex)
201
-
202
- ## v1.0.4 - 2020-06-08
203
-
204
- ### Fixes
205
-
206
- - Fixed missing js files in npm package [#8](https://github.com/raphiniert-com/ra-data-postgrest/issues/8)
207
- - [#9](https://github.com/raphiniert-com/ra-data-postgrest/pull/9), Fixed typo in readme - @[seclace](https://github.com/seclace)
208
-
209
- ## v1.0.3 - 2020-05-17
210
-
211
- ### Fixes
212
-
213
- - Fixed bug when multidelete - @[colonist4096](https://github.com/colonist4096)
214
- - [#5](https://github.com/raphiniert-com/ra-data-postgrest/pull/6), Fixed bug while using multiple filters on the same attribute - @[olivierdalang](https://github.com/olivierdalang)
215
-
216
- ## v1.0.2 - 2020-03-10
217
-
218
- ### Fixes
219
-
220
- - [#4](https://github.com/raphiniert-com/ra-data-postgrest/pull/4), Fixed bug while using ReferenceField with UUID - @[xero88](https://github.com/xero88)
221
-
222
- ## v1.0.1 - 2020-02-01
223
-
224
- - initial release
1
+ # Change Log
2
+
3
+ Find all notable changes of this project in this file.
4
+
5
+ ## v2.1.0 - 2024-02-27
6
+ ### Improvements
7
+ - updated dependencies
8
+
9
+ ### Fixes
10
+ - [#123](https://github.com/raphiniert-com/ra-data-postgrest/pull/123) Modifying update call to only update changed fields @[kav](https://github.com/kav)
11
+
12
+
13
+ ## v2.0.0 - 2023-12-29
14
+ ### Improvements
15
+ - updated dependencies
16
+
17
+ ### Fixes
18
+ - [#113](https://github.com/raphiniert-com/ra-data-postgrest/pull/113) remove {} value wrapping for cs/cd @[ruslantalpa](https://github.com/ruslantalpa)
19
+
20
+ ### Breaking changes
21
+ - the fix in this version might break old versions, as the {} are removed. Thus, one needs to manually add the {} for cs/cd.
22
+
23
+
24
+ ## v2.0.0-alpha.4 - 2023-10-23
25
+ ### Improvements
26
+ - updated dependencies
27
+
28
+ ### New feature
29
+ - [#100](https://github.com/raphiniert-com/ra-data-postgrest/pull/100) support "meta.columns" on all code paths (useful when the user does not have permissions on all the columns in which case doing select=* gives permissions errors) - @[ruslantalpa](https://github.com/ruslantalpa)
30
+
31
+ ### Fixes
32
+ - [#50](https://github.com/raphiniert-com/ra-data-postgrest/issues/50) and [#88](https://github.com/raphiniert-com/ra-data-postgrest/issues/88) solved by [#100](https://github.com/raphiniert-com/ra-data-postgrest/pull/100) including other fixes - @[ruslantalpa](https://github.com/ruslantalpa)
33
+
34
+
35
+ ## v2.0.0-alpha.3 - 2023-06-16
36
+ ### Improvements
37
+ - updated dependencies
38
+
39
+ ### New feature
40
+ - [#82](https://github.com/raphiniert-com/ra-data-postgrest/pull/82), add logical operator filter parsing - @[jordiyapz](https://github.com/jordiyapz)
41
+
42
+ ### Fixes
43
+ - [#81](https://github.com/raphiniert-com/ra-data-postgrest/pull/81), use {} with cs and cd operators url - @[YannBeauxis](https://github.com/YannBeauxis)
44
+
45
+ ### Breaking changes
46
+ - Changed from from regular parameters to instantiate the dataProvider to a configuration interface/class. Thus, in future initalize the dataProvider by creating a structure which implements the interface:
47
+
48
+ ```jsx
49
+ import { fetchUtils } from 'react-admin';
50
+ import postgrestRestProvider,
51
+ { IDataProviderConfig,
52
+ defaultPrimaryKeys,
53
+ defaultSchema } from '@raphiniert/ra-data-postgrest';
54
+
55
+ const config: IDataProviderConfig = {
56
+ apiUrl: 'http://path.to.my.api/',
57
+ httpClient: fetchUtils.fetchJson,
58
+ defaultListOp: 'eq',
59
+ primaryKeys: defaultPrimaryKeys,
60
+ schema: defaultSchema
61
+ }
62
+
63
+ dp = postgrestRestProvider(config);
64
+ ```
65
+
66
+ ## v2.0.0-alpha.2 - 2023-04-24
67
+ ### Improvements
68
+ - updated dependencies
69
+
70
+ ### New feature
71
+ - [#49](https://github.com/raphiniert-com/ra-data-postgrest/issues/49), custom schema name can be used
72
+
73
+ ## v2.0.0-alpha.1 - 2023-04-09
74
+ ### Improvements
75
+ - updated dependencies
76
+ - updated `urlBuilder` and integrated URL encoding
77
+
78
+ ### New feature
79
+ - [#48](https://github.com/raphiniert-com/ra-data-postgrest/issues/48) solved by pull request [#55](https://github.com/raphiniert-com/ra-data-postgrest/pull/55), the create method should return the data returned by postgrest and not the posted data - @[christiaanwesterbeek](https://github.com/christiaanwesterbeek)
80
+ - [#39](https://github.com/raphiniert-com/ra-data-postgrest/pull/39), allow passing extra headers via meta for react-admin hooks - @[christiaanwesterbeek](https://github.com/christiaanwesterbeek)
81
+ - [#41](https://github.com/raphiniert-com/ra-data-postgrest/pull/41), allow columns filtering for getList and getManyReference - @[christiaanwesterbeek](https://github.com/christiaanwesterbeek)
82
+ - added support of [#41](https://github.com/raphiniert-com/ra-data-postgrest/pull/41) for other functions, but `create` and `updateMany`
83
+ - [#38](https://github.com/raphiniert-com/ra-data-postgrest/pull/38), Let the sort param in getList be optional - @[christiaanwesterbeek](https://github.com/christiaanwesterbeek)
84
+
85
+
86
+ ## v1.2.1 - 2023-04-07
87
+ - small fix in condition
88
+ - fixed package name
89
+
90
+ ## v2.0.0-alpha.0 - 2022-11-23
91
+
92
+ - [#42](https://github.com/raphiniert-com/ra-data-postgrest/issues/42), started adding some unit tests - @[christiaanwesterbeek](https://github.com/christiaanwesterbeek)
93
+ - dropped authProvider
94
+ - code cleanup & restructuring
95
+ - minor bugfixes - @[christiaanwesterbeek](https://github.com/christiaanwesterbeek)
96
+ - added some notes to README.md
97
+
98
+ ### Breaking changes
99
+
100
+ - dropped authProvider as this should rather be an own package in case of a generic piece of software or application specific.
101
+
102
+ ## v1.2.0 - 2022-08-23
103
+
104
+ - [#33](https://github.com/raphiniert-com/ra-data-postgrest/pull/33), adding dependabot - @[promitheus7](https://github.com/promitheus7)
105
+ - [#30](https://github.com/raphiniert-com/ra-data-postgrest/pull/30) and [#33](https://github.com/raphiniert-com/ra-data-postgrest/pull/33), updated dependency to compatible starting from `ra-core` 4.1.x - @[corrideat](https://github.com/corrideat), @[promitheus7](https://github.com/promitheus7)
106
+
107
+ ## v1.1.9 - 2022-08-23
108
+
109
+ - [#30](https://github.com/raphiniert-com/ra-data-postgrest/pull/30), updated ts and modified code, such that some package dependencies became unrequired - @[corrideat](https://github.com/corrideat)
110
+
111
+ ## v1.1.8 - 2022-01-07
112
+
113
+ - required re-release as I missed to transpile all and upload the features of 1.1.7 to npm.
114
+
115
+ ## v1.1.7 - 2022-01-07
116
+
117
+ ### Fixes
118
+
119
+ - fixed bad behaivor with compound keys while using field named `id` [issue #27](https://github.com/raphiniert-com/ra-data-postgrest/issues/27) and [issue #19](https://github.com/raphiniert-com/ra-data-postgrest/pull/19) - @[kenfehling](https://github.com/kenfehling)
120
+
121
+ ### New feature
122
+
123
+ - [#26](https://github.com/raphiniert-com/ra-data-postgrest/pull/26), added rpc filter support, which is explained [here](https://github.com/raphiniert-com/ra-data-postgrest#special-filter-feature-rpc-functions) - @[TheRealAstroboy](https://github.com/TheRealAstroboy)
124
+
125
+ ## v1.1.6 - 2021-01-16
126
+
127
+ ### Fixes
128
+
129
+ - [#24](https://github.com/raphiniert-com/ra-data-postgrest/pull/24), fixed eq. prefix for non-compound keys [issue #23](https://github.com/raphiniert-com/ra-data-postgrest/issues/23) - @[andymed-jlp](https://github.com/andymed-jlp)
130
+
131
+ ## v1.1.5 - 2021-01-16
132
+
133
+ ### Fixes
134
+
135
+ - fixed query string generation of rpc endpoints [issue #22](https://github.com/raphiniert-com/ra-data-postgrest/issues/22)
136
+
137
+ ### Breaking changes
138
+
139
+ - Support was dropped for generating the query string given many ids in case of an rpc endpoint. If your application has some psql functions which parse the standard input, I recommend to rework your db design. If this change causes strong damage to your application, please contact me in order to find a proper generic solution. Query strings of single rpc calls now drop the operator (`eq.`) and are generated properly.
140
+
141
+ ## v1.1.4 - 2021-01-16
142
+
143
+ - deployment error
144
+
145
+ ## v1.1.3 - 2020-11-30
146
+
147
+ ### Fixes
148
+
149
+ - [#20](https://github.com/raphiniert-com/ra-data-postgrest/pull/20), fixed small bug in update - @[mkkane](https://github.com/mkkane)
150
+ - removed console log
151
+
152
+ ## v1.1.2 - 2020-10-05
153
+
154
+ ### Fixes
155
+
156
+ - fixed the last fix of getMany and getManyReferecnce for compound keys :)
157
+
158
+ ## v1.1.1 - 2020-09-28
159
+
160
+ ### Fixes
161
+
162
+ - fixed getMany and getManyReferecnce for compound keys
163
+
164
+ ## v1.1.0 - 2020-09-16
165
+
166
+ ### Fixes
167
+
168
+ - removed requirement to define order key in react admin, when using compound keys: default was `id`, now it's the compound key
169
+
170
+ ### Breaking changes
171
+
172
+ - refactored compound primary keys:
173
+ For single custom keys wrap an array as follows:
174
+ ```jsx
175
+ const dataProvider = postgrestRestProvider(
176
+ API_URL,
177
+ fetchUtils.fetchJson,
178
+ 'eq',
179
+ new Map([
180
+ ['some_table', ['custom_id']], // <- instead of ['some_table','custom_id']
181
+ ['another_table', ['first_column', 'second_column']],
182
+ ])
183
+ );
184
+ ```
185
+
186
+ ## v1.0.7 - 2020-08-23
187
+
188
+ ### New feature
189
+
190
+ - [#14](https://github.com/raphiniert-com/ra-data-postgrest/pull/14), added compound primary keys (see [README.md](https://github.com/raphiniert-com/ra-data-postgrest/blob/master/README.md#compound-primary-keys)) - @[programmarchy](https://github.com/programmarchy)
191
+
192
+ ### Maintenance
193
+
194
+ - `import React from 'react';` -> `import * as React from 'react';`
195
+ - Some minor code cleanup
196
+
197
+ ## v1.0.6 - 2020-06-15
198
+
199
+ ### Fixes
200
+
201
+ - Fixed wrong support statement concerning [postgrest starter kit](https://github.com/subzerocloud/postgrest-starter-kit) in readme
202
+
203
+ ## v1.0.5 - 2020-06-15
204
+
205
+ ### Fixes
206
+
207
+ - [#13](https://github.com/raphiniert-com/ra-data-postgrest/pull/13), Remove console.log - @[jpagex](https://github.com/jpagex)
208
+ - [#12](https://github.com/raphiniert-com/ra-data-postgrest/pull/12), Fixed limit parameter - @[jpagex](https://github.com/jpagex)
209
+
210
+ ## v1.0.4 - 2020-06-08
211
+
212
+ ### Fixes
213
+
214
+ - Fixed missing js files in npm package [#8](https://github.com/raphiniert-com/ra-data-postgrest/issues/8)
215
+ - [#9](https://github.com/raphiniert-com/ra-data-postgrest/pull/9), Fixed typo in readme - @[seclace](https://github.com/seclace)
216
+
217
+ ## v1.0.3 - 2020-05-17
218
+
219
+ ### Fixes
220
+
221
+ - Fixed bug when multidelete - @[colonist4096](https://github.com/colonist4096)
222
+ - [#5](https://github.com/raphiniert-com/ra-data-postgrest/pull/6), Fixed bug while using multiple filters on the same attribute - @[olivierdalang](https://github.com/olivierdalang)
223
+
224
+ ## v1.0.2 - 2020-03-10
225
+
226
+ ### Fixes
227
+
228
+ - [#4](https://github.com/raphiniert-com/ra-data-postgrest/pull/4), Fixed bug while using ReferenceField with UUID - @[xero88](https://github.com/xero88)
229
+
230
+ ## v1.0.1 - 2020-02-01
231
+
232
+ - initial release
package/README.md CHANGED
@@ -172,7 +172,7 @@ PostgREST allows to [select and switch the database schema](https://postgrest.or
172
172
  ```jsx
173
173
  const config: IDataProviderConfig = {
174
174
  ...
175
- schema: localStorage.getItem("schema") || "api",
175
+ schema: () => localStorage.getItem("schema") || "api",
176
176
  ...
177
177
  }
178
178
 
package/esm/index.js CHANGED
@@ -11,6 +11,7 @@ var __assign = (this && this.__assign) || function () {
11
11
  };
12
12
  import { getPrimaryKey, parseFilters, getOrderBy, dataWithVirtualId, dataWithoutVirtualId, removePrimaryKey, getQuery, encodeId, } from './urlBuilder';
13
13
  import qs from 'qs';
14
+ import isEqual from 'lodash/isEqual';
14
15
  export var defaultPrimaryKeys = new Map();
15
16
  export var defaultSchema = function () { return ''; };
16
17
  var useCustomSchema = function (schema, metaSchema, method) {
@@ -58,7 +59,7 @@ export default (function (config) { return ({
58
59
  return config.httpClient(url, options).then(function (_a) {
59
60
  var headers = _a.headers, json = _a.json;
60
61
  if (!headers.has('content-range')) {
61
- throw new Error("The Content-Range header is missing in the HTTP Response. The postgREST data provider expects \n responses for lists of resources to contain this header with the total number of results to build \n the pagination. If you are using CORS, did you declare Content-Range in the Access-Control-Expose-Headers header?");
62
+ throw new Error("The Content-Range header is missing in the HTTP Response. The postgREST data provider expects\n responses for lists of resources to contain this header with the total number of results to build\n the pagination. If you are using CORS, did you declare Content-Range in the Access-Control-Expose-Headers header?");
62
63
  }
63
64
  return {
64
65
  data: json.map(function (obj) { return dataWithVirtualId(obj, primaryKey); }),
@@ -126,7 +127,7 @@ export default (function (config) { return ({
126
127
  return config.httpClient(url, options).then(function (_a) {
127
128
  var headers = _a.headers, json = _a.json;
128
129
  if (!headers.has('content-range')) {
129
- throw new Error("The Content-Range header is missing in the HTTP Response. The postgREST data provider expects \n responses for lists of resources to contain this header with the total number of results to build \n the pagination. If you are using CORS, did you declare Content-Range in the Access-Control-Expose-Headers header?");
130
+ throw new Error("The Content-Range header is missing in the HTTP Response. The postgREST data provider expects\n responses for lists of resources to contain this header with the total number of results to build\n the pagination. If you are using CORS, did you declare Content-Range in the Access-Control-Expose-Headers header?");
130
131
  }
131
132
  return {
132
133
  data: json.map(function (data) { return dataWithVirtualId(data, primaryKey); }),
@@ -137,12 +138,13 @@ export default (function (config) { return ({
137
138
  update: function (resource, params) {
138
139
  var _a, _b;
139
140
  if (params === void 0) { params = {}; }
140
- var id = params.id, data = params.data, meta = params.meta;
141
+ var id = params.id, data = params.data, meta = params.meta, previousData = params.previousData;
141
142
  var primaryKey = getPrimaryKey(resource, config.primaryKeys);
142
143
  var query = getQuery(primaryKey, id, resource, meta);
143
144
  var url = "".concat(config.apiUrl, "/").concat(resource, "?").concat(qs.stringify(query));
145
+ var changedData = getChanges(data, previousData);
144
146
  var metaSchema = (_a = params.meta) === null || _a === void 0 ? void 0 : _a.schema;
145
- var body = JSON.stringify(__assign({}, dataWithoutVirtualId(removePrimaryKey(data, primaryKey), primaryKey)));
147
+ var body = JSON.stringify(__assign({}, dataWithoutVirtualId(removePrimaryKey(changedData, primaryKey), primaryKey)));
146
148
  return config
147
149
  .httpClient(url, {
148
150
  method: 'PATCH',
@@ -241,3 +243,12 @@ export default (function (config) { return ({
241
243
  });
242
244
  },
243
245
  }); });
246
+ var getChanges = function (data, previousData) {
247
+ var changes = Object.keys(data).reduce(function (changes, key) {
248
+ if (!isEqual(data[key], previousData[key])) {
249
+ changes[key] = data[key];
250
+ }
251
+ return changes;
252
+ }, {});
253
+ return changes;
254
+ };
package/lib/index.js CHANGED
@@ -17,6 +17,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
17
17
  exports.defaultSchema = exports.defaultPrimaryKeys = void 0;
18
18
  var urlBuilder_1 = require("./urlBuilder");
19
19
  var qs_1 = __importDefault(require("qs"));
20
+ var isEqual_1 = __importDefault(require("lodash/isEqual"));
20
21
  exports.defaultPrimaryKeys = new Map();
21
22
  var defaultSchema = function () { return ''; };
22
23
  exports.defaultSchema = defaultSchema;
@@ -65,7 +66,7 @@ exports.default = (function (config) { return ({
65
66
  return config.httpClient(url, options).then(function (_a) {
66
67
  var headers = _a.headers, json = _a.json;
67
68
  if (!headers.has('content-range')) {
68
- throw new Error("The Content-Range header is missing in the HTTP Response. The postgREST data provider expects \n responses for lists of resources to contain this header with the total number of results to build \n the pagination. If you are using CORS, did you declare Content-Range in the Access-Control-Expose-Headers header?");
69
+ throw new Error("The Content-Range header is missing in the HTTP Response. The postgREST data provider expects\n responses for lists of resources to contain this header with the total number of results to build\n the pagination. If you are using CORS, did you declare Content-Range in the Access-Control-Expose-Headers header?");
69
70
  }
70
71
  return {
71
72
  data: json.map(function (obj) { return (0, urlBuilder_1.dataWithVirtualId)(obj, primaryKey); }),
@@ -133,7 +134,7 @@ exports.default = (function (config) { return ({
133
134
  return config.httpClient(url, options).then(function (_a) {
134
135
  var headers = _a.headers, json = _a.json;
135
136
  if (!headers.has('content-range')) {
136
- throw new Error("The Content-Range header is missing in the HTTP Response. The postgREST data provider expects \n responses for lists of resources to contain this header with the total number of results to build \n the pagination. If you are using CORS, did you declare Content-Range in the Access-Control-Expose-Headers header?");
137
+ throw new Error("The Content-Range header is missing in the HTTP Response. The postgREST data provider expects\n responses for lists of resources to contain this header with the total number of results to build\n the pagination. If you are using CORS, did you declare Content-Range in the Access-Control-Expose-Headers header?");
137
138
  }
138
139
  return {
139
140
  data: json.map(function (data) { return (0, urlBuilder_1.dataWithVirtualId)(data, primaryKey); }),
@@ -144,12 +145,13 @@ exports.default = (function (config) { return ({
144
145
  update: function (resource, params) {
145
146
  var _a, _b;
146
147
  if (params === void 0) { params = {}; }
147
- var id = params.id, data = params.data, meta = params.meta;
148
+ var id = params.id, data = params.data, meta = params.meta, previousData = params.previousData;
148
149
  var primaryKey = (0, urlBuilder_1.getPrimaryKey)(resource, config.primaryKeys);
149
150
  var query = (0, urlBuilder_1.getQuery)(primaryKey, id, resource, meta);
150
151
  var url = "".concat(config.apiUrl, "/").concat(resource, "?").concat(qs_1.default.stringify(query));
152
+ var changedData = getChanges(data, previousData);
151
153
  var metaSchema = (_a = params.meta) === null || _a === void 0 ? void 0 : _a.schema;
152
- var body = JSON.stringify(__assign({}, (0, urlBuilder_1.dataWithoutVirtualId)((0, urlBuilder_1.removePrimaryKey)(data, primaryKey), primaryKey)));
154
+ var body = JSON.stringify(__assign({}, (0, urlBuilder_1.dataWithoutVirtualId)((0, urlBuilder_1.removePrimaryKey)(changedData, primaryKey), primaryKey)));
153
155
  return config
154
156
  .httpClient(url, {
155
157
  method: 'PATCH',
@@ -248,3 +250,12 @@ exports.default = (function (config) { return ({
248
250
  });
249
251
  },
250
252
  }); });
253
+ var getChanges = function (data, previousData) {
254
+ var changes = Object.keys(data).reduce(function (changes, key) {
255
+ if (!(0, isEqual_1.default)(data[key], previousData[key])) {
256
+ changes[key] = data[key];
257
+ }
258
+ return changes;
259
+ }, {});
260
+ return changes;
261
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@raphiniert/ra-data-postgrest",
3
- "version": "2.0.0",
3
+ "version": "2.1.0",
4
4
  "description": "postgREST data provider for react-admin",
5
5
  "main": "lib/index.js",
6
6
  "module": "esm/index.js",
@@ -45,6 +45,7 @@
45
45
  "ra-core": "^4.1.0"
46
46
  },
47
47
  "dependencies": {
48
+ "lodash.isequal": "^4.5.0",
48
49
  "qs": "^6.11.1"
49
50
  }
50
51
  }
package/src/index.ts CHANGED
@@ -23,6 +23,7 @@ import {
23
23
  encodeId,
24
24
  } from './urlBuilder';
25
25
  import qs from 'qs';
26
+ import isEqual from 'lodash/isEqual';
26
27
 
27
28
  /**
28
29
  * Maps react-admin queries to a postgrest REST API
@@ -146,8 +147,8 @@ export default (config: IDataProviderConfig): DataProvider => ({
146
147
  return config.httpClient(url, options).then(({ headers, json }) => {
147
148
  if (!headers.has('content-range')) {
148
149
  throw new Error(
149
- `The Content-Range header is missing in the HTTP Response. The postgREST data provider expects
150
- responses for lists of resources to contain this header with the total number of results to build
150
+ `The Content-Range header is missing in the HTTP Response. The postgREST data provider expects
151
+ responses for lists of resources to contain this header with the total number of results to build
151
152
  the pagination. If you are using CORS, did you declare Content-Range in the Access-Control-Expose-Headers header?`
152
153
  );
153
154
  }
@@ -249,8 +250,8 @@ export default (config: IDataProviderConfig): DataProvider => ({
249
250
  return config.httpClient(url, options).then(({ headers, json }) => {
250
251
  if (!headers.has('content-range')) {
251
252
  throw new Error(
252
- `The Content-Range header is missing in the HTTP Response. The postgREST data provider expects
253
- responses for lists of resources to contain this header with the total number of results to build
253
+ `The Content-Range header is missing in the HTTP Response. The postgREST data provider expects
254
+ responses for lists of resources to contain this header with the total number of results to build
254
255
  the pagination. If you are using CORS, did you declare Content-Range in the Access-Control-Expose-Headers header?`
255
256
  );
256
257
  }
@@ -265,15 +266,16 @@ export default (config: IDataProviderConfig): DataProvider => ({
265
266
  },
266
267
 
267
268
  update: (resource, params: Partial<UpdateParams> = {}) => {
268
- const { id, data, meta } = params;
269
+ const { id, data, meta, previousData } = params;
269
270
  const primaryKey = getPrimaryKey(resource, config.primaryKeys);
270
271
  const query = getQuery(primaryKey, id, resource, meta);
271
272
  const url = `${config.apiUrl}/${resource}?${qs.stringify(query)}`;
273
+ const changedData = getChanges(data, previousData);
272
274
  const metaSchema = params.meta?.schema;
273
275
 
274
276
  const body = JSON.stringify({
275
277
  ...dataWithoutVirtualId(
276
- removePrimaryKey(data, primaryKey),
278
+ removePrimaryKey(changedData, primaryKey),
277
279
  primaryKey
278
280
  ),
279
281
  });
@@ -406,3 +408,13 @@ export default (config: IDataProviderConfig): DataProvider => ({
406
408
  }));
407
409
  },
408
410
  });
411
+
412
+ const getChanges = (data: any, previousData: any) => {
413
+ const changes = Object.keys(data).reduce((changes, key) => {
414
+ if (!isEqual(data[key], previousData[key])) {
415
+ changes[key] = data[key];
416
+ }
417
+ return changes;
418
+ }, {});
419
+ return changes;
420
+ };