From 8a3c4ad67b883afa684d8727b93ba2f27b3e8355 Mon Sep 17 00:00:00 2001 From: Jim Nielsen Date: Tue, 27 Jun 2023 07:48:31 -1000 Subject: [PATCH] fix: allow any for array_output in older versions of the schema (#580) * fix: allow any for array_output * Update validateGridFile.ts * Update validateGridFile.ts * Update validateGridFile.test.ts --- src/schemas/GridFileV1.ts | 2 +- src/schemas/GridFileV1_1.ts | 2 +- src/schemas/validateGridFile.test.ts | 22 +++++++++++++++++++++- 3 files changed, 23 insertions(+), 3 deletions(-) diff --git a/src/schemas/GridFileV1.ts b/src/schemas/GridFileV1.ts index b96e34293e..43ea59216a 100644 --- a/src/schemas/GridFileV1.ts +++ b/src/schemas/GridFileV1.ts @@ -1,6 +1,6 @@ import z from 'zod'; -const ArrayOutputSchema = z.array(z.union([z.string(), z.number(), z.boolean()])); +const ArrayOutputSchema = z.array(z.any()); export enum BorderType { line1 = 0, diff --git a/src/schemas/GridFileV1_1.ts b/src/schemas/GridFileV1_1.ts index 754fdb5336..e30ad3f30e 100644 --- a/src/schemas/GridFileV1_1.ts +++ b/src/schemas/GridFileV1_1.ts @@ -4,7 +4,7 @@ import { v4 as uuid } from 'uuid'; import { DEFAULT_FILE_NAME } from '../constants/app'; // Shared schemas -const ArrayOutputSchema = z.array(z.union([z.string(), z.number(), z.boolean()])); +const ArrayOutputSchema = z.array(z.any()); const BorderDirectionSchema = z.object({ color: z.string().optional(), type: z.enum(['line1', 'line2', 'line3', 'dotted', 'dashed', 'double']).optional(), diff --git a/src/schemas/validateGridFile.test.ts b/src/schemas/validateGridFile.test.ts index 2f223d13b4..07b4ebed01 100644 --- a/src/schemas/validateGridFile.test.ts +++ b/src/schemas/validateGridFile.test.ts @@ -35,7 +35,27 @@ const v1File: GridFileV1 = { const v1_1File: GridFileV1_1 = { version: '1.1', - cells: [], + cells: [ + // Test to allow `any` for `array_output` + { + x: 0, + y: 0, + type: 'PYTHON', + value: '1,2,3', + last_modified: '2023-06-27T16:54:40.619Z', + evaluation_result: { + success: true, + std_out: '', + output_value: '[[[1, 2, 3]]]', + cells_accessed: [], + array_output: [[[1, 2, 3]]], + formatted_code: '[[[1, 2, 3]]]\n', + error_span: null, + }, + python_code: '[[[1,2,3]]]', + array_cells: [[0, 0]], + }, + ], columns: [], rows: [], borders: [],