Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

hydrate-mongodb

Package Overview
Dependencies
Maintainers
1
Versions
71
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

hydrate-mongodb - npm Package Compare versions

Comparing version 1.4.0 to 1.5.0

4

mapping/entityMapping.js

@@ -162,3 +162,3 @@ "use strict";

else {
if (flags & 8192 /* Dereference */) {
if (flags & 16384 /* Dereference */) {
// store reference to resolve later

@@ -174,3 +174,3 @@ references.push(value);

// If this isn't the first entity, only continue if we have the WalkEntities flag
if ((this.flags & 4096 /* WalkEntities */) == 0 && entities.length > 1)
if ((flags & 8192 /* WalkEntities */) == 0 && entities.length > 1)
return;

@@ -177,0 +177,0 @@ _super.prototype.walk.call(this, session, value, flags, entities, embedded, references);

@@ -140,6 +140,10 @@ import { Index } from "./index";

/**
* Property should contain a reference to the parent of the embeddable.
*/
Parent = 4096,
/**
* All non-walk flags.
* @hidden
*/
All = 4095,
All = 8191,
/**

@@ -149,3 +153,3 @@ * Indicates that refererences to entities should be walked.

*/
WalkEntities = 4096,
WalkEntities = 8192,
/**

@@ -155,3 +159,3 @@ * Indicates that reference found during a walk operation should be fetched.

*/
Dereference = 8192,
Dereference = 16384,
}

@@ -158,0 +162,0 @@ /**

@@ -92,4 +92,12 @@ "use strict";

var base = context.path ? context.path + "." : "", properties = this.properties;
var objectParent = context.parent;
context.parent = obj;
for (var i = 0, l = properties.length; i < l; i++) {
var property = properties[i];
// todo: need to validate that the parent is assignable to the property
// set the property value to the parent of the object if this is a parent reference
if ((property.flags & 4096 /* Parent */) != 0) {
property.setPropertyValue(obj, objectParent);
continue;
}
// skip fields that are not persisted

@@ -134,2 +142,3 @@ if ((property.flags & (1 /* Ignored */ | 64 /* InverseSide */

}
context.parent = objectParent;
// if there is an observer in the context, then watch this object for changes.

@@ -239,3 +248,3 @@ if (context.observer && (this.flags & 131072 /* Immutable */) == 0) {

if ((property.flags & 1 /* Ignored */) == 0
&& ((property.flags & flags) != 0 || ((flags & 4095 /* All */) == 0))) {
&& ((property.flags & flags) != 0 || ((flags & 8191 /* All */) == 0))) {
property.mapping.walk(session, property.getPropertyValue(value), flags, entities, embedded, references);

@@ -288,6 +297,9 @@ }

}
if ((property.flags & 64 /* InverseSide */) != 0) {
if ((property.flags & 4096 /* Parent */) != 0) {
context.setError("Cannot resolve parent reference.");
}
else if ((property.flags & 64 /* InverseSide */) != 0) {
context.setError("Cannot resolve inverse side of relationship.");
}
if ((property.flags & 1 /* Ignored */) != 0) {
else if ((property.flags & 1 /* Ignored */) != 0) {
context.setError("Cannot resolve ignored property.");

@@ -294,0 +306,0 @@ }

@@ -270,2 +270,9 @@ import { PropertyConverter, FlushPriority, FetchType } from "../mappingModel";

}
/**
* @hidden
*/
export declare class ParentAnnotation extends Annotation implements PropertyAnnotation {
toString(): string;
processPropertyAnnotation(context: MappingBuilderContext, mapping: MappingModel.ObjectMapping, property: MappingModel.Property, symbol: Property, annotation: FieldAnnotation): void;
}
export interface FieldDescription {

@@ -272,0 +279,0 @@ /**

@@ -523,2 +523,21 @@ "use strict";

*/
var ParentAnnotation = (function (_super) {
__extends(ParentAnnotation, _super);
function ParentAnnotation() {
return _super.apply(this, arguments) || this;
}
ParentAnnotation.prototype.toString = function () {
return "@Parent";
};
ParentAnnotation.prototype.processPropertyAnnotation = function (context, mapping, property, symbol, annotation) {
if (context.assertEmbeddableMapping(mapping)) {
property.setFlags(4096 /* Parent */ | 1 /* Ignored */);
}
};
return ParentAnnotation;
}(Annotation));
exports.ParentAnnotation = ParentAnnotation;
/**
* @hidden
*/
var EnumeratedAnnotation = (function () {

@@ -525,0 +544,0 @@ function EnumeratedAnnotation(members) {

@@ -312,2 +312,29 @@ import { Constructor, ParameterlessConstructor } from "../../index";

/**
* Indicates that a property is a reference to the parent of an embeddable class.
*
* The reference to the parent is automatically populated when the document is read from the database and the object graph is built. The
* value of the property is not saved to the database.
*
* ### Example
*
* ```typescript
*  @Entity()
* export class Person {
*
*  @ElementType(Address)
* addresses: Address[];
* ...
* }
*
*  @Embeddable()
* export class Address {
*
*  @Parent()
* resident: Person;
* ...
* }
* ```
*/
export declare function Parent(): PropertyDecorator;
/**
* Specifies that an enum value should be serialized as a string.

@@ -314,0 +341,0 @@ *

@@ -15,2 +15,3 @@ "use strict";

exports.Field = reflect_helper_1.makeDecorator(annotations_1.FieldAnnotation);
exports.Parent = reflect_helper_1.makeDecorator(annotations_1.ParentAnnotation);
exports.Enumerated = reflect_helper_1.makeDecorator(annotations_1.EnumeratedAnnotation);

@@ -17,0 +18,0 @@ exports.Cascade = reflect_helper_1.makeDecorator(annotations_1.CascadeAnnotation);

@@ -27,2 +27,3 @@ import { Configuration } from "../../config/configuration";

assertClassMapping(mapping: MappingModel.Mapping): boolean;
assertEmbeddableMapping(mapping: MappingModel.Mapping): boolean;
assertRootClassMapping(mapping: MappingModel.Mapping): boolean;

@@ -29,0 +30,0 @@ assertRootEntityMapping(mapping: MappingModel.Mapping): boolean;

@@ -78,2 +78,9 @@ "use strict";

};
MappingBuilderContext.prototype.assertEmbeddableMapping = function (mapping) {
if ((mapping.flags & 2048 /* Embeddable */) === 0) {
this.addError("Annotation can only be defined an embeddable class.");
return false;
}
return true;
};
MappingBuilderContext.prototype.assertRootClassMapping = function (mapping) {

@@ -80,0 +87,0 @@ if (!this.assertClassMapping(mapping))

@@ -167,3 +167,17 @@ "use strict";

}
this.context.addError("Unable to determine mapping for '" + type.name + "'.");
var typeName;
if (type) {
typeName = type.name;
}
else if (typeof target === "string") {
typeName = target;
}
else if (typeof target === "function") {
typeName = target.name;
}
else {
typeName = "unknown";
}
this.context.addError("Unable to determine mapping for '" + typeName + "'."
+ " Has the type been added to the AnnotationMappingProvider?");
};

@@ -170,0 +184,0 @@ return ObjectMappingBuilder;

@@ -29,2 +29,6 @@ import { MappingError } from "./mappingError";

fetches: string[];
/**
* The parent object.
*/
parent: Object;
constructor(session: InternalSession);

@@ -31,0 +35,0 @@ /**

{
"name": "hydrate-mongodb",
"description": "An Object Document Mapper (ODM) for MongoDB.",
"version": "1.4.0",
"version": "1.5.0",
"author": {

@@ -6,0 +6,0 @@ "name": "Artifact Health, LLC",

@@ -453,2 +453,27 @@ [![Build Status](https://travis-ci.org/artifacthealth/hydrate-mongodb.svg?branch=master)](https://travis-ci.org/artifacthealth/hydrate-mongodb)

Using the [Parent](https://artifacthealth.github.io/hydrate-mongodb/globals.html#parent) decorator, Embeddables can designate a property to reference the object they are embedded in.
The property is automatically populated with a reference to the parent object when the embeddable is loaded from the database. Properties annotated
with [Parent](https://artifacthealth.github.io/hydrate-mongodb/globals.html#parent) are not persisted to the database.
```
@Entity()
export class Person {
@ElementType(Address)
addresses: Address[];
}
@Embeddable()
export class Address {
@Parent()
resident: Person;
@Field()
street: string;
...
}
```
<a name="Types"></a>

@@ -455,0 +480,0 @@ ### Types

@@ -413,3 +413,3 @@ "use strict";

return callback(err);
_this._findReferencedEntities(entity, 4 /* CascadeRemove */ | 8192 /* Dereference */, function (err, entities) {
_this._findReferencedEntities(entity, 4 /* CascadeRemove */ | 16384 /* Dereference */, function (err, entities) {
if (err)

@@ -833,3 +833,3 @@ return callback(err);

var references = [];
mapping.walk(this, entity, flags | 4096 /* WalkEntities */, entities, embedded, references);
mapping.walk(this, entity, flags | 8192 /* WalkEntities */, entities, embedded, references);
async.each(references, function (reference, done) {

@@ -836,0 +836,0 @@ reference.fetch(_this, function (err, entity) {

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc