@muze-nl/simplystore 0.6.7 → 0.6.8

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/README.md CHANGED
@@ -6,7 +6,7 @@ SimplyStore is a radically simpler backend storage server. It does not have a da
6
6
  Javascript queries are run in a [VM2](https://www.npmjs.com/package/vm2) sandbox.
7
7
  You can query data using the [array-where-select](https://www.npmjs.com/package/array-where-select) extension.
8
8
 
9
- Note: _There are known security issues in VM2, so the project will switch to V8-isolate. For now don't use SimplyStore in production_
9
+ Note: _There are known security issues in VM2, so the project will switch to V8-isolate. For now make sure SimplyStore is not publically accessible, by adding an api gateway in front of it for example_
10
10
 
11
11
  ## Table of Contents
12
12
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@muze-nl/simplystore",
3
- "version": "0.6.7",
3
+ "version": "0.6.8",
4
4
  "main": "src/server.mjs",
5
5
  "type": "module",
6
6
  "scripts": {
@@ -17,7 +17,7 @@
17
17
  "homepage": "https://github.com/simplyedit/simplystore#readme",
18
18
  "dependencies": {
19
19
  "@muze-nl/jsontag": "^0.9.6",
20
- "@muze-nl/od-jsontag": "^0.1.4",
20
+ "@muze-nl/od-jsontag": "^0.1.5",
21
21
  "codemirror": "^6.0.1",
22
22
  "express": "^4.18.1",
23
23
  "jaqt": "^0.6.2",
@@ -28,17 +28,21 @@ const metaIdProxy = {
28
28
  }
29
29
 
30
30
  const tasks = {
31
- init: async (task) => {
32
- dataspace = parse(task.req.body)
33
- resultArr = dataspace[resultSet]
31
+ init: async (task) => {
32
+ if (task.req.access) {
33
+ task.req.access = await import(task.req.access)
34
+ task.req.access = task.req.access.default
35
+ }
36
+ dataspace = parse(task.req.body, { access: task.req.access })
37
+ resultArr = dataspace[resultSet]
34
38
  meta = task.req.meta
35
39
  metaProxy.index.id = metaIdProxy
36
- //@TODO: add references and baseURL
37
- return true
38
- },
39
- query: async (task) => {
40
- return runQuery(task.req.path, task.req, task.req.body)
41
- },
40
+ //@TODO: add meta.index.references? and baseURL
41
+ return true
42
+ },
43
+ query: async (task) => {
44
+ return runQuery(task.req.path, task.req, task.req.body)
45
+ },
42
46
  memoryUsage: async () => {
43
47
  let result = memoryUsage()
44
48
  console.log('memory',result)
@@ -51,7 +55,7 @@ export default tasks
51
55
  export function runQuery(pointer, request, query) {
52
56
  if (!pointer) { throw new Error('missing pointer parameter')}
53
57
  if (!request) { throw new Error('missing request parameter')}
54
- let response = {
58
+ let response = {
55
59
  jsontag: request.jsontag
56
60
  }
57
61
  let [result,path] = getDataSpace(pointer, dataspace)
@@ -85,16 +89,16 @@ export function runQuery(pointer, request, query) {
85
89
  wasm: false
86
90
  })
87
91
  try {
88
- result = deProxy(vm.run(query))
92
+ result = vm.run(query)
89
93
  let used = Math.round(process.memoryUsage().heapUsed / 1024 / 1024);
90
94
  console.log(`(${used} MB)`);
91
95
  } catch(err) {
92
96
  console.log(err)
93
97
  response.code = 422;
94
98
  if (request.jsontag) {
95
- response.body = '<object class="Error">{"message":'+JSON.stringify(''+err)+',"code":422}'
99
+ response.body = '<object class="Error">{"message":'+JSON.stringify(''+err)+',"code":422}'
96
100
  } else {
97
- response.body = JSON.stringify({message:err, code: 422})
101
+ response.body = JSON.stringify({message:err, code: 422})
98
102
  }
99
103
  }
100
104
  } else {
@@ -103,7 +107,7 @@ export function runQuery(pointer, request, query) {
103
107
  if (!response.code) {
104
108
  if (response.jsontag) {
105
109
  try {
106
- response.body = JSONTag.stringify(result)
110
+ response.body = JSONTag.stringify(result)
107
111
  } catch(err) {
108
112
  console.log(err)
109
113
  response.code = 500
@@ -111,7 +115,7 @@ export function runQuery(pointer, request, query) {
111
115
  }
112
116
  } else {
113
117
  //@FIXME: replace recursive links
114
- response.body = JSON.stringify(result)
118
+ response.body = JSON.stringify(result)
115
119
  }
116
120
  }
117
121
  return response
@@ -169,33 +173,4 @@ export function linkReplacer(data, baseURL) {
169
173
  })
170
174
  }
171
175
  return data
172
- }
173
-
174
- let seen = new WeakMap()
175
- function deProxy(o) {
176
- if (!o) {
177
- return o
178
- }
179
- if (typeof o !== 'object') {
180
- return o
181
- }
182
- if (seen.has(o)) {
183
- return seen.get(o)
184
- }
185
- let result
186
- if (Array.isArray(o)) {
187
- result = o.map(deProxy)
188
- } else if (JSONTag.isNull(o)) {
189
- return o
190
- } else if (JSONTag.getType(o)==='object' && o[source]) {
191
- result = JSONTag.clone(o[source])
192
- seen.set(o, result)
193
- Object.entries(o[source]).forEach(([i,v]) => {
194
- result[i] = deProxy(v)
195
- })
196
- } else {
197
- seen.set(o, o)
198
- result = o
199
- }
200
- return result
201
- }
176
+ }
package/src/server.mjs CHANGED
@@ -28,6 +28,7 @@ async function main(options) {
28
28
  const commandsFile = options.commandsFile || __dirname+'/src/commands.mjs'
29
29
  const commandLog = options.commandLog || './command-log.jsontag'
30
30
  const commandStatus = options.commandStatus || './command-status.jsontag'
31
+ const access = options.access || null
31
32
 
32
33
  server.use(express.static(wwwroot))
33
34
 
@@ -64,7 +65,8 @@ async function main(options) {
64
65
  name: 'init',
65
66
  req: {
66
67
  body: jsontagBuffer,
67
- meta
68
+ meta,
69
+ access
68
70
  }
69
71
  }
70
72
  }