ts-mongoose
Advanced tools
Comparing version 0.0.16 to 0.0.17
{ | ||
"name": "ts-mongoose", | ||
"version": "0.0.16", | ||
"version": "0.0.17", | ||
"description": "", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -34,3 +34,3 @@ # ts-mongoose | ||
zip: String, | ||
}); | ||
}, { _id: false, timestamps: true }); | ||
@@ -62,2 +62,7 @@ const PhoneSchema = new Schema({ | ||
}, | ||
gender: { | ||
type: Schema.Types.String, | ||
required: true, | ||
enum: ['male', 'female'] | ||
}, | ||
otherId: { | ||
@@ -75,3 +80,3 @@ type: Schema.Types.ObjectId, | ||
}, | ||
}); | ||
}, { timestamps: { createdAt: true } }); | ||
@@ -94,2 +99,4 @@ interface UserProps extends Document { | ||
const genders = ['male', 'female'] as const; | ||
const AddressSchema = createSchema({ | ||
@@ -99,3 +106,3 @@ city: Type.string(), | ||
zip: Type.optionalString(), | ||
}, { _id: false }); | ||
}, { _id: false, timestamps: true }); | ||
@@ -122,6 +129,7 @@ const PhoneSchema = createSchema({ | ||
m: Type.mixed(), | ||
gender: Type.string({ enum: genders }), | ||
otherId: Type.objectId(), | ||
address: Type.schema().of(AddressSchema), | ||
phones: Type.array().of(PhoneSchema), | ||
}); | ||
}, { timestamps: { createdAt: true } }); | ||
@@ -154,2 +162,10 @@ const User = typedModel('User', UserSchema); | ||
``` | ||
- Note that enum values need to be readonly array to be treated as literals by typescript | ||
```ts | ||
const genders = ['male', 'female'] as const; | ||
{ | ||
// same as {type: String, required: true, enum: ['male', 'female']} | ||
gender: Type.string({enum: genders}) | ||
} | ||
``` | ||
- `schema`, `object`, `array` types have a method `of` where you must provide a child type | ||
@@ -164,3 +180,3 @@ ```ts | ||
```ts | ||
const AddressSchema = createSchema({city: Type.string()}, { _id: false }); | ||
const AddressSchema = createSchema({city: Type.string()}, { _id: false, timestamps: true }); | ||
{ | ||
@@ -167,0 +183,0 @@ // same as {type: AddressSchema} |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
4246125
45
1286
280
2