jxp 2.15.1 → 2.16.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -302,7 +302,7 @@ var deserialize = function (input) {
302
302
  var val = input[prop];
303
303
  if (parts) {
304
304
  var tmp = assignPropVal(parts, result, val, 0);
305
- newobj = _.deepExtend(newobj, tmp, 0);
305
+ newobj = _.deepExtend(tmp);
306
306
  } else {
307
307
  // console.log("NOT ARRAY", parts);
308
308
  newobj[prop] = input[prop];
@@ -11,10 +11,12 @@ const TestSchema = new JXPSchema({
11
11
  fulltext: { type: String, index: { text: true } },
12
12
  link_id: { type: ObjectId, link: "Link", }, // We can populate these links during a query
13
13
  other_link_id: { type: ObjectId, link: "Link", map_to: "other_link" },
14
+ string_array: [String],
14
15
  array_link_id: [{ type: ObjectId, link: "Link", map_to: "array_link", justOne: false }],
15
16
  composite_array: [
16
17
  { afoo: String, abar: Number }
17
18
  ],
19
+ mixed_array: [Mixed],
18
20
  date_field: { type: Date, index: true } // Added date field for testing date filtering
19
21
  },
20
22
  {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "jxp",
3
3
  "description:": "An opinionated RESTful API library based on Mongoose and Restify. Make an API by just writing Mongoose models.",
4
- "version": "2.15.1",
4
+ "version": "2.16.0",
5
5
  "private": false,
6
6
  "main": "libs/jxp.js",
7
7
  "scripts": {
package/test/test.js CHANGED
@@ -233,6 +233,29 @@ describe('Test', () => {
233
233
  done();
234
234
  });
235
235
  });
236
+
237
+ it("it should POST a test with string_array", (done) => {
238
+ var test = {
239
+ foo: "FooArray",
240
+ bar: "BarArray",
241
+ string_array: ["one", "two", "three"]
242
+ };
243
+ chai.request(server)
244
+ .post("/api/test")
245
+ .auth(init.email, init.password)
246
+ .send(test)
247
+ .end((err, res) => {
248
+ res.should.have.status(200);
249
+ res.body.data.should.be.an('object');
250
+ res.body.data.should.have.property("string_array");
251
+ res.body.data.string_array.should.be.an("array");
252
+ res.body.data.string_array.should.have.length(3);
253
+ res.body.data.string_array[0].should.equal("one");
254
+ res.body.data.string_array[1].should.equal("two");
255
+ res.body.data.string_array[2].should.equal("three");
256
+ done();
257
+ });
258
+ });
236
259
  });
237
260
 
238
261
  describe("/GET test count", () => {
@@ -241,7 +264,7 @@ describe('Test', () => {
241
264
  .get("/count/test")
242
265
  .end((err, res) => {
243
266
  res.should.have.status(200);
244
- res.body.count.should.be.eql(1);
267
+ res.body.count.should.be.eql(2);
245
268
  done();
246
269
  });
247
270
  });
@@ -717,7 +740,7 @@ describe('Test', () => {
717
740
  res.body.data.should.be.an('array');
718
741
  res.body.data[0].should.have.property("_id");
719
742
  res.body.data[0].should.have.property("count");
720
- res.body.data[0].count.should.eql(2);
743
+ res.body.data[0].count.should.eql(3);
721
744
  done();
722
745
  });
723
746
  });
@@ -736,7 +759,7 @@ describe('Test', () => {
736
759
  res.body.data.should.be.an('array');
737
760
  res.body.data[0].should.have.property("_id");
738
761
  res.body.data[0].should.have.property("count");
739
- res.body.data[0].count.should.eql(2);
762
+ res.body.data[0].count.should.eql(3);
740
763
  done();
741
764
  });
742
765
  });
@@ -762,7 +785,7 @@ describe('Test', () => {
762
785
  res.body.data.should.be.an('array');
763
786
  res.body.data[0].should.have.property("_id");
764
787
  res.body.data[0].should.have.property("count");
765
- res.body.data[0].count.should.eql(2);
788
+ res.body.data[0].count.should.eql(3);
766
789
  done();
767
790
  });
768
791
  });
@@ -789,7 +812,7 @@ describe('Test', () => {
789
812
  res.body.data.should.be.an('array');
790
813
  res.body.data[0].should.have.property("_id");
791
814
  res.body.data[0].should.have.property("count");
792
- res.body.data[0].count.should.eql(2);
815
+ res.body.data[0].count.should.eql(3);
793
816
  done();
794
817
  });
795
818
  });
@@ -832,7 +855,7 @@ describe('Test', () => {
832
855
  res.body.data.should.be.an('array');
833
856
  res.body.data[0].should.have.property("_id");
834
857
  res.body.data[0].should.have.property("count");
835
- res.body.data[0].count.should.eql(2);
858
+ res.body.data[0].count.should.eql(3);
836
859
  done();
837
860
  });
838
861
  });
@@ -848,7 +871,7 @@ describe('Test', () => {
848
871
  res.body.data[0].should.have.property("foo");
849
872
  res.body.data[0].foo.should.eql("Foo1");
850
873
  res.body.should.have.property("count");
851
- res.body.count.should.eql(2);
874
+ res.body.count.should.eql(3);
852
875
  done();
853
876
  });
854
877
  })
@@ -917,7 +940,7 @@ describe('Test', () => {
917
940
  res.body.data[1].should.have.property("foo");
918
941
  res.body.data[2].should.have.property("foo");
919
942
  res.body.should.have.property("count");
920
- res.body.count.should.eql(4);
943
+ res.body.count.should.eql(5);
921
944
  done();
922
945
  });
923
946
  });
@@ -952,6 +975,123 @@ describe('Test', () => {
952
975
  });
953
976
  });
954
977
 
978
+ describe("Mixed Array Tests", () => {
979
+ it("should save complex objects in mixed_array", (done) => {
980
+ const complexData = {
981
+ foo: "MixedArrayTest",
982
+ bar: "MixedArrayBar",
983
+ mixed_array: [
984
+ {
985
+ nested: {
986
+ prop1: "value1",
987
+ prop2: 123,
988
+ prop3: true
989
+ },
990
+ array: [1, 2, 3],
991
+ date: new Date("2024-03-20T10:00:00Z")
992
+ },
993
+ ["array", "of", "strings"],
994
+ 42,
995
+ { simple: "object" },
996
+ null,
997
+ new Date("2024-03-21"),
998
+ [
999
+ {
1000
+ foo: "bar",
1001
+ bar: "foo"
1002
+ },
1003
+ {
1004
+ foo: "baz",
1005
+ bar: "baz"
1006
+ }
1007
+ ]
1008
+ ]
1009
+ };
1010
+
1011
+ chai.request(server)
1012
+ .post("/api/test")
1013
+ .auth(init.email, init.password)
1014
+ .send(complexData)
1015
+ .end((err, res) => {
1016
+ res.should.have.status(200);
1017
+ res.body.data.should.be.an('object');
1018
+ res.body.data.should.have.property("mixed_array");
1019
+ res.body.data.mixed_array.should.be.an("array");
1020
+ res.body.data.mixed_array.should.have.length(7);
1021
+
1022
+ // Verify first object with nested properties
1023
+ res.body.data.mixed_array[0].should.have.property("nested");
1024
+ res.body.data.mixed_array[0].nested.prop1.should.equal("value1");
1025
+ res.body.data.mixed_array[0].nested.prop2.should.equal(123);
1026
+ res.body.data.mixed_array[0].nested.prop3.should.equal(true);
1027
+ res.body.data.mixed_array[0].array.should.deep.equal([1, 2, 3]);
1028
+
1029
+ // Verify array of strings
1030
+ res.body.data.mixed_array[1].should.deep.equal(["array", "of", "strings"]);
1031
+
1032
+ // Verify number
1033
+ res.body.data.mixed_array[2].should.equal(42);
1034
+
1035
+ // Verify simple object
1036
+ res.body.data.mixed_array[3].should.have.property("simple");
1037
+ res.body.data.mixed_array[3].simple.should.equal("object");
1038
+
1039
+ // Verify null
1040
+ should.equal(res.body.data.mixed_array[4], null);
1041
+
1042
+ // Verify dates are stored as ISO strings
1043
+ res.body.data.mixed_array[0].date.should.be.a("string");
1044
+ res.body.data.mixed_array[5].should.be.a("string");
1045
+ res.body.data.mixed_array[6].should.be.a("array");
1046
+ res.body.data.mixed_array[6][0].should.have.property("foo");
1047
+ res.body.data.mixed_array[6][0].foo.should.equal("bar");
1048
+ res.body.data.mixed_array[6][1].should.have.property("foo");
1049
+ res.body.data.mixed_array[6][1].foo.should.equal("baz");
1050
+ done();
1051
+ });
1052
+ });
1053
+
1054
+ it("should retrieve and maintain complex objects in mixed_array", (done) => {
1055
+ // First create a test document
1056
+ const testData = {
1057
+ foo: "MixedArrayRetrieveTest",
1058
+ bar: "RetrieveBar",
1059
+ mixed_array: [
1060
+ {
1061
+ deep: { nested: { object: true } },
1062
+ array: [[1, 2], [3, 4]],
1063
+ },
1064
+ Buffer.from("Hello World").toString("base64"),
1065
+ new RegExp("test").toString()
1066
+ ]
1067
+ };
1068
+
1069
+ let testId;
1070
+
1071
+ chai.request(server)
1072
+ .post("/api/test")
1073
+ .auth(init.email, init.password)
1074
+ .send(testData)
1075
+ .end((err, res) => {
1076
+ res.should.have.status(200);
1077
+ testId = res.body.data._id;
1078
+
1079
+ // Now retrieve and verify
1080
+ chai.request(server)
1081
+ .get(`/api/test/${testId}`)
1082
+ .auth(init.email, init.password)
1083
+ .end((err, res) => {
1084
+ res.should.have.status(200);
1085
+ res.body.data.mixed_array[0].deep.nested.object.should.equal(true);
1086
+ res.body.data.mixed_array[0].array.should.deep.equal([[1, 2], [3, 4]]);
1087
+ res.body.data.mixed_array[1].should.be.a("string");
1088
+ res.body.data.mixed_array[2].should.equal("/test/");
1089
+ done();
1090
+ });
1091
+ });
1092
+ });
1093
+ });
1094
+
955
1095
  describe("Delete", () => {
956
1096
  it("should soft-delete an item", (done) => {
957
1097
  chai.request(server)