@elaraai/east 1.0.68 → 1.0.69
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/dist/src/ast.d.ts +2 -0
- package/dist/src/ast.d.ts.map +1 -1
- package/dist/src/ast_to_ir.d.ts +7 -3
- package/dist/src/ast_to_ir.d.ts.map +1 -1
- package/dist/src/ast_to_ir.js +62 -15
- package/dist/src/ast_to_ir.js.map +1 -1
- package/dist/src/codegen/codegen.spec.d.ts +6 -0
- package/dist/src/codegen/codegen.spec.d.ts.map +1 -0
- package/dist/src/codegen/codegen.spec.js +763 -0
- package/dist/src/codegen/codegen.spec.js.map +1 -0
- package/dist/src/codegen/doc.d.ts +111 -0
- package/dist/src/codegen/doc.d.ts.map +1 -0
- package/dist/src/codegen/doc.js +350 -0
- package/dist/src/codegen/doc.js.map +1 -0
- package/dist/src/codegen/doc.spec.d.ts +6 -0
- package/dist/src/codegen/doc.spec.d.ts.map +1 -0
- package/dist/src/codegen/doc.spec.js +86 -0
- package/dist/src/codegen/doc.spec.js.map +1 -0
- package/dist/src/codegen/index.d.ts +15 -0
- package/dist/src/codegen/index.d.ts.map +1 -0
- package/dist/src/codegen/index.js +15 -0
- package/dist/src/codegen/index.js.map +1 -0
- package/dist/src/codegen/printer.d.ts +63 -0
- package/dist/src/codegen/printer.d.ts.map +1 -0
- package/dist/src/codegen/printer.js +1529 -0
- package/dist/src/codegen/printer.js.map +1 -0
- package/dist/src/codegen/spellings.d.ts +73 -0
- package/dist/src/codegen/spellings.d.ts.map +1 -0
- package/dist/src/codegen/spellings.js +298 -0
- package/dist/src/codegen/spellings.js.map +1 -0
- package/dist/src/codegen/spellings.spec.d.ts +6 -0
- package/dist/src/codegen/spellings.spec.d.ts.map +1 -0
- package/dist/src/codegen/spellings.spec.js +191 -0
- package/dist/src/codegen/spellings.spec.js.map +1 -0
- package/dist/src/codegen/types.d.ts +67 -0
- package/dist/src/codegen/types.d.ts.map +1 -0
- package/dist/src/codegen/types.js +173 -0
- package/dist/src/codegen/types.js.map +1 -0
- package/dist/src/expr/block.d.ts +148 -0
- package/dist/src/expr/block.d.ts.map +1 -1
- package/dist/src/expr/block.js +168 -4
- package/dist/src/expr/block.js.map +1 -1
- package/dist/src/expr/index.d.ts +155 -2
- package/dist/src/expr/index.d.ts.map +1 -1
- package/dist/src/expr/index.js +155 -2
- package/dist/src/expr/index.js.map +1 -1
- package/dist/src/functions.crossimport.spec.d.ts +6 -0
- package/dist/src/functions.crossimport.spec.d.ts.map +1 -0
- package/dist/src/functions.crossimport.spec.js +45 -0
- package/dist/src/functions.crossimport.spec.js.map +1 -0
- package/dist/src/functions.d.ts +4103 -0
- package/dist/src/functions.d.ts.map +1 -0
- package/dist/src/functions.js +443 -0
- package/dist/src/functions.js.map +1 -0
- package/dist/src/functions.spec.d.ts +6 -0
- package/dist/src/functions.spec.d.ts.map +1 -0
- package/dist/src/functions.spec.js +123 -0
- package/dist/src/functions.spec.js.map +1 -0
- package/dist/src/index.d.ts +2 -0
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +2 -0
- package/dist/src/index.js.map +1 -1
- package/dist/src/naming.d.ts +50 -0
- package/dist/src/naming.d.ts.map +1 -0
- package/dist/src/naming.js +194 -0
- package/dist/src/naming.js.map +1 -0
- package/dist/src/naming.spec.d.ts +6 -0
- package/dist/src/naming.spec.d.ts.map +1 -0
- package/dist/src/naming.spec.js +154 -0
- package/dist/src/naming.spec.js.map +1 -0
- package/dist/src/serialization/beast2/index.spec.js +25 -0
- package/dist/src/serialization/beast2/index.spec.js.map +1 -1
- package/dist/src/serialization/beast2/shared.d.ts +1 -1
- package/dist/src/serialization/beast2/shared.d.ts.map +1 -1
- package/dist/src/serialization/beast2/shared.js +9 -1
- package/dist/src/serialization/beast2/shared.js.map +1 -1
- package/package.json +11 -2
package/dist/src/expr/index.js
CHANGED
|
@@ -27,8 +27,10 @@ export { RecursiveExpr } from './recursive.js';
|
|
|
27
27
|
export { FunctionExpr } from './function.js';
|
|
28
28
|
export { AsyncFunctionExpr } from './asyncfunction.js';
|
|
29
29
|
// Import factory implementation
|
|
30
|
-
import { from, equal, notEqual, less, lessEqual, print, is, greaterEqual, greater, func, str, platform, asyncFunction, asyncPlatform, genericPlatform, asyncGenericPlatform, compile, compileAsync, equals, eq, notEquals, ne, lessThan, lt, lessThanOrEqual, lte, le, greaterThan, gt, greaterThanOrEqual, gte, ge, diff, applyPatch, composePatch, invertPatch } from './block.js';
|
|
31
|
-
|
|
30
|
+
import { from, equal, notEqual, less, lessEqual, print, is, greaterEqual, greater, func, str, platform, asyncFunction, asyncPlatform, genericPlatform, asyncGenericPlatform, compile, compileAsync, equals, eq, notEquals, ne, lessThan, lt, lessThanOrEqual, lte, le, greaterThan, gt, greaterThanOrEqual, gte, ge, diff, applyPatch, composePatch, invertPatch, builtin, as, wrapRecursive, error } from './block.js';
|
|
31
|
+
import { toSource } from '../codegen/index.js';
|
|
32
|
+
import { importFunction, exportFunctions, encodeFunctionManifest, decodeFunctionManifest, linkImports, platformDependencies } from '../functions.js';
|
|
33
|
+
export { BlockBuilder, PLATFORM_DECLARATION, isPlatformDeclaration, equals, eq, notEquals, ne, lessThan, lt, lessThanOrEqual, lte, le, greaterThan, gt, greaterThanOrEqual, gte, ge, diff, applyPatch, composePatch, invertPatch } from './block.js';
|
|
32
34
|
// Import standard libraries
|
|
33
35
|
import IntegerLib from './libs/integer.js';
|
|
34
36
|
import FloatLib from './libs/float.js';
|
|
@@ -332,6 +334,157 @@ export const East = {
|
|
|
332
334
|
* ```
|
|
333
335
|
*/
|
|
334
336
|
asyncGenericPlatform,
|
|
337
|
+
/**
|
|
338
|
+
* Prints an East function (or its IR) as the TypeScript module that
|
|
339
|
+
* rebuilds it — the `East.function` builder surface, the type constructors
|
|
340
|
+
* hoisted to constants. The python twin is `east.codegen.to_python_source`;
|
|
341
|
+
* `east-node transpile` is the CLI. Rebuilding the printed module yields
|
|
342
|
+
* the same IR under `east-c ir normalize`.
|
|
343
|
+
*
|
|
344
|
+
* @param fnOrIr - An `East.function` result, its `toIR()`, or an IR value
|
|
345
|
+
* @param options - `name` (the export, default `main`) and `importFrom`
|
|
346
|
+
* (the module specifier, default `@elaraai/east`)
|
|
347
|
+
* @returns The module source
|
|
348
|
+
*
|
|
349
|
+
* @example
|
|
350
|
+
* ```ts
|
|
351
|
+
* const double = East.function([IntegerType], IntegerType, ($, x) => x.multiply(2n));
|
|
352
|
+
* East.toSource(double);
|
|
353
|
+
* // export const main = East.function([IntegerType], IntegerType, ($, _0) => {
|
|
354
|
+
* // return _0.multiply(2n);
|
|
355
|
+
* // });
|
|
356
|
+
* ```
|
|
357
|
+
*/
|
|
358
|
+
toSource,
|
|
359
|
+
/**
|
|
360
|
+
* Refers to a function exported by another package — authored in either
|
|
361
|
+
* language — as a typed, callable function expression. Unresolved it is a
|
|
362
|
+
* `Platform` node named `east.importFunction`; `East.linkImports` (which
|
|
363
|
+
* `e3 export` runs on every task) embeds the exported IR after checking
|
|
364
|
+
* the declared type equals the exported type exactly. Python's
|
|
365
|
+
* `East.import_function`.
|
|
366
|
+
*
|
|
367
|
+
* @param pkg - The exporting package's name (its manifest's `package`)
|
|
368
|
+
* @param name - The function's name in that package
|
|
369
|
+
* @param type - The declared `FunctionType` / `AsyncFunctionType`
|
|
370
|
+
* @returns A callable function expression of `type`
|
|
371
|
+
*
|
|
372
|
+
* @example
|
|
373
|
+
* ```ts
|
|
374
|
+
* const score = East.importFunction("pricing", "score", FunctionType([RowType], FloatType));
|
|
375
|
+
* const total = East.function([ArrayType(RowType)], FloatType, ($, rows) => rows.map(($, r) => score(r)).sum());
|
|
376
|
+
* ```
|
|
377
|
+
*/
|
|
378
|
+
importFunction,
|
|
379
|
+
/**
|
|
380
|
+
* Builds a package's function manifest — each function's IR, declared
|
|
381
|
+
* type and platform dependencies — for other packages (in either language)
|
|
382
|
+
* to import. Functions must be closed values: no captures, no unresolved
|
|
383
|
+
* imports. Python's `East.export_functions`; the CLIs are `east-node
|
|
384
|
+
* export-functions` / `east-py export-functions`.
|
|
385
|
+
*
|
|
386
|
+
* @param pkg - The package name importers will use
|
|
387
|
+
* @param version - Its version
|
|
388
|
+
* @param functions - Name → `East.function` result
|
|
389
|
+
* @param options - `providers`: platform name → the package implementing it
|
|
390
|
+
* @returns The manifest value (`East.encodeFunctionManifest` writes it)
|
|
391
|
+
*
|
|
392
|
+
* @example
|
|
393
|
+
* ```ts
|
|
394
|
+
* const manifest = East.exportFunctions("maths", "1.0.0", { double, halve });
|
|
395
|
+
* writeFileSync("maths.functions.beast2", East.encodeFunctionManifest(manifest));
|
|
396
|
+
* ```
|
|
397
|
+
*/
|
|
398
|
+
exportFunctions,
|
|
399
|
+
/** Encodes a function manifest as beast2 (readable by either language). */
|
|
400
|
+
encodeFunctionManifest,
|
|
401
|
+
/** Decodes a function manifest written by either language. */
|
|
402
|
+
decodeFunctionManifest,
|
|
403
|
+
/**
|
|
404
|
+
* Resolves every `East.importFunction` in a function against the given
|
|
405
|
+
* manifests: exact type check, then the exported IR embedded as a
|
|
406
|
+
* `Let`-bound constant. Returns the linked IR and the imports resolved
|
|
407
|
+
* (with their platform dependencies, which `e3 export` validates against
|
|
408
|
+
* the task's runner). Python's `East.link_imports`.
|
|
409
|
+
*
|
|
410
|
+
* @param fnOrIr - The importing function (or its IR)
|
|
411
|
+
* @param manifests - The exporting packages' manifests
|
|
412
|
+
* @returns `{ ir, imports }`
|
|
413
|
+
*
|
|
414
|
+
* @example
|
|
415
|
+
* ```ts
|
|
416
|
+
* const { ir } = East.linkImports(total, [East.decodeFunctionManifest(readFileSync("pricing.functions.beast2"))]);
|
|
417
|
+
* East.compile(new EastIR(ir), [])(rows);
|
|
418
|
+
* ```
|
|
419
|
+
*/
|
|
420
|
+
linkImports,
|
|
421
|
+
/**
|
|
422
|
+
* The platform functions a function calls — name, signature, asyncness —
|
|
423
|
+
* in first-use order. What an export manifest records per function.
|
|
424
|
+
*
|
|
425
|
+
* @param fnOrIr - The function (or its IR)
|
|
426
|
+
* @param providers - Platform name → the package implementing it, recorded when given
|
|
427
|
+
* @returns The dependencies
|
|
428
|
+
*/
|
|
429
|
+
platformDependencies,
|
|
430
|
+
/**
|
|
431
|
+
* Calls an East builtin by name — the raw spelling for a builtin the
|
|
432
|
+
* surface has no method for (see `RAW_ONLY`).
|
|
433
|
+
*
|
|
434
|
+
* @param name - The builtin's IR name
|
|
435
|
+
* @param typeParameters - Its type parameters, in declaration order
|
|
436
|
+
* @param args - Its arguments in IR order
|
|
437
|
+
* @param outputType - The type of the result
|
|
438
|
+
* @returns The builtin call expression
|
|
439
|
+
*
|
|
440
|
+
* @example
|
|
441
|
+
* ```ts
|
|
442
|
+
* East.builtin("ArraySize", [IntegerType], [xs], IntegerType)
|
|
443
|
+
* ```
|
|
444
|
+
*/
|
|
445
|
+
builtin,
|
|
446
|
+
/**
|
|
447
|
+
* Widens a value to a declared supertype explicitly (an `As` node) —
|
|
448
|
+
* python's `East.as_`.
|
|
449
|
+
*
|
|
450
|
+
* @param value - The value or expression to widen
|
|
451
|
+
* @param type - The wider type
|
|
452
|
+
* @returns The value as an expression of `type`
|
|
453
|
+
*
|
|
454
|
+
* @example
|
|
455
|
+
* ```ts
|
|
456
|
+
* East.as(East.value(variant("circle", 2.0)), VariantType({ circle: FloatType, square: FloatType }))
|
|
457
|
+
* ```
|
|
458
|
+
*/
|
|
459
|
+
as,
|
|
460
|
+
/**
|
|
461
|
+
* Wraps a value of a recursive type's node type in the recursive type
|
|
462
|
+
* (a `WrapRecursive` node); `.unwrap()` is its inverse.
|
|
463
|
+
*
|
|
464
|
+
* @param value - The value or expression of the node type
|
|
465
|
+
* @param type - The recursive type
|
|
466
|
+
* @returns A `RecursiveExpr` of `type`
|
|
467
|
+
*
|
|
468
|
+
* @example
|
|
469
|
+
* ```ts
|
|
470
|
+
* East.wrapRecursive(variant("nil", null), ListType)
|
|
471
|
+
* ```
|
|
472
|
+
*/
|
|
473
|
+
wrapRecursive,
|
|
474
|
+
/**
|
|
475
|
+
* Raises an East runtime error with the given message — the Never-typed
|
|
476
|
+
* error EXPRESSION (the statement form is `$.error`).
|
|
477
|
+
*
|
|
478
|
+
* @param message - The error message
|
|
479
|
+
* @returns A `NeverExpr`
|
|
480
|
+
*
|
|
481
|
+
* @example
|
|
482
|
+
* ```ts
|
|
483
|
+
* const checked = East.function([IntegerType], IntegerType, ($, x) =>
|
|
484
|
+
* East.less(x, 0n).ifElse(() => East.error("negative"), () => x));
|
|
485
|
+
* ```
|
|
486
|
+
*/
|
|
487
|
+
error,
|
|
335
488
|
/**
|
|
336
489
|
* Converts any East expression to its string representation.
|
|
337
490
|
* Uses the East serialization format (not JSON).
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/expr/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,sBAAsB;AACtB,cAAc,YAAY,CAAC;AAE3B,+CAA+C;AAC/C,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAEjC,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AACvC,OAAO,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AACrC,OAAO,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAC3C,OAAO,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAC3C,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AACvC,OAAO,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAC7C,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AACrC,OAAO,EAAE,OAAO,EAAE,MAAM,UAAU,CAAC;AACnC,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AACvC,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EA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,IAAI,EAAE,OAAO;IAEb;;;;;;;;;;OAUG;IACH,KAAK,EAAE,QAAQ;IAEf;;;OAGG;IACH,MAAM,EAAE,SAAS;IAEjB;;;OAGG;IACH,MAAM,EAAE,SAAS;IAEjB;;;;;;;;OAQG;IACH,GAAG,EAAE,MAAM;IAEX;;;;;;;;;;;;;;OAcG;IACH,IAAI,EAAE,OAAO;CACd,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"functions.crossimport.spec.d.ts","sourceRoot":"","sources":["../../src/functions.crossimport.spec.ts"],"names":[],"mappings":"AAAA;;;GAGG"}
|
|
@@ -0,0 +1,45 @@
|
|
|
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
|
+
/**
|
|
6
|
+
* python → TypeScript (#628): functions authored in python
|
|
7
|
+
* (`libs/east-py/packages/east-py/tests/fixtures/crosslang_functions.py`,
|
|
8
|
+
* whose manifest `east-py` checks in at `test/fixtures/py-functions.beast2`
|
|
9
|
+
* and keeps current) import into a TypeScript function by name, link into
|
|
10
|
+
* pure IR, and run on the reference compiler with no python present. The
|
|
11
|
+
* other direction lives in east-py's `test_cross_import.py`.
|
|
12
|
+
*/
|
|
13
|
+
import { describe, test } from "node:test";
|
|
14
|
+
import assert from "node:assert/strict";
|
|
15
|
+
import { readFileSync } from "node:fs";
|
|
16
|
+
import { East, EastIR, ArrayType, FloatType, FunctionType, IntegerType, StringType, StructType, } from "./index.js";
|
|
17
|
+
const FIXTURE = new URL("../../test/fixtures/py-functions.beast2", import.meta.url);
|
|
18
|
+
const Row = StructType({ qty: IntegerType, price: FloatType });
|
|
19
|
+
describe("cross-language import: python-authored functions in TypeScript", () => {
|
|
20
|
+
const manifest = East.decodeFunctionManifest(new Uint8Array(readFileSync(FIXTURE)));
|
|
21
|
+
test("the manifest names the package and its functions", () => {
|
|
22
|
+
assert.equal(manifest.package, "crosslang_py");
|
|
23
|
+
assert.deepEqual(manifest.functions.map(f => f.name), ["greet", "score", "total"]);
|
|
24
|
+
assert.deepEqual(manifest.functions.map(f => f.platforms.length), [0, 0, 0]);
|
|
25
|
+
});
|
|
26
|
+
test("imported python functions link and run, alone and inside callbacks", () => {
|
|
27
|
+
const score = East.importFunction("crosslang_py", "score", FunctionType([Row], FloatType));
|
|
28
|
+
const total = East.importFunction("crosslang_py", "total", FunctionType([ArrayType(Row)], FloatType));
|
|
29
|
+
const greet = East.importFunction("crosslang_py", "greet", FunctionType([StringType, IntegerType], StringType));
|
|
30
|
+
const user = East.function([ArrayType(Row), StringType], StringType, ($, rows, name) => {
|
|
31
|
+
const best = $.const(rows.map(($, r) => score(r)).reduce(($, acc, x) => East.greater(x, acc).ifElse($ => x, $ => acc), 0.0));
|
|
32
|
+
return greet(name, 2n).concat(" ").concat(East.print(total(rows))).concat(" ").concat(East.print(best));
|
|
33
|
+
});
|
|
34
|
+
const { ir, imports } = East.linkImports(user, [manifest]);
|
|
35
|
+
assert.deepEqual(imports.map(i => i.name), ["score", "greet", "total"]);
|
|
36
|
+
const run = new EastIR(ir).compile([]);
|
|
37
|
+
assert.equal(run([{ qty: 2n, price: 1.5 }, { qty: 3n, price: 2.0 }], "hi"), "hi!hi! 9.0 6.0");
|
|
38
|
+
});
|
|
39
|
+
test("a wrong declared type is refused with both types named", () => {
|
|
40
|
+
const score = East.importFunction("crosslang_py", "score", FunctionType([Row], IntegerType));
|
|
41
|
+
const user = East.function([Row], IntegerType, ($, r) => score(r));
|
|
42
|
+
assert.throws(() => East.linkImports(user, [manifest]), /crosslang_py\.score is imported as .* but exported as/);
|
|
43
|
+
});
|
|
44
|
+
});
|
|
45
|
+
//# sourceMappingURL=functions.crossimport.spec.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"functions.crossimport.spec.js","sourceRoot":"","sources":["../../src/functions.crossimport.spec.ts"],"names":[],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