@elaraai/east-node-cli 0.0.1-beta.10

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 ADDED
@@ -0,0 +1,157 @@
1
+ # East Node CLI
2
+
3
+ > Command-line interface for running East IR programs with Node.js
4
+
5
+ [![License](https://img.shields.io/badge/license-AGPL--3.0-blue.svg)](LICENSE.md)
6
+ [![Node Version](https://img.shields.io/badge/node-%3E%3D22.0.0-brightgreen.svg)](https://nodejs.org)
7
+
8
+ **East Node CLI** provides a command-line interface for executing compiled [East](https://github.com/elaraai/East) IR programs using Node.js platform implementations.
9
+
10
+ ## Installation
11
+
12
+ ```bash
13
+ # Install the CLI
14
+ npm install -g @elaraai/east-node-cli
15
+
16
+ # Install platform packages (required)
17
+ npm install @elaraai/east-node-std
18
+ npm install @elaraai/east-node-io # if using I/O functions
19
+ ```
20
+
21
+ ## Usage
22
+
23
+ ### Running Programs
24
+
25
+ ```bash
26
+ # Run with standard platform
27
+ east-node run ./program.beast2 -p @elaraai/east-node-std
28
+
29
+ # Run with multiple platforms
30
+ east-node run ./db-query.beast2 \
31
+ -p @elaraai/east-node-std \
32
+ -p @elaraai/east-node-io
33
+
34
+ # Run with input files
35
+ east-node run ./transform.beast2 \
36
+ -p @elaraai/east-node-std \
37
+ -i input.json \
38
+ -i config.east
39
+
40
+ # Run with output file
41
+ east-node run ./process.beast2 \
42
+ -p @elaraai/east-node-std \
43
+ -i input.beast2 \
44
+ -o result.json
45
+
46
+ # Verbose mode
47
+ east-node run ./program.beast2 -p @elaraai/east-node-std -v
48
+ ```
49
+
50
+ ### Version Information
51
+
52
+ ```bash
53
+ # Show CLI version
54
+ east-node version
55
+
56
+ # Show CLI and platform versions
57
+ east-node version -p @elaraai/east-node-std -p @elaraai/east-node-io
58
+ ```
59
+
60
+ ## CLI Reference
61
+
62
+ ### `east-node run`
63
+
64
+ Execute an East IR program.
65
+
66
+ ```
67
+ east-node run <ir_file> [options]
68
+
69
+ Arguments:
70
+ ir_file Path to IR file (.beast2, .beast, .east, or .json)
71
+
72
+ Options:
73
+ -p, --package <package> Platform package to load (can be repeated)
74
+ -i, --input <file> Input data file (can be repeated)
75
+ -o, --output <file> Output file path for result
76
+ -v, --verbose Enable verbose output
77
+ -h, --help Display help
78
+ ```
79
+
80
+ ### `east-node version`
81
+
82
+ Show version information.
83
+
84
+ ```
85
+ east-node version [options]
86
+
87
+ Options:
88
+ -p, --package <package> Platform package to check (can be repeated)
89
+ ```
90
+
91
+ ## Supported File Formats
92
+
93
+ | Extension | Format |
94
+ |-----------|--------|
95
+ | `.beast2`, `.beast` | Binary East format |
96
+ | `.east` | Text East format |
97
+ | `.json` | JSON format |
98
+
99
+ ## Platform Packages
100
+
101
+ Platform packages provide the runtime implementations for East platform functions:
102
+
103
+ - **[@elaraai/east-node-std](https://www.npmjs.com/package/@elaraai/east-node-std)** - Standard platform (console, filesystem, crypto, time, etc.)
104
+ - **[@elaraai/east-node-io](https://www.npmjs.com/package/@elaraai/east-node-io)** - I/O platform (SQL, S3, FTP, Redis, MongoDB, etc.)
105
+
106
+ ## Creating Platform Packages
107
+
108
+ Any npm package can provide platform functions by following this convention:
109
+
110
+ 1. Export a `./platform` subpath that default-exports `PlatformFunction[]`
111
+ 2. Export `./package.json` for version discovery
112
+
113
+ See the [design document](../../docs/east-node-cli-design.md) for details.
114
+
115
+ ## License
116
+
117
+ Dual-licensed:
118
+ - **Open Source**: [AGPL-3.0](LICENSE.md) - Free for open source use
119
+ - **Commercial**: Available for proprietary use - contact support@elara.ai
120
+
121
+
122
+ ### Ecosystem
123
+
124
+ - **[East Node](https://github.com/elaraai/east-node)**: Node.js platform functions for I/O, databases, and system operations. Connect East programs to filesystems, SQL/NoSQL databases, cloud storage, and network services.
125
+ - [@elaraai/east-node-std](https://www.npmjs.com/package/@elaraai/east-node-std): Filesystem, console, HTTP fetch, crypto, random distributions, timestamps
126
+ - [@elaraai/east-node-io](https://www.npmjs.com/package/@elaraai/east-node-io): SQLite, PostgreSQL, MySQL, MongoDB, S3, FTP, SFTP
127
+ - [@elaraai/east-node-cli](https://www.npmjs.com/package/@elaraai/east-node-cli): CLI for running East IR programs in Node.js
128
+
129
+ - **[East Python](https://github.com/elaraai/east-py)**: Python runtime and platform functions for data science and machine learning. Execute East programs with access to optimization solvers, gradient boosting, neural networks, and model explainability.
130
+ - [@elaraai/east-py-datascience](https://www.npmjs.com/package/@elaraai/east-py-datascience): TypeScript types for optimization, gradient boosting, neural networks, explainability
131
+
132
+ - **[East UI](https://github.com/elaraai/east-ui)**: East types and expressions for building dashboards and interactive layouts. Define UIs as data structures that render consistently across React, web, and other environments.
133
+ - [@elaraai/east-ui](https://www.npmjs.com/package/@elaraai/east-ui): 50+ typed UI components for layouts, forms, charts, tables, dialogs
134
+ - [@elaraai/east-ui-components](https://www.npmjs.com/package/@elaraai/east-ui-components): React renderer with Chakra UI styling
135
+
136
+ - **[e3 - East Execution Engine](https://github.com/elaraai/e3)**: Durable execution engine for running East pipelines at scale. Features Git-like content-addressable storage, automatic memoization, task queuing, and real-time monitoring.
137
+ - [@elaraai/e3](https://www.npmjs.com/package/@elaraai/e3): SDK for authoring e3 packages with typed tasks and pipelines
138
+ - [@elaraai/e3-core](https://www.npmjs.com/package/@elaraai/e3-core): Git-like object store, task queue, result caching
139
+ - [@elaraai/e3-types](https://www.npmjs.com/package/@elaraai/e3-types): Shared type definitions for e3 packages
140
+ - [@elaraai/e3-cli](https://www.npmjs.com/package/@elaraai/e3-cli): `e3 init`, `e3 run`, `e3 logs` commands for managing and monitoring tasks
141
+ - [@elaraai/e3-api-client](https://www.npmjs.com/package/@elaraai/e3-api-client): HTTP client for remote e3 servers
142
+ - [@elaraai/e3-api-server](https://www.npmjs.com/package/@elaraai/e3-api-server): REST API server for e3 repositories
143
+
144
+ ## Links
145
+
146
+ - **Website**: [https://elaraai.com/](https://elaraai.com/)
147
+ - **East Repository**: [https://github.com/elaraai/East](https://github.com/elaraai/East)
148
+ - **Issues**: [https://github.com/elaraai/east-node/issues](https://github.com/elaraai/east-node/issues)
149
+ - **Email**: support@elara.ai
150
+
151
+ ## About Elara
152
+
153
+ East is developed by [Elara AI Pty Ltd](https://elaraai.com/), an AI-powered platform that creates economic digital twins of businesses that optimize performance. Elara combines business objectives, decisions and data to help organizations make data-driven decisions across operations, purchasing, sales and customer engagement, and project and investment planning. East powers the computational layer of Elara solutions, enabling the expression of complex business logic and data in a simple, type-safe and portable language.
154
+
155
+ ---
156
+
157
+ *Developed by [Elara AI Pty Ltd](https://elaraai.com/)*
package/dist/cli.d.ts ADDED
@@ -0,0 +1,6 @@
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
+ export declare function main(): void;
6
+ //# sourceMappingURL=cli.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cli.d.ts","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAuFH,wBAAgB,IAAI,IAAI,IAAI,CAyB3B"}
package/dist/cli.js ADDED
@@ -0,0 +1,85 @@
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 { Command } from 'commander';
6
+ import { createRequire } from 'module';
7
+ import { loadPlatforms, loadPlatformWithMetadata } from './loader.js';
8
+ import { runProgram } from './runner.js';
9
+ const require = createRequire(import.meta.url);
10
+ const pkg = require('../package.json');
11
+ async function cmdRun(irFile, options) {
12
+ const packages = options.package ?? [];
13
+ if (packages.length === 0) {
14
+ console.error('Error: At least one platform package is required.');
15
+ console.error('Example: east-node run program.beast2 -p @elaraai/east-node-std');
16
+ process.exit(1);
17
+ }
18
+ try {
19
+ if (options.verbose) {
20
+ console.error(`Loading ${packages.length} platform package(s)...`);
21
+ }
22
+ const platformFns = await loadPlatforms(packages);
23
+ if (options.verbose) {
24
+ console.error(`Loaded ${platformFns.length} platform function(s)`);
25
+ console.error(`Running: ${irFile}`);
26
+ }
27
+ const result = await runProgram(irFile, platformFns, options.input ?? [], options.output, options.verbose ?? false);
28
+ // If no output file specified, print result to stdout
29
+ if (!options.output && result !== undefined && result !== null) {
30
+ console.log(JSON.stringify(result, null, 2));
31
+ }
32
+ }
33
+ catch (err) {
34
+ console.error(`Error: ${err.message}`);
35
+ process.exit(1);
36
+ }
37
+ }
38
+ async function cmdVersion(options) {
39
+ console.log(`${pkg.name} ${pkg.version}`);
40
+ // Try to get east version
41
+ try {
42
+ const eastPkg = require('@elaraai/east/package.json');
43
+ console.log(`@elaraai/east ${eastPkg.version}`);
44
+ }
45
+ catch {
46
+ // east package not found or no package.json export
47
+ }
48
+ const packages = options.package ?? [];
49
+ if (packages.length > 0) {
50
+ console.log('');
51
+ console.log('Platforms:');
52
+ for (const pkgName of packages) {
53
+ try {
54
+ const meta = await loadPlatformWithMetadata(pkgName);
55
+ console.log(` ${meta.name} ${meta.version} (${meta.fns.length} platform functions)`);
56
+ }
57
+ catch (err) {
58
+ console.log(` ${pkgName}: ${err.message}`);
59
+ }
60
+ }
61
+ }
62
+ }
63
+ export function main() {
64
+ const program = new Command();
65
+ program
66
+ .name('east-node')
67
+ .description('Run East IR programs with Node.js platform functions')
68
+ .version(pkg.version);
69
+ program
70
+ .command('run')
71
+ .description('Run an East IR program')
72
+ .argument('<ir_file>', 'Path to IR file (.beast2, .beast, .east, or .json)')
73
+ .option('-p, --package <package...>', 'Platform packages to load (can be repeated)')
74
+ .option('-i, --input <file...>', 'Input data files (order matches function parameters)')
75
+ .option('-o, --output <file>', 'Output file path for result')
76
+ .option('-v, --verbose', 'Enable verbose output')
77
+ .action(cmdRun);
78
+ program
79
+ .command('version')
80
+ .description('Show version information')
81
+ .option('-p, --package <package...>', 'Platform packages to check')
82
+ .action(cmdVersion);
83
+ program.parse();
84
+ }
85
+ //# sourceMappingURL=cli.js.map
@@ -0,0 +1 @@
1
+ {"version":3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AAI,IAAI,IAAI,CAAC,OAAO,KAAK,IAAI,CAAC,GAAG,CAAC,MAAM,sBAAsB,CAAC,CAAC;YAC1F,CAAC;YAAC,OAAO,GAAG,EAAE,CAAC;gBACX,OAAO,CAAC,GAAG,CAAC,KAAK,OAAO,KAAM,GAAa,CAAC,OAAO,EAAE,CAAC,CAAC;YAC3D,CAAC;QACL,CAAC;IACL,CAAC;AACL,CAAC;AAED,MAAM,UAAU,IAAI;IAChB,MAAM,OAAO,GAAG,IAAI,OAAO,EAAE,CAAC;IAE9B,OAAO;SACF,IAAI,CAAC,WAAW,CAAC;SACjB,WAAW,CAAC,sDAAsD,CAAC;SACnE,OAAO,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;IAE1B,OAAO;SACF,OAAO,CAAC,KAAK,CAAC;SACd,WAAW,CAAC,wBAAwB,CAAC;SACrC,QAAQ,CAAC,WAAW,EAAE,oDAAoD,CAAC;SAC3E,MAAM,CAAC,4BAA4B,EAAE,6CAA6C,CAAC;SACnF,MAAM,CAAC,uBAAuB,EAAE,sDAAsD,CAAC;SACvF,MAAM,CAAC,qBAAqB,EAAE,6BAA6B,CAAC;SAC5D,MAAM,CAAC,eAAe,EAAE,uBAAuB,CAAC;SAChD,MAAM,CAAC,MAAM,CAAC,CAAC;IAEpB,OAAO;SACF,OAAO,CAAC,SAAS,CAAC;SAClB,WAAW,CAAC,0BAA0B,CAAC;SACvC,MAAM,CAAC,4BAA4B,EAAE,4BAA4B,CAAC;SAClE,MAAM,CAAC,UAAU,CAAC,CAAC;IAExB,OAAO,CAAC,KAAK,EAAE,CAAC;AACpB,CAAC"}
@@ -0,0 +1,9 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * Copyright (c) 2025 Elara AI Pty Ltd
4
+ * Dual-licensed under AGPL-3.0 and commercial license. See LICENSE for details.
5
+ */
6
+ import { main } from './cli.js';
7
+ export declare const __version__: string;
8
+ export { main };
9
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AACA;;;GAGG;AASH,OAAO,EAAE,IAAI,EAAE,MAAM,UAAU,CAAC;AAKhC,eAAO,MAAM,WAAW,QAAc,CAAC;AACvC,OAAO,EAAE,IAAI,EAAE,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,18 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * Copyright (c) 2025 Elara AI Pty Ltd
4
+ * Dual-licensed under AGPL-3.0 and commercial license. See LICENSE for details.
5
+ */
6
+ /**
7
+ * East Node CLI - Command-line interface for running East IR programs.
8
+ *
9
+ * @packageDocumentation
10
+ */
11
+ import { createRequire } from 'module';
12
+ import { main } from './cli.js';
13
+ const require = createRequire(import.meta.url);
14
+ const pkg = require('../package.json');
15
+ export const __version__ = pkg.version;
16
+ export { main };
17
+ main();
18
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AACA;;;GAGG;AAEH;;;;GAIG;AAEH,OAAO,EAAE,aAAa,EAAE,MAAM,QAAQ,CAAC;AACvC,OAAO,EAAE,IAAI,EAAE,MAAM,UAAU,CAAC;AAEhC,MAAM,OAAO,GAAG,aAAa,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AAC/C,MAAM,GAAG,GAAG,OAAO,CAAC,iBAAiB,CAAwB,CAAC;AAE9D,MAAM,CAAC,MAAM,WAAW,GAAG,GAAG,CAAC,OAAO,CAAC;AACvC,OAAO,EAAE,IAAI,EAAE,CAAC;AAEhB,IAAI,EAAE,CAAC"}
@@ -0,0 +1,65 @@
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 { type EastTypeValue } from '@elaraai/east';
6
+ import type { PlatformFunction, IR, ValueTypeOf } from '@elaraai/east/internal';
7
+ /**
8
+ * Metadata about a loaded platform package.
9
+ */
10
+ export interface PlatformMetadata {
11
+ /** Package name */
12
+ name: string;
13
+ /** Package version */
14
+ version: string;
15
+ /** Platform functions exported by the package */
16
+ fns: PlatformFunction[];
17
+ }
18
+ /**
19
+ * Loads platform functions from a package.
20
+ *
21
+ * The package must export a `./platform` subpath with a default export
22
+ * of `PlatformFunction[]`.
23
+ *
24
+ * @param packageName - The npm package name (e.g., "@elaraai/east-node-std")
25
+ * @returns Array of platform functions
26
+ * @throws Error if package cannot be loaded or doesn't follow convention
27
+ */
28
+ export declare function loadPlatform(packageName: string): Promise<PlatformFunction[]>;
29
+ /**
30
+ * Loads platform functions with metadata from a package.
31
+ *
32
+ * @param packageName - The npm package name
33
+ * @returns Platform metadata including name, version, and functions
34
+ */
35
+ export declare function loadPlatformWithMetadata(packageName: string): Promise<PlatformMetadata>;
36
+ /**
37
+ * Loads platform functions from multiple packages.
38
+ *
39
+ * @param packageNames - Array of npm package names
40
+ * @returns Combined array of all platform functions
41
+ */
42
+ export declare function loadPlatforms(packageNames: string[]): Promise<PlatformFunction[]>;
43
+ /**
44
+ * Loads an IR file and returns the parsed IR.
45
+ *
46
+ * Supports the following formats:
47
+ * - `.beast2`, `.beast` - Binary East format (self-describing)
48
+ * - `.east` - Text East format
49
+ * - `.json` - JSON format
50
+ *
51
+ * @param filePath - Path to the IR file
52
+ * @returns Parsed IR (FunctionIR or AsyncFunctionIR)
53
+ */
54
+ export declare function loadIR(filePath: string): ValueTypeOf<IR>;
55
+ /**
56
+ * Loads input data from a file.
57
+ *
58
+ * The type of the input must be provided to decode correctly.
59
+ *
60
+ * @param filePath - Path to the input file
61
+ * @param type - The expected East type of the input
62
+ * @returns Decoded value
63
+ */
64
+ export declare function loadInput(filePath: string, type: EastTypeValue): unknown;
65
+ //# sourceMappingURL=loader.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"loader.d.ts","sourceRoot":"","sources":["../src/loader.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAKH,OAAO,EAMH,KAAK,aAAa,EACrB,MAAM,eAAe,CAAC;AACvB,OAAO,KAAK,EAAE,gBAAgB,EAAE,EAAE,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AAahF;;GAEG;AACH,MAAM,WAAW,gBAAgB;IAC7B,mBAAmB;IACnB,IAAI,EAAE,MAAM,CAAC;IACb,sBAAsB;IACtB,OAAO,EAAE,MAAM,CAAC;IAChB,iDAAiD;IACjD,GAAG,EAAE,gBAAgB,EAAE,CAAC;CAC3B;AAED;;;;;;;;;GASG;AACH,wBAAsB,YAAY,CAAC,WAAW,EAAE,MAAM,GAAG,OAAO,CAAC,gBAAgB,EAAE,CAAC,CAoCnF;AAED;;;;;GAKG;AACH,wBAAsB,wBAAwB,CAAC,WAAW,EAAE,MAAM,GAAG,OAAO,CAAC,gBAAgB,CAAC,CAgB7F;AAED;;;;;GAKG;AACH,wBAAsB,aAAa,CAAC,YAAY,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,gBAAgB,EAAE,CAAC,CASvF;AAmDD;;;;;;;;;;GAUG;AACH,wBAAgB,MAAM,CAAC,QAAQ,EAAE,MAAM,GAAG,WAAW,CAAC,EAAE,CAAC,CAgCxD;AAED;;;;;;;;GAQG;AACH,wBAAgB,SAAS,CAAC,QAAQ,EAAE,MAAM,EAAE,IAAI,EAAE,aAAa,GAAG,OAAO,CAoBxE"}
package/dist/loader.js ADDED
@@ -0,0 +1,200 @@
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 { readFileSync } from 'fs';
6
+ import { createRequire } from 'module';
7
+ import { extname } from 'path';
8
+ import { IRType, decodeBeast2For, decodeBeast2, decodeEastFor, decodeJSONFor, } from '@elaraai/east';
9
+ const require = createRequire(import.meta.url);
10
+ // Decoder for IR from beast2 format (self-describing)
11
+ const decodeIRFromBeast2 = decodeBeast2For(IRType);
12
+ // Decoder for IR from east text format
13
+ const decodeIRFromEast = decodeEastFor(IRType);
14
+ // Decoder for IR from JSON format
15
+ const decodeIRFromJSON = decodeJSONFor(IRType);
16
+ /**
17
+ * Loads platform functions from a package.
18
+ *
19
+ * The package must export a `./platform` subpath with a default export
20
+ * of `PlatformFunction[]`.
21
+ *
22
+ * @param packageName - The npm package name (e.g., "@elaraai/east-node-std")
23
+ * @returns Array of platform functions
24
+ * @throws Error if package cannot be loaded or doesn't follow convention
25
+ */
26
+ export async function loadPlatform(packageName) {
27
+ try {
28
+ // Dynamic import of the platform subpath
29
+ const platformModule = await import(`${packageName}/platform`);
30
+ const fns = platformModule.default;
31
+ // Validate the export
32
+ if (!Array.isArray(fns)) {
33
+ throw new Error(`Package "${packageName}" does not export a valid platform. ` +
34
+ `Expected default export of PlatformFunction[], got ${typeof fns}.`);
35
+ }
36
+ // Validate each platform function structurally
37
+ for (let i = 0; i < fns.length; i++) {
38
+ const fn = fns[i];
39
+ if (!isValidPlatformFunction(fn)) {
40
+ throw new Error(`Package "${packageName}" exports invalid platform function at index ${i}. ` +
41
+ `Expected { name: string, inputs: EastTypeValue[], output: EastTypeValue, type: 'sync' | 'async', fn: Function }.`);
42
+ }
43
+ }
44
+ return fns;
45
+ }
46
+ catch (err) {
47
+ if (err.code === 'ERR_MODULE_NOT_FOUND' ||
48
+ err.code === 'MODULE_NOT_FOUND') {
49
+ throw new Error(`Could not load platform package "${packageName}". ` +
50
+ `Make sure it is installed: npm install ${packageName}`);
51
+ }
52
+ throw err;
53
+ }
54
+ }
55
+ /**
56
+ * Loads platform functions with metadata from a package.
57
+ *
58
+ * @param packageName - The npm package name
59
+ * @returns Platform metadata including name, version, and functions
60
+ */
61
+ export async function loadPlatformWithMetadata(packageName) {
62
+ const fns = await loadPlatform(packageName);
63
+ // Load package.json for version info
64
+ let name = packageName;
65
+ let version = 'unknown';
66
+ try {
67
+ const pkgJson = require(`${packageName}/package.json`);
68
+ name = pkgJson.name ?? packageName;
69
+ version = pkgJson.version ?? 'unknown';
70
+ }
71
+ catch {
72
+ // Package doesn't export package.json, use defaults
73
+ }
74
+ return { name, version, fns };
75
+ }
76
+ /**
77
+ * Loads platform functions from multiple packages.
78
+ *
79
+ * @param packageNames - Array of npm package names
80
+ * @returns Combined array of all platform functions
81
+ */
82
+ export async function loadPlatforms(packageNames) {
83
+ const allFns = [];
84
+ for (const pkgName of packageNames) {
85
+ const fns = await loadPlatform(pkgName);
86
+ allFns.push(...fns);
87
+ }
88
+ return allFns;
89
+ }
90
+ /**
91
+ * Validates that a value looks like a PlatformFunction.
92
+ * We use structural validation since PlatformFunction contains JS functions.
93
+ */
94
+ function isValidPlatformFunction(value) {
95
+ if (typeof value !== 'object' || value === null) {
96
+ return false;
97
+ }
98
+ const fn = value;
99
+ // Check required string fields
100
+ if (typeof fn.name !== 'string')
101
+ return false;
102
+ if (fn.type !== 'sync' && fn.type !== 'async')
103
+ return false;
104
+ // Check fn is a function
105
+ if (typeof fn.fn !== 'function')
106
+ return false;
107
+ // Check inputs is an array
108
+ if (!Array.isArray(fn.inputs))
109
+ return false;
110
+ // Check output exists (we trust the type structure)
111
+ if (fn.output === undefined)
112
+ return false;
113
+ return true;
114
+ }
115
+ /**
116
+ * Determines the file format from extension.
117
+ */
118
+ function getFileFormat(filePath) {
119
+ const ext = extname(filePath).toLowerCase();
120
+ switch (ext) {
121
+ case '.beast2':
122
+ case '.beast':
123
+ return 'beast2';
124
+ case '.east':
125
+ return 'east';
126
+ case '.json':
127
+ return 'json';
128
+ default:
129
+ throw new Error(`Unsupported file extension "${ext}". ` +
130
+ `Supported extensions: .beast2, .beast, .east, .json`);
131
+ }
132
+ }
133
+ /**
134
+ * Loads an IR file and returns the parsed IR.
135
+ *
136
+ * Supports the following formats:
137
+ * - `.beast2`, `.beast` - Binary East format (self-describing)
138
+ * - `.east` - Text East format
139
+ * - `.json` - JSON format
140
+ *
141
+ * @param filePath - Path to the IR file
142
+ * @returns Parsed IR (FunctionIR or AsyncFunctionIR)
143
+ */
144
+ export function loadIR(filePath) {
145
+ const format = getFileFormat(filePath);
146
+ const data = readFileSync(filePath);
147
+ let ir;
148
+ switch (format) {
149
+ case 'beast2': {
150
+ // Beast2 is self-describing, includes type info in the file
151
+ ir = decodeIRFromBeast2(data);
152
+ break;
153
+ }
154
+ case 'east': {
155
+ // East text format, decode using IR type
156
+ ir = decodeIRFromEast(data);
157
+ break;
158
+ }
159
+ case 'json': {
160
+ // JSON format, decode using IR type
161
+ ir = decodeIRFromJSON(data);
162
+ break;
163
+ }
164
+ }
165
+ // Validate that the IR is a function
166
+ if (ir.type !== 'Function' && ir.type !== 'AsyncFunction') {
167
+ throw new Error(`IR file must contain a function or async function, got "${ir.type}"`);
168
+ }
169
+ return ir;
170
+ }
171
+ /**
172
+ * Loads input data from a file.
173
+ *
174
+ * The type of the input must be provided to decode correctly.
175
+ *
176
+ * @param filePath - Path to the input file
177
+ * @param type - The expected East type of the input
178
+ * @returns Decoded value
179
+ */
180
+ export function loadInput(filePath, type) {
181
+ const format = getFileFormat(filePath);
182
+ const data = readFileSync(filePath);
183
+ switch (format) {
184
+ case 'beast2': {
185
+ // For inputs, we use decodeBeast2 which is self-describing
186
+ // This allows loading data without knowing the exact type
187
+ const result = decodeBeast2(data);
188
+ return result.value;
189
+ }
190
+ case 'east': {
191
+ const decoder = decodeEastFor(type);
192
+ return decoder(data);
193
+ }
194
+ case 'json': {
195
+ const decoder = decodeJSONFor(type);
196
+ return decoder(data);
197
+ }
198
+ }
199
+ }
200
+ //# sourceMappingURL=loader.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"loader.js","sourceRoot":"","sources":["../src/loader.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,YAAY,EAAE,MAAM,IAAI,CAAC;AAClC,OAAO,EAAE,aAAa,EAAE,MAAM,QAAQ,CAAC;AACvC,OAAO,EAAE,OAAO,EAAE,MAAM,MAAM,CAAC;AAC/B,OAAO,EACH,MAA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 * Copyright (c) 2025 Elara AI Pty Ltd
3
+ * Dual-licensed under AGPL-3.0 and commercial license. See LICENSE for details.
4
+ */
5
+ import type { PlatformFunction } from '@elaraai/east/internal';
6
+ /**
7
+ * Runs an East IR program.
8
+ *
9
+ * @param irPath - Path to the IR file
10
+ * @param platformFns - Platform functions to use for execution
11
+ * @param inputPaths - Paths to input data files (order matches function parameters)
12
+ * @param outputPath - Optional path to write the result
13
+ * @param verbose - Enable verbose logging
14
+ * @returns The result of execution (or undefined if written to file)
15
+ */
16
+ export declare function runProgram(irPath: string, platformFns: PlatformFunction[], inputPaths: string[], outputPath?: string, verbose?: boolean): Promise<unknown>;
17
+ //# sourceMappingURL=runner.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"runner.d.ts","sourceRoot":"","sources":["../src/runner.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAWH,OAAO,KAAK,EAAE,gBAAgB,EAA4C,MAAM,wBAAwB,CAAC;AAGzG;;;;;;;;;GASG;AACH,wBAAsB,UAAU,CAC5B,MAAM,EAAE,MAAM,EACd,WAAW,EAAE,gBAAgB,EAAE,EAC/B,UAAU,EAAE,MAAM,EAAE,EACpB,UAAU,CAAC,EAAE,MAAM,EACnB,OAAO,GAAE,OAAe,GACzB,OAAO,CAAC,OAAO,CAAC,CAsElB"}