Skip to content

Commit 44aa9a2

Browse files
committed
1 parent 6704c31 commit 44aa9a2

File tree

1 file changed

+30
-15
lines changed

1 file changed

+30
-15
lines changed

.travis/build-types.ts

Lines changed: 30 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ interface ObjectType {
4848
}
4949

5050
interface OutputType {
51-
type: 'object';
51+
type: 'ObsWebSocket.Output';
5252
properties: Tree;
5353
optional: boolean;
5454
}
@@ -138,7 +138,7 @@ function parseApi(raw: RawComments): void {
138138
if (request.params) {
139139
const foo = unflattenAndResolveTypes(request.params);
140140
argsString += '{';
141-
argsString += stringifyTypes(foo, {terminator: ',', finalTerminator: false});
141+
argsString += stringifyTypes(foo, {terminator: ',', finalTerminator: false, name: request.name});
142142
argsString += '}';
143143
} else {
144144
argsString += 'void';
@@ -147,7 +147,7 @@ function parseApi(raw: RawComments): void {
147147
let returnTypeString = 'void';
148148
if (request.returns) {
149149
const foo = unflattenAndResolveTypes(request.returns);
150-
returnTypeString = `{messageId: string;status: "ok";${stringifyTypes(foo, {terminator: ';', finalTerminator: false})}}`;
150+
returnTypeString = `{messageId: string;status: "ok";${stringifyTypes(foo, {terminator: ';', finalTerminator: false, name: request.name})}}`;
151151
}
152152
responseString += `${returnTypeString};`;
153153

@@ -205,6 +205,13 @@ declare module 'obs-websocket-js' {
205205
"ConnectionClosed": void;
206206
"AuthenticationSuccess": void;
207207
"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+
};
208215
${eventOverloads.join('\n\n ')}
209216
}
210217
@@ -314,11 +321,14 @@ function unflattenAndResolveTypes(inputItems: RawType[]): Tree {
314321

315322
const firstIntermediate = (currentNode as any)[nodeName];
316323
if (firstIntermediate.type === 'array') {
317-
firstIntermediate.items = {
318-
type: 'object',
319-
properties: {},
320-
optional: false
321-
};
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+
}
322332
currentNode = firstIntermediate.items.properties;
323333
} else {
324334
currentNode = firstIntermediate.properties;
@@ -395,7 +405,7 @@ function resolveType(inType: string): AnyType {
395405
return {
396406
type: 'array',
397407
items: {
398-
type: 'object',
408+
type: 'ObsWebSocket.Output',
399409
properties: {},
400410
optional: true
401411
},
@@ -452,14 +462,14 @@ function resolveType(inType: string): AnyType {
452462
type: 'ObsWebSocket.OBSStats',
453463
optional: isOptional
454464
};
455-
case 'string | object':
456-
case 'object':
465+
case 'output':
457466
return {
458-
type: 'object',
467+
type: 'ObsWebSocket.Output',
459468
properties: {},
460469
optional: isOptional
461470
};
462-
case 'output':
471+
case 'string | object':
472+
case 'object':
463473
return {
464474
type: 'object',
465475
properties: {},
@@ -470,7 +480,7 @@ function resolveType(inType: string): AnyType {
470480
}
471481
}
472482

473-
function stringifyTypes(inputTypes: Tree, {terminator = ';', finalTerminator = true, includePrefix = true} = {}): string {
483+
function stringifyTypes(inputTypes: Tree, {terminator = ';', finalTerminator = true, includePrefix = true, name = ''} = {}): string {
474484
let returnString = '';
475485
Object.entries(inputTypes).forEach(([key, typeDef]) => {
476486
if (includePrefix) {
@@ -485,7 +495,12 @@ function stringifyTypes(inputTypes: Tree, {terminator = ';', finalTerminator = t
485495
if (typeDef.items) {
486496
if (typeDef.items.type === 'object') {
487497
if (Object.keys(typeDef.items.properties).length > 0) {
488-
returnString += `${stringifyTypes(typeDef.items.properties, {includePrefix: false, terminator: ''})}[]`;
498+
returnString += `{${stringifyTypes(typeDef.items.properties, {name})}`;
499+
// Allows other arbitrary properties inside of "ExecuteBatch".
500+
if (name === 'ExecuteBatch') {
501+
returnString += '[k: string]: any;';
502+
}
503+
returnString += '}[]';
489504
} else {
490505
returnString += 'Array<{[k: string]: any}>';
491506
}

0 commit comments

Comments
 (0)