Skip to content

Conversation

cmwhited
Copy link
Collaborator

@cmwhited cmwhited commented Nov 7, 2024

Description

Implement the generateId function, that can run in any JS env(Browser, NodeJS server, ReactNative), to:

  • generate a v4 UUID
  • strip the dashes, reducing it to a 32bit string
  • encode the value to base58 of 22char length

Also:

  • created a decodeBase58ToUUID method that takes the base58 encoded UUID and expands it back to its original UUID

Notes

@nikgraf I added some package management with vite to:

  • build a dist folder with: es files, cjs files and typings
  • updated the package.json to export these
  • added a tsconfig.build.json that excludes any .spec.ts or .test.ts files

This may be overkill, so let me know if you think we shouldn't/don't need to go down this path.

resolves #10

@cmwhited
Copy link
Collaborator Author

cmwhited commented Nov 7, 2024

@nikgraf I see it broke ci/cd (and makes sense with my changes). So if you agree to the approach, I will get ci/cd working.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Only if we think moving to this build pattern is a good call; otherwise, will revert

Copy link
Collaborator

Choose a reason for hiding this comment

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

no objection

usually I keep them in parallel so it's easier to see what fails and also to parallelize things, but currently everything fast enough to do this

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yeah had same thought. Parallelizing has the advantage of being able to rerun specific jobs, etc. But felt like we were constantly reinstalling deps, etc. and this let me run build beforehand.

const uuid = uuidv4();
const stripped = uuid.replaceAll(/-/g, "");
const encoded = encodeBase58(stripped);
return encoded.padStart(22, "1");
Copy link
Collaborator

Choose a reason for hiding this comment

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

hmm, do we need it? If the string is shorter we don't need to extend it afaik

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Good point. Will remove

@nikgraf
Copy link
Collaborator

nikgraf commented Nov 7, 2024

very nice PR @cmwhited

tsconfig.build.json is fine for me 👍

feel free to merge once CI/CD is fixed

@nikgraf nikgraf self-requested a review November 7, 2024 21:05
@cmwhited cmwhited merged commit a5f6bac into main Nov 7, 2024
1 check passed
@cmwhited cmwhited deleted the chris.whited/feat-generateId branch November 7, 2024 21:35
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.

implement generateId

2 participants