prototypey.org - atproto lexicon typescript toolkit - mirror https://github.com/tylersayshi/prototypey
TypeScript 98.3%
CSS 0.9%
JavaScript 0.5%
HTML 0.3%
Other 0.1%
155 1 14

Clone this repository

https://tangled.org/tylur.dev/prototypey
git@tangled.org:tylur.dev/prototypey

For self-hosted knots, clone URLs may differ based on your setup.

README.md

typed-lexicon#

WARNING

this project is in the middle of active initial development and not ready for use. there will be updates posted here if you'd like to follow along!

demo of jsdoc with typed-lexicon

this will be a toolkit for writing lexicon json schema's in typescript and providing types for lexicon data shape. it will:

  • remove boilerplate and improve ergonomics
  • type hint for atproto type parameters
  • infer the typescript type definitions for the data shape to avoid duplication and skew
  • methods and a cli for generating json

With each of the above finished, i'll plan to write a validate method that will be published alongside this that takes any lexicon json definition and validates payloads off that.

My working hypothesis: it will be easier to write lexicons in typescript with a single api, then validate based off the json definition, than it would be to start with validation library types (standard-schema style) and attempt to use those as the authoring and validation tools.

what you'd write:

const profileNamespace = lx.lexicon("app.bsky.actor.profile", {
	main: lx.record({
		key: "self",
		record: lx.object({
			displayName: lx.string({ maxLength: 64, maxGraphemes: 64 }),
			description: lx.string({ maxLength: 256, maxGraphemes: 256 }),
		}),
	}),
});

generates to:

{
	"lexicon": 1,
	"id": "app.bsky.actor.profile",
	"defs": {
		"main": {
			"type": "record",
			"key": "self",
			"record": {
				"type": "object",
				"properties": {
					"displayName": {
						"type": "string",
						"maxLength": 64,
						"maxGraphemes": 64
					},
					"description": {
						"type": "string",
						"maxLength": 256,
						"maxGraphemes": 256
					}
				}
			}
		}
	}
}

🤝 Code of Conduct: Kept 📝 License: MIT 💪 TypeScript: Strict

Usage#

tbd

Development#

See .github/CONTRIBUTING.md, then .github/DEVELOPMENT.md. Thanks! 💖

💝 This package was templated with create-typescript-app using the Bingo framework.