Big News: Socket raises $60M Series C at a $1B valuation to secure software supply chains for AI-driven development.Announcement
Sign In

@yued/typegoose

Package Overview
Dependencies
Maintainers
4
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@yued/typegoose - npm Package Compare versions

Comparing version
5.4.4
to
5.5.2
+5
.vscode/settings.json
{
"editor.formatOnSave": true,
"prettier.printWidth": 120,
"editor.wordWrapColumn": 120
}
+17
-15
{
"name": "@yued/typegoose",
"version": "5.4.4",
"version": "5.5.2",
"description": "Define Mongoose models using TypeScript classes.",

@@ -14,6 +14,5 @@ "main": "lib/typegoose.js",

"lint": "tslint --project tsconfig.json",
"test": "npm run lint && npm run cover",
"test": "npm run lint && nyc npm run mocha",
"mocha": "npm run build && mocha ./lib --recursive --exit",
"cover": "npm run build && istanbul cover _mocha -- lib --recursive --exit -R spec",
"coveralls": "cat ./coverage/lcov.info | coveralls"
"coverage": "nyc report --reporter=text-lcov | coveralls"
},

@@ -28,8 +27,4 @@ "repository": {

"license": "MIT",
"dependencies": {
"lodash": "4.17.10"
},
"peerDependencies": {
"mongoose": "^5.0.0",
"reflect-metadata": "^0.1.12"
"mongoose": "^5.4.15"
},

@@ -39,3 +34,2 @@ "devDependencies": {

"@types/dotenv": "4.0.3",
"@types/lodash": "4.14.108",
"@types/mocha": "5.2.0",

@@ -45,11 +39,19 @@ "@types/mongoose": "5.0.10",

"chai": "4.1.2",
"coveralls": "^3.0.1",
"coveralls": "^3.0.3",
"dotenv": "5.0.1",
"istanbul": "0.4.5",
"mocha": "^5.2.0",
"mocha": "5.2.0",
"mocha-lcov-reporter": "^1.3.0",
"mongoose": "^5.4.15",
"mongoose-findorcreate": "3.0.0",
"nyc": "13.3.0",
"prettier": "1.16.4",
"prettier-tslint": "0.4.2",
"rimraf": "2.6.2",
"tslint": "5.9.1",
"typescript": "^2.9.2"
"tslint": "5.13.0",
"tslint-config-prettier": "1.18.0",
"typescript": "2.9.2"
},
"dependencies": {
"reflect-metadata": "^0.1.13"
}
}
+110
-95

@@ -104,3 +104,3 @@ # Typegoose

```
Please note that sub documents doesn't have to extend Typegoose. You can still give them default value in `prop` decorator, but you can't create static or instance methods on them.
Please note that sub documents do not have to extend Typegoose. You can still give them default value in `prop` decorator, but you can't create static or instance methods on them.

@@ -162,87 +162,102 @@ ## Requirements

```typescript
// this is now required in the schema
@prop({ required: true })
firstName: string;
```typescript
// this is now required in the schema
@prop({ required: true })
firstName: string;
// by default, a property is not required
@prop()
lastName?: string; // using the ? optional property
```
// by default, a property is not required
@prop()
lastName?: string; // using the ? optional property
```
- `index`: Tells Mongoose whether to define an index for the property.
```typescript
@prop({ index: true })
indexedField?: string;
```
```typescript
@prop({ index: true })
indexedField?: string;
```
- `unique`: Just like the [Mongoose unique](http://mongoosejs.com/docs/api.html#schematype_SchemaType-unique), tells Mongoose to ensure a unique index is created for this path.
```typescript
// this field is now unique across the collection
@prop({ unique: true })
uniqueId?: string;
```
```typescript
// this field is now unique across the collection
@prop({ unique: true })
uniqueId?: string;
```
```typescript
// this field is now unique across the collection
@prop({ unique: true })
uniqueId?: string;
```
- `enum`: The enum option accepts a string array. The class property which gets this decorator should have an enum-like type which values are from the provided string array. The way how the enum is created is delegated to the developer, Typegoose needs a string array which hold the enum values, and a TypeScript type which tells the possible values of the enum.
However, if you use TS 2.4+, you can use string enum as well.
```typescript
// Enum-like type and definition example.
type Gender = 'male' | 'female';
const Genders = {
MALE: 'male' as Gender,
FEMALE: 'female' as Gender,
};
```typescript
// Enum-like type and definition example.
type Gender = 'male' | 'female';
const Genders = {
MALE: 'male' as Gender,
FEMALE: 'female' as Gender,
};
@prop({ enum: Object.values(Genders) })
gender?: Gender;
@prop({ enum: Object.values(Genders) })
gender?: Gender;
// TS 2.4+ string enum example
enum Gender {
MALE = 'male',
FEMALE = 'female',
}
// TS 2.4+ string enum example
enum Gender {
MALE = 'male',
FEMALE = 'female',
}
@prop({ enum: Gender })
gender?: Gender;
```
@prop({ enum: Gender })
gender?: Gender;
```
- `default`: The provided value will be the default for that Mongoose property.
- `lowercase`: for strings only; whether to always call .toLowerCase() on the value.
```typescript
@prop({ default: 'Nick' })
@prop({ lowercase: true })
nickName?: string;
```
- `ref`: By adding the `ref` option with another Typegoose class as value, a Mongoose reference property will be created. The type of the property on the Typegoose extending class should be `Ref<T>` (see Types section).
- `uppercase`: for strings only; whether to always call .toUpperCase() on the value.
```typescript
class Car extends Typegoose {}
@prop({ ref: Car })
car?: Ref<Car>;
@prop({ uppercase: true })
nickName?: string;
```
- `min` / `max` (numeric validators): Same as [Mongoose numberic validators](http://mongoosejs.com/docs/api.html#schema_number_SchemaNumber-max).
- `trim`: for strings only; whether to always call .trim() on the value.
```typescript
@prop({ min: 10, max: 21 })
age?: number;
@prop({ trim: true })
nickName?: string;
```
- `default`: The provided value will be the default for that Mongoose property.
```typescript
@prop({ default: 'Nick' })
nickName?: string;
```
- `ref`: By adding the `ref` option with another Typegoose class as value, a Mongoose reference property will be created. The type of the property on the Typegoose extending class should be `Ref<T>` (see Types section).
```typescript
class Car extends Typegoose {}
@prop({ ref: Car })
car?: Ref<Car>;
```
- `min` / `max` (numeric validators): Same as [Mongoose numberic validators](http://mongoosejs.com/docs/api.html#schema_number_SchemaNumber-max).
```typescript
@prop({ min: 10, max: 21 })
age?: number;
```
- `minlength` / `maxlength` / `match` (string validators): Same as [Mongoose string validators](http://mongoosejs.com/docs/api.html#schema_string_SchemaString-match).
```typescript
@prop({ minlength: 5, maxlength: 10, match: /[0-9a-f]*/ })
favouriteHexNumber: string;
```
```typescript
@prop({ minlength: 5, maxlength: 10, match: /[0-9a-f]*/ })
favouriteHexNumber: string;
```

@@ -252,42 +267,42 @@

```typescript
// you have to get your own `isEmail` function, this is a placeholder
```typescript
// you have to get your own `isEmail` function, this is a placeholder
@prop({ validate: (value) => isEmail(value)})
email?: string;
@prop({ validate: (value) => isEmail(value)})
email?: string;
// or
// or
@prop({ validate: (value) => { return new Promise(res => { res(isEmail(value)) }) })
email?: string;
@prop({ validate: (value) => { return new Promise(res => { res(isEmail(value)) }) })
email?: string;
// or
// or
@prop({ validate: {
validator: val => isEmail(val),
message: `{VALUE} is not a valid email`
}})
email?: string;
@prop({ validate: {
validator: val => isEmail(val),
message: `{VALUE} is not a valid email`
}})
email?: string;
// or
// or
@prop({ validate: /\S+@\S+\.\S+/ })
email?: string;
@prop({ validate: /\S+@\S+\.\S+/ })
email?: string;
// you can also use multiple validators in an array.
// you can also use multiple validators in an array.
@prop({ validate:
[
{
validator: val => isEmail(val),
message: `{VALUE} is not a valid email`
},
{
validator: val => isBlacklisted(val),
message: `{VALUE} is blacklisted`
}
]
})
email?: string;
```
@prop({ validate:
[
{
validator: val => isEmail(val),
message: `{VALUE} is not a valid email`
},
{
validator: val => isBlacklisted(val),
message: `{VALUE} is blacklisted`
}
]
})
email?: string;
```

@@ -322,6 +337,6 @@ Mongoose gives developers the option to create [virtual properties](http://mongoosejs.com/docs/api.html#schema_Schema-virtual). This means that actual database read/write will not occur these are just 'calculated properties'. A virtual property can have a setter and a getter. TypeScript also has a similar feature which Typegoose uses for virtual property definitions (using the `prop` decorator).

```typescript
@arrayProp({ items: String })
languages?: string[];
```
```typescript
@arrayProp({ items: String })
languages?: string[];
```

@@ -332,8 +347,8 @@ Note that unfortunately the [reflect-metadata](https://github.com/rbuckton/reflect-metadata) API does not let us determine the type of the array, it only returns `Array` when the type of the property is queried. This is why redundancy is required here.

```typescript
class Car extends Typegoose {}
```typescript
class Car extends Typegoose {}
@arrayProp({ itemsRef: Car })
previousCars?: Ref<Car>[];
```
@arrayProp({ itemsRef: Car })
previousCars?: Ref<Car>[];
```

@@ -340,0 +355,0 @@ ### Method decorators