json-as 1.3.0 → 1.3.1
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/CHANGELOG.md +417 -0
- package/README.md +96 -14
- package/assembly/deserialize/index/typedarray.ts +14 -0
- package/assembly/deserialize/simd/string.ts +3 -3
- package/assembly/deserialize/simple/string.ts +88 -2
- package/assembly/deserialize/swar/string.ts +8 -11
- package/assembly/index.ts +137 -181
- package/assembly/serialize/index/arbitrary.ts +5 -0
- package/assembly/serialize/index/typedarray.ts +65 -0
- package/assembly/serialize/simd/string.ts +3 -11
- package/assembly/serialize/simple/arbitrary.ts +6 -0
- package/assembly/serialize/simple/string.ts +3 -11
- package/assembly/serialize/swar/string.ts +3 -11
- package/assembly/util/swar.ts +49 -0
- package/lib/as-bs.ts +88 -69
- package/package.json +19 -1
- package/transform/lib/index.d.ts +1 -0
- package/transform/lib/index.d.ts.map +1 -1
- package/transform/lib/index.js +153 -32
- package/transform/lib/index.js.map +1 -1
- package/transform/lib/linkers/custom.d.ts.map +1 -1
- package/transform/lib/linkers/custom.js +7 -3
- package/transform/lib/linkers/custom.js.map +1 -1
- package/transform/lib/types.d.ts +2 -0
- package/transform/lib/types.d.ts.map +1 -1
- package/transform/lib/types.js +13 -0
- package/transform/lib/types.js.map +1 -1
- package/.as-test/coverage/naive/coverage.arbitrary.spec.ts.log.json +0 -5628
- package/.as-test/coverage/naive/coverage.array.spec.ts.log.json +0 -5187
- package/.as-test/coverage/naive/coverage.bool.spec.ts.log.json +0 -5187
- package/.as-test/coverage/naive/coverage.box.spec.ts.log.json +0 -5187
- package/.as-test/coverage/naive/coverage.custom.spec.ts.log.json +0 -5187
- package/.as-test/coverage/naive/coverage.date.spec.ts.log.json +0 -5187
- package/.as-test/coverage/naive/coverage.enum.spec.ts.log.json +0 -5187
- package/.as-test/coverage/naive/coverage.float.spec.ts.log.json +0 -5187
- package/.as-test/coverage/naive/coverage.generics.spec.ts.log.json +0 -5187
- package/.as-test/coverage/naive/coverage.hierarchy.spec.ts.log.json +0 -5187
- package/.as-test/coverage/naive/coverage.integer.spec.ts.log.json +0 -5187
- package/.as-test/coverage/naive/coverage.map.spec.ts.log.json +0 -5187
- package/.as-test/coverage/naive/coverage.namespace.spec.ts.log.json +0 -5187
- package/.as-test/coverage/naive/coverage.null.spec.ts.log.json +0 -5187
- package/.as-test/coverage/naive/coverage.raw.spec.ts.log.json +0 -5187
- package/.as-test/coverage/naive/coverage.resolving.spec.ts.log.json +0 -5628
- package/.as-test/coverage/naive/coverage.set.spec.ts.log.json +0 -5187
- package/.as-test/coverage/naive/coverage.staticarray.spec.ts.log.json +0 -5187
- package/.as-test/coverage/naive/coverage.string.spec.ts.log.json +0 -5187
- package/.as-test/coverage/naive/coverage.struct.spec.ts.log.json +0 -5187
- package/.as-test/coverage/naive/coverage.types.spec.ts.log.json +0 -5187
- package/.as-test/coverage/simd/coverage.arbitrary.spec.ts.log.json +0 -5628
- package/.as-test/coverage/simd/coverage.array.spec.ts.log.json +0 -5187
- package/.as-test/coverage/simd/coverage.bool.spec.ts.log.json +0 -5187
- package/.as-test/coverage/simd/coverage.box.spec.ts.log.json +0 -5187
- package/.as-test/coverage/simd/coverage.custom.spec.ts.log.json +0 -5187
- package/.as-test/coverage/simd/coverage.date.spec.ts.log.json +0 -5187
- package/.as-test/coverage/simd/coverage.enum.spec.ts.log.json +0 -5187
- package/.as-test/coverage/simd/coverage.float.spec.ts.log.json +0 -5187
- package/.as-test/coverage/simd/coverage.generics.spec.ts.log.json +0 -5187
- package/.as-test/coverage/simd/coverage.hierarchy.spec.ts.log.json +0 -5187
- package/.as-test/coverage/simd/coverage.integer.spec.ts.log.json +0 -5187
- package/.as-test/coverage/simd/coverage.map.spec.ts.log.json +0 -5187
- package/.as-test/coverage/simd/coverage.namespace.spec.ts.log.json +0 -5187
- package/.as-test/coverage/simd/coverage.null.spec.ts.log.json +0 -5187
- package/.as-test/coverage/simd/coverage.raw.spec.ts.log.json +0 -5187
- package/.as-test/coverage/simd/coverage.resolving.spec.ts.log.json +0 -5628
- package/.as-test/coverage/simd/coverage.set.spec.ts.log.json +0 -5187
- package/.as-test/coverage/simd/coverage.staticarray.spec.ts.log.json +0 -5187
- package/.as-test/coverage/simd/coverage.string.spec.ts.log.json +0 -5187
- package/.as-test/coverage/simd/coverage.struct.spec.ts.log.json +0 -5187
- package/.as-test/coverage/simd/coverage.types.spec.ts.log.json +0 -5187
- package/.as-test/coverage/swar/coverage.arbitrary.spec.ts.log.json +0 -5628
- package/.as-test/coverage/swar/coverage.array.spec.ts.log.json +0 -5187
- package/.as-test/coverage/swar/coverage.bool.spec.ts.log.json +0 -5187
- package/.as-test/coverage/swar/coverage.box.spec.ts.log.json +0 -5187
- package/.as-test/coverage/swar/coverage.custom.spec.ts.log.json +0 -5187
- package/.as-test/coverage/swar/coverage.date.spec.ts.log.json +0 -5187
- package/.as-test/coverage/swar/coverage.enum.spec.ts.log.json +0 -5187
- package/.as-test/coverage/swar/coverage.float.spec.ts.log.json +0 -5187
- package/.as-test/coverage/swar/coverage.generics.spec.ts.log.json +0 -5187
- package/.as-test/coverage/swar/coverage.hierarchy.spec.ts.log.json +0 -5187
- package/.as-test/coverage/swar/coverage.integer.spec.ts.log.json +0 -5187
- package/.as-test/coverage/swar/coverage.map.spec.ts.log.json +0 -5187
- package/.as-test/coverage/swar/coverage.namespace.spec.ts.log.json +0 -5187
- package/.as-test/coverage/swar/coverage.null.spec.ts.log.json +0 -5187
- package/.as-test/coverage/swar/coverage.raw.spec.ts.log.json +0 -5187
- package/.as-test/coverage/swar/coverage.resolving.spec.ts.log.json +0 -5628
- package/.as-test/coverage/swar/coverage.set.spec.ts.log.json +0 -5187
- package/.as-test/coverage/swar/coverage.staticarray.spec.ts.log.json +0 -5187
- package/.as-test/coverage/swar/coverage.string.spec.ts.log.json +0 -5187
- package/.as-test/coverage/swar/coverage.struct.spec.ts.log.json +0 -5187
- package/.as-test/coverage/swar/coverage.types.spec.ts.log.json +0 -5187
- package/.as-test/logs/naive/run.arbitrary.spec.ts.log.json +0 -943
- package/.as-test/logs/naive/run.array.spec.ts.log.json +0 -1053
- package/.as-test/logs/naive/run.bool.spec.ts.log.json +0 -257
- package/.as-test/logs/naive/run.box.spec.ts.log.json +0 -353
- package/.as-test/logs/naive/run.custom.spec.ts.log.json +0 -309
- package/.as-test/logs/naive/run.date.spec.ts.log.json +0 -397
- package/.as-test/logs/naive/run.enum.spec.ts.log.json +0 -343
- package/.as-test/logs/naive/run.float.spec.ts.log.json +0 -453
- package/.as-test/logs/naive/run.generics.spec.ts.log.json +0 -393
- package/.as-test/logs/naive/run.hierarchy.spec.ts.log.json +0 -325
- package/.as-test/logs/naive/run.integer.spec.ts.log.json +0 -373
- package/.as-test/logs/naive/run.map.spec.ts.log.json +0 -247
- package/.as-test/logs/naive/run.namespace.spec.ts.log.json +0 -361
- package/.as-test/logs/naive/run.null.spec.ts.log.json +0 -273
- package/.as-test/logs/naive/run.raw.spec.ts.log.json +0 -309
- package/.as-test/logs/naive/run.resolving.spec.ts.log.json +0 -273
- package/.as-test/logs/naive/run.set.spec.ts.log.json +0 -733
- package/.as-test/logs/naive/run.staticarray.spec.ts.log.json +0 -931
- package/.as-test/logs/naive/run.string.spec.ts.log.json +0 -2289
- package/.as-test/logs/naive/run.struct.spec.ts.log.json +0 -523
- package/.as-test/logs/naive/run.types.spec.ts.log.json +0 -273
- package/.as-test/logs/naive/test.arbitrary.spec.ts.log.json +0 -943
- package/.as-test/logs/naive/test.array.spec.ts.log.json +0 -1053
- package/.as-test/logs/naive/test.bool.spec.ts.log.json +0 -257
- package/.as-test/logs/naive/test.box.spec.ts.log.json +0 -353
- package/.as-test/logs/naive/test.custom.spec.ts.log.json +0 -309
- package/.as-test/logs/naive/test.date.spec.ts.log.json +0 -397
- package/.as-test/logs/naive/test.enum.spec.ts.log.json +0 -343
- package/.as-test/logs/naive/test.float.spec.ts.log.json +0 -453
- package/.as-test/logs/naive/test.generics.spec.ts.log.json +0 -393
- package/.as-test/logs/naive/test.hierarchy.spec.ts.log.json +0 -325
- package/.as-test/logs/naive/test.integer.spec.ts.log.json +0 -373
- package/.as-test/logs/naive/test.log.json +0 -2289
- package/.as-test/logs/naive/test.map.spec.ts.log.json +0 -247
- package/.as-test/logs/naive/test.namespace.spec.ts.log.json +0 -361
- package/.as-test/logs/naive/test.null.spec.ts.log.json +0 -273
- package/.as-test/logs/naive/test.raw.spec.ts.log.json +0 -309
- package/.as-test/logs/naive/test.resolving.spec.ts.log.json +0 -273
- package/.as-test/logs/naive/test.set.spec.ts.log.json +0 -733
- package/.as-test/logs/naive/test.staticarray.spec.ts.log.json +0 -931
- package/.as-test/logs/naive/test.string.spec.ts.log.json +0 -2345
- package/.as-test/logs/naive/test.struct.spec.ts.log.json +0 -523
- package/.as-test/logs/naive/test.types.spec.ts.log.json +0 -273
- package/.as-test/logs/simd/run.arbitrary.spec.ts.log.json +0 -943
- package/.as-test/logs/simd/run.array.spec.ts.log.json +0 -1053
- package/.as-test/logs/simd/run.bool.spec.ts.log.json +0 -257
- package/.as-test/logs/simd/run.box.spec.ts.log.json +0 -353
- package/.as-test/logs/simd/run.custom.spec.ts.log.json +0 -309
- package/.as-test/logs/simd/run.date.spec.ts.log.json +0 -397
- package/.as-test/logs/simd/run.enum.spec.ts.log.json +0 -343
- package/.as-test/logs/simd/run.float.spec.ts.log.json +0 -453
- package/.as-test/logs/simd/run.generics.spec.ts.log.json +0 -393
- package/.as-test/logs/simd/run.hierarchy.spec.ts.log.json +0 -325
- package/.as-test/logs/simd/run.integer.spec.ts.log.json +0 -373
- package/.as-test/logs/simd/run.map.spec.ts.log.json +0 -247
- package/.as-test/logs/simd/run.namespace.spec.ts.log.json +0 -361
- package/.as-test/logs/simd/run.null.spec.ts.log.json +0 -273
- package/.as-test/logs/simd/run.raw.spec.ts.log.json +0 -309
- package/.as-test/logs/simd/run.resolving.spec.ts.log.json +0 -273
- package/.as-test/logs/simd/run.set.spec.ts.log.json +0 -733
- package/.as-test/logs/simd/run.staticarray.spec.ts.log.json +0 -931
- package/.as-test/logs/simd/run.string.spec.ts.log.json +0 -2289
- package/.as-test/logs/simd/run.struct.spec.ts.log.json +0 -523
- package/.as-test/logs/simd/run.types.spec.ts.log.json +0 -273
- package/.as-test/logs/simd/test.arbitrary.spec.ts.log.json +0 -943
- package/.as-test/logs/simd/test.array.spec.ts.log.json +0 -1053
- package/.as-test/logs/simd/test.bool.spec.ts.log.json +0 -257
- package/.as-test/logs/simd/test.box.spec.ts.log.json +0 -353
- package/.as-test/logs/simd/test.custom.spec.ts.log.json +0 -309
- package/.as-test/logs/simd/test.date.spec.ts.log.json +0 -397
- package/.as-test/logs/simd/test.enum.spec.ts.log.json +0 -343
- package/.as-test/logs/simd/test.float.spec.ts.log.json +0 -453
- package/.as-test/logs/simd/test.generics.spec.ts.log.json +0 -393
- package/.as-test/logs/simd/test.hierarchy.spec.ts.log.json +0 -325
- package/.as-test/logs/simd/test.integer.spec.ts.log.json +0 -373
- package/.as-test/logs/simd/test.log.json +0 -11371
- package/.as-test/logs/simd/test.map.spec.ts.log.json +0 -247
- package/.as-test/logs/simd/test.namespace.spec.ts.log.json +0 -361
- package/.as-test/logs/simd/test.null.spec.ts.log.json +0 -273
- package/.as-test/logs/simd/test.raw.spec.ts.log.json +0 -309
- package/.as-test/logs/simd/test.resolving.spec.ts.log.json +0 -273
- package/.as-test/logs/simd/test.set.spec.ts.log.json +0 -733
- package/.as-test/logs/simd/test.staticarray.spec.ts.log.json +0 -931
- package/.as-test/logs/simd/test.string.spec.ts.log.json +0 -2345
- package/.as-test/logs/simd/test.struct.spec.ts.log.json +0 -523
- package/.as-test/logs/simd/test.types.spec.ts.log.json +0 -273
- package/.as-test/logs/swar/run.arbitrary.spec.ts.log.json +0 -943
- package/.as-test/logs/swar/run.array.spec.ts.log.json +0 -1053
- package/.as-test/logs/swar/run.bool.spec.ts.log.json +0 -257
- package/.as-test/logs/swar/run.box.spec.ts.log.json +0 -353
- package/.as-test/logs/swar/run.custom.spec.ts.log.json +0 -309
- package/.as-test/logs/swar/run.date.spec.ts.log.json +0 -397
- package/.as-test/logs/swar/run.enum.spec.ts.log.json +0 -343
- package/.as-test/logs/swar/run.float.spec.ts.log.json +0 -453
- package/.as-test/logs/swar/run.generics.spec.ts.log.json +0 -393
- package/.as-test/logs/swar/run.hierarchy.spec.ts.log.json +0 -325
- package/.as-test/logs/swar/run.integer.spec.ts.log.json +0 -373
- package/.as-test/logs/swar/run.map.spec.ts.log.json +0 -247
- package/.as-test/logs/swar/run.namespace.spec.ts.log.json +0 -361
- package/.as-test/logs/swar/run.null.spec.ts.log.json +0 -273
- package/.as-test/logs/swar/run.raw.spec.ts.log.json +0 -309
- package/.as-test/logs/swar/run.resolving.spec.ts.log.json +0 -273
- package/.as-test/logs/swar/run.set.spec.ts.log.json +0 -733
- package/.as-test/logs/swar/run.staticarray.spec.ts.log.json +0 -931
- package/.as-test/logs/swar/run.string.spec.ts.log.json +0 -2289
- package/.as-test/logs/swar/run.struct.spec.ts.log.json +0 -523
- package/.as-test/logs/swar/run.types.spec.ts.log.json +0 -273
- package/.as-test/logs/swar/test.arbitrary.spec.ts.log.json +0 -943
- package/.as-test/logs/swar/test.array.spec.ts.log.json +0 -1053
- package/.as-test/logs/swar/test.bool.spec.ts.log.json +0 -257
- package/.as-test/logs/swar/test.box.spec.ts.log.json +0 -353
- package/.as-test/logs/swar/test.custom.spec.ts.log.json +0 -309
- package/.as-test/logs/swar/test.date.spec.ts.log.json +0 -397
- package/.as-test/logs/swar/test.enum.spec.ts.log.json +0 -343
- package/.as-test/logs/swar/test.float.spec.ts.log.json +0 -453
- package/.as-test/logs/swar/test.generics.spec.ts.log.json +0 -393
- package/.as-test/logs/swar/test.hierarchy.spec.ts.log.json +0 -325
- package/.as-test/logs/swar/test.integer.spec.ts.log.json +0 -373
- package/.as-test/logs/swar/test.log.json +0 -11371
- package/.as-test/logs/swar/test.map.spec.ts.log.json +0 -247
- package/.as-test/logs/swar/test.namespace.spec.ts.log.json +0 -361
- package/.as-test/logs/swar/test.null.spec.ts.log.json +0 -273
- package/.as-test/logs/swar/test.raw.spec.ts.log.json +0 -309
- package/.as-test/logs/swar/test.resolving.spec.ts.log.json +0 -273
- package/.as-test/logs/swar/test.set.spec.ts.log.json +0 -733
- package/.as-test/logs/swar/test.staticarray.spec.ts.log.json +0 -931
- package/.as-test/logs/swar/test.string.spec.ts.log.json +0 -2345
- package/.as-test/logs/swar/test.struct.spec.ts.log.json +0 -523
- package/.as-test/logs/swar/test.types.spec.ts.log.json +0 -273
- package/.as-test/logs/test.arbitrary.spec.ts.log.json +0 -943
- package/.as-test/logs/test.array.spec.ts.log.json +0 -1053
- package/.as-test/logs/test.bool.spec.ts.log.json +0 -257
- package/.as-test/logs/test.box.spec.ts.log.json +0 -353
- package/.as-test/logs/test.custom.spec.ts.log.json +0 -309
- package/.as-test/logs/test.date.spec.ts.log.json +0 -397
- package/.as-test/logs/test.enum.spec.ts.log.json +0 -343
- package/.as-test/logs/test.float.spec.ts.log.json +0 -453
- package/.as-test/logs/test.generics.spec.ts.log.json +0 -393
- package/.as-test/logs/test.hierarchy.spec.ts.log.json +0 -325
- package/.as-test/logs/test.integer.spec.ts.log.json +0 -373
- package/.as-test/logs/test.log.json +0 -11371
- package/.as-test/logs/test.map.spec.ts.log.json +0 -247
- package/.as-test/logs/test.namespace.spec.ts.log.json +0 -361
- package/.as-test/logs/test.null.spec.ts.log.json +0 -273
- package/.as-test/logs/test.raw.spec.ts.log.json +0 -309
- package/.as-test/logs/test.resolving.spec.ts.log.json +0 -273
- package/.as-test/logs/test.set.spec.ts.log.json +0 -733
- package/.as-test/logs/test.staticarray.spec.ts.log.json +0 -931
- package/.as-test/logs/test.string.spec.ts.log.json +0 -2289
- package/.as-test/logs/test.struct.spec.ts.log.json +0 -523
- package/.as-test/logs/test.types.spec.ts.log.json +0 -273
- package/.as-test/runners/default.bindings.js +0 -68
- package/.as-test/runners/default.wasi.js +0 -38
- package/ARCHITECTURE.md +0 -323
- package/CONTRIBUTING.md +0 -244
- package/TODO +0 -1
- package/as-test.config.json +0 -40
- package/assembly/test.ts +0 -24
- package/eslint.config.js +0 -68
- package/lib/tsconfig.json +0 -8
- package/test.ts +0 -99
- package/tools/assemblyscript-eslint-local.js +0 -6
- package/tools/assemblyscript-eslint.js +0 -53
- package/tools/assemblyscript-prettier-plugin.js +0 -33
- package/tools/replacer.js +0 -63
- package/transform/tsconfig.json +0 -35
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,417 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
## Unreleased
|
|
4
|
+
|
|
5
|
+
- feat: allow `JSON.Value` to store and re-serialize built-in typed arrays and `ArrayBuffer`
|
|
6
|
+
- feat: support `JSON.stringify<ArrayBuffer>(...)` directly without a dedicated helper
|
|
7
|
+
- feat: let explicit `__SERIALIZE_CUSTOM` / `__DESERIALIZE_CUSTOM` hooks override built-in typed-array and `ArrayBuffer` handling while keeping generated hooks last
|
|
8
|
+
- feat: support optional JSON shape hints on `@serializer(...)` / `@deserializer(...)` decorators, defaulting to `any` and allowing nullable forms like `string | null`
|
|
9
|
+
- fix: preserve `bs` state across `JSON.internal.stringify(...)` and `JSON.internal.parse(...)`
|
|
10
|
+
- fix: make escaped string deserializers use local `bs` slices so nested parse/custom flows do not clobber active buffer state
|
|
11
|
+
- fix: allow nested `@json` fields that use decorator-based custom deserializers to deserialize correctly from string-valued object properties
|
|
12
|
+
- fix: restore correct object-value end pointers in generated field deserializers so nested maps and custom string-backed fields both deserialize correctly
|
|
13
|
+
- fix: make `JSON.Value` follow built-in subclass rules consistently for typed-array subclasses and custom `@json` subclasses
|
|
14
|
+
- fix: make generated custom serializer wrappers use the provided `ptr` so indirect-call sites like `JSON.Value` serialize correctly
|
|
15
|
+
- fix: resolve stdlib and `--lib` base classes during transform inheritance so `@json` subclasses of built-ins like `Uint8Array` include inherited fields instead of collapsing to empty objects
|
|
16
|
+
- fix: stop preloading transform imports through `parser.parseFile(...)`, so repeated `asc()` calls in the same process no longer poison parser state or trip `lookupForeignFile` assertions
|
|
17
|
+
- fix: rewrite nested `JSON.parse(...)` calls inside custom serializers and deserializers to `JSON.internal.parse(...)`, matching the existing internal stringify rewrite and documented behavior
|
|
18
|
+
- docs: clarify that custom serializers and deserializers must always produce and consume valid JSON
|
|
19
|
+
- docs: document how subclassing built-in container types behaves, including when `@json` custom overrides take effect
|
|
20
|
+
- fix: stop naive string deserialization scratch allocations from growing across repeated large payload parses by using local `ensureSize(...)` scratch capacity instead of serialization-style proposed growth
|
|
21
|
+
- tests: expand custom serializer/deserializer coverage for nullable fields, multiple custom fields, escaped content, whitespace, and repeated round-trips
|
|
22
|
+
- tests: add a repeated large string-heavy struct parse regression that exercises the naive deserialization scratch path
|
|
23
|
+
- tests: add override coverage for plain and custom subclasses of `Array`, `Map`, `Set`, and typed arrays
|
|
24
|
+
- tests: add `JSON.Value` regressions for undecorated and decorated typed-array subclasses
|
|
25
|
+
- tests: add regression coverage for generated `@json` subclasses inheriting stdlib typed-array fields
|
|
26
|
+
- chore: restrict published package contents to the runtime, declarations, built transform output, and top-level metadata files
|
|
27
|
+
- perf: raise the serialization buffer minimum size to 1024 bytes and add adaptive `bs.shrink()`
|
|
28
|
+
- perf: add a packed SWAR `u16_to_hex4_swar` helper for `\uXXXX` emission and use it across simple, SWAR, and SIMD string serializers
|
|
29
|
+
- tests: add dedicated SWAR hex helper coverage, including exhaustive full-range round-trip validation
|
|
30
|
+
- bench: add SWAR hex and SWAR string serializer head-to-head microbenchmarks
|
|
31
|
+
|
|
32
|
+
## 2026-03-19 - 1.3.0
|
|
33
|
+
|
|
34
|
+
- chore: exclude generated `.as-test` build artifacts from ESLint, tighten generic deserializer offset math, and remove the obsolete `run-tests.sh` helper
|
|
35
|
+
- fix: add built-in typed array and `ArrayBuffer` serialization and deserialization support, including transform-generated field handling inside `@json` classes
|
|
36
|
+
- fix: finish subtype-aware `StaticArray` deserialization for nested arrays, maps, JSON value types, transform-backed structs, and related regressions
|
|
37
|
+
- fix: tighten default-path runtime correctness for signed `JSON.Value`, `@omitif("...")`, escaped nested strings, raw-array string handling, and `JSON.Obj.from(...)`
|
|
38
|
+
- perf: add a SIMD string-field deserializer for fast-path object deserialization and align transform codegen with mode-specific field helpers
|
|
39
|
+
- perf: add direct SWAR and SIMD integer-array deserializers with reusable-storage fast paths and dedicated throughput benches
|
|
40
|
+
- refactor: add `assembly/serialize/index/*` and `assembly/deserialize/index/*` dispatchers and route the public API through them
|
|
41
|
+
- perf: speed up float deserialization with handwritten parser paths, bitwise power-of-ten handling, and batched fractional parsing
|
|
42
|
+
- fix: avoid pulling SIMD code into non-SIMD bench builds and make benchmark temp-file cleanup tolerant of missing `asc --converge` outputs
|
|
43
|
+
- compat: add compatability between json-as and try-as by ignoring methods prefixed by __try
|
|
44
|
+
- feat: gate generated fast struct deserialization behind `JSON_USE_FAST_PATH=1`
|
|
45
|
+
- refactor: make generated struct `__DESERIALIZE` methods return the advanced source pointer
|
|
46
|
+
- perf: tune SWAR and SIMD string deserialization to return plain strings directly and only allocate scratch space after the first escape
|
|
47
|
+
- perf: streamline split SWAR string field deserialization and string-buffer reuse on the fast path
|
|
48
|
+
- perf: simplify generated fast integer field parsing to reuse `srcStart` and offset-based stores
|
|
49
|
+
- perf: parse generated numeric fields in a single pass with typed integer, unsigned, and float field helpers
|
|
50
|
+
- perf: hand-tune `small.bench.ts` and refresh benchmark runner turbofan flag configuration
|
|
51
|
+
- bench: add a string deserialization head-to-head benchmark and simplify throughput/chart comparisons back to the final JS/NAIVE/SWAR/SIMD view
|
|
52
|
+
- fix: keep the fast generated path opt-in by default and restore the `large` benchmark slow-path behavior
|
|
53
|
+
- refactor: split numeric deserializers into dedicated `assembly/deserialize/{integer,unsigned,float}` modules
|
|
54
|
+
- tooling: expand benchmark chart metadata parsing for custom string benchmark series
|
|
55
|
+
- tests: add escaped-quote SWAR deserialization regressions around block boundaries
|
|
56
|
+
|
|
57
|
+
## 2026-02-18 - 1.2.6
|
|
58
|
+
|
|
59
|
+
- fix: support arbitrary nested arrays and objects [#176](https://github.com/JairusSW/json-as/pull/176)
|
|
60
|
+
- chore: add contributor from [#176](https://github.com/JairusSW/json-as/pull/176)
|
|
61
|
+
- tests: significantly expand coverage across every file in `assembly/__tests__`
|
|
62
|
+
- tests: add additional primitive, array, nested payload, and escaped string regression cases to all specs
|
|
63
|
+
- tests: add more file-specific deserialize/serialize scenarios for custom, struct, map, resolving, and related schema behaviors
|
|
64
|
+
|
|
65
|
+
## 2026-02-17 - 1.2.5
|
|
66
|
+
|
|
67
|
+
- fix: stabilize ESLint for this repo by excluding AssemblyScript sources from standard TypeScript lint parsing
|
|
68
|
+
- fix: allow underscore-prefixed intentionally-unused TypeScript variables in transformer sources
|
|
69
|
+
- fix: add d8 globals for benchmark runner linting and make `bench/lib/bench.js` parseable by ESLint
|
|
70
|
+
|
|
71
|
+
## 2026-01-23 - 1.2.4
|
|
72
|
+
|
|
73
|
+
- fix: `Set<T>` and `StaticArray<T>` members in classes were not deserializing correctly
|
|
74
|
+
- fix: Fully reset state of transformer between builds
|
|
75
|
+
|
|
76
|
+
## 2026-01-03 - 1.2.3
|
|
77
|
+
|
|
78
|
+
- feat: handle surrogates and code units during string serialization and deserialization
|
|
79
|
+
- perf: add SWAR and SIMD string deserialization implementations
|
|
80
|
+
|
|
81
|
+
## 2025-12-23 - 1.2.2
|
|
82
|
+
|
|
83
|
+
- chore: reduce package size to sub 70kb
|
|
84
|
+
|
|
85
|
+
## 2025-12-23 - 1.2.1
|
|
86
|
+
|
|
87
|
+
- chore: fix chart link in readme
|
|
88
|
+
|
|
89
|
+
## 2025-12-23 - 1.2.0
|
|
90
|
+
|
|
91
|
+
- feat: Implement SWAR based algorithms, SIMD improvements, and better documentation.
|
|
92
|
+
|
|
93
|
+
## 2025-12-21 - 1.1.26
|
|
94
|
+
|
|
95
|
+
- chore: remove log
|
|
96
|
+
|
|
97
|
+
## 2025-12-21 - 1.1.25
|
|
98
|
+
|
|
99
|
+
- feat: Implement SWAR-based string serialization
|
|
100
|
+
|
|
101
|
+
## 2025-11-28 - 1.1.24
|
|
102
|
+
|
|
103
|
+
- feat: Implement a moving average window to determine buffer size (essentially, allow the buffer size to shrink) [#163](https://github.com/JairusSW/json-as/pull/163)
|
|
104
|
+
|
|
105
|
+
## 2025-11-06 - 1.1.23
|
|
106
|
+
|
|
107
|
+
- fix: Map keys should follow proper typing and quote rules [#161](https://github.com/JairusSW/json-as/issues/161)
|
|
108
|
+
|
|
109
|
+
## 2025-09-01 - 1.1.22
|
|
110
|
+
|
|
111
|
+
- fix: Type aliases should work across files [#154](https://github.com/JairusSW/json-as/issues/154)
|
|
112
|
+
|
|
113
|
+
## 2025-08-14 - 1.1.21
|
|
114
|
+
|
|
115
|
+
- fix: JSON.parse on classes with enums [#155](https://github.com/JairusSW/json-as/issues/155)
|
|
116
|
+
- fix: Resolve memory OOB issue within `serializeFloat` function [#153](https://github.com/JairusSW/json-as/issues/153)
|
|
117
|
+
|
|
118
|
+
## 2025-07-14 - 1.1.20
|
|
119
|
+
|
|
120
|
+
- feat: enable SIMD string serialization
|
|
121
|
+
|
|
122
|
+
## 2025-06-30 - 1.1.19
|
|
123
|
+
|
|
124
|
+
- fix: wrong path used in `readFileSync` when importing from a library
|
|
125
|
+
|
|
126
|
+
## 2025-06-30 - 1.1.18
|
|
127
|
+
|
|
128
|
+
- fix: [#150](https://github.com/JairusSW/json-as/issues/150)
|
|
129
|
+
|
|
130
|
+
## 2025-06-17 - 1.1.17
|
|
131
|
+
|
|
132
|
+
- fix: add support for classes within namespaces [#147](https://github.com/JairusSW/json-as/pull/147)
|
|
133
|
+
|
|
134
|
+
## 2025-06-12 - 1.1.16
|
|
135
|
+
|
|
136
|
+
- tests: properly support nulls (in testing lib)
|
|
137
|
+
- fix: initialize generic properties correctly
|
|
138
|
+
- fix: make generated imports compatible with windows
|
|
139
|
+
- feat: add support for fields marked with `readonly`
|
|
140
|
+
|
|
141
|
+
## 2025-06-09 - 1.1.15
|
|
142
|
+
|
|
143
|
+
- feat: add `.as<T>()` method to `JSON.Value`
|
|
144
|
+
- chore: remove all references to `__SERIALIZE_CUSTOM`
|
|
145
|
+
- feat: add support for `StaticArray` serialization
|
|
146
|
+
- feat: support `JSON.Raw` in array types
|
|
147
|
+
- tests: add tests for `JSON.Raw[]`
|
|
148
|
+
|
|
149
|
+
## 2025-05-29 - 1.1.14
|
|
150
|
+
|
|
151
|
+
- fix: hotfix schema resolver
|
|
152
|
+
|
|
153
|
+
## 2025-05-29 - 1.1.13
|
|
154
|
+
|
|
155
|
+
- fix: small issues with schema linking
|
|
156
|
+
- tests: add tests for schema linking and discovery
|
|
157
|
+
|
|
158
|
+
## 2025-05-29 - 1.1.12
|
|
159
|
+
|
|
160
|
+
- fix: add helpful warning on unknown or unaccessible types in fields
|
|
161
|
+
- feat: support deserialization of class generics
|
|
162
|
+
- fix: add support for numerical generics
|
|
163
|
+
- tests: add proper testing for generics
|
|
164
|
+
- feat: support type aliases with a custom type resolver/linker
|
|
165
|
+
- chore: add other linkers to tsconfig and clean up
|
|
166
|
+
- feat: add type alias resolving
|
|
167
|
+
|
|
168
|
+
## 2025-05-28 - 1.1.11
|
|
169
|
+
|
|
170
|
+
- fix: class resolving should only search top level statements for class declarations
|
|
171
|
+
- fix: add helpful error if class is missing an @json decorator
|
|
172
|
+
- fix: properly calculate relative path when json-as is a library
|
|
173
|
+
- fix: add proper null check when resolving imported classes
|
|
174
|
+
|
|
175
|
+
## 2025-05-28 - 1.1.10
|
|
176
|
+
|
|
177
|
+
- feat: add more debug levels (1 = print transform code, 2 = print keys/values at runtime)
|
|
178
|
+
- feat: add write out feature (`JSON_WRITE=path-to-file.ts`) which writes out generated code
|
|
179
|
+
- fix: complete full parity between port and original version for correct deserialization of all types
|
|
180
|
+
- feat: add proper schema resolution and dependency resolution
|
|
181
|
+
- feat: add proper type resolution to schema fields
|
|
182
|
+
- fix: properly calculate the relative path between imports to modules
|
|
183
|
+
|
|
184
|
+
## 2025-05-27 - 1.1.9
|
|
185
|
+
|
|
186
|
+
- change: strict mode is disabled by default. Enable it with JSON_STRICT=true
|
|
187
|
+
- fix: should ignore properties of same length and type if no matching key exists
|
|
188
|
+
- fix: should ignore properties of different type if no matching key exists
|
|
189
|
+
- fix: should ignore complex properties if no matching key exists
|
|
190
|
+
|
|
191
|
+
## 2025-05-27 - 1.1.8
|
|
192
|
+
|
|
193
|
+
- feat: add support for calling `JSON.stringify/JSON.parse` methods inside of custom serializers, but not yet deserializers
|
|
194
|
+
|
|
195
|
+
## 2025-05-27 - 1.1.7
|
|
196
|
+
|
|
197
|
+
- fix: bad boolean logic to decide whether to add 2nd break statement
|
|
198
|
+
|
|
199
|
+
## 2025-05-23 - 1.1.6
|
|
200
|
+
|
|
201
|
+
- fix: null and boolean fields would miscalculate offsets when deserializing
|
|
202
|
+
|
|
203
|
+
## 2025-05-23 - 1.1.5
|
|
204
|
+
|
|
205
|
+
- fix: index.js didn't point to correct file, thus creating a compiler crash
|
|
206
|
+
|
|
207
|
+
## 2025-05-23 - 1.1.4
|
|
208
|
+
|
|
209
|
+
- revert: grouping properties in favor of memory.compare
|
|
210
|
+
|
|
211
|
+
## 2025-05-23 - 1.1.3
|
|
212
|
+
|
|
213
|
+
- feat: group properties of structs before code generation
|
|
214
|
+
- fix: break out of switch case after completion
|
|
215
|
+
- ci: make compatible with act for local testing
|
|
216
|
+
|
|
217
|
+
## 2025-05-22 - 1.1.2
|
|
218
|
+
|
|
219
|
+
- fix: correct small typos in string value deserialization port
|
|
220
|
+
|
|
221
|
+
## 2025-05-22 - 1.1.1
|
|
222
|
+
|
|
223
|
+
- fix: remove random logs
|
|
224
|
+
|
|
225
|
+
## 2025-05-22 - 1.1.0
|
|
226
|
+
|
|
227
|
+
- fix: change _DESERIALIZE<T> to _JSON_T to avoid populating local scope
|
|
228
|
+
|
|
229
|
+
## 2025-05-22 - 1.0.9
|
|
230
|
+
|
|
231
|
+
- fix: [#132](https://github.com/JairusSW/json-as/issues/132)
|
|
232
|
+
- feat: allow base classes to use their child classes if the signatures match
|
|
233
|
+
- perf: rewrite struct deserialization to be significantly faster
|
|
234
|
+
- fix: [#131](https://github.com/JairusSW/json-as/issues/131) Generic classes with custom deserializer crashing
|
|
235
|
+
- fix: [#66](https://github.com/JairusSW/json-as/issues/66) Throw error when additional keys are in JSON
|
|
236
|
+
|
|
237
|
+
## 2025-05-21 - 1.0.8
|
|
238
|
+
|
|
239
|
+
- fix: inline warnings on layer-2 serialize and deserialize functions
|
|
240
|
+
- feat: fully support `JSON.Obj` and `JSON.Box` everywhere
|
|
241
|
+
- fix: temp disable SIMD
|
|
242
|
+
- feat: write fair benchmarks with `v8` using `jsvu`
|
|
243
|
+
|
|
244
|
+
## 2025-05-14 - 1.0.7
|
|
245
|
+
|
|
246
|
+
- merge: pull request [#128](https://github.com/JairusSW/json-as/pull/128) from [loredanacirstea/nested-custom-serializer-fix](https://github.com/loredanacirstea/nested-custom-serializer-fix)
|
|
247
|
+
|
|
248
|
+
## 2025-05-12 - 1.0.6
|
|
249
|
+
|
|
250
|
+
- fix: support zero-param serialization and make sure types are consistent
|
|
251
|
+
- fix: [#124](https://github.com/JairusSW/json-as/issues/124)
|
|
252
|
+
|
|
253
|
+
## 2025-05-11 - 1.0.5
|
|
254
|
+
|
|
255
|
+
- feat: add sanity checks for badly formatted strings
|
|
256
|
+
- fix: [#120](https://github.com/JairusSW/json-as/issues/120) handle empty `JSON.Obj` serialization
|
|
257
|
+
- feat: add SIMD optimization if SIMD is enabled by user
|
|
258
|
+
- fix: handle structs with nullable array as property [#123](https://github.com/JairusSW/json-as/pull/123)
|
|
259
|
+
- fix: struct serialization from writing to incorrect parts of memory when parsing nested structs [#125](https://github.com/JairusSW/json-as/pull/125)
|
|
260
|
+
- chore: add two new contributors
|
|
261
|
+
|
|
262
|
+
## 2025-04-07 - 1.0.4
|
|
263
|
+
|
|
264
|
+
- fix: paths must be resolved as POSIX in order to be valid TypeScript imports [#116](https://github.com/JairusSW/json-as/issues/116)
|
|
265
|
+
|
|
266
|
+
## 2025-03-24 - 1.0.3
|
|
267
|
+
|
|
268
|
+
- fix: make transform windows-compatible [#119](https://github.com/JairusSW/json-as/issues/119?reload=1)
|
|
269
|
+
|
|
270
|
+
## 2025-03-19 - 1.0.2
|
|
271
|
+
|
|
272
|
+
- fix: include check for nullable types for properties when deserialization is called internally [#118](https://github.com/JairusSW/json-as/pull/118)
|
|
273
|
+
|
|
274
|
+
## 2025-03-10 - 1.0.1
|
|
275
|
+
|
|
276
|
+
- docs: add comprehensive performance metrics
|
|
277
|
+
|
|
278
|
+
## 2025-03-09 - 1.0.0
|
|
279
|
+
|
|
280
|
+
- fix: relative paths pointing through node_modules would create a second Source
|
|
281
|
+
- feat: move behavior of `--lib` into transform itself
|
|
282
|
+
- fix: object with an object as a value containing a rhs bracket or brace would exit early [3b33e94](https://github.com/JairusSW/json-as/commit/3b33e9414dc04779d22d65272863372fcd7af4a6)
|
|
283
|
+
|
|
284
|
+
## 2025-03-04 - 1.0.0-beta.17
|
|
285
|
+
|
|
286
|
+
- fix: forgot to build transform
|
|
287
|
+
|
|
288
|
+
## 2025-03-04 - 1.0.0-beta.16
|
|
289
|
+
|
|
290
|
+
- fix: isPrimitive should only trigger on actual primitives
|
|
291
|
+
|
|
292
|
+
## 2025-03-04 - 1.0.0-beta.15
|
|
293
|
+
|
|
294
|
+
- fix: deserialize custom should take in string
|
|
295
|
+
|
|
296
|
+
## 2025-03-04 - 1.0.0-beta.14
|
|
297
|
+
|
|
298
|
+
- fix: reference to nonexistent variable during custom deserialization layer 2
|
|
299
|
+
|
|
300
|
+
## 2025-03-04 - 1.0.0-beta.13
|
|
301
|
+
|
|
302
|
+
- fix: forgot to actually build the transform
|
|
303
|
+
|
|
304
|
+
## 2025-03-04 - 1.0.0-beta.12
|
|
305
|
+
|
|
306
|
+
- fix: build transform
|
|
307
|
+
|
|
308
|
+
## 2025-03-04 - 1.0.0-beta.11
|
|
309
|
+
|
|
310
|
+
- fix: wrongly assumed pointer types within arbitrary deserialization
|
|
311
|
+
- fix: wrong pointer type being passed during map deserialization
|
|
312
|
+
|
|
313
|
+
## 2025-03-04 - 1.0.0-beta.10
|
|
314
|
+
|
|
315
|
+
- fix: transform not generating the right load operations for keys
|
|
316
|
+
- fix: whitespace not working in objects or struct deserialization
|
|
317
|
+
- fix: JSON.Raw not working when deserializing as Map<string, JSON.Raw>
|
|
318
|
+
|
|
319
|
+
## 2025-03-03 - 1.0.0-beta.9
|
|
320
|
+
|
|
321
|
+
- rename: change libs folder to lib
|
|
322
|
+
|
|
323
|
+
## 2025-03-03 - 1.0.0-beta.8
|
|
324
|
+
|
|
325
|
+
- docs: add instructions for using `--lib` in README
|
|
326
|
+
|
|
327
|
+
## 2025-03-03 - 1.0.0-beta.7
|
|
328
|
+
|
|
329
|
+
- fix: add as-bs to `--lib` section
|
|
330
|
+
- chore: clean up transform
|
|
331
|
+
- refactor: transform should import `~lib/as-bs.ts` instead of relative path
|
|
332
|
+
|
|
333
|
+
## 2025-03-01 - 1.0.0-beta.6
|
|
334
|
+
|
|
335
|
+
- fix: import from base directory index.ts
|
|
336
|
+
|
|
337
|
+
## 2025-03-01 - 1.0.0-beta.5
|
|
338
|
+
|
|
339
|
+
- fix: revert pull request [#112](https://github.com/JairusSW/json-as/pull/112)
|
|
340
|
+
|
|
341
|
+
## 2025-02-25 - 1.0.0-beta.4
|
|
342
|
+
|
|
343
|
+
- fix: warn on presence of invalid types contained in a schema [#112](https://github.com/JairusSW/json-as/pull/112)
|
|
344
|
+
|
|
345
|
+
## 2025-02-25 - 1.0.0-beta.3
|
|
346
|
+
|
|
347
|
+
- feat: change `JSON.Raw` to actual class to facilitate proper support without transformations
|
|
348
|
+
- fix: remove old `JSON.Raw` logic from transform code
|
|
349
|
+
|
|
350
|
+
## 2025-02-25 - 1.0.0-beta.2
|
|
351
|
+
|
|
352
|
+
- feat: add support for custom serializers and deserializers [#110](https://github.com/JairusSW/json-as/pull/110)
|
|
353
|
+
|
|
354
|
+
## 2025-02-22 - 1.0.0-beta.1
|
|
355
|
+
|
|
356
|
+
- perf: add benchmarks for both AssemblyScript and JavaScript
|
|
357
|
+
- docs: publish preliminary benchmark results
|
|
358
|
+
- tests: ensure nested serialization works and add to tests
|
|
359
|
+
- feat: finish arbitrary type implementation
|
|
360
|
+
- feat: introduce `JSON.Obj` to handle objects effectively
|
|
361
|
+
- feat: reimplement arbitrary array deserialization
|
|
362
|
+
- fix: remove brace check on array deserialization
|
|
363
|
+
- feat: introduce native support for `JSON.Obj` transformations
|
|
364
|
+
- feat: implement arbitrary object serialization
|
|
365
|
+
- fix: deserialization of booleans panics on `false`
|
|
366
|
+
- fix: `bs.resize` should be type-safe
|
|
367
|
+
- impl: add `JSON.Obj` type as prototype to handle arbitrary object structures
|
|
368
|
+
- chore: rename static objects (schemas) to structs and name arbitrary objects as `obj`
|
|
369
|
+
- tests: add proper tests for arbitrary types
|
|
370
|
+
- fix: empty method generation using outdated function signature
|
|
371
|
+
- docs: update readme to be more concise
|
|
372
|
+
|
|
373
|
+
## 2025-02-13 - 1.0.0-alpha.4
|
|
374
|
+
|
|
375
|
+
- feat: reintroduce support for `Box<T>`-wrapped primitive types
|
|
376
|
+
- tests: add extensive tests to all supported types
|
|
377
|
+
- fix: 6-byte keys being recognized on deserialize
|
|
378
|
+
- perf: take advantage of aligned memory to use a single 64-bit load on 6-byte keys
|
|
379
|
+
- fix: `bs.proposeSize()` should increment `stackSize` by `size` instead of setting it
|
|
380
|
+
- fix: allow runtime to manage `bs.buffer`
|
|
381
|
+
- fix: memory leaks in `bs` module
|
|
382
|
+
- fix: add (possibly temporary) `JSON.Memory.shrink()` to shrink memory in `bs`
|
|
383
|
+
- perf: prefer growing memory by `nextPowerOf2(size + 64)` for less reallocations
|
|
384
|
+
- tests: add boolean tests to `Box<T>`
|
|
385
|
+
- fix: serialization of non-growable data types should grow `bs.stackSize`
|
|
386
|
+
|
|
387
|
+
## 2025-01-31 - 1.0.0-alpha.3
|
|
388
|
+
|
|
389
|
+
- fix: write to proper offset when deserializing string with \u0000-type escapes
|
|
390
|
+
- fix: simplify and fix memory offset issues with bs module
|
|
391
|
+
- fix: properly predict minimum size of to-be-serialized schemas
|
|
392
|
+
- fix: replace as-test with temporary framework to mitigate json-as versioning issues
|
|
393
|
+
- fix: fix multiple memory leaks during serialization
|
|
394
|
+
- feat: align memory allocations for better performance
|
|
395
|
+
- feat: achieve a space complexity of O(n) for serialization operations, unless dealing with \u0000-type escapes
|
|
396
|
+
|
|
397
|
+
## 2025-01-20 - 1.0.0-alpha.2
|
|
398
|
+
|
|
399
|
+
- fix: disable SIMD in generated transform code by default
|
|
400
|
+
- fix: re-add as-bs dependency so that it will not break in non-local environments
|
|
401
|
+
- fix: remove AS201 'conversion from type usize to i32' warning
|
|
402
|
+
- fix: add as-bs to peer dependencies so only one version is installed
|
|
403
|
+
- fix: point as-bs imports to submodule
|
|
404
|
+
- fix: remove submodule in favor of static module
|
|
405
|
+
- fix: bs.ensureSize would not grow and thus cause memory faults
|
|
406
|
+
- fix: bs.ensureSize triggering unintentionally
|
|
407
|
+
|
|
408
|
+
## 2025-01-20 - 1.0.0-alpha.1
|
|
409
|
+
|
|
410
|
+
- feat: finish implementation of arbitrary data serialization and deserialization using JSON.Value
|
|
411
|
+
- feat: reinstate usage of `JSON.Box<T>()` to support nullable primitive types
|
|
412
|
+
- feat: eliminate the need to import the `JSON` namespace when defining a schema
|
|
413
|
+
- feat: reduce memory usage so that it is viable for low-memory environments
|
|
414
|
+
- feat: write to a central buffer and reduce memory overhead
|
|
415
|
+
- feat: rewrite the transform to properly resolve schemas and link them together
|
|
416
|
+
- feat: pre-allocate and compute the minimum size of a schema to avoid memory out of range errors
|
|
417
|
+
>>>>>>> cf237fa (chore: release 1.3.0)
|
package/README.md
CHANGED
|
@@ -14,6 +14,7 @@
|
|
|
14
14
|
- [Using Raw JSON Strings](#using-raw-json-strings)
|
|
15
15
|
- [Working with Enums](#working-with-enums)
|
|
16
16
|
- [Using Custom Serializers or Deserializers](#using-custom-serializers-or-deserializers)
|
|
17
|
+
- [Overriding built-in Container Types](#overriding-built-in-container-types)
|
|
17
18
|
- [Performance](#performance)
|
|
18
19
|
- [Comparison to JavaScript](#comparison-to-javascript)
|
|
19
20
|
- [Performance Tuning](#performance-tuning)
|
|
@@ -334,11 +335,11 @@ const serialized = JSON.stringify<Foo>(Foo.bar);
|
|
|
334
335
|
|
|
335
336
|
This library supports custom serialization and deserialization methods, which can be defined using the `@serializer` and `@deserializer` decorators.
|
|
336
337
|
|
|
337
|
-
|
|
338
|
+
Custom serializers and deserializers must always speak valid JSON. You can optionally provide the JSON value shape they operate on using one of: `"any"`, `"string"`, `"number"`, `"object"`, `"array"`, `"boolean"`, or `"null"`. If omitted, the shape defaults to `"any"`.
|
|
338
339
|
|
|
339
|
-
|
|
340
|
-
import { bytes } from "json-as/assembly/util";
|
|
340
|
+
Here's an example of creating a custom data type called `Point` which serializes to a JSON string:
|
|
341
341
|
|
|
342
|
+
```typescript
|
|
342
343
|
@json
|
|
343
344
|
class Point {
|
|
344
345
|
x: f64 = 0.0;
|
|
@@ -348,21 +349,21 @@ class Point {
|
|
|
348
349
|
this.y = y;
|
|
349
350
|
}
|
|
350
351
|
|
|
351
|
-
@serializer
|
|
352
|
+
@serializer("string")
|
|
352
353
|
serializer(self: Point): string {
|
|
353
|
-
return
|
|
354
|
+
return JSON.stringify(`${self.x},${self.y}`);
|
|
354
355
|
}
|
|
355
356
|
|
|
356
|
-
@deserializer
|
|
357
|
+
@deserializer("string")
|
|
357
358
|
deserializer(data: string): Point {
|
|
358
|
-
const
|
|
359
|
-
if (
|
|
359
|
+
const raw = JSON.parse<string>(data);
|
|
360
|
+
if (!raw.length) throw new Error("Could not deserialize provided data as type Point");
|
|
360
361
|
|
|
361
|
-
const c =
|
|
362
|
-
const x =
|
|
363
|
-
const y =
|
|
362
|
+
const c = raw.indexOf(",");
|
|
363
|
+
const x = raw.slice(0, c);
|
|
364
|
+
const y = raw.slice(c + 1);
|
|
364
365
|
|
|
365
|
-
return new Point(f64.parse(x), f64.parse(y));
|
|
366
|
+
return new Point(f64.parse(x), f64.parse(y)); // NEVER use this in deserializers. Always return a new instance
|
|
366
367
|
}
|
|
367
368
|
}
|
|
368
369
|
|
|
@@ -375,9 +376,11 @@ console.log("Serialized " + serialized);
|
|
|
375
376
|
console.log("Deserialized " + JSON.stringify(deserialized));
|
|
376
377
|
```
|
|
377
378
|
|
|
378
|
-
The serializer function converts a `Point` instance into a string
|
|
379
|
+
The serializer function converts a `Point` instance into a valid JSON string value.
|
|
379
380
|
|
|
380
|
-
The deserializer function parses
|
|
381
|
+
The deserializer function parses that JSON string back into a `Point` instance.
|
|
382
|
+
|
|
383
|
+
Custom deserializers should always instantiate and return a new object. They should not assume an existing destination instance will be passed in or reused.
|
|
381
384
|
|
|
382
385
|
These functions are then wrapped before being consumed by the json-as library:
|
|
383
386
|
|
|
@@ -396,6 +399,85 @@ These functions are then wrapped before being consumed by the json-as library:
|
|
|
396
399
|
|
|
397
400
|
This allows custom serialization while maintaining a generic interface for the library to access.
|
|
398
401
|
|
|
402
|
+
### Overriding built-in container types
|
|
403
|
+
|
|
404
|
+
Undecorated subclasses of built-in container types keep the built-in JSON behavior.
|
|
405
|
+
|
|
406
|
+
This rule applies consistently across:
|
|
407
|
+
|
|
408
|
+
- `JSON.stringify(...)`
|
|
409
|
+
- `JSON.parse<T>(...)`
|
|
410
|
+
- `JSON.Value.from(...)`
|
|
411
|
+
- `JSON.internal.stringify(...)`
|
|
412
|
+
- `JSON.internal.parse(...)`
|
|
413
|
+
|
|
414
|
+
For example:
|
|
415
|
+
|
|
416
|
+
- `class MyBytes extends Uint8Array {}` still serializes like a normal `Uint8Array`
|
|
417
|
+
- `class MyMap extends Map<string, i32> {}` still serializes like a normal `Map<string, i32>`
|
|
418
|
+
- the same applies to subclassable built-ins such as `Array`, `Set`, and typed arrays
|
|
419
|
+
|
|
420
|
+
If you decorate that subclass with `@json`, it is treated as a normal generated class instead of inheriting the built-in container behavior. That means generated `__SERIALIZE` / `__DESERIALIZE` logic and custom serializer/deserializer hooks can take over.
|
|
421
|
+
|
|
422
|
+
If you want a different wire format, decorate the subclass with `@json` and provide custom `@serializer(...)` / `@deserializer(...)` methods:
|
|
423
|
+
|
|
424
|
+
```typescript
|
|
425
|
+
function hexDigit(value: u8): string {
|
|
426
|
+
return String.fromCharCode(value < 10 ? 48 + value : 87 + value);
|
|
427
|
+
}
|
|
428
|
+
|
|
429
|
+
function parseHexNibble(code: u16): u8 {
|
|
430
|
+
if (code >= 48 && code <= 57) return <u8>(code - 48);
|
|
431
|
+
if (code >= 97 && code <= 102) return <u8>(code - 87);
|
|
432
|
+
return <u8>(code - 55);
|
|
433
|
+
}
|
|
434
|
+
|
|
435
|
+
@json
|
|
436
|
+
class HexBytes extends Uint8Array {
|
|
437
|
+
constructor(length: i32 = 0) {
|
|
438
|
+
super(length);
|
|
439
|
+
}
|
|
440
|
+
|
|
441
|
+
@serializer("string")
|
|
442
|
+
serializer(self: HexBytes): string {
|
|
443
|
+
let out = "";
|
|
444
|
+
for (let i = 0; i < self.length; i++) {
|
|
445
|
+
const value = unchecked(self[i]);
|
|
446
|
+
out += hexDigit(value >> 4);
|
|
447
|
+
out += hexDigit(value & 0x0f);
|
|
448
|
+
}
|
|
449
|
+
return JSON.stringify(out);
|
|
450
|
+
}
|
|
451
|
+
|
|
452
|
+
@deserializer("string")
|
|
453
|
+
deserializer(data: string): HexBytes {
|
|
454
|
+
const raw = JSON.parse<string>(data);
|
|
455
|
+
const out = new HexBytes(raw.length >> 1);
|
|
456
|
+
|
|
457
|
+
for (let i = 0, j = 0; i < raw.length; i += 2, j++) {
|
|
458
|
+
const hi = parseHexNibble(<u16>raw.charCodeAt(i));
|
|
459
|
+
const lo = parseHexNibble(<u16>raw.charCodeAt(i + 1));
|
|
460
|
+
unchecked((out[j] = <u8>((hi << 4) | lo)));
|
|
461
|
+
}
|
|
462
|
+
|
|
463
|
+
return out;
|
|
464
|
+
}
|
|
465
|
+
}
|
|
466
|
+
|
|
467
|
+
const bytes = new HexBytes(4);
|
|
468
|
+
bytes[0] = 10;
|
|
469
|
+
bytes[1] = 20;
|
|
470
|
+
bytes[2] = 30;
|
|
471
|
+
bytes[3] = 40;
|
|
472
|
+
|
|
473
|
+
JSON.stringify(bytes); // "\"0a141e28\""
|
|
474
|
+
JSON.parse<HexBytes>("\"0a141e28\"");
|
|
475
|
+
```
|
|
476
|
+
|
|
477
|
+
This same pattern works for subclassable built-ins like `Array`, `Map`, `Set`, and typed arrays.
|
|
478
|
+
|
|
479
|
+
`ArrayBuffer` and `String` are `@final` in AssemblyScript, so they cannot be subclassed there.
|
|
480
|
+
|
|
399
481
|
## Performance
|
|
400
482
|
|
|
401
483
|
The `json-as` library is engineered for **multi-GB/s processing speeds**, leveraging SIMD and SWAR optimizations along with highly efficient transformations. The charts below highlight key performance metrics such as build time, operations-per-second, and throughput.
|
|
@@ -1 +1,15 @@
|
|
|
1
|
+
import { bytes } from "../../util";
|
|
1
2
|
export { deserializeArrayBuffer, deserializeTypedArray } from "../simple/typedarray";
|
|
3
|
+
import { deserializeArrayBuffer, deserializeTypedArray } from "../simple/typedarray";
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
@inline export function parseArrayBuffer(data: string): ArrayBuffer {
|
|
7
|
+
const dataSize = bytes(data);
|
|
8
|
+
const dataPtr = changetype<usize>(data);
|
|
9
|
+
return deserializeArrayBuffer(dataPtr, dataPtr + dataSize, 0);
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
@inline export function __deserializeArrayBuffer(srcStart: usize, srcEnd: usize, dst: usize = 0): ArrayBuffer {
|
|
14
|
+
return deserializeArrayBuffer(srcStart, srcEnd, dst);
|
|
15
|
+
}
|
|
@@ -99,10 +99,10 @@ import { deserializeStringField_SWAR } from "../swar/string";
|
|
|
99
99
|
const prefixLen = <u32>(escapeStart - payloadStart);
|
|
100
100
|
let srcStart = escapeStart;
|
|
101
101
|
const srcEnd16 = srcEnd - 16;
|
|
102
|
+
const outStart = bs.offset - bs.buffer;
|
|
102
103
|
bs.ensureSize(u32(srcEnd - srcStart));
|
|
103
|
-
bs.offset = bs.buffer;
|
|
104
104
|
if (prefixLen != 0) {
|
|
105
|
-
memory.copy(bs.
|
|
105
|
+
memory.copy(bs.offset, payloadStart, prefixLen);
|
|
106
106
|
bs.offset += prefixLen;
|
|
107
107
|
}
|
|
108
108
|
|
|
@@ -195,7 +195,7 @@ import { deserializeStringField_SWAR } from "../swar/string";
|
|
|
195
195
|
bs.offset += 2;
|
|
196
196
|
}
|
|
197
197
|
|
|
198
|
-
return bs.
|
|
198
|
+
return bs.sliceOut<string>(outStart);
|
|
199
199
|
}
|
|
200
200
|
|
|
201
201
|
export function deserializeString_SIMD(srcStart: usize, srcEnd: usize): string {
|