meadow-endpoints 3.0.6 → 4.0.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.
Files changed (126) hide show
  1. package/{Dockerfile → Dockerfile_LUXURYCode} +43 -1
  2. package/README.md +48 -14
  3. package/debug/Animal.json +62 -0
  4. package/debug/Harness-Configuration.json +31 -0
  5. package/debug/Harness.js +7 -108
  6. package/debug/KillHarness.sh +10 -0
  7. package/dist/meadowendpoints.js +4402 -0
  8. package/dist/meadowendpoints.min.js +92 -0
  9. package/dist/meadowendpoints.min.js.map +1 -0
  10. package/gulpfile.js +83 -0
  11. package/package.json +29 -16
  12. package/source/Meadow-Endpoints-Browser-Shim.js +14 -0
  13. package/source/Meadow-Endpoints.js +176 -562
  14. package/source/controller/Meadow-Endpoints-Controller-Base.js +161 -0
  15. package/source/controller/components/Meadow-Endpoints-Controller-BehaviorInjection.js +125 -0
  16. package/source/controller/components/Meadow-Endpoints-Controller-Error-StatusCodes.txt +189 -0
  17. package/source/controller/components/Meadow-Endpoints-Controller-Error.js +118 -0
  18. package/source/controller/components/Meadow-Endpoints-Controller-Log.js +103 -0
  19. package/source/controller/utility/Meadow-Endpoints-Filter-Parser.js +225 -0
  20. package/source/controller/utility/Meadow-Endpoints-Session-Marshaler.js +48 -0
  21. package/source/controller/utility/Meadow-Endpoints-Stream-RecordArray.js +66 -0
  22. package/source/endpoints/count/Meadow-Endpoint-Count.js +49 -0
  23. package/source/endpoints/count/Meadow-Endpoint-CountBy.js +40 -0
  24. package/source/endpoints/create/Meadow-Endpoint-BulkCreate.js +53 -0
  25. package/source/endpoints/create/Meadow-Endpoint-Create.js +58 -0
  26. package/source/endpoints/create/Meadow-Operation-Create.js +83 -0
  27. package/source/endpoints/delete/Meadow-Endpoint-Delete.js +93 -0
  28. package/source/endpoints/delete/Meadow-Endpoint-Undelete.js +108 -0
  29. package/source/endpoints/read/Meadow-Endpoint-Read.js +72 -0
  30. package/source/endpoints/read/Meadow-Endpoint-ReadDistinctList.js +92 -0
  31. package/source/endpoints/read/Meadow-Endpoint-ReadLiteList.js +85 -0
  32. package/source/endpoints/read/Meadow-Endpoint-ReadMax.js +55 -0
  33. package/source/endpoints/read/Meadow-Endpoint-ReadSelectList.js +89 -0
  34. package/source/endpoints/read/Meadow-Endpoint-Reads.js +75 -0
  35. package/source/endpoints/read/Meadow-Endpoint-ReadsBy.js +100 -0
  36. package/source/{crud → endpoints/read}/Meadow-Marshal-DistinctList.js +4 -13
  37. package/source/{crud → endpoints/read}/Meadow-Marshal-LiteList.js +5 -14
  38. package/source/endpoints/schema/Meadow-Endpoint-New.js +36 -0
  39. package/source/endpoints/schema/Meadow-Endpoint-Schema.js +36 -0
  40. package/source/endpoints/schema/Meadow-Endpoint-Validate.js +41 -0
  41. package/source/endpoints/update/Meadow-Endpoint-BulkUpdate.js +50 -0
  42. package/source/endpoints/update/Meadow-Endpoint-Update.js +58 -0
  43. package/source/endpoints/update/Meadow-Operation-Update.js +115 -0
  44. package/source/endpoints/upsert/Meadow-Endpoint-BulkUpsert.js +52 -0
  45. package/source/endpoints/upsert/Meadow-Endpoint-Upsert.js +57 -0
  46. package/source/endpoints/upsert/Meadow-Operation-Upsert.js +137 -0
  47. package/test/MeadowEndpoints_basic_tests.js +50 -2375
  48. package/test_support/bookstore-api-endpoint-exercises.paw +0 -0
  49. package/test_support/bookstore-configuration.json +28 -0
  50. package/test_support/bookstore-import-books-run.js +1 -0
  51. package/test_support/bookstore-import-books.js +215 -0
  52. package/test_support/bookstore-serve-meadow-endpoint-apis-IPC.js +138 -0
  53. package/test_support/bookstore-serve-meadow-endpoint-apis-run.js +6 -0
  54. package/test_support/bookstore-serve-meadow-endpoint-apis.js +129 -0
  55. package/test_support/data/books.csv +10001 -0
  56. package/test_support/model/ddl/BookStore.ddl +66 -0
  57. package/test_support/model/generated_diagram/README.md +1 -0
  58. package/test_support/model/generated_diagram/Stricture_Output.dot +13 -0
  59. package/test_support/model/generated_diagram/Stricture_Output.png +0 -0
  60. package/test_support/model/generated_documentation/Dictionary.md +18 -0
  61. package/test_support/model/generated_documentation/Model-Author.md +20 -0
  62. package/test_support/model/generated_documentation/Model-Book.md +26 -0
  63. package/test_support/model/generated_documentation/Model-BookAuthorJoin.md +14 -0
  64. package/test_support/model/generated_documentation/Model-BookPrice.md +25 -0
  65. package/test_support/model/generated_documentation/Model-Review.md +22 -0
  66. package/test_support/model/generated_documentation/ModelChangeTracking.md +17 -0
  67. package/test_support/model/generated_documentation/README.md +1 -0
  68. package/test_support/model/manual_scripts/DropTables.sql +5 -0
  69. package/test_support/model/manual_scripts/README.md +2 -0
  70. package/test_support/model/sql_create/BookStore-CreateDatabase.mysql.sql +116 -0
  71. package/test_support/model/sql_create/README.md +1 -0
  72. package/test_support/test_old/Tests.js +3243 -0
  73. package/test_support/test_old/untitled.js +88 -0
  74. package/source/Meadow-Authenticator.js +0 -31
  75. package/source/Meadow-Authorizers.js +0 -214
  76. package/source/Meadow-BehaviorModifications.js +0 -170
  77. package/source/Meadow-CommonServices.js +0 -206
  78. package/source/Meadow-MarshallSessionData.js +0 -64
  79. package/source/Restify-RouteParser.js +0 -114
  80. package/source/authorizers/Meadow-Authorizer-Allow.js +0 -17
  81. package/source/authorizers/Meadow-Authorizer-Deny.js +0 -17
  82. package/source/authorizers/Meadow-Authorizer-Mine.js +0 -47
  83. package/source/authorizers/Meadow-Authorizer-MyCustomer.js +0 -48
  84. package/source/crud/Meadow-Endpoint-BulkCreate.js +0 -67
  85. package/source/crud/Meadow-Endpoint-BulkUpdate.js +0 -74
  86. package/source/crud/Meadow-Endpoint-BulkUpsert.js +0 -76
  87. package/source/crud/Meadow-Endpoint-Count.js +0 -93
  88. package/source/crud/Meadow-Endpoint-CountBy.js +0 -101
  89. package/source/crud/Meadow-Endpoint-Create.js +0 -77
  90. package/source/crud/Meadow-Endpoint-Delete.js +0 -139
  91. package/source/crud/Meadow-Endpoint-Read.js +0 -109
  92. package/source/crud/Meadow-Endpoint-ReadDistinctList.js +0 -146
  93. package/source/crud/Meadow-Endpoint-ReadLiteList.js +0 -139
  94. package/source/crud/Meadow-Endpoint-ReadMax.js +0 -86
  95. package/source/crud/Meadow-Endpoint-ReadSelectList.js +0 -145
  96. package/source/crud/Meadow-Endpoint-Reads.js +0 -129
  97. package/source/crud/Meadow-Endpoint-ReadsBy.js +0 -155
  98. package/source/crud/Meadow-Endpoint-Update.js +0 -80
  99. package/source/crud/Meadow-Endpoint-Upsert.js +0 -78
  100. package/source/crud/Meadow-Operation-Create.js +0 -105
  101. package/source/crud/Meadow-Operation-Update.js +0 -145
  102. package/source/crud/Meadow-Operation-Upsert.js +0 -106
  103. package/source/crud/Meadow-StreamRecordArray.js +0 -45
  104. package/source/schema/Meadow-Endpoint-New.js +0 -37
  105. package/source/schema/Meadow-Endpoint-Schema.js +0 -37
  106. package/source/schema/Meadow-Endpoint-Validate.js +0 -43
  107. package/test/Animal.json +0 -140
  108. package/test/MeadowEndpoints_disabledAuth_tests.js +0 -1325
  109. package/test/MeadowEndpoints_trustedSession_tests.js +0 -1731
  110. package/test/load/artillery-low.yml +0 -10
  111. package/test/load/cloud9setup.sh +0 -25
  112. package/test/load/package.json +0 -19
  113. package/test/load/test-schema-initializedatabase.sql +0 -29
  114. package/test/load/test-schema.json +0 -119
  115. package/test/load/test-server.js +0 -157
  116. package/test/scripts/InitializeDatabase-C9.sql +0 -7
  117. /package/{test/schemas → test_support/model}/json_schema/BookStore-Extended.json +0 -0
  118. /package/{test/schemas → test_support/model}/json_schema/BookStore-PICT.json +0 -0
  119. /package/{test/schemas → test_support/model}/json_schema/BookStore.json +0 -0
  120. /package/{test/schemas → test_support/model}/json_schema/README.md +0 -0
  121. /package/{test/schemas → test_support/model}/meadow_schema/BookStore-MeadowSchema-Author.json +0 -0
  122. /package/{test/schemas → test_support/model}/meadow_schema/BookStore-MeadowSchema-Book.json +0 -0
  123. /package/{test/schemas → test_support/model}/meadow_schema/BookStore-MeadowSchema-BookAuthorJoin.json +0 -0
  124. /package/{test/schemas → test_support/model}/meadow_schema/BookStore-MeadowSchema-BookPrice.json +0 -0
  125. /package/{test/schemas → test_support/model}/meadow_schema/BookStore-MeadowSchema-Review.json +0 -0
  126. /package/{test/schemas → test_support/model}/meadow_schema/README.md +0 -0
@@ -1,620 +1,234 @@
1
1
  /**
2
- * Meadow Data Broker Library
2
+ * Meadow Endpoints Service Data Broker Library
3
3
  *
4
4
  * @license MIT
5
- *
6
5
  * @author Steven Velozo <steven@velozo.com>
7
- * @module Meadow
8
6
  */
9
7
 
10
- /**
11
- * Meadow Data Broker Library
12
- *
13
- * @class MeadowEndpoints
14
- * @constructor
15
- */
16
- var MeadowEndpoints = function()
8
+ const libMeadowEndpointsControllerBase = require('./controller/Meadow-Endpoints-Controller-Base.js');
9
+ const libMeadow = require('meadow');
10
+
11
+ class MeadowEndpoints
17
12
  {
18
- function createNew(pMeadow)
13
+ constructor(pMeadow, pControllerOptions)
19
14
  {
20
- // If a valid Fable object isn't passed in, return a constructor
21
- if ((typeof(pMeadow) !== 'object') || !('fable' in pMeadow))
22
- {
23
- return {new: createNew};
24
- }
25
- var _Meadow = pMeadow;
26
- var _Fable = pMeadow.fable;
27
-
28
- var libAsync = require('async');
29
- var libRestRouteParse = require('./Restify-RouteParser.js');
15
+ this._Meadow = pMeadow;
16
+ // This is for backwards compatibility
17
+ this.DAL = this._Meadow;
30
18
 
31
- const _AuthenticationMode = _Fable.settings.MeadowAuthenticationMode || 'Disabled';
19
+ this._Controller = false;
20
+ this._ControllerOptions = (typeof(pControllerOptions) == 'object') ? pControllerOptions : {};
32
21
 
33
- var _CommonServices = require('./Meadow-CommonServices.js').new(pMeadow, _AuthenticationMode);
34
-
35
- // This holds any changed behaviors.
36
- var _BehaviorModifications = require('./Meadow-BehaviorModifications.js').new(pMeadow);
37
-
38
- // This holds the authorizers.
39
- var _Authorizers = require('./Meadow-Authorizers.js').new(pMeadow);
40
-
41
- // This checks that the user is authenticated. In the future, it will be overloadable.
42
- var _Authenticator = require('./Meadow-Authenticator.js')(_AuthenticationMode);
43
-
44
- // The default endpoints
45
- var _Endpoints = (
22
+ if (typeof(pMeadow) != 'object')
46
23
  {
47
- Create: require('./crud/Meadow-Endpoint-Create.js'),
48
- Creates: require('./crud/Meadow-Endpoint-BulkCreate.js'),
49
-
50
- Read: require('./crud/Meadow-Endpoint-Read.js'),
51
- ReadMax: require('./crud/Meadow-Endpoint-ReadMax.js'),
52
-
53
- Reads: require('./crud/Meadow-Endpoint-Reads.js'),
54
- ReadsBy: require('./crud/Meadow-Endpoint-ReadsBy.js'),
55
-
56
- ReadSelectList: require('./crud/Meadow-Endpoint-ReadSelectList.js'),
57
- ReadLiteList: require('./crud/Meadow-Endpoint-ReadLiteList.js'),
58
- ReadDistinctList: require('./crud/Meadow-Endpoint-ReadDistinctList.js'),
59
-
60
- Update: require('./crud/Meadow-Endpoint-Update.js'),
61
- Updates: require('./crud/Meadow-Endpoint-BulkUpdate.js'),
62
-
63
- Upsert: require('./crud/Meadow-Endpoint-Upsert.js'),
64
- Upserts: require('./crud/Meadow-Endpoint-BulkUpsert.js'),
65
-
66
- Delete: require('./crud/Meadow-Endpoint-Delete.js'),
67
-
68
- Count: require('./crud/Meadow-Endpoint-Count.js'),
69
- CountBy: require('./crud/Meadow-Endpoint-CountBy.js'),
70
-
71
- // Get the JSONSchema spec schema
72
- /* http://json-schema.org/examples.html
73
- * http://json-schema.org/latest/json-schema-core.html
74
- */
75
- Schema: require('./schema/Meadow-Endpoint-Schema.js'),
76
- // Validate a passed-in JSON object for if it matches the schema
77
- Validate: require('./schema/Meadow-Endpoint-Validate.js'),
78
- // Get an empty initialized JSON object for this.
79
- New: require('./schema/Meadow-Endpoint-New.js')
80
- });
81
-
82
- /**
83
- * Customize a default endpoint (or create more)
84
- *
85
- * @method setEndpoint
86
- */
87
- var setEndpoint = function(pEndpointHash, fEndpoint)
88
- {
89
- if (typeof(fEndpoint) === 'function')
90
- {
91
- _Endpoints[pEndpointHash] = fEndpoint;
92
- }
93
-
94
- return this;
95
- };
96
-
24
+ throw new Error('Meadow endpoints requires a valid Meadow DAL object as the first parameter of the constructor.');
25
+ }
97
26
 
98
- // The default authenticators
99
- var _EndpointAuthenticators = (
27
+ if (this._ControllerOptions.hasOwnProperty('ControllerInstance'))
100
28
  {
101
- Create: _Authenticator,
102
- Read: _Authenticator,
103
- Reads: _Authenticator,
104
- Update: _Authenticator,
105
- Delete: _Authenticator,
106
- Count: _Authenticator,
107
-
108
- Schema: _Authenticator,
109
- Validate: _Authenticator,
110
- New: _Authenticator
111
- });
112
-
113
- /**
114
- * Customize an endpoint Authenticator
115
- *
116
- * @method setEndpointAuthenticator
117
- */
118
- var setEndpointAuthenticator = function(pEndpointHash, fAuthenticator)
29
+ // Passed in already instantiated controller instance
30
+ this._Controller = this._ControllerOptions.ControllerInstance;
31
+ }
32
+ else if (this._ControllerOptions.hasOwnProperty('ControllerClass'))
119
33
  {
120
- if (typeof(fAuthenticator) === 'function')
121
- {
122
- _EndpointAuthenticators[pEndpointHash] = fAuthenticator;
123
- }
124
-
125
- return this;
126
- };
127
-
128
-
129
- // The default endpoint authorization levels
130
- var _EndpointAuthorizationLevels = (
34
+ // Passed in controller class, ready to initialize
35
+ this._Controller = new this._ControllerOptions.ControllerClass(this);
36
+ }
37
+ else
131
38
  {
132
- Create: 1,
133
- Read: 0,
134
- Reads: 0,
135
- Update: 1,
136
- Delete: 1,
137
- Count: 0,
138
-
139
- Schema: 0,
140
- Validate: 0,
141
- New: 1
142
- });
39
+ this._Controller = new libMeadowEndpointsControllerBase(this);
40
+ }
143
41
 
42
+ // Pull version from the settings; default to 1.0
43
+ this.EndpointVersion = this._Controller.settings.MeadowEndpointVersion || '1.0';
44
+ // Pull endpoint name from settings if the user to override the endpoint "name" eventually.
45
+ this.EndpointName = this.DAL.scope;
46
+ // This allows a wily developer to change what this prefix is....
47
+ this.EndpointPrefix = `/${this.EndpointVersion}/${this.EndpointName}`;
144
48
 
145
- // The default behaviors available.
49
+ // The default behavior sets available.
146
50
  // Turning these off before wiring the endpoints up will result in their counterpart endpoints not being available.
147
- var _EnabledBehaviors = (
51
+ this._EnabledBehaviorSets = (
148
52
  {
149
53
  Create: true,
150
- // POST [/1.0/SomeEndpoint]
151
-
152
54
  Read: true,
153
- // GET [/1.0/SomeEndpoint/:IDRecord]
154
- // GET [/1.0/SomeEndpoint/Max/:ColumnName]
155
-
156
55
  Reads: true,
157
- // GET [/1.0/SomeEndpoints]
158
- // GET [/1.0/SomeEndpoints/:Begin/:Cap]
159
- // GET [/1.0/SomeEndpoints/By/:ByField/:ByValue]
160
- // GET [/1.0/SomeEndpoints/By/:ByField/:ByValue/:Begin/:Cap]
161
- // GET [/1.0/SomeEndpoints/FilteredTo/:Filter]
162
- // GET [/1.0/SomeEndpoints/FilteredTo/:Filter/:Begin/:Cap]
163
- // GET [/1.0/SomeEndpointSelect]
164
- // GET [/1.0/SomeEndpointSelect/:Begin/:Cap]
165
- // GET [/1.0/SomeEndpointSelect/FilteredTo/:Filter]
166
- // GET [/1.0/SomeEndpointSelect/FilteredTo/:Filter/:Begin/:Cap]
167
- // GET [/1.0/SomeEndpoint/Lite]
168
- // GET [/1.0/SomeEndpoint/Lite/:Begin/:Cap]
169
- // GET [/1.0/SomeEndpoint/Lite/FilteredTo/:Filter]
170
- // GET [/1.0/SomeEndpoint/Lite/FilteredTo/:Filter/:Begin/:Cap]
171
- // GET [/1.0/SomeEndpoint/LiteExtended/:ExtraColumns]
172
- // GET [/1.0/SomeEndpoint/LiteExtended/:ExtraColumns/:Begin/:Cap]
173
- // GET [/1.0/SomeEndpoint/LiteExtended/:ExtraColumns/FilteredTo/:Filter]
174
- // GET [/1.0/SomeEndpoint/LiteExtended/:ExtraColumns/FilteredTo/:Filter/:Begin/:Cap]
175
- // GET [/1.0/SomeEndpoint/Distinct/:Columns]
176
- // GET [/1.0/SomeEndpoint/Distinct/:Columns/:Begin/:Cap]
177
- // GET [/1.0/SomeEndpoint/Distinct/:Columns/FilteredTo/:Filter]
178
- // GET [/1.0/SomeEndpoint/Distinct/:Columns/FilteredTo/:Filter/:Begin/:Cap]
179
-
180
56
  Update: true,
181
- // PUT [/1.0/SomeEndpoint]
182
- // PUT [/1.0/SomeEndpoint/Upsert]
183
-
184
57
  Delete: true,
185
- // DEL [/1.0/SomeEndpoint]
186
- // DEL [/1.0/SomeEndpoint/:IDRecord]
187
-
188
58
  Count: true,
189
- // GET [/1.0/SomeEndpoints/Count]
190
- // GET [/1.0/SomeEndpoints/Count/By/:ByField/:ByValue]
191
- // GET [/1.0/SomeEndpoints/Count/FilteredTo/:Filter]
192
-
193
59
  Schema: true,
194
- // GET [/1.0/SomeEndpoint/Schema]
195
-
196
60
  Validate: true,
197
- // POST [/1.0/SomeEndpoint/Schema/Validate]
198
-
199
61
  New: true
200
- // GET [/1.0/SomeEndpoint/Schema/New]
201
62
  });
202
63
 
203
- /**
204
- * Customize an endpoint Authorization Level
205
- *
206
- * @method setEndpointAuthorization
207
- */
208
- var setEndpointAuthorization = function(pEndpointHash, pAuthorizationLevel)
209
- {
210
- _EndpointAuthorizationLevels[pEndpointHash] = pAuthorizationLevel;
211
- return true;
212
- };
213
-
214
-
215
- /**
216
- * Add the common services object to the request early in the route chain
217
- */
218
- var wireCommonServices = function (pRequest, pResponse, fNext)
64
+ // The default endpoints
65
+ this._Endpoints = (
219
66
  {
220
- // TODO: There is a shared state issue with using this as the source for the authorization levels. Fix it.
221
- pRequest.CommonServices = _CommonServices;
222
- fNext();
223
- };
224
-
67
+ Create: require('./endpoints/create/Meadow-Endpoint-Create.js'),
68
+ Creates: require('./endpoints/create/Meadow-Endpoint-BulkCreate.js'),
225
69
 
226
- /**
227
- * Add the explicit state to the request that is coming through this endpoint
228
- */
229
- var wireState = function (pRequest, pResponse, fNext)
230
- {
231
- // TODO: There is a shared state issue with using this as the source for the authorization levels. Fix it.
232
- pRequest.EndpointAuthorizationLevels = _EndpointAuthorizationLevels;
233
- pRequest.DAL = _Meadow;
234
- pRequest.BehaviorModifications = _BehaviorModifications;
235
- pRequest.Authorizers = _Authorizers;
236
- pRequest.forEachRecord = function(fIterator)
237
- {
238
- if (pRequest.Record)
239
- return fIterator(pRequest.Record)
240
- else if (pRequest.Records)
241
- return pRequest.Records.forEach(fIterator);
242
- }
70
+ Read: require('./endpoints/read/Meadow-Endpoint-Read.js'),
71
+ ReadMax: require('./endpoints/read/Meadow-Endpoint-ReadMax.js'),
243
72
 
244
- //maximum number of records to return by default on Read queries. Override via "MeadowDefaultMaxCap" fable setting.
245
- pRequest.DEFAULT_MAX_CAP = (_Fable.settings['MeadowDefaultMaxCap']) || 250;
73
+ Reads: require('./endpoints/read/Meadow-Endpoint-Reads.js'),
74
+ ReadsBy: require('./endpoints/read/Meadow-Endpoint-ReadsBy.js'),
246
75
 
247
- fNext();
248
- };
76
+ ReadSelectList: require('./endpoints/read/Meadow-Endpoint-ReadSelectList.js'),
77
+ ReadLiteList: require('./endpoints/read/Meadow-Endpoint-ReadLiteList.js'),
78
+ ReadDistinctList: require('./endpoints/read/Meadow-Endpoint-ReadDistinctList.js'),
249
79
 
250
- /**
251
- * Reparse route parameters, attach 'formattedParams' to Request obj
252
- */
253
- var formatRouteParams = function(pRequest, pResponse, fNext)
254
- {
255
- if (pRequest.method === 'GET')
256
- {
257
- var tmpParams = libRestRouteParse(
258
- pRequest.route.path,
259
- pRequest.url
260
- );
80
+ Update: require('./endpoints/update/Meadow-Endpoint-Update.js'),
81
+ Updates: require('./endpoints/update/Meadow-Endpoint-BulkUpdate.js'),
261
82
 
262
- for(var key in tmpParams)
263
- {
264
- var tmpArray = tmpParams[key].split(',');
265
- if (tmpArray.length > 1)
266
- {
267
- for(var i=0; i<tmpArray.length; i++)
268
- {
269
- tmpArray[i] = decodeURIComponent(tmpArray[i]);
270
- }
83
+ Upsert: require('./endpoints/upsert/Meadow-Endpoint-Upsert.js'),
84
+ Upserts: require('./endpoints/upsert/Meadow-Endpoint-BulkUpsert.js'),
271
85
 
272
- tmpParams[key] = tmpArray;
273
- }
274
- else
275
- {
276
- tmpParams[key] = decodeURIComponent(tmpParams[key]);
277
- }
278
- }
86
+ Delete: require('./endpoints/delete/Meadow-Endpoint-Delete.js'),
87
+ Undelete: require('./endpoints/delete/Meadow-Endpoint-Undelete.js'),
279
88
 
280
- pRequest.formattedParams = tmpParams;
281
- }
89
+ Count: require('./endpoints/count/Meadow-Endpoint-Count.js'),
90
+ CountBy: require('./endpoints/count/Meadow-Endpoint-CountBy.js'),
282
91
 
283
- //libRestRouteParse
284
- return fNext();
285
- };
92
+ // Get the JSONSchema spec schema
93
+ /* http://json-schema.org/examples.html
94
+ * http://json-schema.org/latest/json-schema-core.html
95
+ */
96
+ Schema: require('./endpoints/schema/Meadow-Endpoint-Schema.js'),
97
+ // Validate a passed-in JSON object for if it matches the schema
98
+ Validate: require('./endpoints/schema/Meadow-Endpoint-Validate.js'),
99
+ // Get an empty initialized JSON object for this.
100
+ New: require('./endpoints/schema/Meadow-Endpoint-New.js')
101
+ });
102
+ }
286
103
 
104
+ get controller()
105
+ {
106
+ return this._Controller;
107
+ }
108
+ set controller(pController)
109
+ {
110
+ this._Controller = pController;
111
+ }
287
112
 
288
- /**
289
- * Wire up routes for the API
290
- *
291
- * @method connectRoutes
292
- * @param {Object} pRestServer The Restify server object to add routes to
293
- */
294
- var connectRoutes = function(pRestServer)
113
+ /**
114
+ * Customize a default endpoint (or create more)
115
+ *
116
+ * @method setEndpoint
117
+ */
118
+ setBehaviorEndpoint(pEndpointHash, fEndpoint)
119
+ {
120
+ if (typeof(fEndpoint) === 'function')
295
121
  {
296
- // TODO: Pull version from the config file.
297
- const tmpEndpointVersion = _Fable.settings.MeadowEndpointVersion || '1.0';
298
- // TODO: Allow the user to override the endpoint "name" eventually.
299
- const tmpEndpointName = _Meadow.scope;
300
-
301
- _Fable.log.trace('Creating endpoint', { Version: tmpEndpointVersion, Name: tmpEndpointName });
302
-
303
- const tmpEndpointPrefix = `/${tmpEndpointVersion}/${tmpEndpointName}`;
304
-
305
- if (!pRestServer._AttachedMeadowEndpointsRequestHandlers)
306
- {
307
- pRestServer._AttachedMeadowEndpointsRequestHandlers = true;
308
- // Connect the common services to the route
309
- pRestServer.use(wireCommonServices);
310
-
311
- // Build formattedParams route parameters
312
- pRestServer.use(formatRouteParams);
313
-
314
- // Marshall session data in, if needed / configured
315
- pRestServer.use(require('./Meadow-MarshallSessionData')(_Fable));
316
- }
317
-
318
- // These special schema services must come in the route table before the READ because they
319
- // technically block out the routes for the IDRecord 'Schema' (e.g. /1.0/EntityName/Schema)
320
- if (_EnabledBehaviors.Schema)
321
- {
322
- pRestServer.get(`${tmpEndpointPrefix}/Schema`, _EndpointAuthenticators.Schema, wireState, _Endpoints.Schema);
323
- }
324
- if (_EnabledBehaviors.New)
325
- {
326
- pRestServer.get(`${tmpEndpointPrefix}/Schema/New`, _EndpointAuthenticators.New, wireState, _Endpoints.New);
327
- }
328
- if (_EnabledBehaviors.Validate)
329
- {
330
- pRestServer.post(`${tmpEndpointPrefix}/Schema/Validate`, _CommonServices.bodyParser(), _EndpointAuthenticators.Validate, wireState, _Endpoints.Validate);
331
- }
122
+ this._Endpoints[pEndpointHash] = fEndpoint;
123
+ }
332
124
 
333
- // Custom single record endpoints
125
+ return this;
126
+ }
334
127
 
335
- // Standard CRUD and Count endpoints
336
- if (_EnabledBehaviors.Create)
337
- {
338
- pRestServer.post(`${tmpEndpointPrefix}`, _CommonServices.bodyParser(), _EndpointAuthenticators.Create, wireState, _Endpoints.Create);
339
- pRestServer.post(`${tmpEndpointPrefix}s`, _CommonServices.bodyParser(), _EndpointAuthenticators.Create, wireState, _Endpoints.Creates);
340
- }
341
- if (_EnabledBehaviors.Read)
342
- {
343
- pRestServer.get(`${tmpEndpointPrefix}/Max/:ColumnName`, _EndpointAuthenticators.Read, wireState, _Endpoints.ReadMax);
344
- pRestServer.get(`${tmpEndpointPrefix}/:IDRecord`, _EndpointAuthenticators.Read, wireState, _Endpoints.Read);
345
- }
346
- if (_EnabledBehaviors.Reads)
347
- {
348
- pRestServer.get(`${tmpEndpointPrefix}s`, _EndpointAuthenticators.Reads, wireState, _Endpoints.Reads);
349
- pRestServer.get(`${tmpEndpointPrefix}s/By/:ByField/:ByValue`, _EndpointAuthenticators.Reads, wireState, _Endpoints.ReadsBy);
350
- pRestServer.get(`${tmpEndpointPrefix}s/By/:ByField/:ByValue/:Begin/:Cap`, _EndpointAuthenticators.Reads, wireState, _Endpoints.ReadsBy);
351
- pRestServer.get(`${tmpEndpointPrefix}s/FilteredTo/:Filter`, _EndpointAuthenticators.Reads, wireState, _Endpoints.Reads);
352
- pRestServer.get(`${tmpEndpointPrefix}s/FilteredTo/:Filter/:Begin/:Cap`, _EndpointAuthenticators.Reads, wireState, _Endpoints.Reads);
353
- pRestServer.get(`${tmpEndpointPrefix}Select`, _EndpointAuthenticators.Reads, wireState, _Endpoints.ReadSelectList);
354
- pRestServer.get(`${tmpEndpointPrefix}Select/FilteredTo/:Filter`, _EndpointAuthenticators.Reads, wireState, _Endpoints.ReadSelectList);
355
- pRestServer.get(`${tmpEndpointPrefix}Select/FilteredTo/:Filter/:Begin/:Cap`, _EndpointAuthenticators.Reads, wireState, _Endpoints.ReadSelectList);
356
- pRestServer.get(`${tmpEndpointPrefix}Select/:Begin/:Cap`, _EndpointAuthenticators.Reads, wireState, _Endpoints.ReadSelectList);
357
- pRestServer.get(`${tmpEndpointPrefix}s/Lite`, _EndpointAuthenticators.Reads, wireState, _Endpoints.ReadLiteList);
358
- pRestServer.get(`${tmpEndpointPrefix}s/Lite/FilteredTo/:Filter`, _EndpointAuthenticators.Reads, wireState, _Endpoints.ReadLiteList);
359
- pRestServer.get(`${tmpEndpointPrefix}s/Lite/FilteredTo/:Filter/:Begin/:Cap`, _EndpointAuthenticators.Reads, wireState, _Endpoints.ReadLiteList);
360
- pRestServer.get(`${tmpEndpointPrefix}s/Lite/:Begin/:Cap`, _EndpointAuthenticators.Reads, wireState, _Endpoints.ReadLiteList);
361
- pRestServer.get(`${tmpEndpointPrefix}s/LiteExtended/:ExtraColumns`, _EndpointAuthenticators.Reads, wireState, _Endpoints.ReadLiteList);
362
- pRestServer.get(`${tmpEndpointPrefix}s/LiteExtended/:ExtraColumns/FilteredTo/:Filter`, _EndpointAuthenticators.Reads, wireState, _Endpoints.ReadLiteList);
363
- pRestServer.get(`${tmpEndpointPrefix}s/LiteExtended/:ExtraColumns/FilteredTo/:Filter/:Begin/:Cap`, _EndpointAuthenticators.Reads, wireState, _Endpoints.ReadLiteList);
364
- pRestServer.get(`${tmpEndpointPrefix}s/LiteExtended/:ExtraColumns/:Begin/:Cap`, _EndpointAuthenticators.Reads, wireState, _Endpoints.ReadLiteList);
365
- pRestServer.get(`${tmpEndpointPrefix}s/Distinct/:Columns`, _EndpointAuthenticators.Reads, wireState, _Endpoints.ReadDistinctList);
366
- pRestServer.get(`${tmpEndpointPrefix}s/Distinct/:Columns/FilteredTo/:Filter`, _EndpointAuthenticators.Reads, wireState, _Endpoints.ReadDistinctList);
367
- pRestServer.get(`${tmpEndpointPrefix}s/Distinct/:Columns/FilteredTo/:Filter/:Begin/:Cap`, _EndpointAuthenticators.Reads, wireState, _Endpoints.ReadDistinctList);
368
- pRestServer.get(`${tmpEndpointPrefix}s/Distinct/:Columns/:Begin/:Cap`, _EndpointAuthenticators.Reads, wireState, _Endpoints.ReadDistinctList);
369
- pRestServer.get(`${tmpEndpointPrefix}s/:Begin/:Cap`, _EndpointAuthenticators.Reads, wireState, _Endpoints.Reads);
370
- }
371
- if (_EnabledBehaviors.Update)
372
- {
373
- pRestServer.put(`${tmpEndpointPrefix}`, _CommonServices.bodyParser(), _EndpointAuthenticators.Update, wireState, _Endpoints.Update);
374
- pRestServer.put(`${tmpEndpointPrefix}s`, _CommonServices.bodyParser(), _EndpointAuthenticators.Update, wireState, _Endpoints.Updates);
375
- pRestServer.put(`${tmpEndpointPrefix}/Upsert`, _CommonServices.bodyParser(), _EndpointAuthenticators.Update, wireState, _Endpoints.Upsert);
376
- pRestServer.put(`${tmpEndpointPrefix}/Upserts`, _CommonServices.bodyParser(), _EndpointAuthenticators.Update, wireState, _Endpoints.Upserts);
377
- }
378
- if (_EnabledBehaviors.Delete)
379
- {
380
- pRestServer.del(`${tmpEndpointPrefix}`, _CommonServices.bodyParser(), _EndpointAuthenticators.Delete, wireState, _Endpoints.Delete);
381
- pRestServer.del(`${tmpEndpointPrefix}/:IDRecord`, _EndpointAuthenticators.Delete, wireState, _Endpoints.Delete);
382
- }
383
- if (_EnabledBehaviors.Count)
384
- {
385
- pRestServer.get(`${tmpEndpointPrefix}s/Count`, _EndpointAuthenticators.Count, wireState, _Endpoints.Count);
386
- pRestServer.get(`${tmpEndpointPrefix}s/Count/By/:ByField/:ByValue`, _EndpointAuthenticators.Count, wireState, _Endpoints.CountBy);
387
- pRestServer.get(`${tmpEndpointPrefix}s/Count/FilteredTo/:Filter`, _EndpointAuthenticators.Count, wireState, _Endpoints.Count);
388
- }
389
- };
128
+ connectRoute(pServiceServer, pRequestMethod, pRoutePartial, pEndpointProcessingFunction, pBehaviorName)
129
+ {
130
+ let tmpRoute = `${this.EndpointPrefix}${pRoutePartial}`;
131
+ let tmpBehaviorName = (typeof(pBehaviorName) == 'string') ? pBehaviorName : 'an unnamed custom behavior'
390
132
 
133
+ this._Controller.log.trace(`...meadow-endpoints mapping a ${pRequestMethod} endpoint for scope ${this.DAL.scope} on route [${tmpRoute}] which runs ${tmpBehaviorName}.`);
391
134
 
392
- /**
393
- * Emulate a response object
394
- */
395
- var wireResponse = function(pResponse, fCallback)
135
+ try
396
136
  {
397
- pResponse.send = function(data)
398
- {
399
- this.body = data;
400
-
401
- if (!data.Error)
402
- {
403
- if (data.constructor === Array)
404
- {
405
- this.Records = data;
406
- }
407
- else
408
- {
409
- this.Record = data;
410
- }
411
- }
412
- };
413
-
414
- Object.defineProperty(pResponse, 'text',
415
- {
416
- get: function() { return JSON.stringify(pResponse.body); },
417
- enumerable: true
418
- });
137
+ (pServiceServer[pRequestMethod])(tmpRoute, pEndpointProcessingFunction.bind(this._Controller));
138
+ }
139
+ catch (pServiceServerRouteConnectError)
140
+ {
141
+ this._Controller.log.error(`...error mapping ${pBehaviorName} to method ${pRequestMethod} for scope ${this.DAL.scope} to route [${tmpRoute}]: ${pServiceServerRouteConnectError}`, pServiceServerRouteConnectError.stack);
142
+ }
143
+ return true;
144
+ }
419
145
 
420
- return fCallback();
421
- };
146
+ connectRoutes(pServiceServer)
147
+ {
148
+ this._Controller.log.trace(`Creating automatic meadow endpoints at prefix [${this.EndpointPrefix}] for scope ${this.DAL.scope}...`);
422
149
 
423
- var _InvokeSetupCallback;
424
- var getInvokeSetupCallback = function()
150
+ // These special schema services must come in the route table before the READ because they
151
+ // technically block out the routes for the IDRecord 'Schema' (e.g. GET[/1.0/EntityName/Schema] ==NEEDS=> GET[/1.0/EntityName/100])
152
+ if (this._EnabledBehaviorSets.Schema)
425
153
  {
426
- return _InvokeSetupCallback;
427
- };
428
-
429
- var setInvokeSetupCallback = function(fCallback)
154
+ this.connectRoute(pServiceServer, 'get', `/Schema`, this._Endpoints.Schema, `the internal behavior _Endpoints.Schema`);
155
+ }
156
+ if (this._EnabledBehaviorSets.New)
430
157
  {
431
- _InvokeSetupCallback = fCallback;
432
- };
433
-
434
- /**
435
- * Invoke a meadow endpoint programmatically
436
- *
437
- * @method invokeEndpoint
438
- */
439
- var invokeEndpoint = function(pMethod, pData, pOptions, fCallback)
158
+ this.connectRoute(pServiceServer, 'get', `/Schema/New`, this._Endpoints.New, `the internal behavior _Endpoints.New`);
159
+ }
160
+ if (this._EnabledBehaviorSets.Validate)
440
161
  {
441
- var tmpCallback = (typeof(pOptions) === 'function') ? pOptions : fCallback;
442
-
443
- if (!_Endpoints[pMethod])
444
- {
445
- _CommonServices.log.error('Endpoint \'' + pMethod + '\' does not exist!');
446
- return tmpCallback('Endpoint \'' + pMethod + '\' does not exist!'); //might be better as an exception
447
- }
448
-
449
- // TODO: should switch depending on type
450
- // TODO: should we keep this around, just make a deep copy of 'pOptions'
451
- var pRequest = {params: pData, formattedParams: pData, body: pData};
452
- if (typeof(pOptions) === 'object' && typeof(pOptions.header) === 'function') {
453
- // carry over header function
454
- pRequest.header = pOptions.header.bind(pOptions);
455
- }
456
- var pResponse = {};
457
-
458
- libAsync.waterfall([
459
- function(fStageComplete)
460
- {
461
- return wireResponse(pResponse, fStageComplete);
462
- },
463
- function(fStageComplete)
464
- {
465
- //allow consumer to specify user session data
466
- if (pOptions.UserSession)
467
- {
468
- //make a copy of the UserSession
469
- pRequest.UserSession = JSON.parse(JSON.stringify(pOptions.UserSession));
470
- }
471
- else
472
- {
473
- //else fill in default user session data
474
- pRequest.EndpointInvoked = true; //bypass session auth check
475
- pRequest.UserSession = { UserID: 0, UserRoleIndex: 0 };
476
- }
477
-
478
- // The Satchel is a workaround to pass state between query invocation and query decoration
479
- // Unfortunately, it has other uses, so we can't safely remove it here; this creates a risk of
480
- // cross-request state contamination (which we have seen cause issues).
481
- //FIXME: We should rework invokeEndpoint to make this state management unnecessary
482
- pRequest.Satchel = pOptions.Satchel;
483
- //internal invoke mark as authenticated (because this is not called via webservice)
484
- pRequest.EndpointAuthenticated = true;
485
-
486
- if (_InvokeSetupCallback && typeof(_InvokeSetupCallback) == 'function')
487
- {
488
- _InvokeSetupCallback(pRequest, pResponse, typeof(pOptions) === 'object' && pOptions);
489
- }
490
- return fStageComplete();
491
- },
492
- function(fStageComplete)
493
- {
494
- return wireCommonServices(pRequest, pResponse, fStageComplete);
495
- },
496
- function(fStageComplete)
497
- {
498
- return wireState(pRequest, pResponse, fStageComplete);
499
- },
500
- function(fStageComplete)
501
- {
502
- //Invoke the endpoint method
503
- _Endpoints[pMethod](pRequest, pResponse, function(err)
504
- {
505
- return fStageComplete(err, pResponse);
506
- });
507
- }
508
- ],
509
- function complete(err)
510
- {
511
- return tmpCallback(err, pResponse);
512
- });
513
- };
514
-
162
+ this.connectRoute(pServiceServer, 'postWithBodyParser', `/Schema/Validate`, this._Endpoints.Validate, `the internal behavior _Endpoints.Validate`);
163
+ }
515
164
 
516
- /**
517
- * Container Object for our Factory Pattern
518
- */
519
- var tmpNewMeadowEndpointObject = (
165
+ // Standard CRUD and Count endpoints
166
+ if (this._EnabledBehaviorSets.Create)
520
167
  {
521
- setEndpoint: setEndpoint,
522
- setEndpointAuthenticator: setEndpointAuthenticator,
523
- setEndpointAuthorization: setEndpointAuthorization,
524
-
525
- wireState: wireState,
526
-
527
- connectRoutes: connectRoutes,
528
-
529
- parseFilter: require('meadow-filter').parse,
530
-
531
- // Expose the DAL
532
- DAL: _Meadow,
533
-
534
- getInvokeSetupCallback: getInvokeSetupCallback,
535
- setInvokeSetupCallback: setInvokeSetupCallback,
536
- invokeEndpoint: invokeEndpoint,
537
-
538
- // Factory
539
- new: createNew
540
- });
541
-
542
- /**
543
- * Endpoint Authorization Levels
544
- *
545
- * @property endpointAuthorizationLevels
546
- * @type object
547
- */
548
- Object.defineProperty(tmpNewMeadowEndpointObject, 'endpointAuthorizationLevels',
549
- {
550
- get: function() { return _EndpointAuthorizationLevels; },
551
- enumerable: true
552
- });
553
-
554
- /**
555
- * Endpoints
556
- *
557
- * @property endpoints
558
- * @type object
559
- */
560
- Object.defineProperty(tmpNewMeadowEndpointObject, 'endpoints',
561
- {
562
- get: function() { return _Endpoints; },
563
- enumerable: true
564
- });
565
-
566
- /**
567
- * EndpointAuthenticators
568
- *
569
- * @property endpointAuthorizers
570
- * @type object
571
- */
572
- Object.defineProperty(tmpNewMeadowEndpointObject, 'endpointAuthorizers',
573
- {
574
- get: function() { return _Authorizers; },
575
- enumerable: true
576
- });
577
-
578
- /**
579
- * EndpointAuthenticators
580
- *
581
- * @property endpointAuthenticators
582
- * @type object
583
- */
584
- Object.defineProperty(tmpNewMeadowEndpointObject, 'endpointAuthenticators',
585
- {
586
- get: function() { return _EndpointAuthenticators; },
587
- enumerable: true
588
- });
589
-
590
- /**
591
- * EnabledBehaviors
592
- *
593
- * @property enabledBehaviors
594
- * @type object
595
- */
596
- Object.defineProperty(tmpNewMeadowEndpointObject, 'enabledBehaviors',
597
- {
598
- get: function() { return _EnabledBehaviors; },
599
- enumerable: true
600
- });
168
+ this.connectRoute(pServiceServer, 'postWithBodyParser', ``, this._Endpoints.Create, `the internal behavior _Endpoints.Create`);
169
+ this.connectRoute(pServiceServer, 'postWithBodyParser', `s`, this._Endpoints.Creates, `the internal behavior _Endpoints.Creates`);
170
+ }
171
+ if (this._EnabledBehaviorSets.Read)
172
+ {
173
+ this.connectRoute(pServiceServer, 'get', `/Max/:ColumnName`, this._Endpoints.ReadMax, `the internal behavior _Endpoints.ReadMax`);
174
+ this.connectRoute(pServiceServer, 'get', `/:IDRecord`, this._Endpoints.Read, `the internal behavior _Endpoints.Read`);
175
+ }
176
+ if (this._EnabledBehaviorSets.Reads)
177
+ {
178
+ this.connectRoute(pServiceServer, 'get', `s`, this._Endpoints.Reads, `the internal behavior _Endpoints.Reads`);
179
+ this.connectRoute(pServiceServer, 'get', `s/By/:ByField/:ByValue`, this._Endpoints.ReadsBy, `the internal behavior _Endpoints.ReadsBy`);
180
+ this.connectRoute(pServiceServer, 'get', `s/By/:ByField/:ByValue/:Begin/:Cap`, this._Endpoints.ReadsBy, `the internal behavior _Endpoints.ReadsBy`);
181
+ this.connectRoute(pServiceServer, 'get', `s/FilteredTo/:Filter`, this._Endpoints.Reads, `the internal behavior _Endpoints.Reads`);
182
+ this.connectRoute(pServiceServer, 'get', `s/FilteredTo/:Filter/:Begin/:Cap`, this._Endpoints.Reads, `the internal behavior _Endpoints.Reads`);
183
+ this.connectRoute(pServiceServer, 'get', `Select`, this._Endpoints.ReadSelectList, `the internal behavior _Endpoints.ReadSelectList`);
184
+ this.connectRoute(pServiceServer, 'get', `Select/FilteredTo/:Filter`, this._Endpoints.ReadSelectList, `the internal behavior _Endpoints.ReadSelectList`);
185
+ this.connectRoute(pServiceServer, 'get', `Select/FilteredTo/:Filter/:Begin/:Cap`, this._Endpoints.ReadSelectList, `the internal behavior _Endpoints.ReadSelectList`);
186
+ this.connectRoute(pServiceServer, 'get', `Select/:Begin/:Cap`, this._Endpoints.ReadSelectList, `the internal behavior _Endpoints.ReadSelectList`);
187
+ this.connectRoute(pServiceServer, 'get', `s/Lite`, this._Endpoints.ReadLiteList, `the internal behavior _Endpoints.ReadLiteList`);
188
+ this.connectRoute(pServiceServer, 'get', `s/Lite/FilteredTo/:Filter`, this._Endpoints.ReadLiteList, `the internal behavior _Endpoints.ReadLiteList`);
189
+ this.connectRoute(pServiceServer, 'get', `s/Lite/FilteredTo/:Filter/:Begin/:Cap`, this._Endpoints.ReadLiteList, `the internal behavior _Endpoints.ReadLiteList`);
190
+ this.connectRoute(pServiceServer, 'get', `s/Lite/:Begin/:Cap`, this._Endpoints.ReadLiteList, `the internal behavior _Endpoints.ReadLiteList`);
191
+ this.connectRoute(pServiceServer, 'get', `s/LiteExtended/:ExtraColumns`, this._Endpoints.ReadLiteList, `the internal behavior _Endpoints.ReadLiteList`);
192
+ this.connectRoute(pServiceServer, 'get', `s/LiteExtended/:ExtraColumns/FilteredTo/:Filter`, this._Endpoints.ReadLiteList, `the internal behavior _Endpoints.ReadLiteList`);
193
+ this.connectRoute(pServiceServer, 'get', `s/LiteExtended/:ExtraColumns/FilteredTo/:Filter/:Begin/:Cap`, this._Endpoints.ReadLiteList, `the internal behavior _Endpoints.ReadLiteList`);
194
+ this.connectRoute(pServiceServer, 'get', `s/LiteExtended/:ExtraColumns/:Begin/:Cap`, this._Endpoints.ReadLiteList, `the internal behavior _Endpoints.ReadLiteList`);
195
+ this.connectRoute(pServiceServer, 'get', `s/Distinct/:Columns`, this._Endpoints.ReadDistinctList, `the internal behavior _Endpoints.ReadDistinctList`);
196
+ this.connectRoute(pServiceServer, 'get', `s/Distinct/:Columns/FilteredTo/:Filter`, this._Endpoints.ReadDistinctList, `the internal behavior _Endpoints.ReadDistinctList`);
197
+ this.connectRoute(pServiceServer, 'get', `s/Distinct/:Columns/FilteredTo/:Filter/:Begin/:Cap`, this._Endpoints.ReadDistinctList, `the internal behavior _Endpoints.ReadDistinctList`);
198
+ this.connectRoute(pServiceServer, 'get', `s/Distinct/:Columns/:Begin/:Cap`, this._Endpoints.ReadDistinctList, `the internal behavior _Endpoints.ReadDistinctList`);
199
+ this.connectRoute(pServiceServer, 'get', `s/:Begin/:Cap`, this._Endpoints.Reads, `the internal behavior _Endpoints.Reads`);
200
+ }
201
+ if (this._EnabledBehaviorSets.Update)
202
+ {
203
+ this.connectRoute(pServiceServer, 'putWithBodyParser', ``, this._Endpoints.Update, `the internal behavior _Endpoints.Update`);
204
+ this.connectRoute(pServiceServer, 'putWithBodyParser', `s`, this._Endpoints.Updates, `the internal behavior _Endpoints.Updates`);
205
+ this.connectRoute(pServiceServer, 'putWithBodyParser', `/Upsert`, this._Endpoints.Upsert, `the internal behavior _Endpoints.Upsert`);
206
+ this.connectRoute(pServiceServer, 'putWithBodyParser', `/Upserts`, this._Endpoints.Upserts, `the internal behavior _Endpoints.Upserts`);
207
+ }
208
+ if (this._EnabledBehaviorSets.Delete)
209
+ {
210
+ this.connectRoute(pServiceServer, 'del', ``, this._Endpoints.Delete, `the internal behavior _Endpoints.Delete`);
211
+ this.connectRoute(pServiceServer, 'del', `/:IDRecord`, this._Endpoints.Delete, `the internal behavior _Endpoints.Delete`);
212
+ this.connectRoute(pServiceServer, 'get', `/Undelete/:IDRecord`, this._Endpoints.Undelete, `the internal behavior _Endpoints.Undelete`);
213
+ }
214
+ if (this._EnabledBehaviorSets.Count)
215
+ {
216
+ this.connectRoute(pServiceServer, 'get', `s/Count`, this._Endpoints.Count, `the internal behavior _Endpoints.Count`);
217
+ this.connectRoute(pServiceServer, 'get', `s/Count/By/:ByField/:ByValue`, this._Endpoints.CountBy, `the internal behavior _Endpoints.CountBy`);
218
+ this.connectRoute(pServiceServer, 'get', `s/Count/FilteredTo/:Filter`, this._Endpoints.Count, `the internal behavior _Endpoints.Count`);
219
+ }
220
+ }
221
+ }
601
222
 
602
- /**
603
- * Behavior Modifications
604
- *
605
- * @property behaviorModifications
606
- * @type object
607
- */
608
- Object.defineProperty(tmpNewMeadowEndpointObject, 'behaviorModifications',
609
- {
610
- get: function() { return _BehaviorModifications; },
611
- enumerable: true
612
- });
613
223
 
614
- return tmpNewMeadowEndpointObject;
615
- }
224
+ // This is for backwards compatibility
225
+ function autoConstruct(pMeadow, pControllerOptions)
226
+ {
227
+ return new MeadowEndpoints(pMeadow, pControllerOptions);
228
+ }
616
229
 
617
- return createNew();
618
- };
230
+ module.exports = MeadowEndpoints;
231
+ module.exports.new = autoConstruct;
619
232
 
620
- module.exports = new MeadowEndpoints();
233
+ module.exports.Meadow = libMeadow;
234
+ module.exports.BaseController = libMeadowEndpointsControllerBase;