semanticdb-core 1.1.6 → 1.1.8
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.
|
@@ -1,6 +1,16 @@
|
|
|
1
1
|
import { PropertyType } from './property';
|
|
2
2
|
import { SchemaType } from './schema';
|
|
3
3
|
import { LogicformType } from '../logicform/logicform';
|
|
4
|
+
export interface SchemaValidationResult {
|
|
5
|
+
valid: boolean;
|
|
6
|
+
message: string;
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* 检查 schema 是否有效
|
|
10
|
+
* @param schema - 要检查的 schema
|
|
11
|
+
* @returns 验证结果,包含 valid 和 message
|
|
12
|
+
*/
|
|
13
|
+
export declare function isSchemaValid(schema: Partial<SchemaType>, schemasDict: Record<string, SchemaType>): SchemaValidationResult;
|
|
4
14
|
export declare const findPropertyByType: (type: string, schema: SchemaType) => PropertyType | undefined;
|
|
5
15
|
/**
|
|
6
16
|
* Find a property by name within a specific schema
|
|
@@ -1,6 +1,47 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.getRefChain = exports.getHierarchyCodeLength = exports.findPropertyForOtherSchema = exports.findTimestampLikeProperty = exports.findDisplayNameProperty = exports.findPropertyByName = exports.findPropertyByType = void 0;
|
|
4
|
+
exports.isSchemaValid = isSchemaValid;
|
|
5
|
+
/**
|
|
6
|
+
* 检查 schema 是否有效
|
|
7
|
+
* @param schema - 要检查的 schema
|
|
8
|
+
* @returns 验证结果,包含 valid 和 message
|
|
9
|
+
*/
|
|
10
|
+
function isSchemaValid(schema, schemasDict) {
|
|
11
|
+
if (!schema.name) {
|
|
12
|
+
return { valid: false, message: '缺少名称' };
|
|
13
|
+
}
|
|
14
|
+
if (!schema.type) {
|
|
15
|
+
return { valid: false, message: '缺少类型' };
|
|
16
|
+
}
|
|
17
|
+
if (!schema.db) {
|
|
18
|
+
return { valid: false, message: '缺少数据库配置' };
|
|
19
|
+
}
|
|
20
|
+
if (!schema.properties || schema.properties.length === 0) {
|
|
21
|
+
return { valid: false, message: '缺少属性定义' };
|
|
22
|
+
}
|
|
23
|
+
if (!schema.properties.every((property) => property.name && property.type)) {
|
|
24
|
+
return { valid: false, message: '每一个属性都必须有名称和类型' };
|
|
25
|
+
}
|
|
26
|
+
// entity和event各自必须的字段
|
|
27
|
+
if (schema.type === 'entity') {
|
|
28
|
+
const IDProp = schema.properties.find((property) => property.type === 'ID');
|
|
29
|
+
if (!IDProp) {
|
|
30
|
+
return { valid: false, message: 'entity类型必须有一个type为ID的属性' };
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
else if (schema.type === 'event') {
|
|
34
|
+
const timestampProps = schema.properties.filter((property) => property.type === 'timestamp');
|
|
35
|
+
if (timestampProps.length === 0) {
|
|
36
|
+
return { valid: false, message: 'event类型必须有一个type为timestamp的属性' };
|
|
37
|
+
}
|
|
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
|
+
}
|
|
43
|
+
return { valid: true, message: '' };
|
|
44
|
+
}
|
|
4
45
|
const findPropertyByType = (type, schema) => {
|
|
5
46
|
return schema.properties.find((property) => property.type === type);
|
|
6
47
|
};
|