@nocobase/utils 2.0.0-alpha.3 → 2.0.0-alpha.31

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/lib/client.d.ts CHANGED
@@ -31,4 +31,6 @@ export * from './url';
31
31
  export * from './transformMultiColumnToSingleColumn';
32
32
  export * from './transformFilter';
33
33
  export * from './variable-usage';
34
+ export * from './run-sql';
35
+ export * from './liquidjs';
34
36
  export { dayjs, lodash, getDayRangeByParams, getOffsetRangeByParams };
package/lib/client.js CHANGED
@@ -68,6 +68,8 @@ __reExport(client_exports, require("./url"), module.exports);
68
68
  __reExport(client_exports, require("./transformMultiColumnToSingleColumn"), module.exports);
69
69
  __reExport(client_exports, require("./transformFilter"), module.exports);
70
70
  __reExport(client_exports, require("./variable-usage"), module.exports);
71
+ __reExport(client_exports, require("./run-sql"), module.exports);
72
+ __reExport(client_exports, require("./liquidjs"), module.exports);
71
73
  // Annotate the CommonJS export names for ESM import in node:
72
74
  0 && (module.exports = {
73
75
  dayjs,
@@ -95,5 +97,7 @@ __reExport(client_exports, require("./variable-usage"), module.exports);
95
97
  ...require("./url"),
96
98
  ...require("./transformMultiColumnToSingleColumn"),
97
99
  ...require("./transformFilter"),
98
- ...require("./variable-usage")
100
+ ...require("./variable-usage"),
101
+ ...require("./run-sql"),
102
+ ...require("./liquidjs")
99
103
  });
package/lib/index.d.ts CHANGED
@@ -41,4 +41,6 @@ export * from './uid';
41
41
  export * from './url';
42
42
  export * from './variable-usage';
43
43
  export * from './wrap-middleware';
44
+ export * from './run-sql';
45
+ export * from './liquidjs';
44
46
  export { lodash };
package/lib/index.js CHANGED
@@ -77,6 +77,8 @@ __reExport(src_exports, require("./uid"), module.exports);
77
77
  __reExport(src_exports, require("./url"), module.exports);
78
78
  __reExport(src_exports, require("./variable-usage"), module.exports);
79
79
  __reExport(src_exports, require("./wrap-middleware"), module.exports);
80
+ __reExport(src_exports, require("./run-sql"), module.exports);
81
+ __reExport(src_exports, require("./liquidjs"), module.exports);
80
82
  // Annotate the CommonJS export names for ESM import in node:
81
83
  0 && (module.exports = {
82
84
  Schema,
@@ -113,5 +115,7 @@ __reExport(src_exports, require("./wrap-middleware"), module.exports);
113
115
  ...require("./uid"),
114
116
  ...require("./url"),
115
117
  ...require("./variable-usage"),
116
- ...require("./wrap-middleware")
118
+ ...require("./wrap-middleware"),
119
+ ...require("./run-sql"),
120
+ ...require("./liquidjs")
117
121
  });
@@ -0,0 +1,11 @@
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
+ export declare function transformLiquidContext(paths?: any[]): {};
10
+ export declare function getLiquidContext(template: string): Promise<{}>;
11
+ export declare function parseLiquidContext(template: string, liquidContext: any): Promise<any>;
@@ -0,0 +1,71 @@
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 __name = (target, value) => __defProp(target, "name", { value, configurable: true });
15
+ var __export = (target, all) => {
16
+ for (var name in all)
17
+ __defProp(target, name, { get: all[name], enumerable: true });
18
+ };
19
+ var __copyProps = (to, from, except, desc) => {
20
+ if (from && typeof from === "object" || typeof from === "function") {
21
+ for (let key of __getOwnPropNames(from))
22
+ if (!__hasOwnProp.call(to, key) && key !== except)
23
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
24
+ }
25
+ return to;
26
+ };
27
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
28
+ var liquidjs_exports = {};
29
+ __export(liquidjs_exports, {
30
+ getLiquidContext: () => getLiquidContext,
31
+ parseLiquidContext: () => parseLiquidContext,
32
+ transformLiquidContext: () => transformLiquidContext
33
+ });
34
+ module.exports = __toCommonJS(liquidjs_exports);
35
+ var import_liquidjs = require("liquidjs");
36
+ const liquid = new import_liquidjs.Liquid();
37
+ function transformLiquidContext(paths = []) {
38
+ const result = {};
39
+ for (const fullPath of paths) {
40
+ const path = fullPath.replace(/^ctx\./, "");
41
+ const keys = path.split(".");
42
+ let current = result;
43
+ for (let i = 0; i < keys.length; i++) {
44
+ const key = keys[i];
45
+ const isLast = i === keys.length - 1;
46
+ if (isLast) {
47
+ current[key] = `{{${fullPath}}}`;
48
+ } else {
49
+ current[key] = current[key] || {};
50
+ current = current[key];
51
+ }
52
+ }
53
+ }
54
+ return result;
55
+ }
56
+ __name(transformLiquidContext, "transformLiquidContext");
57
+ async function getLiquidContext(template) {
58
+ const vars = await liquid.fullVariables(template);
59
+ return transformLiquidContext(vars);
60
+ }
61
+ __name(getLiquidContext, "getLiquidContext");
62
+ async function parseLiquidContext(template, liquidContext) {
63
+ return await liquid.parseAndRender(template, { ctx: liquidContext });
64
+ }
65
+ __name(parseLiquidContext, "parseLiquidContext");
66
+ // Annotate the CommonJS export names for ESM import in node:
67
+ 0 && (module.exports = {
68
+ getLiquidContext,
69
+ parseLiquidContext,
70
+ transformLiquidContext
71
+ });
@@ -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
+ export declare function parseSQLBindParams(template: string): {
10
+ sql: string;
11
+ bind: {};
12
+ };
13
+ export declare function transformSQL(template: string): Promise<{
14
+ sql: string;
15
+ bind: {};
16
+ liquidContext: {};
17
+ }>;
package/lib/run-sql.js ADDED
@@ -0,0 +1,57 @@
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 __name = (target, value) => __defProp(target, "name", { value, configurable: true });
15
+ var __export = (target, all) => {
16
+ for (var name in all)
17
+ __defProp(target, name, { get: all[name], enumerable: true });
18
+ };
19
+ var __copyProps = (to, from, except, desc) => {
20
+ if (from && typeof from === "object" || typeof from === "function") {
21
+ for (let key of __getOwnPropNames(from))
22
+ if (!__hasOwnProp.call(to, key) && key !== except)
23
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
24
+ }
25
+ return to;
26
+ };
27
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
28
+ var run_sql_exports = {};
29
+ __export(run_sql_exports, {
30
+ parseSQLBindParams: () => parseSQLBindParams,
31
+ transformSQL: () => transformSQL
32
+ });
33
+ module.exports = __toCommonJS(run_sql_exports);
34
+ var import_liquidjs = require("./liquidjs");
35
+ function parseSQLBindParams(template) {
36
+ let index = 1;
37
+ const bind = {};
38
+ const sql = template.replace(/{{\s*([^}]+)\s*}}/g, (_, expr) => {
39
+ const key = `__var${index}`;
40
+ bind[key] = `{{${expr.trim()}}}`;
41
+ index++;
42
+ return `$${key}`;
43
+ });
44
+ return { sql, bind };
45
+ }
46
+ __name(parseSQLBindParams, "parseSQLBindParams");
47
+ async function transformSQL(template) {
48
+ const { sql, bind } = parseSQLBindParams(template);
49
+ const liquidContext = await (0, import_liquidjs.getLiquidContext)(sql);
50
+ return { sql, bind, liquidContext };
51
+ }
52
+ __name(transformSQL, "transformSQL");
53
+ // Annotate the CommonJS export names for ESM import in node:
54
+ 0 && (module.exports = {
55
+ parseSQLBindParams,
56
+ transformSQL
57
+ });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nocobase/utils",
3
- "version": "2.0.0-alpha.3",
3
+ "version": "2.0.0-alpha.31",
4
4
  "main": "lib/index.js",
5
5
  "types": "./lib/index.d.ts",
6
6
  "license": "AGPL-3.0",
@@ -13,8 +13,9 @@
13
13
  "flat-to-nested": "^1.1.1",
14
14
  "graphlib": "^2.1.8",
15
15
  "handlebars": "^4.7.8",
16
+ "liquidjs": "^10.23.0",
16
17
  "multer": "^1.4.5-lts.2",
17
18
  "object-path": "^0.11.8"
18
19
  },
19
- "gitHead": "8efc23aa78058d871e98a91419f3c4a61762cc15"
20
+ "gitHead": "1ccdc0a8af73f6c2e3e83df75741947a5a8c1984"
20
21
  }