How to use the @serverless/utils.equals 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 / AwsIamPolicy / src / index.js View on Github external
shouldDeploy(prevInstance) {
      const inputs = {
        document: this.document
      }
      const prevInputs = prevInstance ? pick(keys(inputs), prevInstance) : {}
      const configChanged = not(equals(inputs, prevInputs))

      // make sure any added suffix from prevInstance is preserved
      // otherwise name will always be different
      if (prevInstance && this.policyName === `policy-${this.instanceId}`) {
        this.policyName = prevInstance.policyName
      }

      // if config changed, change the name to trigger replace
      if (prevInstance && configChanged && this.policyName.includes(`policy-${this.instanceId}`)) {
        this.policyName = `policy-${this.instanceId}-${Math.random()
          .toString(36)
          .substring(7)}`
      }

      // if the user changed the config without changing the name, error!
      if (prevInstance && configChanged && prevInstance.policyName === this.policyName) {
github serverless / components / src / types / AwsIamRole / index.js View on Github external
arn: 'arn:aws:iam::aws:policy/AdministratorAccess'
      }
      const policy = this.policy || defaultPolicy

      if (!prevInstance) {
        context.log(`Creating Role: ${roleName}`)
        this.arn = await createRole(IAM, {
          roleName,
          service: this.service,
          policy
        })
      } else {
        if (prevInstance.service !== this.service) {
          await updateAssumeRolePolicy(IAM, this)
        }
        if (!equals(prevInstance.policy, policy)) {
          await detachRolePolicy(IAM, this)
          await attachRolePolicy(IAM, this)
        }
      }
    }
github serverless / components / registry / AwsSnsSubscription / src / index.js View on Github external
shouldDeploy(prevInstance) {
      if (!prevInstance) {
        return 'deploy'
      }
      const inputs = {
        topic: this.topic,
        protocol: this.protocol,
        endpoint: this.endpoint,
        subscriptionAttributes: this.subscriptionAttributes
      }
      const prevInputs = prevInstance ? pick(keys(inputs), prevInstance) : {}
      const configChanged = not(equals(inputs, prevInputs))
      if (
        not(equals(prevInstance.protocol, inputs.protocol)) ||
        not(equals(prevInstance.topic, inputs.topic))
      ) {
        return 'replace'
      } else if (configChanged) {
        return 'deploy'
      }

      return undefined
    }
github serverless / components / registry / TwilioPhoneNumber / src / index.js View on Github external
shouldDeploy(prevInstance) {
      if (!prevInstance) {
        return 'deploy'
      }
      const inputs = pick(inputsProps, this)
      const prevInputs = prevInstance ? pick(inputsProps, prevInstance) : {}
      const configChanged = not(equals(inputs, prevInputs))
      if (not(equals(prevInputs.phoneNumber, inputs.phoneNumber))) {
        return 'replace'
      } else if (configChanged) {
        return 'deploy'
      }

      return undefined
    }
github serverless / components / registry / AwsDynamoDb / src / index.js View on Github external
async deploy(prevInstance, context) {
      const tableName = get('tableName', this)

      if (
        prevInstance &&
        (not(equals(prevInstance.attributeDefinitions, this.attributeDefinitions)) ||
          not(equals(prevInstance.provisionedThroughput, this.provisionedThroughput)) ||
          not(equals(prevInstance.globalSecondaryIndexes, this.globalSecondaryIndexes)) ||
          not(equals(prevInstance.sseSpecification, this.sseSpecification)) ||
          not(equals(prevInstance.streamSpecification, this.streamSpecification)))
      ) {
        context.log(`Updating table: '${tableName}'`)
        if (not(equals(prevInstance.globalSecondaryIndexes, this.globalSecondaryIndexes))) {
          context.log(
            `Skipping GlobalSecondaryIndex updates for table '${tableName}' (currently not supported)`
          )
        }

        await ensureTable(updateTable, this)
        context.log(`Table updated: '${tableName}'`)
      } else if (
        prevInstance &&
        not(equals(prevInstance.timeToLiveSpecification, this.timeToLiveSpecification))
      ) {
        context.log(`Updating time to live of the table: '${tableName}'`)
        await updateTimeToLive(this)
        context.log(`Time to live of the table updated: '${tableName}'`)
      } else {
        context.log(`Creating table: '${tableName}'`)
github serverless / components / registry / AwsIamRole / src / index.js View on Github external
const { provider } = this
      const AWS = provider.getSdk()
      const IAM = new AWS.IAM()

      if (!prevInstance || this.roleName !== prevInstance.roleName) {
        context.log(`Creating Role: ${this.roleName}`)
        this.arn = await createRole(IAM, {
          roleName: this.roleName,
          service: this.service,
          policy: this.policy
        })
      } else {
        if (prevInstance.service !== this.service) {
          await updateAssumeRolePolicy(IAM, this)
        }
        if (!equals(prevInstance.policy, this.policy)) {
          await removeRolePolicy(IAM, prevInstance)
          await addRolePolicy(IAM, { roleName: this.roleName, policy: this.policy })
        }
      }
    }
github serverless / components / registry / AwsDynamoDb / src / index.js View on Github external
async deploy(prevInstance, context) {
      const tableName = get('tableName', this)

      if (
        prevInstance &&
        (not(equals(prevInstance.attributeDefinitions, this.attributeDefinitions)) ||
          not(equals(prevInstance.provisionedThroughput, this.provisionedThroughput)) ||
          not(equals(prevInstance.globalSecondaryIndexes, this.globalSecondaryIndexes)) ||
          not(equals(prevInstance.sseSpecification, this.sseSpecification)) ||
          not(equals(prevInstance.streamSpecification, this.streamSpecification)))
      ) {
        context.log(`Updating table: '${tableName}'`)
        if (not(equals(prevInstance.globalSecondaryIndexes, this.globalSecondaryIndexes))) {
          context.log(
            `Skipping GlobalSecondaryIndex updates for table '${tableName}' (currently not supported)`
          )
        }

        await ensureTable(updateTable, this)
        context.log(`Table updated: '${tableName}'`)
      } else if (
        prevInstance &&
github serverless / components / registry / AwsDynamoDb / src / index.js View on Github external
not(equals(prevInstance.globalSecondaryIndexes, this.globalSecondaryIndexes)) ||
          not(equals(prevInstance.sseSpecification, this.sseSpecification)) ||
          not(equals(prevInstance.streamSpecification, this.streamSpecification)))
      ) {
        context.log(`Updating table: '${tableName}'`)
        if (not(equals(prevInstance.globalSecondaryIndexes, this.globalSecondaryIndexes))) {
          context.log(
            `Skipping GlobalSecondaryIndex updates for table '${tableName}' (currently not supported)`
          )
        }

        await ensureTable(updateTable, this)
        context.log(`Table updated: '${tableName}'`)
      } else if (
        prevInstance &&
        not(equals(prevInstance.timeToLiveSpecification, this.timeToLiveSpecification))
      ) {
        context.log(`Updating time to live of the table: '${tableName}'`)
        await updateTimeToLive(this)
        context.log(`Time to live of the table updated: '${tableName}'`)
      } else {
        context.log(`Creating table: '${tableName}'`)
        await ensureTable(createTable, this)
        context.log(`Table created: '${tableName}'`)

        if (this.timeToLiveSpecification) {
          context.log(`Updating time to live of the table: '${tableName}'`)
          await updateTimeToLive(this)
          context.log(`Time to live of the table updated: '${tableName}'`)
        }
      }
    }