@benrogmans/lemma-engine 0.7.4 → 0.8.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/LICENSE ADDED
@@ -0,0 +1,191 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ Copyright 2025 Ben Rogmans
179
+
180
+ Licensed under the Apache License, Version 2.0 (the "License");
181
+ you may not use this file except in compliance with the License.
182
+ You may obtain a copy of the License at
183
+
184
+ http://www.apache.org/licenses/LICENSE-2.0
185
+
186
+ Unless required by applicable law or agreed to in writing, software
187
+ distributed under the License is distributed on an "AS IS" BASIS,
188
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
189
+ See the License for the specific language governing permissions and
190
+ limitations under the License.
191
+
package/README.md CHANGED
@@ -48,23 +48,23 @@ const engine = new WasmEngine();
48
48
 
49
49
  #### `addLemmaFile(code: string, filename: string): string`
50
50
 
51
- Adds a Lemma document to the engine.
51
+ Adds a Lemma spec to the engine.
52
52
 
53
53
  ```javascript
54
54
  const result = engine.addLemmaFile(`
55
- doc employee_contract
55
+ spec employee_contract
56
56
 
57
- fact salary = 5000 eur
58
- fact start_date = 2024-01-15
59
- fact vacation_days = 25
57
+ fact salary: 5000 eur
58
+ fact start_date: 2024-01-15
59
+ fact vacation_days: 25
60
60
 
61
- rule annual_salary = salary * 12
62
- rule daily_rate = salary / 21
61
+ rule annual_salary: salary * 12
62
+ rule daily_rate: salary / 21
63
63
  `, 'employee.lemma');
64
64
 
65
65
  const response = JSON.parse(result);
66
66
  if (response.success) {
67
- console.log('Document loaded:', response.data);
67
+ console.log('Spec loaded:', response.data);
68
68
  } else {
69
69
  console.error('Error:', response.error);
70
70
  }
@@ -72,7 +72,7 @@ if (response.success) {
72
72
 
73
73
  #### `evaluate(docName: string, facts: string): string`
74
74
 
75
- Evaluates a document with optional runtime facts.
75
+ Evaluates a spec with optional runtime facts.
76
76
 
77
77
  ```javascript
78
78
  // Evaluate with default facts
@@ -86,24 +86,24 @@ const result2 = engine.evaluate('employee_contract', JSON.stringify({
86
86
 
87
87
  const response = JSON.parse(result2);
88
88
  if (response.success) {
89
- console.log('Document:', response.data.document);
89
+ console.log('Spec:', response.data.spec);
90
90
  console.log('Rules:', response.data.rules);
91
91
  // Access specific rule results directly:
92
92
  // response.data.rules.annual_salary.value
93
93
  }
94
94
  ```
95
95
 
96
- #### `listDocuments(): string`
96
+ #### `listSpecs(): string`
97
97
 
98
- Lists all loaded documents in the engine.
98
+ Lists all loaded specs in the engine.
99
99
 
100
100
  ```javascript
101
- const result = engine.listDocuments();
101
+ const result = engine.listSpecs();
102
102
  const response = JSON.parse(result);
103
103
 
104
104
  if (response.success) {
105
- console.log('Loaded documents:', response.data);
106
- // response.data is an array of document names
105
+ console.log('Loaded specs:', response.data);
106
+ // response.data is an array of spec names
107
107
  }
108
108
  ```
109
109
 
@@ -132,35 +132,35 @@ async function calculatePricing() {
132
132
 
133
133
  // Define pricing rules
134
134
  const pricingDoc = `
135
- doc product_pricing
135
+ spec product_pricing
136
136
 
137
- fact base_price = 100 usd
138
- fact quantity = 1
139
- fact is_member = false
140
- fact promo_code = ""
137
+ fact base_price: 100 usd
138
+ fact quantity: 1
139
+ fact is_member: false
140
+ fact promo_code: ""
141
141
 
142
- rule bulk_discount = 0%
142
+ rule bulk_discount: 0%
143
143
  unless quantity >= 10 then 5%
144
144
  unless quantity >= 50 then 10%
145
145
  unless quantity >= 100 then 15%
146
146
 
147
- rule member_discount = 0%
147
+ rule member_discount: 0%
148
148
  unless is_member then 10%
149
149
 
150
- rule promo_discount = 0%
150
+ rule promo_discount: 0%
151
151
  unless promo_code == "SAVE10" then 10%
152
152
  unless promo_code == "SAVE20" then 20%
153
153
 
154
- rule best_discount = bulk_discount?
155
- unless member_discount? >= bulk_discount? then member_discount?
156
- unless promo_discount? >= bulk_discount? then promo_discount?
157
- unless member_discount? >= promo_discount? then member_discount?
158
- unless promo_discount? >= member_discount? then promo_discount?
154
+ rule best_discount: bulk_discount
155
+ unless member_discount >= bulk_discount then member_discount
156
+ unless promo_discount >= bulk_discount then promo_discount
157
+ unless member_discount >= promo_discount then member_discount
158
+ unless promo_discount >= member_discount then promo_discount
159
159
 
160
- rule final_price = base_price * quantity * (1 - best_discount?)
160
+ rule final_price: base_price * quantity * (1 - best_discount)
161
161
  `;
162
162
 
163
- // Load the document
163
+ // Load the spec
164
164
  const loadResult = JSON.parse(
165
165
  engine.addLemmaFile(pricingDoc, 'pricing.lemma')
166
166
  );
@@ -219,7 +219,7 @@ interface PricingResults {
219
219
  interface EvaluationResponse {
220
220
  success: boolean;
221
221
  data?: {
222
- document: string;
222
+ spec: string;
223
223
  rules: {
224
224
  [ruleName: string]: {
225
225
  value: any; // The computed value (e.g., {Number: "100"})
@@ -233,14 +233,14 @@ interface EvaluationResponse {
233
233
  };
234
234
  };
235
235
  error?: string;
236
- warnings?: string[]; // Document-level warnings
236
+ warnings?: string[]; // Spec-level warnings
237
237
  }
238
238
 
239
239
  async function typedExample() {
240
240
  await init();
241
241
  const engine = new WasmEngine();
242
242
 
243
- // ... load document
243
+ // ... load spec
244
244
 
245
245
  const facts = {
246
246
  quantity: 10,
@@ -279,8 +279,8 @@ try {
279
279
  ### Performance Tips
280
280
 
281
281
  1. **Initialize once**: The WASM module should be initialized once per application
282
- 2. **Reuse engines**: Create one `WasmEngine` and load multiple documents
283
- 3. **Batch operations**: Load all documents before evaluating
282
+ 2. **Reuse engines**: Create one `WasmEngine` and load multiple specs
283
+ 3. **Batch operations**: Load all specs before evaluating
284
284
  4. **Cache results**: Evaluation results can be cached if facts don't change
285
285
 
286
286
  ### Compatibility
package/lemma.d.ts CHANGED
@@ -70,39 +70,26 @@ export class ServerConfig {
70
70
  export class WasmEngine {
71
71
  free(): void;
72
72
  [Symbol.dispose](): void;
73
- /**
74
- * Add Lemma source (e.g. file contents). Returns a Promise that resolves to a JSON string result.
75
- */
76
73
  addLemmaFile(code: string, source: string): Promise<any>;
77
74
  /**
78
- * Evaluate rules in a document.
79
- *
80
- * Pass `rule_names_json` as `"[]"` or `""` to evaluate all rules.
81
- * Pass a JSON array like `'["total","discount"]'` to evaluate specific rules.
75
+ * Evaluate at current time.
82
76
  */
83
- evaluate(doc_name: string, rule_names_json: string, fact_values_json: string): string;
77
+ evaluate(spec_name: string, hash: string, rule_names_json: string, fact_values_json: string): string;
84
78
  /**
85
- * Format Lemma source code. Returns a JSON string: `{ "success": true, "formatted": "..." }`
86
- * or `{ "success": false, "error": "..." }`. Only formats if the source parses successfully.
87
- * Call from JS (e.g. Monaco playground) to implement "Format" without an LSP; there is no on-save in the browser.
79
+ * Evaluate at a specific datetime.
88
80
  */
81
+ evaluateEffective(spec_name: string, effective: string, hash: string, rule_names_json: string, fact_values_json: string): string;
89
82
  formatSource(code: string, source_attribute: string): string;
90
83
  /**
91
- * Return the full document schema: all facts and rules with their types.
92
- *
93
- * Returns the `DocumentSchema` used by all Lemma interfaces, serialized as
94
- * JSON. Use `getSchema` with specific rule names to get only the facts
95
- * required by those rules.
84
+ * Schema at current time.
96
85
  */
97
- getSchema(doc_name: string, rule_names_json: string): string;
98
- invert(_doc_name: string, _rule_name: string, _target_json: string, _provided_values_json: string): string;
86
+ getSchema(spec_name: string, rule_names_json: string): string;
99
87
  /**
100
- * List all loaded documents with their full schemas.
101
- *
102
- * Returns `{ success: true, documents: [DocumentSchema, ...] }` sorted by
103
- * document name, consistent with the HTTP and MCP interfaces.
88
+ * Schema at a specific datetime.
104
89
  */
105
- listDocuments(): string;
90
+ getSchemaEffective(spec_name: string, effective: string, rule_names_json: string): string;
91
+ invert(_spec_name: string, _rule_name: string, _target_json: string, _provided_values_json: string): string;
92
+ listSpecs(): string;
106
93
  constructor();
107
94
  }
108
95
 
@@ -143,15 +130,17 @@ export interface InitOutput {
143
130
  readonly readablestreamgetreaderoptions_mode: (a: number) => number;
144
131
  readonly __wbg_wasmengine_free: (a: number, b: number) => void;
145
132
  readonly wasmengine_addLemmaFile: (a: number, b: number, c: number, d: number, e: number) => number;
146
- readonly wasmengine_evaluate: (a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number) => void;
133
+ readonly wasmengine_evaluate: (a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number, i: number, j: number) => void;
134
+ readonly wasmengine_evaluateEffective: (a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number, i: number, j: number, k: number, l: number) => void;
147
135
  readonly wasmengine_formatSource: (a: number, b: number, c: number, d: number, e: number, f: number) => void;
148
136
  readonly wasmengine_getSchema: (a: number, b: number, c: number, d: number, e: number, f: number) => void;
137
+ readonly wasmengine_getSchemaEffective: (a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number) => void;
149
138
  readonly wasmengine_invert: (a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number, i: number, j: number) => void;
150
- readonly wasmengine_listDocuments: (a: number, b: number) => void;
139
+ readonly wasmengine_listSpecs: (a: number, b: number) => void;
151
140
  readonly wasmengine_new: () => number;
152
- readonly __wasm_bindgen_func_elem_8774: (a: number, b: number) => void;
153
- readonly __wasm_bindgen_func_elem_9930: (a: number, b: number, c: number, d: number) => void;
154
- readonly __wasm_bindgen_func_elem_8789: (a: number, b: number, c: number) => void;
141
+ readonly __wasm_bindgen_func_elem_9471: (a: number, b: number) => void;
142
+ readonly __wasm_bindgen_func_elem_10661: (a: number, b: number, c: number, d: number) => void;
143
+ readonly __wasm_bindgen_func_elem_9486: (a: number, b: number, c: number) => void;
155
144
  readonly __wbindgen_export: (a: number, b: number) => number;
156
145
  readonly __wbindgen_export2: (a: number, b: number, c: number, d: number) => number;
157
146
  readonly __wbindgen_export3: (a: number) => void;
package/lemma.js CHANGED
@@ -238,7 +238,6 @@ export class WasmEngine {
238
238
  wasm.__wbg_wasmengine_free(ptr, 0);
239
239
  }
240
240
  /**
241
- * Add Lemma source (e.g. file contents). Returns a Promise that resolves to a JSON string result.
242
241
  * @param {string} code
243
242
  * @param {string} source
244
243
  * @returns {Promise<any>}
@@ -252,41 +251,73 @@ export class WasmEngine {
252
251
  return takeObject(ret);
253
252
  }
254
253
  /**
255
- * Evaluate rules in a document.
256
- *
257
- * Pass `rule_names_json` as `"[]"` or `""` to evaluate all rules.
258
- * Pass a JSON array like `'["total","discount"]'` to evaluate specific rules.
259
- * @param {string} doc_name
254
+ * Evaluate at current time.
255
+ * @param {string} spec_name
256
+ * @param {string} hash
260
257
  * @param {string} rule_names_json
261
258
  * @param {string} fact_values_json
262
259
  * @returns {string}
263
260
  */
264
- evaluate(doc_name, rule_names_json, fact_values_json) {
265
- let deferred4_0;
266
- let deferred4_1;
261
+ evaluate(spec_name, hash, rule_names_json, fact_values_json) {
262
+ let deferred5_0;
263
+ let deferred5_1;
267
264
  try {
268
265
  const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
269
- const ptr0 = passStringToWasm0(doc_name, wasm.__wbindgen_export, wasm.__wbindgen_export2);
266
+ const ptr0 = passStringToWasm0(spec_name, wasm.__wbindgen_export, wasm.__wbindgen_export2);
270
267
  const len0 = WASM_VECTOR_LEN;
271
- const ptr1 = passStringToWasm0(rule_names_json, wasm.__wbindgen_export, wasm.__wbindgen_export2);
268
+ const ptr1 = passStringToWasm0(hash, wasm.__wbindgen_export, wasm.__wbindgen_export2);
272
269
  const len1 = WASM_VECTOR_LEN;
273
- const ptr2 = passStringToWasm0(fact_values_json, wasm.__wbindgen_export, wasm.__wbindgen_export2);
270
+ const ptr2 = passStringToWasm0(rule_names_json, wasm.__wbindgen_export, wasm.__wbindgen_export2);
274
271
  const len2 = WASM_VECTOR_LEN;
275
- wasm.wasmengine_evaluate(retptr, this.__wbg_ptr, ptr0, len0, ptr1, len1, ptr2, len2);
272
+ const ptr3 = passStringToWasm0(fact_values_json, wasm.__wbindgen_export, wasm.__wbindgen_export2);
273
+ const len3 = WASM_VECTOR_LEN;
274
+ wasm.wasmengine_evaluate(retptr, this.__wbg_ptr, ptr0, len0, ptr1, len1, ptr2, len2, ptr3, len3);
276
275
  var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
277
276
  var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
278
- deferred4_0 = r0;
279
- deferred4_1 = r1;
277
+ deferred5_0 = r0;
278
+ deferred5_1 = r1;
280
279
  return getStringFromWasm0(r0, r1);
281
280
  } finally {
282
281
  wasm.__wbindgen_add_to_stack_pointer(16);
283
- wasm.__wbindgen_export4(deferred4_0, deferred4_1, 1);
282
+ wasm.__wbindgen_export4(deferred5_0, deferred5_1, 1);
283
+ }
284
+ }
285
+ /**
286
+ * Evaluate at a specific datetime.
287
+ * @param {string} spec_name
288
+ * @param {string} effective
289
+ * @param {string} hash
290
+ * @param {string} rule_names_json
291
+ * @param {string} fact_values_json
292
+ * @returns {string}
293
+ */
294
+ evaluateEffective(spec_name, effective, hash, rule_names_json, fact_values_json) {
295
+ let deferred6_0;
296
+ let deferred6_1;
297
+ try {
298
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
299
+ const ptr0 = passStringToWasm0(spec_name, wasm.__wbindgen_export, wasm.__wbindgen_export2);
300
+ const len0 = WASM_VECTOR_LEN;
301
+ const ptr1 = passStringToWasm0(effective, wasm.__wbindgen_export, wasm.__wbindgen_export2);
302
+ const len1 = WASM_VECTOR_LEN;
303
+ const ptr2 = passStringToWasm0(hash, wasm.__wbindgen_export, wasm.__wbindgen_export2);
304
+ const len2 = WASM_VECTOR_LEN;
305
+ const ptr3 = passStringToWasm0(rule_names_json, wasm.__wbindgen_export, wasm.__wbindgen_export2);
306
+ const len3 = WASM_VECTOR_LEN;
307
+ const ptr4 = passStringToWasm0(fact_values_json, wasm.__wbindgen_export, wasm.__wbindgen_export2);
308
+ const len4 = WASM_VECTOR_LEN;
309
+ wasm.wasmengine_evaluateEffective(retptr, this.__wbg_ptr, ptr0, len0, ptr1, len1, ptr2, len2, ptr3, len3, ptr4, len4);
310
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
311
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
312
+ deferred6_0 = r0;
313
+ deferred6_1 = r1;
314
+ return getStringFromWasm0(r0, r1);
315
+ } finally {
316
+ wasm.__wbindgen_add_to_stack_pointer(16);
317
+ wasm.__wbindgen_export4(deferred6_0, deferred6_1, 1);
284
318
  }
285
319
  }
286
320
  /**
287
- * Format Lemma source code. Returns a JSON string: `{ "success": true, "formatted": "..." }`
288
- * or `{ "success": false, "error": "..." }`. Only formats if the source parses successfully.
289
- * Call from JS (e.g. Monaco playground) to implement "Format" without an LSP; there is no on-save in the browser.
290
321
  * @param {string} code
291
322
  * @param {string} source_attribute
292
323
  * @returns {string}
@@ -312,21 +343,17 @@ export class WasmEngine {
312
343
  }
313
344
  }
314
345
  /**
315
- * Return the full document schema: all facts and rules with their types.
316
- *
317
- * Returns the `DocumentSchema` used by all Lemma interfaces, serialized as
318
- * JSON. Use `getSchema` with specific rule names to get only the facts
319
- * required by those rules.
320
- * @param {string} doc_name
346
+ * Schema at current time.
347
+ * @param {string} spec_name
321
348
  * @param {string} rule_names_json
322
349
  * @returns {string}
323
350
  */
324
- getSchema(doc_name, rule_names_json) {
351
+ getSchema(spec_name, rule_names_json) {
325
352
  let deferred3_0;
326
353
  let deferred3_1;
327
354
  try {
328
355
  const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
329
- const ptr0 = passStringToWasm0(doc_name, wasm.__wbindgen_export, wasm.__wbindgen_export2);
356
+ const ptr0 = passStringToWasm0(spec_name, wasm.__wbindgen_export, wasm.__wbindgen_export2);
330
357
  const len0 = WASM_VECTOR_LEN;
331
358
  const ptr1 = passStringToWasm0(rule_names_json, wasm.__wbindgen_export, wasm.__wbindgen_export2);
332
359
  const len1 = WASM_VECTOR_LEN;
@@ -342,18 +369,47 @@ export class WasmEngine {
342
369
  }
343
370
  }
344
371
  /**
345
- * @param {string} _doc_name
372
+ * Schema at a specific datetime.
373
+ * @param {string} spec_name
374
+ * @param {string} effective
375
+ * @param {string} rule_names_json
376
+ * @returns {string}
377
+ */
378
+ getSchemaEffective(spec_name, effective, rule_names_json) {
379
+ let deferred4_0;
380
+ let deferred4_1;
381
+ try {
382
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
383
+ const ptr0 = passStringToWasm0(spec_name, wasm.__wbindgen_export, wasm.__wbindgen_export2);
384
+ const len0 = WASM_VECTOR_LEN;
385
+ const ptr1 = passStringToWasm0(effective, wasm.__wbindgen_export, wasm.__wbindgen_export2);
386
+ const len1 = WASM_VECTOR_LEN;
387
+ const ptr2 = passStringToWasm0(rule_names_json, wasm.__wbindgen_export, wasm.__wbindgen_export2);
388
+ const len2 = WASM_VECTOR_LEN;
389
+ wasm.wasmengine_getSchemaEffective(retptr, this.__wbg_ptr, ptr0, len0, ptr1, len1, ptr2, len2);
390
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
391
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
392
+ deferred4_0 = r0;
393
+ deferred4_1 = r1;
394
+ return getStringFromWasm0(r0, r1);
395
+ } finally {
396
+ wasm.__wbindgen_add_to_stack_pointer(16);
397
+ wasm.__wbindgen_export4(deferred4_0, deferred4_1, 1);
398
+ }
399
+ }
400
+ /**
401
+ * @param {string} _spec_name
346
402
  * @param {string} _rule_name
347
403
  * @param {string} _target_json
348
404
  * @param {string} _provided_values_json
349
405
  * @returns {string}
350
406
  */
351
- invert(_doc_name, _rule_name, _target_json, _provided_values_json) {
407
+ invert(_spec_name, _rule_name, _target_json, _provided_values_json) {
352
408
  let deferred5_0;
353
409
  let deferred5_1;
354
410
  try {
355
411
  const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
356
- const ptr0 = passStringToWasm0(_doc_name, wasm.__wbindgen_export, wasm.__wbindgen_export2);
412
+ const ptr0 = passStringToWasm0(_spec_name, wasm.__wbindgen_export, wasm.__wbindgen_export2);
357
413
  const len0 = WASM_VECTOR_LEN;
358
414
  const ptr1 = passStringToWasm0(_rule_name, wasm.__wbindgen_export, wasm.__wbindgen_export2);
359
415
  const len1 = WASM_VECTOR_LEN;
@@ -373,18 +429,14 @@ export class WasmEngine {
373
429
  }
374
430
  }
375
431
  /**
376
- * List all loaded documents with their full schemas.
377
- *
378
- * Returns `{ success: true, documents: [DocumentSchema, ...] }` sorted by
379
- * document name, consistent with the HTTP and MCP interfaces.
380
432
  * @returns {string}
381
433
  */
382
- listDocuments() {
434
+ listSpecs() {
383
435
  let deferred1_0;
384
436
  let deferred1_1;
385
437
  try {
386
438
  const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
387
- wasm.wasmengine_listDocuments(retptr, this.__wbg_ptr);
439
+ wasm.wasmengine_listSpecs(retptr, this.__wbg_ptr);
388
440
  var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
389
441
  var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
390
442
  deferred1_0 = r0;
@@ -514,6 +566,14 @@ function __wbg_get_imports() {
514
566
  const ret = fetch(getObject(arg0));
515
567
  return addHeapObject(ret);
516
568
  },
569
+ __wbg_getTime_1e3cd1391c5c3995: function(arg0) {
570
+ const ret = getObject(arg0).getTime();
571
+ return ret;
572
+ },
573
+ __wbg_getTimezoneOffset_81776d10a4ec18a8: function(arg0) {
574
+ const ret = getObject(arg0).getTimezoneOffset();
575
+ return ret;
576
+ },
517
577
  __wbg_getWriter_1d11da1210cc84ba: function() { return handleError(function (arg0) {
518
578
  const ret = getObject(arg0).getWriter();
519
579
  return addHeapObject(ret);
@@ -564,6 +624,14 @@ function __wbg_get_imports() {
564
624
  const ret = new URLSearchParams();
565
625
  return addHeapObject(ret);
566
626
  }, arguments); },
627
+ __wbg_new_0_73afc35eb544e539: function() {
628
+ const ret = new Date();
629
+ return addHeapObject(ret);
630
+ },
631
+ __wbg_new_245cd5c49157e602: function(arg0) {
632
+ const ret = new Date(getObject(arg0));
633
+ return addHeapObject(ret);
634
+ },
567
635
  __wbg_new_361308b2356cecd0: function() {
568
636
  const ret = new Object();
569
637
  return addHeapObject(ret);
@@ -587,7 +655,7 @@ function __wbg_get_imports() {
587
655
  const a = state0.a;
588
656
  state0.a = 0;
589
657
  try {
590
- return __wasm_bindgen_func_elem_9930(a, state0.b, arg0, arg1);
658
+ return __wasm_bindgen_func_elem_10661(a, state0.b, arg0, arg1);
591
659
  } finally {
592
660
  state0.a = a;
593
661
  }
@@ -740,11 +808,16 @@ function __wbg_get_imports() {
740
808
  return addHeapObject(ret);
741
809
  },
742
810
  __wbindgen_cast_0000000000000001: function(arg0, arg1) {
743
- // Cast intrinsic for `Closure(Closure { dtor_idx: 1159, function: Function { arguments: [Externref], shim_idx: 1160, ret: Unit, inner_ret: Some(Unit) }, mutable: true }) -> Externref`.
744
- const ret = makeMutClosure(arg0, arg1, wasm.__wasm_bindgen_func_elem_8774, __wasm_bindgen_func_elem_8789);
811
+ // Cast intrinsic for `Closure(Closure { dtor_idx: 1154, function: Function { arguments: [Externref], shim_idx: 1155, ret: Unit, inner_ret: Some(Unit) }, mutable: true }) -> Externref`.
812
+ const ret = makeMutClosure(arg0, arg1, wasm.__wasm_bindgen_func_elem_9471, __wasm_bindgen_func_elem_9486);
813
+ return addHeapObject(ret);
814
+ },
815
+ __wbindgen_cast_0000000000000002: function(arg0) {
816
+ // Cast intrinsic for `F64 -> Externref`.
817
+ const ret = arg0;
745
818
  return addHeapObject(ret);
746
819
  },
747
- __wbindgen_cast_0000000000000002: function(arg0, arg1) {
820
+ __wbindgen_cast_0000000000000003: function(arg0, arg1) {
748
821
  // Cast intrinsic for `Ref(String) -> Externref`.
749
822
  const ret = getStringFromWasm0(arg0, arg1);
750
823
  return addHeapObject(ret);
@@ -763,12 +836,12 @@ function __wbg_get_imports() {
763
836
  };
764
837
  }
765
838
 
766
- function __wasm_bindgen_func_elem_8789(arg0, arg1, arg2) {
767
- wasm.__wasm_bindgen_func_elem_8789(arg0, arg1, addHeapObject(arg2));
839
+ function __wasm_bindgen_func_elem_9486(arg0, arg1, arg2) {
840
+ wasm.__wasm_bindgen_func_elem_9486(arg0, arg1, addHeapObject(arg2));
768
841
  }
769
842
 
770
- function __wasm_bindgen_func_elem_9930(arg0, arg1, arg2, arg3) {
771
- wasm.__wasm_bindgen_func_elem_9930(arg0, arg1, addHeapObject(arg2), addHeapObject(arg3));
843
+ function __wasm_bindgen_func_elem_10661(arg0, arg1, arg2, arg3) {
844
+ wasm.__wasm_bindgen_func_elem_10661(arg0, arg1, addHeapObject(arg2), addHeapObject(arg3));
772
845
  }
773
846
 
774
847
 
package/lemma_bg.wasm CHANGED
Binary file
@@ -28,15 +28,17 @@ export const queuingstrategy_highWaterMark: (a: number) => number;
28
28
  export const readablestreamgetreaderoptions_mode: (a: number) => number;
29
29
  export const __wbg_wasmengine_free: (a: number, b: number) => void;
30
30
  export const wasmengine_addLemmaFile: (a: number, b: number, c: number, d: number, e: number) => number;
31
- export const wasmengine_evaluate: (a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number) => void;
31
+ export const wasmengine_evaluate: (a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number, i: number, j: number) => void;
32
+ export const wasmengine_evaluateEffective: (a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number, i: number, j: number, k: number, l: number) => void;
32
33
  export const wasmengine_formatSource: (a: number, b: number, c: number, d: number, e: number, f: number) => void;
33
34
  export const wasmengine_getSchema: (a: number, b: number, c: number, d: number, e: number, f: number) => void;
35
+ export const wasmengine_getSchemaEffective: (a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number) => void;
34
36
  export const wasmengine_invert: (a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number, i: number, j: number) => void;
35
- export const wasmengine_listDocuments: (a: number, b: number) => void;
37
+ export const wasmengine_listSpecs: (a: number, b: number) => void;
36
38
  export const wasmengine_new: () => number;
37
- export const __wasm_bindgen_func_elem_8774: (a: number, b: number) => void;
38
- export const __wasm_bindgen_func_elem_9930: (a: number, b: number, c: number, d: number) => void;
39
- export const __wasm_bindgen_func_elem_8789: (a: number, b: number, c: number) => void;
39
+ export const __wasm_bindgen_func_elem_9471: (a: number, b: number) => void;
40
+ export const __wasm_bindgen_func_elem_10661: (a: number, b: number, c: number, d: number) => void;
41
+ export const __wasm_bindgen_func_elem_9486: (a: number, b: number, c: number) => void;
40
42
  export const __wbindgen_export: (a: number, b: number) => number;
41
43
  export const __wbindgen_export2: (a: number, b: number, c: number, d: number) => number;
42
44
  export const __wbindgen_export3: (a: number) => void;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@benrogmans/lemma-engine",
3
- "version": "0.7.4",
3
+ "version": "0.8.0",
4
4
  "description": "Language Server Protocol implementation for Lemma",
5
5
  "type": "module",
6
6
  "main": "lemma.js",