@muze-nl/simplystore 0.5.4 → 0.5.5

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.4",
3
+ "version": "0.5.5",
4
4
  "main": "src/server.mjs",
5
5
  "type": "module",
6
6
  "scripts": {
@@ -77,6 +77,7 @@ 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
80
81
  FastJSONTag.setAttribute(dataspace, 'command', task.id)
81
82
 
82
83
  const strData = resultSetStringify(resultSet)
@@ -87,7 +88,7 @@ export default async function runCommand(commandStr, request) {
87
88
  id: meta.index.id
88
89
  }
89
90
  }
90
-
91
+ //TODO: write data every x commands or x minutes, in seperate thread
91
92
  await writeFileAtomic(datafile, uint8sab)
92
93
  let end = Date.now()
93
94
  console.log('task time',end-time)
package/src/server.mjs CHANGED
@@ -29,43 +29,43 @@ async function main(options) {
29
29
  const commandLog = options.commandLog || './command-log.jsontag'
30
30
  const commandStatus = options.commandStatus || './command-status.jsontag'
31
31
 
32
- server.use(express.static(wwwroot))
32
+ server.use(express.static(wwwroot))
33
33
 
34
- // allow access to raw body, used to parse a query send as post body
34
+ // allow access to raw body, used to parse a query send as post body
35
35
  server.use(express.raw({
36
36
  type: (req) => true // parse body on all requests
37
37
  }))
38
38
 
39
39
  function loadData() {
40
- return new Promise((resolve,reject) => {
41
- let worker = new Worker(loadWorker)
42
- worker.on('message', result => {
43
- resolve(result)
44
- worker.terminate()
45
- })
46
- worker.on('error', error => {
47
- reject(error)
48
- worker.terminate()
49
- })
50
- worker.postMessage(datafile)
51
- })
40
+ return new Promise((resolve,reject) => {
41
+ let worker = new Worker(loadWorker)
42
+ worker.on('message', result => {
43
+ resolve(result)
44
+ worker.terminate()
45
+ })
46
+ worker.on('error', error => {
47
+ reject(error)
48
+ worker.terminate()
49
+ })
50
+ worker.postMessage(datafile)
51
+ })
52
52
  }
53
53
  try {
54
54
  let data = await loadData()
55
- jsontagBuffer = data.data
55
+ jsontagBuffer = data.data
56
56
  meta = data.meta
57
- } catch(err) {
58
- console.error('ERROR: SimplyStore cannot load '+datafile, err)
59
- process.exit(1)
60
- }
57
+ } catch(err) {
58
+ console.error('ERROR: SimplyStore cannot load '+datafile, err)
59
+ process.exit(1)
60
+ }
61
61
 
62
62
  const queryWorkerInitTask = () => {
63
63
  return {
64
- name: 'init',
65
- req: {
66
- body: jsontagBuffer,
64
+ name: 'init',
65
+ req: {
66
+ body: jsontagBuffer,
67
67
  meta
68
- }
68
+ }
69
69
  }
70
70
  }
71
71
 
@@ -94,19 +94,19 @@ async function main(options) {
94
94
  let path = req.path.substr(6) // cut '/query'
95
95
  console.log('query',path)
96
96
  let request = {
97
- method: req.method,
98
- url: req.originalUrl,
99
- query: req.query,
100
- path: path
97
+ method: req.method,
98
+ url: req.originalUrl,
99
+ query: req.query,
100
+ path: path
101
101
  }
102
102
  if (accept(req,res,['application/jsontag'])) {
103
103
  request.jsontag = true
104
104
  }
105
105
  try {
106
- let result = await queryWorkerPool.run('query', request)
107
- sendResponse(result, res)
106
+ let result = await queryWorkerPool.run('query', request)
107
+ sendResponse(result, res)
108
108
  } catch(error) {
109
- sendError(error, res)
109
+ sendError(error, res)
110
110
  }
111
111
  let end = Date.now()
112
112
  console.log(path, (end-start), process.memoryUsage())
@@ -122,20 +122,20 @@ async function main(options) {
122
122
  }
123
123
  let path = req.path.substr(6) // cut '/query'
124
124
  let request = {
125
- method: req.method,
126
- url: req.originalUrl,
127
- query: req.query,
128
- path: path,
129
- body: req.body.toString()
125
+ method: req.method,
126
+ url: req.originalUrl,
127
+ query: req.query,
128
+ path: path,
129
+ body: req.body.toString()
130
130
  }
131
131
  if (accept(req,res,['application/jsontag'])) {
132
132
  request.jsontag = true
133
133
  }
134
134
  try {
135
- let result = await queryWorkerPool.run('query', request)
136
- sendResponse(result, res)
135
+ let result = await queryWorkerPool.run('query', request)
136
+ sendResponse(result, res)
137
137
  } catch(error) {
138
- sendError(error, res)
138
+ sendError(error, res)
139
139
  }
140
140
  let end = Date.now()
141
141
  console.log(path, (end-start), process.memoryUsage())
@@ -153,9 +153,13 @@ async function main(options) {
153
153
  let lines = file.split("\n").filter(Boolean) //filter clears empty lines
154
154
  for(let line of lines) {
155
155
  let command = JSONTag.parse(line)
156
- status.set(command.id, command)
156
+ status.set(command.command, command)
157
157
  }
158
+ } else {
159
+ console.error('Could not open command status',commandStatusFile)
158
160
  }
161
+ } else {
162
+ console.log('no command status', commandStatusFile)
159
163
  }
160
164
  return status
161
165
  }