Mirror of https://github.com/roostorg/coop
github.com/roostorg/coop
1import _ from 'lodash';
2import stringify from 'safe-stable-stringify';
3
4import {
5 getDerivedFieldValue,
6 type DerivedFieldSpec,
7} from '../services/derivedFieldsService/index.js';
8import { type ItemSubmission } from '../services/itemProcessingService/index.js';
9import { type TransientRunSignalWithCache } from '../services/orgAwareSignalExecutionService/index.js';
10
11export default function makeGetDerivedFieldValueWithCache(
12 runSignal: TransientRunSignalWithCache,
13 orgId: string,
14) {
15 return _.memoize(
16 async (itemSubmission: ItemSubmission, input: DerivedFieldSpec) =>
17 getDerivedFieldValue(runSignal, orgId, itemSubmission, input),
18 (itemSubmission, input) => stringify([itemSubmission, input]),
19 );
20}