How to use the @serverless/utils.map function in @serverless/utils

To help you get started, we’ve selected a few @serverless/utils examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github serverless / components / registry / AwsSnsSubscription / src / index.js View on Github external
const concatSubscriptionAttributes = (inputs, state = {}) =>
  concat(
    // inputs subscriptionAttributes as array
    map((key) => ({ [key]: inputs[key] }), keys(inputs)),
    // state subscriptionAttributes as array with removed items
    reduce(
      (attributes, key) => {
        if (!contains(key, keys(inputs))) {
          // return empty object to "unset" removed value
          return concat(attributes, [{ [key]: {} }])
        }
        return attributes
      },
      [],
      keys(state)
    )
  )
github serverless / components / registry / AwsSnsTopic / src / index.js View on Github external
const concatInputsAndState = (inputs, state = []) => {
  const attributeKeys = map((item) => head(keys(item)), inputs)
  return filter((item) => isNil(find(equals(item))(state)))(
    concat(
      inputs,
      reduce(
        (attributes, attribute) => {
          const key = head(keys(attribute))
          if (!contains(key, attributeKeys)) {
            // return empty string to "unset" removed value
            return concat(attributes, [{ [key]: '' }])
          }
          return attributes
        },
        [],
        state
      )
    )
github serverless / components / src / utils / component / defineComponent.js View on Github external
const defineComponent = async (component, state, context) => {
  // TODO BRN: If we ever need to retrigger define (redefine) hydrating state here may be an issue
  if (!isComponent(component)) {
    throw new TypeError(
      `defineComponent expected component parameter to be a component. Instead received ${component}`
    )
  }
  component = hydrateComponent(component, state, context)
  if (isFunction(component.define)) {
    let children = await or(component.define(context), {})
    children = filter(isComponent, map(resolve, children))

    if (isObject(children)) {
      forEach((child) => {
        // TODO BRN: Look for children that already have parents. If this is the case then someone has returned a child from define that was defined by another component (possibly passed along as a variable)
        child.parent = component
        // child = setKey(appendKey(getKey(component), kdx), child)
      }, children)
    } else {
      throw new Error(
        `define() method must return either an object or an array. Instead received ${children} from ${component}.`
      )
    }
    component.children = await map(
      async (child, key) => defineComponent(child, get(['children', key], state), context),
      children
    )
github serverless / components / tests / integration / define-types / Child / index.js View on Github external
async define(context) {
      return all(
        map({
          grandChildA: context.construct(GrandChild, { bar: '' }),
          grandChildB: context.construct(GrandChild, { bar: '' })
        })
      )
    }
  }
github serverless / serverless-websockets-plugin / src / index.js View on Github external
async clearIntegrations() {
    const res = await this.provider.request('ApiGatewayV2', 'getIntegrations', { ApiId: this.apiId })
    return all(
      map(
        (integration) =>
          this.provider.request('ApiGatewayV2', 'deleteIntegration', {
            ApiId: this.apiId,
            IntegrationId: integration.IntegrationId
          }),
        res.Items
      )
    )
  }
github serverless / components / registry / AwsSnsTopic / src / index.js View on Github external
const updateTopicAttributes = async (sns, { topicAttributes, topicArn }) =>
  Promise.all(
    map((topicAttribute) => {
      const value = head(values(topicAttribute))
      const params = {
        TopicArn: topicArn,
        AttributeName: capitalize(head(keys(topicAttribute))),
        AttributeValue: typeof value !== 'string' ? JSON.stringify(value) : value
      }
      return sns.setTopicAttributes(params).promise()
    }, topicAttributes)
  )
github serverless / components / registry / AwsIamPolicy / src / index.js View on Github external
await all([
    all(
      map(
        (group) => IAM.detachGroupPolicy({ GroupName: group.GroupName, PolicyArn: arn }).promise(),
        PolicyGroups
      )
    ),
    all(
      map(
        (role) => IAM.detachRolePolicy({ RoleName: role.RoleName, PolicyArn: arn }).promise(),
        PolicyRoles
      )
    ),
    all(
      map(
        (user) => IAM.detachUserPolicy({ UserName: user.UserName, PolicyArn: arn }).promise(),
        PolicyUsers
      )
    )
  ])
  await IAM.deletePolicy({
    PolicyArn: arn
  }).promise()

  return null
}
github serverless / components / src / utils / plugin / loadPlugins.js View on Github external
const loadPlugins = async (plugins, context) =>
  map(async (pluginPath) => loadPlugin(pluginPath, context), plugins)
github serverless / serverless-websockets-plugin / src / index.js View on Github external
async createRoutes() {
    const integrationsPromises = map(async (fn) => {
      const integrationId = await this.createIntegration(fn.arn)
      await this.addPermission(fn.arn)
      const routesPromises = map((route) => this.createRoute(integrationId, route), fn.routes)
      return all(routesPromises)
    }, this.functions)

    return all(integrationsPromises)
  }