Dataset, Entities, and Enums
The Dataset
The Dataset
is the main data structure that you will be working with when writing custom transformations. It is a self-referential data structure that contains Maps
of all the entities. It is recommended that you modify this dataset in place and then return it for the best results.
More importantly, it allows the entities to contain references to each other. For example, a Person
entity has a school_ids
property that is a reference to Schools, however, it also has a schools
property which contains a reference to the actual School entities. This allows you to easily access the related entities without having to do any additional work.
For example to check if a person is enrolled in a class, you can do the following:
import { Dataset } from 'index';
function transform($ctx: Context, $config: Record<string, any>, $input: Dataset): Dataset {
const person = $input.people.get('person_id');
for (const _class of $input.classes.values()) {
const enrollment = _class.enrollments.find((e) => e.person_id === person.id);
if (enrollment) {
// The person is enrolled in this class
console.log(enrollment.role); // 'teacher', 'student', etc.
}
}
return $input;
}
Enums
Edlink uses many enums to standardize values. They can be imported from the index
module. For example:
import { Dataset, Role } from 'index';
function transform($ctx: Context, $config: Record<string, any>, $input: Dataset): Dataset {
console.log(Role.Teacher); // 'teacher'
console.log(Role.Student); // 'student'
return $input;
}
The following enums are available for use in your custom transformations: