contentful-management
Version:
Client for Contentful's Content Management API
33 lines (30 loc) • 1.32 kB
JavaScript
import copy from 'fast-copy';
import { toPlainObject, freezeSys } from 'contentful-sdk-core';
import enhanceWithMethods from '../enhance-with-methods.js';
import createEnvironmentApi from '../create-environment-api.js';
import { wrapCollection } from '../common-utils.js';
/**
* This method creates the API for the given environment with all the methods for
* reading and creating other entities. It also passes down a clone of the
* http client with a environment id, so the base path for requests now has the
* environment id already set.
* @internal
* @param makeRequest - function to make requests via an adapter
* @param data - API response for a Environment
* @returns
*/
function wrapEnvironment(makeRequest, data) {
// do not pollute generated typings
const environment = toPlainObject(copy(data));
const environmentApi = createEnvironmentApi(makeRequest);
const enhancedEnvironment = enhanceWithMethods(environment, environmentApi);
return freezeSys(enhancedEnvironment);
}
/**
* This method wraps each environment in a collection with the environment API. See wrapEnvironment
* above for more details.
* @internal
*/
const wrapEnvironmentCollection = wrapCollection(wrapEnvironment);
export { wrapEnvironment, wrapEnvironmentCollection };
//# sourceMappingURL=environment.js.map