Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
import debugLevels from 'resolve-debug-levels'
import createSchedulerEventTypes from './scheduler-event-types'
import createSchedulerSagaHandlers from './scheduler-saga-handlers'
import sagaEventHandler from './saga-event-handler'
const log = debugLevels('resolve:resolve-runtime:wrap-scheduler-sagas')
const execute = async (
sagaProvider,
schedulerAggregateName,
taskId,
date,
command
) =>
await sagaProvider.executeCommand({
aggregateName: schedulerAggregateName,
aggregateId: taskId,
type: 'execute',
payload: { date, command }
})
const createSchedulerSagas = (schedulers, sagaProvider) => {
import debugLevels from 'resolve-debug-levels'
import handleApiGatewayEvent from './api-gateway-handler'
import handleDeployServiceEvent from './deploy-service-event-handler'
import handleEventBusEvent from './event-bus-event-handler'
import handleSchedulerEvent from './scheduler-event-handler'
import putMetrics from './metrics'
import initResolve from '../common/init-resolve'
import disposeResolve from '../common/dispose-resolve'
const log = debugLevels('resolve:resolve-runtime:cloud-entry')
let coldStart = true
const lambdaWorker = async (resolveBase, lambdaEvent, lambdaContext) => {
log.debug('executing application lambda')
log.verbose('incoming event', JSON.stringify(lambdaEvent, null, 2))
lambdaContext.callbackWaitsForEmptyEventLoop = false
const resolve = Object.create(resolveBase)
resolve.getRemainingTimeInMillis = lambdaContext.getRemainingTimeInMillis.bind(
lambdaContext
)
const lambdaRemainingTimeStart = lambdaContext.getRemainingTimeInMillis()
try {
import debugLevels from 'resolve-debug-levels'
const log = debugLevels('resolve:resolve-runtime:subscribe-handler')
const subscribeHandler = async (req, res) => {
try {
const parameters = req.method === 'POST' ? JSON.parse(req.body) : req.query
const { origin, adapterName } = parameters
await res.setHeader('Content-Type', 'application/json')
await res.json(
await req.resolve.getSubscribeAdapterOptions(origin, adapterName)
)
} catch (err) {
log.warn('Subscribe handler error', err)
await res.status(500)
await res.setHeader('Content-Type', 'text/plain')
await res.end(err.toString())
}
}
import debugLevels from 'resolve-debug-levels'
import EventEmitter from 'events'
import http from 'http'
import MqttConnection from 'mqtt-connection'
import createSocketServer from 'socket.io'
import getWebSocketStream from 'websocket-stream'
import { Server as WebSocketServer } from 'ws'
import uuid from 'uuid/v4'
import createPubsubManager from './create-pubsub-manager'
import getRootBasedUrl from '../common/utils/get-root-based-url'
import getSubscribeAdapterOptions from './get-subscribe-adapter-options'
const log = debugLevels('resolve:resolve-runtime:local-subscribe-adapter')
const getMqttTopic = (appId, { topicName, topicId }) => {
return `${appId}/${topicName === '*' ? '+' : topicName}/${
topicId === '*' ? '+' : topicId
}`
}
const createServerMqttHandler = (pubsubManager, appId, qos) => ws => {
const stream = getWebSocketStream(ws)
const client = new MqttConnection(stream)
let messageId = 1
const publisher = (topicName, topicId, event) =>
new Promise((resolve, reject) => {
client.publish(
{
import debugLevels from 'resolve-debug-levels'
import { globalPartitionKey, rangedIndex } from './constants'
const log = debugLevels('resolve:resolve-storage-dynamo:init')
const init = async ({
tableName,
billingMode = 'PAY_PER_REQUEST',
readCapacityUnits,
writeCapacityUnits,
database,
checkTableExists,
lazyWaitForCreate = false
}) => {
log.debug(`init started${lazyWaitForCreate ? ' (mode:"lazy")' : ''}`)
if (await checkTableExists(database, tableName)) {
return
}
import 'source-map-support/register'
import debugLevels from 'resolve-debug-levels'
import { createActions } from 'resolve-redux'
import initBroker from './init-broker'
import initPerformanceTracer from './init-performance-tracer'
import initExpress from './init-express'
import initWebsockets from './init-websockets'
import startExpress from './start-express'
import emptyWorker from './empty-worker'
const log = debugLevels('resolve:resolve-runtime:local-entry')
const localEntry = async ({ assemblies, constants, domain, redux, routes }) => {
try {
const resolve = {
instanceId: `${process.pid}${Math.floor(Math.random() * 100000)}`,
seedClientEnvs: assemblies.seedClientEnvs,
...domain,
...constants,
eventBroker: {},
assemblies,
redux,
routes
}
resolve.aggregateActions = {}
for (const aggregate of domain.aggregates) {
import debugLevels from 'resolve-debug-levels'
const log = debugLevels('resolve:resolve-runtime:cloud-entry')
const invokeMeta = async (resolve, listenerId, operation, options) => {
const invokeFunctionName = process.env.RESOLVE_META_LAMBDA_ARN
const invokePayload = JSON.stringify({
...options,
listenerId,
operation
})
log.debug(`invoking lambda ${invokeFunctionName} ${invokePayload}`)
const { Payload, FunctionError } = await resolve.lambda
.invoke({
FunctionName: invokeFunctionName,
Payload: invokePayload
})
import debugLevels from 'resolve-debug-levels'
import fs from 'fs'
import path from 'path'
import crypto from 'crypto'
import fileType from 'file-type'
import extractRequestBody from '../utils/extract-request-body'
const log = debugLevels('resolve:resolve-runtime:uploader-handler')
const uploaderHandler = async (req, res) => {
try {
const { directory, bucket, secretKey } = req.resolve.uploader
const bucketPath = path.join(directory, bucket)
if (!fs.existsSync(bucketPath)) {
fs.mkdirSync(bucketPath, { recursive: true })
}
if (req.method === 'POST' || req.method === 'PUT') {
const { dir, uploadId } = req.query
const dirName = path.join(directory, bucket, dir)
if (!fs.existsSync(dirName)) {
fs.mkdirSync(dirName, { recursive: true })
import debugLevels from 'resolve-debug-levels'
import bootstrap from '../common/bootstrap'
const log = debugLevels('resolve:resolve-runtime:deploy-service-event-handler')
const getReadModelNames = resolve => resolve.readModels.map(({ name }) => name)
const getSagaNames = resolve => [
...resolve.schedulers.map(({ name }) => name),
...resolve.sagas.map(({ name }) => name)
]
const handleResolveReadModelEvent = async (
lambdaEvent,
resolve,
getListenerIds
) => {
const { listenerId, key, value } = lambdaEvent
switch (lambdaEvent.operation) {
case 'reset': {
log.debug('operation "reset" started')
import debugLevels from 'resolve-debug-levels'
const log = debugLevels('resolve:resolve-runtime:cloud-entry')
const invokeUpdateLambda = async (
{ lambda },
{ name: listenerId, invariantHash, eventTypes }
) => {
const invokeFunctionName = process.env.RESOLVE_META_LOCK_LAMBDA_ARN
const invokePayload = JSON.stringify({
listenerId,
invariantHash,
inactiveTimeout: 1000 * 60 * 60,
eventTypes
})
log.debug(`invoking lambda ${invokeFunctionName} ${invokePayload}`)