deepkit-framework
deepkit-framework copied to clipboard
Support for CUID and NanoId
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.
I think string would be enough, no?
class User {
cuid: string & PrimaryKey = cuid();
}
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
);
True, no validation happens. When we add a new type like CUID
we can add validation logic like so
https://github.com/deepkit/deepkit-framework/blob/master/packages/type/src/serializer.ts#L1865-L1871
and
https://github.com/deepkit/deepkit-framework/blob/master/packages/type/src/serializer.ts#L2050-L2054