diff --git a/package.json b/package.json index bfc6723..e7161df 100644 --- a/package.json +++ b/package.json @@ -30,11 +30,11 @@ "license": "MIT", "dependencies": { "bluebird": "^3.7.2", - "cuid": "^2.1.8", "graceful-fs": "^4.2.10", "hexo-log": "^4.0.1", "is-plain-object": "^5.0.0", "jsonparse": "^1.3.1", + "nanoid": "^3.3.7", "rfdc": "^1.3.0", "through2": "^4.0.2" }, diff --git a/src/types/cuid.ts b/src/types/cuid.ts index 476cfa0..c361d04 100644 --- a/src/types/cuid.ts +++ b/src/types/cuid.ts @@ -1,9 +1,9 @@ import SchemaType from '../schematype'; -import cuid from 'cuid'; +import { nanoid } from 'nanoid'; import ValidationError from '../error/validation'; /** - * [CUID](https://github.com/ericelliott/cuid) schema type. + * [CUID](https://github.com/ai/nanoid) schema type. */ class SchemaTypeCUID extends SchemaType { @@ -16,7 +16,7 @@ class SchemaTypeCUID extends SchemaType { */ cast(value?: string): string { if (value == null && this.options.required) { - return cuid(); + return 'cuid' + nanoid(); } return value; diff --git a/test/scripts/model.ts b/test/scripts/model.ts index c5b2011..13d6e76 100644 --- a/test/scripts/model.ts +++ b/test/scripts/model.ts @@ -7,7 +7,7 @@ import lodash from 'lodash'; const { sortBy } = lodash; import Promise from 'bluebird'; import sinon from 'sinon'; -import cuid from 'cuid'; +import { nanoid } from 'nanoid'; import Database from '../../dist/database'; import type Query from '../../dist/query'; import type Document from '../../dist/document'; @@ -214,7 +214,7 @@ describe('Model', () => { }).then(data => User.removeById(data._id))); it('save() - sync problem', () => { - const id = cuid(); + const id = 'cuid' + nanoid(); return Promise.all([ User.save({_id: id, age: 1}), diff --git a/test/scripts/types/cuid.ts b/test/scripts/types/cuid.ts index 9023eb8..86a4aa9 100644 --- a/test/scripts/types/cuid.ts +++ b/test/scripts/types/cuid.ts @@ -1,5 +1,6 @@ import chai from 'chai'; const should = chai.should(); // eslint-disable-line +import { nanoid } from 'nanoid'; import ValidationError from '../../../dist/error/validation'; import SchemaTypeCUID from '../../../dist/types/cuid'; @@ -17,7 +18,8 @@ describe('SchemaTypeCUID', () => { }); it('validate()', () => { - type.validate('ch72gsb320000udocl363eofy').should.eql('ch72gsb320000udocl363eofy'); + const id = 'cuid' + nanoid(); + type.validate(id).should.eql(id); (() => type.validate('foo')).should.to.throw(ValidationError, '`foo` is not a valid CUID'); });