Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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)
)
)
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
)
)
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
)
async define(context) {
return all(
map({
grandChildA: context.construct(GrandChild, { bar: '' }),
grandChildB: context.construct(GrandChild, { bar: '' })
})
)
}
}
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
)
)
}
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)
)
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
}
const loadPlugins = async (plugins, context) =>
map(async (pluginPath) => loadPlugin(pluginPath, context), plugins)
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)
}