···11-# prototypey
22-33-A (soon-to-be) fully-featured sdk for developing lexicons with typescript.
44-55-## Installation
66-77-```bash
88-npm install prototypey
99-```
1010-1111-## Usage
1212-1313-Prototypey provides both a TypeScript library for authoring lexicons and a CLI for code generation.
1414-1515-### Authoring Lexicons
1616-1717-Use the library to author type-safe lexicon schemas in TypeScript:
1818-1919-**what you'll write:**
2020-2121-```ts
2222-const lex = lx.lexicon("app.bsky.actor.profile", {
2323- main: lx.record({
2424- key: "self",
2525- record: lx.object({
2626- displayName: lx.string({ maxLength: 64, maxGraphemes: 64 }),
2727- description: lx.string({ maxLength: 256, maxGraphemes: 256 }),
2828- }),
2929- }),
3030-});
3131-```
3232-3333-**generates to:**
3434-3535-```json
3636-{
3737- "lexicon": 1,
3838- "id": "app.bsky.actor.profile",
3939- "defs": {
4040- "main": {
4141- "type": "record",
4242- "key": "self",
4343- "record": {
4444- "type": "object",
4545- "properties": {
4646- "displayName": {
4747- "type": "string",
4848- "maxLength": 64,
4949- "maxGraphemes": 64
5050- },
5151- "description": {
5252- "type": "string",
5353- "maxLength": 256,
5454- "maxGraphemes": 256
5555- }
5656- }
5757- }
5858- }
5959- }
6060-}
6161-```
6262-6363-### CLI Commands
6464-6565-The `prototypey` package includes a CLI with two main commands:
6666-6767-#### `gen-inferred` - Generate TypeScript from JSON schemas
6868-6969-```bash
7070-prototypey gen-inferred <outdir> <schemas...>
7171-```
7272-7373-Reads ATProto lexicon JSON schemas and generates TypeScript types.
7474-7575-**Example:**
7676-7777-```bash
7878-prototypey gen-inferred ./generated/inferred ./lexicons/**/*.json
7979-```
8080-8181-#### `gen-emit` - Emit JSON schemas from TypeScript
8282-8383-```bash
8484-prototypey gen-emit <outdir> <sources...>
8585-```
8686-8787-Extracts JSON schemas from TypeScript lexicon definitions.
8888-8989-**Example:**
9090-9191-```bash
9292-prototypey gen-emit ./lexicons ./src/lexicons/**/*.ts
9393-```
9494-9595-### Typical Workflow
9696-9797-1. Author lexicons in TypeScript using the library
9898-2. Emit JSON schemas with `gen-emit` for runtime validation
9999-100100-**Recommended:** Add as a script to your `package.json`:
101101-102102-```json
103103-{
104104- "scripts": {
105105- "lexicon:emit": "prototypey gen-emit ./schemas ./src/lexicons/**/*.ts"
106106- }
107107-}
108108-```
109109-110110-Then run:
111111-112112-```bash
113113-npm run lexicon:emit
114114-```
115115-116116-## State of the Project
117117-118118-**Done:**
119119-120120-- Full atproto spec lexicon authoring with in IDE docs & hints for each attribute (ts => json)
121121-- CLI generates json from ts definitions
122122-- CLI generates ts from json definitions
123123-- Inferrance of valid type from full lexicon definition
124124- - the really cool part of this is that it fills in the refs from the defs all at the type level
125125-126126-**TODO/In Progress:**
127127-128128-- Library art! Please reach out if you'd be willing to contribute some drawings or anything!
129129-- Runtime validation using [@atproto/lexicon](https://www.npmjs.com/package/@atproto/lexicon)
130130- - this will be hard to get correct, I'm weary of loading all of the json in a project's lexicons into js memory and would like to run benchmarks and find the best way to get this right.
131131-- The CLI needs more real world use and mileage. I expect bugs and weird behavior in this initial release (sorry).
132132-133133-## Disclaimer:
134134-135135-I'm considering how to use the json for validation (there will likely be some lazy-loading). For the cli,
136136-files may need to adopt a convention so it's easy to determine what is an `lx.lexicon` and then generate out it's json and export it as a validator that lazy loads json to validate. (these are just ideas right now, but I want to share where we are now :)
137137-138138-Please give any and all feedback. I've not really written many lexicons much myself yet, so this project is at a point of "well I think this makes sense" 😂. Both the [issues page](https://github.com/tylersayshi/prototypey/issues) and [discussions](https://github.com/tylersayshi/prototypey/discussions) are open and ready for y'all 🙂.
139139-140140----
141141-142142-> 💝 This package was templated with
143143-> [`create-typescript-app`](https://github.com/JoshuaKGoldberg/create-typescript-app)
144144-> using the [Bingo framework](https://create.bingo).
11+./packages/prototypey/README.md
···4242- Reads ATProto lexicon JSON schemas
4343- Generates TypeScript types that match the schema structure
4444- Organizes output files by namespace (e.g., `app.bsky.feed.post` → `app/bsky/feed/post.ts`)
4545-- Provides type-safe interfaces for working with lexicon data
4545+- Provides typescript definitions of the lexicons for inference and later: validation
46464747### `gen-emit`
4848
···11+# prototypey
22+33+A (soon-to-be) fully-featured sdk for developing lexicons with typescript.
44+55+## Installation
66+77+```bash
88+npm install prototypey
99+```
1010+1111+## Usage
1212+1313+Prototypey provides both a TypeScript library for authoring lexicons and a CLI for code generation.
1414+1515+### Authoring Lexicons
1616+1717+**what you'll write:**
1818+1919+```ts
2020+const lex = lx.lexicon("app.bsky.actor.profile", {
2121+ main: lx.record({
2222+ key: "self",
2323+ record: lx.object({
2424+ displayName: lx.string({ maxLength: 64, maxGraphemes: 64 }),
2525+ description: lx.string({ maxLength: 256, maxGraphemes: 256 }),
2626+ }),
2727+ }),
2828+});
2929+```
3030+3131+**generates to:**
3232+3333+```json
3434+{
3535+ "lexicon": 1,
3636+ "id": "app.bsky.actor.profile",
3737+ "defs": {
3838+ "main": {
3939+ "type": "record",
4040+ "key": "self",
4141+ "record": {
4242+ "type": "object",
4343+ "properties": {
4444+ "displayName": {
4545+ "type": "string",
4646+ "maxLength": 64,
4747+ "maxGraphemes": 64
4848+ },
4949+ "description": {
5050+ "type": "string",
5151+ "maxLength": 256,
5252+ "maxGraphemes": 256
5353+ }
5454+ }
5555+ }
5656+ }
5757+ }
5858+}
5959+```
6060+6161+you could also access the json definition with `lex.json()`.
6262+6363+### CLI Commands
6464+6565+The `prototypey` package includes a CLI with two main commands:
6666+6767+#### `gen-inferred` - Generate TypeScript from JSON schemas
6868+6969+```bash
7070+prototypey gen-inferred <outdir> <schemas...>
7171+```
7272+7373+Reads ATProto lexicon JSON schemas and generates TypeScript types.
7474+7575+**Example:**
7676+7777+```bash
7878+prototypey gen-inferred ./generated/inferred ./lexicons/**/*.json
7979+```
8080+8181+#### `gen-emit` - Emit JSON schemas from TypeScript
8282+8383+```bash
8484+prototypey gen-emit <outdir> <sources...>
8585+```
8686+8787+Extracts JSON schemas from TypeScript lexicon definitions.
8888+8989+**Example:**
9090+9191+```bash
9292+prototypey gen-emit ./lexicons ./src/lexicons/**/*.ts
9393+```
9494+9595+### Typical Workflow
9696+9797+1. Author lexicons in TypeScript using the library
9898+2. Emit JSON schemas with `gen-emit` for runtime validation
9999+100100+**Recommended:** Add as a script to your `package.json`:
101101+102102+```json
103103+{
104104+ "scripts": {
105105+ "lexicon:emit": "prototypey gen-emit ./schemas ./src/lexicons/**/*.ts"
106106+ }
107107+}
108108+```
109109+110110+Then run:
111111+112112+```bash
113113+npm run lexicon:emit
114114+```
115115+116116+## State of the Project
117117+118118+**Done:**
119119+120120+- Full atproto spec lexicon authoring with in IDE docs & hints for each attribute (ts => json)
121121+- CLI generates json from ts definitions
122122+- CLI generates ts from json definitions
123123+- Inferrance of valid type from full lexicon definition
124124+ - the really cool part of this is that it fills in the refs from the defs all at the type level
125125+126126+**TODO/In Progress:**
127127+128128+- Library art! Please reach out if you'd be willing to contribute some drawings or anything!
129129+- Runtime validation using [@atproto/lexicon](https://www.npmjs.com/package/@atproto/lexicon)
130130+ - this will be hard to get correct, I'm weary of loading all of the json in a project's lexicons into js memory and would like to run benchmarks and find the best way to get this right.
131131+- The CLI needs more real world use and mileage. I expect bugs and weird behavior in this initial release (sorry).
132132+133133+## Disclaimer:
134134+135135+I'm considering how to use the json for validation (there will likely be some lazy-loading). For the cli,
136136+files may need to adopt a convention so it's easy to determine what is an `lx.lexicon` and then generate out it's json and export it as a validator that lazy loads json to validate. (these are just ideas right now, but I want to share where we are now :)
137137+138138+Please give any and all feedback. I've not really written many lexicons much myself yet, so this project is at a point of "well I think this makes sense" 😂. Both the [issues page](https://github.com/tylersayshi/prototypey/issues) and [discussions](https://github.com/tylersayshi/prototypey/discussions) are open and ready for y'all 🙂.
139139+140140+---
141141+142142+> 💝 This package was templated with
143143+> [`create-typescript-app`](https://github.com/JoshuaKGoldberg/create-typescript-app)
144144+> using the [Bingo framework](https://create.bingo).