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

Support for CUID and NanoId #419

Open
therosbif opened this issue Mar 7, 2023 · 3 comments
Open

Support for CUID and NanoId #419

therosbif opened this issue Mar 7, 2023 · 3 comments
Labels
enhancement New feature or request

Comments

@therosbif
Copy link

therosbif commented Mar 7, 2023

Could support for CUIDs and NanoIds be added?
Can be used in the same way as uuid:

import { cuid, CUID, NanoId, nanoId, PrimaryKey } from '@deepkit/type';

class User {
    cuid: CUID & PrimaryKey = cuid();
	// Or the following
	// nanoId: NanoID & PrimaryKey = nanoId();
}

This would be nice to have to shorten ids.

@marcj
Copy link
Member

marcj commented Mar 7, 2023

I think string would be enough, no?

class User {
    cuid: string & PrimaryKey = cuid();
}

@therosbif
Copy link
Author

therosbif commented Mar 7, 2023

I guess so, it wouldn't be able to validate the field though would it?

The @paralleldrive/cuid2 package exposes an isCuid function so it should be trivial to add validation if I'm not mistaken?

import { createId, isCuid } from '@paralleldrive/cuid2';

console.log(
  isCuid(createId()), // true
  isCuid('not a cuid'), // false
);

@marcj
Copy link
Member

marcj commented Mar 7, 2023

@marcj marcj added the enhancement New feature or request label Mar 7, 2023
@therosbif therosbif mentioned this issue Mar 8, 2023
1 task
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants