@muze-nl/simplystore 0.5.6 → 0.5.7

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.6",
3
+ "version": "0.5.7",
4
4
  "main": "src/server.mjs",
5
5
  "type": "module",
6
6
  "scripts": {
@@ -1,5 +1,5 @@
1
1
  import JSONTag from '@muze-nl/jsontag'
2
- import {source, isChanged} from './symbols.mjs'
2
+ import {source, isChanged, getIndex} from './symbols.mjs'
3
3
  import fastParse from './fastParse.mjs'
4
4
  import {stringToSAB,resultSetStringify} from './fastStringify.mjs'
5
5
  import writeFileAtomic from 'write-file-atomic'
@@ -25,8 +25,16 @@ export const metaIdProxy = {
25
25
  })
26
26
  },
27
27
  set: (id,ref) => {
28
- //FIXME: is this correct?
29
- meta.index.id.set(id, resultSet.length-1)
28
+ if (!meta.index.id.has(id)) {
29
+ if (ref[getIndex]) {
30
+ meta.index.id.set(id, ref[getIndex])
31
+ } else {
32
+ throw new Error('cannot set index.id for non-proxy')
33
+ }
34
+ } else {
35
+ let line = meta.index.id.get(id)
36
+ resultSet[line] = ref
37
+ }
30
38
  },
31
39
  get: (id) => {
32
40
  let index = meta.index.id.get(id)
@@ -44,15 +52,16 @@ export const metaIdProxy = {
44
52
  }
45
53
 
46
54
  export const FastJSONTag = {
47
- getType: (obj) => JSONTag.getType(obj[source]),
48
- getAttribute: (obj, attr) => JSONTag.getAttribute(obj[source],attr),
55
+ getType: (obj) => JSONTag.getType(obj?.[source]),
56
+ getAttribute: (obj, attr) => JSONTag.getAttribute(obj?.[source],attr),
49
57
  setAttribute: (obj, attr, value) => {
58
+ if (!obj) return
50
59
  obj[isChanged] = true
51
60
  return JSONTag.setAttribute(obj[source], attr, value)
52
61
  },
53
- getAttributes: (obj) => JSONTag.getAttributes(obj[source]),
54
- getAttributeString: (obj) => JSONTag.getAttributesString(obj[source]),
55
- getTypeString: (obj) => JSONTag.getTypeString(obj[source])
62
+ getAttributes: (obj) => JSONTag.getAttributes(obj?.[source]),
63
+ getAttributeString: (obj) => JSONTag.getAttributesString(obj?.[source]),
64
+ getTypeString: (obj) => JSONTag.getTypeString(obj?.[source])
56
65
  }
57
66
 
58
67
  export async function initialize(task) {
package/src/fastParse.mjs CHANGED
@@ -726,7 +726,7 @@ export default function parse(input, meta, immutable=true)
726
726
  if (JSONTag.getType(value)==='object' && !value[isProxy]) {
727
727
  value = getNewValueProxy(value)
728
728
  }
729
- target[prop] = val
729
+ target[prop] = value
730
730
  return true
731
731
  }
732
732
  }
@@ -761,6 +761,9 @@ export default function parse(input, meta, immutable=true)
761
761
  get(target, prop) {
762
762
  if (target[prop] instanceof Function) {
763
763
  if (['copyWithin','fill','pop','push','reverse','shift','sort','splice','unshift'].indexOf(prop)!==-1) {
764
+ if (immutable) {
765
+ throw new Error('dataspace is immutable')
766
+ }
764
767
  targetIsChanged = true
765
768
  }
766
769
  return (...args) => {
@@ -782,6 +785,9 @@ export default function parse(input, meta, immutable=true)
782
785
  }
783
786
  },
784
787
  set(target, prop, value) {
788
+ if (immutable) {
789
+ throw new Error('dataspace is immutable')
790
+ }
785
791
  if (JSONTag.getType(value)==='object' && !value[isProxy]) {
786
792
  value = getNewValueProxy(value)
787
793
  }
@@ -790,6 +796,9 @@ export default function parse(input, meta, immutable=true)
790
796
  return true
791
797
  },
792
798
  deleteProperty(target, prop) {
799
+ if (immutable) {
800
+ throw new Error('dataspace is immutable')
801
+ }
793
802
  //FIXME: if target[prop] was the last reference to an object
794
803
  //that object should be deleted so that its line will become empty
795
804
  //when stringifying resultArray again
@@ -828,7 +837,7 @@ export default function parse(input, meta, immutable=true)
828
837
  return targetIsChanged
829
838
  break
830
839
  default:
831
- if (!immutable && Array.isArray(target[prop])) {
840
+ if (Array.isArray(target[prop]) && target[prop].propertyIsEnumerable()) {
832
841
  return new Proxy(target[prop], arrayHandler)
833
842
  }
834
843
  return target[prop] // FIXME: make arrays immutable as well
@@ -1021,5 +1030,4 @@ export default function parse(input, meta, immutable=true)
1021
1030
  }
1022
1031
 
1023
1032
  return resultArray
1024
- }
1025
-
1033
+ }
package/src/server.mjs CHANGED
@@ -289,12 +289,12 @@ async function main(options) {
289
289
  })
290
290
 
291
291
  function checkCommand(req, res) {
292
- let error
292
+ let error, command, commandOK
293
293
  let commandStr = req.body.toString() // raw body through express.raw()
294
294
  try {
295
- let command = JSONTag.parse(commandStr)
295
+ command = JSONTag.parse(commandStr)
296
296
 
297
- let commandOK = {
297
+ commandOK = {
298
298
  command: command?.id,
299
299
  code: 202,
300
300
  status: 'accepted'