11import { Validator , helpers } from "@tableland/sdk" ;
2- import { Store } from "@tableland/studio-store" ;
2+ import { Schema , Store } from "@tableland/studio-store" ;
33import { TRPCError } from "@trpc/server" ;
44import { z } from "zod" ;
55import { projectProcedure , publicProcedure , router } from "../trpc" ;
66
7+ const schemaSchema : z . ZodType < Schema > = z . object ( {
8+ columns : z . array (
9+ z . object ( {
10+ name : z . string ( ) . nonempty ( ) ,
11+ type : z . string ( ) . nonempty ( ) ,
12+ constraints : z . array ( z . string ( ) . nonempty ( ) ) . optional ( ) ,
13+ } ) ,
14+ ) ,
15+ table_constraints : z . array ( z . string ( ) . nonempty ( ) ) . optional ( ) ,
16+ } ) ;
17+
718export function tablesRouter ( store : Store ) {
819 return router ( {
920 projectTables : publicProcedure
@@ -15,8 +26,8 @@ export function tablesRouter(store: Store) {
1526 . input (
1627 z . object ( {
1728 name : z . string ( ) ,
18- schema : z . string ( ) ,
1929 description : z . string ( ) . nonempty ( ) ,
30+ schema : schemaSchema ,
2031 } ) ,
2132 )
2233 . mutation ( async ( { input } ) => {
@@ -47,12 +58,11 @@ export function tablesRouter(store: Store) {
4758 tableId : input . tableId ,
4859 } ) ;
4960
50- // TODO: Figure out a standard way of encoding schema for both Tables created in Studio and imported tables.
5161 const table = await store . tables . createTable (
5262 input . projectId ,
5363 input . name ,
5464 input . description ,
55- JSON . stringify ( tablelandTable . schema ) ,
65+ tablelandTable . schema ,
5666 ) ;
5767 const createdAttr = tablelandTable . attributes ?. find (
5868 ( attr ) => attr . traitType === "created" ,
0 commit comments