meadow-endpoints 4.0.14 → 4.0.16

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.
Files changed (27) hide show
  1. package/dist/indoctrinate_content_staging/Indoctrinate-Catalog-AppData.json +1286 -1065
  2. package/dist/meadow-endpoints.js +253 -164
  3. package/dist/meadow-endpoints.js.map +1 -1
  4. package/dist/meadow-endpoints.min.js +7 -7
  5. package/dist/meadow-endpoints.min.js.map +1 -1
  6. package/docs/_version.json +7 -0
  7. package/docs/css/docuserve.css +277 -23
  8. package/docs/index.html +2 -2
  9. package/docs/retold-catalog.json +13 -1
  10. package/docs/retold-keyword-index.json +1 -1
  11. package/package.json +9 -8
  12. package/source/Meadow-Endpoints-Browser-Shim.js +4 -1
  13. package/source/Meadow-Endpoints.js +6 -6
  14. package/source/controller/Meadow-Endpoints-Controller-Base.js +6 -6
  15. package/source/controller/components/Meadow-Endpoints-Controller-BehaviorInjection.js +11 -11
  16. package/source/controller/components/Meadow-Endpoints-Controller-Error.js +23 -15
  17. package/source/controller/components/Meadow-Endpoints-Controller-Log.js +9 -9
  18. package/source/controller/utility/Meadow-Endpoints-Filter-Parser.js +16 -16
  19. package/source/controller/utility/Meadow-Endpoints-Session-Marshaler.js +42 -42
  20. package/source/controller/utility/Meadow-Endpoints-Stream-RecordArray.js +6 -6
  21. package/source/endpoints/create/Meadow-Operation-Create.js +1 -1
  22. package/source/endpoints/schema/Meadow-Endpoint-Validate.js +1 -1
  23. package/source/endpoints/update/Meadow-Endpoint-BulkUpdate.js +2 -0
  24. package/source/endpoints/update/Meadow-Operation-Update.js +2 -0
  25. package/source/endpoints/upsert/Meadow-Endpoint-BulkUpsert.js +3 -1
  26. package/source/endpoints/upsert/Meadow-Operation-Upsert.js +5 -3
  27. package/test/MeadowEndpoints_basic_tests.js +776 -0
@@ -11,24 +11,24 @@ const { parse } = require('meadow-filter');
11
11
 
12
12
  class MeadowEndpointsFilterParser
13
13
  {
14
- /**
15
- * @param {import('../Meadow-Endpoints-Controller-Base.js')} pController - The controller instance to which this parser belongs.
16
- */
17
- constructor(pController)
14
+ /**
15
+ * @param {import('../Meadow-Endpoints-Controller-Base.js')} pController - The controller instance to which this parser belongs.
16
+ */
17
+ constructor(pController)
18
18
  {
19
- this._Controller = pController;
20
- }
19
+ this._Controller = pController;
20
+ }
21
21
 
22
- /**
23
- * @param {string} pFilterString - The filter string to parse.
24
- * @param {any} pQuery - The foxhound query object to populate.
25
- *
26
- * @return {boolean} - True if the filter was parsed successfully, false otherwise.
27
- */
28
- parseFilter(pFilterString, pQuery)
29
- {
30
- return parse(pFilterString, pQuery);
31
- }
22
+ /**
23
+ * @param {string} pFilterString - The filter string to parse.
24
+ * @param {any} pQuery - The foxhound query object to populate.
25
+ *
26
+ * @return {boolean} - True if the filter was parsed successfully, false otherwise.
27
+ */
28
+ parseFilter(pFilterString, pQuery)
29
+ {
30
+ return parse(pFilterString, pQuery);
31
+ }
32
32
  }
33
33
 
34
34
  module.exports = MeadowEndpointsFilterParser;
@@ -1,52 +1,52 @@
1
1
  class MeadowEndpointsSessionMarshaler
2
2
  {
3
- /**
4
- * @param {import('../Meadow-Endpoints-Controller-Base.js')} pController
5
- */
6
- constructor(pController)
3
+ /**
4
+ * @param {import('../Meadow-Endpoints-Controller-Base.js')} pController
5
+ */
6
+ constructor(pController)
7
7
  {
8
- this._Controller = pController;
9
- }
8
+ this._Controller = pController;
9
+ }
10
10
 
11
- getSessionData(pRequest)
12
- {
13
- let tmpSession = Object.assign({}, this._Controller.settings.MeadowEndpointsDefaultSessionObject);
14
- let tmpHeaderSessionString;
11
+ getSessionData(pRequest)
12
+ {
13
+ let tmpSession = Object.assign({}, this._Controller.settings.MeadowEndpointsDefaultSessionObject);
14
+ let tmpHeaderSessionString;
15
15
 
16
- switch (this._Controller.settings.MeadowEndpointsSessionDataSource || 'Request')
17
- {
18
- default:
19
- this._Controller.log.warn(`Unknown session source configured: ${this._Controller.settings.MeadowEndpointsSessionDataSource} - defaulting to Request for backward compatibility`);
20
- case 'Request':
21
- // noop - already set by orator-session
22
- tmpSession = this._Controller.extend(tmpSession, pRequest.UserSession);
23
- break;
24
- case 'None':
25
- break;
26
- case 'Header':
27
- try
28
- {
29
- tmpHeaderSessionString = pRequest.headers['x-trusted-session'];
30
- if (!tmpHeaderSessionString)
31
- {
32
- break;
33
- }
34
- const tmpHeaderSession = JSON.parse(tmpHeaderSessionString);
35
- tmpSession = this._Controller.extend(tmpSession, tmpHeaderSession);
36
- }
37
- catch (pError)
38
- {
39
- this._Controller.log.error(`Meadow Endpoints attempted to process a Header Session String with value [${tmpHeaderSessionString}] and failed -- likely culprit is bad JSON.`)
40
- }
41
- break;
42
- }
16
+ switch (this._Controller.settings.MeadowEndpointsSessionDataSource || 'Request')
17
+ {
18
+ default:
19
+ this._Controller.log.warn(`Unknown session source configured: ${this._Controller.settings.MeadowEndpointsSessionDataSource} - defaulting to Request for backward compatibility`);
20
+ case 'Request':
21
+ // noop - already set by orator-session
22
+ tmpSession = this._Controller.extend(tmpSession, pRequest.UserSession);
23
+ break;
24
+ case 'None':
25
+ break;
26
+ case 'Header':
27
+ try
28
+ {
29
+ tmpHeaderSessionString = pRequest.headers['x-trusted-session'];
30
+ if (!tmpHeaderSessionString)
31
+ {
32
+ break;
33
+ }
34
+ const tmpHeaderSession = JSON.parse(tmpHeaderSessionString);
35
+ tmpSession = this._Controller.extend(tmpSession, tmpHeaderSession);
36
+ }
37
+ catch (pError)
38
+ {
39
+ this._Controller.log.error(`Meadow Endpoints attempted to process a Header Session String with value [${tmpHeaderSessionString}] and failed -- likely culprit is bad JSON.`)
40
+ }
41
+ break;
42
+ }
43
43
 
44
- // Do we keep this here for backwards compatibility?
45
- // Yes this makes sense here.
46
- pRequest.UserSession = tmpSession;
44
+ // Do we keep this here for backwards compatibility?
45
+ // Yes this makes sense here.
46
+ pRequest.UserSession = tmpSession;
47
47
 
48
- return tmpSession;
49
- }
48
+ return tmpSession;
49
+ }
50
50
  }
51
51
 
52
52
  module.exports = MeadowEndpointsSessionMarshaler;
@@ -6,13 +6,13 @@ const JSONStream = require('JSONStream');
6
6
 
7
7
  class MeadowEndpointsStreamRecordArray
8
8
  {
9
- /**
10
- * @param {import('../Meadow-Endpoints-Controller-Base.js')} pController
11
- */
12
- constructor(pController)
9
+ /**
10
+ * @param {import('../Meadow-Endpoints-Controller-Base.js')} pController
11
+ */
12
+ constructor(pController)
13
13
  {
14
- this._Controller = pController;
15
- }
14
+ this._Controller = pController;
15
+ }
16
16
 
17
17
  chunk(pInput, pChunkSize, pChunkCache)
18
18
  {
@@ -19,7 +19,7 @@ const doCreate = function(pRecord, pRequest, pRequestState, pResponse, fCallback
19
19
  tmpRequestState.RecordToCreate = pRecord;
20
20
 
21
21
  //Make sure record gets created with a customerID
22
- if (!tmpRequestState.RecordToCreate.hasOwnProperty('IDCustomer') && this.DAL.jsonSchema.properties.hasOwnProperty('IDCustomer'))
22
+ if (!tmpRequestState.RecordToCreate.hasOwnProperty('IDCustomer') && this.DAL.jsonSchema && this.DAL.jsonSchema.properties && this.DAL.jsonSchema.properties.hasOwnProperty('IDCustomer'))
23
23
  {
24
24
  tmpRequestState.RecordToCreate.IDCustomer = tmpRequestState.SessionData.CustomerID || 0;
25
25
  }
@@ -27,7 +27,7 @@ const doAPIEndpointValidate = function(pRequest, pResponse, fNext)
27
27
  (fStageComplete) =>
28
28
  {
29
29
  pResponse.send(tmpRequestState.RecordValidation);
30
- this.log.requestCompletedSuccessfully(pRequest, tmpRequestState, `Validated Record for ${this.DAL.scope} - ${tmpRequestState.RecordValidation}`);
30
+ this.log.requestCompletedSuccessfully(pRequest, tmpRequestState, `Validated Record for ${this.DAL.scope} - ${JSON.stringify(tmpRequestState.RecordValidation)}`);
31
31
  return fStageComplete();
32
32
  }
33
33
  ],
@@ -23,6 +23,7 @@ const doAPIEndpointUpdate = function(pRequest, pResponse, fNext)
23
23
 
24
24
  return fStageComplete();
25
25
  },
26
+ fBehaviorInjector(`UpdateBulk-PreOperation`),
26
27
  (fStageComplete) =>
27
28
  {
28
29
  this.eachLimit(tmpRequestState.BulkRecords, 1,
@@ -31,6 +32,7 @@ const doAPIEndpointUpdate = function(pRequest, pResponse, fNext)
31
32
  doUpdate.call(this, pRecord, pRequest, tmpRequestState, pResponse, fCallback);
32
33
  }, fStageComplete);
33
34
  },
35
+ fBehaviorInjector(`UpdateBulk-PostOperation`),
34
36
  (fStageComplete) =>
35
37
  {
36
38
  return this.doStreamRecordArray(pResponse, tmpRequestState.UpdatedRecords, fStageComplete);
@@ -58,6 +58,7 @@ const doUpdate = function(pRecordToModify, pRequest, pRequestState, pResponse, f
58
58
  tmpRequestState.Query = this.DAL.query;
59
59
  return fStageComplete();
60
60
  },
61
+ fBehaviorInjector(`Update-PreOperation`),
61
62
  (fStageComplete) =>
62
63
  {
63
64
  tmpRequestState.Query.setIDUser(tmpRequestState.SessionData.UserID);
@@ -65,6 +66,7 @@ const doUpdate = function(pRecordToModify, pRequest, pRequestState, pResponse, f
65
66
 
66
67
  return fStageComplete();
67
68
  },
69
+ fBehaviorInjector(`Update-QueryConfiguration`),
68
70
  (fStageComplete) =>
69
71
  {
70
72
  this.DAL.doUpdate(tmpRequestState.Query,
@@ -28,6 +28,7 @@ const doAPIEndpointUpserts = function(pRequest, pResponse, fNext)
28
28
 
29
29
  return fStageComplete();
30
30
  },
31
+ fBehaviorInjector(`UpsertBulk-PreOperation`),
31
32
  (fStageComplete) =>
32
33
  {
33
34
  this.eachLimit(tmpRequestState.BulkRecords, 1,
@@ -36,13 +37,14 @@ const doAPIEndpointUpserts = function(pRequest, pResponse, fNext)
36
37
  doUpsert.call(this, pRecord, pRequest, tmpRequestState, pResponse, fCallback);
37
38
  }, fStageComplete);
38
39
  },
40
+ fBehaviorInjector(`UpsertBulk-PostOperation`),
39
41
  (fStageComplete) =>
40
42
  {
41
43
  return this.doStreamRecordArray(pResponse, marshalLiteList.call(this, tmpRequestState.UpsertedRecords, pRequest), fStageComplete);
42
44
  },
43
45
  (fStageComplete) =>
44
46
  {
45
- this.log.requestCompletedSuccessfully(pRequest, tmpRequestState, `Bulk upsert complete -- ${tmpRequestState.UpsertedRecords} records processed`);
47
+ this.log.requestCompletedSuccessfully(pRequest, tmpRequestState, `Bulk upsert complete -- ${tmpRequestState.UpsertedRecords.length} records processed`);
46
48
  return fStageComplete();
47
49
  }
48
50
  ], (pError) =>
@@ -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
- if (!tmpRequestState.Record.hasOwnProperty(this.DAL.defaultIdentifier))
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;