const HappyNumbers = class HappyNumbers extends Collection {
fields = {
number: new FieldTypes.Int(),
double_number: new FieldTypes.CachedValue(
new FieldTypes.Int(),
{
get_value: async (
context: Context,
number_id: string
) => {
const response = await new ItemList(
app.collections["happy-numbers"],
context
)
.ids([number_id])
.fetch();
return (
response.items[0].get("number") * 2
);
},
refresh_on: [
{
event: new EventDescription(
"happy-numbers",
"after:create"
),
resource_id_getter: async (
- _: any,
+ _,
item
) => [item.id],
},
],
initial_value: 0,
}
),
};
};
const new_app = new (class extends app_class {
collections = {
...super.collections,
"happy-numbers": new HappyNumbers(),
};
})();
await new_app.start();
},
(e) => {
- assert.equal(
+ assert.strictEqual(
e.message,
`In the happy-numbers collection definition you've tried to create the double_number cached-value field that refers to the collection itself. Consider using 'derived-value' field type to avoid problems with endless recurrence.`
);
}
);
}));
});
function make_refresh_on(): RefreshCondition[] {
return [
{
event: new EventDescription("actions", "after:create"),
- resource_id_getter: async (_: any, item) => [
+ resource_id_getter: async (_, item) => [
item.get("account") as string,
],
},
{
event: new EventDescription("actions", "after:edit"),