json-as 1.2.6 → 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.
Files changed (135) hide show
  1. package/CHANGELOG.md +417 -0
  2. package/README.md +135 -36
  3. package/assembly/custom/util.ts +24 -70
  4. package/assembly/deserialize/float.ts +181 -0
  5. package/assembly/deserialize/helpers/uint.ts +12 -0
  6. package/assembly/deserialize/index/arbitrary.ts +25 -0
  7. package/assembly/deserialize/index/array.ts +61 -0
  8. package/assembly/deserialize/index/bool.ts +1 -0
  9. package/assembly/deserialize/index/date.ts +1 -0
  10. package/assembly/deserialize/index/float.ts +1 -0
  11. package/assembly/deserialize/index/integer.ts +1 -0
  12. package/assembly/deserialize/index/map.ts +1 -0
  13. package/assembly/deserialize/index/object.ts +1 -0
  14. package/assembly/deserialize/index/raw.ts +1 -0
  15. package/assembly/deserialize/index/set.ts +1 -0
  16. package/assembly/deserialize/index/staticarray.ts +1 -0
  17. package/assembly/deserialize/index/string.ts +15 -0
  18. package/assembly/deserialize/index/struct.ts +1 -0
  19. package/assembly/deserialize/index/typedarray.ts +15 -0
  20. package/assembly/deserialize/index/unsigned.ts +1 -0
  21. package/assembly/deserialize/index.ts +14 -0
  22. package/assembly/deserialize/integer.ts +42 -0
  23. package/assembly/deserialize/simd/array/integer.ts +307 -0
  24. package/assembly/deserialize/simd/string.ts +130 -11
  25. package/assembly/deserialize/simple/arbitrary.ts +5 -12
  26. package/assembly/deserialize/simple/array/arbitrary.ts +12 -36
  27. package/assembly/deserialize/simple/array/array.ts +2 -8
  28. package/assembly/deserialize/simple/array/bool.ts +2 -8
  29. package/assembly/deserialize/simple/array/box.ts +2 -8
  30. package/assembly/deserialize/simple/array/float.ts +2 -8
  31. package/assembly/deserialize/simple/array/integer.ts +2 -8
  32. package/assembly/deserialize/simple/array/map.ts +6 -26
  33. package/assembly/deserialize/simple/array/object.ts +6 -26
  34. package/assembly/deserialize/simple/array/raw.ts +18 -61
  35. package/assembly/deserialize/simple/array/string.ts +5 -10
  36. package/assembly/deserialize/simple/array/struct.ts +6 -26
  37. package/assembly/deserialize/simple/array.ts +2 -5
  38. package/assembly/deserialize/simple/bool.ts +2 -6
  39. package/assembly/deserialize/simple/map.ts +29 -102
  40. package/assembly/deserialize/simple/object.ts +24 -81
  41. package/assembly/deserialize/simple/raw.ts +1 -4
  42. package/assembly/deserialize/simple/set.ts +11 -37
  43. package/assembly/deserialize/simple/staticarray/array.ts +1 -1
  44. package/assembly/deserialize/simple/staticarray/bool.ts +1 -1
  45. package/assembly/deserialize/simple/staticarray/float.ts +1 -1
  46. package/assembly/deserialize/simple/staticarray/integer.ts +1 -1
  47. package/assembly/deserialize/simple/staticarray/string.ts +7 -14
  48. package/assembly/deserialize/simple/staticarray/struct.ts +1 -1
  49. package/assembly/deserialize/simple/staticarray.ts +57 -21
  50. package/assembly/deserialize/simple/string.ts +90 -10
  51. package/assembly/deserialize/simple/struct.ts +25 -121
  52. package/assembly/deserialize/simple/typedarray.ts +94 -0
  53. package/assembly/deserialize/swar/array/arbitrary.ts +8 -0
  54. package/assembly/deserialize/swar/array/array.ts +39 -0
  55. package/assembly/deserialize/swar/array/bool.ts +47 -0
  56. package/assembly/deserialize/swar/array/box.ts +8 -0
  57. package/assembly/deserialize/swar/array/float.ts +39 -0
  58. package/assembly/deserialize/swar/array/integer.ts +461 -0
  59. package/assembly/deserialize/swar/array/map.ts +7 -0
  60. package/assembly/deserialize/swar/array/object.ts +44 -0
  61. package/assembly/deserialize/swar/array/raw.ts +8 -0
  62. package/assembly/deserialize/swar/array/shared.ts +96 -0
  63. package/assembly/deserialize/swar/array/string.ts +39 -0
  64. package/assembly/deserialize/swar/array/struct.ts +44 -0
  65. package/assembly/deserialize/swar/array.ts +49 -0
  66. package/assembly/deserialize/swar/string.ts +648 -15
  67. package/assembly/deserialize/unsigned.ts +75 -0
  68. package/assembly/index.d.ts +1 -3
  69. package/assembly/index.ts +316 -374
  70. package/assembly/serialize/index/arbitrary.ts +75 -0
  71. package/assembly/serialize/index/array.ts +1 -0
  72. package/assembly/serialize/index/bool.ts +1 -0
  73. package/assembly/serialize/index/date.ts +1 -0
  74. package/assembly/serialize/index/float.ts +1 -0
  75. package/assembly/serialize/index/integer.ts +1 -0
  76. package/assembly/serialize/index/map.ts +1 -0
  77. package/assembly/serialize/index/object.ts +46 -0
  78. package/assembly/serialize/index/raw.ts +1 -0
  79. package/assembly/serialize/index/set.ts +1 -0
  80. package/assembly/serialize/index/staticarray.ts +1 -0
  81. package/assembly/serialize/index/string.ts +15 -0
  82. package/assembly/serialize/index/struct.ts +1 -0
  83. package/assembly/serialize/index/typedarray.ts +66 -0
  84. package/assembly/serialize/index.ts +13 -0
  85. package/assembly/serialize/simd/string.ts +4 -13
  86. package/assembly/serialize/simple/arbitrary.ts +6 -0
  87. package/assembly/serialize/simple/raw.ts +1 -5
  88. package/assembly/serialize/simple/string.ts +3 -11
  89. package/assembly/serialize/simple/typedarray.ts +63 -0
  90. package/assembly/serialize/swar/string.ts +6 -21
  91. package/assembly/util/concat.ts +1 -5
  92. package/assembly/util/index.ts +1 -0
  93. package/assembly/util/masks.ts +12 -18
  94. package/assembly/util/memory.ts +0 -0
  95. package/assembly/util/snp.ts +1 -4
  96. package/assembly/util/stringScan.ts +24 -0
  97. package/assembly/util/swar.ts +50 -6
  98. package/lib/as-bs.ts +137 -127
  99. package/package.json +26 -5
  100. package/transform/lib/builder.d.ts.map +1 -1
  101. package/transform/lib/builder.js +5 -13
  102. package/transform/lib/builder.js.map +1 -1
  103. package/transform/lib/index.d.ts +1 -0
  104. package/transform/lib/index.d.ts.map +1 -1
  105. package/transform/lib/index.js +672 -757
  106. package/transform/lib/index.js.map +1 -1
  107. package/transform/lib/linkers/alias.d.ts.map +1 -1
  108. package/transform/lib/linkers/alias.js.map +1 -1
  109. package/transform/lib/linkers/custom.d.ts.map +1 -1
  110. package/transform/lib/linkers/custom.js +8 -9
  111. package/transform/lib/linkers/custom.js.map +1 -1
  112. package/transform/lib/linkers/imports.d.ts.map +1 -1
  113. package/transform/lib/linkers/imports.js.map +1 -1
  114. package/transform/lib/types.d.ts +6 -0
  115. package/transform/lib/types.d.ts.map +1 -1
  116. package/transform/lib/types.js +83 -21
  117. package/transform/lib/types.js.map +1 -1
  118. package/transform/lib/util.d.ts.map +1 -1
  119. package/transform/lib/util.js +1 -1
  120. package/transform/lib/util.js.map +1 -1
  121. package/transform/lib/visitor.d.ts.map +1 -1
  122. package/transform/lib/visitor.js +1 -2
  123. package/transform/lib/visitor.js.map +1 -1
  124. package/.prettierrc +0 -3
  125. package/ARCHITECTURE.md +0 -320
  126. package/CONTRIBUTING.md +0 -238
  127. package/TODO +0 -1
  128. package/assembly/deserialize/simple/float.ts +0 -11
  129. package/assembly/deserialize/simple/integer.ts +0 -9
  130. package/assembly/test.ts +0 -30
  131. package/eslint.config.js +0 -60
  132. package/lib/tsconfig.json +0 -8
  133. package/tools/assemblyscript-eslint-local.js +0 -29
  134. package/tools/assemblyscript-eslint.js +0 -29
  135. package/transform/tsconfig.json +0 -35
package/ARCHITECTURE.md DELETED
@@ -1,320 +0,0 @@
1
- # Architecture
2
-
3
- This document describes the architecture of json-as, a high-performance JSON serialization library for AssemblyScript.
4
-
5
- ## Overview
6
-
7
- json-as uses a two-tier architecture:
8
-
9
- 1. **Compile-time Transform**: A TypeScript-based AST transformer that generates optimized serialization/deserialization code
10
- 2. **Runtime Library**: AssemblyScript implementations for JSON processing with multiple optimization levels
11
-
12
- ```
13
- ┌─────────────────────────────────────────────────────────────────┐
14
- │ Compile Time │
15
- │ ┌─────────────┐ ┌──────────────┐ ┌──────────────────┐ │
16
- │ │ Source Code │ -> │ Transform │ -> │ Generated Code │ │
17
- │ │ with @json │ │ (TypeScript) │ │ __SERIALIZE etc │ │
18
- │ └─────────────┘ └──────────────┘ └──────────────────┘ │
19
- └─────────────────────────────────────────────────────────────────┘
20
-
21
- V
22
- ┌─────────────────────────────────────────────────────────────────┐
23
- │ Runtime │
24
- │ ┌──────────────────────────────────────────────────────────┐ │
25
- │ │ JSON Namespace │ │
26
- │ │ ┌─────────────┐ ┌─────────────┐ ┌─────────────────┐ │ │
27
- │ │ │ stringify │ │ parse │ │ Dynamic Types │ │ │
28
- │ │ └──────┬──────┘ └──────┬──────┘ │ Value, Obj, │ │ │
29
- │ │ │ │ │ Box, Raw │ │ │
30
- │ │ V V └─────────────────┘ │ │
31
- │ │ ┌───────────────────────────────────────────────────┐ │ │
32
- │ │ │ Optimization Modes │ │ │
33
- │ │ │ ┌───────┐ ┌────────┐ ┌────────┐ │ │ │
34
- │ │ │ │ NAIVE │ │ SWAR │ │ SIMD │ │ │ │
35
- │ │ │ └───────┘ └────────┘ └────────┘ │ │ │
36
- │ │ └───────────────────────────────────────────────────┘ │ │
37
- │ └──────────────────────────────────────────────────────────┘ │
38
- │ │ │
39
- │ V │
40
- │ ┌──────────────────────────────────────────────────────────┐ │
41
- │ │ Memory Allocator (bs namespace) │ │
42
- │ │ - Dynamic buffer management │ │
43
- │ │ - EMA-based adaptive sizing │ │
44
- │ │ - Optional string caching (sc namespace) │ │
45
- │ └──────────────────────────────────────────────────────────┘ │
46
- └─────────────────────────────────────────────────────────────────┘
47
- ```
48
-
49
- ## Transform System
50
-
51
- The transform (`transform/src/`) is an AssemblyScript compiler plugin that runs during compilation.
52
-
53
- ### How It Works
54
-
55
- 1. **Discovery**: Scans source files for classes decorated with `@json` or `@serializable`
56
- 2. **Schema Building**: Creates a schema for each decorated class including:
57
- - Field names and types
58
- - Decorator metadata (@alias, @omit, @omitnull, @omitif)
59
- - Inheritance relationships
60
- - Type dependencies
61
- 3. **Code Generation**: Generates two methods for each class:
62
- - `__SERIALIZE(ptr: usize): void` - Writes JSON to the buffer
63
- - `__DESERIALIZE<T>(srcStart, srcEnd, out): T` - Parses JSON into object
64
-
65
- ### Key Files
66
-
67
- - `transform/src/index.ts` - Main transform entry point (JSONTransform class)
68
- - `transform/src/visitor.ts` - AST visitor for traversing source code
69
- - `transform/src/builder.ts` - AST builder for code generation
70
- - `transform/src/types.ts` - Type definitions (Property, Schema, Src)
71
-
72
- ### Generated Code Example
73
-
74
- For this class:
75
- ```typescript
76
- @json
77
- class Player {
78
- name: string = "";
79
- score: i32 = 0;
80
- }
81
- ```
82
-
83
- The transform generates:
84
- ```typescript
85
- __SERIALIZE(ptr: usize): void {
86
- store<u16>(bs.offset, 123); // {
87
- bs.offset += 2;
88
- // ... "name": serialize string ...
89
- // ... "score": serialize integer ...
90
- store<u16>(bs.offset, 125); // }
91
- bs.offset += 2;
92
- }
93
-
94
- __DESERIALIZE<T>(srcStart: usize, srcEnd: usize, out: T): T {
95
- // Key matching and value parsing logic
96
- // Uses switch statements on key length for efficiency
97
- }
98
- ```
99
-
100
- ## Optimization Modes
101
-
102
- json-as provides three optimization levels, selected via the `JSON_MODE` environment variable:
103
-
104
- ### NAIVE Mode
105
-
106
- The baseline implementation with character-by-character processing.
107
-
108
- - **Best for**: Debugging, compatibility testing
109
- - **Performance**: Slowest but most readable
110
- - **String escaping**: Checks each character individually
111
-
112
- ### SWAR Mode (Default)
113
-
114
- Single Instruction, Multiple Data processing at the word level.
115
-
116
- - **Best for**: General use, good balance of speed and compatibility
117
- - **Performance**: Processes 4 characters at once
118
- - **String escaping**: Uses bit manipulation to detect escape characters in parallel:
119
- ```
120
- // Check if any byte in a 64-bit word needs escaping
121
- const hasEscape = (word ^ 0x2222...) - 0x0101... & 0x8080...
122
- ```
123
-
124
- ### SIMD Mode
125
-
126
- Uses WebAssembly SIMD instructions for 128-bit parallel processing.
127
-
128
- - **Best for**: Maximum performance when SIMD is available
129
- - **Performance**: Processes 8 characters at once
130
- - **Requirement**: `--enable simd` flag during compilation
131
- - **String escaping**: Uses `v128` operations for parallel character checking
132
-
133
- ## Buffer System
134
-
135
- Located in `lib/as-bs.ts`, the buffer system (`bs` namespace) manages memory for serialization output.
136
-
137
- ### Key Features
138
-
139
- 1. **Dynamic Growth**: Buffer grows as needed during serialization
140
- 2. **Adaptive Sizing**: Uses exponential moving average (EMA) to track typical output sizes
141
- 3. **Automatic Shrinking**: Periodically shrinks if buffer is oversized for typical usage
142
-
143
- ### Memory Layout
144
-
145
- ```
146
- ┌───────────────────────────────────────────┐
147
- │ ArrayBuffer │
148
- │ ┌───────────────────┬─────────────────┐ │
149
- │ │ Written Data │ Free Space │ │
150
- │ └───────────────────┴─────────────────┘ │
151
- │ ^ buffer ^ offset │
152
- └───────────────────────────────────────────┘
153
- ```
154
-
155
- ### Key Functions
156
-
157
- - `proposeSize(size)` - Ensure buffer can hold additional bytes
158
- - `ensureSize(size)` - Grow buffer if necessary
159
- - `out<T>()` - Copy buffer contents to new string, reset for next use
160
- - `resize(size)` - Explicitly resize buffer
161
-
162
- ### String Caching (`sc` namespace)
163
-
164
- Optional feature enabled via `JSON_CACHE=1` for repeated string serialization.
165
-
166
- ```
167
- ┌───────────────────────────────────────────────────────────────┐
168
- │ Cache Structure │
169
- │ ┌─────────────────────────────────────────────────────────┐ │
170
- │ │ Entry Table (4096 slots) │ │
171
- │ │ ┌────────┬────────┬────────┬────────┐ │ │
172
- │ │ │ Entry 0│ Entry 1│ ... │Entry N │ │ │
173
- │ │ │key,ptr,│key,ptr,│ │key,ptr,│ │ │
174
- │ │ │ len │ len │ │ len │ │ │
175
- │ │ └────────┴────────┴────────┴────────┘ │ │
176
- │ └─────────────────────────────────────────────────────────┘ │
177
- │ ┌─────────────────────────────────────────────────────────┐ │
178
- │ │ Arena (1MB circular buffer) │ │
179
- │ │ ┌──────────────────────────────────────────────────┐ │ │
180
- │ │ │ Cached serialized string data... │ │ │
181
- │ │ └──────────────────────────────────────────────────┘ │ │
182
- │ │ ^ │ │
183
- │ │ arenaPtr │ │
184
- │ └─────────────────────────────────────────────────────────┘ │
185
- └───────────────────────────────────────────────────────────────┘
186
- ```
187
-
188
- ## Type System
189
-
190
- ### Static Types
191
-
192
- Regular AssemblyScript types handled directly:
193
- - Primitives: `i8`, `i16`, `i32`, `i64`, `u8`, `u16`, `u32`, `u64`, `f32`, `f64`, `bool`
194
- - Strings: `string`
195
- - Collections: `Array<T>`, `StaticArray<T>`, `Map<K, V>`
196
- - Classes decorated with `@json`
197
-
198
- ### Dynamic Types
199
-
200
- For runtime type flexibility:
201
-
202
- - **`JSON.Value`**: Can hold any JSON type
203
- ```typescript
204
- const v = JSON.Value.from<i32>(42);
205
- v.set<string>("hello"); // Can change type
206
- ```
207
-
208
- - **`JSON.Obj`**: Dynamic object with string keys
209
- ```typescript
210
- const obj = new JSON.Obj();
211
- obj.set("key", 123);
212
- ```
213
-
214
- - **`JSON.Box<T>`**: Nullable wrapper for primitives
215
- ```typescript
216
- let maybeInt: JSON.Box<i32> | null = null;
217
- ```
218
-
219
- - **`JSON.Raw`**: Pre-formatted JSON string (no re-serialization)
220
- ```typescript
221
- map.set("data", new JSON.Raw('{"already":"json"}'));
222
- ```
223
-
224
- ## Serialization Flow
225
-
226
- ```
227
- JSON.stringify<T>(data)
228
-
229
- V
230
- ┌───────────────────┐
231
- │ Type Dispatch │
232
- │ (compile-time) │
233
- └─────────┬─────────┘
234
-
235
- ┌─────┴─────┬─────────────┬──────────────┐
236
- V V V V
237
- ┌───────┐ ┌────────┐ ┌──────────┐ ┌──────────┐
238
- │Boolean│ │Integer │ │ String │ │ Struct │
239
- │ Float │ │ │ │ │ │ (@json) │
240
- └───┬───┘ └────┬───┘ └────┬─────┘ └────┬─────┘
241
- │ │ │ │
242
- │ │ │ │
243
- └───────────┴─────┬──────┴──────────────┘
244
- V
245
- ┌───────────────┐
246
- │ Buffer System │
247
- └───────┬───────┘
248
- V
249
- ┌───────────────┐
250
- │ Heap │
251
- └───────┬───────┘
252
- V
253
- String
254
- ```
255
-
256
- ## Deserialization Flow
257
-
258
- ```
259
- JSON.parse<T>(jsonString)
260
-
261
- V
262
- ┌───────────────────┐
263
- │ Type Dispatch │
264
- │ (compile-time) │
265
- └─────────┬─────────┘
266
-
267
- ┌─────┴─────┬─────────────┬──────────────┐
268
- V V V V
269
- ┌───────┐ ┌────────┐ ┌──────────┐ ┌──────────┐
270
- │Boolean│ │Integer │ │ String │ │ Struct │
271
- └───┬───┘ └────┬───┘ └────┬─────┘ └────┬─────┘
272
- │ │ │ │
273
- └───────────┴─────┬──────┴──────────────┘
274
-
275
- V
276
- T
277
- ```
278
-
279
- ### Struct Deserialization
280
-
281
- For `@json` decorated classes, the generated `__DESERIALIZE` method:
282
-
283
- 1. Scans for opening `{`
284
- 2. Iterates through key-value pairs
285
- 3. Uses switch on key length for fast dispatch
286
- 4. Compares key bytes directly (often as `u32` or `u64` for short keys)
287
- 5. Deserializes value to appropriate type
288
- 6. Stores in output object at correct offset
289
-
290
- ## Environment Variables
291
-
292
- | Variable | Default | Description |
293
- |----------|---------|-------------|
294
- | `JSON_MODE` | SWAR | Optimization mode: NAIVE, SWAR, SIMD |
295
- | `JSON_DEBUG` | 0 | Debug level 0-3 (prints generated code) |
296
- | `JSON_WRITE` | "" | Comma-separated files to output after transform |
297
- | `JSON_CACHE` | 0 | Enable string caching (set to 1) |
298
- | `JSON_STRICT` | false | Enable strict JSON validation |
299
-
300
- ## Performance Considerations
301
-
302
- ### Serialization
303
-
304
- - Pre-computes static key bytes at compile time
305
- - Uses direct memory stores for known strings
306
- - SIMD/SWAR for escape character detection
307
- - Optional caching for repeated strings
308
-
309
- ### Deserialization
310
-
311
- - Groups fields by key length for switch optimization
312
- - Uses direct memory loads for key comparison
313
- - Avoids string allocation during key matching
314
- - Tracks depth for nested structures
315
-
316
- ### Memory
317
-
318
- - Single reusable buffer reduces allocations
319
- - EMA-based sizing prevents memory waste
320
- - Circular arena for cache prevents unbounded growth
package/CONTRIBUTING.md DELETED
@@ -1,238 +0,0 @@
1
- # Contributing to json-as
2
-
3
- Thank you for your interest in contributing to json-as! This document provides guidelines and instructions for contributing.
4
-
5
- ## Table of Contents
6
-
7
- - [Getting Started](#getting-started)
8
- - [Development Setup](#development-setup)
9
- - [Project Structure](#project-structure)
10
- - [Making Changes](#making-changes)
11
- - [Testing](#testing)
12
- - [Code Style](#code-style)
13
- - [Pull Request Process](#pull-request-process)
14
- - [Reporting Issues](#reporting-issues)
15
-
16
- ## Getting Started
17
-
18
- 1. Fork the repository on GitHub
19
- 2. Clone your fork locally:
20
- ```bash
21
- git clone https://github.com/YOUR_USERNAME/json-as.git
22
- cd json-as
23
- ```
24
- 3. Add the upstream remote:
25
- ```bash
26
- git remote add upstream https://github.com/JairusSW/json-as.git
27
- ```
28
-
29
- ## Development Setup
30
-
31
- ### Prerequisites
32
-
33
- - Node.js 18+ or Bun
34
- - Wasmtime (for running tests)
35
-
36
- ### Install Dependencies
37
-
38
- ```bash
39
- npm install
40
- # or
41
- bun install
42
- ```
43
-
44
- ### Build the Transform
45
-
46
- The transform is written in TypeScript and needs to be compiled:
47
-
48
- ```bash
49
- npm run build:transform
50
- ```
51
-
52
- ### Running Tests
53
-
54
- Run the full test suite across all modes (NAIVE, SWAR, SIMD):
55
-
56
- ```bash
57
- npm test
58
- ```
59
-
60
- Run a specific test file:
61
-
62
- ```bash
63
- ./run-tests.sh string # Runs string.spec.ts
64
- ```
65
-
66
- ### Running Benchmarks
67
-
68
- AssemblyScript benchmarks:
69
- ```bash
70
- npm run bench:as
71
- ```
72
-
73
- JavaScript comparison benchmarks:
74
- ```bash
75
- npm run bench:js
76
- ```
77
-
78
- ## Project Structure
79
-
80
- ```
81
- json-as/
82
- ├── assembly/ # AssemblyScript runtime implementation
83
- │ ├── index.ts # Main entry point (JSON namespace)
84
- │ ├── serialize/ # Serialization implementations
85
- │ │ ├── simple/ # Naive implementation
86
- │ │ ├── swar/ # SWAR-optimized
87
- │ │ └── simd/ # SIMD-optimized
88
- │ ├── deserialize/ # Deserialization implementations
89
- │ ├── util/ # Utility functions
90
- │ ├── custom/ # Constants and character codes
91
- │ └── __tests__/ # Test files
92
- ├── transform/ # TypeScript compiler transform
93
- │ └── src/ # Transform source code
94
- ├── lib/ # Shared utilities (buffer system)
95
- ├── bench/ # Benchmark suite
96
- └── .github/ # CI/CD workflows
97
- ```
98
-
99
- ## Making Changes
100
-
101
- ### Branching Strategy
102
-
103
- 1. Create a feature branch from `main`:
104
- ```bash
105
- git checkout -b feature/your-feature-name
106
- ```
107
-
108
- 2. Make your changes with clear, atomic commits
109
-
110
- 3. Keep your branch up to date:
111
- ```bash
112
- git fetch upstream
113
- git rebase upstream/main
114
- ```
115
-
116
- ### Commit Messages
117
-
118
- Use clear, descriptive commit messages:
119
-
120
- - `feat: add support for BigInt serialization`
121
- - `fix: handle escaped unicode in strings`
122
- - `perf: optimize SIMD string escaping`
123
- - `docs: update README examples`
124
- - `test: add edge case tests for nested arrays`
125
- - `chore: update dependencies`
126
-
127
- ## Testing
128
-
129
- ### Writing Tests
130
-
131
- Tests are located in `assembly/__tests__/`. Each test file follows the pattern `*.spec.ts`.
132
-
133
- Example test structure:
134
-
135
- ```typescript
136
- import { JSON } from "..";
137
-
138
- describe("Feature Name", () => {
139
- test("should serialize correctly", () => {
140
- const result = JSON.stringify<string>("hello");
141
- expect(result).toBe('"hello"');
142
- });
143
-
144
- test("should deserialize correctly", () => {
145
- const result = JSON.parse<string>('"hello"');
146
- expect(result).toBe("hello");
147
- });
148
- });
149
- ```
150
-
151
- ### Test Coverage
152
-
153
- Ensure your changes include tests for:
154
- - Happy path scenarios
155
- - Edge cases
156
- - Error conditions
157
- - All three modes (NAIVE, SWAR, SIMD) if applicable
158
-
159
- ## Code Style
160
-
161
- ### Formatting
162
-
163
- The project uses Prettier for formatting:
164
-
165
- ```bash
166
- npm run format
167
- ```
168
-
169
- ### AssemblyScript Guidelines
170
-
171
- - Use `@inline` decorator for small, frequently-called functions
172
- - Prefer `store<T>` and `load<T>` for direct memory operations
173
- - Use typed arrays and explicit types
174
- - Add `// @ts-ignore` comments with explanations when necessary
175
-
176
- ### TypeScript Guidelines (Transform)
177
-
178
- - Use strict TypeScript settings
179
- - Document complex logic with comments
180
- - Keep functions focused and small
181
-
182
- ## Pull Request Process
183
-
184
- 1. **Before submitting:**
185
- - Run the full test suite: `npm test`
186
- - Run the formatter: `npm run format`
187
- - Ensure your branch is up to date with `main`
188
-
189
- 2. **PR Description:**
190
- - Clearly describe the changes
191
- - Reference any related issues
192
- - Include before/after benchmarks for performance changes
193
-
194
- 3. **Review Process:**
195
- - PRs require at least one approval
196
- - Address review feedback promptly
197
- - Keep the PR focused on a single concern
198
-
199
- 4. **After Merge:**
200
- - Delete your feature branch
201
- - Update any related issues
202
-
203
- ## Reporting Issues
204
-
205
- ### Bug Reports
206
-
207
- Include:
208
- - json-as version
209
- - AssemblyScript version
210
- - Minimal reproduction case
211
- - Expected vs actual behavior
212
- - Error messages (if any)
213
-
214
- ### Feature Requests
215
-
216
- Include:
217
- - Use case description
218
- - Proposed API (if applicable)
219
- - Alternatives considered
220
-
221
- ## Performance Contributions
222
-
223
- If your change affects performance:
224
-
225
- 1. Run benchmarks before and after
226
- 2. Include benchmark results in the PR
227
- 3. Test across all three modes (NAIVE, SWAR, SIMD)
228
- 4. Consider memory usage implications
229
-
230
- ## Questions?
231
-
232
- - Open a GitHub Discussion for general questions
233
- - Join the [AssemblyScript Discord](https://discord.gg/assemblyscript)
234
- - Email the maintainer at [me@jairus.dev](mailto:me@jairus.dev)
235
-
236
- ## License
237
-
238
- By contributing, you agree that your contributions will be licensed under the MIT License.
package/TODO DELETED
@@ -1 +0,0 @@
1
- get staticarrays working within classes
@@ -1,11 +0,0 @@
1
- import { ptrToStr } from "../../util/ptrToStr";
2
-
3
- // @ts-ignore: inline
4
- @inline export function deserializeFloat<T>(srcStart: usize, srcEnd: usize): T {
5
- // @ts-ignore
6
- const type: T = 0;
7
- // @ts-ignore
8
- if (type instanceof f64) return f64.parse(ptrToStr(srcStart, srcEnd));
9
- // @ts-ignore
10
- return f32.parse(ptrToStr(srcStart, srcEnd));
11
- }
@@ -1,9 +0,0 @@
1
- import { atoi } from "../../util/atoi";
2
-
3
- // @ts-ignore: inline
4
- @inline export function deserializeInteger<T>(
5
- srcStart: usize,
6
- srcEnd: usize,
7
- ): T {
8
- return atoi<T>(srcStart, srcEnd);
9
- }
package/assembly/test.ts DELETED
@@ -1,30 +0,0 @@
1
- class Test {
2
- a: string;
3
- b: string;
4
- }
5
-
6
- // @ts-expect-error: decorator
7
- @inline function deserializeTest_NAIVE(
8
- srcStart: usize,
9
- srcEnd: usize,
10
- dst: Test,
11
- ): usize {
12
- // fast path
13
- do {
14
- if (
15
- load<u64>(srcStart) != load<u64>(changetype<usize>('{"a"')) ||
16
- load<u16>(srcStart, 8) != 0x3a
17
- )
18
- break;
19
- srcStart += 10;
20
- srcStart += deserializeString_NAIVE(srcStart, srcEnd); // this needs to somehow return an error (perhaps usize.MAX_VALUE) and also deserialize to the a field in dst.
21
- if (
22
- load<u64>(srcStart) != load<u64>(changetype<usize>(',"b"')) ||
23
- load<u16>(srcStart, 8) != 0x3a
24
- )
25
- break;
26
- srcStart += 10;
27
- srcStart += deserializeString_NAIVE(srcStart, srcEnd);
28
- } while (false);
29
- // have slow path here
30
- }
package/eslint.config.js DELETED
@@ -1,60 +0,0 @@
1
- // @ts-check
2
-
3
- import eslint from "@eslint/js";
4
- import tseslint from "typescript-eslint";
5
-
6
- export default tseslint.config(
7
- {
8
- ignores: [
9
- "bin/**",
10
- "templates/**",
11
- "tests/**/*.js",
12
- "transform/lib/**",
13
- "build/**",
14
- "assembly/**/*.ts",
15
- "lib/as-bs.ts",
16
- ],
17
- },
18
- eslint.configs.recommended,
19
- ...tseslint.configs.recommended,
20
- {
21
- files: ["**/*.{js,mjs,cjs,ts}"],
22
- languageOptions: {
23
- globals: {
24
- Buffer: "readonly",
25
- WebAssembly: "readonly",
26
- console: "readonly",
27
- process: "readonly",
28
- },
29
- },
30
- },
31
- {
32
- files: ["**/*.ts"],
33
- rules: {
34
- "@typescript-eslint/no-unused-vars": [
35
- "error",
36
- { argsIgnorePattern: "^_", varsIgnorePattern: "^_" },
37
- ],
38
- },
39
- },
40
- {
41
- files: ["bench/runners/assemblyscript.js"],
42
- languageOptions: {
43
- globals: {
44
- arguments: "readonly",
45
- performance: "readonly",
46
- readbuffer: "readonly",
47
- writeFile: "readonly",
48
- },
49
- },
50
- },
51
- {
52
- files: ["bench/lib/bench.js"],
53
- languageOptions: {
54
- globals: {
55
- performance: "readonly",
56
- writeFile: "readonly",
57
- },
58
- },
59
- },
60
- );
package/lib/tsconfig.json DELETED
@@ -1,8 +0,0 @@
1
- {
2
- "extends": "assemblyscript/std/assembly.json",
3
- "include": ["./**/*.ts"],
4
- "compilerOptions": {
5
- "experimentalDecorators": true,
6
- "emitDecoratorMetadata": true
7
- }
8
- }