|
1 | | -/* eslint-disable eqeqeq */ |
2 | 1 | import fakeRestProvider from 'ra-data-fakerest'; |
3 | 2 | import { DataProvider, RaRecord } from 'ra-core'; |
4 | 3 | import pullAt from 'lodash/pullAt.js'; |
@@ -255,31 +254,34 @@ export default (params?: LocalStorageDataProviderParams): DataProvider => { |
255 | 254 | }; |
256 | 255 | }; |
257 | 256 |
|
258 | | -const getResourceCollection = (data, resource) => { |
| 257 | +const getResourceCollection = (data: Record<string, any>, resource: string) => { |
259 | 258 | if (!Object.prototype.hasOwnProperty.call(data, resource)) { |
260 | 259 | throw new Error(`Unknown resource key: ${resource}`); |
261 | 260 | } |
262 | 261 |
|
263 | 262 | return data[resource]; |
264 | 263 | }; |
265 | 264 |
|
266 | | -const getOrCreateResourceCollection = (data, resource) => { |
| 265 | +const getOrCreateResourceCollection = ( |
| 266 | + data: Record<string, any>, |
| 267 | + resource: string |
| 268 | +) => { |
267 | 269 | if (!Object.prototype.hasOwnProperty.call(data, resource)) { |
268 | 270 | data[resource] = []; |
269 | 271 | } |
270 | 272 |
|
271 | 273 | return data[resource]; |
272 | 274 | }; |
273 | 275 |
|
274 | | -const checkResource = resource => { |
| 276 | +const checkResource = (resource: string) => { |
275 | 277 | // Reject "__proto__" so dynamic writes like data[resource] = value don't |
276 | 278 | // mutate Object.prototype instead of creating a normal resource collection. |
277 | 279 | if (resource === '__proto__') { |
278 | 280 | throw new Error(`Invalid resource key: ${resource}`); |
279 | 281 | } |
280 | 282 | }; |
281 | 283 |
|
282 | | -const assertRecordsExist = (resourceData, ids) => { |
| 284 | +const assertRecordsExist = (resourceData: any[], ids: any[]) => { |
283 | 285 | ids.forEach(id => { |
284 | 286 | if (resourceData.findIndex(record => record.id == id) === -1) { |
285 | 287 | throw new Error(`No item with identifier ${id}`); |
|
0 commit comments