From bce557cc2dc767628bed6aac87301a1be7c5431b Mon Sep 17 00:00:00 2001 From: rxliuli Date: Tue, 4 Nov 2025 05:03:50 +0800 Subject: init commit --- .../tmp/src/foundation/util/validation-util.js | 30 ++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 node_modules/@jet-app/app-store/tmp/src/foundation/util/validation-util.js (limited to 'node_modules/@jet-app/app-store/tmp/src/foundation/util/validation-util.js') diff --git a/node_modules/@jet-app/app-store/tmp/src/foundation/util/validation-util.js b/node_modules/@jet-app/app-store/tmp/src/foundation/util/validation-util.js new file mode 100644 index 0000000..fe9bd93 --- /dev/null +++ b/node_modules/@jet-app/app-store/tmp/src/foundation/util/validation-util.js @@ -0,0 +1,30 @@ +import { isSome } from "@jet/environment"; +import * as validation from "@jet/environment/json/validation"; +import { tryAwait } from "./promise-util"; +/** + * Creates a validation context for async operations and ensures proper cleanup. + * + * Wraps an async operation in a validation context, automatically handling + * context cleanup even when errors occur. Optionally processes errors through + * a provided error handler. + * + * @param name - The name for the validation context + * @param producer - Async function that produces the result + * @param errorHandler - Optional function to handle errors from the producer + * @returns The result of the async operation + */ +export async function withAsyncValidationContext(name, producer, errorHandler) { + validation.beginContext(name); + let result = await tryAwait(producer()); + if (!result.success && isSome(errorHandler)) { + result = await tryAwait(errorHandler(result.error)); + } + validation.endContext(); + if (!result.success) { + throw result.error; + } + else { + return result.value; + } +} +//# sourceMappingURL=validation-util.js.map \ No newline at end of file -- cgit v1.2.3