permify icon indicating copy to clipboard operation
permify copied to clipboard

Schema: Typescript Codegen

Open junwen-k opened this issue 9 months ago • 0 comments

Is your feature request related to a problem? Please describe.

Currently, client that talks to Permify API is loosely typed.

Describe the solution you'd like

It would be amazing to have Typescript client automatically generated using some sort of codegen based on Permify schema, think of it like Prisma's prisma-client-js.

E.g,

entity user {} 

entity organization {
    relation admin @user    
    relation member @user     
    
    action view_files = admin or member
    action edit_files = admin
} 

Generates a client that allow us to do:

import { Permify } from '@permify/client'

const client = new Permify({
    endpoint: "localhost:3478",
})

// orm-like syntax
client.permission.tenantId("t1").organization("organization-001").permission("view_files").user("user-001").check({
    metadata: {
        snapToken: "",
        schemaVersion: "",
        depth: 20
    },
}).then(...);

// strongly typed, you will get compile error if you attempt to check against something that is not written in your schema
const response = await client.permission.tenantId("t1").organization().permission("edit_files").user().subjectPermission();

Describe alternatives you've considered

  1. Manually writing types and using the default client.
  2. Standalone orm builder that can be used in all services.

Additional context

Having a strongly typed client automatically generated will greatly improve DX.

Caveats

Not sure about the complexity of implementing it and how it will work for Data service / attribute, etc. The above example roughly demonstrates the idea.

junwen-k avatar May 07 '24 07:05 junwen-k