Skip to content

Commit 0529f91

Browse files
authored
Merge pull request #36 from link-foundation/issue-35-03946ff48852
feat(js): support readable recursive indented data
2 parents 5f88dcb + a9ad369 commit 0529f91

8 files changed

Lines changed: 823 additions & 157 deletions

File tree

.gitkeep

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# .gitkeep file auto-generated at 2026-05-10T19:22:27.543Z for PR creation at branch issue-35-03946ff48852 for issue https://github.com/link-foundation/lino-objects-codec/issues/35

README.md

Lines changed: 36 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -73,13 +73,13 @@ npm install lino-objects-codec
7373
```
7474

7575
```javascript
76-
import { encode, decode } from 'lino-objects-codec';
76+
import { formatIndented, parseIndented } from "lino-objects-codec";
7777

78-
// Encode and decode
79-
const data = { name: 'Alice', age: 30, active: true };
80-
const encoded = encode(data);
81-
const decoded = decode(encoded);
82-
console.log(JSON.stringify(decoded) === JSON.stringify(data)); // true
78+
// Readable indented Links Notation for repository data
79+
const data = { name: "Alice", age: 30, active: true };
80+
const text = formatIndented({ id: "obj_root", obj: data });
81+
const { obj } = parseIndented({ text });
82+
console.log(JSON.stringify(obj) === JSON.stringify(data)); // true
8383
```
8484

8585
### Rust
@@ -166,6 +166,7 @@ All implementations support the same features with language-appropriate syntax:
166166
### Circular References
167167

168168
**Python:**
169+
169170
```python
170171
from link_notation_objects_codec import encode, decode
171172

@@ -177,8 +178,9 @@ assert decoded[3] is decoded # Reference preserved
177178
```
178179

179180
**JavaScript:**
181+
180182
```javascript
181-
import { encode, decode } from 'lino-objects-codec';
183+
import { encode, decode } from "lino-objects-codec";
182184

183185
// Self-referencing array
184186
const arr = [1, 2, 3];
@@ -188,6 +190,7 @@ console.log(decoded[3] === decoded); // true - Reference preserved
188190
```
189191

190192
**Rust:**
193+
191194
```rust
192195
use lino_objects_codec::{encode, decode, LinoValue};
193196

@@ -199,6 +202,7 @@ let decoded = decode(&encoded).unwrap();
199202
```
200203

201204
**C#:**
205+
202206
```csharp
203207
using Lino.Objects.Codec;
204208

@@ -212,6 +216,7 @@ Console.WriteLine(ReferenceEquals(decoded, decoded?[0])); // True - Reference pr
212216
### Complex Nested Structures
213217

214218
**Python:**
219+
215220
```python
216221
data = {
217222
"users": [
@@ -224,18 +229,20 @@ assert decode(encode(data)) == data
224229
```
225230

226231
**JavaScript:**
232+
227233
```javascript
228234
const data = {
229235
users: [
230-
{ id: 1, name: 'Alice' },
231-
{ id: 2, name: 'Bob' }
236+
{ id: 1, name: "Alice" },
237+
{ id: 2, name: "Bob" },
232238
],
233-
metadata: { version: 1, count: 2 }
239+
metadata: { version: 1, count: 2 },
234240
};
235241
console.log(JSON.stringify(decode(encode(data))) === JSON.stringify(data));
236242
```
237243

238244
**Rust:**
245+
239246
```rust
240247
use lino_objects_codec::{encode, decode, LinoValue};
241248

@@ -253,6 +260,7 @@ assert_eq!(decode(&encode(&data)).unwrap(), data);
253260
```
254261

255262
**C#:**
263+
256264
```csharp
257265
var data = new Dictionary<string, object?>
258266
{
@@ -273,27 +281,34 @@ var decoded = Codec.Decode(Codec.Encode(data));
273281
The indented format provides a human-readable representation for displaying objects:
274282

275283
**JavaScript:**
284+
276285
```javascript
277-
import { formatIndented, parseIndented } from 'lino-objects-codec';
286+
import { formatIndented, parseIndented } from "lino-objects-codec";
278287

279288
// Format an object with an identifier
280289
const formatted = formatIndented({
281-
id: '6dcf4c1b-ff3f-482c-95ab-711ea7d1b019',
282-
obj: { uuid: '6dcf4c1b-ff3f-482c-95ab-711ea7d1b019', status: 'executed', command: 'echo test', exitCode: '0' }
290+
id: "6dcf4c1b-ff3f-482c-95ab-711ea7d1b019",
291+
obj: {
292+
uuid: "6dcf4c1b-ff3f-482c-95ab-711ea7d1b019",
293+
status: "executed",
294+
command: "echo test",
295+
exitCode: "0",
296+
},
283297
});
284298
console.log(formatted);
285299
// Output:
286-
// 6dcf4c1b-ff3f-482c-95ab-711ea7d1b019
287-
// uuid "6dcf4c1b-ff3f-482c-95ab-711ea7d1b019"
288-
// status "executed"
289-
// command "echo test"
290-
// exitCode "0"
300+
// 6dcf4c1b-ff3f-482c-95ab-711ea7d1b019:
301+
// uuid '6dcf4c1b-ff3f-482c-95ab-711ea7d1b019'
302+
// status executed
303+
// command 'echo test'
304+
// exitCode '0'
291305

292306
// Parse it back
293307
const { id, obj } = parseIndented({ text: formatted });
294308
```
295309

296310
**Python:**
311+
297312
```python
298313
from link_notation_objects_codec import format_indented, parse_indented
299314

@@ -308,6 +323,7 @@ id, obj = parse_indented(formatted)
308323
```
309324

310325
**Rust:**
326+
311327
```rust
312328
use lino_objects_codec::format::{format_indented_ordered, parse_indented};
313329

@@ -320,6 +336,7 @@ let (id, obj) = parse_indented(&formatted).unwrap();
320336
```
321337

322338
**C#:**
339+
323340
```csharp
324341
using Lino.Objects.Codec;
325342

@@ -345,6 +362,7 @@ The library uses the [links-notation](https://github.com/link-foundation/links-n
345362
- Circular references use direct object ID references: `obj_0` (without the `ref` keyword)
346363

347364
This approach allows for:
365+
348366
- Universal representation of object graphs
349367
- Preservation of object identity
350368
- Natural handling of circular references using built-in links notation syntax
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'lino-objects-codec': minor
3+
---
4+
5+
Add recursive readable indented object formatting and parsing for untyped repository data.

0 commit comments

Comments
 (0)