json-as 1.2.6 → 1.3.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/.as-test/coverage/naive/coverage.arbitrary.spec.ts.log.json +5628 -0
- package/.as-test/coverage/naive/coverage.array.spec.ts.log.json +5187 -0
- package/.as-test/coverage/naive/coverage.bool.spec.ts.log.json +5187 -0
- package/.as-test/coverage/naive/coverage.box.spec.ts.log.json +5187 -0
- package/.as-test/coverage/naive/coverage.custom.spec.ts.log.json +5187 -0
- package/.as-test/coverage/naive/coverage.date.spec.ts.log.json +5187 -0
- package/.as-test/coverage/naive/coverage.enum.spec.ts.log.json +5187 -0
- package/.as-test/coverage/naive/coverage.float.spec.ts.log.json +5187 -0
- package/.as-test/coverage/naive/coverage.generics.spec.ts.log.json +5187 -0
- package/.as-test/coverage/naive/coverage.hierarchy.spec.ts.log.json +5187 -0
- package/.as-test/coverage/naive/coverage.integer.spec.ts.log.json +5187 -0
- package/.as-test/coverage/naive/coverage.map.spec.ts.log.json +5187 -0
- package/.as-test/coverage/naive/coverage.namespace.spec.ts.log.json +5187 -0
- package/.as-test/coverage/naive/coverage.null.spec.ts.log.json +5187 -0
- package/.as-test/coverage/naive/coverage.raw.spec.ts.log.json +5187 -0
- package/.as-test/coverage/naive/coverage.resolving.spec.ts.log.json +5628 -0
- package/.as-test/coverage/naive/coverage.set.spec.ts.log.json +5187 -0
- package/.as-test/coverage/naive/coverage.staticarray.spec.ts.log.json +5187 -0
- package/.as-test/coverage/naive/coverage.string.spec.ts.log.json +5187 -0
- package/.as-test/coverage/naive/coverage.struct.spec.ts.log.json +5187 -0
- package/.as-test/coverage/naive/coverage.types.spec.ts.log.json +5187 -0
- package/.as-test/coverage/simd/coverage.arbitrary.spec.ts.log.json +5628 -0
- package/.as-test/coverage/simd/coverage.array.spec.ts.log.json +5187 -0
- package/.as-test/coverage/simd/coverage.bool.spec.ts.log.json +5187 -0
- package/.as-test/coverage/simd/coverage.box.spec.ts.log.json +5187 -0
- package/.as-test/coverage/simd/coverage.custom.spec.ts.log.json +5187 -0
- package/.as-test/coverage/simd/coverage.date.spec.ts.log.json +5187 -0
- package/.as-test/coverage/simd/coverage.enum.spec.ts.log.json +5187 -0
- package/.as-test/coverage/simd/coverage.float.spec.ts.log.json +5187 -0
- package/.as-test/coverage/simd/coverage.generics.spec.ts.log.json +5187 -0
- package/.as-test/coverage/simd/coverage.hierarchy.spec.ts.log.json +5187 -0
- package/.as-test/coverage/simd/coverage.integer.spec.ts.log.json +5187 -0
- package/.as-test/coverage/simd/coverage.map.spec.ts.log.json +5187 -0
- package/.as-test/coverage/simd/coverage.namespace.spec.ts.log.json +5187 -0
- package/.as-test/coverage/simd/coverage.null.spec.ts.log.json +5187 -0
- package/.as-test/coverage/simd/coverage.raw.spec.ts.log.json +5187 -0
- package/.as-test/coverage/simd/coverage.resolving.spec.ts.log.json +5628 -0
- package/.as-test/coverage/simd/coverage.set.spec.ts.log.json +5187 -0
- package/.as-test/coverage/simd/coverage.staticarray.spec.ts.log.json +5187 -0
- package/.as-test/coverage/simd/coverage.string.spec.ts.log.json +5187 -0
- package/.as-test/coverage/simd/coverage.struct.spec.ts.log.json +5187 -0
- package/.as-test/coverage/simd/coverage.types.spec.ts.log.json +5187 -0
- package/.as-test/coverage/swar/coverage.arbitrary.spec.ts.log.json +5628 -0
- package/.as-test/coverage/swar/coverage.array.spec.ts.log.json +5187 -0
- package/.as-test/coverage/swar/coverage.bool.spec.ts.log.json +5187 -0
- package/.as-test/coverage/swar/coverage.box.spec.ts.log.json +5187 -0
- package/.as-test/coverage/swar/coverage.custom.spec.ts.log.json +5187 -0
- package/.as-test/coverage/swar/coverage.date.spec.ts.log.json +5187 -0
- package/.as-test/coverage/swar/coverage.enum.spec.ts.log.json +5187 -0
- package/.as-test/coverage/swar/coverage.float.spec.ts.log.json +5187 -0
- package/.as-test/coverage/swar/coverage.generics.spec.ts.log.json +5187 -0
- package/.as-test/coverage/swar/coverage.hierarchy.spec.ts.log.json +5187 -0
- package/.as-test/coverage/swar/coverage.integer.spec.ts.log.json +5187 -0
- package/.as-test/coverage/swar/coverage.map.spec.ts.log.json +5187 -0
- package/.as-test/coverage/swar/coverage.namespace.spec.ts.log.json +5187 -0
- package/.as-test/coverage/swar/coverage.null.spec.ts.log.json +5187 -0
- package/.as-test/coverage/swar/coverage.raw.spec.ts.log.json +5187 -0
- package/.as-test/coverage/swar/coverage.resolving.spec.ts.log.json +5628 -0
- package/.as-test/coverage/swar/coverage.set.spec.ts.log.json +5187 -0
- package/.as-test/coverage/swar/coverage.staticarray.spec.ts.log.json +5187 -0
- package/.as-test/coverage/swar/coverage.string.spec.ts.log.json +5187 -0
- package/.as-test/coverage/swar/coverage.struct.spec.ts.log.json +5187 -0
- package/.as-test/coverage/swar/coverage.types.spec.ts.log.json +5187 -0
- package/.as-test/logs/naive/run.arbitrary.spec.ts.log.json +943 -0
- package/.as-test/logs/naive/run.array.spec.ts.log.json +1053 -0
- package/.as-test/logs/naive/run.bool.spec.ts.log.json +257 -0
- package/.as-test/logs/naive/run.box.spec.ts.log.json +353 -0
- package/.as-test/logs/naive/run.custom.spec.ts.log.json +309 -0
- package/.as-test/logs/naive/run.date.spec.ts.log.json +397 -0
- package/.as-test/logs/naive/run.enum.spec.ts.log.json +343 -0
- package/.as-test/logs/naive/run.float.spec.ts.log.json +453 -0
- package/.as-test/logs/naive/run.generics.spec.ts.log.json +393 -0
- package/.as-test/logs/naive/run.hierarchy.spec.ts.log.json +325 -0
- package/.as-test/logs/naive/run.integer.spec.ts.log.json +373 -0
- package/.as-test/logs/naive/run.map.spec.ts.log.json +247 -0
- package/.as-test/logs/naive/run.namespace.spec.ts.log.json +361 -0
- package/.as-test/logs/naive/run.null.spec.ts.log.json +273 -0
- package/.as-test/logs/naive/run.raw.spec.ts.log.json +309 -0
- package/.as-test/logs/naive/run.resolving.spec.ts.log.json +273 -0
- package/.as-test/logs/naive/run.set.spec.ts.log.json +733 -0
- package/.as-test/logs/naive/run.staticarray.spec.ts.log.json +931 -0
- package/.as-test/logs/naive/run.string.spec.ts.log.json +2289 -0
- package/.as-test/logs/naive/run.struct.spec.ts.log.json +523 -0
- package/.as-test/logs/naive/run.types.spec.ts.log.json +273 -0
- package/.as-test/logs/naive/test.arbitrary.spec.ts.log.json +943 -0
- package/.as-test/logs/naive/test.array.spec.ts.log.json +1053 -0
- package/.as-test/logs/naive/test.bool.spec.ts.log.json +257 -0
- package/.as-test/logs/naive/test.box.spec.ts.log.json +353 -0
- package/.as-test/logs/naive/test.custom.spec.ts.log.json +309 -0
- package/.as-test/logs/naive/test.date.spec.ts.log.json +397 -0
- package/.as-test/logs/naive/test.enum.spec.ts.log.json +343 -0
- package/.as-test/logs/naive/test.float.spec.ts.log.json +453 -0
- package/.as-test/logs/naive/test.generics.spec.ts.log.json +393 -0
- package/.as-test/logs/naive/test.hierarchy.spec.ts.log.json +325 -0
- package/.as-test/logs/naive/test.integer.spec.ts.log.json +373 -0
- package/.as-test/logs/naive/test.log.json +2289 -0
- package/.as-test/logs/naive/test.map.spec.ts.log.json +247 -0
- package/.as-test/logs/naive/test.namespace.spec.ts.log.json +361 -0
- package/.as-test/logs/naive/test.null.spec.ts.log.json +273 -0
- package/.as-test/logs/naive/test.raw.spec.ts.log.json +309 -0
- package/.as-test/logs/naive/test.resolving.spec.ts.log.json +273 -0
- package/.as-test/logs/naive/test.set.spec.ts.log.json +733 -0
- package/.as-test/logs/naive/test.staticarray.spec.ts.log.json +931 -0
- package/.as-test/logs/naive/test.string.spec.ts.log.json +2345 -0
- package/.as-test/logs/naive/test.struct.spec.ts.log.json +523 -0
- package/.as-test/logs/naive/test.types.spec.ts.log.json +273 -0
- package/.as-test/logs/simd/run.arbitrary.spec.ts.log.json +943 -0
- package/.as-test/logs/simd/run.array.spec.ts.log.json +1053 -0
- package/.as-test/logs/simd/run.bool.spec.ts.log.json +257 -0
- package/.as-test/logs/simd/run.box.spec.ts.log.json +353 -0
- package/.as-test/logs/simd/run.custom.spec.ts.log.json +309 -0
- package/.as-test/logs/simd/run.date.spec.ts.log.json +397 -0
- package/.as-test/logs/simd/run.enum.spec.ts.log.json +343 -0
- package/.as-test/logs/simd/run.float.spec.ts.log.json +453 -0
- package/.as-test/logs/simd/run.generics.spec.ts.log.json +393 -0
- package/.as-test/logs/simd/run.hierarchy.spec.ts.log.json +325 -0
- package/.as-test/logs/simd/run.integer.spec.ts.log.json +373 -0
- package/.as-test/logs/simd/run.map.spec.ts.log.json +247 -0
- package/.as-test/logs/simd/run.namespace.spec.ts.log.json +361 -0
- package/.as-test/logs/simd/run.null.spec.ts.log.json +273 -0
- package/.as-test/logs/simd/run.raw.spec.ts.log.json +309 -0
- package/.as-test/logs/simd/run.resolving.spec.ts.log.json +273 -0
- package/.as-test/logs/simd/run.set.spec.ts.log.json +733 -0
- package/.as-test/logs/simd/run.staticarray.spec.ts.log.json +931 -0
- package/.as-test/logs/simd/run.string.spec.ts.log.json +2289 -0
- package/.as-test/logs/simd/run.struct.spec.ts.log.json +523 -0
- package/.as-test/logs/simd/run.types.spec.ts.log.json +273 -0
- package/.as-test/logs/simd/test.arbitrary.spec.ts.log.json +943 -0
- package/.as-test/logs/simd/test.array.spec.ts.log.json +1053 -0
- package/.as-test/logs/simd/test.bool.spec.ts.log.json +257 -0
- package/.as-test/logs/simd/test.box.spec.ts.log.json +353 -0
- package/.as-test/logs/simd/test.custom.spec.ts.log.json +309 -0
- package/.as-test/logs/simd/test.date.spec.ts.log.json +397 -0
- package/.as-test/logs/simd/test.enum.spec.ts.log.json +343 -0
- package/.as-test/logs/simd/test.float.spec.ts.log.json +453 -0
- package/.as-test/logs/simd/test.generics.spec.ts.log.json +393 -0
- package/.as-test/logs/simd/test.hierarchy.spec.ts.log.json +325 -0
- package/.as-test/logs/simd/test.integer.spec.ts.log.json +373 -0
- package/.as-test/logs/simd/test.log.json +11371 -0
- package/.as-test/logs/simd/test.map.spec.ts.log.json +247 -0
- package/.as-test/logs/simd/test.namespace.spec.ts.log.json +361 -0
- package/.as-test/logs/simd/test.null.spec.ts.log.json +273 -0
- package/.as-test/logs/simd/test.raw.spec.ts.log.json +309 -0
- package/.as-test/logs/simd/test.resolving.spec.ts.log.json +273 -0
- package/.as-test/logs/simd/test.set.spec.ts.log.json +733 -0
- package/.as-test/logs/simd/test.staticarray.spec.ts.log.json +931 -0
- package/.as-test/logs/simd/test.string.spec.ts.log.json +2345 -0
- package/.as-test/logs/simd/test.struct.spec.ts.log.json +523 -0
- package/.as-test/logs/simd/test.types.spec.ts.log.json +273 -0
- package/.as-test/logs/swar/run.arbitrary.spec.ts.log.json +943 -0
- package/.as-test/logs/swar/run.array.spec.ts.log.json +1053 -0
- package/.as-test/logs/swar/run.bool.spec.ts.log.json +257 -0
- package/.as-test/logs/swar/run.box.spec.ts.log.json +353 -0
- package/.as-test/logs/swar/run.custom.spec.ts.log.json +309 -0
- package/.as-test/logs/swar/run.date.spec.ts.log.json +397 -0
- package/.as-test/logs/swar/run.enum.spec.ts.log.json +343 -0
- package/.as-test/logs/swar/run.float.spec.ts.log.json +453 -0
- package/.as-test/logs/swar/run.generics.spec.ts.log.json +393 -0
- package/.as-test/logs/swar/run.hierarchy.spec.ts.log.json +325 -0
- package/.as-test/logs/swar/run.integer.spec.ts.log.json +373 -0
- package/.as-test/logs/swar/run.map.spec.ts.log.json +247 -0
- package/.as-test/logs/swar/run.namespace.spec.ts.log.json +361 -0
- package/.as-test/logs/swar/run.null.spec.ts.log.json +273 -0
- package/.as-test/logs/swar/run.raw.spec.ts.log.json +309 -0
- package/.as-test/logs/swar/run.resolving.spec.ts.log.json +273 -0
- package/.as-test/logs/swar/run.set.spec.ts.log.json +733 -0
- package/.as-test/logs/swar/run.staticarray.spec.ts.log.json +931 -0
- package/.as-test/logs/swar/run.string.spec.ts.log.json +2289 -0
- package/.as-test/logs/swar/run.struct.spec.ts.log.json +523 -0
- package/.as-test/logs/swar/run.types.spec.ts.log.json +273 -0
- package/.as-test/logs/swar/test.arbitrary.spec.ts.log.json +943 -0
- package/.as-test/logs/swar/test.array.spec.ts.log.json +1053 -0
- package/.as-test/logs/swar/test.bool.spec.ts.log.json +257 -0
- package/.as-test/logs/swar/test.box.spec.ts.log.json +353 -0
- package/.as-test/logs/swar/test.custom.spec.ts.log.json +309 -0
- package/.as-test/logs/swar/test.date.spec.ts.log.json +397 -0
- package/.as-test/logs/swar/test.enum.spec.ts.log.json +343 -0
- package/.as-test/logs/swar/test.float.spec.ts.log.json +453 -0
- package/.as-test/logs/swar/test.generics.spec.ts.log.json +393 -0
- package/.as-test/logs/swar/test.hierarchy.spec.ts.log.json +325 -0
- package/.as-test/logs/swar/test.integer.spec.ts.log.json +373 -0
- package/.as-test/logs/swar/test.log.json +11371 -0
- package/.as-test/logs/swar/test.map.spec.ts.log.json +247 -0
- package/.as-test/logs/swar/test.namespace.spec.ts.log.json +361 -0
- package/.as-test/logs/swar/test.null.spec.ts.log.json +273 -0
- package/.as-test/logs/swar/test.raw.spec.ts.log.json +309 -0
- package/.as-test/logs/swar/test.resolving.spec.ts.log.json +273 -0
- package/.as-test/logs/swar/test.set.spec.ts.log.json +733 -0
- package/.as-test/logs/swar/test.staticarray.spec.ts.log.json +931 -0
- package/.as-test/logs/swar/test.string.spec.ts.log.json +2345 -0
- package/.as-test/logs/swar/test.struct.spec.ts.log.json +523 -0
- package/.as-test/logs/swar/test.types.spec.ts.log.json +273 -0
- package/.as-test/logs/test.arbitrary.spec.ts.log.json +943 -0
- package/.as-test/logs/test.array.spec.ts.log.json +1053 -0
- package/.as-test/logs/test.bool.spec.ts.log.json +257 -0
- package/.as-test/logs/test.box.spec.ts.log.json +353 -0
- package/.as-test/logs/test.custom.spec.ts.log.json +309 -0
- package/.as-test/logs/test.date.spec.ts.log.json +397 -0
- package/.as-test/logs/test.enum.spec.ts.log.json +343 -0
- package/.as-test/logs/test.float.spec.ts.log.json +453 -0
- package/.as-test/logs/test.generics.spec.ts.log.json +393 -0
- package/.as-test/logs/test.hierarchy.spec.ts.log.json +325 -0
- package/.as-test/logs/test.integer.spec.ts.log.json +373 -0
- package/.as-test/logs/test.log.json +11371 -0
- package/.as-test/logs/test.map.spec.ts.log.json +247 -0
- package/.as-test/logs/test.namespace.spec.ts.log.json +361 -0
- package/.as-test/logs/test.null.spec.ts.log.json +273 -0
- package/.as-test/logs/test.raw.spec.ts.log.json +309 -0
- package/.as-test/logs/test.resolving.spec.ts.log.json +273 -0
- package/.as-test/logs/test.set.spec.ts.log.json +733 -0
- package/.as-test/logs/test.staticarray.spec.ts.log.json +931 -0
- package/.as-test/logs/test.string.spec.ts.log.json +2289 -0
- package/.as-test/logs/test.struct.spec.ts.log.json +523 -0
- package/.as-test/logs/test.types.spec.ts.log.json +273 -0
- package/.as-test/runners/default.bindings.js +68 -0
- package/.as-test/runners/default.wasi.js +38 -0
- package/ARCHITECTURE.md +6 -3
- package/CONTRIBUTING.md +9 -3
- package/README.md +39 -22
- package/as-test.config.json +40 -0
- package/assembly/custom/util.ts +24 -70
- package/assembly/deserialize/float.ts +181 -0
- package/assembly/deserialize/helpers/uint.ts +12 -0
- package/assembly/deserialize/index/arbitrary.ts +25 -0
- package/assembly/deserialize/index/array.ts +61 -0
- package/assembly/deserialize/index/bool.ts +1 -0
- package/assembly/deserialize/index/date.ts +1 -0
- package/assembly/deserialize/index/float.ts +1 -0
- package/assembly/deserialize/index/integer.ts +1 -0
- package/assembly/deserialize/index/map.ts +1 -0
- package/assembly/deserialize/index/object.ts +1 -0
- package/assembly/deserialize/index/raw.ts +1 -0
- package/assembly/deserialize/index/set.ts +1 -0
- package/assembly/deserialize/index/staticarray.ts +1 -0
- package/assembly/deserialize/index/string.ts +15 -0
- package/assembly/deserialize/index/struct.ts +1 -0
- package/assembly/deserialize/index/typedarray.ts +1 -0
- package/assembly/deserialize/index/unsigned.ts +1 -0
- package/assembly/deserialize/index.ts +14 -0
- package/assembly/deserialize/integer.ts +42 -0
- package/assembly/deserialize/simd/array/integer.ts +307 -0
- package/assembly/deserialize/simd/string.ts +129 -10
- package/assembly/deserialize/simple/arbitrary.ts +5 -12
- package/assembly/deserialize/simple/array/arbitrary.ts +12 -36
- package/assembly/deserialize/simple/array/array.ts +2 -8
- package/assembly/deserialize/simple/array/bool.ts +2 -8
- package/assembly/deserialize/simple/array/box.ts +2 -8
- package/assembly/deserialize/simple/array/float.ts +2 -8
- package/assembly/deserialize/simple/array/integer.ts +2 -8
- package/assembly/deserialize/simple/array/map.ts +6 -26
- package/assembly/deserialize/simple/array/object.ts +6 -26
- package/assembly/deserialize/simple/array/raw.ts +18 -61
- package/assembly/deserialize/simple/array/string.ts +5 -10
- package/assembly/deserialize/simple/array/struct.ts +6 -26
- package/assembly/deserialize/simple/array.ts +2 -5
- package/assembly/deserialize/simple/bool.ts +2 -6
- package/assembly/deserialize/simple/map.ts +29 -102
- package/assembly/deserialize/simple/object.ts +24 -81
- package/assembly/deserialize/simple/raw.ts +1 -4
- package/assembly/deserialize/simple/set.ts +11 -37
- package/assembly/deserialize/simple/staticarray/array.ts +1 -1
- package/assembly/deserialize/simple/staticarray/bool.ts +1 -1
- package/assembly/deserialize/simple/staticarray/float.ts +1 -1
- package/assembly/deserialize/simple/staticarray/integer.ts +1 -1
- package/assembly/deserialize/simple/staticarray/string.ts +7 -14
- package/assembly/deserialize/simple/staticarray/struct.ts +1 -1
- package/assembly/deserialize/simple/staticarray.ts +57 -21
- package/assembly/deserialize/simple/string.ts +2 -8
- package/assembly/deserialize/simple/struct.ts +25 -121
- package/assembly/deserialize/simple/typedarray.ts +94 -0
- package/assembly/deserialize/swar/array/arbitrary.ts +8 -0
- package/assembly/deserialize/swar/array/array.ts +39 -0
- package/assembly/deserialize/swar/array/bool.ts +47 -0
- package/assembly/deserialize/swar/array/box.ts +8 -0
- package/assembly/deserialize/swar/array/float.ts +39 -0
- package/assembly/deserialize/swar/array/integer.ts +461 -0
- package/assembly/deserialize/swar/array/map.ts +7 -0
- package/assembly/deserialize/swar/array/object.ts +44 -0
- package/assembly/deserialize/swar/array/raw.ts +8 -0
- package/assembly/deserialize/swar/array/shared.ts +96 -0
- package/assembly/deserialize/swar/array/string.ts +39 -0
- package/assembly/deserialize/swar/array/struct.ts +44 -0
- package/assembly/deserialize/swar/array.ts +49 -0
- package/assembly/deserialize/swar/string.ts +650 -14
- package/assembly/deserialize/unsigned.ts +75 -0
- package/assembly/index.d.ts +1 -3
- package/assembly/index.ts +251 -265
- package/assembly/serialize/index/arbitrary.ts +70 -0
- package/assembly/serialize/index/array.ts +1 -0
- package/assembly/serialize/index/bool.ts +1 -0
- package/assembly/serialize/index/date.ts +1 -0
- package/assembly/serialize/index/float.ts +1 -0
- package/assembly/serialize/index/integer.ts +1 -0
- package/assembly/serialize/index/map.ts +1 -0
- package/assembly/serialize/index/object.ts +46 -0
- package/assembly/serialize/index/raw.ts +1 -0
- package/assembly/serialize/index/set.ts +1 -0
- package/assembly/serialize/index/staticarray.ts +1 -0
- package/assembly/serialize/index/string.ts +15 -0
- package/assembly/serialize/index/struct.ts +1 -0
- package/assembly/serialize/index/typedarray.ts +1 -0
- package/assembly/serialize/index.ts +13 -0
- package/assembly/serialize/simd/string.ts +1 -2
- package/assembly/serialize/simple/raw.ts +1 -5
- package/assembly/serialize/simple/typedarray.ts +63 -0
- package/assembly/serialize/swar/string.ts +3 -10
- package/assembly/test.ts +21 -27
- package/assembly/util/concat.ts +1 -5
- package/assembly/util/index.ts +1 -0
- package/assembly/util/masks.ts +12 -18
- package/assembly/util/memory.ts +0 -0
- package/assembly/util/snp.ts +1 -4
- package/assembly/util/stringScan.ts +24 -0
- package/assembly/util/swar.ts +1 -6
- package/eslint.config.js +21 -13
- package/lib/as-bs.ts +69 -78
- package/package.json +8 -5
- package/test.ts +99 -0
- package/tools/assemblyscript-eslint-local.js +1 -24
- package/tools/assemblyscript-eslint.js +38 -14
- package/tools/assemblyscript-prettier-plugin.js +33 -0
- package/tools/replacer.js +63 -0
- package/transform/lib/builder.d.ts.map +1 -1
- package/transform/lib/builder.js +5 -13
- package/transform/lib/builder.js.map +1 -1
- package/transform/lib/index.d.ts.map +1 -1
- package/transform/lib/index.js +529 -735
- package/transform/lib/index.js.map +1 -1
- package/transform/lib/linkers/alias.d.ts.map +1 -1
- package/transform/lib/linkers/alias.js.map +1 -1
- package/transform/lib/linkers/custom.d.ts.map +1 -1
- package/transform/lib/linkers/custom.js +4 -9
- package/transform/lib/linkers/custom.js.map +1 -1
- package/transform/lib/linkers/imports.d.ts.map +1 -1
- package/transform/lib/linkers/imports.js.map +1 -1
- package/transform/lib/types.d.ts +4 -0
- package/transform/lib/types.d.ts.map +1 -1
- package/transform/lib/types.js +70 -21
- package/transform/lib/types.js.map +1 -1
- package/transform/lib/util.d.ts.map +1 -1
- package/transform/lib/util.js +1 -1
- package/transform/lib/util.js.map +1 -1
- package/transform/lib/visitor.d.ts.map +1 -1
- package/transform/lib/visitor.js +1 -2
- package/transform/lib/visitor.js.map +1 -1
- package/.prettierrc +0 -3
- package/assembly/deserialize/simple/float.ts +0 -11
- package/assembly/deserialize/simple/integer.ts +0 -9
package/assembly/index.ts
CHANGED
|
@@ -1,46 +1,40 @@
|
|
|
1
1
|
/// <reference path="./index.d.ts" />
|
|
2
2
|
|
|
3
3
|
import { bs } from "../lib/as-bs";
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
11
|
-
import {
|
|
12
|
-
import {
|
|
13
|
-
import {
|
|
14
|
-
import {
|
|
15
|
-
import {
|
|
16
|
-
import {
|
|
17
|
-
import {
|
|
18
|
-
|
|
19
|
-
import {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
NULL_WORD_U64,
|
|
23
|
-
TRUE_WORD_U64,
|
|
24
|
-
FALSE_WORD_U64,
|
|
25
|
-
} from "./custom/chars";
|
|
4
|
+
import { OBJECT, TOTAL_OVERHEAD } from "rt/common";
|
|
5
|
+
import { serializeArray } from "./serialize/index/array";
|
|
6
|
+
import { serializeMap } from "./serialize/index/map";
|
|
7
|
+
import { serializeDate } from "./serialize/index/date";
|
|
8
|
+
import { deserializeBoolean } from "./deserialize/index/bool";
|
|
9
|
+
import { deserializeArray } from "./deserialize/index/array";
|
|
10
|
+
import { deserializeFloat } from "./deserialize/index/float";
|
|
11
|
+
import { deserializeMap } from "./deserialize/index/map";
|
|
12
|
+
import { deserializeDate } from "./deserialize/index/date";
|
|
13
|
+
import { deserializeInteger } from "./deserialize/index/integer";
|
|
14
|
+
import { deserializeUnsigned } from "./deserialize/index/unsigned";
|
|
15
|
+
import { serializeArbitrary } from "./serialize/index/arbitrary";
|
|
16
|
+
import { serializeSet } from "./serialize/index/set";
|
|
17
|
+
import { deserializeSet } from "./deserialize/index/set";
|
|
18
|
+
import { serializeStaticArray } from "./serialize/index/staticarray";
|
|
19
|
+
import { deserializeStaticArray } from "./deserialize/index/staticarray";
|
|
20
|
+
|
|
21
|
+
import { NULL_WORD, QUOTE, NULL_WORD_U64, TRUE_WORD_U64, FALSE_WORD_U64 } from "./custom/chars";
|
|
26
22
|
import { dtoa_buffered, itoa_buffered } from "util/number";
|
|
27
|
-
import { serializeBool } from "./serialize/
|
|
28
|
-
import { serializeInteger } from "./serialize/
|
|
29
|
-
import { serializeFloat } from "./serialize/
|
|
30
|
-
import { serializeStruct } from "./serialize/
|
|
23
|
+
import { serializeBool } from "./serialize/index/bool";
|
|
24
|
+
import { serializeInteger } from "./serialize/index/integer";
|
|
25
|
+
import { serializeFloat } from "./serialize/index/float";
|
|
26
|
+
import { serializeStruct } from "./serialize/index/struct";
|
|
31
27
|
import { ptrToStr } from "./util/ptrToStr";
|
|
32
28
|
import { atoi, bytes } from "./util";
|
|
33
|
-
import { deserializeArbitrary } from "./deserialize/
|
|
34
|
-
import { serializeObject } from "./serialize/
|
|
35
|
-
import { deserializeObject } from "./deserialize/
|
|
36
|
-
import { serializeRaw } from "./serialize/
|
|
37
|
-
import { deserializeRaw } from "./deserialize/
|
|
38
|
-
import {
|
|
39
|
-
import {
|
|
40
|
-
import {
|
|
41
|
-
import {
|
|
42
|
-
import { serializeString } from "./serialize/simple/string";
|
|
43
|
-
import { deserializeString_SIMD } from "./deserialize/simd/string";
|
|
29
|
+
import { deserializeArbitrary } from "./deserialize/index/arbitrary";
|
|
30
|
+
import { serializeObject } from "./serialize/index/object";
|
|
31
|
+
import { deserializeObject } from "./deserialize/index/object";
|
|
32
|
+
import { serializeRaw } from "./serialize/index/raw";
|
|
33
|
+
import { deserializeRaw } from "./deserialize/index/raw";
|
|
34
|
+
import { deserializeString } from "./deserialize/index/string";
|
|
35
|
+
import { serializeString } from "./serialize/index/string";
|
|
36
|
+
import { deserializeArrayBuffer, deserializeTypedArray } from "./deserialize/index/typedarray";
|
|
37
|
+
import { serializeArrayBufferUnsafe, serializeTypedArray } from "./serialize/index/typedarray";
|
|
44
38
|
|
|
45
39
|
/**
|
|
46
40
|
* Offset of the 'storage' property in the JSON.Value class.
|
|
@@ -77,10 +71,7 @@ export namespace JSON {
|
|
|
77
71
|
* @returns string
|
|
78
72
|
*/
|
|
79
73
|
// @ts-expect-error: inline
|
|
80
|
-
@inline export function stringify<T>(
|
|
81
|
-
data: T,
|
|
82
|
-
out: string | null = null,
|
|
83
|
-
): string {
|
|
74
|
+
@inline export function stringify<T>(data: T, out: string | null = null): string {
|
|
84
75
|
if (isBoolean<T>()) {
|
|
85
76
|
if (out) {
|
|
86
77
|
if (<bool>data == true) {
|
|
@@ -94,12 +85,7 @@ export namespace JSON {
|
|
|
94
85
|
return out;
|
|
95
86
|
}
|
|
96
87
|
return data ? "true" : "false";
|
|
97
|
-
} else if (
|
|
98
|
-
isInteger<T>() &&
|
|
99
|
-
!isSigned<T>() &&
|
|
100
|
-
nameof<T>() == "usize" &&
|
|
101
|
-
data == 0
|
|
102
|
-
) {
|
|
88
|
+
} else if (isInteger<T>() && !isSigned<T>() && nameof<T>() == "usize" && data == 0) {
|
|
103
89
|
if (out) {
|
|
104
90
|
out = changetype<string>(__renew(changetype<usize>(out), 8));
|
|
105
91
|
store<u64>(changetype<usize>(out), NULL_WORD_U64);
|
|
@@ -108,14 +94,10 @@ export namespace JSON {
|
|
|
108
94
|
return NULL_WORD;
|
|
109
95
|
} else if (isInteger<T>(data)) {
|
|
110
96
|
if (out) {
|
|
111
|
-
out = changetype<string>(
|
|
112
|
-
__renew(changetype<usize>(out), sizeof<T>() << 3),
|
|
113
|
-
);
|
|
97
|
+
out = changetype<string>(__renew(changetype<usize>(out), sizeof<T>() << 3));
|
|
114
98
|
|
|
115
99
|
const bytes = itoa_buffered(changetype<usize>(out), data) << 1;
|
|
116
|
-
return (out = changetype<string>(
|
|
117
|
-
__renew(changetype<usize>(out), bytes),
|
|
118
|
-
));
|
|
100
|
+
return (out = changetype<string>(__renew(changetype<usize>(out), bytes)));
|
|
119
101
|
}
|
|
120
102
|
return data.toString();
|
|
121
103
|
} else if (isFloat<T>(data)) {
|
|
@@ -123,9 +105,7 @@ export namespace JSON {
|
|
|
123
105
|
out = changetype<string>(__renew(changetype<usize>(out), 64));
|
|
124
106
|
|
|
125
107
|
const bytes = dtoa_buffered(changetype<usize>(out), data) << 1;
|
|
126
|
-
return (out = changetype<string>(
|
|
127
|
-
__renew(changetype<usize>(out), bytes),
|
|
128
|
-
));
|
|
108
|
+
return (out = changetype<string>(__renew(changetype<usize>(out), bytes)));
|
|
129
109
|
}
|
|
130
110
|
return data.toString();
|
|
131
111
|
} else if (isNullable<T>() && changetype<usize>(data) == <usize>0) {
|
|
@@ -136,13 +116,7 @@ export namespace JSON {
|
|
|
136
116
|
}
|
|
137
117
|
return NULL_WORD;
|
|
138
118
|
} else if (isString<nonnull<T>>()) {
|
|
139
|
-
|
|
140
|
-
serializeString_SIMD(data as string);
|
|
141
|
-
} else if (JSON_MODE === JSONMode.SWAR) {
|
|
142
|
-
serializeString_SWAR(data as string);
|
|
143
|
-
} else {
|
|
144
|
-
serializeString(data as string);
|
|
145
|
-
}
|
|
119
|
+
serializeString(data as string);
|
|
146
120
|
return bs.out<string>();
|
|
147
121
|
// @ts-expect-error: Supplied by transform
|
|
148
122
|
} else if (isDefined(data.__SERIALIZE)) {
|
|
@@ -150,16 +124,10 @@ export namespace JSON {
|
|
|
150
124
|
inline.always(data.__SERIALIZE(changetype<usize>(data)));
|
|
151
125
|
return bs.out<string>();
|
|
152
126
|
} else if (data instanceof Date) {
|
|
153
|
-
out = out
|
|
154
|
-
? changetype<string>(__renew(changetype<usize>(out), 52))
|
|
155
|
-
: changetype<string>(__new(52, idof<string>()));
|
|
127
|
+
out = out ? changetype<string>(__renew(changetype<usize>(out), 52)) : changetype<string>(__new(52, idof<string>()));
|
|
156
128
|
|
|
157
129
|
store<u16>(changetype<usize>(out), QUOTE);
|
|
158
|
-
memory.copy(
|
|
159
|
-
changetype<usize>(out) + 2,
|
|
160
|
-
changetype<usize>(data.toISOString()),
|
|
161
|
-
48,
|
|
162
|
-
);
|
|
130
|
+
memory.copy(changetype<usize>(out) + 2, changetype<usize>(data.toISOString()), 48);
|
|
163
131
|
store<u16>(changetype<usize>(out), QUOTE, 50);
|
|
164
132
|
return changetype<string>(out);
|
|
165
133
|
} else if (data instanceof Array) {
|
|
@@ -170,6 +138,39 @@ export namespace JSON {
|
|
|
170
138
|
// @ts-expect-error
|
|
171
139
|
inline.always(serializeStaticArray(changetype<nonnull<T>>(data)));
|
|
172
140
|
return bs.out<string>();
|
|
141
|
+
} else if (data instanceof Int8Array) {
|
|
142
|
+
inline.always(serializeTypedArray<Int8Array>(data));
|
|
143
|
+
return bs.out<string>();
|
|
144
|
+
} else if (data instanceof Uint8Array) {
|
|
145
|
+
inline.always(serializeTypedArray<Uint8Array>(data));
|
|
146
|
+
return bs.out<string>();
|
|
147
|
+
} else if (data instanceof Uint8ClampedArray) {
|
|
148
|
+
inline.always(serializeTypedArray<Uint8ClampedArray>(data));
|
|
149
|
+
return bs.out<string>();
|
|
150
|
+
} else if (data instanceof Int16Array) {
|
|
151
|
+
inline.always(serializeTypedArray<Int16Array>(data));
|
|
152
|
+
return bs.out<string>();
|
|
153
|
+
} else if (data instanceof Uint16Array) {
|
|
154
|
+
inline.always(serializeTypedArray<Uint16Array>(data));
|
|
155
|
+
return bs.out<string>();
|
|
156
|
+
} else if (data instanceof Int32Array) {
|
|
157
|
+
inline.always(serializeTypedArray<Int32Array>(data));
|
|
158
|
+
return bs.out<string>();
|
|
159
|
+
} else if (data instanceof Uint32Array) {
|
|
160
|
+
inline.always(serializeTypedArray<Uint32Array>(data));
|
|
161
|
+
return bs.out<string>();
|
|
162
|
+
} else if (data instanceof Int64Array) {
|
|
163
|
+
inline.always(serializeTypedArray<Int64Array>(data));
|
|
164
|
+
return bs.out<string>();
|
|
165
|
+
} else if (data instanceof Uint64Array) {
|
|
166
|
+
inline.always(serializeTypedArray<Uint64Array>(data));
|
|
167
|
+
return bs.out<string>();
|
|
168
|
+
} else if (data instanceof Float32Array) {
|
|
169
|
+
inline.always(serializeTypedArray<Float32Array>(data));
|
|
170
|
+
return bs.out<string>();
|
|
171
|
+
} else if (data instanceof Float64Array) {
|
|
172
|
+
inline.always(serializeTypedArray<Float64Array>(data));
|
|
173
|
+
return bs.out<string>();
|
|
173
174
|
} else if (data instanceof Set) {
|
|
174
175
|
// @ts-expect-error
|
|
175
176
|
inline.always(serializeSet(changetype<nonnull<T>>(data)));
|
|
@@ -190,14 +191,16 @@ export namespace JSON {
|
|
|
190
191
|
} else if (data instanceof JSON.Box) {
|
|
191
192
|
return JSON.stringify(data.value);
|
|
192
193
|
} else {
|
|
193
|
-
throw new Error(
|
|
194
|
-
`Could not serialize data of type '${nameof<T>()}'. ` +
|
|
195
|
-
`If this is a custom class, add the @json decorator: @json class ${nameof<T>()} { ... }. ` +
|
|
196
|
-
`Supported types: primitives, string, Array, Map, Date, and @json decorated classes.`,
|
|
197
|
-
);
|
|
194
|
+
throw new Error(`Could not serialize data of type '${nameof<T>()}'. ` + `If this is a custom class, add the @json decorator: @json class ${nameof<T>()} { ... }. ` + `Supported types: primitives, string, Array, StaticArray, TypedArray, Map, Date, and @json decorated classes. ` + `For ArrayBuffer, use JSON.stringifyArrayBuffer(changetype<usize>(...)).`);
|
|
198
195
|
}
|
|
199
196
|
}
|
|
200
197
|
|
|
198
|
+
|
|
199
|
+
@inline export function stringifyArrayBuffer(dataStart: usize): string {
|
|
200
|
+
serializeArrayBufferUnsafe(dataStart, changetype<OBJECT>(dataStart - TOTAL_OVERHEAD).rtSize);
|
|
201
|
+
return bs.out<string>();
|
|
202
|
+
}
|
|
203
|
+
|
|
201
204
|
/**
|
|
202
205
|
* Parses valid JSON strings into their original format
|
|
203
206
|
* ```js
|
|
@@ -213,61 +216,59 @@ export namespace JSON {
|
|
|
213
216
|
if (isBoolean<T>()) {
|
|
214
217
|
return deserializeBoolean(dataPtr, dataPtr + dataSize) as T;
|
|
215
218
|
} else if (isInteger<T>()) {
|
|
216
|
-
return deserializeInteger<T>(dataPtr, dataPtr + dataSize);
|
|
219
|
+
return isSigned<T>() ? deserializeInteger<T>(dataPtr, dataPtr + dataSize) : deserializeUnsigned<T>(dataPtr, dataPtr + dataSize);
|
|
217
220
|
} else if (isFloat<T>()) {
|
|
218
221
|
return deserializeFloat<T>(dataPtr, dataPtr + dataSize);
|
|
219
|
-
} else if (
|
|
220
|
-
isNullable<T>() &&
|
|
221
|
-
dataSize == 8 &&
|
|
222
|
-
load<u64>(dataPtr) == NULL_WORD_U64
|
|
223
|
-
) {
|
|
222
|
+
} else if (isNullable<T>() && dataSize == 8 && load<u64>(dataPtr) == NULL_WORD_U64) {
|
|
224
223
|
return null;
|
|
225
224
|
} else if (isString<T>()) {
|
|
226
|
-
|
|
227
|
-
// @ts-expect-error: type
|
|
228
|
-
return deserializeString(dataPtr, dataPtr + dataSize);
|
|
229
|
-
} else if (JSON_MODE === JSONMode.SWAR) {
|
|
230
|
-
// @ts-expect-error: type
|
|
231
|
-
return deserializeString_SWAR(dataPtr, dataPtr + dataSize);
|
|
232
|
-
} else if (JSON_MODE === JSONMode.SIMD) {
|
|
233
|
-
// @ts-expect-error: type
|
|
234
|
-
return deserializeString_SIMD(dataPtr, dataPtr + dataSize);
|
|
235
|
-
}
|
|
225
|
+
return deserializeString(dataPtr, dataPtr + dataSize) as T;
|
|
236
226
|
} else {
|
|
237
227
|
let type: nonnull<T> = changetype<nonnull<T>>(0);
|
|
238
228
|
if (type instanceof StaticArray) {
|
|
239
229
|
// @ts-expect-error
|
|
240
|
-
return inline.always(
|
|
241
|
-
deserializeStaticArray<nonnull<T>>(dataPtr, dataPtr + dataSize, 0),
|
|
242
|
-
);
|
|
230
|
+
return inline.always(deserializeStaticArray<nonnull<T>>(dataPtr, dataPtr + dataSize, 0));
|
|
243
231
|
} else if (type instanceof Array) {
|
|
244
232
|
// @ts-expect-error
|
|
245
|
-
return inline.always(
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
);
|
|
233
|
+
return inline.always(deserializeArray<nonnull<T>>(dataPtr, dataPtr + dataSize, changetype<usize>(instantiate<T>())));
|
|
234
|
+
} else if (type instanceof Int8Array) {
|
|
235
|
+
return deserializeTypedArray<Int8Array>(dataPtr, dataPtr + dataSize, 0) as T;
|
|
236
|
+
} else if (type instanceof Uint8Array) {
|
|
237
|
+
return deserializeTypedArray<Uint8Array>(dataPtr, dataPtr + dataSize, 0) as T;
|
|
238
|
+
} else if (type instanceof Uint8ClampedArray) {
|
|
239
|
+
return deserializeTypedArray<Uint8ClampedArray>(dataPtr, dataPtr + dataSize, 0) as T;
|
|
240
|
+
} else if (type instanceof Int16Array) {
|
|
241
|
+
return deserializeTypedArray<Int16Array>(dataPtr, dataPtr + dataSize, 0) as T;
|
|
242
|
+
} else if (type instanceof Uint16Array) {
|
|
243
|
+
return deserializeTypedArray<Uint16Array>(dataPtr, dataPtr + dataSize, 0) as T;
|
|
244
|
+
} else if (type instanceof Int32Array) {
|
|
245
|
+
return deserializeTypedArray<Int32Array>(dataPtr, dataPtr + dataSize, 0) as T;
|
|
246
|
+
} else if (type instanceof Uint32Array) {
|
|
247
|
+
return deserializeTypedArray<Uint32Array>(dataPtr, dataPtr + dataSize, 0) as T;
|
|
248
|
+
} else if (type instanceof Int64Array) {
|
|
249
|
+
return deserializeTypedArray<Int64Array>(dataPtr, dataPtr + dataSize, 0) as T;
|
|
250
|
+
} else if (type instanceof Uint64Array) {
|
|
251
|
+
return deserializeTypedArray<Uint64Array>(dataPtr, dataPtr + dataSize, 0) as T;
|
|
252
|
+
} else if (type instanceof Float32Array) {
|
|
253
|
+
return deserializeTypedArray<Float32Array>(dataPtr, dataPtr + dataSize, 0) as T;
|
|
254
|
+
} else if (type instanceof Float64Array) {
|
|
255
|
+
return deserializeTypedArray<Float64Array>(dataPtr, dataPtr + dataSize, 0) as T;
|
|
256
|
+
} else if (type instanceof ArrayBuffer) {
|
|
257
|
+
return deserializeArrayBuffer(dataPtr, dataPtr + dataSize, 0) as T;
|
|
252
258
|
} else if (type instanceof Set) {
|
|
253
259
|
// @ts-expect-error
|
|
254
|
-
return inline.always(
|
|
255
|
-
deserializeSet<nonnull<T>>(dataPtr, dataPtr + dataSize, 0),
|
|
256
|
-
);
|
|
260
|
+
return inline.always(deserializeSet<nonnull<T>>(dataPtr, dataPtr + dataSize, 0));
|
|
257
261
|
// @ts-expect-error: Defined by transform
|
|
258
262
|
} else if (isDefined(type.__DESERIALIZE)) {
|
|
259
|
-
const out = changetype<nonnull<T>>(
|
|
260
|
-
__new(offsetof<nonnull<T>>(), idof<nonnull<T>>()),
|
|
261
|
-
);
|
|
263
|
+
const out = changetype<nonnull<T>>(__new(offsetof<nonnull<T>>(), idof<nonnull<T>>()));
|
|
262
264
|
// @ts-expect-error: Defined by transform
|
|
263
265
|
if (isDefined(type.__INITIALIZE)) out.__INITIALIZE();
|
|
264
266
|
// @ts-expect-error
|
|
265
|
-
|
|
267
|
+
out.__DESERIALIZE(dataPtr, dataPtr + dataSize, out);
|
|
268
|
+
return out;
|
|
266
269
|
} else if (type instanceof Map) {
|
|
267
270
|
// @ts-expect-error
|
|
268
|
-
return inline.always(
|
|
269
|
-
deserializeMap<nonnull<T>>(dataPtr, dataPtr + dataSize, 0),
|
|
270
|
-
);
|
|
271
|
+
return inline.always(deserializeMap<nonnull<T>>(dataPtr, dataPtr + dataSize, 0));
|
|
271
272
|
} else if (type instanceof Date) {
|
|
272
273
|
// @ts-expect-error
|
|
273
274
|
return deserializeDate(dataPtr, dataPtr + dataSize);
|
|
@@ -276,9 +277,7 @@ export namespace JSON {
|
|
|
276
277
|
return deserializeRaw(dataPtr, dataPtr + dataSize);
|
|
277
278
|
} else if (type instanceof JSON.Value) {
|
|
278
279
|
// @ts-expect-error
|
|
279
|
-
return inline.always(
|
|
280
|
-
deserializeArbitrary(dataPtr, dataPtr + dataSize, 0),
|
|
281
|
-
);
|
|
280
|
+
return inline.always(deserializeArbitrary(dataPtr, dataPtr + dataSize, 0));
|
|
282
281
|
} else if (type instanceof JSON.Obj) {
|
|
283
282
|
// @ts-expect-error
|
|
284
283
|
return inline.always(deserializeObject(dataPtr, dataPtr + dataSize, 0));
|
|
@@ -286,11 +285,7 @@ export namespace JSON {
|
|
|
286
285
|
// @ts-expect-error
|
|
287
286
|
return new JSON.Box(parseBox(data, changetype<nonnull<T>>(0).value));
|
|
288
287
|
} else {
|
|
289
|
-
throw new Error(
|
|
290
|
-
`Could not deserialize JSON to type '${nameof<T>()}'. ` +
|
|
291
|
-
`If this is a custom class, ensure it has the @json decorator: @json class ${nameof<T>()} { ... }. ` +
|
|
292
|
-
`Input: "${data.length > 50 ? data.slice(0, 50) + "..." : data}"`,
|
|
293
|
-
);
|
|
288
|
+
throw new Error(`Could not deserialize JSON to type '${nameof<T>()}'. ` + `If this is a custom class, ensure it has the @json decorator: @json class ${nameof<T>()} { ... }. ` + `Input: "${data.length > 50 ? data.slice(0, 50) + "..." : data}"`);
|
|
294
289
|
}
|
|
295
290
|
}
|
|
296
291
|
}
|
|
@@ -437,9 +432,7 @@ export namespace JSON {
|
|
|
437
432
|
* @returns An instance of JSON.Value.
|
|
438
433
|
*/
|
|
439
434
|
@inline static empty(): JSON.Value {
|
|
440
|
-
return changetype<JSON.Value>(
|
|
441
|
-
__new(offsetof<JSON.Value>(), idof<JSON.Value>()),
|
|
442
|
-
);
|
|
435
|
+
return changetype<JSON.Value>(__new(offsetof<JSON.Value>(), idof<JSON.Value>()));
|
|
443
436
|
}
|
|
444
437
|
|
|
445
438
|
/**
|
|
@@ -449,9 +442,7 @@ export namespace JSON {
|
|
|
449
442
|
*/
|
|
450
443
|
@inline static from<T>(value: T): JSON.Value {
|
|
451
444
|
if (value instanceof JSON.Value) return value;
|
|
452
|
-
const out = changetype<JSON.Value>(
|
|
453
|
-
__new(offsetof<JSON.Value>(), idof<JSON.Value>()),
|
|
454
|
-
);
|
|
445
|
+
const out = changetype<JSON.Value>(__new(offsetof<JSON.Value>(), idof<JSON.Value>()));
|
|
455
446
|
out.set<T>(value);
|
|
456
447
|
return out;
|
|
457
448
|
}
|
|
@@ -462,29 +453,21 @@ export namespace JSON {
|
|
|
462
453
|
* @returns JSON.Types
|
|
463
454
|
*/
|
|
464
455
|
@inline getType<T>(value: T): JSON.Types {
|
|
465
|
-
if (isNullable<T>() && changetype<usize>(value) === 0)
|
|
466
|
-
return JSON.Types.Null;
|
|
456
|
+
if (isNullable<T>() && changetype<usize>(value) === 0) return JSON.Types.Null;
|
|
467
457
|
if (isBoolean<T>()) return JSON.Types.Bool;
|
|
468
|
-
if (
|
|
469
|
-
isInteger<T>() &&
|
|
470
|
-
!isSigned<T>() &&
|
|
471
|
-
changetype<usize>(value) == 0 &&
|
|
472
|
-
nameof<T>() == "usize"
|
|
473
|
-
)
|
|
474
|
-
return JSON.Types.Null;
|
|
458
|
+
if (isInteger<T>() && !isSigned<T>() && changetype<usize>(value) == 0 && nameof<T>() == "usize") return JSON.Types.Null;
|
|
475
459
|
if (isString<T>()) return JSON.Types.String;
|
|
476
460
|
// @ts-expect-error: can assume that T is ArrayLike based on previous condition
|
|
477
|
-
if (isArray<T>() && idof<valueof<T>>() == idof<JSON.Value>())
|
|
478
|
-
return JSON.Types.Array;
|
|
461
|
+
if (isArray<T>() && idof<valueof<T>>() == idof<JSON.Value>()) return JSON.Types.Array;
|
|
479
462
|
if (value instanceof JSON.Box) return this.getType(value.value);
|
|
480
|
-
if (value instanceof u8 || value instanceof i8) return JSON.Types.U8;
|
|
481
|
-
if (value instanceof u16 || value instanceof i16) return JSON.Types.U16;
|
|
482
|
-
if (value instanceof u32 || value instanceof i32) return JSON.Types.U32;
|
|
483
|
-
if (value instanceof u64 || value instanceof i64) return JSON.Types.U64;
|
|
484
463
|
if (value instanceof i8) return JSON.Types.I8;
|
|
485
464
|
if (value instanceof i16) return JSON.Types.I16;
|
|
486
465
|
if (value instanceof i32) return JSON.Types.I32;
|
|
487
466
|
if (value instanceof i64) return JSON.Types.I64;
|
|
467
|
+
if (value instanceof u8) return JSON.Types.U8;
|
|
468
|
+
if (value instanceof u16) return JSON.Types.U16;
|
|
469
|
+
if (value instanceof u32) return JSON.Types.U32;
|
|
470
|
+
if (value instanceof u64) return JSON.Types.U64;
|
|
488
471
|
if (value instanceof f32) return JSON.Types.F32;
|
|
489
472
|
if (value instanceof f64) return JSON.Types.F64;
|
|
490
473
|
if (value instanceof Map) return JSON.Types.Map;
|
|
@@ -492,8 +475,7 @@ export namespace JSON {
|
|
|
492
475
|
if (value instanceof JSON.Obj) return JSON.Types.Object;
|
|
493
476
|
|
|
494
477
|
// @ts-expect-error: supplied by transform
|
|
495
|
-
if (isDefined(value.__SERIALIZE) && isManaged<T>(value))
|
|
496
|
-
return u16(idof<T>()) + JSON.Types.Struct;
|
|
478
|
+
if (isDefined(value.__SERIALIZE) && isManaged<T>(value)) return u16(idof<T>()) + JSON.Types.Struct;
|
|
497
479
|
return JSON.Types.Null;
|
|
498
480
|
}
|
|
499
481
|
/**
|
|
@@ -504,22 +486,12 @@ export namespace JSON {
|
|
|
504
486
|
this.type = this.getType<T>(value);
|
|
505
487
|
|
|
506
488
|
if (value instanceof JSON.Box) this.set(value.value);
|
|
507
|
-
else if (isBoolean<T>())
|
|
508
|
-
|
|
509
|
-
else if (
|
|
510
|
-
|
|
511
|
-
!isSigned<T>() &&
|
|
512
|
-
changetype<usize>(value) == 0 &&
|
|
513
|
-
nameof<T>() == "usize"
|
|
514
|
-
)
|
|
515
|
-
store<usize>(changetype<usize>(this), 0, STORAGE);
|
|
516
|
-
else if (isInteger<T>() || isFloat<T>())
|
|
517
|
-
store<T>(changetype<usize>(this), value, STORAGE);
|
|
518
|
-
else if (isNullable<T>() && changetype<usize>(value) === 0)
|
|
519
|
-
store<usize>(changetype<usize>(this), 0, STORAGE);
|
|
489
|
+
else if (isBoolean<T>()) store<T>(changetype<usize>(this), value, STORAGE);
|
|
490
|
+
else if (isInteger<T>() && !isSigned<T>() && changetype<usize>(value) == 0 && nameof<T>() == "usize") store<usize>(changetype<usize>(this), 0, STORAGE);
|
|
491
|
+
else if (isInteger<T>() || isFloat<T>()) store<T>(changetype<usize>(this), value, STORAGE);
|
|
492
|
+
else if (isNullable<T>() && changetype<usize>(value) === 0) store<usize>(changetype<usize>(this), 0, STORAGE);
|
|
520
493
|
else if (isString<T>()) store<T>(changetype<usize>(this), value, STORAGE);
|
|
521
|
-
else if (value instanceof JSON.Raw)
|
|
522
|
-
store<T>(changetype<usize>(this), value, STORAGE);
|
|
494
|
+
else if (value instanceof JSON.Raw) store<T>(changetype<usize>(this), value, STORAGE);
|
|
523
495
|
else if (value instanceof Map) {
|
|
524
496
|
if (idof<T>() !== idof<Map<string, JSON.Value>>()) {
|
|
525
497
|
abort("Maps must be of type Map<string, JSON.Value>!");
|
|
@@ -528,13 +500,8 @@ export namespace JSON {
|
|
|
528
500
|
// @ts-expect-error: supplied by transform
|
|
529
501
|
} else if (isDefined(value.__SERIALIZE) && isManaged<T>(value)) {
|
|
530
502
|
// @ts-expect-error
|
|
531
|
-
if (!JSON.Value.METHODS.has(idof<T>()))
|
|
532
|
-
|
|
533
|
-
store<usize>(
|
|
534
|
-
changetype<usize>(this),
|
|
535
|
-
changetype<usize>(value),
|
|
536
|
-
STORAGE,
|
|
537
|
-
);
|
|
503
|
+
if (!JSON.Value.METHODS.has(idof<T>())) JSON.Value.METHODS.set(idof<T>(), value.__SERIALIZE.index);
|
|
504
|
+
store<usize>(changetype<usize>(this), changetype<usize>(value), STORAGE);
|
|
538
505
|
} else if (value instanceof JSON.Obj) {
|
|
539
506
|
store<T>(changetype<usize>(this), value, STORAGE);
|
|
540
507
|
// @ts-expect-error
|
|
@@ -586,6 +553,14 @@ export namespace JSON {
|
|
|
586
553
|
return this.get<u32>().toString();
|
|
587
554
|
case JSON.Types.U64:
|
|
588
555
|
return this.get<u64>().toString();
|
|
556
|
+
case JSON.Types.I8:
|
|
557
|
+
return this.get<i8>().toString();
|
|
558
|
+
case JSON.Types.I16:
|
|
559
|
+
return this.get<i16>().toString();
|
|
560
|
+
case JSON.Types.I32:
|
|
561
|
+
return this.get<i32>().toString();
|
|
562
|
+
case JSON.Types.I64:
|
|
563
|
+
return this.get<i64>().toString();
|
|
589
564
|
case JSON.Types.F32:
|
|
590
565
|
return this.get<f32>().toString();
|
|
591
566
|
case JSON.Types.F64:
|
|
@@ -732,11 +707,25 @@ export namespace JSON {
|
|
|
732
707
|
*/
|
|
733
708
|
@inline static from<T>(value: T): JSON.Obj {
|
|
734
709
|
if (value instanceof JSON.Obj) return value;
|
|
735
|
-
const out = new JSON.Obj();
|
|
736
|
-
|
|
737
710
|
if (value instanceof Map) {
|
|
711
|
+
const out = new JSON.Obj();
|
|
712
|
+
if (!isString<indexof<T>>()) {
|
|
713
|
+
throw new Error("JSON.Obj.from only supports maps with string keys");
|
|
714
|
+
}
|
|
715
|
+
|
|
716
|
+
const keys = value.keys();
|
|
717
|
+
const values = value.values();
|
|
718
|
+
for (let i = 0; i < keys.length; i++) {
|
|
719
|
+
out.set(unchecked(keys[i]), unchecked(values[i]));
|
|
720
|
+
}
|
|
721
|
+
return out;
|
|
738
722
|
}
|
|
739
|
-
|
|
723
|
+
|
|
724
|
+
const parsed = JSON.parse<JSON.Value>(JSON.stringify(value));
|
|
725
|
+
if (parsed.type != JSON.Types.Object) {
|
|
726
|
+
throw new Error("JSON.Obj.from expects a value that serializes to a JSON object");
|
|
727
|
+
}
|
|
728
|
+
return parsed.get<JSON.Obj>();
|
|
740
729
|
}
|
|
741
730
|
}
|
|
742
731
|
/**
|
|
@@ -744,8 +733,7 @@ export namespace JSON {
|
|
|
744
733
|
*/
|
|
745
734
|
export class Box<T> {
|
|
746
735
|
constructor(public value: T) {
|
|
747
|
-
if (!isInteger<T>() && !isFloat<T>())
|
|
748
|
-
ERROR("JSON.Box should only hold primitive types!");
|
|
736
|
+
if (!isInteger<T>() && !isFloat<T>() && !isBoolean<T>()) ERROR("JSON.Box should only hold primitive types!");
|
|
749
737
|
}
|
|
750
738
|
/**
|
|
751
739
|
* Set the internal value of Box to new value
|
|
@@ -768,11 +756,9 @@ export namespace JSON {
|
|
|
768
756
|
* @returns Box<T> | null
|
|
769
757
|
*/
|
|
770
758
|
@inline static fromValue<T>(value: JSON.Value): Box<T> | null {
|
|
771
|
-
if (!(value instanceof JSON.Value))
|
|
772
|
-
throw new Error("value must be of type JSON.Value");
|
|
759
|
+
if (!(value instanceof JSON.Value)) throw new Error("value must be of type JSON.Value");
|
|
773
760
|
if (value.type === JSON.Types.Null) return null;
|
|
774
|
-
const v =
|
|
775
|
-
value.type === JSON.Types.F64 ? value.get<f64>() : value.get<T>();
|
|
761
|
+
const v = value.type === JSON.Types.F64 ? value.get<f64>() : value.get<T>();
|
|
776
762
|
// @ts-expect-error
|
|
777
763
|
return new Box(isInteger<T>() || isFloat<T>() ? <T>v : v);
|
|
778
764
|
}
|
|
@@ -821,13 +807,7 @@ export namespace JSON {
|
|
|
821
807
|
store<u64>(bs.offset, NULL_WORD_U64);
|
|
822
808
|
bs.offset += 8;
|
|
823
809
|
} else if (isString<nonnull<T>>()) {
|
|
824
|
-
|
|
825
|
-
serializeString_SIMD(data as string);
|
|
826
|
-
} else if (JSON_MODE === JSONMode.SWAR) {
|
|
827
|
-
serializeString_SWAR(data as string);
|
|
828
|
-
} else {
|
|
829
|
-
serializeString(data as string);
|
|
830
|
-
}
|
|
810
|
+
serializeString(data as string);
|
|
831
811
|
// @ts-expect-error: Supplied by transform
|
|
832
812
|
} else if (isDefined(data.__SERIALIZE_CUSTOM)) {
|
|
833
813
|
// @ts-expect-error
|
|
@@ -845,6 +825,28 @@ export namespace JSON {
|
|
|
845
825
|
} else if (data instanceof StaticArray) {
|
|
846
826
|
// @ts-expect-error
|
|
847
827
|
serializeStaticArray(changetype<nonnull<T>>(data));
|
|
828
|
+
} else if (data instanceof Int8Array) {
|
|
829
|
+
serializeTypedArray<Int8Array>(data);
|
|
830
|
+
} else if (data instanceof Uint8Array) {
|
|
831
|
+
serializeTypedArray<Uint8Array>(data);
|
|
832
|
+
} else if (data instanceof Uint8ClampedArray) {
|
|
833
|
+
serializeTypedArray<Uint8ClampedArray>(data);
|
|
834
|
+
} else if (data instanceof Int16Array) {
|
|
835
|
+
serializeTypedArray<Int16Array>(data);
|
|
836
|
+
} else if (data instanceof Uint16Array) {
|
|
837
|
+
serializeTypedArray<Uint16Array>(data);
|
|
838
|
+
} else if (data instanceof Int32Array) {
|
|
839
|
+
serializeTypedArray<Int32Array>(data);
|
|
840
|
+
} else if (data instanceof Uint32Array) {
|
|
841
|
+
serializeTypedArray<Uint32Array>(data);
|
|
842
|
+
} else if (data instanceof Int64Array) {
|
|
843
|
+
serializeTypedArray<Int64Array>(data);
|
|
844
|
+
} else if (data instanceof Uint64Array) {
|
|
845
|
+
serializeTypedArray<Uint64Array>(data);
|
|
846
|
+
} else if (data instanceof Float32Array) {
|
|
847
|
+
serializeTypedArray<Float32Array>(data);
|
|
848
|
+
} else if (data instanceof Float64Array) {
|
|
849
|
+
serializeTypedArray<Float64Array>(data);
|
|
848
850
|
} else if (data instanceof Set) {
|
|
849
851
|
// @ts-expect-error
|
|
850
852
|
serializeSet(changetype<nonnull<T>>(data));
|
|
@@ -860,14 +862,33 @@ export namespace JSON {
|
|
|
860
862
|
} else if (data instanceof JSON.Box) {
|
|
861
863
|
__serialize(data.value);
|
|
862
864
|
} else {
|
|
863
|
-
throw new Error(
|
|
864
|
-
`Could not serialize data of type '${nameof<T>()}'. ` +
|
|
865
|
-
`If this is a custom class, add the @json decorator: @json class ${nameof<T>()} { ... }. ` +
|
|
866
|
-
`Supported types: primitives, string, Array, Map, Date, and @json decorated classes.`,
|
|
867
|
-
);
|
|
865
|
+
throw new Error(`Could not serialize data of type '${nameof<T>()}'. ` + `If this is a custom class, add the @json decorator: @json class ${nameof<T>()} { ... }. ` + `Supported types: primitives, string, Array, StaticArray, TypedArray, Map, Date, and @json decorated classes. ` + `For ArrayBuffer, use JSON.stringifyArrayBuffer(changetype<usize>(...)).`);
|
|
868
866
|
}
|
|
869
867
|
}
|
|
870
868
|
|
|
869
|
+
|
|
870
|
+
@inline export function __serializeArrayBufferUnsafe(dataStart: usize): void {
|
|
871
|
+
serializeArrayBufferUnsafe(dataStart, changetype<OBJECT>(dataStart - TOTAL_OVERHEAD).rtSize);
|
|
872
|
+
}
|
|
873
|
+
|
|
874
|
+
|
|
875
|
+
@inline export function __serializeArrayBuffer(data: ArrayBuffer): void {
|
|
876
|
+
const dataStart = changetype<usize>(data);
|
|
877
|
+
serializeArrayBufferUnsafe(dataStart, changetype<OBJECT>(dataStart - TOTAL_OVERHEAD).rtSize);
|
|
878
|
+
}
|
|
879
|
+
|
|
880
|
+
|
|
881
|
+
@inline export function parseArrayBuffer(data: string): ArrayBuffer {
|
|
882
|
+
const dataSize = bytes(data);
|
|
883
|
+
const dataPtr = changetype<usize>(data);
|
|
884
|
+
return deserializeArrayBuffer(dataPtr, dataPtr + dataSize, 0);
|
|
885
|
+
}
|
|
886
|
+
|
|
887
|
+
|
|
888
|
+
@inline export function __deserializeArrayBuffer(srcStart: usize, srcEnd: usize, dst: usize = 0): ArrayBuffer {
|
|
889
|
+
return deserializeArrayBuffer(srcStart, srcEnd, dst);
|
|
890
|
+
}
|
|
891
|
+
|
|
871
892
|
/**
|
|
872
893
|
* Deserializes JSON data directly from the buffer.
|
|
873
894
|
* Should only be used if you know what you are doing.
|
|
@@ -876,31 +897,19 @@ export namespace JSON {
|
|
|
876
897
|
* @param dst - usize
|
|
877
898
|
* @returns void
|
|
878
899
|
*/
|
|
879
|
-
export function __deserialize<T>(
|
|
880
|
-
srcStart: usize,
|
|
881
|
-
srcEnd: usize,
|
|
882
|
-
dst: usize = 0,
|
|
883
|
-
): T {
|
|
900
|
+
export function __deserialize<T>(srcStart: usize, srcEnd: usize, dst: usize = 0): T {
|
|
884
901
|
if (isBoolean<T>()) {
|
|
885
902
|
// @ts-expect-error: type
|
|
886
903
|
return deserializeBoolean(srcStart, srcEnd);
|
|
887
904
|
} else if (isInteger<T>()) {
|
|
888
|
-
return
|
|
905
|
+
return isSigned<T>() ? deserializeInteger<T>(srcStart, srcEnd) : deserializeUnsigned<T>(srcStart, srcEnd);
|
|
889
906
|
} else if (isFloat<T>()) {
|
|
890
907
|
return deserializeFloat<T>(srcStart, srcEnd);
|
|
891
908
|
} else if (isString<T>()) {
|
|
892
|
-
if (srcEnd - srcStart < 4)
|
|
893
|
-
throw new Error(
|
|
894
|
-
"Cannot parse data as string because it was formatted incorrectly!",
|
|
895
|
-
);
|
|
909
|
+
if (srcEnd - srcStart < 4) throw new Error("Cannot parse data as string because it was formatted incorrectly!");
|
|
896
910
|
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
} else if (
|
|
900
|
-
isNullable<T>() &&
|
|
901
|
-
srcEnd - srcStart == 8 &&
|
|
902
|
-
load<u64>(srcStart) == NULL_WORD_U64
|
|
903
|
-
) {
|
|
911
|
+
return deserializeString(srcStart, srcEnd) as T;
|
|
912
|
+
} else if (isNullable<T>() && srcEnd - srcStart == 8 && load<u64>(srcStart) == NULL_WORD_U64) {
|
|
904
913
|
return null;
|
|
905
914
|
} else {
|
|
906
915
|
let type: nonnull<T> = changetype<nonnull<T>>(0);
|
|
@@ -910,18 +919,41 @@ export namespace JSON {
|
|
|
910
919
|
} else if (type instanceof Array) {
|
|
911
920
|
// @ts-expect-error: type
|
|
912
921
|
return deserializeArray<T>(srcStart, srcEnd, dst);
|
|
922
|
+
} else if (type instanceof Int8Array) {
|
|
923
|
+
return deserializeTypedArray<Int8Array>(srcStart, srcEnd, dst) as T;
|
|
924
|
+
} else if (type instanceof Uint8Array) {
|
|
925
|
+
return deserializeTypedArray<Uint8Array>(srcStart, srcEnd, dst) as T;
|
|
926
|
+
} else if (type instanceof Uint8ClampedArray) {
|
|
927
|
+
return deserializeTypedArray<Uint8ClampedArray>(srcStart, srcEnd, dst) as T;
|
|
928
|
+
} else if (type instanceof Int16Array) {
|
|
929
|
+
return deserializeTypedArray<Int16Array>(srcStart, srcEnd, dst) as T;
|
|
930
|
+
} else if (type instanceof Uint16Array) {
|
|
931
|
+
return deserializeTypedArray<Uint16Array>(srcStart, srcEnd, dst) as T;
|
|
932
|
+
} else if (type instanceof Int32Array) {
|
|
933
|
+
return deserializeTypedArray<Int32Array>(srcStart, srcEnd, dst) as T;
|
|
934
|
+
} else if (type instanceof Uint32Array) {
|
|
935
|
+
return deserializeTypedArray<Uint32Array>(srcStart, srcEnd, dst) as T;
|
|
936
|
+
} else if (type instanceof Int64Array) {
|
|
937
|
+
return deserializeTypedArray<Int64Array>(srcStart, srcEnd, dst) as T;
|
|
938
|
+
} else if (type instanceof Uint64Array) {
|
|
939
|
+
return deserializeTypedArray<Uint64Array>(srcStart, srcEnd, dst) as T;
|
|
940
|
+
} else if (type instanceof Float32Array) {
|
|
941
|
+
return deserializeTypedArray<Float32Array>(srcStart, srcEnd, dst) as T;
|
|
942
|
+
} else if (type instanceof Float64Array) {
|
|
943
|
+
return deserializeTypedArray<Float64Array>(srcStart, srcEnd, dst) as T;
|
|
944
|
+
} else if (type instanceof ArrayBuffer) {
|
|
945
|
+
return deserializeArrayBuffer(srcStart, srcEnd, dst) as T;
|
|
913
946
|
} else if (type instanceof Set) {
|
|
914
947
|
// @ts-expect-error: type
|
|
915
948
|
return deserializeSet<T>(srcStart, srcEnd, dst);
|
|
916
949
|
// @ts-expect-error: Defined by transform
|
|
917
950
|
} else if (isDefined(type.__DESERIALIZE)) {
|
|
918
|
-
const out = changetype<nonnull<T>>(
|
|
919
|
-
dst || __new(offsetof<nonnull<T>>(), idof<nonnull<T>>()),
|
|
920
|
-
);
|
|
951
|
+
const out = changetype<nonnull<T>>(dst || __new(offsetof<nonnull<T>>(), idof<nonnull<T>>()));
|
|
921
952
|
// @ts-expect-error: Defined by transform
|
|
922
953
|
if (isDefined(type.__INITIALIZE)) out.__INITIALIZE();
|
|
923
954
|
// @ts-expect-error: Defined by transform
|
|
924
|
-
|
|
955
|
+
out.__DESERIALIZE(srcStart, srcEnd, out);
|
|
956
|
+
return out;
|
|
925
957
|
} else if (type instanceof Map) {
|
|
926
958
|
// @ts-expect-error: type
|
|
927
959
|
return deserializeMap<T>(srcStart, srcEnd, dst);
|
|
@@ -939,22 +971,11 @@ export namespace JSON {
|
|
|
939
971
|
return deserializeObject(srcStart, srcEnd, 0);
|
|
940
972
|
} else if (type instanceof JSON.Box) {
|
|
941
973
|
// @ts-expect-error: type
|
|
942
|
-
return new JSON.Box(
|
|
943
|
-
deserializeBox(
|
|
944
|
-
srcStart,
|
|
945
|
-
srcEnd,
|
|
946
|
-
dst,
|
|
947
|
-
changetype<nonnull<T>>(0).value,
|
|
948
|
-
),
|
|
949
|
-
);
|
|
974
|
+
return new JSON.Box(deserializeBox(srcStart, srcEnd, dst, changetype<nonnull<T>>(0).value));
|
|
950
975
|
}
|
|
951
976
|
}
|
|
952
977
|
const snippet = ptrToStr(srcStart, srcEnd);
|
|
953
|
-
throw new Error(
|
|
954
|
-
`Could not deserialize JSON to type '${nameof<T>()}'. ` +
|
|
955
|
-
`If this is a custom class, ensure it has the @json decorator: @json class ${nameof<T>()} { ... }. ` +
|
|
956
|
-
`Input: "${snippet.length > 50 ? snippet.slice(0, 50) + "..." : snippet}"`,
|
|
957
|
-
);
|
|
978
|
+
throw new Error(`Could not deserialize JSON to type '${nameof<T>()}'. ` + `If this is a custom class, ensure it has the @json decorator: @json class ${nameof<T>()} { ... }. ` + `Input: "${snippet.length > 50 ? snippet.slice(0, 50) + "..." : snippet}"`);
|
|
958
979
|
}
|
|
959
980
|
export namespace Util {
|
|
960
981
|
// @ts-expect-error: decorator
|
|
@@ -980,10 +1001,7 @@ export namespace JSON {
|
|
|
980
1001
|
* @returns - string
|
|
981
1002
|
*/
|
|
982
1003
|
// @ts-expect-error: inline
|
|
983
|
-
@inline export function stringify<T>(
|
|
984
|
-
data: T,
|
|
985
|
-
out: string | null = null,
|
|
986
|
-
): string {
|
|
1004
|
+
@inline export function stringify<T>(data: T, out: string | null = null): string {
|
|
987
1005
|
if (isBoolean<T>()) {
|
|
988
1006
|
if (out) {
|
|
989
1007
|
if (<bool>data == true) {
|
|
@@ -997,12 +1015,7 @@ export namespace JSON {
|
|
|
997
1015
|
return out;
|
|
998
1016
|
}
|
|
999
1017
|
return data ? "true" : "false";
|
|
1000
|
-
} else if (
|
|
1001
|
-
isInteger<T>() &&
|
|
1002
|
-
!isSigned<T>() &&
|
|
1003
|
-
nameof<T>() == "usize" &&
|
|
1004
|
-
data == 0
|
|
1005
|
-
) {
|
|
1018
|
+
} else if (isInteger<T>() && !isSigned<T>() && nameof<T>() == "usize" && data == 0) {
|
|
1006
1019
|
if (out) {
|
|
1007
1020
|
out = changetype<string>(__renew(changetype<usize>(out), 8));
|
|
1008
1021
|
store<u64>(changetype<usize>(out), NULL_WORD_U64);
|
|
@@ -1011,14 +1024,10 @@ export namespace JSON {
|
|
|
1011
1024
|
return NULL_WORD;
|
|
1012
1025
|
} else if (isInteger<T>(data)) {
|
|
1013
1026
|
if (out) {
|
|
1014
|
-
out = changetype<string>(
|
|
1015
|
-
__renew(changetype<usize>(out), sizeof<T>() << 3),
|
|
1016
|
-
);
|
|
1027
|
+
out = changetype<string>(__renew(changetype<usize>(out), sizeof<T>() << 3));
|
|
1017
1028
|
|
|
1018
1029
|
const bytes = itoa_buffered(changetype<usize>(out), data) << 1;
|
|
1019
|
-
return (out = changetype<string>(
|
|
1020
|
-
__renew(changetype<usize>(out), bytes),
|
|
1021
|
-
));
|
|
1030
|
+
return (out = changetype<string>(__renew(changetype<usize>(out), bytes)));
|
|
1022
1031
|
}
|
|
1023
1032
|
return data.toString();
|
|
1024
1033
|
} else if (isFloat<T>(data)) {
|
|
@@ -1026,9 +1035,7 @@ export namespace JSON {
|
|
|
1026
1035
|
out = changetype<string>(__renew(changetype<usize>(out), 64));
|
|
1027
1036
|
|
|
1028
1037
|
const bytes = dtoa_buffered(changetype<usize>(out), data) << 1;
|
|
1029
|
-
return (out = changetype<string>(
|
|
1030
|
-
__renew(changetype<usize>(out), bytes),
|
|
1031
|
-
));
|
|
1038
|
+
return (out = changetype<string>(__renew(changetype<usize>(out), bytes)));
|
|
1032
1039
|
}
|
|
1033
1040
|
return data.toString();
|
|
1034
1041
|
} else if (isNullable<T>() && changetype<usize>(data) == <usize>0) {
|
|
@@ -1039,13 +1046,7 @@ export namespace JSON {
|
|
|
1039
1046
|
}
|
|
1040
1047
|
return NULL_WORD;
|
|
1041
1048
|
} else if (isString<nonnull<T>>()) {
|
|
1042
|
-
|
|
1043
|
-
serializeString_SIMD(data as string);
|
|
1044
|
-
} else if (JSON_MODE === JSONMode.SWAR) {
|
|
1045
|
-
serializeString_SWAR(data as string);
|
|
1046
|
-
} else {
|
|
1047
|
-
serializeString(data as string);
|
|
1048
|
-
}
|
|
1049
|
+
serializeString(data as string);
|
|
1049
1050
|
return bs.cpyOut<string>();
|
|
1050
1051
|
// @ts-expect-error: Supplied by transform
|
|
1051
1052
|
} else if (isDefined(data.__SERIALIZE)) {
|
|
@@ -1054,16 +1055,10 @@ export namespace JSON {
|
|
|
1054
1055
|
inline.always(data.__SERIALIZE(changetype<usize>(data)));
|
|
1055
1056
|
return bs.cpyOut<string>();
|
|
1056
1057
|
} else if (data instanceof Date) {
|
|
1057
|
-
out = out
|
|
1058
|
-
? changetype<string>(__renew(changetype<usize>(out), 52))
|
|
1059
|
-
: changetype<string>(__new(52, idof<string>()));
|
|
1058
|
+
out = out ? changetype<string>(__renew(changetype<usize>(out), 52)) : changetype<string>(__new(52, idof<string>()));
|
|
1060
1059
|
|
|
1061
1060
|
store<u16>(changetype<usize>(out), QUOTE);
|
|
1062
|
-
memory.copy(
|
|
1063
|
-
changetype<usize>(out) + 2,
|
|
1064
|
-
changetype<usize>(data.toISOString()),
|
|
1065
|
-
48,
|
|
1066
|
-
);
|
|
1061
|
+
memory.copy(changetype<usize>(out) + 2, changetype<usize>(data.toISOString()), 48);
|
|
1067
1062
|
store<u16>(changetype<usize>(out), QUOTE, 50);
|
|
1068
1063
|
return changetype<string>(out);
|
|
1069
1064
|
} else if (data instanceof Array) {
|
|
@@ -1101,11 +1096,7 @@ export namespace JSON {
|
|
|
1101
1096
|
} else if (data instanceof JSON.Box) {
|
|
1102
1097
|
return JSON.internal.stringify(data.value);
|
|
1103
1098
|
} else {
|
|
1104
|
-
throw new Error(
|
|
1105
|
-
`Could not serialize data of type '${nameof<T>()}'. ` +
|
|
1106
|
-
`If this is a custom class, add the @json decorator: @json class ${nameof<T>()} { ... }. ` +
|
|
1107
|
-
`Supported types: primitives, string, Array, Map, Date, and @json decorated classes.`,
|
|
1108
|
-
);
|
|
1099
|
+
throw new Error(`Could not serialize data of type '${nameof<T>()}'. ` + `If this is a custom class, add the @json decorator: @json class ${nameof<T>()} { ... }. ` + `Supported types: primitives, string, Array, Map, Date, and @json decorated classes.`);
|
|
1109
1100
|
}
|
|
1110
1101
|
}
|
|
1111
1102
|
}
|
|
@@ -1122,12 +1113,7 @@ export enum JSONMode {
|
|
|
1122
1113
|
return JSON.parse<T>(data);
|
|
1123
1114
|
}
|
|
1124
1115
|
// @ts-expect-error: inline
|
|
1125
|
-
@inline function deserializeBox<T>(
|
|
1126
|
-
srcStart: usize,
|
|
1127
|
-
srcEnd: usize,
|
|
1128
|
-
dst: usize,
|
|
1129
|
-
ty: T,
|
|
1130
|
-
): T {
|
|
1116
|
+
@inline function deserializeBox<T>(srcStart: usize, srcEnd: usize, dst: usize, ty: T): T {
|
|
1131
1117
|
return JSON.__deserialize<T>(srcStart, srcEnd, dst);
|
|
1132
1118
|
}
|
|
1133
1119
|
|