@holon-sh/typr 0.0.0-stage → 0.0.1-dev.2
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 +22 -0
- package/README.md +62 -2
- package/package.json +26 -4
- package/typ.d.ts +8 -0
- package/typ.js +60 -0
- package/typ.wasm +0 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Holon Systems, Inc.
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
22
|
+
|
package/README.md
CHANGED
|
@@ -1,3 +1,63 @@
|
|
|
1
|
-
#
|
|
1
|
+
# typ
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
```bash
|
|
4
|
+
go get github.com/holon-sh/typr
|
|
5
|
+
```
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @holon-sh/typr
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
```js
|
|
12
|
+
import { readFileSync } from "node:fs";
|
|
13
|
+
import { run } from "@holon-sh/typr";
|
|
14
|
+
|
|
15
|
+
const outcome = run(readFileSync("examples/generate.json", "utf8"));
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
`run` takes a request and returns `{ kind: "answered", answer }` or `{ kind: "refused", reason }`.
|
|
19
|
+
|
|
20
|
+
```bash
|
|
21
|
+
uv add typr
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
```python
|
|
25
|
+
from pathlib import Path
|
|
26
|
+
from typr import run
|
|
27
|
+
|
|
28
|
+
outcome = run(Path("examples/generate.json").read_text())
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
`run` takes a request and returns `Answered(answer)` or `Refused(reason)`.
|
|
32
|
+
|
|
33
|
+
`typ.wasm` also runs under any WASI preview 1 runtime: one JSON request on stdin, one answer on stdout. [FORMAT.md](FORMAT.md) describes the requests and answers, and [examples/](examples) holds a request for each function.
|
|
34
|
+
|
|
35
|
+
```bash
|
|
36
|
+
wasmtime typ.wasm < examples/same_contract.json
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
Each `v0.0.1-dev.N` tag attaches `typ.wasm` and `typ.wasm.sha256` to its release and publishes `@holon-sh/typr` at version `0.0.1-dev.N` and `typr` at `0.0.1.devN`.
|
|
40
|
+
|
|
41
|
+
`typ.wasm` is built from `src/` with the pinned Rust toolchain:
|
|
42
|
+
|
|
43
|
+
```bash
|
|
44
|
+
scripts/build
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
Tests:
|
|
48
|
+
|
|
49
|
+
```bash
|
|
50
|
+
go test ./...
|
|
51
|
+
cargo test
|
|
52
|
+
npm ci && npm test
|
|
53
|
+
uv build --wheel && uv run --project tooling --with dist/*.whl pytest typ_test.py
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
The tests that run Node, Python and the type checkers against generated clients need `tooling/` installed and the `toolchains` tag:
|
|
57
|
+
|
|
58
|
+
```bash
|
|
59
|
+
npm ci --prefix tooling
|
|
60
|
+
uv sync --project tooling
|
|
61
|
+
(cd tooling && go mod download)
|
|
62
|
+
go test -tags toolchains ./...
|
|
63
|
+
```
|
package/package.json
CHANGED
|
@@ -1,6 +1,28 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@holon-sh/typr",
|
|
3
|
-
"
|
|
4
|
-
"
|
|
5
|
-
|
|
6
|
-
|
|
3
|
+
"description": "typ.wasm and a Node.js host that sends it one request",
|
|
4
|
+
"repository": {
|
|
5
|
+
"type": "git",
|
|
6
|
+
"url": "git+https://github.com/holon-sh/typr.git"
|
|
7
|
+
},
|
|
8
|
+
"license": "MIT",
|
|
9
|
+
"type": "module",
|
|
10
|
+
"exports": "./typ.js",
|
|
11
|
+
"files": [
|
|
12
|
+
"typ.js",
|
|
13
|
+
"typ.d.ts",
|
|
14
|
+
"typ.wasm"
|
|
15
|
+
],
|
|
16
|
+
"scripts": {
|
|
17
|
+
"prepack": "tsc",
|
|
18
|
+
"test": "tsc && node --test typ.test.ts"
|
|
19
|
+
},
|
|
20
|
+
"publishConfig": {
|
|
21
|
+
"access": "public"
|
|
22
|
+
},
|
|
23
|
+
"devDependencies": {
|
|
24
|
+
"@types/node": "22.20.5",
|
|
25
|
+
"typescript": "7.0.2"
|
|
26
|
+
},
|
|
27
|
+
"version": "0.0.1-dev.2"
|
|
28
|
+
}
|
package/typ.d.ts
ADDED
package/typ.js
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { readFileSync } from "node:fs";
|
|
2
|
+
function parseModule({ exports }) {
|
|
3
|
+
const { memory, _start: start } = exports;
|
|
4
|
+
if (!(memory instanceof WebAssembly.Memory) || typeof start !== "function")
|
|
5
|
+
throw new Error("typ.wasm exports no memory and _start");
|
|
6
|
+
return { memory, start: () => void start() };
|
|
7
|
+
}
|
|
8
|
+
export function run(request) {
|
|
9
|
+
const stdin = Buffer.from(request);
|
|
10
|
+
const [stdout, stderr] = [[], []];
|
|
11
|
+
const exit = Symbol("exit");
|
|
12
|
+
let offset = 0;
|
|
13
|
+
let code = 0;
|
|
14
|
+
let memory;
|
|
15
|
+
const transfer = (iovs, count, done, each) => {
|
|
16
|
+
const view = new DataView(memory.buffer);
|
|
17
|
+
let total = 0;
|
|
18
|
+
for (let index = 0; index < count; index++)
|
|
19
|
+
total += each(view.getUint32(iovs + 8 * index, true), view.getUint32(iovs + 8 * index + 4, true));
|
|
20
|
+
view.setUint32(done, total, true);
|
|
21
|
+
return 0;
|
|
22
|
+
};
|
|
23
|
+
const wasi = {
|
|
24
|
+
environ_get: () => 0,
|
|
25
|
+
environ_sizes_get: (count, size) => {
|
|
26
|
+
const view = new DataView(memory.buffer);
|
|
27
|
+
view.setUint32(count, 0, true);
|
|
28
|
+
view.setUint32(size, 0, true);
|
|
29
|
+
return 0;
|
|
30
|
+
},
|
|
31
|
+
fd_read: (_, iovs, count, done) => transfer(iovs, count, done, (at, length) => {
|
|
32
|
+
const read = stdin.copy(new Uint8Array(memory.buffer), at, offset, offset + length);
|
|
33
|
+
offset += read;
|
|
34
|
+
return read;
|
|
35
|
+
}),
|
|
36
|
+
fd_write: (fd, iovs, count, done) => transfer(iovs, count, done, (at, length) => {
|
|
37
|
+
(fd === 1 ? stdout : stderr).push(Buffer.from(new Uint8Array(memory.buffer, at, length)));
|
|
38
|
+
return length;
|
|
39
|
+
}),
|
|
40
|
+
proc_exit: (status) => {
|
|
41
|
+
code = status;
|
|
42
|
+
throw exit;
|
|
43
|
+
},
|
|
44
|
+
};
|
|
45
|
+
const module = parseModule(new WebAssembly.Instance(new WebAssembly.Module(readFileSync(new URL("./typ.wasm", import.meta.url))), { wasi_snapshot_preview1: wasi }));
|
|
46
|
+
memory = module.memory;
|
|
47
|
+
try {
|
|
48
|
+
module.start();
|
|
49
|
+
}
|
|
50
|
+
catch (error) {
|
|
51
|
+
if (error !== exit)
|
|
52
|
+
throw new Error(`typ: ${Buffer.concat(stderr).toString().trim()}`, { cause: error });
|
|
53
|
+
}
|
|
54
|
+
const text = Buffer.concat(stdout).toString();
|
|
55
|
+
if (code === 0)
|
|
56
|
+
return { kind: "answered", answer: text };
|
|
57
|
+
if (code === 1)
|
|
58
|
+
return { kind: "refused", reason: text };
|
|
59
|
+
throw new Error(`typ exited ${code}: ${Buffer.concat(stderr).toString().trim()}`);
|
|
60
|
+
}
|
package/typ.wasm
ADDED
|
Binary file
|