semanticdb-core 1.1.7 → 1.1.9

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.
@@ -3,9 +3,9 @@ import { PropertyType } from '../schema/property';
3
3
  import { SchemaType } from '../schema/schema';
4
4
  export interface LogicformResultType {
5
5
  error?: string;
6
- result: Record<string, any>[];
7
- logicform: LogicformType;
8
- schemas: Record<string, SchemaType>;
9
- columnProperties: PropertyType[];
6
+ result?: Record<string, any>[];
7
+ logicform?: LogicformType;
8
+ schemas?: Record<string, SchemaType>;
9
+ columnProperties?: PropertyType[];
10
10
  }
11
11
  export declare const logicformResultToMarkdown: (ret: LogicformResultType, number_only?: boolean) => string;
@@ -8,6 +8,8 @@ const json2md_1 = __importDefault(require("json2md"));
8
8
  const property_utils_1 = require("../schema/property.utils");
9
9
  const logicformResultToMarkdown = (ret, number_only) => {
10
10
  const { schemas, result, logicform, columnProperties } = ret;
11
+ if (!result || !logicform || !columnProperties || !schemas)
12
+ return '没有数据';
11
13
  if (result.length === 0)
12
14
  return '没有数据';
13
15
  let markdownText = '';
@@ -10,7 +10,7 @@ export interface SchemaValidationResult {
10
10
  * @param schema - 要检查的 schema
11
11
  * @returns 验证结果,包含 valid 和 message
12
12
  */
13
- export declare function isSchemaValid(schema: Partial<SchemaType>): SchemaValidationResult;
13
+ export declare function isSchemaValid(schema: Partial<SchemaType>, schemasDict: Record<string, SchemaType>): SchemaValidationResult;
14
14
  export declare const findPropertyByType: (type: string, schema: SchemaType) => PropertyType | undefined;
15
15
  /**
16
16
  * Find a property by name within a specific schema
@@ -7,7 +7,7 @@ exports.isSchemaValid = isSchemaValid;
7
7
  * @param schema - 要检查的 schema
8
8
  * @returns 验证结果,包含 valid 和 message
9
9
  */
10
- function isSchemaValid(schema) {
10
+ function isSchemaValid(schema, schemasDict) {
11
11
  if (!schema.name) {
12
12
  return { valid: false, message: '缺少名称' };
13
13
  }
@@ -20,23 +20,26 @@ function isSchemaValid(schema) {
20
20
  if (!schema.properties || schema.properties.length === 0) {
21
21
  return { valid: false, message: '缺少属性定义' };
22
22
  }
23
- const validProperties = schema.properties.filter((property) => property.name && property.type);
24
- if (validProperties.length === 0) {
25
- return { valid: false, message: '没有有效的属性' };
23
+ if (!schema.properties.every((property) => property.name && property.type)) {
24
+ return { valid: false, message: '每一个属性都必须有名称和类型' };
26
25
  }
27
26
  // entity和event各自必须的字段
28
27
  if (schema.type === 'entity') {
29
- const IDProp = validProperties.find((property) => property.type === 'ID');
28
+ const IDProp = schema.properties.find((property) => property.type === 'ID');
30
29
  if (!IDProp) {
31
- return { valid: false, message: 'entity类型必须有一个type为ID的属性' };
30
+ return { valid: false, message: '实体必须有一个语义类型为 ID 的属性' };
32
31
  }
33
32
  }
34
33
  else if (schema.type === 'event') {
35
- const timestampProps = validProperties.filter((property) => property.type === 'timestamp');
34
+ const timestampProps = schema.properties.filter((property) => property.type === 'timestamp');
36
35
  if (timestampProps.length === 0) {
37
- return { valid: false, message: 'event类型必须有一个type为timestamp的属性' };
36
+ return { valid: false, message: '事件必须有一个语义类型为 时间戳 的属性' };
38
37
  }
39
38
  }
39
+ const noRefProperty = schema.properties.find((property) => property.ref && !(property.ref in schemasDict));
40
+ if (noRefProperty) {
41
+ return { valid: false, message: `属性 ${noRefProperty.name} 引用的实体表 ${noRefProperty.ref} 不存在` };
42
+ }
40
43
  return { valid: true, message: '' };
41
44
  }
42
45
  const findPropertyByType = (type, schema) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "semanticdb-core",
3
- "version": "1.1.7",
3
+ "version": "1.1.9",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "files": [