How to use the @serverless/utils.or 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 / 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 / registry / RestApi / src / utils.js View on Github external
[normalizedMethod, 'security'],
          [{ [securityDefinition.name]: [] }],
          updatedMethods
        )
        securityDefinitions[securityDefinition.name] = securityDefinition.definition
      }
    }, or(methods, {}))

    if (enableCorsOnPath) {
      const corsOptionsMethod = getCorsOptionsConfig()
      updatedMethods = set('options', corsOptionsMethod, updatedMethods)
    }

    // set the paths
    paths = set([normalizedPath], updatedMethods, paths)
  }, or(routes, {}))

  const definition = {
    swagger: '2.0',
    info: {
      title: name,
      version: new Date().toISOString()
    },
    schemes: ['https'],
    consumes: ['application/json'],
    produces: ['application/json'],
    securityDefinitions,
    paths
  }
  return definition
}
github serverless / components / registry / Service / src / index.js View on Github external
construct(inputs, context) {
      super.construct(inputs, context)
      // construct function instances
      this.functions = map(
        (func, alias) =>
          context.construct(Fn, {
            ...func,
            functionName: resolvable(() => or(func.functionName, alias)),
            code: resolvable(() => resolveCodePath(resolve(func.code), this.getType().root))
          }),
        or(this.functions, {})
      )
      // construct component instances
      this.components = map((component, key) => {
        if (isComponent(component)) {
          return component
        } else if (isTypeConstruct(component)) {
          // eslint-disable-next-line no-shadow
          const { type, inputs } = component
          const Type = context.require(type)
          component = context.construct(Type, inputs)
          if (!isComponent(component)) {
            throw new Error(
              `The component "${key}" is not of type Component (it's of type ${component.name})`
            )
          }
          return component
github serverless / components / registry / Service / src / index.js View on Github external
async define() {
      // TODO BRN: Change this once we support multiple layers here. This could cause collisions between functions and components that are named the same thing.
      return {
        ...or(this.functions, {}),
        ...or(this.components, {})
      }
    }
github serverless / components / registry / AwsApiGateway / src / utils.js View on Github external
undefined,
        normalizedPath,
        normalizedMethod
      )
      const defaultResponses = getDefaultResponses(isCorsEnabled)
      updatedMethods = set([normalizedMethod], apiGatewayIntegration, updatedMethods)
      updatedMethods = set([normalizedMethod, 'responses'], defaultResponses, updatedMethods)
      if (securityDefinition) {
        updatedMethods = set(
          [normalizedMethod, 'security'],
          [{ [securityDefinition.name]: [] }],
          updatedMethods
        )
        securityDefinitions[securityDefinition.name] = securityDefinition.definition
      }
    }, or(methods, {}))

    if (enableCorsOnPath) {
      const corsOptionsMethod = getCorsOptionsConfig()
      updatedMethods = set('options', corsOptionsMethod, updatedMethods)
    }

    // set the paths
    paths = set([normalizedPath], updatedMethods, paths)
  }, or(routes, {}))
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 / registry / Service / src / index.js View on Github external
async info() {
      const functions = await reduce(
        async (accum, func) => append(await func.info(), accum),
        [],
        or(this.functions, {})
      )
      const components = await reduce(
        async (accum, component) => append(await component.info(), accum),
        [],
        or(this.components, {})
      )

      return {
        title: this.name,
        type: 'Service',
        data: {},
        children: [...functions, ...components]
      }
    }
  }
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 / registry / Component / src / utils / pickComponentProps.js View on Github external
    (accum, Type) => union(accum, keys(or(Type.props, {}))),
    ['inputs'],
github serverless / components / registry / AwsS3Bucket / src / index.js View on Github external
      this.provider = resolvable(() => or(inputs.provider, context.get('provider')))
    }