diff --git a/package.json b/package.json index a99c5fa..f6191c6 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "gooeyai", - "version": "0.0.1-beta7", + "version": "0.0.39", "private": false, "repository": "https://github.com/GooeyAI/typescript-sdk", "main": "./index.js", diff --git a/src/Client.ts b/src/Client.ts index fec1dac..1dbcdf5 100644 --- a/src/Client.ts +++ b/src/Client.ts @@ -45,7 +45,7 @@ export class GooeyClient { public async copilotAsync( request: Gooey.VideoBotsPageRequest = {}, requestOptions?: GooeyClient.RequestOptions - ): Promise { + ): Promise { const { exampleId, ..._body } = request; const _queryParams: Record = {}; if (exampleId != null) { @@ -62,7 +62,7 @@ export class GooeyClient { Authorization: await this._getAuthorizationHeader(), "X-Fern-Language": "JavaScript", "X-Fern-SDK-Name": "gooeyai", - "X-Fern-SDK-Version": "0.0.1-beta7", + "X-Fern-SDK-Version": "0.0.39", "X-Fern-Runtime": core.RUNTIME.type, "X-Fern-Runtime-Version": core.RUNTIME.version, }, @@ -75,7 +75,7 @@ export class GooeyClient { abortSignal: requestOptions?.abortSignal, }); if (_response.ok) { - return serializers.AsyncApiResponseModelV3.parseOrThrow(_response.body, { + return serializers.VideoBotsPageResponse.parseOrThrow(_response.body, { unrecognizedObjectKeys: "passthrough", allowUnrecognizedUnionMembers: true, allowUnrecognizedEnumValues: true, @@ -161,7 +161,7 @@ export class GooeyClient { Authorization: await this._getAuthorizationHeader(), "X-Fern-Language": "JavaScript", "X-Fern-SDK-Name": "gooeyai", - "X-Fern-SDK-Version": "0.0.1-beta7", + "X-Fern-SDK-Version": "0.0.39", "X-Fern-Runtime": core.RUNTIME.type, "X-Fern-Runtime-Version": core.RUNTIME.version, }, @@ -248,7 +248,7 @@ export class GooeyClient { public async animationGeneratorAsync( request: Gooey.DeforumSdPageRequest, requestOptions?: GooeyClient.RequestOptions - ): Promise { + ): Promise { const { exampleId, ..._body } = request; const _queryParams: Record = {}; if (exampleId != null) { @@ -265,7 +265,7 @@ export class GooeyClient { Authorization: await this._getAuthorizationHeader(), "X-Fern-Language": "JavaScript", "X-Fern-SDK-Name": "gooeyai", - "X-Fern-SDK-Version": "0.0.1-beta7", + "X-Fern-SDK-Version": "0.0.39", "X-Fern-Runtime": core.RUNTIME.type, "X-Fern-Runtime-Version": core.RUNTIME.version, }, @@ -278,7 +278,7 @@ export class GooeyClient { abortSignal: requestOptions?.abortSignal, }); if (_response.ok) { - return serializers.AsyncApiResponseModelV3.parseOrThrow(_response.body, { + return serializers.DeforumSdPageResponse.parseOrThrow(_response.body, { unrecognizedObjectKeys: "passthrough", allowUnrecognizedUnionMembers: true, allowUnrecognizedEnumValues: true, @@ -364,7 +364,7 @@ export class GooeyClient { Authorization: await this._getAuthorizationHeader(), "X-Fern-Language": "JavaScript", "X-Fern-SDK-Name": "gooeyai", - "X-Fern-SDK-Version": "0.0.1-beta7", + "X-Fern-SDK-Version": "0.0.39", "X-Fern-Runtime": core.RUNTIME.type, "X-Fern-Runtime-Version": core.RUNTIME.version, }, @@ -448,7 +448,7 @@ export class GooeyClient { public async qrCodeAsync( request: Gooey.QrCodeGeneratorPageRequest, requestOptions?: GooeyClient.RequestOptions - ): Promise { + ): Promise { const { exampleId, ..._body } = request; const _queryParams: Record = {}; if (exampleId != null) { @@ -465,7 +465,7 @@ export class GooeyClient { Authorization: await this._getAuthorizationHeader(), "X-Fern-Language": "JavaScript", "X-Fern-SDK-Name": "gooeyai", - "X-Fern-SDK-Version": "0.0.1-beta7", + "X-Fern-SDK-Version": "0.0.39", "X-Fern-Runtime": core.RUNTIME.type, "X-Fern-Runtime-Version": core.RUNTIME.version, }, @@ -478,7 +478,7 @@ export class GooeyClient { abortSignal: requestOptions?.abortSignal, }); if (_response.ok) { - return serializers.AsyncApiResponseModelV3.parseOrThrow(_response.body, { + return serializers.QrCodeGeneratorPageResponse.parseOrThrow(_response.body, { unrecognizedObjectKeys: "passthrough", allowUnrecognizedUnionMembers: true, allowUnrecognizedEnumValues: true, @@ -564,7 +564,7 @@ export class GooeyClient { Authorization: await this._getAuthorizationHeader(), "X-Fern-Language": "JavaScript", "X-Fern-SDK-Name": "gooeyai", - "X-Fern-SDK-Version": "0.0.1-beta7", + "X-Fern-SDK-Version": "0.0.39", "X-Fern-Runtime": core.RUNTIME.type, "X-Fern-Runtime-Version": core.RUNTIME.version, }, @@ -649,7 +649,7 @@ export class GooeyClient { public async relatedQnaMakerAsync( request: Gooey.RelatedQnAPageRequest, requestOptions?: GooeyClient.RequestOptions - ): Promise { + ): Promise { const { exampleId, ..._body } = request; const _queryParams: Record = {}; if (exampleId != null) { @@ -666,7 +666,7 @@ export class GooeyClient { Authorization: await this._getAuthorizationHeader(), "X-Fern-Language": "JavaScript", "X-Fern-SDK-Name": "gooeyai", - "X-Fern-SDK-Version": "0.0.1-beta7", + "X-Fern-SDK-Version": "0.0.39", "X-Fern-Runtime": core.RUNTIME.type, "X-Fern-Runtime-Version": core.RUNTIME.version, }, @@ -679,7 +679,7 @@ export class GooeyClient { abortSignal: requestOptions?.abortSignal, }); if (_response.ok) { - return serializers.AsyncApiResponseModelV3.parseOrThrow(_response.body, { + return serializers.RelatedQnAPageResponse.parseOrThrow(_response.body, { unrecognizedObjectKeys: "passthrough", allowUnrecognizedUnionMembers: true, allowUnrecognizedEnumValues: true, @@ -765,7 +765,7 @@ export class GooeyClient { Authorization: await this._getAuthorizationHeader(), "X-Fern-Language": "JavaScript", "X-Fern-SDK-Name": "gooeyai", - "X-Fern-SDK-Version": "0.0.1-beta7", + "X-Fern-SDK-Version": "0.0.39", "X-Fern-Runtime": core.RUNTIME.type, "X-Fern-Runtime-Version": core.RUNTIME.version, }, @@ -852,7 +852,7 @@ export class GooeyClient { public async seoParagraphGeneratorAsync( request: Gooey.SeoSummaryPageRequest, requestOptions?: GooeyClient.RequestOptions - ): Promise { + ): Promise { const { exampleId, ..._body } = request; const _queryParams: Record = {}; if (exampleId != null) { @@ -869,7 +869,7 @@ export class GooeyClient { Authorization: await this._getAuthorizationHeader(), "X-Fern-Language": "JavaScript", "X-Fern-SDK-Name": "gooeyai", - "X-Fern-SDK-Version": "0.0.1-beta7", + "X-Fern-SDK-Version": "0.0.39", "X-Fern-Runtime": core.RUNTIME.type, "X-Fern-Runtime-Version": core.RUNTIME.version, }, @@ -882,7 +882,7 @@ export class GooeyClient { abortSignal: requestOptions?.abortSignal, }); if (_response.ok) { - return serializers.AsyncApiResponseModelV3.parseOrThrow(_response.body, { + return serializers.SeoSummaryPageResponse.parseOrThrow(_response.body, { unrecognizedObjectKeys: "passthrough", allowUnrecognizedUnionMembers: true, allowUnrecognizedEnumValues: true, @@ -968,7 +968,7 @@ export class GooeyClient { Authorization: await this._getAuthorizationHeader(), "X-Fern-Language": "JavaScript", "X-Fern-SDK-Name": "gooeyai", - "X-Fern-SDK-Version": "0.0.1-beta7", + "X-Fern-SDK-Version": "0.0.39", "X-Fern-Runtime": core.RUNTIME.type, "X-Fern-Runtime-Version": core.RUNTIME.version, }, @@ -1053,7 +1053,7 @@ export class GooeyClient { public async googleGptAsync( request: Gooey.GoogleGptPageRequest, requestOptions?: GooeyClient.RequestOptions - ): Promise { + ): Promise { const { exampleId, ..._body } = request; const _queryParams: Record = {}; if (exampleId != null) { @@ -1070,7 +1070,7 @@ export class GooeyClient { Authorization: await this._getAuthorizationHeader(), "X-Fern-Language": "JavaScript", "X-Fern-SDK-Name": "gooeyai", - "X-Fern-SDK-Version": "0.0.1-beta7", + "X-Fern-SDK-Version": "0.0.39", "X-Fern-Runtime": core.RUNTIME.type, "X-Fern-Runtime-Version": core.RUNTIME.version, }, @@ -1083,7 +1083,7 @@ export class GooeyClient { abortSignal: requestOptions?.abortSignal, }); if (_response.ok) { - return serializers.AsyncApiResponseModelV3.parseOrThrow(_response.body, { + return serializers.GoogleGptPageResponse.parseOrThrow(_response.body, { unrecognizedObjectKeys: "passthrough", allowUnrecognizedUnionMembers: true, allowUnrecognizedEnumValues: true, @@ -1169,7 +1169,7 @@ export class GooeyClient { Authorization: await this._getAuthorizationHeader(), "X-Fern-Language": "JavaScript", "X-Fern-SDK-Name": "gooeyai", - "X-Fern-SDK-Version": "0.0.1-beta7", + "X-Fern-SDK-Version": "0.0.39", "X-Fern-Runtime": core.RUNTIME.type, "X-Fern-Runtime-Version": core.RUNTIME.version, }, @@ -1253,7 +1253,7 @@ export class GooeyClient { public async emailWriterWithProfileLookupAsync( request: Gooey.SocialLookupEmailPageRequest, requestOptions?: GooeyClient.RequestOptions - ): Promise { + ): Promise { const { exampleId, ..._body } = request; const _queryParams: Record = {}; if (exampleId != null) { @@ -1270,7 +1270,7 @@ export class GooeyClient { Authorization: await this._getAuthorizationHeader(), "X-Fern-Language": "JavaScript", "X-Fern-SDK-Name": "gooeyai", - "X-Fern-SDK-Version": "0.0.1-beta7", + "X-Fern-SDK-Version": "0.0.39", "X-Fern-Runtime": core.RUNTIME.type, "X-Fern-Runtime-Version": core.RUNTIME.version, }, @@ -1283,7 +1283,7 @@ export class GooeyClient { abortSignal: requestOptions?.abortSignal, }); if (_response.ok) { - return serializers.AsyncApiResponseModelV3.parseOrThrow(_response.body, { + return serializers.SocialLookupEmailPageResponse.parseOrThrow(_response.body, { unrecognizedObjectKeys: "passthrough", allowUnrecognizedUnionMembers: true, allowUnrecognizedEnumValues: true, @@ -1369,7 +1369,7 @@ export class GooeyClient { Authorization: await this._getAuthorizationHeader(), "X-Fern-Language": "JavaScript", "X-Fern-SDK-Name": "gooeyai", - "X-Fern-SDK-Version": "0.0.1-beta7", + "X-Fern-SDK-Version": "0.0.39", "X-Fern-Runtime": core.RUNTIME.type, "X-Fern-Runtime-Version": core.RUNTIME.version, }, @@ -1460,7 +1460,7 @@ export class GooeyClient { public async bulkAsync( request: Gooey.BulkRunnerPageRequest, requestOptions?: GooeyClient.RequestOptions - ): Promise { + ): Promise { const { exampleId, ..._body } = request; const _queryParams: Record = {}; if (exampleId != null) { @@ -1477,7 +1477,7 @@ export class GooeyClient { Authorization: await this._getAuthorizationHeader(), "X-Fern-Language": "JavaScript", "X-Fern-SDK-Name": "gooeyai", - "X-Fern-SDK-Version": "0.0.1-beta7", + "X-Fern-SDK-Version": "0.0.39", "X-Fern-Runtime": core.RUNTIME.type, "X-Fern-Runtime-Version": core.RUNTIME.version, }, @@ -1490,7 +1490,7 @@ export class GooeyClient { abortSignal: requestOptions?.abortSignal, }); if (_response.ok) { - return serializers.AsyncApiResponseModelV3.parseOrThrow(_response.body, { + return serializers.BulkRunnerPageResponse.parseOrThrow(_response.body, { unrecognizedObjectKeys: "passthrough", allowUnrecognizedUnionMembers: true, allowUnrecognizedEnumValues: true, @@ -1576,7 +1576,7 @@ export class GooeyClient { Authorization: await this._getAuthorizationHeader(), "X-Fern-Language": "JavaScript", "X-Fern-SDK-Name": "gooeyai", - "X-Fern-SDK-Version": "0.0.1-beta7", + "X-Fern-SDK-Version": "0.0.39", "X-Fern-Runtime": core.RUNTIME.type, "X-Fern-Runtime-Version": core.RUNTIME.version, }, @@ -1660,7 +1660,7 @@ export class GooeyClient { public async evalAsync( request: Gooey.BulkEvalPageRequest, requestOptions?: GooeyClient.RequestOptions - ): Promise { + ): Promise { const { exampleId, ..._body } = request; const _queryParams: Record = {}; if (exampleId != null) { @@ -1677,7 +1677,7 @@ export class GooeyClient { Authorization: await this._getAuthorizationHeader(), "X-Fern-Language": "JavaScript", "X-Fern-SDK-Name": "gooeyai", - "X-Fern-SDK-Version": "0.0.1-beta7", + "X-Fern-SDK-Version": "0.0.39", "X-Fern-Runtime": core.RUNTIME.type, "X-Fern-Runtime-Version": core.RUNTIME.version, }, @@ -1690,7 +1690,7 @@ export class GooeyClient { abortSignal: requestOptions?.abortSignal, }); if (_response.ok) { - return serializers.AsyncApiResponseModelV3.parseOrThrow(_response.body, { + return serializers.BulkEvalPageResponse.parseOrThrow(_response.body, { unrecognizedObjectKeys: "passthrough", allowUnrecognizedUnionMembers: true, allowUnrecognizedEnumValues: true, @@ -1776,7 +1776,7 @@ export class GooeyClient { Authorization: await this._getAuthorizationHeader(), "X-Fern-Language": "JavaScript", "X-Fern-SDK-Name": "gooeyai", - "X-Fern-SDK-Version": "0.0.1-beta7", + "X-Fern-SDK-Version": "0.0.39", "X-Fern-Runtime": core.RUNTIME.type, "X-Fern-Runtime-Version": core.RUNTIME.version, }, @@ -1860,7 +1860,7 @@ export class GooeyClient { public async docExtractAsync( request: Gooey.DocExtractPageRequest, requestOptions?: GooeyClient.RequestOptions - ): Promise { + ): Promise { const { exampleId, ..._body } = request; const _queryParams: Record = {}; if (exampleId != null) { @@ -1877,7 +1877,7 @@ export class GooeyClient { Authorization: await this._getAuthorizationHeader(), "X-Fern-Language": "JavaScript", "X-Fern-SDK-Name": "gooeyai", - "X-Fern-SDK-Version": "0.0.1-beta7", + "X-Fern-SDK-Version": "0.0.39", "X-Fern-Runtime": core.RUNTIME.type, "X-Fern-Runtime-Version": core.RUNTIME.version, }, @@ -1890,7 +1890,7 @@ export class GooeyClient { abortSignal: requestOptions?.abortSignal, }); if (_response.ok) { - return serializers.AsyncApiResponseModelV3.parseOrThrow(_response.body, { + return serializers.DocExtractPageResponse.parseOrThrow(_response.body, { unrecognizedObjectKeys: "passthrough", allowUnrecognizedUnionMembers: true, allowUnrecognizedEnumValues: true, @@ -1976,7 +1976,7 @@ export class GooeyClient { Authorization: await this._getAuthorizationHeader(), "X-Fern-Language": "JavaScript", "X-Fern-SDK-Name": "gooeyai", - "X-Fern-SDK-Version": "0.0.1-beta7", + "X-Fern-SDK-Version": "0.0.39", "X-Fern-Runtime": core.RUNTIME.type, "X-Fern-Runtime-Version": core.RUNTIME.version, }, @@ -2058,7 +2058,7 @@ export class GooeyClient { public async compareLargeLanguageModelsAsync( request: Gooey.CompareLlmPageRequest = {}, requestOptions?: GooeyClient.RequestOptions - ): Promise { + ): Promise { const { exampleId, ..._body } = request; const _queryParams: Record = {}; if (exampleId != null) { @@ -2075,7 +2075,7 @@ export class GooeyClient { Authorization: await this._getAuthorizationHeader(), "X-Fern-Language": "JavaScript", "X-Fern-SDK-Name": "gooeyai", - "X-Fern-SDK-Version": "0.0.1-beta7", + "X-Fern-SDK-Version": "0.0.39", "X-Fern-Runtime": core.RUNTIME.type, "X-Fern-Runtime-Version": core.RUNTIME.version, }, @@ -2088,7 +2088,7 @@ export class GooeyClient { abortSignal: requestOptions?.abortSignal, }); if (_response.ok) { - return serializers.AsyncApiResponseModelV3.parseOrThrow(_response.body, { + return serializers.CompareLlmPageResponse.parseOrThrow(_response.body, { unrecognizedObjectKeys: "passthrough", allowUnrecognizedUnionMembers: true, allowUnrecognizedEnumValues: true, @@ -2174,7 +2174,7 @@ export class GooeyClient { Authorization: await this._getAuthorizationHeader(), "X-Fern-Language": "JavaScript", "X-Fern-SDK-Name": "gooeyai", - "X-Fern-SDK-Version": "0.0.1-beta7", + "X-Fern-SDK-Version": "0.0.39", "X-Fern-Runtime": core.RUNTIME.type, "X-Fern-Runtime-Version": core.RUNTIME.version, }, @@ -2258,7 +2258,7 @@ export class GooeyClient { public async docSearchAsync( request: Gooey.DocSearchPageRequest, requestOptions?: GooeyClient.RequestOptions - ): Promise { + ): Promise { const { exampleId, ..._body } = request; const _queryParams: Record = {}; if (exampleId != null) { @@ -2275,7 +2275,7 @@ export class GooeyClient { Authorization: await this._getAuthorizationHeader(), "X-Fern-Language": "JavaScript", "X-Fern-SDK-Name": "gooeyai", - "X-Fern-SDK-Version": "0.0.1-beta7", + "X-Fern-SDK-Version": "0.0.39", "X-Fern-Runtime": core.RUNTIME.type, "X-Fern-Runtime-Version": core.RUNTIME.version, }, @@ -2288,7 +2288,7 @@ export class GooeyClient { abortSignal: requestOptions?.abortSignal, }); if (_response.ok) { - return serializers.AsyncApiResponseModelV3.parseOrThrow(_response.body, { + return serializers.DocSearchPageResponse.parseOrThrow(_response.body, { unrecognizedObjectKeys: "passthrough", allowUnrecognizedUnionMembers: true, allowUnrecognizedEnumValues: true, @@ -2374,7 +2374,7 @@ export class GooeyClient { Authorization: await this._getAuthorizationHeader(), "X-Fern-Language": "JavaScript", "X-Fern-SDK-Name": "gooeyai", - "X-Fern-SDK-Version": "0.0.1-beta7", + "X-Fern-SDK-Version": "0.0.39", "X-Fern-Runtime": core.RUNTIME.type, "X-Fern-Runtime-Version": core.RUNTIME.version, }, @@ -2458,7 +2458,7 @@ export class GooeyClient { public async smartGptAsync( request: Gooey.SmartGptPageRequest, requestOptions?: GooeyClient.RequestOptions - ): Promise { + ): Promise { const { exampleId, ..._body } = request; const _queryParams: Record = {}; if (exampleId != null) { @@ -2475,7 +2475,7 @@ export class GooeyClient { Authorization: await this._getAuthorizationHeader(), "X-Fern-Language": "JavaScript", "X-Fern-SDK-Name": "gooeyai", - "X-Fern-SDK-Version": "0.0.1-beta7", + "X-Fern-SDK-Version": "0.0.39", "X-Fern-Runtime": core.RUNTIME.type, "X-Fern-Runtime-Version": core.RUNTIME.version, }, @@ -2488,7 +2488,7 @@ export class GooeyClient { abortSignal: requestOptions?.abortSignal, }); if (_response.ok) { - return serializers.AsyncApiResponseModelV3.parseOrThrow(_response.body, { + return serializers.SmartGptPageResponse.parseOrThrow(_response.body, { unrecognizedObjectKeys: "passthrough", allowUnrecognizedUnionMembers: true, allowUnrecognizedEnumValues: true, @@ -2574,7 +2574,7 @@ export class GooeyClient { Authorization: await this._getAuthorizationHeader(), "X-Fern-Language": "JavaScript", "X-Fern-SDK-Name": "gooeyai", - "X-Fern-SDK-Version": "0.0.1-beta7", + "X-Fern-SDK-Version": "0.0.39", "X-Fern-Runtime": core.RUNTIME.type, "X-Fern-Runtime-Version": core.RUNTIME.version, }, @@ -2658,7 +2658,7 @@ export class GooeyClient { public async docSummaryAsync( request: Gooey.DocSummaryPageRequest, requestOptions?: GooeyClient.RequestOptions - ): Promise { + ): Promise { const { exampleId, ..._body } = request; const _queryParams: Record = {}; if (exampleId != null) { @@ -2675,7 +2675,7 @@ export class GooeyClient { Authorization: await this._getAuthorizationHeader(), "X-Fern-Language": "JavaScript", "X-Fern-SDK-Name": "gooeyai", - "X-Fern-SDK-Version": "0.0.1-beta7", + "X-Fern-SDK-Version": "0.0.39", "X-Fern-Runtime": core.RUNTIME.type, "X-Fern-Runtime-Version": core.RUNTIME.version, }, @@ -2688,7 +2688,7 @@ export class GooeyClient { abortSignal: requestOptions?.abortSignal, }); if (_response.ok) { - return serializers.AsyncApiResponseModelV3.parseOrThrow(_response.body, { + return serializers.DocSummaryPageResponse.parseOrThrow(_response.body, { unrecognizedObjectKeys: "passthrough", allowUnrecognizedUnionMembers: true, allowUnrecognizedEnumValues: true, @@ -2774,7 +2774,7 @@ export class GooeyClient { Authorization: await this._getAuthorizationHeader(), "X-Fern-Language": "JavaScript", "X-Fern-SDK-Name": "gooeyai", - "X-Fern-SDK-Version": "0.0.1-beta7", + "X-Fern-SDK-Version": "0.0.39", "X-Fern-Runtime": core.RUNTIME.type, "X-Fern-Runtime-Version": core.RUNTIME.version, }, @@ -2856,7 +2856,7 @@ export class GooeyClient { public async functionsAsync( request: Gooey.FunctionsPageRequest = {}, requestOptions?: GooeyClient.RequestOptions - ): Promise { + ): Promise { const { exampleId, ..._body } = request; const _queryParams: Record = {}; if (exampleId != null) { @@ -2873,7 +2873,7 @@ export class GooeyClient { Authorization: await this._getAuthorizationHeader(), "X-Fern-Language": "JavaScript", "X-Fern-SDK-Name": "gooeyai", - "X-Fern-SDK-Version": "0.0.1-beta7", + "X-Fern-SDK-Version": "0.0.39", "X-Fern-Runtime": core.RUNTIME.type, "X-Fern-Runtime-Version": core.RUNTIME.version, }, @@ -2886,7 +2886,7 @@ export class GooeyClient { abortSignal: requestOptions?.abortSignal, }); if (_response.ok) { - return serializers.AsyncApiResponseModelV3.parseOrThrow(_response.body, { + return serializers.FunctionsPageResponse.parseOrThrow(_response.body, { unrecognizedObjectKeys: "passthrough", allowUnrecognizedUnionMembers: true, allowUnrecognizedEnumValues: true, @@ -2972,7 +2972,7 @@ export class GooeyClient { Authorization: await this._getAuthorizationHeader(), "X-Fern-Language": "JavaScript", "X-Fern-SDK-Name": "gooeyai", - "X-Fern-SDK-Version": "0.0.1-beta7", + "X-Fern-SDK-Version": "0.0.39", "X-Fern-Runtime": core.RUNTIME.type, "X-Fern-Runtime-Version": core.RUNTIME.version, }, @@ -3054,7 +3054,7 @@ export class GooeyClient { public async lipsyncAsync( request: Gooey.LipsyncPageRequest = {}, requestOptions?: GooeyClient.RequestOptions - ): Promise { + ): Promise { const { exampleId, ..._body } = request; const _queryParams: Record = {}; if (exampleId != null) { @@ -3071,7 +3071,7 @@ export class GooeyClient { Authorization: await this._getAuthorizationHeader(), "X-Fern-Language": "JavaScript", "X-Fern-SDK-Name": "gooeyai", - "X-Fern-SDK-Version": "0.0.1-beta7", + "X-Fern-SDK-Version": "0.0.39", "X-Fern-Runtime": core.RUNTIME.type, "X-Fern-Runtime-Version": core.RUNTIME.version, }, @@ -3084,7 +3084,7 @@ export class GooeyClient { abortSignal: requestOptions?.abortSignal, }); if (_response.ok) { - return serializers.AsyncApiResponseModelV3.parseOrThrow(_response.body, { + return serializers.LipsyncPageResponse.parseOrThrow(_response.body, { unrecognizedObjectKeys: "passthrough", allowUnrecognizedUnionMembers: true, allowUnrecognizedEnumValues: true, @@ -3170,7 +3170,7 @@ export class GooeyClient { Authorization: await this._getAuthorizationHeader(), "X-Fern-Language": "JavaScript", "X-Fern-SDK-Name": "gooeyai", - "X-Fern-SDK-Version": "0.0.1-beta7", + "X-Fern-SDK-Version": "0.0.39", "X-Fern-Runtime": core.RUNTIME.type, "X-Fern-Runtime-Version": core.RUNTIME.version, }, @@ -3254,7 +3254,7 @@ export class GooeyClient { public async lipsyncMakerAsync( request: Gooey.LipsyncTtsPageRequest, requestOptions?: GooeyClient.RequestOptions - ): Promise { + ): Promise { const { exampleId, ..._body } = request; const _queryParams: Record = {}; if (exampleId != null) { @@ -3271,7 +3271,7 @@ export class GooeyClient { Authorization: await this._getAuthorizationHeader(), "X-Fern-Language": "JavaScript", "X-Fern-SDK-Name": "gooeyai", - "X-Fern-SDK-Version": "0.0.1-beta7", + "X-Fern-SDK-Version": "0.0.39", "X-Fern-Runtime": core.RUNTIME.type, "X-Fern-Runtime-Version": core.RUNTIME.version, }, @@ -3284,7 +3284,7 @@ export class GooeyClient { abortSignal: requestOptions?.abortSignal, }); if (_response.ok) { - return serializers.AsyncApiResponseModelV3.parseOrThrow(_response.body, { + return serializers.LipsyncTtsPageResponse.parseOrThrow(_response.body, { unrecognizedObjectKeys: "passthrough", allowUnrecognizedUnionMembers: true, allowUnrecognizedEnumValues: true, @@ -3370,7 +3370,7 @@ export class GooeyClient { Authorization: await this._getAuthorizationHeader(), "X-Fern-Language": "JavaScript", "X-Fern-SDK-Name": "gooeyai", - "X-Fern-SDK-Version": "0.0.1-beta7", + "X-Fern-SDK-Version": "0.0.39", "X-Fern-Runtime": core.RUNTIME.type, "X-Fern-Runtime-Version": core.RUNTIME.version, }, @@ -3454,7 +3454,7 @@ export class GooeyClient { public async compareTextToSpeechEnginesAsync( request: Gooey.TextToSpeechPageRequest, requestOptions?: GooeyClient.RequestOptions - ): Promise { + ): Promise { const { exampleId, ..._body } = request; const _queryParams: Record = {}; if (exampleId != null) { @@ -3471,7 +3471,7 @@ export class GooeyClient { Authorization: await this._getAuthorizationHeader(), "X-Fern-Language": "JavaScript", "X-Fern-SDK-Name": "gooeyai", - "X-Fern-SDK-Version": "0.0.1-beta7", + "X-Fern-SDK-Version": "0.0.39", "X-Fern-Runtime": core.RUNTIME.type, "X-Fern-Runtime-Version": core.RUNTIME.version, }, @@ -3484,7 +3484,7 @@ export class GooeyClient { abortSignal: requestOptions?.abortSignal, }); if (_response.ok) { - return serializers.AsyncApiResponseModelV3.parseOrThrow(_response.body, { + return serializers.TextToSpeechPageResponse.parseOrThrow(_response.body, { unrecognizedObjectKeys: "passthrough", allowUnrecognizedUnionMembers: true, allowUnrecognizedEnumValues: true, @@ -3570,7 +3570,7 @@ export class GooeyClient { Authorization: await this._getAuthorizationHeader(), "X-Fern-Language": "JavaScript", "X-Fern-SDK-Name": "gooeyai", - "X-Fern-SDK-Version": "0.0.1-beta7", + "X-Fern-SDK-Version": "0.0.39", "X-Fern-Runtime": core.RUNTIME.type, "X-Fern-Runtime-Version": core.RUNTIME.version, }, @@ -3654,7 +3654,7 @@ export class GooeyClient { public async speechAsync( request: Gooey.AsrPageRequest, requestOptions?: GooeyClient.RequestOptions - ): Promise { + ): Promise { const { exampleId, ..._body } = request; const _queryParams: Record = {}; if (exampleId != null) { @@ -3671,7 +3671,7 @@ export class GooeyClient { Authorization: await this._getAuthorizationHeader(), "X-Fern-Language": "JavaScript", "X-Fern-SDK-Name": "gooeyai", - "X-Fern-SDK-Version": "0.0.1-beta7", + "X-Fern-SDK-Version": "0.0.39", "X-Fern-Runtime": core.RUNTIME.type, "X-Fern-Runtime-Version": core.RUNTIME.version, }, @@ -3684,7 +3684,7 @@ export class GooeyClient { abortSignal: requestOptions?.abortSignal, }); if (_response.ok) { - return serializers.AsyncApiResponseModelV3.parseOrThrow(_response.body, { + return serializers.AsrPageResponse.parseOrThrow(_response.body, { unrecognizedObjectKeys: "passthrough", allowUnrecognizedUnionMembers: true, allowUnrecognizedEnumValues: true, @@ -3770,7 +3770,7 @@ export class GooeyClient { Authorization: await this._getAuthorizationHeader(), "X-Fern-Language": "JavaScript", "X-Fern-SDK-Name": "gooeyai", - "X-Fern-SDK-Version": "0.0.1-beta7", + "X-Fern-SDK-Version": "0.0.39", "X-Fern-Runtime": core.RUNTIME.type, "X-Fern-Runtime-Version": core.RUNTIME.version, }, @@ -3854,7 +3854,7 @@ export class GooeyClient { public async text2AudioAsync( request: Gooey.Text2AudioPageRequest, requestOptions?: GooeyClient.RequestOptions - ): Promise { + ): Promise { const { exampleId, ..._body } = request; const _queryParams: Record = {}; if (exampleId != null) { @@ -3871,7 +3871,7 @@ export class GooeyClient { Authorization: await this._getAuthorizationHeader(), "X-Fern-Language": "JavaScript", "X-Fern-SDK-Name": "gooeyai", - "X-Fern-SDK-Version": "0.0.1-beta7", + "X-Fern-SDK-Version": "0.0.39", "X-Fern-Runtime": core.RUNTIME.type, "X-Fern-Runtime-Version": core.RUNTIME.version, }, @@ -3884,7 +3884,7 @@ export class GooeyClient { abortSignal: requestOptions?.abortSignal, }); if (_response.ok) { - return serializers.AsyncApiResponseModelV3.parseOrThrow(_response.body, { + return serializers.Text2AudioPageResponse.parseOrThrow(_response.body, { unrecognizedObjectKeys: "passthrough", allowUnrecognizedUnionMembers: true, allowUnrecognizedEnumValues: true, @@ -3970,7 +3970,7 @@ export class GooeyClient { Authorization: await this._getAuthorizationHeader(), "X-Fern-Language": "JavaScript", "X-Fern-SDK-Name": "gooeyai", - "X-Fern-SDK-Version": "0.0.1-beta7", + "X-Fern-SDK-Version": "0.0.39", "X-Fern-Runtime": core.RUNTIME.type, "X-Fern-Runtime-Version": core.RUNTIME.version, }, @@ -4052,7 +4052,7 @@ export class GooeyClient { public async compareAiTranslationAsync( request: Gooey.TranslationPageRequest = {}, requestOptions?: GooeyClient.RequestOptions - ): Promise { + ): Promise { const { exampleId, ..._body } = request; const _queryParams: Record = {}; if (exampleId != null) { @@ -4069,7 +4069,7 @@ export class GooeyClient { Authorization: await this._getAuthorizationHeader(), "X-Fern-Language": "JavaScript", "X-Fern-SDK-Name": "gooeyai", - "X-Fern-SDK-Version": "0.0.1-beta7", + "X-Fern-SDK-Version": "0.0.39", "X-Fern-Runtime": core.RUNTIME.type, "X-Fern-Runtime-Version": core.RUNTIME.version, }, @@ -4082,7 +4082,7 @@ export class GooeyClient { abortSignal: requestOptions?.abortSignal, }); if (_response.ok) { - return serializers.AsyncApiResponseModelV3.parseOrThrow(_response.body, { + return serializers.TranslationPageResponse.parseOrThrow(_response.body, { unrecognizedObjectKeys: "passthrough", allowUnrecognizedUnionMembers: true, allowUnrecognizedEnumValues: true, @@ -4168,7 +4168,7 @@ export class GooeyClient { Authorization: await this._getAuthorizationHeader(), "X-Fern-Language": "JavaScript", "X-Fern-SDK-Name": "gooeyai", - "X-Fern-SDK-Version": "0.0.1-beta7", + "X-Fern-SDK-Version": "0.0.39", "X-Fern-Runtime": core.RUNTIME.type, "X-Fern-Runtime-Version": core.RUNTIME.version, }, @@ -4237,7 +4237,7 @@ export class GooeyClient { } /** - * @param {Gooey.Img2ImgPageRequest} request + * @param {Gooey.AiPhotoEditorAsyncRequest} request * @param {GooeyClient.RequestOptions} requestOptions - Request-specific configuration. * * @throws {@link Gooey.PaymentRequiredError} @@ -4246,14 +4246,16 @@ export class GooeyClient { * * @example * await client.aiPhotoEditorAsync({ - * inputImage: "input_image" + * body: { + * inputImage: "input_image" + * } * }) */ public async aiPhotoEditorAsync( - request: Gooey.Img2ImgPageRequest, + request: Gooey.AiPhotoEditorAsyncRequest, requestOptions?: GooeyClient.RequestOptions - ): Promise { - const { exampleId, ..._body } = request; + ): Promise { + const { exampleId, body: _body } = request; const _queryParams: Record = {}; if (exampleId != null) { _queryParams["example_id"] = exampleId; @@ -4269,7 +4271,7 @@ export class GooeyClient { Authorization: await this._getAuthorizationHeader(), "X-Fern-Language": "JavaScript", "X-Fern-SDK-Name": "gooeyai", - "X-Fern-SDK-Version": "0.0.1-beta7", + "X-Fern-SDK-Version": "0.0.39", "X-Fern-Runtime": core.RUNTIME.type, "X-Fern-Runtime-Version": core.RUNTIME.version, }, @@ -4282,7 +4284,7 @@ export class GooeyClient { abortSignal: requestOptions?.abortSignal, }); if (_response.ok) { - return serializers.AsyncApiResponseModelV3.parseOrThrow(_response.body, { + return serializers.Img2ImgPageResponse.parseOrThrow(_response.body, { unrecognizedObjectKeys: "passthrough", allowUnrecognizedUnionMembers: true, allowUnrecognizedEnumValues: true, @@ -4368,7 +4370,7 @@ export class GooeyClient { Authorization: await this._getAuthorizationHeader(), "X-Fern-Language": "JavaScript", "X-Fern-SDK-Name": "gooeyai", - "X-Fern-SDK-Version": "0.0.1-beta7", + "X-Fern-SDK-Version": "0.0.39", "X-Fern-Runtime": core.RUNTIME.type, "X-Fern-Runtime-Version": core.RUNTIME.version, }, @@ -4437,7 +4439,7 @@ export class GooeyClient { } /** - * @param {Gooey.CompareText2ImgPageRequest} request + * @param {Gooey.CompareAiImageGeneratorsAsyncRequest} request * @param {GooeyClient.RequestOptions} requestOptions - Request-specific configuration. * * @throws {@link Gooey.PaymentRequiredError} @@ -4446,14 +4448,16 @@ export class GooeyClient { * * @example * await client.compareAiImageGeneratorsAsync({ - * textPrompt: "text_prompt" + * body: { + * inputImage: "input_image" + * } * }) */ public async compareAiImageGeneratorsAsync( - request: Gooey.CompareText2ImgPageRequest, + request: Gooey.CompareAiImageGeneratorsAsyncRequest, requestOptions?: GooeyClient.RequestOptions - ): Promise { - const { exampleId, ..._body } = request; + ): Promise { + const { exampleId, body: _body } = request; const _queryParams: Record = {}; if (exampleId != null) { _queryParams["example_id"] = exampleId; @@ -4469,20 +4473,20 @@ export class GooeyClient { Authorization: await this._getAuthorizationHeader(), "X-Fern-Language": "JavaScript", "X-Fern-SDK-Name": "gooeyai", - "X-Fern-SDK-Version": "0.0.1-beta7", + "X-Fern-SDK-Version": "0.0.39", "X-Fern-Runtime": core.RUNTIME.type, "X-Fern-Runtime-Version": core.RUNTIME.version, }, contentType: "application/json", queryParameters: _queryParams, requestType: "json", - body: serializers.CompareText2ImgPageRequest.jsonOrThrow(_body, { unrecognizedObjectKeys: "strip" }), + body: serializers.Img2ImgPageRequest.jsonOrThrow(_body, { unrecognizedObjectKeys: "strip" }), timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, maxRetries: requestOptions?.maxRetries, abortSignal: requestOptions?.abortSignal, }); if (_response.ok) { - return serializers.AsyncApiResponseModelV3.parseOrThrow(_response.body, { + return serializers.Img2ImgPageResponse.parseOrThrow(_response.body, { unrecognizedObjectKeys: "passthrough", allowUnrecognizedUnionMembers: true, allowUnrecognizedEnumValues: true, @@ -4568,7 +4572,7 @@ export class GooeyClient { Authorization: await this._getAuthorizationHeader(), "X-Fern-Language": "JavaScript", "X-Fern-SDK-Name": "gooeyai", - "X-Fern-SDK-Version": "0.0.1-beta7", + "X-Fern-SDK-Version": "0.0.39", "X-Fern-Runtime": core.RUNTIME.type, "X-Fern-Runtime-Version": core.RUNTIME.version, }, @@ -4653,7 +4657,7 @@ export class GooeyClient { public async productPhotoBackgroundGeneratorAsync( request: Gooey.ObjectInpaintingPageRequest, requestOptions?: GooeyClient.RequestOptions - ): Promise { + ): Promise { const { exampleId, ..._body } = request; const _queryParams: Record = {}; if (exampleId != null) { @@ -4670,7 +4674,7 @@ export class GooeyClient { Authorization: await this._getAuthorizationHeader(), "X-Fern-Language": "JavaScript", "X-Fern-SDK-Name": "gooeyai", - "X-Fern-SDK-Version": "0.0.1-beta7", + "X-Fern-SDK-Version": "0.0.39", "X-Fern-Runtime": core.RUNTIME.type, "X-Fern-Runtime-Version": core.RUNTIME.version, }, @@ -4683,7 +4687,7 @@ export class GooeyClient { abortSignal: requestOptions?.abortSignal, }); if (_response.ok) { - return serializers.AsyncApiResponseModelV3.parseOrThrow(_response.body, { + return serializers.ObjectInpaintingPageResponse.parseOrThrow(_response.body, { unrecognizedObjectKeys: "passthrough", allowUnrecognizedUnionMembers: true, allowUnrecognizedEnumValues: true, @@ -4769,7 +4773,7 @@ export class GooeyClient { Authorization: await this._getAuthorizationHeader(), "X-Fern-Language": "JavaScript", "X-Fern-SDK-Name": "gooeyai", - "X-Fern-SDK-Version": "0.0.1-beta7", + "X-Fern-SDK-Version": "0.0.39", "X-Fern-Runtime": core.RUNTIME.type, "X-Fern-Runtime-Version": core.RUNTIME.version, }, @@ -4854,7 +4858,7 @@ export class GooeyClient { public async faceInAiGeneratedPhotoAsync( request: Gooey.FaceInpaintingPageRequest, requestOptions?: GooeyClient.RequestOptions - ): Promise { + ): Promise { const { exampleId, ..._body } = request; const _queryParams: Record = {}; if (exampleId != null) { @@ -4871,7 +4875,7 @@ export class GooeyClient { Authorization: await this._getAuthorizationHeader(), "X-Fern-Language": "JavaScript", "X-Fern-SDK-Name": "gooeyai", - "X-Fern-SDK-Version": "0.0.1-beta7", + "X-Fern-SDK-Version": "0.0.39", "X-Fern-Runtime": core.RUNTIME.type, "X-Fern-Runtime-Version": core.RUNTIME.version, }, @@ -4884,7 +4888,7 @@ export class GooeyClient { abortSignal: requestOptions?.abortSignal, }); if (_response.ok) { - return serializers.AsyncApiResponseModelV3.parseOrThrow(_response.body, { + return serializers.FaceInpaintingPageResponse.parseOrThrow(_response.body, { unrecognizedObjectKeys: "passthrough", allowUnrecognizedUnionMembers: true, allowUnrecognizedEnumValues: true, @@ -4970,7 +4974,7 @@ export class GooeyClient { Authorization: await this._getAuthorizationHeader(), "X-Fern-Language": "JavaScript", "X-Fern-SDK-Name": "gooeyai", - "X-Fern-SDK-Version": "0.0.1-beta7", + "X-Fern-SDK-Version": "0.0.39", "X-Fern-Runtime": core.RUNTIME.type, "X-Fern-Runtime-Version": core.RUNTIME.version, }, @@ -5055,7 +5059,7 @@ export class GooeyClient { public async aiImageFromEmailLookupAsync( request: Gooey.EmailFaceInpaintingPageRequest, requestOptions?: GooeyClient.RequestOptions - ): Promise { + ): Promise { const { exampleId, ..._body } = request; const _queryParams: Record = {}; if (exampleId != null) { @@ -5072,7 +5076,7 @@ export class GooeyClient { Authorization: await this._getAuthorizationHeader(), "X-Fern-Language": "JavaScript", "X-Fern-SDK-Name": "gooeyai", - "X-Fern-SDK-Version": "0.0.1-beta7", + "X-Fern-SDK-Version": "0.0.39", "X-Fern-Runtime": core.RUNTIME.type, "X-Fern-Runtime-Version": core.RUNTIME.version, }, @@ -5085,7 +5089,7 @@ export class GooeyClient { abortSignal: requestOptions?.abortSignal, }); if (_response.ok) { - return serializers.AsyncApiResponseModelV3.parseOrThrow(_response.body, { + return serializers.EmailFaceInpaintingPageResponse.parseOrThrow(_response.body, { unrecognizedObjectKeys: "passthrough", allowUnrecognizedUnionMembers: true, allowUnrecognizedEnumValues: true, @@ -5171,7 +5175,7 @@ export class GooeyClient { Authorization: await this._getAuthorizationHeader(), "X-Fern-Language": "JavaScript", "X-Fern-SDK-Name": "gooeyai", - "X-Fern-SDK-Version": "0.0.1-beta7", + "X-Fern-SDK-Version": "0.0.39", "X-Fern-Runtime": core.RUNTIME.type, "X-Fern-Runtime-Version": core.RUNTIME.version, }, @@ -5256,7 +5260,7 @@ export class GooeyClient { public async renderImagesWithAiAsync( request: Gooey.GoogleImageGenPageRequest, requestOptions?: GooeyClient.RequestOptions - ): Promise { + ): Promise { const { exampleId, ..._body } = request; const _queryParams: Record = {}; if (exampleId != null) { @@ -5273,7 +5277,7 @@ export class GooeyClient { Authorization: await this._getAuthorizationHeader(), "X-Fern-Language": "JavaScript", "X-Fern-SDK-Name": "gooeyai", - "X-Fern-SDK-Version": "0.0.1-beta7", + "X-Fern-SDK-Version": "0.0.39", "X-Fern-Runtime": core.RUNTIME.type, "X-Fern-Runtime-Version": core.RUNTIME.version, }, @@ -5286,7 +5290,7 @@ export class GooeyClient { abortSignal: requestOptions?.abortSignal, }); if (_response.ok) { - return serializers.AsyncApiResponseModelV3.parseOrThrow(_response.body, { + return serializers.GoogleImageGenPageResponse.parseOrThrow(_response.body, { unrecognizedObjectKeys: "passthrough", allowUnrecognizedUnionMembers: true, allowUnrecognizedEnumValues: true, @@ -5372,7 +5376,7 @@ export class GooeyClient { Authorization: await this._getAuthorizationHeader(), "X-Fern-Language": "JavaScript", "X-Fern-SDK-Name": "gooeyai", - "X-Fern-SDK-Version": "0.0.1-beta7", + "X-Fern-SDK-Version": "0.0.39", "X-Fern-Runtime": core.RUNTIME.type, "X-Fern-Runtime-Version": core.RUNTIME.version, }, @@ -5456,7 +5460,7 @@ export class GooeyClient { public async removeImageBackgroundWithAiAsync( request: Gooey.ImageSegmentationPageRequest, requestOptions?: GooeyClient.RequestOptions - ): Promise { + ): Promise { const { exampleId, ..._body } = request; const _queryParams: Record = {}; if (exampleId != null) { @@ -5473,7 +5477,7 @@ export class GooeyClient { Authorization: await this._getAuthorizationHeader(), "X-Fern-Language": "JavaScript", "X-Fern-SDK-Name": "gooeyai", - "X-Fern-SDK-Version": "0.0.1-beta7", + "X-Fern-SDK-Version": "0.0.39", "X-Fern-Runtime": core.RUNTIME.type, "X-Fern-Runtime-Version": core.RUNTIME.version, }, @@ -5486,7 +5490,7 @@ export class GooeyClient { abortSignal: requestOptions?.abortSignal, }); if (_response.ok) { - return serializers.AsyncApiResponseModelV3.parseOrThrow(_response.body, { + return serializers.ImageSegmentationPageResponse.parseOrThrow(_response.body, { unrecognizedObjectKeys: "passthrough", allowUnrecognizedUnionMembers: true, allowUnrecognizedEnumValues: true, @@ -5572,7 +5576,7 @@ export class GooeyClient { Authorization: await this._getAuthorizationHeader(), "X-Fern-Language": "JavaScript", "X-Fern-SDK-Name": "gooeyai", - "X-Fern-SDK-Version": "0.0.1-beta7", + "X-Fern-SDK-Version": "0.0.39", "X-Fern-Runtime": core.RUNTIME.type, "X-Fern-Runtime-Version": core.RUNTIME.version, }, @@ -5656,7 +5660,7 @@ export class GooeyClient { public async compareAiUpscalersAsync( request: Gooey.CompareUpscalerPageRequest, requestOptions?: GooeyClient.RequestOptions - ): Promise { + ): Promise { const { exampleId, ..._body } = request; const _queryParams: Record = {}; if (exampleId != null) { @@ -5673,7 +5677,7 @@ export class GooeyClient { Authorization: await this._getAuthorizationHeader(), "X-Fern-Language": "JavaScript", "X-Fern-SDK-Name": "gooeyai", - "X-Fern-SDK-Version": "0.0.1-beta7", + "X-Fern-SDK-Version": "0.0.39", "X-Fern-Runtime": core.RUNTIME.type, "X-Fern-Runtime-Version": core.RUNTIME.version, }, @@ -5686,7 +5690,7 @@ export class GooeyClient { abortSignal: requestOptions?.abortSignal, }); if (_response.ok) { - return serializers.AsyncApiResponseModelV3.parseOrThrow(_response.body, { + return serializers.CompareUpscalerPageResponse.parseOrThrow(_response.body, { unrecognizedObjectKeys: "passthrough", allowUnrecognizedUnionMembers: true, allowUnrecognizedEnumValues: true, @@ -5772,7 +5776,7 @@ export class GooeyClient { Authorization: await this._getAuthorizationHeader(), "X-Fern-Language": "JavaScript", "X-Fern-SDK-Name": "gooeyai", - "X-Fern-SDK-Version": "0.0.1-beta7", + "X-Fern-SDK-Version": "0.0.39", "X-Fern-Runtime": core.RUNTIME.type, "X-Fern-Runtime-Version": core.RUNTIME.version, }, @@ -5856,7 +5860,7 @@ export class GooeyClient { public async chyronPlantAsync( request: Gooey.ChyronPlantPageRequest, requestOptions?: GooeyClient.RequestOptions - ): Promise { + ): Promise { const { exampleId, ..._body } = request; const _queryParams: Record = {}; if (exampleId != null) { @@ -5873,7 +5877,7 @@ export class GooeyClient { Authorization: await this._getAuthorizationHeader(), "X-Fern-Language": "JavaScript", "X-Fern-SDK-Name": "gooeyai", - "X-Fern-SDK-Version": "0.0.1-beta7", + "X-Fern-SDK-Version": "0.0.39", "X-Fern-Runtime": core.RUNTIME.type, "X-Fern-Runtime-Version": core.RUNTIME.version, }, @@ -5886,7 +5890,7 @@ export class GooeyClient { abortSignal: requestOptions?.abortSignal, }); if (_response.ok) { - return serializers.AsyncApiResponseModelV3.parseOrThrow(_response.body, { + return serializers.ChyronPlantPageResponse.parseOrThrow(_response.body, { unrecognizedObjectKeys: "passthrough", allowUnrecognizedUnionMembers: true, allowUnrecognizedEnumValues: true, @@ -5972,7 +5976,7 @@ export class GooeyClient { Authorization: await this._getAuthorizationHeader(), "X-Fern-Language": "JavaScript", "X-Fern-SDK-Name": "gooeyai", - "X-Fern-SDK-Version": "0.0.1-beta7", + "X-Fern-SDK-Version": "0.0.39", "X-Fern-Runtime": core.RUNTIME.type, "X-Fern-Runtime-Version": core.RUNTIME.version, }, @@ -6056,7 +6060,7 @@ export class GooeyClient { public async letterWriterAsync( request: Gooey.LetterWriterPageRequest, requestOptions?: GooeyClient.RequestOptions - ): Promise { + ): Promise { const { exampleId, ..._body } = request; const _queryParams: Record = {}; if (exampleId != null) { @@ -6073,7 +6077,7 @@ export class GooeyClient { Authorization: await this._getAuthorizationHeader(), "X-Fern-Language": "JavaScript", "X-Fern-SDK-Name": "gooeyai", - "X-Fern-SDK-Version": "0.0.1-beta7", + "X-Fern-SDK-Version": "0.0.39", "X-Fern-Runtime": core.RUNTIME.type, "X-Fern-Runtime-Version": core.RUNTIME.version, }, @@ -6086,7 +6090,7 @@ export class GooeyClient { abortSignal: requestOptions?.abortSignal, }); if (_response.ok) { - return serializers.AsyncApiResponseModelV3.parseOrThrow(_response.body, { + return serializers.LetterWriterPageResponse.parseOrThrow(_response.body, { unrecognizedObjectKeys: "passthrough", allowUnrecognizedUnionMembers: true, allowUnrecognizedEnumValues: true, @@ -6172,7 +6176,7 @@ export class GooeyClient { Authorization: await this._getAuthorizationHeader(), "X-Fern-Language": "JavaScript", "X-Fern-SDK-Name": "gooeyai", - "X-Fern-SDK-Version": "0.0.1-beta7", + "X-Fern-SDK-Version": "0.0.39", "X-Fern-Runtime": core.RUNTIME.type, "X-Fern-Runtime-Version": core.RUNTIME.version, }, @@ -6256,7 +6260,7 @@ export class GooeyClient { public async textEmbedingsAsync( request: Gooey.EmbeddingsPageRequest, requestOptions?: GooeyClient.RequestOptions - ): Promise { + ): Promise { const { exampleId, ..._body } = request; const _queryParams: Record = {}; if (exampleId != null) { @@ -6273,7 +6277,7 @@ export class GooeyClient { Authorization: await this._getAuthorizationHeader(), "X-Fern-Language": "JavaScript", "X-Fern-SDK-Name": "gooeyai", - "X-Fern-SDK-Version": "0.0.1-beta7", + "X-Fern-SDK-Version": "0.0.39", "X-Fern-Runtime": core.RUNTIME.type, "X-Fern-Runtime-Version": core.RUNTIME.version, }, @@ -6286,7 +6290,7 @@ export class GooeyClient { abortSignal: requestOptions?.abortSignal, }); if (_response.ok) { - return serializers.AsyncApiResponseModelV3.parseOrThrow(_response.body, { + return serializers.EmbeddingsPageResponse.parseOrThrow(_response.body, { unrecognizedObjectKeys: "passthrough", allowUnrecognizedUnionMembers: true, allowUnrecognizedEnumValues: true, @@ -6372,7 +6376,7 @@ export class GooeyClient { Authorization: await this._getAuthorizationHeader(), "X-Fern-Language": "JavaScript", "X-Fern-SDK-Name": "gooeyai", - "X-Fern-SDK-Version": "0.0.1-beta7", + "X-Fern-SDK-Version": "0.0.39", "X-Fern-Runtime": core.RUNTIME.type, "X-Fern-Runtime-Version": core.RUNTIME.version, }, @@ -6456,7 +6460,7 @@ export class GooeyClient { public async relatedQnaMakerDocAsync( request: Gooey.RelatedQnADocPageRequest, requestOptions?: GooeyClient.RequestOptions - ): Promise { + ): Promise { const { exampleId, ..._body } = request; const _queryParams: Record = {}; if (exampleId != null) { @@ -6473,7 +6477,7 @@ export class GooeyClient { Authorization: await this._getAuthorizationHeader(), "X-Fern-Language": "JavaScript", "X-Fern-SDK-Name": "gooeyai", - "X-Fern-SDK-Version": "0.0.1-beta7", + "X-Fern-SDK-Version": "0.0.39", "X-Fern-Runtime": core.RUNTIME.type, "X-Fern-Runtime-Version": core.RUNTIME.version, }, @@ -6486,7 +6490,7 @@ export class GooeyClient { abortSignal: requestOptions?.abortSignal, }); if (_response.ok) { - return serializers.AsyncApiResponseModelV3.parseOrThrow(_response.body, { + return serializers.RelatedQnADocPageResponse.parseOrThrow(_response.body, { unrecognizedObjectKeys: "passthrough", allowUnrecognizedUnionMembers: true, allowUnrecognizedEnumValues: true, @@ -6572,7 +6576,7 @@ export class GooeyClient { Authorization: await this._getAuthorizationHeader(), "X-Fern-Language": "JavaScript", "X-Fern-SDK-Name": "gooeyai", - "X-Fern-SDK-Version": "0.0.1-beta7", + "X-Fern-SDK-Version": "0.0.39", "X-Fern-Runtime": core.RUNTIME.type, "X-Fern-Runtime-Version": core.RUNTIME.version, }, diff --git a/src/api/client/requests/AiPhotoEditorAsyncRequest.ts b/src/api/client/requests/AiPhotoEditorAsyncRequest.ts new file mode 100644 index 0000000..190c4ec --- /dev/null +++ b/src/api/client/requests/AiPhotoEditorAsyncRequest.ts @@ -0,0 +1,18 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +import * as Gooey from "../../index"; + +/** + * @example + * { + * body: { + * inputImage: "input_image" + * } + * } + */ +export interface AiPhotoEditorAsyncRequest { + exampleId?: string; + body: Gooey.Img2ImgPageRequest; +} diff --git a/src/api/client/requests/CompareAiImageGeneratorsAsyncRequest.ts b/src/api/client/requests/CompareAiImageGeneratorsAsyncRequest.ts new file mode 100644 index 0000000..6d66fc5 --- /dev/null +++ b/src/api/client/requests/CompareAiImageGeneratorsAsyncRequest.ts @@ -0,0 +1,18 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +import * as Gooey from "../../index"; + +/** + * @example + * { + * body: { + * inputImage: "input_image" + * } + * } + */ +export interface CompareAiImageGeneratorsAsyncRequest { + exampleId?: string; + body: Gooey.Img2ImgPageRequest; +} diff --git a/src/api/client/requests/index.ts b/src/api/client/requests/index.ts index 48dfa51..e1d079d 100644 --- a/src/api/client/requests/index.ts +++ b/src/api/client/requests/index.ts @@ -40,9 +40,9 @@ export { type Text2AudioPageRequest } from "./Text2AudioPageRequest"; export { type Text2AudioStatusRequest } from "./Text2AudioStatusRequest"; export { type TranslationPageRequest } from "./TranslationPageRequest"; export { type CompareAiTranslationStatusRequest } from "./CompareAiTranslationStatusRequest"; -export { type Img2ImgPageRequest } from "./Img2ImgPageRequest"; +export { type AiPhotoEditorAsyncRequest } from "./AiPhotoEditorAsyncRequest"; export { type AiPhotoEditorStatusRequest } from "./AiPhotoEditorStatusRequest"; -export { type CompareText2ImgPageRequest } from "./CompareText2ImgPageRequest"; +export { type CompareAiImageGeneratorsAsyncRequest } from "./CompareAiImageGeneratorsAsyncRequest"; export { type CompareAiImageGeneratorsStatusRequest } from "./CompareAiImageGeneratorsStatusRequest"; export { type ObjectInpaintingPageRequest } from "./ObjectInpaintingPageRequest"; export { type ProductPhotoBackgroundGeneratorStatusRequest } from "./ProductPhotoBackgroundGeneratorStatusRequest"; diff --git a/src/api/resources/copilotIntegrations/client/Client.ts b/src/api/resources/copilotIntegrations/client/Client.ts index 8d766b0..0cfeded 100644 --- a/src/api/resources/copilotIntegrations/client/Client.ts +++ b/src/api/resources/copilotIntegrations/client/Client.ts @@ -55,7 +55,7 @@ export class CopilotIntegrations { Authorization: await this._getAuthorizationHeader(), "X-Fern-Language": "JavaScript", "X-Fern-SDK-Name": "gooeyai", - "X-Fern-SDK-Version": "0.0.1-beta7", + "X-Fern-SDK-Version": "0.0.39", "X-Fern-Runtime": core.RUNTIME.type, "X-Fern-Runtime-Version": core.RUNTIME.version, }, @@ -137,7 +137,7 @@ export class CopilotIntegrations { Authorization: await this._getAuthorizationHeader(), "X-Fern-Language": "JavaScript", "X-Fern-SDK-Name": "gooeyai", - "X-Fern-SDK-Version": "0.0.1-beta7", + "X-Fern-SDK-Version": "0.0.39", "X-Fern-Runtime": core.RUNTIME.type, "X-Fern-Runtime-Version": core.RUNTIME.version, }, diff --git a/src/api/resources/misc/client/Client.ts b/src/api/resources/misc/client/Client.ts index c8abe35..d18f714 100644 --- a/src/api/resources/misc/client/Client.ts +++ b/src/api/resources/misc/client/Client.ts @@ -46,7 +46,7 @@ export class Misc { Authorization: await this._getAuthorizationHeader(), "X-Fern-Language": "JavaScript", "X-Fern-SDK-Name": "gooeyai", - "X-Fern-SDK-Version": "0.0.1-beta7", + "X-Fern-SDK-Version": "0.0.39", "X-Fern-Runtime": core.RUNTIME.type, "X-Fern-Runtime-Version": core.RUNTIME.version, }, @@ -123,7 +123,7 @@ export class Misc { Authorization: await this._getAuthorizationHeader(), "X-Fern-Language": "JavaScript", "X-Fern-SDK-Name": "gooeyai", - "X-Fern-SDK-Version": "0.0.1-beta7", + "X-Fern-SDK-Version": "0.0.39", "X-Fern-Runtime": core.RUNTIME.type, "X-Fern-Runtime-Version": core.RUNTIME.version, }, diff --git a/src/api/client/requests/CompareText2ImgPageRequest.ts b/src/api/types/CompareText2ImgPageRequest.ts similarity index 85% rename from src/api/client/requests/CompareText2ImgPageRequest.ts rename to src/api/types/CompareText2ImgPageRequest.ts index b1cfead..bcd1a8c 100644 --- a/src/api/client/requests/CompareText2ImgPageRequest.ts +++ b/src/api/types/CompareText2ImgPageRequest.ts @@ -2,16 +2,9 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as Gooey from "../../index"; +import * as Gooey from "../index"; -/** - * @example - * { - * textPrompt: "text_prompt" - * } - */ export interface CompareText2ImgPageRequest { - exampleId?: string; functions?: Gooey.RecipeFunction[]; /** Variables to be used as Jinja prompt templates and in functions as arguments */ variables?: Record; diff --git a/src/api/client/requests/Img2ImgPageRequest.ts b/src/api/types/Img2ImgPageRequest.ts similarity index 85% rename from src/api/client/requests/Img2ImgPageRequest.ts rename to src/api/types/Img2ImgPageRequest.ts index cd40b2e..252bc47 100644 --- a/src/api/client/requests/Img2ImgPageRequest.ts +++ b/src/api/types/Img2ImgPageRequest.ts @@ -2,16 +2,9 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as Gooey from "../../index"; +import * as Gooey from "../index"; -/** - * @example - * { - * inputImage: "input_image" - * } - */ export interface Img2ImgPageRequest { - exampleId?: string; functions?: Gooey.RecipeFunction[]; /** Variables to be used as Jinja prompt templates and in functions as arguments */ variables?: Record; diff --git a/src/api/types/index.ts b/src/api/types/index.ts index 9988175..3513e5a 100644 --- a/src/api/types/index.ts +++ b/src/api/types/index.ts @@ -52,11 +52,6 @@ export * from "./AsrPageRequestSelectedModel"; export * from "./AsrPageRequestTranslationModel"; export * from "./AsrPageRequestOutputFormat"; export * from "./TranslationPageRequestSelectedModel"; -export * from "./Img2ImgPageRequestSelectedModel"; -export * from "./Img2ImgPageRequestSelectedControlnetModelItem"; -export * from "./Img2ImgPageRequestSelectedControlnetModel"; -export * from "./CompareText2ImgPageRequestSelectedModelsItem"; -export * from "./CompareText2ImgPageRequestScheduler"; export * from "./ObjectInpaintingPageRequestSelectedModel"; export * from "./FaceInpaintingPageRequestSelectedModel"; export * from "./EmailFaceInpaintingPageRequestSelectedModel"; @@ -100,6 +95,9 @@ export * from "./CompareLlmPageOutput"; export * from "./CompareLlmPageResponse"; export * from "./CompareLlmPageStatusResponse"; export * from "./CompareText2ImgPageOutput"; +export * from "./CompareText2ImgPageRequestSelectedModelsItem"; +export * from "./CompareText2ImgPageRequestScheduler"; +export * from "./CompareText2ImgPageRequest"; export * from "./CompareText2ImgPageResponse"; export * from "./CompareText2ImgPageStatusResponse"; export * from "./CompareUpscalerPageOutput"; @@ -156,6 +154,10 @@ export * from "./ImageSegmentationPageStatusResponse"; export * from "./ImageUrlDetail"; export * from "./ImageUrl"; export * from "./Img2ImgPageOutput"; +export * from "./Img2ImgPageRequestSelectedModel"; +export * from "./Img2ImgPageRequestSelectedControlnetModelItem"; +export * from "./Img2ImgPageRequestSelectedControlnetModel"; +export * from "./Img2ImgPageRequest"; export * from "./Img2ImgPageResponse"; export * from "./Img2ImgPageStatusResponse"; export * from "./LlmTools"; diff --git a/src/serialization/client/requests/index.ts b/src/serialization/client/requests/index.ts index 3c08d8d..210acc1 100644 --- a/src/serialization/client/requests/index.ts +++ b/src/serialization/client/requests/index.ts @@ -19,8 +19,6 @@ export { TextToSpeechPageRequest } from "./TextToSpeechPageRequest"; export { AsrPageRequest } from "./AsrPageRequest"; export { Text2AudioPageRequest } from "./Text2AudioPageRequest"; export { TranslationPageRequest } from "./TranslationPageRequest"; -export { Img2ImgPageRequest } from "./Img2ImgPageRequest"; -export { CompareText2ImgPageRequest } from "./CompareText2ImgPageRequest"; export { ObjectInpaintingPageRequest } from "./ObjectInpaintingPageRequest"; export { FaceInpaintingPageRequest } from "./FaceInpaintingPageRequest"; export { EmailFaceInpaintingPageRequest } from "./EmailFaceInpaintingPageRequest"; diff --git a/src/serialization/client/requests/CompareText2ImgPageRequest.ts b/src/serialization/types/CompareText2ImgPageRequest.ts similarity index 82% rename from src/serialization/client/requests/CompareText2ImgPageRequest.ts rename to src/serialization/types/CompareText2ImgPageRequest.ts index 1493079..80bad8b 100644 --- a/src/serialization/client/requests/CompareText2ImgPageRequest.ts +++ b/src/serialization/types/CompareText2ImgPageRequest.ts @@ -2,17 +2,17 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as serializers from "../../index"; -import * as Gooey from "../../../api/index"; -import * as core from "../../../core"; -import { RecipeFunction } from "../../types/RecipeFunction"; -import { CompareText2ImgPageRequestSelectedModelsItem } from "../../types/CompareText2ImgPageRequestSelectedModelsItem"; -import { CompareText2ImgPageRequestScheduler } from "../../types/CompareText2ImgPageRequestScheduler"; -import { RunSettings } from "../../types/RunSettings"; +import * as serializers from "../index"; +import * as Gooey from "../../api/index"; +import * as core from "../../core"; +import { RecipeFunction } from "./RecipeFunction"; +import { CompareText2ImgPageRequestSelectedModelsItem } from "./CompareText2ImgPageRequestSelectedModelsItem"; +import { CompareText2ImgPageRequestScheduler } from "./CompareText2ImgPageRequestScheduler"; +import { RunSettings } from "./RunSettings"; -export const CompareText2ImgPageRequest: core.serialization.Schema< +export const CompareText2ImgPageRequest: core.serialization.ObjectSchema< serializers.CompareText2ImgPageRequest.Raw, - Omit + Gooey.CompareText2ImgPageRequest > = core.serialization.object({ functions: core.serialization.list(RecipeFunction).optional(), variables: core.serialization.record(core.serialization.string(), core.serialization.unknown()).optional(), diff --git a/src/serialization/client/requests/Img2ImgPageRequest.ts b/src/serialization/types/Img2ImgPageRequest.ts similarity index 82% rename from src/serialization/client/requests/Img2ImgPageRequest.ts rename to src/serialization/types/Img2ImgPageRequest.ts index 615030c..0a1f18f 100644 --- a/src/serialization/client/requests/Img2ImgPageRequest.ts +++ b/src/serialization/types/Img2ImgPageRequest.ts @@ -2,17 +2,17 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as serializers from "../../index"; -import * as Gooey from "../../../api/index"; -import * as core from "../../../core"; -import { RecipeFunction } from "../../types/RecipeFunction"; -import { Img2ImgPageRequestSelectedModel } from "../../types/Img2ImgPageRequestSelectedModel"; -import { Img2ImgPageRequestSelectedControlnetModel } from "../../types/Img2ImgPageRequestSelectedControlnetModel"; -import { RunSettings } from "../../types/RunSettings"; +import * as serializers from "../index"; +import * as Gooey from "../../api/index"; +import * as core from "../../core"; +import { RecipeFunction } from "./RecipeFunction"; +import { Img2ImgPageRequestSelectedModel } from "./Img2ImgPageRequestSelectedModel"; +import { Img2ImgPageRequestSelectedControlnetModel } from "./Img2ImgPageRequestSelectedControlnetModel"; +import { RunSettings } from "./RunSettings"; -export const Img2ImgPageRequest: core.serialization.Schema< +export const Img2ImgPageRequest: core.serialization.ObjectSchema< serializers.Img2ImgPageRequest.Raw, - Omit + Gooey.Img2ImgPageRequest > = core.serialization.object({ functions: core.serialization.list(RecipeFunction).optional(), variables: core.serialization.record(core.serialization.string(), core.serialization.unknown()).optional(), diff --git a/src/serialization/types/index.ts b/src/serialization/types/index.ts index 9988175..3513e5a 100644 --- a/src/serialization/types/index.ts +++ b/src/serialization/types/index.ts @@ -52,11 +52,6 @@ export * from "./AsrPageRequestSelectedModel"; export * from "./AsrPageRequestTranslationModel"; export * from "./AsrPageRequestOutputFormat"; export * from "./TranslationPageRequestSelectedModel"; -export * from "./Img2ImgPageRequestSelectedModel"; -export * from "./Img2ImgPageRequestSelectedControlnetModelItem"; -export * from "./Img2ImgPageRequestSelectedControlnetModel"; -export * from "./CompareText2ImgPageRequestSelectedModelsItem"; -export * from "./CompareText2ImgPageRequestScheduler"; export * from "./ObjectInpaintingPageRequestSelectedModel"; export * from "./FaceInpaintingPageRequestSelectedModel"; export * from "./EmailFaceInpaintingPageRequestSelectedModel"; @@ -100,6 +95,9 @@ export * from "./CompareLlmPageOutput"; export * from "./CompareLlmPageResponse"; export * from "./CompareLlmPageStatusResponse"; export * from "./CompareText2ImgPageOutput"; +export * from "./CompareText2ImgPageRequestSelectedModelsItem"; +export * from "./CompareText2ImgPageRequestScheduler"; +export * from "./CompareText2ImgPageRequest"; export * from "./CompareText2ImgPageResponse"; export * from "./CompareText2ImgPageStatusResponse"; export * from "./CompareUpscalerPageOutput"; @@ -156,6 +154,10 @@ export * from "./ImageSegmentationPageStatusResponse"; export * from "./ImageUrlDetail"; export * from "./ImageUrl"; export * from "./Img2ImgPageOutput"; +export * from "./Img2ImgPageRequestSelectedModel"; +export * from "./Img2ImgPageRequestSelectedControlnetModelItem"; +export * from "./Img2ImgPageRequestSelectedControlnetModel"; +export * from "./Img2ImgPageRequest"; export * from "./Img2ImgPageResponse"; export * from "./Img2ImgPageStatusResponse"; export * from "./LlmTools"; diff --git a/tests/unit/auth/BasicAuth.test.ts b/tests/unit/auth/BasicAuth.test.ts new file mode 100644 index 0000000..fc35704 --- /dev/null +++ b/tests/unit/auth/BasicAuth.test.ts @@ -0,0 +1,22 @@ +import { BasicAuth } from "../../../src/core/auth/BasicAuth"; + +describe("BasicAuth", () => { + describe("toAuthorizationHeader", () => { + it("correctly converts to header", () => { + expect( + BasicAuth.toAuthorizationHeader({ + username: "username", + password: "password", + }) + ).toBe("Basic dXNlcm5hbWU6cGFzc3dvcmQ="); + }); + }); + describe("fromAuthorizationHeader", () => { + it("correctly parses header", () => { + expect(BasicAuth.fromAuthorizationHeader("Basic dXNlcm5hbWU6cGFzc3dvcmQ=")).toEqual({ + username: "username", + password: "password", + }); + }); + }); +}); diff --git a/tests/unit/auth/BearerToken.test.ts b/tests/unit/auth/BearerToken.test.ts new file mode 100644 index 0000000..7757b87 --- /dev/null +++ b/tests/unit/auth/BearerToken.test.ts @@ -0,0 +1,14 @@ +import { BearerToken } from "../../../src/core/auth/BearerToken"; + +describe("BearerToken", () => { + describe("toAuthorizationHeader", () => { + it("correctly converts to header", () => { + expect(BearerToken.toAuthorizationHeader("my-token")).toBe("Bearer my-token"); + }); + }); + describe("fromAuthorizationHeader", () => { + it("correctly parses header", () => { + expect(BearerToken.fromAuthorizationHeader("Bearer my-token")).toBe("my-token"); + }); + }); +}); diff --git a/tests/unit/fetcher/Fetcher.test.ts b/tests/unit/fetcher/Fetcher.test.ts new file mode 100644 index 0000000..db04526 --- /dev/null +++ b/tests/unit/fetcher/Fetcher.test.ts @@ -0,0 +1,47 @@ +import { Fetcher, fetcherImpl } from "../../../src/core/fetcher/Fetcher"; + +describe("Test fetcherImpl", () => { + let mockCreateUrl: jest.Mock; + let mockGetBody: jest.Mock; + let mockGetFetchFn: jest.Mock; + let mockRequestWithRetries: jest.Mock; + let mockGetResponseBody: jest.Mock; + + beforeEach(() => { + mockCreateUrl = jest.fn(); + mockGetBody = jest.fn(); + mockGetFetchFn = jest.fn(); + mockRequestWithRetries = jest.fn(); + mockGetResponseBody = jest.fn(); + + jest.mock("../../../src/core/fetcher/Fetcher", () => ({ + createUrl: mockCreateUrl, + getBody: mockGetBody, + getFetchFn: mockGetFetchFn, + requestWithRetries: mockRequestWithRetries, + getResponseBody: mockGetResponseBody, + })); + }); + + it("should handle successful request", async () => { + const mockArgs: Fetcher.Args = { + url: "https://httpbin.org/post", + method: "POST", + headers: { "X-Test": "x-test-header" }, + body: { data: "test" }, + contentType: "application/json", + requestType: "json", + }; + + mockCreateUrl.mockReturnValue("https://test.com"); + mockGetBody.mockResolvedValue(JSON.stringify({ data: "test" })); + mockGetFetchFn.mockResolvedValue(() => Promise.resolve()); + mockRequestWithRetries.mockResolvedValue({ status: 200 }); + mockGetResponseBody.mockResolvedValue({ result: "success" }); + + const result = await fetcherImpl(mockArgs); + expect(result.ok).toBe(true); + // @ts-expect-error + expect(result.body.json).toEqual({ data: "test" }); + }); +}); diff --git a/tests/unit/fetcher/createRequestUrl.test.ts b/tests/unit/fetcher/createRequestUrl.test.ts new file mode 100644 index 0000000..f2cd24b --- /dev/null +++ b/tests/unit/fetcher/createRequestUrl.test.ts @@ -0,0 +1,51 @@ +import { createRequestUrl } from "../../../src/core/fetcher/createRequestUrl"; + +describe("Test createRequestUrl", () => { + it("should return the base URL when no query parameters are provided", () => { + const baseUrl = "https://api.example.com"; + expect(createRequestUrl(baseUrl)).toBe(baseUrl); + }); + + it("should append simple query parameters", () => { + const baseUrl = "https://api.example.com"; + const queryParams = { key: "value", another: "param" }; + expect(createRequestUrl(baseUrl, queryParams)).toBe("https://api.example.com?key=value&another=param"); + }); + + it("should handle array query parameters", () => { + const baseUrl = "https://api.example.com"; + const queryParams = { items: ["a", "b", "c"] }; + expect(createRequestUrl(baseUrl, queryParams)).toBe("https://api.example.com?items=a&items=b&items=c"); + }); + + it("should handle object query parameters", () => { + const baseUrl = "https://api.example.com"; + const queryParams = { filter: { name: "John", age: 30 } }; + expect(createRequestUrl(baseUrl, queryParams)).toBe( + "https://api.example.com?filter%5Bname%5D=John&filter%5Bage%5D=30" + ); + }); + + it("should handle mixed types of query parameters", () => { + const baseUrl = "https://api.example.com"; + const queryParams = { + simple: "value", + array: ["x", "y"], + object: { key: "value" }, + }; + expect(createRequestUrl(baseUrl, queryParams)).toBe( + "https://api.example.com?simple=value&array=x&array=y&object%5Bkey%5D=value" + ); + }); + + it("should handle empty query parameters object", () => { + const baseUrl = "https://api.example.com"; + expect(createRequestUrl(baseUrl, {})).toBe(baseUrl); + }); + + it("should encode special characters in query parameters", () => { + const baseUrl = "https://api.example.com"; + const queryParams = { special: "a&b=c d" }; + expect(createRequestUrl(baseUrl, queryParams)).toBe("https://api.example.com?special=a%26b%3Dc%20d"); + }); +}); diff --git a/tests/unit/fetcher/getFetchFn.test.ts b/tests/unit/fetcher/getFetchFn.test.ts new file mode 100644 index 0000000..9b315ad --- /dev/null +++ b/tests/unit/fetcher/getFetchFn.test.ts @@ -0,0 +1,22 @@ +import { RUNTIME } from "../../../src/core/runtime"; +import { getFetchFn } from "../../../src/core/fetcher/getFetchFn"; + +describe("Test for getFetchFn", () => { + it("should get node-fetch function", async () => { + if (RUNTIME.type == "node") { + if (RUNTIME.parsedVersion != null && RUNTIME.parsedVersion >= 18) { + expect(await getFetchFn()).toBe(fetch); + } else { + expect(await getFetchFn()).toEqual((await import("node-fetch")).default as any); + } + } + }); + + it("should get fetch function", async () => { + if (RUNTIME.type == "browser") { + const fetchFn = await getFetchFn(); + expect(typeof fetchFn).toBe("function"); + expect(fetchFn.name).toBe("fetch"); + } + }); +}); diff --git a/tests/unit/fetcher/getRequestBody.test.ts b/tests/unit/fetcher/getRequestBody.test.ts new file mode 100644 index 0000000..1b1462c --- /dev/null +++ b/tests/unit/fetcher/getRequestBody.test.ts @@ -0,0 +1,81 @@ +import { RUNTIME } from "../../../src/core/runtime"; +import { getRequestBody } from "../../../src/core/fetcher/getRequestBody"; + +if (RUNTIME.type === "browser") { + require("jest-fetch-mock").enableMocks(); +} + +describe("Test getRequestBody", () => { + it("should return FormData as is in Node environment", async () => { + if (RUNTIME.type === "node") { + const formData = new (await import("formdata-node")).FormData(); + formData.append("key", "value"); + const result = await getRequestBody({ + body: formData, + type: "file", + }); + expect(result).toBe(formData); + } + }); + + it("should stringify body if not FormData in Node environment", async () => { + if (RUNTIME.type === "node") { + const body = { key: "value" }; + const result = await getRequestBody({ + body, + type: "json", + }); + expect(result).toBe('{"key":"value"}'); + } + }); + + it("should return FormData in browser environment", async () => { + if (RUNTIME.type === "browser") { + const formData = new (await import("form-data")).default(); + formData.append("key", "value"); + const result = await getRequestBody({ + body: formData, + type: "file", + }); + expect(result).toBe(formData); + } + }); + + it("should stringify body if not FormData in browser environment", async () => { + if (RUNTIME.type === "browser") { + const body = { key: "value" }; + const result = await getRequestBody({ + body, + type: "json", + }); + expect(result).toBe('{"key":"value"}'); + } + }); + + it("should return the Uint8Array", async () => { + const input = new Uint8Array([1, 2, 3]); + const result = await getRequestBody({ + body: input, + type: "bytes", + }); + expect(result).toBe(input); + }); + + it("should return the input for content-type 'application/x-www-form-urlencoded'", async () => { + const input = "key=value&another=param"; + const result = await getRequestBody({ + body: input, + type: "other", + }); + expect(result).toBe(input); + }); + + it("should JSON stringify objects", async () => { + const input = { key: "value" }; + const result = await getRequestBody({ + body: input, + type: "json", + }); + expect(result).toBe('{"key":"value"}'); + }); +}); diff --git a/tests/unit/fetcher/getResponseBody.test.ts b/tests/unit/fetcher/getResponseBody.test.ts new file mode 100644 index 0000000..f3563ff --- /dev/null +++ b/tests/unit/fetcher/getResponseBody.test.ts @@ -0,0 +1,57 @@ +import { RUNTIME } from "../../../src/core/runtime"; +import { getResponseBody } from "../../../src/core/fetcher/getResponseBody"; + +if (RUNTIME.type === "browser") { + require("jest-fetch-mock").enableMocks(); +} + +describe("Test getResponseBody", () => { + it("should handle blob response type", async () => { + const mockBlob = new Blob(["test"], { type: "text/plain" }); + const mockResponse = new Response(mockBlob); + const result = await getResponseBody(mockResponse, "blob"); + // @ts-expect-error + expect(result.constructor.name).toBe("Blob"); + }); + + it("should handle streaming response type", async () => { + if (RUNTIME.type === "node") { + const mockStream = new ReadableStream(); + const mockResponse = new Response(mockStream); + const result = await getResponseBody(mockResponse, "streaming"); + expect(result).toBe(mockStream); + } + }); + + it("should handle text response type", async () => { + const mockResponse = new Response("test text"); + const result = await getResponseBody(mockResponse, "text"); + expect(result).toBe("test text"); + }); + + it("should handle JSON response", async () => { + const mockJson = { key: "value" }; + const mockResponse = new Response(JSON.stringify(mockJson)); + const result = await getResponseBody(mockResponse); + expect(result).toEqual(mockJson); + }); + + it("should handle empty response", async () => { + const mockResponse = new Response(""); + const result = await getResponseBody(mockResponse); + expect(result).toBeUndefined(); + }); + + it("should handle non-JSON response", async () => { + const mockResponse = new Response("invalid json"); + const result = await getResponseBody(mockResponse); + expect(result).toEqual({ + ok: false, + error: { + reason: "non-json", + statusCode: 200, + rawBody: "invalid json", + }, + }); + }); +}); diff --git a/tests/unit/fetcher/makeRequest.test.ts b/tests/unit/fetcher/makeRequest.test.ts new file mode 100644 index 0000000..5969d51 --- /dev/null +++ b/tests/unit/fetcher/makeRequest.test.ts @@ -0,0 +1,58 @@ +import { RUNTIME } from "../../../src/core/runtime"; +import { makeRequest } from "../../../src/core/fetcher/makeRequest"; + +if (RUNTIME.type === "browser") { + require("jest-fetch-mock").enableMocks(); +} + +describe("Test makeRequest", () => { + const mockPostUrl = "https://httpbin.org/post"; + const mockGetUrl = "https://httpbin.org/get"; + const mockHeaders = { "Content-Type": "application/json" }; + const mockBody = JSON.stringify({ key: "value" }); + + let mockFetch: jest.Mock; + + beforeEach(() => { + mockFetch = jest.fn(); + mockFetch.mockResolvedValue(new Response(JSON.stringify({ test: "successful" }), { status: 200 })); + }); + + it("should handle POST request correctly", async () => { + const response = await makeRequest(mockFetch, mockPostUrl, "POST", mockHeaders, mockBody); + const responseBody = await response.json(); + expect(responseBody).toEqual({ test: "successful" }); + expect(mockFetch).toHaveBeenCalledTimes(1); + const [calledUrl, calledOptions] = mockFetch.mock.calls[0]; + expect(calledUrl).toBe(mockPostUrl); + expect(calledOptions).toEqual( + expect.objectContaining({ + method: "POST", + headers: mockHeaders, + body: mockBody, + credentials: undefined, + }) + ); + expect(calledOptions.signal).toBeDefined(); + expect(calledOptions.signal).toBeInstanceOf(AbortSignal); + }); + + it("should handle GET request correctly", async () => { + const response = await makeRequest(mockFetch, mockGetUrl, "GET", mockHeaders, undefined); + const responseBody = await response.json(); + expect(responseBody).toEqual({ test: "successful" }); + expect(mockFetch).toHaveBeenCalledTimes(1); + const [calledUrl, calledOptions] = mockFetch.mock.calls[0]; + expect(calledUrl).toBe(mockGetUrl); + expect(calledOptions).toEqual( + expect.objectContaining({ + method: "GET", + headers: mockHeaders, + body: undefined, + credentials: undefined, + }) + ); + expect(calledOptions.signal).toBeDefined(); + expect(calledOptions.signal).toBeInstanceOf(AbortSignal); + }); +}); diff --git a/tests/unit/fetcher/requestWithRetries.test.ts b/tests/unit/fetcher/requestWithRetries.test.ts new file mode 100644 index 0000000..b53e043 --- /dev/null +++ b/tests/unit/fetcher/requestWithRetries.test.ts @@ -0,0 +1,85 @@ +import { RUNTIME } from "../../../src/core/runtime"; +import { requestWithRetries } from "../../../src/core/fetcher/requestWithRetries"; + +if (RUNTIME.type === "browser") { + require("jest-fetch-mock").enableMocks(); +} + +describe("Test exponential backoff", () => { + let mockFetch: jest.Mock; + let originalSetTimeout: typeof setTimeout; + + beforeEach(() => { + mockFetch = jest.fn(); + originalSetTimeout = global.setTimeout; + jest.useFakeTimers(); + }); + + afterEach(() => { + jest.useRealTimers(); + global.setTimeout = originalSetTimeout; + }); + + it("should retry on 408, 409, 429, 500+", async () => { + mockFetch + .mockResolvedValueOnce(new Response("", { status: 408 })) + .mockResolvedValueOnce(new Response("", { status: 409 })) + .mockResolvedValueOnce(new Response("", { status: 429 })) + .mockResolvedValueOnce(new Response("", { status: 500 })) + .mockResolvedValueOnce(new Response("", { status: 502 })) + .mockResolvedValueOnce(new Response("", { status: 200 })) + .mockResolvedValueOnce(new Response("", { status: 408 })); + + const responsePromise = requestWithRetries(() => mockFetch(), 10); + + await jest.advanceTimersByTimeAsync(10000); + const response = await responsePromise; + + expect(mockFetch).toHaveBeenCalledTimes(6); + expect(response.status).toBe(200); + }); + + it("should retry max 3 times", async () => { + mockFetch + .mockResolvedValueOnce(new Response("", { status: 408 })) + .mockResolvedValueOnce(new Response("", { status: 409 })) + .mockResolvedValueOnce(new Response("", { status: 429 })) + .mockResolvedValueOnce(new Response("", { status: 429 })); + + const responsePromise = requestWithRetries(() => mockFetch(), 3); + + await jest.advanceTimersByTimeAsync(10000); + const response = await responsePromise; + + expect(mockFetch).toHaveBeenCalledTimes(4); + expect(response.status).toBe(429); + }); + it("should not retry on 200", async () => { + mockFetch + .mockResolvedValueOnce(new Response("", { status: 200 })) + .mockResolvedValueOnce(new Response("", { status: 409 })); + + const responsePromise = requestWithRetries(() => mockFetch(), 3); + + await jest.advanceTimersByTimeAsync(10000); + const response = await responsePromise; + + expect(mockFetch).toHaveBeenCalledTimes(1); + expect(response.status).toBe(200); + }); + + it("should retry with exponential backoff timing", async () => { + mockFetch.mockResolvedValue(new Response("", { status: 500 })); + const maxRetries = 7; + const responsePromise = requestWithRetries(() => mockFetch(), maxRetries); + expect(mockFetch).toHaveBeenCalledTimes(1); + + const delays = [1, 2, 4, 8, 16, 32, 64]; + for (let i = 0; i < delays.length; i++) { + await jest.advanceTimersByTimeAsync(delays[i] as number); + expect(mockFetch).toHaveBeenCalledTimes(Math.min(i + 2, maxRetries + 1)); + } + const response = await responsePromise; + expect(response.status).toBe(500); + }); +}); diff --git a/tests/unit/fetcher/signals.test.ts b/tests/unit/fetcher/signals.test.ts new file mode 100644 index 0000000..9cabfa0 --- /dev/null +++ b/tests/unit/fetcher/signals.test.ts @@ -0,0 +1,69 @@ +import { anySignal, getTimeoutSignal } from "../../../src/core/fetcher/signals"; + +describe("Test getTimeoutSignal", () => { + beforeEach(() => { + jest.useFakeTimers(); + }); + + afterEach(() => { + jest.useRealTimers(); + }); + + it("should return an object with signal and abortId", () => { + const { signal, abortId } = getTimeoutSignal(1000); + + expect(signal).toBeDefined(); + expect(abortId).toBeDefined(); + expect(signal).toBeInstanceOf(AbortSignal); + expect(signal.aborted).toBe(false); + }); + + it("should create a signal that aborts after the specified timeout", () => { + const timeoutMs = 5000; + const { signal } = getTimeoutSignal(timeoutMs); + + expect(signal.aborted).toBe(false); + + jest.advanceTimersByTime(timeoutMs - 1); + expect(signal.aborted).toBe(false); + + jest.advanceTimersByTime(1); + expect(signal.aborted).toBe(true); + }); +}); + +describe("Test anySignal", () => { + it("should return an AbortSignal", () => { + const signal = anySignal(new AbortController().signal); + expect(signal).toBeInstanceOf(AbortSignal); + }); + + it("should abort when any of the input signals is aborted", () => { + const controller1 = new AbortController(); + const controller2 = new AbortController(); + const signal = anySignal(controller1.signal, controller2.signal); + + expect(signal.aborted).toBe(false); + controller1.abort(); + expect(signal.aborted).toBe(true); + }); + + it("should handle an array of signals", () => { + const controller1 = new AbortController(); + const controller2 = new AbortController(); + const signal = anySignal([controller1.signal, controller2.signal]); + + expect(signal.aborted).toBe(false); + controller2.abort(); + expect(signal.aborted).toBe(true); + }); + + it("should abort immediately if one of the input signals is already aborted", () => { + const controller1 = new AbortController(); + const controller2 = new AbortController(); + controller1.abort(); + + const signal = anySignal(controller1.signal, controller2.signal); + expect(signal.aborted).toBe(true); + }); +}); diff --git a/tests/unit/zurg/date/date.test.ts b/tests/unit/zurg/date/date.test.ts new file mode 100644 index 0000000..2790268 --- /dev/null +++ b/tests/unit/zurg/date/date.test.ts @@ -0,0 +1,31 @@ +import { date } from "../../../../src/core/schemas/builders/date"; +import { itSchema } from "../utils/itSchema"; +import { itValidateJson, itValidateParse } from "../utils/itValidate"; + +describe("date", () => { + itSchema("converts between raw ISO string and parsed Date", date(), { + raw: "2022-09-29T05:41:21.939Z", + parsed: new Date("2022-09-29T05:41:21.939Z"), + }); + + itValidateParse("non-string", date(), 42, [ + { + message: "Expected string. Received 42.", + path: [], + }, + ]); + + itValidateParse("non-ISO", date(), "hello world", [ + { + message: 'Expected ISO 8601 date string. Received "hello world".', + path: [], + }, + ]); + + itValidateJson("non-Date", date(), "hello", [ + { + message: 'Expected Date object. Received "hello".', + path: [], + }, + ]); +}); diff --git a/tests/unit/zurg/enum/enum.test.ts b/tests/unit/zurg/enum/enum.test.ts new file mode 100644 index 0000000..ab0df02 --- /dev/null +++ b/tests/unit/zurg/enum/enum.test.ts @@ -0,0 +1,30 @@ +import { enum_ } from "../../../../src/core/schemas/builders/enum"; +import { itSchemaIdentity } from "../utils/itSchema"; +import { itValidate } from "../utils/itValidate"; + +describe("enum", () => { + itSchemaIdentity(enum_(["A", "B", "C"]), "A"); + + itSchemaIdentity(enum_(["A", "B", "C"]), "D" as any, { + opts: { allowUnrecognizedEnumValues: true }, + }); + + itValidate("invalid enum", enum_(["A", "B", "C"]), "D", [ + { + message: 'Expected enum. Received "D".', + path: [], + }, + ]); + + itValidate( + "non-string", + enum_(["A", "B", "C"]), + [], + [ + { + message: "Expected string. Received list.", + path: [], + }, + ] + ); +}); diff --git a/tests/unit/zurg/lazy/lazy.test.ts b/tests/unit/zurg/lazy/lazy.test.ts new file mode 100644 index 0000000..6906bf4 --- /dev/null +++ b/tests/unit/zurg/lazy/lazy.test.ts @@ -0,0 +1,57 @@ +import { Schema } from "../../../../src/core/schemas/Schema"; +import { lazy, list, object, string } from "../../../../src/core/schemas/builders"; +import { itSchemaIdentity } from "../utils/itSchema"; + +describe("lazy", () => { + it("doesn't run immediately", () => { + let wasRun = false; + lazy(() => { + wasRun = true; + return string(); + }); + expect(wasRun).toBe(false); + }); + + it("only runs first time", async () => { + let count = 0; + const schema = lazy(() => { + count++; + return string(); + }); + await schema.parse("hello"); + await schema.json("world"); + expect(count).toBe(1); + }); + + itSchemaIdentity( + lazy(() => object({})), + { foo: "hello" }, + { + title: "passes opts through", + opts: { unrecognizedObjectKeys: "passthrough" }, + } + ); + + itSchemaIdentity( + lazy(() => object({ foo: string() })), + { foo: "hello" } + ); + + // eslint-disable-next-line jest/expect-expect + it("self-referencial schema doesn't compile", () => { + () => { + // @ts-expect-error + const a = lazy(() => object({ foo: a })); + }; + }); + + // eslint-disable-next-line jest/expect-expect + it("self-referencial compiles with explicit type", () => { + () => { + interface TreeNode { + children: TreeNode[]; + } + const TreeNode: Schema = lazy(() => object({ children: list(TreeNode) })); + }; + }); +}); diff --git a/tests/unit/zurg/lazy/lazyObject.test.ts b/tests/unit/zurg/lazy/lazyObject.test.ts new file mode 100644 index 0000000..8813cc9 --- /dev/null +++ b/tests/unit/zurg/lazy/lazyObject.test.ts @@ -0,0 +1,18 @@ +import { lazyObject, number, object, string } from "../../../../src/core/schemas/builders"; +import { itSchemaIdentity } from "../utils/itSchema"; + +describe("lazy", () => { + itSchemaIdentity( + lazyObject(() => object({ foo: string() })), + { foo: "hello" } + ); + + itSchemaIdentity( + lazyObject(() => object({ foo: string() })).extend(object({ bar: number() })), + { + foo: "hello", + bar: 42, + }, + { title: "returned schema has object utils" } + ); +}); diff --git a/tests/unit/zurg/lazy/recursive/a.ts b/tests/unit/zurg/lazy/recursive/a.ts new file mode 100644 index 0000000..8b7d5e4 --- /dev/null +++ b/tests/unit/zurg/lazy/recursive/a.ts @@ -0,0 +1,7 @@ +import { object } from "../../../../../src/core/schemas/builders/object"; +import { schemaB } from "./b"; + +// @ts-expect-error +export const schemaA = object({ + b: schemaB, +}); diff --git a/tests/unit/zurg/lazy/recursive/b.ts b/tests/unit/zurg/lazy/recursive/b.ts new file mode 100644 index 0000000..fb219d5 --- /dev/null +++ b/tests/unit/zurg/lazy/recursive/b.ts @@ -0,0 +1,8 @@ +import { object } from "../../../../../src/core/schemas/builders/object"; +import { optional } from "../../../../../src/core/schemas/builders/schema-utils"; +import { schemaA } from "./a"; + +// @ts-expect-error +export const schemaB = object({ + a: optional(schemaA), +}); diff --git a/tests/unit/zurg/list/list.test.ts b/tests/unit/zurg/list/list.test.ts new file mode 100644 index 0000000..424ed64 --- /dev/null +++ b/tests/unit/zurg/list/list.test.ts @@ -0,0 +1,41 @@ +import { list, object, property, string } from "../../../../src/core/schemas/builders"; +import { itSchema, itSchemaIdentity } from "../utils/itSchema"; +import { itValidate } from "../utils/itValidate"; + +describe("list", () => { + itSchemaIdentity(list(string()), ["hello", "world"], { + title: "functions as identity when item type is primitive", + }); + + itSchema( + "converts objects correctly", + list( + object({ + helloWorld: property("hello_world", string()), + }) + ), + { + raw: [{ hello_world: "123" }], + parsed: [{ helloWorld: "123" }], + } + ); + + itValidate("not a list", list(string()), 42, [ + { + path: [], + message: "Expected list. Received 42.", + }, + ]); + + itValidate( + "invalid item type", + list(string()), + [42], + [ + { + path: ["[0]"], + message: "Expected string. Received 42.", + }, + ] + ); +}); diff --git a/tests/unit/zurg/literals/stringLiteral.test.ts b/tests/unit/zurg/literals/stringLiteral.test.ts new file mode 100644 index 0000000..fa6c888 --- /dev/null +++ b/tests/unit/zurg/literals/stringLiteral.test.ts @@ -0,0 +1,21 @@ +import { stringLiteral } from "../../../../src/core/schemas/builders"; +import { itSchemaIdentity } from "../utils/itSchema"; +import { itValidate } from "../utils/itValidate"; + +describe("stringLiteral", () => { + itSchemaIdentity(stringLiteral("A"), "A"); + + itValidate("incorrect string", stringLiteral("A"), "B", [ + { + path: [], + message: 'Expected "A". Received "B".', + }, + ]); + + itValidate("non-string", stringLiteral("A"), 42, [ + { + path: [], + message: 'Expected "A". Received 42.', + }, + ]); +}); diff --git a/tests/unit/zurg/object-like/withParsedProperties.test.ts b/tests/unit/zurg/object-like/withParsedProperties.test.ts new file mode 100644 index 0000000..9f5dd0e --- /dev/null +++ b/tests/unit/zurg/object-like/withParsedProperties.test.ts @@ -0,0 +1,57 @@ +import { object, property, string, stringLiteral } from "../../../../src/core/schemas/builders"; + +describe("withParsedProperties", () => { + it("Added properties included on parsed object", async () => { + const schema = object({ + foo: property("raw_foo", string()), + bar: stringLiteral("bar"), + }).withParsedProperties({ + printFoo: (parsed) => () => parsed.foo, + printHelloWorld: () => () => "Hello world", + helloWorld: "Hello world", + }); + + const parsed = await schema.parse({ raw_foo: "value of foo", bar: "bar" }); + if (!parsed.ok) { + throw new Error("Failed to parse"); + } + expect(parsed.value.printFoo()).toBe("value of foo"); + expect(parsed.value.printHelloWorld()).toBe("Hello world"); + expect(parsed.value.helloWorld).toBe("Hello world"); + }); + + it("Added property is removed on raw object", async () => { + const schema = object({ + foo: property("raw_foo", string()), + bar: stringLiteral("bar"), + }).withParsedProperties({ + printFoo: (parsed) => () => parsed.foo, + }); + + const original = { raw_foo: "value of foo", bar: "bar" } as const; + const parsed = await schema.parse(original); + if (!parsed.ok) { + throw new Error("Failed to parse()"); + } + + const raw = await schema.json(parsed.value); + + if (!raw.ok) { + throw new Error("Failed to json()"); + } + + expect(raw.value).toEqual(original); + }); + + describe("compile", () => { + // eslint-disable-next-line jest/expect-expect + it("doesn't compile with non-object schema", () => { + () => + object({ + foo: string(), + }) + // @ts-expect-error + .withParsedProperties(42); + }); + }); +}); diff --git a/tests/unit/zurg/object/extend.test.ts b/tests/unit/zurg/object/extend.test.ts new file mode 100644 index 0000000..54fc8c4 --- /dev/null +++ b/tests/unit/zurg/object/extend.test.ts @@ -0,0 +1,89 @@ +import { boolean, object, property, string, stringLiteral } from "../../../../src/core/schemas/builders"; +import { itSchema, itSchemaIdentity } from "../utils/itSchema"; + +describe("extend", () => { + itSchemaIdentity( + object({ + foo: string(), + }).extend( + object({ + bar: stringLiteral("bar"), + }) + ), + { + foo: "", + bar: "bar", + } as const, + { + title: "extended properties are included in schema", + } + ); + + itSchemaIdentity( + object({ + foo: string(), + }) + .extend( + object({ + bar: stringLiteral("bar"), + }) + ) + .extend( + object({ + baz: boolean(), + }) + ), + { + foo: "", + bar: "bar", + baz: true, + } as const, + { + title: "extensions can be extended", + } + ); + + itSchema( + "converts nested object", + object({ + item: object({ + helloWorld: property("hello_world", string()), + }), + }).extend( + object({ + goodbye: property("goodbye_raw", string()), + }) + ), + { + raw: { item: { hello_world: "yo" }, goodbye_raw: "peace" }, + parsed: { item: { helloWorld: "yo" }, goodbye: "peace" }, + } + ); + + itSchema( + "extensions work with raw/parsed property name conversions", + object({ + item: property("item_raw", string()), + }).extend( + object({ + goodbye: property("goodbye_raw", string()), + }) + ), + { + raw: { item_raw: "hi", goodbye_raw: "peace" }, + parsed: { item: "hi", goodbye: "peace" }, + } + ); + + describe("compile", () => { + // eslint-disable-next-line jest/expect-expect + it("doesn't compile with non-object schema", () => { + () => + object({ + foo: string(), + }) + // @ts-expect-error + .extend([]); + }); + }); +}); diff --git a/tests/unit/zurg/object/object.test.ts b/tests/unit/zurg/object/object.test.ts new file mode 100644 index 0000000..0acf0e2 --- /dev/null +++ b/tests/unit/zurg/object/object.test.ts @@ -0,0 +1,255 @@ +import { any, number, object, property, string, stringLiteral, unknown } from "../../../../src/core/schemas/builders"; +import { itJson, itParse, itSchema, itSchemaIdentity } from "../utils/itSchema"; +import { itValidate } from "../utils/itValidate"; + +describe("object", () => { + itSchemaIdentity( + object({ + foo: string(), + bar: stringLiteral("bar"), + }), + { + foo: "", + bar: "bar", + }, + { + title: "functions as identity when values are primitives and property() isn't used", + } + ); + + itSchema( + "uses raw key from property()", + object({ + foo: property("raw_foo", string()), + bar: stringLiteral("bar"), + }), + { + raw: { raw_foo: "foo", bar: "bar" }, + parsed: { foo: "foo", bar: "bar" }, + } + ); + + itSchema( + "keys with unknown type can be omitted", + object({ + foo: unknown(), + }), + { + raw: {}, + parsed: {}, + } + ); + + itSchema( + "keys with any type can be omitted", + object({ + foo: any(), + }), + { + raw: {}, + parsed: {}, + } + ); + + describe("unrecognizedObjectKeys", () => { + describe("parse", () => { + itParse( + 'includes unknown values when unrecognizedObjectKeys === "passthrough"', + object({ + foo: property("raw_foo", string()), + bar: stringLiteral("bar"), + }), + { + raw: { + raw_foo: "foo", + bar: "bar", + // @ts-expect-error + baz: "yoyo", + }, + parsed: { + foo: "foo", + bar: "bar", + // @ts-expect-error + baz: "yoyo", + }, + opts: { + unrecognizedObjectKeys: "passthrough", + }, + } + ); + + itParse( + 'strips unknown values when unrecognizedObjectKeys === "strip"', + object({ + foo: property("raw_foo", string()), + bar: stringLiteral("bar"), + }), + { + raw: { + raw_foo: "foo", + bar: "bar", + // @ts-expect-error + baz: "yoyo", + }, + parsed: { + foo: "foo", + bar: "bar", + }, + opts: { + unrecognizedObjectKeys: "strip", + }, + } + ); + }); + + describe("json", () => { + itJson( + 'includes unknown values when unrecognizedObjectKeys === "passthrough"', + object({ + foo: property("raw_foo", string()), + bar: stringLiteral("bar"), + }), + { + raw: { + raw_foo: "foo", + bar: "bar", + // @ts-expect-error + baz: "yoyo", + }, + parsed: { + foo: "foo", + bar: "bar", + // @ts-expect-error + baz: "yoyo", + }, + opts: { + unrecognizedObjectKeys: "passthrough", + }, + } + ); + + itJson( + 'strips unknown values when unrecognizedObjectKeys === "strip"', + object({ + foo: property("raw_foo", string()), + bar: stringLiteral("bar"), + }), + { + raw: { + raw_foo: "foo", + bar: "bar", + }, + parsed: { + foo: "foo", + bar: "bar", + // @ts-expect-error + baz: "yoyo", + }, + opts: { + unrecognizedObjectKeys: "strip", + }, + } + ); + }); + }); + + describe("nullish properties", () => { + itSchema("missing properties are not added", object({ foo: property("raw_foo", string().optional()) }), { + raw: {}, + parsed: {}, + }); + + itSchema("undefined properties are not dropped", object({ foo: property("raw_foo", string().optional()) }), { + raw: { raw_foo: null }, + parsed: { foo: undefined }, + }); + + itSchema("null properties are not dropped", object({ foo: property("raw_foo", string().optional()) }), { + raw: { raw_foo: null }, + parsed: { foo: undefined }, + }); + + describe("extensions", () => { + itSchema( + "undefined properties are not dropped", + object({}).extend(object({ foo: property("raw_foo", string().optional()) })), + { + raw: { raw_foo: null }, + parsed: { foo: undefined }, + } + ); + + describe("parse()", () => { + itParse( + "null properties are not dropped", + object({}).extend(object({ foo: property("raw_foo", string().optional()) })), + { + raw: { raw_foo: null }, + parsed: { foo: undefined }, + } + ); + }); + }); + }); + + itValidate( + "missing property", + object({ + foo: string(), + bar: stringLiteral("bar"), + }), + { foo: "hello" }, + [ + { + path: [], + message: 'Missing required key "bar"', + }, + ] + ); + + itValidate( + "extra property", + object({ + foo: string(), + bar: stringLiteral("bar"), + }), + { foo: "hello", bar: "bar", baz: 42 }, + [ + { + path: ["baz"], + message: 'Unexpected key "baz"', + }, + ] + ); + + itValidate( + "not an object", + object({ + foo: string(), + bar: stringLiteral("bar"), + }), + [], + [ + { + path: [], + message: "Expected object. Received list.", + }, + ] + ); + + itValidate( + "nested validation error", + object({ + foo: object({ + bar: number(), + }), + }), + { foo: { bar: "hello" } }, + [ + { + path: ["foo", "bar"], + message: 'Expected number. Received "hello".', + }, + ] + ); +}); diff --git a/tests/unit/zurg/object/objectWithoutOptionalProperties.test.ts b/tests/unit/zurg/object/objectWithoutOptionalProperties.test.ts new file mode 100644 index 0000000..d87a65f --- /dev/null +++ b/tests/unit/zurg/object/objectWithoutOptionalProperties.test.ts @@ -0,0 +1,21 @@ +import { objectWithoutOptionalProperties, string, stringLiteral } from "../../../../src/core/schemas/builders"; +import { itSchema } from "../utils/itSchema"; + +describe("objectWithoutOptionalProperties", () => { + itSchema( + "all properties are required", + objectWithoutOptionalProperties({ + foo: string(), + bar: stringLiteral("bar").optional(), + }), + { + raw: { + foo: "hello", + }, + // @ts-expect-error + parsed: { + foo: "hello", + }, + } + ); +}); diff --git a/tests/unit/zurg/primitives/any.test.ts b/tests/unit/zurg/primitives/any.test.ts new file mode 100644 index 0000000..1adbbe2 --- /dev/null +++ b/tests/unit/zurg/primitives/any.test.ts @@ -0,0 +1,6 @@ +import { any } from "../../../../src/core/schemas/builders"; +import { itSchemaIdentity } from "../utils/itSchema"; + +describe("any", () => { + itSchemaIdentity(any(), true); +}); diff --git a/tests/unit/zurg/primitives/boolean.test.ts b/tests/unit/zurg/primitives/boolean.test.ts new file mode 100644 index 0000000..897a829 --- /dev/null +++ b/tests/unit/zurg/primitives/boolean.test.ts @@ -0,0 +1,14 @@ +import { boolean } from "../../../../src/core/schemas/builders"; +import { itSchemaIdentity } from "../utils/itSchema"; +import { itValidate } from "../utils/itValidate"; + +describe("boolean", () => { + itSchemaIdentity(boolean(), true); + + itValidate("non-boolean", boolean(), {}, [ + { + path: [], + message: "Expected boolean. Received object.", + }, + ]); +}); diff --git a/tests/unit/zurg/primitives/number.test.ts b/tests/unit/zurg/primitives/number.test.ts new file mode 100644 index 0000000..2d01415 --- /dev/null +++ b/tests/unit/zurg/primitives/number.test.ts @@ -0,0 +1,14 @@ +import { number } from "../../../../src/core/schemas/builders"; +import { itSchemaIdentity } from "../utils/itSchema"; +import { itValidate } from "../utils/itValidate"; + +describe("number", () => { + itSchemaIdentity(number(), 42); + + itValidate("non-number", number(), "hello", [ + { + path: [], + message: 'Expected number. Received "hello".', + }, + ]); +}); diff --git a/tests/unit/zurg/primitives/string.test.ts b/tests/unit/zurg/primitives/string.test.ts new file mode 100644 index 0000000..57b2368 --- /dev/null +++ b/tests/unit/zurg/primitives/string.test.ts @@ -0,0 +1,14 @@ +import { string } from "../../../../src/core/schemas/builders"; +import { itSchemaIdentity } from "../utils/itSchema"; +import { itValidate } from "../utils/itValidate"; + +describe("string", () => { + itSchemaIdentity(string(), "hello"); + + itValidate("non-string", string(), 42, [ + { + path: [], + message: "Expected string. Received 42.", + }, + ]); +}); diff --git a/tests/unit/zurg/primitives/unknown.test.ts b/tests/unit/zurg/primitives/unknown.test.ts new file mode 100644 index 0000000..4d17a7d --- /dev/null +++ b/tests/unit/zurg/primitives/unknown.test.ts @@ -0,0 +1,6 @@ +import { unknown } from "../../../../src/core/schemas/builders"; +import { itSchemaIdentity } from "../utils/itSchema"; + +describe("unknown", () => { + itSchemaIdentity(unknown(), true); +}); diff --git a/tests/unit/zurg/record/record.test.ts b/tests/unit/zurg/record/record.test.ts new file mode 100644 index 0000000..7e4ba39 --- /dev/null +++ b/tests/unit/zurg/record/record.test.ts @@ -0,0 +1,34 @@ +import { number, record, string } from "../../../../src/core/schemas/builders"; +import { itSchemaIdentity } from "../utils/itSchema"; +import { itValidate } from "../utils/itValidate"; + +describe("record", () => { + itSchemaIdentity(record(string(), string()), { hello: "world" }); + itSchemaIdentity(record(number(), string()), { 42: "world" }); + + itValidate( + "non-record", + record(number(), string()), + [], + [ + { + path: [], + message: "Expected object. Received list.", + }, + ] + ); + + itValidate("invalid key type", record(number(), string()), { hello: "world" }, [ + { + path: ["hello (key)"], + message: 'Expected number. Received "hello".', + }, + ]); + + itValidate("invalid value type", record(string(), number()), { hello: "world" }, [ + { + path: ["hello"], + message: 'Expected number. Received "world".', + }, + ]); +}); diff --git a/tests/unit/zurg/schema-utils/getSchemaUtils.test.ts b/tests/unit/zurg/schema-utils/getSchemaUtils.test.ts new file mode 100644 index 0000000..da10086 --- /dev/null +++ b/tests/unit/zurg/schema-utils/getSchemaUtils.test.ts @@ -0,0 +1,83 @@ +import { object, string } from "../../../../src/core/schemas/builders"; +import { itSchema } from "../utils/itSchema"; + +describe("getSchemaUtils", () => { + describe("optional()", () => { + itSchema("optional fields allow original schema", string().optional(), { + raw: "hello", + parsed: "hello", + }); + + itSchema("optional fields are not required", string().optional(), { + raw: null, + parsed: undefined, + }); + }); + + describe("transform()", () => { + itSchema( + "transorm and untransform run correctly", + string().transform({ + transform: (x) => x + "X", + untransform: (x) => (x as string).slice(0, -1), + }), + { + raw: "hello", + parsed: "helloX", + } + ); + }); + + describe("parseOrThrow()", () => { + it("parses valid value", async () => { + const value = string().parseOrThrow("hello"); + expect(value).toBe("hello"); + }); + + it("throws on invalid value", async () => { + const value = () => object({ a: string(), b: string() }).parseOrThrow({ a: 24 }); + expect(value).toThrowError(new Error('a: Expected string. Received 24.; Missing required key "b"')); + }); + }); + + describe("jsonOrThrow()", () => { + it("serializes valid value", async () => { + const value = string().jsonOrThrow("hello"); + expect(value).toBe("hello"); + }); + + it("throws on invalid value", async () => { + const value = () => object({ a: string(), b: string() }).jsonOrThrow({ a: 24 }); + expect(value).toThrowError(new Error('a: Expected string. Received 24.; Missing required key "b"')); + }); + }); + + describe("omitUndefined", () => { + it("serializes undefined as null", async () => { + const value = object({ + a: string().optional(), + b: string().optional(), + }).jsonOrThrow({ + a: "hello", + b: undefined, + }); + expect(value).toEqual({ a: "hello", b: null }); + }); + + it("omits undefined values", async () => { + const value = object({ + a: string().optional(), + b: string().optional(), + }).jsonOrThrow( + { + a: "hello", + b: undefined, + }, + { + omitUndefined: true, + } + ); + expect(value).toEqual({ a: "hello" }); + }); + }); +}); diff --git a/tests/unit/zurg/schema.test.ts b/tests/unit/zurg/schema.test.ts new file mode 100644 index 0000000..94089a9 --- /dev/null +++ b/tests/unit/zurg/schema.test.ts @@ -0,0 +1,78 @@ +import { + boolean, + discriminant, + list, + number, + object, + string, + stringLiteral, + union, +} from "../../../src/core/schemas/builders"; +import { booleanLiteral } from "../../../src/core/schemas/builders/literals/booleanLiteral"; +import { property } from "../../../src/core/schemas/builders/object/property"; +import { itSchema } from "./utils/itSchema"; + +describe("Schema", () => { + itSchema( + "large nested object", + object({ + a: string(), + b: stringLiteral("b value"), + c: property( + "raw_c", + list( + object({ + animal: union(discriminant("type", "_type"), { + dog: object({ value: boolean() }), + cat: object({ value: property("raw_cat", number()) }), + }), + }) + ) + ), + d: property("raw_d", boolean()), + e: booleanLiteral(true), + }), + { + raw: { + a: "hello", + b: "b value", + raw_c: [ + { + animal: { + _type: "dog", + value: true, + }, + }, + { + animal: { + _type: "cat", + raw_cat: 42, + }, + }, + ], + raw_d: false, + e: true, + }, + parsed: { + a: "hello", + b: "b value", + c: [ + { + animal: { + type: "dog", + value: true, + }, + }, + { + animal: { + type: "cat", + value: 42, + }, + }, + ], + d: false, + e: true, + }, + } + ); +}); diff --git a/tests/unit/zurg/set/set.test.ts b/tests/unit/zurg/set/set.test.ts new file mode 100644 index 0000000..e17f908 --- /dev/null +++ b/tests/unit/zurg/set/set.test.ts @@ -0,0 +1,48 @@ +import { set, string } from "../../../../src/core/schemas/builders"; +import { itSchema } from "../utils/itSchema"; +import { itValidateJson, itValidateParse } from "../utils/itValidate"; + +describe("set", () => { + itSchema("converts between raw list and parsed Set", set(string()), { + raw: ["A", "B"], + parsed: new Set(["A", "B"]), + }); + + itValidateParse("not a list", set(string()), 42, [ + { + path: [], + message: "Expected list. Received 42.", + }, + ]); + + itValidateJson( + "not a Set", + set(string()), + [], + [ + { + path: [], + message: "Expected Set. Received list.", + }, + ] + ); + + itValidateParse( + "invalid item type", + set(string()), + [42], + [ + { + path: ["[0]"], + message: "Expected string. Received 42.", + }, + ] + ); + + itValidateJson("invalid item type", set(string()), new Set([42]), [ + { + path: ["[0]"], + message: "Expected string. Received 42.", + }, + ]); +}); diff --git a/tests/unit/zurg/skipValidation.test.ts b/tests/unit/zurg/skipValidation.test.ts new file mode 100644 index 0000000..5dc8809 --- /dev/null +++ b/tests/unit/zurg/skipValidation.test.ts @@ -0,0 +1,45 @@ +/* eslint-disable no-console */ + +import { boolean, number, object, property, string, undiscriminatedUnion } from "../../../src/core/schemas/builders"; + +describe("skipValidation", () => { + it("allows data that doesn't conform to the schema", async () => { + const warningLogs: string[] = []; + const originalConsoleWarn = console.warn; + console.warn = (...args) => warningLogs.push(args.join(" ")); + + const schema = object({ + camelCase: property("snake_case", string()), + numberProperty: number(), + requiredProperty: boolean(), + anyPrimitive: undiscriminatedUnion([string(), number(), boolean()]), + }); + + const parsed = await schema.parse( + { + snake_case: "hello", + numberProperty: "oops", + anyPrimitive: true, + }, + { + skipValidation: true, + } + ); + + expect(parsed).toEqual({ + ok: true, + value: { + camelCase: "hello", + numberProperty: "oops", + anyPrimitive: true, + }, + }); + + expect(warningLogs).toEqual([ + `Failed to validate. + - numberProperty: Expected number. Received "oops".`, + ]); + + console.warn = originalConsoleWarn; + }); +}); diff --git a/tests/unit/zurg/undiscriminated-union/undiscriminatedUnion.test.ts b/tests/unit/zurg/undiscriminated-union/undiscriminatedUnion.test.ts new file mode 100644 index 0000000..0e66433 --- /dev/null +++ b/tests/unit/zurg/undiscriminated-union/undiscriminatedUnion.test.ts @@ -0,0 +1,44 @@ +import { number, object, property, string, undiscriminatedUnion } from "../../../../src/core/schemas/builders"; +import { itSchema, itSchemaIdentity } from "../utils/itSchema"; + +describe("undiscriminatedUnion", () => { + itSchemaIdentity(undiscriminatedUnion([string(), number()]), "hello world"); + + itSchemaIdentity(undiscriminatedUnion([object({ hello: string() }), object({ goodbye: string() })]), { + goodbye: "foo", + }); + + itSchema( + "Correctly transforms", + undiscriminatedUnion([object({ hello: string() }), object({ helloWorld: property("hello_world", string()) })]), + { + raw: { hello_world: "foo " }, + parsed: { helloWorld: "foo " }, + } + ); + + it("Returns errors for all variants", async () => { + const result = await undiscriminatedUnion([string(), number()]).parse(true); + if (result.ok) { + throw new Error("Unexpectedly passed validation"); + } + expect(result.errors).toEqual([ + { + message: "[Variant 0] Expected string. Received true.", + path: [], + }, + { + message: "[Variant 1] Expected number. Received true.", + path: [], + }, + ]); + }); + + describe("compile", () => { + // eslint-disable-next-line jest/expect-expect + it("doesn't compile with zero members", () => { + // @ts-expect-error + () => undiscriminatedUnion([]); + }); + }); +}); diff --git a/tests/unit/zurg/union/union.test.ts b/tests/unit/zurg/union/union.test.ts new file mode 100644 index 0000000..7901846 --- /dev/null +++ b/tests/unit/zurg/union/union.test.ts @@ -0,0 +1,113 @@ +import { boolean, discriminant, number, object, string, union } from "../../../../src/core/schemas/builders"; +import { itSchema, itSchemaIdentity } from "../utils/itSchema"; +import { itValidate } from "../utils/itValidate"; + +describe("union", () => { + itSchemaIdentity( + union("type", { + lion: object({ + meows: boolean(), + }), + giraffe: object({ + heightInInches: number(), + }), + }), + { type: "lion", meows: true }, + { title: "doesn't transform discriminant when it's a string" } + ); + + itSchema( + "transforms discriminant when it's a discriminant()", + union(discriminant("type", "_type"), { + lion: object({ meows: boolean() }), + giraffe: object({ heightInInches: number() }), + }), + { + raw: { _type: "lion", meows: true }, + parsed: { type: "lion", meows: true }, + } + ); + + describe("allowUnrecognizedUnionMembers", () => { + itSchema( + "transforms discriminant & passes through values when discriminant value is unrecognized", + union(discriminant("type", "_type"), { + lion: object({ meows: boolean() }), + giraffe: object({ heightInInches: number() }), + }), + { + // @ts-expect-error + raw: { _type: "moose", isAMoose: true }, + // @ts-expect-error + parsed: { type: "moose", isAMoose: true }, + opts: { + allowUnrecognizedUnionMembers: true, + }, + } + ); + }); + + describe("withParsedProperties", () => { + it("Added property is included on parsed object", async () => { + const schema = union("type", { + lion: object({}), + tiger: object({ value: string() }), + }).withParsedProperties({ + printType: (parsed) => () => parsed.type, + }); + + const parsed = await schema.parse({ type: "lion" }); + if (!parsed.ok) { + throw new Error("Failed to parse"); + } + expect(parsed.value.printType()).toBe("lion"); + }); + }); + + itValidate( + "non-object", + union("type", { + lion: object({}), + tiger: object({ value: string() }), + }), + [], + [ + { + path: [], + message: "Expected object. Received list.", + }, + ] + ); + + itValidate( + "missing discriminant", + union("type", { + lion: object({}), + tiger: object({ value: string() }), + }), + {}, + [ + { + path: [], + message: 'Missing discriminant ("type")', + }, + ] + ); + + itValidate( + "unrecognized discriminant value", + union("type", { + lion: object({}), + tiger: object({ value: string() }), + }), + { + type: "bear", + }, + [ + { + path: ["type"], + message: 'Expected enum. Received "bear".', + }, + ] + ); +}); diff --git a/tests/unit/zurg/utils/itSchema.ts b/tests/unit/zurg/utils/itSchema.ts new file mode 100644 index 0000000..67b6c92 --- /dev/null +++ b/tests/unit/zurg/utils/itSchema.ts @@ -0,0 +1,78 @@ +/* eslint-disable jest/no-export */ +import { Schema, SchemaOptions } from "../../../../src/core/schemas/Schema"; + +export function itSchemaIdentity( + schema: Schema, + value: T, + { title = "functions as identity", opts }: { title?: string; opts?: SchemaOptions } = {} +): void { + itSchema(title, schema, { raw: value, parsed: value, opts }); +} + +export function itSchema( + title: string, + schema: Schema, + { + raw, + parsed, + opts, + only = false, + }: { + raw: Raw; + parsed: Parsed; + opts?: SchemaOptions; + only?: boolean; + } +): void { + // eslint-disable-next-line jest/valid-title + (only ? describe.only : describe)(title, () => { + itParse("parse()", schema, { raw, parsed, opts }); + itJson("json()", schema, { raw, parsed, opts }); + }); +} + +export function itParse( + title: string, + schema: Schema, + { + raw, + parsed, + opts, + }: { + raw: Raw; + parsed: Parsed; + opts?: SchemaOptions; + } +): void { + // eslint-disable-next-line jest/valid-title + it(title, () => { + const maybeValid = schema.parse(raw, opts); + if (!maybeValid.ok) { + throw new Error("Failed to parse() " + JSON.stringify(maybeValid.errors, undefined, 4)); + } + expect(maybeValid.value).toStrictEqual(parsed); + }); +} + +export function itJson( + title: string, + schema: Schema, + { + raw, + parsed, + opts, + }: { + raw: Raw; + parsed: Parsed; + opts?: SchemaOptions; + } +): void { + // eslint-disable-next-line jest/valid-title + it(title, () => { + const maybeValid = schema.json(parsed, opts); + if (!maybeValid.ok) { + throw new Error("Failed to json() " + JSON.stringify(maybeValid.errors, undefined, 4)); + } + expect(maybeValid.value).toStrictEqual(raw); + }); +} diff --git a/tests/unit/zurg/utils/itValidate.ts b/tests/unit/zurg/utils/itValidate.ts new file mode 100644 index 0000000..75b2c08 --- /dev/null +++ b/tests/unit/zurg/utils/itValidate.ts @@ -0,0 +1,56 @@ +/* eslint-disable jest/no-export */ +import { Schema, SchemaOptions, ValidationError } from "../../../../src/core/schemas/Schema"; + +export function itValidate( + title: string, + schema: Schema, + input: unknown, + errors: ValidationError[], + opts?: SchemaOptions +): void { + // eslint-disable-next-line jest/valid-title + describe("parse()", () => { + itValidateParse(title, schema, input, errors, opts); + }); + describe("json()", () => { + itValidateJson(title, schema, input, errors, opts); + }); +} + +export function itValidateParse( + title: string, + schema: Schema, + raw: unknown, + errors: ValidationError[], + opts?: SchemaOptions +): void { + describe("parse", () => { + // eslint-disable-next-line jest/valid-title + it(title, async () => { + const maybeValid = await schema.parse(raw, opts); + if (maybeValid.ok) { + throw new Error("Value passed validation"); + } + expect(maybeValid.errors).toStrictEqual(errors); + }); + }); +} + +export function itValidateJson( + title: string, + schema: Schema, + parsed: unknown, + errors: ValidationError[], + opts?: SchemaOptions +): void { + describe("json", () => { + // eslint-disable-next-line jest/valid-title + it(title, async () => { + const maybeValid = await schema.json(parsed, opts); + if (maybeValid.ok) { + throw new Error("Value passed validation"); + } + expect(maybeValid.errors).toStrictEqual(errors); + }); + }); +} diff --git a/yarn.lock b/yarn.lock index 9950b81..97745f0 100644 --- a/yarn.lock +++ b/yarn.lock @@ -150,14 +150,28 @@ dependencies: "@babel/helper-plugin-utils" "^7.8.0" -"@babel/plugin-syntax-class-properties@^7.8.3": +"@babel/plugin-syntax-class-properties@^7.12.13": version "7.12.13" resolved "https://registry.yarnpkg.com/@babel/plugin-syntax-class-properties/-/plugin-syntax-class-properties-7.12.13.tgz#b5c987274c4a3a82b89714796931a6b53544ae10" integrity sha512-fm4idjKla0YahUNgFNLCB0qySdsoPiZP3iQE3rky0mBUtMZ23yDJ9SJdg6dXTSDnulOVqiF3Hgr9nbXvXTQZYA== dependencies: "@babel/helper-plugin-utils" "^7.12.13" -"@babel/plugin-syntax-import-meta@^7.8.3": +"@babel/plugin-syntax-class-static-block@^7.14.5": + version "7.14.5" + resolved "https://registry.yarnpkg.com/@babel/plugin-syntax-class-static-block/-/plugin-syntax-class-static-block-7.14.5.tgz#195df89b146b4b78b3bf897fd7a257c84659d406" + integrity sha512-b+YyPmr6ldyNnM6sqYeMWE+bgJcJpO6yS4QD7ymxgH34GBPNDM/THBh8iunyvKIZztiwLH4CJZ0RxTk9emgpjw== + dependencies: + "@babel/helper-plugin-utils" "^7.14.5" + +"@babel/plugin-syntax-import-attributes@^7.24.7": + version "7.24.7" + resolved "https://registry.yarnpkg.com/@babel/plugin-syntax-import-attributes/-/plugin-syntax-import-attributes-7.24.7.tgz#b4f9ea95a79e6912480c4b626739f86a076624ca" + integrity sha512-hbX+lKKeUMGihnK8nvKqmXBInriT3GVjzXKFriV3YC6APGxMbP8RZNFwy91+hocLXq90Mta+HshoB31802bb8A== + dependencies: + "@babel/helper-plugin-utils" "^7.24.7" + +"@babel/plugin-syntax-import-meta@^7.10.4": version "7.10.4" resolved "https://registry.yarnpkg.com/@babel/plugin-syntax-import-meta/-/plugin-syntax-import-meta-7.10.4.tgz#ee601348c370fa334d2207be158777496521fd51" integrity sha512-Yqfm+XDx0+Prh3VSeEQCPU81yC+JWZ2pDPFSS4ZdpfZhp4MkFMaDC1UqseovEKwSUpnIL7+vK+Clp7bfh0iD7g== @@ -178,7 +192,7 @@ dependencies: "@babel/helper-plugin-utils" "^7.24.7" -"@babel/plugin-syntax-logical-assignment-operators@^7.8.3": +"@babel/plugin-syntax-logical-assignment-operators@^7.10.4": version "7.10.4" resolved "https://registry.yarnpkg.com/@babel/plugin-syntax-logical-assignment-operators/-/plugin-syntax-logical-assignment-operators-7.10.4.tgz#ca91ef46303530448b906652bac2e9fe9941f699" integrity sha512-d8waShlpFDinQ5MtvGU9xDAOzKH47+FFoney2baFIoMr952hKOLp1HR7VszoZvOsV/4+RRszNY7D17ba0te0ig== @@ -192,7 +206,7 @@ dependencies: "@babel/helper-plugin-utils" "^7.8.0" -"@babel/plugin-syntax-numeric-separator@^7.8.3": +"@babel/plugin-syntax-numeric-separator@^7.10.4": version "7.10.4" resolved "https://registry.yarnpkg.com/@babel/plugin-syntax-numeric-separator/-/plugin-syntax-numeric-separator-7.10.4.tgz#b9b070b3e33570cd9fd07ba7fa91c0dd37b9af97" integrity sha512-9H6YdfkcK/uOnY/K7/aA2xpzaAgkQn37yzWUMRK7OaPOqOpGS1+n0H5hxT9AUw9EsSjPW8SVyMJwYRtWs3X3ug== @@ -220,7 +234,14 @@ dependencies: "@babel/helper-plugin-utils" "^7.8.0" -"@babel/plugin-syntax-top-level-await@^7.8.3": +"@babel/plugin-syntax-private-property-in-object@^7.14.5": + version "7.14.5" + resolved "https://registry.yarnpkg.com/@babel/plugin-syntax-private-property-in-object/-/plugin-syntax-private-property-in-object-7.14.5.tgz#0dc6671ec0ea22b6e94a1114f857970cd39de1ad" + integrity sha512-0wVnp9dxJ72ZUJDV27ZfbSj6iHLoytYZmh3rFcxNnvsJF3ktkzLDZPy/mA17HGsaQT3/DQsWYX1f1QGWkCoVUg== + dependencies: + "@babel/helper-plugin-utils" "^7.14.5" + +"@babel/plugin-syntax-top-level-await@^7.14.5": version "7.14.5" resolved "https://registry.yarnpkg.com/@babel/plugin-syntax-top-level-await/-/plugin-syntax-top-level-await-7.14.5.tgz#c1cfdadc35a646240001f06138247b741c34d94c" integrity sha512-hx++upLv5U1rgYfwe1xBQUhRmU41NEvpUvrp8jkrSCdvGSnM5/qdRMtylJ6PG5OFkBaHkbTAKTnd3/YyESRHFw== @@ -619,9 +640,9 @@ form-data "^4.0.0" "@types/node@*": - version "22.1.0" - resolved "https://registry.yarnpkg.com/@types/node/-/node-22.1.0.tgz#6d6adc648b5e03f0e83c78dc788c2b037d0ad94b" - integrity sha512-AOmuRF0R2/5j1knA3c6G3HOk523Ga+l+ZXltX8SF1+5oqcXijjfTd8fY3XRZqSihEu9XhtQnKYLmkFaoxgsJHw== + version "22.2.0" + resolved "https://registry.yarnpkg.com/@types/node/-/node-22.2.0.tgz#7cf046a99f0ba4d628ad3088cb21f790df9b0c5b" + integrity sha512-bm6EG6/pCpkxDf/0gDNDdtDILMOHgaQBVOJGdwsqClnxA3xL6jtMv76rLBc006RVMWbmaf0xbmom4Z/5o2nRkQ== dependencies: undici-types "~6.13.0" @@ -780,22 +801,25 @@ babel-plugin-jest-hoist@^29.6.3: "@types/babel__traverse" "^7.0.6" babel-preset-current-node-syntax@^1.0.0: - version "1.0.1" - resolved "https://registry.yarnpkg.com/babel-preset-current-node-syntax/-/babel-preset-current-node-syntax-1.0.1.tgz#b4399239b89b2a011f9ddbe3e4f401fc40cff73b" - integrity sha512-M7LQ0bxarkxQoN+vz5aJPsLBn77n8QgTFmo8WK0/44auK2xlCXrYcUxHFxgU7qW5Yzw/CjmLRK2uJzaCd7LvqQ== + version "1.1.0" + resolved "https://registry.yarnpkg.com/babel-preset-current-node-syntax/-/babel-preset-current-node-syntax-1.1.0.tgz#9a929eafece419612ef4ae4f60b1862ebad8ef30" + integrity sha512-ldYss8SbBlWva1bs28q78Ju5Zq1F+8BrqBZZ0VFhLBvhh6lCpC2o3gDJi/5DRLs9FgYZCnmPYIVFU4lRXCkyUw== dependencies: "@babel/plugin-syntax-async-generators" "^7.8.4" "@babel/plugin-syntax-bigint" "^7.8.3" - "@babel/plugin-syntax-class-properties" "^7.8.3" - "@babel/plugin-syntax-import-meta" "^7.8.3" + "@babel/plugin-syntax-class-properties" "^7.12.13" + "@babel/plugin-syntax-class-static-block" "^7.14.5" + "@babel/plugin-syntax-import-attributes" "^7.24.7" + "@babel/plugin-syntax-import-meta" "^7.10.4" "@babel/plugin-syntax-json-strings" "^7.8.3" - "@babel/plugin-syntax-logical-assignment-operators" "^7.8.3" + "@babel/plugin-syntax-logical-assignment-operators" "^7.10.4" "@babel/plugin-syntax-nullish-coalescing-operator" "^7.8.3" - "@babel/plugin-syntax-numeric-separator" "^7.8.3" + "@babel/plugin-syntax-numeric-separator" "^7.10.4" "@babel/plugin-syntax-object-rest-spread" "^7.8.3" "@babel/plugin-syntax-optional-catch-binding" "^7.8.3" "@babel/plugin-syntax-optional-chaining" "^7.8.3" - "@babel/plugin-syntax-top-level-await" "^7.8.3" + "@babel/plugin-syntax-private-property-in-object" "^7.14.5" + "@babel/plugin-syntax-top-level-await" "^7.14.5" babel-preset-jest@^29.6.3: version "29.6.3" @@ -1079,9 +1103,9 @@ domexception@^4.0.0: webidl-conversions "^7.0.0" electron-to-chromium@^1.5.4: - version "1.5.5" - resolved "https://registry.yarnpkg.com/electron-to-chromium/-/electron-to-chromium-1.5.5.tgz#03bfdf422bdd2c05ee2657efedde21264a1a566b" - integrity sha512-QR7/A7ZkMS8tZuoftC/jfqNkZLQO779SSW3YuZHP4eXpj3EffGLFcB/Xu9AAZQzLccTiCV+EmUo3ha4mQ9wnlA== + version "1.5.6" + resolved "https://registry.yarnpkg.com/electron-to-chromium/-/electron-to-chromium-1.5.6.tgz#c81d9938b5a877314ad370feb73b4e5409b36abd" + integrity sha512-jwXWsM5RPf6j9dPYzaorcBSUg6AiqocPEyMpkchkvntaH9HGfOOMZwxMJjDY/XEs3T5dM7uyH1VhRMkqUU9qVw== emittery@^0.13.1: version "0.13.1"