Skip to content

Commit

Permalink
feat(cu): /state returns the process memory as binary data #203
Browse files Browse the repository at this point in the history
  • Loading branch information
TillaTheHun0 committed Dec 15, 2023
1 parent 1d939f1 commit 0fee138
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 5 deletions.
2 changes: 1 addition & 1 deletion servers/cu/src/routes/middleware/withInMemoryCache.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ export const withInMemoryCache = ({
}
})

return (req, res) => dataloader.load(req)
return (req, res) => dataloader.load({ req, res })
.then(result => res.send(result))
.catch(err => {
if (evict(req, err)) dataloader.clear(keyer(req))
Expand Down
4 changes: 2 additions & 2 deletions servers/cu/src/routes/result.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ export const withResultRoutes = app => {
const { params: { messageTxId } } = req
return messageTxId
},
loader: async (reqs) => {
return reqs.map(async (req) => {
loader: async (requests) => {
return requests.map(async ({ req }) => {
const {
params: { messageTxId },
query: { 'process-id': processId },
Expand Down
14 changes: 12 additions & 2 deletions servers/cu/src/routes/state.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ export const withStateRoutes = (app) => {
const { params: { messageTxId } } = req
return messageTxId
},
loader: async (reqs) => {
return reqs.map(async (req) => {
loader: async (requests) => {
return requests.map(async ({ req, res }) => {
const {
params: { processId },
query: { to },
Expand All @@ -31,6 +31,16 @@ export const withStateRoutes = (app) => {
const input = inputSchema.parse({ processId, to })

return readState(input)
.map((output) => {
/**
* The cu sends the array buffer as binary data,
* so make sure to set the header to indicate such
*
* and then return only the buffer received from BL
*/
res.header('Content-Type', 'application/octet-stream')
return output.buffer
})
.toPromise()
/**
* Will bubble up to the individual load call
Expand Down

0 comments on commit 0fee138

Please sign in to comment.