beancount-wasm 0.1.0-alpha.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/README.md +106 -0
- package/dist/chunk-COWu0jBU.js +21 -0
- package/dist/inline/v2.d.ts +6 -0
- package/dist/inline/v2.js +15 -0
- package/dist/inline/v3.d.ts +6 -0
- package/dist/inline/v3.js +15 -0
- package/dist/runtime-CHUI0_WN.js +249 -0
- package/dist/runtime-CmgNndA1.d.ts +65 -0
- package/dist/runtime.d.ts +2 -0
- package/dist/runtime.js +3 -0
- package/dist/v2.d.ts +14 -0
- package/dist/v2.js +15 -0
- package/dist/v3.d.ts +14 -0
- package/dist/v3.js +15 -0
- package/package.json +48 -0
- package/wheels/v2/beancount-2.3.6-cp311-cp311-emscripten_3_1_46_wasm32.whl +0 -0
- package/wheels/v3/beancount-3.2.0-cp311-cp311-emscripten_3_1_46_wasm32.whl +0 -0
package/README.md
ADDED
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
# beancount-wasm
|
|
2
|
+
|
|
3
|
+
This package ships Pyodide-compatible Beancount wheels for v2 and v3 and a tiny
|
|
4
|
+
wrapper to install them into a Pyodide runtime.
|
|
5
|
+
|
|
6
|
+
## Usage
|
|
7
|
+
|
|
8
|
+
```js
|
|
9
|
+
import { createBeancountRuntime } from "beancount-wasm/runtime";
|
|
10
|
+
|
|
11
|
+
const { pyodide } = await createBeancountRuntime({
|
|
12
|
+
version: "v3",
|
|
13
|
+
// Optional: override the base URL for Pyodide assets.
|
|
14
|
+
// The base URL must contain pyodide.mjs and follow the same layout as
|
|
15
|
+
// https://cdn.jsdelivr.net/pyodide/v0.25.1/full/
|
|
16
|
+
// pyodideBaseUrl: "https://cdn.jsdelivr.net/pyodide/v0.25.1/full/",
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
const result = await pyodide.runPythonAsync(`
|
|
20
|
+
from beancount import loader
|
|
21
|
+
entries, errors, options = loader.load_string("2024-01-01 open Assets:Cash USD")
|
|
22
|
+
len(entries)
|
|
23
|
+
`);
|
|
24
|
+
console.log(result);
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
## API
|
|
28
|
+
|
|
29
|
+
### `createBeancountRuntime(options)`
|
|
30
|
+
Loads Pyodide and installs Beancount in one step.
|
|
31
|
+
|
|
32
|
+
Options:
|
|
33
|
+
- `version`: `"v2"` or `"v3"` (aliases: `"2"`, `"3"`, default: `"v3"`)
|
|
34
|
+
- `pyodideBaseUrl`: base URL for Pyodide assets (defaults to jsDelivr)
|
|
35
|
+
- `wheelBaseUrl`: base URL for wheels (defaults to jsDelivr npm CDN)
|
|
36
|
+
- `deps`: override Beancount dependency installation
|
|
37
|
+
- `inline`: `"auto" | "prefer" | "only" | "off"` (default: `"auto"`)
|
|
38
|
+
- `auto`: try URL first, fallback to inline on failure
|
|
39
|
+
- `prefer`: try inline first, fallback to URL
|
|
40
|
+
- `only`: inline only
|
|
41
|
+
- `off`: URL only
|
|
42
|
+
- `onStatus`: optional status callback
|
|
43
|
+
|
|
44
|
+
Example forcing inline-only mode:
|
|
45
|
+
|
|
46
|
+
```js
|
|
47
|
+
import { createBeancountRuntime } from "beancount-wasm/runtime";
|
|
48
|
+
|
|
49
|
+
const { pyodide } = await createBeancountRuntime({
|
|
50
|
+
version: "v2",
|
|
51
|
+
inline: "only",
|
|
52
|
+
});
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
### `installBeancount(pyodide, options)`
|
|
56
|
+
Installs Beancount into an existing Pyodide runtime.
|
|
57
|
+
Uses the same options as `createBeancountRuntime` (minus `pyodideBaseUrl`).
|
|
58
|
+
|
|
59
|
+
### `createFileTree(pyodide, { root, cache })`
|
|
60
|
+
Creates a file tree helper for the Pyodide FS. Each file entry is
|
|
61
|
+
`{ name, content }` where `name` is relative to `root`.
|
|
62
|
+
|
|
63
|
+
The returned helper exposes:
|
|
64
|
+
- `update(files)`: incremental writes for new/changed files
|
|
65
|
+
- `remove(names)`: delete files by name
|
|
66
|
+
- `reset(files)`: replace the tree to match the provided list
|
|
67
|
+
|
|
68
|
+
Example:
|
|
69
|
+
|
|
70
|
+
```js
|
|
71
|
+
import { createFileTree } from "beancount-wasm/runtime";
|
|
72
|
+
|
|
73
|
+
const fileTree = createFileTree(pyodide, { root: "/work" });
|
|
74
|
+
fileTree.update([{ name: "main.bean", content: "2024-01-01 open Assets:Cash" }]);
|
|
75
|
+
fileTree.remove(["old.bean"]);
|
|
76
|
+
fileTree.reset([{ name: "main.bean", content: "..." }]);
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
### `resolveWheelUrl({ version, wheelBaseUrl })`
|
|
80
|
+
Returns the URL used for the selected wheel.
|
|
81
|
+
|
|
82
|
+
### `getWheelInfo(version)`
|
|
83
|
+
Returns `{ version, filename, deps }` for the selected Beancount version.
|
|
84
|
+
|
|
85
|
+
## Wheel assets
|
|
86
|
+
|
|
87
|
+
The wheels live under `wheels/v2/` and `wheels/v3/` within the package. When
|
|
88
|
+
serving in the browser, these files must be available over HTTP unless you rely
|
|
89
|
+
on the built-in inline fallback (`inline: "auto"`).
|
|
90
|
+
|
|
91
|
+
## Exports
|
|
92
|
+
|
|
93
|
+
This package exposes subpath exports only:
|
|
94
|
+
- `beancount-wasm/runtime`
|
|
95
|
+
- `beancount-wasm/v2`
|
|
96
|
+
- `beancount-wasm/v3`
|
|
97
|
+
- `beancount-wasm/inline/v2`
|
|
98
|
+
- `beancount-wasm/inline/v3`
|
|
99
|
+
|
|
100
|
+
Version-specific entry example:
|
|
101
|
+
|
|
102
|
+
```js
|
|
103
|
+
import { createBeancountRuntime } from "beancount-wasm/v3";
|
|
104
|
+
|
|
105
|
+
const { pyodide } = await createBeancountRuntime();
|
|
106
|
+
```
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
//#region rolldown:runtime
|
|
2
|
+
var __toBinary = /* @__PURE__ */ (() => {
|
|
3
|
+
var table = new Uint8Array(128);
|
|
4
|
+
for (var i = 0; i < 64; i++) {
|
|
5
|
+
table[i < 26 ? i + 65 : i < 52 ? i + 71 : i < 62 ? i - 4 : i * 4 - 205] = i;
|
|
6
|
+
}
|
|
7
|
+
return (base64) => {
|
|
8
|
+
var n = base64.length, bytes = new Uint8Array((n - (base64[n - 1] == "=") - (base64[n - 2] == "=")) * 3 / 4 | 0);
|
|
9
|
+
for (var i = 0, j = 0; i < n;) {
|
|
10
|
+
var c0 = table[base64.charCodeAt(i++)], c1 = table[base64.charCodeAt(i++)];
|
|
11
|
+
var c2 = table[base64.charCodeAt(i++)], c3 = table[base64.charCodeAt(i++)];
|
|
12
|
+
bytes[j++] = c0 << 2 | c1 >> 4;
|
|
13
|
+
bytes[j++] = c1 << 4 | c2 >> 2;
|
|
14
|
+
bytes[j++] = c2 << 6 | c3;
|
|
15
|
+
}
|
|
16
|
+
return bytes;
|
|
17
|
+
};
|
|
18
|
+
})();
|
|
19
|
+
|
|
20
|
+
//#endregion
|
|
21
|
+
export { __toBinary as t };
|