@muze-nl/od-jsontag 0.3.3 → 0.4.0
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 +5 -3
- package/src/jsontag.mjs +30 -0
- package/src/parse.mjs +583 -993
- package/src/serialize.mjs +8 -9
- package/src/symbols.mjs +1 -0
package/src/serialize.mjs
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import JSONTag from '@muze-nl/jsontag';
|
|
2
2
|
import {source,isProxy, isChanged, getIndex, getBuffer, resultSet} from './symbols.mjs'
|
|
3
|
-
import * as odJSONTag from './jsontag.mjs'
|
|
4
3
|
|
|
5
4
|
// faststringify function for a fast parseable arraybuffer output
|
|
6
5
|
//
|
|
@@ -40,8 +39,8 @@ export default function serialize(value, options={}) {
|
|
|
40
39
|
|
|
41
40
|
function stringifyValue(value, inarray=false, current) {
|
|
42
41
|
let prop
|
|
43
|
-
let typeString =
|
|
44
|
-
let type =
|
|
42
|
+
let typeString = JSONTag.getTypeString(value)
|
|
43
|
+
let type = JSONTag.getType(value)
|
|
45
44
|
switch (type) {
|
|
46
45
|
case 'string':
|
|
47
46
|
case 'decimal':
|
|
@@ -59,7 +58,7 @@ export default function serialize(value, options={}) {
|
|
|
59
58
|
case 'date':
|
|
60
59
|
case 'time':
|
|
61
60
|
case 'datetime':
|
|
62
|
-
if (
|
|
61
|
+
if (JSONTag.isNull(value)) {
|
|
63
62
|
value = 'null'
|
|
64
63
|
} else {
|
|
65
64
|
value = realJSON.stringify(''+value)
|
|
@@ -82,7 +81,7 @@ export default function serialize(value, options={}) {
|
|
|
82
81
|
case 'timestamp':
|
|
83
82
|
case 'number':
|
|
84
83
|
case 'boolean':
|
|
85
|
-
if (
|
|
84
|
+
if (JSONTag.isNull(value)) {
|
|
86
85
|
value = 'null'
|
|
87
86
|
} else {
|
|
88
87
|
value = realJSON.stringify(value)
|
|
@@ -149,7 +148,7 @@ export default function serialize(value, options={}) {
|
|
|
149
148
|
let result
|
|
150
149
|
|
|
151
150
|
// if value is a valueProxy, just copy the input slice
|
|
152
|
-
if (object && !
|
|
151
|
+
if (object && !JSONTag.isNull(object) && object[isProxy] && !object[isChanged]) {
|
|
153
152
|
return decoder.decode(object[getBuffer](current))
|
|
154
153
|
}
|
|
155
154
|
if (typeof object === 'undefined' || object === null) {
|
|
@@ -163,7 +162,7 @@ export default function serialize(value, options={}) {
|
|
|
163
162
|
let enumerable = object.propertyIsEnumerable(key) ? '' : '#'
|
|
164
163
|
props.push(enumerable+realJSON.stringify(key)+':'+prop) //FIXME: how does key get escaped?
|
|
165
164
|
}
|
|
166
|
-
result =
|
|
165
|
+
result = JSONTag.getTypeString(object)+'{'+props.join(',')+'}'
|
|
167
166
|
return result
|
|
168
167
|
}
|
|
169
168
|
|
|
@@ -201,7 +200,7 @@ export default function serialize(value, options={}) {
|
|
|
201
200
|
}
|
|
202
201
|
result[currentResult] = encoder.encode(innerStringify(currentSource))
|
|
203
202
|
if (options.meta) {
|
|
204
|
-
const id=
|
|
203
|
+
const id=JSONTag.getAttribute(resultArray[currentSource],'id')
|
|
205
204
|
if (id) {
|
|
206
205
|
options.meta.index.id.set(id, currentSource)
|
|
207
206
|
}
|
|
@@ -210,7 +209,7 @@ export default function serialize(value, options={}) {
|
|
|
210
209
|
} else if (!options.changes) {
|
|
211
210
|
result[currentResult] = resultArray[currentSource][getBuffer](currentSource)
|
|
212
211
|
if (options.meta) {
|
|
213
|
-
const id=
|
|
212
|
+
const id=JSONTag.getAttribute(resultArray[currentSource],'id')
|
|
214
213
|
if (id) {
|
|
215
214
|
options.meta.index.id.set(id, currentSource)
|
|
216
215
|
}
|
package/src/symbols.mjs
CHANGED
|
@@ -5,6 +5,7 @@ export const getBuffer = Symbol('getBuffer')
|
|
|
5
5
|
export const getIndex = Symbol('getIndex')
|
|
6
6
|
export const isChanged = Symbol('isChanged')
|
|
7
7
|
export const isParsed = Symbol('isParsed')
|
|
8
|
+
export const isReceived = Symbol('isReceived')
|
|
8
9
|
export const getString = Symbol('getString')
|
|
9
10
|
export const position = Symbol('position')
|
|
10
11
|
export const parent = Symbol('parent')
|