bunsane 0.5.5 → 0.5.6
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.
package/endpoints/archetypes.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { getSerializedMetadataStorage } from "../core/metadata";
|
|
2
|
-
import { findIndicatorComponentName } from "../
|
|
2
|
+
import { findIndicatorComponentName } from "../utils/archetypeIndicator";
|
|
3
3
|
import db from "../database";
|
|
4
4
|
import type {
|
|
5
5
|
StudioArcheTypeQueryParams,
|
package/package.json
CHANGED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Finds the indicator component name from an archetype's field list.
|
|
3
|
+
* The indicator is used to identify entities of this archetype type.
|
|
4
|
+
*
|
|
5
|
+
* Priority order:
|
|
6
|
+
* 1. {ArcheTypeName}Tag (e.g., UserTag)
|
|
7
|
+
* 2. {ArcheTypeName}Id (e.g., UserId)
|
|
8
|
+
* 3. Any field starting with {ArcheTypeName}
|
|
9
|
+
* 4. Any field containing {ArcheTypeName}
|
|
10
|
+
* 5. Fallback to first component
|
|
11
|
+
*/
|
|
12
|
+
export function findIndicatorComponentName(
|
|
13
|
+
archeTypeName: string,
|
|
14
|
+
fields: Array<{ componentName: string; fieldName: string }>
|
|
15
|
+
): string | null {
|
|
16
|
+
if (fields.length === 0) {
|
|
17
|
+
return null;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
const archeTypeNameLower = archeTypeName.toLowerCase();
|
|
21
|
+
const componentNames = fields.map(field => field.componentName);
|
|
22
|
+
|
|
23
|
+
const tagComponentName = `${archeTypeName}Tag`;
|
|
24
|
+
const tagMatch = componentNames.find(
|
|
25
|
+
name => name.toLowerCase() === tagComponentName.toLowerCase()
|
|
26
|
+
);
|
|
27
|
+
if (tagMatch) {
|
|
28
|
+
return tagMatch;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
const idComponentName = `${archeTypeName}Id`;
|
|
32
|
+
const idMatch = componentNames.find(
|
|
33
|
+
name => name.toLowerCase() === idComponentName.toLowerCase()
|
|
34
|
+
);
|
|
35
|
+
if (idMatch) {
|
|
36
|
+
return idMatch;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
const startsWithMatch = componentNames.find(
|
|
40
|
+
name => name.toLowerCase().startsWith(archeTypeNameLower)
|
|
41
|
+
);
|
|
42
|
+
if (startsWithMatch) {
|
|
43
|
+
return startsWithMatch;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
const containsMatch = componentNames.find(
|
|
47
|
+
name => name.toLowerCase().includes(archeTypeNameLower)
|
|
48
|
+
);
|
|
49
|
+
if (containsMatch) {
|
|
50
|
+
return containsMatch;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
return componentNames[0] ?? null;
|
|
54
|
+
}
|