Skip to content
Merged
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 @@ -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"
},
Expand Down
6 changes: 3 additions & 3 deletions src/types/cuid.ts
Original file line number Diff line number Diff line change
@@ -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<string> {

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

return value;
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 { nanoid } from 'nanoid';
import Database from '../../dist/database';
import type Query from '../../dist/query';
import type Document from '../../dist/document';
Expand Down Expand Up @@ -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}),
Expand Down
4 changes: 3 additions & 1 deletion test/scripts/types/cuid.ts
Original file line number Diff line number Diff line change
@@ -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';

Expand All @@ -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');
});
Expand Down