prototypey.org - atproto lexicon typescript toolkit - mirror https://github.com/tylersayshi/prototypey

most tests passing and templates removed

Tyler 2a09b10c 6a799dd0

+91 -544
-131
.github/CODE_OF_CONDUCT.md
··· 1 - # Contributor Covenant Code of Conduct 2 - 3 - ## Our Pledge 4 - 5 - We as members, contributors, and leaders pledge to make participation in our 6 - community a harassment-free experience for everyone, regardless of age, body 7 - size, visible or invisible disability, ethnicity, sex characteristics, gender 8 - identity and expression, level of experience, education, socio-economic status, 9 - nationality, personal appearance, race, caste, color, religion, or sexual 10 - identity and orientation. 11 - 12 - We pledge to act and interact in ways that contribute to an open, welcoming, 13 - diverse, inclusive, and healthy community. 14 - 15 - ## Our Standards 16 - 17 - Examples of behavior that contributes to a positive environment for our 18 - community include: 19 - 20 - - Demonstrating empathy and kindness toward other people 21 - - Being respectful of differing opinions, viewpoints, and experiences 22 - - Giving and gracefully accepting constructive feedback 23 - - Accepting responsibility and apologizing to those affected by our mistakes, 24 - and learning from the experience 25 - - Focusing on what is best not just for us as individuals, but for the overall 26 - community 27 - 28 - Examples of unacceptable behavior include: 29 - 30 - - The use of sexualized language or imagery, and sexual attention or advances of 31 - any kind 32 - - Trolling, insulting or derogatory comments, and personal or political attacks 33 - - Public or private harassment 34 - - Publishing others' private information, such as a physical or email address, 35 - without their explicit permission 36 - - Other conduct which could reasonably be considered inappropriate in a 37 - professional setting 38 - 39 - ## Enforcement Responsibilities 40 - 41 - Community leaders are responsible for clarifying and enforcing our standards of 42 - acceptable behavior and will take appropriate and fair corrective action in 43 - response to any behavior that they deem inappropriate, threatening, offensive, 44 - or harmful. 45 - 46 - Community leaders have the right and responsibility to remove, edit, or reject 47 - comments, commits, code, wiki edits, issues, and other contributions that are 48 - not aligned to this Code of Conduct, and will communicate reasons for moderation 49 - decisions when appropriate. 50 - 51 - ## Scope 52 - 53 - This Code of Conduct applies within all community spaces, and also applies when 54 - an individual is officially representing the community in public spaces. 55 - Examples of representing our community include using an official e-mail address, 56 - posting via an official social media account, or acting as an appointed 57 - representative at an online or offline event. 58 - 59 - ## Enforcement 60 - 61 - Instances of abusive, harassing, or otherwise unacceptable behavior may be 62 - reported to the community leaders responsible for enforcement at hi@tylur.dev. 63 - All complaints will be reviewed and investigated promptly and fairly. 64 - 65 - All community leaders are obligated to respect the privacy and security of the 66 - reporter of any incident. 67 - 68 - ## Enforcement Guidelines 69 - 70 - Community leaders will follow these Community Impact Guidelines in determining 71 - the consequences for any action they deem in violation of this Code of Conduct: 72 - 73 - ### 1. Correction 74 - 75 - **Community Impact**: Use of inappropriate language or other behavior deemed 76 - unprofessional or unwelcome in the community. 77 - 78 - **Consequence**: A private, written warning from community leaders, providing 79 - clarity around the nature of the violation and an explanation of why the 80 - behavior was inappropriate. A public apology may be requested. 81 - 82 - ### 2. Warning 83 - 84 - **Community Impact**: A violation through a single incident or series of 85 - actions. 86 - 87 - **Consequence**: A warning with consequences for continued behavior. No 88 - interaction with the people involved, including unsolicited interaction with 89 - those enforcing the Code of Conduct, for a specified period of time. This 90 - includes avoiding interactions in community spaces as well as external channels 91 - like social media. Violating these terms may lead to a temporary or permanent 92 - ban. 93 - 94 - ### 3. Temporary Ban 95 - 96 - **Community Impact**: A serious violation of community standards, including 97 - sustained inappropriate behavior. 98 - 99 - **Consequence**: A temporary ban from any sort of interaction or public 100 - communication with the community for a specified period of time. No public or 101 - private interaction with the people involved, including unsolicited interaction 102 - with those enforcing the Code of Conduct, is allowed during this period. 103 - Violating these terms may lead to a permanent ban. 104 - 105 - ### 4. Permanent Ban 106 - 107 - **Community Impact**: Demonstrating a pattern of violation of community 108 - standards, including sustained inappropriate behavior, harassment of an 109 - individual, or aggression toward or disparagement of classes of individuals. 110 - 111 - **Consequence**: A permanent ban from any sort of public interaction within the 112 - community. 113 - 114 - ## Attribution 115 - 116 - This Code of Conduct is adapted from the [Contributor Covenant][homepage], 117 - version 2.1, available at 118 - [https://www.contributor-covenant.org/version/2/1/code_of_conduct.html][v2.1]. 119 - 120 - Community Impact Guidelines were inspired by 121 - [Mozilla's code of conduct enforcement ladder][mozilla coc]. 122 - 123 - For answers to common questions about this code of conduct, see the FAQ at 124 - [https://www.contributor-covenant.org/faq][faq]. Translations are available at 125 - [https://www.contributor-covenant.org/translations][translations]. 126 - 127 - [homepage]: https://www.contributor-covenant.org 128 - [v2.1]: https://www.contributor-covenant.org/version/2/1/code_of_conduct.html 129 - [mozilla coc]: https://github.com/mozilla/diversity 130 - [faq]: https://www.contributor-covenant.org/faq 131 - [translations]: https://www.contributor-covenant.org/translations
···
-97
.github/CONTRIBUTING.md
··· 1 - # Contributing 2 - 3 - Thanks for your interest in contributing to `prototypey`! 💖 4 - 5 - > After this page, see [DEVELOPMENT.md](./DEVELOPMENT.md) for local development instructions. 6 - 7 - ## Code of Conduct 8 - 9 - This project contains a [Contributor Covenant code of conduct](./CODE_OF_CONDUCT.md) all contributors are expected to follow. 10 - 11 - ## Reporting Issues 12 - 13 - Please do [report an issue on the issue tracker](https://github.com/tylersayshi/prototypey/issues/new/choose) if there's any bugfix, documentation improvement, or general enhancement you'd like to see in the repository! Please fully fill out all required fields in the most appropriate issue form. 14 - 15 - ## Sending Contributions 16 - 17 - Sending your own changes as contribution is always appreciated! 18 - There are two steps involved: 19 - 20 - 1. [Finding an Issue](#finding-an-issue) 21 - 2. [Sending a Pull Request](#sending-a-pull-request) 22 - 23 - ### Finding an Issue 24 - 25 - With the exception of very small typos, all changes to this repository generally need to correspond to an [unassigned open issue marked as `status: accepting prs` on the issue tracker](https://github.com/tylersayshi/prototypey/issues?q=is%3Aissue+is%3Aopen+label%3A%22status%3A+accepting+prs%22+no%3Aassignee+). 26 - If this is your first time contributing, consider searching for [unassigned issues that also have the `good first issue` label](https://github.com/tylersayshi/prototypey/issues?q=is%3Aissue+is%3Aopen+label%3A%22good+first+issue%22+label%3A%22status%3A+accepting+prs%22+no%3Aassignee+). 27 - If the issue you'd like to fix isn't found on the issue, see [Reporting Issues](#reporting-issues) for filing your own (please do!). 28 - 29 - #### Issue Claiming 30 - 31 - We don't use any kind of issue claiming system. 32 - We've found in the past that they result in accidental ["licked cookie"](https://devblogs.microsoft.com/oldnewthing/20091201-00/?p=15843) situations where contributors claim an issue but run out of time or energy trying before sending a PR. 33 - 34 - If an unassigned issue has been marked as `status: accepting prs` and an open PR does not exist, feel free to send a PR. 35 - Please don't post comments asking for permission or stating you will work on an issue. 36 - 37 - ### Sending a Pull Request 38 - 39 - Once you've identified an open issue accepting PRs that doesn't yet have a PR sent, you're free to send a pull request. 40 - Be sure to fill out the pull request template's requested information -- otherwise your PR will likely be closed. 41 - 42 - PRs are also expected to have a title that adheres to [conventional commits](https://www.conventionalcommits.org/en/v1.0.0). 43 - Only PR titles need to be in that format, not individual commits. 44 - Don't worry if you get this wrong: you can always change the PR title after sending it. 45 - Check [previously merged PRs](https://github.com/tylersayshi/prototypey/pulls?q=is%3Apr+is%3Amerged+-label%3Adependencies+) for reference. 46 - 47 - #### Draft PRs 48 - 49 - If you don't think your PR is ready for review, [set it as a draft](https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/proposing-changes-to-your-work-with-pull-requests/changing-the-stage-of-a-pull-request#converting-a-pull-request-to-a-draft). 50 - Draft PRs won't be reviewed. 51 - 52 - #### Granular PRs 53 - 54 - Please keep pull requests single-purpose: in other words, don't attempt to solve multiple unrelated problems in one pull request. 55 - Send one PR per area of concern. 56 - Multi-purpose pull requests are harder and slower to review, block all changes from being merged until the whole pull request is reviewed, and are difficult to name well with semantic PR titles. 57 - 58 - #### Pull Request Reviews 59 - 60 - When a PR is not in draft, it's considered ready for review. 61 - Please don't manually `@` tag anybody to request review. 62 - A maintainer will look at it when they're next able to. 63 - 64 - PRs should have passing [GitHub status checks](https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/collaborating-on-repositories-with-code-quality-features/about-status-checks) before review is requested (unless there are explicit questions asked in the PR about any failures). 65 - 66 - #### Asking Questions 67 - 68 - If you need help and/or have a question, posting a comment in the PR is a great way to do so. 69 - There's no need to tag anybody individually. 70 - One of us will drop by and help when we can. 71 - 72 - Please post comments as [line comments](https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/reviewing-changes-in-pull-requests/commenting-on-a-pull-request#adding-line-comments-to-a-pull-request) when possible, so that they can be threaded. 73 - You can [resolve conversations](https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/reviewing-changes-in-pull-requests/commenting-on-a-pull-request#resolving-conversations) on your own when you feel they're resolved - no need to comment explicitly and/or wait for a maintainer. 74 - 75 - #### Requested Changes 76 - 77 - After a maintainer reviews your PR, they may request changes on it. 78 - Once you've made those changes, [re-request review on GitHub](https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/reviewing-changes-in-pull-requests/about-pull-request-reviews#re-requesting-a-review). 79 - 80 - Please try not to force-push commits to PRs that have already been reviewed. 81 - Doing so makes it harder to review the changes. 82 - We squash merge all commits so there's no need to try to preserve Git history within a PR branch. 83 - 84 - Once you've addressed all our feedback by making code changes and/or started a followup discussion, [re-request review](https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/reviewing-changes-in-pull-requests/about-pull-request-reviews#re-requesting-a-review) from each maintainer whose feedback you addressed. 85 - 86 - Once all feedback is addressed and the PR is approved, we'll ensure the branch is up to date with `main` and merge it for you. 87 - 88 - #### Post-Merge Recognition 89 - 90 - Once your PR is merged, if you haven't yet been added to the [_Contributors_ table in the README.md](../README.md#contributors) for its [type of contribution](https://allcontributors.org/docs/en/emoji-key "Allcontributors emoji key"), you should be soon. 91 - Please do ping the maintainer who merged your PR if that doesn't happen within 24 hours - it was likely an oversight on our end! 92 - 93 - ## Emojis & Appreciation 94 - 95 - If you made it all the way to the end, bravo dear user, we love you. 96 - Please include an emoji in the bottom of your issues and PRs to signal to us that you did in fact read this file and are trying to conform to it as best as possible. 97 - 💖 is a good starter if you're not sure which to use.
···
-67
.github/DEVELOPMENT.md
··· 1 - # Development 2 - 3 - After [forking the repo from GitHub](https://help.github.com/articles/fork-a-repo) and [installing pnpm](https://pnpm.io/installation): 4 - 5 - ```shell 6 - git clone https://github.com/(your-name-here)/prototypey 7 - cd prototypey 8 - pnpm install 9 - ``` 10 - 11 - ## Building 12 - 13 - Run [**tsdown**](https://tsdown.dev) locally to build source files from `src/` into output files in `lib/`: 14 - 15 - ```shell 16 - pnpm build 17 - ``` 18 - 19 - Add `--watch` to run the builder in a watch mode that continuously cleans and recreates `lib/` as you save files: 20 - 21 - ```shell 22 - pnpm build --watch 23 - ``` 24 - 25 - ## Formatting 26 - 27 - [Prettier](https://prettier.io) is used to format code. 28 - It should be applied automatically when you save files in VS Code or make a Git commit. 29 - 30 - To manually reformat all files, you can run: 31 - 32 - ```shell 33 - pnpm format --write 34 - ``` 35 - 36 - ## Linting 37 - 38 - This package includes several forms of linting to enforce consistent code quality and styling. 39 - Each should be shown in VS Code, and can be run manually on the command-line: 40 - 41 - - `pnpm lint` ([ESLint](https://eslint.org) with [typescript-eslint](https://typescript-eslint.io)): Lints JavaScript and TypeScript source files 42 - 43 - Read the individual documentation for each linter to understand how it can be configured and used best. 44 - 45 - For example, ESLint can be run with `--fix` to auto-fix some lint rule complaints: 46 - 47 - ```shell 48 - pnpm run lint --fix 49 - ``` 50 - 51 - Note that you'll need to run `pnpm build` before `pnpm lint` so that lint rules which check the file system can pick up on any built files. 52 - 53 - ## Type Checking 54 - 55 - You should be able to see suggestions from [TypeScript](https://typescriptlang.org) in your editor for all open files. 56 - 57 - However, it can be useful to run the TypeScript command-line (`tsc`) to type check all files in `src/`: 58 - 59 - ```shell 60 - pnpm tsc 61 - ``` 62 - 63 - Add `--watch` to keep the type checker running in a watch mode that updates the display as you save files: 64 - 65 - ```shell 66 - pnpm tsc --watch 67 - ```
···
-9
.github/ISSUE_TEMPLATE.md
··· 1 - <!-- Note: Please must use one of our issue templates to file an issue! 🛑 --> 2 - <!-- 👉 https://github.com/tylersayshi/prototypey/issues/new/choose 👈 --> 3 - <!-- **Issues that should have been filed with a template will be closed without action, and we will ask you to use a template.** --> 4 - 5 - <!-- This blank issue template is only for issues that don't fit any of the templates. --> 6 - 7 - ## Overview 8 - 9 - ...
···
-37
.github/ISSUE_TEMPLATE/01-bug.yml
··· 1 - body: 2 - - attributes: 3 - description: If any of these required steps are not taken, we may not be able to review your issue. Help us to help you! 4 - label: Bug Report Checklist 5 - options: 6 - - label: I have tried restarting my IDE and the issue persists. 7 - required: true 8 - - label: I have pulled the latest `main` branch of the repository. 9 - required: true 10 - - label: I have [searched for related issues](https://github.com/tylersayshi/prototypey/issues?q=is%3Aissue) and found none that matched my issue. 11 - required: true 12 - type: checkboxes 13 - - attributes: 14 - description: What did you expect to happen? 15 - label: Expected 16 - type: textarea 17 - validations: 18 - required: true 19 - - attributes: 20 - description: What happened instead? 21 - label: Actual 22 - type: textarea 23 - validations: 24 - required: true 25 - - attributes: 26 - description: Any additional info you'd like to provide. 27 - label: Additional Info 28 - type: textarea 29 - 30 - description: Report a bug trying to run the code 31 - 32 - labels: 33 - - "type: bug" 34 - 35 - name: 🐛 Bug 36 - 37 - title: "🐛 Bug: <short description of the bug>"
···
-29
.github/ISSUE_TEMPLATE/02-documentation.yml
··· 1 - body: 2 - - attributes: 3 - description: If any of these required steps are not taken, we may not be able to review your issue. Help us to help you! 4 - label: Documentation Report Checklist 5 - options: 6 - - label: I have pulled the latest `main` branch of the repository. 7 - required: true 8 - - label: I have [searched for related issues](https://github.com/tylersayshi/prototypey/issues?q=is%3Aissue) and found none that matched my issue. 9 - required: true 10 - type: checkboxes 11 - - attributes: 12 - description: What would you like to report? 13 - label: Overview 14 - type: textarea 15 - validations: 16 - required: true 17 - - attributes: 18 - description: Any additional info you'd like to provide. 19 - label: Additional Info 20 - type: textarea 21 - 22 - description: Report a typo or missing area of documentation 23 - 24 - labels: 25 - - "area: documentation" 26 - 27 - name: 📝 Documentation 28 - 29 - title: "📝 Documentation: <short description of the request>"
···
-29
.github/ISSUE_TEMPLATE/03-feature.yml
··· 1 - body: 2 - - attributes: 3 - description: If any of these required steps are not taken, we may not be able to review your issue. Help us to help you! 4 - label: Feature Request Checklist 5 - options: 6 - - label: I have pulled the latest `main` branch of the repository. 7 - required: true 8 - - label: I have [searched for related issues](https://github.com/tylersayshi/prototypey/issues?q=is%3Aissue) and found none that matched my issue. 9 - required: true 10 - type: checkboxes 11 - - attributes: 12 - description: What did you expect to be able to do? 13 - label: Overview 14 - type: textarea 15 - validations: 16 - required: true 17 - - attributes: 18 - description: Any additional info you'd like to provide. 19 - label: Additional Info 20 - type: textarea 21 - 22 - description: Request that a new feature be added or an existing feature improved 23 - 24 - labels: 25 - - "type: feature" 26 - 27 - name: 🚀 Feature 28 - 29 - title: "🚀 Feature: <short description of the feature>"
···
-31
.github/ISSUE_TEMPLATE/04-tooling.yml
··· 1 - body: 2 - - attributes: 3 - description: If any of these required steps are not taken, we may not be able to review your issue. Help us to help you! 4 - label: Tooling Report Checklist 5 - options: 6 - - label: I have tried restarting my IDE and the issue persists. 7 - required: true 8 - - label: I have pulled the latest `main` branch of the repository. 9 - required: true 10 - - label: I have [searched for related issues](https://github.com/tylersayshi/prototypey/issues?q=is%3Aissue) and found none that matched my issue. 11 - required: true 12 - type: checkboxes 13 - - attributes: 14 - description: What did you expect to be able to do? 15 - label: Overview 16 - type: textarea 17 - validations: 18 - required: true 19 - - attributes: 20 - description: Any additional info you'd like to provide. 21 - label: Additional Info 22 - type: textarea 23 - 24 - description: Report a bug or request an enhancement in repository tooling 25 - 26 - labels: 27 - - "area: tooling" 28 - 29 - name: 🛠 Tooling 30 - 31 - title: "🛠 Tooling: <short description of the change>"
···
-13
.github/PULL_REQUEST_TEMPLATE.md
··· 1 - <!-- 👋 Hi, thanks for sending a PR to prototypey! 💖 2 - Please fill out all fields below and make sure each item is true and [x] checked. 3 - Otherwise we may not be able to review your PR. --> 4 - 5 - ## PR Checklist 6 - 7 - - [ ] Addresses an existing open issue: fixes #000 8 - - [ ] That issue was marked as [`status: accepting prs`](https://github.com/tylersayshi/prototypey/issues?q=is%3Aopen+is%3Aissue+label%3A%22status%3A+accepting+prs%22) 9 - - [ ] Steps in [CONTRIBUTING.md](https://github.com/tylersayshi/prototypey/blob/main/.github/CONTRIBUTING.md) were taken 10 - 11 - ## Overview 12 - 13 - <!-- Description of what is changed and how the code change does that. -->
···
-9
.github/SECURITY.md
··· 1 - # Security Policy 2 - 3 - We take all security vulnerabilities seriously. 4 - If you have a vulnerability or other security issues to disclose: 5 - 6 - - Thank you very much, please do! 7 - - Please send them to us by emailing `hi@tylur.dev` 8 - 9 - We appreciate your efforts and responsible disclosure and will make every effort to acknowledge your contributions.
···
+15 -3
src/lib.ts
··· 1 // deno-lint-ignore-file ban-types 2 /** @see https://atproto.com/specs/lexicon#overview-of-types */ 3 type LexiconType = 4 // Concrete types ··· 304 errors?: ErrorDef[]; 305 } 306 307 /** 308 * Main API for creating lexicon schemas. 309 * @see https://atproto.com/specs/lexicon ··· 541 namespace<ID extends string, D extends LexiconNamespace["defs"]>( 542 id: ID, 543 defs: D, 544 - ): { lexicon: 1; id: ID; defs: D } { 545 - return { 546 lexicon: 1, 547 id, 548 defs, 549 - }; 550 }, 551 };
··· 1 // deno-lint-ignore-file ban-types 2 + 3 + import { InferNS } from "./infer.ts"; 4 + 5 /** @see https://atproto.com/specs/lexicon#overview-of-types */ 6 type LexiconType = 7 // Concrete types ··· 307 errors?: ErrorDef[]; 308 } 309 310 + class Namespace<T extends LexiconNamespace> { 311 + public json: T; 312 + public infer: InferNS<T> = null as unknown as InferNS<T>; 313 + 314 + constructor(json: T) { 315 + this.json = json; 316 + } 317 + } 318 + 319 /** 320 * Main API for creating lexicon schemas. 321 * @see https://atproto.com/specs/lexicon ··· 553 namespace<ID extends string, D extends LexiconNamespace["defs"]>( 554 id: ID, 555 defs: D, 556 + ): Namespace<{ lexicon: 1; id: ID; defs: D }> { 557 + return new Namespace({ 558 lexicon: 1, 559 id, 560 defs, 561 + }); 562 }, 563 };
+2 -2
src/tests/base-case.test.ts tests/base-case.test.ts
··· 1 import { expect, test } from "vitest"; 2 - import { lx } from "../lib.ts"; 3 4 test("app.bsky.actor.profile", () => { 5 const profileNamespace = lx.namespace("app.bsky.actor.profile", { ··· 12 }), 13 }); 14 15 - expect(profileNamespace).toEqual({ 16 lexicon: 1, 17 id: "app.bsky.actor.profile", 18 defs: {
··· 1 import { expect, test } from "vitest"; 2 + import { lx } from "../src/lib.ts"; 3 4 test("app.bsky.actor.profile", () => { 5 const profileNamespace = lx.namespace("app.bsky.actor.profile", { ··· 12 }), 13 }); 14 15 + expect(profileNamespace.json).toEqual({ 16 lexicon: 1, 17 id: "app.bsky.actor.profile", 18 defs: {
+5 -5
src/tests/bsky-actor.test.ts tests/bsky-actor.test.ts
··· 1 import { expect, test } from "vitest"; 2 - import { lx } from "../lib.ts"; 3 4 test("app.bsky.actor.defs - profileViewBasic", () => { 5 const profileViewBasic = lx.object({ ··· 860 }), 861 }); 862 863 - expect(actorDefs.lexicon).toEqual(1); 864 - expect(actorDefs.id).toEqual("app.bsky.actor.defs"); 865 - expect(actorDefs.defs.profileViewBasic.type).toEqual("object"); 866 - expect(actorDefs.defs.viewerState.type).toEqual("object"); 867 });
··· 1 import { expect, test } from "vitest"; 2 + import { lx } from "../src/lib.ts"; 3 4 test("app.bsky.actor.defs - profileViewBasic", () => { 5 const profileViewBasic = lx.object({ ··· 860 }), 861 }); 862 863 + expect(actorDefs.json.lexicon).toEqual(1); 864 + expect(actorDefs.json.id).toEqual("app.bsky.actor.defs"); 865 + expect(actorDefs.json.defs.profileViewBasic.type).toEqual("object"); 866 + expect(actorDefs.json.defs.viewerState.type).toEqual("object"); 867 });
+7 -7
src/tests/bsky-feed.test.ts tests/bsky-feed.test.ts
··· 1 import { expect, test } from "vitest"; 2 - import { lx } from "../lib.ts"; 3 4 test("app.bsky.feed.defs - postView", () => { 5 const postView = lx.object({ ··· 672 interactionShare: lx.token("User shared the feed item"), 673 }); 674 675 - expect(feedDefs.lexicon).toEqual(1); 676 - expect(feedDefs.id).toEqual("app.bsky.feed.defs"); 677 - expect(feedDefs.defs.postView.type).toEqual("object"); 678 - expect(feedDefs.defs.viewerState.type).toEqual("object"); 679 - expect(feedDefs.defs.requestLess.type).toEqual("token"); 680 - expect(feedDefs.defs.contentModeVideo.type).toEqual("token"); 681 });
··· 1 import { expect, test } from "vitest"; 2 + import { lx } from "../src/lib.ts"; 3 4 test("app.bsky.feed.defs - postView", () => { 5 const postView = lx.object({ ··· 672 interactionShare: lx.token("User shared the feed item"), 673 }); 674 675 + expect(feedDefs.json.lexicon).toEqual(1); 676 + expect(feedDefs.json.id).toEqual("app.bsky.feed.defs"); 677 + expect(feedDefs.json.defs.postView.type).toEqual("object"); 678 + expect(feedDefs.json.defs.viewerState.type).toEqual("object"); 679 + expect(feedDefs.json.defs.requestLess.type).toEqual("token"); 680 + expect(feedDefs.json.defs.contentModeVideo.type).toEqual("token"); 681 });
+4 -4
src/tests/infer.bench.ts tests/infer.bench.ts
··· 1 import { bench } from "@ark/attest"; 2 - import type { InferNS } from "../infer.ts"; 3 - import { lx } from "../lib.ts"; 4 5 bench("InferNS with simple object", () => { 6 const schema = lx.namespace("test.simple", { ··· 10 }), 11 }); 12 13 - return null as unknown as InferNS<typeof schema>; 14 }).types([63, "instantiations"]); 15 16 bench("InferNS with complex nested structure", () => { ··· 34 }), 35 }); 36 37 - return null as unknown as InferNS<typeof schema>; 38 }).types([125, "instantiations"]);
··· 1 import { bench } from "@ark/attest"; 2 + import type { InferNS } from "../src/infer.ts"; 3 + import { lx } from "../src/lib.ts"; 4 5 bench("InferNS with simple object", () => { 6 const schema = lx.namespace("test.simple", { ··· 10 }), 11 }); 12 13 + return schema.infer; 14 }).types([63, "instantiations"]); 15 16 bench("InferNS with complex nested structure", () => { ··· 34 }), 35 }); 36 37 + return schema.infer; 38 }).types([125, "instantiations"]);
-69
src/tests/infer.test.ts
··· 1 - import { test } from "vitest"; 2 - import { attest } from "@ark/attest"; 3 - import type { InferNS } from "../infer.ts"; 4 - import { lx } from "../lib.ts"; 5 - 6 - test("InferNS produces expected type shape", () => { 7 - const exampleLexicon = lx.namespace("com.example.post", { 8 - main: lx.record({ 9 - key: "tid", 10 - record: lx.object({ 11 - text: lx.string({ required: true }), 12 - createdAt: lx.string({ required: true, format: "datetime" }), 13 - likes: lx.integer(), 14 - tags: lx.array(lx.string(), { maxLength: 5 }), 15 - }), 16 - }), 17 - }); 18 - 19 - type Result = InferNS<typeof exampleLexicon>; 20 - 21 - // Type snapshot - this captures how types appear on hover 22 - const result = {} as Result; 23 - attest(result).type.toString.snap(`{ 24 - main: { 25 - createdAt?: string | undefined 26 - tags?: string[] | undefined 27 - text?: string | undefined 28 - likes?: number | undefined 29 - } 30 - }`); 31 - }); 32 - 33 - test("InferObject handles required fields", () => { 34 - const schema = lx.object({ 35 - required: lx.string({ required: true }), 36 - optional: lx.string(), 37 - }); 38 - 39 - type Result = InferNS<{ 40 - lexicon: 1; 41 - id: "test"; 42 - defs: { main: typeof schema }; 43 - }>; 44 - 45 - const result = {} as Result; 46 - attest(result).type.toString.snap(`{ 47 - main: { 48 - required?: string | undefined 49 - optional?: string | undefined 50 - } 51 - }`); 52 - }); 53 - 54 - test("InferObject handles nullable fields", () => { 55 - const schema = lx.object({ 56 - nullable: lx.string({ nullable: true, required: true }), 57 - }); 58 - 59 - type Result = InferNS<{ 60 - lexicon: 1; 61 - id: "test"; 62 - defs: { main: typeof schema }; 63 - }>; 64 - 65 - const result = {} as Result; 66 - attest(result).type.toString.snap( 67 - "{ main: { nullable?: string | undefined } }", 68 - ); 69 - });
···
+1 -1
src/tests/primitives.test.ts tests/primitives.test.ts
··· 1 import { expect, test } from "vitest"; 2 - import { lx } from "../lib.ts"; 3 4 test("lx.null()", () => { 5 const result = lx.null();
··· 1 import { expect, test } from "vitest"; 2 + import { lx } from "../src/lib.ts"; 3 4 test("lx.null()", () => { 5 const result = lx.null();
+56
tests/infer.test.ts
···
··· 1 + import { test } from "vitest"; 2 + import { attest } from "@ark/attest"; 3 + import type { InferNS } from "../src/infer.ts"; 4 + import { lx } from "../src/lib.ts"; 5 + 6 + test("InferNS produces expected type shape", () => { 7 + const exampleLexicon = lx.namespace("com.example.post", { 8 + main: lx.record({ 9 + key: "tid", 10 + record: lx.object({ 11 + text: lx.string({ required: true }), 12 + createdAt: lx.string({ required: true, format: "datetime" }), 13 + likes: lx.integer(), 14 + tags: lx.array(lx.string(), { maxLength: 5 }), 15 + }), 16 + }), 17 + }); 18 + 19 + // Type snapshot - this captures how types appear on hover 20 + attest(exampleLexicon.infer).type.toString.snap(`{ 21 + main: { 22 + createdAt?: string | undefined 23 + tags?: string[] | undefined 24 + text?: string | undefined 25 + likes?: number | undefined 26 + } 27 + }`); 28 + }); 29 + 30 + test("InferObject handles required fields", () => { 31 + const schema = lx.namespace("test", { 32 + main: lx.object({ 33 + required: lx.string({ required: true }), 34 + optional: lx.string(), 35 + }), 36 + }); 37 + 38 + attest(schema.infer).type.toString.snap(`{ 39 + main: { 40 + required?: string | undefined 41 + optional?: string | undefined 42 + } 43 + }`); 44 + }); 45 + 46 + test("InferObject handles nullable fields", () => { 47 + const schema = lx.namespace("test", { 48 + main: lx.object({ 49 + nullable: lx.string({ nullable: true, required: true }), 50 + }), 51 + }); 52 + 53 + attest(schema.infer).type.toString.snap( 54 + "{ main: { nullable?: string | undefined } }", 55 + ); 56 + });
+1 -1
vitest.config.ts
··· 2 3 export default defineConfig({ 4 test: { 5 - include: ["src/**/*.test.ts"], 6 globalSetup: ["setup-vitest.ts"], 7 }, 8 });
··· 2 3 export default defineConfig({ 4 test: { 5 + include: ["tests/*.test.ts"], 6 globalSetup: ["setup-vitest.ts"], 7 }, 8 });