directus

Форк
0
/
generate-host-function-reference.ts 
32 строки · 1.1 Кб
1
/**
2
 * Generate an anonymous function wrapper with the provided arguments that applies the args against a referenced function in the host
3
 *
4
 * @param index - Generator function that tracks the indexes used
5
 * @param args - Named arguments of the host function
6
 * @param options - Options to modify the output function
7
 * @param options.async - Whether or not to generate the wrapper function as an async function
8
 */
9
export function generateHostFunctionReference(
10
	index: Generator<number, number, number>,
11
	args: string[],
12
	options: { async: boolean },
13
): string {
14
	const argsList = args.join(', ');
15
	const i = index.next().value;
16

17
	if (options.async) {
18
		return `
19
			async (${argsList}) => {
20
				const { result, error } = await $${i}.apply(undefined, [${argsList}], { arguments: { reference: true }, result: { copy: true, promise: true } });
21

22
				if (error) {
23
					throw result;
24
				} else {
25
					return result;
26
				}
27
			};
28
		`;
29
	} else {
30
		return `(${argsList}) => $${i}.applySync(undefined, [${argsList}], { arguments: { reference: true }, result: { copy: true } });`;
31
	}
32
}
33

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.