@nattyjs/core 0.0.1-beta.46 → 0.0.1-beta.48

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/dist/index.cjs CHANGED
@@ -126,13 +126,59 @@ function init(config, appConfig) {
126
126
  common.commonContainer.setupConfig(config);
127
127
  common.commonContainer.setEnvTsDefinition(appConfig.envTsDefinition);
128
128
  nattyContainer.setup(config, appConfig.routes, appConfig.resolver);
129
- return initializeModule(config);
129
+ callLifeCycleEvents(config, true);
130
+ const result = initializeModule(config);
131
+ callLifeCycleEvents(config);
132
+ startWebSchedule(config);
133
+ return result;
134
+ }
135
+ async function startWebSchedule(config) {
136
+ if (config.webSchedule) {
137
+ const interval = setInterval(async () => {
138
+ try {
139
+ clearInterval(interval);
140
+ await config.webSchedule.scheduleFunction();
141
+ startWebSchedule(config);
142
+ } catch (ex) {
143
+ startWebSchedule(config);
144
+ }
145
+ }, config.webSchedule.interval);
146
+ }
130
147
  }
131
148
  function initializeModule(config) {
132
149
  if (config.app) {
133
150
  return config.app.init(config);
134
151
  }
135
152
  }
153
+ async function callLifeCycleEvents(config, isPreInit = false) {
154
+ if (config.lifeCycle) {
155
+ if (config.lifeCycle.preInit && isPreInit) {
156
+ const preInit = config.lifeCycle.preInit();
157
+ if (preInit) {
158
+ if (preInit.cors) {
159
+ if (!config.cors) {
160
+ const jObject = { origin: [] };
161
+ config.cors = jObject;
162
+ } else if (!config.cors.origin)
163
+ config.cors.origin = [];
164
+ if (preInit.cors.origin)
165
+ preInit.cors.origin.forEach((t) => {
166
+ config.cors?.origin.push(t);
167
+ });
168
+ if (preInit.cors.methods)
169
+ config.cors.methods = preInit.cors.methods;
170
+ if (preInit.cors.optionsSuccessStatus)
171
+ config.cors.optionsSuccessStatus = preInit.cors.optionsSuccessStatus;
172
+ if (preInit.cors.preflightContinue)
173
+ config.cors.preflightContinue = preInit.cors.preflightContinue;
174
+ }
175
+ }
176
+ }
177
+ if (config.lifeCycle.onStart) {
178
+ config.lifeCycle.onStart();
179
+ }
180
+ }
181
+ }
136
182
 
137
183
  function getPreResponseBody(body, isBuffer = false) {
138
184
  let bodyInfo;
package/dist/index.mjs CHANGED
@@ -124,13 +124,59 @@ function init(config, appConfig) {
124
124
  commonContainer.setupConfig(config);
125
125
  commonContainer.setEnvTsDefinition(appConfig.envTsDefinition);
126
126
  nattyContainer.setup(config, appConfig.routes, appConfig.resolver);
127
- return initializeModule(config);
127
+ callLifeCycleEvents(config, true);
128
+ const result = initializeModule(config);
129
+ callLifeCycleEvents(config);
130
+ startWebSchedule(config);
131
+ return result;
132
+ }
133
+ async function startWebSchedule(config) {
134
+ if (config.webSchedule) {
135
+ const interval = setInterval(async () => {
136
+ try {
137
+ clearInterval(interval);
138
+ await config.webSchedule.scheduleFunction();
139
+ startWebSchedule(config);
140
+ } catch (ex) {
141
+ startWebSchedule(config);
142
+ }
143
+ }, config.webSchedule.interval);
144
+ }
128
145
  }
129
146
  function initializeModule(config) {
130
147
  if (config.app) {
131
148
  return config.app.init(config);
132
149
  }
133
150
  }
151
+ async function callLifeCycleEvents(config, isPreInit = false) {
152
+ if (config.lifeCycle) {
153
+ if (config.lifeCycle.preInit && isPreInit) {
154
+ const preInit = config.lifeCycle.preInit();
155
+ if (preInit) {
156
+ if (preInit.cors) {
157
+ if (!config.cors) {
158
+ const jObject = { origin: [] };
159
+ config.cors = jObject;
160
+ } else if (!config.cors.origin)
161
+ config.cors.origin = [];
162
+ if (preInit.cors.origin)
163
+ preInit.cors.origin.forEach((t) => {
164
+ config.cors?.origin.push(t);
165
+ });
166
+ if (preInit.cors.methods)
167
+ config.cors.methods = preInit.cors.methods;
168
+ if (preInit.cors.optionsSuccessStatus)
169
+ config.cors.optionsSuccessStatus = preInit.cors.optionsSuccessStatus;
170
+ if (preInit.cors.preflightContinue)
171
+ config.cors.preflightContinue = preInit.cors.preflightContinue;
172
+ }
173
+ }
174
+ }
175
+ if (config.lifeCycle.onStart) {
176
+ config.lifeCycle.onStart();
177
+ }
178
+ }
179
+ }
134
180
 
135
181
  function getPreResponseBody(body, isBuffer = false) {
136
182
  let bodyInfo;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nattyjs/core",
3
- "version": "0.0.1-beta.46",
3
+ "version": "0.0.1-beta.48",
4
4
  "description": "",
5
5
  "keywords": [],
6
6
  "author": "ajayojha",
@@ -18,7 +18,7 @@
18
18
  "reflect-metadata": "0.2.2",
19
19
  "tsyringe": "^4.7.0",
20
20
  "path-to-regexp": "6.2.1",
21
- "@nattyjs/common": "0.0.1-beta.46"
21
+ "@nattyjs/common": "0.0.1-beta.48"
22
22
  },
23
23
  "devDependencies": {
24
24
  "unbuild": "1.2.1"