semanticdb-core 1.1.44 → 1.1.46

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,8 @@ const buildExplainResult = (title, values) => ({
7
7
  title,
8
8
  values,
9
9
  });
10
+ const buildExplainResultWithEntities = (title, values, entities = []) => (Object.assign({ title,
11
+ values }, (entities.length > 0 ? { entities } : {})));
10
12
  const normalizeExplainLogicformLocale = (locale) => {
11
13
  if (locale === exports.DEFAULT_EXPLAIN_LOGICFORM_LOCALE) {
12
14
  return locale;
@@ -176,6 +178,35 @@ const getEntityIdFromValue = (value) => {
176
178
  const entityId = value.entity_id;
177
179
  return typeof entityId === 'string' && entityId ? entityId : undefined;
178
180
  };
181
+ const isPlainObject = (value) => {
182
+ return Boolean(value && typeof value === 'object' && !Array.isArray(value));
183
+ };
184
+ const collectQueryEntitiesFromValue = (value, fallbackSchema, entities) => {
185
+ if (!isPlainObject(value)) {
186
+ return;
187
+ }
188
+ const schema = typeof value.schema === 'string' && value.schema ? value.schema : fallbackSchema;
189
+ const entityId = getEntityIdFromValue(value);
190
+ if (schema && entityId) {
191
+ entities.push({ schema, id: entityId });
192
+ }
193
+ for (const nestedValue of Object.values(value)) {
194
+ if (Array.isArray(nestedValue)) {
195
+ for (const item of nestedValue) {
196
+ collectQueryEntitiesFromValue(item, schema, entities);
197
+ }
198
+ continue;
199
+ }
200
+ collectQueryEntitiesFromValue(nestedValue, schema, entities);
201
+ }
202
+ };
203
+ const collectQueryEntities = (logicform, query) => {
204
+ const entities = [];
205
+ if (query) {
206
+ collectQueryEntitiesFromValue(query, logicform.schema, entities);
207
+ }
208
+ return entities.filter((entity, index, allEntities) => allEntities.findIndex((item) => item.schema === entity.schema && item.id === entity.id) === index);
209
+ };
179
210
  const explainFilterLikeQuery = (query, prefix = '筛选', includeValue = false, schemas = {}) => {
180
211
  if (!query || Object.keys(query).length === 0) {
181
212
  return buildExplainResult(prefix, []);
@@ -242,7 +273,9 @@ const explainSchema = (logicform, schemas, locale = exports.DEFAULT_EXPLAIN_LOGI
242
273
  exports.explainSchema = explainSchema;
243
274
  const explainQuery = (logicform, _schemas, locale = exports.DEFAULT_EXPLAIN_LOGICFORM_LOCALE) => {
244
275
  (0, exports.normalizeExplainLogicformLocale)(locale);
245
- return explainFilterLikeQuery(logicform.query ? (0, logicform_utils_1.getFlattenQuery)(logicform.query, _schemas) : undefined, '筛选', true, _schemas);
276
+ const query = logicform.query ? (0, logicform_utils_1.getFlattenQuery)(logicform.query, _schemas) : undefined;
277
+ const entities = collectQueryEntities(logicform, logicform.query);
278
+ return buildExplainResultWithEntities('筛选', explainFilterLikeQuery(query, '筛选', true, _schemas).values, entities);
246
279
  };
247
280
  exports.explainQuery = explainQuery;
248
281
  const explainEntityID = (logicform, _schemas, locale = exports.DEFAULT_EXPLAIN_LOGICFORM_LOCALE) => {
@@ -250,7 +283,9 @@ const explainEntityID = (logicform, _schemas, locale = exports.DEFAULT_EXPLAIN_L
250
283
  if (!logicform.entity_id) {
251
284
  return buildExplainResult('ID', []);
252
285
  }
253
- return buildExplainResult('ID', [logicform.entity_id]);
286
+ return buildExplainResultWithEntities('ID', [logicform.entity_id], [
287
+ { schema: logicform.schema, id: logicform.entity_id },
288
+ ]);
254
289
  };
255
290
  exports.explainEntityID = explainEntityID;
256
291
  const explainPreds = (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.46",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "files": [