Skip to content

Commit 41cd478

Browse files
committed
extract policy plugin to its own package
1 parent be2553b commit 41cd478

26 files changed

+193
-107
lines changed
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
{
2+
"name": "@zenstackhq/plugin-policy",
3+
"version": "3.0.0-beta.8",
4+
"description": "ZenStack Policy Plugin",
5+
"type": "module",
6+
"scripts": {
7+
"build": "tsc --noEmit && tsup-node",
8+
"watch": "tsup-node --watch",
9+
"lint": "eslint src --ext ts",
10+
"pack": "pnpm pack"
11+
},
12+
"keywords": [],
13+
"author": "ZenStack Team",
14+
"license": "MIT",
15+
"files": [
16+
"dist"
17+
],
18+
"exports": {
19+
".": {
20+
"import": {
21+
"types": "./dist/index.d.ts",
22+
"default": "./dist/index.js"
23+
},
24+
"require": {
25+
"types": "./dist/index.d.cts",
26+
"default": "./dist/index.cjs"
27+
}
28+
},
29+
"./package.json": {
30+
"import": "./package.json",
31+
"require": "./package.json"
32+
}
33+
},
34+
"dependencies": {
35+
"@zenstackhq/common-helpers": "workspace:*",
36+
"@zenstackhq/sdk": "workspace:*",
37+
"@zenstackhq/runtime": "workspace:*",
38+
"ts-pattern": "catalog:"
39+
},
40+
"peerDependencies": {
41+
"kysely": "catalog:"
42+
},
43+
"devDependencies": {
44+
"@types/better-sqlite3": "^7.6.13",
45+
"@types/pg": "^8.0.0",
46+
"@zenstackhq/eslint-config": "workspace:*",
47+
"@zenstackhq/typescript-config": "workspace:*",
48+
"@zenstackhq/vitest-config": "workspace:*"
49+
}
50+
}

packages/runtime/src/plugins/policy/column-collector.ts renamed to packages/plugins/policy/src/column-collector.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import type { ColumnNode, OperationNode } from 'kysely';
2-
import { DefaultOperationNodeVisitor } from '../../utils/default-operation-node-visitor';
2+
import { DefaultOperationNodeVisitor } from '@zenstackhq/sdk';
33

44
/**
55
* Collects all column names from a query.

packages/runtime/src/plugins/policy/expression-evaluator.ts renamed to packages/plugins/policy/src/expression-evaluator.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import {
1010
type LiteralExpression,
1111
type MemberExpression,
1212
type UnaryExpression,
13-
} from '../../schema';
13+
} from '@zenstackhq/runtime/schema';
1414

1515
type ExpressionEvaluatorContext = {
1616
auth?: any;

packages/runtime/src/plugins/policy/expression-transformer.ts renamed to packages/plugins/policy/src/expression-transformer.ts

Lines changed: 27 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,31 @@
11
import { invariant } from '@zenstackhq/common-helpers';
2+
import {
3+
getCrudDialect,
4+
InternalError,
5+
QueryError,
6+
QueryUtils,
7+
type BaseCrudDialect,
8+
type ClientContract,
9+
type CRUD_EXT,
10+
} from '@zenstackhq/runtime';
11+
import type {
12+
BinaryExpression,
13+
BinaryOperator,
14+
BuiltinType,
15+
FieldDef,
16+
GetModels,
17+
LiteralExpression,
18+
MemberExpression,
19+
UnaryExpression,
20+
} from '@zenstackhq/runtime/schema';
21+
import {
22+
ExpressionUtils,
23+
type ArrayExpression,
24+
type CallExpression,
25+
type Expression,
26+
type FieldExpression,
27+
type SchemaDef,
28+
} from '@zenstackhq/runtime/schema';
229
import {
330
AliasNode,
431
BinaryOperationNode,
@@ -20,29 +47,6 @@ import {
2047
type OperationNode,
2148
} from 'kysely';
2249
import { match } from 'ts-pattern';
23-
import { QueryUtils } from '../../client';
24-
import type { ClientContract, CRUD_EXT } from '../../client/contract';
25-
import { getCrudDialect } from '../../client/crud/dialects';
26-
import type { BaseCrudDialect } from '../../client/crud/dialects/base-dialect';
27-
import { InternalError, QueryError } from '../../client/errors';
28-
import type {
29-
BinaryExpression,
30-
BinaryOperator,
31-
BuiltinType,
32-
FieldDef,
33-
GetModels,
34-
LiteralExpression,
35-
MemberExpression,
36-
UnaryExpression,
37-
} from '../../schema';
38-
import {
39-
ExpressionUtils,
40-
type ArrayExpression,
41-
type CallExpression,
42-
type Expression,
43-
type FieldExpression,
44-
type SchemaDef,
45-
} from '../../schema';
4650
import { ExpressionEvaluator } from './expression-evaluator';
4751
import { conjunction, disjunction, falseNode, isBeforeInvocation, logicalNot, trueNode } from './utils';
4852

packages/runtime/src/plugins/policy/functions.ts renamed to packages/plugins/policy/src/functions.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
import { invariant } from '@zenstackhq/common-helpers';
2+
import type { ZModelFunction, ZModelFunctionContext } from '@zenstackhq/runtime';
3+
import { CRUD, QueryUtils } from '@zenstackhq/runtime';
24
import { ExpressionWrapper, ValueNode, type Expression, type ExpressionBuilder } from 'kysely';
3-
import { QueryUtils } from '../../client';
4-
import { CRUD } from '../../client/contract';
5-
import type { ZModelFunction, ZModelFunctionContext } from '../../client/options';
65
import { PolicyHandler } from './policy-handler';
76

87
/**

packages/runtime/src/plugins/policy/plugin.ts renamed to packages/plugins/policy/src/plugin.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import { type OnKyselyQueryArgs, type RuntimePlugin } from '../../client/plugin';
2-
import type { SchemaDef } from '../../schema';
1+
import { type OnKyselyQueryArgs, type RuntimePlugin } from '@zenstackhq/runtime';
2+
import type { SchemaDef } from '@zenstackhq/runtime/schema';
33
import { check } from './functions';
44
import { PolicyHandler } from './policy-handler';
55

packages/runtime/src/plugins/policy/policy-handler.ts renamed to packages/plugins/policy/src/policy-handler.ts

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,23 @@
11
import { invariant } from '@zenstackhq/common-helpers';
2+
import type { BaseCrudDialect, ClientContract, ProceedKyselyQueryFunction } from '@zenstackhq/runtime';
3+
import {
4+
getCrudDialect,
5+
InternalError,
6+
QueryError,
7+
QueryUtils,
8+
RejectedByPolicyError,
9+
RejectedByPolicyReason,
10+
type CRUD_EXT,
11+
} from '@zenstackhq/runtime';
12+
import {
13+
ExpressionUtils,
14+
type BuiltinType,
15+
type Expression,
16+
type GetModels,
17+
type MemberExpression,
18+
type SchemaDef,
19+
} from '@zenstackhq/runtime/schema';
20+
import { ExpressionVisitor } from '@zenstackhq/sdk';
221
import {
322
AliasNode,
423
BinaryOperationNode,
@@ -33,22 +52,6 @@ import {
3352
type RootOperationNode,
3453
} from 'kysely';
3554
import { match } from 'ts-pattern';
36-
import type { ClientContract } from '../../client';
37-
import { QueryUtils } from '../../client';
38-
import { type CRUD_EXT } from '../../client/contract';
39-
import { getCrudDialect } from '../../client/crud/dialects';
40-
import type { BaseCrudDialect } from '../../client/crud/dialects/base-dialect';
41-
import { InternalError, QueryError, RejectedByPolicyError, RejectedByPolicyReason } from '../../client/errors';
42-
import type { ProceedKyselyQueryFunction } from '../../client/plugin';
43-
import {
44-
ExpressionUtils,
45-
type BuiltinType,
46-
type Expression,
47-
type GetModels,
48-
type MemberExpression,
49-
type SchemaDef,
50-
} from '../../schema';
51-
import { ExpressionVisitor } from '../../utils/expression-utils';
5255
import { ColumnCollector } from './column-collector';
5356
import { ExpressionTransformer } from './expression-transformer';
5457
import type { Policy, PolicyOperation } from './types';

packages/runtime/src/plugins/policy/types.ts renamed to packages/plugins/policy/src/types.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import type { CRUD_EXT } from '../../client/contract';
2-
import type { Expression } from '../../schema';
1+
import type { CRUD_EXT } from '@zenstackhq/runtime';
2+
import type { Expression } from '@zenstackhq/runtime/schema';
33

44
/**
55
* Access policy kind.

packages/runtime/src/plugins/policy/utils.ts renamed to packages/plugins/policy/src/utils.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import type { BaseCrudDialect } from '@zenstackhq/runtime';
2+
import { ExpressionUtils, type Expression, type SchemaDef } from '@zenstackhq/runtime/schema';
13
import type { OperationNode } from 'kysely';
24
import {
35
AliasNode,
@@ -12,8 +14,6 @@ import {
1214
UnaryOperationNode,
1315
ValueNode,
1416
} from 'kysely';
15-
import type { BaseCrudDialect } from '../../client/crud/dialects/base-dialect';
16-
import { ExpressionUtils, type Expression, type SchemaDef } from '../../schema';
1717

1818
/**
1919
* Creates a `true` value node.

0 commit comments

Comments
 (0)