How to use the @serverless/utils.isEmpty 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 / serverless-websockets-plugin / src / index.js View on Github external
async deployWebsockets() {
    this.init()
    await this.prepareFunctions()
    if (
      !is(Object, this.serverless.service.functions) ||
      keys(this.serverless.service.functions).length === 0 ||
      isEmpty(this.functions)
    ) {
      return
    }
    this.serverless.cli.log(`Deploying Websockets API named "${this.apiName}"...`)
    await this.createApi()
    // We clear routes before deploying the new routes for idempotency
    // since we lost the idempotency feature of CF
    await this.clearRoutes()
    await this.clearAuthorizers()
    await this.clearIntegrations()
    await this.createAuthorizers()
    await this.createRoutes()
    await this.createDeployment()
    this.serverless.cli.log(
      `Websockets API named "${this.apiName}" with ID "${this.apiId}" has been deployed.`
    )
github serverless / components / src / utils / dag / logStatus.js View on Github external
let paramsAsObject = reduce(
      (accum, _, key) => {
        const value = resolve(instance.inputs[key])
        // TODO: replace with a universal util function which checks whether we're
        // dealing with a Component, Object, Provider, etc. instance here
        // omitting own Types due to circular structure / verbosity here
        if (!(value.name && value.version)) {
          return assoc(key, value, accum)
        }
        return accum
      },
      {},
      requiredParams
    )

    if (not(isEmpty(paramsAsObject))) {
      try {
        paramsAsObject = JSON.stringify(paramsAsObject, null, 2)
      } catch (error) {
        // simply reassign to an empty object
        paramsAsObject = {}
      } finally {
        return paramsAsObject
      }
    }
    return paramsAsObject
  }
}
github serverless / components / registry / AwsProvider / src / index.js View on Github external
validate() {
      if (!/.+-.+.\d+/.test(this.region)) {
        throw new Error(`Invalid region "${this.region}" in your AWS provider setup`)
      }

      if (!this.credentials || isEmpty(this.credentials)) {
        throw new Error(`Credentials not set in your AWS provider setup`)
      }
    }
  }
github serverless / serverless-websockets-plugin / src / index.js View on Github external
async displayWebsockets() {
    this.init()
    await this.prepareFunctions()
    if (isEmpty(this.functions)) {
      return
    }
    await this.getApi()
    const baseUrl = this.getWebsocketUrl()
    const routes = flatten(map((fn) => fn.routes.routeKey, this.functions))
    this.serverless.cli.consoleLog(chalk.yellow('WebSockets:'))
    this.serverless.cli.consoleLog(`  ${chalk.yellow('Base URL:')} ${baseUrl}`)
    this.serverless.cli.consoleLog(chalk.yellow('  Routes:'))
    map((route) => this.serverless.cli.consoleLog(`    - ${baseUrl}${route}`), routes)
  }
}
github serverless / components / src / utils / dag / logStatus.js View on Github external
const { prevInstance, nextInstance } = node

  const componentName =
    (nextInstance && nextInstance.constructor.name) ||
    (prevInstance && prevInstance.constructor.name)

  if (iteratee.name === 'deployNode') {
    const params = getParameters(nextInstance)
    context.log(
      `Deploying "${componentName}" ${not(isEmpty(params)) ? `with parameters: ${params}` : ''}`
    )
  } else if (iteratee.name === 'removeNode') {
    if (prevInstance) {
      const params = getParameters(prevInstance)
      context.log(
        `Removing "${componentName}" ${not(isEmpty(params)) ? `with parameters: ${params}` : ''}`
      )
    }
  }
}
github serverless / components / registry / AwsIamRole / src / index.js View on Github external
const addRolePolicy = async (IAM, { roleName, policy }) => {
  if (has('arn', policy)) {
    await IAM.attachRolePolicy({
      RoleName: roleName,
      PolicyArn: policy.arn
    }).promise()
  } else if (!isEmpty(policy)) {
    await IAM.putRolePolicy({
      RoleName: roleName,
      PolicyName: `${roleName}-policy`,
      PolicyDocument: JSON.stringify(policy)
    }).promise()
  }

  return sleep(15000)
}
github serverless / components / registry / AwsSnsSubscription / src / protocols / lib.js View on Github external
const setSubscriptionAttributes = async (
  { provider, subscriptionArn, attributeName, attributeValue },
  context
) => {
  const SDK = provider.getSdk()
  const sns = new SDK.SNS()
  if (isEmpty(attributeValue)) {
    context.log(
      `Removing SNS Subscription Attribute '${attributeName}' from subscription ${subscriptionArn}`
    )
  } else {
    context.log(
      `Setting SNS Subscription Attribute '${attributeName}' to subscription ${subscriptionArn}`
    )
  }
  try {
    const response = await sns
      .setSubscriptionAttributes({
        AttributeName: attributeName,
        SubscriptionArn: subscriptionArn,
        AttributeValue:
          typeof attributeValue === 'string' ? attributeValue : JSON.stringify(attributeValue)
      })
github serverless / components / src / utils / dag / removeGraph.js View on Github external
const removeNode = async (node, context) => {
  const { instanceId, operation } = node
  let { nextInstance, prevInstance } = node
  if (!isEmpty(nextInstance)) {
    nextInstance = resolveComponentEvaluables(nextInstance)
  }
  if (!isEmpty(prevInstance)) {
    prevInstance = resolveComponentEvaluables(prevInstance)
  }
  context.debug(
    `checking if component should be removed - operation: ${operation} instanceId: ${instanceId} nextInstance: ${get(
      'name',
      nextInstance
    )} prevInstance: ${get('name', prevInstance)}`
  )
  validateNode(node, context)
  if (contains(operation, ['remove', 'replace'])) {
    if (operation === 'replace') {
      if (prevInstance) {
        await removeInstance(prevInstance, context)
github serverless / components / registry / TwilioPhoneNumber / src / index.js View on Github external
const createPhoneNumber = async (twilio, params) => {
  if (params.phoneNumber) {
    const exists = await twilio.incomingPhoneNumbers.list({
      phoneNumber: params.phoneNumber
    })
    if (!isEmpty(exists)) {
      return updatePhoneNumber(twilio, {
        ...params,
        sid: exists[0].sid
      })
    }
  }
  const phoneNumber = await twilio.incomingPhoneNumbers.create(params)
  return pick(phoneNumberProps, phoneNumber)
}