semanticdb-core 1.1.44 → 1.1.45

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,9 +2,14 @@ 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 ExplainLogicformEntityRef = {
6
+ schema: string;
7
+ id: string;
8
+ };
5
9
  export type ExplainLogicformResultItem = {
6
10
  title: string;
7
11
  values: string[];
12
+ entities?: ExplainLogicformEntityRef[];
8
13
  };
9
14
  export type ExplainFilterLikeResult = ExplainLogicformResultItem;
10
15
  export type ExplainQueryResult = ExplainLogicformResultItem;
@@ -7,6 +7,11 @@ const buildExplainResult = (title, values) => ({
7
7
  title,
8
8
  values,
9
9
  });
10
+ const buildExplainResultWithEntities = (title, values, entities = []) => ({
11
+ title,
12
+ values,
13
+ entities,
14
+ });
10
15
  const normalizeExplainLogicformLocale = (locale) => {
11
16
  if (locale === exports.DEFAULT_EXPLAIN_LOGICFORM_LOCALE) {
12
17
  return locale;
@@ -176,6 +181,35 @@ const getEntityIdFromValue = (value) => {
176
181
  const entityId = value.entity_id;
177
182
  return typeof entityId === 'string' && entityId ? entityId : undefined;
178
183
  };
184
+ const isPlainObject = (value) => {
185
+ return Boolean(value && typeof value === 'object' && !Array.isArray(value));
186
+ };
187
+ const collectQueryEntitiesFromValue = (value, fallbackSchema, entities) => {
188
+ if (!isPlainObject(value)) {
189
+ return;
190
+ }
191
+ const schema = typeof value.schema === 'string' && value.schema ? value.schema : fallbackSchema;
192
+ const entityId = getEntityIdFromValue(value);
193
+ if (schema && entityId) {
194
+ entities.push({ schema, id: entityId });
195
+ }
196
+ for (const nestedValue of Object.values(value)) {
197
+ if (Array.isArray(nestedValue)) {
198
+ for (const item of nestedValue) {
199
+ collectQueryEntitiesFromValue(item, schema, entities);
200
+ }
201
+ continue;
202
+ }
203
+ collectQueryEntitiesFromValue(nestedValue, schema, entities);
204
+ }
205
+ };
206
+ const collectQueryEntities = (logicform, query) => {
207
+ const entities = [];
208
+ if (query) {
209
+ collectQueryEntitiesFromValue(query, logicform.schema, entities);
210
+ }
211
+ return entities.filter((entity, index, allEntities) => allEntities.findIndex((item) => item.schema === entity.schema && item.id === entity.id) === index);
212
+ };
179
213
  const explainFilterLikeQuery = (query, prefix = '筛选', includeValue = false, schemas = {}) => {
180
214
  if (!query || Object.keys(query).length === 0) {
181
215
  return buildExplainResult(prefix, []);
@@ -242,7 +276,9 @@ const explainSchema = (logicform, schemas, locale = exports.DEFAULT_EXPLAIN_LOGI
242
276
  exports.explainSchema = explainSchema;
243
277
  const explainQuery = (logicform, _schemas, locale = exports.DEFAULT_EXPLAIN_LOGICFORM_LOCALE) => {
244
278
  (0, exports.normalizeExplainLogicformLocale)(locale);
245
- return explainFilterLikeQuery(logicform.query ? (0, logicform_utils_1.getFlattenQuery)(logicform.query, _schemas) : undefined, '筛选', true, _schemas);
279
+ const query = logicform.query ? (0, logicform_utils_1.getFlattenQuery)(logicform.query, _schemas) : undefined;
280
+ const entities = collectQueryEntities(logicform, logicform.query);
281
+ return buildExplainResultWithEntities('筛选', explainFilterLikeQuery(query, '筛选', true, _schemas).values, entities);
246
282
  };
247
283
  exports.explainQuery = explainQuery;
248
284
  const explainEntityID = (logicform, _schemas, locale = exports.DEFAULT_EXPLAIN_LOGICFORM_LOCALE) => {
@@ -2,6 +2,11 @@ import { RepresentationType } from '../common/representation';
2
2
  import { PropertyType } from '../schema/property';
3
3
  import { SchemaType } from '../schema/schema';
4
4
  import { QueryType } from './types/query';
5
+ export type LogicformOutputTypeValue = 'url' | 'data' | 'export' | 'sql' | 'sqlComponents';
6
+ export interface LogicformOutputType {
7
+ type: LogicformOutputTypeValue;
8
+ filename?: string;
9
+ }
5
10
  export interface PredItemType {
6
11
  operator?: string;
7
12
  pred?: string | PredItemType;
@@ -35,6 +40,7 @@ export interface LogicformType {
35
40
  [key: string]: 1 | -1;
36
41
  };
37
42
  having?: QueryType;
43
+ output?: LogicformOutputType;
38
44
  limit?: number;
39
45
  limitBy?: number;
40
46
  skip?: number;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "semanticdb-core",
3
- "version": "1.1.44",
3
+ "version": "1.1.45",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "files": [