5htp 0.5.9-2 → 0.5.9-41

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/app/index.ts CHANGED
@@ -24,11 +24,13 @@ type TServiceSetup = {
24
24
  id: string,
25
25
  name: string,
26
26
  config: {},
27
- subservices: TServiceSubservices
27
+ subservices: TServiceSubservices,
28
+ type: 'service.setup'
28
29
  }
29
30
 
30
31
  type TServiceRef = {
31
- refTo: string
32
+ refTo: string,
33
+ type: 'service.ref'
32
34
  }
33
35
 
34
36
  type TServiceSubservices = {
@@ -134,6 +136,7 @@ export class App {
134
136
 
135
137
  return {
136
138
  refTo: referenceName,
139
+ type: 'service.ref'
137
140
  }
138
141
  }
139
142
 
@@ -141,21 +144,19 @@ export class App {
141
144
  // { user: app.setup('Core/User') }
142
145
  servicePath: string,
143
146
  serviceConfig?: {},
144
- serviceSubservices?: TServiceSubservices
145
147
  ] | [
146
148
  // app.setup('User', 'Core/User')
147
149
  serviceName: string,
148
150
  servicePath: string,
149
151
  serviceConfig?: {},
150
- serviceSubservices?: TServiceSubservices
151
152
  ]): TServiceSetup {
152
153
 
153
154
  // Registration to app root
154
155
  if (typeof args[1] === 'string') {
155
156
 
156
- const [name, id, config, subservices] = args;
157
+ const [name, id, config] = args;
157
158
 
158
- const service = { id, name, config, subservices } as TServiceSetup
159
+ const service = { id, name, config, type: 'service.setup' } as TServiceSetup
159
160
 
160
161
  this.registered[name] = service;
161
162
 
@@ -164,9 +165,9 @@ export class App {
164
165
  // Scoped to a parent service
165
166
  } else {
166
167
 
167
- const [id, config, subservices] = args;
168
+ const [id, config] = args;
168
169
 
169
- const service = { id, config, subservices } as TServiceSetup
170
+ const service = { id, config, type: 'service.setup' } as TServiceSetup
170
171
 
171
172
  return service;
172
173
  }
@@ -181,27 +182,6 @@ export class App {
181
182
  console.log("Loading config file:", configFile);
182
183
  require( path.resolve(configDir, configFile) );
183
184
  }
184
-
185
- // Wait 2 seconds
186
- await new Promise(resolve => setTimeout(resolve, 1000));
187
-
188
- // Load subservices
189
- // for (const serviceName in this.registered) {
190
- // const service = this.registered[serviceName];
191
-
192
- // const subservices = {}
193
- // if (service.subservices) {
194
- // const list = service.subservices( this.registered );
195
- // for (const subservice of list) {
196
-
197
- // subservices[subservice.name] = list[];
198
-
199
- // }
200
- // }
201
- // service.subservices = subservices;
202
- // }
203
-
204
- // console.log("SERVICES", this.registered);
205
185
  }
206
186
  }
207
187
 
package/compiler/index.ts CHANGED
@@ -34,7 +34,6 @@ type TRegisteredService = {
34
34
  name: string,
35
35
  instanciation: (parentRef: string) => string,
36
36
  priority: number,
37
- subservices?: string[]
38
37
  }
39
38
 
40
39
  /*----------------------------------
@@ -216,31 +215,37 @@ export default class Compiler {
216
215
  if (serviceConfig.name !== undefined)
217
216
  referencedNames[serviceConfig.id] = serviceConfig.name;
218
217
 
219
- // Subservices
220
- let subservices: string = '';
221
- let sortedSubservices: TRegisteredService[] = [];
222
- if (serviceConfig.subservices) {
218
+ const processConfig = (config: any, level: number = 0) => {
223
219
 
224
- const subservicesList = serviceConfig.subservices;
225
- const subservicesCode = Object.entries(subservicesList).map(([name, service]) =>
226
- refService(name, service, level + 1)
227
- );
220
+ let propsStr = '';
221
+ for (const key in config) {
222
+ const value = config[key];
223
+
224
+ if (!value || typeof value !== 'object')
225
+ propsStr += `"${key}":${serialize(value, { space: 4 })},\n`;
226
+
227
+ // Reference to a service
228
+ else if (value.type === 'service.setup' || value.type === 'service.ref') // TODO: more reliable way to detect a service reference
229
+ propsStr += `${key}:`+ refService(key, value, level + 1).instanciation('instance') + ',\n'
230
+
231
+ // Recursion
232
+ else if (level <= 4 && !Array.isArray(value))
233
+ propsStr += `"${key}":` + processConfig(value, level + 1) + ',\n';
228
234
 
229
- // Sort by priority
230
- sortedSubservices = subservicesCode.sort((a, b) => a.priority - b.priority);
235
+ else
236
+ propsStr += `"${key}":${serialize(value, { space: 4 })},\n`;
237
+
238
+ }
231
239
 
232
- // Generate code
233
- subservices = sortedSubservices.map(s => `${s.name}: ${s.instanciation('instance')},`).join('\n');
240
+ return `{ ${propsStr} }`;
234
241
  }
242
+ const config = processConfig(serviceConfig.config || {});
235
243
 
236
244
  // Generate the service instance
237
245
  const instanciation = (parentRef: string) =>
238
246
  `new ${serviceMetas.name}(
239
247
  ${parentRef},
240
- ${serialize(serviceConfig.config || {}) || '{}'},
241
- (instance: ${serviceMetas.name}) => ({
242
- ${subservices}
243
- }),
248
+ (instance: ${serviceMetas.name}) => (${config}),
244
249
  this
245
250
  )`
246
251
 
@@ -249,7 +254,6 @@ export default class Compiler {
249
254
  name: serviceName,
250
255
  instanciation,
251
256
  priority: serviceConfig.config?.priority || serviceMetas.priority || 0,
252
- subservices: sortedSubservices
253
257
  };
254
258
  }
255
259
 
@@ -42,6 +42,7 @@ const debug = false;
42
42
  export default function createCompiler( app: App, mode: TCompileMode ): webpack.Configuration {
43
43
 
44
44
  debug && console.info(`Creating compiler for server (${mode}).`);
45
+ mode = 'dev';
45
46
  const dev = mode === 'dev';
46
47
 
47
48
  const commonConfig = createCommonConfig(app, 'server', mode);
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "5htp",
3
3
  "description": "Convenient TypeScript framework designed for Performance and Productivity.",
4
- "version": "0.5.9-2",
4
+ "version": "0.5.9-41",
5
5
  "author": "Gaetan Le Gac (https://github.com/gaetanlegac)",
6
6
  "repository": "git://github.com/gaetanlegac/5htp.git",
7
7
  "license": "MIT",