electron-injector 1.1.1 → 1.1.3

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
@@ -52,7 +52,8 @@ __export(index_exports, {
52
52
  Reflector: () => Reflector,
53
53
  SetMetadata: () => SetMetadata,
54
54
  UseGuards: () => UseGuards,
55
- applyDecorators: () => applyDecorators
55
+ applyDecorators: () => applyDecorators,
56
+ createParamDecorator: () => createParamDecorator
56
57
  });
57
58
  module.exports = __toCommonJS(index_exports);
58
59
  var import_reflect_metadata = require("reflect-metadata");
@@ -200,6 +201,14 @@ function applyDecorators(...decorators) {
200
201
  };
201
202
  }
202
203
  __name(applyDecorators, "applyDecorators");
204
+ function createParamDecorator(fn) {
205
+ return function(target, propertyKey, paramIndex) {
206
+ const params = Reflect.getMetadata(PARAM, target, propertyKey) ?? [];
207
+ params[paramIndex] = fn;
208
+ Reflect.defineMetadata(PARAM, params, target, propertyKey);
209
+ };
210
+ }
211
+ __name(createParamDecorator, "createParamDecorator");
203
212
 
204
213
  // src/container.ts
205
214
  var Container = class {
@@ -294,7 +303,7 @@ var Application = class _Application {
294
303
  loadProviders() {
295
304
  for (const provider of this.configOptions.providers || []) {
296
305
  this.container.addProvider(provider);
297
- DEV_LOGGER(`Provider ${typeof provider == "object" ? provider.provided.name : provider.name} loaded`);
306
+ DEV_LOGGER(`[Electron Injector] Provider ${typeof provider == "object" ? provider.provided.name : provider.name} loaded`);
298
307
  }
299
308
  }
300
309
  bootstrap() {
@@ -309,7 +318,7 @@ var Application = class _Application {
309
318
  if (typeof handlerMetadata !== "object") continue;
310
319
  const handlerGuards = this.getGuards(controllerInstance[controllerMethod]);
311
320
  const guards = controllerGuards.filter((guard) => !handlerGuards.includes(guard)).concat(handlerGuards).map((guard) => this.container.resolve(guard));
312
- const path = this.buildPath(controllerPrefix, controllerMethod);
321
+ const path = this.buildPath(controllerPrefix, handlerMetadata.path);
313
322
  const handlerCallback = /* @__PURE__ */ __name(async (event, data) => {
314
323
  const executionContext = new ExecutionContext(controller, controllerInstance[controllerMethod], data, event);
315
324
  for (const guard of guards) {
@@ -362,6 +371,9 @@ var Application = class _Application {
362
371
  }
363
372
  return executionContext.payload;
364
373
  }
374
+ if (typeof param === "function") {
375
+ return param(executionContext);
376
+ }
365
377
  return void 0;
366
378
  }));
367
379
  }
@@ -553,5 +565,6 @@ __name(Catch, "Catch");
553
565
  Reflector,
554
566
  SetMetadata,
555
567
  UseGuards,
556
- applyDecorators
568
+ applyDecorators,
569
+ createParamDecorator
557
570
  });
package/dist/index.d.cts CHANGED
@@ -21,6 +21,7 @@ declare class ExecutionContext {
21
21
  set payload(payload: any);
22
22
  }
23
23
  declare function applyDecorators(...decorators: CallableFunction[]): (target: Object, _propertyKey?: string | symbol, descriptor?: PropertyDescriptor) => void;
24
+ declare function createParamDecorator(fn: (context: ExecutionContext) => any): ParameterDecorator;
24
25
 
25
26
  type Class<T = any> = new (...args: any[]) => T;
26
27
  type InjectableType = 'singleton' | 'transient';
@@ -100,4 +101,4 @@ declare class ForbiddenAccessError extends ElectronInjectorError {
100
101
  constructor(path: string, guardName: string);
101
102
  }
102
103
 
103
- export { Application, type CanActivate, Catch, CircularDependency, type ConfigOptions, Controller, ControllerIsNotValid, Ctx, DataValidationError, ElectronInjectorError, Event, type ExceptionFilter, ExecutionContext, ForbiddenAccessError, Injectable, type InjectableType, IsNotExceptionFilter, OnInvoke, OnSend, Payload, ProviderIsNotInjectable, ProviderNotFound, Reflector, SetMetadata, UseGuards, applyDecorators };
104
+ export { Application, type CanActivate, Catch, CircularDependency, type ConfigOptions, Controller, ControllerIsNotValid, Ctx, DataValidationError, ElectronInjectorError, Event, type ExceptionFilter, ExecutionContext, ForbiddenAccessError, Injectable, type InjectableType, IsNotExceptionFilter, OnInvoke, OnSend, Payload, ProviderIsNotInjectable, ProviderNotFound, Reflector, SetMetadata, UseGuards, applyDecorators, createParamDecorator };
package/dist/index.d.ts CHANGED
@@ -21,6 +21,7 @@ declare class ExecutionContext {
21
21
  set payload(payload: any);
22
22
  }
23
23
  declare function applyDecorators(...decorators: CallableFunction[]): (target: Object, _propertyKey?: string | symbol, descriptor?: PropertyDescriptor) => void;
24
+ declare function createParamDecorator(fn: (context: ExecutionContext) => any): ParameterDecorator;
24
25
 
25
26
  type Class<T = any> = new (...args: any[]) => T;
26
27
  type InjectableType = 'singleton' | 'transient';
@@ -100,4 +101,4 @@ declare class ForbiddenAccessError extends ElectronInjectorError {
100
101
  constructor(path: string, guardName: string);
101
102
  }
102
103
 
103
- export { Application, type CanActivate, Catch, CircularDependency, type ConfigOptions, Controller, ControllerIsNotValid, Ctx, DataValidationError, ElectronInjectorError, Event, type ExceptionFilter, ExecutionContext, ForbiddenAccessError, Injectable, type InjectableType, IsNotExceptionFilter, OnInvoke, OnSend, Payload, ProviderIsNotInjectable, ProviderNotFound, Reflector, SetMetadata, UseGuards, applyDecorators };
104
+ export { Application, type CanActivate, Catch, CircularDependency, type ConfigOptions, Controller, ControllerIsNotValid, Ctx, DataValidationError, ElectronInjectorError, Event, type ExceptionFilter, ExecutionContext, ForbiddenAccessError, Injectable, type InjectableType, IsNotExceptionFilter, OnInvoke, OnSend, Payload, ProviderIsNotInjectable, ProviderNotFound, Reflector, SetMetadata, UseGuards, applyDecorators, createParamDecorator };
package/dist/index.js CHANGED
@@ -147,6 +147,14 @@ function applyDecorators(...decorators) {
147
147
  };
148
148
  }
149
149
  __name(applyDecorators, "applyDecorators");
150
+ function createParamDecorator(fn) {
151
+ return function(target, propertyKey, paramIndex) {
152
+ const params = Reflect.getMetadata(PARAM, target, propertyKey) ?? [];
153
+ params[paramIndex] = fn;
154
+ Reflect.defineMetadata(PARAM, params, target, propertyKey);
155
+ };
156
+ }
157
+ __name(createParamDecorator, "createParamDecorator");
150
158
 
151
159
  // src/container.ts
152
160
  var Container = class {
@@ -241,7 +249,7 @@ var Application = class _Application {
241
249
  loadProviders() {
242
250
  for (const provider of this.configOptions.providers || []) {
243
251
  this.container.addProvider(provider);
244
- DEV_LOGGER(`Provider ${typeof provider == "object" ? provider.provided.name : provider.name} loaded`);
252
+ DEV_LOGGER(`[Electron Injector] Provider ${typeof provider == "object" ? provider.provided.name : provider.name} loaded`);
245
253
  }
246
254
  }
247
255
  bootstrap() {
@@ -256,7 +264,7 @@ var Application = class _Application {
256
264
  if (typeof handlerMetadata !== "object") continue;
257
265
  const handlerGuards = this.getGuards(controllerInstance[controllerMethod]);
258
266
  const guards = controllerGuards.filter((guard) => !handlerGuards.includes(guard)).concat(handlerGuards).map((guard) => this.container.resolve(guard));
259
- const path = this.buildPath(controllerPrefix, controllerMethod);
267
+ const path = this.buildPath(controllerPrefix, handlerMetadata.path);
260
268
  const handlerCallback = /* @__PURE__ */ __name(async (event, data) => {
261
269
  const executionContext = new ExecutionContext(controller, controllerInstance[controllerMethod], data, event);
262
270
  for (const guard of guards) {
@@ -309,6 +317,9 @@ var Application = class _Application {
309
317
  }
310
318
  return executionContext.payload;
311
319
  }
320
+ if (typeof param === "function") {
321
+ return param(executionContext);
322
+ }
312
323
  return void 0;
313
324
  }));
314
325
  }
@@ -499,5 +510,6 @@ export {
499
510
  Reflector,
500
511
  SetMetadata,
501
512
  UseGuards,
502
- applyDecorators
513
+ applyDecorators,
514
+ createParamDecorator
503
515
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "electron-injector",
3
- "version": "1.1.1",
3
+ "version": "1.1.3",
4
4
  "description": "Biblioteca para el desarrollo de aplicaciones con electron que proporciona una arquitectura robusta con inyección e inversion de dependencias.",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",