🎥 Make videos programmatically with React
start
Jonny Burger78cd620e2800
diff --git a/packages/cli/src/editor/components/RenderModal/SchemaEditor/create-zod-values.ts b/packages/cli/src/editor/components/RenderModal/SchemaEditor/create-zod-values.tsnew file mode 100644index 0000000000..98cc05fd5b--- /dev/null+++ b/packages/cli/src/editor/components/RenderModal/SchemaEditor/create-zod-values.ts@@ -0,0 +1,71 @@+import {z} from 'remotion';++export const createZodValues = (schema: z.ZodTypeAny) => {+ const def = schema._def;+ const typeName = def.typeName as z.ZodFirstPartyTypeKind;++ switch (typeName) {+ case z.ZodFirstPartyTypeKind.ZodString:+ return '';+ case z.ZodFirstPartyTypeKind.ZodNumber:+ return 0;+ case z.ZodFirstPartyTypeKind.ZodBigInt:+ return BigInt(0);+ case z.ZodFirstPartyTypeKind.ZodBoolean:+ return false;+ case z.ZodFirstPartyTypeKind.ZodNaN:+ return NaN;+ case z.ZodFirstPartyTypeKind.ZodDate:+ return new Date();+ case z.ZodFirstPartyTypeKind.ZodSymbol:+ return Symbol('remotion');+ case z.ZodFirstPartyTypeKind.ZodUndefined:+ return undefined;+ case z.ZodFirstPartyTypeKind.ZodNull:+ return null;+ case z.ZodFirstPartyTypeKind.ZodAny:+ throw new Error('Cannot create a value for any');+ case z.ZodFirstPartyTypeKind.ZodUnknown:+ throw new Error('Cannot create a value for unknown');+ case z.ZodFirstPartyTypeKind.ZodNever:+ throw new Error('Cannot create a value for never');+ case z.ZodFirstPartyTypeKind.ZodVoid:+ return undefined;+ case z.ZodFirstPartyTypeKind.ZodObject: {+ const shape = def.shape() as Record<string, z.ZodTypeAny>;+ const keys = Object.keys(shape);+ const returnValue = keys.reduce((existing, key) => {+ existing[key] = createZodValues(shape[key]);+ return existing;+ }, {} as Record<string, unknown>);+ return returnValue;+ }++ case z.ZodFirstPartyTypeKind.ZodArray: {+ return [createZodValues(def.type)];+ }++ case z.ZodFirstPartyTypeKind.ZodUnion:+ case z.ZodFirstPartyTypeKind.ZodDiscriminatedUnion:+ case z.ZodFirstPartyTypeKind.ZodIntersection:+ case z.ZodFirstPartyTypeKind.ZodTuple:+ case z.ZodFirstPartyTypeKind.ZodRecord:+ case z.ZodFirstPartyTypeKind.ZodMap:+ case z.ZodFirstPartyTypeKind.ZodSet:+ case z.ZodFirstPartyTypeKind.ZodFunction:+ case z.ZodFirstPartyTypeKind.ZodLazy:+ case z.ZodFirstPartyTypeKind.ZodLiteral:+ case z.ZodFirstPartyTypeKind.ZodEnum:+ case z.ZodFirstPartyTypeKind.ZodEffects:+ case z.ZodFirstPartyTypeKind.ZodNativeEnum:+ case z.ZodFirstPartyTypeKind.ZodOptional:+ case z.ZodFirstPartyTypeKind.ZodNullable:+ case z.ZodFirstPartyTypeKind.ZodDefault:+ case z.ZodFirstPartyTypeKind.ZodCatch:+ case z.ZodFirstPartyTypeKind.ZodPromise:+ case z.ZodFirstPartyTypeKind.ZodBranded:+ case z.ZodFirstPartyTypeKind.ZodPipeline:+ default:+ throw new Error('Not implemented');+ }+};diff --git a/packages/cli/src/test/create-zod-values.test.ts b/packages/cli/src/test/create-zod-values.test.tsnew file mode 100644index 0000000000..16bca3b16f--- /dev/null+++ b/packages/cli/src/test/create-zod-values.test.ts@@ -0,0 +1,28 @@+import {z} from 'remotion';+import {expect, test} from 'vitest';+import {createZodValues} from '../editor/components/RenderModal/SchemaEditor/create-zod-values';++test('Should be able to create a string', () => {+ const hi = createZodValues(z.string());+ expect(hi).toBe('');+});++test('Should be able to create a number', () => {+ const hi = createZodValues(z.number());+ expect(hi).toBe(0);+});++test('Should be able to create an object', () => {+ const hi = createZodValues(+ z.object({+ a: z.string(),+ b: z.number(),+ })+ );+ expect(hi).toEqual({a: '', b: 0});+});++test('Should be able to create an array', () => {+ expect(createZodValues(z.array(z.string()))).toEqual(['']);+ expect(createZodValues(z.array(z.number()))).toEqual([0]);+});