File tree 2 files changed +10
-1
lines changed
@xen-orchestra/xapi-generator/src/generators
2 files changed +10
-1
lines changed Original file line number Diff line number Diff line change @@ -5,7 +5,11 @@ export const generateBase = () => {
5
5
6
6
const branded = 'export type Branded<TBrand extends string, TType = string> = TType & { [__brand]: TBrand }'
7
7
8
- return `${ brand } \n\n${ branded } \n`
8
+ const opaqueRefEnum = "export const OPAQUE_REF = { EMPTY: 'OpaqueRef:NULL' } as const"
9
+
10
+ const opaqueRefType = "export type OPAQUE_REF_NULL = typeof OPAQUE_REF['EMPTY']"
11
+
12
+ return `${ brand } \n\n${ branded } \n\n${ opaqueRefEnum } \n\n${ opaqueRefType } \n`
9
13
}
10
14
11
15
const baseCommand = new Command ( 'base' ) . description ( 'Generate base types' ) . action ( async ( ) => {
Original file line number Diff line number Diff line change @@ -38,6 +38,8 @@ export const generateRecord = (item: XapiItem) => {
38
38
t => t . transition === 'published' && VERSION_BY_CODE_NAME [ t . release ] === undefined
39
39
)
40
40
const isDeprecated = field . lifecycle . transitions . some ( t => t . transition === 'deprecated' )
41
+ const isEmptyOpaqueRef =
42
+ field . default === 'OpaqueRef:NULL' || ( field . default === 'Null' && field . type . endsWith ( 'ref' ) )
41
43
42
44
function isAlwaysExisting ( ) {
43
45
if ( ! isPublished || isPublishedAfterDundee ) {
@@ -51,6 +53,9 @@ export const generateRecord = (item: XapiItem) => {
51
53
// field.name === 'uuid' || field.type.endsWith(' set') || (isPublished && isFromRio && !isDeprecated && !isOptional)
52
54
53
55
const result = [ ` ${ field . name } ${ isAlwaysExisting ( ) ? '' : '?' } : ${ toType ( field . type ) } ` ]
56
+ if ( isEmptyOpaqueRef ) {
57
+ result [ 0 ] = result [ 0 ] . concat ( ' | OPAQUE_REF_NULL' )
58
+ }
54
59
55
60
if ( isDeprecated ) {
56
61
result . unshift ( ' /** @deprecated */' )
You can’t perform that action at this time.
0 commit comments