@hitchy/plugin-odem-rest 0.9.0 → 0.9.2
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/index.js +12 -11
- package/package.json +2 -2
package/index.js
CHANGED
|
@@ -98,7 +98,7 @@ export default function() { // eslint-disable-line jsdoc/require-jsdoc
|
|
|
98
98
|
* @param {Map<string,function(IncomingMessage,ServerResponse):Promise>} routes maps
|
|
99
99
|
* route patterns into function handling requests matching that pattern
|
|
100
100
|
* @param {string} urlPrefix common prefix to use on every route regarding any model-related processing
|
|
101
|
-
* @param {
|
|
101
|
+
* @param {Object<string,class<Model>>} models lists all currently available models
|
|
102
102
|
* @returns {void}
|
|
103
103
|
*/
|
|
104
104
|
function addGlobalRoutes( routes, urlPrefix, models ) {
|
|
@@ -148,7 +148,7 @@ export default function() { // eslint-disable-line jsdoc/require-jsdoc
|
|
|
148
148
|
* @param {string} urlPrefix common prefix to use on every route regarding any model-related processing
|
|
149
149
|
* @param {string} routeName name of model to be used in path name of request
|
|
150
150
|
* @param {string} modelName name of model derived from name extracted from path name of request in `routeName`
|
|
151
|
-
* @param {
|
|
151
|
+
* @param {Class<Model>} Model model class
|
|
152
152
|
* @param {boolean} includeConvenienceRoutes set true to include additional set of routes for controlling all action via GET-requests
|
|
153
153
|
* @returns {void}
|
|
154
154
|
*/
|
|
@@ -270,7 +270,7 @@ export default function() { // eslint-disable-line jsdoc/require-jsdoc
|
|
|
270
270
|
return;
|
|
271
271
|
}
|
|
272
272
|
|
|
273
|
-
const item = new Model( uuid );
|
|
273
|
+
const item = new Model( uuid ).withContext( this );
|
|
274
274
|
|
|
275
275
|
await item.$exists
|
|
276
276
|
.then( exists => {
|
|
@@ -308,7 +308,7 @@ export default function() { // eslint-disable-line jsdoc/require-jsdoc
|
|
|
308
308
|
return;
|
|
309
309
|
}
|
|
310
310
|
|
|
311
|
-
const item = new Model( uuid );
|
|
311
|
+
const item = new Model( uuid ).withContext( this );
|
|
312
312
|
|
|
313
313
|
await item.load()
|
|
314
314
|
.then( loaded => res.json( Schema.filterItem( serializeItem( loaded, true ), req, Model, "read" ) ) )
|
|
@@ -457,7 +457,8 @@ export default function() { // eslint-disable-line jsdoc/require-jsdoc
|
|
|
457
457
|
|
|
458
458
|
await Model.find( Schema.checkQuery( parsedQuery, req, Model ), { offset, limit, sortBy, sortAscendingly: !descending }, {
|
|
459
459
|
metaCollector: meta,
|
|
460
|
-
loadRecords
|
|
460
|
+
loadRecords,
|
|
461
|
+
context: this,
|
|
461
462
|
} )
|
|
462
463
|
.then( matches => {
|
|
463
464
|
const result = {
|
|
@@ -497,7 +498,7 @@ export default function() { // eslint-disable-line jsdoc/require-jsdoc
|
|
|
497
498
|
limit,
|
|
498
499
|
sortBy,
|
|
499
500
|
sortAscendingly: !descending
|
|
500
|
-
}, { loadRecords, metaCollector: meta } )
|
|
501
|
+
}, { loadRecords, metaCollector: meta, context: this } )
|
|
501
502
|
.then( matches => {
|
|
502
503
|
const result = {
|
|
503
504
|
items: matches.map( item => Schema.filterItem( serializeItem( item, false ), req, Model, "list" ) ),
|
|
@@ -537,7 +538,7 @@ export default function() { // eslint-disable-line jsdoc/require-jsdoc
|
|
|
537
538
|
return;
|
|
538
539
|
}
|
|
539
540
|
|
|
540
|
-
const item = new Model();
|
|
541
|
+
const item = new Model().withContext( this );
|
|
541
542
|
|
|
542
543
|
await ( req.method === "GET" ? Promise.resolve( req.query ) : req.fetchBody() )
|
|
543
544
|
.then( record => {
|
|
@@ -596,7 +597,7 @@ export default function() { // eslint-disable-line jsdoc/require-jsdoc
|
|
|
596
597
|
return;
|
|
597
598
|
}
|
|
598
599
|
|
|
599
|
-
const item = new Model( uuid );
|
|
600
|
+
const item = new Model( uuid ).withContext( this );
|
|
600
601
|
|
|
601
602
|
await item.$exists
|
|
602
603
|
.then( exists => {
|
|
@@ -661,7 +662,7 @@ export default function() { // eslint-disable-line jsdoc/require-jsdoc
|
|
|
661
662
|
return;
|
|
662
663
|
}
|
|
663
664
|
|
|
664
|
-
const item = new Model( uuid, { onUnsaved: false } );
|
|
665
|
+
const item = new Model( uuid, { onUnsaved: false } ).withContext( this );
|
|
665
666
|
|
|
666
667
|
await Promise.all( [ item.$exists, req.method === "GET" ? Promise.resolve( req.query ) : req.fetchBody() ] )
|
|
667
668
|
.then( ( [ exists, record ] ) => {
|
|
@@ -725,7 +726,7 @@ export default function() { // eslint-disable-line jsdoc/require-jsdoc
|
|
|
725
726
|
return;
|
|
726
727
|
}
|
|
727
728
|
|
|
728
|
-
const item = new Model( uuid );
|
|
729
|
+
const item = new Model( uuid ).withContext( this );
|
|
729
730
|
|
|
730
731
|
await item.$exists
|
|
731
732
|
.then( exists => {
|
|
@@ -779,7 +780,7 @@ export default function() { // eslint-disable-line jsdoc/require-jsdoc
|
|
|
779
780
|
|
|
780
781
|
const lazy = definition?.lazy;
|
|
781
782
|
|
|
782
|
-
if ( !lazy || ( typeof lazy === "string" && lazy !== "rest" ) || !lazy.rest ) {
|
|
783
|
+
if ( !lazy || ( typeof lazy === "string" && lazy !== "rest" ) || ( typeof lazy === "object" && !lazy.rest ) ) {
|
|
783
784
|
filtered[name] = record[name];
|
|
784
785
|
}
|
|
785
786
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hitchy/plugin-odem-rest",
|
|
3
|
-
"version": "0.9.
|
|
3
|
+
"version": "0.9.2",
|
|
4
4
|
"description": "HTTP REST API for Hitchy's document-oriented database",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -21,7 +21,7 @@
|
|
|
21
21
|
"homepage": "https://gitlab.com/hitchy/plugin-odem-rest#plugin-odem-rest",
|
|
22
22
|
"peerDependencies": {
|
|
23
23
|
"@hitchy/core": "1.x",
|
|
24
|
-
"@hitchy/plugin-odem": "0.13.
|
|
24
|
+
"@hitchy/plugin-odem": "^0.13.2",
|
|
25
25
|
"@hitchy/plugin-auth": "0.6.x"
|
|
26
26
|
},
|
|
27
27
|
"devDependencies": {
|