From 843babf6c510c0057cd0d16df006f1f4adfb8889 Mon Sep 17 00:00:00 2001 From: zoton2 Date: Thu, 4 Mar 2021 09:51:04 +0000 Subject: [PATCH 1/5] Fix build-types for ScenesCollection, add error event type --- .travis/build-types.ts | 29 +++++++++++++++++++++++++---- 1 file changed, 25 insertions(+), 4 deletions(-) diff --git a/.travis/build-types.ts b/.travis/build-types.ts index c22f7c32..9b5cb6e7 100644 --- a/.travis/build-types.ts +++ b/.travis/build-types.ts @@ -1,7 +1,7 @@ import * as fs from 'fs'; +import * as got from 'got'; import * as path from 'path'; import * as prettier from 'prettier'; -import * as got from 'got'; import deburr = require('lodash.deburr'); interface RawType { @@ -55,9 +55,14 @@ interface OutputType { optional: boolean; } +interface OBSStatsType { + type: 'ObsWebSocket.OBSStats'; + optional: boolean; +} + interface ArrayType { type: 'array'; - items: PrimitiveType | ObjectType | OutputType | SceneType | SceneItemType | SceneItemTransformType; + items: PrimitiveType | ObjectType | OutputType | SceneType | SceneItemType | SceneItemTransformType | ScenesCollectionType; optional: boolean; } @@ -76,8 +81,8 @@ interface SceneItemTransformType { optional: boolean; } -interface OBSStatsType { - type: 'ObsWebSocket.OBSStats'; +interface ScenesCollectionType { + type: 'ObsWebSocket.ScenesCollection'; optional: boolean; } @@ -200,6 +205,13 @@ declare module 'obs-websocket-js' { "ConnectionClosed": void; "AuthenticationSuccess": void; "AuthenticationFailure": void; + "error": { + error: any; + message: string; + type: string; + // This would require importing all of the WebSocket types so leaving out for now. + // target: WebSocket; + }; ${eventOverloads.join('\n\n ')} } @@ -423,6 +435,15 @@ function resolveType(inType: string): AnyType { }, optional: isOptional }; + case 'array': + return { + type: 'array', + items: { + type: 'ObsWebSocket.ScenesCollection', + optional: true + }, + optional: isOptional + }; case 'sceneitemtransform': return { type: 'ObsWebSocket.SceneItemTransform', From 4da0a2b7b68f4ff19e968e908d7ba09ab549c692 Mon Sep 17 00:00:00 2001 From: zoton2 Date: Sun, 28 Feb 2021 21:48:25 +0000 Subject: [PATCH 2/5] build-types: fix Output Typedef not being used correctly --- .travis/build-types.ts | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/.travis/build-types.ts b/.travis/build-types.ts index 9b5cb6e7..143174f8 100644 --- a/.travis/build-types.ts +++ b/.travis/build-types.ts @@ -50,7 +50,7 @@ interface ObjectType { } interface OutputType { - type: 'object'; + type: 'ObsWebSocket.Output'; properties: Tree; optional: boolean; } @@ -402,7 +402,7 @@ function resolveType(inType: string): AnyType { return { type: 'array', items: { - type: 'object', + type: 'ObsWebSocket.Output', properties: {}, optional: true }, @@ -454,6 +454,12 @@ function resolveType(inType: string): AnyType { type: 'ObsWebSocket.OBSStats', optional: isOptional }; + case 'output': + return { + type: 'ObsWebSocket.Output', + properties: {}, + optional: isOptional + }; case 'string | object': case 'object': return { @@ -461,12 +467,6 @@ function resolveType(inType: string): AnyType { properties: {}, optional: isOptional }; - case 'output': - return { - type: 'object', - properties: {}, - optional: isOptional - }; default: throw new Error(`Unknown type: ${inType}`); } From 21a4f749a7aaa875ca628445930a6621d790edc7 Mon Sep 17 00:00:00 2001 From: zoton2 Date: Mon, 1 Mar 2021 00:22:51 +0000 Subject: [PATCH 3/5] build-types: fix arrays of objects not actually type building correctly --- .travis/build-types.ts | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/.travis/build-types.ts b/.travis/build-types.ts index 143174f8..ffac46ea 100644 --- a/.travis/build-types.ts +++ b/.travis/build-types.ts @@ -321,11 +321,14 @@ function unflattenAndResolveTypes(inputItems: RawType[]): Tree { const firstIntermediate = (currentNode as any)[nodeName]; if (firstIntermediate.type === 'array') { - firstIntermediate.items = { - type: 'object', - properties: {}, - optional: false - }; + // Not sure if needed at all, but was here before and causing issues, so added a check. + if (!firstIntermediate.items.properties) { + firstIntermediate.items = { + type: 'object', + properties: {}, + optional: true // Matches the "array" case in "resolveType". + }; + } currentNode = firstIntermediate.items.properties; } else { currentNode = firstIntermediate.properties; @@ -487,7 +490,7 @@ function stringifyTypes(inputTypes: Tree, {terminator = ';', finalTerminator = t if (typeDef.items) { if (typeDef.items.type === 'object') { if (Object.keys(typeDef.items.properties).length > 0) { - returnString += `${stringifyTypes(typeDef.items.properties, {includePrefix: false, terminator: ''})}[]`; + returnString += `{ ${stringifyTypes(typeDef.items.properties)} }[]`; } else { returnString += 'Array<{[k: string]: any}>'; } From 1c8851f616115f9c34cdbd337dc775788f44ca3f Mon Sep 17 00:00:00 2001 From: zoton2 Date: Mon, 1 Mar 2021 00:43:29 +0000 Subject: [PATCH 4/5] build-types: hack to allow arbitrary properties inside of ExecuteBatch --- .travis/build-types.ts | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/.travis/build-types.ts b/.travis/build-types.ts index ffac46ea..26fbbe91 100644 --- a/.travis/build-types.ts +++ b/.travis/build-types.ts @@ -138,7 +138,7 @@ function parseApi(raw: RawComments): void { if (request.params) { const foo = unflattenAndResolveTypes(request.params); argsString += '{'; - argsString += stringifyTypes(foo, {terminator: ',', finalTerminator: false}); + argsString += stringifyTypes(foo, {terminator: ',', finalTerminator: false, name: request.name}); argsString += '}'; } else { argsString += 'void'; @@ -147,7 +147,7 @@ function parseApi(raw: RawComments): void { let returnTypeString = 'void'; if (request.returns) { const foo = unflattenAndResolveTypes(request.returns); - returnTypeString = `{messageId: string;status: "ok";${stringifyTypes(foo, {terminator: ';', finalTerminator: false})}}`; + returnTypeString = `{messageId: string;status: "ok";${stringifyTypes(foo, {terminator: ';', finalTerminator: false, name: request.name})}}`; } responseString += `${returnTypeString};`; @@ -475,7 +475,7 @@ function resolveType(inType: string): AnyType { } } -function stringifyTypes(inputTypes: Tree, {terminator = ';', finalTerminator = true, includePrefix = true} = {}): string { +function stringifyTypes(inputTypes: Tree, {terminator = ';', finalTerminator = true, includePrefix = true, name = ''} = {}): string { let returnString = ''; Object.entries(inputTypes).forEach(([key, typeDef]) => { if (includePrefix) { @@ -490,7 +490,12 @@ function stringifyTypes(inputTypes: Tree, {terminator = ';', finalTerminator = t if (typeDef.items) { if (typeDef.items.type === 'object') { if (Object.keys(typeDef.items.properties).length > 0) { - returnString += `{ ${stringifyTypes(typeDef.items.properties)} }[]`; + returnString += `{ ${stringifyTypes(typeDef.items.properties, {name})}`; + // Allows other arbitrary properties inside of "ExecuteBatch". + if (name === 'ExecuteBatch') { + returnString += ' [k: string]: any;'; + } + returnString += ' }[]'; } else { returnString += 'Array<{[k: string]: any}>'; } From 00463322bddc0bff7bc5a6fef6d87f5102a98541 Mon Sep 17 00:00:00 2001 From: zoton2 Date: Mon, 1 Mar 2021 00:52:53 +0000 Subject: [PATCH 5/5] build-types: remove unneeded spaces --- .travis/build-types.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.travis/build-types.ts b/.travis/build-types.ts index 26fbbe91..f3492557 100644 --- a/.travis/build-types.ts +++ b/.travis/build-types.ts @@ -490,12 +490,12 @@ function stringifyTypes(inputTypes: Tree, {terminator = ';', finalTerminator = t if (typeDef.items) { if (typeDef.items.type === 'object') { if (Object.keys(typeDef.items.properties).length > 0) { - returnString += `{ ${stringifyTypes(typeDef.items.properties, {name})}`; + returnString += `{${stringifyTypes(typeDef.items.properties, {name})}`; // Allows other arbitrary properties inside of "ExecuteBatch". if (name === 'ExecuteBatch') { - returnString += ' [k: string]: any;'; + returnString += '[k: string]: any;'; } - returnString += ' }[]'; + returnString += '}[]'; } else { returnString += 'Array<{[k: string]: any}>'; }