@emagjby/strata-js 0.3.3 → 0.4.4

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Emagjby
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,16 +1,52 @@
1
1
  # @emagjby/strata-js
2
2
 
3
- Deterministic Strata implementation for JavaScript.
3
+ **Deterministic Strata implementation for JavaScript.**
4
4
 
5
- Strata is a deterministic binary data format with canonical encoding: identical logical values must produce identical bytes (and therefore identical hashes) across all implementations.
5
+ This package is the **JavaScript parity implementation** of **Strata**.
6
6
 
7
- This package is a **parity implementation** with the Rust reference implementation. If Rust and JavaScript ever disagree, **that is a bug**.
7
+ > Same data same bytes same hash.
8
+ > No ambiguity. No normalization. No silent coercions.
8
9
 
9
- - Canonical encoding: one value one byte representation
10
- - Hashing: stable hash over canonical bytes (BLAKE3-256)
11
- - Strata Text (`.st`): human authoring format that compiles to canonical Strata Core Binary (`.scb`)
10
+ If Rust and JavaScript ever disagree, **that is a bug**.
12
11
 
13
- Docs: https://strata.emagjby.com/docs
12
+ ---
13
+
14
+ ## What is Strata?
15
+
16
+ Strata is a **strict, minimal data model** with a **fully deterministic binary encoding**.
17
+
18
+ It is designed for systems where:
19
+
20
+ - data integrity is non-negotiable
21
+ - hashes must be stable forever
22
+ - cross-language verification is required
23
+ - ambiguity is unacceptable
24
+
25
+ Strata draws a hard line between **representation** and **truth**:
26
+
27
+ - `Value` is an in-memory representation
28
+ - canonical `.scb` bytes define truth
29
+ - hashes are computed only from canonical bytes
30
+
31
+ ---
32
+
33
+ ## What this package provides
34
+
35
+ This package provides:
36
+
37
+ - Canonical encoder for Strata Core Binary (`.scb`)
38
+ - Safe decoder with explicit error semantics
39
+ - Parser for Strata Text (`.st`)
40
+ - Deterministic BLAKE3 hashing
41
+ - Deterministic formatting (`fmt`)
42
+ - CLI tooling (mirrors Rust CLI)
43
+ - Golden vector enforcement
44
+ - Behavioral parity with the Rust reference implementation
45
+
46
+ This package does **not** define canonical truth.
47
+ The Rust implementation does.
48
+
49
+ ---
14
50
 
15
51
  ## Install
16
52
 
@@ -26,9 +62,11 @@ CLI:
26
62
  npm install -g @emagjby/strata-js
27
63
  ```
28
64
 
65
+ ---
66
+
29
67
  ## Quickstart (Library)
30
68
 
31
- ### Parse Strata Text (`.st`) → encode (`.scb`) → hash
69
+ ### Parse `.st` → encode `.scb` → hash
32
70
 
33
71
  ```js
34
72
  import { parse, encodeValue, hashValueHex } from "@emagjby/strata-js";
@@ -40,39 +78,126 @@ const source = `{
40
78
  }`;
41
79
 
42
80
  const value = parse(source);
43
- const scb = encodeValue(value); // Uint8Array canonical bytes
81
+ const scb = encodeValue(value); // Uint8Array (canonical bytes)
44
82
 
45
- // Hashing is defined over canonical bytes.
83
+ // Hashing is defined over canonical bytes
46
84
  console.log(hashValueHex(value));
47
85
  ```
48
86
 
49
- ### Decode `.scb` bytes back into a Strata value
87
+ ---
88
+
89
+ ### Decode `.scb` bytes back into a Value
50
90
 
51
91
  ```js
52
92
  import { decodeValue, encodeValue } from "@emagjby/strata-js";
53
93
 
54
- // Given canonical bytes (or bytes captured from storage/wire)
55
94
  const originalScb = new Uint8Array([0x00]); // example only
56
95
 
57
96
  const value = decodeValue(originalScb);
58
97
  const roundtrippedScb = encodeValue(value);
59
98
 
60
- // Strata guarantees: decode(encode(value)) == value
61
- // The reverse is intentionally NOT guaranteed.
99
+ // Guaranteed: encode(decode(bytes)) === bytes
100
+ // NOT guaranteed: decode(encode(value)) === value
62
101
  console.log(roundtrippedScb);
63
102
  ```
64
103
 
65
- ### Hash a value (canonical re-encode)
104
+ ---
66
105
 
67
- If you already have a JS `Value` and want a canonical hash:
106
+ ### Hash an existing Value
68
107
 
69
108
  ```js
70
- import { hashValueHex, parse } from "@emagjby/strata-js";
109
+ import { parse, hashValueHex } from "@emagjby/strata-js";
71
110
 
72
111
  const value = parse("[1, 2, 3]");
73
112
  console.log(hashValueHex(value));
74
113
  ```
75
114
 
115
+ ---
116
+
117
+ ## Constructing Values (JavaScript)
118
+
119
+ The recommended construction API is the **`Value` factory**.
120
+
121
+ The legacy alias `V` remains supported for backwards compatibility.
122
+
123
+ ```js
124
+ import { Value } from "@emagjby/strata-js";
125
+
126
+ const value = Value.mapOf(
127
+ ["id", Value.int(42n)],
128
+ ["name", Value.string("Gencho")],
129
+ ["active", Value.bool(true)],
130
+ ["skills", Value.listOf(Value.string("rust"), Value.string("systems"))],
131
+ [
132
+ "meta",
133
+ Value.mapOf(
134
+ ["a", Value.int(1n)],
135
+ ["a", Value.int(2n)], // last-write-wins
136
+ ),
137
+ ],
138
+ );
139
+ ```
140
+
141
+ Available helpers:
142
+
143
+ - `Value.null()`
144
+ - `Value.bool(boolean)`
145
+ - `Value.int(bigint)` **(BigInt only)**
146
+ - `Value.string(string)`
147
+ - `Value.bytes(Uint8Array)`
148
+ - `Value.list(Value[])`
149
+ - `Value.map(Iterable<[string, Value]>)`
150
+
151
+ DX helpers (additive):
152
+
153
+ - `Value.listOf(...Value)`
154
+ - `Value.mapObj({ [key]: Value })`
155
+ - `Value.mapOf(...[string, Value])`
156
+ - `Value.bytesFrom(Uint8Array | ArrayBuffer | number[] | Iterable<number>)`
157
+ - `Value.bytesHex(hexString)` (strict hex)
158
+
159
+ Duplicate map keys resolve via **last-write-wins**.
160
+
161
+ ---
162
+
163
+ ## JavaScript Value model (important)
164
+
165
+ Strata values are **not JSON** and are intentionally strict.
166
+
167
+ Rules:
168
+
169
+ - Integers are `bigint` (JS `number` is rejected)
170
+ - Bytes are `Uint8Array`
171
+ - Maps are `ReadonlyMap<string, Value>`
172
+ - No floats
173
+ - No implicit conversions
174
+
175
+ Type shape (abridged):
176
+
177
+ - `{ kind: "null" }`
178
+ - `{ kind: "bool", value: boolean }`
179
+ - `{ kind: "int", value: bigint }`
180
+ - `{ kind: "string", value: string }`
181
+ - `{ kind: "bytes", value: Uint8Array }`
182
+ - `{ kind: "list", value: readonly Value[] }`
183
+ - `{ kind: "map", value: ReadonlyMap<string, Value> }`
184
+
185
+ If you need JSON interoperability, you must define an **explicit mapping**.
186
+
187
+ ---
188
+
189
+ ## Canonical encoding & determinism
190
+
191
+ - Encoding is fully deterministic
192
+ - Map keys are sorted by UTF-8 byte order during encoding
193
+ - Duplicate keys overwrite earlier entries (last-write-wins)
194
+ - Hashing is defined over canonical `.scb` bytes
195
+
196
+ If your system needs “mostly the same bytes”, Strata is not the tool.
197
+ If it needs **exactly the same bytes**, it is.
198
+
199
+ ---
200
+
76
201
  ## CLI
77
202
 
78
203
  The `strata-js` CLI mirrors the Rust CLI.
@@ -80,9 +205,9 @@ The `strata-js` CLI mirrors the Rust CLI.
80
205
  Commands:
81
206
 
82
207
  - `compile` – compile `.st` → canonical `.scb`
83
- - `decode` – decode `.scb` into a stable inspection format
84
- - `hash` – compute deterministic hash (BLAKE3-256)
85
- - `fmt` – parse `.st` and print a structured inspection format
208
+ - `decode` – decode `.scb` for inspection
209
+ - `hash` – compute deterministic hash
210
+ - `fmt` – parse and pretty-print `.st` (or `.scb`)
86
211
 
87
212
  ### Compile
88
213
 
@@ -99,8 +224,8 @@ strata-js hash input.scb
99
224
 
100
225
  Behavior:
101
226
 
102
- - If input is `.st`, it is parsed and canonically encoded first
103
- - If input is `.scb`, bytes are hashed directly
227
+ - `.st` is parsed and canonically encoded first
228
+ - `.scb` bytes are hashed directly
104
229
  - Output is lowercase hex
105
230
 
106
231
  ### Decode
@@ -109,10 +234,18 @@ Behavior:
109
234
  strata-js decode input.scb
110
235
  ```
111
236
 
112
- ### Fmt
237
+ ### Format
113
238
 
114
239
  ```bash
115
240
  strata-js fmt input.st
241
+ strata-js fmt input.scb
242
+ ```
243
+
244
+ Format options:
245
+
246
+ ```bash
247
+ strata-js fmt --format pretty input.st
248
+ strata-js fmt --format ast input.st
116
249
  ```
117
250
 
118
251
  ### Exit codes
@@ -122,59 +255,59 @@ strata-js fmt input.st
122
255
  - `2` I/O failure
123
256
  - `100` internal error
124
257
 
125
- ## JavaScript value model (important)
126
-
127
- Strata values in JS are **not JSON** and are intentionally strict.
128
-
129
- - Integers are `bigint` (JS `number` MUST NOT be used)
130
- - Bytes are `Uint8Array`
131
- - Maps are `ReadonlyMap<string, Value>`
132
-
133
- If you need to bridge into JSON:
134
-
135
- - `bigint` cannot be directly serialized by `JSON.stringify`
136
- - You must choose an explicit representation (commonly decimal strings)
137
-
138
- Type shape (abridged):
139
-
140
- - `{ kind: "null" }`
141
- - `{ kind: "bool", value: boolean }`
142
- - `{ kind: "int", value: bigint }`
143
- - `{ kind: "string", value: string }`
144
- - `{ kind: "bytes", value: Uint8Array }`
145
- - `{ kind: "list", value: readonly Value[] }`
146
- - `{ kind: "map", value: ReadonlyMap<string, Value> }`
147
-
148
- ## Determinism notes
149
-
150
- - Hashing is defined over **canonical encoded bytes**, not decoded structures.
151
- - Decoding exists to inspect reality; encoding defines canonical truth.
152
- - Map keys are canonically ordered by UTF-8 byte order during encoding.
153
-
154
- If your system needs “mostly the same bytes”, Strata is not the tool. If it needs _exactly the same bytes_, it is.
258
+ ---
155
259
 
156
260
  ## Golden vectors
157
261
 
158
- Strata correctness is enforced via golden vectors (authored in `.st`) and cross-implementation tests.
262
+ Correctness is enforced using **golden vectors** shared with the Rust implementation.
263
+
264
+ Golden vectors are law:
159
265
 
160
- Golden vectors are not examples; they are law:
266
+ - If this package disagrees with vectors, **this package is wrong**
267
+ - Vectors are not adjusted to match buggy behavior
161
268
 
162
- - If this package disagrees with a golden vector, **the implementation is wrong**.
163
- - Vectors are not adjusted to match buggy behavior.
269
+ ---
164
270
 
165
271
  ## What Strata does NOT do
166
272
 
167
273
  Strata intentionally does not provide:
168
274
 
169
275
  - Schemas or validation rules
170
- - Optional fields or default values
276
+ - Optional fields or defaults
171
277
  - Backward-compatible schema evolution
172
278
  - Floating point numbers
173
- - Streaming/framing rules (transport concerns are external)
279
+ - Streaming or framing rules
174
280
  - Compression, encryption, or authentication
175
281
 
282
+ ---
283
+
284
+ ## Documentation
285
+
286
+ Canonical integration documentation lives in the **Integration Reference**:
287
+
288
+ https://strata.emagjby.com/docs
289
+
290
+ This is the **single source of truth** for integrators.
291
+
292
+ ---
293
+
176
294
  ## Links
177
295
 
178
296
  - Documentation: https://strata.emagjby.com/docs
179
- - Repo: https://github.com/Emagjby/Strata
180
- - Strata JS package source: https://github.com/Emagjby/Strata/tree/main/strata-js
297
+ - Monorepo: https://github.com/Emagjby/Strata
298
+ - JS source: https://github.com/Emagjby/Strata/tree/main/strata-js
299
+
300
+ ---
301
+
302
+ ## License
303
+
304
+ MIT License
305
+
306
+ ---
307
+
308
+ ## Final note
309
+
310
+ This package is intentionally strict.
311
+
312
+ If convenience matters more than correctness, use something else.
313
+ If correctness matters, this is the JavaScript implementation.
package/dist/cli.d.ts CHANGED
@@ -1,3 +1,3 @@
1
- #!/usr/bin/env node
1
+ #!/usr/bin/env bun
2
2
  export {};
3
3
  //# sourceMappingURL=cli.d.ts.map
package/dist/cli.js CHANGED
@@ -1,4 +1,4 @@
1
- #!/usr/bin/env node
1
+ #!/usr/bin/env bun
2
2
  import fs from "node:fs";
3
3
  import process from "node:process";
4
4
  import { parse } from "./parser.js";
@@ -8,6 +8,7 @@ import { hashBytes } from "./hash.js";
8
8
  import { DecodeError } from "./decode_error.js";
9
9
  import { ParseError } from "./parse_error.js";
10
10
  import { inspectValue } from "./inspect.js";
11
+ import { fmt, FormatOptions } from "./fmt.js";
11
12
  function exitOk() {
12
13
  process.exit(0);
13
14
  }
@@ -57,10 +58,12 @@ function cmdHash(input) {
57
58
  const hashed = hashBytes(encoded);
58
59
  console.log(hex(hashed));
59
60
  }
60
- function cmdFmt(input) {
61
- const source = fs.readFileSync(input, "utf8");
62
- const parsedValue = parse(source);
63
- console.log(JSON.stringify(inspectValue(parsedValue), null, 2));
61
+ function cmdFmt(input, options = FormatOptions.PRETTY) {
62
+ const value = input.endsWith(".scb")
63
+ ? decodeValue(fs.readFileSync(input))
64
+ : parse(fs.readFileSync(input, "utf8"));
65
+ const formatted = fmt(options, value);
66
+ console.log(formatted);
64
67
  }
65
68
  function main() {
66
69
  const [, , cmd, ...args] = process.argv;
@@ -90,21 +93,34 @@ function main() {
90
93
  return exitOk();
91
94
  }
92
95
  case "fmt": {
93
- if (args.length !== 1) {
94
- exitInvalid("usage: strata-js fmt <input.st>");
96
+ if (args.length < 1 || args.length > 3)
97
+ return exitInvalid("usage: strata-js fmt [format] <input.st>");
98
+ if (args.length === 2) {
99
+ return exitInvalid("usage: --format [type] must be provided if format is provided");
100
+ }
101
+ if (args.length === 1) {
102
+ cmdFmt(args[0]);
103
+ return exitOk();
104
+ }
105
+ if (args[0] !== "--format") {
106
+ return exitInvalid("usage: first argument must be --format if format is provided");
107
+ }
108
+ if (args[1] !== "pretty" && args[1] !== "ast") {
109
+ return exitInvalid("usage: format type must be one of: pretty, ast");
95
110
  }
96
- cmdFmt(args[0]);
111
+ const format = args[1] === "pretty" ? FormatOptions.PRETTY : FormatOptions.AST;
112
+ cmdFmt(args[2], format);
97
113
  return exitOk();
98
114
  }
99
115
  case "--help": {
100
116
  console.log(`
101
- Strata CLI (JavaScript)
117
+ Strata CLI (JavaScript)
102
118
 
103
- Commands:
104
- compile <input.st> <output.scb>
105
- decode <input.scb>
106
- hash <input.st|input.scb>
107
- fmt <input.st>
119
+ Commands:
120
+ compile <input.st> <output.scb>
121
+ decode <input.scb>
122
+ hash <input.st|input.scb>
123
+ fmt [format] <input.st>
108
124
  `);
109
125
  process.exit(0);
110
126
  }
package/dist/cli.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"cli.js","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":";AAEA,OAAO,EAAE,MAAM,SAAS,CAAC;AACzB,OAAO,OAAO,MAAM,cAAc,CAAC;AAEnC,OAAO,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AACpC,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC1C,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC1C,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AAEtC,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAChD,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAE9C,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAE5C,SAAS,MAAM;IACX,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AACpB,CAAC;AAED,SAAS,WAAW,CAAC,GAAY;IAC7B,IAAI,GAAG,EAAE,CAAC;QACN,OAAO,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;IACvB,CAAC;IACD,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AACpB,CAAC;AAED,SAAS,MAAM,CAAC,GAAY;IACxB,IAAI,GAAG,YAAY,KAAK,EAAE,CA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,CAAC,CAAC;YACzE,CAAC;YAED,MAAM,MAAM,GACR,IAAI,CAAC,CAAC,CAAC,KAAK,QAAQ,CAAC,CAAC,CAAC,aAAa,CAAC,MAAM,CAAC,CAAC,CAAC,aAAa,CAAC,GAAG,CAAC;YAEpE,MAAM,CAAC,IAAI,CAAC,CAAC,CAAE,EAAE,MAAM,CAAC,CAAC;YACzB,OAAO,MAAM,EAAE,CAAC;QACpB,CAAC;QAED,KAAK,QAAQ,CAAC,CAAC,CAAC;YACZ,OAAO,CAAC,GAAG,CAAC;;;;;;;;aAQX,CAAC,CAAC;YACH,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;QACpB,CAAC;QAED;YACI,WAAW,CAAC,oBAAoB,GAAG,EAAE,CAAC,CAAC;IAC/C,CAAC;AACL,CAAC;AAED,IAAI,CAAC;IACD,IAAI,EAAE,CAAC;AACX,CAAC;AAAC,OAAO,GAAG,EAAE,CAAC;IACX,IAAI,GAAG,YAAY,WAAW,IAAI,GAAG,YAAY,UAAU,EAAE,CAAC;QAC1D,OAAO,CAAC,KAAK,CAAC,SAAS,EAAE,GAAG,CAAC,OAAO,CAAC,CAAC;QACtC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IACpB,CAAC;IAED,IAAI,GAAG,YAAY,KAAK,IAAI,MAAM,IAAI,GAAG,IAAK,GAAW,CAAC,IAAI,KAAK,QAAQ,EAAE,CAAC;QAC1E,MAAM,CAAC,GAAG,CAAC,CAAC;IAChB,CAAC;IAED,YAAY,CAAC,GAAG,CAAC,CAAC;AACtB,CAAC"}
package/dist/fmt.d.ts ADDED
@@ -0,0 +1,7 @@
1
+ import { Value } from "./value.js";
2
+ export declare enum FormatOptions {
3
+ PRETTY = "PRETTY",
4
+ AST = "AST"
5
+ }
6
+ export declare function fmt(opts: FormatOptions, value: Value): string;
7
+ //# sourceMappingURL=fmt.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fmt.d.ts","sourceRoot":"","sources":["../src/fmt.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AAEnC,oBAAY,aAAa;IACrB,MAAM,WAAW;IACjB,GAAG,QAAQ;CACd;AAED,wBAAgB,GAAG,CAAC,IAAI,EAAE,aAAa,EAAE,KAAK,EAAE,KAAK,GAAG,MAAM,CAU7D"}
package/dist/fmt.js ADDED
@@ -0,0 +1,84 @@
1
+ export var FormatOptions;
2
+ (function (FormatOptions) {
3
+ FormatOptions["PRETTY"] = "PRETTY";
4
+ FormatOptions["AST"] = "AST";
5
+ })(FormatOptions || (FormatOptions = {}));
6
+ export function fmt(opts, value) {
7
+ switch (opts) {
8
+ case FormatOptions.PRETTY: {
9
+ const f = new PrettyFmt();
10
+ f.value(value);
11
+ return f.out;
12
+ }
13
+ case FormatOptions.AST:
14
+ return prettyDebug(value);
15
+ }
16
+ }
17
+ class PrettyFmt {
18
+ out = "";
19
+ depth = 0;
20
+ indent = 2;
21
+ pad() {
22
+ return " ".repeat(this.depth * this.indent);
23
+ }
24
+ value(v) {
25
+ switch (v.kind) {
26
+ case "null":
27
+ this.out += "null";
28
+ break;
29
+ case "bool":
30
+ this.out += String(v.value);
31
+ break;
32
+ case "int":
33
+ this.out += String(v.value);
34
+ break;
35
+ case "string":
36
+ this.out += `"${v.value}"`;
37
+ break;
38
+ case "bytes":
39
+ this.bytes(v.value);
40
+ break;
41
+ case "list":
42
+ this.list(v.value);
43
+ break;
44
+ case "map":
45
+ this.map(v.value);
46
+ break;
47
+ }
48
+ }
49
+ bytes(bytes) {
50
+ this.out += "[";
51
+ for (const b of bytes) {
52
+ this.out += b.toString(16).padStart(2, "0");
53
+ }
54
+ this.out += "]";
55
+ }
56
+ list(list) {
57
+ this.out += "[";
58
+ for (let i = 0; i < list.length; i++) {
59
+ this.value(list[i]);
60
+ if (i + 1 !== list.length)
61
+ this.out += ", ";
62
+ }
63
+ this.out += "]";
64
+ }
65
+ map(map) {
66
+ this.out += "{\n";
67
+ this.depth += 1;
68
+ const entries = [...map.entries()].sort(([a], [b]) => a.localeCompare(b));
69
+ for (const [k, v] of entries) {
70
+ this.out += this.pad();
71
+ this.out += k;
72
+ this.out += ": ";
73
+ this.value(v);
74
+ this.out += "\n";
75
+ }
76
+ this.depth -= 1;
77
+ this.out += this.pad();
78
+ this.out += "}";
79
+ }
80
+ }
81
+ function prettyDebug(value) {
82
+ return JSON.stringify(value, null, 2);
83
+ }
84
+ //# sourceMappingURL=fmt.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fmt.js","sourceRoot":"","sources":["../src/fmt.ts"],"names":[],"mappings":"AAEA,MAAM,CAAN,IAAY,aAGX;AAHD,WAAY,aAAa;IACrB,kCAAiB,CAAA;IACjB,4BAAW,CAAA;AACf,CAAC,EAHW,aAAa,KAAb,aAAa,QAGxB;AAED,MAAM,UAAU,GAAG,CAAC,IAAmB,EAAE,KAAY;IACjD,QAAQ,IAAI,EAAE,CAAC;QACX,KAAK,aAAa,CAAC,MAAM,CAAC,CAAC,CAAC;YACxB,MAAM,CAAC,GAAG,IAAI,SAAS,EAAE,CAAC;YAC1B,CAAC,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;YACf,OAAO,CAAC,CAAC,GAAG,CAAC;QACjB,CAAC;QACD,KAAK,aAAa,CAAC,GAAG;YAClB,OAAO,WAAW,CAAC,KAAK,CAAC,CAAC;IAClC,CAAC;AACL,CAAC;AAED,MAAM,SAAS;IACX,GAAG,GAAG,EAAE,CAAC;IACT,KAAK,GAAG,CAAC,CAAC;IACV,MAAM,GAAG,CAAC,CAAC;IAEH,GAAG;QACP,OAAO,GAAG,CAAC,MAAM,CAAC,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC,MAAM,CAAC,CAAC;IAChD,CAAC;IAED,KAAK,CAAC,CAAQ;QACV,QAAQ,CAAC,CAAC,IAAI,EAAE,CAAC;YACb,KAAK,MAAM;gBACP,IAAI,CAAC,GAAG,IAAI,MAAM,CAAC;gBACnB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,CAAC;QAChD,CAAC;QACD,IAAI,CAAC,GAAG,IAAI,GAAG,CAAC;IACpB,CAAC;IAEO,GAAG,CAAC,GAAuB;QAC/B,IAAI,CAAC,GAAG,IAAI,KAAK,CAAC;QAClB,IAAI,CAAC,KAAK,IAAI,CAAC,CAAC;QAEhB,MAAM,OAAO,GAAG,CAAC,GAAG,GAAG,CAAC,OAAO,EAAE,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,aAAa,CAAC,CAAC,CAAC,CAAC,CAAC;QAE1E,KAAK,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,IAAI,OAAO,EAAE,CAAC;YAC3B,IAAI,CAAC,GAAG,IAAI,IAAI,CAAC,GAAG,EAAE,CAAC;YACvB,IAAI,CAAC,GAAG,IAAI,CAAC,CAAC;YACd,IAAI,CAAC,GAAG,IAAI,IAAI,CAAC;YACjB,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;YACd,IAAI,CAAC,GAAG,IAAI,IAAI,CAAC;QACrB,CAAC;QAED,IAAI,CAAC,KAAK,IAAI,CAAC,CAAC;QAChB,IAAI,CAAC,GAAG,IAAI,IAAI,CAAC,GAAG,EAAE,CAAC;QACvB,IAAI,CAAC,GAAG,IAAI,GAAG,CAAC;IACpB,CAAC;CACJ;AAED,SAAS,WAAW,CAAC,KAAc;IAC/B,OAAO,IAAI,CAAC,SAAS,CAAC,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC;AAC1C,CAAC"}
package/dist/index.d.ts CHANGED
@@ -2,6 +2,8 @@ export { encodeValue } from "./encode.js";
2
2
  export { decodeValue } from "./decode.js";
3
3
  export { hashValueHex, hashBytes as hashValue } from "./hash.js";
4
4
  export { parse } from "./parser.js";
5
+ export { fmt } from "./fmt.js";
6
+ export { Value, V } from "./value_factory.js";
5
7
  export { V as ValueFactory } from "./value_factory.js";
6
8
  export * from "./value.js";
7
9
  export * from "./decode_error.js";
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC1C,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC1C,OAAO,EAAE,YAAY,EAAE,SAAS,IAAI,SAAS,EAAE,MAAM,WAAW,CAAC;AACjE,OAAO,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AACpC,OAAO,EAAE,CAAC,IAAI,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAEvD,cAAc,YAAY,CAAC;AAC3B,cAAc,mBAAmB,CAAC;AAClC,cAAc,kBAAkB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC1C,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC1C,OAAO,EAAE,YAAY,EAAE,SAAS,IAAI,SAAS,EAAE,MAAM,WAAW,CAAC;AACjE,OAAO,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AACpC,OAAO,EAAE,GAAG,EAAE,MAAM,UAAU,CAAC;AAE/B,OAAO,EAAE,KAAK,EAAE,CAAC,EAAE,MAAM,oBAAoB,CAAC;AAC9C,OAAO,EAAE,CAAC,IAAI,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAEvD,cAAc,YAAY,CAAC;AAC3B,cAAc,mBAAmB,CAAC;AAClC,cAAc,kBAAkB,CAAC"}
package/dist/index.js CHANGED
@@ -4,6 +4,8 @@ export { encodeValue } from "./encode.js";
4
4
  export { decodeValue } from "./decode.js";
5
5
  export { hashValueHex, hashBytes as hashValue } from "./hash.js";
6
6
  export { parse } from "./parser.js";
7
+ export { fmt } from "./fmt.js";
8
+ export { Value, V } from "./value_factory.js";
7
9
  export { V as ValueFactory } from "./value_factory.js";
8
10
  export * from "./value.js";
9
11
  export * from "./decode_error.js";
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,wBAAwB;AACxB,+BAA+B;AAC/B,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC1C,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC1C,OAAO,EAAE,YAAY,EAAE,SAAS,IAAI,SAAS,EAAE,MAAM,WAAW,CAAC;AACjE,OAAO,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AACpC,OAAO,EAAE,CAAC,IAAI,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAEvD,cAAc,YAAY,CAAC;AAC3B,cAAc,mBAAmB,CAAC;AAClC,cAAc,kBAAkB,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,wBAAwB;AACxB,+BAA+B;AAC/B,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC1C,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC1C,OAAO,EAAE,YAAY,EAAE,SAAS,IAAI,SAAS,EAAE,MAAM,WAAW,CAAC;AACjE,OAAO,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AACpC,OAAO,EAAE,GAAG,EAAE,MAAM,UAAU,CAAC;AAE/B,OAAO,EAAE,KAAK,EAAE,CAAC,EAAE,MAAM,oBAAoB,CAAC;AAC9C,OAAO,EAAE,CAAC,IAAI,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAEvD,cAAc,YAAY,CAAC;AAC3B,cAAc,mBAAmB,CAAC;AAClC,cAAc,kBAAkB,CAAC"}
@@ -1,11 +1,30 @@
1
- import { Value, NullValue, BoolValue, IntValue, StringValue, BytesValue, ListValue, MapValue } from "./value.js";
1
+ import { Value as ValueT, NullValue, BoolValue, IntValue, StringValue, BytesValue, ListValue, MapValue } from "./value.js";
2
+ export declare const Value: {
3
+ readonly null: () => NullValue;
4
+ readonly bool: (value: boolean) => BoolValue;
5
+ readonly int: (value: bigint) => IntValue;
6
+ readonly string: (value: string) => StringValue;
7
+ readonly bytes: (value: Uint8Array) => BytesValue;
8
+ readonly bytesFrom: (value: ArrayBuffer | Uint8Array | readonly number[] | Iterable<number>) => BytesValue;
9
+ readonly bytesHex: (hex: string) => BytesValue;
10
+ readonly list: (value: readonly ValueT[]) => ListValue;
11
+ readonly listOf: (...values: ValueT[]) => ListValue;
12
+ readonly map: (entries: Iterable<[string, ValueT]>) => MapValue;
13
+ readonly mapObj: (obj: Record<string, ValueT>) => MapValue;
14
+ readonly mapOf: (...entries: [string, ValueT][]) => MapValue;
15
+ };
2
16
  export declare const V: {
3
17
  readonly null: () => NullValue;
4
18
  readonly bool: (value: boolean) => BoolValue;
5
19
  readonly int: (value: bigint) => IntValue;
6
20
  readonly string: (value: string) => StringValue;
7
21
  readonly bytes: (value: Uint8Array) => BytesValue;
8
- readonly list: (value: readonly Value[]) => ListValue;
9
- readonly map: (entries: Iterable<[string, Value]>) => MapValue;
22
+ readonly bytesFrom: (value: ArrayBuffer | Uint8Array | readonly number[] | Iterable<number>) => BytesValue;
23
+ readonly bytesHex: (hex: string) => BytesValue;
24
+ readonly list: (value: readonly ValueT[]) => ListValue;
25
+ readonly listOf: (...values: ValueT[]) => ListValue;
26
+ readonly map: (entries: Iterable<[string, ValueT]>) => MapValue;
27
+ readonly mapObj: (obj: Record<string, ValueT>) => MapValue;
28
+ readonly mapOf: (...entries: [string, ValueT][]) => MapValue;
10
29
  };
11
30
  //# sourceMappingURL=value_factory.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"value_factory.d.ts","sourceRoot":"","sources":["../src/value_factory.ts"],"names":[],"mappings":"AAAA,OAAO,EACH,KAAK,EACL,SAAS,EACT,SAAS,EACT,QAAQ,EACR,WAAW,EACX,UAAU,EACV,SAAS,EACT,QAAQ,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AQ,CAAC,MAAM,CAAC,KACvE,UAAU;6BAcC,MAAM,KAAG,UAAU;2BAIrB,SAAS,MAAM,EAAE,KAAG,SAAS;iCAIvB,MAAM,EAAE,KAAG,SAAS;4BAIzB,QAAQ,CAAC,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,KAAG,QAAQ;2BAItC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,KAAG,QAAQ;iCAO3B,CAAC,MAAM,EAAE,MAAM,CAAC,EAAE,KAAG,QAAQ;CAK7B,CAAC"}
@@ -1,4 +1,33 @@
1
- export const V = {
1
+ function assertByte(n) {
2
+ if (!Number.isInteger(n) || n < 0 || n > 255) {
3
+ throw new TypeError("Byte values must be integers in range 0..255");
4
+ }
5
+ }
6
+ function bytesFromIterable(it) {
7
+ const out = [];
8
+ for (const n of it) {
9
+ assertByte(n);
10
+ out.push(n);
11
+ }
12
+ return Uint8Array.from(out);
13
+ }
14
+ function bytesFromHexStrict(hex) {
15
+ if (typeof hex !== "string") {
16
+ throw new TypeError("Hex string must be a string");
17
+ }
18
+ if (hex.length % 2 !== 0) {
19
+ throw new TypeError("Hex string must have even length");
20
+ }
21
+ if (!/^[0-9a-fA-F]*$/.test(hex)) {
22
+ throw new TypeError("Hex string contains invalid characters");
23
+ }
24
+ const out = new Uint8Array(hex.length / 2);
25
+ for (let i = 0; i < hex.length; i += 2) {
26
+ out[i / 2] = Number.parseInt(hex.slice(i, i + 2), 16);
27
+ }
28
+ return out;
29
+ }
30
+ export const Value = {
2
31
  null() {
3
32
  return { kind: "null" };
4
33
  },
@@ -20,11 +49,41 @@ export const V = {
20
49
  }
21
50
  return { kind: "bytes", value };
22
51
  },
52
+ bytesFrom(value) {
53
+ if (value instanceof Uint8Array) {
54
+ return Value.bytes(value);
55
+ }
56
+ if (value instanceof ArrayBuffer) {
57
+ return Value.bytes(new Uint8Array(value));
58
+ }
59
+ if (Array.isArray(value)) {
60
+ for (const n of value)
61
+ assertByte(n);
62
+ return Value.bytes(Uint8Array.from(value));
63
+ }
64
+ return Value.bytes(bytesFromIterable(value));
65
+ },
66
+ bytesHex(hex) {
67
+ return Value.bytes(bytesFromHexStrict(hex));
68
+ },
23
69
  list(value) {
24
70
  return { kind: "list", value };
25
71
  },
72
+ listOf(...values) {
73
+ return { kind: "list", value: values };
74
+ },
26
75
  map(entries) {
27
76
  return { kind: "map", value: new Map(entries) };
28
77
  },
78
+ mapObj(obj) {
79
+ return {
80
+ kind: "map",
81
+ value: new Map(Object.entries(obj)),
82
+ };
83
+ },
84
+ mapOf(...entries) {
85
+ return { kind: "map", value: new Map(entries) };
86
+ },
29
87
  };
88
+ export const V = Value;
30
89
  //# sourceMappingURL=value_factory.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"value_factory.js","sourceRoot":"","sources":["../src/value_factory.ts"],"names":[],"mappings":"AAWA,MAAM,CAAC,MAAM,CAAC,GAAG;IACb,IAAI;QACA,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;IAC5B,CAAC;IAED,IAAI,CAAC,KAAc;QACf,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC;IACnC,CAAC;IAED,GAAG,CAAC,KAAa;QACb,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;YAC5B,MAAM,IAAI,SAAS,CAAC,6BAA6B,CAAC,CAAC;QACvD,CAAC;QACD,OAAO,EAAE,IAAI,EAAE,KAAK,EAAE,KAAK,EAAE,CAAC;IAClC,CAAC;IAED,MAAM,CAAC,KAAa;QAChB,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,KAAK,EAAE,CAAC;IACrC,CAAC;IAED,KAAK,CAAC,KAAiB;QACnB,IAAI,CAAC,CAAC,KAAK,YAAY,UAAU,CAAC,EAAE,CAAC;YACjC,MAAM,IAAI,SAAS,CAAC,mCAAmC,CAAC,CAAC;QAC7D,CAAC;QACD,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,KAAK,EAAE,CAAC;IACpC,C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AAC,MAAM,CAAC,GAAG,KAAK,CAAC"}
package/package.json CHANGED
@@ -1,12 +1,14 @@
1
1
  {
2
2
  "name": "@emagjby/strata-js",
3
- "version": "0.3.3",
3
+ "version": "0.4.4",
4
4
  "type": "module",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",
7
7
  "exports": {
8
8
  ".": "./dist/index.js"
9
9
  },
10
+ "license": "MIT",
11
+ "author": "Emagjby",
10
12
  "bin": {
11
13
  "strata-js": "./dist/cli.js"
12
14
  },