From 02bf95265998cf304e3b33ec12e4a27cb9f96163 Mon Sep 17 00:00:00 2001 From: Travis Fischer Date: Wed, 31 May 2023 19:05:28 -0700 Subject: [PATCH] =?UTF-8?q?=F0=9F=8D=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package.json | 7 ++++--- pnpm-lock.yaml | 36 ++++++++++++++++++++++-------------- src/openai.test.ts | 25 +++++++------------------ 3 files changed, 33 insertions(+), 35 deletions(-) diff --git a/package.json b/package.json index 7f972a1..5476f65 100644 --- a/package.json +++ b/package.json @@ -35,16 +35,14 @@ "test:prettier": "prettier '**/*.{js,jsx,ts,tsx}' --check" }, "dependencies": { - "dotenv": "^16.1.3", "handlebars": "^4.7.7", "js-tiktoken": "^1.0.6", "jsonrepair": "^3.1.0", "ky": "^0.33.3", - "openai-fetch": "^1.3.0", + "openai-fetch": "^1.5.0", "p-map": "^6.0.0", "quick-lru": "^6.1.1", "ts-dedent": "^2.2.0", - "type-fest": "^3.11.0", "zod": "^3.21.4", "zod-to-ts": "^1.1.4", "zod-validation-error": "^1.3.0" @@ -54,12 +52,15 @@ "@types/node": "^20.2.5", "ava": "^5.3.0", "del-cli": "^5.0.0", + "dotenv": "^16.1.3", + "expect-type": "^0.16.0", "husky": "^8.0.3", "lint-staged": "^13.2.2", "npm-run-all": "^4.1.5", "prettier": "^2.8.8", "tsup": "^6.7.0", "tsx": "^3.12.7", + "type-fest": "^3.11.1", "typescript": "^5.0.4" }, "lint-staged": { diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 03af3b0..8f2fcc1 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -1,9 +1,6 @@ lockfileVersion: '6.0' dependencies: - dotenv: - specifier: ^16.1.3 - version: 16.1.3 handlebars: specifier: ^4.7.7 version: 4.7.7 @@ -17,8 +14,8 @@ dependencies: specifier: ^0.33.3 version: 0.33.3 openai-fetch: - specifier: ^1.3.0 - version: 1.3.0 + specifier: ^1.5.0 + version: 1.5.0 p-map: specifier: ^6.0.0 version: 6.0.0 @@ -28,9 +25,6 @@ dependencies: ts-dedent: specifier: ^2.2.0 version: 2.2.0 - type-fest: - specifier: ^3.11.0 - version: 3.11.0 zod: specifier: ^3.21.4 version: 3.21.4 @@ -54,6 +48,12 @@ devDependencies: del-cli: specifier: ^5.0.0 version: 5.0.0 + dotenv: + specifier: ^16.1.3 + version: 16.1.3 + expect-type: + specifier: ^0.16.0 + version: 0.16.0 husky: specifier: ^8.0.3 version: 8.0.3 @@ -72,6 +72,9 @@ devDependencies: tsx: specifier: ^3.12.7 version: 3.12.7 + type-fest: + specifier: ^3.11.1 + version: 3.11.1 typescript: specifier: ^5.0.4 version: 5.0.4 @@ -1027,7 +1030,7 @@ packages: /dotenv@16.1.3: resolution: {integrity: sha512-FYssxsmCTtKL72fGBSvb1K9dRz0/VZeWqFme/vSb7r7323x4CRaHu4LvQ5JG3+s6yt2YPbBrkpiEODktfyjI9A==} engines: {node: '>=12'} - dev: false + dev: true /eastasianwidth@0.2.0: resolution: {integrity: sha512-I88TYZWc9XiYHRQ4/3c5rjjfgkjhLyW2luGIheGERbNQ6OY7yTybanSpDXZa8y7VUP9YmDcYa+eyq4ca7iLqWA==} @@ -1201,6 +1204,11 @@ packages: strip-final-newline: 3.0.0 dev: true + /expect-type@0.16.0: + resolution: {integrity: sha512-wCpFeVBiAPGiYkQZzaqvGuuBnNCHbtnowMOBpBGY8a27XbG8VAit3lklWph1r8VmgsH61mOZqI3NuGm8bZnUlw==} + engines: {node: '>=12.0.0'} + dev: true + /fast-diff@1.3.0: resolution: {integrity: sha512-VxPP4NqbUjj6MaAOafWeUn2cXWLcCtljklUtZf0Ind4XQ+QPtmA0b18zZy0jIQx+ExRVCR/ZQpBmik5lXshNsw==} dev: true @@ -2121,8 +2129,8 @@ packages: mimic-fn: 4.0.0 dev: true - /openai-fetch@1.3.0: - resolution: {integrity: sha512-p3U4bZzAqfG0kkN9Z2fze0jqL2cZkbUSPI7oyzaVoms4T/Rovlar+ZaUf8evStgFH6p7WoBmeqnH6tt/Y50/+Q==} + /openai-fetch@1.5.0: + resolution: {integrity: sha512-GSCt5JPNWTADNeip9DUXlkZMwwxczKBRokKLInTQbbX0t81VqTBBUYis36XZeWHQP4eWeWMLe9nGiTtciqZ1HA==} dependencies: ky: 0.33.3 zod: 3.21.4 @@ -2897,10 +2905,10 @@ packages: engines: {node: '>=10'} dev: true - /type-fest@3.11.0: - resolution: {integrity: sha512-JaPw5U9ixP0XcpUbQoVSbxSDcK/K4nww20C3kjm9yE6cDRRhptU28AH60VWf9ltXmCrIfIbtt9J+2OUk2Uqiaw==} + /type-fest@3.11.1: + resolution: {integrity: sha512-aCuRNRERRVh33lgQaJRlUxZqzfhzwTrsE98Mc3o3VXqmiaQdHacgUtJ0esp+7MvZ92qhtzKPeusaX6vIEcoreA==} engines: {node: '>=14.16'} - dev: false + dev: true /typed-array-length@1.0.4: resolution: {integrity: sha512-KjZypGq+I/H7HI5HlOoGHkWUUGq+Q0TPhQurLbyrVrvnKTBgzLhIJ7j6J/XTQOi0d1RjyZ0wdas8bKs2p0x3Ng==} diff --git a/src/openai.test.ts b/src/openai.test.ts index bb2a6c7..938234d 100644 --- a/src/openai.test.ts +++ b/src/openai.test.ts @@ -1,4 +1,5 @@ import test from 'ava' +import { expectTypeOf } from 'expect-type' import { OpenAIClient } from 'openai-fetch' import { z } from 'zod' @@ -17,22 +18,10 @@ test('OpenAIChatModel ⇒ json output', async (t) => { }).output(z.object({ foo: z.string(), bar: z.number() })) const result = await builder.call() - type verify = Expect< - Equal< - typeof result, - { - foo: string - bar: number - } - > - > -}) + t.truthy(result) + t.truthy(typeof result.foo === 'string') + t.truthy(typeof result.bar === 'number') + t.is(Object.keys(result).length, 2) -// Ensure parsed results are typed correctly -// https://github.com/total-typescript/zod-tutorial/blob/main/src/helpers/type-utils.ts -type Expect = T -type Equal = (() => T extends X ? 1 : 2) extends () => T extends Y - ? 1 - : 2 - ? true - : false + expectTypeOf(result).toMatchTypeOf<{ foo: string; bar: number }>() +})