📣The December 6th release is out!Read the release notes

    An astronaut attempting to open a locked door on the moon

    Preserve your data with permissions

    TLDR

    We introduce a new, more granular permissions API and add support for String enums in your schema.

    New permissions API

    We've changed how access controls are defined in Triplit. This new permissions API will replace the old rules API, though the latter will continue to be supported. permissions will allow you define specific access control rules in your schema for querying, inserting, updating, and deleting data. It also allows greater flexibility in the structure of the JWTs you use for authentication.

    Read more about permissions in the docs.

    Here's a brief example

    // define roles and the matching criteria for a JWT. Clients are assigned roles on the server based on their JWT.
    const roles = {
      user: {
        match: {
          type: 'user',
          uid: '$userId',
        },
      },
      admin: {
        match: {
          type: 'admin',
        },
      }
    }
    
    const schema = {
      collections: {
        todos: {
          schema: S.Schema({
            id: S.Id(),
            text: S.String(),
            authorId: S.String(),
          })
          // define permissions for the todos collection on a per-role basis
          permissions: {
            // clients with the user role can only read and insert todos that they authored
            user: {
              read: {
                filter: [['authorId', '=', '$role.userId']],
              },
              insert: {
                filter: [['authorId', '=', '$role.userId']],
              }
            },
            // clients with the admin role can read all todos and insert new todos
            admin: {
              read: {
                filter: [true], // Allow all reads
              },
              insert: {
                filter: [true], // Allow all inserts
              }
            }
          },
        },
      },
    };
    

    Additional features like attribute level permissions will also be supported soon in a future release.

    New enum options for String attributes

    We're happy to be shipping a much-requested feature: enum options for String attributes. This will allow you to define a set of allowed values for a String attribute.

    Here's an example:

    const schema = {
      collections: {
        todos: {
          schema: S.Schema({
            id: S.Id(),
            text: S.String(),
            status: S.String({
              enum: ['open', 'in-progress', 'done'],
            }),
          }),
        },
      },
    };
    

    You'll get validation at runtime for any mutations to the status attribute, and because this is Triplit, you'll get autocompletion and type checking in your IDE.

    Read more about enum options in the docs.

    Simplified triplit schema print

    We've added changed the defaults for triplit schema print to make it more immediately useful. Now, when you run triplit schema print, it will output the server schema as a TypeScript file. This is especially useful when you're making changes to your schema with the Triplit Console and need to keep your local schema in sync.

    npx triplit schema print > triplit/schema.ts