From e19fabb02ff9a3d4044c5a208a2f8d0692c0aa81 Mon Sep 17 00:00:00 2001 From: Ruben Fiszel Date: Sun, 28 May 2023 22:59:08 +0200 Subject: [PATCH] feat(cli): add resolveDefaultResource --- deno-client/mod.ts | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/deno-client/mod.ts b/deno-client/mod.ts index be76e614e5..fd00b2ff7d 100644 --- a/deno-client/mod.ts +++ b/deno-client/mod.ts @@ -80,6 +80,19 @@ export async function getResource( } } +/** + * Resolve a resource value in case the default value was picked because the input payload was undefined + * @param obj resource value or path of the resource under the format `$res:path` + * @returns resource value + */ +export async function resolveDefaultResource(obj: any): Promise { + if (typeof obj === "string" && obj.startsWith("$res:")) { + return await getResource(obj.substring(5), true); + } else { + return obj; + } +} + /** * Get the full resource value by path * @param path path of the resource, default to internal state path