@muze-nl/simplystore 0.5.5 → 0.5.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@muze-nl/simplystore",
3
- "version": "0.5.5",
3
+ "version": "0.5.6",
4
4
  "main": "src/server.mjs",
5
5
  "type": "module",
6
6
  "scripts": {
@@ -77,7 +77,6 @@ export default async function runCommand(commandStr, request) {
77
77
  if (commands[task.name]) {
78
78
  let time = Date.now()
79
79
  commands[task.name](dataspace, task, request, metaProxy)
80
- //TODO: if command/task makes no changes, skip updating data.jsontag and writing it, skip response.data
81
80
  FastJSONTag.setAttribute(dataspace, 'command', task.id)
82
81
 
83
82
  const strData = resultSetStringify(resultSet)
@@ -88,7 +87,7 @@ export default async function runCommand(commandStr, request) {
88
87
  id: meta.index.id
89
88
  }
90
89
  }
91
- //TODO: write data every x commands or x minutes, in seperate thread
90
+
92
91
  await writeFileAtomic(datafile, uint8sab)
93
92
  let end = Date.now()
94
93
  console.log('task time',end-time)
package/src/server.mjs CHANGED
@@ -261,8 +261,8 @@ async function main(options) {
261
261
  if (!commandId) {
262
262
  return
263
263
  }
264
- let commandStr = req.body.toString()
265
264
  try {
265
+ let commandStr = req.body.toString()
266
266
  let request = {
267
267
  method: req.method,
268
268
  url: req.originalUrl,
@@ -289,12 +289,24 @@ async function main(options) {
289
289
  })
290
290
 
291
291
  function checkCommand(req, res) {
292
+ let error
292
293
  let commandStr = req.body.toString() // raw body through express.raw()
293
- let command = JSONTag.parse(commandStr)
294
- let commandOK = {
295
- command: command?.id,
296
- code: 202,
297
- status: 'accepted'
294
+ try {
295
+ let command = JSONTag.parse(commandStr)
296
+
297
+ let commandOK = {
298
+ command: command?.id,
299
+ code: 202,
300
+ status: 'accepted'
301
+ }
302
+ } catch(err) {
303
+ error = {
304
+ code: 400,
305
+ message: "Bad request",
306
+ details: err
307
+ }
308
+ sendResponse({code: 400, body: JSON.stringify(error)}, res)
309
+ return false
298
310
  }
299
311
  if (!command || !command.id) {
300
312
  error = {