retold-data-service 2.0.0 → 2.0.4

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": "2.0.0",
3
+ "version": "2.0.4",
4
4
  "description": "Serve up a whole model!",
5
5
  "main": "source/Retold-Data-Service.js",
6
6
  "scripts": {
@@ -54,7 +54,7 @@
54
54
  "meadow": "^2.0.15",
55
55
  "meadow-connection-mysql": "^1.0.4",
56
56
  "meadow-endpoints": "^4.0.5",
57
- "orator": "^4.0.2",
58
- "orator-serviceserver-restify": "^2.0.2"
57
+ "orator": "^4.0.3",
58
+ "orator-serviceserver-restify": "^2.0.3"
59
59
  }
60
60
  }
@@ -52,75 +52,123 @@ class RetoldDataService extends libFableServiceProviderBase
52
52
  // Create DAL objects for each table in the schema
53
53
  // These will be unnecessary when meadow and meadow-endpoints are full fledged fable services
54
54
  this._DAL = {};
55
- this.fable.DAL = this._DAL;
56
55
  this._MeadowEndpoints = {};
56
+
57
+ // Decorate fable with the same -- this is a temporary hack until meadow and meadow-endpoints are full fledged fable services
58
+ this.fable.DAL = this._DAL;
57
59
  this.fable.MeadowEndpoints = this._MeadowEndpoints;
60
+
61
+ // Storage for the model and entities
62
+ this.fullModel = false;
63
+ this.entityList = false;
64
+
65
+ this.serviceInitialized = false;
66
+ }
67
+
68
+ onBeforeInitialize(fCallback)
69
+ {
70
+ return fCallback();
71
+ }
72
+ onInitialize(fCallback)
73
+ {
74
+ return fCallback();
75
+ }
76
+ onAfterInitialize(fCallback)
77
+ {
78
+ return fCallback();
79
+ }
80
+
81
+ initializePersistenceEngine(fCallback)
82
+ {
83
+ // TODO: Change this to an option (e.g. we might want to do ALASQL)
84
+ // Load the mysql connection for meadow if it doesn't exist yet
85
+ this.fable.serviceManager.addAndInstantiateServiceType('MeadowMySQLProvider', require('meadow-connection-mysql'));
86
+ return fCallback();
87
+ }
88
+ initializeDataEndpoints(fCallback)
89
+ {
90
+ this.fable.log.info("Retold Data Service initializing Endpoints...");
91
+
92
+ // Create DAL objects for each table in the schema
93
+
94
+ // 1. Load full compiled schema of the model from stricture
95
+ _Fable.log.info(`...loading full model stricture schema...`);
96
+ this.fullModel = require (`${this.options.FullMeadowSchemaPath}${this.options.FullMeadowSchemaFilename}`);
97
+ _Fable.log.info(`...full model stricture schema loaded.`);
98
+
99
+ // 2. Extract an array of each table in the schema
100
+ _Fable.log.info(`...getting entity list...`);
101
+ this.entityList = Object.keys(this.fullModel.Tables);
102
+
103
+ // 3. Enumerate each entry in the compiled model and load a DAL for that table
104
+ _Fable.log.info(`...initializing ${this.entityList.length} DAL objects and corresponding Meadow Endpoints...`);
105
+ for (let i = 0; i < this.entityList.length; i++)
106
+ {
107
+ // 4. Create the DAL for each entry (e.g. it would be at _DAL.Movie for the Movie entity)
108
+ let tmpDALEntityName = this.entityList[i];
109
+ let tmpDALPackageFile = `${this.options.DALMeadowSchemaPath}${this.options.DALMeadowSchemaPrefix}${tmpDALEntityName}${this.options.DALMeadowSchemaPostfix}.json`
110
+ _Fable.log.info(`Initializing the ${tmpDALEntityName} DAL from [${tmpDALPackageFile}]...`);
111
+ this._DAL[tmpDALEntityName] = this._Meadow.loadFromPackage(tmpDALPackageFile);
112
+ // 5. Tell this DAL object to use MySQL
113
+ _Fable.log.info(`...defaulting the ${tmpDALEntityName} DAL to use MySQL`);
114
+ this._DAL[tmpDALEntityName].setProvider('MySQL');
115
+ // 6. Create a Meadow Endpoints class for this DAL
116
+ _Fable.log.info(`...initializing the ${tmpDALEntityName} Meadow Endpoints to use MySQL`);
117
+ this._MeadowEndpoints[tmpDALEntityName] = libMeadowEndpoints.new(this._DAL[tmpDALEntityName]);
118
+ // 8. Expose the meadow endpoints on Orator
119
+ _Fable.log.info(`...mapping the ${tmpDALEntityName} Meadow Endpoints to Orator`);
120
+ this._MeadowEndpoints[tmpDALEntityName].connectRoutes(this.fable.OratorServiceServer);
121
+ }
122
+
123
+ return fCallback();
58
124
  }
59
125
 
60
126
  initializeService(fCallback)
61
127
  {
62
128
  if (this.serviceInitialized)
63
129
  {
64
- this.fable.log.error("Retold Data Service Application is being initialized but has already been initialized...");
65
130
  return fCallback(new Error("Retold Data Service Application is being initialized but has already been initialized..."));
66
131
  }
67
132
  else
68
133
  {
134
+ let tmpAnticipate = this.fable.newAnticipate();
135
+
69
136
  this.fable.log.info(`The Retold Data Service is Auto Starting Orator`);
70
- this.fable.Orator.startWebServer(
71
- (pError) =>
137
+
138
+ tmpAnticipate.anticipate(this.onBeforeInitialize.bind(this));
139
+
140
+ tmpAnticipate.anticipate(
141
+ (fCallback) =>
72
142
  {
73
- if (pError)
143
+ if (this.options.AutoStartOrator)
74
144
  {
75
- console.log(`Error auto-starting Orator: ${pError}`, pError);
76
- return fCallback(pError);
145
+ this.fable.Orator.startWebServer(fCallback);
77
146
  }
147
+ else
148
+ {
149
+ return fCallback();
150
+ }
151
+ });
78
152
 
79
- // TODO: Change this to an option (e.g. we might want to do ALASQL)
80
- // Load the mysql connection for meadow if it doesn't exist yet
81
- _Fable.serviceManager.addAndInstantiateServiceType('MeadowMySQLProvider', require('meadow-connection-mysql'));
82
-
83
- this.fullModel = false;
84
- this.entityList = false;
85
-
86
- this.serviceInitialized = false;
87
-
88
- this.fable.log.info("Retold Data Service Application is starting up...");
153
+ tmpAnticipate.anticipate(this.initializePersistenceEngine.bind(this));
89
154
 
90
- // Create DAL objects for each table in the schema
155
+ tmpAnticipate.anticipate(this.onInitialize.bind(this));
91
156
 
92
- // 1. Load full compiled schema of the model from stricture
93
- _Fable.log.info(`...loading full model stricture schema...`);
94
- this.fullModel = require (`${this.options.FullMeadowSchemaPath}${this.options.FullMeadowSchemaFilename}`);
95
- _Fable.log.info(`...full model stricture schema loaded.`);
157
+ tmpAnticipate.anticipate(this.initializeDataEndpoints.bind(this));
96
158
 
97
- // 2. Extract an array of each table in the schema
98
- _Fable.log.info(`...getting entity list...`);
99
- this.entityList = Object.keys(this.fullModel.Tables);
159
+ tmpAnticipate.anticipate(this.onAfterInitialize.bind(this));
100
160
 
101
- // 3. Enumerate each entry in the compiled model and load a DAL for that table
102
- _Fable.log.info(`...initializing ${this.entityList.length} DAL objects and corresponding Meadow Endpoints...`);
103
- for (let i = 0; i < this.entityList.length; i++)
161
+ tmpAnticipate.wait(
162
+ (pError)=>
163
+ {
164
+ if (pError)
104
165
  {
105
- // 4. Create the DAL for each entry (e.g. it would be at _DAL.Movie for the Movie entity)
106
- let tmpDALEntityName = this.entityList[i];
107
- let tmpDALPackageFile = `${this.options.DALMeadowSchemaPath}${this.options.DALMeadowSchemaPrefix}${tmpDALEntityName}${this.options.DALMeadowSchemaPostfix}.json`
108
- _Fable.log.info(`Initializing the ${tmpDALEntityName} DAL from [${tmpDALPackageFile}]...`);
109
- this._DAL[tmpDALEntityName] = this._Meadow.loadFromPackage(tmpDALPackageFile);
110
- // 5. Tell this DAL object to use MySQL
111
- _Fable.log.info(`...defaulting the ${tmpDALEntityName} DAL to use MySQL`);
112
- this._DAL[tmpDALEntityName].setProvider('MySQL');
113
- // 6. Create a Meadow Endpoints class for this DAL
114
- _Fable.log.info(`...initializing the ${tmpDALEntityName} Meadow Endpoints to use MySQL`);
115
- this._MeadowEndpoints[tmpDALEntityName] = libMeadowEndpoints.new(this._DAL[tmpDALEntityName]);
116
- // 8. Expose the meadow endpoints on Orator
117
- _Fable.log.info(`...mapping the ${tmpDALEntityName} Meadow Endpoints to Orator`);
118
- this._MeadowEndpoints[tmpDALEntityName].connectRoutes(this.fable.Orator.webServer);
166
+ this.log.error(`Error initializing Retold Data Service: ${pError}`);
167
+ return fCallback(pError);
119
168
  }
120
-
169
+ this.fable.Orator.startWebServer.bind(this.fable.Orator);
121
170
  this.serviceInitialized = true;
122
-
123
- return fCallback(pError);
171
+ return fCallback();
124
172
  });
125
173
  }
126
174
  }