-
Notifications
You must be signed in to change notification settings - Fork 727
Expand file tree
/
Copy pathpopulator.ts
More file actions
28 lines (25 loc) · 955 Bytes
/
populator.ts
File metadata and controls
28 lines (25 loc) · 955 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
import BaseRecord from '../../adapters/record/base-record.js'
import { populateProperty } from './populate-property.js'
import { ActionContext } from '../../actions/index.js'
/**
* @load ./populator.doc.md
* @param {Array<BaseRecord>} records
* @param context
* @new In version 3.3
*/
export async function populator(
records: Array<BaseRecord>,
context?:ActionContext,
): Promise<Array<BaseRecord>> {
if (!records || !records.length) {
return records
}
const resourceDecorator = records[0].resource.decorate()
const allProperties = Object.values(resourceDecorator.getFlattenProperties())
const references = allProperties.filter((p) => !!p.reference() && (p.isVisible('show') || p.isVisible('list') || p.isVisible('edit') || p.isVisible('filter')))
await Promise.all(references.map(async (propertyDecorator) => {
await populateProperty(records, propertyDecorator, context)
}))
return records
}
export default populator