semanticdb-core 1.0.12 → 1.0.13
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,5 +1,6 @@
|
|
|
1
1
|
import { PropertyType } from './property';
|
|
2
2
|
import { SchemaType } from './schema';
|
|
3
|
+
export declare const findPropertyByType: (type: string, schema: SchemaType) => PropertyType | undefined;
|
|
3
4
|
/**
|
|
4
5
|
* Find a property by name within a specific schema
|
|
5
6
|
* @param schemaID - The unique identifier of the schema to search in
|
|
@@ -20,4 +21,4 @@ export declare const findDisplayNameProperty: (schema: SchemaType) => PropertyTy
|
|
|
20
21
|
* @param fromSchema
|
|
21
22
|
* @param toSchema
|
|
22
23
|
*/
|
|
23
|
-
export declare const findPropertyForOtherSchema: (propertyName: string, fromSchemaID: string, toSchemaID: string, schemasDict: Record<string, SchemaType>) => PropertyType |
|
|
24
|
+
export declare const findPropertyForOtherSchema: (propertyName: string, fromSchemaID: string, toSchemaID: string, schemasDict: Record<string, SchemaType>) => PropertyType | undefined;
|
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.findPropertyForOtherSchema = exports.findDisplayNameProperty = exports.findPropertyByName = void 0;
|
|
3
|
+
exports.findPropertyForOtherSchema = exports.findDisplayNameProperty = exports.findPropertyByName = exports.findPropertyByType = void 0;
|
|
4
|
+
const findPropertyByType = (type, schema) => {
|
|
5
|
+
return schema.properties.find((property) => property.type === type);
|
|
6
|
+
};
|
|
7
|
+
exports.findPropertyByType = findPropertyByType;
|
|
4
8
|
/**
|
|
5
9
|
* Find a property by name within a specific schema
|
|
6
10
|
* @param schemaID - The unique identifier of the schema to search in
|
|
@@ -82,8 +86,15 @@ const findPropertyForOtherSchema = (propertyName, fromSchemaID, toSchemaID, sche
|
|
|
82
86
|
throw new Error(`[schema.utils.findPropertyForOtherSchema]Property with name ${propertyName} not found in ${fromSchemaID}`);
|
|
83
87
|
// 只有object类型才能跨schema找到
|
|
84
88
|
if (property.ref) {
|
|
85
|
-
|
|
89
|
+
if (property.ref === toSchemaID) {
|
|
90
|
+
// 如果本身就是自己
|
|
91
|
+
const idProperty = (0, exports.findPropertyByType)('ID', schemasDict[property.ref]);
|
|
92
|
+
if (idProperty) {
|
|
93
|
+
return idProperty;
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
return (_b = (_a = schemasDict[toSchemaID]) === null || _a === void 0 ? void 0 : _a.properties) === null || _b === void 0 ? void 0 : _b.find((p) => p.ref === property.ref); // 这里要加?.,因为property.ref可能为undefined,会导致properties为undefined,从而导致find函数报错
|
|
86
97
|
}
|
|
87
|
-
return
|
|
98
|
+
return undefined;
|
|
88
99
|
};
|
|
89
100
|
exports.findPropertyForOtherSchema = findPropertyForOtherSchema;
|