@rustledger/wasm 0.1.0 → 0.4.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.
@@ -73,18 +73,18 @@ export interface CloseDirective extends BaseDirective {
73
73
 
74
74
  /** All directive types. */
75
75
  export type Directive =
76
- | TransactionDirective
77
- | BalanceDirective
78
- | OpenDirective
79
- | CloseDirective
80
- | { type: 'commodity'; date: string; currency: string }
81
- | { type: 'pad'; date: string; account: string; source_account: string }
82
- | { type: 'event'; date: string; event_type: string; value: string }
83
- | { type: 'note'; date: string; account: string; comment: string }
84
- | { type: 'document'; date: string; account: string; path: string }
85
- | { type: 'price'; date: string; currency: string; amount: Amount }
86
- | { type: 'query'; date: string; name: string; query_string: string }
87
- | { type: 'custom'; date: string; custom_type: string };
76
+ | TransactionDirective
77
+ | BalanceDirective
78
+ | OpenDirective
79
+ | CloseDirective
80
+ | { type: 'commodity'; date: string; currency: string }
81
+ | { type: 'pad'; date: string; account: string; source_account: string }
82
+ | { type: 'event'; date: string; event_type: string; value: string }
83
+ | { type: 'note'; date: string; account: string; comment: string }
84
+ | { type: 'document'; date: string; account: string; path: string }
85
+ | { type: 'price'; date: string; currency: string; amount: Amount }
86
+ | { type: 'query'; date: string; name: string; query_string: string }
87
+ | { type: 'custom'; date: string; custom_type: string };
88
88
 
89
89
  /** Ledger options. */
90
90
  export interface LedgerOptions {
@@ -112,14 +112,14 @@ export interface ValidationResult {
112
112
 
113
113
  /** Cell value in query results. */
114
114
  export type CellValue =
115
- | null
116
- | string
117
- | number
118
- | boolean
119
- | Amount
120
- | { units: Amount; cost?: { number: string; currency: string; date?: string; label?: string } }
121
- | { positions: Array<{ units: Amount }> }
122
- | string[];
115
+ | null
116
+ | string
117
+ | number
118
+ | boolean
119
+ | Amount
120
+ | { units: Amount; cost?: { number: string; currency: string; date?: string; label?: string } }
121
+ | { positions: Array<{ units: Amount }> }
122
+ | string[];
123
123
 
124
124
  /** Result of a BQL query. */
125
125
  export interface QueryResult {
@@ -166,6 +166,60 @@ export interface CompletionResult {
166
166
  context: string;
167
167
  }
168
168
 
169
+ // =============================================================================
170
+ // Editor Integration Types (LSP-like features)
171
+ // =============================================================================
172
+
173
+ /** The kind of a completion item. */
174
+ export type EditorCompletionKind = 'keyword' | 'account' | 'accountsegment' | 'currency' | 'payee' | 'date' | 'text';
175
+
176
+ /** A completion item for Beancount source editing. */
177
+ export interface EditorCompletion {
178
+ label: string;
179
+ kind: EditorCompletionKind;
180
+ detail?: string;
181
+ insertText?: string;
182
+ }
183
+
184
+ /** Result of an editor completion request. */
185
+ export interface EditorCompletionResult {
186
+ completions: EditorCompletion[];
187
+ context: string;
188
+ }
189
+
190
+ /** A range in the document. */
191
+ export interface EditorRange {
192
+ start_line: number;
193
+ start_character: number;
194
+ end_line: number;
195
+ end_character: number;
196
+ }
197
+
198
+ /** Hover information for a symbol. */
199
+ export interface EditorHoverInfo {
200
+ contents: string;
201
+ range?: EditorRange;
202
+ }
203
+
204
+ /** A location in the document. */
205
+ export interface EditorLocation {
206
+ line: number;
207
+ character: number;
208
+ }
209
+
210
+ /** The kind of a symbol. */
211
+ export type SymbolKind = 'transaction' | 'account' | 'balance' | 'commodity' | 'posting' | 'pad' | 'event' | 'note' | 'document' | 'price' | 'query' | 'custom';
212
+
213
+ /** A document symbol for the outline view. */
214
+ export interface EditorDocumentSymbol {
215
+ name: string;
216
+ detail?: string;
217
+ kind: SymbolKind;
218
+ range: EditorRange;
219
+ children?: EditorDocumentSymbol[];
220
+ deprecated?: boolean;
221
+ }
222
+
169
223
  /**
170
224
  * A parsed and validated ledger that caches the parse result.
171
225
  * Use this class when you need to perform multiple operations on the same
@@ -210,67 +264,126 @@ export class ParsedLedger {
210
264
 
211
265
  /** Run a native plugin on this ledger. */
212
266
  runPlugin(pluginName: string): PluginResult;
267
+
268
+ // =========================================================================
269
+ // Editor Integration (LSP-like features)
270
+ // =========================================================================
271
+
272
+ /** Get completions at the given position. */
273
+ getCompletions(line: number, character: number): EditorCompletionResult;
274
+
275
+ /** Get hover information at the given position. */
276
+ getHoverInfo(line: number, character: number): EditorHoverInfo | null;
277
+
278
+ /** Get the definition location for the symbol at the given position. */
279
+ getDefinition(line: number, character: number): EditorLocation | null;
280
+
281
+ /** Get all document symbols for the outline view. */
282
+ getDocumentSymbols(): EditorDocumentSymbol[];
213
283
  }
214
284
 
215
285
 
216
286
 
287
+ /**
288
+ * A parsed and validated ledger that caches the parse result.
289
+ *
290
+ * Use this class when you need to perform multiple operations on the same
291
+ * source without re-parsing each time.
292
+ *
293
+ * # Example (JavaScript)
294
+ *
295
+ * ```javascript
296
+ * const ledger = new ParsedLedger(source);
297
+ * if (ledger.isValid()) {
298
+ * const balances = ledger.query("BALANCES");
299
+ * const formatted = ledger.format();
300
+ * }
301
+ * ```
302
+ */
217
303
  export class ParsedLedger {
218
- free(): void;
219
- [Symbol.dispose](): void;
220
- /**
221
- * Get all errors (parse + validation).
222
- */
223
- getErrors(): any;
224
- /**
225
- * Run a native plugin on this ledger.
226
- */
227
- runPlugin(plugin_name: string): any;
228
- /**
229
- * Expand pad directives.
230
- */
231
- expandPads(): any;
232
- /**
233
- * Get the ledger options.
234
- */
235
- getOptions(): any;
236
- /**
237
- * Get the parsed directives.
238
- */
239
- getDirectives(): any;
240
- /**
241
- * Get the number of directives.
242
- */
243
- directiveCount(): number;
244
- /**
245
- * Get parse errors only.
246
- */
247
- getParseErrors(): any;
248
- /**
249
- * Get validation errors only.
250
- */
251
- getValidationErrors(): any;
252
- /**
253
- * Create a new `ParsedLedger` from source text.
254
- *
255
- * Parses, interpolates, and validates the source. Call `isValid()` to check for errors.
256
- */
257
- constructor(source: string);
258
- /**
259
- * Run a BQL query on this ledger.
260
- */
261
- query(query_str: string): any;
262
- /**
263
- * Format the ledger source.
264
- */
265
- format(): any;
266
- /**
267
- * Get account balances (shorthand for query("BALANCES")).
268
- */
269
- balances(): any;
270
- /**
271
- * Check if the ledger is valid (no parse or validation errors).
272
- */
273
- isValid(): boolean;
304
+ free(): void;
305
+ [Symbol.dispose](): void;
306
+ /**
307
+ * Get account balances (shorthand for query("BALANCES")).
308
+ */
309
+ balances(): any;
310
+ /**
311
+ * Get the number of directives.
312
+ */
313
+ directiveCount(): number;
314
+ /**
315
+ * Expand pad directives.
316
+ */
317
+ expandPads(): any;
318
+ /**
319
+ * Format the ledger source.
320
+ */
321
+ format(): any;
322
+ /**
323
+ * Get completions at the given position.
324
+ *
325
+ * Returns context-aware completions for accounts, currencies, directives, etc.
326
+ * Uses cached account/currency/payee data for efficiency.
327
+ */
328
+ getCompletions(line: number, character: number): any;
329
+ /**
330
+ * Get the definition location for the symbol at the given position.
331
+ *
332
+ * Returns the location of the `open` or `commodity` directive for accounts/currencies.
333
+ * Uses cached `LineIndex` for O(log n) position lookups.
334
+ */
335
+ getDefinition(line: number, character: number): any;
336
+ /**
337
+ * Get the parsed directives.
338
+ */
339
+ getDirectives(): any;
340
+ /**
341
+ * Get all document symbols for the outline view.
342
+ *
343
+ * Returns a hierarchical list of all directives with their positions.
344
+ * Uses cached `LineIndex` for O(log n) position lookups.
345
+ */
346
+ getDocumentSymbols(): any;
347
+ /**
348
+ * Get all errors (parse + validation).
349
+ */
350
+ getErrors(): any;
351
+ /**
352
+ * Get hover information at the given position.
353
+ *
354
+ * Returns documentation for accounts, currencies, and directive keywords.
355
+ */
356
+ getHoverInfo(line: number, character: number): any;
357
+ /**
358
+ * Get the ledger options.
359
+ */
360
+ getOptions(): any;
361
+ /**
362
+ * Get parse errors only.
363
+ */
364
+ getParseErrors(): any;
365
+ /**
366
+ * Get validation errors only.
367
+ */
368
+ getValidationErrors(): any;
369
+ /**
370
+ * Check if the ledger is valid (no parse or validation errors).
371
+ */
372
+ isValid(): boolean;
373
+ /**
374
+ * Create a new `ParsedLedger` from source text.
375
+ *
376
+ * Parses, interpolates, and validates the source. Call `isValid()` to check for errors.
377
+ */
378
+ constructor(source: string);
379
+ /**
380
+ * Run a BQL query on this ledger.
381
+ */
382
+ query(query_str: string): any;
383
+ /**
384
+ * Run a native plugin on this ledger.
385
+ */
386
+ runPlugin(plugin_name: string): any;
274
387
  }
275
388
 
276
389
  /**
@@ -357,57 +470,61 @@ export function version(): string;
357
470
  export type InitInput = RequestInfo | URL | Response | BufferSource | WebAssembly.Module;
358
471
 
359
472
  export interface InitOutput {
360
- readonly memory: WebAssembly.Memory;
361
- readonly __wbg_parsedledger_free: (a: number, b: number) => void;
362
- readonly balances: (a: number, b: number, c: number) => void;
363
- readonly bqlCompletions: (a: number, b: number, c: number, d: number) => void;
364
- readonly expandPads: (a: number, b: number, c: number) => void;
365
- readonly format: (a: number, b: number, c: number) => void;
366
- readonly listPlugins: (a: number) => void;
367
- readonly parse: (a: number, b: number, c: number) => void;
368
- readonly parsedledger_balances: (a: number, b: number) => void;
369
- readonly parsedledger_directiveCount: (a: number) => number;
370
- readonly parsedledger_expandPads: (a: number, b: number) => void;
371
- readonly parsedledger_format: (a: number, b: number) => void;
372
- readonly parsedledger_getDirectives: (a: number, b: number) => void;
373
- readonly parsedledger_getErrors: (a: number, b: number) => void;
374
- readonly parsedledger_getOptions: (a: number, b: number) => void;
375
- readonly parsedledger_getParseErrors: (a: number, b: number) => void;
376
- readonly parsedledger_getValidationErrors: (a: number, b: number) => void;
377
- readonly parsedledger_isValid: (a: number) => number;
378
- readonly parsedledger_new: (a: number, b: number) => number;
379
- readonly parsedledger_query: (a: number, b: number, c: number, d: number) => void;
380
- readonly parsedledger_runPlugin: (a: number, b: number, c: number, d: number) => void;
381
- readonly query: (a: number, b: number, c: number, d: number, e: number) => void;
382
- readonly runPlugin: (a: number, b: number, c: number, d: number, e: number) => void;
383
- readonly validateSource: (a: number, b: number, c: number) => void;
384
- readonly version: (a: number) => void;
385
- readonly init: () => void;
386
- readonly __wbindgen_export: (a: number, b: number) => number;
387
- readonly __wbindgen_export2: (a: number, b: number, c: number, d: number) => number;
388
- readonly __wbindgen_export3: (a: number, b: number, c: number) => void;
389
- readonly __wbindgen_add_to_stack_pointer: (a: number) => number;
390
- readonly __wbindgen_start: () => void;
473
+ readonly memory: WebAssembly.Memory;
474
+ readonly __wbg_parsedledger_free: (a: number, b: number) => void;
475
+ readonly balances: (a: number, b: number, c: number) => void;
476
+ readonly bqlCompletions: (a: number, b: number, c: number, d: number) => void;
477
+ readonly expandPads: (a: number, b: number, c: number) => void;
478
+ readonly format: (a: number, b: number, c: number) => void;
479
+ readonly listPlugins: (a: number) => void;
480
+ readonly parse: (a: number, b: number, c: number) => void;
481
+ readonly parsedledger_balances: (a: number, b: number) => void;
482
+ readonly parsedledger_directiveCount: (a: number) => number;
483
+ readonly parsedledger_expandPads: (a: number, b: number) => void;
484
+ readonly parsedledger_format: (a: number, b: number) => void;
485
+ readonly parsedledger_getCompletions: (a: number, b: number, c: number, d: number) => void;
486
+ readonly parsedledger_getDefinition: (a: number, b: number, c: number, d: number) => void;
487
+ readonly parsedledger_getDirectives: (a: number, b: number) => void;
488
+ readonly parsedledger_getDocumentSymbols: (a: number, b: number) => void;
489
+ readonly parsedledger_getErrors: (a: number, b: number) => void;
490
+ readonly parsedledger_getHoverInfo: (a: number, b: number, c: number, d: number) => void;
491
+ readonly parsedledger_getOptions: (a: number, b: number) => void;
492
+ readonly parsedledger_getParseErrors: (a: number, b: number) => void;
493
+ readonly parsedledger_getValidationErrors: (a: number, b: number) => void;
494
+ readonly parsedledger_isValid: (a: number) => number;
495
+ readonly parsedledger_new: (a: number, b: number) => number;
496
+ readonly parsedledger_query: (a: number, b: number, c: number, d: number) => void;
497
+ readonly parsedledger_runPlugin: (a: number, b: number, c: number, d: number) => void;
498
+ readonly query: (a: number, b: number, c: number, d: number, e: number) => void;
499
+ readonly runPlugin: (a: number, b: number, c: number, d: number, e: number) => void;
500
+ readonly validateSource: (a: number, b: number, c: number) => void;
501
+ readonly version: (a: number) => void;
502
+ readonly init: () => void;
503
+ readonly __wbindgen_export: (a: number, b: number) => number;
504
+ readonly __wbindgen_export2: (a: number, b: number, c: number, d: number) => number;
505
+ readonly __wbindgen_export3: (a: number, b: number, c: number) => void;
506
+ readonly __wbindgen_add_to_stack_pointer: (a: number) => number;
507
+ readonly __wbindgen_start: () => void;
391
508
  }
392
509
 
393
510
  export type SyncInitInput = BufferSource | WebAssembly.Module;
394
511
 
395
512
  /**
396
- * Instantiates the given `module`, which can either be bytes or
397
- * a precompiled `WebAssembly.Module`.
398
- *
399
- * @param {{ module: SyncInitInput }} module - Passing `SyncInitInput` directly is deprecated.
400
- *
401
- * @returns {InitOutput}
402
- */
513
+ * Instantiates the given `module`, which can either be bytes or
514
+ * a precompiled `WebAssembly.Module`.
515
+ *
516
+ * @param {{ module: SyncInitInput }} module - Passing `SyncInitInput` directly is deprecated.
517
+ *
518
+ * @returns {InitOutput}
519
+ */
403
520
  export function initSync(module: { module: SyncInitInput } | SyncInitInput): InitOutput;
404
521
 
405
522
  /**
406
- * If `module_or_path` is {RequestInfo} or {URL}, makes a request and
407
- * for everything else, calls `WebAssembly.instantiate` directly.
408
- *
409
- * @param {{ module_or_path: InitInput | Promise<InitInput> }} module_or_path - Passing `InitInput` directly is deprecated.
410
- *
411
- * @returns {Promise<InitOutput>}
412
- */
523
+ * If `module_or_path` is {RequestInfo} or {URL}, makes a request and
524
+ * for everything else, calls `WebAssembly.instantiate` directly.
525
+ *
526
+ * @param {{ module_or_path: InitInput | Promise<InitInput> }} module_or_path - Passing `InitInput` directly is deprecated.
527
+ *
528
+ * @returns {Promise<InitOutput>}
529
+ */
413
530
  export default function __wbg_init (module_or_path?: { module_or_path: InitInput | Promise<InitInput> } | InitInput | Promise<InitInput>): Promise<InitOutput>;