forked from zenstackhq/zenstack
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplugin.ts
More file actions
33 lines (26 loc) · 949 Bytes
/
plugin.ts
File metadata and controls
33 lines (26 loc) · 949 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import { type OnKyselyQueryArgs, type RuntimePlugin } from '@zenstackhq/orm';
import type { SchemaDef } from '@zenstackhq/orm/schema';
import { check } from './functions';
import { PolicyHandler, type PolicyHandlerOptions } from './policy-handler';
export type PolicyPluginOptions = PolicyHandlerOptions;
export class PolicyPlugin implements RuntimePlugin<SchemaDef, {}, {}, {}> {
constructor(private readonly options: PolicyPluginOptions = {}) {}
get id() {
return 'policy' as const;
}
get name() {
return 'Access Policy';
}
get description() {
return 'Enforces access policies defined in the schema.';
}
get functions() {
return {
check,
};
}
onKyselyQuery({ query, client, proceed }: OnKyselyQueryArgs<SchemaDef>) {
const handler = new PolicyHandler<SchemaDef>(client, this.options);
return handler.handle(query, proceed);
}
}