sebastianwessel / surrealdb-client-generator

Tool which generates a typescript client for SurrealDB and zod schema of a given database
MIT License
76 stars 12 forks source link

Object arrays just turning into objects #37

Closed CiskaLV closed 3 months ago

CiskaLV commented 3 months ago

I had tried it on my project and it did not work then i tried it with the book table in the tests it just came out like this

import { z } from "zod";

// the create schema for table book
export const bookInputSchemaGen = z.object({
vendors: z.object({
name: z.string(),
  price: z.number(),
  ratings: z.object({
score: z.number().optional()
})
}),
});

// the select schema for table book
export const bookOutputSchemaGen = z.object({
vendors: z.object({
name: z.string(),
  price: z.number(),
  ratings: z.object({
score: z.number()
})
}),
});

My im using surrealDb version 1.5.4

and this is the definition for the field

fields: {
    vendors: 'DEFINE FIELD vendors ON book TYPE array<object> DEFAULT [] PERMISSIONS FULL',
    'vendors[*]': 'DEFINE FIELD vendors[*] ON book TYPE object PERMISSIONS FULL',
    'vendors[*].name': 'DEFINE FIELD vendors[*].name ON book TYPE string PERMISSIONS FULL',
    'vendors[*].price': 'DEFINE FIELD vendors[*].price ON book TYPE number PERMISSIONS FULL',
    'vendors[*].ratings': 'DEFINE FIELD vendors[*].ratings ON book TYPE array<object> DEFAULT [] PERMISSIONS FULL',
    'vendors[*].ratings[*]': 'DEFINE FIELD vendors[*].ratings[*] ON book TYPE object PERMISSIONS FULL',
    'vendors[*].ratings[*].score': 'DEFINE FIELD vendors[*].ratings[*].score ON book TYPE number DEFAULT 0 PERMISSIONS FULL'
  }
sebastianwessel commented 3 months ago

@hammo92 are you maybe willing to take a look into this issue?

hammo92 commented 3 months ago

@hammo92 are you maybe willing to take a look into this issue?

Sure, there are a couple of fixes I'm working on for the objects; should cover this as well.

sebastianwessel commented 3 months ago

Version 2.5 is out! This should fix the issue @CiskaLV - maybe you want to give it a try and let us know...