meadow-endpoints 3.0.7 → 4.0.3
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/Dockerfile_LUXURYCode +1 -1
- package/README.md +48 -14
- package/debug/Animal.json +62 -0
- package/debug/Harness-Configuration.json +31 -0
- package/debug/Harness.js +7 -108
- package/debug/KillHarness.sh +10 -0
- package/dist/meadowendpoints.js +4402 -0
- package/dist/meadowendpoints.min.js +92 -0
- package/dist/meadowendpoints.min.js.map +1 -0
- package/gulpfile.js +83 -0
- package/package.json +27 -15
- package/source/Controller/Meadow-Endpoints-Controller-Base.js +161 -0
- package/source/Controller/components/Meadow-Endpoints-Controller-BehaviorInjection.js +125 -0
- package/source/Controller/components/Meadow-Endpoints-Controller-Error-StatusCodes.txt +189 -0
- package/source/Controller/components/Meadow-Endpoints-Controller-Error.js +118 -0
- package/source/Controller/components/Meadow-Endpoints-Controller-Log.js +103 -0
- package/source/Controller/utility/Meadow-Endpoints-Filter-Parser.js +225 -0
- package/source/Controller/utility/Meadow-Endpoints-Session-Marshaler.js +48 -0
- package/source/Controller/utility/Meadow-Endpoints-Stream-RecordArray.js +66 -0
- package/source/Meadow-Endpoints-Browser-Shim.js +14 -0
- package/source/Meadow-Endpoints.js +176 -565
- package/source/endpoints/count/Meadow-Endpoint-Count.js +49 -0
- package/source/endpoints/count/Meadow-Endpoint-CountBy.js +40 -0
- package/source/endpoints/create/Meadow-Endpoint-BulkCreate.js +53 -0
- package/source/endpoints/create/Meadow-Endpoint-Create.js +58 -0
- package/source/endpoints/create/Meadow-Operation-Create.js +83 -0
- package/source/endpoints/delete/Meadow-Endpoint-Delete.js +93 -0
- package/source/endpoints/delete/Meadow-Endpoint-Undelete.js +108 -0
- package/source/endpoints/read/Meadow-Endpoint-Read.js +72 -0
- package/source/endpoints/read/Meadow-Endpoint-ReadDistinctList.js +92 -0
- package/source/endpoints/read/Meadow-Endpoint-ReadLiteList.js +85 -0
- package/source/endpoints/read/Meadow-Endpoint-ReadMax.js +55 -0
- package/source/endpoints/read/Meadow-Endpoint-ReadSelectList.js +89 -0
- package/source/endpoints/read/Meadow-Endpoint-Reads.js +75 -0
- package/source/endpoints/read/Meadow-Endpoint-ReadsBy.js +100 -0
- package/source/{crud → endpoints/read}/Meadow-Marshal-DistinctList.js +4 -13
- package/source/{crud → endpoints/read}/Meadow-Marshal-LiteList.js +5 -14
- package/source/endpoints/schema/Meadow-Endpoint-New.js +36 -0
- package/source/endpoints/schema/Meadow-Endpoint-Schema.js +36 -0
- package/source/endpoints/schema/Meadow-Endpoint-Validate.js +41 -0
- package/source/endpoints/update/Meadow-Endpoint-BulkUpdate.js +50 -0
- package/source/endpoints/update/Meadow-Endpoint-Update.js +58 -0
- package/source/endpoints/update/Meadow-Operation-Update.js +115 -0
- package/source/endpoints/upsert/Meadow-Endpoint-BulkUpsert.js +53 -0
- package/source/endpoints/upsert/Meadow-Endpoint-Upsert.js +58 -0
- package/source/endpoints/upsert/Meadow-Operation-Upsert.js +132 -0
- package/test/MeadowEndpoints_basic_tests.js +50 -2408
- package/test_support/bookstore-api-endpoint-exercises.paw +0 -0
- package/test_support/bookstore-configuration.json +28 -0
- package/test_support/bookstore-import-books-run.js +1 -0
- package/test_support/bookstore-import-books.js +215 -0
- package/test_support/bookstore-serve-meadow-endpoint-apis-IPC.js +138 -0
- package/test_support/bookstore-serve-meadow-endpoint-apis-run.js +6 -0
- package/test_support/bookstore-serve-meadow-endpoint-apis.js +129 -0
- package/test_support/data/books.csv +10001 -0
- package/test_support/model/ddl/BookStore.ddl +66 -0
- package/test_support/model/generated_diagram/README.md +1 -0
- package/test_support/model/generated_diagram/Stricture_Output.dot +13 -0
- package/test_support/model/generated_diagram/Stricture_Output.png +0 -0
- package/test_support/model/generated_documentation/Dictionary.md +18 -0
- package/test_support/model/generated_documentation/Model-Author.md +20 -0
- package/test_support/model/generated_documentation/Model-Book.md +26 -0
- package/test_support/model/generated_documentation/Model-BookAuthorJoin.md +14 -0
- package/test_support/model/generated_documentation/Model-BookPrice.md +25 -0
- package/test_support/model/generated_documentation/Model-Review.md +22 -0
- package/test_support/model/generated_documentation/ModelChangeTracking.md +17 -0
- package/test_support/model/generated_documentation/README.md +1 -0
- package/test_support/model/manual_scripts/DropTables.sql +5 -0
- package/test_support/model/manual_scripts/README.md +2 -0
- package/test_support/model/sql_create/BookStore-CreateDatabase.mysql.sql +116 -0
- package/test_support/model/sql_create/README.md +1 -0
- package/test_support/test_old/Tests.js +3243 -0
- package/test_support/test_old/untitled.js +88 -0
- package/source/Meadow-Authenticator.js +0 -31
- package/source/Meadow-Authorizers.js +0 -214
- package/source/Meadow-BehaviorModifications.js +0 -170
- package/source/Meadow-CommonServices.js +0 -206
- package/source/Meadow-MarshallSessionData.js +0 -64
- package/source/Restify-RouteParser.js +0 -114
- package/source/authorizers/Meadow-Authorizer-Allow.js +0 -17
- package/source/authorizers/Meadow-Authorizer-Deny.js +0 -17
- package/source/authorizers/Meadow-Authorizer-Mine.js +0 -47
- package/source/authorizers/Meadow-Authorizer-MyCustomer.js +0 -48
- package/source/crud/Meadow-Endpoint-BulkCreate.js +0 -67
- package/source/crud/Meadow-Endpoint-BulkUpdate.js +0 -74
- package/source/crud/Meadow-Endpoint-BulkUpsert.js +0 -76
- package/source/crud/Meadow-Endpoint-Count.js +0 -93
- package/source/crud/Meadow-Endpoint-CountBy.js +0 -101
- package/source/crud/Meadow-Endpoint-Create.js +0 -77
- package/source/crud/Meadow-Endpoint-Delete.js +0 -139
- package/source/crud/Meadow-Endpoint-Read.js +0 -109
- package/source/crud/Meadow-Endpoint-ReadDistinctList.js +0 -146
- package/source/crud/Meadow-Endpoint-ReadLiteList.js +0 -139
- package/source/crud/Meadow-Endpoint-ReadMax.js +0 -86
- package/source/crud/Meadow-Endpoint-ReadSelectList.js +0 -145
- package/source/crud/Meadow-Endpoint-Reads.js +0 -129
- package/source/crud/Meadow-Endpoint-ReadsBy.js +0 -155
- package/source/crud/Meadow-Endpoint-Undelete.js +0 -161
- package/source/crud/Meadow-Endpoint-Update.js +0 -80
- package/source/crud/Meadow-Endpoint-Upsert.js +0 -78
- package/source/crud/Meadow-Operation-Create.js +0 -105
- package/source/crud/Meadow-Operation-Update.js +0 -145
- package/source/crud/Meadow-Operation-Upsert.js +0 -106
- package/source/crud/Meadow-StreamRecordArray.js +0 -45
- package/source/schema/Meadow-Endpoint-New.js +0 -37
- package/source/schema/Meadow-Endpoint-Schema.js +0 -37
- package/source/schema/Meadow-Endpoint-Validate.js +0 -43
- package/test/Animal.json +0 -140
- package/test/MeadowEndpoints_disabledAuth_tests.js +0 -1325
- package/test/MeadowEndpoints_trustedSession_tests.js +0 -1731
- package/test/load/artillery-low.yml +0 -10
- package/test/load/cloud9setup.sh +0 -25
- package/test/load/package.json +0 -19
- package/test/load/test-schema-initializedatabase.sql +0 -29
- package/test/load/test-schema.json +0 -119
- package/test/load/test-server.js +0 -157
- package/test/scripts/InitializeDatabase-C9.sql +0 -7
- /package/{test/schemas → test_support/model}/json_schema/BookStore-Extended.json +0 -0
- /package/{test/schemas → test_support/model}/json_schema/BookStore-PICT.json +0 -0
- /package/{test/schemas → test_support/model}/json_schema/BookStore.json +0 -0
- /package/{test/schemas → test_support/model}/json_schema/README.md +0 -0
- /package/{test/schemas → test_support/model}/meadow_schema/BookStore-MeadowSchema-Author.json +0 -0
- /package/{test/schemas → test_support/model}/meadow_schema/BookStore-MeadowSchema-Book.json +0 -0
- /package/{test/schemas → test_support/model}/meadow_schema/BookStore-MeadowSchema-BookAuthorJoin.json +0 -0
- /package/{test/schemas → test_support/model}/meadow_schema/BookStore-MeadowSchema-BookPrice.json +0 -0
- /package/{test/schemas → test_support/model}/meadow_schema/BookStore-MeadowSchema-Review.json +0 -0
- /package/{test/schemas → test_support/model}/meadow_schema/README.md +0 -0
|
@@ -1,139 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Meadow Endpoint - Read a list of lite Records (for Drop-downs and such)
|
|
3
|
-
*
|
|
4
|
-
* @license MIT
|
|
5
|
-
*
|
|
6
|
-
* @author Steven Velozo <steven@velozo.com>
|
|
7
|
-
* @module Meadow
|
|
8
|
-
*/
|
|
9
|
-
var libAsync = require('async');
|
|
10
|
-
const meadowFilterParser = require('meadow-filter').parse;
|
|
11
|
-
var marshalLiteList = require('./Meadow-Marshal-LiteList.js');
|
|
12
|
-
const streamRecordsToResponse = require('./Meadow-StreamRecordArray');
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
* Get a set of records from a DAL.
|
|
16
|
-
*/
|
|
17
|
-
var doAPIReadLiteEndpoint = function(pRequest, pResponse, fNext)
|
|
18
|
-
{
|
|
19
|
-
// This state is the requirement for the UserRoleIndex value in the UserSession object... processed by default as >=
|
|
20
|
-
// The default here is that any authenticated user can use this endpoint.
|
|
21
|
-
pRequest.EndpointAuthorizationRequirement = pRequest.EndpointAuthorizationLevels.Reads;
|
|
22
|
-
|
|
23
|
-
// INJECT: Pre authorization (for instance to change the authorization level)
|
|
24
|
-
|
|
25
|
-
if (pRequest.CommonServices.authorizeEndpoint(pRequest, pResponse, fNext) === false)
|
|
26
|
-
{
|
|
27
|
-
// If this endpoint fails, it's sent an error automatically.
|
|
28
|
-
return;
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
libAsync.waterfall(
|
|
32
|
-
[
|
|
33
|
-
// 1a. Get the records
|
|
34
|
-
function (fStageComplete)
|
|
35
|
-
{
|
|
36
|
-
pRequest.Query = pRequest.DAL.query;
|
|
37
|
-
// TODO: Limit the query to the columns we need for the templated expression
|
|
38
|
-
|
|
39
|
-
var tmpCap = false;
|
|
40
|
-
var tmpBegin = false;
|
|
41
|
-
if (typeof(pRequest.params.Begin) === 'string' ||
|
|
42
|
-
typeof(pRequest.params.Begin) === 'number')
|
|
43
|
-
{
|
|
44
|
-
tmpBegin = parseInt(pRequest.params.Begin, 10);
|
|
45
|
-
}
|
|
46
|
-
if (typeof(pRequest.params.Cap) === 'string' ||
|
|
47
|
-
typeof(pRequest.params.Cap) === 'number')
|
|
48
|
-
{
|
|
49
|
-
tmpCap = parseInt(pRequest.params.Cap, 10);
|
|
50
|
-
}
|
|
51
|
-
else
|
|
52
|
-
{
|
|
53
|
-
//maximum number of records to return by default on Read queries. Override via "MeadowDefaultMaxCap" fable setting.
|
|
54
|
-
tmpCap = pRequest.DEFAULT_MAX_CAP;
|
|
55
|
-
}
|
|
56
|
-
pRequest.Query.setCap(tmpCap).setBegin(tmpBegin);
|
|
57
|
-
if (typeof(pRequest.params.Filter) === 'string')
|
|
58
|
-
{
|
|
59
|
-
// If a filter has been passed in, parse it and add the values to the query.
|
|
60
|
-
meadowFilterParser(pRequest.params.Filter, pRequest.Query);
|
|
61
|
-
}
|
|
62
|
-
else if (pRequest.params.Filter)
|
|
63
|
-
{
|
|
64
|
-
pRequest.Query.setFilter(pRequest.params.Filter);
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
fStageComplete(false);
|
|
68
|
-
},
|
|
69
|
-
// 1b. INJECT: Query configuration
|
|
70
|
-
function (fStageComplete)
|
|
71
|
-
{
|
|
72
|
-
pRequest.BehaviorModifications.runBehavior('Reads-QueryConfiguration', pRequest, fStageComplete);
|
|
73
|
-
},
|
|
74
|
-
// 1b2. INJECT: Query pre-authorization behavior (ex. if authorizer needs fields to be included, it can add them)
|
|
75
|
-
function (fStageComplete)
|
|
76
|
-
{
|
|
77
|
-
pRequest.BehaviorModifications.runBehavior('Reads-PreAuth', pRequest, fStageComplete);
|
|
78
|
-
},
|
|
79
|
-
// 1c. Do the record read
|
|
80
|
-
function (fStageComplete)
|
|
81
|
-
{
|
|
82
|
-
pRequest.DAL.doReads(pRequest.Query, fStageComplete);
|
|
83
|
-
},
|
|
84
|
-
// 2. Post processing of the records
|
|
85
|
-
function (pQuery, pRecords, fStageComplete)
|
|
86
|
-
{
|
|
87
|
-
if (pRecords.length < 1)
|
|
88
|
-
{
|
|
89
|
-
pRecords = [];
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
pRequest.Records = pRecords;
|
|
93
|
-
|
|
94
|
-
// Complete the waterfall operation
|
|
95
|
-
fStageComplete(false);
|
|
96
|
-
},
|
|
97
|
-
// 2.5: Check if there is an authorizer set for this endpoint and user role combination, and authorize based on that
|
|
98
|
-
function (fStageComplete)
|
|
99
|
-
{
|
|
100
|
-
// shared permission with reads
|
|
101
|
-
pRequest.Authorizers.authorizeRequest('Reads', pRequest, fStageComplete);
|
|
102
|
-
},
|
|
103
|
-
// 2.6: Check if authorization or post processing denied security access to the record
|
|
104
|
-
function (fStageComplete)
|
|
105
|
-
{
|
|
106
|
-
if (pRequest.MeadowAuthorization)
|
|
107
|
-
{
|
|
108
|
-
return fStageComplete(false);
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
// It looks like this record was not authorized. Send an error.
|
|
112
|
-
return fStageComplete({Code:405,Message:'UNAUTHORIZED ACCESS IS NOT ALLOWED'});
|
|
113
|
-
},
|
|
114
|
-
// 3. Marshalling of records into the hash list, using underscore templates.
|
|
115
|
-
function (fStageComplete)
|
|
116
|
-
{
|
|
117
|
-
// Allow the endpoint to pass in extra columns.
|
|
118
|
-
// Break it apart by comma separated list
|
|
119
|
-
fStageComplete(false, marshalLiteList(pRequest.Records, pRequest, (typeof(pRequest.params.ExtraColumns) === 'string') ? pRequest.params.ExtraColumns.split(',') : []));
|
|
120
|
-
}
|
|
121
|
-
],
|
|
122
|
-
// 3. Return the results to the user
|
|
123
|
-
function(pError, pResultRecords)
|
|
124
|
-
{
|
|
125
|
-
// Remove 'Records' object from pRequest, instead return template results (pResultRecords) for the records
|
|
126
|
-
delete pRequest['Records'];
|
|
127
|
-
|
|
128
|
-
if (pError)
|
|
129
|
-
{
|
|
130
|
-
return pRequest.CommonServices.sendCodedError('Error retreiving a recordset.', pError, pRequest, pResponse, fNext);
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
pRequest.CommonServices.log.info('Read a recordset lite list with '+pResultRecords.length+' results.', {SessionID:pRequest.UserSession.SessionID, RequestID:pRequest.RequestUUID, RequestURL:pRequest.url, Action:pRequest.DAL.scope+'-ReadLite'}, pRequest);
|
|
134
|
-
return streamRecordsToResponse(pResponse, pResultRecords, fNext);
|
|
135
|
-
}
|
|
136
|
-
);
|
|
137
|
-
};
|
|
138
|
-
|
|
139
|
-
module.exports = doAPIReadLiteEndpoint;
|
|
@@ -1,86 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Meadow Endpoint - Read the Max Value of a Column in a Set
|
|
3
|
-
*
|
|
4
|
-
* @license MIT
|
|
5
|
-
*
|
|
6
|
-
* @author Steven Velozo <steven@velozo.com>
|
|
7
|
-
* @module Meadow
|
|
8
|
-
*/
|
|
9
|
-
var libAsync = require('async');
|
|
10
|
-
/**
|
|
11
|
-
* Get a specific record from a DAL.
|
|
12
|
-
*/
|
|
13
|
-
var doAPIReadEndpoint = function(pRequest, pResponse, fNext)
|
|
14
|
-
{
|
|
15
|
-
// This state is the requirement for the UserRoleIndex value in the UserSession object... processed by default as >=
|
|
16
|
-
// The default here is that any authenticated user can use this endpoint.
|
|
17
|
-
pRequest.EndpointAuthorizationRequirement = pRequest.EndpointAuthorizationLevels.Read;
|
|
18
|
-
|
|
19
|
-
if (pRequest.CommonServices.authorizeEndpoint(pRequest, pResponse, fNext) === false)
|
|
20
|
-
{
|
|
21
|
-
// If this endpoint fails, it's sent an error automatically.
|
|
22
|
-
return;
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
libAsync.waterfall(
|
|
26
|
-
[
|
|
27
|
-
// 1. Create the query
|
|
28
|
-
function (fStageComplete)
|
|
29
|
-
{
|
|
30
|
-
pRequest.Query = pRequest.DAL.query;
|
|
31
|
-
fStageComplete(false);
|
|
32
|
-
},
|
|
33
|
-
// 2. Set the query up with the Column Name
|
|
34
|
-
function (fStageComplete)
|
|
35
|
-
{
|
|
36
|
-
var tmpColumnName = pRequest.params.ColumnName;
|
|
37
|
-
// We use a custon name for this (RequestDefaultIdentifier) in case there is a query with a dot in the default identifier.
|
|
38
|
-
pRequest.Query.setSort({Column:tmpColumnName, Direction:'Descending'});
|
|
39
|
-
pRequest.Query.setCap(1);
|
|
40
|
-
|
|
41
|
-
fStageComplete(false);
|
|
42
|
-
},
|
|
43
|
-
// 3. INJECT: Query configuration
|
|
44
|
-
function (fStageComplete)
|
|
45
|
-
{
|
|
46
|
-
pRequest.BehaviorModifications.runBehavior('ReadMax-QueryConfiguration', pRequest, fStageComplete);
|
|
47
|
-
},
|
|
48
|
-
// 4. Execute the query
|
|
49
|
-
function (fStageComplete)
|
|
50
|
-
{
|
|
51
|
-
pRequest.DAL.doRead(pRequest.Query, fStageComplete);
|
|
52
|
-
},
|
|
53
|
-
// 5. Post processing of the records
|
|
54
|
-
function (pQuery, pRecord, fStageComplete)
|
|
55
|
-
{
|
|
56
|
-
if (!pRecord)
|
|
57
|
-
{
|
|
58
|
-
pRequest.CommonServices.log.info('Record not found', {SessionID:pRequest.UserSession.SessionID, RequestID:pRequest.RequestUUID, RequestURL:pRequest.url, Action:pRequest.DAL.scope+'-ReadMax'}, pRequest);
|
|
59
|
-
return pResponse.send({});
|
|
60
|
-
}
|
|
61
|
-
pRequest.Record = pRecord;
|
|
62
|
-
fStageComplete(false);
|
|
63
|
-
},
|
|
64
|
-
// 6. INJECT: Post process the record, tacking on or altering anything we want to.
|
|
65
|
-
function (fStageComplete)
|
|
66
|
-
{
|
|
67
|
-
// This will also complete the waterfall operation
|
|
68
|
-
pRequest.BehaviorModifications.runBehavior('ReadMax-PostOperation', pRequest, fStageComplete);
|
|
69
|
-
}
|
|
70
|
-
],
|
|
71
|
-
// 3. Return the results to the user
|
|
72
|
-
function(pError)
|
|
73
|
-
{
|
|
74
|
-
if (pError)
|
|
75
|
-
{
|
|
76
|
-
return pRequest.CommonServices.sendError('Error retreiving a record.', pRequest, pResponse, fNext);
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
pRequest.CommonServices.log.info('Read top record of '+pRequest.params.IDRecord+'.', {SessionID:pRequest.UserSession.SessionID, RequestID:pRequest.RequestUUID, RequestURL:pRequest.url, Action:pRequest.DAL.scope+'-ReadMax'}, pRequest);
|
|
80
|
-
pResponse.send(pRequest.Record);
|
|
81
|
-
return fNext();
|
|
82
|
-
}
|
|
83
|
-
);
|
|
84
|
-
};
|
|
85
|
-
|
|
86
|
-
module.exports = doAPIReadEndpoint;
|
|
@@ -1,145 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Meadow Endpoint - Read a select list of Records (for Drop-downs and such)
|
|
3
|
-
*
|
|
4
|
-
* @license MIT
|
|
5
|
-
*
|
|
6
|
-
* @author Steven Velozo <steven@velozo.com>
|
|
7
|
-
* @module Meadow
|
|
8
|
-
*/
|
|
9
|
-
var libAsync = require('async');
|
|
10
|
-
const meadowFilterParser = require('meadow-filter').parse;
|
|
11
|
-
const streamRecordsToResponse = require('./Meadow-StreamRecordArray');
|
|
12
|
-
|
|
13
|
-
/**
|
|
14
|
-
* Get a set of records from a DAL.
|
|
15
|
-
*/
|
|
16
|
-
var doAPIReadSelectListEndpoint = function(pRequest, pResponse, fNext)
|
|
17
|
-
{
|
|
18
|
-
// This state is the requirement for the UserRoleIndex value in the UserSession object... processed by default as >=
|
|
19
|
-
// The default here is that any authenticated user can use this endpoint.
|
|
20
|
-
pRequest.EndpointAuthorizationRequirement = pRequest.EndpointAuthorizationLevels.Reads;
|
|
21
|
-
|
|
22
|
-
// INJECT: Pre authorization (for instance to change the authorization level)
|
|
23
|
-
|
|
24
|
-
if (pRequest.CommonServices.authorizeEndpoint(pRequest, pResponse, fNext) === false)
|
|
25
|
-
{
|
|
26
|
-
// If this endpoint fails, it's sent an error automatically.
|
|
27
|
-
return;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
libAsync.waterfall(
|
|
31
|
-
[
|
|
32
|
-
// 1a. Get the records
|
|
33
|
-
function (fStageComplete)
|
|
34
|
-
{
|
|
35
|
-
pRequest.Query = pRequest.DAL.query;
|
|
36
|
-
// TODO: Limit the query to the columns we need for the templated expression
|
|
37
|
-
|
|
38
|
-
var tmpCap = false;
|
|
39
|
-
var tmpBegin = false;
|
|
40
|
-
if (typeof(pRequest.params.Begin) === 'string' ||
|
|
41
|
-
typeof(pRequest.params.Begin) === 'number')
|
|
42
|
-
{
|
|
43
|
-
tmpBegin = parseInt(pRequest.params.Begin);
|
|
44
|
-
}
|
|
45
|
-
if (typeof(pRequest.params.Cap) === 'string' ||
|
|
46
|
-
typeof(pRequest.params.Cap) === 'number')
|
|
47
|
-
{
|
|
48
|
-
tmpCap = parseInt(pRequest.params.Cap);
|
|
49
|
-
}
|
|
50
|
-
else
|
|
51
|
-
{
|
|
52
|
-
//maximum number of records to return by default on Read queries. Override via "MeadowDefaultMaxCap" fable setting.
|
|
53
|
-
tmpCap = pRequest.DEFAULT_MAX_CAP;
|
|
54
|
-
}
|
|
55
|
-
pRequest.Query.setCap(tmpCap).setBegin(tmpBegin);
|
|
56
|
-
if (typeof(pRequest.params.Filter) === 'string')
|
|
57
|
-
{
|
|
58
|
-
// If a filter has been passed in, parse it and add the values to the query.
|
|
59
|
-
meadowFilterParser(pRequest.params.Filter, pRequest.Query);
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
fStageComplete(false);
|
|
63
|
-
},
|
|
64
|
-
// 1b. INJECT: Query configuration
|
|
65
|
-
function (fStageComplete)
|
|
66
|
-
{
|
|
67
|
-
pRequest.BehaviorModifications.runBehavior('Reads-QueryConfiguration', pRequest, fStageComplete);
|
|
68
|
-
},
|
|
69
|
-
// 1b2. INJECT: Query pre-authorization behavior (ex. if authorizer needs fields to be included, it can add them)
|
|
70
|
-
function (fStageComplete)
|
|
71
|
-
{
|
|
72
|
-
pRequest.BehaviorModifications.runBehavior('Reads-PreAuth', pRequest, fStageComplete);
|
|
73
|
-
},
|
|
74
|
-
// 1c. Do the record read
|
|
75
|
-
function (fStageComplete)
|
|
76
|
-
{
|
|
77
|
-
pRequest.DAL.doReads(pRequest.Query, fStageComplete);
|
|
78
|
-
},
|
|
79
|
-
// 2. Post processing of the records
|
|
80
|
-
function (pQuery, pRecords, fStageComplete)
|
|
81
|
-
{
|
|
82
|
-
if (pRecords.length < 1)
|
|
83
|
-
{
|
|
84
|
-
pRecords = [];
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
pRequest.Records = pRecords;
|
|
88
|
-
|
|
89
|
-
// Complete the waterfall operation
|
|
90
|
-
fStageComplete(false);
|
|
91
|
-
},
|
|
92
|
-
// 2.5: Check if there is an authorizer set for this endpoint and user role combination, and authorize based on that
|
|
93
|
-
function (fStageComplete)
|
|
94
|
-
{
|
|
95
|
-
pRequest.Authorizers.authorizeRequest('ReadSelectList', pRequest, fStageComplete);
|
|
96
|
-
},
|
|
97
|
-
// 2.6: Check if authorization or post processing denied security access to the record
|
|
98
|
-
function (fStageComplete)
|
|
99
|
-
{
|
|
100
|
-
if (pRequest.MeadowAuthorization)
|
|
101
|
-
{
|
|
102
|
-
return fStageComplete(false);
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
// It looks like this record was not authorized. Send an error.
|
|
106
|
-
return fStageComplete({Code:405,Message:'UNAUTHORIZED ACCESS IS NOT ALLOWED'});
|
|
107
|
-
},
|
|
108
|
-
// 3. Marshalling of records into the hash list, using underscore templates.
|
|
109
|
-
function (fStageComplete)
|
|
110
|
-
{
|
|
111
|
-
// Look on the Endpoint Customization object for an underscore template to generate hashes.
|
|
112
|
-
var tmpSelectList = [];
|
|
113
|
-
|
|
114
|
-
for (var i = 0; i < pRequest.Records.length; i++)
|
|
115
|
-
{
|
|
116
|
-
tmpSelectList.push
|
|
117
|
-
(
|
|
118
|
-
{
|
|
119
|
-
Hash: pRequest.Records[i][pRequest.DAL.defaultIdentifier],
|
|
120
|
-
Value: pRequest.BehaviorModifications.processTemplate('SelectList', {Record:pRequest.Records[i]}, pRequest.DAL.scope+' #<%= Record.'+pRequest.DAL.defaultIdentifier+'%>')
|
|
121
|
-
}
|
|
122
|
-
);
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
fStageComplete(false, tmpSelectList);
|
|
126
|
-
}
|
|
127
|
-
],
|
|
128
|
-
// 3. Return the results to the user
|
|
129
|
-
function(pError, pResultRecords)
|
|
130
|
-
{
|
|
131
|
-
// Remove 'Records' object from pRequest, instead return template results (pResultRecords) for the records
|
|
132
|
-
delete pRequest['Records'];
|
|
133
|
-
|
|
134
|
-
if (pError)
|
|
135
|
-
{
|
|
136
|
-
return pRequest.CommonServices.sendCodedError('Error retreiving a recordset.', pError, pRequest, pResponse, fNext);
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
pRequest.CommonServices.log.info('Read a recordset select list with '+pResultRecords.length+' results.', {SessionID:pRequest.UserSession.SessionID, RequestID:pRequest.RequestUUID, RequestURL:pRequest.url, Action:pRequest.DAL.scope+'-ReadSelectList'}, pRequest);
|
|
140
|
-
return streamRecordsToResponse(pResponse, pResultRecords, fNext);
|
|
141
|
-
}
|
|
142
|
-
);
|
|
143
|
-
};
|
|
144
|
-
|
|
145
|
-
module.exports = doAPIReadSelectListEndpoint;
|
|
@@ -1,129 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Meadow Endpoint - Read a Set of Records
|
|
3
|
-
*
|
|
4
|
-
* @license MIT
|
|
5
|
-
*
|
|
6
|
-
* @author Steven Velozo <steven@velozo.com>
|
|
7
|
-
* @module Meadow
|
|
8
|
-
*/
|
|
9
|
-
var libAsync = require('async');
|
|
10
|
-
const meadowFilterParser = require('meadow-filter').parse;
|
|
11
|
-
const streamRecordsToResponse = require('./Meadow-StreamRecordArray');
|
|
12
|
-
|
|
13
|
-
/**
|
|
14
|
-
* Get a set of records from a DAL.
|
|
15
|
-
*/
|
|
16
|
-
var doAPIReadsEndpoint = function(pRequest, pResponse, fNext)
|
|
17
|
-
{
|
|
18
|
-
// This state is the requirement for the UserRoleIndex value in the UserSession object... processed by default as >=
|
|
19
|
-
// The default here is that any authenticated user can use this endpoint.
|
|
20
|
-
pRequest.EndpointAuthorizationRequirement = pRequest.EndpointAuthorizationLevels.Reads;
|
|
21
|
-
|
|
22
|
-
if (pRequest.CommonServices.authorizeEndpoint(pRequest, pResponse, fNext) === false)
|
|
23
|
-
{
|
|
24
|
-
// If this endpoint fails, it's sent an error automatically.
|
|
25
|
-
return;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
libAsync.waterfall(
|
|
29
|
-
[
|
|
30
|
-
// 1. Construct the Query
|
|
31
|
-
function (fStageComplete)
|
|
32
|
-
{
|
|
33
|
-
pRequest.Query = pRequest.DAL.query;
|
|
34
|
-
|
|
35
|
-
var tmpCap = false;
|
|
36
|
-
var tmpBegin = false;
|
|
37
|
-
if (typeof(pRequest.params.Begin) === 'string' ||
|
|
38
|
-
typeof(pRequest.params.Begin) === 'number')
|
|
39
|
-
{
|
|
40
|
-
tmpBegin = parseInt(pRequest.params.Begin);
|
|
41
|
-
}
|
|
42
|
-
if (typeof(pRequest.params.Cap) === 'string' ||
|
|
43
|
-
typeof(pRequest.params.Cap) === 'number')
|
|
44
|
-
{
|
|
45
|
-
tmpCap = parseInt(pRequest.params.Cap);
|
|
46
|
-
}
|
|
47
|
-
else
|
|
48
|
-
{
|
|
49
|
-
//maximum number of records to return by default on Read queries. Override via "MeadowDefaultMaxCap" fable setting.
|
|
50
|
-
tmpCap = pRequest.DEFAULT_MAX_CAP;
|
|
51
|
-
}
|
|
52
|
-
pRequest.Query.setCap(tmpCap).setBegin(tmpBegin);
|
|
53
|
-
if (typeof(pRequest.params.Filter) === 'string')
|
|
54
|
-
{
|
|
55
|
-
// If a filter has been passed in, parse it and add the values to the query.
|
|
56
|
-
meadowFilterParser(pRequest.params.Filter, pRequest.Query);
|
|
57
|
-
}
|
|
58
|
-
else if (pRequest.params.Filter)
|
|
59
|
-
{
|
|
60
|
-
pRequest.Query.setFilter(pRequest.params.Filter);
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
fStageComplete(false);
|
|
64
|
-
},
|
|
65
|
-
// 2. INJECT: Query configuration
|
|
66
|
-
function (fStageComplete)
|
|
67
|
-
{
|
|
68
|
-
pRequest.BehaviorModifications.runBehavior('Reads-QueryConfiguration', pRequest, fStageComplete);
|
|
69
|
-
},
|
|
70
|
-
// 2b. INJECT: Query pre-authorization behavior (ex. if authorizer needs fields to be included, it can add them)
|
|
71
|
-
function (fStageComplete)
|
|
72
|
-
{
|
|
73
|
-
pRequest.BehaviorModifications.runBehavior('Reads-PreAuth', pRequest, fStageComplete);
|
|
74
|
-
},
|
|
75
|
-
// 3. Execute the query
|
|
76
|
-
function (fStageComplete)
|
|
77
|
-
{
|
|
78
|
-
pRequest.DAL.doReads(pRequest.Query, fStageComplete);
|
|
79
|
-
},
|
|
80
|
-
// 4. Post processing of the records
|
|
81
|
-
function (pQuery, pRecords, fStageComplete)
|
|
82
|
-
{
|
|
83
|
-
if (!pRecords)
|
|
84
|
-
{
|
|
85
|
-
pRequest.CommonServices.log.info('Records not found', {SessionID:pRequest.UserSession.SessionID, RequestID:pRequest.RequestUUID, RequestURL:pRequest.url, Action:pRequest.DAL.scope+'-Reads'}, pRequest);
|
|
86
|
-
return fStageComplete('Records not found');
|
|
87
|
-
}
|
|
88
|
-
pRequest.Records = pRecords;
|
|
89
|
-
fStageComplete(false);
|
|
90
|
-
},
|
|
91
|
-
// 4.5: Check if there is an authorizer set for this endpoint and user role combination, and authorize based on that
|
|
92
|
-
function (fStageComplete)
|
|
93
|
-
{
|
|
94
|
-
pRequest.Authorizers.authorizeRequest('Reads', pRequest, fStageComplete);
|
|
95
|
-
},
|
|
96
|
-
// 5. INJECT: Post process the record, tacking on or altering anything we want to.
|
|
97
|
-
function (fStageComplete)
|
|
98
|
-
{
|
|
99
|
-
pRequest.BehaviorModifications.runBehavior('Reads-PostOperation', pRequest, fStageComplete);
|
|
100
|
-
},
|
|
101
|
-
// 5.5: Check if authorization or post processing denied security access to the record
|
|
102
|
-
function (fStageComplete)
|
|
103
|
-
{
|
|
104
|
-
if (pRequest.MeadowAuthorization)
|
|
105
|
-
{
|
|
106
|
-
// This will complete the waterfall operation
|
|
107
|
-
return fStageComplete(false);
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
// It looks like this record was not authorized. Send an error.
|
|
111
|
-
return fStageComplete({Code:405,Message:'UNAUTHORIZED ACCESS IS NOT ALLOWED'});
|
|
112
|
-
}
|
|
113
|
-
],
|
|
114
|
-
// 6. Return the results to the user
|
|
115
|
-
function(pError)
|
|
116
|
-
{
|
|
117
|
-
if (pError)
|
|
118
|
-
{
|
|
119
|
-
return pRequest.CommonServices.sendCodedError('Error retreiving records by value.', pError, pRequest, pResponse, fNext);
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
pRequest.CommonServices.log.info('Read a list of records.', {SessionID:pRequest.UserSession.SessionID, RequestID:pRequest.RequestUUID, RequestURL:pRequest.url, Action:pRequest.DAL.scope+'-Reads'}, pRequest);
|
|
123
|
-
|
|
124
|
-
streamRecordsToResponse(pResponse, pRequest.Records, fNext);
|
|
125
|
-
}
|
|
126
|
-
);
|
|
127
|
-
};
|
|
128
|
-
|
|
129
|
-
module.exports = doAPIReadsEndpoint;
|
|
@@ -1,155 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Meadow Endpoint - Read a Record
|
|
3
|
-
*
|
|
4
|
-
* @license MIT
|
|
5
|
-
*
|
|
6
|
-
* @author Steven Velozo <steven@velozo.com>
|
|
7
|
-
* @module Meadow
|
|
8
|
-
*/
|
|
9
|
-
var libAsync = require('async');
|
|
10
|
-
const streamRecordsToResponse = require('./Meadow-StreamRecordArray');
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* Get a specific record from a DAL.
|
|
14
|
-
*/
|
|
15
|
-
var doAPIReadsByEndpoint = function(pRequest, pResponse, fNext)
|
|
16
|
-
{
|
|
17
|
-
// This state is the requirement for the UserRoleIndex value in the UserSession object... processed by default as >=
|
|
18
|
-
// The default here is that any authenticated user can use this endpoint.
|
|
19
|
-
pRequest.EndpointAuthorizationRequirement = pRequest.EndpointAuthorizationLevels.Reads;
|
|
20
|
-
|
|
21
|
-
// INJECT: Pre authorization (for instance to change the authorization level)
|
|
22
|
-
|
|
23
|
-
if (pRequest.CommonServices.authorizeEndpoint(pRequest, pResponse, fNext) === false)
|
|
24
|
-
{
|
|
25
|
-
// If this endpoint fails, it's sent an error automatically.
|
|
26
|
-
return;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
// INJECT: Pre endpoint operation
|
|
30
|
-
|
|
31
|
-
libAsync.waterfall(
|
|
32
|
-
[
|
|
33
|
-
// 1. Construct the Query
|
|
34
|
-
function (fStageComplete)
|
|
35
|
-
{
|
|
36
|
-
pRequest.Query = pRequest.DAL.query;
|
|
37
|
-
|
|
38
|
-
var tmpCap = false;
|
|
39
|
-
var tmpBegin = false;
|
|
40
|
-
if (typeof(pRequest.params.Begin) === 'string' ||
|
|
41
|
-
typeof(pRequest.params.Begin) === 'number')
|
|
42
|
-
{
|
|
43
|
-
tmpBegin = parseInt(pRequest.params.Begin);
|
|
44
|
-
}
|
|
45
|
-
if (typeof(pRequest.params.Cap) === 'string' ||
|
|
46
|
-
typeof(pRequest.params.Cap) === 'number')
|
|
47
|
-
{
|
|
48
|
-
tmpCap = parseInt(pRequest.params.Cap);
|
|
49
|
-
}
|
|
50
|
-
else
|
|
51
|
-
{
|
|
52
|
-
//maximum number of records to return by default on Read queries. Override via "MeadowDefaultMaxCap" fable setting.
|
|
53
|
-
tmpCap = pRequest.DEFAULT_MAX_CAP;
|
|
54
|
-
}
|
|
55
|
-
pRequest.Query.setCap(tmpCap).setBegin(tmpBegin);
|
|
56
|
-
|
|
57
|
-
fStageComplete(false);
|
|
58
|
-
},
|
|
59
|
-
// 2. Set the query up with the By Value/Field combo
|
|
60
|
-
function (fStageComplete)
|
|
61
|
-
{
|
|
62
|
-
function addField(pByField, pByValue)
|
|
63
|
-
{
|
|
64
|
-
// TODO: Validate theat the ByField exists in the current database
|
|
65
|
-
if (pByValue.constructor === Array)
|
|
66
|
-
{
|
|
67
|
-
pRequest.Query.addFilter(pByField, pByValue, 'IN', 'AND', 'RequestByField');
|
|
68
|
-
}
|
|
69
|
-
else
|
|
70
|
-
{
|
|
71
|
-
// We use a custon name for this (RequestDefaultIdentifier) in case there is a query with a dot in the default identifier.
|
|
72
|
-
pRequest.Query.addFilter(pByField, pByValue, '=', 'AND', 'RequestByField');
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
var tmpFilters = pRequest.params.Filters;
|
|
77
|
-
if (tmpFilters &&
|
|
78
|
-
tmpFilters.constructor === Array)
|
|
79
|
-
{
|
|
80
|
-
tmpFilters.forEach(function(filter)
|
|
81
|
-
{
|
|
82
|
-
addField(filter.ByField, filter.ByValue);
|
|
83
|
-
});
|
|
84
|
-
}
|
|
85
|
-
else
|
|
86
|
-
{
|
|
87
|
-
addField(pRequest.params.ByField, pRequest.formattedParams.ByValue);
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
fStageComplete(false);
|
|
91
|
-
},
|
|
92
|
-
// 3. INJECT: Query configuration
|
|
93
|
-
function (fStageComplete)
|
|
94
|
-
{
|
|
95
|
-
pRequest.BehaviorModifications.runBehavior('Reads-QueryConfiguration', pRequest, fStageComplete);
|
|
96
|
-
},
|
|
97
|
-
// 3b. INJECT: Query pre-authorization behavior (ex. if authorizer needs fields to be included, it can add them)
|
|
98
|
-
function (fStageComplete)
|
|
99
|
-
{
|
|
100
|
-
pRequest.BehaviorModifications.runBehavior('Reads-PreAuth', pRequest, fStageComplete);
|
|
101
|
-
},
|
|
102
|
-
// 4. Execute the query
|
|
103
|
-
function (fStageComplete)
|
|
104
|
-
{
|
|
105
|
-
pRequest.DAL.doReads(pRequest.Query, fStageComplete);
|
|
106
|
-
},
|
|
107
|
-
// 5. Post processing of the records
|
|
108
|
-
function (pQuery, pRecords, fStageComplete)
|
|
109
|
-
{
|
|
110
|
-
if (!pRecords)
|
|
111
|
-
{
|
|
112
|
-
pRequest.CommonServices.log.info('Records not found', {SessionID:pRequest.UserSession.SessionID, RequestID:pRequest.RequestUUID, RequestURL:pRequest.url, Action:pRequest.DAL.scope+'-ReadsBy'}, pRequest);
|
|
113
|
-
return pResponse.send([]);
|
|
114
|
-
}
|
|
115
|
-
pRequest.Records = pRecords;
|
|
116
|
-
fStageComplete(false);
|
|
117
|
-
},
|
|
118
|
-
// 5.5: Check if there is an authorizer set for this endpoint and user role combination, and authorize based on that
|
|
119
|
-
function (fStageComplete)
|
|
120
|
-
{
|
|
121
|
-
pRequest.Authorizers.authorizeRequest('ReadsBy', pRequest, fStageComplete);
|
|
122
|
-
},
|
|
123
|
-
// 6. INJECT: Post process the record, tacking on or altering anything we want to.
|
|
124
|
-
function (fStageComplete)
|
|
125
|
-
{
|
|
126
|
-
pRequest.BehaviorModifications.runBehavior('Reads-PostOperation', pRequest, fStageComplete);
|
|
127
|
-
},
|
|
128
|
-
// 6.5: Check if authorization or post processing denied security access to the record
|
|
129
|
-
function (fStageComplete)
|
|
130
|
-
{
|
|
131
|
-
if (pRequest.MeadowAuthorization)
|
|
132
|
-
{
|
|
133
|
-
// This will complete the waterfall operation
|
|
134
|
-
return fStageComplete(false);
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
// It looks like this record was not authorized. Send an error.
|
|
138
|
-
return fStageComplete({Code:405,Message:'UNAUTHORIZED ACCESS IS NOT ALLOWED'});
|
|
139
|
-
}
|
|
140
|
-
],
|
|
141
|
-
// 7. Return the results to the user
|
|
142
|
-
function(pError)
|
|
143
|
-
{
|
|
144
|
-
if (pError)
|
|
145
|
-
{
|
|
146
|
-
return pRequest.CommonServices.sendCodedError('Error retreiving records by value.', pError, pRequest, pResponse, fNext);
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
pRequest.CommonServices.log.info('Read a list of records by '+pRequest.params.ByField+' = '+pRequest.params.ByValue+'.', {SessionID:pRequest.UserSession.SessionID, RequestID:pRequest.RequestUUID, RequestURL:pRequest.url, Action:pRequest.DAL.scope+'-ReadsBy'}, pRequest);
|
|
150
|
-
return streamRecordsToResponse(pResponse, pRequest.Records, fNext);
|
|
151
|
-
}
|
|
152
|
-
);
|
|
153
|
-
};
|
|
154
|
-
|
|
155
|
-
module.exports = doAPIReadsByEndpoint;
|