Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve codegen bundle size and typings #2999

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

matthieusieben
Copy link
Contributor

@matthieusieben matthieusieben commented Nov 14, 2024

This PR is the first of a 3 step changes aimed at improving typing in the atproto repo:

Note

When reviewing, "codegen" commits can be ignored as they only contain generated code changes.

@matthieusieben matthieusieben force-pushed the msi/lex-gen-optimization branch 2 times, most recently from 9ed3816 to 5400766 Compare November 14, 2024 13:48
@matthieusieben matthieusieben changed the title Improve codegen bundle size Improve codegen bundle size and typings Nov 14, 2024
@matthieusieben matthieusieben force-pushed the msi/lex-gen-optimization branch 2 times, most recently from bebca0e to 0bea135 Compare November 14, 2024 16:05
cd packages/pds; pnpm run codegen
cd packages/bsky; pnpm run codegen
cd packages/ozone; pnpm run codegen
pnpm run --parallel codegen
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For consistency, we could do this more similarly to how we do the build task. That is, do a pnpm codegen here on the makefile, and "codegen": "pnpm run --parallel codegen", in package.json.

@@ -1,24 +1,18 @@
const TID_LENGTH = 13
const TID_REGEX = /^[234567abcdefghij][234567abcdefghijklmnopqrstuvwxyz]{12}$/

export const ensureValidTid = (tid: string): void => {
if (tid.length !== 13) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Forgot to use the constant here.

export function isObj(obj: unknown): obj is Record<string, unknown> {
return obj !== null && typeof obj === 'object'
export function isObj<V>(v: V): v is V & object {
return v != null && typeof v === 'object'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I found it a bit weird that we would want to use != instead of !==. In this case, it doesn't seem to make a difference. Just mentioning in case you did it by accident. Could probably be !!v as well, so it is less ambiguous.

BTW, are we fine with isObj returning true for arrays? I'm just wondering if that's the behavior we expect in this project from isObj, despite arrays being objects at the language level.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants