Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const importEventStoreHandler = options => async (req, res) => {
const { storageAdapter } = req.resolve
try {
const { importFile } = options
const eventStream = storageAdapter.import()
const fsStream = fs.createReadStream(path.join(importFile))
await pipeline(fsStream, eventStream)
res.end('ok')
} catch (error) {
// eslint-disable-next-line no-console
console.error(error)
res.status(500)
res.end(String(error))
}
}
const exportEventStoreHandler = options => async (req, res) => {
const { storageAdapter } = req.resolve
try {
const { exportFile } = options
const eventStream = storageAdapter.export()
const fsStream = fs.createWriteStream(path.join(exportFile))
await pipeline(eventStream, fsStream)
res.end('ok')
} catch (error) {
// eslint-disable-next-line no-console
console.error(error)
res.status(500)
res.end(String(error))
}
}
import { globalPartitionKey, rangedIndex, apiVersion } from './constants'
// as resource
import ApplicationAutoScaling from 'aws-sdk/clients/applicationautoscaling'
import setupAutoScaling from './resource/setup-auto-scaling'
import setupAutoScalingItem from './resource/setup-auto-scaling-item'
import resourceCreate from './resource/create'
import resourceDispose from './resource/dispose'
import resourceDestroy from './resource/destroy'
import resourceWaitForCreate from './resource/wait-for-create'
const resourceMap = new WeakMap()
// as adapter
const createAdapter = _createAdapter.bind(null, {
connect,
init,
loadEvents,
getEventStream,
getLatestEvent,
saveEvent,
drop,
dispose: _dispose,
DynamoDB,
createTypeExpression,
createTimestampExpression,
createAggregateIdExpression,
createQuery,
expressionObject,
expressionString,
checkTableExists,
db.findOne({ aggregateId, aggregateVersion }, (err, doc) => {
if (doc !== null) {
return reject(
new ConcurrentError(
// eslint-disable-next-line max-len
`Can not save the event because aggregate '${aggregateId}' is not actual at the moment. Please retry later.`
)
)
}
db.insert(event, error => (error ? reject(error) : resolve()))
})
})
error => {
if (!error) {
resolve()
} else if (error.errorType === 'uniqueViolated') {
reject(
new ConcurrentError(
// eslint-disable-next-line max-len
`Can not save the event because aggregate '${
event.aggregateId
}' is not actual at the moment. Please retry later.`
)
)
} else {
reject(error)
}
}
)
import NeDB from 'nedb'
import createAdapter from 'resolve-storage-base'
import connect from './connect'
import init from './init'
import loadEvents from './load-events'
import getLatestEvent from './get-latest-event'
import saveEvent from './save-event'
import dispose from './dispose'
import promiseInvoke from './promise-invoke'
export default createAdapter.bind(
null,
connect,
init,
loadEvents,
getLatestEvent,
saveEvent,
dispose,
{ NeDB, promiseInvoke }
)
import createAdapter from 'resolve-storage-base'
import connect from './connect'
import loadEvents from './load-events'
import getLatestEvent from './get-latest-event'
import saveEvent from './save-event'
import init from './init'
import drop from './drop'
import dispose from './dispose'
import paginateEvents from './paginate-events'
import saveEventOnly from './save-event-only'
import isFrozen from './is-frozen'
import freeze from './freeze'
import unfreeze from './unfreeze'
export default createAdapter.bind(null, {
connect,
loadEvents,
getLatestEvent,
saveEvent,
init,
drop,
dispose,
paginateEvents,
saveEventOnly,
isFrozen,
freeze,
unfreeze,
MongoClient
})
import init from './init'
import loadEvents from './load-events'
import getEventStream from './get-event-stream'
import getLatestEvent from './get-latest-event'
import saveEvent from './save-event'
import drop from './drop'
import dispose from './dispose'
import _createResource from './resource/create'
import _disposeResource from './resource/dispose'
import _destroyResource from './resource/destroy'
const escapeId = str => `"${String(str).replace(/(["])/gi, '$1$1')}"`
const escape = str => `'${String(str).replace(/(['])/gi, '$1$1')}'`
const createAdapter = _createAdapter.bind(null, {
connect,
init,
loadEvents,
getEventStream,
getLatestEvent,
saveEvent,
drop,
dispose,
RDSDataService,
escapeId,
escape
})
export default createAdapter
const pool = {
import loadEvents from './load-events'
import getLatestEvent from './get-latest-event'
import saveEvent from './save-event'
import drop from './drop'
import dispose from './dispose'
import _createResource from './resource/create'
import _disposeResource from './resource/dispose'
import _destroyResource from './resource/destroy'
const escapeUnicode = str =>
`FROM_BASE64("${Buffer.from(String(str), 'utf8').toString('base64')}")`
const escapeId = str => `\`${String(str).replace(/([`])/gi, '$1$1')}\``
const escape = str => `"${String(str).replace(/(["])/gi, '$1$1')}"`
const createAdapter = _createAdapter.bind(
null,
connect,
init,
loadEvents,
getLatestEvent,
saveEvent,
drop,
dispose,
{
RDSDataService,
escapeUnicode,
escapeId,
escape
}
)
import createAdapter from 'resolve-storage-base'
import connect from './connect'
import loadEvents from './load-events'
import getLatestEvent from './get-latest-event'
import saveEvent from './save-event'
import init from './init'
import drop from './drop'
import dispose from './dispose'
import paginateEvents from './paginate-events'
import saveEventOnly from './save-event-only'
import freeze from './freeze'
import unfreeze from './unfreeze'
export default createAdapter.bind(null, {
connect,
loadEvents,
getLatestEvent,
saveEvent,
init,
drop,
dispose,
paginateEvents,
saveEventOnly,
freeze,
unfreeze,
MySQL,
escapeId,
escape
})