@nocobase/plugin-workflow-json-query 1.9.7

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.
Files changed (50) hide show
  1. package/LICENSE.txt +172 -0
  2. package/README.md +1 -0
  3. package/client.d.ts +2 -0
  4. package/client.js +1 -0
  5. package/dist/client/index.d.ts +23 -0
  6. package/dist/client/index.js +10 -0
  7. package/dist/client/instruction.d.ts +167 -0
  8. package/dist/externalVersion.js +19 -0
  9. package/dist/index.d.ts +17 -0
  10. package/dist/index.js +42 -0
  11. package/dist/locale/en-US.json +13 -0
  12. package/dist/locale/index.d.ts +10 -0
  13. package/dist/locale/index.js +42 -0
  14. package/dist/locale/zh-CN.json +14 -0
  15. package/dist/node_modules/jmespath/LICENSE +13 -0
  16. package/dist/node_modules/jmespath/artifacts/jmespath.min.js +2 -0
  17. package/dist/node_modules/jmespath/bower.json +24 -0
  18. package/dist/node_modules/jmespath/jmespath.js +1 -0
  19. package/dist/node_modules/jmespath/jp.js +23 -0
  20. package/dist/node_modules/jmespath/package.json +1 -0
  21. package/dist/node_modules/jsonata/LICENSE +19 -0
  22. package/dist/node_modules/jsonata/jsonata-es5.js +9875 -0
  23. package/dist/node_modules/jsonata/jsonata-es5.min.js +1 -0
  24. package/dist/node_modules/jsonata/jsonata.d.ts +72 -0
  25. package/dist/node_modules/jsonata/jsonata.js +1 -0
  26. package/dist/node_modules/jsonata/jsonata.min.js +1 -0
  27. package/dist/node_modules/jsonata/package.json +1 -0
  28. package/dist/node_modules/jsonpath-plus/LICENSE +22 -0
  29. package/dist/node_modules/jsonpath-plus/bin/jsonpath-cli.js +36 -0
  30. package/dist/node_modules/jsonpath-plus/dist/index-browser-esm.js +2158 -0
  31. package/dist/node_modules/jsonpath-plus/dist/index-browser-esm.min.js +2 -0
  32. package/dist/node_modules/jsonpath-plus/dist/index-browser-umd.cjs +2166 -0
  33. package/dist/node_modules/jsonpath-plus/dist/index-browser-umd.min.cjs +2 -0
  34. package/dist/node_modules/jsonpath-plus/dist/index-node-cjs.cjs +1 -0
  35. package/dist/node_modules/jsonpath-plus/dist/index-node-esm.js +2068 -0
  36. package/dist/node_modules/jsonpath-plus/package.json +1 -0
  37. package/dist/node_modules/jsonpath-plus/src/Safe-Script.js +200 -0
  38. package/dist/node_modules/jsonpath-plus/src/jsonpath-browser.js +102 -0
  39. package/dist/node_modules/jsonpath-plus/src/jsonpath-node.js +8 -0
  40. package/dist/node_modules/jsonpath-plus/src/jsonpath.d.ts +226 -0
  41. package/dist/node_modules/jsonpath-plus/src/jsonpath.js +784 -0
  42. package/dist/server/JSONQueryInstruction.d.ts +42 -0
  43. package/dist/server/JSONQueryInstruction.js +99 -0
  44. package/dist/server/Plugin.d.ts +24 -0
  45. package/dist/server/Plugin.js +62 -0
  46. package/dist/server/index.d.ts +17 -0
  47. package/dist/server/index.js +42 -0
  48. package/package.json +31 -0
  49. package/server.d.ts +2 -0
  50. package/server.js +1 -0
@@ -0,0 +1,42 @@
1
+ /**
2
+ * This file is part of the NocoBase (R) project.
3
+ * Copyright (c) 2020-2024 NocoBase Co., Ltd.
4
+ * Authors: NocoBase Team.
5
+ *
6
+ * This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
7
+ * For more information, please refer to: https://www.nocobase.com/agreement.
8
+ */
9
+ import { Registry } from '@nocobase/utils';
10
+ import { Instruction, Processor, FlowNodeModel } from '@nocobase/plugin-workflow';
11
+ type JSONQueryEngine = (expression: string, scope: any) => any;
12
+ export default class extends Instruction {
13
+ engines: Registry<JSONQueryEngine>;
14
+ constructor(workflow: any);
15
+ execute({ engine, expression, model, source }: {
16
+ engine?: string;
17
+ expression: any;
18
+ model: any;
19
+ source: any;
20
+ }): Promise<{
21
+ result: any;
22
+ status: 1;
23
+ } | {
24
+ result: any;
25
+ status: -2;
26
+ }>;
27
+ run(node: FlowNodeModel, prevJob: any, processor: Processor): Promise<{
28
+ result: any;
29
+ status: 1;
30
+ } | {
31
+ result: any;
32
+ status: -2;
33
+ }>;
34
+ test(config: any): Promise<{
35
+ result: any;
36
+ status: 1;
37
+ } | {
38
+ result: any;
39
+ status: -2;
40
+ }>;
41
+ }
42
+ export {};
@@ -0,0 +1,99 @@
1
+ /**
2
+ * This file is part of the NocoBase (R) project.
3
+ * Copyright (c) 2020-2024 NocoBase Co., Ltd.
4
+ * Authors: NocoBase Team.
5
+ *
6
+ * This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
7
+ * For more information, please refer to: https://www.nocobase.com/agreement.
8
+ */
9
+
10
+ var __defProp = Object.defineProperty;
11
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
12
+ var __getOwnPropNames = Object.getOwnPropertyNames;
13
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
14
+ var __export = (target, all) => {
15
+ for (var name in all)
16
+ __defProp(target, name, { get: all[name], enumerable: true });
17
+ };
18
+ var __copyProps = (to, from, except, desc) => {
19
+ if (from && typeof from === "object" || typeof from === "function") {
20
+ for (let key of __getOwnPropNames(from))
21
+ if (!__hasOwnProp.call(to, key) && key !== except)
22
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
23
+ }
24
+ return to;
25
+ };
26
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
27
+ var JSONQueryInstruction_exports = {};
28
+ __export(JSONQueryInstruction_exports, {
29
+ default: () => JSONQueryInstruction_default
30
+ });
31
+ module.exports = __toCommonJS(JSONQueryInstruction_exports);
32
+ var import_lodash = require("lodash");
33
+ var import_utils = require("@nocobase/utils");
34
+ var import_plugin_workflow = require("@nocobase/plugin-workflow");
35
+ function mapModel(data, model) {
36
+ const result = {};
37
+ model.forEach(({ path, alias }) => {
38
+ if (typeof data === "object" && data) {
39
+ result[alias || path.replace(/\./g, "_")] = (0, import_lodash.get)(data, path);
40
+ }
41
+ });
42
+ return result;
43
+ }
44
+ class JSONQueryInstruction_default extends import_plugin_workflow.Instruction {
45
+ engines = new import_utils.Registry();
46
+ constructor(workflow) {
47
+ super(workflow);
48
+ this.engines.register("jmespath", (expression, scope) => {
49
+ const jmespath = require("jmespath");
50
+ return jmespath.search(scope, expression);
51
+ });
52
+ this.engines.register("jsonpathplus", (expression, scope) => {
53
+ const { JSONPath } = require("jsonpath-plus");
54
+ return JSONPath({ path: expression, json: scope, wrap: false });
55
+ });
56
+ this.engines.register("jsonata", (expression, scope) => {
57
+ const jsonata = require("jsonata");
58
+ return jsonata(expression).evaluate(scope);
59
+ });
60
+ }
61
+ async execute({ engine = "jmespath", expression, model, source }) {
62
+ const query = this.engines.get(engine);
63
+ try {
64
+ let result = query ? await query(expression, source) : source;
65
+ if ((model == null ? void 0 : model.length) && typeof result === "object" && result) {
66
+ result = Array.isArray(result) ? result.map((item) => mapModel(item, model)) : mapModel(result, model);
67
+ }
68
+ return {
69
+ result,
70
+ status: import_plugin_workflow.JOB_STATUS.RESOLVED
71
+ };
72
+ } catch (e) {
73
+ return {
74
+ result: e.toString(),
75
+ status: import_plugin_workflow.JOB_STATUS.ERROR
76
+ };
77
+ }
78
+ }
79
+ async run(node, prevJob, processor) {
80
+ var _a;
81
+ const { engine = "jmespath", model, source = "" } = node.config;
82
+ const { data, expression } = processor.getParsedValue(
83
+ {
84
+ data: source,
85
+ expression: ((_a = node.config) == null ? void 0 : _a.expression) || ""
86
+ },
87
+ node.id
88
+ );
89
+ return this.execute({
90
+ engine,
91
+ expression,
92
+ model,
93
+ source: data
94
+ });
95
+ }
96
+ async test(config) {
97
+ return this.execute(config);
98
+ }
99
+ }
@@ -0,0 +1,24 @@
1
+ /**
2
+ * This file is part of the NocoBase (R) project.
3
+ * Copyright (c) 2020-2024 NocoBase Co., Ltd.
4
+ * Authors: NocoBase Team.
5
+ *
6
+ * This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
7
+ * For more information, please refer to: https://www.nocobase.com/agreement.
8
+ */
9
+ /**
10
+ * This file is part of the NocoBase (R) project.
11
+ * Copyright (c) 2020-2024 NocoBase Co., Ltd.
12
+ * Authors: NocoBase Team.
13
+ *
14
+ * This program is offered under a commercial license.
15
+ * For more information, see <https://www.nocobase.com/agreement>
16
+ */
17
+ import { Plugin } from '@nocobase/server';
18
+ export declare class WorkflowJSONQueryPlugin extends Plugin {
19
+ load(): Promise<void>;
20
+ afterEnable(): Promise<void>;
21
+ afterDisable(): Promise<void>;
22
+ remove(): Promise<void>;
23
+ }
24
+ export default WorkflowJSONQueryPlugin;
@@ -0,0 +1,62 @@
1
+ /**
2
+ * This file is part of the NocoBase (R) project.
3
+ * Copyright (c) 2020-2024 NocoBase Co., Ltd.
4
+ * Authors: NocoBase Team.
5
+ *
6
+ * This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
7
+ * For more information, please refer to: https://www.nocobase.com/agreement.
8
+ */
9
+
10
+ var __create = Object.create;
11
+ var __defProp = Object.defineProperty;
12
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
13
+ var __getOwnPropNames = Object.getOwnPropertyNames;
14
+ var __getProtoOf = Object.getPrototypeOf;
15
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
16
+ var __export = (target, all) => {
17
+ for (var name in all)
18
+ __defProp(target, name, { get: all[name], enumerable: true });
19
+ };
20
+ var __copyProps = (to, from, except, desc) => {
21
+ if (from && typeof from === "object" || typeof from === "function") {
22
+ for (let key of __getOwnPropNames(from))
23
+ if (!__hasOwnProp.call(to, key) && key !== except)
24
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
25
+ }
26
+ return to;
27
+ };
28
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
29
+ // If the importer is in node compatibility mode or this is not an ESM
30
+ // file that has been converted to a CommonJS file using a Babel-
31
+ // compatible transform (i.e. "__esModule" has not been set), then set
32
+ // "default" to the CommonJS "module.exports" for node compatibility.
33
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
34
+ mod
35
+ ));
36
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
37
+ var Plugin_exports = {};
38
+ __export(Plugin_exports, {
39
+ WorkflowJSONQueryPlugin: () => WorkflowJSONQueryPlugin,
40
+ default: () => Plugin_default
41
+ });
42
+ module.exports = __toCommonJS(Plugin_exports);
43
+ var import_server = require("@nocobase/server");
44
+ var import_plugin_workflow = __toESM(require("@nocobase/plugin-workflow"));
45
+ var import_JSONQueryInstruction = __toESM(require("./JSONQueryInstruction"));
46
+ class WorkflowJSONQueryPlugin extends import_server.Plugin {
47
+ async load() {
48
+ const workflowPlugin = this.app.getPlugin(import_plugin_workflow.default);
49
+ workflowPlugin.registerInstruction("json-query", import_JSONQueryInstruction.default);
50
+ }
51
+ async afterEnable() {
52
+ }
53
+ async afterDisable() {
54
+ }
55
+ async remove() {
56
+ }
57
+ }
58
+ var Plugin_default = WorkflowJSONQueryPlugin;
59
+ // Annotate the CommonJS export names for ESM import in node:
60
+ 0 && (module.exports = {
61
+ WorkflowJSONQueryPlugin
62
+ });
@@ -0,0 +1,17 @@
1
+ /**
2
+ * This file is part of the NocoBase (R) project.
3
+ * Copyright (c) 2020-2024 NocoBase Co., Ltd.
4
+ * Authors: NocoBase Team.
5
+ *
6
+ * This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
7
+ * For more information, please refer to: https://www.nocobase.com/agreement.
8
+ */
9
+ /**
10
+ * This file is part of the NocoBase (R) project.
11
+ * Copyright (c) 2020-2024 NocoBase Co., Ltd.
12
+ * Authors: NocoBase Team.
13
+ *
14
+ * This program is offered under a commercial license.
15
+ * For more information, see <https://www.nocobase.com/agreement>
16
+ */
17
+ export { default } from './Plugin';
@@ -0,0 +1,42 @@
1
+ /**
2
+ * This file is part of the NocoBase (R) project.
3
+ * Copyright (c) 2020-2024 NocoBase Co., Ltd.
4
+ * Authors: NocoBase Team.
5
+ *
6
+ * This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
7
+ * For more information, please refer to: https://www.nocobase.com/agreement.
8
+ */
9
+
10
+ var __create = Object.create;
11
+ var __defProp = Object.defineProperty;
12
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
13
+ var __getOwnPropNames = Object.getOwnPropertyNames;
14
+ var __getProtoOf = Object.getPrototypeOf;
15
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
16
+ var __export = (target, all) => {
17
+ for (var name in all)
18
+ __defProp(target, name, { get: all[name], enumerable: true });
19
+ };
20
+ var __copyProps = (to, from, except, desc) => {
21
+ if (from && typeof from === "object" || typeof from === "function") {
22
+ for (let key of __getOwnPropNames(from))
23
+ if (!__hasOwnProp.call(to, key) && key !== except)
24
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
25
+ }
26
+ return to;
27
+ };
28
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
29
+ // If the importer is in node compatibility mode or this is not an ESM
30
+ // file that has been converted to a CommonJS file using a Babel-
31
+ // compatible transform (i.e. "__esModule" has not been set), then set
32
+ // "default" to the CommonJS "module.exports" for node compatibility.
33
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
34
+ mod
35
+ ));
36
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
37
+ var server_exports = {};
38
+ __export(server_exports, {
39
+ default: () => import_Plugin.default
40
+ });
41
+ module.exports = __toCommonJS(server_exports);
42
+ var import_Plugin = __toESM(require("./Plugin"));
package/package.json ADDED
@@ -0,0 +1,31 @@
1
+ {
2
+ "name": "@nocobase/plugin-workflow-json-query",
3
+ "version": "1.9.7",
4
+ "displayName": "Workflow: JSON calculation",
5
+ "displayName.zh-CN": "工作流:JSON 计算",
6
+ "description": "Used for transforming or calculating values from complex JSON data (result of HTTP request or SQL etc.).",
7
+ "description.zh-CN": "用于转换或计算复杂 JSON 对象的值(例如 HTTP 请求节点和 SQL 节点的结果)。",
8
+ "main": "./dist/server/index.js",
9
+ "homepage": "https://docs.nocobase.com/handbook/workflow-json-query",
10
+ "homepage.zh-CN": "https://docs-cn.nocobase.com/handbook/workflow-json-query",
11
+ "keywords": [
12
+ "Workflow"
13
+ ],
14
+ "devDependencies": {
15
+ "@nocobase/plugin-workflow-test": "1.9.7",
16
+ "jmespath": "^0.16.0",
17
+ "jsonata": "^2.0.3",
18
+ "jsonpath-plus": "^10.3.0"
19
+ },
20
+ "peerDependencies": {
21
+ "@nocobase/client": "1.x",
22
+ "@nocobase/plugin-workflow": "1.x",
23
+ "@nocobase/server": "1.x",
24
+ "@nocobase/test": "1.x",
25
+ "@nocobase/utils": "1.x"
26
+ },
27
+ "gitHead": "f5b5050e4bb51b59a294a66481f563c9eb409d71",
28
+ "nocobase": {
29
+ "defaultEnabled": true
30
+ }
31
+ }
package/server.d.ts ADDED
@@ -0,0 +1,2 @@
1
+ export * from './dist/server';
2
+ export { default } from './dist/server';
package/server.js ADDED
@@ -0,0 +1 @@
1
+ module.exports = require('./dist/server/index.js');