codemod
Rename the identifiers a permdock release renamed, in every file that imports permdock, rewrite the call shapes it can tie to an import, and list the rest for a manual edit.
permdock codemod 0.17 rewrites the object literals 0.17.0 reshaped. permdock codemod 0.26 rewrites a stored catalog-v1 document and the generate commands 0.26 removed. It lists the sites it would not change on its own, each with file:line:column. It exits 0 whether or not it found anything; run your type checker afterwards.
Usage
permdock codemod 0.26 # every source file under the working directory
permdock codemod 0.26 src apps/web --dry-run # report only, write nothing
permdock codemod 0.17 src --json # the report as JSONThe positional arguments after the version are files or directories; the default is the working directory. The command reads .ts, .tsx, .mts, .cts, .js, .jsx, .mjs, .cjs, .vue and .svelte files and skips node_modules, dist, .git, .next, .turbo, .svelte-kit and coverage. In a Vue or Svelte file it rewrites each <script> block. A file that imports no permdock entry is never changed, except a permdock.config.* file.
| Flag | Meaning |
|---|---|
--dry-run | Print the report without writing any file |
--force | Rewrite files with uncommitted changes too; without it, a dirty file in a git work tree exits 1 (file_conflict) |
--json | data in the result: { version, dryRun, scanned, files, followUps }; an unknown version is a usage error document |
--prune | With config: remove each key set to its default (Prune the config) |
--check | With config --prune or bsb-access-tags: write nothing and exit 1 when a key would be removed or a table would move |
The codemod rewrites files in place, so in agent mode a run without --dry-run first asks for the person's confirmation (rewrite).
The version is 0.17, 0.26 or 0.31 (0.17.0 and v0.17 are read the same way; 0.32 is an alias of 0.31). Any other version is a usage error that names the supported ones, exit 2. The 0.5 and 0.8 rename tables are history on the Naming page.
Prune the config
permdock codemod config --prune removes each permdock.config key set to its default, the keys doctor PD120 lists. Before it writes, it regenerates every plugin output and the gen modules in memory, with and without the keys. When a byte differs it tries each section, then each key of a section that differs, and keeps a key whose removal changes a file. The comment lines directly above a removed key go with it.
Besides the fixed defaults, it removes a rls.actions verb set to 'none' that compiles to no command without its entry, and a rls.tables or rls.scopeTypes entry equal to what the schema files resolve (table bindings). The same byte check decides each of them.
permdock codemod config --prune --check # exit 1 when a key would be removed, for CI
permdock codemod config --prune # remove themWith --json, data is { file, check, removed, kept, unreachable }. unreachable lists keys the codemod found in the loaded config but not as an object literal key in the file, such as a value from a spread; remove those by hand.
Replace manager walks
permdock codemod manager-chain [dir] replaces hand-written functions that walk the self-referencing rls.approvals.managers table with the generated helpers (self-referencing manager tables). It reads the SQL files in dir (default supabase/schemas), matches each function that walks the table with with recursive to a helper by its signature, rewrites every call site, in policies and in function bodies, and deletes the definition with its grant, revoke and comment statements. A function whose status filter differs from active stays. With --json, data is { replaced, kept, files }.
Move tenant policies to access tags
permdock codemod bsb-access-tags [dir] rewrites plain tenant policies into a better-supabase @bsb access tag. A policy qualifies when its parsed expression is <column> in (select <schema>.permitted_<scope>_ids('<key>')), optionally followed by and <schema>.permdock_actor_may_write(). The codemod swaps a key only when permitted_<scope>_ids_by_permission(key) returns the same rows: every grant of the key is an allow of that key itself, with no condition and no deny. It then sets the tag on the table comment, renders the tag's block with better-supabase's renderTagBlock, and deletes the old policies. Every other policy stays and is listed with its reason. For a key the helpers answer differently, the reason names the first grant that decides it: a deny (role blocked on organization denies it), a grant under a condition (grant key note.read#1) or a grant through another key. --check writes nothing, prints the same list and exits 1 when a table would move. With --json, data is { moved, kept, files }. The codemod needs better-supabase installed.
rls verify --introspect, rls verify --shadow, rls explain, rls report and doctor read the policies each @bsb access tag renders from better-supabase's accessPolicies and treat them as generated: verify does not report them as policy-extra, and PD090, PD103, PD104 and PD108 do not count them as hand-written. A policy is never recognised by its bsb_access_ name prefix.
Move block keys to answers
permdock codemod bsb-action-keys moves the keys a better-supabase config names under a blocks entry's permissions into the answers of the permission with that key, so the provider's actionKeys carries them. It moves only the actions better-supabase's listActions reports with source config.
// better-supabase.config.ts, before
blocks: [{ block: "audit", permissions: { read: "audit.view" } }],
// src/permissions.ts, after
audit: resource({ collection: { view: { answers: ["blocks.audit.read"] } } }),The codemod removes the string from the blocks entry, and the permissions object once it is empty. It adds the answer to the action's meta in the definePermissions call of the permissions module, turning an action array into a record when needed. The path to the action may run through object literals, top-level constants and resource() calls. Options nested deeper in an entry, such as on.<event>.permissions, stay. A key stays in the config, and is listed with its reason, when the config names it outside a literal blocks entry or the module declares the action in another form. With --json, data is { moved, kept, files }. The codemod needs better-supabase 0.84.0 or later installed.
What it renames
The 0.5.0 names are history on the Naming page. permdock codemod no longer applies that table. A row renamed an identifier only where it was imported from one of the entries the row names, so a local memorySink of your own stayed as it was.
| Source | Result |
|---|---|
import { memorySink } from 'permdock' | import { memoryDecisionSink }, and every reference to it renamed |
import { memorySink as sink } from 'permdock' | import { memoryDecisionSink as sink }; sink stays |
import type { MemorySink }, { type MemorySink } | The type renamed the same way, in type positions too |
const config = { memorySink } | { memorySink: memoryDecisionSink }, so the object keeps its shape |
export { memorySink } | export { memoryDecisionSink as memorySink }, so your module's export keeps its name |
export { memorySink } from 'permdock' | export { memoryDecisionSink as memorySink } from 'permdock' |
import * as pd from 'permdock', pd.memorySink | pd.memoryDecisionSink |
scimHandler({ store }) | scimHandler({ directory: store }): an option key in an object literal passed straight to the function the row names |
const kit = createPermDock(…), kit.permdock() | kit.middleware() from permdock/hono, kit.getPermDock() from permdock/server: a member on a module-level const that holds the factory's result |
A reference the import does not bind keeps its name: a parameter, a local variable, a destructured name, a property key or a member of another object. When the new name is already bound where a reference sits, or the file is a Vue or Svelte component whose template may read the import, the codemod writes import { memoryDecisionSink as memorySink } instead and leaves the references alone.
What it rewrites
Some 0.5.0 changes move more than a name. The codemod rewrites these where the import binding shows the call is PermDock's; the rows live in packages/permdock/src/cli/codemod/shapes-0.5.ts.
| Source | Result |
|---|---|
<Protected fallback={…}> from permdock/react, react-native, solid | <Protected denied={…}> |
h(Protected, props, { fallback }) from permdock/vue | h(Protected, props, { denied: fallback }) |
<PermDockProvider defaults={{ fallback }}> | <PermDockProvider defaults={{ denied: fallback }}> |
await createPermDock(policy, user, options) from permdock | await getPermDock(policy, user, options), imported beside the others; any other core createPermDock call becomes getPermDockSync |
createPermDock from permdock/pdp | getPermDock, which keeps its always-async behaviour |
customRoleSource({ rolesOf }) | customRoleSource({ rolesFor: rolesOf }) |
permdock.decideRoleChange(change), and decideCredential, decideAutomation, decideSupportSession, whoCan on any receiver | decideRoleChange(permdock, change), imported from permdock |
permdock.simulate({ arazzo, openapi }) | simulateArazzo(permdock, { arazzo, openapi }) |
permdock.activate(input) on a receiver named like permdock or a module-level factory result | activate(permdock, input) |
permittedIds(permdock, permission, scope), mayUse(permdock, permission) | permdock.permittedIds(permission, scope), permdock.mayUse(permission); the import goes once nothing reads it |
createPermDock(policy, user, { approvalPolicies: source }) from permdock or permdock/pdp | { approvalPolicies: approvalPolicies(source) }; a memoryApprovalPolicySource([…]) value stays as it is |
createPermDock(policy, user, { policies: source }) | { policies: hostedPolicies(source) } |
ttl: '30m', after, per, window, maxDuration, duration or a durations list of s, m, h, d or w strings, inside a call to a PermDock import | Whole seconds: ttl: 1800 |
CLI calls
The same run rewrites permdock command lines renamed in 0.5.0 in package.json, Makefile, justfile, Dockerfile, .yml, .yaml and .sh files: moved commands (permdock openapi becomes permdock openapi emit), renamed flags and values (usage --strict becomes usage --fail-on warning, catalog --format schema becomes catalog --kind json-schema), and a changed default (rls migrate without --write or --retire-out gains --dry-run, since it now writes by default). It matches permdock, npx permdock, pnpm exec permdock and a versioned permdock@0.4, and stops a command at &&, ||, ;, a pipe, a redirect or a comment.
A flag that needs a person's choice is a follow-up, not a rewrite: cloud push --environment asks for the project id. A removed generate command (rls generate, gen and the others) becomes permdock generate --only <plugin>, and each flag permdock generate does not take, such as --out or --force-rls, stays on the line as a follow-up to move onto the plugin's options in permdock.config.ts. In .md and .mdx files every call is a follow-up, since prose around it may need the same edit. The rows are on the Naming page.
Config keys in 0.8
permdock codemod no longer applies the 0.8.0 config moves. This table is the history of the keys 0.8.0 folded into named scopes.
| Source | Result |
|---|---|
rls.tenantType | rls.scopeTypes.tenant |
rls.teamType | rls.scopeTypes.team |
rls.memberships.tenant, rls.memberships.team | rls.memberships.scopes.tenant, .scopes.team |
tenant and team on a table under rls.memberships.scopes or rls.memberships.resource | columns.tenant, columns.team |
tenant and team stay valid keys there: they name the first and second declared scope. A key whose target is already set, or sits under a value that is not an object literal, is a follow-up to merge by hand. The options of supabaseRls() keep their shape; it normalises them itself.
The client RolesOptions lost team in 0.8. Every useRoles call (permdock/react, react-native, vue, solid) and every roles or rolesFor call in permdock/svelte is a follow-up: useRoles({ team: id }) becomes useRoles({ scope: "team", id }), which lists only the roles on that team's memberships.
Literals in 0.17
permdock codemod 0.17 rewrites the object literals 0.17.0 reshaped, in .ts, .tsx, .js and .jsx files that mention permdock; the rows live in packages/permdock/src/cli/codemod/shapes-0.17.ts. It matches an object by its keys, not by the call it reaches, so run your type checker afterwards.
| Source | Result |
|---|---|
{ tenant: "acme", roles } | { scope: "tenant", id: "acme", roles } |
{ tenant: "acme", team: "t1", roles } | { within: { tenant: "acme" }, scope: "team", id: "t1", roles } |
{ by, mode: "sequential" }, "all", "any" (with by or stages) | { by, combine: "sequential" } |
{ by, distinct: false } | { by, mode: "confirm" } |
{ by, distinct: true } | { by }: authorize is the default |
A membership literal counts only when it has roles, tenant or team holds a string expression, and every key is a membership field (via, expiresAt, grantedBy, reason, member, managedBy, entitlements, keep, eligible, x). A credential, an event or a principal that carries tenant and roles stays as it is. A distinct that is not a literal and every ApprovalMode type reference are follow-ups: ApprovalMode is now 'confirm' | 'authorize', and the stage combinator type is ApprovalCombine.
Rewrites in 0.26
permdock codemod 0.26 also reads .sql files and the string and template literals of each source file. There, permitted_<resource>_row( becomes can_<resource>(, ::text around a helper call goes and own_subject() is deleted; the same text in code outside a literal stays. A .sql file under a migrations or drizzle directory is history, so each rewrite there is a follow-up to write a new migration.
In a config object, the one defineConfig from permdock receives or a permdock.config.* file exports, { tableOf: "owner" } entries move onto the owner's also list, and an rls.actions entry equal to the command PermDock infers from the action name is removed with its comment lines. Imports of the 0.25 generated files move to the new names: permdock.generated.ts is constants.ts, permdock.schemas.ts is standard-schema.ts.
Rewrites in 0.31
permdock codemod 0.31 rewrites the config object, the one defineConfig from permdock receives or a permdock.config.* file exports. The 0.31 upgrade guide lists every breaking change, with the ones this codemod does not make.
| Source | Result |
|---|---|
doctor.waivers: [{ code: "PD017", key, reason }] | { "code": "PD017", "reason": ..., "targets": [key] } in the doctor.baseline file |
doctor.ignore: [{ id: "<code>:<target>", reason }] | { "code": ..., "reason": ..., "targets": [target] } in the doctor.baseline file |
Without doctor.baseline, the config gains baseline: "doctor-baseline.json" and the codemod writes that file next to the config. With it, the entries merge into the file it names. The file is written with the config, so --dry-run writes neither and lists both. A list the config computes, a doctor.baseline that is not a string literal, or a baseline file that does not parse is a follow-up, and the config stays as it is (accept a finding).
What it reports
These sites go under Manual follow-ups and are never rewritten:
- Call shapes. A call to an import whose signature changed, such as
subjectFromApiKey(options)(key), nowsubjectFromApiKey(key, options). ForsubjectFromApiKeyonly the old shape counts: one argument that is an object literal or whose result is called. A call already in the new shape is left alone. An import of such a function that is never called is reported at the import. - Members. A member renamed on a value a factory returns, when the value is not a module-level
constholding the factory's result: a parameter,const { permdock } = …, or a value passed between modules. - Option keys. An option key in an object literal that reaches a PermDock call, such as
{ source: 'mcp' }forcall. The object reaches the call when it is an argument of a function imported from the entry, or of a method on a value named after PermDock or held in a module constant from a PermDock factory, directly or nested in that argument's objects and arrays. An object passed to the application's own functions is left alone. - Unawaited core
createPermDock. A call returned or chained with.thenwithoutawait. It still becomesgetPermDockSync, which returns the instance; a source that answers asynchronously needsgetPermDock. - Feature methods it cannot move. An optional call such as
permdock?.whoCan(…), a call with type arguments, or one where the function name is already bound in that scope. - Approval policy options elsewhere. An
approvalPolicieskey in an object literal that is not passed straight tocreatePermDock,getPermDockorgetPermDockSync. - Duration strings elsewhere. The same keys in an object literal that is not inside a call to a PermDock import, with the seconds to write.
- Template slots. A Vue
#fallbackslot or a Svelte{#snippet fallback}in a component that importsProtected, and aPermDockProviderwhosedefaultsthe codemod cannot read or whose import it cannot see. - Parse failures. A file the parser rejects is listed and left as it is.
Side effects
What each command may change; side effects explains each one.
| Command | Side effects |
|---|---|
permdock codemod | rewrite |
Why
A rename that only a changelog describes costs every consumer the same search and replace, and a text replace renames a local memorySink or an object key along with the import. The codemod parses each file with oxc-parser and follows the import binding through its scopes, so it changes exactly the names PermDock exported. A call whose shape changed is rewritten only where the import binding or the call proves it is PermDock's; every other site is listed instead of guessed. The rename map is one TypeScript file that the changesets and the Naming page are checked against by pnpm docs:drift, so the three cannot drift apart.
Related
Last updated on
scim
permdock scim generate writes the Postgres tables postgresDirectoryStore keeps a SCIM directory in, with every row keyed on its tenant and userName and externalId unique per tenant.
Next.js plugin
createPermDockPlugin runs permdock collect during next dev and next build; it is a build hook only and never wires the PermDock API.