typp 0.0.1.dev1__py3-none-any.whl
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.
- typp/__init__.py +90 -0
- typp/py.typed +0 -0
- typp/typ.wasm +0 -0
- typp-0.0.1.dev1.dist-info/METADATA +74 -0
- typp-0.0.1.dev1.dist-info/RECORD +7 -0
- typp-0.0.1.dev1.dist-info/WHEEL +4 -0
- typp-0.0.1.dev1.dist-info/licenses/LICENSE +22 -0
typp/__init__.py
ADDED
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import struct
|
|
2
|
+
from dataclasses import dataclass
|
|
3
|
+
from importlib.resources import files
|
|
4
|
+
|
|
5
|
+
from wasmtime import (
|
|
6
|
+
Caller,
|
|
7
|
+
Engine,
|
|
8
|
+
ExitTrap,
|
|
9
|
+
Func,
|
|
10
|
+
FuncType,
|
|
11
|
+
Linker,
|
|
12
|
+
Memory,
|
|
13
|
+
Module,
|
|
14
|
+
Store,
|
|
15
|
+
ValType,
|
|
16
|
+
WasiConfig,
|
|
17
|
+
WasmtimeError,
|
|
18
|
+
)
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
@dataclass
|
|
22
|
+
class Answered:
|
|
23
|
+
answer: str
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
@dataclass
|
|
27
|
+
class Refused:
|
|
28
|
+
reason: str
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
Outcome = Answered | Refused
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
def _parse(memory: object, start: object) -> tuple[Memory, Func]:
|
|
35
|
+
if not isinstance(memory, Memory) or not isinstance(start, Func):
|
|
36
|
+
raise TypeError("typ.wasm exports no memory and _start")
|
|
37
|
+
return memory, start
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
def run(request: str) -> Outcome:
|
|
41
|
+
stdin = request.encode()
|
|
42
|
+
offset = 0
|
|
43
|
+
stdout, stderr = bytearray(), bytearray()
|
|
44
|
+
memory: Memory
|
|
45
|
+
|
|
46
|
+
def fd_read(caller: Caller, fd: int, iovs: int, count: int, done: int) -> int:
|
|
47
|
+
nonlocal offset
|
|
48
|
+
total = 0
|
|
49
|
+
for index in range(count):
|
|
50
|
+
at, length = struct.unpack(
|
|
51
|
+
"<II", memory.read(caller, iovs + 8 * index, iovs + 8 * index + 8)
|
|
52
|
+
)
|
|
53
|
+
chunk = stdin[offset : offset + length]
|
|
54
|
+
memory.write(caller, chunk, at)
|
|
55
|
+
offset += len(chunk)
|
|
56
|
+
total += len(chunk)
|
|
57
|
+
memory.write(caller, struct.pack("<I", total), done)
|
|
58
|
+
return 0
|
|
59
|
+
|
|
60
|
+
engine = Engine()
|
|
61
|
+
linker = Linker(engine)
|
|
62
|
+
linker.allow_shadowing = True
|
|
63
|
+
linker.define_wasi()
|
|
64
|
+
linker.define_func(
|
|
65
|
+
"wasi_snapshot_preview1",
|
|
66
|
+
"fd_read",
|
|
67
|
+
FuncType([ValType.i32()] * 4, [ValType.i32()]),
|
|
68
|
+
fd_read,
|
|
69
|
+
access_caller=True,
|
|
70
|
+
)
|
|
71
|
+
wasi = WasiConfig()
|
|
72
|
+
wasi.stdout_custom = stdout.extend
|
|
73
|
+
wasi.stderr_custom = stderr.extend
|
|
74
|
+
store = Store(engine)
|
|
75
|
+
store.set_wasi(wasi)
|
|
76
|
+
module = Module(engine, (files(__name__) / "typ.wasm").read_bytes())
|
|
77
|
+
exports = linker.instantiate(store, module).exports(store)
|
|
78
|
+
memory, start = _parse(exports["memory"], exports["_start"])
|
|
79
|
+
code = 0
|
|
80
|
+
try:
|
|
81
|
+
start(store)
|
|
82
|
+
except ExitTrap as exited:
|
|
83
|
+
code = exited.code
|
|
84
|
+
except WasmtimeError as fault:
|
|
85
|
+
raise RuntimeError(f"typ: {stderr.decode().strip()}") from fault
|
|
86
|
+
if code == 0:
|
|
87
|
+
return Answered(stdout.decode())
|
|
88
|
+
if code == 1:
|
|
89
|
+
return Refused(stdout.decode())
|
|
90
|
+
raise RuntimeError(f"typ exited {code}: {stderr.decode().strip()}")
|
typp/py.typed
ADDED
|
File without changes
|
typp/typ.wasm
ADDED
|
Binary file
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: typp
|
|
3
|
+
Version: 0.0.1.dev1
|
|
4
|
+
Summary: typ.wasm and a Python host that sends it one request
|
|
5
|
+
Project-URL: Repository, https://github.com/holon-sh/typ
|
|
6
|
+
License-Expression: MIT
|
|
7
|
+
License-File: LICENSE
|
|
8
|
+
Requires-Python: >=3.11
|
|
9
|
+
Requires-Dist: wasmtime<52,>=51
|
|
10
|
+
Description-Content-Type: text/markdown
|
|
11
|
+
|
|
12
|
+
# typ
|
|
13
|
+
|
|
14
|
+
```bash
|
|
15
|
+
go get github.com/holon-sh/typ
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
```bash
|
|
19
|
+
npm install @holon-sh/typ
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
```js
|
|
23
|
+
import { readFileSync } from "node:fs";
|
|
24
|
+
import { run } from "@holon-sh/typ";
|
|
25
|
+
|
|
26
|
+
const outcome = run(readFileSync("examples/generate.json", "utf8"));
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
`run` takes a request and returns `{ kind: "answered", answer }` or `{ kind: "refused", reason }`.
|
|
30
|
+
|
|
31
|
+
```bash
|
|
32
|
+
uv add typp
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
```python
|
|
36
|
+
from pathlib import Path
|
|
37
|
+
from typp import run
|
|
38
|
+
|
|
39
|
+
outcome = run(Path("examples/generate.json").read_text())
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
`run` takes a request and returns `Answered(answer)` or `Refused(reason)`.
|
|
43
|
+
|
|
44
|
+
`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.
|
|
45
|
+
|
|
46
|
+
```bash
|
|
47
|
+
wasmtime typ.wasm < examples/same_contract.json
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
Each `v0.0.1-dev.N` tag attaches `typ.wasm` and `typ.wasm.sha256` to its release and publishes `@holon-sh/typ` at version `0.0.1-dev.N` and `typp` at `0.0.1.devN`.
|
|
51
|
+
|
|
52
|
+
`typ.wasm` is built from `src/` with the pinned Rust toolchain:
|
|
53
|
+
|
|
54
|
+
```bash
|
|
55
|
+
scripts/build
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
Tests:
|
|
59
|
+
|
|
60
|
+
```bash
|
|
61
|
+
go test ./...
|
|
62
|
+
cargo test
|
|
63
|
+
npm ci && npm test
|
|
64
|
+
uv build --wheel && uv run --project tooling --with dist/*.whl pytest typ_test.py
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
The tests that run Node, Python and the type checkers against generated clients need `tooling/` installed and the `toolchains` tag:
|
|
68
|
+
|
|
69
|
+
```bash
|
|
70
|
+
npm ci --prefix tooling
|
|
71
|
+
uv sync --project tooling
|
|
72
|
+
(cd tooling && go mod download)
|
|
73
|
+
go test -tags toolchains ./...
|
|
74
|
+
```
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
typp/__init__.py,sha256=pDO0gu5D7wh_pXzCVU6aVdcGtPqb35jNeWBzVyv9OOk,2345
|
|
2
|
+
typp/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
3
|
+
typp/typ.wasm,sha256=FA1-KXBA-mZJj9pTSB7-rjAbazpcEPBLIC6CM_DD_UA,397813
|
|
4
|
+
typp-0.0.1.dev1.dist-info/METADATA,sha256=Qm4lrrGCURV-_xobJuZccUcN9glbNbGeK8vyE3AFd6w,1832
|
|
5
|
+
typp-0.0.1.dev1.dist-info/WHEEL,sha256=2iZrJkDIkeDh0k9SikKMqFuRP-ua6mb4Ir1AsER4BEw,87
|
|
6
|
+
typp-0.0.1.dev1.dist-info/licenses/LICENSE,sha256=lY_6LhCHAwlhWJ-aCyK--ygY6y7c5PyHnNQd_PmgNzA,1077
|
|
7
|
+
typp-0.0.1.dev1.dist-info/RECORD,,
|
|
@@ -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
|
+
|