Skip to content

Commit f3b8a6b

Browse files
committed
refactor(policy): extract plugin options type
1 parent cc4504b commit f3b8a6b

3 files changed

Lines changed: 13 additions & 12 deletions

File tree

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
export type PolicyPluginOptions = {
2+
/**
3+
* Dangerously bypasses access-policy enforcement for raw SQL queries.
4+
* Raw queries remain in the current transaction, but the policy plugin will
5+
* not inspect or reject them.
6+
*/
7+
dangerouslyAllowRawSql?: boolean;
8+
};

packages/plugins/policy/src/plugin.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
import { type OnKyselyQueryArgs, type RuntimePlugin } from '@zenstackhq/orm';
22
import type { SchemaDef } from '@zenstackhq/orm/schema';
3+
import type { PolicyPluginOptions } from './options';
34
import { check } from './functions';
4-
import { PolicyHandler, type PolicyHandlerOptions } from './policy-handler';
5+
import { PolicyHandler } from './policy-handler';
56

6-
export type PolicyPluginOptions = PolicyHandlerOptions;
7+
export type { PolicyPluginOptions } from './options';
78

89
export class PolicyPlugin implements RuntimePlugin<SchemaDef, {}, {}, {}> {
910
constructor(private readonly options: PolicyPluginOptions = {}) {}

packages/plugins/policy/src/policy-handler.ts

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ import {
4343
import { match } from 'ts-pattern';
4444
import { ColumnCollector } from './column-collector';
4545
import { ExpressionTransformer } from './expression-transformer';
46+
import type { PolicyPluginOptions } from './options';
4647
import type { Policy, PolicyOperation } from './types';
4748
import {
4849
buildIsFalse,
@@ -64,22 +65,13 @@ export type MutationQueryNode = InsertQueryNode | UpdateQueryNode | DeleteQueryN
6465

6566
type FieldLevelPolicyOperations = Exclude<CRUD_EXT, 'create' | 'delete'>;
6667

67-
export type PolicyHandlerOptions = {
68-
/**
69-
* Dangerously bypasses access-policy enforcement for raw SQL queries.
70-
* Raw queries remain in the current transaction, but the policy plugin will
71-
* not inspect or reject them.
72-
*/
73-
dangerouslyAllowRawSql?: boolean;
74-
};
75-
7668
export class PolicyHandler<Schema extends SchemaDef> extends OperationNodeTransformer {
7769
private readonly dialect: BaseCrudDialect<Schema>;
7870
private readonly eb = expressionBuilder<any, any>();
7971

8072
constructor(
8173
private readonly client: ClientContract<Schema>,
82-
private readonly options: PolicyHandlerOptions = {},
74+
private readonly options: PolicyPluginOptions = {},
8375
) {
8476
super();
8577
this.dialect = getCrudDialect(this.client.$schema, this.client.$options);

0 commit comments

Comments
 (0)