retold-data-service 1.0.0 → 1.0.1

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "retold-data-service",
3
- "version": "1.0.0",
3
+ "version": "1.0.1",
4
4
  "description": "Serve up a whole model!",
5
5
  "main": "source/Retold-Data-Service.js",
6
6
  "scripts": {
@@ -10,7 +10,7 @@
10
10
  module.exports = (
11
11
  {
12
12
  // The server to connect to (with trailing forward slash)
13
- Server: 'http://127.0.0.1:8080/',
13
+ Server: 'http://127.0.0.1:8088/1.0/',
14
14
 
15
15
  // Any cookies to be sent
16
16
  Cookies: {},
@@ -11,7 +11,7 @@ const libGraphGet = require('./GraphGet.js');
11
11
  */
12
12
  class Cumulation
13
13
  {
14
- constructor(pFable, pRequestSettings, pModel)
14
+ constructor(pFable, pRequestSettings)
15
15
  {
16
16
  this._Dependencies = {};
17
17
  this._Dependencies.underscore = require('underscore');
@@ -20,7 +20,7 @@ class Cumulation
20
20
  this._Dependencies.cumulation = this;
21
21
 
22
22
  // We want to make sure these are unique settings trees for each Cumulation object created.
23
- this._RequestSettings = JSON.parse(JSON.stringify(this._Dependencies.underscore.extend(JSON.parse(JSON.stringify(require('./Cumulation-Settings-Default.js'))), pSettings)));
23
+ this._RequestSettings = JSON.parse(JSON.stringify(this._Dependencies.underscore.extend(JSON.parse(JSON.stringify(require('./Cumulation-Settings-Default.js'))), pRequestSettings)));
24
24
 
25
25
  // This has behaviors similar to bunyan, for consistency
26
26
  this._Log = pFable.log;
@@ -31,7 +31,7 @@ class Cumulation
31
31
  * GET RECORDS (plural)
32
32
  *
33
33
  **/
34
- getRecordsFromServerGeneric (pEntity, pRecordsString, fCallback)
34
+ fetchRecords (pEntity, pRecordsString, fCallback)
35
35
  {
36
36
  let tmpCallBack = (typeof(fCallback) === 'function') ? fCallback : ()=>{};
37
37
  let tmpURL = this._RequestSettings.Server+pEntity+'s/'+pRecordsString;
@@ -51,7 +51,7 @@ class Cumulation
51
51
 
52
52
  if (this._RequestSettings.DebugLog)
53
53
  this._Log.debug(`Beginning GET plural request`,tmpRequestOptions);
54
- let tmpRequestTime = this._Log.getTimeStamp();
54
+ //let tmpRequestTime = this._Log.getTimeStamp();
55
55
 
56
56
  this._Dependencies.simpleget.get(tmpRequestOptions, (pError, pResponse)=>
57
57
  {
@@ -59,15 +59,15 @@ class Cumulation
59
59
  {
60
60
  return tmpCallBack(pError);
61
61
  }
62
- if (this._RequestSettings.DebugLog)
63
- this._Log.debug(`--> GET plural connected in ${this._Log.getTimeDelta(tmpRequestTime)}ms code ${pResponse.statusCode}`);
62
+ //if (this._RequestSettings.DebugLog)
63
+ // this._Log.debug(`--> GET plural connected in ${this._Log.getTimeDelta(tmpRequestTime)}ms code ${pResponse.statusCode}`);
64
64
 
65
65
  let tmpData = '';
66
66
 
67
67
  pResponse.on('data', (pChunk)=>
68
68
  {
69
- if (this._RequestSettings.DebugLog)
70
- this._Log.debug(`--> GET plural data chunk size ${pChunk.length}b received in ${this._Log.getTimeDelta(tmpRequestTime)}ms`);
69
+ //if (this._RequestSettings.DebugLog)
70
+ // this._Log.debug(`--> GET plural data chunk size ${pChunk.length}b received in ${this._Log.getTimeDelta(tmpRequestTime)}ms`);
71
71
  tmpData += pChunk;
72
72
  });
73
73
 
@@ -79,7 +79,7 @@ class Cumulation
79
79
  if (this._RequestSettings.DebugLog)
80
80
  {
81
81
  //this._Log.debug(`==> GET plural completed data size ${tmpData.length}b received in ${this._Log.getTimeDelta(tmpRequestTime)}ms`,tmpResult);
82
- this._Log.debug(`==> GET plural completed data size ${tmpData.length}b (${tmpResult.length} records) received in ${this._Log.getTimeDelta(tmpRequestTime)}ms`);
82
+ //this._Log.debug(`==> GET plural completed data size ${tmpData.length}b (${tmpResult.length} records) received in ${this._Log.getTimeDelta(tmpRequestTime)}ms`);
83
83
  }
84
84
  tmpCallBack(pError, tmpResult);
85
85
  });
@@ -14,15 +14,13 @@ var libUnderscore = require('underscore');
14
14
 
15
15
  class GraphGet
16
16
  {
17
- constructor(pFable, pCumulation, pModel)
17
+ constructor(pFable, pModel)
18
18
  {
19
- this._Cumulation = pCumulation;
20
-
21
- // Wire up logging
19
+ // Wire up logging
22
20
  this.log = pFable.log;
23
21
 
24
22
  // Wire up settings
25
- this._Settings = pFable._Settings;
23
+ this._Settings = pFable.settings;
26
24
 
27
25
  // Get the data model graph
28
26
  this._DataModel = pModel;
@@ -237,12 +235,12 @@ class GraphGet
237
235
  return fCallback(null, tmpValidFilters);
238
236
  };
239
237
 
240
- get(pEntityName, pFilterObject, fGetRecords, fCallback)
238
+ get(pEntityName, pFilterObject, pCumulation, fCallback)
241
239
  {
242
240
  // Get a set of EntityNames based on the FilterObject
243
241
  if (this._Settings.DebugLog)
244
242
  this.log.debug(`[${pEntityName}] Beginning to graph GET a set of records based on some filter criteria`,pFilterObject);
245
- let tmpGraphGetTime = this.log.getTimeStamp();
243
+ //let tmpGraphGetTime = this.log.getTimeStamp();
246
244
 
247
245
  let tmpGraphHints = {};
248
246
  let tmpGraphIgnores = {};
@@ -457,7 +455,7 @@ class GraphGet
457
455
 
458
456
  // TODO: This is sick. Fix it.
459
457
  tmpURIFilter += `/0/10000`;
460
- fGetRecords(pFilter.SatisfyingJoin, tmpURIFilter,
458
+ pCumulation.fetchRecords(pFilter.SatisfyingJoin, tmpURIFilter,
461
459
  (pError, pData)=>
462
460
  {
463
461
  tmpJoinedDataSets[pFilter.Entity] = pData;
@@ -586,7 +584,7 @@ class GraphGet
586
584
  if (tmpURIFilter !== '')
587
585
  tmpURIFilter += '/';
588
586
  tmpURIFilter += tmpPagingString;
589
- fGetRecords(pEntityName, tmpURIFilter,
587
+ pCumulation.fetchRecords(pEntityName, tmpURIFilter,
590
588
  (pError, pData)=>
591
589
  {
592
590
  return fStageComplete(pError, pData, pValidFilters, pFinalFilters, pJoinedDataSets, pValidIdentities);
@@ -598,7 +596,8 @@ class GraphGet
598
596
  if (pError)
599
597
  this.log.error(`[${pEntityName}] Graph Filter operation failed due to error: ${pError}`);
600
598
 
601
- this.log.debug(`[${pEntityName}] Graph Filter operation completed in ${this.log.getTimeDelta(tmpGraphGetTime)}ms`);
599
+ //this.log.debug(`[${pEntityName}] Graph Filter operation completed in ${this.log.getTimeDelta(tmpGraphGetTime)}ms`);
600
+ this.log.debug(`[${pEntityName}] Graph Filter operation completed`);
602
601
 
603
602
  fCallback(pError, pRecords, pValidFilters, pFinalFilters, pJoinedDataSets, pValidIdentities);
604
603
  });
@@ -9,6 +9,9 @@ const libMeadow = require('meadow');
9
9
  const libMeadowEndpoints = require('meadow-endpoints');
10
10
 
11
11
  const libProviderBase = require('./ProviderHelpers/Meadow-Provider-Helper-Base.js');
12
+
13
+ const libGraphSolver = require('./GraphGet.js');
14
+ const libCumulation = require('./Cumulation.js');
12
15
  /**
13
16
  * Retold Data Service
14
17
  *
@@ -54,6 +57,8 @@ class RetoldDataService
54
57
 
55
58
  this._Providers = {};
56
59
 
60
+ this._GraphSolver = false;
61
+
57
62
  this.log = this._Fable.log;
58
63
 
59
64
  // Load the configurations
@@ -138,6 +143,45 @@ class RetoldDataService
138
143
  return fStageComplete();
139
144
  },
140
145
  (fStageComplete) =>
146
+ {
147
+ // Initialize the graph solver library
148
+ this.initializeGraphEndpoints();
149
+ // Map the graph endpoints to it
150
+ // TODO: Decide if this follows the Meadow pattern or some other prefix pattern
151
+ this._Orator.webServer.post(`/1.0/GraphRead/:Entity`,
152
+ (pRequest, pResponse, fNext) =>
153
+ {
154
+ let tmpGraphRequestEntity = pRequest.params.Entity;
155
+ let tmpGraphRequestFilter = pRequest.body;
156
+
157
+ // TODO: Discuss how to pass in request settings -- what was in there worked for the web client and works for tokens so maybe it's okay?
158
+ let tmpCumulation = new libCumulation(this._Fable, {});
159
+
160
+ this._GraphSolver.get(tmpGraphRequestEntity, tmpGraphRequestFilter, tmpCumulation,
161
+ (pError, pRecords, pValidFilters, pFinalFilters, pJoinedDataSets, pValidIdentities) =>
162
+ {
163
+ pResponse.send(
164
+ {
165
+ GraphRequestEntity: tmpGraphRequestEntity,
166
+ GraphRequestFilter: tmpGraphRequestFilter,
167
+
168
+ Records: pRecords,
169
+
170
+ ValidFilters: pValidFilters,
171
+ Finalfilters: pFinalFilters,
172
+
173
+ JoinedDataSets: pJoinedDataSets,
174
+ ValidIdentities: pValidIdentities,
175
+
176
+ Error: pError
177
+ });
178
+ return fNext();
179
+ });
180
+ });
181
+
182
+ return fStageComplete();
183
+ },
184
+ (fStageComplete) =>
141
185
  {
142
186
  if (this._Settings.Retold.AutoStartAPIServer)
143
187
  {
@@ -170,6 +214,11 @@ class RetoldDataService
170
214
  return this._Providers.Default.connect();
171
215
  }
172
216
 
217
+ initializeGraphEndpoints()
218
+ {
219
+ this._GraphSolver = new libGraphSolver(this._Fable, this._MeadowModelGraph);
220
+ }
221
+
173
222
  mapBackplaneEndpoints()
174
223
  {
175
224
  const tmpBackplanePrefix = 'BACKPLANE';