more cleanup

This commit is contained in:
2026-01-28 22:28:42 -05:00
parent ffcb6f658b
commit e04fe8cef3
4 changed files with 84 additions and 71 deletions

105
README.md
View File

@@ -1,6 +1,6 @@
# Poiesis
A Go tool that transpiles TypeScript to JavaScript using esbuild and executes it with goja, with an extensible builtin system.
A Go tool that transpiles TypeScript to JavaScript using esbuild and executes it with qjs, with an extensible function system.
## Project Structure
@@ -10,35 +10,37 @@ reichard.io/poiesis/
│ └── poiesis/ # CLI application entry point
│ └── main.go
├── internal/
── runtime/
├── pkg/
│ └── builtin/ # Builtin framework (framework only)
└── builtin.go # Registration system & type conversion
├── standard/ # Standard builtin implementations
│ ├── fetch.go # HTTP fetch builtin
── fetch_test.go # Tests for fetch
├── runtime.go # Transpilation & execution
└── runtime_test.go # Runtime tests
── runtime/ # Runtime management, transpilation, execution
├── runtime.go # Core runtime, transpilation, execution
│ │ └── runtime_test.go # Runtime tests
├── functions/ # Function registration framework
├── registry.go # Registration system
│ │ ├── types.go # Core interfaces and types
│ │ ── typescript.go # TypeScript definition generation
├── collector.go # Type collection utilities
└── typescript_test.go # Type system tests
│ └── stdlib/ # Standard library implementations
│ ├── fetch.go # HTTP fetch implementation
│ └── fetch_test.go # Fetch tests
```
## Architecture
The project is cleanly separated into three packages:
1. **`internal/runtime/pkg/builtin`** - The framework for registering builtins and type conversion
- Generic registration with automatic type inference
- Bidirectional Go ↔ JavaScript type conversion
- No builtin implementations (pure framework)
2. **`internal/runtime/standard`** - Standard builtin implementations
- `fetch`, `add`, `greet`
- Custom type converters for complex types
- Independent and easily extensible
3. **`internal/runtime`** - Runtime management
1. **`internal/runtime`** - Runtime management
- TypeScript transpilation with esbuild
- JavaScript execution with goja
- Automatically imports and registers standard builtins
- JavaScript execution with qjs
- Automatic function registration and execution
2. **`internal/functions`** - Generic function registration framework
- Type-safe registration with generics
- Bidirectional Go ↔ JavaScript type conversion
- Automatic TypeScript declaration generation
3. **`internal/stdlib`** - Standard library implementations
- `fetch` - HTTP requests
- Extensible for additional standard functions
## Installation & Build
@@ -57,55 +59,74 @@ golangci-lint run
```bash
poiesis <typescript-file>
poiesis -print-types
```
## Builtin System
## Function System
The builtin system allows you to easily expose Go functions to TypeScript/JavaScript.
The function system allows you to easily expose Go functions to TypeScript/JavaScript.
### Adding a Builtin
### Adding a Function
Just write a Go function and register it:
```go
// Your function
func add(a, b int) int {
return a + b
package mystdlib
import (
"context"
"reichard.io/poiesis/internal/functions"
)
type AddArgs struct {
A int `json:"a"`
B int `json:"b"`
}
func (a AddArgs) Validate() error {
return nil
}
func Add(_ context.Context, args AddArgs) (int, error) {
return args.A + args.B, nil
}
// Register it
func init() {
builtin.RegisterBuiltin("add", add)
functions.RegisterFunction[AddArgs, int]("add", Add)
}
```
That's it! The framework automatically:
- Converts TypeScript values to Go types
- Converts JavaScript values to Go types
- Handles errors (panics as JS errors)
- Generates TypeScript definitions
- Manages the goja integration
- Manages the qjs integration
### Example
```typescript
// TypeScript code
console.log("5 + 10 =", add(5, 10));
const response = fetch("https://httpbin.org/get");
const response = fetch({input: "https://httpbin.org/get"});
console.log("OK:", response.ok);
console.log("Status:", response.status);
console.log("Body:", response.text());
console.log("Body:", response.body);
```
### Built-in Functions
- `fetch(url, options?)` - HTTP requests
- `add(a, b)` - Simple arithmetic example
- `greet(name)` - String manipulation example
- `fetch(options)` - HTTP requests
- `options.input` (string) - URL to fetch
- `options.init` (object) - Optional init object with `method`, `headers`, `body`
## Dependencies
- `github.com/evanw/esbuild/pkg/api` - TypeScript transpilation
- `github.com/dop251/goja` - JavaScript execution
- `github.com/fastschema/qjs` - JavaScript execution (QuickJS)
- `github.com/stretchr/testify/assert` - Test assertions
## Development
- **Test framework**: Go's built-in `testing` package
- **Code style**: Follow standard Go conventions
- **Linting**: `golangci-lint run` - must pass before committing
- **TypeScript test files**: Tests that require TypeScript files should create them inline using `os.CreateTemp()` instead of relying on external test files