Skip to content

imzlh/cno

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

CTS

Enable your circu.js to run Deno applications.

Description

CTS (Circu.js TypeScript Runtime) is a TypeScript bootstrap that provides full TypeScript experience for circu.js. It implements Web API and Deno API polyfills, enabling Deno applications to run in circu.js environment.

Built on QuickJS engine, CTS bridges the gap between circu.js runtime and Deno's API surface, making it possible to run Deno-compatible code with minimal modifications.

Status

WebAPI

  • [-] Event
    • Event
    • EventTarget
    • CustomEvent
    • MessageEvent
    • CloseEvent
    • ErrorEvent
    • StorageEvent
    • PromiseRejectionEvent
  • [-] URL、URLPattern
    • URL
    • URLSearchParams
    • URLPattern (polyfill)
  • [-] Stream
    • ReadableStream
    • WritableStream
    • TransformStream
    • ReadableStreamDefaultController
    • WritableStreamDefaultController
  • [-] Blob、FormData
    • Blob
    • File
    • FileReader
    • FormData
  • [-] AbortSignal
    • AbortController
    • AbortSignal
  • [-] Header Request Response
    • Headers
    • Request
    • Response
  • [-] fetch
    • fetch API
    • Redirect handling
    • Connection pooling
    • Keep-alive support
  • [-] WebSocket
    • WebSocket client
    • WebSocket server upgrade
    • RFC 6455 compliant
  • [-] CryptoSubtle crypto
    • crypto.getRandomValues
    • SHA-1, SHA-256, SHA-384, SHA-512
    • AES-CBC, AES-GCM, AES-CTR
    • RSA-OAEP, RSA-PSS, RSASSA-PKCS1-v1_5
    • ECDSA, ECDH
    • HMAC, PBKDF2
    • Key generation, import, export
  • [-] performance
    • performance.now()
    • performance.mark()
    • performance.measure()
    • PerformanceObserver
  • [-] wasm
    • WebAssembly.compile
    • WebAssembly.instantiate
    • WebAssembly.compileStreaming
    • WebAssembly.instantiateStreaming
  • [-] Storage
    • localStorage
    • sessionStorage
    • SQLite-backed persistence
    • WAL mode support
  • [-] Temporal
    • Temporal (polyfill available, not enabled)
  • [-] Intl
    • DateTimeFormat
    • NumberFormat
    • RelativeTimeFormat
    • DisplayNames
    • Locale data (zh, en)
  • more
    • atob / btoa
    • TextEncoder / TextDecoder
    • setTimeout / setInterval / clearTimeout
    • structuredClone
    • alert / prompt / confirm
    • close
    • reportError
    • EventSource (SSE)

Deno

  • permission (partial)
    • permissions.query (always granted)
    • permissions.request
    • permissions.revoke
  • unstable
    • ffi (soon)
    • kv
    • vsock
    • multicast
    • datagram (soon)
    • bundle (Deno.bundle)
    • cron
    • ws stream
  • [-] basic
    • Deno.pid / Deno.ppid
    • Deno.args
    • Deno.env
    • Deno.exit / Deno.exitCode
    • Deno.build
    • Deno.version
    • Deno.cwd / Deno.chdir
    • Deno.mainModule
    • Deno.execPath
    • Deno.noColor
    • Deno.memoryUsage
    • Deno.systemMemoryInfo
    • Deno.hostname
    • Deno.loadavg
    • Deno.osRelease
    • Deno.osUptime
    • Deno.uid / Deno.gid
    • Deno.inspect
    • Deno.errors
    • Deno.addSignalListener
    • Deno.removeSignalListener
  • [-] net
    • Deno.connect (TCP, Unix)
    • Deno.connectTls
    • Deno.listen (TCP, Unix)
    • Deno.listenTls
    • Deno.startTls
    • Deno.resolveDns (A, AAAA, CNAME, MX, NS, PTR, SOA, SRV, TXT, CAA, NAPTR)
    • Deno.networkInterfaces
    • TcpConn / TlsConn / UnixConn
    • Listener / TcpListener / TlsListener
  • [-] fs
    • Deno.readFile / readTextFile
    • Deno.writeFile / writeTextFile
    • Deno.readDir
    • Deno.mkdir
    • Deno.remove
    • Deno.rename
    • Deno.copyFile
    • Deno.stat / lstat
    • Deno.truncate
    • Deno.chmod / chown
    • Deno.link / symlink / readLink
    • Deno.realPath
    • Deno.makeTempDir / makeTempFile
    • Deno.open / FsFile
    • Deno.watchFs
  • [-] terminal
    • Deno.stdin
    • Deno.stdout
    • Deno.stderr
    • Deno.consoleSize
    • isTerminal
    • setRaw
  • [-] process
    • Deno.Command
    • Deno.kill
    • ChildProcess
    • spawn / output / outputSync
    • Deno.umask
  • [-] serve
    • Deno.serve
    • HTTP/1.1 server
    • HTTPS support
    • Request/Response handling
  • [-] serve ws
    • Deno.upgradeWebSocket
    • WebSocket server

CNO Namespace

  • CNO.openpty - PTY spawning
  • CNO.engine
    • serialize / deserialize
    • evalModule
    • compileModule

Node.js Compatibility

  • [-] fs
    • readFileSync / readFile
    • writeFileSync / writeFile
    • appendFileSync
    • existsSync
    • statSync / lstatSync / fstatSync
    • accessSync
    • mkdirSync / mkdirSync (recursive)
    • rmdirSync / rmSync
    • readdirSync
    • renameSync
    • copyFileSync
    • unlinkSync
    • readlinkSync / symlinkSync / linkSync
    • realpathSync
    • truncateSync / ftruncateSync
    • chmodSync / chownSync / fchmodSync / fchownSync
    • utimesSync / futimesSync
    • openSync / closeSync
    • readSync / writeSync
    • fsyncSync / fdatasyncSync
    • mkdirpSync
    • promises API (async fs operations)
    • callback API
    • constants (F_OK, R_OK, W_OK, X_OK, etc.)
  • path
    • join, resolve, normalize, dirname, basename, extname
    • relative, isAbsolute
    • parse, format
    • sep, delimiter
    • win32, posix namespaces
  • os
    • hostname, type, platform, arch
    • release, version, uptime
    • cpus, loadavg, freemem, totalmem
    • homedir, tmpdir, userinfo
    • networkInterfaces
    • EOL, constants
  • dns
    • lookup, resolve
    • resolve4, resolve6
    • reverse
    • promises API
  • events
    • EventEmitter
    • once, on, off
    • captureRejectionSymbol
  • util
    • promisify, callbackify
    • inherits
    • isDeepStrictEqual
    • format, inspect
    • types (isArray, isNull, etc.)
  • [-] crypto
    • createHash (SHA-1, SHA-256, SHA-512, MD5)
    • createHmac
    • createCipher / createDecipher
    • createSign / createVerify
    • randomBytes
    • pbkdf2 / pbkdf2Sync
    • scrypt / scryptSync
    • constants
  • [-] stream
    • Stream (base class)
    • Readable
    • Writable
    • Duplex
    • Transform
    • PassThrough
    • pipeline, finished
    • Readable.from
    • promises namespace
    • addAbortSignal
  • [-] net
    • Socket
    • Server
    • createServer
    • connect / createConnection
    • isIP, isIPv4, isIPv6
    • setNoDelay, setKeepAlive
    • setTimeout, ref, unref
  • [-] child_process
    • spawn
    • exec, execFile
    • execSync, execFileSync
    • fork (partial)
    • ChildProcess class
    • stdin/stdout/stderr streams
  • buffer
    • Buffer class
    • Buffer.from, Buffer.alloc, Buffer.allocUnsafe
    • Buffer.concat, Buffer.isBuffer
    • Buffer.byteLength
    • toString, toJSON, equals, compare
    • slice, subarray, copy, fill
    • readInt*, writeInt*, readUInt*, writeUInt*
    • transcode
  • [-] zlib
    • deflate / deflateSync / deflateRaw / deflateRawSync
    • inflate / inflateSync / inflateRaw / inflateRawSync
    • gzip / gzipSync / gunzip / gunzipSync
    • unzip / unzipSync
    • brotliCompress / brotliDecompress
    • constants (compression levels, strategies, etc.)
    • createDeflate, createInflate, etc.
  • [-] dgram
    • createSocket (udp4, udp6)
    • bind, send, close
    • addMembership, dropMembership
    • setBroadcast, setTTL, setMulticastTTL
    • address, remoteAddress
    • message, listening, error, close events
  • [-] process
    • argv, argv0, execArgv
    • env (Proxy-based)
    • cwd, chdir
    • exit, exitCode
    • pid, ppid
    • platform, arch
    • version, versions
    • title
    • execPath
    • memoryUsage, cpuUsage
    • hrtime, uptime
    • nextTick
    • kill, abort
    • signal handling (on, off, once)
    • getuid, getgid, geteuid, getegid
    • umask
    • config, release, features
    • report, resourceUsage
    • emitWarning
    • permission.has
  • timers
    • setTimeout, clearTimeout
    • setInterval, clearInterval
    • setImmediate, clearImmediate
    • promises namespace (setTimeout, scheduler)

Architecture

CTS loads in the following order:

  1. WebAPI (src/webapi/) - Web standard API polyfills
  2. Deno (src/deno/) - Deno runtime API implementation
  3. CJS (src/cjs/) - CNO private namespace and extensions (PTY, engine)
  4. Module (src/module/) - HTTP module (fetch, websocket, SSE, server)

Project Structure

denort/
├── src/
│   ├── main.ts              # Entry point
│   ├── webapi/              # Web API polyfills
│   │   ├── basic.ts         # atob, btoa, TextEncoder, timers, etc.
│   │   ├── url.ts           # URL, URLSearchParams
│   │   ├── streams.ts       # ReadableStream, WritableStream
│   │   ├── crypto.ts        # SubtleCrypto implementation
│   │   ├── performance.ts   # Performance API
│   │   ├── storage.ts       # localStorage, sessionStorage
│   │   ├── intl.ts          # Intl API
│   │   ├── wasm.ts          # WebAssembly
│   │   └── events.ts        # Event, EventTarget
│   ├── deno/                # Deno API implementation
│   │   ├── 00_permission.ts # Permission system
│   │   ├── 01_errors.ts     # Deno error classes
│   │   ├── 02_fs.ts         # File system operations
│   │   ├── 03_fopen.ts      # File handle (FsFile)
│   │   ├── 04_stdio.ts      # stdin, stdout, stderr
│   │   ├── 05_net.ts        # TCP, TLS, Unix sockets
│   │   ├── 06_process.ts    # Process spawning
│   │   ├── 07_http.ts       # HTTP utilities
│   │   └── 08_serve.ts      # Deno.serve, upgradeWebSocket
│   ├── cjs/                 # CNO namespace
│   │   ├── pty.ts           # PTY spawning
│   │   └── engine.ts        # Engine utilities
│   ├── module/              # HTTP module
│   │   └── http/
│   │       ├── fetch.ts     # fetch API
│   │       ├── websocket.ts # WebSocket
│   │       ├── sse.ts       # EventSource
│   │       ├── server.ts    # HTTP server
│   │       ├── connection.ts# Connection pooling
│   │       └── http.ts      # HTTP parser/builder
│   ├── node/                # Node.js compatibility
│   └── utils/               # Utility functions
├── example/                 # Example projects
├── types/                   # Type definitions
├── dist.js                  # Bundled output
└── Makefile

Build

# Install dependencies
pnpm install

# Build bundle
pnpm run build

# Bundle to single file
pnpm run bundle

# Build node polyfills (requires cts)
make

Usage

After building, dist.js can be loaded in circu.js environment to provide Deno-compatible APIs.

// File system
const data = await Deno.readTextFile("./example.txt");
console.log(data);

// HTTP client
const response = await fetch("https://api.example.com/data");
const json = await response.json();

// HTTP server
Deno.serve({ port: 8000 }, (request) => {
  return new Response("Hello World");
});

// WebSocket
const ws = new WebSocket("wss://example.com/socket");
ws.onmessage = (e) => console.log(e.data);

// Process spawning
const cmd = new Deno.Command("echo", { args: ["hello"] });
const { stdout } = await cmd.output();

// Network
const conn = await Deno.connect({ hostname: "example.com", port: 80 });
await conn.write(new TextEncoder().encode("GET / HTTP/1.1\r\n\r\n"));

Dependencies

Web API Polyfills

  • web-streams-polyfill - Streams API
  • formdata-polyfill - FormData
  • blob-polyfill - Blob/File
  • abortcontroller-polyfill - AbortController/AbortSignal
  • urlpattern-polyfill - URLPattern
  • whatwg-url - URL implementation
  • headers-polyfill - Headers API
  • temporal-polyfill - Temporal API
  • @formatjs/intl - Intl API

Build Tools

  • esbuild - Bundling
  • sucrase - TypeScript transformation

License

MIT

About

A deno-compatible circu.js bootstrap, provide polyfill to run deno applications

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors