@muze-nl/simplystore 0.5.0 → 0.5.2
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 +3 -4
- package/src/fastParse.mjs +1 -1
- package/src/fastStringify.mjs +105 -140
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@muze-nl/simplystore",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.2",
|
|
4
4
|
"main": "src/server.mjs",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"scripts": {
|
|
@@ -16,13 +16,12 @@
|
|
|
16
16
|
"bugs": "https://github.com/simplyedit/simplystore/issues",
|
|
17
17
|
"homepage": "https://github.com/simplyedit/simplystore#readme",
|
|
18
18
|
"dependencies": {
|
|
19
|
-
"@muze-nl/jsontag": "^0.
|
|
19
|
+
"@muze-nl/jsontag": "^0.9.1",
|
|
20
20
|
"array-where-select": "^0.4.7",
|
|
21
21
|
"codemirror": "^6.0.1",
|
|
22
22
|
"express": "^4.18.1",
|
|
23
23
|
"json-pointer": "^0.6.2",
|
|
24
24
|
"jsonpath-plus": "^7.2.0",
|
|
25
|
-
"piscina": "^4.1.0",
|
|
26
25
|
"vm2": "^3.9.13",
|
|
27
26
|
"write-file-atomic": "^5.0.1"
|
|
28
27
|
},
|
|
@@ -38,4 +37,4 @@
|
|
|
38
37
|
"www/",
|
|
39
38
|
"scripts/"
|
|
40
39
|
]
|
|
41
|
-
}
|
|
40
|
+
}
|
package/src/fastParse.mjs
CHANGED
|
@@ -744,7 +744,7 @@ export default function parse(input, meta, immutable=true)
|
|
|
744
744
|
start: at-1,
|
|
745
745
|
end: at-1+length
|
|
746
746
|
}
|
|
747
|
-
let cache = {}
|
|
747
|
+
let cache = {}
|
|
748
748
|
let targetIsChanged = false
|
|
749
749
|
let parsed = false
|
|
750
750
|
at += length
|
package/src/fastStringify.mjs
CHANGED
|
@@ -6,7 +6,7 @@ import {source,isProxy,getIndex, getBuffer} from './symbols.mjs'
|
|
|
6
6
|
const encoder = new TextEncoder()
|
|
7
7
|
const decoder = new TextDecoder()
|
|
8
8
|
|
|
9
|
-
export default function stringify(value, meta, skipLength=false, index) {
|
|
9
|
+
export default function stringify(value, meta, skipLength=false, index=false) {
|
|
10
10
|
let resultArray = []
|
|
11
11
|
if (!meta) {
|
|
12
12
|
meta = {}
|
|
@@ -19,7 +19,87 @@ export default function stringify(value, meta, skipLength=false, index) {
|
|
|
19
19
|
}
|
|
20
20
|
let references = new WeakMap()
|
|
21
21
|
|
|
22
|
-
|
|
22
|
+
function stringifyValue(value) {
|
|
23
|
+
let prop
|
|
24
|
+
let typeString = JSONTag.getTypeString(value)
|
|
25
|
+
let type = JSONTag.getType(value)
|
|
26
|
+
switch (type) {
|
|
27
|
+
case 'string':
|
|
28
|
+
case 'decimal':
|
|
29
|
+
case 'money':
|
|
30
|
+
case 'link':
|
|
31
|
+
case 'text':
|
|
32
|
+
case 'blob':
|
|
33
|
+
case 'color':
|
|
34
|
+
case 'email':
|
|
35
|
+
case 'hash':
|
|
36
|
+
case 'duration':
|
|
37
|
+
case 'phone':
|
|
38
|
+
case 'url':
|
|
39
|
+
case 'uuid':
|
|
40
|
+
case 'date':
|
|
41
|
+
case 'time':
|
|
42
|
+
case 'datetime':
|
|
43
|
+
if (JSONTag.isNull(value)) {
|
|
44
|
+
value = 'null'
|
|
45
|
+
} else {
|
|
46
|
+
value = JSON.stringify(''+value)
|
|
47
|
+
}
|
|
48
|
+
prop = typeString + value
|
|
49
|
+
break
|
|
50
|
+
case 'int':
|
|
51
|
+
case 'uint':
|
|
52
|
+
case 'int8':
|
|
53
|
+
case 'uint8':
|
|
54
|
+
case 'int16':
|
|
55
|
+
case 'uint16':
|
|
56
|
+
case 'int32':
|
|
57
|
+
case 'uint32':
|
|
58
|
+
case 'int64':
|
|
59
|
+
case 'uint64':
|
|
60
|
+
case 'float':
|
|
61
|
+
case 'float32':
|
|
62
|
+
case 'float64':
|
|
63
|
+
case 'timestamp':
|
|
64
|
+
case 'number':
|
|
65
|
+
case 'boolean':
|
|
66
|
+
if (JSONTag.isNull(value)) {
|
|
67
|
+
value = 'null'
|
|
68
|
+
} else {
|
|
69
|
+
value = JSON.stringify(value)
|
|
70
|
+
}
|
|
71
|
+
prop = typeString + value
|
|
72
|
+
break
|
|
73
|
+
case 'array':
|
|
74
|
+
let entries = value.map(e => stringifyValue(e)).join(',')
|
|
75
|
+
prop = typeString + '[' + entries + ']'
|
|
76
|
+
break
|
|
77
|
+
case 'object':
|
|
78
|
+
if (!value) {
|
|
79
|
+
prop = 'null'
|
|
80
|
+
} else if (value[isProxy]) {
|
|
81
|
+
prop = decoder.decode(value[getBuffer](current))
|
|
82
|
+
} else {
|
|
83
|
+
if (!references.has(value)) {
|
|
84
|
+
references.set(value, resultArray.length)
|
|
85
|
+
resultArray.push(value)
|
|
86
|
+
}
|
|
87
|
+
prop = '~'+references.get(value)
|
|
88
|
+
}
|
|
89
|
+
break
|
|
90
|
+
default:
|
|
91
|
+
throw new Error(JSONTag.getType(value)+' type not yet implemented')
|
|
92
|
+
break
|
|
93
|
+
}
|
|
94
|
+
return prop
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
const encoder = new TextEncoder()
|
|
98
|
+
const decoder = new TextDecoder()
|
|
99
|
+
|
|
100
|
+
// is only ever called on object values
|
|
101
|
+
// and should always return a stringified object, not a reference (~n)
|
|
102
|
+
const innerStringify = (current) => {
|
|
23
103
|
let indent = ""
|
|
24
104
|
let gap = ""
|
|
25
105
|
|
|
@@ -29,147 +109,26 @@ export default function stringify(value, meta, skipLength=false, index) {
|
|
|
29
109
|
indent = space
|
|
30
110
|
}
|
|
31
111
|
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
let enumerable = obj.propertyIsEnumerable(prop) ? '' : '#'
|
|
35
|
-
return enumerable+'"'+prop+'":'+str(prop, obj)
|
|
36
|
-
}).join(',')
|
|
37
|
-
}
|
|
112
|
+
let object = resultArray[current]
|
|
113
|
+
let result
|
|
38
114
|
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
}).join(",")
|
|
43
|
-
return result
|
|
115
|
+
// if value is a valueProxy, just copy the input slice
|
|
116
|
+
if (object && !JSONTag.isNull(object) && object[isProxy]) {
|
|
117
|
+
return decoder.decode(object[getBuffer](current))
|
|
44
118
|
}
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
if (typeof crypto === 'undefined') {
|
|
48
|
-
console.error('JSONTag: cannot generate uuid, crypto support is disabled.')
|
|
49
|
-
throw new Error('Cannot create links to resolve references, crypto support is disabled')
|
|
50
|
-
}
|
|
51
|
-
if (typeof crypto.randomUUID === 'function') {
|
|
52
|
-
var id = crypto.randomUUID()
|
|
53
|
-
} else {
|
|
54
|
-
var id = ([1e7]+-1e3+-4e3+-8e3+-1e11).replace(/[018]/g, c =>
|
|
55
|
-
(c ^ crypto.getRandomValues(new Uint8Array(1))[0] & 15 >> c / 4).toString(16)
|
|
56
|
-
);
|
|
57
|
-
}
|
|
58
|
-
JSONTag.setAttribute(value, 'id', id)
|
|
59
|
-
return id
|
|
119
|
+
if (typeof object === 'undefined' || object === null) {
|
|
120
|
+
return 'null'
|
|
60
121
|
}
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
let
|
|
67
|
-
|
|
68
|
-
// if value is a valueProxy, just copy the input slice
|
|
69
|
-
if (value && !JSONTag.isNull(value) && value[isProxy]) {
|
|
70
|
-
if (index===0) {
|
|
71
|
-
resultArray.push(decoder.decode(value[getBuffer](index)))
|
|
72
|
-
}
|
|
73
|
-
return decoder.decode(value[getBuffer](index))
|
|
74
|
-
}
|
|
75
|
-
if (typeof value === 'undefined' || value === null) {
|
|
76
|
-
return 'null'
|
|
77
|
-
}
|
|
78
|
-
if (JSONTag.getType(value) === 'object' && !Array.isArray(value)) {
|
|
79
|
-
let id = JSONTag.getAttribute(value, 'id')
|
|
80
|
-
if (!references.has(value)) {
|
|
81
|
-
let reference = resultArray.length
|
|
82
|
-
updateReference = reference
|
|
83
|
-
references.set(value, updateReference)
|
|
84
|
-
resultArray.push('')
|
|
85
|
-
if (id && !meta.index.id.has(id)) {
|
|
86
|
-
meta.index.id.set(id, updateReference)
|
|
87
|
-
}
|
|
88
|
-
} else {
|
|
89
|
-
return '~'+references.get(value)
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
if (Array.isArray(value)) {
|
|
93
|
-
result = JSONTag.getTypeString(value) + "["+encodeEntries(value)+"]"
|
|
94
|
-
} else if (value instanceof Object) {
|
|
95
|
-
let typeString = JSONTag.getTypeString(value)
|
|
96
|
-
let type = JSONTag.getType(value)
|
|
97
|
-
switch (type) {
|
|
98
|
-
case 'string':
|
|
99
|
-
case 'decimal':
|
|
100
|
-
case 'money':
|
|
101
|
-
case 'link':
|
|
102
|
-
case 'text':
|
|
103
|
-
case 'blob':
|
|
104
|
-
case 'color':
|
|
105
|
-
case 'email':
|
|
106
|
-
case 'hash':
|
|
107
|
-
case 'duration':
|
|
108
|
-
case 'phone':
|
|
109
|
-
case 'url':
|
|
110
|
-
case 'uuid':
|
|
111
|
-
case 'date':
|
|
112
|
-
case 'time':
|
|
113
|
-
case 'datetime':
|
|
114
|
-
if (JSONTag.isNull(value)) {
|
|
115
|
-
value = 'null'
|
|
116
|
-
} else {
|
|
117
|
-
value = JSON.stringify(''+value)
|
|
118
|
-
}
|
|
119
|
-
result = typeString + value
|
|
120
|
-
break
|
|
121
|
-
case 'int':
|
|
122
|
-
case 'uint':
|
|
123
|
-
case 'int8':
|
|
124
|
-
case 'uint8':
|
|
125
|
-
case 'int16':
|
|
126
|
-
case 'uint16':
|
|
127
|
-
case 'int32':
|
|
128
|
-
case 'uint32':
|
|
129
|
-
case 'int64':
|
|
130
|
-
case 'uint64':
|
|
131
|
-
case 'float':
|
|
132
|
-
case 'float32':
|
|
133
|
-
case 'float64':
|
|
134
|
-
case 'timestamp':
|
|
135
|
-
case 'number':
|
|
136
|
-
case 'boolean':
|
|
137
|
-
if (JSONTag.isNull(value)) {
|
|
138
|
-
value = 'null'
|
|
139
|
-
} else {
|
|
140
|
-
value = JSON.stringify(value)
|
|
141
|
-
}
|
|
142
|
-
result = typeString + value
|
|
143
|
-
break
|
|
144
|
-
case 'array':
|
|
145
|
-
let entries = encodeEntries(value) // calculate children first so parent references can add id attribute
|
|
146
|
-
result = typeString + '[' + entries + '}'
|
|
147
|
-
break
|
|
148
|
-
case 'object':
|
|
149
|
-
if (JSONTag.isNull(value)) {
|
|
150
|
-
result = typeString + "null"
|
|
151
|
-
} else {
|
|
152
|
-
let props = encodeProperties(value); // calculate children first so parent references can add id attribute
|
|
153
|
-
result = typeString + '{' + props + '}'
|
|
154
|
-
}
|
|
155
|
-
break
|
|
156
|
-
default:
|
|
157
|
-
throw new Error(JSONTag.getType(value)+' type not yet implemented')
|
|
158
|
-
break
|
|
159
|
-
}
|
|
160
|
-
} else {
|
|
161
|
-
result = JSON.stringify(value)
|
|
162
|
-
}
|
|
163
|
-
if (typeof updateReference != 'undefined') {
|
|
164
|
-
resultArray[updateReference] = result
|
|
165
|
-
if (index!==updateReference) {
|
|
166
|
-
result = '~'+updateReference
|
|
167
|
-
}
|
|
168
|
-
}
|
|
169
|
-
return result
|
|
122
|
+
|
|
123
|
+
let props = []
|
|
124
|
+
for (let key of Object.getOwnPropertyNames(object)) {
|
|
125
|
+
let value = object[key]
|
|
126
|
+
let prop = stringifyValue(value)
|
|
127
|
+
let enumerable = object.propertyIsEnumerable(key) ? '' : '#'
|
|
128
|
+
props.push(enumerable+'"'+key+'":'+prop)
|
|
170
129
|
}
|
|
171
|
-
|
|
172
|
-
return
|
|
130
|
+
result = JSONTag.getTypeString(object)+'{'+props.join(',')+'}'
|
|
131
|
+
return result
|
|
173
132
|
}
|
|
174
133
|
|
|
175
134
|
const encode = (s) => {
|
|
@@ -180,7 +139,13 @@ export default function stringify(value, meta, skipLength=false, index) {
|
|
|
180
139
|
return '('+length+')'+s
|
|
181
140
|
}
|
|
182
141
|
|
|
183
|
-
|
|
142
|
+
resultArray.push(value)
|
|
143
|
+
let current = 0
|
|
144
|
+
while(current<resultArray.length) {
|
|
145
|
+
resultArray[current] = innerStringify(current)
|
|
146
|
+
current++
|
|
147
|
+
}
|
|
148
|
+
|
|
184
149
|
return resultArray.map(encode).join("\n")
|
|
185
150
|
}
|
|
186
151
|
|