@elaraai/east-node-std 1.0.69 โ 1.0.71
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/README.md +10 -10
- package/dist/src/fs.d.ts +81 -1
- package/dist/src/fs.d.ts.map +1 -1
- package/dist/src/fs.js +169 -2
- package/dist/src/fs.js.map +1 -1
- package/dist/src/index.d.ts +1 -0
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +4 -0
- package/dist/src/index.js.map +1 -1
- package/dist/src/json.d.ts +191 -0
- package/dist/src/json.d.ts.map +1 -0
- package/dist/src/json.js +265 -0
- package/dist/src/json.js.map +1 -0
- package/dist/src/json_reader.d.ts +153 -0
- package/dist/src/json_reader.d.ts.map +1 -0
- package/dist/src/json_reader.js +1271 -0
- package/dist/src/json_reader.js.map +1 -0
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -9,14 +9,14 @@
|
|
|
9
9
|
|
|
10
10
|
## Features
|
|
11
11
|
|
|
12
|
-
-
|
|
13
|
-
-
|
|
14
|
-
-
|
|
12
|
+
- **File System** - Read/write files, manage directories, open huge beast2 collection files lazily
|
|
13
|
+
- **Console I/O** - stdout/stderr output, stdin input
|
|
14
|
+
- **HTTP Client** - Modern Fetch API for HTTP requests
|
|
15
15
|
- **Cryptography** - Random bytes, SHA-256, UUID generation
|
|
16
|
-
-
|
|
17
|
-
-
|
|
18
|
-
-
|
|
19
|
-
-
|
|
16
|
+
- **Random** - Random number generation with statistical distributions
|
|
17
|
+
- **Time Operations** - Timestamps and sleep
|
|
18
|
+
- **Path Utilities** - Cross-platform path manipulation
|
|
19
|
+
- **Test Framework** - Built-in testing utilities
|
|
20
20
|
- **Type-Safe** - Full TypeScript support with EastError handling
|
|
21
21
|
|
|
22
22
|
## Installation
|
|
@@ -49,17 +49,17 @@ compiled("/path/to/input.txt");
|
|
|
49
49
|
|
|
50
50
|
## Platform Functions
|
|
51
51
|
|
|
52
|
-
East Node provides
|
|
52
|
+
East Node provides these platform modules:
|
|
53
53
|
|
|
54
54
|
| Module | Functions | Description |
|
|
55
55
|
|--------|-----------|-------------|
|
|
56
56
|
| **Console** | `log`, `error`, `write` | Console I/O operations |
|
|
57
|
-
| **FileSystem** | `readFile`, `writeFile`, `exists`, `createDirectory`, etc. | File system operations
|
|
57
|
+
| **FileSystem** | `readFile`, `writeFile`, `exists`, `createDirectory`, `openBeast`, etc. | File system operations, including lazily paged beast2 collection files |
|
|
58
58
|
| **Fetch** | `get`, `post`, `request` | HTTP client using Fetch API |
|
|
59
59
|
| **Crypto** | `randomBytes`, `hashSha256`, `uuid` | Cryptographic operations |
|
|
60
60
|
| **Time** | `now`, `sleep` | Time and delay operations |
|
|
61
61
|
| **Path** | `join`, `resolve`, `dirname`, `basename`, `extname` | Path manipulation |
|
|
62
|
-
| **Random** | `uniform`, `normal`, `range`, `exponential`, `bernoulli`, etc. | Random number generation with
|
|
62
|
+
| **Random** | `uniform`, `normal`, `range`, `exponential`, `bernoulli`, etc. | Random number generation with statistical distributions |
|
|
63
63
|
|
|
64
64
|
**Complete platform:**
|
|
65
65
|
```typescript
|
package/dist/src/fs.d.ts
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* Copyright (c) 2025 Elara AI Pty Ltd
|
|
3
3
|
* Dual-licensed under AGPL-3.0 and commercial license. See LICENSE for details.
|
|
4
4
|
*/
|
|
5
|
-
import { StringType, NullType, BooleanType, ArrayType, BlobType } from "@elaraai/east";
|
|
5
|
+
import { StringType, NullType, BooleanType, ArrayType, BlobType, type SetType, type DictType, type SubtypeExprOrValue, type ExprType } from "@elaraai/east";
|
|
6
6
|
import type { PlatformFunction } from "@elaraai/east/internal";
|
|
7
7
|
/**
|
|
8
8
|
* Reads a file as a UTF-8 string.
|
|
@@ -274,6 +274,50 @@ export declare const fs_read_file_bytes: import("@elaraai/east").PlatformDefinit
|
|
|
274
274
|
* ```
|
|
275
275
|
*/
|
|
276
276
|
export declare const fs_write_file_bytes: import("@elaraai/east").PlatformDefinition<[StringType, BlobType], NullType>;
|
|
277
|
+
/**
|
|
278
|
+
* Opens an indexed beast2 collection file as a frozen, lazily paged value.
|
|
279
|
+
*
|
|
280
|
+
* Generic over the collection type `T` (an `Array`, `Set` or `Dict` type),
|
|
281
|
+
* passed first at the call site as every generic platform call is spelled:
|
|
282
|
+
* `fs_open_beast([T], path)`. The result behaves exactly as `blob.openBeast`'s:
|
|
283
|
+
* `size`, `get`, `has` and a `$.for` loop decode one segment of the file at a
|
|
284
|
+
* time, the value is frozen (mutation is an error, copy first), and a file
|
|
285
|
+
* without a paging index (what `East.Blob.encodeBeast` writes) or whose element
|
|
286
|
+
* shape holds `Ref` or function values decodes whole, frozen. The file's header
|
|
287
|
+
* must carry exactly `T`.
|
|
288
|
+
*
|
|
289
|
+
* The file is paged from the file system on every runtime: east-c and east-py
|
|
290
|
+
* map it, Node reads each segment frame through positioned reads on an open
|
|
291
|
+
* descriptor โ the wire bytes never sit on the heap whole, and only the
|
|
292
|
+
* segments a program touches are ever resident (a Set or Dict file's first
|
|
293
|
+
* keyed read also probes every segment's fence once). The descriptor closes
|
|
294
|
+
* when the value is garbage collected, which is not prompt: a loop opening
|
|
295
|
+
* thousands of files can exhaust descriptors before any are released. Keep
|
|
296
|
+
* the file unchanged while the value is alive โ the other runtimes map it,
|
|
297
|
+
* and a truncated mapping faults. The same program produces the same values
|
|
298
|
+
* on all three.
|
|
299
|
+
*
|
|
300
|
+
* Prefer {@link FileSystem.openBeast}, which checks `T` when the expression is
|
|
301
|
+
* built.
|
|
302
|
+
*
|
|
303
|
+
* @param path - The file path to open (relative or absolute)
|
|
304
|
+
* @returns The frozen collection of type `T`
|
|
305
|
+
*
|
|
306
|
+
* @throws {EastError} When the file cannot be opened as `T`:
|
|
307
|
+
* - File doesn't exist: `Failed to open beast file <path>: ENOENT: no such file or directory`
|
|
308
|
+
* - Header carries another type: `Failed to open beast file <path>: beast2: cannot open a blob of type <wire> as <T>`
|
|
309
|
+
* - Not a beast2 container: `Failed to open beast file <path>: <decode error>`
|
|
310
|
+
*
|
|
311
|
+
* @example
|
|
312
|
+
* ```ts
|
|
313
|
+
* const TableType = DictType(IntegerType, StructType({ id: IntegerType, name: StringType }));
|
|
314
|
+
* const lookup = East.function([StringType], StringType, ($, path) => {
|
|
315
|
+
* const table = $.let(fs_open_beast([TableType], path));
|
|
316
|
+
* return table.get(7n).name; // decodes the one segment holding key 7
|
|
317
|
+
* });
|
|
318
|
+
* ```
|
|
319
|
+
*/
|
|
320
|
+
export declare const fs_open_beast: import("@elaraai/east").GenericPlatformDefinition<readonly ["T"], readonly [StringType], "T">;
|
|
277
321
|
/**
|
|
278
322
|
* Node.js implementation of file system platform functions.
|
|
279
323
|
*
|
|
@@ -509,6 +553,42 @@ export declare const FileSystem: {
|
|
|
509
553
|
* ```
|
|
510
554
|
*/
|
|
511
555
|
readonly writeFileBytes: import("@elaraai/east").PlatformDefinition<[StringType, BlobType], NullType>;
|
|
556
|
+
/**
|
|
557
|
+
* Opens an indexed beast2 collection file as a frozen, lazily paged value.
|
|
558
|
+
*
|
|
559
|
+
* The file-backed twin of `blob.openBeast`: `size`, `get`, `has` and a
|
|
560
|
+
* `$.for` loop decode one segment of the file at a time, the value is
|
|
561
|
+
* frozen, and a file without a paging index (or whose element shape holds
|
|
562
|
+
* `Ref` or function values) decodes whole, frozen. The file's header must
|
|
563
|
+
* carry exactly `type`. Only `Array`, `Set` and `Dict` types are accepted,
|
|
564
|
+
* checked when the expression is built; the same program produces the
|
|
565
|
+
* same values on the east-node, east-c and east-py runners.
|
|
566
|
+
*
|
|
567
|
+
* @typeParam T - The collection type the file was written with
|
|
568
|
+
* @param type - The `Array`, `Set` or `Dict` type to open the file as
|
|
569
|
+
* @param path - The file path to open (relative or absolute)
|
|
570
|
+
* @returns The frozen collection of type `T`
|
|
571
|
+
* @throws {Error} When `type` is not an Array, Set or Dict type (at build time)
|
|
572
|
+
* @throws {EastError} When the file cannot be opened as `type`
|
|
573
|
+
* (`Failed to open beast file <path>: ...`, naming both types on a mismatch)
|
|
574
|
+
*
|
|
575
|
+
* @example
|
|
576
|
+
* ```ts
|
|
577
|
+
* const TableType = DictType(IntegerType, StructType({ id: IntegerType, name: StringType }));
|
|
578
|
+
* const total = East.function([StringType], IntegerType, ($, path) => {
|
|
579
|
+
* const table = $.let(FileSystem.openBeast(TableType, path));
|
|
580
|
+
* const sum = $.let(0n);
|
|
581
|
+
* $.for(table, ($, row) => {
|
|
582
|
+
* $.assign(sum, sum.add(row.id)); // one segment decoded at a time
|
|
583
|
+
* });
|
|
584
|
+
* return sum;
|
|
585
|
+
* });
|
|
586
|
+
*
|
|
587
|
+
* const compiled = East.compile(total, FileSystem.Implementation);
|
|
588
|
+
* compiled("rows.beast2");
|
|
589
|
+
* ```
|
|
590
|
+
*/
|
|
591
|
+
readonly openBeast: <T extends ArrayType | SetType | DictType>(type: T, path: SubtypeExprOrValue<StringType>) => ExprType<T>;
|
|
512
592
|
/**
|
|
513
593
|
* Node.js implementation of file system platform functions.
|
|
514
594
|
*
|
package/dist/src/fs.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fs.d.ts","sourceRoot":"","sources":["../../src/fs.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,
|
|
1
|
+
{"version":3,"file":"fs.d.ts","sourceRoot":"","sources":["../../src/fs.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,EACG,UAAU,EAAE,QAAQ,EAAE,WAAW,EAAE,SAAS,EAAE,QAAQ,EAC5D,KAAK,OAAO,EAAE,KAAK,QAAQ,EAAiB,KAAK,kBAAkB,EAAE,KAAK,QAAQ,EAIrF,MAAM,eAAe,CAAC;AACvB,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAiB/D;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,eAAO,MAAM,YAAY,sEAA0D,CAAC;AAEpF;;;;;;;;;;;;;;;;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;;;;;;OAgBG;;IAGH;;;;;;;;;;;;;;;;OAgBG;;IAGH;;;;;;;;;;;;;;;;OAgBG;;IAGH;;;;;;;;;;;;;;;;;;;;;OAqBG;;IAGH;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAkCG;yBACO,CAAC,SAAS,SAAS,GAAG,OAAO,GAAG,QAAQ,QAAQ,CAAC,QAAQ,kBAAkB,CAAC,UAAU,CAAC,KAAG,QAAQ,CAAC,CAAC,CAAC;IAO/G;;;;OAIG;;CAEG,CAAC;AAGX,OAAO,EAAE,cAAc,EAAE,CAAC"}
|
package/dist/src/fs.js
CHANGED
|
@@ -2,9 +2,9 @@
|
|
|
2
2
|
* Copyright (c) 2025 Elara AI Pty Ltd
|
|
3
3
|
* Dual-licensed under AGPL-3.0 and commercial license. See LICENSE for details.
|
|
4
4
|
*/
|
|
5
|
-
import { East, StringType, NullType, BooleanType, ArrayType, BlobType } from "@elaraai/east";
|
|
5
|
+
import { East, StringType, NullType, BooleanType, ArrayType, BlobType, isTypeValueEqual, printTypeValue, readBeast2Type, readBeast2Extents, isBeast2LazySafe, openBeast2LazyFor, decodeBeast2For, } from "@elaraai/east";
|
|
6
6
|
import { EastError } from "@elaraai/east/internal";
|
|
7
|
-
import { readFileSync, writeFileSync, appendFileSync, unlinkSync, existsSync, statSync, mkdirSync, readdirSync, } from "node:fs";
|
|
7
|
+
import { readFileSync, writeFileSync, appendFileSync, unlinkSync, existsSync, statSync, mkdirSync, readdirSync, openSync, closeSync, fstatSync, readSync, } from "node:fs";
|
|
8
8
|
/**
|
|
9
9
|
* Reads a file as a UTF-8 string.
|
|
10
10
|
*
|
|
@@ -275,6 +275,61 @@ export const fs_read_file_bytes = East.platform("fs_read_file_bytes", [StringTyp
|
|
|
275
275
|
* ```
|
|
276
276
|
*/
|
|
277
277
|
export const fs_write_file_bytes = East.platform("fs_write_file_bytes", [StringType, BlobType], NullType);
|
|
278
|
+
/**
|
|
279
|
+
* Opens an indexed beast2 collection file as a frozen, lazily paged value.
|
|
280
|
+
*
|
|
281
|
+
* Generic over the collection type `T` (an `Array`, `Set` or `Dict` type),
|
|
282
|
+
* passed first at the call site as every generic platform call is spelled:
|
|
283
|
+
* `fs_open_beast([T], path)`. The result behaves exactly as `blob.openBeast`'s:
|
|
284
|
+
* `size`, `get`, `has` and a `$.for` loop decode one segment of the file at a
|
|
285
|
+
* time, the value is frozen (mutation is an error, copy first), and a file
|
|
286
|
+
* without a paging index (what `East.Blob.encodeBeast` writes) or whose element
|
|
287
|
+
* shape holds `Ref` or function values decodes whole, frozen. The file's header
|
|
288
|
+
* must carry exactly `T`.
|
|
289
|
+
*
|
|
290
|
+
* The file is paged from the file system on every runtime: east-c and east-py
|
|
291
|
+
* map it, Node reads each segment frame through positioned reads on an open
|
|
292
|
+
* descriptor โ the wire bytes never sit on the heap whole, and only the
|
|
293
|
+
* segments a program touches are ever resident (a Set or Dict file's first
|
|
294
|
+
* keyed read also probes every segment's fence once). The descriptor closes
|
|
295
|
+
* when the value is garbage collected, which is not prompt: a loop opening
|
|
296
|
+
* thousands of files can exhaust descriptors before any are released. Keep
|
|
297
|
+
* the file unchanged while the value is alive โ the other runtimes map it,
|
|
298
|
+
* and a truncated mapping faults. The same program produces the same values
|
|
299
|
+
* on all three.
|
|
300
|
+
*
|
|
301
|
+
* Prefer {@link FileSystem.openBeast}, which checks `T` when the expression is
|
|
302
|
+
* built.
|
|
303
|
+
*
|
|
304
|
+
* @param path - The file path to open (relative or absolute)
|
|
305
|
+
* @returns The frozen collection of type `T`
|
|
306
|
+
*
|
|
307
|
+
* @throws {EastError} When the file cannot be opened as `T`:
|
|
308
|
+
* - File doesn't exist: `Failed to open beast file <path>: ENOENT: no such file or directory`
|
|
309
|
+
* - Header carries another type: `Failed to open beast file <path>: beast2: cannot open a blob of type <wire> as <T>`
|
|
310
|
+
* - Not a beast2 container: `Failed to open beast file <path>: <decode error>`
|
|
311
|
+
*
|
|
312
|
+
* @example
|
|
313
|
+
* ```ts
|
|
314
|
+
* const TableType = DictType(IntegerType, StructType({ id: IntegerType, name: StringType }));
|
|
315
|
+
* const lookup = East.function([StringType], StringType, ($, path) => {
|
|
316
|
+
* const table = $.let(fs_open_beast([TableType], path));
|
|
317
|
+
* return table.get(7n).name; // decodes the one segment holding key 7
|
|
318
|
+
* });
|
|
319
|
+
* ```
|
|
320
|
+
*/
|
|
321
|
+
export const fs_open_beast = East.genericPlatform("fs_open_beast", ["T"], [StringType], "T");
|
|
322
|
+
/** The descriptors behind lazily opened beast files, closed when their
|
|
323
|
+
* value is collected: the value reads segment frames from the descriptor
|
|
324
|
+
* for its whole life, so nothing shorter-lived may own it. */
|
|
325
|
+
const openBeastFiles = new FinalizationRegistry((fd) => {
|
|
326
|
+
try {
|
|
327
|
+
closeSync(fd);
|
|
328
|
+
}
|
|
329
|
+
catch {
|
|
330
|
+
// Already closed โ nothing else to release.
|
|
331
|
+
}
|
|
332
|
+
});
|
|
278
333
|
/**
|
|
279
334
|
* Node.js implementation of file system platform functions.
|
|
280
335
|
*
|
|
@@ -389,6 +444,77 @@ const FileSystemImpl = [
|
|
|
389
444
|
});
|
|
390
445
|
}
|
|
391
446
|
}),
|
|
447
|
+
fs_open_beast.implement((T) => {
|
|
448
|
+
// The decoders are built once per type argument, the whole one on
|
|
449
|
+
// first use (a paged file never needs it). The lazy open is reserved
|
|
450
|
+
// for the element shapes it can serve frozen; anything else takes
|
|
451
|
+
// the whole frozen decode, as blob.openBeast does.
|
|
452
|
+
let whole = null;
|
|
453
|
+
const lazy = isBeast2LazySafe(T, { frozen: true }) ? openBeast2LazyFor(T, { frozen: true }) : null;
|
|
454
|
+
return (path) => {
|
|
455
|
+
const file = path;
|
|
456
|
+
let fd = -1;
|
|
457
|
+
try {
|
|
458
|
+
fd = openSync(file, "r");
|
|
459
|
+
const handle = fd;
|
|
460
|
+
const reader = {
|
|
461
|
+
size: fstatSync(handle).size,
|
|
462
|
+
read(offset, length) {
|
|
463
|
+
const out = new Uint8Array(length);
|
|
464
|
+
let done = 0;
|
|
465
|
+
while (done < length) {
|
|
466
|
+
const n = readSync(handle, out, done, length - done, offset + done);
|
|
467
|
+
if (n === 0)
|
|
468
|
+
throw new Error(`beast2: short read at offset ${offset + done}`);
|
|
469
|
+
done += n;
|
|
470
|
+
}
|
|
471
|
+
return out;
|
|
472
|
+
},
|
|
473
|
+
};
|
|
474
|
+
// An indexed collection file pages from the descriptor: the
|
|
475
|
+
// open reads its tail and head, and a program's reads fetch
|
|
476
|
+
// the segment frames they decode.
|
|
477
|
+
let extents = null;
|
|
478
|
+
try {
|
|
479
|
+
extents = readBeast2Extents(reader);
|
|
480
|
+
}
|
|
481
|
+
catch {
|
|
482
|
+
extents = null;
|
|
483
|
+
}
|
|
484
|
+
if (extents !== null) {
|
|
485
|
+
if (!isTypeValueEqual(extents.typeValue, T)) {
|
|
486
|
+
throw new Error(`beast2: cannot open a blob of type ${printTypeValue(extents.typeValue)} as ${printTypeValue(T)}`);
|
|
487
|
+
}
|
|
488
|
+
if (lazy !== null && extents.selfContained) {
|
|
489
|
+
const value = lazy(reader);
|
|
490
|
+
openBeastFiles.register(value, handle);
|
|
491
|
+
fd = -1; // the value owns the descriptor from here
|
|
492
|
+
return value;
|
|
493
|
+
}
|
|
494
|
+
}
|
|
495
|
+
// Not pageable (index-less, or a gated element shape): the
|
|
496
|
+
// whole frozen decode from one read of the file. Both
|
|
497
|
+
// container versions name their type in the header.
|
|
498
|
+
const data = reader.read(0, reader.size);
|
|
499
|
+
const wire = readBeast2Type(data);
|
|
500
|
+
if (!isTypeValueEqual(wire, T)) {
|
|
501
|
+
throw new Error(`beast2: cannot open a blob of type ${printTypeValue(wire)} as ${printTypeValue(T)}`);
|
|
502
|
+
}
|
|
503
|
+
whole ??= decodeBeast2For(T, { frozen: true });
|
|
504
|
+
return whole(data);
|
|
505
|
+
}
|
|
506
|
+
catch (err) {
|
|
507
|
+
throw new EastError(`Failed to open beast file ${file}: ${err.message}`, {
|
|
508
|
+
location: [{ filename: "fs_open_beast", line: 0n, column: 0n }],
|
|
509
|
+
cause: err
|
|
510
|
+
});
|
|
511
|
+
}
|
|
512
|
+
finally {
|
|
513
|
+
if (fd >= 0)
|
|
514
|
+
closeSync(fd);
|
|
515
|
+
}
|
|
516
|
+
};
|
|
517
|
+
}),
|
|
392
518
|
];
|
|
393
519
|
/**
|
|
394
520
|
* Grouped file system platform functions.
|
|
@@ -619,6 +745,47 @@ export const FileSystem = {
|
|
|
619
745
|
* ```
|
|
620
746
|
*/
|
|
621
747
|
writeFileBytes: fs_write_file_bytes,
|
|
748
|
+
/**
|
|
749
|
+
* Opens an indexed beast2 collection file as a frozen, lazily paged value.
|
|
750
|
+
*
|
|
751
|
+
* The file-backed twin of `blob.openBeast`: `size`, `get`, `has` and a
|
|
752
|
+
* `$.for` loop decode one segment of the file at a time, the value is
|
|
753
|
+
* frozen, and a file without a paging index (or whose element shape holds
|
|
754
|
+
* `Ref` or function values) decodes whole, frozen. The file's header must
|
|
755
|
+
* carry exactly `type`. Only `Array`, `Set` and `Dict` types are accepted,
|
|
756
|
+
* checked when the expression is built; the same program produces the
|
|
757
|
+
* same values on the east-node, east-c and east-py runners.
|
|
758
|
+
*
|
|
759
|
+
* @typeParam T - The collection type the file was written with
|
|
760
|
+
* @param type - The `Array`, `Set` or `Dict` type to open the file as
|
|
761
|
+
* @param path - The file path to open (relative or absolute)
|
|
762
|
+
* @returns The frozen collection of type `T`
|
|
763
|
+
* @throws {Error} When `type` is not an Array, Set or Dict type (at build time)
|
|
764
|
+
* @throws {EastError} When the file cannot be opened as `type`
|
|
765
|
+
* (`Failed to open beast file <path>: ...`, naming both types on a mismatch)
|
|
766
|
+
*
|
|
767
|
+
* @example
|
|
768
|
+
* ```ts
|
|
769
|
+
* const TableType = DictType(IntegerType, StructType({ id: IntegerType, name: StringType }));
|
|
770
|
+
* const total = East.function([StringType], IntegerType, ($, path) => {
|
|
771
|
+
* const table = $.let(FileSystem.openBeast(TableType, path));
|
|
772
|
+
* const sum = $.let(0n);
|
|
773
|
+
* $.for(table, ($, row) => {
|
|
774
|
+
* $.assign(sum, sum.add(row.id)); // one segment decoded at a time
|
|
775
|
+
* });
|
|
776
|
+
* return sum;
|
|
777
|
+
* });
|
|
778
|
+
*
|
|
779
|
+
* const compiled = East.compile(total, FileSystem.Implementation);
|
|
780
|
+
* compiled("rows.beast2");
|
|
781
|
+
* ```
|
|
782
|
+
*/
|
|
783
|
+
openBeast(type, path) {
|
|
784
|
+
if (type.type !== "Array" && type.type !== "Set" && type.type !== "Dict") {
|
|
785
|
+
throw new Error(`FileSystem.openBeast opens Array, Set or Dict files, not ${type.type} โ read the bytes with FileSystem.readFileBytes and decodeBeast for other types`);
|
|
786
|
+
}
|
|
787
|
+
return fs_open_beast([type], path);
|
|
788
|
+
},
|
|
622
789
|
/**
|
|
623
790
|
* Node.js implementation of file system platform functions.
|
|
624
791
|
*
|
package/dist/src/fs.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fs.js","sourceRoot":"","sources":["../../src/fs.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,
|
|
1
|
+
{"version":3,"file":"fs.js","sourceRoot":"","sources":["../../src/fs.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,EACH,IAAI,EAAE,UAAU,EAAE,QAAQ,EAAE,WAAW,EAAE,SAAS,EAAE,QAAQ,EAG5D,gBAAgB,EAAE,cAAc,EAChC,cAAc,EAAE,iBAAiB,EAAE,gBAAgB,EAAE,iBAAiB,EAAE,eAAe,GAC1F,MAAM,eAAe,CAAC;AAEvB,OAAO,EAAE,SAAS,EAAE,MAAM,wBAAwB,CAAC;AACnD,OAAO,EACH,YAAY,EACZ,aAAa,EACb,cAAc,EACd,UAAU,EACV,UAAU,EACV,QAAQ,EACR,SAAS,EACT,WAAW,EACX,QAAQ,EACR,SAAS,EACT,SAAS,EACT,QAAQ,GACX,MAAM,SAAS,CAAC;AAEjB;;;;;;;;;;;;;;;;;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C;;;;;;;;;;;;;;;;OAgBG;IACH,aAAa,EAAE,iBAAiB;IAEhC;;;;;;;;;;;;;;;;OAgBG;IACH,aAAa,EAAE,kBAAkB;IAEjC;;;;;;;;;;;;;;;;;;;;;OAqBG;IACH,cAAc,EAAE,mBAAmB;IAEnC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAkCG;IACH,SAAS,CAA2C,IAAO,EAAE,IAAoC;QAC7F,IAAI,IAAI,CAAC,IAAI,KAAK,OAAO,IAAI,IAAI,CAAC,IAAI,KAAK,KAAK,IAAI,IAAI,CAAC,IAAI,KAAK,MAAM,EAAE,CAAC;YACvE,MAAM,IAAI,KAAK,CAAC,4DAA6D,IAAiB,CAAC,IAAI,iFAAiF,CAAC,CAAC;QAC1L,CAAC;QACD,OAAO,aAAa,CAAC,CAAC,IAAI,CAAC,EAAE,IAAI,CAAgB,CAAC;IACtD,CAAC;IAED;;;;OAIG;IACH,cAAc,EAAE,cAAc;CACxB,CAAC;AAEX,qCAAqC;AACrC,OAAO,EAAE,cAAc,EAAE,CAAC"}
|
package/dist/src/index.d.ts
CHANGED
package/dist/src/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH;;;;GAIG;AAGH,cAAc,WAAW,CAAC;AAG1B,cAAc,cAAc,CAAC;AAC7B,cAAc,UAAU,CAAC;AACzB,cAAc,SAAS,CAAC;AACxB,cAAc,WAAW,CAAC;AAC1B,cAAc,aAAa,CAAC;AAC5B,cAAc,WAAW,CAAC;AAC1B,cAAc,YAAY,CAAC;AAC3B,cAAc,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH;;;;GAIG;AAGH,cAAc,WAAW,CAAC;AAG1B,cAAc,cAAc,CAAC;AAC7B,cAAc,UAAU,CAAC;AACzB,cAAc,SAAS,CAAC;AACxB,cAAc,WAAW,CAAC;AAC1B,cAAc,aAAa,CAAC;AAC5B,cAAc,WAAW,CAAC;AAC1B,cAAc,YAAY,CAAC;AAC3B,cAAc,aAAa,CAAC;AAC5B,cAAc,WAAW,CAAC;AAc1B;;;;;;;;;;;;;;;;;;;GAmBG;AACH,eAAO,MAAM,YAAY,qDAWxB,CAAC;AAEF;;;;;;;;;;;;;;;;;GAiBG;AACH,eAAO,MAAM,gBAAgB,qDAU5B,CAAC;AAGF,OAAO,KAAK,QAAQ,MAAM,YAAY,CAAC"}
|
package/dist/src/index.js
CHANGED
|
@@ -18,6 +18,7 @@ export * from "./crypto.js";
|
|
|
18
18
|
export * from "./time.js";
|
|
19
19
|
export * from "./fetch.js";
|
|
20
20
|
export * from "./random.js";
|
|
21
|
+
export * from "./json.js";
|
|
21
22
|
// Import implementations for combined export
|
|
22
23
|
import { ConsoleImpl } from "./console.js";
|
|
23
24
|
import { EnvImpl } from "./env.js";
|
|
@@ -27,6 +28,7 @@ import { CryptoImpl } from "./crypto.js";
|
|
|
27
28
|
import { TimeImpl } from "./time.js";
|
|
28
29
|
import { FetchImpl } from "./fetch.js";
|
|
29
30
|
import { RandomImpl } from "./random.js";
|
|
31
|
+
import { JsonImpl } from "./json.js";
|
|
30
32
|
import { TestImpl } from "./test.js";
|
|
31
33
|
/**
|
|
32
34
|
* Complete Node.js platform implementation.
|
|
@@ -57,6 +59,7 @@ export const NodePlatform = [
|
|
|
57
59
|
...TimeImpl,
|
|
58
60
|
...FetchImpl,
|
|
59
61
|
...RandomImpl,
|
|
62
|
+
...JsonImpl,
|
|
60
63
|
...TestImpl,
|
|
61
64
|
];
|
|
62
65
|
/**
|
|
@@ -84,6 +87,7 @@ export const NodePlatformSync = [
|
|
|
84
87
|
...PathImpl,
|
|
85
88
|
...CryptoImpl,
|
|
86
89
|
...RandomImpl,
|
|
90
|
+
...JsonImpl,
|
|
87
91
|
// TimeImpl excluded (has async sleep)
|
|
88
92
|
// FetchImpl excluded (all async)
|
|
89
93
|
];
|
package/dist/src/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH;;;;GAIG;AAEH,wBAAwB;AACxB,cAAc,WAAW,CAAC;AAE1B,2DAA2D;AAC3D,cAAc,cAAc,CAAC;AAC7B,cAAc,UAAU,CAAC;AACzB,cAAc,SAAS,CAAC;AACxB,cAAc,WAAW,CAAC;AAC1B,cAAc,aAAa,CAAC;AAC5B,cAAc,WAAW,CAAC;AAC1B,cAAc,YAAY,CAAC;AAC3B,cAAc,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH;;;;GAIG;AAEH,wBAAwB;AACxB,cAAc,WAAW,CAAC;AAE1B,2DAA2D;AAC3D,cAAc,cAAc,CAAC;AAC7B,cAAc,UAAU,CAAC;AACzB,cAAc,SAAS,CAAC;AACxB,cAAc,WAAW,CAAC;AAC1B,cAAc,aAAa,CAAC;AAC5B,cAAc,WAAW,CAAC;AAC1B,cAAc,YAAY,CAAC;AAC3B,cAAc,aAAa,CAAC;AAC5B,cAAc,WAAW,CAAC;AAE1B,6CAA6C;AAC7C,OAAO,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAC3C,OAAO,EAAE,OAAO,EAAE,MAAM,UAAU,CAAC;AACnC,OAAO,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AACzC,OAAO,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AACrC,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AACrC,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AACvC,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AACrC,OAAO,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AAErC;;;;;;;;;;;;;;;;;;;GAmBG;AACH,MAAM,CAAC,MAAM,YAAY,GAAG;IACxB,GAAG,WAAW;IACd,GAAG,OAAO;IACV,GAAG,cAAc;IACjB,GAAG,QAAQ;IACX,GAAG,UAAU;IACb,GAAG,QAAQ;IACX,GAAG,SAAS;IACZ,GAAG,UAAU;IACb,GAAG,QAAQ;IACX,GAAG,QAAQ;CACd,CAAC;AAEF;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAM,CAAC,MAAM,gBAAgB,GAAG;IAC5B,GAAG,WAAW;IACd,GAAG,OAAO;IACV,GAAG,cAAc;IACjB,GAAG,QAAQ;IACX,GAAG,UAAU;IACb,GAAG,UAAU;IACb,GAAG,QAAQ;IACX,sCAAsC;IACtC,iCAAiC;CACpC,CAAC;AAEF,oFAAoF;AACpF,OAAO,KAAK,QAAQ,MAAM,YAAY,CAAC"}
|
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2025 Elara AI Pty Ltd
|
|
3
|
+
* Dual-licensed under AGPL-3.0 and commercial license. See LICENSE for details.
|
|
4
|
+
*/
|
|
5
|
+
import { StringType, NullType, BooleanType, type EastType, type SubtypeExprOrValue, type ExprType } from "@elaraai/east";
|
|
6
|
+
import type { PlatformFunction } from "@elaraai/east/internal";
|
|
7
|
+
/**
|
|
8
|
+
* Opens a JSON file and positions a reader on the array or object to iterate.
|
|
9
|
+
*
|
|
10
|
+
* @param path - The file to read
|
|
11
|
+
* @param pointer - RFC 6901 pointer to the container, `""` for the whole document
|
|
12
|
+
* @returns An opaque handle
|
|
13
|
+
*
|
|
14
|
+
* @throws {EastError} When the file cannot be opened, the pointer does not
|
|
15
|
+
* resolve, or the node it names is not an array or object
|
|
16
|
+
*
|
|
17
|
+
* @remarks
|
|
18
|
+
* The document is never held: the reader pulls one chunk of text at a time and
|
|
19
|
+
* constructs one value per {@link json_next}. Reading past the container is
|
|
20
|
+
* skipping, not parsing, so a pointer naming a small envelope member costs a
|
|
21
|
+
* scan and nothing more.
|
|
22
|
+
*/
|
|
23
|
+
export declare const json_open: import("@elaraai/east").PlatformDefinition<[StringType, StringType], StringType>;
|
|
24
|
+
/**
|
|
25
|
+
* Opens an in-memory JSON payload, as {@link json_open} opens a file.
|
|
26
|
+
*
|
|
27
|
+
* @param text - The document
|
|
28
|
+
* @param pointer - RFC 6901 pointer to the container, `""` for the whole document
|
|
29
|
+
* @returns An opaque handle
|
|
30
|
+
*
|
|
31
|
+
* @remarks
|
|
32
|
+
* The same reader over a string, so a request body and a multi-gigabyte file
|
|
33
|
+
* are read by one implementation and held to one definition of strict.
|
|
34
|
+
*/
|
|
35
|
+
export declare const json_open_text: import("@elaraai/east").PlatformDefinition<[StringType, StringType], StringType>;
|
|
36
|
+
/**
|
|
37
|
+
* Whether the container being iterated has another element.
|
|
38
|
+
*
|
|
39
|
+
* @param handle - A handle from {@link json_open} or {@link json_open_text}
|
|
40
|
+
* @returns True while elements remain
|
|
41
|
+
*
|
|
42
|
+
* @throws {EastError} When the handle is not open, or the document is malformed
|
|
43
|
+
*
|
|
44
|
+
* @remarks
|
|
45
|
+
* A predicate, not an advance: {@link json_next} moves the cursor, so the two
|
|
46
|
+
* need not alternate and asking twice is harmless.
|
|
47
|
+
*/
|
|
48
|
+
export declare const json_more: import("@elaraai/east").PlatformDefinition<[StringType], BooleanType>;
|
|
49
|
+
/**
|
|
50
|
+
* Reads the next element of the container as `T`.
|
|
51
|
+
*
|
|
52
|
+
* @param handle - A handle from {@link json_open} or {@link json_open_text}
|
|
53
|
+
* @returns The decoded value
|
|
54
|
+
*
|
|
55
|
+
* @throws {EastError} When the element does not satisfy `T` under East JSON's
|
|
56
|
+
* encoding, naming the RFC 6901 pointer of the offending node
|
|
57
|
+
*
|
|
58
|
+
* @remarks
|
|
59
|
+
* Strict: it accepts exactly what `jsonSchemaFor(T)` describes, which is what
|
|
60
|
+
* the ENCODER emits rather than what the historic decoder tolerated. An
|
|
61
|
+
* integer must be a quoted decimal in i64 range โ not `"0x10"`, not `" 7 "`,
|
|
62
|
+
* not `"007"`; a timestamp must carry an explicit `+00:00`, not `Z` and not a
|
|
63
|
+
* numeric offset; a blob's hex must be lowercase.
|
|
64
|
+
*
|
|
65
|
+
* When the container is a JSON object, `T` must be a `Struct` of exactly `key`
|
|
66
|
+
* and `value`, in either order, and each member arrives as one of those โ
|
|
67
|
+
* which is what a `Dict` output needs. An error inside an element is located
|
|
68
|
+
* by its index in an array and by its member name in an object, and reads
|
|
69
|
+
* word for word as it does on east-c and east-py.
|
|
70
|
+
*/
|
|
71
|
+
export declare const json_next: import("@elaraai/east").GenericPlatformDefinition<readonly ["T"], readonly [StringType], "T">;
|
|
72
|
+
/**
|
|
73
|
+
* Reads one whole value from a file, without iterating.
|
|
74
|
+
*
|
|
75
|
+
* @param path - The file to read
|
|
76
|
+
* @param pointer - RFC 6901 pointer to the value
|
|
77
|
+
* @returns The decoded value
|
|
78
|
+
*
|
|
79
|
+
* @throws {EastError} When the file cannot be read, the pointer does not
|
|
80
|
+
* resolve, or the value does not satisfy `T`
|
|
81
|
+
*
|
|
82
|
+
* @remarks
|
|
83
|
+
* For the small parts of a document whose large parts are streamed โ an
|
|
84
|
+
* envelope's metadata beside a ten-million-row array. Everything outside the
|
|
85
|
+
* pointer is skipped rather than constructed.
|
|
86
|
+
*/
|
|
87
|
+
export declare const json_value: import("@elaraai/east").GenericPlatformDefinition<readonly ["T"], readonly [StringType, StringType], "T">;
|
|
88
|
+
/**
|
|
89
|
+
* Closes a reader and releases its file descriptor.
|
|
90
|
+
*
|
|
91
|
+
* @param handle - A handle from {@link json_open} or {@link json_open_text}
|
|
92
|
+
* @returns Null
|
|
93
|
+
*
|
|
94
|
+
* @remarks
|
|
95
|
+
* Handles are held until closed, as a database connection is. A body that can
|
|
96
|
+
* fail mid-document should close in a `.catch` that re-raises, since a `$.try`
|
|
97
|
+
* whose `.catch` is left implicit swallows the error.
|
|
98
|
+
*/
|
|
99
|
+
export declare const json_close: import("@elaraai/east").PlatformDefinition<[StringType], NullType>;
|
|
100
|
+
/** Node.js implementation of the JSON reader platform functions. */
|
|
101
|
+
declare const JsonImpl: PlatformFunction[];
|
|
102
|
+
/**
|
|
103
|
+
* Reading JSON documents that do not fit in memory.
|
|
104
|
+
*
|
|
105
|
+
* @remarks
|
|
106
|
+
* The ingest half of the contract boundary: `jsonSchemaFor(T)` publishes what a
|
|
107
|
+
* producer must send, and these read it back under exactly that contract. One
|
|
108
|
+
* element is in flight at a time, whatever the document's size, so the natural
|
|
109
|
+
* home is an `e3.streamTask` producer that emits as it reads.
|
|
110
|
+
*
|
|
111
|
+
* @example
|
|
112
|
+
* ```ts
|
|
113
|
+
* const rows = e3.streamTask('rows', {
|
|
114
|
+
* inputs: [path],
|
|
115
|
+
* output: ArrayType(RowType),
|
|
116
|
+
* }, ($, p, emit) => {
|
|
117
|
+
* const handle = $.let(Json.open(p, "/data"));
|
|
118
|
+
* $.while(Json.more(handle), $ => {
|
|
119
|
+
* $(emit(Json.next(RowType, handle)));
|
|
120
|
+
* });
|
|
121
|
+
* $(Json.close(handle));
|
|
122
|
+
* });
|
|
123
|
+
* ```
|
|
124
|
+
*/
|
|
125
|
+
export declare const Json: {
|
|
126
|
+
/**
|
|
127
|
+
* Opens a JSON file and positions a reader on the container to iterate.
|
|
128
|
+
*
|
|
129
|
+
* @param path - The file to read
|
|
130
|
+
* @param pointer - RFC 6901 pointer to the container, `""` for the whole document
|
|
131
|
+
* @returns An opaque handle
|
|
132
|
+
* @throws {EastError} When the file cannot be opened or the pointer does not resolve
|
|
133
|
+
*/
|
|
134
|
+
readonly open: import("@elaraai/east").PlatformDefinition<[StringType, StringType], StringType>;
|
|
135
|
+
/**
|
|
136
|
+
* Opens an in-memory payload, as {@link Json.open} opens a file.
|
|
137
|
+
*
|
|
138
|
+
* @param text - The document
|
|
139
|
+
* @param pointer - RFC 6901 pointer to the container, `""` for the whole document
|
|
140
|
+
* @returns An opaque handle
|
|
141
|
+
* @throws {EastError} When the pointer does not resolve
|
|
142
|
+
*/
|
|
143
|
+
readonly openText: import("@elaraai/east").PlatformDefinition<[StringType, StringType], StringType>;
|
|
144
|
+
/**
|
|
145
|
+
* Whether the container has another element.
|
|
146
|
+
*
|
|
147
|
+
* @param handle - A handle from {@link Json.open} or {@link Json.openText}
|
|
148
|
+
* @returns True while elements remain
|
|
149
|
+
*/
|
|
150
|
+
readonly more: import("@elaraai/east").PlatformDefinition<[StringType], BooleanType>;
|
|
151
|
+
/**
|
|
152
|
+
* Reads the next element as `type`.
|
|
153
|
+
*
|
|
154
|
+
* @typeParam T - The element's East type
|
|
155
|
+
* @param type - The type to decode the element as
|
|
156
|
+
* @param handle - A handle from {@link Json.open} or {@link Json.openText}
|
|
157
|
+
* @returns The decoded element
|
|
158
|
+
* @throws {Error} When `type` has no JSON form (at build time)
|
|
159
|
+
* @throws {EastError} When the element does not satisfy `type`, naming the
|
|
160
|
+
* RFC 6901 pointer of the offending node
|
|
161
|
+
*/
|
|
162
|
+
readonly next: <T extends EastType>(type: T, handle: SubtypeExprOrValue<StringType>) => ExprType<T>;
|
|
163
|
+
/**
|
|
164
|
+
* Reads one whole value from a file without iterating.
|
|
165
|
+
*
|
|
166
|
+
* @typeParam T - The value's East type
|
|
167
|
+
* @param type - The type to decode the value as
|
|
168
|
+
* @param path - The file to read
|
|
169
|
+
* @param pointer - RFC 6901 pointer to the value
|
|
170
|
+
* @returns The decoded value
|
|
171
|
+
* @throws {Error} When `type` has no JSON form (at build time)
|
|
172
|
+
* @throws {EastError} When the value does not satisfy `type`
|
|
173
|
+
*/
|
|
174
|
+
readonly value: <T extends EastType>(type: T, path: SubtypeExprOrValue<StringType>, pointer: SubtypeExprOrValue<StringType>) => ExprType<T>;
|
|
175
|
+
/**
|
|
176
|
+
* Closes a reader and releases its file descriptor.
|
|
177
|
+
*
|
|
178
|
+
* @param handle - A handle from {@link Json.open} or {@link Json.openText}
|
|
179
|
+
* @returns Null
|
|
180
|
+
*/
|
|
181
|
+
readonly close: import("@elaraai/east").PlatformDefinition<[StringType], NullType>;
|
|
182
|
+
/**
|
|
183
|
+
* Node.js implementation of the JSON reader platform functions.
|
|
184
|
+
*
|
|
185
|
+
* Pass this to {@link East.compile} to enable them.
|
|
186
|
+
*/
|
|
187
|
+
readonly Implementation: PlatformFunction[];
|
|
188
|
+
};
|
|
189
|
+
export { JsonImpl };
|
|
190
|
+
export { JsonReadError } from "./json_reader.js";
|
|
191
|
+
//# sourceMappingURL=json.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"json.d.ts","sourceRoot":"","sources":["../../src/json.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,EACG,UAAU,EAAE,QAAQ,EAAE,WAAW,EACvC,KAAK,QAAQ,EAAE,KAAK,kBAAkB,EAAE,KAAK,QAAQ,EAExD,MAAM,eAAe,CAAC;AACvB,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAuC/D;;;;;;;;;;;;;;;GAeG;AACH,eAAO,MAAM,SAAS,kFAAmE,CAAC;AAE1F;;;;;;;;;;GAUG;AACH,eAAO,MAAM,cAAc,kFAAwE,CAAC;AAEpG;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,SAAS,uEAAwD,CAAC;AAE/E;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,eAAO,MAAM,SAAS,+FAA8D,CAAC;AAErF;;;;;;;;;;;;;;GAcG;AACH,eAAO,MAAM,UAAU,2GAA2E,CAAC;AAEnG;;;;;;;;;;GAUG;AACH,eAAO,MAAM,UAAU,oEAAsD,CAAC;AAE9E,oEAAoE;AACpE,QAAA,MAAM,QAAQ,EAAE,gBAAgB,EAqC/B,CAAC;AASF;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,eAAO,MAAM,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