@raphiniert/ra-data-postgrest 2.0.0-alpha.0 → 2.0.0-alpha.1

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/esm/index.js CHANGED
@@ -9,8 +9,9 @@ var __assign = (this && this.__assign) || function () {
9
9
  };
10
10
  return __assign.apply(this, arguments);
11
11
  };
12
- import { fetchUtils } from 'ra-core';
12
+ import { fetchUtils, } from 'ra-core';
13
13
  import { getPrimaryKey, parseFilters, getOrderBy, dataWithId, getQuery, getKeyData, encodeId, decodeId, isCompoundKey, } from './urlBuilder';
14
+ import qs from 'qs';
14
15
  /**
15
16
  * Maps react-admin queries to a postgrest REST API
16
17
  *
@@ -34,7 +35,7 @@ import { getPrimaryKey, parseFilters, getOrderBy, dataWithId, getQuery, getKeyDa
34
35
  *
35
36
  * import * as React from 'react';
36
37
  * import { Admin, Resource } from 'react-admin';
37
- * import postgrestRestProvider from '@promitheus/ra-data-postgrest';
38
+ * import postgrestRestProvider from '@raphiniert/ra-data-postgrest';
38
39
  *
39
40
  * import { PostList } from './posts';
40
41
  *
@@ -53,19 +54,24 @@ export default (function (apiUrl, httpClient, defaultListOp, primaryKeys) {
53
54
  if (primaryKeys === void 0) { primaryKeys = defaultPrimaryKeys; }
54
55
  return ({
55
56
  getList: function (resource, params) {
57
+ var _a;
58
+ if (params === void 0) { params = {}; }
56
59
  var primaryKey = getPrimaryKey(resource, primaryKeys);
57
- var _a = params.pagination, page = _a.page, perPage = _a.perPage;
58
- var _b = params.sort, field = _b.field, order = _b.order;
59
- var parsedFilter = parseFilters(params.filter, defaultListOp);
60
- var query = __assign({ order: getOrderBy(field, order, primaryKey), offset: String((page - 1) * perPage), limit: String(perPage) }, parsedFilter);
60
+ var _b = params.pagination, page = _b.page, perPage = _b.perPage;
61
+ var _c = params.sort || {}, field = _c.field, order = _c.order;
62
+ var _d = parseFilters(params, defaultListOp), filter = _d.filter, select = _d.select;
63
+ var query = __assign({ offset: String((page - 1) * perPage), limit: String(perPage) }, filter);
64
+ if (field) {
65
+ query.order = getOrderBy(field, order, primaryKey);
66
+ }
67
+ if (select) {
68
+ query.select = select;
69
+ }
61
70
  // add header that Content-Range is in returned header
62
71
  var options = {
63
- headers: new Headers({
64
- Accept: 'application/json',
65
- Prefer: 'count=exact',
66
- }),
72
+ headers: new Headers(__assign({ Accept: 'application/json', Prefer: 'count=exact' }, (((_a = params.meta) === null || _a === void 0 ? void 0 : _a.headers) || {}))),
67
73
  };
68
- var url = "".concat(apiUrl, "/").concat(resource, "?").concat(new URLSearchParams(query));
74
+ var url = "".concat(apiUrl, "/").concat(resource, "?").concat(qs.stringify(query));
69
75
  return httpClient(url, options).then(function (_a) {
70
76
  var headers = _a.headers, json = _a.json;
71
77
  if (!headers.has('content-range')) {
@@ -78,14 +84,14 @@ export default (function (apiUrl, httpClient, defaultListOp, primaryKeys) {
78
84
  });
79
85
  },
80
86
  getOne: function (resource, params) {
81
- var id = params.id;
87
+ var _a;
88
+ if (params === void 0) { params = {}; }
89
+ var id = params.id, meta = params.meta;
82
90
  var primaryKey = getPrimaryKey(resource, primaryKeys);
83
- var query = getQuery(primaryKey, id, resource);
84
- var url = "".concat(apiUrl, "/").concat(resource, "?").concat(query);
91
+ var query = getQuery(primaryKey, id, resource, meta);
92
+ var url = "".concat(apiUrl, "/").concat(resource, "?").concat(qs.stringify(query));
85
93
  return httpClient(url, {
86
- headers: new Headers({
87
- accept: 'application/vnd.pgrst.object+json',
88
- }),
94
+ headers: new Headers(__assign({ accept: 'application/vnd.pgrst.object+json' }, (((_a = params.meta) === null || _a === void 0 ? void 0 : _a.headers) || {}))),
89
95
  }).then(function (_a) {
90
96
  var json = _a.json;
91
97
  return ({
@@ -94,10 +100,11 @@ export default (function (apiUrl, httpClient, defaultListOp, primaryKeys) {
94
100
  });
95
101
  },
96
102
  getMany: function (resource, params) {
103
+ if (params === void 0) { params = {}; }
97
104
  var ids = params.ids;
98
105
  var primaryKey = getPrimaryKey(resource, primaryKeys);
99
- var query = getQuery(primaryKey, ids, resource);
100
- var url = "".concat(apiUrl, "/").concat(resource, "?").concat(query);
106
+ var query = getQuery(primaryKey, ids, resource, params.meta);
107
+ var url = "".concat(apiUrl, "/").concat(resource, "?").concat(qs.stringify(query));
101
108
  return httpClient(url).then(function (_a) {
102
109
  var json = _a.json;
103
110
  return ({
@@ -107,20 +114,22 @@ export default (function (apiUrl, httpClient, defaultListOp, primaryKeys) {
107
114
  },
108
115
  getManyReference: function (resource, params) {
109
116
  var _a;
110
- var _b = params.pagination, page = _b.page, perPage = _b.perPage;
111
- var _c = params.sort, field = _c.field, order = _c.order;
112
- var parsedFilter = parseFilters(params.filter, defaultListOp);
117
+ var _b;
118
+ if (params === void 0) { params = {}; }
119
+ var _c = params.pagination, page = _c.page, perPage = _c.perPage;
120
+ var _d = params.sort, field = _d.field, order = _d.order;
121
+ var _e = parseFilters(params, defaultListOp), filter = _e.filter, select = _e.select;
113
122
  var primaryKey = getPrimaryKey(resource, primaryKeys);
114
123
  var query = params.target
115
- ? __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);
124
+ ? __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), filter) : __assign({ order: getOrderBy(field, order, primaryKey), offset: String((page - 1) * perPage), limit: String(perPage) }, filter);
125
+ if (select) {
126
+ query.select = select;
127
+ }
116
128
  // add header that Content-Range is in returned header
117
129
  var options = {
118
- headers: new Headers({
119
- Accept: 'application/json',
120
- Prefer: 'count=exact',
121
- }),
130
+ headers: new Headers(__assign({ Accept: 'application/json', Prefer: 'count=exact' }, (((_b = params.meta) === null || _b === void 0 ? void 0 : _b.headers) || {}))),
122
131
  };
123
- var url = "".concat(apiUrl, "/").concat(resource, "?").concat(new URLSearchParams(query));
132
+ var url = "".concat(apiUrl, "/").concat(resource, "?").concat(qs.stringify(query));
124
133
  return httpClient(url, options).then(function (_a) {
125
134
  var headers = _a.headers, json = _a.json;
126
135
  if (!headers.has('content-range')) {
@@ -133,19 +142,17 @@ export default (function (apiUrl, httpClient, defaultListOp, primaryKeys) {
133
142
  });
134
143
  },
135
144
  update: function (resource, params) {
136
- var id = params.id, data = params.data;
145
+ var _a;
146
+ if (params === void 0) { params = {}; }
147
+ var id = params.id, data = params.data, meta = params.meta;
137
148
  var primaryKey = getPrimaryKey(resource, primaryKeys);
138
- var query = getQuery(primaryKey, id, resource);
149
+ var query = getQuery(primaryKey, id, resource, meta);
139
150
  var primaryKeyData = getKeyData(primaryKey, data);
140
- var url = "".concat(apiUrl, "/").concat(resource, "?").concat(query);
151
+ var url = "".concat(apiUrl, "/").concat(resource, "?").concat(qs.stringify(query));
141
152
  var body = JSON.stringify(__assign(__assign({}, data), primaryKeyData));
142
153
  return httpClient(url, {
143
154
  method: 'PATCH',
144
- headers: new Headers({
145
- Accept: 'application/vnd.pgrst.object+json',
146
- Prefer: 'return=representation',
147
- 'Content-Type': 'application/json',
148
- }),
155
+ headers: new Headers(__assign({ Accept: 'application/vnd.pgrst.object+json', Prefer: 'return=representation', 'Content-Type': 'application/json' }, (((_a = params.meta) === null || _a === void 0 ? void 0 : _a.headers) || {}))),
149
156
  body: body,
150
157
  }).then(function (_a) {
151
158
  var json = _a.json;
@@ -153,6 +160,8 @@ export default (function (apiUrl, httpClient, defaultListOp, primaryKeys) {
153
160
  });
154
161
  },
155
162
  updateMany: function (resource, params) {
163
+ var _a;
164
+ if (params === void 0) { params = {}; }
156
165
  var ids = params.ids;
157
166
  var primaryKey = getPrimaryKey(resource, primaryKeys);
158
167
  var body = JSON.stringify(params.ids.map(function (id) {
@@ -172,10 +181,7 @@ export default (function (apiUrl, httpClient, defaultListOp, primaryKeys) {
172
181
  var url = "".concat(apiUrl, "/").concat(resource);
173
182
  return httpClient(url, {
174
183
  method: 'PATCH',
175
- headers: new Headers({
176
- Prefer: 'return=representation',
177
- 'Content-Type': 'application/json',
178
- }),
184
+ headers: new Headers(__assign({ Prefer: 'return=representation', 'Content-Type': 'application/json' }, (((_a = params.meta) === null || _a === void 0 ? void 0 : _a.headers) || {}))),
179
185
  body: body,
180
186
  }).then(function (_a) {
181
187
  var json = _a.json;
@@ -185,51 +191,46 @@ export default (function (apiUrl, httpClient, defaultListOp, primaryKeys) {
185
191
  });
186
192
  },
187
193
  create: function (resource, params) {
194
+ var _a;
195
+ if (params === void 0) { params = {}; }
188
196
  var primaryKey = getPrimaryKey(resource, primaryKeys);
189
197
  var url = "".concat(apiUrl, "/").concat(resource);
190
198
  return httpClient(url, {
191
199
  method: 'POST',
192
- headers: new Headers({
193
- Accept: 'application/vnd.pgrst.object+json',
194
- Prefer: 'return=representation',
195
- 'Content-Type': 'application/json',
196
- }),
200
+ headers: new Headers(__assign({ Accept: 'application/vnd.pgrst.object+json', Prefer: 'return=representation', 'Content-Type': 'application/json' }, (((_a = params.meta) === null || _a === void 0 ? void 0 : _a.headers) || {}))),
197
201
  body: JSON.stringify(params.data),
198
202
  }).then(function (_a) {
199
203
  var json = _a.json;
200
204
  return ({
201
- data: __assign(__assign({}, params.data), { id: encodeId(json, primaryKey) }),
205
+ data: __assign(__assign({}, json), { id: encodeId(json, primaryKey) }),
202
206
  });
203
207
  });
204
208
  },
205
209
  delete: function (resource, params) {
206
- var id = params.id;
210
+ var _a;
211
+ if (params === void 0) { params = {}; }
212
+ var id = params.id, meta = params.meta;
207
213
  var primaryKey = getPrimaryKey(resource, primaryKeys);
208
- var query = getQuery(primaryKey, id, resource);
209
- var url = "".concat(apiUrl, "/").concat(resource, "?").concat(query);
214
+ var query = getQuery(primaryKey, id, resource, meta);
215
+ var url = "".concat(apiUrl, "/").concat(resource, "?").concat(qs.stringify(query));
210
216
  return httpClient(url, {
211
217
  method: 'DELETE',
212
- headers: new Headers({
213
- Accept: 'application/vnd.pgrst.object+json',
214
- Prefer: 'return=representation',
215
- 'Content-Type': 'application/json',
216
- }),
218
+ headers: new Headers(__assign({ Accept: 'application/vnd.pgrst.object+json', Prefer: 'return=representation', 'Content-Type': 'application/json' }, (((_a = params.meta) === null || _a === void 0 ? void 0 : _a.headers) || {}))),
217
219
  }).then(function (_a) {
218
220
  var json = _a.json;
219
221
  return ({ data: dataWithId(json, primaryKey) });
220
222
  });
221
223
  },
222
224
  deleteMany: function (resource, params) {
223
- var ids = params.ids;
225
+ var _a;
226
+ if (params === void 0) { params = {}; }
227
+ var ids = params.ids, meta = params.meta;
224
228
  var primaryKey = getPrimaryKey(resource, primaryKeys);
225
- var query = getQuery(primaryKey, ids, resource);
226
- var url = "".concat(apiUrl, "/").concat(resource, "?").concat(query);
229
+ var query = getQuery(primaryKey, ids, resource, meta);
230
+ var url = "".concat(apiUrl, "/").concat(resource, "?").concat(qs.stringify(query));
227
231
  return httpClient(url, {
228
232
  method: 'DELETE',
229
- headers: new Headers({
230
- Prefer: 'return=representation',
231
- 'Content-Type': 'application/json',
232
- }),
233
+ headers: new Headers(__assign({ Prefer: 'return=representation', 'Content-Type': 'application/json' }, (((_a = params.meta) === null || _a === void 0 ? void 0 : _a.headers) || {}))),
233
234
  }).then(function (_a) {
234
235
  var json = _a.json;
235
236
  return ({
@@ -4,15 +4,19 @@ import { Identifier } from 'ra-core';
4
4
  * (https://postgrest.org/en/stable/api.html#operators)
5
5
  */
6
6
  declare const postgrestOperators: readonly ["eq", "gt", "gte", "lt", "lte", "neq", "like", "ilike", "match", "imatch", "in", "is", "fts", "plfts", "phfts", "wfts", "cs", "cd", "ov", "sl", "sr", "nxr", "nxl", "adj", "not", "or", "and"];
7
- export type PostgRestOperator = typeof postgrestOperators[number];
8
- export declare const parseFilters: (filter: Record<string, any>, defaultListOp: PostgRestOperator) => {};
7
+ type ParsedFiltersResult = {
8
+ filter: any;
9
+ select: any;
10
+ };
11
+ export type PostgRestOperator = (typeof postgrestOperators)[number];
12
+ export declare const parseFilters: (params: any, defaultListOp: PostgRestOperator) => Partial<ParsedFiltersResult>;
9
13
  export type PrimaryKey = Array<string>;
10
14
  export declare const getPrimaryKey: (resource: string, primaryKeys: Map<string, PrimaryKey>) => PrimaryKey;
11
15
  export declare const decodeId: (id: Identifier, primaryKey: PrimaryKey) => string[] | number[];
12
16
  export declare const encodeId: (data: any, primaryKey: PrimaryKey) => Identifier;
13
17
  export declare const dataWithId: (data: any, primaryKey: PrimaryKey) => any;
14
18
  export declare const isCompoundKey: (primaryKey: PrimaryKey) => Boolean;
15
- export declare const getQuery: (primaryKey: PrimaryKey, ids: Identifier | Array<Identifier>, resource: string) => string;
19
+ export declare const getQuery: (primaryKey: PrimaryKey, ids: Identifier | Array<Identifier>, resource: string, meta?: any) => any;
16
20
  export declare const getKeyData: (primaryKey: PrimaryKey, data: object) => object;
17
21
  export declare const getOrderBy: (field: string, order: string, primaryKey: PrimaryKey) => string;
18
22
  export {};
package/esm/urlBuilder.js CHANGED
@@ -42,8 +42,10 @@ var postgrestOperators = [
42
42
  'or',
43
43
  'and',
44
44
  ];
45
- export var parseFilters = function (filter, defaultListOp) {
45
+ export var parseFilters = function (params, defaultListOp) {
46
+ var filter = params.filter, _a = params.meta, meta = _a === void 0 ? {} : _a;
46
47
  var result = {};
48
+ result.filter = {};
47
49
  Object.keys(filter).forEach(function (key) {
48
50
  // key: the name of the object key
49
51
  var splitKey = key.split('@');
@@ -65,22 +67,30 @@ export var parseFilters = function (filter, defaultListOp) {
65
67
  : operation.length == 0
66
68
  ? "".concat(value)
67
69
  : "".concat(operation, ".").concat(value);
68
- if (result[splitKey[0]] === undefined) {
70
+ if (result.filter[splitKey[0]] === undefined) {
69
71
  // first operator for the key, we add it to the dict
70
- result[splitKey[0]] = op;
72
+ result.filter[splitKey[0]] = op;
71
73
  }
72
74
  else {
73
75
  if (!Array.isArray(result[splitKey[0]])) {
74
76
  // second operator, we transform to an array
75
- result[splitKey[0]] = [result[splitKey[0]], op];
77
+ result.filter[splitKey[0]] = [
78
+ result.filter[splitKey[0]],
79
+ op,
80
+ ];
76
81
  }
77
82
  else {
78
83
  // third and subsequent, we add to array
79
- result[splitKey[0]].push(op);
84
+ result.filter[splitKey[0]].push(op);
80
85
  }
81
86
  }
82
87
  });
83
88
  });
89
+ if (meta === null || meta === void 0 ? void 0 : meta.columns) {
90
+ result.select = Array.isArray(meta.columns)
91
+ ? meta.columns.join(',')
92
+ : meta.columns;
93
+ }
84
94
  return result;
85
95
  };
86
96
  export var getPrimaryKey = function (resource, primaryKeys) {
@@ -113,8 +123,10 @@ export var dataWithId = function (data, primaryKey) {
113
123
  export var isCompoundKey = function (primaryKey) {
114
124
  return primaryKey.length > 1;
115
125
  };
116
- export var getQuery = function (primaryKey, ids, resource) {
117
- var _a;
126
+ export var getQuery = function (primaryKey, ids, resource, meta) {
127
+ var _a, _b;
128
+ if (meta === void 0) { meta = null; }
129
+ var result = {};
118
130
  if (Array.isArray(ids) && ids.length > 1) {
119
131
  // no standardized query with multiple ids possible for rpc endpoints which are api-exposed database functions
120
132
  if (resource.startsWith('rpc/')) {
@@ -122,18 +134,19 @@ export var getQuery = function (primaryKey, ids, resource) {
122
134
  return;
123
135
  }
124
136
  if (isCompoundKey(primaryKey)) {
125
- // TODO: Should be URL encoded
126
- return "or=(".concat(ids.map(function (id) {
127
- var primaryKeyParams = decodeId(id, primaryKey);
128
- return "and(".concat(primaryKey
129
- .map(function (key, i) { return "".concat(key, ".eq.").concat(primaryKeyParams[i]); })
130
- .join(','), ")");
131
- }), ")");
137
+ result = {
138
+ or: "(".concat(ids.map(function (id) {
139
+ var primaryKeyParams = decodeId(id, primaryKey);
140
+ return "and(".concat(primaryKey
141
+ .map(function (key, i) { return "".concat(key, ".eq.").concat(primaryKeyParams[i]); })
142
+ .join(','), ")");
143
+ }), ")"),
144
+ };
132
145
  }
133
146
  else {
134
- return new URLSearchParams((_a = {},
147
+ result = (_a = {},
135
148
  _a[primaryKey[0]] = "in.(".concat(ids.join(','), ")"),
136
- _a)).toString();
149
+ _a);
137
150
  }
138
151
  }
139
152
  else {
@@ -141,25 +154,32 @@ export var getQuery = function (primaryKey, ids, resource) {
141
154
  var id = ids.toString();
142
155
  var primaryKeyParams_1 = decodeId(id, primaryKey);
143
156
  if (isCompoundKey(primaryKey)) {
144
- if (resource.startsWith('rpc/'))
145
- // TODO: Should be URL encoded
146
- return "".concat(primaryKey
147
- .map(function (key, i) { return "".concat(key, "=").concat(primaryKeyParams_1[i]); })
148
- .join('&'));
149
- // TODO: Should be URL encoded
150
- else
151
- return "and=(".concat(primaryKey
152
- .map(function (key, i) {
153
- return "".concat(key, ".eq.").concat(primaryKeyParams_1[i]);
154
- })
155
- .join(','), ")");
157
+ if (resource.startsWith('rpc/')) {
158
+ result = {};
159
+ primaryKey.map(function (key, i) {
160
+ return (result[key] = "".concat(primaryKeyParams_1[i]));
161
+ });
162
+ }
163
+ else {
164
+ result = {
165
+ and: "(".concat(primaryKey.map(function (key, i) {
166
+ return "".concat(key, ".eq.").concat(primaryKeyParams_1[i]);
167
+ }), ")"),
168
+ };
169
+ }
156
170
  }
157
171
  else {
158
- return new URLSearchParams([
159
- [primaryKey[0], "eq.".concat(id)],
160
- ]).toString();
172
+ result = (_b = {},
173
+ _b[primaryKey[0]] = "eq.".concat(id),
174
+ _b);
161
175
  }
162
176
  }
177
+ if (meta && meta.columns) {
178
+ result.select = Array.isArray(meta.columns)
179
+ ? meta.columns.join(',')
180
+ : meta.columns;
181
+ }
182
+ return result;
163
183
  };
164
184
  export var getKeyData = function (primaryKey, data) {
165
185
  var _a;
package/lib/index.js CHANGED
@@ -10,9 +10,13 @@ var __assign = (this && this.__assign) || function () {
10
10
  };
11
11
  return __assign.apply(this, arguments);
12
12
  };
13
+ var __importDefault = (this && this.__importDefault) || function (mod) {
14
+ return (mod && mod.__esModule) ? mod : { "default": mod };
15
+ };
13
16
  Object.defineProperty(exports, "__esModule", { value: true });
14
17
  var ra_core_1 = require("ra-core");
15
18
  var urlBuilder_1 = require("./urlBuilder");
19
+ var qs_1 = __importDefault(require("qs"));
16
20
  /**
17
21
  * Maps react-admin queries to a postgrest REST API
18
22
  *
@@ -36,7 +40,7 @@ var urlBuilder_1 = require("./urlBuilder");
36
40
  *
37
41
  * import * as React from 'react';
38
42
  * import { Admin, Resource } from 'react-admin';
39
- * import postgrestRestProvider from '@promitheus/ra-data-postgrest';
43
+ * import postgrestRestProvider from '@raphiniert/ra-data-postgrest';
40
44
  *
41
45
  * import { PostList } from './posts';
42
46
  *
@@ -55,19 +59,24 @@ exports.default = (function (apiUrl, httpClient, defaultListOp, primaryKeys) {
55
59
  if (primaryKeys === void 0) { primaryKeys = defaultPrimaryKeys; }
56
60
  return ({
57
61
  getList: function (resource, params) {
62
+ var _a;
63
+ if (params === void 0) { params = {}; }
58
64
  var primaryKey = (0, urlBuilder_1.getPrimaryKey)(resource, primaryKeys);
59
- var _a = params.pagination, page = _a.page, perPage = _a.perPage;
60
- var _b = params.sort, field = _b.field, order = _b.order;
61
- var parsedFilter = (0, urlBuilder_1.parseFilters)(params.filter, defaultListOp);
62
- var query = __assign({ order: (0, urlBuilder_1.getOrderBy)(field, order, primaryKey), offset: String((page - 1) * perPage), limit: String(perPage) }, parsedFilter);
65
+ var _b = params.pagination, page = _b.page, perPage = _b.perPage;
66
+ var _c = params.sort || {}, field = _c.field, order = _c.order;
67
+ var _d = (0, urlBuilder_1.parseFilters)(params, defaultListOp), filter = _d.filter, select = _d.select;
68
+ var query = __assign({ offset: String((page - 1) * perPage), limit: String(perPage) }, filter);
69
+ if (field) {
70
+ query.order = (0, urlBuilder_1.getOrderBy)(field, order, primaryKey);
71
+ }
72
+ if (select) {
73
+ query.select = select;
74
+ }
63
75
  // add header that Content-Range is in returned header
64
76
  var options = {
65
- headers: new Headers({
66
- Accept: 'application/json',
67
- Prefer: 'count=exact',
68
- }),
77
+ headers: new Headers(__assign({ Accept: 'application/json', Prefer: 'count=exact' }, (((_a = params.meta) === null || _a === void 0 ? void 0 : _a.headers) || {}))),
69
78
  };
70
- var url = "".concat(apiUrl, "/").concat(resource, "?").concat(new URLSearchParams(query));
79
+ var url = "".concat(apiUrl, "/").concat(resource, "?").concat(qs_1.default.stringify(query));
71
80
  return httpClient(url, options).then(function (_a) {
72
81
  var headers = _a.headers, json = _a.json;
73
82
  if (!headers.has('content-range')) {
@@ -80,14 +89,14 @@ exports.default = (function (apiUrl, httpClient, defaultListOp, primaryKeys) {
80
89
  });
81
90
  },
82
91
  getOne: function (resource, params) {
83
- var id = params.id;
92
+ var _a;
93
+ if (params === void 0) { params = {}; }
94
+ var id = params.id, meta = params.meta;
84
95
  var primaryKey = (0, urlBuilder_1.getPrimaryKey)(resource, primaryKeys);
85
- var query = (0, urlBuilder_1.getQuery)(primaryKey, id, resource);
86
- var url = "".concat(apiUrl, "/").concat(resource, "?").concat(query);
96
+ var query = (0, urlBuilder_1.getQuery)(primaryKey, id, resource, meta);
97
+ var url = "".concat(apiUrl, "/").concat(resource, "?").concat(qs_1.default.stringify(query));
87
98
  return httpClient(url, {
88
- headers: new Headers({
89
- accept: 'application/vnd.pgrst.object+json',
90
- }),
99
+ headers: new Headers(__assign({ accept: 'application/vnd.pgrst.object+json' }, (((_a = params.meta) === null || _a === void 0 ? void 0 : _a.headers) || {}))),
91
100
  }).then(function (_a) {
92
101
  var json = _a.json;
93
102
  return ({
@@ -96,10 +105,11 @@ exports.default = (function (apiUrl, httpClient, defaultListOp, primaryKeys) {
96
105
  });
97
106
  },
98
107
  getMany: function (resource, params) {
108
+ if (params === void 0) { params = {}; }
99
109
  var ids = params.ids;
100
110
  var primaryKey = (0, urlBuilder_1.getPrimaryKey)(resource, primaryKeys);
101
- var query = (0, urlBuilder_1.getQuery)(primaryKey, ids, resource);
102
- var url = "".concat(apiUrl, "/").concat(resource, "?").concat(query);
111
+ var query = (0, urlBuilder_1.getQuery)(primaryKey, ids, resource, params.meta);
112
+ var url = "".concat(apiUrl, "/").concat(resource, "?").concat(qs_1.default.stringify(query));
103
113
  return httpClient(url).then(function (_a) {
104
114
  var json = _a.json;
105
115
  return ({
@@ -109,20 +119,22 @@ exports.default = (function (apiUrl, httpClient, defaultListOp, primaryKeys) {
109
119
  },
110
120
  getManyReference: function (resource, params) {
111
121
  var _a;
112
- var _b = params.pagination, page = _b.page, perPage = _b.perPage;
113
- var _c = params.sort, field = _c.field, order = _c.order;
114
- var parsedFilter = (0, urlBuilder_1.parseFilters)(params.filter, defaultListOp);
122
+ var _b;
123
+ if (params === void 0) { params = {}; }
124
+ var _c = params.pagination, page = _c.page, perPage = _c.perPage;
125
+ var _d = params.sort, field = _d.field, order = _d.order;
126
+ var _e = (0, urlBuilder_1.parseFilters)(params, defaultListOp), filter = _e.filter, select = _e.select;
115
127
  var primaryKey = (0, urlBuilder_1.getPrimaryKey)(resource, primaryKeys);
116
128
  var query = params.target
117
- ? __assign((_a = {}, _a[params.target] = "eq.".concat(params.id), _a.order = (0, urlBuilder_1.getOrderBy)(field, order, primaryKey), _a.offset = String((page - 1) * perPage), _a.limit = String(perPage), _a), parsedFilter) : __assign({ order: (0, urlBuilder_1.getOrderBy)(field, order, primaryKey), offset: String((page - 1) * perPage), limit: String(perPage) }, parsedFilter);
129
+ ? __assign((_a = {}, _a[params.target] = "eq.".concat(params.id), _a.order = (0, urlBuilder_1.getOrderBy)(field, order, primaryKey), _a.offset = String((page - 1) * perPage), _a.limit = String(perPage), _a), filter) : __assign({ order: (0, urlBuilder_1.getOrderBy)(field, order, primaryKey), offset: String((page - 1) * perPage), limit: String(perPage) }, filter);
130
+ if (select) {
131
+ query.select = select;
132
+ }
118
133
  // add header that Content-Range is in returned header
119
134
  var options = {
120
- headers: new Headers({
121
- Accept: 'application/json',
122
- Prefer: 'count=exact',
123
- }),
135
+ headers: new Headers(__assign({ Accept: 'application/json', Prefer: 'count=exact' }, (((_b = params.meta) === null || _b === void 0 ? void 0 : _b.headers) || {}))),
124
136
  };
125
- var url = "".concat(apiUrl, "/").concat(resource, "?").concat(new URLSearchParams(query));
137
+ var url = "".concat(apiUrl, "/").concat(resource, "?").concat(qs_1.default.stringify(query));
126
138
  return httpClient(url, options).then(function (_a) {
127
139
  var headers = _a.headers, json = _a.json;
128
140
  if (!headers.has('content-range')) {
@@ -135,19 +147,17 @@ exports.default = (function (apiUrl, httpClient, defaultListOp, primaryKeys) {
135
147
  });
136
148
  },
137
149
  update: function (resource, params) {
138
- var id = params.id, data = params.data;
150
+ var _a;
151
+ if (params === void 0) { params = {}; }
152
+ var id = params.id, data = params.data, meta = params.meta;
139
153
  var primaryKey = (0, urlBuilder_1.getPrimaryKey)(resource, primaryKeys);
140
- var query = (0, urlBuilder_1.getQuery)(primaryKey, id, resource);
154
+ var query = (0, urlBuilder_1.getQuery)(primaryKey, id, resource, meta);
141
155
  var primaryKeyData = (0, urlBuilder_1.getKeyData)(primaryKey, data);
142
- var url = "".concat(apiUrl, "/").concat(resource, "?").concat(query);
156
+ var url = "".concat(apiUrl, "/").concat(resource, "?").concat(qs_1.default.stringify(query));
143
157
  var body = JSON.stringify(__assign(__assign({}, data), primaryKeyData));
144
158
  return httpClient(url, {
145
159
  method: 'PATCH',
146
- headers: new Headers({
147
- Accept: 'application/vnd.pgrst.object+json',
148
- Prefer: 'return=representation',
149
- 'Content-Type': 'application/json',
150
- }),
160
+ headers: new Headers(__assign({ Accept: 'application/vnd.pgrst.object+json', Prefer: 'return=representation', 'Content-Type': 'application/json' }, (((_a = params.meta) === null || _a === void 0 ? void 0 : _a.headers) || {}))),
151
161
  body: body,
152
162
  }).then(function (_a) {
153
163
  var json = _a.json;
@@ -155,6 +165,8 @@ exports.default = (function (apiUrl, httpClient, defaultListOp, primaryKeys) {
155
165
  });
156
166
  },
157
167
  updateMany: function (resource, params) {
168
+ var _a;
169
+ if (params === void 0) { params = {}; }
158
170
  var ids = params.ids;
159
171
  var primaryKey = (0, urlBuilder_1.getPrimaryKey)(resource, primaryKeys);
160
172
  var body = JSON.stringify(params.ids.map(function (id) {
@@ -174,10 +186,7 @@ exports.default = (function (apiUrl, httpClient, defaultListOp, primaryKeys) {
174
186
  var url = "".concat(apiUrl, "/").concat(resource);
175
187
  return httpClient(url, {
176
188
  method: 'PATCH',
177
- headers: new Headers({
178
- Prefer: 'return=representation',
179
- 'Content-Type': 'application/json',
180
- }),
189
+ headers: new Headers(__assign({ Prefer: 'return=representation', 'Content-Type': 'application/json' }, (((_a = params.meta) === null || _a === void 0 ? void 0 : _a.headers) || {}))),
181
190
  body: body,
182
191
  }).then(function (_a) {
183
192
  var json = _a.json;
@@ -187,51 +196,46 @@ exports.default = (function (apiUrl, httpClient, defaultListOp, primaryKeys) {
187
196
  });
188
197
  },
189
198
  create: function (resource, params) {
199
+ var _a;
200
+ if (params === void 0) { params = {}; }
190
201
  var primaryKey = (0, urlBuilder_1.getPrimaryKey)(resource, primaryKeys);
191
202
  var url = "".concat(apiUrl, "/").concat(resource);
192
203
  return httpClient(url, {
193
204
  method: 'POST',
194
- headers: new Headers({
195
- Accept: 'application/vnd.pgrst.object+json',
196
- Prefer: 'return=representation',
197
- 'Content-Type': 'application/json',
198
- }),
205
+ headers: new Headers(__assign({ Accept: 'application/vnd.pgrst.object+json', Prefer: 'return=representation', 'Content-Type': 'application/json' }, (((_a = params.meta) === null || _a === void 0 ? void 0 : _a.headers) || {}))),
199
206
  body: JSON.stringify(params.data),
200
207
  }).then(function (_a) {
201
208
  var json = _a.json;
202
209
  return ({
203
- data: __assign(__assign({}, params.data), { id: (0, urlBuilder_1.encodeId)(json, primaryKey) }),
210
+ data: __assign(__assign({}, json), { id: (0, urlBuilder_1.encodeId)(json, primaryKey) }),
204
211
  });
205
212
  });
206
213
  },
207
214
  delete: function (resource, params) {
208
- var id = params.id;
215
+ var _a;
216
+ if (params === void 0) { params = {}; }
217
+ var id = params.id, meta = params.meta;
209
218
  var primaryKey = (0, urlBuilder_1.getPrimaryKey)(resource, primaryKeys);
210
- var query = (0, urlBuilder_1.getQuery)(primaryKey, id, resource);
211
- var url = "".concat(apiUrl, "/").concat(resource, "?").concat(query);
219
+ var query = (0, urlBuilder_1.getQuery)(primaryKey, id, resource, meta);
220
+ var url = "".concat(apiUrl, "/").concat(resource, "?").concat(qs_1.default.stringify(query));
212
221
  return httpClient(url, {
213
222
  method: 'DELETE',
214
- headers: new Headers({
215
- Accept: 'application/vnd.pgrst.object+json',
216
- Prefer: 'return=representation',
217
- 'Content-Type': 'application/json',
218
- }),
223
+ headers: new Headers(__assign({ Accept: 'application/vnd.pgrst.object+json', Prefer: 'return=representation', 'Content-Type': 'application/json' }, (((_a = params.meta) === null || _a === void 0 ? void 0 : _a.headers) || {}))),
219
224
  }).then(function (_a) {
220
225
  var json = _a.json;
221
226
  return ({ data: (0, urlBuilder_1.dataWithId)(json, primaryKey) });
222
227
  });
223
228
  },
224
229
  deleteMany: function (resource, params) {
225
- var ids = params.ids;
230
+ var _a;
231
+ if (params === void 0) { params = {}; }
232
+ var ids = params.ids, meta = params.meta;
226
233
  var primaryKey = (0, urlBuilder_1.getPrimaryKey)(resource, primaryKeys);
227
- var query = (0, urlBuilder_1.getQuery)(primaryKey, ids, resource);
228
- var url = "".concat(apiUrl, "/").concat(resource, "?").concat(query);
234
+ var query = (0, urlBuilder_1.getQuery)(primaryKey, ids, resource, meta);
235
+ var url = "".concat(apiUrl, "/").concat(resource, "?").concat(qs_1.default.stringify(query));
229
236
  return httpClient(url, {
230
237
  method: 'DELETE',
231
- headers: new Headers({
232
- Prefer: 'return=representation',
233
- 'Content-Type': 'application/json',
234
- }),
238
+ headers: new Headers(__assign({ Prefer: 'return=representation', 'Content-Type': 'application/json' }, (((_a = params.meta) === null || _a === void 0 ? void 0 : _a.headers) || {}))),
235
239
  }).then(function (_a) {
236
240
  var json = _a.json;
237
241
  return ({