Comparing version 0.1.22 to 0.1.23
@@ -71,4 +71,15 @@ "use strict"; | ||
}); | ||
function removeAll(collection) { | ||
return collection.getAll().then(function (objects) { | ||
var propmises = []; | ||
objects.forEach(function (o) { | ||
console.log("deleting ", o); | ||
var promise = collection.remove(reob.getId(o)); | ||
propmises.push(promise); | ||
}); | ||
return Promise.all(propmises).thenReturn(); | ||
}); | ||
} | ||
var count = 0; | ||
beforeEach(function () { | ||
beforeEach(function (done) { | ||
count++; | ||
@@ -82,2 +93,7 @@ reob.setVerbose(true); | ||
server.removeAllMethodListeners(); | ||
removeAll(personCollection).then(function () { | ||
return removeAll(treeCollection); | ||
}).then(function () { | ||
return removeAll(carCollection); | ||
}).then(done).catch(done.fail); | ||
}); | ||
@@ -294,2 +310,4 @@ it("isVerbose", function () { | ||
expect(t1.treeId).toBe("t1"); | ||
expect(t1 instanceof Tests.TestTree).toBeTruthy(); | ||
console.log(t1); | ||
expect(t1.getLeaves()[0] instanceof Tests.TestLeaf).toBeTruthy(); | ||
@@ -583,2 +601,20 @@ }); | ||
}); | ||
it("stores objects of different classes in an array", function (done) { | ||
var s = new reob.Serializer(); | ||
var person = new Tests.TestPerson('p1', 'pete'); | ||
var child = new Tests.TestInheritanceChild(); | ||
var wheel = new Tests.TestWheel(); | ||
var car = new Tests.TestCar(); | ||
person.addresses.push(child); | ||
person.addresses.push(wheel); | ||
person.addresses.push(car); | ||
personCollection.insert(person).then(function (id) { | ||
return personCollection.getByIdOrFail(id); | ||
}).then(function (person2) { | ||
expect(person2.addresses[0] instanceof Tests.TestInheritanceChild).toBeTruthy(); | ||
expect(person2.addresses[1] instanceof Tests.TestWheel).toBeTruthy(); | ||
expect(person2.addresses[2] instanceof Tests.TestCar).toBeTruthy(); | ||
done(); | ||
}); | ||
}); | ||
it("can get the testwheel class by its configured name", function () { | ||
@@ -876,2 +912,3 @@ var p = reob.Reflect.getEntityClassByName("TestWheelBanzai"); | ||
expect(updateEvent.beforeUpdateDocument).toBeDefined(); | ||
console.log("updateEvent.beforeUpdateDocument", updateEvent.beforeUpdateDocument); | ||
if (updateEvent.beforeUpdateDocument) | ||
@@ -878,0 +915,0 @@ expect(updateEvent.beforeUpdateDocument["someBoolean"]).toBe(false); |
@@ -10,6 +10,2 @@ /** | ||
/** | ||
* @hidden | ||
*/ | ||
var jsd = require("jsondiffpatch"); | ||
/** | ||
* This is class represents the startingpoint from the website. Use it to register services and load objects. | ||
@@ -16,0 +12,0 @@ */ |
@@ -11,4 +11,3 @@ import { Document } from "./Document"; | ||
toDocument(object: Object, includeContext?: boolean, omitPropertiesPrivateToServer?: boolean): Document; | ||
private toDocumentRecursive(object, includeContext?, omitPropertiesPrivateToServer?, rootClass?, parentObject?, propertyNameOnParentObject?); | ||
private createDocument(object, includeContext?, omitPropertiesPrivateToServer?, rootClass?, parentObject?, propertyNameOnParentObject?); | ||
private toDocumentRecursive(object, expectedClass?, includeContext?, omitPropertiesPrivateToServer?); | ||
} |
@@ -133,79 +133,64 @@ "use strict"; | ||
}; | ||
// this is the function that gets called when the process of converting an object to a document starts. | ||
// its called once in the process | ||
Serializer.prototype.toDocument = function (object, includeContext, omitPropertiesPrivateToServer) { | ||
return this.toDocumentRecursive(object, includeContext, omitPropertiesPrivateToServer); | ||
var objectClass = Annotations_1.Reflect.getClass(object); | ||
var result = this.toDocumentRecursive(object, objectClass, omitPropertiesPrivateToServer); | ||
// console.log("returning document:",result); | ||
return result; | ||
}; | ||
Serializer.prototype.toDocumentRecursive = function (object, includeContext, omitPropertiesPrivateToServer, rootClass, parentObject, propertyNameOnParentObject) { | ||
Serializer.prototype.toDocumentRecursive = function (object, expectedClass, includeContext, omitPropertiesPrivateToServer) { | ||
var result; | ||
if (!object || typeof object == "string" || typeof object == "number" || typeof object == "date" || typeof object == "boolean") | ||
var objectClass = Annotations_1.Reflect.getClass(object); | ||
var context = reob.SerializationPath.getObjectContext(object); | ||
// console.log(" documenting ", object, typeof object); | ||
// is there a customized way to create a document ? | ||
if (objectClass && typeof objectClass.toDocument == "function") { | ||
result = objectClass.toDocument(object); | ||
} | ||
else if (!object || typeof object == "string" || typeof object == "number" || typeof object == "date" || typeof object == "boolean") { | ||
result = object; | ||
else if (Array.isArray(object)) { | ||
result = []; | ||
for (var i = 0; i < object.length; i++) { | ||
result[i] = this.toDocumentRecursive(object[i], includeContext); | ||
} | ||
else if (Array.isArray(object) || Annotations_1.Reflect.isArrayOrMap(objectClass, property)) { | ||
result = Array.isArray(object) ? [] : {}; | ||
var expectedClass_1 = Annotations_1.Reflect.getPropertyClass(objectClass, property); | ||
for (var property in object) { | ||
var subDoc = this.toDocumentRecursive(object[property], expectedClass_1, includeContext, omitPropertiesPrivateToServer); | ||
result[property] = subDoc; | ||
} | ||
} | ||
else { | ||
var objectClass = Annotations_1.Reflect.getClass(object); | ||
if (typeof objectClass.toDocument == "function") { | ||
result = objectClass.toDocument(object); | ||
} | ||
else { | ||
var parentClass = Annotations_1.Reflect.getClass(parentObject); | ||
{ | ||
result = this.createDocument(object, includeContext, omitPropertiesPrivateToServer, rootClass ? rootClass : Annotations_1.Reflect.getClass(object), parentObject, propertyNameOnParentObject); | ||
else if (typeof object == "object") { | ||
result = {}; | ||
// for all enumerable properties in the object ... | ||
for (var property in object) { | ||
var value = object[property]; | ||
var expectedClass_2 = Annotations_1.Reflect.getPropertyClass(objectClass, property); | ||
// figure out if the property needs to be part of the document or not | ||
var canBeIgnored = omitPropertiesPrivateToServer && Annotations_1.Reflect.isPrivateToServer(objectClass, property); // its private to the server | ||
canBeIgnored = canBeIgnored || Annotations_1.Reflect.isIgnored(objectClass, property); | ||
canBeIgnored = canBeIgnored || value === undefined; // it's undefined | ||
canBeIgnored = canBeIgnored || Annotations_1.Reflect.isParent(objectClass, property); // parent properties are not part of documents, they're deducted | ||
canBeIgnored = canBeIgnored || typeof value === "function"; // its's a function | ||
if (!canBeIgnored) { | ||
var documentNameOfTheProperty = Annotations_1.Reflect.getDocumentPropertyName(objectClass, property) || property; | ||
var subDoc = this.toDocumentRecursive(value, expectedClass_2, includeContext, omitPropertiesPrivateToServer); | ||
result[documentNameOfTheProperty] = subDoc; | ||
} | ||
} | ||
} | ||
//console.log("returning document:",result); | ||
return result; | ||
}; | ||
Serializer.prototype.createDocument = function (object, includeContext, omitPropertiesPrivateToServer, rootClass, parentObject, propertyNameOnParentObject) { | ||
var doc = {}; | ||
var context = reob.SerializationPath.getObjectContext(object); | ||
if (includeContext) { | ||
if (context && context.serializationPath) | ||
doc['_serializationPath'] = context.serializationPath.toString(); | ||
var cls = reob.Reflect.getClass(object); | ||
if (cls && reob.Reflect.isEntity(cls)) { | ||
doc['_className'] = reob.Reflect.getClassName(cls); | ||
// add the serialization path if needed (for network) | ||
if (includeContext && context && context.serializationPath) { | ||
result['_serializationPath'] = context.serializationPath.toString(); | ||
} | ||
} | ||
var objectClass = Annotations_1.Reflect.getClass(object); | ||
for (var property in object) { | ||
var value = object[property]; | ||
var documentNameOfTheProperty = Annotations_1.Reflect.getDocumentPropertyName(objectClass, property); | ||
if (!documentNameOfTheProperty) | ||
documentNameOfTheProperty = property; | ||
var needsToBeOmittedBecauseItsPrivate = omitPropertiesPrivateToServer && Annotations_1.Reflect.isPrivateToServer(objectClass, property); | ||
if (value !== undefined && !Annotations_1.Reflect.isIgnored(objectClass, property) && !Annotations_1.Reflect.isParent(objectClass, property) && !needsToBeOmittedBecauseItsPrivate) { | ||
// primitives | ||
if (Annotations_1.Reflect.getPropertyClass(objectClass, property)) { | ||
// array | ||
if (Annotations_1.Reflect.isArrayOrMap(objectClass, property)) { | ||
var result; | ||
if (Array.isArray(value)) | ||
result = []; | ||
else | ||
result = {}; | ||
for (var i in value) { | ||
var subObject = value[i]; | ||
result[i] = this.toDocumentRecursive(subObject, includeContext, omitPropertiesPrivateToServer, rootClass, object, property); | ||
} | ||
doc[documentNameOfTheProperty] = result; | ||
} | ||
else if (typeof object[property] == 'object') { | ||
doc[documentNameOfTheProperty] = this.toDocumentRecursive(value, includeContext, omitPropertiesPrivateToServer, rootClass, object, property); | ||
} | ||
else { | ||
throw new Error("Unsupported type : " + typeof value); | ||
} | ||
} | ||
else if (typeof value == 'function') { | ||
} | ||
else { | ||
doc[documentNameOfTheProperty] = Cloner.clone(value); | ||
} | ||
// add the object class if it deviates from what's expected or its required | ||
if (objectClass && reob.Reflect.isEntity(objectClass) && (includeContext || expectedClass != objectClass)) { | ||
result['_className'] = reob.Reflect.getClassName(objectClass); | ||
} | ||
} | ||
return doc; | ||
else if (typeof object == "function") { | ||
} | ||
else { | ||
throw new Error("Unexpected object type :" + (typeof object)); | ||
} | ||
// console.log(" documenting result:", result); | ||
return result; | ||
}; | ||
@@ -212,0 +197,0 @@ return Serializer; |
{ | ||
"name": "reob", | ||
"description": "Remote objects - Create backends for one page web apps with ease. Uses mongo and express.", | ||
"version": "0.1.22", | ||
"version": "0.1.23", | ||
"repository": "https://github.com/bvanheukelom/reob", | ||
@@ -28,3 +28,4 @@ "license": "MIT", | ||
"dependencies": { | ||
"web-methods": "*", | ||
"@types/bluebird": "^3.0.36", | ||
"@types/express": "^4.0.34", | ||
"bluebird": "^3.4.1", | ||
@@ -35,4 +36,5 @@ "compression": "^1.6.2", | ||
"mongodb": "^2.1.18", | ||
"node-uuid": "^1.4.7" | ||
"node-uuid": "^1.4.7", | ||
"web-methods": "*" | ||
} | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
499023
145
5030
9
+ Added@types/bluebird@^3.0.36
+ Added@types/express@^4.0.34
+ Added@types/bluebird@3.5.42(transitive)
+ Added@types/body-parser@1.19.5(transitive)
+ Added@types/connect@3.4.38(transitive)
+ Added@types/express@4.17.21(transitive)
+ Added@types/express-serve-static-core@4.19.6(transitive)
+ Added@types/http-errors@2.0.4(transitive)
+ Added@types/mime@1.3.5(transitive)
+ Added@types/node@22.10.2(transitive)
+ Added@types/qs@6.9.17(transitive)
+ Added@types/range-parser@1.2.7(transitive)
+ Added@types/send@0.17.4(transitive)
+ Added@types/serve-static@1.15.7(transitive)
+ Addedundici-types@6.20.0(transitive)