@elaraai/east-node-std 0.0.1-beta.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/CLA.md +26 -0
- package/CONTRIBUTING.md +28 -0
- package/README.md +135 -0
- package/dist/console.d.ts +192 -0
- package/dist/console.d.ts.map +1 -0
- package/dist/console.js +228 -0
- package/dist/console.js.map +1 -0
- package/dist/crypto.d.ts +212 -0
- package/dist/crypto.d.ts.map +1 -0
- package/dist/crypto.js +259 -0
- package/dist/crypto.js.map +1 -0
- package/dist/fetch.d.ts +310 -0
- package/dist/fetch.d.ts.map +1 -0
- package/dist/fetch.js +336 -0
- package/dist/fetch.js.map +1 -0
- package/dist/fs.d.ts +520 -0
- package/dist/fs.d.ts.map +1 -0
- package/dist/fs.js +630 -0
- package/dist/fs.js.map +1 -0
- package/dist/index.d.ts +59 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +86 -0
- package/dist/index.js.map +1 -0
- package/dist/path.d.ts +241 -0
- package/dist/path.d.ts.map +1 -0
- package/dist/path.js +299 -0
- package/dist/path.js.map +1 -0
- package/dist/random/crypto-rng.d.ts +31 -0
- package/dist/random/crypto-rng.d.ts.map +1 -0
- package/dist/random/crypto-rng.js +44 -0
- package/dist/random/crypto-rng.js.map +1 -0
- package/dist/random/distributions/bates.d.ts +12 -0
- package/dist/random/distributions/bates.d.ts.map +1 -0
- package/dist/random/distributions/bates.js +15 -0
- package/dist/random/distributions/bates.js.map +1 -0
- package/dist/random/distributions/bernoulli.d.ts +12 -0
- package/dist/random/distributions/bernoulli.d.ts.map +1 -0
- package/dist/random/distributions/bernoulli.js +13 -0
- package/dist/random/distributions/bernoulli.js.map +1 -0
- package/dist/random/distributions/binomial.d.ts +12 -0
- package/dist/random/distributions/binomial.d.ts.map +1 -0
- package/dist/random/distributions/binomial.js +24 -0
- package/dist/random/distributions/binomial.js.map +1 -0
- package/dist/random/distributions/exponential.d.ts +12 -0
- package/dist/random/distributions/exponential.d.ts.map +1 -0
- package/dist/random/distributions/exponential.js +13 -0
- package/dist/random/distributions/exponential.js.map +1 -0
- package/dist/random/distributions/geometric.d.ts +12 -0
- package/dist/random/distributions/geometric.d.ts.map +1 -0
- package/dist/random/distributions/geometric.js +14 -0
- package/dist/random/distributions/geometric.js.map +1 -0
- package/dist/random/distributions/irwin-hall.d.ts +12 -0
- package/dist/random/distributions/irwin-hall.d.ts.map +1 -0
- package/dist/random/distributions/irwin-hall.js +18 -0
- package/dist/random/distributions/irwin-hall.js.map +1 -0
- package/dist/random/distributions/log-normal.d.ts +12 -0
- package/dist/random/distributions/log-normal.d.ts.map +1 -0
- package/dist/random/distributions/log-normal.js +12 -0
- package/dist/random/distributions/log-normal.js.map +1 -0
- package/dist/random/distributions/normal.d.ts +13 -0
- package/dist/random/distributions/normal.d.ts.map +1 -0
- package/dist/random/distributions/normal.js +16 -0
- package/dist/random/distributions/normal.js.map +1 -0
- package/dist/random/distributions/pareto.d.ts +12 -0
- package/dist/random/distributions/pareto.d.ts.map +1 -0
- package/dist/random/distributions/pareto.js +14 -0
- package/dist/random/distributions/pareto.js.map +1 -0
- package/dist/random/distributions/poisson.d.ts +12 -0
- package/dist/random/distributions/poisson.d.ts.map +1 -0
- package/dist/random/distributions/poisson.js +81 -0
- package/dist/random/distributions/poisson.js.map +1 -0
- package/dist/random/distributions/uniform-int.d.ts +12 -0
- package/dist/random/distributions/uniform-int.d.ts.map +1 -0
- package/dist/random/distributions/uniform-int.js +16 -0
- package/dist/random/distributions/uniform-int.js.map +1 -0
- package/dist/random/distributions/uniform.d.ts +12 -0
- package/dist/random/distributions/uniform.d.ts.map +1 -0
- package/dist/random/distributions/uniform.js +10 -0
- package/dist/random/distributions/uniform.js.map +1 -0
- package/dist/random/rng.d.ts +17 -0
- package/dist/random/rng.d.ts.map +1 -0
- package/dist/random/rng.js +7 -0
- package/dist/random/rng.js.map +1 -0
- package/dist/random/xorshift128.d.ts +35 -0
- package/dist/random/xorshift128.d.ts.map +1 -0
- package/dist/random/xorshift128.js +112 -0
- package/dist/random/xorshift128.js.map +1 -0
- package/dist/random.d.ts +773 -0
- package/dist/random.d.ts.map +1 -0
- package/dist/random.js +934 -0
- package/dist/random.js.map +1 -0
- package/dist/test.d.ts +253 -0
- package/dist/test.d.ts.map +1 -0
- package/dist/test.js +407 -0
- package/dist/test.js.map +1 -0
- package/dist/time.d.ts +130 -0
- package/dist/time.d.ts.map +1 -0
- package/dist/time.js +154 -0
- package/dist/time.js.map +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -0
- package/package.json +84 -0
package/CLA.md
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
# Contributor License Agreement
|
|
2
|
+
|
|
3
|
+
This Contributor License Agreement ("Agreement") is entered into between Elara AI Pty Ltd ("Company") and you (the "Contributor").
|
|
4
|
+
|
|
5
|
+
## Grant of Copyright License
|
|
6
|
+
|
|
7
|
+
You hereby grant to the Company and to recipients of software distributed by the Company a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare derivative works of, publicly display, publicly perform, sublicense, distribute, and use Your Contributions and such derivative works.
|
|
8
|
+
|
|
9
|
+
## Grant of Patent License
|
|
10
|
+
|
|
11
|
+
You hereby grant to the Company and to recipients of software distributed by the Company a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer Your Contributions.
|
|
12
|
+
|
|
13
|
+
## Relicensing Rights
|
|
14
|
+
|
|
15
|
+
You grant the Company the right to license Your Contributions under any license terms, including but not limited to commercial licenses, in addition to the open source license under which the project is distributed.
|
|
16
|
+
|
|
17
|
+
## Your Representations
|
|
18
|
+
|
|
19
|
+
You represent that:
|
|
20
|
+
- You are legally entitled to grant the above licenses
|
|
21
|
+
- Each of Your Contributions is Your original creation
|
|
22
|
+
- Your Contribution submissions include complete details of any third-party license or other restriction of which you are aware
|
|
23
|
+
|
|
24
|
+
## Agreement
|
|
25
|
+
|
|
26
|
+
By signing this Agreement through CLA Assistant or by submitting a Contribution, you accept and agree to the terms of this Agreement.
|
package/CONTRIBUTING.md
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
# Contributing to East
|
|
2
|
+
|
|
3
|
+
Thank you for your interest in contributing! We welcome contributions from the community.
|
|
4
|
+
|
|
5
|
+
## Contributor License Agreement (CLA)
|
|
6
|
+
|
|
7
|
+
Before we can accept your contribution, you must sign our Contributor License Agreement (CLA). This agreement gives Elara AI Pty Ltd the right to use and relicense your contributions, including under commercial licenses, while you retain ownership of your contribution.
|
|
8
|
+
|
|
9
|
+
**Why do we require a CLA?**
|
|
10
|
+
This project is dual-licensed under AGPL-3.0 and commercial licenses. The CLA allows us to offer commercial licenses to users who wish to use this software in proprietary applications.
|
|
11
|
+
|
|
12
|
+
### Signing the CLA
|
|
13
|
+
|
|
14
|
+
When you submit your first pull request, the CLA Assistant bot will automatically comment on your PR with a link to sign the CLA electronically. It only takes a minute, and you'll only need to sign it once.
|
|
15
|
+
|
|
16
|
+
## Contributing Process
|
|
17
|
+
|
|
18
|
+
1. Fork the repository
|
|
19
|
+
2. Create a feature branch (`git checkout -b feature/amazing-feature`)
|
|
20
|
+
3. Make your changes
|
|
21
|
+
4. Commit your changes (`git commit -m 'Add amazing feature'`)
|
|
22
|
+
5. Push to the branch (`git push origin feature/amazing-feature`)
|
|
23
|
+
6. Open a Pull Request
|
|
24
|
+
7. Sign the CLA when the bot prompts you
|
|
25
|
+
|
|
26
|
+
## Questions?
|
|
27
|
+
|
|
28
|
+
Contact us at support@elara.ai
|
package/README.md
ADDED
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
# East Node
|
|
2
|
+
|
|
3
|
+
> Node platform functions for the East language
|
|
4
|
+
|
|
5
|
+
[](LICENSE.md)
|
|
6
|
+
[](https://nodejs.org)
|
|
7
|
+
|
|
8
|
+
**East Node** provides Node.js platform integration for the [East language](https://github.com/elaraai/East). It enables East programs to interact with the Node.js runtime through platform functions for file system operations, console I/O, HTTP requests, cryptography, and more.
|
|
9
|
+
|
|
10
|
+
## Features
|
|
11
|
+
|
|
12
|
+
- **📁 File System** - Read/write files, manage directories
|
|
13
|
+
- **🖥️ Console I/O** - stdout/stderr output, stdin input
|
|
14
|
+
- **🌐 HTTP Client** - Modern Fetch API for HTTP requests
|
|
15
|
+
- **🔐 Cryptography** - Random bytes, SHA-256, UUID generation
|
|
16
|
+
- **🎲 Random** - Random number generation with 14 statistical distributions
|
|
17
|
+
- **⏱️ Time Operations** - Timestamps and sleep
|
|
18
|
+
- **🛤️ Path Utilities** - Cross-platform path manipulation
|
|
19
|
+
- **🧪 Test Framework** - Built-in testing utilities
|
|
20
|
+
- **🛡️ Type-Safe** - Full TypeScript support with EastError handling
|
|
21
|
+
|
|
22
|
+
## Installation
|
|
23
|
+
|
|
24
|
+
```bash
|
|
25
|
+
npm install @elaraai/east-node-std @elaraai/east
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
## Quick Start
|
|
29
|
+
|
|
30
|
+
```typescript
|
|
31
|
+
import { East, NullType, StringType } from "@elaraai/east";
|
|
32
|
+
import { NodePlatform, Console, FileSystem } from "@elaraai/east-node-std";
|
|
33
|
+
|
|
34
|
+
// Define an East function using platform functions
|
|
35
|
+
const processFile = East.function(
|
|
36
|
+
[StringType], // Input: file path
|
|
37
|
+
NullType, // Output: null
|
|
38
|
+
($, inputPath) => {
|
|
39
|
+
const content = $.let(FileSystem.readFile(inputPath));
|
|
40
|
+
$(Console.log(content));
|
|
41
|
+
$(FileSystem.writeFile("output.txt", content));
|
|
42
|
+
}
|
|
43
|
+
);
|
|
44
|
+
|
|
45
|
+
// Compile with Node.js platform and execute
|
|
46
|
+
const compiled = East.compile(processFile.toIR(), NodePlatform);
|
|
47
|
+
compiled("/path/to/input.txt");
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
## Platform Functions
|
|
51
|
+
|
|
52
|
+
East Node provides seven platform modules:
|
|
53
|
+
|
|
54
|
+
| Module | Functions | Description |
|
|
55
|
+
|--------|-----------|-------------|
|
|
56
|
+
| **Console** | `log`, `error`, `write` | Console I/O operations |
|
|
57
|
+
| **FileSystem** | `readFile`, `writeFile`, `exists`, `createDirectory`, etc. | File system operations (11 functions) |
|
|
58
|
+
| **Fetch** | `get`, `post`, `request` | HTTP client using Fetch API |
|
|
59
|
+
| **Crypto** | `randomBytes`, `hashSha256`, `uuid` | Cryptographic operations |
|
|
60
|
+
| **Time** | `now`, `sleep` | Time and delay operations |
|
|
61
|
+
| **Path** | `join`, `resolve`, `dirname`, `basename`, `extname` | Path manipulation |
|
|
62
|
+
| **Random** | `uniform`, `normal`, `range`, `exponential`, `bernoulli`, etc. | Random number generation with 14 distributions |
|
|
63
|
+
|
|
64
|
+
**Complete platform:**
|
|
65
|
+
```typescript
|
|
66
|
+
import { NodePlatform } from "@elaraai/east-node-std";
|
|
67
|
+
const compiled = East.compile(myFunction.toIR(), NodePlatform);
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
**Individual modules:**
|
|
71
|
+
```typescript
|
|
72
|
+
import { Console, FileSystem } from "@elaraai/east-node-std";
|
|
73
|
+
const compiled = East.compile(myFunction.toIR(), [...Console.Implementation, ...FileSystem.Implementation]);
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
## Documentation
|
|
77
|
+
|
|
78
|
+
- **[USAGE.md](USAGE.md)** - Comprehensive guide with examples for all platform functions
|
|
79
|
+
- **[East Documentation](https://github.com/elaraai/East)** - Core East language documentation
|
|
80
|
+
|
|
81
|
+
## Testing
|
|
82
|
+
|
|
83
|
+
East Node includes a test framework for East code:
|
|
84
|
+
|
|
85
|
+
```typescript
|
|
86
|
+
import { describeEast, Test } from "@elaraai/east-node-std";
|
|
87
|
+
import { East } from "@elaraai/east";
|
|
88
|
+
|
|
89
|
+
await describeEast("Math operations", (test) => {
|
|
90
|
+
test("addition works", $ => {
|
|
91
|
+
const result = $.let(East.value(1n).add(2n));
|
|
92
|
+
$(Test.equal(result, 3n));
|
|
93
|
+
});
|
|
94
|
+
});
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
Run tests:
|
|
98
|
+
```bash
|
|
99
|
+
npm test # Run all tests
|
|
100
|
+
make test # Alternative via Makefile
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
## Development
|
|
104
|
+
|
|
105
|
+
```bash
|
|
106
|
+
npm run build # Compile TypeScript
|
|
107
|
+
npm run test # Run test suite (requires build)
|
|
108
|
+
npm run lint # Check code quality
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
## Security
|
|
112
|
+
|
|
113
|
+
Platform functions are intentionally limited for sandbox security:
|
|
114
|
+
|
|
115
|
+
- ❌ No process access (exit, environment variables, command-line arguments)
|
|
116
|
+
- ❌ No arbitrary command execution
|
|
117
|
+
- ✅ Controlled I/O operations only
|
|
118
|
+
- ✅ All operations are type-checked
|
|
119
|
+
|
|
120
|
+
## License
|
|
121
|
+
|
|
122
|
+
Dual-licensed:
|
|
123
|
+
- **Open Source**: [AGPL-3.0](LICENSE.md) - Free for open source use
|
|
124
|
+
- **Commercial**: Available for proprietary use - contact support@elara.ai
|
|
125
|
+
|
|
126
|
+
## Links
|
|
127
|
+
|
|
128
|
+
- **Website**: [https://elaraai.com/](https://elaraai.com/)
|
|
129
|
+
- **East Repository**: [https://github.com/elaraai/East](https://github.com/elaraai/East)
|
|
130
|
+
- **Issues**: [https://github.com/elaraai/East/issues](https://github.com/elaraai/East/issues)
|
|
131
|
+
- **Email**: support@elara.ai
|
|
132
|
+
|
|
133
|
+
---
|
|
134
|
+
|
|
135
|
+
*Developed by [Elara AI Pty Ltd](https://elaraai.com/) - Powering the computational layer of AI-driven business optimization.*
|
|
@@ -0,0 +1,192 @@
|
|
|
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 } from "@elaraai/east";
|
|
6
|
+
import type { PlatformFunction, PlatformFunctionDef } from "@elaraai/east/internal";
|
|
7
|
+
/**
|
|
8
|
+
* Writes a message to stdout with a newline.
|
|
9
|
+
*
|
|
10
|
+
* Outputs a string message to standard output (stdout) followed by a newline character.
|
|
11
|
+
* This is useful for general logging and output in East programs.
|
|
12
|
+
*
|
|
13
|
+
* This is a platform function for the East language, enabling console output
|
|
14
|
+
* in East programs running on Node.js.
|
|
15
|
+
*
|
|
16
|
+
* @param message - The message to write to stdout
|
|
17
|
+
* @returns Null
|
|
18
|
+
*
|
|
19
|
+
* @throws {EastError} When writing to stdout fails (rare, typically only on broken pipes)
|
|
20
|
+
*
|
|
21
|
+
* @example
|
|
22
|
+
* ```ts
|
|
23
|
+
* const logMessage = East.function([], NullType, $ => {
|
|
24
|
+
* $(Console.log("Hello, World!"));
|
|
25
|
+
* });
|
|
26
|
+
* ```
|
|
27
|
+
*/
|
|
28
|
+
export declare const console_log: PlatformFunctionDef<[typeof StringType], typeof NullType>;
|
|
29
|
+
/**
|
|
30
|
+
* Writes a message to stderr with a newline.
|
|
31
|
+
*
|
|
32
|
+
* Outputs a string message to standard error (stderr) followed by a newline character.
|
|
33
|
+
* This is used for error messages and warnings, keeping them separate from normal output.
|
|
34
|
+
*
|
|
35
|
+
* This is a platform function for the East language, enabling error output
|
|
36
|
+
* in East programs running on Node.js.
|
|
37
|
+
*
|
|
38
|
+
* @param message - The message to write to stderr
|
|
39
|
+
* @returns Null
|
|
40
|
+
*
|
|
41
|
+
* @throws {EastError} When writing to stderr fails (rare, typically only on broken pipes)
|
|
42
|
+
*
|
|
43
|
+
* @example
|
|
44
|
+
* ```ts
|
|
45
|
+
* const logError = East.function([], NullType, $ => {
|
|
46
|
+
* $(Console.error("Error: Invalid input"));
|
|
47
|
+
* });
|
|
48
|
+
* ```
|
|
49
|
+
*/
|
|
50
|
+
export declare const console_error: PlatformFunctionDef<[typeof StringType], typeof NullType>;
|
|
51
|
+
/**
|
|
52
|
+
* Writes a message to stdout without a newline.
|
|
53
|
+
*
|
|
54
|
+
* Outputs a string message to standard output (stdout) without appending a newline.
|
|
55
|
+
* This allows building output incrementally or creating progress indicators on a single line.
|
|
56
|
+
*
|
|
57
|
+
* This is a platform function for the East language, enabling raw console output
|
|
58
|
+
* in East programs running on Node.js.
|
|
59
|
+
*
|
|
60
|
+
* @param message - The message to write to stdout
|
|
61
|
+
* @returns Null
|
|
62
|
+
*
|
|
63
|
+
* @throws {EastError} When writing to stdout fails (rare, typically only on broken pipes)
|
|
64
|
+
*
|
|
65
|
+
* @example
|
|
66
|
+
* ```ts
|
|
67
|
+
* const showProgress = East.function([], NullType, $ => {
|
|
68
|
+
* $(Console.write("Processing... "));
|
|
69
|
+
* $(Console.log("done!"));
|
|
70
|
+
* });
|
|
71
|
+
* ```
|
|
72
|
+
*/
|
|
73
|
+
export declare const console_write: PlatformFunctionDef<[typeof StringType], typeof NullType>;
|
|
74
|
+
/**
|
|
75
|
+
* Node.js implementation of console platform functions.
|
|
76
|
+
*
|
|
77
|
+
* Pass this array to {@link East.compile} to enable console I/O operations.
|
|
78
|
+
*/
|
|
79
|
+
declare const ConsoleImpl: PlatformFunction[];
|
|
80
|
+
/**
|
|
81
|
+
* Grouped console I/O platform functions.
|
|
82
|
+
*
|
|
83
|
+
* Provides standard console operations for East programs.
|
|
84
|
+
*
|
|
85
|
+
* @example
|
|
86
|
+
* ```ts
|
|
87
|
+
* import { East, NullType } from "@elaraai/east";
|
|
88
|
+
* import { Console } from "@elaraai/east-node-std";
|
|
89
|
+
*
|
|
90
|
+
* const greet = East.function([], NullType, $ => {
|
|
91
|
+
* $(Console.log("Hello, World!"));
|
|
92
|
+
* $(Console.error("This is a warning"));
|
|
93
|
+
* $(Console.write("No newline here"));
|
|
94
|
+
* });
|
|
95
|
+
*
|
|
96
|
+
* const compiled = East.compile(greet.toIR(), Console.Implementation);
|
|
97
|
+
* await compiled();
|
|
98
|
+
* ```
|
|
99
|
+
*/
|
|
100
|
+
export declare const Console: {
|
|
101
|
+
/**
|
|
102
|
+
* Writes a message to stdout with a newline.
|
|
103
|
+
*
|
|
104
|
+
* Outputs a string message to standard output (stdout) followed by a newline character.
|
|
105
|
+
* This is useful for general logging and output in East programs.
|
|
106
|
+
*
|
|
107
|
+
* @param message - The message to write to stdout
|
|
108
|
+
* @returns Null
|
|
109
|
+
* @throws {EastError} When writing to stdout fails
|
|
110
|
+
*
|
|
111
|
+
* @example
|
|
112
|
+
* ```ts
|
|
113
|
+
* const logMessage = East.function([], NullType, $ => {
|
|
114
|
+
* $(Console.log("Hello, World!"));
|
|
115
|
+
* });
|
|
116
|
+
*
|
|
117
|
+
* const compiled = East.compile(logMessage.toIR(), Console.Implementation);
|
|
118
|
+
* await compiled(); // Outputs: Hello, World!
|
|
119
|
+
* ```
|
|
120
|
+
*/
|
|
121
|
+
readonly log: PlatformFunctionDef<[StringType], NullType>;
|
|
122
|
+
/**
|
|
123
|
+
* Writes a message to stderr with a newline.
|
|
124
|
+
*
|
|
125
|
+
* Outputs a string message to standard error (stderr) followed by a newline character.
|
|
126
|
+
* This is used for error messages and warnings, keeping them separate from normal output.
|
|
127
|
+
*
|
|
128
|
+
* @param message - The message to write to stderr
|
|
129
|
+
* @returns Null
|
|
130
|
+
* @throws {EastError} When writing to stderr fails
|
|
131
|
+
*
|
|
132
|
+
* @example
|
|
133
|
+
* ```ts
|
|
134
|
+
* const logError = East.function([], NullType, $ => {
|
|
135
|
+
* $(Console.error("Error: Invalid input"));
|
|
136
|
+
* });
|
|
137
|
+
*
|
|
138
|
+
* const compiled = East.compile(logError.toIR(), Console.Implementation);
|
|
139
|
+
* await compiled(); // Outputs to stderr: Error: Invalid input
|
|
140
|
+
* ```
|
|
141
|
+
*/
|
|
142
|
+
readonly error: PlatformFunctionDef<[StringType], NullType>;
|
|
143
|
+
/**
|
|
144
|
+
* Writes a message to stdout without a newline.
|
|
145
|
+
*
|
|
146
|
+
* Outputs a string message to standard output (stdout) without appending a newline.
|
|
147
|
+
* This allows building output incrementally or creating progress indicators.
|
|
148
|
+
*
|
|
149
|
+
* @param message - The message to write to stdout
|
|
150
|
+
* @returns Null
|
|
151
|
+
* @throws {EastError} When writing to stdout fails
|
|
152
|
+
*
|
|
153
|
+
* @example
|
|
154
|
+
* ```ts
|
|
155
|
+
* const showProgress = East.function([], NullType, $ => {
|
|
156
|
+
* $(Console.write("Processing... "));
|
|
157
|
+
* $(Console.log("done!"));
|
|
158
|
+
* });
|
|
159
|
+
*
|
|
160
|
+
* const compiled = East.compile(showProgress.toIR(), Console.Implementation);
|
|
161
|
+
* await compiled(); // Outputs: Processing... done!
|
|
162
|
+
* ```
|
|
163
|
+
*/
|
|
164
|
+
readonly write: PlatformFunctionDef<[StringType], NullType>;
|
|
165
|
+
/**
|
|
166
|
+
* Node.js implementation of console platform functions.
|
|
167
|
+
*
|
|
168
|
+
* Pass this to {@link East.compile} to enable console I/O operations.
|
|
169
|
+
*/
|
|
170
|
+
readonly Implementation: PlatformFunction[];
|
|
171
|
+
};
|
|
172
|
+
export { ConsoleImpl };
|
|
173
|
+
/**
|
|
174
|
+
East.package(
|
|
175
|
+
name: "console",
|
|
176
|
+
....
|
|
177
|
+
|
|
178
|
+
)
|
|
179
|
+
|
|
180
|
+
|
|
181
|
+
|
|
182
|
+
import(..)
|
|
183
|
+
|
|
184
|
+
|
|
185
|
+
|
|
186
|
+
ed3 import ./path_to_east_desdcribing_package...
|
|
187
|
+
|
|
188
|
+
|
|
189
|
+
ed3 run console.log "Hello, World!"
|
|
190
|
+
|
|
191
|
+
*/
|
|
192
|
+
//# sourceMappingURL=console.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"console.d.ts","sourceRoot":"","sources":["../src/console.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,EAAQ,UAAU,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAC3D,OAAO,KAAK,EAAE,gBAAgB,EAAE,mBAAmB,EAAE,MAAM,wBAAwB,CAAC;AAIpF;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,eAAO,MAAM,WAAW,EAAE,mBAAmB,CAAC,CAAC,OAAO,UAAU,CAAC,EAAE,OAAO,QAAQ,CAC1B,CAAC;AAEzD;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,eAAO,MAAM,aAAa,EAAE,mBAAmB,CAAC,CAAC,OAAO,UAAU,CAAC,EAAE,OAAO,QAAQ,CAC1B,CAAC;AAE3D;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,eAAO,MAAM,aAAa,EAAE,mBAAmB,CAAC,CAAC,OAAO,UAAU,CAAC,EAAE,OAAO,QAAQ,CAC1B,CAAC;AAE3D;;;;GAIG;AACH,QAAA,MAAM,WAAW,EAAE,gBAAgB,EA+BlC,CAAC;AAEF;;;;;;;;;;;;;;;;;;;GAmBG;AACH,eAAO,MAAM,OAAO;IAChB;;;;;;;;;;;;;;;;;;;OAmBG;;IAGH;;;;;;;;;;;;;;;;;;;OAmBG;;IAGH;;;;;;;;;;;;;;;;;;;;OAoBG;;IAGH;;;;OAIG;;CAEG,CAAC;AAGX,OAAO,EAAE,WAAW,EAAE,CAAC;AAEvB;;;;;;;;;;;;;;;;;;GAkBG"}
|
package/dist/console.js
ADDED
|
@@ -0,0 +1,228 @@
|
|
|
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 { East, StringType, NullType } from "@elaraai/east";
|
|
6
|
+
import { EastError } from "@elaraai/east/internal";
|
|
7
|
+
import { stdout } from "node:process";
|
|
8
|
+
/**
|
|
9
|
+
* Writes a message to stdout with a newline.
|
|
10
|
+
*
|
|
11
|
+
* Outputs a string message to standard output (stdout) followed by a newline character.
|
|
12
|
+
* This is useful for general logging and output in East programs.
|
|
13
|
+
*
|
|
14
|
+
* This is a platform function for the East language, enabling console output
|
|
15
|
+
* in East programs running on Node.js.
|
|
16
|
+
*
|
|
17
|
+
* @param message - The message to write to stdout
|
|
18
|
+
* @returns Null
|
|
19
|
+
*
|
|
20
|
+
* @throws {EastError} When writing to stdout fails (rare, typically only on broken pipes)
|
|
21
|
+
*
|
|
22
|
+
* @example
|
|
23
|
+
* ```ts
|
|
24
|
+
* const logMessage = East.function([], NullType, $ => {
|
|
25
|
+
* $(Console.log("Hello, World!"));
|
|
26
|
+
* });
|
|
27
|
+
* ```
|
|
28
|
+
*/
|
|
29
|
+
export const console_log = East.platform("console_log", [StringType], NullType);
|
|
30
|
+
/**
|
|
31
|
+
* Writes a message to stderr with a newline.
|
|
32
|
+
*
|
|
33
|
+
* Outputs a string message to standard error (stderr) followed by a newline character.
|
|
34
|
+
* This is used for error messages and warnings, keeping them separate from normal output.
|
|
35
|
+
*
|
|
36
|
+
* This is a platform function for the East language, enabling error output
|
|
37
|
+
* in East programs running on Node.js.
|
|
38
|
+
*
|
|
39
|
+
* @param message - The message to write to stderr
|
|
40
|
+
* @returns Null
|
|
41
|
+
*
|
|
42
|
+
* @throws {EastError} When writing to stderr fails (rare, typically only on broken pipes)
|
|
43
|
+
*
|
|
44
|
+
* @example
|
|
45
|
+
* ```ts
|
|
46
|
+
* const logError = East.function([], NullType, $ => {
|
|
47
|
+
* $(Console.error("Error: Invalid input"));
|
|
48
|
+
* });
|
|
49
|
+
* ```
|
|
50
|
+
*/
|
|
51
|
+
export const console_error = East.platform("console_error", [StringType], NullType);
|
|
52
|
+
/**
|
|
53
|
+
* Writes a message to stdout without a newline.
|
|
54
|
+
*
|
|
55
|
+
* Outputs a string message to standard output (stdout) without appending a newline.
|
|
56
|
+
* This allows building output incrementally or creating progress indicators on a single line.
|
|
57
|
+
*
|
|
58
|
+
* This is a platform function for the East language, enabling raw console output
|
|
59
|
+
* in East programs running on Node.js.
|
|
60
|
+
*
|
|
61
|
+
* @param message - The message to write to stdout
|
|
62
|
+
* @returns Null
|
|
63
|
+
*
|
|
64
|
+
* @throws {EastError} When writing to stdout fails (rare, typically only on broken pipes)
|
|
65
|
+
*
|
|
66
|
+
* @example
|
|
67
|
+
* ```ts
|
|
68
|
+
* const showProgress = East.function([], NullType, $ => {
|
|
69
|
+
* $(Console.write("Processing... "));
|
|
70
|
+
* $(Console.log("done!"));
|
|
71
|
+
* });
|
|
72
|
+
* ```
|
|
73
|
+
*/
|
|
74
|
+
export const console_write = East.platform("console_write", [StringType], NullType);
|
|
75
|
+
/**
|
|
76
|
+
* Node.js implementation of console platform functions.
|
|
77
|
+
*
|
|
78
|
+
* Pass this array to {@link East.compile} to enable console I/O operations.
|
|
79
|
+
*/
|
|
80
|
+
const ConsoleImpl = [
|
|
81
|
+
console_log.implement((msg) => {
|
|
82
|
+
try {
|
|
83
|
+
console.log(msg);
|
|
84
|
+
}
|
|
85
|
+
catch (err) {
|
|
86
|
+
throw new EastError(`Failed to write to stdout: ${err.message}`, {
|
|
87
|
+
location: { filename: "console_log", line: 0n, column: 0n },
|
|
88
|
+
cause: err
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
}),
|
|
92
|
+
console_error.implement((msg) => {
|
|
93
|
+
try {
|
|
94
|
+
console.error(msg);
|
|
95
|
+
}
|
|
96
|
+
catch (err) {
|
|
97
|
+
throw new EastError(`Failed to write to stderr: ${err.message}`, {
|
|
98
|
+
location: { filename: "console_error", line: 0n, column: 0n },
|
|
99
|
+
cause: err
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
}),
|
|
103
|
+
console_write.implement((msg) => {
|
|
104
|
+
try {
|
|
105
|
+
stdout.write(msg);
|
|
106
|
+
}
|
|
107
|
+
catch (err) {
|
|
108
|
+
throw new EastError(`Failed to write to stdout: ${err.message}`, {
|
|
109
|
+
location: { filename: "console_write", line: 0n, column: 0n },
|
|
110
|
+
cause: err
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
})
|
|
114
|
+
];
|
|
115
|
+
/**
|
|
116
|
+
* Grouped console I/O platform functions.
|
|
117
|
+
*
|
|
118
|
+
* Provides standard console operations for East programs.
|
|
119
|
+
*
|
|
120
|
+
* @example
|
|
121
|
+
* ```ts
|
|
122
|
+
* import { East, NullType } from "@elaraai/east";
|
|
123
|
+
* import { Console } from "@elaraai/east-node-std";
|
|
124
|
+
*
|
|
125
|
+
* const greet = East.function([], NullType, $ => {
|
|
126
|
+
* $(Console.log("Hello, World!"));
|
|
127
|
+
* $(Console.error("This is a warning"));
|
|
128
|
+
* $(Console.write("No newline here"));
|
|
129
|
+
* });
|
|
130
|
+
*
|
|
131
|
+
* const compiled = East.compile(greet.toIR(), Console.Implementation);
|
|
132
|
+
* await compiled();
|
|
133
|
+
* ```
|
|
134
|
+
*/
|
|
135
|
+
export const Console = {
|
|
136
|
+
/**
|
|
137
|
+
* Writes a message to stdout with a newline.
|
|
138
|
+
*
|
|
139
|
+
* Outputs a string message to standard output (stdout) followed by a newline character.
|
|
140
|
+
* This is useful for general logging and output in East programs.
|
|
141
|
+
*
|
|
142
|
+
* @param message - The message to write to stdout
|
|
143
|
+
* @returns Null
|
|
144
|
+
* @throws {EastError} When writing to stdout fails
|
|
145
|
+
*
|
|
146
|
+
* @example
|
|
147
|
+
* ```ts
|
|
148
|
+
* const logMessage = East.function([], NullType, $ => {
|
|
149
|
+
* $(Console.log("Hello, World!"));
|
|
150
|
+
* });
|
|
151
|
+
*
|
|
152
|
+
* const compiled = East.compile(logMessage.toIR(), Console.Implementation);
|
|
153
|
+
* await compiled(); // Outputs: Hello, World!
|
|
154
|
+
* ```
|
|
155
|
+
*/
|
|
156
|
+
log: console_log,
|
|
157
|
+
/**
|
|
158
|
+
* Writes a message to stderr with a newline.
|
|
159
|
+
*
|
|
160
|
+
* Outputs a string message to standard error (stderr) followed by a newline character.
|
|
161
|
+
* This is used for error messages and warnings, keeping them separate from normal output.
|
|
162
|
+
*
|
|
163
|
+
* @param message - The message to write to stderr
|
|
164
|
+
* @returns Null
|
|
165
|
+
* @throws {EastError} When writing to stderr fails
|
|
166
|
+
*
|
|
167
|
+
* @example
|
|
168
|
+
* ```ts
|
|
169
|
+
* const logError = East.function([], NullType, $ => {
|
|
170
|
+
* $(Console.error("Error: Invalid input"));
|
|
171
|
+
* });
|
|
172
|
+
*
|
|
173
|
+
* const compiled = East.compile(logError.toIR(), Console.Implementation);
|
|
174
|
+
* await compiled(); // Outputs to stderr: Error: Invalid input
|
|
175
|
+
* ```
|
|
176
|
+
*/
|
|
177
|
+
error: console_error,
|
|
178
|
+
/**
|
|
179
|
+
* Writes a message to stdout without a newline.
|
|
180
|
+
*
|
|
181
|
+
* Outputs a string message to standard output (stdout) without appending a newline.
|
|
182
|
+
* This allows building output incrementally or creating progress indicators.
|
|
183
|
+
*
|
|
184
|
+
* @param message - The message to write to stdout
|
|
185
|
+
* @returns Null
|
|
186
|
+
* @throws {EastError} When writing to stdout fails
|
|
187
|
+
*
|
|
188
|
+
* @example
|
|
189
|
+
* ```ts
|
|
190
|
+
* const showProgress = East.function([], NullType, $ => {
|
|
191
|
+
* $(Console.write("Processing... "));
|
|
192
|
+
* $(Console.log("done!"));
|
|
193
|
+
* });
|
|
194
|
+
*
|
|
195
|
+
* const compiled = East.compile(showProgress.toIR(), Console.Implementation);
|
|
196
|
+
* await compiled(); // Outputs: Processing... done!
|
|
197
|
+
* ```
|
|
198
|
+
*/
|
|
199
|
+
write: console_write,
|
|
200
|
+
/**
|
|
201
|
+
* Node.js implementation of console platform functions.
|
|
202
|
+
*
|
|
203
|
+
* Pass this to {@link East.compile} to enable console I/O operations.
|
|
204
|
+
*/
|
|
205
|
+
Implementation: ConsoleImpl,
|
|
206
|
+
};
|
|
207
|
+
// Export for backwards compatibility
|
|
208
|
+
export { ConsoleImpl };
|
|
209
|
+
/**
|
|
210
|
+
East.package(
|
|
211
|
+
name: "console",
|
|
212
|
+
....
|
|
213
|
+
|
|
214
|
+
)
|
|
215
|
+
|
|
216
|
+
|
|
217
|
+
|
|
218
|
+
import(..)
|
|
219
|
+
|
|
220
|
+
|
|
221
|
+
|
|
222
|
+
ed3 import ./path_to_east_desdcribing_package...
|
|
223
|
+
|
|
224
|
+
|
|
225
|
+
ed3 run console.log "Hello, World!"
|
|
226
|
+
|
|
227
|
+
*/
|
|
228
|
+
//# sourceMappingURL=console.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"console.js","sourceRoot":"","sources":["../src/console.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,EAAE,IAAI,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAE3D,OAAO,EAAE,SAAS,EAAE,MAAM,wBAAwB,CAAC;AACnD,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AAEtC;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,MAAM,CAAC,MAAM,WAAW,GACpB,IAAI,CAAC,QAAQ,CAAC,aAAa,EAAE,CAAC,UAAU,CAAC,EAAE,QAAQ,CAAC,CAAC;AAEzD;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,MAAM,CAAC,MAAM,aAAa,GACtB,IAAI,CAAC,QAAQ,CAAC,eAAe,EAAE,CAAC,UAAU,CAAC,EAAE,QAAQ,CAAC,CAAC;AAE3D;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,MAAM,CAAC,MAAM,aAAa,GACtB,IAAI,CAAC,QAAQ,CAAC,eAAe,EAAE,CAAC,UAAU,CAAC,EAAE,QAAQ,CAAC,CAAC;AAE3D;;;;GAIG;AACH,MAAM,WAAW,GAAuB;IACpC,WAAW,CAAC,SAAS,CAAC,CAAC,GAAW,EAAE,EAAE;QAClC,IAAI,CAAC;YACD,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;QACrB,CAAC;QAAC,OAAO,GAAQ,EAAE,CAAC;YAChB,MAAM,IAAI,SAAS,CAAC,8BAA8B,GAAG,CAAC,OAAO,EAAE,EAAE;gBAC7D,QAAQ,EAAE,EAAE,QAAQ,EAAE,aAAa,EAAE,IAAI,EAAE,EAAE,EAAE,MAAM,EAAE,EAAE,EAAE;gBAC3D,KAAK,EAAE,GAAG;aACb,CAAC,CAAC;QACP,CAAC;IACL,CAAC,CAAC;IACF,aAAa,CAAC,SAAS,CAAC,CAAC,GAAW,EAAE,EAAE;QACpC,IAAI,CAAC;YACD,OAAO,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;QACvB,CAAC;QAAC,OAAO,GAAQ,EAAE,CAAC;YAChB,MAAM,IAAI,SAAS,CAAC,8BAA8B,GAAG,CAAC,OAAO,EAAE,EAAE;gBAC7D,QAAQ,EAAE,EAAE,QAAQ,EAAE,eAAe,EAAE,IAAI,EAAE,EAAE,EAAE,MAAM,EAAE,EAAE,EAAE;gBAC7D,KAAK,EAAE,GAAG;aACb,CAAC,CAAC;QACP,CAAC;IACL,CAAC,CAAC;IACF,aAAa,CAAC,SAAS,CAAC,CAAC,GAAW,EAAE,EAAE;QACpC,IAAI,CAAC;YACD,MAAM,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;QACtB,CAAC;QAAC,OAAO,GAAQ,EAAE,CAAC;YAChB,MAAM,IAAI,SAAS,CAAC,8BAA8B,GAAG,CAAC,OAAO,EAAE,EAAE;gBAC7D,QAAQ,EAAE,EAAE,QAAQ,EAAE,eAAe,EAAE,IAAI,EAAE,EAAE,EAAE,MAAM,EAAE,EAAE,EAAE;gBAC7D,KAAK,EAAE,GAAG;aACb,CAAC,CAAC;QACP,CAAC;IACL,CAAC,CAAC;CACL,CAAC;AAEF;;;;;;;;;;;;;;;;;;;GAmBG;AACH,MAAM,CAAC,MAAM,OAAO,GAAG;IACnB;;;;;;;;;;;;;;;;;;;OAmBG;IACH,GAAG,EAAE,WAAW;IAEhB;;;;;;;;;;;;;;;;;;;OAmBG;IACH,KAAK,EAAE,aAAa;IAEpB;;;;;;;;;;;;;;;;;;;;OAoBG;IACH,KAAK,EAAE,aAAa;IAEpB;;;;OAIG;IACH,cAAc,EAAE,WAAW;CACrB,CAAC;AAEX,qCAAqC;AACrC,OAAO,EAAE,WAAW,EAAE,CAAC;AAEvB;;;;;;;;;;;;;;;;;;GAkBG"}
|