Generate Typescript types from schema #1872
-
| 
         Has anyone attempted to generate TypeScript types from Spice schema? would produce: const acmeSystemRelations = {
  ADMIN: admin
  SUPPORT: support
} as const
type AcmeSystemRelations = typeof acmeSystemRelations[keyof typeof acmeSystemRelations]
const acmeSystemPermissions = {
  ROOT_ACCESS: 'root_access',
  SUPPORT_ACCESS: 'support_access',
  CREATE_SOMETHING: 'create_something',
} as const
type AcmeSystemPermissions = typeof acmeSystemPermissions[keyof typeof acmeSystemPermissions] | 
  
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 3 replies
-
| 
         We actually have a prototype of a well-generated client for TypeScript, but we're still unsure of the best means of generating the TypeScript code necessary  | 
  
Beta Was this translation helpful? Give feedback.
-
| 
         This could be done to almost any language with relatively little effort by using SpiceDB Reflect Schema API. However it does not have parsing information about he permissions themselves. Only relations. This way you could just use dockerized spicedb instance, load the schema, use reflect API to generate necessary target language code. For C# I was able to do for example: Where Applications and Group are schema Definitions and Admin is a relation. You can do this with Permissions too, but unfortunately you cannot figure out potential Subject IDs and Types with it. For example I could generate a function like this to make client code more nice: But I kinda want something like this:  | 
  
Beta Was this translation helpful? Give feedback.
-
| 
         We built something for our internal use in https://github.com/yahiaosama/authz-schema-sync-check, that generates Typescript and Python types based on SpiceDB's tree-sitter grammar in https://github.com/authzed/tree-sitter-spicedb. It's built in Python and uses Jinja templates. I think the most flexible approach might be for SpiceDB to provide a binary that does the generic parsing step and can invoke some popular templating engines (or just one reasonably popular one). Then it can ship with some opinionated templates for various languages (just types, not fully-fledged clients / DSLs) but users could always tweak it when necessary.  | 
  
Beta Was this translation helpful? Give feedback.
We actually have a prototype of a well-generated client for TypeScript, but we're still unsure of the best means of generating the TypeScript code necessary