semanticdb-core 1.1.39 → 1.1.40

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.
@@ -2,13 +2,20 @@ import { LogicformType } from './logicform';
2
2
  import { SchemaType } from '../schema/schema';
3
3
  export declare const DEFAULT_EXPLAIN_LOGICFORM_LOCALE = "zh-CN";
4
4
  export type ExplainLogicformSchemas = Record<string, SchemaType>;
5
+ export type ExplainLogicformResultItem = {
6
+ title: string;
7
+ values: string[];
8
+ };
9
+ export type ExplainFilterLikeResult = ExplainLogicformResultItem;
10
+ export type ExplainQueryResult = ExplainLogicformResultItem;
5
11
  export declare const normalizeExplainLogicformLocale: (locale?: string) => string;
12
+ export declare const stringifyExplainFilterLikeResult: (result: ExplainLogicformResultItem, separator?: string) => string;
6
13
  export declare const explainGroupbyLevel: (level?: string) => string;
7
- export declare const explainSchema: (logicform: LogicformType, schemas: ExplainLogicformSchemas, locale?: string) => string;
8
- export declare const explainQuery: (logicform: LogicformType, _schemas: ExplainLogicformSchemas, locale?: string) => string;
9
- export declare const explainEntityID: (logicform: LogicformType, _schemas: ExplainLogicformSchemas, locale?: string) => string;
10
- export declare const explainPreds: (logicform: LogicformType, _schemas: ExplainLogicformSchemas, locale?: string) => string;
11
- export declare const explainGroupby: (logicform: LogicformType, _schemas: ExplainLogicformSchemas, locale?: string) => string;
12
- export declare const explainLimit: (logicform: LogicformType, _schemas: ExplainLogicformSchemas, locale?: string) => string;
13
- export declare const explainHaving: (logicform: LogicformType, _schemas: ExplainLogicformSchemas, locale?: string) => string;
14
- export declare const explainLogicform: (logicform: LogicformType, schemas: ExplainLogicformSchemas, locale?: string) => string[];
14
+ export declare const explainSchema: (logicform: LogicformType, schemas: ExplainLogicformSchemas, locale?: string) => ExplainLogicformResultItem;
15
+ export declare const explainQuery: (logicform: LogicformType, _schemas: ExplainLogicformSchemas, locale?: string) => ExplainQueryResult;
16
+ export declare const explainEntityID: (logicform: LogicformType, _schemas: ExplainLogicformSchemas, locale?: string) => ExplainLogicformResultItem;
17
+ export declare const explainPreds: (logicform: LogicformType, _schemas: ExplainLogicformSchemas, locale?: string) => ExplainLogicformResultItem;
18
+ export declare const explainGroupby: (logicform: LogicformType, _schemas: ExplainLogicformSchemas, locale?: string) => ExplainLogicformResultItem;
19
+ export declare const explainLimit: (logicform: LogicformType, _schemas: ExplainLogicformSchemas, locale?: string) => ExplainLogicformResultItem;
20
+ export declare const explainHaving: (logicform: LogicformType, _schemas: ExplainLogicformSchemas, locale?: string) => ExplainLogicformResultItem;
21
+ export declare const explainLogicform: (logicform: LogicformType, schemas: ExplainLogicformSchemas, locale?: string) => ExplainLogicformResultItem[];
@@ -1,7 +1,12 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.explainLogicform = exports.explainHaving = exports.explainLimit = exports.explainGroupby = exports.explainPreds = exports.explainEntityID = exports.explainQuery = exports.explainSchema = exports.explainGroupbyLevel = exports.normalizeExplainLogicformLocale = exports.DEFAULT_EXPLAIN_LOGICFORM_LOCALE = void 0;
3
+ exports.explainLogicform = exports.explainHaving = exports.explainLimit = exports.explainGroupby = exports.explainPreds = exports.explainEntityID = exports.explainQuery = exports.explainSchema = exports.explainGroupbyLevel = exports.stringifyExplainFilterLikeResult = exports.normalizeExplainLogicformLocale = exports.DEFAULT_EXPLAIN_LOGICFORM_LOCALE = void 0;
4
+ const logicform_utils_1 = require("./logicform.utils");
4
5
  exports.DEFAULT_EXPLAIN_LOGICFORM_LOCALE = 'zh-CN';
6
+ const buildExplainResult = (title, values) => ({
7
+ title,
8
+ values,
9
+ });
5
10
  const normalizeExplainLogicformLocale = (locale) => {
6
11
  if (locale === exports.DEFAULT_EXPLAIN_LOGICFORM_LOCALE) {
7
12
  return locale;
@@ -27,6 +32,9 @@ const stringifyJson = (value) => {
27
32
  if (value === undefined) {
28
33
  return '无';
29
34
  }
35
+ if (typeof value === 'string') {
36
+ return value;
37
+ }
30
38
  const stringified = JSON.stringify(value);
31
39
  return stringified === undefined ? String(value) : stringified;
32
40
  };
@@ -40,26 +48,39 @@ const getEntityIdFromValue = (value) => {
40
48
  const entityId = value.entity_id;
41
49
  return typeof entityId === 'string' && entityId ? entityId : undefined;
42
50
  };
43
- const explainFilterLikeQuery = (query, prefix = '筛选', separator = ' ') => {
51
+ const explainFilterLikeQuery = (query, prefix = '筛选', includeValue = false) => {
44
52
  if (!query || Object.keys(query).length === 0) {
45
- return '';
53
+ return buildExplainResult(prefix, []);
46
54
  }
47
- const parts = Object.keys(query)
48
- .filter((k) => k !== 'entity_id')
49
- .map((k) => {
55
+ const values = Object.entries(query)
56
+ .filter(([k]) => includeValue || k !== 'entity_id')
57
+ .map(([k, v]) => {
50
58
  const key = k.split('_').pop() || '';
59
+ if (includeValue) {
60
+ if (k === 'entity_id') {
61
+ return `ID为${stringifyJson(v)}`;
62
+ }
63
+ return `${key} = ${stringifyJson(v)}`;
64
+ }
51
65
  const entityId = getEntityIdFromValue(query[k]);
52
66
  if (entityId) {
53
67
  return `${key}(${entityId})`;
54
68
  }
55
69
  return key;
56
70
  });
57
- const queryEntityId = getEntityIdFromValue(query);
71
+ const queryEntityId = includeValue ? undefined : getEntityIdFromValue(query);
58
72
  if (queryEntityId) {
59
- parts.push(`ID为${queryEntityId}`);
73
+ values.push(`ID为${queryEntityId}`);
74
+ }
75
+ return buildExplainResult(prefix, values);
76
+ };
77
+ const stringifyExplainFilterLikeResult = (result, separator = ' ') => {
78
+ if (result.values.length === 0) {
79
+ return '';
60
80
  }
61
- return parts.length > 0 ? `${prefix}${separator}${parts.join('、')}` : '';
81
+ return `${result.title}${separator}${result.values.join('、')}`;
62
82
  };
83
+ exports.stringifyExplainFilterLikeResult = stringifyExplainFilterLikeResult;
63
84
  const explainGroupbyLevel = (level) => {
64
85
  if (!level) {
65
86
  return '';
@@ -71,54 +92,65 @@ const explainSchema = (logicform, schemas, locale = exports.DEFAULT_EXPLAIN_LOGI
71
92
  var _a;
72
93
  (0, exports.normalizeExplainLogicformLocale)(locale);
73
94
  if (!logicform.schema) {
74
- return '未指定主题';
95
+ return buildExplainResult('主题', ['未指定']);
75
96
  }
76
- const schemaName = ((_a = schemas[logicform.schema]) === null || _a === void 0 ? void 0 : _a.name) || logicform.schema;
77
- return `${schemaName}主题`;
97
+ const schemaValues = [
98
+ ((_a = schemas[logicform.schema]) === null || _a === void 0 ? void 0 : _a.name) || logicform.schema,
99
+ ...(logicform.preds || [])
100
+ .map((pred) => {
101
+ var _a;
102
+ if (!pred || typeof pred !== 'object' || !pred.schema) {
103
+ return null;
104
+ }
105
+ return ((_a = schemas[pred.schema]) === null || _a === void 0 ? void 0 : _a.name) || pred.schema;
106
+ })
107
+ .filter((schemaName) => typeof schemaName === 'string' && schemaName.length > 0),
108
+ ];
109
+ return buildExplainResult('主题', Array.from(new Set(schemaValues)));
78
110
  };
79
111
  exports.explainSchema = explainSchema;
80
112
  const explainQuery = (logicform, _schemas, locale = exports.DEFAULT_EXPLAIN_LOGICFORM_LOCALE) => {
81
113
  (0, exports.normalizeExplainLogicformLocale)(locale);
82
- return explainFilterLikeQuery(logicform.query, '筛选');
114
+ return explainFilterLikeQuery(logicform.query ? (0, logicform_utils_1.getFlattenQuery)(logicform.query) : undefined, '筛选', true);
83
115
  };
84
116
  exports.explainQuery = explainQuery;
85
117
  const explainEntityID = (logicform, _schemas, locale = exports.DEFAULT_EXPLAIN_LOGICFORM_LOCALE) => {
86
118
  (0, exports.normalizeExplainLogicformLocale)(locale);
87
119
  if (!logicform.entity_id) {
88
- return '';
120
+ return buildExplainResult('ID', []);
89
121
  }
90
- return `ID为"${logicform.entity_id}"`;
122
+ return buildExplainResult('ID', [logicform.entity_id]);
91
123
  };
92
124
  exports.explainEntityID = explainEntityID;
93
125
  const explainPreds = (logicform, _schemas, locale = exports.DEFAULT_EXPLAIN_LOGICFORM_LOCALE) => {
94
126
  (0, exports.normalizeExplainLogicformLocale)(locale);
95
127
  if (!logicform.preds || logicform.preds.length === 0) {
96
- return '';
128
+ return buildExplainResult('计算', []);
97
129
  }
98
- return `计算 ${logicform.preds.map((p) => p.name).join('、')}`;
130
+ return buildExplainResult('计算', logicform.preds
131
+ .map((p) => p.name)
132
+ .filter((name) => typeof name === 'string' && name.length > 0));
99
133
  };
100
134
  exports.explainPreds = explainPreds;
101
135
  const explainGroupby = (logicform, _schemas, locale = exports.DEFAULT_EXPLAIN_LOGICFORM_LOCALE) => {
102
136
  (0, exports.normalizeExplainLogicformLocale)(locale);
103
137
  if (!logicform.groupby || logicform.groupby.length === 0) {
104
- return '';
138
+ return buildExplainResult('分组', []);
105
139
  }
106
- return `按 ${logicform.groupby
107
- .map((gi) => (0, exports.explainGroupbyLevel)(gi.level) || gi.name || '')
108
- .join('、')} 分组`;
140
+ return buildExplainResult('分组', logicform.groupby.map((gi) => (0, exports.explainGroupbyLevel)(gi.level) || gi.name || ''));
109
141
  };
110
142
  exports.explainGroupby = explainGroupby;
111
143
  const explainLimit = (logicform, _schemas, locale = exports.DEFAULT_EXPLAIN_LOGICFORM_LOCALE) => {
112
144
  (0, exports.normalizeExplainLogicformLocale)(locale);
113
145
  if (typeof logicform.limit !== 'number') {
114
- return '';
146
+ return buildExplainResult('限制', []);
115
147
  }
116
- return `限制 ${logicform.limit} 条记录`;
148
+ return buildExplainResult('限制', [`${logicform.limit} 条记录`]);
117
149
  };
118
150
  exports.explainLimit = explainLimit;
119
151
  const explainHaving = (logicform, _schemas, locale = exports.DEFAULT_EXPLAIN_LOGICFORM_LOCALE) => {
120
152
  (0, exports.normalizeExplainLogicformLocale)(locale);
121
- return explainFilterLikeQuery(logicform.having, '结果过滤:', '');
153
+ return explainFilterLikeQuery(logicform.having, '结果过滤');
122
154
  };
123
155
  exports.explainHaving = explainHaving;
124
156
  const explainLogicform = (logicform, schemas, locale = exports.DEFAULT_EXPLAIN_LOGICFORM_LOCALE) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "semanticdb-core",
3
- "version": "1.1.39",
3
+ "version": "1.1.40",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "files": [