@hla4ts/fom-codegen 0.1.0 → 0.1.1
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/package.json +1 -1
- package/src/cli.ts +179 -179
- package/src/generated/index.ts +25 -25
- package/src/generated/xsd-types.ts +63 -63
- package/src/xsd-parser.ts +404 -404
- package/src/xsd-type-generator.ts +452 -452
- package/src/xsd-types-adapter.ts +177 -177
package/src/xsd-types-adapter.ts
CHANGED
|
@@ -1,177 +1,177 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* XSD Types Adapter
|
|
3
|
-
*
|
|
4
|
-
* Provides adapters to convert between XSD-generated types and FomRegistry schema types.
|
|
5
|
-
* This allows using XSD-generated types for autocomplete while maintaining compatibility
|
|
6
|
-
* with the existing FomRegistry API.
|
|
7
|
-
*/
|
|
8
|
-
|
|
9
|
-
import type {
|
|
10
|
-
ModelIdentification as XsdModelIdentification,
|
|
11
|
-
ObjectClass as XsdObjectClass,
|
|
12
|
-
InteractionClass as XsdInteractionClass,
|
|
13
|
-
Attribute as XsdAttribute,
|
|
14
|
-
Parameter as XsdParameter,
|
|
15
|
-
SharingEnumeration,
|
|
16
|
-
OrderEnumeration,
|
|
17
|
-
UpdateEnumeration,
|
|
18
|
-
OwnershipEnumeration,
|
|
19
|
-
} from "./generated/xsd-types.ts";
|
|
20
|
-
|
|
21
|
-
import type {
|
|
22
|
-
ModelIdentification,
|
|
23
|
-
ObjectClassSchema,
|
|
24
|
-
InteractionClassSchema,
|
|
25
|
-
AttributeSchema,
|
|
26
|
-
ParameterSchema,
|
|
27
|
-
} from "./types.ts";
|
|
28
|
-
|
|
29
|
-
/**
|
|
30
|
-
* Convert XSD ModelIdentification to FomRegistry ModelIdentification.
|
|
31
|
-
* This provides autocomplete based on XSD schema.
|
|
32
|
-
*/
|
|
33
|
-
export function adaptModelIdentification(
|
|
34
|
-
xsd: XsdModelIdentification
|
|
35
|
-
): ModelIdentification {
|
|
36
|
-
return {
|
|
37
|
-
name: xsd.name ?? "",
|
|
38
|
-
type: (xsd.type ?? "FOM") as "FOM" | "SOM",
|
|
39
|
-
version: xsd.version ?? "",
|
|
40
|
-
modificationDate: xsd.modificationDate ?? "",
|
|
41
|
-
securityClassification: xsd.securityClassification ?? "",
|
|
42
|
-
description: xsd.description ?? "",
|
|
43
|
-
purpose: xsd.purpose,
|
|
44
|
-
applicationDomain: xsd.applicationDomain,
|
|
45
|
-
useLimitation: xsd.useLimitation,
|
|
46
|
-
keyword: xsd.keyword?.map((kw) => ({
|
|
47
|
-
taxonomy: kw.taxonomy,
|
|
48
|
-
keywordValue: kw.keywordValue ?? "",
|
|
49
|
-
})),
|
|
50
|
-
};
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
/**
|
|
54
|
-
* Convert XSD ObjectClass to FomRegistry ObjectClassSchema.
|
|
55
|
-
* Provides autocomplete based on XSD schema.
|
|
56
|
-
*/
|
|
57
|
-
export function adaptObjectClass(xsd: XsdObjectClass): ObjectClassSchema {
|
|
58
|
-
// XSD uses 'attribute' (singular) for the array property
|
|
59
|
-
const attributes = (xsd as any).attribute || (xsd as any).attributes;
|
|
60
|
-
return {
|
|
61
|
-
name: xsd.name,
|
|
62
|
-
parent: (xsd as any).parent,
|
|
63
|
-
sharing: adaptSharingType(xsd.sharing),
|
|
64
|
-
semantics: (xsd as any).semantics,
|
|
65
|
-
attributes: attributes?.map(adaptAttribute),
|
|
66
|
-
};
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
/**
|
|
70
|
-
* Convert XSD InteractionClass to FomRegistry InteractionClassSchema.
|
|
71
|
-
* Provides autocomplete based on XSD schema.
|
|
72
|
-
*/
|
|
73
|
-
export function adaptInteractionClass(
|
|
74
|
-
xsd: XsdInteractionClass
|
|
75
|
-
): InteractionClassSchema {
|
|
76
|
-
// XSD uses 'parameter' (singular) for the array property
|
|
77
|
-
const parameters = (xsd as any).parameter || (xsd as any).parameters;
|
|
78
|
-
return {
|
|
79
|
-
name: xsd.name,
|
|
80
|
-
parent: (xsd as any).parent,
|
|
81
|
-
sharing: adaptSharingType(xsd.sharing),
|
|
82
|
-
transportation: (xsd as any).transportation,
|
|
83
|
-
order: adaptOrderType(xsd.order),
|
|
84
|
-
semantics: (xsd as any).semantics,
|
|
85
|
-
parameters: parameters?.map(adaptParameter),
|
|
86
|
-
};
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
/**
|
|
90
|
-
* Convert XSD Attribute to FomRegistry AttributeSchema.
|
|
91
|
-
*/
|
|
92
|
-
function adaptAttribute(xsd: XsdAttribute): AttributeSchema {
|
|
93
|
-
return {
|
|
94
|
-
name: xsd.name,
|
|
95
|
-
dataType: xsd.dataType ?? "",
|
|
96
|
-
updateType: adaptUpdateType(xsd.updateType) ?? "NA",
|
|
97
|
-
updateCondition: xsd.updateCondition ?? "",
|
|
98
|
-
ownership: adaptOwnershipType(xsd.ownership) ?? "NoTransfer",
|
|
99
|
-
sharing: adaptSharingType(xsd.sharing) ?? "Neither",
|
|
100
|
-
transportation: xsd.transportation ?? "",
|
|
101
|
-
order: adaptOrderType(xsd.order) ?? "Receive",
|
|
102
|
-
semantics: xsd.semantics,
|
|
103
|
-
valueRequired: xsd.valueRequired === "true",
|
|
104
|
-
};
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
/**
|
|
108
|
-
* Convert XSD Parameter to FomRegistry ParameterSchema.
|
|
109
|
-
*/
|
|
110
|
-
function adaptParameter(xsd: XsdParameter): ParameterSchema {
|
|
111
|
-
return {
|
|
112
|
-
name: xsd.name,
|
|
113
|
-
dataType: xsd.dataType ?? "",
|
|
114
|
-
semantics: xsd.semantics,
|
|
115
|
-
};
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
/**
|
|
119
|
-
* Convert XSD SharingEnumeration to FomRegistry SharingType.
|
|
120
|
-
*/
|
|
121
|
-
function adaptSharingType(
|
|
122
|
-
sharing?: SharingEnumeration
|
|
123
|
-
): "Publish" | "Subscribe" | "PublishSubscribe" | "Neither" | undefined {
|
|
124
|
-
if (!sharing) return undefined;
|
|
125
|
-
return sharing as "Publish" | "Subscribe" | "PublishSubscribe" | "Neither";
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
/**
|
|
129
|
-
* Convert XSD OrderEnumeration to FomRegistry OrderType.
|
|
130
|
-
*/
|
|
131
|
-
function adaptOrderType(
|
|
132
|
-
order?: OrderEnumeration
|
|
133
|
-
): "Receive" | "TimeStamp" | undefined {
|
|
134
|
-
if (!order) return undefined;
|
|
135
|
-
return order as "Receive" | "TimeStamp";
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
/**
|
|
139
|
-
* Convert XSD UpdateEnumeration to FomRegistry UpdateType.
|
|
140
|
-
*/
|
|
141
|
-
function adaptUpdateType(
|
|
142
|
-
update?: UpdateEnumeration
|
|
143
|
-
): "Static" | "Periodic" | "Conditional" | "NA" {
|
|
144
|
-
if (!update) return "NA";
|
|
145
|
-
return update as "Static" | "Periodic" | "Conditional" | "NA";
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
/**
|
|
149
|
-
* Convert XSD OwnershipEnumeration to FomRegistry OwnershipType.
|
|
150
|
-
*/
|
|
151
|
-
function adaptOwnershipType(
|
|
152
|
-
ownership?: OwnershipEnumeration
|
|
153
|
-
): "Divest" | "Acquire" | "DivestAcquire" | "NoTransfer" {
|
|
154
|
-
if (!ownership) return "NoTransfer";
|
|
155
|
-
return ownership as "Divest" | "Acquire" | "DivestAcquire" | "NoTransfer";
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
/**
|
|
159
|
-
* Helper type that provides autocomplete for ModelIdentification using XSD types.
|
|
160
|
-
* Use this when you want XSD-based autocomplete:
|
|
161
|
-
*
|
|
162
|
-
* @example
|
|
163
|
-
* ```ts
|
|
164
|
-
* import { FomRegistry } from "@hla4ts/fom-codegen";
|
|
165
|
-
* import type { ModelIdentification } from "@hla4ts/fom-codegen/generated";
|
|
166
|
-
*
|
|
167
|
-
* const registry = new FomRegistry();
|
|
168
|
-
* const modelId: ModelIdentification = {
|
|
169
|
-
* name: "MyFOM",
|
|
170
|
-
* type: "FOM", // Autocomplete shows "FOM" | "SOM"
|
|
171
|
-
* version: "1.0",
|
|
172
|
-
* // ... other fields with autocomplete
|
|
173
|
-
* };
|
|
174
|
-
* registry.setModelIdentification(adaptModelIdentification(modelId));
|
|
175
|
-
* ```
|
|
176
|
-
*/
|
|
177
|
-
export type { XsdModelIdentification, XsdObjectClass, XsdInteractionClass };
|
|
1
|
+
/**
|
|
2
|
+
* XSD Types Adapter
|
|
3
|
+
*
|
|
4
|
+
* Provides adapters to convert between XSD-generated types and FomRegistry schema types.
|
|
5
|
+
* This allows using XSD-generated types for autocomplete while maintaining compatibility
|
|
6
|
+
* with the existing FomRegistry API.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
import type {
|
|
10
|
+
ModelIdentification as XsdModelIdentification,
|
|
11
|
+
ObjectClass as XsdObjectClass,
|
|
12
|
+
InteractionClass as XsdInteractionClass,
|
|
13
|
+
Attribute as XsdAttribute,
|
|
14
|
+
Parameter as XsdParameter,
|
|
15
|
+
SharingEnumeration,
|
|
16
|
+
OrderEnumeration,
|
|
17
|
+
UpdateEnumeration,
|
|
18
|
+
OwnershipEnumeration,
|
|
19
|
+
} from "./generated/xsd-types.ts";
|
|
20
|
+
|
|
21
|
+
import type {
|
|
22
|
+
ModelIdentification,
|
|
23
|
+
ObjectClassSchema,
|
|
24
|
+
InteractionClassSchema,
|
|
25
|
+
AttributeSchema,
|
|
26
|
+
ParameterSchema,
|
|
27
|
+
} from "./types.ts";
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Convert XSD ModelIdentification to FomRegistry ModelIdentification.
|
|
31
|
+
* This provides autocomplete based on XSD schema.
|
|
32
|
+
*/
|
|
33
|
+
export function adaptModelIdentification(
|
|
34
|
+
xsd: XsdModelIdentification
|
|
35
|
+
): ModelIdentification {
|
|
36
|
+
return {
|
|
37
|
+
name: xsd.name ?? "",
|
|
38
|
+
type: (xsd.type ?? "FOM") as "FOM" | "SOM",
|
|
39
|
+
version: xsd.version ?? "",
|
|
40
|
+
modificationDate: xsd.modificationDate ?? "",
|
|
41
|
+
securityClassification: xsd.securityClassification ?? "",
|
|
42
|
+
description: xsd.description ?? "",
|
|
43
|
+
purpose: xsd.purpose,
|
|
44
|
+
applicationDomain: xsd.applicationDomain,
|
|
45
|
+
useLimitation: xsd.useLimitation,
|
|
46
|
+
keyword: xsd.keyword?.map((kw) => ({
|
|
47
|
+
taxonomy: kw.taxonomy,
|
|
48
|
+
keywordValue: kw.keywordValue ?? "",
|
|
49
|
+
})),
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* Convert XSD ObjectClass to FomRegistry ObjectClassSchema.
|
|
55
|
+
* Provides autocomplete based on XSD schema.
|
|
56
|
+
*/
|
|
57
|
+
export function adaptObjectClass(xsd: XsdObjectClass): ObjectClassSchema {
|
|
58
|
+
// XSD uses 'attribute' (singular) for the array property
|
|
59
|
+
const attributes = (xsd as any).attribute || (xsd as any).attributes;
|
|
60
|
+
return {
|
|
61
|
+
name: xsd.name,
|
|
62
|
+
parent: (xsd as any).parent,
|
|
63
|
+
sharing: adaptSharingType(xsd.sharing),
|
|
64
|
+
semantics: (xsd as any).semantics,
|
|
65
|
+
attributes: attributes?.map(adaptAttribute),
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* Convert XSD InteractionClass to FomRegistry InteractionClassSchema.
|
|
71
|
+
* Provides autocomplete based on XSD schema.
|
|
72
|
+
*/
|
|
73
|
+
export function adaptInteractionClass(
|
|
74
|
+
xsd: XsdInteractionClass
|
|
75
|
+
): InteractionClassSchema {
|
|
76
|
+
// XSD uses 'parameter' (singular) for the array property
|
|
77
|
+
const parameters = (xsd as any).parameter || (xsd as any).parameters;
|
|
78
|
+
return {
|
|
79
|
+
name: xsd.name,
|
|
80
|
+
parent: (xsd as any).parent,
|
|
81
|
+
sharing: adaptSharingType(xsd.sharing),
|
|
82
|
+
transportation: (xsd as any).transportation,
|
|
83
|
+
order: adaptOrderType(xsd.order),
|
|
84
|
+
semantics: (xsd as any).semantics,
|
|
85
|
+
parameters: parameters?.map(adaptParameter),
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* Convert XSD Attribute to FomRegistry AttributeSchema.
|
|
91
|
+
*/
|
|
92
|
+
function adaptAttribute(xsd: XsdAttribute): AttributeSchema {
|
|
93
|
+
return {
|
|
94
|
+
name: xsd.name,
|
|
95
|
+
dataType: xsd.dataType ?? "",
|
|
96
|
+
updateType: adaptUpdateType(xsd.updateType) ?? "NA",
|
|
97
|
+
updateCondition: xsd.updateCondition ?? "",
|
|
98
|
+
ownership: adaptOwnershipType(xsd.ownership) ?? "NoTransfer",
|
|
99
|
+
sharing: adaptSharingType(xsd.sharing) ?? "Neither",
|
|
100
|
+
transportation: xsd.transportation ?? "",
|
|
101
|
+
order: adaptOrderType(xsd.order) ?? "Receive",
|
|
102
|
+
semantics: xsd.semantics,
|
|
103
|
+
valueRequired: xsd.valueRequired === "true",
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* Convert XSD Parameter to FomRegistry ParameterSchema.
|
|
109
|
+
*/
|
|
110
|
+
function adaptParameter(xsd: XsdParameter): ParameterSchema {
|
|
111
|
+
return {
|
|
112
|
+
name: xsd.name,
|
|
113
|
+
dataType: xsd.dataType ?? "",
|
|
114
|
+
semantics: xsd.semantics,
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
/**
|
|
119
|
+
* Convert XSD SharingEnumeration to FomRegistry SharingType.
|
|
120
|
+
*/
|
|
121
|
+
function adaptSharingType(
|
|
122
|
+
sharing?: SharingEnumeration
|
|
123
|
+
): "Publish" | "Subscribe" | "PublishSubscribe" | "Neither" | undefined {
|
|
124
|
+
if (!sharing) return undefined;
|
|
125
|
+
return sharing as "Publish" | "Subscribe" | "PublishSubscribe" | "Neither";
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
/**
|
|
129
|
+
* Convert XSD OrderEnumeration to FomRegistry OrderType.
|
|
130
|
+
*/
|
|
131
|
+
function adaptOrderType(
|
|
132
|
+
order?: OrderEnumeration
|
|
133
|
+
): "Receive" | "TimeStamp" | undefined {
|
|
134
|
+
if (!order) return undefined;
|
|
135
|
+
return order as "Receive" | "TimeStamp";
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
/**
|
|
139
|
+
* Convert XSD UpdateEnumeration to FomRegistry UpdateType.
|
|
140
|
+
*/
|
|
141
|
+
function adaptUpdateType(
|
|
142
|
+
update?: UpdateEnumeration
|
|
143
|
+
): "Static" | "Periodic" | "Conditional" | "NA" {
|
|
144
|
+
if (!update) return "NA";
|
|
145
|
+
return update as "Static" | "Periodic" | "Conditional" | "NA";
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
/**
|
|
149
|
+
* Convert XSD OwnershipEnumeration to FomRegistry OwnershipType.
|
|
150
|
+
*/
|
|
151
|
+
function adaptOwnershipType(
|
|
152
|
+
ownership?: OwnershipEnumeration
|
|
153
|
+
): "Divest" | "Acquire" | "DivestAcquire" | "NoTransfer" {
|
|
154
|
+
if (!ownership) return "NoTransfer";
|
|
155
|
+
return ownership as "Divest" | "Acquire" | "DivestAcquire" | "NoTransfer";
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
/**
|
|
159
|
+
* Helper type that provides autocomplete for ModelIdentification using XSD types.
|
|
160
|
+
* Use this when you want XSD-based autocomplete:
|
|
161
|
+
*
|
|
162
|
+
* @example
|
|
163
|
+
* ```ts
|
|
164
|
+
* import { FomRegistry } from "@hla4ts/fom-codegen";
|
|
165
|
+
* import type { ModelIdentification } from "@hla4ts/fom-codegen/generated";
|
|
166
|
+
*
|
|
167
|
+
* const registry = new FomRegistry();
|
|
168
|
+
* const modelId: ModelIdentification = {
|
|
169
|
+
* name: "MyFOM",
|
|
170
|
+
* type: "FOM", // Autocomplete shows "FOM" | "SOM"
|
|
171
|
+
* version: "1.0",
|
|
172
|
+
* // ... other fields with autocomplete
|
|
173
|
+
* };
|
|
174
|
+
* registry.setModelIdentification(adaptModelIdentification(modelId));
|
|
175
|
+
* ```
|
|
176
|
+
*/
|
|
177
|
+
export type { XsdModelIdentification, XsdObjectClass, XsdInteractionClass };
|