@lemmabase/lemma-engine 0.9.9 → 0.9.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 CHANGED
@@ -111,13 +111,13 @@ A pre-wired Monaco adapter ships at `@lemmabase/lemma-engine/monaco`.
111
111
 
112
112
  | Method | Description |
113
113
  |--------|-------------|
114
- | `load(code)` | Load inline Lemma source as a volatile workspace source |
114
+ | `load(code)` | Load inline Lemma source as a volatile source in the default repository |
115
115
  | `load(sources)` | Load multiple sources in one planning pass (`Record<label, text>` or `[label, code][]`; object keys keep insertion order; `@org/pkg` keys tag LemmaBase repositories) |
116
116
  | `Engine.withLimits(limits)` | Static: create engine with named limit overrides (unknown keys throw) |
117
117
  | `Engine.fromSnapshot(bytes)` | Static: restore engine from `snapshot()` bytes (`Uint8Array`) |
118
118
  | `install(name)` | Download a repository from LemmaBase; resolves with `{ source, id }`. Does not load. Rejects with `EngineError[]`. |
119
119
  | `list()` | Slim catalog: `ResolvedRepository[]` with `repository` and temporal `specs` rows. Always includes embedded `lemma` / `spec units`. |
120
- | `show(repo, name, effective?)` | Spec interface + temporal window; `repo` null for workspace. |
120
+ | `show(repo, name, effective?)` | Spec interface + temporal window; `repo` null for the default repository. |
121
121
  | `source(repo, spec?, effective?)` | Canonical Lemma source text. Omit `spec` for whole repository. |
122
122
  | `run({ spec, repository?, effective?, data?, rules?, explain? })` | Evaluate. Omit `rules` for all rules; pass a non-empty array to scope. `[]` errors. Returns a `Response`. `explain: true` adds per-rule explanation trees. |
123
123
  | `remove(repo, name, effective?)` | Remove a temporal spec slice. |
@@ -35,7 +35,7 @@ export class Engine {
35
35
  /**
36
36
  * Load Lemma source(s).
37
37
  *
38
- * - string → one volatile workspace source
38
+ * - string → one volatile source in the default repository
39
39
  * - plain object or `[label, code][]` → labeled sources in one planning pass
40
40
  *
41
41
  * Throws with an array of serialized errors on failure. `null` / `undefined` are rejected.
@@ -158,10 +158,10 @@ export interface InitOutput {
158
158
  readonly engine_source: (a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number) => void;
159
159
  readonly engine_update: (a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number) => void;
160
160
  readonly engine_withLimits: (a: number, b: number) => void;
161
- readonly __wasm_bindgen_func_elem_13544: (a: number, b: number, c: number, d: number) => void;
161
+ readonly __wasm_bindgen_func_elem_13706: (a: number, b: number, c: number, d: number) => void;
162
162
  readonly __wasm_bindgen_func_elem_2736: (a: number, b: number, c: number, d: number) => void;
163
- readonly __wasm_bindgen_func_elem_13550: (a: number, b: number, c: number, d: number) => void;
164
- readonly __wasm_bindgen_func_elem_7929: (a: number, b: number) => void;
163
+ readonly __wasm_bindgen_func_elem_13712: (a: number, b: number, c: number, d: number) => void;
164
+ readonly __wasm_bindgen_func_elem_7982: (a: number, b: number) => void;
165
165
  readonly __wbindgen_export: (a: number, b: number) => number;
166
166
  readonly __wbindgen_export2: (a: number, b: number, c: number, d: number) => number;
167
167
  readonly __wbindgen_export3: (a: number) => void;
package/lemma.bindings.js CHANGED
@@ -117,7 +117,7 @@ export class Engine {
117
117
  /**
118
118
  * Load Lemma source(s).
119
119
  *
120
- * - string → one volatile workspace source
120
+ * - string → one volatile source in the default repository
121
121
  * - plain object or `[label, code][]` → labeled sources in one planning pass
122
122
  *
123
123
  * Throws with an array of serialized errors on failure. `null` / `undefined` are rejected.
@@ -803,7 +803,7 @@ function __wbg_get_imports() {
803
803
  const a = state0.a;
804
804
  state0.a = 0;
805
805
  try {
806
- return __wasm_bindgen_func_elem_13550(a, state0.b, arg0, arg1);
806
+ return __wasm_bindgen_func_elem_13712(a, state0.b, arg0, arg1);
807
807
  } finally {
808
808
  state0.a = a;
809
809
  }
@@ -943,8 +943,8 @@ function __wbg_get_imports() {
943
943
  return addHeapObject(ret);
944
944
  },
945
945
  __wbindgen_cast_0000000000000001: function(arg0, arg1) {
946
- // Cast intrinsic for `Closure(Closure { owned: true, function: Function { arguments: [Externref], shim_idx: 1470, ret: Result(Unit), inner_ret: Some(Result(Unit)) }, mutable: true }) -> Externref`.
947
- const ret = makeMutClosure(arg0, arg1, __wasm_bindgen_func_elem_13544);
946
+ // Cast intrinsic for `Closure(Closure { owned: true, function: Function { arguments: [Externref], shim_idx: 1510, ret: Result(Unit), inner_ret: Some(Result(Unit)) }, mutable: true }) -> Externref`.
947
+ const ret = makeMutClosure(arg0, arg1, __wasm_bindgen_func_elem_13706);
948
948
  return addHeapObject(ret);
949
949
  },
950
950
  __wbindgen_cast_0000000000000002: function(arg0, arg1) {
@@ -953,8 +953,8 @@ function __wbg_get_imports() {
953
953
  return addHeapObject(ret);
954
954
  },
955
955
  __wbindgen_cast_0000000000000003: function(arg0, arg1) {
956
- // Cast intrinsic for `Closure(Closure { owned: true, function: Function { arguments: [], shim_idx: 913, ret: Unit, inner_ret: Some(Unit) }, mutable: true }) -> Externref`.
957
- const ret = makeMutClosure(arg0, arg1, __wasm_bindgen_func_elem_7929);
956
+ // Cast intrinsic for `Closure(Closure { owned: true, function: Function { arguments: [], shim_idx: 910, ret: Unit, inner_ret: Some(Unit) }, mutable: true }) -> Externref`.
957
+ const ret = makeMutClosure(arg0, arg1, __wasm_bindgen_func_elem_7982);
958
958
  return addHeapObject(ret);
959
959
  },
960
960
  __wbindgen_cast_0000000000000004: function(arg0) {
@@ -991,14 +991,14 @@ function __wbg_get_imports() {
991
991
  };
992
992
  }
993
993
 
994
- function __wasm_bindgen_func_elem_7929(arg0, arg1) {
995
- wasm.__wasm_bindgen_func_elem_7929(arg0, arg1);
994
+ function __wasm_bindgen_func_elem_7982(arg0, arg1) {
995
+ wasm.__wasm_bindgen_func_elem_7982(arg0, arg1);
996
996
  }
997
997
 
998
- function __wasm_bindgen_func_elem_13544(arg0, arg1, arg2) {
998
+ function __wasm_bindgen_func_elem_13706(arg0, arg1, arg2) {
999
999
  try {
1000
1000
  const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
1001
- wasm.__wasm_bindgen_func_elem_13544(retptr, arg0, arg1, addHeapObject(arg2));
1001
+ wasm.__wasm_bindgen_func_elem_13706(retptr, arg0, arg1, addHeapObject(arg2));
1002
1002
  var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
1003
1003
  var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
1004
1004
  if (r1) {
@@ -1023,8 +1023,8 @@ function __wasm_bindgen_func_elem_2736(arg0, arg1, arg2) {
1023
1023
  }
1024
1024
  }
1025
1025
 
1026
- function __wasm_bindgen_func_elem_13550(arg0, arg1, arg2, arg3) {
1027
- wasm.__wasm_bindgen_func_elem_13550(arg0, arg1, addHeapObject(arg2), addHeapObject(arg3));
1026
+ function __wasm_bindgen_func_elem_13712(arg0, arg1, arg2, arg3) {
1027
+ wasm.__wasm_bindgen_func_elem_13712(arg0, arg1, addHeapObject(arg2), addHeapObject(arg3));
1028
1028
  }
1029
1029
 
1030
1030
 
package/lemma.d.ts CHANGED
@@ -20,7 +20,7 @@ declare module './lemma.bindings.js' {
20
20
  interface Engine {
21
21
  /**
22
22
  * Load Lemma source(s).
23
- * - string → volatile workspace source
23
+ * - string → volatile source in the default repository
24
24
  * - object → labeled sources (key insertion order); `[label, code][]` → labeled sources (array order)
25
25
  * Throws `EngineError[]` on failure. `null`/`undefined` rejected.
26
26
  */
@@ -36,7 +36,7 @@ declare module './lemma.bindings.js' {
36
36
 
37
37
  /**
38
38
  * JSON serialization of `Vec<ResolvedRepository>` from [`Engine::list`]:
39
- * each item has `repository` (name or null for workspace) and `specs`
39
+ * each item has `repository` (name, or omitted for the default repository) and `specs`
40
40
  * (`ListedSpec` rows: name, effective_from, effective_to).
41
41
  */
42
42
  list(): ResolvedRepository[];
@@ -109,7 +109,7 @@ declare module './lemma.bindings.js' {
109
109
  export interface RunOptions {
110
110
  /** Spec name (required). */
111
111
  spec: string;
112
- /** Repository qualifier (e.g. `@org/repo`), or omit for workspace. */
112
+ /** Repository qualifier (e.g. `@org/repo`), or omit for the default repository. */
113
113
  repository?: string | null;
114
114
  /** ISO datetime for temporal resolution, or omit for now. */
115
115
  effective?: string | null;
@@ -455,6 +455,112 @@ export type LiteralValue =
455
455
  | { boolean: "true" | "false" | "yes" | "no" }
456
456
  | { range: [LiteralValue, LiteralValue] };
457
457
 
458
+ /** Conversion target on a Show `as` expression. */
459
+ export type ShowConversionTarget =
460
+ | {
461
+ type:
462
+ | "boolean"
463
+ | "measure"
464
+ | "measure_range"
465
+ | "number"
466
+ | "number_range"
467
+ | "ratio"
468
+ | "ratio_range"
469
+ | "text"
470
+ | "date"
471
+ | "date_range"
472
+ | "time"
473
+ | "time_range";
474
+ }
475
+ | { unit: { unit_name: string } };
476
+
477
+ /** Resolved expression on a Show rule branch (tagged by `type`). */
478
+ export type ShowExpression =
479
+ | ({ type: "literal" } & RuleResultValue)
480
+ | { type: "data"; name: string }
481
+ | { type: "rule"; name: string }
482
+ | { type: "and"; left: ShowExpression; right: ShowExpression }
483
+ | { type: "not"; operand: ShowExpression }
484
+ | {
485
+ type: "arithmetic";
486
+ op: "add" | "subtract" | "multiply" | "divide" | "modulo" | "power";
487
+ left: ShowExpression;
488
+ right: ShowExpression;
489
+ }
490
+ | {
491
+ type: "comparison";
492
+ op:
493
+ | "greater_than"
494
+ | "less_than"
495
+ | "greater_than_or_equal"
496
+ | "less_than_or_equal"
497
+ | "is"
498
+ | "is_not";
499
+ left: ShowExpression;
500
+ right: ShowExpression;
501
+ }
502
+ | {
503
+ type: "unit_conversion";
504
+ operand: ShowExpression;
505
+ target: ShowConversionTarget;
506
+ }
507
+ | {
508
+ type: "math";
509
+ op:
510
+ | "sqrt"
511
+ | "sin"
512
+ | "cos"
513
+ | "tan"
514
+ | "asin"
515
+ | "acos"
516
+ | "atan"
517
+ | "log"
518
+ | "exp"
519
+ | "abs"
520
+ | "floor"
521
+ | "ceil"
522
+ | "round";
523
+ operand: ShowExpression;
524
+ }
525
+ | { type: "veto"; message?: string }
526
+ | { type: "now" }
527
+ | {
528
+ type: "date_relative";
529
+ kind: "in_past" | "in_future";
530
+ operand: ShowExpression;
531
+ }
532
+ | {
533
+ type: "date_calendar";
534
+ kind: "current" | "past" | "future" | "not_in";
535
+ unit: "year" | "month" | "week";
536
+ operand: ShowExpression;
537
+ }
538
+ | { type: "range_literal"; from: ShowExpression; to: ShowExpression }
539
+ | {
540
+ type: "past_future_range";
541
+ kind: "in_past" | "in_future";
542
+ operand: ShowExpression;
543
+ }
544
+ | {
545
+ type: "range_containment";
546
+ value: ShowExpression;
547
+ range: ShowExpression;
548
+ }
549
+ | { type: "is_veto"; operand: ShowExpression };
550
+
551
+ /** One arm of a rule's flat last-match table. Default arm omits condition. */
552
+ export interface ShowBranch {
553
+ condition?: ShowExpression;
554
+ result: ShowExpression;
555
+ }
556
+
557
+ /** Local rule on Show: result type, branches, stored depends_on_rules. */
558
+ export interface ShowRule {
559
+ type: LemmaType;
560
+ branches: ShowBranch[];
561
+ depends_on_rules: string[];
562
+ }
563
+
458
564
  /** Return shape of {@link Engine.show}. */
459
565
  export interface Show {
460
566
  spec: string;
@@ -465,8 +571,8 @@ export interface Show {
465
571
  source_type?: SourceType;
466
572
  versions?: ShowVersion[];
467
573
  data: Record<string, ShowData>;
468
- /** Rule result types; measure and ratio entries expose `units[]` like their data counterparts. */
469
- rules: Record<string, LemmaType>;
574
+ /** Local rule graph; measure/ratio units live under `type.units`. */
575
+ rules: Record<string, ShowRule>;
470
576
  meta: Record<string, LiteralValue>;
471
577
  }
472
578
 
@@ -479,7 +585,7 @@ export interface ListedSpec {
479
585
 
480
586
  /** Rust `ResolvedRepository` (engine `list`). */
481
587
  export interface ResolvedRepository {
482
- /** Absent for the local workspace group (only real repositories carry a name). */
588
+ /** Absent for the default unnamed repository (only named repositories carry a name). */
483
589
  repository?: string;
484
590
  specs: ListedSpec[];
485
591
  }