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

chore(deps): use cuid2 instead of cuid #147

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 <[email protected]> (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