@emagjby/strata-js 0.3.2 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +192 -66
- package/dist/index.d.ts +3 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -1
- package/dist/index.js.map +1 -1
- package/dist/value_factory.d.ts +22 -3
- package/dist/value_factory.d.ts.map +1 -1
- package/dist/value_factory.js +60 -1
- package/dist/value_factory.js.map +1 -1
- package/package.json +3 -1
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,51 @@
|
|
|
1
1
|
# @emagjby/strata-js
|
|
2
2
|
|
|
3
|
-
Deterministic Strata implementation for JavaScript
|
|
3
|
+
**Deterministic Strata implementation for JavaScript.**
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
This package is the **JavaScript parity implementation** of **Strata**.
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
> Same data → same bytes → same hash.
|
|
8
|
+
> No ambiguity. No normalization. No silent coercions.
|
|
8
9
|
|
|
9
|
-
|
|
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
|
-
|
|
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
|
+
- CLI tooling (mirrors Rust CLI)
|
|
42
|
+
- Golden vector enforcement
|
|
43
|
+
- Behavioral parity with the Rust reference implementation
|
|
44
|
+
|
|
45
|
+
This package does **not** define canonical truth.
|
|
46
|
+
The Rust implementation does.
|
|
47
|
+
|
|
48
|
+
---
|
|
14
49
|
|
|
15
50
|
## Install
|
|
16
51
|
|
|
@@ -26,53 +61,144 @@ CLI:
|
|
|
26
61
|
npm install -g @emagjby/strata-js
|
|
27
62
|
```
|
|
28
63
|
|
|
64
|
+
---
|
|
65
|
+
|
|
29
66
|
## Quickstart (Library)
|
|
30
67
|
|
|
31
|
-
### Parse
|
|
68
|
+
### Parse `.st` → encode `.scb` → hash
|
|
32
69
|
|
|
33
70
|
```js
|
|
34
71
|
import { parse, encodeValue, hashValueHex } from "@emagjby/strata-js";
|
|
35
72
|
|
|
36
73
|
const source = `{
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
74
|
+
name: "alice"
|
|
75
|
+
active: true
|
|
76
|
+
count: 3
|
|
40
77
|
}`;
|
|
41
78
|
|
|
42
79
|
const value = parse(source);
|
|
43
|
-
const scb = encodeValue(value); // Uint8Array canonical bytes
|
|
80
|
+
const scb = encodeValue(value); // Uint8Array (canonical bytes)
|
|
44
81
|
|
|
45
|
-
// Hashing is defined over canonical bytes
|
|
46
|
-
console.log(hashValueHex(
|
|
82
|
+
// Hashing is defined over canonical bytes
|
|
83
|
+
console.log(hashValueHex(scb));
|
|
47
84
|
```
|
|
48
85
|
|
|
49
|
-
|
|
86
|
+
---
|
|
87
|
+
|
|
88
|
+
### Decode `.scb` bytes back into a Value
|
|
50
89
|
|
|
51
90
|
```js
|
|
52
91
|
import { decodeValue, encodeValue } from "@emagjby/strata-js";
|
|
53
92
|
|
|
54
|
-
// Given canonical bytes (or bytes captured from storage/wire)
|
|
55
93
|
const originalScb = new Uint8Array([0x00]); // example only
|
|
56
94
|
|
|
57
95
|
const value = decodeValue(originalScb);
|
|
58
96
|
const roundtrippedScb = encodeValue(value);
|
|
59
97
|
|
|
60
|
-
//
|
|
61
|
-
//
|
|
98
|
+
// Guaranteed: encode(decode(bytes)) === bytes
|
|
99
|
+
// NOT guaranteed: decode(encode(value)) === value
|
|
62
100
|
console.log(roundtrippedScb);
|
|
63
101
|
```
|
|
64
102
|
|
|
65
|
-
|
|
103
|
+
---
|
|
66
104
|
|
|
67
|
-
|
|
105
|
+
### Hash an existing Value
|
|
68
106
|
|
|
69
107
|
```js
|
|
70
|
-
import {
|
|
108
|
+
import { parse, encodeValue, hashValueHex } from "@emagjby/strata-js";
|
|
71
109
|
|
|
72
110
|
const value = parse("[1, 2, 3]");
|
|
73
|
-
|
|
111
|
+
const bytes = encodeValue(value);
|
|
112
|
+
|
|
113
|
+
console.log(hashValueHex(bytes));
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
---
|
|
117
|
+
|
|
118
|
+
## Constructing Values (JavaScript)
|
|
119
|
+
|
|
120
|
+
The recommended construction API is the **`Value` factory**.
|
|
121
|
+
|
|
122
|
+
The legacy alias `V` remains supported for backwards compatibility.
|
|
123
|
+
|
|
124
|
+
```js
|
|
125
|
+
import { Value } from "@emagjby/strata-js";
|
|
126
|
+
|
|
127
|
+
const value = Value.mapOf(
|
|
128
|
+
["id", Value.int(42n)],
|
|
129
|
+
["name", Value.string("Gencho")],
|
|
130
|
+
["active", Value.bool(true)],
|
|
131
|
+
["skills", Value.listOf(Value.string("rust"), Value.string("systems"))],
|
|
132
|
+
[
|
|
133
|
+
"meta",
|
|
134
|
+
Value.mapOf(
|
|
135
|
+
["a", Value.int(1n)],
|
|
136
|
+
["a", Value.int(2n)], // last-write-wins
|
|
137
|
+
),
|
|
138
|
+
],
|
|
139
|
+
);
|
|
74
140
|
```
|
|
75
141
|
|
|
142
|
+
Available helpers:
|
|
143
|
+
|
|
144
|
+
- `Value.null()`
|
|
145
|
+
- `Value.bool(boolean)`
|
|
146
|
+
- `Value.int(bigint)` **(BigInt only)**
|
|
147
|
+
- `Value.string(string)`
|
|
148
|
+
- `Value.bytes(Uint8Array)`
|
|
149
|
+
- `Value.list(Value[])`
|
|
150
|
+
- `Value.map(Iterable<[string, Value]>)`
|
|
151
|
+
|
|
152
|
+
DX helpers (additive):
|
|
153
|
+
|
|
154
|
+
- `Value.listOf(...Value)`
|
|
155
|
+
- `Value.mapObj({ [key]: Value })`
|
|
156
|
+
- `Value.mapOf(...[string, Value])`
|
|
157
|
+
- `Value.bytesFrom(Uint8Array | ArrayBuffer | number[] | Iterable<number>)`
|
|
158
|
+
- `Value.bytesHex(hexString)` (strict hex)
|
|
159
|
+
|
|
160
|
+
Duplicate map keys resolve via **last-write-wins**.
|
|
161
|
+
|
|
162
|
+
---
|
|
163
|
+
|
|
164
|
+
## JavaScript Value model (important)
|
|
165
|
+
|
|
166
|
+
Strata values are **not JSON** and are intentionally strict.
|
|
167
|
+
|
|
168
|
+
Rules:
|
|
169
|
+
|
|
170
|
+
- Integers are `bigint` (JS `number` is rejected)
|
|
171
|
+
- Bytes are `Uint8Array`
|
|
172
|
+
- Maps are `ReadonlyMap<string, Value>`
|
|
173
|
+
- No floats
|
|
174
|
+
- No implicit conversions
|
|
175
|
+
|
|
176
|
+
Type shape (abridged):
|
|
177
|
+
|
|
178
|
+
- `{ kind: "null" }`
|
|
179
|
+
- `{ kind: "bool", value: boolean }`
|
|
180
|
+
- `{ kind: "int", value: bigint }`
|
|
181
|
+
- `{ kind: "string", value: string }`
|
|
182
|
+
- `{ kind: "bytes", value: Uint8Array }`
|
|
183
|
+
- `{ kind: "list", value: readonly Value[] }`
|
|
184
|
+
- `{ kind: "map", value: ReadonlyMap<string, Value> }`
|
|
185
|
+
|
|
186
|
+
If you need JSON interoperability, you must define an **explicit mapping**.
|
|
187
|
+
|
|
188
|
+
---
|
|
189
|
+
|
|
190
|
+
## Canonical encoding & determinism
|
|
191
|
+
|
|
192
|
+
- Encoding is fully deterministic
|
|
193
|
+
- Map keys are sorted by UTF-8 byte order during encoding
|
|
194
|
+
- Duplicate keys overwrite earlier entries (last-write-wins)
|
|
195
|
+
- Hashing is defined over canonical `.scb` bytes
|
|
196
|
+
|
|
197
|
+
If your system needs “mostly the same bytes”, Strata is not the tool.
|
|
198
|
+
If it needs **exactly the same bytes**, it is.
|
|
199
|
+
|
|
200
|
+
---
|
|
201
|
+
|
|
76
202
|
## CLI
|
|
77
203
|
|
|
78
204
|
The `strata-js` CLI mirrors the Rust CLI.
|
|
@@ -80,9 +206,9 @@ The `strata-js` CLI mirrors the Rust CLI.
|
|
|
80
206
|
Commands:
|
|
81
207
|
|
|
82
208
|
- `compile` – compile `.st` → canonical `.scb`
|
|
83
|
-
- `decode` – decode `.scb`
|
|
84
|
-
- `hash` – compute deterministic hash
|
|
85
|
-
- `fmt` – parse
|
|
209
|
+
- `decode` – decode `.scb` for inspection
|
|
210
|
+
- `hash` – compute deterministic hash
|
|
211
|
+
- `fmt` – parse and pretty-print `.st`
|
|
86
212
|
|
|
87
213
|
### Compile
|
|
88
214
|
|
|
@@ -99,8 +225,8 @@ strata-js hash input.scb
|
|
|
99
225
|
|
|
100
226
|
Behavior:
|
|
101
227
|
|
|
102
|
-
-
|
|
103
|
-
-
|
|
228
|
+
- `.st` is parsed and canonically encoded first
|
|
229
|
+
- `.scb` bytes are hashed directly
|
|
104
230
|
- Output is lowercase hex
|
|
105
231
|
|
|
106
232
|
### Decode
|
|
@@ -109,7 +235,7 @@ Behavior:
|
|
|
109
235
|
strata-js decode input.scb
|
|
110
236
|
```
|
|
111
237
|
|
|
112
|
-
###
|
|
238
|
+
### Format
|
|
113
239
|
|
|
114
240
|
```bash
|
|
115
241
|
strata-js fmt input.st
|
|
@@ -122,59 +248,59 @@ strata-js fmt input.st
|
|
|
122
248
|
- `2` I/O failure
|
|
123
249
|
- `100` internal error
|
|
124
250
|
|
|
125
|
-
|
|
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.
|
|
251
|
+
---
|
|
155
252
|
|
|
156
253
|
## Golden vectors
|
|
157
254
|
|
|
158
|
-
|
|
255
|
+
Correctness is enforced using **golden vectors** shared with the Rust implementation.
|
|
256
|
+
|
|
257
|
+
Golden vectors are law:
|
|
159
258
|
|
|
160
|
-
|
|
259
|
+
- If this package disagrees with vectors, **this package is wrong**
|
|
260
|
+
- Vectors are not adjusted to match buggy behavior
|
|
161
261
|
|
|
162
|
-
|
|
163
|
-
- Vectors are not adjusted to match buggy behavior.
|
|
262
|
+
---
|
|
164
263
|
|
|
165
264
|
## What Strata does NOT do
|
|
166
265
|
|
|
167
266
|
Strata intentionally does not provide:
|
|
168
267
|
|
|
169
268
|
- Schemas or validation rules
|
|
170
|
-
- Optional fields or
|
|
269
|
+
- Optional fields or defaults
|
|
171
270
|
- Backward-compatible schema evolution
|
|
172
271
|
- Floating point numbers
|
|
173
|
-
- Streaming
|
|
272
|
+
- Streaming or framing rules
|
|
174
273
|
- Compression, encryption, or authentication
|
|
175
274
|
|
|
275
|
+
---
|
|
276
|
+
|
|
277
|
+
## Documentation
|
|
278
|
+
|
|
279
|
+
Canonical integration documentation lives in the **Integration Reference**:
|
|
280
|
+
|
|
281
|
+
https://strata.emagjby.com/docs
|
|
282
|
+
|
|
283
|
+
This is the **single source of truth** for integrators.
|
|
284
|
+
|
|
285
|
+
---
|
|
286
|
+
|
|
176
287
|
## Links
|
|
177
288
|
|
|
178
289
|
- Documentation: https://strata.emagjby.com/docs
|
|
179
|
-
-
|
|
180
|
-
-
|
|
290
|
+
- Monorepo: https://github.com/Emagjby/Strata
|
|
291
|
+
- JS source: https://github.com/Emagjby/Strata/tree/main/strata-js
|
|
292
|
+
|
|
293
|
+
---
|
|
294
|
+
|
|
295
|
+
## License
|
|
296
|
+
|
|
297
|
+
MIT License
|
|
298
|
+
|
|
299
|
+
---
|
|
300
|
+
|
|
301
|
+
## Final note
|
|
302
|
+
|
|
303
|
+
This package is intentionally strict.
|
|
304
|
+
|
|
305
|
+
If convenience matters more than correctness, use something else.
|
|
306
|
+
If correctness matters, this is the JavaScript implementation.
|
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
export { encodeValue } from "./encode.js";
|
|
2
2
|
export { decodeValue } from "./decode.js";
|
|
3
|
-
export { hashBytes as hashValue } from "./hash.js";
|
|
3
|
+
export { hashValueHex, hashBytes as hashValue } from "./hash.js";
|
|
4
4
|
export { parse } from "./parser.js";
|
|
5
|
+
export { Value, V } from "./value_factory.js";
|
|
6
|
+
export { V as ValueFactory } from "./value_factory.js";
|
|
5
7
|
export * from "./value.js";
|
|
6
8
|
export * from "./decode_error.js";
|
|
7
9
|
export * from "./parse_error.js";
|
package/dist/index.d.ts.map
CHANGED
|
@@ -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,SAAS,IAAI,SAAS,EAAE,MAAM,WAAW,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;AAEpC,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
|
@@ -2,8 +2,10 @@
|
|
|
2
2
|
// Intentionally empty for now.
|
|
3
3
|
export { encodeValue } from "./encode.js";
|
|
4
4
|
export { decodeValue } from "./decode.js";
|
|
5
|
-
export { hashBytes as hashValue } from "./hash.js";
|
|
5
|
+
export { hashValueHex, hashBytes as hashValue } from "./hash.js";
|
|
6
6
|
export { parse } from "./parser.js";
|
|
7
|
+
export { Value, V } from "./value_factory.js";
|
|
8
|
+
export { V as ValueFactory } from "./value_factory.js";
|
|
7
9
|
export * from "./value.js";
|
|
8
10
|
export * from "./decode_error.js";
|
|
9
11
|
export * from "./parse_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,SAAS,IAAI,SAAS,EAAE,MAAM,WAAW,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;AAEpC,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/value_factory.d.ts
CHANGED
|
@@ -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
|
|
9
|
-
readonly
|
|
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,
|
|
1
|
+
{"version":3,"file":"value_factory.d.ts","sourceRoot":"","sources":["../src/value_factory.ts"],"names":[],"mappings":"AAAA,OAAO,EACH,KAAK,IAAI,MAAM,EACf,SAAS,EACT,SAAS,EACT,QAAQ,EACR,WAAW,EACX,UAAU,EACV,SAAS,EACT,QAAQ,EACX,MAAM,YAAY,CAAC;AAoCpB,eAAO,MAAM,KAAK;yBACN,SAAS;2BAIL,O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ytesFromIterable(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;
|
|
1
|
+
{"version":3,"file":"value_factory.js","sourceRoot":"","sources":["../src/value_factory.ts"],"names":[],"mappings":"AAWA,SAAS,UAAU,CAAC,CAAS;IACzB,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,GAAG,GAAG,EAAE,CAAC;QAC3C,MAAM,IAAI,SAAS,CAAC,8CAA8C,CAAC,CAAC;IACxE,CAAC;AACL,CAAC;AAED,SAAS,iBAAiB,CAAC,EAAoB;IAC3C,MAAM,GAAG,GAAa,EAAE,CAAC;IACzB,KAAK,MAAM,CAAC,IAAI,EAAE,EAAE,CAAC;QACjB,UAAU,CAAC,CAAC,CAAC,CAAC;QACd,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAChB,CAAC;IACD,OAAO,UAAU,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AAChC,CAAC;AAED,SAAS,kBAAkB,CAAC,GAAW;IACnC,IAAI,OAAO,GAAG,KAAK,QAAQ,EAAE,CAAC;Q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AC;IACpD,CAAC;IAED,MAAM,CAAC,GAA2B;QAC9B,OAAO;YACH,IAAI,EAAE,KAAK;YACX,KAAK,EAAE,IAAI,GAAG,CAAC,MAAM,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;SACtC,CAAC;IACN,CAAC;IAED,KAAK,CAAC,GAAG,OAA2B;QAChC,OAAO,EAAE,IAAI,EAAE,KAAK,EAAE,KAAK,EAAE,IAAI,GAAG,CAAC,OAAO,CAAC,EAAE,CAAC;IACpD,CAAC;CACK,CAAC;AAEX,MAAM,CAAC,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
|
+
"version": "0.4.0",
|
|
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
|
},
|