1
1
import * as fs from 'fs' ;
2
+ import * as got from 'got' ;
2
3
import * as path from 'path' ;
3
4
import * as prettier from 'prettier' ;
4
- import * as got from 'got' ;
5
5
import deburr = require( 'lodash.deburr' ) ;
6
6
7
7
interface RawType {
@@ -50,14 +50,19 @@ interface ObjectType {
50
50
}
51
51
52
52
interface OutputType {
53
- type : 'object ' ;
53
+ type : 'ObsWebSocket.Output ' ;
54
54
properties : Tree ;
55
55
optional : boolean ;
56
56
}
57
57
58
+ interface OBSStatsType {
59
+ type : 'ObsWebSocket.OBSStats' ;
60
+ optional : boolean ;
61
+ }
62
+
58
63
interface ArrayType {
59
64
type : 'array' ;
60
- items : PrimitiveType | ObjectType | OutputType | SceneType | SceneItemType | SceneItemTransformType ;
65
+ items : PrimitiveType | ObjectType | OutputType | SceneType | SceneItemType | SceneItemTransformType | ScenesCollectionType ;
61
66
optional : boolean ;
62
67
}
63
68
@@ -76,8 +81,8 @@ interface SceneItemTransformType {
76
81
optional : boolean ;
77
82
}
78
83
79
- interface OBSStatsType {
80
- type : 'ObsWebSocket.OBSStats ' ;
84
+ interface ScenesCollectionType {
85
+ type : 'ObsWebSocket.ScenesCollection ' ;
81
86
optional : boolean ;
82
87
}
83
88
@@ -133,7 +138,7 @@ function parseApi(raw: RawComments): void {
133
138
if ( request . params ) {
134
139
const foo = unflattenAndResolveTypes ( request . params ) ;
135
140
argsString += '{' ;
136
- argsString += stringifyTypes ( foo , { terminator : ',' , finalTerminator : false } ) ;
141
+ argsString += stringifyTypes ( foo , { terminator : ',' , finalTerminator : false , name : request . name } ) ;
137
142
argsString += '}' ;
138
143
} else {
139
144
argsString += 'void' ;
@@ -142,7 +147,7 @@ function parseApi(raw: RawComments): void {
142
147
let returnTypeString = 'void' ;
143
148
if ( request . returns ) {
144
149
const foo = unflattenAndResolveTypes ( request . returns ) ;
145
- returnTypeString = `{messageId: string;status: "ok";${ stringifyTypes ( foo , { terminator : ';' , finalTerminator : false } ) } }` ;
150
+ returnTypeString = `{messageId: string;status: "ok";${ stringifyTypes ( foo , { terminator : ';' , finalTerminator : false , name : request . name } ) } }` ;
146
151
}
147
152
responseString += `${ returnTypeString } ;` ;
148
153
@@ -200,6 +205,13 @@ declare module 'obs-websocket-js' {
200
205
"ConnectionClosed": void;
201
206
"AuthenticationSuccess": void;
202
207
"AuthenticationFailure": void;
208
+ "error": {
209
+ error: any;
210
+ message: string;
211
+ type: string;
212
+ // This would require importing all of the WebSocket types so leaving out for now.
213
+ // target: WebSocket;
214
+ };
203
215
${ eventOverloads . join ( '\n\n ' ) }
204
216
}
205
217
@@ -309,11 +321,14 @@ function unflattenAndResolveTypes(inputItems: RawType[]): Tree {
309
321
310
322
const firstIntermediate = ( currentNode as any ) [ nodeName ] ;
311
323
if ( firstIntermediate . type === 'array' ) {
312
- firstIntermediate . items = {
313
- type : 'object' ,
314
- properties : { } ,
315
- optional : false
316
- } ;
324
+ // Not sure if needed at all, but was here before and causing issues, so added a check.
325
+ if ( ! firstIntermediate . items . properties ) {
326
+ firstIntermediate . items = {
327
+ type : 'object' ,
328
+ properties : { } ,
329
+ optional : true // Matches the "array<object>" case in "resolveType".
330
+ } ;
331
+ }
317
332
currentNode = firstIntermediate . items . properties ;
318
333
} else {
319
334
currentNode = firstIntermediate . properties ;
@@ -390,7 +405,7 @@ function resolveType(inType: string): AnyType {
390
405
return {
391
406
type : 'array' ,
392
407
items : {
393
- type : 'object ' ,
408
+ type : 'ObsWebSocket.Output ' ,
394
409
properties : { } ,
395
410
optional : true
396
411
} ,
@@ -423,6 +438,15 @@ function resolveType(inType: string): AnyType {
423
438
} ,
424
439
optional : isOptional
425
440
} ;
441
+ case 'array<scenescollection>' :
442
+ return {
443
+ type : 'array' ,
444
+ items : {
445
+ type : 'ObsWebSocket.ScenesCollection' ,
446
+ optional : true
447
+ } ,
448
+ optional : isOptional
449
+ } ;
426
450
case 'sceneitemtransform' :
427
451
return {
428
452
type : 'ObsWebSocket.SceneItemTransform' ,
@@ -433,25 +457,25 @@ function resolveType(inType: string): AnyType {
433
457
type : 'ObsWebSocket.OBSStats' ,
434
458
optional : isOptional
435
459
} ;
460
+ case 'output' :
461
+ return {
462
+ type : 'ObsWebSocket.Output' ,
463
+ properties : { } ,
464
+ optional : isOptional
465
+ } ;
436
466
case 'string | object' :
437
467
case 'object' :
438
468
return {
439
469
type : 'object' ,
440
470
properties : { } ,
441
471
optional : isOptional
442
472
} ;
443
- case 'output' :
444
- return {
445
- type : 'object' ,
446
- properties : { } ,
447
- optional : isOptional
448
- } ;
449
473
default :
450
474
throw new Error ( `Unknown type: ${ inType } ` ) ;
451
475
}
452
476
}
453
477
454
- function stringifyTypes ( inputTypes : Tree , { terminator = ';' , finalTerminator = true , includePrefix = true } = { } ) : string {
478
+ function stringifyTypes ( inputTypes : Tree , { terminator = ';' , finalTerminator = true , includePrefix = true , name = '' } = { } ) : string {
455
479
let returnString = '' ;
456
480
Object . entries ( inputTypes ) . forEach ( ( [ key , typeDef ] ) => {
457
481
if ( includePrefix ) {
@@ -466,7 +490,12 @@ function stringifyTypes(inputTypes: Tree, {terminator = ';', finalTerminator = t
466
490
if ( typeDef . items ) {
467
491
if ( typeDef . items . type === 'object' ) {
468
492
if ( Object . keys ( typeDef . items . properties ) . length > 0 ) {
469
- returnString += `${ stringifyTypes ( typeDef . items . properties , { includePrefix : false , terminator : '' } ) } []` ;
493
+ returnString += `{${ stringifyTypes ( typeDef . items . properties , { name} ) } ` ;
494
+ // Allows other arbitrary properties inside of "ExecuteBatch".
495
+ if ( name === 'ExecuteBatch' ) {
496
+ returnString += '[k: string]: any;' ;
497
+ }
498
+ returnString += '}[]' ;
470
499
} else {
471
500
returnString += 'Array<{[k: string]: any}>' ;
472
501
}
0 commit comments