@proteinjs/service 1.1.1 → 1.2.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/CHANGELOG.md CHANGED
@@ -3,6 +3,22 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
+ # [1.2.0](https://github.com/proteinjs/service/compare/@proteinjs/service@1.1.1...@proteinjs/service@1.2.0) (2025-02-06)
7
+
8
+
9
+ ### Bug Fixes
10
+
11
+ * fix typing for the debounce config ([62bb2d6](https://github.com/proteinjs/service/commit/62bb2d646e2c71f2bf5300364cd92bbd95911f21))
12
+
13
+
14
+ ### Features
15
+
16
+ * method specific debouncers. allows one service to use multiple debouncers for each method in the service. ([00fa7b2](https://github.com/proteinjs/service/commit/00fa7b23c4960ad9a006d4791e9f5a12f9ab6c89))
17
+
18
+
19
+
20
+
21
+
6
22
  ## [1.1.1](https://github.com/proteinjs/service/compare/@proteinjs/service@1.1.0...@proteinjs/service@1.1.1) (2024-09-10)
7
23
 
8
24
 
@@ -22,7 +22,7 @@ require("@proteinjs/server-api");
22
22
  require("@proteinjs/user-auth");
23
23
  require("@proteinjs/util");
24
24
  /** Generate Source Graph */
25
- var sourceGraph = "{\"options\":{\"directed\":true,\"multigraph\":false,\"compound\":false},\"nodes\":[{\"v\":\"@proteinjs/service/Service\",\"value\":{\"packageName\":\"@proteinjs/service\",\"name\":\"Service\",\"filePath\":\"/home/runner/work/service/service/packages/service/src/Service.ts\",\"qualifiedName\":\"@proteinjs/service/Service\",\"properties\":[{\"name\":\"serviceMetadata\",\"type\":{\"packageName\":\"@proteinjs/service\",\"name\":\"{\\n auth?: {\\n /** If true, the user does not need to be logged in or have any roles to call this service. If blank, defaults to false. */\\n public?: boolean;\\n /** If true, the user does not need to have any roles to call this service, but must be logged in. If blank, defaults to false. */\\n allUsers?: boolean;\\n /** The user must be logged in and have these roles to call this service. If blank, defaults to requiring the 'admin' role. */\\n roles?: string[];\\n /**\\n * Custom auth function. If provided, all other auth properties are ignored.\\n * @param methodName the name of the service method to be executed\\n * @param args the args[] that will be passed into the method\\n * @return true if the user can access the service method\\n */\\n canAccess?: (methodName: string, args: any[]) => boolean;\\n };\\n /** Don't await the service's execution, return a response to the client immediately */\\n doNotAwait?: boolean;\\n }\",\"filePath\":null,\"qualifiedName\":\"@proteinjs/service/{\\n auth?: {\\n /** If true, the user does not need to be logged in or have any roles to call this service. If blank, defaults to false. */\\n public?: boolean;\\n /** If true, the user does not need to have any roles to call this service, but must be logged in. If blank, defaults to false. */\\n allUsers?: boolean;\\n /** The user must be logged in and have these roles to call this service. If blank, defaults to requiring the 'admin' role. */\\n roles?: string[];\\n /**\\n * Custom auth function. If provided, all other auth properties are ignored.\\n * @param methodName the name of the service method to be executed\\n * @param args the args[] that will be passed into the method\\n * @return true if the user can access the service method\\n */\\n canAccess?: (methodName: string, args: any[]) => boolean;\\n };\\n /** Don't await the service's execution, return a response to the client immediately */\\n doNotAwait?: boolean;\\n }\",\"typeParameters\":null,\"directParents\":null},\"isOptional\":true,\"isAbstract\":false,\"isStatic\":false,\"visibility\":\"public\"}],\"methods\":[],\"typeParameters\":[],\"directParents\":[{\"packageName\":\"@proteinjs/reflection\",\"name\":\"Loadable\",\"filePath\":null,\"qualifiedName\":\"@proteinjs/reflection/Loadable\",\"properties\":[],\"methods\":[],\"typeParameters\":[],\"directParents\":[]}],\"sourceType\":3}},{\"v\":\"@proteinjs/reflection/Loadable\"},{\"v\":\"/Error\"},{\"v\":\"@proteinjs/service/ServiceRouter\",\"value\":{\"packageName\":\"@proteinjs/service\",\"name\":\"ServiceRouter\",\"filePath\":\"/home/runner/work/service/service/packages/service/src/ServiceRouter.ts\",\"qualifiedName\":\"@proteinjs/service/ServiceRouter\",\"isAbstract\":false,\"isStatic\":false,\"visibility\":\"public\",\"properties\":[{\"name\":\"logger\",\"type\":null,\"isOptional\":false,\"isAbstract\":false,\"isStatic\":false,\"visibility\":\"private\"},{\"name\":\"serviceExecutorMap\",\"type\":{\"packageName\":\"@proteinjs/service\",\"name\":\"{ [path: string]: ServiceExecutor } | undefined\",\"filePath\":null,\"qualifiedName\":\"@proteinjs/service/{ [path: string]: ServiceExecutor } | undefined\",\"typeParameters\":null,\"directParents\":null},\"isOptional\":false,\"isAbstract\":false,\"isStatic\":false,\"visibility\":\"private\"},{\"name\":\"path\",\"type\":null,\"isOptional\":false,\"isAbstract\":false,\"isStatic\":false,\"visibility\":\"public\"},{\"name\":\"method\",\"type\":{\"packageName\":\"\",\"name\":\"'post'\",\"filePath\":null,\"qualifiedName\":\"/'post'\",\"typeParameters\":null,\"directParents\":null},\"isOptional\":false,\"isAbstract\":false,\"isStatic\":false,\"visibility\":\"public\"}],\"methods\":[{\"name\":\"getServiceExecutorMap\",\"returnType\":null,\"isAsync\":false,\"isOptional\":false,\"isAbstract\":false,\"isStatic\":false,\"visibility\":\"private\",\"parameters\":[]},{\"name\":\"onRequest\",\"returnType\":{\"packageName\":\"\",\"name\":\"Promise<any>\",\"filePath\":null,\"qualifiedName\":\"/Promise<any>\",\"typeParameters\":null,\"directParents\":null},\"isAsync\":true,\"isOptional\":false,\"isAbstract\":false,\"isStatic\":false,\"visibility\":\"public\",\"parameters\":[{\"name\":\"request\",\"type\":{\"packageName\":\"\",\"name\":\"any\",\"filePath\":null,\"qualifiedName\":\"/any\",\"typeParameters\":null,\"directParents\":null}},{\"name\":\"response\",\"type\":{\"packageName\":\"\",\"name\":\"any\",\"filePath\":null,\"qualifiedName\":\"/any\",\"typeParameters\":null,\"directParents\":null}}]}],\"typeParameters\":[],\"directParentInterfaces\":[{\"packageName\":\"@proteinjs/server-api\",\"name\":\"Route\",\"filePath\":null,\"qualifiedName\":\"@proteinjs/server-api/Route\",\"properties\":[],\"methods\":[],\"typeParameters\":[],\"directParents\":[]}],\"directParentClasses\":[],\"sourceType\":2}},{\"v\":\"@proteinjs/server-api/Route\"}],\"edges\":[{\"v\":\"@proteinjs/service/Service\",\"w\":\"@proteinjs/reflection/Loadable\",\"value\":\"extends interface\"},{\"v\":\"@proteinjs/service/ServiceRouter\",\"w\":\"@proteinjs/server-api/Route\",\"value\":\"implements interface\"}]}";
25
+ var sourceGraph = "{\"options\":{\"directed\":true,\"multigraph\":false,\"compound\":false},\"nodes\":[{\"v\":\"@proteinjs/service/MethodDebounceConfig\"},{\"v\":\"@proteinjs/service/Service\",\"value\":{\"packageName\":\"@proteinjs/service\",\"name\":\"Service\",\"filePath\":\"/Users/brentbahry/repos/n3xa/packages/proteinjs/packages/service/packages/service/src/Service.ts\",\"qualifiedName\":\"@proteinjs/service/Service\",\"properties\":[{\"name\":\"serviceMetadata\",\"type\":{\"packageName\":\"@proteinjs/service\",\"name\":\"{\\n auth?: {\\n /** If true, the user does not need to be logged in or have any roles to call this service. If blank, defaults to false. */\\n public?: boolean;\\n /** If true, the user does not need to have any roles to call this service, but must be logged in. If blank, defaults to false. */\\n allUsers?: boolean;\\n /** The user must be logged in and have these roles to call this service. If blank, defaults to requiring the 'admin' role. */\\n roles?: string[];\\n /**\\n * Custom auth function. If provided, all other auth properties are ignored.\\n * @param methodName the name of the service method to be executed\\n * @param args the args[] that will be passed into the method\\n * @return true if the user can access the service method\\n */\\n canAccess?: (methodName: string, args: any[]) => boolean;\\n };\\n /** Don't await the service's execution, return a response to the client immediately */\\n doNotAwait?: boolean;\\n /** Don't await the service's execution, return a response to the client immediately (configured per method) */\\n doNotAwaitMethod?: MethodAwaitConfig;\\n }\",\"filePath\":null,\"qualifiedName\":\"@proteinjs/service/{\\n auth?: {\\n /** If true, the user does not need to be logged in or have any roles to call this service. If blank, defaults to false. */\\n public?: boolean;\\n /** If true, the user does not need to have any roles to call this service, but must be logged in. If blank, defaults to false. */\\n allUsers?: boolean;\\n /** The user must be logged in and have these roles to call this service. If blank, defaults to requiring the 'admin' role. */\\n roles?: string[];\\n /**\\n * Custom auth function. If provided, all other auth properties are ignored.\\n * @param methodName the name of the service method to be executed\\n * @param args the args[] that will be passed into the method\\n * @return true if the user can access the service method\\n */\\n canAccess?: (methodName: string, args: any[]) => boolean;\\n };\\n /** Don't await the service's execution, return a response to the client immediately */\\n doNotAwait?: boolean;\\n /** Don't await the service's execution, return a response to the client immediately (configured per method) */\\n doNotAwaitMethod?: MethodAwaitConfig;\\n }\",\"typeParameters\":null,\"directParents\":null},\"isOptional\":true,\"isAbstract\":false,\"isStatic\":false,\"visibility\":\"public\"}],\"methods\":[],\"typeParameters\":[],\"directParents\":[{\"packageName\":\"@proteinjs/reflection\",\"name\":\"Loadable\",\"filePath\":null,\"qualifiedName\":\"@proteinjs/reflection/Loadable\",\"properties\":[],\"methods\":[],\"typeParameters\":[],\"directParents\":[]}],\"sourceType\":3}},{\"v\":\"@proteinjs/reflection/Loadable\"},{\"v\":\"/Error\"},{\"v\":\"@proteinjs/service/ServiceRouter\",\"value\":{\"packageName\":\"@proteinjs/service\",\"name\":\"ServiceRouter\",\"filePath\":\"/Users/brentbahry/repos/n3xa/packages/proteinjs/packages/service/packages/service/src/ServiceRouter.ts\",\"qualifiedName\":\"@proteinjs/service/ServiceRouter\",\"isAbstract\":false,\"isStatic\":false,\"visibility\":\"public\",\"properties\":[{\"name\":\"logger\",\"type\":null,\"isOptional\":false,\"isAbstract\":false,\"isStatic\":false,\"visibility\":\"private\"},{\"name\":\"serviceExecutorMap\",\"type\":{\"packageName\":\"@proteinjs/service\",\"name\":\"{ [path: string]: ServiceExecutor } | undefined\",\"filePath\":null,\"qualifiedName\":\"@proteinjs/service/{ [path: string]: ServiceExecutor } | undefined\",\"typeParameters\":null,\"directParents\":null},\"isOptional\":false,\"isAbstract\":false,\"isStatic\":false,\"visibility\":\"private\"},{\"name\":\"path\",\"type\":null,\"isOptional\":false,\"isAbstract\":false,\"isStatic\":false,\"visibility\":\"public\"},{\"name\":\"method\",\"type\":{\"packageName\":\"\",\"name\":\"'post'\",\"filePath\":null,\"qualifiedName\":\"/'post'\",\"typeParameters\":null,\"directParents\":null},\"isOptional\":false,\"isAbstract\":false,\"isStatic\":false,\"visibility\":\"public\"}],\"methods\":[{\"name\":\"getServiceExecutorMap\",\"returnType\":null,\"isAsync\":false,\"isOptional\":false,\"isAbstract\":false,\"isStatic\":false,\"visibility\":\"private\",\"parameters\":[]},{\"name\":\"onRequest\",\"returnType\":{\"packageName\":\"\",\"name\":\"Promise<any>\",\"filePath\":null,\"qualifiedName\":\"/Promise<any>\",\"typeParameters\":null,\"directParents\":null},\"isAsync\":true,\"isOptional\":false,\"isAbstract\":false,\"isStatic\":false,\"visibility\":\"public\",\"parameters\":[{\"name\":\"request\",\"type\":{\"packageName\":\"\",\"name\":\"any\",\"filePath\":null,\"qualifiedName\":\"/any\",\"typeParameters\":null,\"directParents\":null}},{\"name\":\"response\",\"type\":{\"packageName\":\"\",\"name\":\"any\",\"filePath\":null,\"qualifiedName\":\"/any\",\"typeParameters\":null,\"directParents\":null}}]}],\"typeParameters\":[],\"directParentInterfaces\":[{\"packageName\":\"@proteinjs/server-api\",\"name\":\"Route\",\"filePath\":null,\"qualifiedName\":\"@proteinjs/server-api/Route\",\"properties\":[],\"methods\":[],\"typeParameters\":[],\"directParents\":[]}],\"directParentClasses\":[],\"sourceType\":2}},{\"v\":\"@proteinjs/server-api/Route\"}],\"edges\":[{\"v\":\"@proteinjs/service/Service\",\"w\":\"@proteinjs/reflection/Loadable\",\"value\":\"extends interface\"},{\"v\":\"@proteinjs/service/ServiceRouter\",\"w\":\"@proteinjs/server-api/Route\",\"value\":\"implements interface\"}]}";
26
26
  /** Generate Source Links */
27
27
  var ServiceRouter_1 = require("../src/ServiceRouter");
28
28
  var sourceLinks = {
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../generated/index.ts"],"names":[],"mappings":";AAAA,oCAAoC;;;;;;;;;;;;;;;;AAEpC,6BAA2B;AAC3B,iCAA+B;AAC/B,iCAA+B;AAC/B,iCAA+B;AAC/B,gCAA8B;AAC9B,2BAAyB;AAGzB,4BAA4B;AAE5B,IAAM,WAAW,GAAG,2jLAA2jL,CAAC;AAGhlL,4BAA4B;AAE5B,sDAAqD;AAErD,IAAM,WAAW,GAAG;IACnB,kCAAkC,EAAE,6BAAa;CACjD,CAAC;AAGF,kCAAkC;AAElC,oDAAyD;AACzD,6BAAgB,CAAC,KAAK,CAAC,WAAW,EAAE,WAAW,CAAC,CAAC;AAGjD,2CAAyB"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../generated/index.ts"],"names":[],"mappings":";AAAA,oCAAoC;;;;;;;;;;;;;;;;AAEpC,6BAA2B;AAC3B,iCAA+B;AAC/B,iCAA+B;AAC/B,iCAA+B;AAC/B,gCAA8B;AAC9B,2BAAyB;AAGzB,4BAA4B;AAE5B,IAAM,WAAW,GAAG,i/LAAi/L,CAAC;AAGtgM,4BAA4B;AAE5B,sDAAqD;AAErD,IAAM,WAAW,GAAG;IACnB,kCAAkC,EAAE,6BAAa;CACjD,CAAC;AAGF,kCAAkC;AAElC,oDAAyD;AACzD,6BAAgB,CAAC,KAAK,CAAC,WAAW,EAAE,WAAW,CAAC,CAAC;AAGjD,2CAAyB"}
@@ -1,6 +1,6 @@
1
1
  import { SerializableFunction, NotFunction } from '@proteinjs/serializer';
2
2
  import { Loadable } from '@proteinjs/reflection';
3
- import { Debouncer } from '@proteinjs/util';
3
+ import { Debouncer, GetDebounceKey } from '@proteinjs/util';
4
4
  type RemoveIndex<T> = {
5
5
  [K in keyof T as string extends K ? never : number extends K ? never : symbol extends K ? never : K]: T[K];
6
6
  };
@@ -10,6 +10,17 @@ type KeysWithoutService<T extends Service> = Diff<KeysWithoutIndexSignature<T>,
10
10
  type RetryConfig<T extends Service> = {
11
11
  [K in KeysWithoutService<T>]?: number;
12
12
  };
13
+ interface DebounceConfig {
14
+ waitTime: number;
15
+ getDebounceKey?: GetDebounceKey;
16
+ }
17
+ type MethodDebounceConfig<T extends Service> = {
18
+ [K in KeysWithoutService<T>]?: DebounceConfig;
19
+ };
20
+ type MethodAwaitConfig = {
21
+ [methodName: string]: boolean;
22
+ };
23
+ export type ServiceDebounceConfig<T extends Service> = MethodDebounceConfig<T> | Debouncer;
13
24
  export interface Service extends Loadable {
14
25
  serviceMetadata?: {
15
26
  auth?: {
@@ -29,6 +40,8 @@ export interface Service extends Loadable {
29
40
  };
30
41
  /** Don't await the service's execution, return a response to the client immediately */
31
42
  doNotAwait?: boolean;
43
+ /** Don't await the service's execution, return a response to the client immediately (configured per method) */
44
+ doNotAwaitMethod?: MethodAwaitConfig;
32
45
  };
33
46
  [prop: string]: SerializableFunction | NotFunction<any>;
34
47
  }
@@ -36,9 +49,9 @@ export interface Service extends Loadable {
36
49
  * Create a factory that creates an instance of the Service. The Service instance is a
37
50
  * ServiceClient wrapped in the interface's api.
38
51
  * @param serviceInterfaceQualifiedName the package-qualified name of the service interface (ie. service-package-name/MyService)
39
- * @param debouncer optionally pass in an instance of debouncer if you want to limit service client calls
52
+ * @param debouncer pass in either a single debouncer instance or method-specific debounce configurations
40
53
  * @returns a function that creates a Service
41
54
  */
42
- export declare const serviceFactory: <T extends Service>(serviceInterfaceQualifiedName: string, debouncer?: Debouncer, retryConfig?: RetryConfig<T> | undefined) => () => T;
55
+ export declare const serviceFactory: <T extends Service>(serviceInterfaceQualifiedName: string, debouncer?: ServiceDebounceConfig<T> | undefined, retryConfig?: RetryConfig<T> | undefined) => () => T;
43
56
  export {};
44
57
  //# sourceMappingURL=Service.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"Service.d.ts","sourceRoot":"","sources":["../../src/Service.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AAC1E,OAAO,EAAE,QAAQ,EAAoB,MAAM,uBAAuB,CAAC;AAEnE,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAE5C,KAAK,WAAW,CAAC,CAAC,IAAI;KACnB,CAAC,IAAI,MAAM,CAAC,IAAI,MAAM,SAAS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,IAAI,oBAAoB,CAAC,CAAC,CAAC,GAAG,SAAS,CAAC;AAE3F,MAAM,WAAW,OAAQ,SAAQ,QAAQ;IACvC,eAAe,CAAC,EAAE;QAChB,IAAI,CAAC,EAAE;YACL,2HAA2H;YAC3H,MAAM,CAAC,EAAE,OAAO,CAAC;YACjB,kIAAkI;YAClI,QAAQ,CAAC,EAAE,OAAO,CAAC;YACnB,8HAA8H;YAC9H,KAAK,CAAC,EAAE,MAAM,EAAE,CAAC;YACjB;;;;;eAKG;YACH,SAAS,CAAC,EAAE,CAAC,UAAU,EAAE,MAAM,EAAE,IAAI,EAAE,GAAG,EAAE,KAAK,OAAO,CAAC;SAC1D,CAAC;QACF,uFAAuF;QACvF,UAAU,CAAC,EAAE,OAAO,CAAC;QACrB,+GAA+G;QAC/G,gBAAgB,CAAC,EAAE,iBAAiB,CAAC;KACtC,CAAC;IACF,CAAC,IAAI,EAAE,MAAM,GAAG,oBAAoB,GAAG,WAAW,CAAC,GAAG,CAAC,CAAC;CACzD;AAaD;;;;;;GAMG;AACH,eAAO,MAAM,cAAc,qDACM,MAAM,wGAkCtC,CAAC"}
@@ -3,11 +3,22 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.serviceFactory = void 0;
4
4
  var reflection_1 = require("@proteinjs/reflection");
5
5
  var ServiceClient_1 = require("./ServiceClient");
6
+ var util_1 = require("@proteinjs/util");
7
+ var debouncerMap = {};
8
+ /** Retrieve an existing debouncer from the map or make a new one.
9
+ * This allows the debouncer instance per method to remain the same across multiple service calls.
10
+ */
11
+ function getOrCreateDebouncer(methodName, config) {
12
+ if (!debouncerMap[methodName]) {
13
+ debouncerMap[methodName] = new util_1.Debouncer(config.waitTime, config.getDebounceKey);
14
+ }
15
+ return debouncerMap[methodName];
16
+ }
6
17
  /**
7
18
  * Create a factory that creates an instance of the Service. The Service instance is a
8
19
  * ServiceClient wrapped in the interface's api.
9
20
  * @param serviceInterfaceQualifiedName the package-qualified name of the service interface (ie. service-package-name/MyService)
10
- * @param debouncer optionally pass in an instance of debouncer if you want to limit service client calls
21
+ * @param debouncer pass in either a single debouncer instance or method-specific debounce configurations
11
22
  * @returns a function that creates a Service
12
23
  */
13
24
  var serviceFactory = function (serviceInterfaceQualifiedName, debouncer, retryConfig) {
@@ -17,13 +28,25 @@ var serviceFactory = function (serviceInterfaceQualifiedName, debouncer, retryCo
17
28
  for (var _i = 0, _a = serviceInterface.methods; _i < _a.length; _i++) {
18
29
  var method = _a[_i];
19
30
  var servicePath = "/service/".concat(serviceInterface.qualifiedName, "/").concat(method.name);
31
+ var methodName = method.name;
20
32
  var retryCount = 0;
21
- if (retryConfig && method.name in retryConfig) {
22
- var methodName = method.name;
33
+ if (retryConfig && methodName in retryConfig) {
23
34
  retryCount = retryConfig[methodName];
24
35
  }
25
- var serviceClient = new ServiceClient_1.ServiceClient(servicePath, method, debouncer, retryCount);
26
- service[method.name] = serviceClient.send.bind(serviceClient);
36
+ var methodDebouncer = void 0;
37
+ if (debouncer) {
38
+ if ((0, util_1.isInstanceOf)(debouncer, util_1.Debouncer)) {
39
+ methodDebouncer = debouncer;
40
+ }
41
+ else if (methodName in debouncer) {
42
+ var methodConfig = debouncer[methodName];
43
+ if (methodConfig) {
44
+ methodDebouncer = getOrCreateDebouncer(methodName, methodConfig);
45
+ }
46
+ }
47
+ }
48
+ var serviceClient = new ServiceClient_1.ServiceClient(servicePath, method, methodDebouncer, retryCount);
49
+ service[methodName] = serviceClient.send.bind(serviceClient);
27
50
  }
28
51
  return service;
29
52
  };
@@ -1 +1 @@
1
- {"version":3,"file":"Service.js","sourceRoot":"","sources":["../../src/Service.ts"],"names":[],"mappings":";;;AACA,oDAAmE;AACnE,iDAAgD;AAyChD;;;;;;GAMG;AACI,IAAM,cAAc,GAAG,UAC5B,6BAAqC,EACrC,SAAqB,EACrB,WAA4B;IAE5B,OAAO;QACL,IAAM,OAAO,GAAQ,EAAE,CAAC;QACxB,IAAM,gBAAgB,GAAG,6BAAgB,CAAC,GAA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= /** @class */ (function () {
111
111
  }); };
112
112
  executeRequest = this.retryCount > 0 ? executeWithRetry : function (fn) { return fn(); };
113
113
  if (this.debouncer) {
114
- return [2 /*return*/, this.debouncer.debounce(function () { return executeRequest(sendRequest); })];
114
+ return [2 /*return*/, this.debouncer.debounce(function () { return executeRequest(sendRequest); }, args)];
115
115
  }
116
116
  else {
117
117
  return [2 /*return*/, executeRequest(sendRequest)];
@@ -1 +1 @@
1
- {"version":3,"file":"ServiceClient.js","sourceRoot":"","sources":["../../src/ServiceClient.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AACA,oDAAmD;AAEnD,uDAAsD;AAEtD;IAGE,uBACU,WAAmB,EACnB,aAAqB,EACrB,SAAqB,EACrB,UAAsB;QAAtB,2BAAA,EAAA,cAAsB;QAHtB,gBAAW,GAAX,WAAW,CAAQ;QACnB,kBAAa,GAAb,aAAa,CAAQ;QACrB,cAAS,GAAT,SAAS,CAAY;QACrB,eAAU,GAAV,UAAU,CAAY;IAC7B,CAAC;IAEE,4BAAI,GAAV;QAAW,cAAc;aAAd,UAAc,EAAd,qBAAc,EAAd,IAAc;YAAd,yBAAc;;;;;;gBACjB,WAAW,GAAG;;;;;gCACZ,cAAc,GAAG,uBAAU,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC;gCAC5C,aAAa,GAAG,aAAa,CAAC,cAAc,CAAC;gCACnD,aAAa,CAAC,cAAc,EAAE,CAAC;gCAC/B,OAAO,CAAC,cAAc,CAAC,YAAK,aAAa,wCAA8B,IAAI,CAAC,WAAW,YAAS,CAAC,CAAC;gCAClG,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;gCAClB,OAAO,CAAC,QAAQ,EAAE,CAAC;gCACM,qBAAM,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,WAAW,EAAE,cAAc,CAAC,EAAA;;gCAArE,gBAAgB,GAAG,SAAkD;gCACrE,kBAAkB,GAAG,uBAAU,CAAC,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AAI,CAAC,KAAK,CAAC,CAAC;yBAC7B;wBAED,sBAAO,IAAI,CAAC,gBAAgB,EAAC;;;;KAC9B;IAxEc,4BAAc,GAAG,CAAC,CAAC;IAyEpC,oBAAC;CAAA,AA1ED,IA0EC;AA1EY,sCAAa"}
@@ -12,6 +12,7 @@ export declare class ServiceExecutor {
12
12
  private serviceMethodName;
13
13
  constructor(service: Service, _interface: Interface, method: Method);
14
14
  execute(requestBody: any): Promise<any>;
15
+ private doNotAwait;
15
16
  private shouldLogArgsAndReturn;
16
17
  }
17
18
  //# sourceMappingURL=ServiceExecutor.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"ServiceExecutor.d.ts","sourceRoot":"","sources":["../../src/ServiceExecutor.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM,uBAAuB,CAAC;AAC1D,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAOpC,qBAAa,YAAa,SAAQ,KAAK;gBACzB,OAAO,EAAE,MAAM;CAI5B;AAED,qBAAa,eAAe;IAKjB,OAAO,EAAE,OAAO;IACvB,OAAO,CAAC,UAAU;IAClB,OAAO,CAAC,MAAM;IANhB,OAAO,CAAC,MAAM,CAAS;IAChB,gBAAgB,EAAE,GAAG,CAAC;IAC7B,OAAO,CAAC,iBAAiB,CAAS;gBAEzB,OAAO,EAAE,OAAO,EACf,UAAU,EAAE,SAAS,EACrB,MAAM,EAAE,MAAM;IAMlB,OAAO,CAAC,WAAW,EAAE,GAAG,GAAG,OAAO,CAAC,GAAG,CAAC;IA4C7C,OAAO,CAAC,sBAAsB;CAG/B"}
1
+ {"version":3,"file":"ServiceExecutor.d.ts","sourceRoot":"","sources":["../../src/ServiceExecutor.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM,uBAAuB,CAAC;AAC1D,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAOpC,qBAAa,YAAa,SAAQ,KAAK;gBACzB,OAAO,EAAE,MAAM;CAI5B;AAED,qBAAa,eAAe;IAKjB,OAAO,EAAE,OAAO;IACvB,OAAO,CAAC,UAAU;IAClB,OAAO,CAAC,MAAM;IANhB,OAAO,CAAC,MAAM,CAAS;IAChB,gBAAgB,EAAE,GAAG,CAAC;IAC7B,OAAO,CAAC,iBAAiB,CAAS;gBAEzB,OAAO,EAAE,OAAO,EACf,UAAU,EAAE,SAAS,EACrB,MAAM,EAAE,MAAM;IAMlB,OAAO,CAAC,WAAW,EAAE,GAAG,GAAG,OAAO,CAAC,GAAG,CAAC;IA4C7C,OAAO,CAAC,UAAU;IAalB,OAAO,CAAC,sBAAsB;CAG/B"}
@@ -76,11 +76,10 @@ var ServiceExecutor = /** @class */ (function () {
76
76
  this.logger = new logger_1.Logger({ name: this.serviceMethodName });
77
77
  }
78
78
  ServiceExecutor.prototype.execute = function (requestBody) {
79
- var _a;
80
79
  return __awaiter(this, void 0, void 0, function () {
81
80
  var method, deserializedArgs, error, _return, error_1, serializedReturn;
82
- return __generator(this, function (_b) {
83
- switch (_b.label) {
81
+ return __generator(this, function (_a) {
82
+ switch (_a.label) {
84
83
  case 0:
85
84
  method = this.service[this.method.name].bind(this.service);
86
85
  deserializedArgs = serializer_1.Serializer.deserialize(requestBody);
@@ -91,19 +90,19 @@ var ServiceExecutor = /** @class */ (function () {
91
90
  error = "User not authorized to run service: ".concat(this._interface.name, ".").concat(this.method.name);
92
91
  throw new Error(error);
93
92
  }
94
- _b.label = 1;
93
+ _a.label = 1;
95
94
  case 1:
96
- _b.trys.push([1, 5, , 6]);
97
- if (!((_a = this.service.serviceMetadata) === null || _a === void 0 ? void 0 : _a.doNotAwait)) return [3 /*break*/, 2];
95
+ _a.trys.push([1, 5, , 6]);
96
+ if (!this.doNotAwait()) return [3 /*break*/, 2];
98
97
  method.apply(void 0, deserializedArgs);
99
98
  return [3 /*break*/, 4];
100
99
  case 2: return [4 /*yield*/, method.apply(void 0, deserializedArgs)];
101
100
  case 3:
102
- _return = _b.sent();
103
- _b.label = 4;
101
+ _return = _a.sent();
102
+ _a.label = 4;
104
103
  case 4: return [3 /*break*/, 6];
105
104
  case 5:
106
- error_1 = _b.sent();
105
+ error_1 = _a.sent();
107
106
  this.logger.error({
108
107
  message: "Failed",
109
108
  error: error_1,
@@ -129,6 +128,17 @@ var ServiceExecutor = /** @class */ (function () {
129
128
  });
130
129
  });
131
130
  };
131
+ ServiceExecutor.prototype.doNotAwait = function () {
132
+ var _a, _b, _c;
133
+ if ((_a = this.service.serviceMetadata) === null || _a === void 0 ? void 0 : _a.doNotAwait) {
134
+ return true;
135
+ }
136
+ if ((_b = this.service.serviceMetadata) === null || _b === void 0 ? void 0 : _b.doNotAwaitMethod) {
137
+ var methodDoNotAwait = (_c = this.service.serviceMetadata) === null || _c === void 0 ? void 0 : _c.doNotAwaitMethod[this.method.name];
138
+ return typeof methodDoNotAwait === 'boolean' ? methodDoNotAwait : false;
139
+ }
140
+ return false;
141
+ };
132
142
  ServiceExecutor.prototype.shouldLogArgsAndReturn = function () {
133
143
  return !server_api_1.EnvInfo.isDev() || process.env.DETAILED_SERVICE_LOGS;
134
144
  };
@@ -1 +1 @@
1
- {"version":3,"file":"ServiceExecutor.js","sourceRoot":"","sources":["../../src/ServiceExecutor.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEA,4CAA2C;AAC3C,oDAAmD;AACnD,6CAA4C;AAC5C,uDAAsD;AACtD,oDAAgD;AAEhD;IAAkC,gCAAK;IACrC,sBAAY,OAAe;QAA3B,YACE,kBAAM,OAAO,CAAC,SAEf;QADC,KAAI,CAAC,IAAI,GAAG,cAAc,CAAC;;IAC7B,CAAC;IACH,mBAAC;AAAD,CAAC,AALD,CAAkC,KAAK,GAKtC;AALY,oCAAY;AAOzB;IAIE,yBACS,OAAgB,EACf,UAAqB,EACrB,MAAc;QAFf,YAAO,GAAP,OAAO,CA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,OAAO,CAAC,eAAe,0CAAE,UAAU,EAAE;YAC5C,OAAO,IAAI,CAAC;SACb;QAED,IAAI,MAAA,IAAI,CAAC,OAAO,CAAC,eAAe,0CAAE,gBAAgB,EAAE;YAClD,IAAM,gBAAgB,GAAG,MAAA,IAAI,CAAC,OAAO,CAAC,eAAe,0CAAE,gBAAgB,CAAC,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;YAC1F,OAAO,OAAO,gBAAgB,KAAK,SAAS,CAAC,CAAC,CAAC,gBAAgB,CAAC,CAAC,CAAC,KAAK,CAAC;SACzE;QAED,OAAO,KAAK,CAAC;IACf,CAAC;IAEO,gDAAsB,GAA9B;QACE,OAAO,CAAC,oBAAO,CAAC,KAAK,EAAE,IAAI,OAAO,CAAC,GAAG,CAAC,qBAAqB,CAAC;IAC/D,CAAC;IACH,sBAAC;AAAD,CAAC,AAzED,IAyEC;AAzEY,0CAAe"}
@@ -7,22 +7,25 @@ import '@proteinjs/server-api';
7
7
  import '@proteinjs/user-auth';
8
8
  import '@proteinjs/util';
9
9
 
10
+
10
11
  /** Generate Source Graph */
11
12
 
12
- const sourceGraph =
13
- '{"options":{"directed":true,"multigraph":false,"compound":false},"nodes":[{"v":"@proteinjs/service/Service","value":{"packageName":"@proteinjs/service","name":"Service","filePath":"/home/runner/work/service/service/packages/service/src/Service.ts","qualifiedName":"@proteinjs/service/Service","properties":[{"name":"serviceMetadata","type":{"packageName":"@proteinjs/service","name":"{\\n auth?: {\\n /** If true, the user does not need to be logged in or have any roles to call this service. If blank, defaults to false. */\\n public?: boolean;\\n /** If true, the user does not need to have any roles to call this service, but must be logged in. If blank, defaults to false. */\\n allUsers?: boolean;\\n /** The user must be logged in and have these roles to call this service. If blank, defaults to requiring the \'admin\' role. */\\n roles?: string[];\\n /**\\n * Custom auth function. If provided, all other auth properties are ignored.\\n * @param methodName the name of the service method to be executed\\n * @param args the args[] that will be passed into the method\\n * @return true if the user can access the service method\\n */\\n canAccess?: (methodName: string, args: any[]) => boolean;\\n };\\n /** Don\'t await the service\'s execution, return a response to the client immediately */\\n doNotAwait?: boolean;\\n }","filePath":null,"qualifiedName":"@proteinjs/service/{\\n auth?: {\\n /** If true, the user does not need to be logged in or have any roles to call this service. If blank, defaults to false. */\\n public?: boolean;\\n /** If true, the user does not need to have any roles to call this service, but must be logged in. If blank, defaults to false. */\\n allUsers?: boolean;\\n /** The user must be logged in and have these roles to call this service. If blank, defaults to requiring the \'admin\' role. */\\n roles?: string[];\\n /**\\n * Custom auth function. If provided, all other auth properties are ignored.\\n * @param methodName the name of the service method to be executed\\n * @param args the args[] that will be passed into the method\\n * @return true if the user can access the service method\\n */\\n canAccess?: (methodName: string, args: any[]) => boolean;\\n };\\n /** Don\'t await the service\'s execution, return a response to the client immediately */\\n doNotAwait?: boolean;\\n }","typeParameters":null,"directParents":null},"isOptional":true,"isAbstract":false,"isStatic":false,"visibility":"public"}],"methods":[],"typeParameters":[],"directParents":[{"packageName":"@proteinjs/reflection","name":"Loadable","filePath":null,"qualifiedName":"@proteinjs/reflection/Loadable","properties":[],"methods":[],"typeParameters":[],"directParents":[]}],"sourceType":3}},{"v":"@proteinjs/reflection/Loadable"},{"v":"/Error"},{"v":"@proteinjs/service/ServiceRouter","value":{"packageName":"@proteinjs/service","name":"ServiceRouter","filePath":"/home/runner/work/service/service/packages/service/src/ServiceRouter.ts","qualifiedName":"@proteinjs/service/ServiceRouter","isAbstract":false,"isStatic":false,"visibility":"public","properties":[{"name":"logger","type":null,"isOptional":false,"isAbstract":false,"isStatic":false,"visibility":"private"},{"name":"serviceExecutorMap","type":{"packageName":"@proteinjs/service","name":"{ [path: string]: ServiceExecutor } | undefined","filePath":null,"qualifiedName":"@proteinjs/service/{ [path: string]: ServiceExecutor } | undefined","typeParameters":null,"directParents":null},"isOptional":false,"isAbstract":false,"isStatic":false,"visibility":"private"},{"name":"path","type":null,"isOptional":false,"isAbstract":false,"isStatic":false,"visibility":"public"},{"name":"method","type":{"packageName":"","name":"\'post\'","filePath":null,"qualifiedName":"/\'post\'","typeParameters":null,"directParents":null},"isOptional":false,"isAbstract":false,"isStatic":false,"visibility":"public"}],"methods":[{"name":"getServiceExecutorMap","returnType":null,"isAsync":false,"isOptional":false,"isAbstract":false,"isStatic":false,"visibility":"private","parameters":[]},{"name":"onRequest","returnType":{"packageName":"","name":"Promise<any>","filePath":null,"qualifiedName":"/Promise<any>","typeParameters":null,"directParents":null},"isAsync":true,"isOptional":false,"isAbstract":false,"isStatic":false,"visibility":"public","parameters":[{"name":"request","type":{"packageName":"","name":"any","filePath":null,"qualifiedName":"/any","typeParameters":null,"directParents":null}},{"name":"response","type":{"packageName":"","name":"any","filePath":null,"qualifiedName":"/any","typeParameters":null,"directParents":null}}]}],"typeParameters":[],"directParentInterfaces":[{"packageName":"@proteinjs/server-api","name":"Route","filePath":null,"qualifiedName":"@proteinjs/server-api/Route","properties":[],"methods":[],"typeParameters":[],"directParents":[]}],"directParentClasses":[],"sourceType":2}},{"v":"@proteinjs/server-api/Route"}],"edges":[{"v":"@proteinjs/service/Service","w":"@proteinjs/reflection/Loadable","value":"extends interface"},{"v":"@proteinjs/service/ServiceRouter","w":"@proteinjs/server-api/Route","value":"implements interface"}]}';
13
+ const sourceGraph = "{\"options\":{\"directed\":true,\"multigraph\":false,\"compound\":false},\"nodes\":[{\"v\":\"@proteinjs/service/MethodDebounceConfig\"},{\"v\":\"@proteinjs/service/Service\",\"value\":{\"packageName\":\"@proteinjs/service\",\"name\":\"Service\",\"filePath\":\"/Users/brentbahry/repos/n3xa/packages/proteinjs/packages/service/packages/service/src/Service.ts\",\"qualifiedName\":\"@proteinjs/service/Service\",\"properties\":[{\"name\":\"serviceMetadata\",\"type\":{\"packageName\":\"@proteinjs/service\",\"name\":\"{\\n auth?: {\\n /** If true, the user does not need to be logged in or have any roles to call this service. If blank, defaults to false. */\\n public?: boolean;\\n /** If true, the user does not need to have any roles to call this service, but must be logged in. If blank, defaults to false. */\\n allUsers?: boolean;\\n /** The user must be logged in and have these roles to call this service. If blank, defaults to requiring the 'admin' role. */\\n roles?: string[];\\n /**\\n * Custom auth function. If provided, all other auth properties are ignored.\\n * @param methodName the name of the service method to be executed\\n * @param args the args[] that will be passed into the method\\n * @return true if the user can access the service method\\n */\\n canAccess?: (methodName: string, args: any[]) => boolean;\\n };\\n /** Don't await the service's execution, return a response to the client immediately */\\n doNotAwait?: boolean;\\n /** Don't await the service's execution, return a response to the client immediately (configured per method) */\\n doNotAwaitMethod?: MethodAwaitConfig;\\n }\",\"filePath\":null,\"qualifiedName\":\"@proteinjs/service/{\\n auth?: {\\n /** If true, the user does not need to be logged in or have any roles to call this service. If blank, defaults to false. */\\n public?: boolean;\\n /** If true, the user does not need to have any roles to call this service, but must be logged in. If blank, defaults to false. */\\n allUsers?: boolean;\\n /** The user must be logged in and have these roles to call this service. If blank, defaults to requiring the 'admin' role. */\\n roles?: string[];\\n /**\\n * Custom auth function. If provided, all other auth properties are ignored.\\n * @param methodName the name of the service method to be executed\\n * @param args the args[] that will be passed into the method\\n * @return true if the user can access the service method\\n */\\n canAccess?: (methodName: string, args: any[]) => boolean;\\n };\\n /** Don't await the service's execution, return a response to the client immediately */\\n doNotAwait?: boolean;\\n /** Don't await the service's execution, return a response to the client immediately (configured per method) */\\n doNotAwaitMethod?: MethodAwaitConfig;\\n }\",\"typeParameters\":null,\"directParents\":null},\"isOptional\":true,\"isAbstract\":false,\"isStatic\":false,\"visibility\":\"public\"}],\"methods\":[],\"typeParameters\":[],\"directParents\":[{\"packageName\":\"@proteinjs/reflection\",\"name\":\"Loadable\",\"filePath\":null,\"qualifiedName\":\"@proteinjs/reflection/Loadable\",\"properties\":[],\"methods\":[],\"typeParameters\":[],\"directParents\":[]}],\"sourceType\":3}},{\"v\":\"@proteinjs/reflection/Loadable\"},{\"v\":\"/Error\"},{\"v\":\"@proteinjs/service/ServiceRouter\",\"value\":{\"packageName\":\"@proteinjs/service\",\"name\":\"ServiceRouter\",\"filePath\":\"/Users/brentbahry/repos/n3xa/packages/proteinjs/packages/service/packages/service/src/ServiceRouter.ts\",\"qualifiedName\":\"@proteinjs/service/ServiceRouter\",\"isAbstract\":false,\"isStatic\":false,\"visibility\":\"public\",\"properties\":[{\"name\":\"logger\",\"type\":null,\"isOptional\":false,\"isAbstract\":false,\"isStatic\":false,\"visibility\":\"private\"},{\"name\":\"serviceExecutorMap\",\"type\":{\"packageName\":\"@proteinjs/service\",\"name\":\"{ [path: string]: ServiceExecutor } | undefined\",\"filePath\":null,\"qualifiedName\":\"@proteinjs/service/{ [path: string]: ServiceExecutor } | undefined\",\"typeParameters\":null,\"directParents\":null},\"isOptional\":false,\"isAbstract\":false,\"isStatic\":false,\"visibility\":\"private\"},{\"name\":\"path\",\"type\":null,\"isOptional\":false,\"isAbstract\":false,\"isStatic\":false,\"visibility\":\"public\"},{\"name\":\"method\",\"type\":{\"packageName\":\"\",\"name\":\"'post'\",\"filePath\":null,\"qualifiedName\":\"/'post'\",\"typeParameters\":null,\"directParents\":null},\"isOptional\":false,\"isAbstract\":false,\"isStatic\":false,\"visibility\":\"public\"}],\"methods\":[{\"name\":\"getServiceExecutorMap\",\"returnType\":null,\"isAsync\":false,\"isOptional\":false,\"isAbstract\":false,\"isStatic\":false,\"visibility\":\"private\",\"parameters\":[]},{\"name\":\"onRequest\",\"returnType\":{\"packageName\":\"\",\"name\":\"Promise<any>\",\"filePath\":null,\"qualifiedName\":\"/Promise<any>\",\"typeParameters\":null,\"directParents\":null},\"isAsync\":true,\"isOptional\":false,\"isAbstract\":false,\"isStatic\":false,\"visibility\":\"public\",\"parameters\":[{\"name\":\"request\",\"type\":{\"packageName\":\"\",\"name\":\"any\",\"filePath\":null,\"qualifiedName\":\"/any\",\"typeParameters\":null,\"directParents\":null}},{\"name\":\"response\",\"type\":{\"packageName\":\"\",\"name\":\"any\",\"filePath\":null,\"qualifiedName\":\"/any\",\"typeParameters\":null,\"directParents\":null}}]}],\"typeParameters\":[],\"directParentInterfaces\":[{\"packageName\":\"@proteinjs/server-api\",\"name\":\"Route\",\"filePath\":null,\"qualifiedName\":\"@proteinjs/server-api/Route\",\"properties\":[],\"methods\":[],\"typeParameters\":[],\"directParents\":[]}],\"directParentClasses\":[],\"sourceType\":2}},{\"v\":\"@proteinjs/server-api/Route\"}],\"edges\":[{\"v\":\"@proteinjs/service/Service\",\"w\":\"@proteinjs/reflection/Loadable\",\"value\":\"extends interface\"},{\"v\":\"@proteinjs/service/ServiceRouter\",\"w\":\"@proteinjs/server-api/Route\",\"value\":\"implements interface\"}]}";
14
+
14
15
 
15
16
  /** Generate Source Links */
16
17
 
17
18
  import { ServiceRouter } from '../src/ServiceRouter';
18
19
 
19
20
  const sourceLinks = {
20
- '@proteinjs/service/ServiceRouter': ServiceRouter,
21
+ '@proteinjs/service/ServiceRouter': ServiceRouter,
21
22
  };
22
23
 
24
+
23
25
  /** Load Source Graph and Links */
24
26
 
25
27
  import { SourceRepository } from '@proteinjs/reflection';
26
28
  SourceRepository.merge(sourceGraph, sourceLinks);
27
29
 
28
- export * from '../index';
30
+
31
+ export * from '../index';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@proteinjs/service",
3
- "version": "1.1.1",
3
+ "version": "1.2.1",
4
4
  "description": "Service api",
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -21,15 +21,15 @@
21
21
  "watch": "reflection-watch"
22
22
  },
23
23
  "dependencies": {
24
- "@proteinjs/logger": "1.0.6",
25
- "@proteinjs/reflection": "1.1.9",
26
- "@proteinjs/serializer": "1.0.15",
27
- "@proteinjs/server-api": "1.5.0",
28
- "@proteinjs/user-auth": "1.1.1",
29
- "@proteinjs/util": "1.4.1"
24
+ "@proteinjs/logger": "1.0.7",
25
+ "@proteinjs/reflection": "1.1.10",
26
+ "@proteinjs/serializer": "1.0.16",
27
+ "@proteinjs/server-api": "1.5.1",
28
+ "@proteinjs/user-auth": "1.1.2",
29
+ "@proteinjs/util": "1.5.0"
30
30
  },
31
31
  "devDependencies": {
32
- "@proteinjs/reflection-build": "1.0.24",
32
+ "@proteinjs/reflection-build": "1.0.25",
33
33
  "@types/jest": "29.5.5",
34
34
  "@types/node": "14.0.27",
35
35
  "@typescript-eslint/eslint-plugin": "7.8.0",
@@ -42,6 +42,5 @@
42
42
  "typescript": "5.2.2"
43
43
  },
44
44
  "main": "./dist/generated/index.js",
45
- "types": "./dist/generated/index.d.ts",
46
- "gitHead": "9e03cddf33d8d7d2becba67275e19adb67adaaf4"
45
+ "types": "./dist/generated/index.d.ts"
47
46
  }
package/src/Service.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import { SerializableFunction, NotFunction } from '@proteinjs/serializer';
2
2
  import { Loadable, SourceRepository } from '@proteinjs/reflection';
3
3
  import { ServiceClient } from './ServiceClient';
4
- import { Debouncer } from '@proteinjs/util';
4
+ import { Debouncer, GetDebounceKey, isInstanceOf } from '@proteinjs/util';
5
5
 
6
6
  type RemoveIndex<T> = {
7
7
  [K in keyof T as string extends K ? never : number extends K ? never : symbol extends K ? never : K]: T[K];
@@ -18,6 +18,19 @@ type RetryConfig<T extends Service> = {
18
18
  [K in KeysWithoutService<T>]?: number;
19
19
  };
20
20
 
21
+ interface DebounceConfig {
22
+ waitTime: number;
23
+ getDebounceKey?: GetDebounceKey;
24
+ }
25
+
26
+ type MethodDebounceConfig<T extends Service> = {
27
+ [K in KeysWithoutService<T>]?: DebounceConfig;
28
+ };
29
+
30
+ type MethodAwaitConfig = { [methodName: string]: boolean };
31
+
32
+ export type ServiceDebounceConfig<T extends Service> = MethodDebounceConfig<T> | Debouncer;
33
+
21
34
  export interface Service extends Loadable {
22
35
  serviceMetadata?: {
23
36
  auth?: {
@@ -37,20 +50,33 @@ export interface Service extends Loadable {
37
50
  };
38
51
  /** Don't await the service's execution, return a response to the client immediately */
39
52
  doNotAwait?: boolean;
53
+ /** Don't await the service's execution, return a response to the client immediately (configured per method) */
54
+ doNotAwaitMethod?: MethodAwaitConfig;
40
55
  };
41
56
  [prop: string]: SerializableFunction | NotFunction<any>;
42
57
  }
43
58
 
59
+ const debouncerMap: { [key: string]: Debouncer } = {};
60
+ /** Retrieve an existing debouncer from the map or make a new one.
61
+ * This allows the debouncer instance per method to remain the same across multiple service calls.
62
+ */
63
+ function getOrCreateDebouncer(methodName: string, config: DebounceConfig): Debouncer {
64
+ if (!debouncerMap[methodName]) {
65
+ debouncerMap[methodName] = new Debouncer(config.waitTime, config.getDebounceKey);
66
+ }
67
+ return debouncerMap[methodName];
68
+ }
69
+
44
70
  /**
45
71
  * Create a factory that creates an instance of the Service. The Service instance is a
46
72
  * ServiceClient wrapped in the interface's api.
47
73
  * @param serviceInterfaceQualifiedName the package-qualified name of the service interface (ie. service-package-name/MyService)
48
- * @param debouncer optionally pass in an instance of debouncer if you want to limit service client calls
74
+ * @param debouncer pass in either a single debouncer instance or method-specific debounce configurations
49
75
  * @returns a function that creates a Service
50
76
  */
51
77
  export const serviceFactory = <T extends Service>(
52
78
  serviceInterfaceQualifiedName: string,
53
- debouncer?: Debouncer,
79
+ debouncer?: ServiceDebounceConfig<T>,
54
80
  retryConfig?: RetryConfig<T>
55
81
  ): (() => T) => {
56
82
  return () => {
@@ -58,15 +84,27 @@ export const serviceFactory = <T extends Service>(
58
84
  const serviceInterface = SourceRepository.get().interface(serviceInterfaceQualifiedName);
59
85
  for (const method of serviceInterface.methods) {
60
86
  const servicePath = `/service/${serviceInterface.qualifiedName}/${method.name}`;
87
+ const methodName = method.name as KeysWithoutService<T>;
61
88
 
62
89
  let retryCount = 0;
63
- if (retryConfig && method.name in retryConfig) {
64
- const methodName = method.name as KeysWithoutService<T>;
90
+ if (retryConfig && methodName in retryConfig) {
65
91
  retryCount = retryConfig[methodName]!;
66
92
  }
67
93
 
68
- const serviceClient = new ServiceClient(servicePath, method, debouncer, retryCount);
69
- service[method.name] = serviceClient.send.bind(serviceClient);
94
+ let methodDebouncer: Debouncer | undefined;
95
+ if (debouncer) {
96
+ if (isInstanceOf(debouncer, Debouncer)) {
97
+ methodDebouncer = debouncer as Debouncer;
98
+ } else if (methodName in debouncer) {
99
+ const methodConfig = (debouncer as MethodDebounceConfig<T>)[methodName];
100
+ if (methodConfig) {
101
+ methodDebouncer = getOrCreateDebouncer(methodName as string, methodConfig);
102
+ }
103
+ }
104
+ }
105
+
106
+ const serviceClient = new ServiceClient(servicePath, method, methodDebouncer, retryCount);
107
+ service[methodName] = serviceClient.send.bind(serviceClient);
70
108
  }
71
109
 
72
110
  return service;
@@ -49,7 +49,7 @@ export class ServiceClient {
49
49
  const executeRequest = this.retryCount > 0 ? executeWithRetry : (fn: () => Promise<any>) => fn();
50
50
 
51
51
  if (this.debouncer) {
52
- return this.debouncer.debounce(() => executeRequest(sendRequest));
52
+ return this.debouncer.debounce(() => executeRequest(sendRequest), args);
53
53
  } else {
54
54
  return executeRequest(sendRequest);
55
55
  }
@@ -39,7 +39,7 @@ export class ServiceExecutor {
39
39
 
40
40
  let _return: any;
41
41
  try {
42
- if (this.service.serviceMetadata?.doNotAwait) {
42
+ if (this.doNotAwait()) {
43
43
  method(...deserializedArgs);
44
44
  } else {
45
45
  _return = await method(...deserializedArgs);
@@ -70,6 +70,19 @@ export class ServiceExecutor {
70
70
  return serializedReturn;
71
71
  }
72
72
 
73
+ private doNotAwait() {
74
+ if (this.service.serviceMetadata?.doNotAwait) {
75
+ return true;
76
+ }
77
+
78
+ if (this.service.serviceMetadata?.doNotAwaitMethod) {
79
+ const methodDoNotAwait = this.service.serviceMetadata?.doNotAwaitMethod[this.method.name];
80
+ return typeof methodDoNotAwait === 'boolean' ? methodDoNotAwait : false;
81
+ }
82
+
83
+ return false;
84
+ }
85
+
73
86
  private shouldLogArgsAndReturn() {
74
87
  return !EnvInfo.isDev() || process.env.DETAILED_SERVICE_LOGS;
75
88
  }
package/LICENSE DELETED
@@ -1,21 +0,0 @@
1
- MIT License
2
-
3
- Copyright (c) 2023 Brent Bahry
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.