Skip to content

Commit

Permalink
chore(deps): use cuid2 instead of cuid
Browse files Browse the repository at this point in the history
  • Loading branch information
yoshinorin committed Feb 28, 2023
1 parent bc313ce commit d55c08d
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 8 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@
"author": "Tommy Chen <tommy351@gmail.com> (https://zespia.tw)",
"license": "MIT",
"dependencies": {
"@paralleldrive/cuid2": "^2.0.1",
"bluebird": "^3.7.2",
"cuid": "^2.1.8",
"graceful-fs": "^4.2.10",
"hexo-log": "^4.0.1",
"is-plain-object": "^5.0.0",
Expand Down
8 changes: 4 additions & 4 deletions src/types/cuid.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import SchemaType from '../schematype';
import cuid from 'cuid';
import { createId, getConstants } from '@paralleldrive/cuid2';
import ValidationError from '../error/validation';

/**
Expand All @@ -16,20 +16,20 @@ class SchemaTypeCUID extends SchemaType<string> {
*/
cast(value?) {
if (value == null && this.options.required) {
return cuid();
return createId();
}

return value;
}

/**
* Validates data. A valid CUID must be started with `c` and 25 in length.
* Validates data. A valid CUID must be 24 in length.
*
* @param {*} value
* @return {String|Error}
*/
validate(value?) {
if (value && (value[0] !== 'c' || value.length !== 25)) {
if (value && (value.length !== getConstants().defaultLength)) {
throw new ValidationError(`\`${value}\` is not a valid CUID`);
}

Expand Down
4 changes: 2 additions & 2 deletions test/scripts/model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import lodash from 'lodash';
const { sortBy } = lodash;
import Promise from 'bluebird';
import sinon from 'sinon';
import cuid from 'cuid';
import { createId } from '@paralleldrive/cuid2';
import Database from '../../dist/database';

describe('Model', () => {
Expand Down Expand Up @@ -193,7 +193,7 @@ describe('Model', () => {
}).then(data => User.removeById(data._id)));

it('save() - sync problem', () => {
const id = cuid();
const id = createId();

return Promise.all([
User.save({_id: id, age: 1}),
Expand Down
2 changes: 1 addition & 1 deletion test/scripts/types/cuid.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ describe('SchemaTypeCUID', () => {
});

it('validate()', () => {
type.validate('ch72gsb320000udocl363eofy').should.eql('ch72gsb320000udocl363eofy');
type.validate('ch72gsb320000udocl363eof').should.eql('ch72gsb320000udocl363eof');

(() => type.validate('foo')).should.to.throw(ValidationError, '`foo` is not a valid CUID');
});
Expand Down

0 comments on commit d55c08d

Please sign in to comment.