UNPKG

aws-amplify

Version:

AWS Amplify is a JavaScript library for Frontend and mobile developers building cloud-enabled applications.

33 lines (31 loc) 1.48 kB
'use strict'; // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. // SPDX-License-Identifier: Apache-2.0 Object.defineProperty(exports, "__esModule", { value: true }); exports.runWithAmplifyServerContext = void 0; const adapter_core_1 = require("@aws-amplify/core/internals/adapter-core"); /** * The low level function that supports framework specific helpers. * It creates an Amplify server context based on the input and runs the operation * with injecting the context, and finally returns the result of the operation. * * @param amplifyConfig The Amplify resource config. * @param libraryOptions The Amplify library options. * @param operation The operation to run with the server context created from * `amplifyConfig` and `libraryOptions`. * @returns The result returned by the `operation`. */ const runWithAmplifyServerContext = async (amplifyConfig, libraryOptions, operation) => { const contextSpec = (0, adapter_core_1.createAmplifyServerContext)(amplifyConfig, libraryOptions); // run the operation with injecting the context try { const result = await operation(contextSpec); return result; } finally { // ensures destroy the context regardless whether the operation succeeded or failed (0, adapter_core_1.destroyAmplifyServerContext)(contextSpec); } }; exports.runWithAmplifyServerContext = runWithAmplifyServerContext; //# sourceMappingURL=runWithAmplifyServerContext.js.map