@raphiniert/ra-data-postgrest 1.1.8 → 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 +6 -3
- package/README.md +2 -6
- package/esm/dataProvider/index.js +22 -23
- package/lib/dataProvider/index.js +22 -23
- package/package.json +4 -7
- package/src/dataProvider/index.ts +10 -11
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,9 @@
|
|
|
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
|
+
|
|
5
8
|
## v1.1.8 - 2022-01-07
|
|
6
9
|
- required re-release as I missed to transpile all and upload the features of 1.1.7 to npm.
|
|
7
10
|
|
|
@@ -10,12 +13,12 @@ Find all notable changes of this project in this file.
|
|
|
10
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)
|
|
11
14
|
|
|
12
15
|
### 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)
|
|
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)
|
|
14
17
|
|
|
15
18
|
|
|
16
19
|
## v1.1.6 - 2021-01-16
|
|
17
20
|
### 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)
|
|
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)
|
|
19
22
|
|
|
20
23
|
## v1.1.5 - 2021-01-16
|
|
21
24
|
### Fixes
|
|
@@ -56,7 +59,7 @@ Find all notable changes of this project in this file.
|
|
|
56
59
|
|
|
57
60
|
## v1.0.7 - 2020-08-23
|
|
58
61
|
### New feature
|
|
59
|
-
- [#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)
|
|
60
63
|
|
|
61
64
|
### Maintenance
|
|
62
65
|
- `import React from 'react';` -> `import * as React from 'react';`
|
package/README.md
CHANGED
|
@@ -135,15 +135,11 @@ 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
|
-
|
|
139
|
-
|
|
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)
|
|
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:
|
|
143
140
|
|
|
144
141
|
```jsx
|
|
145
142
|
<Filter {...props}>
|
|
146
|
-
<TextInput label="Search" source="post_title" alwaysOn />
|
|
147
143
|
<TextInput label="Search" source="post_author@" alwaysOn />
|
|
148
144
|
// some more filters
|
|
149
145
|
</Filter>
|
|
@@ -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
|
|
@@ -73,7 +72,7 @@ function parseFilters(filter, defaultListOp) {
|
|
|
73
72
|
}
|
|
74
73
|
values.forEach(function (value) {
|
|
75
74
|
// if operator is intentionally blank, rpc syntax
|
|
76
|
-
var op = operation.includes('like') ? operation
|
|
75
|
+
var op = operation.includes('like') ? "".concat(operation, ".*").concat(value, "*") : operation.length == 0 ? "".concat(value) : "".concat(operation, ".").concat(value);
|
|
77
76
|
if (result[splitKey[0]] === undefined) {
|
|
78
77
|
// first operator for the key, we add it to the dict
|
|
79
78
|
result[splitKey[0]] = op;
|
|
@@ -123,7 +122,7 @@ var isCompoundKey = function (primaryKey) {
|
|
|
123
122
|
return primaryKey.length > 1;
|
|
124
123
|
};
|
|
125
124
|
var getQuery = function (primaryKey, ids, resource) {
|
|
126
|
-
var _a
|
|
125
|
+
var _a;
|
|
127
126
|
if (Array.isArray(ids) && ids.length > 1) {
|
|
128
127
|
// no standardized query with multiple ids possible for rpc endpoints which are api-exposed database functions
|
|
129
128
|
if (resource.startsWith('rpc/')) {
|
|
@@ -131,13 +130,13 @@ var getQuery = function (primaryKey, ids, resource) {
|
|
|
131
130
|
return;
|
|
132
131
|
}
|
|
133
132
|
if (isCompoundKey(primaryKey)) {
|
|
134
|
-
return "or=(\n "
|
|
133
|
+
return "or=(\n ".concat(ids.map(function (id) {
|
|
135
134
|
var primaryKeyParams = decodeId(id, primaryKey);
|
|
136
|
-
return "and("
|
|
137
|
-
})
|
|
135
|
+
return "and(".concat(primaryKey.map(function (key, i) { return "".concat(key, ".eq.").concat(primaryKeyParams[i]); }).join(','), ")");
|
|
136
|
+
}), "\n )");
|
|
138
137
|
}
|
|
139
138
|
else {
|
|
140
|
-
return
|
|
139
|
+
return new URLSearchParams((_a = {}, _a[primaryKey[0]] = "in.(".concat(ids.join(','), ")"), _a)).toString();
|
|
141
140
|
}
|
|
142
141
|
}
|
|
143
142
|
else {
|
|
@@ -146,12 +145,12 @@ var getQuery = function (primaryKey, ids, resource) {
|
|
|
146
145
|
var primaryKeyParams_1 = decodeId(id, primaryKey);
|
|
147
146
|
if (isCompoundKey(primaryKey)) {
|
|
148
147
|
if (resource.startsWith('rpc/'))
|
|
149
|
-
return ""
|
|
148
|
+
return "".concat(primaryKey.map(function (key, i) { return "".concat(key, "=").concat(primaryKeyParams_1[i]); }).join('&'));
|
|
150
149
|
else
|
|
151
|
-
return "and=("
|
|
150
|
+
return "and=(".concat(primaryKey.map(function (key, i) { return "".concat(key, ".eq.").concat(primaryKeyParams_1[i]); }).join(','), ")");
|
|
152
151
|
}
|
|
153
152
|
else {
|
|
154
|
-
return
|
|
153
|
+
return new URLSearchParams([[primaryKey[0], "eq.".concat(id)]]).toString();
|
|
155
154
|
}
|
|
156
155
|
}
|
|
157
156
|
};
|
|
@@ -169,10 +168,10 @@ var getKeyData = function (primaryKey, data) {
|
|
|
169
168
|
};
|
|
170
169
|
var getOrderBy = function (field, order, primaryKey) {
|
|
171
170
|
if (field == 'id') {
|
|
172
|
-
return primaryKey.map(function (key) { return (key
|
|
171
|
+
return primaryKey.map(function (key) { return ("".concat(key, ".").concat(order.toLowerCase())); }).join(',');
|
|
173
172
|
}
|
|
174
173
|
else {
|
|
175
|
-
return field
|
|
174
|
+
return "".concat(field, ".").concat(order.toLowerCase());
|
|
176
175
|
}
|
|
177
176
|
};
|
|
178
177
|
var defaultPrimaryKeys = new Map();
|
|
@@ -186,7 +185,7 @@ export default (function (apiUrl, httpClient, defaultListOp, primaryKeys) {
|
|
|
186
185
|
var _a = params.pagination, page = _a.page, perPage = _a.perPage;
|
|
187
186
|
var _b = params.sort, field = _b.field, order = _b.order;
|
|
188
187
|
var parsedFilter = parseFilters(params.filter, defaultListOp);
|
|
189
|
-
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);
|
|
190
189
|
// add header that Content-Range is in returned header
|
|
191
190
|
var options = {
|
|
192
191
|
headers: new Headers({
|
|
@@ -194,7 +193,7 @@ export default (function (apiUrl, httpClient, defaultListOp, primaryKeys) {
|
|
|
194
193
|
Prefer: 'count=exact'
|
|
195
194
|
})
|
|
196
195
|
};
|
|
197
|
-
var url = apiUrl
|
|
196
|
+
var url = "".concat(apiUrl, "/").concat(resource, "?").concat(new URLSearchParams(query));
|
|
198
197
|
return httpClient(url, options).then(function (_a) {
|
|
199
198
|
var headers = _a.headers, json = _a.json;
|
|
200
199
|
if (!headers.has('content-range')) {
|
|
@@ -213,7 +212,7 @@ export default (function (apiUrl, httpClient, defaultListOp, primaryKeys) {
|
|
|
213
212
|
var id = params.id;
|
|
214
213
|
var primaryKey = getPrimaryKey(resource, primaryKeys);
|
|
215
214
|
var query = getQuery(primaryKey, id, resource);
|
|
216
|
-
var url = apiUrl
|
|
215
|
+
var url = "".concat(apiUrl, "/").concat(resource, "?").concat(query);
|
|
217
216
|
return httpClient(url, {
|
|
218
217
|
headers: new Headers({ 'accept': 'application/vnd.pgrst.object+json' }),
|
|
219
218
|
}).then(function (_a) {
|
|
@@ -227,7 +226,7 @@ export default (function (apiUrl, httpClient, defaultListOp, primaryKeys) {
|
|
|
227
226
|
var ids = params.ids;
|
|
228
227
|
var primaryKey = getPrimaryKey(resource, primaryKeys);
|
|
229
228
|
var query = getQuery(primaryKey, ids, resource);
|
|
230
|
-
var url = apiUrl
|
|
229
|
+
var url = "".concat(apiUrl, "/").concat(resource, "?").concat(query);
|
|
231
230
|
return httpClient(url).then(function (_a) {
|
|
232
231
|
var json = _a.json;
|
|
233
232
|
return ({ data: json.map(function (data) { return dataWithId(data, primaryKey); }) });
|
|
@@ -239,7 +238,7 @@ export default (function (apiUrl, httpClient, defaultListOp, primaryKeys) {
|
|
|
239
238
|
var _c = params.sort, field = _c.field, order = _c.order;
|
|
240
239
|
var parsedFilter = parseFilters(params.filter, defaultListOp);
|
|
241
240
|
var primaryKey = getPrimaryKey(resource, primaryKeys);
|
|
242
|
-
var query = params.target ? __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);
|
|
243
242
|
// add header that Content-Range is in returned header
|
|
244
243
|
var options = {
|
|
245
244
|
headers: new Headers({
|
|
@@ -247,7 +246,7 @@ export default (function (apiUrl, httpClient, defaultListOp, primaryKeys) {
|
|
|
247
246
|
Prefer: 'count=exact'
|
|
248
247
|
})
|
|
249
248
|
};
|
|
250
|
-
var url = apiUrl
|
|
249
|
+
var url = "".concat(apiUrl, "/").concat(resource, "?").concat(new URLSearchParams(query));
|
|
251
250
|
return httpClient(url, options).then(function (_a) {
|
|
252
251
|
var headers = _a.headers, json = _a.json;
|
|
253
252
|
if (!headers.has('content-range')) {
|
|
@@ -267,7 +266,7 @@ export default (function (apiUrl, httpClient, defaultListOp, primaryKeys) {
|
|
|
267
266
|
var primaryKey = getPrimaryKey(resource, primaryKeys);
|
|
268
267
|
var query = getQuery(primaryKey, id, resource);
|
|
269
268
|
var primaryKeyData = getKeyData(primaryKey, data);
|
|
270
|
-
var url = apiUrl
|
|
269
|
+
var url = "".concat(apiUrl, "/").concat(resource, "?").concat(query);
|
|
271
270
|
var body = JSON.stringify(__assign(__assign({}, data), primaryKeyData));
|
|
272
271
|
return httpClient(url, {
|
|
273
272
|
method: 'PATCH',
|
|
@@ -291,7 +290,7 @@ export default (function (apiUrl, httpClient, defaultListOp, primaryKeys) {
|
|
|
291
290
|
var primaryKeyData = getKeyData(primaryKey, data);
|
|
292
291
|
return __assign(__assign({}, data), primaryKeyData);
|
|
293
292
|
}));
|
|
294
|
-
var url = apiUrl
|
|
293
|
+
var url = "".concat(apiUrl, "/").concat(resource, "?").concat(query);
|
|
295
294
|
return httpClient(url, {
|
|
296
295
|
method: 'PATCH',
|
|
297
296
|
headers: new Headers({
|
|
@@ -308,7 +307,7 @@ export default (function (apiUrl, httpClient, defaultListOp, primaryKeys) {
|
|
|
308
307
|
},
|
|
309
308
|
create: function (resource, params) {
|
|
310
309
|
var primaryKey = getPrimaryKey(resource, primaryKeys);
|
|
311
|
-
var url = apiUrl
|
|
310
|
+
var url = "".concat(apiUrl, "/").concat(resource);
|
|
312
311
|
return httpClient(url, {
|
|
313
312
|
method: 'POST',
|
|
314
313
|
headers: new Headers({
|
|
@@ -328,7 +327,7 @@ export default (function (apiUrl, httpClient, defaultListOp, primaryKeys) {
|
|
|
328
327
|
var id = params.id;
|
|
329
328
|
var primaryKey = getPrimaryKey(resource, primaryKeys);
|
|
330
329
|
var query = getQuery(primaryKey, id, resource);
|
|
331
|
-
var url = apiUrl
|
|
330
|
+
var url = "".concat(apiUrl, "/").concat(resource, "?").concat(query);
|
|
332
331
|
return httpClient(url, {
|
|
333
332
|
method: 'DELETE',
|
|
334
333
|
headers: new Headers({
|
|
@@ -345,7 +344,7 @@ export default (function (apiUrl, httpClient, defaultListOp, primaryKeys) {
|
|
|
345
344
|
var ids = params.ids;
|
|
346
345
|
var primaryKey = getPrimaryKey(resource, primaryKeys);
|
|
347
346
|
var query = getQuery(primaryKey, ids, resource);
|
|
348
|
-
var url = apiUrl
|
|
347
|
+
var url = "".concat(apiUrl, "/").concat(resource, "?").concat(query);
|
|
349
348
|
return httpClient(url, {
|
|
350
349
|
method: 'DELETE',
|
|
351
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
|
|
@@ -75,7 +74,7 @@ function parseFilters(filter, defaultListOp) {
|
|
|
75
74
|
}
|
|
76
75
|
values.forEach(function (value) {
|
|
77
76
|
// if operator is intentionally blank, rpc syntax
|
|
78
|
-
var op = operation.includes('like') ? operation
|
|
77
|
+
var op = operation.includes('like') ? "".concat(operation, ".*").concat(value, "*") : operation.length == 0 ? "".concat(value) : "".concat(operation, ".").concat(value);
|
|
79
78
|
if (result[splitKey[0]] === undefined) {
|
|
80
79
|
// first operator for the key, we add it to the dict
|
|
81
80
|
result[splitKey[0]] = op;
|
|
@@ -125,7 +124,7 @@ var isCompoundKey = function (primaryKey) {
|
|
|
125
124
|
return primaryKey.length > 1;
|
|
126
125
|
};
|
|
127
126
|
var getQuery = function (primaryKey, ids, resource) {
|
|
128
|
-
var _a
|
|
127
|
+
var _a;
|
|
129
128
|
if (Array.isArray(ids) && ids.length > 1) {
|
|
130
129
|
// no standardized query with multiple ids possible for rpc endpoints which are api-exposed database functions
|
|
131
130
|
if (resource.startsWith('rpc/')) {
|
|
@@ -133,13 +132,13 @@ var getQuery = function (primaryKey, ids, resource) {
|
|
|
133
132
|
return;
|
|
134
133
|
}
|
|
135
134
|
if (isCompoundKey(primaryKey)) {
|
|
136
|
-
return "or=(\n "
|
|
135
|
+
return "or=(\n ".concat(ids.map(function (id) {
|
|
137
136
|
var primaryKeyParams = decodeId(id, primaryKey);
|
|
138
|
-
return "and("
|
|
139
|
-
})
|
|
137
|
+
return "and(".concat(primaryKey.map(function (key, i) { return "".concat(key, ".eq.").concat(primaryKeyParams[i]); }).join(','), ")");
|
|
138
|
+
}), "\n )");
|
|
140
139
|
}
|
|
141
140
|
else {
|
|
142
|
-
return
|
|
141
|
+
return new URLSearchParams((_a = {}, _a[primaryKey[0]] = "in.(".concat(ids.join(','), ")"), _a)).toString();
|
|
143
142
|
}
|
|
144
143
|
}
|
|
145
144
|
else {
|
|
@@ -148,12 +147,12 @@ var getQuery = function (primaryKey, ids, resource) {
|
|
|
148
147
|
var primaryKeyParams_1 = decodeId(id, primaryKey);
|
|
149
148
|
if (isCompoundKey(primaryKey)) {
|
|
150
149
|
if (resource.startsWith('rpc/'))
|
|
151
|
-
return ""
|
|
150
|
+
return "".concat(primaryKey.map(function (key, i) { return "".concat(key, "=").concat(primaryKeyParams_1[i]); }).join('&'));
|
|
152
151
|
else
|
|
153
|
-
return "and=("
|
|
152
|
+
return "and=(".concat(primaryKey.map(function (key, i) { return "".concat(key, ".eq.").concat(primaryKeyParams_1[i]); }).join(','), ")");
|
|
154
153
|
}
|
|
155
154
|
else {
|
|
156
|
-
return
|
|
155
|
+
return new URLSearchParams([[primaryKey[0], "eq.".concat(id)]]).toString();
|
|
157
156
|
}
|
|
158
157
|
}
|
|
159
158
|
};
|
|
@@ -171,10 +170,10 @@ var getKeyData = function (primaryKey, data) {
|
|
|
171
170
|
};
|
|
172
171
|
var getOrderBy = function (field, order, primaryKey) {
|
|
173
172
|
if (field == 'id') {
|
|
174
|
-
return primaryKey.map(function (key) { return (key
|
|
173
|
+
return primaryKey.map(function (key) { return ("".concat(key, ".").concat(order.toLowerCase())); }).join(',');
|
|
175
174
|
}
|
|
176
175
|
else {
|
|
177
|
-
return field
|
|
176
|
+
return "".concat(field, ".").concat(order.toLowerCase());
|
|
178
177
|
}
|
|
179
178
|
};
|
|
180
179
|
var defaultPrimaryKeys = new Map();
|
|
@@ -188,7 +187,7 @@ exports.default = (function (apiUrl, httpClient, defaultListOp, primaryKeys) {
|
|
|
188
187
|
var _a = params.pagination, page = _a.page, perPage = _a.perPage;
|
|
189
188
|
var _b = params.sort, field = _b.field, order = _b.order;
|
|
190
189
|
var parsedFilter = parseFilters(params.filter, defaultListOp);
|
|
191
|
-
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);
|
|
192
191
|
// add header that Content-Range is in returned header
|
|
193
192
|
var options = {
|
|
194
193
|
headers: new Headers({
|
|
@@ -196,7 +195,7 @@ exports.default = (function (apiUrl, httpClient, defaultListOp, primaryKeys) {
|
|
|
196
195
|
Prefer: 'count=exact'
|
|
197
196
|
})
|
|
198
197
|
};
|
|
199
|
-
var url = apiUrl
|
|
198
|
+
var url = "".concat(apiUrl, "/").concat(resource, "?").concat(new URLSearchParams(query));
|
|
200
199
|
return httpClient(url, options).then(function (_a) {
|
|
201
200
|
var headers = _a.headers, json = _a.json;
|
|
202
201
|
if (!headers.has('content-range')) {
|
|
@@ -215,7 +214,7 @@ exports.default = (function (apiUrl, httpClient, defaultListOp, primaryKeys) {
|
|
|
215
214
|
var id = params.id;
|
|
216
215
|
var primaryKey = getPrimaryKey(resource, primaryKeys);
|
|
217
216
|
var query = getQuery(primaryKey, id, resource);
|
|
218
|
-
var url = apiUrl
|
|
217
|
+
var url = "".concat(apiUrl, "/").concat(resource, "?").concat(query);
|
|
219
218
|
return httpClient(url, {
|
|
220
219
|
headers: new Headers({ 'accept': 'application/vnd.pgrst.object+json' }),
|
|
221
220
|
}).then(function (_a) {
|
|
@@ -229,7 +228,7 @@ exports.default = (function (apiUrl, httpClient, defaultListOp, primaryKeys) {
|
|
|
229
228
|
var ids = params.ids;
|
|
230
229
|
var primaryKey = getPrimaryKey(resource, primaryKeys);
|
|
231
230
|
var query = getQuery(primaryKey, ids, resource);
|
|
232
|
-
var url = apiUrl
|
|
231
|
+
var url = "".concat(apiUrl, "/").concat(resource, "?").concat(query);
|
|
233
232
|
return httpClient(url).then(function (_a) {
|
|
234
233
|
var json = _a.json;
|
|
235
234
|
return ({ data: json.map(function (data) { return dataWithId(data, primaryKey); }) });
|
|
@@ -241,7 +240,7 @@ exports.default = (function (apiUrl, httpClient, defaultListOp, primaryKeys) {
|
|
|
241
240
|
var _c = params.sort, field = _c.field, order = _c.order;
|
|
242
241
|
var parsedFilter = parseFilters(params.filter, defaultListOp);
|
|
243
242
|
var primaryKey = getPrimaryKey(resource, primaryKeys);
|
|
244
|
-
var query = params.target ? __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);
|
|
245
244
|
// add header that Content-Range is in returned header
|
|
246
245
|
var options = {
|
|
247
246
|
headers: new Headers({
|
|
@@ -249,7 +248,7 @@ exports.default = (function (apiUrl, httpClient, defaultListOp, primaryKeys) {
|
|
|
249
248
|
Prefer: 'count=exact'
|
|
250
249
|
})
|
|
251
250
|
};
|
|
252
|
-
var url = apiUrl
|
|
251
|
+
var url = "".concat(apiUrl, "/").concat(resource, "?").concat(new URLSearchParams(query));
|
|
253
252
|
return httpClient(url, options).then(function (_a) {
|
|
254
253
|
var headers = _a.headers, json = _a.json;
|
|
255
254
|
if (!headers.has('content-range')) {
|
|
@@ -269,7 +268,7 @@ exports.default = (function (apiUrl, httpClient, defaultListOp, primaryKeys) {
|
|
|
269
268
|
var primaryKey = getPrimaryKey(resource, primaryKeys);
|
|
270
269
|
var query = getQuery(primaryKey, id, resource);
|
|
271
270
|
var primaryKeyData = getKeyData(primaryKey, data);
|
|
272
|
-
var url = apiUrl
|
|
271
|
+
var url = "".concat(apiUrl, "/").concat(resource, "?").concat(query);
|
|
273
272
|
var body = JSON.stringify(__assign(__assign({}, data), primaryKeyData));
|
|
274
273
|
return httpClient(url, {
|
|
275
274
|
method: 'PATCH',
|
|
@@ -293,7 +292,7 @@ exports.default = (function (apiUrl, httpClient, defaultListOp, primaryKeys) {
|
|
|
293
292
|
var primaryKeyData = getKeyData(primaryKey, data);
|
|
294
293
|
return __assign(__assign({}, data), primaryKeyData);
|
|
295
294
|
}));
|
|
296
|
-
var url = apiUrl
|
|
295
|
+
var url = "".concat(apiUrl, "/").concat(resource, "?").concat(query);
|
|
297
296
|
return httpClient(url, {
|
|
298
297
|
method: 'PATCH',
|
|
299
298
|
headers: new Headers({
|
|
@@ -310,7 +309,7 @@ exports.default = (function (apiUrl, httpClient, defaultListOp, primaryKeys) {
|
|
|
310
309
|
},
|
|
311
310
|
create: function (resource, params) {
|
|
312
311
|
var primaryKey = getPrimaryKey(resource, primaryKeys);
|
|
313
|
-
var url = apiUrl
|
|
312
|
+
var url = "".concat(apiUrl, "/").concat(resource);
|
|
314
313
|
return httpClient(url, {
|
|
315
314
|
method: 'POST',
|
|
316
315
|
headers: new Headers({
|
|
@@ -330,7 +329,7 @@ exports.default = (function (apiUrl, httpClient, defaultListOp, primaryKeys) {
|
|
|
330
329
|
var id = params.id;
|
|
331
330
|
var primaryKey = getPrimaryKey(resource, primaryKeys);
|
|
332
331
|
var query = getQuery(primaryKey, id, resource);
|
|
333
|
-
var url = apiUrl
|
|
332
|
+
var url = "".concat(apiUrl, "/").concat(resource, "?").concat(query);
|
|
334
333
|
return httpClient(url, {
|
|
335
334
|
method: 'DELETE',
|
|
336
335
|
headers: new Headers({
|
|
@@ -347,7 +346,7 @@ exports.default = (function (apiUrl, httpClient, defaultListOp, primaryKeys) {
|
|
|
347
346
|
var ids = params.ids;
|
|
348
347
|
var primaryKey = getPrimaryKey(resource, primaryKeys);
|
|
349
348
|
var query = getQuery(primaryKey, ids, resource);
|
|
350
|
-
var url = apiUrl
|
|
349
|
+
var url = "".concat(apiUrl, "/").concat(resource, "?").concat(query);
|
|
351
350
|
return httpClient(url, {
|
|
352
351
|
method: 'DELETE',
|
|
353
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,14 +26,11 @@
|
|
|
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
36
|
"ra-core": "^3.19.6"
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { stringify } from 'query-string';
|
|
2
1
|
import { fetchUtils, DataProvider, Identifier } from 'ra-core';
|
|
3
2
|
|
|
4
3
|
/**
|
|
@@ -132,7 +131,7 @@ const getQuery = (primaryKey : PrimaryKey, ids: Identifier | Array<Identifier>,
|
|
|
132
131
|
}
|
|
133
132
|
)`;
|
|
134
133
|
} else {
|
|
135
|
-
return
|
|
134
|
+
return new URLSearchParams({ [primaryKey[0]]: `in.(${ids.join(',')})` }).toString();
|
|
136
135
|
}
|
|
137
136
|
} else {
|
|
138
137
|
// if ids is one Identifier
|
|
@@ -145,7 +144,7 @@ const getQuery = (primaryKey : PrimaryKey, ids: Identifier | Array<Identifier>,
|
|
|
145
144
|
else
|
|
146
145
|
return `and=(${primaryKey.map((key : string, i: any) => `${key}.eq.${primaryKeyParams[i]}`).join(',')})`;
|
|
147
146
|
} else {
|
|
148
|
-
return
|
|
147
|
+
return new URLSearchParams([[primaryKey[0], `eq.${id}`]]).toString();
|
|
149
148
|
}
|
|
150
149
|
}
|
|
151
150
|
}
|
|
@@ -184,8 +183,8 @@ export default (apiUrl, httpClient = fetchUtils.fetchJson, defaultListOp = 'eq',
|
|
|
184
183
|
|
|
185
184
|
const query = {
|
|
186
185
|
order: getOrderBy(field, order, primaryKey),
|
|
187
|
-
offset: (page - 1) * perPage,
|
|
188
|
-
limit: perPage,
|
|
186
|
+
offset: String((page - 1) * perPage),
|
|
187
|
+
limit: String(perPage),
|
|
189
188
|
// append filters
|
|
190
189
|
...parsedFilter
|
|
191
190
|
};
|
|
@@ -198,7 +197,7 @@ export default (apiUrl, httpClient = fetchUtils.fetchJson, defaultListOp = 'eq',
|
|
|
198
197
|
})
|
|
199
198
|
};
|
|
200
199
|
|
|
201
|
-
const url = `${apiUrl}/${resource}?${
|
|
200
|
+
const url = `${apiUrl}/${resource}?${new URLSearchParams(query)}`;
|
|
202
201
|
|
|
203
202
|
return httpClient(url, options).then(({ headers, json }) => {
|
|
204
203
|
if (!headers.has('content-range')) {
|
|
@@ -256,13 +255,13 @@ export default (apiUrl, httpClient = fetchUtils.fetchJson, defaultListOp = 'eq',
|
|
|
256
255
|
const query = params.target ? {
|
|
257
256
|
[params.target]: `eq.${params.id}`,
|
|
258
257
|
order: getOrderBy(field, order, primaryKey),
|
|
259
|
-
offset: (page - 1) * perPage,
|
|
260
|
-
limit: perPage,
|
|
258
|
+
offset: String((page - 1) * perPage),
|
|
259
|
+
limit: String(perPage),
|
|
261
260
|
...parsedFilter,
|
|
262
261
|
}:{
|
|
263
262
|
order: getOrderBy(field, order, primaryKey),
|
|
264
|
-
offset: (page - 1) * perPage,
|
|
265
|
-
limit: perPage,
|
|
263
|
+
offset: String((page - 1) * perPage),
|
|
264
|
+
limit: String(perPage),
|
|
266
265
|
...parsedFilter,
|
|
267
266
|
};
|
|
268
267
|
|
|
@@ -274,7 +273,7 @@ export default (apiUrl, httpClient = fetchUtils.fetchJson, defaultListOp = 'eq',
|
|
|
274
273
|
})
|
|
275
274
|
}
|
|
276
275
|
|
|
277
|
-
const url = `${apiUrl}/${resource}?${
|
|
276
|
+
const url = `${apiUrl}/${resource}?${new URLSearchParams(query)}`;
|
|
278
277
|
|
|
279
278
|
return httpClient(url, options).then(({ headers, json }) => {
|
|
280
279
|
if (!headers.has('content-range')) {
|