@steedos/service-rest 2.7.1-beta.8 → 2.7.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/consts.js +3 -2
- package/package.json +4 -4
- package/package.service.js +70 -4
package/consts.js
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
/*
|
|
2
2
|
* @Author: sunhaolin@hotoa.com
|
|
3
3
|
* @Date: 2023-06-12 17:20:40
|
|
4
|
-
* @LastEditors:
|
|
5
|
-
* @LastEditTime: 2024-
|
|
4
|
+
* @LastEditors: 孙浩林 sunhaolin@steedos.com
|
|
5
|
+
* @LastEditTime: 2024-05-14 16:54:31
|
|
6
6
|
* @Description:
|
|
7
7
|
*/
|
|
8
8
|
module.exports = {
|
|
9
9
|
QUERY_DOCS_TOP: 500,
|
|
10
10
|
REQUEST_SUCCESS_STATUS: 0,
|
|
11
|
+
METADATA_CACHER_SERVICE_NAME: 'metadata-cachers-service',
|
|
11
12
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@steedos/service-rest",
|
|
3
|
-
"version": "2.7.1
|
|
3
|
+
"version": "2.7.1",
|
|
4
4
|
"main": "package.service.js",
|
|
5
5
|
"private": false,
|
|
6
6
|
"publishConfig": {
|
|
@@ -16,9 +16,9 @@
|
|
|
16
16
|
"repository": {},
|
|
17
17
|
"license": "MIT",
|
|
18
18
|
"dependencies": {
|
|
19
|
-
"@steedos/objectql": "2.7.1
|
|
20
|
-
"@steedos/service-object-mixin": "2.7.1
|
|
19
|
+
"@steedos/objectql": "2.7.1",
|
|
20
|
+
"@steedos/service-object-mixin": "2.7.1",
|
|
21
21
|
"lodash": "^4.17.21"
|
|
22
22
|
},
|
|
23
|
-
"gitHead": "
|
|
23
|
+
"gitHead": "5485c0bd811776f2ffde988c0a9394d778a2dc90"
|
|
24
24
|
}
|
package/package.service.js
CHANGED
|
@@ -1,14 +1,16 @@
|
|
|
1
1
|
/*
|
|
2
2
|
* @Author: sunhaolin@hotoa.com
|
|
3
3
|
* @Date: 2023-03-23 15:12:14
|
|
4
|
-
* @LastEditors:
|
|
5
|
-
* @LastEditTime: 2024-
|
|
4
|
+
* @LastEditors: 孙浩林 sunhaolin@steedos.com
|
|
5
|
+
* @LastEditTime: 2024-05-21 13:22:25
|
|
6
6
|
* @Description:
|
|
7
7
|
*/
|
|
8
8
|
"use strict";
|
|
9
9
|
// @ts-check
|
|
10
10
|
const serviceObjectMixin = require('@steedos/service-object-mixin');
|
|
11
|
-
const {
|
|
11
|
+
const {
|
|
12
|
+
QUERY_DOCS_TOP, REQUEST_SUCCESS_STATUS, METADATA_CACHER_SERVICE_NAME
|
|
13
|
+
} = require('./consts')
|
|
12
14
|
const { translateRecords } = require('./translate');
|
|
13
15
|
const _ = require('lodash')
|
|
14
16
|
const { getObject } = require('@steedos/objectql');
|
|
@@ -719,7 +721,71 @@ module.exports = {
|
|
|
719
721
|
}
|
|
720
722
|
}
|
|
721
723
|
}
|
|
722
|
-
}
|
|
724
|
+
},
|
|
725
|
+
/**
|
|
726
|
+
* @api {POST} /api/v1/:objectName/functions/:functionApiName 函数
|
|
727
|
+
* @apiVersion 0.0.0
|
|
728
|
+
* @apiName functions
|
|
729
|
+
* @apiGroup @steedos/service-rest
|
|
730
|
+
* @apiParam {String} objectName 对象API Name,如:contracts
|
|
731
|
+
* @apiParam {String} functionApiName 函数API Name,如:pay
|
|
732
|
+
* @apiBody {Object} doc 新增的内容,如:{ name: 'test', description: 'test' }
|
|
733
|
+
* @apiSuccess {Object} result 执行结果
|
|
734
|
+
* @apiSuccessExample {json} Success-Response:
|
|
735
|
+
* HTTP/1.1 200 OK
|
|
736
|
+
* {
|
|
737
|
+
* "status": 0, // 返回 0,表示当前接口正确返回,否则按错误请求处理
|
|
738
|
+
* "msg": "", // 返回接口处理信息
|
|
739
|
+
* "data": {
|
|
740
|
+
* "_id": "5a6b1c3c8d6d1d0b7c6d1d0b",
|
|
741
|
+
* "name": "",
|
|
742
|
+
* ...
|
|
743
|
+
* }
|
|
744
|
+
* }
|
|
745
|
+
* }
|
|
746
|
+
* @apiErrorExample {json} Error-Response:
|
|
747
|
+
* HTTP/1.1 500 Error
|
|
748
|
+
* {
|
|
749
|
+
* "status": -1,
|
|
750
|
+
* "msg": "",
|
|
751
|
+
* "data": {}
|
|
752
|
+
* }
|
|
753
|
+
*/
|
|
754
|
+
functions: {
|
|
755
|
+
rest: [
|
|
756
|
+
{
|
|
757
|
+
method: "GET",
|
|
758
|
+
path: "/:objectName/functions/:functionApiName",
|
|
759
|
+
}, {
|
|
760
|
+
method: "POST",
|
|
761
|
+
path: "/:objectName/functions/:functionApiName",
|
|
762
|
+
}
|
|
763
|
+
],
|
|
764
|
+
async handler(ctx) {
|
|
765
|
+
const userSession = ctx.meta.user;
|
|
766
|
+
const { objectName, functionApiName } = ctx.params;
|
|
767
|
+
const object = getObject(objectName)
|
|
768
|
+
|
|
769
|
+
// 启用API(is_rest === true) 的函数才在这里执行
|
|
770
|
+
// 从缓存获取
|
|
771
|
+
const fDocs = await broker.call(`${METADATA_CACHER_SERVICE_NAME}.find`, {metadataName: 'object_functions', filters: [
|
|
772
|
+
["objectApiName", "=", objectName],
|
|
773
|
+
["_name", "=", functionApiName],
|
|
774
|
+
["is_rest", "=", true]
|
|
775
|
+
]});
|
|
776
|
+
|
|
777
|
+
if (!fDocs || fDocs.length == 0) {
|
|
778
|
+
throw new Error(`function need to enable api access.`);
|
|
779
|
+
}
|
|
780
|
+
|
|
781
|
+
const result = await object.runFunction(functionApiName, ctx.params, userSession);
|
|
782
|
+
return {
|
|
783
|
+
"status": REQUEST_SUCCESS_STATUS,
|
|
784
|
+
"msg": "",
|
|
785
|
+
"data": result
|
|
786
|
+
}
|
|
787
|
+
}
|
|
788
|
+
},
|
|
723
789
|
},
|
|
724
790
|
|
|
725
791
|
/**
|