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 nanoid instead of cuid #244

Merged
merged 2 commits into from
Apr 18, 2024
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 @@
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 @@ -68,7 +68,7 @@
age: 20
});

user._id!.should.exist;

Check warning on line 71 in test/scripts/model.ts

View workflow job for this annotation

GitHub Actions / linter

Forbidden non-null assertion
user.name.first.should.eql('John');
user.name.last.should.eql('Doe');
user.name.full.should.eql('John Doe');
Expand Down Expand Up @@ -214,7 +214,7 @@
}).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 Expand Up @@ -688,7 +688,7 @@
{age: 30},
{age: 40}
]).then(data => {
(User.findOne({age: {$gt: 20}}, {lean: true}) as Document<UserType>)._id!.should.eql(data[2]._id);

Check warning on line 691 in test/scripts/model.ts

View workflow job for this annotation

GitHub Actions / linter

Forbidden non-null assertion
return data;
}).map<unknown, any>(item => User.removeById(item._id)));

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
Loading