@raphiniert/ra-data-postgrest 1.1.6 → 1.1.9
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 +16 -2
- package/README.md +9 -0
- package/esm/dataProvider/index.js +24 -24
- package/lib/dataProvider/index.js +24 -24
- package/package.json +5 -8
- package/src/dataProvider/index.ts +18 -12
package/CHANGELOG.md
CHANGED
|
@@ -2,9 +2,23 @@
|
|
|
2
2
|
|
|
3
3
|
Find all notable changes of this project in this file.
|
|
4
4
|
|
|
5
|
+
## v1.1.9 - 2023-08-23
|
|
6
|
+
- [#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)
|
|
7
|
+
|
|
8
|
+
## v1.1.8 - 2022-01-07
|
|
9
|
+
- required re-release as I missed to transpile all and upload the features of 1.1.7 to npm.
|
|
10
|
+
|
|
11
|
+
## v1.1.7 - 2022-01-07
|
|
12
|
+
### Fixes
|
|
13
|
+
- 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)
|
|
14
|
+
|
|
15
|
+
### New feature
|
|
16
|
+
- [#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)
|
|
17
|
+
|
|
18
|
+
|
|
5
19
|
## v1.1.6 - 2021-01-16
|
|
6
20
|
### Fixes
|
|
7
|
-
- 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)
|
|
21
|
+
- [#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)
|
|
8
22
|
|
|
9
23
|
## v1.1.5 - 2021-01-16
|
|
10
24
|
### Fixes
|
|
@@ -45,7 +59,7 @@ Find all notable changes of this project in this file.
|
|
|
45
59
|
|
|
46
60
|
## v1.0.7 - 2020-08-23
|
|
47
61
|
### New feature
|
|
48
|
-
- [#14](https://github.com/raphiniert-com/ra-data-postgrest/pull/14) 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)
|
|
62
|
+
- [#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)
|
|
49
63
|
|
|
50
64
|
### Maintenance
|
|
51
65
|
- `import React from 'react';` -> `import * as React from 'react';`
|
package/README.md
CHANGED
|
@@ -135,6 +135,15 @@ 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
|
+
#### RPC Functions
|
|
139
|
+
Given a RPC call as ```GET /rpc/add_them?post_author=Herbert HTTP/1.1```, the dataProvider allows you to filter such endpoints. As they are no view, but a SQL procedure, several postgREST features do not apply. I.e. no comparators such as `ilike`, `like`, `eq` are applicable. Only the raw value without comparator needs to be send to the API. In order to realize this behavior, just add an "empty" comparator to the field, i.e. end `source` with an `@` as in the example:
|
|
140
|
+
|
|
141
|
+
```jsx
|
|
142
|
+
<Filter {...props}>
|
|
143
|
+
<TextInput label="Search" source="post_author@" alwaysOn />
|
|
144
|
+
// some more filters
|
|
145
|
+
</Filter>
|
|
146
|
+
```
|
|
138
147
|
|
|
139
148
|
### Compound primary keys
|
|
140
149
|
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:
|
|
@@ -20,7 +20,6 @@ var __rest = (this && this.__rest) || function (s, e) {
|
|
|
20
20
|
}
|
|
21
21
|
return t;
|
|
22
22
|
};
|
|
23
|
-
import { stringify } from 'query-string';
|
|
24
23
|
import { fetchUtils } from 'ra-core';
|
|
25
24
|
/**
|
|
26
25
|
* Maps react-admin queries to a postgrest REST API
|
|
@@ -72,7 +71,8 @@ function parseFilters(filter, defaultListOp) {
|
|
|
72
71
|
values = [filter[key]];
|
|
73
72
|
}
|
|
74
73
|
values.forEach(function (value) {
|
|
75
|
-
|
|
74
|
+
// if operator is intentionally blank, rpc syntax
|
|
75
|
+
var op = operation.includes('like') ? "".concat(operation, ".*").concat(value, "*") : operation.length == 0 ? "".concat(value) : "".concat(operation, ".").concat(value);
|
|
76
76
|
if (result[splitKey[0]] === undefined) {
|
|
77
77
|
// first operator for the key, we add it to the dict
|
|
78
78
|
result[splitKey[0]] = op;
|
|
@@ -111,7 +111,7 @@ var encodeId = function (data, primaryKey) {
|
|
|
111
111
|
}
|
|
112
112
|
};
|
|
113
113
|
var dataWithId = function (data, primaryKey) {
|
|
114
|
-
if (primaryKey === ['id']
|
|
114
|
+
if (primaryKey === ['id']) {
|
|
115
115
|
return data;
|
|
116
116
|
}
|
|
117
117
|
return Object.assign(data, {
|
|
@@ -122,7 +122,7 @@ var isCompoundKey = function (primaryKey) {
|
|
|
122
122
|
return primaryKey.length > 1;
|
|
123
123
|
};
|
|
124
124
|
var getQuery = function (primaryKey, ids, resource) {
|
|
125
|
-
var _a
|
|
125
|
+
var _a;
|
|
126
126
|
if (Array.isArray(ids) && ids.length > 1) {
|
|
127
127
|
// no standardized query with multiple ids possible for rpc endpoints which are api-exposed database functions
|
|
128
128
|
if (resource.startsWith('rpc/')) {
|
|
@@ -130,13 +130,13 @@ var getQuery = function (primaryKey, ids, resource) {
|
|
|
130
130
|
return;
|
|
131
131
|
}
|
|
132
132
|
if (isCompoundKey(primaryKey)) {
|
|
133
|
-
return "or=(\n "
|
|
133
|
+
return "or=(\n ".concat(ids.map(function (id) {
|
|
134
134
|
var primaryKeyParams = decodeId(id, primaryKey);
|
|
135
|
-
return "and("
|
|
136
|
-
})
|
|
135
|
+
return "and(".concat(primaryKey.map(function (key, i) { return "".concat(key, ".eq.").concat(primaryKeyParams[i]); }).join(','), ")");
|
|
136
|
+
}), "\n )");
|
|
137
137
|
}
|
|
138
138
|
else {
|
|
139
|
-
return
|
|
139
|
+
return new URLSearchParams((_a = {}, _a[primaryKey[0]] = "in.(".concat(ids.join(','), ")"), _a)).toString();
|
|
140
140
|
}
|
|
141
141
|
}
|
|
142
142
|
else {
|
|
@@ -145,12 +145,12 @@ var getQuery = function (primaryKey, ids, resource) {
|
|
|
145
145
|
var primaryKeyParams_1 = decodeId(id, primaryKey);
|
|
146
146
|
if (isCompoundKey(primaryKey)) {
|
|
147
147
|
if (resource.startsWith('rpc/'))
|
|
148
|
-
return ""
|
|
148
|
+
return "".concat(primaryKey.map(function (key, i) { return "".concat(key, "=").concat(primaryKeyParams_1[i]); }).join('&'));
|
|
149
149
|
else
|
|
150
|
-
return "and=("
|
|
150
|
+
return "and=(".concat(primaryKey.map(function (key, i) { return "".concat(key, ".eq.").concat(primaryKeyParams_1[i]); }).join(','), ")");
|
|
151
151
|
}
|
|
152
152
|
else {
|
|
153
|
-
return
|
|
153
|
+
return new URLSearchParams([[primaryKey[0], "eq.".concat(id)]]).toString();
|
|
154
154
|
}
|
|
155
155
|
}
|
|
156
156
|
};
|
|
@@ -168,10 +168,10 @@ var getKeyData = function (primaryKey, data) {
|
|
|
168
168
|
};
|
|
169
169
|
var getOrderBy = function (field, order, primaryKey) {
|
|
170
170
|
if (field == 'id') {
|
|
171
|
-
return primaryKey.map(function (key) { return (key
|
|
171
|
+
return primaryKey.map(function (key) { return ("".concat(key, ".").concat(order.toLowerCase())); }).join(',');
|
|
172
172
|
}
|
|
173
173
|
else {
|
|
174
|
-
return field
|
|
174
|
+
return "".concat(field, ".").concat(order.toLowerCase());
|
|
175
175
|
}
|
|
176
176
|
};
|
|
177
177
|
var defaultPrimaryKeys = new Map();
|
|
@@ -185,7 +185,7 @@ export default (function (apiUrl, httpClient, defaultListOp, primaryKeys) {
|
|
|
185
185
|
var _a = params.pagination, page = _a.page, perPage = _a.perPage;
|
|
186
186
|
var _b = params.sort, field = _b.field, order = _b.order;
|
|
187
187
|
var parsedFilter = parseFilters(params.filter, defaultListOp);
|
|
188
|
-
var query = __assign({ order: getOrderBy(field, order, primaryKey), offset: (page - 1) * perPage, limit: perPage }, parsedFilter);
|
|
188
|
+
var query = __assign({ order: getOrderBy(field, order, primaryKey), offset: String((page - 1) * perPage), limit: String(perPage) }, parsedFilter);
|
|
189
189
|
// add header that Content-Range is in returned header
|
|
190
190
|
var options = {
|
|
191
191
|
headers: new Headers({
|
|
@@ -193,7 +193,7 @@ export default (function (apiUrl, httpClient, defaultListOp, primaryKeys) {
|
|
|
193
193
|
Prefer: 'count=exact'
|
|
194
194
|
})
|
|
195
195
|
};
|
|
196
|
-
var url = apiUrl
|
|
196
|
+
var url = "".concat(apiUrl, "/").concat(resource, "?").concat(new URLSearchParams(query));
|
|
197
197
|
return httpClient(url, options).then(function (_a) {
|
|
198
198
|
var headers = _a.headers, json = _a.json;
|
|
199
199
|
if (!headers.has('content-range')) {
|
|
@@ -212,7 +212,7 @@ export default (function (apiUrl, httpClient, defaultListOp, primaryKeys) {
|
|
|
212
212
|
var id = params.id;
|
|
213
213
|
var primaryKey = getPrimaryKey(resource, primaryKeys);
|
|
214
214
|
var query = getQuery(primaryKey, id, resource);
|
|
215
|
-
var url = apiUrl
|
|
215
|
+
var url = "".concat(apiUrl, "/").concat(resource, "?").concat(query);
|
|
216
216
|
return httpClient(url, {
|
|
217
217
|
headers: new Headers({ 'accept': 'application/vnd.pgrst.object+json' }),
|
|
218
218
|
}).then(function (_a) {
|
|
@@ -226,7 +226,7 @@ export default (function (apiUrl, httpClient, defaultListOp, primaryKeys) {
|
|
|
226
226
|
var ids = params.ids;
|
|
227
227
|
var primaryKey = getPrimaryKey(resource, primaryKeys);
|
|
228
228
|
var query = getQuery(primaryKey, ids, resource);
|
|
229
|
-
var url = apiUrl
|
|
229
|
+
var url = "".concat(apiUrl, "/").concat(resource, "?").concat(query);
|
|
230
230
|
return httpClient(url).then(function (_a) {
|
|
231
231
|
var json = _a.json;
|
|
232
232
|
return ({ data: json.map(function (data) { return dataWithId(data, primaryKey); }) });
|
|
@@ -238,7 +238,7 @@ export default (function (apiUrl, httpClient, defaultListOp, primaryKeys) {
|
|
|
238
238
|
var _c = params.sort, field = _c.field, order = _c.order;
|
|
239
239
|
var parsedFilter = parseFilters(params.filter, defaultListOp);
|
|
240
240
|
var primaryKey = getPrimaryKey(resource, primaryKeys);
|
|
241
|
-
var query = __assign((_a = {}, _a[params.target] = "eq."
|
|
241
|
+
var query = params.target ? __assign((_a = {}, _a[params.target] = "eq.".concat(params.id), _a.order = getOrderBy(field, order, primaryKey), _a.offset = String((page - 1) * perPage), _a.limit = String(perPage), _a), parsedFilter) : __assign({ order: getOrderBy(field, order, primaryKey), offset: String((page - 1) * perPage), limit: String(perPage) }, parsedFilter);
|
|
242
242
|
// add header that Content-Range is in returned header
|
|
243
243
|
var options = {
|
|
244
244
|
headers: new Headers({
|
|
@@ -246,7 +246,7 @@ export default (function (apiUrl, httpClient, defaultListOp, primaryKeys) {
|
|
|
246
246
|
Prefer: 'count=exact'
|
|
247
247
|
})
|
|
248
248
|
};
|
|
249
|
-
var url = apiUrl
|
|
249
|
+
var url = "".concat(apiUrl, "/").concat(resource, "?").concat(new URLSearchParams(query));
|
|
250
250
|
return httpClient(url, options).then(function (_a) {
|
|
251
251
|
var headers = _a.headers, json = _a.json;
|
|
252
252
|
if (!headers.has('content-range')) {
|
|
@@ -266,7 +266,7 @@ export default (function (apiUrl, httpClient, defaultListOp, primaryKeys) {
|
|
|
266
266
|
var primaryKey = getPrimaryKey(resource, primaryKeys);
|
|
267
267
|
var query = getQuery(primaryKey, id, resource);
|
|
268
268
|
var primaryKeyData = getKeyData(primaryKey, data);
|
|
269
|
-
var url = apiUrl
|
|
269
|
+
var url = "".concat(apiUrl, "/").concat(resource, "?").concat(query);
|
|
270
270
|
var body = JSON.stringify(__assign(__assign({}, data), primaryKeyData));
|
|
271
271
|
return httpClient(url, {
|
|
272
272
|
method: 'PATCH',
|
|
@@ -290,7 +290,7 @@ export default (function (apiUrl, httpClient, defaultListOp, primaryKeys) {
|
|
|
290
290
|
var primaryKeyData = getKeyData(primaryKey, data);
|
|
291
291
|
return __assign(__assign({}, data), primaryKeyData);
|
|
292
292
|
}));
|
|
293
|
-
var url = apiUrl
|
|
293
|
+
var url = "".concat(apiUrl, "/").concat(resource, "?").concat(query);
|
|
294
294
|
return httpClient(url, {
|
|
295
295
|
method: 'PATCH',
|
|
296
296
|
headers: new Headers({
|
|
@@ -307,7 +307,7 @@ export default (function (apiUrl, httpClient, defaultListOp, primaryKeys) {
|
|
|
307
307
|
},
|
|
308
308
|
create: function (resource, params) {
|
|
309
309
|
var primaryKey = getPrimaryKey(resource, primaryKeys);
|
|
310
|
-
var url = apiUrl
|
|
310
|
+
var url = "".concat(apiUrl, "/").concat(resource);
|
|
311
311
|
return httpClient(url, {
|
|
312
312
|
method: 'POST',
|
|
313
313
|
headers: new Headers({
|
|
@@ -327,7 +327,7 @@ export default (function (apiUrl, httpClient, defaultListOp, primaryKeys) {
|
|
|
327
327
|
var id = params.id;
|
|
328
328
|
var primaryKey = getPrimaryKey(resource, primaryKeys);
|
|
329
329
|
var query = getQuery(primaryKey, id, resource);
|
|
330
|
-
var url = apiUrl
|
|
330
|
+
var url = "".concat(apiUrl, "/").concat(resource, "?").concat(query);
|
|
331
331
|
return httpClient(url, {
|
|
332
332
|
method: 'DELETE',
|
|
333
333
|
headers: new Headers({
|
|
@@ -344,7 +344,7 @@ export default (function (apiUrl, httpClient, defaultListOp, primaryKeys) {
|
|
|
344
344
|
var ids = params.ids;
|
|
345
345
|
var primaryKey = getPrimaryKey(resource, primaryKeys);
|
|
346
346
|
var query = getQuery(primaryKey, ids, resource);
|
|
347
|
-
var url = apiUrl
|
|
347
|
+
var url = "".concat(apiUrl, "/").concat(resource, "?").concat(query);
|
|
348
348
|
return httpClient(url, {
|
|
349
349
|
method: 'DELETE',
|
|
350
350
|
headers: new Headers({
|
|
@@ -22,7 +22,6 @@ var __rest = (this && this.__rest) || function (s, e) {
|
|
|
22
22
|
return t;
|
|
23
23
|
};
|
|
24
24
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
25
|
-
var query_string_1 = require("query-string");
|
|
26
25
|
var ra_core_1 = require("ra-core");
|
|
27
26
|
/**
|
|
28
27
|
* Maps react-admin queries to a postgrest REST API
|
|
@@ -74,7 +73,8 @@ function parseFilters(filter, defaultListOp) {
|
|
|
74
73
|
values = [filter[key]];
|
|
75
74
|
}
|
|
76
75
|
values.forEach(function (value) {
|
|
77
|
-
|
|
76
|
+
// if operator is intentionally blank, rpc syntax
|
|
77
|
+
var op = operation.includes('like') ? "".concat(operation, ".*").concat(value, "*") : operation.length == 0 ? "".concat(value) : "".concat(operation, ".").concat(value);
|
|
78
78
|
if (result[splitKey[0]] === undefined) {
|
|
79
79
|
// first operator for the key, we add it to the dict
|
|
80
80
|
result[splitKey[0]] = op;
|
|
@@ -113,7 +113,7 @@ var encodeId = function (data, primaryKey) {
|
|
|
113
113
|
}
|
|
114
114
|
};
|
|
115
115
|
var dataWithId = function (data, primaryKey) {
|
|
116
|
-
if (primaryKey === ['id']
|
|
116
|
+
if (primaryKey === ['id']) {
|
|
117
117
|
return data;
|
|
118
118
|
}
|
|
119
119
|
return Object.assign(data, {
|
|
@@ -124,7 +124,7 @@ var isCompoundKey = function (primaryKey) {
|
|
|
124
124
|
return primaryKey.length > 1;
|
|
125
125
|
};
|
|
126
126
|
var getQuery = function (primaryKey, ids, resource) {
|
|
127
|
-
var _a
|
|
127
|
+
var _a;
|
|
128
128
|
if (Array.isArray(ids) && ids.length > 1) {
|
|
129
129
|
// no standardized query with multiple ids possible for rpc endpoints which are api-exposed database functions
|
|
130
130
|
if (resource.startsWith('rpc/')) {
|
|
@@ -132,13 +132,13 @@ var getQuery = function (primaryKey, ids, resource) {
|
|
|
132
132
|
return;
|
|
133
133
|
}
|
|
134
134
|
if (isCompoundKey(primaryKey)) {
|
|
135
|
-
return "or=(\n "
|
|
135
|
+
return "or=(\n ".concat(ids.map(function (id) {
|
|
136
136
|
var primaryKeyParams = decodeId(id, primaryKey);
|
|
137
|
-
return "and("
|
|
138
|
-
})
|
|
137
|
+
return "and(".concat(primaryKey.map(function (key, i) { return "".concat(key, ".eq.").concat(primaryKeyParams[i]); }).join(','), ")");
|
|
138
|
+
}), "\n )");
|
|
139
139
|
}
|
|
140
140
|
else {
|
|
141
|
-
return
|
|
141
|
+
return new URLSearchParams((_a = {}, _a[primaryKey[0]] = "in.(".concat(ids.join(','), ")"), _a)).toString();
|
|
142
142
|
}
|
|
143
143
|
}
|
|
144
144
|
else {
|
|
@@ -147,12 +147,12 @@ var getQuery = function (primaryKey, ids, resource) {
|
|
|
147
147
|
var primaryKeyParams_1 = decodeId(id, primaryKey);
|
|
148
148
|
if (isCompoundKey(primaryKey)) {
|
|
149
149
|
if (resource.startsWith('rpc/'))
|
|
150
|
-
return ""
|
|
150
|
+
return "".concat(primaryKey.map(function (key, i) { return "".concat(key, "=").concat(primaryKeyParams_1[i]); }).join('&'));
|
|
151
151
|
else
|
|
152
|
-
return "and=("
|
|
152
|
+
return "and=(".concat(primaryKey.map(function (key, i) { return "".concat(key, ".eq.").concat(primaryKeyParams_1[i]); }).join(','), ")");
|
|
153
153
|
}
|
|
154
154
|
else {
|
|
155
|
-
return
|
|
155
|
+
return new URLSearchParams([[primaryKey[0], "eq.".concat(id)]]).toString();
|
|
156
156
|
}
|
|
157
157
|
}
|
|
158
158
|
};
|
|
@@ -170,10 +170,10 @@ var getKeyData = function (primaryKey, data) {
|
|
|
170
170
|
};
|
|
171
171
|
var getOrderBy = function (field, order, primaryKey) {
|
|
172
172
|
if (field == 'id') {
|
|
173
|
-
return primaryKey.map(function (key) { return (key
|
|
173
|
+
return primaryKey.map(function (key) { return ("".concat(key, ".").concat(order.toLowerCase())); }).join(',');
|
|
174
174
|
}
|
|
175
175
|
else {
|
|
176
|
-
return field
|
|
176
|
+
return "".concat(field, ".").concat(order.toLowerCase());
|
|
177
177
|
}
|
|
178
178
|
};
|
|
179
179
|
var defaultPrimaryKeys = new Map();
|
|
@@ -187,7 +187,7 @@ exports.default = (function (apiUrl, httpClient, defaultListOp, primaryKeys) {
|
|
|
187
187
|
var _a = params.pagination, page = _a.page, perPage = _a.perPage;
|
|
188
188
|
var _b = params.sort, field = _b.field, order = _b.order;
|
|
189
189
|
var parsedFilter = parseFilters(params.filter, defaultListOp);
|
|
190
|
-
var query = __assign({ order: getOrderBy(field, order, primaryKey), offset: (page - 1) * perPage, limit: perPage }, parsedFilter);
|
|
190
|
+
var query = __assign({ order: getOrderBy(field, order, primaryKey), offset: String((page - 1) * perPage), limit: String(perPage) }, parsedFilter);
|
|
191
191
|
// add header that Content-Range is in returned header
|
|
192
192
|
var options = {
|
|
193
193
|
headers: new Headers({
|
|
@@ -195,7 +195,7 @@ exports.default = (function (apiUrl, httpClient, defaultListOp, primaryKeys) {
|
|
|
195
195
|
Prefer: 'count=exact'
|
|
196
196
|
})
|
|
197
197
|
};
|
|
198
|
-
var url = apiUrl
|
|
198
|
+
var url = "".concat(apiUrl, "/").concat(resource, "?").concat(new URLSearchParams(query));
|
|
199
199
|
return httpClient(url, options).then(function (_a) {
|
|
200
200
|
var headers = _a.headers, json = _a.json;
|
|
201
201
|
if (!headers.has('content-range')) {
|
|
@@ -214,7 +214,7 @@ exports.default = (function (apiUrl, httpClient, defaultListOp, primaryKeys) {
|
|
|
214
214
|
var id = params.id;
|
|
215
215
|
var primaryKey = getPrimaryKey(resource, primaryKeys);
|
|
216
216
|
var query = getQuery(primaryKey, id, resource);
|
|
217
|
-
var url = apiUrl
|
|
217
|
+
var url = "".concat(apiUrl, "/").concat(resource, "?").concat(query);
|
|
218
218
|
return httpClient(url, {
|
|
219
219
|
headers: new Headers({ 'accept': 'application/vnd.pgrst.object+json' }),
|
|
220
220
|
}).then(function (_a) {
|
|
@@ -228,7 +228,7 @@ exports.default = (function (apiUrl, httpClient, defaultListOp, primaryKeys) {
|
|
|
228
228
|
var ids = params.ids;
|
|
229
229
|
var primaryKey = getPrimaryKey(resource, primaryKeys);
|
|
230
230
|
var query = getQuery(primaryKey, ids, resource);
|
|
231
|
-
var url = apiUrl
|
|
231
|
+
var url = "".concat(apiUrl, "/").concat(resource, "?").concat(query);
|
|
232
232
|
return httpClient(url).then(function (_a) {
|
|
233
233
|
var json = _a.json;
|
|
234
234
|
return ({ data: json.map(function (data) { return dataWithId(data, primaryKey); }) });
|
|
@@ -240,7 +240,7 @@ exports.default = (function (apiUrl, httpClient, defaultListOp, primaryKeys) {
|
|
|
240
240
|
var _c = params.sort, field = _c.field, order = _c.order;
|
|
241
241
|
var parsedFilter = parseFilters(params.filter, defaultListOp);
|
|
242
242
|
var primaryKey = getPrimaryKey(resource, primaryKeys);
|
|
243
|
-
var query = __assign((_a = {}, _a[params.target] = "eq."
|
|
243
|
+
var query = params.target ? __assign((_a = {}, _a[params.target] = "eq.".concat(params.id), _a.order = getOrderBy(field, order, primaryKey), _a.offset = String((page - 1) * perPage), _a.limit = String(perPage), _a), parsedFilter) : __assign({ order: getOrderBy(field, order, primaryKey), offset: String((page - 1) * perPage), limit: String(perPage) }, parsedFilter);
|
|
244
244
|
// add header that Content-Range is in returned header
|
|
245
245
|
var options = {
|
|
246
246
|
headers: new Headers({
|
|
@@ -248,7 +248,7 @@ exports.default = (function (apiUrl, httpClient, defaultListOp, primaryKeys) {
|
|
|
248
248
|
Prefer: 'count=exact'
|
|
249
249
|
})
|
|
250
250
|
};
|
|
251
|
-
var url = apiUrl
|
|
251
|
+
var url = "".concat(apiUrl, "/").concat(resource, "?").concat(new URLSearchParams(query));
|
|
252
252
|
return httpClient(url, options).then(function (_a) {
|
|
253
253
|
var headers = _a.headers, json = _a.json;
|
|
254
254
|
if (!headers.has('content-range')) {
|
|
@@ -268,7 +268,7 @@ exports.default = (function (apiUrl, httpClient, defaultListOp, primaryKeys) {
|
|
|
268
268
|
var primaryKey = getPrimaryKey(resource, primaryKeys);
|
|
269
269
|
var query = getQuery(primaryKey, id, resource);
|
|
270
270
|
var primaryKeyData = getKeyData(primaryKey, data);
|
|
271
|
-
var url = apiUrl
|
|
271
|
+
var url = "".concat(apiUrl, "/").concat(resource, "?").concat(query);
|
|
272
272
|
var body = JSON.stringify(__assign(__assign({}, data), primaryKeyData));
|
|
273
273
|
return httpClient(url, {
|
|
274
274
|
method: 'PATCH',
|
|
@@ -292,7 +292,7 @@ exports.default = (function (apiUrl, httpClient, defaultListOp, primaryKeys) {
|
|
|
292
292
|
var primaryKeyData = getKeyData(primaryKey, data);
|
|
293
293
|
return __assign(__assign({}, data), primaryKeyData);
|
|
294
294
|
}));
|
|
295
|
-
var url = apiUrl
|
|
295
|
+
var url = "".concat(apiUrl, "/").concat(resource, "?").concat(query);
|
|
296
296
|
return httpClient(url, {
|
|
297
297
|
method: 'PATCH',
|
|
298
298
|
headers: new Headers({
|
|
@@ -309,7 +309,7 @@ exports.default = (function (apiUrl, httpClient, defaultListOp, primaryKeys) {
|
|
|
309
309
|
},
|
|
310
310
|
create: function (resource, params) {
|
|
311
311
|
var primaryKey = getPrimaryKey(resource, primaryKeys);
|
|
312
|
-
var url = apiUrl
|
|
312
|
+
var url = "".concat(apiUrl, "/").concat(resource);
|
|
313
313
|
return httpClient(url, {
|
|
314
314
|
method: 'POST',
|
|
315
315
|
headers: new Headers({
|
|
@@ -329,7 +329,7 @@ exports.default = (function (apiUrl, httpClient, defaultListOp, primaryKeys) {
|
|
|
329
329
|
var id = params.id;
|
|
330
330
|
var primaryKey = getPrimaryKey(resource, primaryKeys);
|
|
331
331
|
var query = getQuery(primaryKey, id, resource);
|
|
332
|
-
var url = apiUrl
|
|
332
|
+
var url = "".concat(apiUrl, "/").concat(resource, "?").concat(query);
|
|
333
333
|
return httpClient(url, {
|
|
334
334
|
method: 'DELETE',
|
|
335
335
|
headers: new Headers({
|
|
@@ -346,7 +346,7 @@ exports.default = (function (apiUrl, httpClient, defaultListOp, primaryKeys) {
|
|
|
346
346
|
var ids = params.ids;
|
|
347
347
|
var primaryKey = getPrimaryKey(resource, primaryKeys);
|
|
348
348
|
var query = getQuery(primaryKey, ids, resource);
|
|
349
|
-
var url = apiUrl
|
|
349
|
+
var url = "".concat(apiUrl, "/").concat(resource, "?").concat(query);
|
|
350
350
|
return httpClient(url, {
|
|
351
351
|
method: 'DELETE',
|
|
352
352
|
headers: new Headers({
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@raphiniert/ra-data-postgrest",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.9",
|
|
4
4
|
"description": "postgREST data provider for react-admin",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"module": "esm/index.js",
|
|
@@ -26,16 +26,13 @@
|
|
|
26
26
|
"watch": "tsc --outDir esm --module es2015 --watch",
|
|
27
27
|
"prepare": "install-peers"
|
|
28
28
|
},
|
|
29
|
-
"dependencies": {
|
|
30
|
-
"query-string": "^5.1.1"
|
|
31
|
-
},
|
|
32
29
|
"devDependencies": {
|
|
33
|
-
"cross-env": "^
|
|
30
|
+
"cross-env": "^7.0.3",
|
|
34
31
|
"install-peers-cli": "^2.2.0",
|
|
35
|
-
"rimraf": "^
|
|
36
|
-
"typescript": "^
|
|
32
|
+
"rimraf": "^3.0.2",
|
|
33
|
+
"typescript": "^4.6.4"
|
|
37
34
|
},
|
|
38
35
|
"peerDependencies": {
|
|
39
|
-
"ra-core": "^3.
|
|
36
|
+
"ra-core": "^3.19.6"
|
|
40
37
|
}
|
|
41
38
|
}
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { stringify } from 'query-string';
|
|
2
1
|
import { fetchUtils, DataProvider, Identifier } from 'ra-core';
|
|
3
2
|
|
|
4
3
|
/**
|
|
@@ -53,7 +52,9 @@ function parseFilters(filter, defaultListOp) {
|
|
|
53
52
|
}
|
|
54
53
|
|
|
55
54
|
values.forEach(value => {
|
|
56
|
-
|
|
55
|
+
// if operator is intentionally blank, rpc syntax
|
|
56
|
+
let op = operation.includes('like') ? `${operation}.*${value}*` : operation.length == 0 ? `${value}` : `${operation}.${value}`;
|
|
57
|
+
|
|
57
58
|
if (result[splitKey[0]] === undefined) {
|
|
58
59
|
// first operator for the key, we add it to the dict
|
|
59
60
|
result[splitKey[0]] = op;
|
|
@@ -99,7 +100,7 @@ const encodeId = (data: any, primaryKey: PrimaryKey): Identifier => {
|
|
|
99
100
|
}
|
|
100
101
|
|
|
101
102
|
const dataWithId = (data: any, primaryKey: PrimaryKey) => {
|
|
102
|
-
if (primaryKey === ['id']
|
|
103
|
+
if (primaryKey === ['id']) {
|
|
103
104
|
return data;
|
|
104
105
|
}
|
|
105
106
|
|
|
@@ -130,7 +131,7 @@ const getQuery = (primaryKey : PrimaryKey, ids: Identifier | Array<Identifier>,
|
|
|
130
131
|
}
|
|
131
132
|
)`;
|
|
132
133
|
} else {
|
|
133
|
-
return
|
|
134
|
+
return new URLSearchParams({ [primaryKey[0]]: `in.(${ids.join(',')})` }).toString();
|
|
134
135
|
}
|
|
135
136
|
} else {
|
|
136
137
|
// if ids is one Identifier
|
|
@@ -143,7 +144,7 @@ const getQuery = (primaryKey : PrimaryKey, ids: Identifier | Array<Identifier>,
|
|
|
143
144
|
else
|
|
144
145
|
return `and=(${primaryKey.map((key : string, i: any) => `${key}.eq.${primaryKeyParams[i]}`).join(',')})`;
|
|
145
146
|
} else {
|
|
146
|
-
return
|
|
147
|
+
return new URLSearchParams([[primaryKey[0], `eq.${id}`]]).toString();
|
|
147
148
|
}
|
|
148
149
|
}
|
|
149
150
|
}
|
|
@@ -182,8 +183,8 @@ export default (apiUrl, httpClient = fetchUtils.fetchJson, defaultListOp = 'eq',
|
|
|
182
183
|
|
|
183
184
|
const query = {
|
|
184
185
|
order: getOrderBy(field, order, primaryKey),
|
|
185
|
-
offset: (page - 1) * perPage,
|
|
186
|
-
limit: perPage,
|
|
186
|
+
offset: String((page - 1) * perPage),
|
|
187
|
+
limit: String(perPage),
|
|
187
188
|
// append filters
|
|
188
189
|
...parsedFilter
|
|
189
190
|
};
|
|
@@ -196,7 +197,7 @@ export default (apiUrl, httpClient = fetchUtils.fetchJson, defaultListOp = 'eq',
|
|
|
196
197
|
})
|
|
197
198
|
};
|
|
198
199
|
|
|
199
|
-
const url = `${apiUrl}/${resource}?${
|
|
200
|
+
const url = `${apiUrl}/${resource}?${new URLSearchParams(query)}`;
|
|
200
201
|
|
|
201
202
|
return httpClient(url, options).then(({ headers, json }) => {
|
|
202
203
|
if (!headers.has('content-range')) {
|
|
@@ -251,11 +252,16 @@ export default (apiUrl, httpClient = fetchUtils.fetchJson, defaultListOp = 'eq',
|
|
|
251
252
|
const parsedFilter = parseFilters(params.filter, defaultListOp);
|
|
252
253
|
const primaryKey = getPrimaryKey(resource, primaryKeys);
|
|
253
254
|
|
|
254
|
-
const query = {
|
|
255
|
+
const query = params.target ? {
|
|
255
256
|
[params.target]: `eq.${params.id}`,
|
|
256
257
|
order: getOrderBy(field, order, primaryKey),
|
|
257
|
-
offset: (page - 1) * perPage,
|
|
258
|
-
limit: perPage,
|
|
258
|
+
offset: String((page - 1) * perPage),
|
|
259
|
+
limit: String(perPage),
|
|
260
|
+
...parsedFilter,
|
|
261
|
+
}:{
|
|
262
|
+
order: getOrderBy(field, order, primaryKey),
|
|
263
|
+
offset: String((page - 1) * perPage),
|
|
264
|
+
limit: String(perPage),
|
|
259
265
|
...parsedFilter,
|
|
260
266
|
};
|
|
261
267
|
|
|
@@ -267,7 +273,7 @@ export default (apiUrl, httpClient = fetchUtils.fetchJson, defaultListOp = 'eq',
|
|
|
267
273
|
})
|
|
268
274
|
}
|
|
269
275
|
|
|
270
|
-
const url = `${apiUrl}/${resource}?${
|
|
276
|
+
const url = `${apiUrl}/${resource}?${new URLSearchParams(query)}`;
|
|
271
277
|
|
|
272
278
|
return httpClient(url, options).then(({ headers, json }) => {
|
|
273
279
|
if (!headers.has('content-range')) {
|