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: 2 comments 2 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 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