···11-you're working on a TypeSpec emitter for atproto lexicons. you have these commands: `pnpm run build` builds the example (you can inspect the generated lexicons in the `packages/example/lexicon`) and `pnpm test` runs tests (they are in `packages/emitter/test/`).
22-33-what i want you to do is to gradually keep adding features to typelex so that in the end it's possible to express all Lexicon code with that language. you have the following resources:
44-55-- read `SYNTAX.md`!!! it's the main guideline
66-77-- `../typespec/packages` has a bunch of other emitters (so you can check how they're implemented and common patterns)
88-99-- `../typespec/website/src/content` has typescpec docs (which you might find very useful)
1010-1111-- `../atproto-website/src/app/[locale]/specs/lexicon` contains lexicon spec (where we want to reach feature parity), and most importantly
1212-1313-- `test/scenarios/atproto/output` contains a TON of lexicon definitions which i want you to translate to typespec one by one. for each atproto lexicon you're porting, your job is to create the corresponding "`input`s" for them (and fix bugs or add missing features along the way).
1414-1515-the goal is to end up with a language that feels nice and concise, not some weird interop thing. so try to do things "typespec" way as you go through each lexicon. and try to respect atproto too. this should feel like a *language for atproto*. consider whether your design is elegant. and make sure to look at other typespec emitters for design ideas!
1616-1717-remember NOT to change the output to fit the input -- your job is to make the input MATCH the output. if some lexicon is too hard, you can give up on it and try another one. good luck!
1818-1919-the workflow is: pick some new lexicons, create the input files, figure out missing features / bugs, and try to get tests to pass. repeat. when you make nontrivial progress, you'll want to prepare a commit.
2020-2121-before you want to make a commit, make sure `pnpm test` and `pnpm run build` passes and, ideally, inspect the `example` app output (and maybe add the features you've just implemented there for parity). then stop and notify me.
2222-2323-ps. be mindful of the code style. we only put decorators on same line if it's `@required` alone; otherwise, put each on newline and add a newline after. see existing files for a hint.
2424-2525-good luck! i believe in you
2626-2727-2828----
2929-3030-whenever you get stuck (try `npm test`) because you don't have a convention for how to define some pattern yetm i want you to read these sources
3131-3232- - `../typespec/packages` has a bunch of other emitters (so you can check how they're implemented and common patterns)
3333-3434- - `../typespec/website/src/content` has typescpec docs (which you might find very useful)
3535-3636- - `../atproto-website/src/app/[locale]/specs/lexicon` contains lexicon spec
3737-3838- and ultrathink about what's the most appropriate way to define defs like you want would be in this typespec translation of atproto. you can research these sources for what feels most idiomatic to define that syntax, and how to make
3939- the formatter understand that convention and emit the JSON we want.
4040-4141- also note that you can always look at generated atproto lexicons in ../atproto/lexicons -- use these!! look at the TS types there for corresponding
4242- models to inspire how you represent things in tsp syntax.
4343-4444- - read `SYNTAX.md`!!! it's the main guideline
+8-2
DOCS.md
···11-# TypeSpec to Lexicon Reference
11+# Typelex Docs
22+33+This guide maps atproto Lexicon JSON syntax to typelex (a [TypeSpec](https://typespec.io/) emitter). It assumes you're familiar with Lexicon and want to understand how to express it in TypeSpec. Consult [TypeSpec docs](https://typespec.io/) on details of TypeSpec syntax.
2433-This guide maps atproto Lexicon JSON syntax to TypeSpec (typelex). It assumes you're familiar with Lexicon and want to understand how to express it in TypeSpec.
55+Btw, this page was mostly written by Claude. I hope it's mostly correct and comprehensible.
66+77+## Playground
88+99+Go to https://typelex-playground.pages.dev/ to play with a bunch of lexicons.
410511## Quick Start
612
LICENSE
LICENSE.md
+8-132
README.md
···11# typelex
2233-> TypeSpec-based IDL for ATProto Lexicons
44-55-typelex allows you to define [ATProto](https://atproto.com) lexicons using [TypeSpec](https://typespec.io), providing type safety, better tooling, and a more ergonomic syntax compared to writing raw JSON.
66-77-## Features
88-99-- 🔧 **Type-safe** - Leverage TypeSpec's type system to catch errors at compile time
1010-- 📝 **Better DX** - Write lexicons with IDE support, auto-completion, and inline documentation
1111-- 🎯 **ATProto-compliant** - Generates valid lexicon JSON that works with any ATProto implementation
1212-- 🚀 **Simple** - No complex tooling or configuration required
1313-1414-## Quick Start
1515-1616-```bash
1717-# Install TypeSpec compiler
1818-npm install -g @typespec/compiler
1919-2020-# Install typelex emitter
2121-npm install --save-dev @typelex/emitter
2222-```
2323-2424-Create a `main.tsp` file:
2525-2626-```typescript
2727-namespace app.bsky.feed;
2828-2929-@doc("A post in the feed")
3030-model Post {
3131- @doc("Post content")
3232- text: string;
3333-3434- @doc("Creation timestamp")
3535- createdAt: utcDateTime;
3636-3737- @doc("Languages the post is written in")
3838- langs?: string[];
3939-}
4040-```
4141-4242-Add a `tspconfig.yaml`:
4343-4444-```yaml
4545-emit:
4646- - "@typelex/emitter"
4747-options:
4848- "@typelex/emitter":
4949- output-dir: "./lexicons"
5050-```
5151-5252-Compile to lexicon JSON:
5353-5454-```bash
5555-tsp compile .
5656-```
5757-5858-## Output
5959-6060-typelex generates standard ATProto lexicon files:
6161-6262-```json
6363-{
6464- "lexicon": 1,
6565- "id": "app.bsky.feed.post",
6666- "defs": {
6767- "main": {
6868- "type": "record",
6969- "key": "tid",
7070- "record": {
7171- "type": "object",
7272- "properties": {
7373- "text": {
7474- "type": "string",
7575- "description": "Post content"
7676- },
7777- "createdAt": {
7878- "type": "string",
7979- "format": "datetime",
8080- "description": "Creation timestamp"
8181- },
8282- "langs": {
8383- "type": "array",
8484- "items": {
8585- "type": "string"
8686- },
8787- "description": "Languages the post is written in"
8888- }
8989- },
9090- "required": ["text", "createdAt"]
9191- }
9292- }
9393- }
9494-}
9595-```
9696-9797-## Examples
9898-9999-See the [`packages/example`](./packages/example) directory for a complete example project.
100100-101101-## Development
102102-103103-```bash
104104-# Clone the repository
105105-git clone https://github.com/yourusername/typelex.git
106106-cd typelex
107107-108108-# Build the emitter
109109-pnpm install
110110-pnpm run build
33+An experimental TypeSpec emitter for Lexicon.
1114112112-# Try the example
113113-pnpm run example
114114-```
55+See https://typelex.pages.dev/
1156116116-## Current Status
77+## Playground
1178118118-⚠️ **Early Development** - typelex currently supports basic record types. Support for queries, procedures, and subscriptions is coming soon.
99+See https://typelex-playground.pages.dev/
11910120120-### Supported
1111+## Reference
12112122122-- ✅ Record types
123123-- ✅ Basic types (string, boolean, integer, datetime)
124124-- ✅ Arrays and objects
125125-- ✅ Optional fields
126126-- ✅ Documentation
1313+See [DOCS.md](./DOCS.md)
12714128128-### Coming Soon
1515+## License
12916130130-- 🚧 XRPC queries and procedures
131131-- 🚧 Subscriptions
132132-- 🚧 Union types
133133-- 🚧 ATProto-specific validations (maxGraphemes, etc.)
134134-- 🚧 Blob references
1717+MIT
13518136136-## Contributing
137137-138138-Contributions are welcome! Please feel free to submit a Pull Request.
139139-140140-## License
141141-142142-MIT