npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@contember/bindx-generator

v0.1.13

Published

Schema generator for @contember/bindx with role-based ACL support

Readme

@contember/bindx-generator

Schema generator for @contember/bindx with role-based ACL support. Generates TypeScript types and runtime schema definitions from Contember Model.Schema and Acl.Schema.

Installation

npm install @contember/bindx-generator @contember/schema @contember/schema-utils

Usage

Basic Generation (Without ACL)

import { generate } from '@contember/bindx-generator'
import { Model } from '@contember/schema'

const model: Model.Schema = {
  enums: { /* ... */ },
  entities: { /* ... */ }
}

const files = generate(model)

// Write files
for (const [filename, content] of Object.entries(files)) {
  fs.writeFileSync(`./generated/${filename}`, content)
}

Generation with Role-Based ACL

import { generate } from '@contember/bindx-generator'
import { Model, Acl } from '@contember/schema'

const model: Model.Schema = { /* ... */ }
const acl: Acl.Schema = {
  roles: {
    public: {
      stages: '*',
      entities: {
        Article: {
          predicates: {},
          operations: {
            read: {
              id: true,
              title: true,
              // Only public fields
            }
          }
        }
      },
      variables: {}
    },
    editor: {
      stages: '*',
      entities: {
        Article: {
          predicates: {},
          operations: {
            read: {
              id: true,
              title: true,
              content: true,
              author: true,
              // All fields accessible to editors
            }
          }
        }
      },
      variables: {}
    }
  }
}

const files = generate(model, acl)

Generated Files

The generator produces 5 files:

| File | Description | |------|-------------| | entities.ts | TypeScript entity types with columns, hasOne, hasMany structure | | names.ts | Runtime schema names (JSON) for query building | | enums.ts | TypeScript enum types | | types.ts | Shared schema interface definitions | | index.ts | Exports and pre-configured bindx instance |

Example Output

Without ACL

// entities.ts
export interface Article {
  columns: {
    id: string
    title: string
    content: string | null
  }
  hasOne: {
    author: Author
  }
  hasMany: {
    tags: Tag
  }
}

// index.ts
export const { useEntity, useEntityList, Entity, createComponent } = createBindx<BindxSchema>(schemaNames)

With Role-Based ACL

// entities.ts
export interface PublicArticle {
  columns: {
    id: string
    title: string
  }
  hasOne: {}
  hasMany: {}
}

export interface EditorArticle {
  columns: {
    id: string
    title: string
    content: string | null
  }
  hasOne: {
    author: EditorAuthor
  }
  hasMany: {
    tags: EditorTag
  }
}

export interface RoleSchemas {
  public: PublicSchema
  editor: EditorSchema
}

// index.ts
export const {
  roleSchemaRegistry,
  RoleAwareProvider,
  Entity,
  HasRole,
  useEntity,
  useEntityList,
  createComponent
} = createRoleAwareBindx<RoleSchemas>(roleSchemaDefinitions)

Options

export interface BindxGeneratorOptions {
  /**
   * Whether to flatten inherited roles.
   * Default: true
   */
  flattenInheritance?: boolean

  /**
   * Whether to treat predicate-based permissions as allowed.
   * When true, any non-false permission allows access.
   * When false, only explicit `true` permissions are allowed.
   * Default: true
   */
  allowPredicateAccess?: boolean
}

const files = generate(model, acl, {
  flattenInheritance: true,
  allowPredicateAccess: true
})

CLI Usage

You can create a script to generate schemas:

// scripts/generate-schema.ts
import { generate } from '@contember/bindx-generator'
import { Model, Acl } from '@contember/schema'
import { writeFile, mkdir } from 'fs/promises'
import { join } from 'path'

// Import your model and ACL
import { model, acl } from './your-schema'

async function main() {
  const files = generate(model, acl)
  
  const outputDir = './src/generated'
  await mkdir(outputDir, { recursive: true })
  
  for (const [filename, content] of Object.entries(files)) {
    await writeFile(join(outputDir, filename), content)
  }
  
  console.log('✅ Schema generated')
}

main()

Add to package.json:

{
  "scripts": {
    "generate:schema": "tsx scripts/generate-schema.ts"
  }
}

How It Works

ACL Filtering

The generator applies ACL permissions similar to Contember's IntrospectionSchemaFactory:

  1. Entity Filtering: Only entities with read operations are included
  2. Field Filtering: Only fields with read permissions (true or predicates) are included
  3. Relation Filtering: Relations to inaccessible entities are excluded
  4. Role Inheritance: Permissions from inherited roles are merged

Type Safety

Generated types are fully type-safe:

// Public role cannot access content field
<RoleAwareProvider roles={['public']}>
  <Entity name="Article" id={id}>
    {article => (
      // ✅ OK
      <div>{article.data.title}</div>
      
      // ❌ Type error: 'content' doesn't exist on PublicArticle
      <div>{article.data.content}</div>
    )}
  </Entity>
</RoleAwareProvider>

License

MIT