@raphiniert/ra-data-postgrest 1.1.4 → 1.1.8

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
@@ -2,12 +2,30 @@
2
2
 
3
3
  Find all notable changes of this project in this file.
4
4
 
5
- ## v1.1.4 - 2021-01-16
6
- ### fixed
5
+ ## v1.1.8 - 2022-01-07
6
+ - required re-release as I missed to transpile all and upload the features of 1.1.7 to npm.
7
+
8
+ ## v1.1.7 - 2022-01-07
9
+ ### Fixes
10
+ - 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)
11
+
12
+ ### New feature
13
+ - 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)
14
+
15
+
16
+ ## v1.1.6 - 2021-01-16
17
+ ### Fixes
18
+ - 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)
19
+
20
+ ## v1.1.5 - 2021-01-16
21
+ ### Fixes
7
22
  - fixed query string generation of rpc endpoints [issue #22](https://github.com/raphiniert-com/ra-data-postgrest/issues/22)
8
23
 
9
24
  ### Breaking changes
10
- - 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. Query strings of single rpc calls now drop the operator (`eq.`) and are generated properly.
25
+ - 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.
26
+
27
+ ## v1.1.4 - 2021-01-16
28
+ - deployment error
11
29
 
12
30
  ## v1.1.3 - 2020-11-30
13
31
  ### Fixes
package/README.md CHANGED
@@ -135,6 +135,19 @@ The dataProvider is designed to enable you to specify the comparator in your rea
135
135
 
136
136
  One can simply append the comparator with an `@` to the source. In this example the field `post_title` would be filtered with `ilike` whereas `post_author` would be filtered using `eq` which is the default if no special comparator is specified.
137
137
 
138
+ ### Special Filter Feature (RPC Functions)
139
+ The dataProvider is designed to enable you to use Get RPC functions:
140
+
141
+ ```GET /rpc/add_them?post_author=Herbert HTTP/1.1```
142
+ The function parameter names match the query parameters ```&post_author=Herbert``` if you end the field with an `@` (neither default comparator nor special comparator)
143
+
144
+ ```jsx
145
+ <Filter {...props}>
146
+ <TextInput label="Search" source="post_title" alwaysOn />
147
+ <TextInput label="Search" source="post_author@" alwaysOn />
148
+ // some more filters
149
+ </Filter>
150
+ ```
138
151
 
139
152
  ### Compound primary keys
140
153
  If one has data resources without primary keys named `id`, one will have to define this specifically. Also, if there is a primary key, which is defined over multiple columns:
@@ -1,3 +1,9 @@
1
+ import { fetchUtils, DataProvider } from 'ra-core';
1
2
  declare type PrimaryKey = Array<string>;
2
- declare const _default: (apiUrl: any, httpClient?: any, defaultListOp?: string, primaryKeys?: Map<string, PrimaryKey>) => any;
3
+ declare const _default: (apiUrl: any, httpClient?: (url: any, options?: fetchUtils.Options) => Promise<{
4
+ status: number;
5
+ headers: Headers;
6
+ body: string;
7
+ json: any;
8
+ }>, defaultListOp?: string, primaryKeys?: Map<string, PrimaryKey>) => DataProvider;
3
9
  export default _default;
@@ -72,7 +72,8 @@ function parseFilters(filter, defaultListOp) {
72
72
  values = [filter[key]];
73
73
  }
74
74
  values.forEach(function (value) {
75
- var op = operation.includes('like') ? operation + ".*" + value + "*" : operation + "." + value;
75
+ // if operator is intentionally blank, rpc syntax
76
+ var op = operation.includes('like') ? operation + ".*" + value + "*" : operation.length == 0 ? "" + value : operation + "." + value;
76
77
  if (result[splitKey[0]] === undefined) {
77
78
  // first operator for the key, we add it to the dict
78
79
  result[splitKey[0]] = op;
@@ -111,7 +112,7 @@ var encodeId = function (data, primaryKey) {
111
112
  }
112
113
  };
113
114
  var dataWithId = function (data, primaryKey) {
114
- if (primaryKey === ['id'] || (data && data.id)) {
115
+ if (primaryKey === ['id']) {
115
116
  return data;
116
117
  }
117
118
  return Object.assign(data, {
@@ -150,7 +151,7 @@ var getQuery = function (primaryKey, ids, resource) {
150
151
  return "and=(" + primaryKey.map(function (key, i) { return key + ".eq." + primaryKeyParams_1[i]; }).join(',') + ")";
151
152
  }
152
153
  else {
153
- return stringify((_b = {}, _b[primaryKey[0]] = "" + id, _b));
154
+ return stringify((_b = {}, _b[primaryKey[0]] = "eq." + id, _b));
154
155
  }
155
156
  }
156
157
  };
@@ -238,7 +239,7 @@ export default (function (apiUrl, httpClient, defaultListOp, primaryKeys) {
238
239
  var _c = params.sort, field = _c.field, order = _c.order;
239
240
  var parsedFilter = parseFilters(params.filter, defaultListOp);
240
241
  var primaryKey = getPrimaryKey(resource, primaryKeys);
241
- var query = __assign((_a = {}, _a[params.target] = "eq." + params.id, _a.order = getOrderBy(field, order, primaryKey), _a.offset = (page - 1) * perPage, _a.limit = perPage, _a), parsedFilter);
242
+ var query = params.target ? __assign((_a = {}, _a[params.target] = "eq." + params.id, _a.order = getOrderBy(field, order, primaryKey), _a.offset = (page - 1) * perPage, _a.limit = perPage, _a), parsedFilter) : __assign({ order: getOrderBy(field, order, primaryKey), offset: (page - 1) * perPage, limit: perPage }, parsedFilter);
242
243
  // add header that Content-Range is in returned header
243
244
  var options = {
244
245
  headers: new Headers({
@@ -47,7 +47,7 @@ exports.default = {
47
47
  checkError: function (error) {
48
48
  var status = error.status;
49
49
  if (status === 401 || status === 403) {
50
- localStorage.removeItem('token');
50
+ localStorage.removeItem('me');
51
51
  return Promise.reject();
52
52
  }
53
53
  return Promise.resolve();
@@ -1,8 +1,9 @@
1
1
  import { fetchUtils, DataProvider } from 'ra-core';
2
+ declare type PrimaryKey = Array<string>;
2
3
  declare const _default: (apiUrl: any, httpClient?: (url: any, options?: fetchUtils.Options) => Promise<{
3
4
  status: number;
4
5
  headers: Headers;
5
6
  body: string;
6
7
  json: any;
7
- }>, defaultListOp?: string) => DataProvider;
8
+ }>, defaultListOp?: string, primaryKeys?: Map<string, PrimaryKey>) => DataProvider;
8
9
  export default _default;
@@ -10,6 +10,17 @@ var __assign = (this && this.__assign) || function () {
10
10
  };
11
11
  return __assign.apply(this, arguments);
12
12
  };
13
+ var __rest = (this && this.__rest) || function (s, e) {
14
+ var t = {};
15
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
16
+ t[p] = s[p];
17
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
18
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
19
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
20
+ t[p[i]] = s[p[i]];
21
+ }
22
+ return t;
23
+ };
13
24
  Object.defineProperty(exports, "__esModule", { value: true });
14
25
  var query_string_1 = require("query-string");
15
26
  var ra_core_1 = require("ra-core");
@@ -18,7 +29,7 @@ var ra_core_1 = require("ra-core");
18
29
  *
19
30
  * This REST dialect uses postgrest syntax
20
31
  *
21
- * @see https://postgrest.org/en/v6.0/api.html#embedded-filters
32
+ * @see https://postgrest.org/en/stable/api.html#embedded-filters
22
33
  *
23
34
  * @example
24
35
  *
@@ -34,7 +45,7 @@ var ra_core_1 = require("ra-core");
34
45
  *
35
46
  * @example
36
47
  *
37
- * import React from 'react';
48
+ * import * as React from 'react';
38
49
  * import { Admin, Resource } from 'react-admin';
39
50
  * import postgrestRestProvider from '@raphiniert/ra-data-postgrest';
40
51
  *
@@ -54,21 +65,130 @@ function parseFilters(filter, defaultListOp) {
54
65
  // key: the name of the object key
55
66
  var splitKey = key.split('@');
56
67
  var operation = splitKey.length == 2 ? splitKey[1] : defaultListOp;
57
- var value = filter[key];
58
- result[splitKey[0]] =
59
- operation.includes('like') ? operation + ".*" + value + "*" : operation + "." + value;
68
+ var values;
69
+ if (operation.includes('like')) {
70
+ // we split the search term in words
71
+ values = filter[key].trim().split(' ');
72
+ }
73
+ else {
74
+ values = [filter[key]];
75
+ }
76
+ values.forEach(function (value) {
77
+ // if operator is intentionally blank, rpc syntax
78
+ var op = operation.includes('like') ? operation + ".*" + value + "*" : operation.length == 0 ? "" + value : operation + "." + value;
79
+ if (result[splitKey[0]] === undefined) {
80
+ // first operator for the key, we add it to the dict
81
+ result[splitKey[0]] = op;
82
+ }
83
+ else {
84
+ if (!Array.isArray(result[splitKey[0]])) {
85
+ // second operator, we transform to an array
86
+ result[splitKey[0]] = [result[splitKey[0]], op];
87
+ }
88
+ else {
89
+ // third and subsequent, we add to array
90
+ result[splitKey[0]].push(op);
91
+ }
92
+ }
93
+ });
60
94
  });
61
95
  return result;
62
96
  }
63
- exports.default = (function (apiUrl, httpClient, defaultListOp) {
97
+ var getPrimaryKey = function (resource, primaryKeys) {
98
+ return primaryKeys.get(resource) || ['id'];
99
+ };
100
+ var decodeId = function (id, primaryKey) {
101
+ if (isCompoundKey(primaryKey)) {
102
+ return JSON.parse(id.toString());
103
+ }
104
+ else {
105
+ return [id.toString()];
106
+ }
107
+ };
108
+ var encodeId = function (data, primaryKey) {
109
+ if (isCompoundKey(primaryKey)) {
110
+ return JSON.stringify(primaryKey.map(function (key) { return data[key]; }));
111
+ }
112
+ else {
113
+ return data[primaryKey[0]];
114
+ }
115
+ };
116
+ var dataWithId = function (data, primaryKey) {
117
+ if (primaryKey === ['id']) {
118
+ return data;
119
+ }
120
+ return Object.assign(data, {
121
+ id: encodeId(data, primaryKey)
122
+ });
123
+ };
124
+ var isCompoundKey = function (primaryKey) {
125
+ return primaryKey.length > 1;
126
+ };
127
+ var getQuery = function (primaryKey, ids, resource) {
128
+ var _a, _b;
129
+ if (Array.isArray(ids) && ids.length > 1) {
130
+ // no standardized query with multiple ids possible for rpc endpoints which are api-exposed database functions
131
+ if (resource.startsWith('rpc/')) {
132
+ console.error('PostgREST\'s rpc endpoints are not intended to be handled as views. Therefore, no query generation for multiple key values implemented!');
133
+ return;
134
+ }
135
+ if (isCompoundKey(primaryKey)) {
136
+ return "or=(\n " + ids.map(function (id) {
137
+ var primaryKeyParams = decodeId(id, primaryKey);
138
+ return "and(" + primaryKey.map(function (key, i) { return key + ".eq." + primaryKeyParams[i]; }).join(',') + ")";
139
+ }) + "\n )";
140
+ }
141
+ else {
142
+ return query_string_1.stringify((_a = {}, _a[primaryKey[0]] = "in.(" + ids.join(',') + ")", _a));
143
+ }
144
+ }
145
+ else {
146
+ // if ids is one Identifier
147
+ var id = ids.toString();
148
+ var primaryKeyParams_1 = decodeId(id, primaryKey);
149
+ if (isCompoundKey(primaryKey)) {
150
+ if (resource.startsWith('rpc/'))
151
+ return "" + primaryKey.map(function (key, i) { return key + "=" + primaryKeyParams_1[i]; }).join('&');
152
+ else
153
+ return "and=(" + primaryKey.map(function (key, i) { return key + ".eq." + primaryKeyParams_1[i]; }).join(',') + ")";
154
+ }
155
+ else {
156
+ return query_string_1.stringify((_b = {}, _b[primaryKey[0]] = "eq." + id, _b));
157
+ }
158
+ }
159
+ };
160
+ var getKeyData = function (primaryKey, data) {
161
+ var _a;
162
+ if (isCompoundKey(primaryKey)) {
163
+ return primaryKey.reduce(function (keyData, key) {
164
+ var _a;
165
+ return (__assign(__assign({}, keyData), (_a = {}, _a[key] = data[key], _a)));
166
+ }, {});
167
+ }
168
+ else {
169
+ return _a = {}, _a[primaryKey[0]] = data[primaryKey[0]], _a;
170
+ }
171
+ };
172
+ var getOrderBy = function (field, order, primaryKey) {
173
+ if (field == 'id') {
174
+ return primaryKey.map(function (key) { return (key + "." + order.toLowerCase()); }).join(',');
175
+ }
176
+ else {
177
+ return field + "." + order.toLowerCase();
178
+ }
179
+ };
180
+ var defaultPrimaryKeys = new Map();
181
+ exports.default = (function (apiUrl, httpClient, defaultListOp, primaryKeys) {
64
182
  if (httpClient === void 0) { httpClient = ra_core_1.fetchUtils.fetchJson; }
65
183
  if (defaultListOp === void 0) { defaultListOp = 'eq'; }
184
+ if (primaryKeys === void 0) { primaryKeys = defaultPrimaryKeys; }
66
185
  return ({
67
186
  getList: function (resource, params) {
187
+ var primaryKey = getPrimaryKey(resource, primaryKeys);
68
188
  var _a = params.pagination, page = _a.page, perPage = _a.perPage;
69
189
  var _b = params.sort, field = _b.field, order = _b.order;
70
190
  var parsedFilter = parseFilters(params.filter, defaultListOp);
71
- var query = __assign({ order: field + "." + order.toLowerCase(), offset: (page - 1) * perPage, limit: page * perPage - 1 }, parsedFilter);
191
+ var query = __assign({ order: getOrderBy(field, order, primaryKey), offset: (page - 1) * perPage, limit: perPage }, parsedFilter);
72
192
  // add header that Content-Range is in returned header
73
193
  var options = {
74
194
  headers: new Headers({
@@ -83,7 +203,7 @@ exports.default = (function (apiUrl, httpClient, defaultListOp) {
83
203
  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?");
84
204
  }
85
205
  return {
86
- data: json,
206
+ data: json.map(function (obj) { return dataWithId(obj, primaryKey); }),
87
207
  total: parseInt(headers
88
208
  .get('content-range')
89
209
  .split('/')
@@ -92,21 +212,27 @@ exports.default = (function (apiUrl, httpClient, defaultListOp) {
92
212
  });
93
213
  },
94
214
  getOne: function (resource, params) {
95
- return httpClient(apiUrl + "/" + resource + "?id=eq." + params.id, {
215
+ var id = params.id;
216
+ var primaryKey = getPrimaryKey(resource, primaryKeys);
217
+ var query = getQuery(primaryKey, id, resource);
218
+ var url = apiUrl + "/" + resource + "?" + query;
219
+ return httpClient(url, {
96
220
  headers: new Headers({ 'accept': 'application/vnd.pgrst.object+json' }),
97
221
  }).then(function (_a) {
98
222
  var json = _a.json;
99
223
  return ({
100
- data: json,
224
+ data: dataWithId(json, primaryKey),
101
225
  });
102
226
  });
103
227
  },
104
228
  getMany: function (resource, params) {
105
- var ids = params.ids.join(",");
106
- var url = apiUrl + "/" + resource + "?id=in.(" + ids + ")";
229
+ var ids = params.ids;
230
+ var primaryKey = getPrimaryKey(resource, primaryKeys);
231
+ var query = getQuery(primaryKey, ids, resource);
232
+ var url = apiUrl + "/" + resource + "?" + query;
107
233
  return httpClient(url).then(function (_a) {
108
234
  var json = _a.json;
109
- return ({ data: json });
235
+ return ({ data: json.map(function (data) { return dataWithId(data, primaryKey); }) });
110
236
  });
111
237
  },
112
238
  getManyReference: function (resource, params) {
@@ -114,7 +240,8 @@ exports.default = (function (apiUrl, httpClient, defaultListOp) {
114
240
  var _b = params.pagination, page = _b.page, perPage = _b.perPage;
115
241
  var _c = params.sort, field = _c.field, order = _c.order;
116
242
  var parsedFilter = parseFilters(params.filter, defaultListOp);
117
- var query = __assign((_a = {}, _a[params.target] = "eq." + params.id, _a.order = field + "." + order.toLowerCase(), _a.offset = (page - 1) * perPage, _a.limit = page * perPage - 1, _a), parsedFilter);
243
+ var primaryKey = getPrimaryKey(resource, primaryKeys);
244
+ var query = params.target ? __assign((_a = {}, _a[params.target] = "eq." + params.id, _a.order = getOrderBy(field, order, primaryKey), _a.offset = (page - 1) * perPage, _a.limit = perPage, _a), parsedFilter) : __assign({ order: getOrderBy(field, order, primaryKey), offset: (page - 1) * perPage, limit: perPage }, parsedFilter);
118
245
  // add header that Content-Range is in returned header
119
246
  var options = {
120
247
  headers: new Headers({
@@ -129,7 +256,7 @@ exports.default = (function (apiUrl, httpClient, defaultListOp) {
129
256
  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
257
  }
131
258
  return {
132
- data: json,
259
+ data: json.map(function (data) { return dataWithId(data, primaryKey); }),
133
260
  total: parseInt(headers
134
261
  .get('content-range')
135
262
  .split('/')
@@ -138,34 +265,53 @@ exports.default = (function (apiUrl, httpClient, defaultListOp) {
138
265
  });
139
266
  },
140
267
  update: function (resource, params) {
141
- return httpClient(apiUrl + "/" + resource + "?id=eq." + params.id, {
268
+ var id = params.id, data = params.data;
269
+ var primaryKey = getPrimaryKey(resource, primaryKeys);
270
+ var query = getQuery(primaryKey, id, resource);
271
+ var primaryKeyData = getKeyData(primaryKey, data);
272
+ var url = apiUrl + "/" + resource + "?" + query;
273
+ var body = JSON.stringify(__assign(__assign({}, data), primaryKeyData));
274
+ return httpClient(url, {
142
275
  method: 'PATCH',
143
276
  headers: new Headers({
144
277
  'Accept': 'application/vnd.pgrst.object+json',
145
278
  'Prefer': 'return=representation',
146
279
  'Content-Type': 'application/json'
147
280
  }),
148
- body: JSON.stringify(params.data),
281
+ body: body,
149
282
  }).then(function (_a) {
150
283
  var json = _a.json;
151
- return ({ data: json });
284
+ return ({ data: dataWithId(json, primaryKey) });
152
285
  });
153
286
  },
154
287
  updateMany: function (resource, params) {
155
- return httpClient(apiUrl + "/" + resource + "?id=in.(" + params.ids.join(',') + ")", {
288
+ var ids = params.ids;
289
+ var primaryKey = getPrimaryKey(resource, primaryKeys);
290
+ var query = getQuery(primaryKey, ids, resource);
291
+ var body = JSON.stringify(params.data.map(function (obj) {
292
+ var id = obj.id, data = __rest(obj, ["id"]);
293
+ var primaryKeyData = getKeyData(primaryKey, data);
294
+ return __assign(__assign({}, data), primaryKeyData);
295
+ }));
296
+ var url = apiUrl + "/" + resource + "?" + query;
297
+ return httpClient(url, {
156
298
  method: 'PATCH',
157
299
  headers: new Headers({
158
300
  'Prefer': 'return=representation',
159
301
  'Content-Type': 'application/json',
160
302
  }),
161
- body: JSON.stringify(params.data),
303
+ body: body,
162
304
  }).then(function (_a) {
163
305
  var json = _a.json;
164
- return ({ data: json.map(function (data) { return data.id; }) });
306
+ return ({
307
+ data: json.map(function (data) { return encodeId(data, primaryKey); })
308
+ });
165
309
  });
166
310
  },
167
311
  create: function (resource, params) {
168
- return httpClient(apiUrl + "/" + resource, {
312
+ var primaryKey = getPrimaryKey(resource, primaryKeys);
313
+ var url = apiUrl + "/" + resource;
314
+ return httpClient(url, {
169
315
  method: 'POST',
170
316
  headers: new Headers({
171
317
  'Accept': 'application/vnd.pgrst.object+json',
@@ -175,14 +321,17 @@ exports.default = (function (apiUrl, httpClient, defaultListOp) {
175
321
  body: JSON.stringify(params.data),
176
322
  }).then(function (_a) {
177
323
  var json = _a.json;
178
- console.log(json);
179
- return {
180
- data: __assign(__assign({}, params.data), { id: json.id }),
181
- };
324
+ return ({
325
+ data: __assign(__assign({}, params.data), { id: encodeId(json, primaryKey) })
326
+ });
182
327
  });
183
328
  },
184
329
  delete: function (resource, params) {
185
- return httpClient(apiUrl + "/" + resource + "?id=eq." + params.id, {
330
+ var id = params.id;
331
+ var primaryKey = getPrimaryKey(resource, primaryKeys);
332
+ var query = getQuery(primaryKey, id, resource);
333
+ var url = apiUrl + "/" + resource + "?" + query;
334
+ return httpClient(url, {
186
335
  method: 'DELETE',
187
336
  headers: new Headers({
188
337
  'Accept': 'application/vnd.pgrst.object+json',
@@ -191,11 +340,15 @@ exports.default = (function (apiUrl, httpClient, defaultListOp) {
191
340
  }),
192
341
  }).then(function (_a) {
193
342
  var json = _a.json;
194
- return ({ data: json });
343
+ return ({ data: dataWithId(json, primaryKey) });
195
344
  });
196
345
  },
197
346
  deleteMany: function (resource, params) {
198
- return httpClient(apiUrl + "/" + resource + "?id=in.(" + params.ids.join(',') + ")", {
347
+ var ids = params.ids;
348
+ var primaryKey = getPrimaryKey(resource, primaryKeys);
349
+ var query = getQuery(primaryKey, ids, resource);
350
+ var url = apiUrl + "/" + resource + "?" + query;
351
+ return httpClient(url, {
199
352
  method: 'DELETE',
200
353
  headers: new Headers({
201
354
  'Prefer': 'return=representation',
@@ -203,7 +356,7 @@ exports.default = (function (apiUrl, httpClient, defaultListOp) {
203
356
  }),
204
357
  }).then(function (_a) {
205
358
  var json = _a.json;
206
- return ({ data: json.json().map(function (data) { return data.id; }) });
359
+ return ({ data: json.map(function (data) { return encodeId(data, primaryKey); }) });
207
360
  });
208
361
  },
209
362
  });
package/lib/index.js CHANGED
@@ -3,6 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.authProvider = void 0;
6
7
  var dataProvider_1 = __importDefault(require("./dataProvider"));
7
8
  var authProvider_1 = __importDefault(require("./authProvider"));
8
9
  exports.authProvider = authProvider_1.default;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@raphiniert/ra-data-postgrest",
3
- "version": "1.1.4",
3
+ "version": "1.1.8",
4
4
  "description": "postgREST data provider for react-admin",
5
5
  "main": "lib/index.js",
6
6
  "module": "esm/index.js",
@@ -36,6 +36,6 @@
36
36
  "typescript": "^3.9.5"
37
37
  },
38
38
  "peerDependencies": {
39
- "ra-core": "^3.8.4"
39
+ "ra-core": "^3.19.6"
40
40
  }
41
41
  }
@@ -53,7 +53,9 @@ function parseFilters(filter, defaultListOp) {
53
53
  }
54
54
 
55
55
  values.forEach(value => {
56
- let op = operation.includes('like') ? `${operation}.*${value}*` : `${operation}.${value}`;
56
+ // if operator is intentionally blank, rpc syntax
57
+ let op = operation.includes('like') ? `${operation}.*${value}*` : operation.length == 0 ? `${value}` : `${operation}.${value}`;
58
+
57
59
  if (result[splitKey[0]] === undefined) {
58
60
  // first operator for the key, we add it to the dict
59
61
  result[splitKey[0]] = op;
@@ -99,7 +101,7 @@ const encodeId = (data: any, primaryKey: PrimaryKey): Identifier => {
99
101
  }
100
102
 
101
103
  const dataWithId = (data: any, primaryKey: PrimaryKey) => {
102
- if (primaryKey === ['id'] || (data && data.id)) {
104
+ if (primaryKey === ['id']) {
103
105
  return data;
104
106
  }
105
107
 
@@ -143,7 +145,7 @@ const getQuery = (primaryKey : PrimaryKey, ids: Identifier | Array<Identifier>,
143
145
  else
144
146
  return `and=(${primaryKey.map((key : string, i: any) => `${key}.eq.${primaryKeyParams[i]}`).join(',')})`;
145
147
  } else {
146
- return stringify({ [primaryKey[0]]: `${id}` });
148
+ return stringify({ [primaryKey[0]]: `eq.${id}` });
147
149
  }
148
150
  }
149
151
  }
@@ -251,12 +253,17 @@ export default (apiUrl, httpClient = fetchUtils.fetchJson, defaultListOp = 'eq',
251
253
  const parsedFilter = parseFilters(params.filter, defaultListOp);
252
254
  const primaryKey = getPrimaryKey(resource, primaryKeys);
253
255
 
254
- const query = {
256
+ const query = params.target ? {
255
257
  [params.target]: `eq.${params.id}`,
256
258
  order: getOrderBy(field, order, primaryKey),
257
259
  offset: (page - 1) * perPage,
258
260
  limit: perPage,
259
261
  ...parsedFilter,
262
+ }:{
263
+ order: getOrderBy(field, order, primaryKey),
264
+ offset: (page - 1) * perPage,
265
+ limit: perPage,
266
+ ...parsedFilter,
260
267
  };
261
268
 
262
269
  // add header that Content-Range is in returned header