@proteinjs/service 1.0.16 → 1.0.17
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 +11 -0
- package/LICENSE +21 -0
- package/dist/generated/index.js +1 -1
- package/dist/generated/index.js.map +1 -1
- package/dist/src/Service.js +1 -1
- package/dist/src/Service.js.map +1 -1
- package/dist/src/ServiceClient.d.ts +3 -1
- package/dist/src/ServiceClient.d.ts.map +1 -1
- package/dist/src/ServiceClient.js +4 -2
- package/dist/src/ServiceClient.js.map +1 -1
- package/dist/src/ServiceExecutor.d.ts.map +1 -1
- package/dist/src/ServiceExecutor.js +5 -0
- package/dist/src/ServiceExecutor.js.map +1 -1
- package/dist/src/isVoidReturnType.d.ts +3 -0
- package/dist/src/isVoidReturnType.d.ts.map +1 -0
- package/dist/src/isVoidReturnType.js +8 -0
- package/dist/src/isVoidReturnType.js.map +1 -0
- package/generated/index.ts +4 -7
- package/package.json +3 -2
- package/src/Service.ts +1 -1
- package/src/ServiceClient.ts +10 -2
- package/src/ServiceExecutor.ts +7 -0
- package/src/isVoidReturnType.ts +5 -0
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,17 @@
|
|
|
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.0.17](https://github.com/proteinjs/service/compare/@proteinjs/service@1.0.16...@proteinjs/service@1.0.17) (2024-05-23)
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
### Bug Fixes
|
|
10
|
+
|
|
11
|
+
* logging of returned objects should be more clear when the service method is void ([cdfe631](https://github.com/proteinjs/service/commit/cdfe631a2859a1ccd2de210232a4b3b58c86e094))
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
|
|
6
17
|
## [1.0.14](https://github.com/proteinjs/service/compare/@proteinjs/service@1.0.13...@proteinjs/service@1.0.14) (2024-05-18)
|
|
7
18
|
|
|
8
19
|
|
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
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.
|
package/dist/generated/index.js
CHANGED
|
@@ -21,7 +21,7 @@ require("@proteinjs/server-api");
|
|
|
21
21
|
require("@proteinjs/user-auth");
|
|
22
22
|
require("@proteinjs/util");
|
|
23
23
|
/** Generate Source Graph */
|
|
24
|
-
var sourceGraph = "{\"options\":{\"directed\":true,\"multigraph\":false,\"compound\":false},\"nodes\":[{\"v\":\"@proteinjs/service/Service\",\"value\":{\"packageName\":\"@proteinjs/service\",\"name\":\"Service\",\"filePath\":\"/
|
|
24
|
+
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\":\"@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
25
|
/** Generate Source Links */
|
|
26
26
|
var ServiceRouter_1 = require("../src/ServiceRouter");
|
|
27
27
|
var sourceLinks = {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../generated/index.ts"],"names":[],"mappings":";AAAA,oCAAoC;;;;;;;;;;;;;;;;AAEpC,iCAA+B;AAC/B,iCAA+B;AAC/B,iCAA+B;AAC/B,gCAA8B;AAC9B,2BAAyB;AAGzB,4BAA4B;AAE5B,IAAM,WAAW,GAAG,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../generated/index.ts"],"names":[],"mappings":";AAAA,oCAAoC;;;;;;;;;;;;;;;;AAEpC,iCAA+B;AAC/B,iCAA+B;AAC/B,iCAA+B;AAC/B,gCAA8B;AAC9B,2BAAyB;AAGzB,4BAA4B;AAE5B,IAAM,WAAW,GAAG,wiLAAwiL,CAAC;AAG7jL,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"}
|
package/dist/src/Service.js
CHANGED
|
@@ -16,7 +16,7 @@ var serviceFactory = function (serviceInterfaceQualifiedName) {
|
|
|
16
16
|
for (var _i = 0, _a = serviceInterface.methods; _i < _a.length; _i++) {
|
|
17
17
|
var method = _a[_i];
|
|
18
18
|
var servicePath = "/service/".concat(serviceInterface.qualifiedName, "/").concat(method.name);
|
|
19
|
-
var serviceClient = new ServiceClient_1.ServiceClient(servicePath);
|
|
19
|
+
var serviceClient = new ServiceClient_1.ServiceClient(servicePath, method);
|
|
20
20
|
service[method.name] = serviceClient.send.bind(serviceClient);
|
|
21
21
|
}
|
|
22
22
|
return service;
|
package/dist/src/Service.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Service.js","sourceRoot":"","sources":["../../src/Service.ts"],"names":[],"mappings":";;;AACA,oDAA2E;AAC3E,iDAAgD;AAyBhD;;;;;GAKG;AACI,IAAM,cAAc,GAAG,UAAoB,6BAAqC;IACrF,OAAO;QACL,IAAM,OAAO,GAAQ,EAAE,CAAC;QACxB,IAAM,gBAAgB,GAAG,6BAAgB,CAAC,GAAG,EAAE,CAAC,SAAS,CAAC,6BAA6B,CAAC,CAAC;QACzF,KAAqB,UAAwB,EAAxB,KAAA,gBAAgB,CAAC,OAAO,EAAxB,cAAwB,EAAxB,IAAwB,EAAE;YAA1C,IAAM,MAAM,SAAA;YACf,IAAM,WAAW,GAAG,mBAAY,gBAAgB,CAAC,aAAa,cAAI,MAAM,CAAC,IAAI,CAAE,CAAC;YAChF,IAAM,aAAa,GAAG,IAAI,6BAAa,CAAC,WAAW,CAAC,CAAC;
|
|
1
|
+
{"version":3,"file":"Service.js","sourceRoot":"","sources":["../../src/Service.ts"],"names":[],"mappings":";;;AACA,oDAA2E;AAC3E,iDAAgD;AAyBhD;;;;;GAKG;AACI,IAAM,cAAc,GAAG,UAAoB,6BAAqC;IACrF,OAAO;QACL,IAAM,OAAO,GAAQ,EAAE,CAAC;QACxB,IAAM,gBAAgB,GAAG,6BAAgB,CAAC,GAAG,EAAE,CAAC,SAAS,CAAC,6BAA6B,CAAC,CAAC;QACzF,KAAqB,UAAwB,EAAxB,KAAA,gBAAgB,CAAC,OAAO,EAAxB,cAAwB,EAAxB,IAAwB,EAAE;YAA1C,IAAM,MAAM,SAAA;YACf,IAAM,WAAW,GAAG,mBAAY,gBAAgB,CAAC,aAAa,cAAI,MAAM,CAAC,IAAI,CAAE,CAAC;YAChF,IAAM,aAAa,GAAG,IAAI,6BAAa,CAAC,WAAW,EAAE,MAAM,CAAC,CAAC;YAC7D,OAAO,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,aAAa,CAAC,IAAI,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC;SAC/D;QAED,OAAO,OAAO,CAAC;IACjB,CAAC,CAAC;AACJ,CAAC,CAAC;AAZW,QAAA,cAAc,kBAYzB"}
|
|
@@ -1,8 +1,10 @@
|
|
|
1
|
+
import { Method } from '@proteinjs/reflection';
|
|
1
2
|
export declare class ServiceClient {
|
|
2
3
|
private servicePath;
|
|
4
|
+
private serviceMethod;
|
|
3
5
|
private static requestCounter;
|
|
4
6
|
private logger;
|
|
5
|
-
constructor(servicePath: string);
|
|
7
|
+
constructor(servicePath: string, serviceMethod: Method);
|
|
6
8
|
send(...args: any[]): Promise<any>;
|
|
7
9
|
private _send;
|
|
8
10
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ServiceClient.d.ts","sourceRoot":"","sources":["../../src/ServiceClient.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"ServiceClient.d.ts","sourceRoot":"","sources":["../../src/ServiceClient.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,uBAAuB,CAAC;AAK/C,qBAAa,aAAa;IAKtB,OAAO,CAAC,WAAW;IACnB,OAAO,CAAC,aAAa;IALvB,OAAO,CAAC,MAAM,CAAC,cAAc,CAAK;IAClC,OAAO,CAAC,MAAM,CAAmD;gBAGvD,WAAW,EAAE,MAAM,EACnB,aAAa,EAAE,MAAM;IAGzB,IAAI,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,GAAG,OAAO,CAAC,GAAG,CAAC;YAiB1B,KAAK;CAsBpB"}
|
|
@@ -39,9 +39,11 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
39
39
|
exports.ServiceClient = void 0;
|
|
40
40
|
var serializer_1 = require("@proteinjs/serializer");
|
|
41
41
|
var util_1 = require("@proteinjs/util");
|
|
42
|
+
var isVoidReturnType_1 = require("./isVoidReturnType");
|
|
42
43
|
var ServiceClient = /** @class */ (function () {
|
|
43
|
-
function ServiceClient(servicePath) {
|
|
44
|
+
function ServiceClient(servicePath, serviceMethod) {
|
|
44
45
|
this.servicePath = servicePath;
|
|
46
|
+
this.serviceMethod = serviceMethod;
|
|
45
47
|
this.logger = new util_1.Logger(this.constructor.name, 'info', 2000);
|
|
46
48
|
}
|
|
47
49
|
ServiceClient.prototype.send = function () {
|
|
@@ -63,7 +65,7 @@ var ServiceClient = /** @class */ (function () {
|
|
|
63
65
|
return [4 /*yield*/, this._send(this.servicePath, serializedArgs)];
|
|
64
66
|
case 1:
|
|
65
67
|
serializedReturn = _a.sent();
|
|
66
|
-
console.groupCollapsed("[#".concat(requestNumber, "] Received service response: ").concat(this.servicePath, ", return:"));
|
|
68
|
+
console.groupCollapsed("[#".concat(requestNumber, "] Received service response: ").concat(this.servicePath, ", return:").concat((0, isVoidReturnType_1.isVoidReturnType)(this.serviceMethod) ? ' (void)' : ''));
|
|
67
69
|
console.log(serializedReturn);
|
|
68
70
|
console.groupEnd();
|
|
69
71
|
return [2 /*return*/, serializer_1.Serializer.deserialize(serializedReturn)];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ServiceClient.js","sourceRoot":"","sources":["../../src/ServiceClient.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"ServiceClient.js","sourceRoot":"","sources":["../../src/ServiceClient.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AACA,oDAAmD;AACnD,wCAAyC;AACzC,uDAAsD;AAEtD;IAIE,uBACU,WAAmB,EACnB,aAAqB;QADrB,gBAAW,GAAX,WAAW,CAAQ;QACnB,kBAAa,GAAb,aAAa,CAAQ;QAJvB,WAAM,GAAG,IAAI,aAAM,CAAC,IAAI,CAAC,WAAW,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,CAAC,CAAC;IAK9D,CAAC;IAEE,4BAAI,GAAV;QAAW,cAAc;aAAd,UAAc,EAAd,qBAAc,EAAd,IAAc;YAAd,yBAAc;;;;;;;wBACjB,cAAc,GAAG,uBAAU,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC;wBAC5C,aAAa,GAAG,aAAa,CAAC,cAAc,CAAC;wBACnD,aAAa,CAAC,cAAc,EAAE,CAAC;wBAC/B,OAAO,CAAC,cAAc,CAAC,YAAK,aAAa,wCAA8B,IAAI,CAAC,WAAW,YAAS,CAAC,CAAC;wBAClG,OAAO,CAAC,GAAG,CAAC,cAAc,CAAC,CAAC;wBAC5B,OAAO,CAAC,QAAQ,EAAE,CAAC;wBACM,qBAAM,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,WAAW,EAAE,cAAc,CAAC,EAAA;;wBAArE,gBAAgB,GAAG,SAAkD;wBAC3E,OAAO,CAAC,cAAc,CACpB,YAAK,aAAa,0CAAgC,IAAI,CAAC,WAAW,sBAAY,IAAA,mCAAgB,EAAC,IAAI,CAAC,aAAa,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,EAAE,CAAE,CACtI,CAAC;wBACF,OAAO,CAAC,GAAG,CAAC,gBAAgB,CAAC,CAAC;wBAC9B,OAAO,CAAC,QAAQ,EAAE,CAAC;wBAEnB,sBAAO,uBAAU,CAAC,WAAW,CAAC,gBAAgB,CAAC,EAAC;;;;KACjD;IAEa,6BAAK,GAAnB,UAAoB,WAAmB,EAAE,cAAsB;;;;;;wBACvD,OAAO,GAAG,IAAI,OAAO,CAAC,WAAW,EAAE;4BACvC,MAAM,EAAE,MAAM;4BACd,IAAI,EAAE,cAAc;4BACpB,QAAQ,EAAE,QAAQ;4BAClB,WAAW,EAAE,aAAa;4BAC1B,OAAO,EAAE;gCACP,cAAc,EAAE,kBAAkB;6BACnC;yBACF,CAAC,CAAC;wBACc,qBAAM,KAAK,CAAC,OAAO,CAAC,EAAA;;wBAA/B,QAAQ,GAAG,SAAoB;wBACrC,IAAI,QAAQ,CAAC,MAAM,IAAI,GAAG,EAAE;4BAC1B,MAAM,IAAI,KAAK,CAAC,6CAAsC,WAAW,sBAAY,QAAQ,CAAC,UAAU,CAAE,CAAC,CAAC;yBACrG;wBAEY,qBAAM,QAAQ,CAAC,IAAI,EAAE,EAAA;;wBAA5B,IAAI,GAAG,SAAqB;wBAClC,IAAI,IAAI,CAAC,KAAK,EAAE;4BACd,MAAM,IAAI,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;yBAC7B;wBAED,sBAAO,IAAI,CAAC,gBAAgB,EAAC;;;;KAC9B;IA9Cc,4BAAc,GAAG,CAAC,AAAJ,CAAK;IA+CpC,oBAAC;CAAA,AAhDD,IAgDC;AAhDY,sCAAa"}
|
|
@@ -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;
|
|
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;AAMpC,qBAAa,eAAe;IAIjB,OAAO,EAAE,OAAO;IACvB,OAAO,CAAC,UAAU;IAClB,OAAO,CAAC,MAAM;IALhB,OAAO,CAAC,MAAM,CAAS;IAChB,gBAAgB,EAAE,GAAG,CAAC;gBAEpB,OAAO,EAAE,OAAO,EACf,UAAU,EAAE,SAAS,EACrB,MAAM,EAAE,MAAM;IAKlB,OAAO,CAAC,WAAW,EAAE,GAAG,GAAG,OAAO,CAAC,GAAG,CAAC;CA8B9C"}
|
|
@@ -40,6 +40,7 @@ exports.ServiceExecutor = void 0;
|
|
|
40
40
|
var util_1 = require("@proteinjs/util");
|
|
41
41
|
var serializer_1 = require("@proteinjs/serializer");
|
|
42
42
|
var ServiceAuth_1 = require("./ServiceAuth");
|
|
43
|
+
var isVoidReturnType_1 = require("./isVoidReturnType");
|
|
43
44
|
var ServiceExecutor = /** @class */ (function () {
|
|
44
45
|
function ServiceExecutor(service, _interface, method) {
|
|
45
46
|
this.service = service;
|
|
@@ -77,6 +78,10 @@ var ServiceExecutor = /** @class */ (function () {
|
|
|
77
78
|
this.logger.error("Failed with args:\n".concat(JSON.stringify(requestBody, null, 2)));
|
|
78
79
|
throw error_1;
|
|
79
80
|
case 6:
|
|
81
|
+
if ((0, isVoidReturnType_1.isVoidReturnType)(this.method)) {
|
|
82
|
+
this.logger.info("Returning: (void)");
|
|
83
|
+
return [2 /*return*/, undefined];
|
|
84
|
+
}
|
|
80
85
|
serializedReturn = serializer_1.Serializer.serialize(_return);
|
|
81
86
|
this.logger.info("Returning:\n".concat(serializedReturn));
|
|
82
87
|
return [2 /*return*/, serializedReturn];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ServiceExecutor.js","sourceRoot":"","sources":["../../src/ServiceExecutor.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEA,wCAAyC;AACzC,oDAAmD;AACnD,6CAA4C;
|
|
1
|
+
{"version":3,"file":"ServiceExecutor.js","sourceRoot":"","sources":["../../src/ServiceExecutor.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEA,wCAAyC;AACzC,oDAAmD;AACnD,6CAA4C;AAC5C,uDAAsD;AAEtD;IAGE,yBACS,OAAgB,EACf,UAAqB,EACrB,MAAc;QAFf,YAAO,GAAP,OAAO,CAAS;QACf,eAAU,GAAV,UAAU,CAAW;QACrB,WAAM,GAAN,MAAM,CAAQ;QAEtB,IAAI,CAAC,MAAM,GAAG,IAAI,aAAM,CAAC,UAAG,UAAU,CAAC,IAAI,cAAI,MAAM,CAAC,IAAI,CAAE,EAAE,SAAS,EAAE,IAAI,CAAC,CAAC;IACjF,CAAC;IAEK,iCAAO,GAAb,UAAc,WAAgB;;;;;;;wBAC5B,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,gCAAyB,IAAI,CAAC,SAAS,CAAC,WAAW,EAAE,IAAI,EAAE,CAAC,CAAC,CAAE,CAAC,CAAC;wBAC5E,MAAM,GAAG,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;wBAC3D,gBAAgB,GAAG,uBAAU,CAAC,WAAW,CAAC,WAAW,CAAC,CAAC;wBAC7D,IAAI,CAAC,yBAAW,CAAC,aAAa,CAAC,IAAI,CAAC,OAAO,EAAE,IAAI,CAAC,MAAM,EAAE,gBAAgB,CAAC,EAAE;4BACrE,KAAK,GAAG,8CAAuC,IAAI,CAAC,UAAU,CAAC,IAAI,cAAI,IAAI,CAAC,MAAM,CAAC,IAAI,CAAE,CAAC;4BAChG,MAAM,IAAI,KAAK,CAAC,KAAK,CAAC,CAAC;yBACxB;;;;6BAIK,CAAA,MAAA,IAAI,CAAC,OAAO,CAAC,eAAe,0CAAE,UAAU,CAAA,EAAxC,wBAAwC;wBAC1C,MAAM,eAAI,gBAAgB,EAAE;;4BAElB,qBAAM,MAAM,eAAI,gBAAgB,GAAC;;wBAA3C,OAAO,GAAG,SAAiC,CAAC;;;;;wBAG9C,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,6BAAsB,IAAI,CAAC,SAAS,CAAC,WAAW,EAAE,IAAI,EAAE,CAAC,CAAC,CAAE,CAAC,CAAC;wBAChF,MAAM,OAAK,CAAC;;wBAGd,IAAI,IAAA,mCAAgB,EAAC,IAAI,CAAC,MAAM,CAAC,EAAE;4BACjC,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,mBAAmB,CAAC,CAAC;4BACtC,sBAAO,SAAS,EAAC;yBAClB;wBAEK,gBAAgB,GAAG,uBAAU,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC;wBACvD,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,sBAAe,gBAAgB,CAAE,CAAC,CAAC;wBACpD,sBAAO,gBAAgB,EAAC;;;;KACzB;IACH,sBAAC;AAAD,CAAC,AAzCD,IAyCC;AAzCY,0CAAe"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"isVoidReturnType.d.ts","sourceRoot":"","sources":["../../src/isVoidReturnType.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,uBAAuB,CAAC;AAE/C,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,MAAM,WAE9C"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isVoidReturnType = void 0;
|
|
4
|
+
function isVoidReturnType(method) {
|
|
5
|
+
return !method.returnType || method.returnType.name === 'void' || method.returnType.name === 'Promise<void>';
|
|
6
|
+
}
|
|
7
|
+
exports.isVoidReturnType = isVoidReturnType;
|
|
8
|
+
//# sourceMappingURL=isVoidReturnType.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"isVoidReturnType.js","sourceRoot":"","sources":["../../src/isVoidReturnType.ts"],"names":[],"mappings":";;;AAEA,SAAgB,gBAAgB,CAAC,MAAc;IAC7C,OAAO,CAAC,MAAM,CAAC,UAAU,IAAI,MAAM,CAAC,UAAU,CAAC,IAAI,KAAK,MAAM,IAAI,MAAM,CAAC,UAAU,CAAC,IAAI,KAAK,eAAe,CAAC;AAC/G,CAAC;AAFD,4CAEC"}
|
package/generated/index.ts
CHANGED
|
@@ -6,25 +6,22 @@ import '@proteinjs/server-api';
|
|
|
6
6
|
import '@proteinjs/user-auth';
|
|
7
7
|
import '@proteinjs/util';
|
|
8
8
|
|
|
9
|
-
|
|
10
9
|
/** Generate Source Graph */
|
|
11
10
|
|
|
12
|
-
const sourceGraph =
|
|
13
|
-
|
|
11
|
+
const sourceGraph =
|
|
12
|
+
'{"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":"@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"}]}';
|
|
14
13
|
|
|
15
14
|
/** Generate Source Links */
|
|
16
15
|
|
|
17
16
|
import { ServiceRouter } from '../src/ServiceRouter';
|
|
18
17
|
|
|
19
18
|
const sourceLinks = {
|
|
20
|
-
|
|
19
|
+
'@proteinjs/service/ServiceRouter': ServiceRouter,
|
|
21
20
|
};
|
|
22
21
|
|
|
23
|
-
|
|
24
22
|
/** Load Source Graph and Links */
|
|
25
23
|
|
|
26
24
|
import { SourceRepository } from '@proteinjs/reflection';
|
|
27
25
|
SourceRepository.merge(sourceGraph, sourceLinks);
|
|
28
26
|
|
|
29
|
-
|
|
30
|
-
export * from '../index';
|
|
27
|
+
export * from '../index';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@proteinjs/service",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.17",
|
|
4
4
|
"description": "Service api",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
@@ -41,5 +41,6 @@
|
|
|
41
41
|
"typescript": "5.2.2"
|
|
42
42
|
},
|
|
43
43
|
"main": "./dist/generated/index.js",
|
|
44
|
-
"types": "./dist/generated/index.d.ts"
|
|
44
|
+
"types": "./dist/generated/index.d.ts",
|
|
45
|
+
"gitHead": "b00ed0512004080bf7022ccd1221ff448aa4c174"
|
|
45
46
|
}
|
package/src/Service.ts
CHANGED
|
@@ -37,7 +37,7 @@ export const serviceFactory = <T extends Service>(serviceInterfaceQualifiedName:
|
|
|
37
37
|
const serviceInterface = SourceRepository.get().interface(serviceInterfaceQualifiedName);
|
|
38
38
|
for (const method of serviceInterface.methods) {
|
|
39
39
|
const servicePath = `/service/${serviceInterface.qualifiedName}/${method.name}`;
|
|
40
|
-
const serviceClient = new ServiceClient(servicePath);
|
|
40
|
+
const serviceClient = new ServiceClient(servicePath, method);
|
|
41
41
|
service[method.name] = serviceClient.send.bind(serviceClient);
|
|
42
42
|
}
|
|
43
43
|
|
package/src/ServiceClient.ts
CHANGED
|
@@ -1,11 +1,16 @@
|
|
|
1
|
+
import { Method } from '@proteinjs/reflection';
|
|
1
2
|
import { Serializer } from '@proteinjs/serializer';
|
|
2
3
|
import { Logger } from '@proteinjs/util';
|
|
4
|
+
import { isVoidReturnType } from './isVoidReturnType';
|
|
3
5
|
|
|
4
6
|
export class ServiceClient {
|
|
5
7
|
private static requestCounter = 1;
|
|
6
8
|
private logger = new Logger(this.constructor.name, 'info', 2000);
|
|
7
9
|
|
|
8
|
-
constructor(
|
|
10
|
+
constructor(
|
|
11
|
+
private servicePath: string,
|
|
12
|
+
private serviceMethod: Method
|
|
13
|
+
) {}
|
|
9
14
|
|
|
10
15
|
async send(...args: any[]): Promise<any> {
|
|
11
16
|
const serializedArgs = Serializer.serialize(args);
|
|
@@ -15,9 +20,12 @@ export class ServiceClient {
|
|
|
15
20
|
console.log(serializedArgs);
|
|
16
21
|
console.groupEnd();
|
|
17
22
|
const serializedReturn = await this._send(this.servicePath, serializedArgs);
|
|
18
|
-
console.groupCollapsed(
|
|
23
|
+
console.groupCollapsed(
|
|
24
|
+
`[#${requestNumber}] Received service response: ${this.servicePath}, return:${isVoidReturnType(this.serviceMethod) ? ' (void)' : ''}`
|
|
25
|
+
);
|
|
19
26
|
console.log(serializedReturn);
|
|
20
27
|
console.groupEnd();
|
|
28
|
+
|
|
21
29
|
return Serializer.deserialize(serializedReturn);
|
|
22
30
|
}
|
|
23
31
|
|
package/src/ServiceExecutor.ts
CHANGED
|
@@ -3,6 +3,7 @@ import { Service } from './Service';
|
|
|
3
3
|
import { Logger } from '@proteinjs/util';
|
|
4
4
|
import { Serializer } from '@proteinjs/serializer';
|
|
5
5
|
import { ServiceAuth } from './ServiceAuth';
|
|
6
|
+
import { isVoidReturnType } from './isVoidReturnType';
|
|
6
7
|
|
|
7
8
|
export class ServiceExecutor {
|
|
8
9
|
private logger: Logger;
|
|
@@ -35,6 +36,12 @@ export class ServiceExecutor {
|
|
|
35
36
|
this.logger.error(`Failed with args:\n${JSON.stringify(requestBody, null, 2)}`);
|
|
36
37
|
throw error;
|
|
37
38
|
}
|
|
39
|
+
|
|
40
|
+
if (isVoidReturnType(this.method)) {
|
|
41
|
+
this.logger.info(`Returning: (void)`);
|
|
42
|
+
return undefined;
|
|
43
|
+
}
|
|
44
|
+
|
|
38
45
|
const serializedReturn = Serializer.serialize(_return);
|
|
39
46
|
this.logger.info(`Returning:\n${serializedReturn}`);
|
|
40
47
|
return serializedReturn;
|