Skip to content

qddegtya/tlang

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

24 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

tlang

tlang

Visual-first type system above TypeScript, powered by FBP

npm version npm downloads TypeScript License Ask DeepWiki

๐ŸŽฏ Philosophy

TypeScript's type system is Turing-complete, but complex type transformations often result in unreadable "type gymnastics". This library applies Flow-Based Programming (FBP) principles to the type level, making type transformations:

  • Composable: Chain type transformations like data flows
  • Port-First: Multi-port nodes for complex data routing
  • DAG-Capable: Express computation graphs impossible in linear pipes
  • Declarative: Define typeflows visually with structured topology

๐Ÿš€ What Makes tlang Different?

vs HotScript

Feature HotScript tlang Advantage
Architecture Single-param Pipe Multi-port Node + DAG โœ… Superior
Branching โŒ Not supported โœ… Supported ๐Ÿš€ Unique
Merging โŒ Not supported โœ… Supported ๐Ÿš€ Unique
Multi-input nodes Requires Apply/Call Native support ๐Ÿš€ Unique
Tuples 13 operations 16 operations โœ… Caught up
Strings 18 operations 22 operations โœ… Caught up
Objects Basic + Advanced Basic + Advanced โœ… Caught up
Numbers BigInt arithmetic Tuple-based โœ… Caught up
Booleans 4 operations 5 operations โœ… Caught up
Unions Map, Extract, Exclude Map, Extract, Exclude โœ… Caught up

tlang = HotScript's features + FBP's powerful architecture ๐Ÿ’ช

๐Ÿ”ฅ Core Examples

Linear Pipeline (Like HotScript)

import type { Pipe, Omit, Pick } from '@atools/tlang'

type User = {
  id: number
  email: string
  password: string
  secret: string
}

// Simple linear transformation
type PublicUser = Pipe<User, [
  Omit<'password' | 'secret'>,
  Pick<'id' | 'email'>
]>
// Result: { id: number; email: string }

DAG TypeFlows (Unique to tlang!)

import type { Exec, Out, TypeFlow } from '@atools/tlang'

// Branching: One input, multiple outputs
type Split = Exec<SplitNode, { value: 3 }>
// { original: 3, doubled: 6 }

type BranchA = Exec<DoubleNode, { in: Out<Split, 'original'> }>
type BranchB = Exec<IncrementNode, { in: Out<Split, 'doubled'> }>

// Merging: Multiple inputs, one output
type Merged = Exec<AddNode, {
  a: Out<BranchA, 'out'>,  // From branch 1
  b: Out<BranchB, 'out'>   // From branch 2
}>
// { sum: 12 }

// Declarative TypeFlow Definition
type MyTypeFlow = TypeFlow<
  {
    split: SplitNode
    doubleNode: DoubleNode
    incNode: IncrementNode
    addNode: AddNode
  },
  [
    { from: { node: 'split'; port: 'original' }; to: { node: 'doubleNode'; port: 'in' } },
    { from: { node: 'split'; port: 'doubled' }; to: { node: 'incNode'; port: 'in' } },
    { from: { node: 'doubleNode'; port: 'out' }; to: { node: 'addNode'; port: 'a' } },
    { from: { node: 'incNode'; port: 'out' }; to: { node: 'addNode'; port: 'b' } }
  ],
  { split: { value: 3 } }
>

HotScript's Pipe fundamentally cannot express these DAG structures!

๐Ÿ“ฆ Installation

npm install @atools/tlang
# or
pnpm add @atools/tlang

๐Ÿ—๏ธ Core Primitives

Node

The fundamental unit - all nodes have inputs and outputs:

interface MyNode extends Node {
  inputs: { a: number; b: number }
  outputs: { sum: number }
}

Exec

Execute a node with inputs, get all outputs:

type Result = Exec<AddNode, { a: 2, b: 3 }>
// { sum: 5 }

Out

Extract value from a specific output port:

type Sum = Out<Result, 'sum'>
// 5

Pipe

Linear pipeline for single-port nodes { in } โ†’ { out }:

type Result = Pipe<5, [DoubleNode, IncrementNode]>
// 11

TypeFlow

Declarative DAG definition:

type MyTypeFlow = TypeFlow<
  { node1: Node1, node2: Node2 },
  [{ from: {...}, to: {...} }],
  { initialData }
>

๐Ÿ“š Available Operations

Tuples (16 operations)

Map, Filter, Reduce, Join, Head, Tail, Last, At, Reverse, Concat, ToUnion, ToIntersection, Length, IsEmpty, Prepend, Append

Strings (22 operations)

Split, Replace, Repeat, CamelCase, SnakeCase, KebabCase, Uppercase, Lowercase, Capitalize, Uncapitalize, Trim, TrimLeft, TrimRight, StartsWith, EndsWith, Includes, Length, ToTuple, ToString, ToNumber, Prepend, Append

Objects

Namespace operations (6): MapValues, MapKeys, Keys, Values, Entries, FromEntries

Top-level basic operations (6): Omit, Pick, Partial, Required, Readonly, Extend

Numbers (13 operations)

Add, Sub, Mul, Div, Mod, Abs, Negate, Max, Min, Compare, Equal, LessThan, GreaterThan

Booleans (5 operations)

And, Or, Not, Equals, Xor

Unions (5 operations)

Map, Extract, Exclude, UnionKeys, UnionToIntersection

๐ŸŽจ Real-World Use Cases

API Data Transformation Pipeline

// Transform backend data through validation and formatting
type UserProcessing = TypeFlow<
  {
    split: UserSplitNode,
    validateEmail: ValidateEmailNode,
    hashPassword: HashPasswordNode,
    merge: MergeUserNode
  },
  [
    { from: { node: 'split'; port: 'emailData' }; to: { node: 'validateEmail'; port: 'in' } },
    { from: { node: 'split'; port: 'passwordData' }; to: { node: 'hashPassword'; port: 'in' } },
    { from: { node: 'validateEmail'; port: 'out' }; to: { node: 'merge'; port: 'email' } },
    { from: { node: 'hashPassword'; port: 'out' }; to: { node: 'merge'; port: 'password' } }
  ],
  { initialUser }
>

Complex Form Validation

// One input branches to multiple validators, then merges results
type FormValidation = TypeFlow<
  { split: SplitInput, emailCheck: Email, phoneCheck: Phone, merge: CombineResults },
  [/* connections */],
  { formData }
>

๐ŸŽจ Visual Playground

tlang comes with a full-featured visual editor that brings type-level programming to life! Build complex type transformations by dragging and dropping nodes, connecting them visually, and seeing the generated TypeScript code in real-time.

tlang Visual Playground - Main Interface

Visual Node Editor
Drag nodes from the library, connect ports to build type transformation flows, and configure selected nodes in the properties panel!

tlang Visual Playground - Example Projects

Pre-built Examples
Load ready-to-use examples: string transformations, number calculations, object processing, and real-world API scenarios!

tlang Visual Playground - Input Configuration

Input Values Dialog
Configure entry node inputs to test your type flows - only shows nodes without incoming connections!

tlang Visual Playground - Code Generation

Generated TypeScript Code
View the generated type-level code with syntax highlighting - copy and use directly in your projects!

โœจ Playground Features

  • ๐ŸŽฏ Drag & Drop Interface - Intuitive visual node editor powered by ReactFlow
  • ๐Ÿ”— Live Connections - Connect node ports to build complex type transformation graphs
  • ๐Ÿ’ป Code Generation - Automatic TypeScript code generation from your visual graph
  • โšก Real-time Execution - TypeScript type checker runs in-browser using official @typescript/vfs
  • ๐Ÿ“Š DAG Support - Build branching and merging flows impossible in linear pipelines
  • ๐ŸŽจ Syntax Highlighting - Beautiful code display with Prism.js
  • โœ… Validation - Real-time graph validation with helpful error messages
  • ๐Ÿ“ฆ Examples - Pre-built examples to get you started quickly

๐Ÿš€ Try it Now

cd playground
pnpm install
pnpm run dev

Open your browser and start building type-level computation graphs visually!

๐Ÿ”ฎ Future Enhancements

  • ๐Ÿ” Type Debugger - Step through type evaluation process
  • ๐Ÿ’พ Save/Load Projects - Persist your type graphs locally or in the cloud
  • ๐ŸŽ“ Interactive Tutorials - Learn type-level programming through guided exercises
  • ๐ŸŒ Share & Collaborate - Share your type graphs with others via URL

๐Ÿ“Š Statistics

  • Lines of Code: ~3700+ type definitions
  • Test Coverage: 89 tests, 100% passing
  • Feature Parity: 100% of HotScript core features
  • Unique Features: DAG support (HotScript 0%)

๐Ÿค Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

๐Ÿ“„ License

MIT


Tlang: Type-level programming, evolved. ๐Ÿš€

About

๐Ÿ‘€ Visual-first type system above TypeScript, powered by FBP.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published