How to use the @serverless/utils.reduce 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 / AwsSnsTopic / src / index.js View on Github external
[{ displayName }, { policy }, { deliveryPolicy }]
  )

  const prevInstanceTopicAttributes = filter((item) => !isNil(head(values(item))))([
    { displayName: prevInstance.displayName },
    { policy: prevInstance.policy },
    { deliveryPolicy: prevInstance.deliveryPolicy }
  ])

  // combine inputs and check if something is removed
  const topicAttributesToUpdate = concatInputsAndState(topicAttributes, prevInstanceTopicAttributes)

  await updateTopicAttributes(sns, { topicAttributes: topicAttributesToUpdate, topicArn })

  // flatten delivery status attributes array
  const flatDeliveryStatusAttributes = reduce(
    (result, attribute) =>
      concat(result, map((key) => ({ [key]: attribute[key] }), keys(attribute))),
    [],
    deliveryStatusAttributes
  )

  // combine inputs and check if something is removed and select only ones that differs in state and inputs
  const deliveryStatusAttributesToUpdate = concatInputsAndState(
    flatDeliveryStatusAttributes,
    prevInstance.deliveryStatusAttributes
  )

  // update delivery status attributes
  await updateDeliveryStatusAttributes(sns, {
    deliveryStatusAttributes: deliveryStatusAttributesToUpdate,
    topicArn
github serverless / components / src / utils / serialize / utils / serializeObject.js View on Github external
const serializeObject = curry((context, object) =>
  reduce(
    (accum, value, key) => {
      value = resolve(value)
      if (isSerializable(value)) {
        if (isSymbol(key)) {
          const symbolString = getSymbolString(context, key)
          if (symbolString) {
            if (isSerializableReferenceable(value)) {
              return set(['symbols', symbolString], toReference(context, value), accum)
            }
            return set(['symbols', symbolString], serializeValue(context, value), accum)
          }
          // context.log(`unhandled symbol detected ${toString(key)}`)
        } else {
          if (isSerializableReferenceable(value)) {
            return set(['props', key], toReference(context, value), accum)
          }
github serverless / components / registry / AwsSnsTopic / src / index.js View on Github external
)

  // combine inputs and check if something is removed and select only ones that differs in state and inputs
  const deliveryStatusAttributesToUpdate = concatInputsAndState(
    flatDeliveryStatusAttributes,
    prevInstance.deliveryStatusAttributes
  )

  // update delivery status attributes
  await updateDeliveryStatusAttributes(sns, {
    deliveryStatusAttributes: deliveryStatusAttributesToUpdate,
    topicArn
  })

  return merge(
    reduce(
      (result, value) => merge({ [head(keys(value))]: head(values(value)) }, result),
      {},
      topicAttributes
    ),
    { deliveryStatusAttributes: flatDeliveryStatusAttributes }
  )
}
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 / 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 / App / src / index.js View on Github external
async info() {
    const services = await reduce(
      async (accum, service) => append(await service.info(), accum),
      [],
      or(this.services, {})
    )
    const components = await reduce(
      async (accum, component) => append(await component.info(), accum),
      [],
      or(this.components, {})
    )

    return {
      title: this.name,
      type: this.name,
      data: {},
      children: [...components, ...services]
    }
github serverless / components / src / utils / dag / execGraph.js View on Github external
const execNodeIds = async (iteratee, nodeIds, graph, context) =>
  all(
    reduce(
      (accum, nodeId) => {
        const node = graph.node(nodeId)
        if (!node) {
          throw new Error(`could not find node for nodeId:${nodeId}`)
        }
        graph.removeNode(nodeId)
        return append(execNode(iteratee, node, context), accum)
      },
      [],
      nodeIds
    )
  )
github serverless / components / registry / AwsSnsTopic / src / index.js View on Github external
const resolveInSequence = async (functionsToExecute) =>
  reduce(
    (promise, functionToExecute) =>
      promise.then((result) => functionToExecute().then(Array.prototype.concat.bind(result))),
    Promise.resolve([]),
    functionsToExecute
  )