meadow-endpoints 4.0.14 → 4.0.15
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.
- package/dist/meadow-endpoints.js +16 -21
- package/dist/meadow-endpoints.js.map +1 -1
- package/dist/meadow-endpoints.min.js +6 -6
- package/dist/meadow-endpoints.min.js.map +1 -1
- package/package.json +7 -7
- package/source/endpoints/upsert/Meadow-Operation-Upsert.js +5 -3
- package/test/MeadowEndpoints_basic_tests.js +39 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "meadow-endpoints",
|
|
3
|
-
"version": "4.0.
|
|
3
|
+
"version": "4.0.15",
|
|
4
4
|
"description": "Automatic API endpoints for Meadow data.",
|
|
5
5
|
"main": "source/Meadow-Endpoints.js",
|
|
6
6
|
"scripts": {
|
|
@@ -49,24 +49,24 @@
|
|
|
49
49
|
"homepage": "https://github.com/stevenvelozo/meadow-endpoints",
|
|
50
50
|
"devDependencies": {
|
|
51
51
|
"alasql": "^4.17.0",
|
|
52
|
-
"better-sqlite3": "^12.
|
|
52
|
+
"better-sqlite3": "^12.8.0",
|
|
53
53
|
"chance": "^1.1.13",
|
|
54
54
|
"gulp-util": "^3.0.8",
|
|
55
55
|
"meadow-connection-sqlite": "^1.0.18",
|
|
56
|
-
"mysql2": "^3.
|
|
57
|
-
"orator-serviceserver-restify": "^2.0.
|
|
56
|
+
"mysql2": "^3.20.0",
|
|
57
|
+
"orator-serviceserver-restify": "^2.0.10",
|
|
58
58
|
"papaparse": "^5.5.3",
|
|
59
|
-
"quackage": "^1.0.
|
|
59
|
+
"quackage": "^1.0.65",
|
|
60
60
|
"supertest": "^7.2.2",
|
|
61
61
|
"typescript": "^5.9.3",
|
|
62
62
|
"why-is-node-running": "^3.2.2"
|
|
63
63
|
},
|
|
64
64
|
"dependencies": {
|
|
65
65
|
"async": "3.2.6",
|
|
66
|
-
"fable": "^3.1.
|
|
66
|
+
"fable": "^3.1.67",
|
|
67
67
|
"fable-serviceproviderbase": "^3.0.19",
|
|
68
68
|
"JSONStream": "^1.3.5",
|
|
69
|
-
"meadow": "^2.0.
|
|
69
|
+
"meadow": "^2.0.33",
|
|
70
70
|
"meadow-filter": "^1.0.10",
|
|
71
71
|
"orator": "^6.0.4",
|
|
72
72
|
"underscore": "^1.13.8"
|
|
@@ -66,8 +66,10 @@ const doUpsert = function(pRecordToUpsert, pRequest, pRequestState, pResponse, f
|
|
|
66
66
|
}
|
|
67
67
|
else
|
|
68
68
|
{
|
|
69
|
-
// Set the default ID in the passed-in record if it doesn't exist
|
|
70
|
-
|
|
69
|
+
// Set the default ID in the passed-in record if it doesn't exist
|
|
70
|
+
// or is zero (which is never a valid ID).
|
|
71
|
+
if (!tmpRequestState.Record.hasOwnProperty(this.DAL.defaultIdentifier)
|
|
72
|
+
|| !tmpRequestState.Record[this.DAL.defaultIdentifier])
|
|
71
73
|
{
|
|
72
74
|
tmpRequestState.Record[this.DAL.defaultIdentifier] = pRecord[this.DAL.defaultIdentifier];
|
|
73
75
|
}
|
|
@@ -129,4 +131,4 @@ const doUpsert = function(pRecordToUpsert, pRequest, pRequestState, pResponse, f
|
|
|
129
131
|
});
|
|
130
132
|
};
|
|
131
133
|
|
|
132
|
-
module.exports = doUpsert;
|
|
134
|
+
module.exports = doUpsert;
|
|
@@ -819,6 +819,45 @@ suite
|
|
|
819
819
|
);
|
|
820
820
|
}
|
|
821
821
|
);
|
|
822
|
+
test
|
|
823
|
+
(
|
|
824
|
+
'upsert: update by GUID when passed ID is zero',
|
|
825
|
+
function (fDone)
|
|
826
|
+
{
|
|
827
|
+
// First create a record so we have a known GUID
|
|
828
|
+
_SuperTest
|
|
829
|
+
.post('1.0/Book')
|
|
830
|
+
.send({ Title: 'Zero ID Upsert Test', Genre: 'Test' })
|
|
831
|
+
.end(
|
|
832
|
+
(pError, pResponse) =>
|
|
833
|
+
{
|
|
834
|
+
let tmpCreated = JSON.parse(pResponse.text);
|
|
835
|
+
let tmpRecord = Array.isArray(tmpCreated) ? tmpCreated[0] : tmpCreated;
|
|
836
|
+
let tmpGUID = tmpRecord.GUIDBook;
|
|
837
|
+
let tmpID = tmpRecord.IDBook;
|
|
838
|
+
Expect(tmpID).to.be.above(0);
|
|
839
|
+
Expect(tmpGUID).to.be.a('string');
|
|
840
|
+
|
|
841
|
+
// Now upsert with ID=0 but the same GUID — should
|
|
842
|
+
// find the record by GUID and update it, not fail
|
|
843
|
+
// with "Record IDs do not match".
|
|
844
|
+
_SuperTest
|
|
845
|
+
.put('1.0/Book/Upsert')
|
|
846
|
+
.send({ IDBook: 0, GUIDBook: tmpGUID, Title: 'Zero ID Upsert Updated' })
|
|
847
|
+
.end(
|
|
848
|
+
(pUpsertError, pUpsertResponse) =>
|
|
849
|
+
{
|
|
850
|
+
Expect(pUpsertResponse.status).to.equal(200);
|
|
851
|
+
let tmpResult = JSON.parse(pUpsertResponse.text);
|
|
852
|
+
Expect(tmpResult.IDBook).to.equal(tmpID);
|
|
853
|
+
Expect(tmpResult.Title).to.equal('Zero ID Upsert Updated');
|
|
854
|
+
fDone();
|
|
855
|
+
}
|
|
856
|
+
);
|
|
857
|
+
}
|
|
858
|
+
);
|
|
859
|
+
}
|
|
860
|
+
);
|
|
822
861
|
}
|
|
823
862
|
);
|
|
824
863
|
|