retold-data-service 2.0.0 → 2.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 +1 -1
- package/source/Retold-Data-Service.js +82 -46
package/package.json
CHANGED
|
@@ -52,75 +52,111 @@ 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.Orator.webServer);
|
|
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
|
{
|
|
69
|
-
this.fable.
|
|
70
|
-
this.fable.Orator.startWebServer(
|
|
71
|
-
(pError) =>
|
|
72
|
-
{
|
|
73
|
-
if (pError)
|
|
74
|
-
{
|
|
75
|
-
console.log(`Error auto-starting Orator: ${pError}`, pError);
|
|
76
|
-
return fCallback(pError);
|
|
77
|
-
}
|
|
134
|
+
let tmpAnticipate = this.fable.newAnticipate();
|
|
78
135
|
|
|
79
|
-
|
|
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;
|
|
136
|
+
this.fable.log.info(`The Retold Data Service is Auto Starting Orator`);
|
|
85
137
|
|
|
86
|
-
|
|
138
|
+
tmpAnticipate.anticipate(this.onBeforeInitialize.bind(this));
|
|
87
139
|
|
|
88
|
-
|
|
140
|
+
tmpAnticipate.anticipate(this.fable.Orator.startWebServer.bind(this.fable.Orator));
|
|
141
|
+
tmpAnticipate.anticipate(this.initializePersistenceEngine.bind(this));
|
|
89
142
|
|
|
90
|
-
|
|
143
|
+
tmpAnticipate.anticipate(this.onInitialize.bind(this));
|
|
91
144
|
|
|
92
|
-
|
|
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.`);
|
|
145
|
+
tmpAnticipate.anticipate(this.initializeDataEndpoints.bind(this));
|
|
96
146
|
|
|
97
|
-
|
|
98
|
-
_Fable.log.info(`...getting entity list...`);
|
|
99
|
-
this.entityList = Object.keys(this.fullModel.Tables);
|
|
147
|
+
tmpAnticipate.anticipate(this.onAfterInitialize.bind(this));
|
|
100
148
|
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
149
|
+
tmpAnticipate.wait(
|
|
150
|
+
(pError)=>
|
|
151
|
+
{
|
|
152
|
+
if (pError)
|
|
104
153
|
{
|
|
105
|
-
|
|
106
|
-
|
|
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);
|
|
154
|
+
this.log.error(`Error initializing Retold Data Service: ${pError}`);
|
|
155
|
+
return fCallback(pError);
|
|
119
156
|
}
|
|
120
157
|
|
|
121
158
|
this.serviceInitialized = true;
|
|
122
|
-
|
|
123
|
-
return fCallback(pError);
|
|
159
|
+
return fCallback();
|
|
124
160
|
});
|
|
125
161
|
}
|
|
126
162
|
}
|