@lunora/server 1.0.0-alpha.26 → 1.0.0-alpha.28

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.mjs CHANGED
@@ -20,7 +20,7 @@ export { ValidationError, v } from '@lunora/values';
20
20
  export { buildRlsReadRegistry, composeShapeReadWhere } from './packem_shared/buildRlsReadRegistry-D54vUQe4.mjs';
21
21
  export { createPolicyDsl, definePermission, definePolicies, definePolicy, defineRole } from './packem_shared/createPolicyDsl-By3QB4he.mjs';
22
22
  export { defineStorageRule, defineStorageRules } from './packem_shared/defineStorageRule-B5nL4Z1P.mjs';
23
- export { mask } from './packem_shared/mask-DSBtA3qp.mjs';
23
+ export { mask } from './packem_shared/mask-CZuu9WAF.mjs';
24
24
  export { rls } from './packem_shared/rls-B_ZWgslr.mjs';
25
25
  export { storageRules } from './packem_shared/storageRules-6QxzDOcx.mjs';
26
26
 
@@ -208,6 +208,20 @@ const wrapDatabase = (base, perTable, context) => {
208
208
  };
209
209
  const wrapped = {
210
210
  ...base,
211
+ async deleteWhere(tableName, where, options) {
212
+ assertWhereAllowed(tableName, where, "deleteMany({ where })");
213
+ if (base.deleteWhere === void 0) {
214
+ throw new LunoraError("INTERNAL", `ctx.db.${tableName}.deleteMany({ where }) is unavailable: this writer has no where-based delete`);
215
+ }
216
+ return base.deleteWhere(tableName, where, options);
217
+ },
218
+ async patchWhere(tableName, args, options) {
219
+ assertWhereAllowed(tableName, args.where, "patchMany({ where })");
220
+ if (base.patchWhere === void 0) {
221
+ throw new LunoraError("INTERNAL", `ctx.db.${tableName}.patchMany({ where }) is unavailable: this writer has no where-based patch`);
222
+ }
223
+ return base.patchWhere(tableName, args, options);
224
+ },
211
225
  aggregate(tableName, options) {
212
226
  assertReductionAllowed(tableName, [options.field], "aggregate");
213
227
  assertWhereAllowed(tableName, options.where, "aggregate");
@@ -224,6 +238,7 @@ const wrapDatabase = (base, perTable, context) => {
224
238
  },
225
239
  async findFirst(tableName, args) {
226
240
  assertWhereAllowed(tableName, args?.where, "findFirst");
241
+ assertWhereAllowed(tableName, args?.baseWhere, "findFirst");
227
242
  assertOrderByAllowed(tableName, args?.orderBy, "findFirst");
228
243
  const row = await base.findFirst(tableName, args);
229
244
  const columns = perTable.get(tableName);
@@ -231,6 +246,7 @@ const wrapDatabase = (base, perTable, context) => {
231
246
  },
232
247
  async findFirstOrThrow(tableName, args) {
233
248
  assertWhereAllowed(tableName, args?.where, "findFirstOrThrow");
249
+ assertWhereAllowed(tableName, args?.baseWhere, "findFirstOrThrow");
234
250
  assertOrderByAllowed(tableName, args?.orderBy, "findFirstOrThrow");
235
251
  const row = await base.findFirstOrThrow(tableName, args);
236
252
  const columns = perTable.get(tableName);
@@ -238,6 +254,7 @@ const wrapDatabase = (base, perTable, context) => {
238
254
  },
239
255
  async findMany(tableName, args) {
240
256
  assertWhereAllowed(tableName, args?.where, "findMany");
257
+ assertWhereAllowed(tableName, args?.baseWhere, "findMany");
241
258
  assertOrderByAllowed(tableName, args?.orderBy, "findMany");
242
259
  const page = await base.findMany(tableName, args);
243
260
  const columns = perTable.get(tableName);
@@ -0,0 +1,141 @@
1
+ import { WhereOf } from "../data-model.mjs";
2
+ /** Structural mirror of `@lunora/do`'s `WhereInput`. */
3
+ interface WhereInput {
4
+ [field: string]: unknown;
5
+ AND?: WhereInput[];
6
+ NOT?: WhereInput;
7
+ OR?: WhereInput[];
8
+ }
9
+ /** Operations a policy can gate. `read` covers `get`/`findMany`/`query`/`count`. */
10
+ type PolicyOperation = "delete" | "insert" | "read" | "update";
11
+ /**
12
+ * A policy's `when` decision:
13
+ *
14
+ * - `WhereInput`: a row-shape predicate. On reads it is AND-merged into every
15
+ * query against the table — the row is invisible unless it matches. On writes
16
+ * it is evaluated against the candidate document (`insert`) or the pre-write
17
+ * row (`update`/`delete`); a mismatch denies the write with
18
+ * `LunoraError("FORBIDDEN")`. Same operator set as the SQL compiler
19
+ * (`eq`/`ne`/`in`/`notIn`/`lt`/`lte`/`gt`/`gte`/`isNull`/`contains` +
20
+ * `AND`/`OR`/`NOT`).
21
+ * - `true`: unrestricted. On reads no predicate is merged; on writes the row is
22
+ * allowed.
23
+ * - `false`: deny. On reads the table is forced to match zero rows (a sentinel
24
+ * predicate); on writes the operation throws `LunoraError("FORBIDDEN")`.
25
+ *
26
+ * Returning `undefined` opts this specific policy out (rare; useful when
27
+ * branching on `ctx.auth.roles`).
28
+ */
29
+ type PolicyDecision = WhereInput | boolean | undefined;
30
+ /**
31
+ * Relation-aware twin of {@link PolicyDecision}, parameterized over the
32
+ * generated `DataModel` (`DM`) + `Relations` (`REL`) maps and a table `T`. A
33
+ * read policy may now return a Prisma-style relation predicate (the
34
+ * `@lunora/do` pre-resolver resolves it via a semijoin), so the typed
35
+ * authoring surface accepts `WhereOf<DM, REL, T>` — column predicates **and**
36
+ * `is`/`isNot`/`some`/`none`/`every` over `T`'s declared relations — in
37
+ * addition to the `boolean`/`undefined` decisions. Used by the project-bound
38
+ * `definePolicy` from `createPolicyDsl`.
39
+ */
40
+ type PolicyDecisionOf<DM, REL extends Record<keyof DM, object>, T extends keyof DM> = WhereOf<DM, REL, T> | boolean | undefined;
41
+ /**
42
+ * Relation-aware input for a project-bound `definePolicy` (see
43
+ * `createPolicyDsl`). `table` is constrained to a real table name and
44
+ * `when`'s return type is the table-specific {@link PolicyDecisionOf} — so an
45
+ * unknown table, a stray column, or a relation predicate naming a relation the
46
+ * table does not declare is a compile error rather than a silent runtime deny.
47
+ */
48
+ interface TypedDefinePolicyInput<DM, REL extends Record<keyof DM, object>, T extends keyof DM, Context = unknown, Identity = Record<string, unknown>> {
49
+ on: PolicyOperation;
50
+ table: T;
51
+ when: (context: PolicyContext<Context, Identity>) => PolicyDecisionOf<DM, REL, T>;
52
+ }
53
+ /**
54
+ * Context handed to a policy. `auth.roles` is the per-request role list,
55
+ * sourced from the identity resolver (better-auth claims today). `auth.can`
56
+ * answers whether any of those roles grants a permission (see
57
+ * {@link Permission} / {@link RlsOptions}). `row` is present only on write
58
+ * policies (`insert`/`update`/`delete`) — for `update` and `delete` it is the
59
+ * pre-write row; for `insert` it is the candidate document. `ctx` is the full
60
+ * procedure context the middleware closed over.
61
+ */
62
+ interface PolicyContext<Context = unknown, Identity = Record<string, unknown>> {
63
+ readonly auth: {
64
+ /**
65
+ * `true` when any of the request's `roles` grants `permission` (passed
66
+ * by {@link Permission} object or its `name`). Always `false` when no
67
+ * roles were handed to the middleware (`rls(policies, { roles })`), or
68
+ * when none of the request's roles lists the permission.
69
+ */
70
+ readonly can: (permission: Permission | string) => boolean;
71
+ /**
72
+ * The resolved identity, typed to the `Identity` type parameter bound on
73
+ * `createPolicyDsl` — e.g. the app's `defineIdentity(...)` claim type via
74
+ * the `InferIdentity` helper; otherwise the untyped claim bag.
75
+ * `undefined`/`null` when the request is anonymous.
76
+ */
77
+ readonly identity?: Identity | null;
78
+ readonly roles: ReadonlyArray<string>;
79
+ readonly userId: null | string;
80
+ };
81
+ readonly ctx: Context;
82
+ readonly row?: Record<string, unknown>;
83
+ }
84
+ /** A registered policy as stored in the policy table. */
85
+ interface Policy<Context = unknown> {
86
+ readonly on: PolicyOperation;
87
+ readonly table: string;
88
+ readonly when: (context: PolicyContext<Context>) => PolicyDecision;
89
+ }
90
+ /**
91
+ * Input accepted by `definePolicy`. The branded result is the same
92
+ * shape; we keep the input/output split so callers can read JSDoc on the
93
+ * constructor without the type re-exposing `Policy` internals.
94
+ */
95
+ interface DefinePolicyInput<Context = unknown> {
96
+ on: PolicyOperation;
97
+ /** Logical table name the policy applies to. */
98
+ table: string;
99
+ /**
100
+ * Decision function. Returning a `WhereInput` (read only) AND-merges the
101
+ * predicate; `true` allows; `false` denies; `undefined` skips this policy.
102
+ *
103
+ * NOTE: `count()` is **unsupported** on a policy-restricted table — the
104
+ * reader throws `LunoraError("COUNT_RLS_UNSUPPORTED")` (422). This mirrors
105
+ * kitcn's documented behavior.
106
+ */
107
+ when: (context: PolicyContext<Context>) => PolicyDecision;
108
+ }
109
+ /**
110
+ * A named, abstract capability a policy can check with `ctx.auth.can(...)`,
111
+ * instead of branching on raw role strings. Declare one with
112
+ * `definePermission`; grant it to a role via {@link Role.permissions};
113
+ * register the roles with the middleware via {@link RlsOptions.roles}.
114
+ */
115
+ interface Permission {
116
+ readonly description?: string;
117
+ readonly name: string;
118
+ }
119
+ /**
120
+ * A role declaration. Roles are string labels attached to the request's
121
+ * identity (via better-auth claims today). `permissions` lists the
122
+ * capabilities the role grants — at request time the middleware unions the
123
+ * permissions of every role in `ctx.auth.roles` so a policy can ask
124
+ * `ctx.auth.can(permission)` rather than enumerate roles.
125
+ */
126
+ interface Role {
127
+ readonly description?: string;
128
+ readonly name: string;
129
+ /** Permissions this role grants — by {@link Permission} object or bare name. */
130
+ readonly permissions?: ReadonlyArray<Permission | string>;
131
+ }
132
+ /**
133
+ * Options for the `rls(policies, options)` middleware. `roles` registers the
134
+ * role→permission grants that back `ctx.auth.can(...)`; a role not listed here
135
+ * grants no permissions (so `can` is conservative — it fails closed for
136
+ * unknown roles).
137
+ */
138
+ interface RlsOptions {
139
+ readonly roles?: ReadonlyArray<Role>;
140
+ }
141
+ export { DefinePolicyInput as D, PolicyOperation as P, Role as R, TypedDefinePolicyInput as T, WhereInput as W, Policy as a, Permission as b, RlsOptions as c, PolicyContext as d, PolicyDecision as e, PolicyDecisionOf as f };
@@ -0,0 +1,141 @@
1
+ import { WhereOf } from "../data-model.js";
2
+ /** Structural mirror of `@lunora/do`'s `WhereInput`. */
3
+ interface WhereInput {
4
+ [field: string]: unknown;
5
+ AND?: WhereInput[];
6
+ NOT?: WhereInput;
7
+ OR?: WhereInput[];
8
+ }
9
+ /** Operations a policy can gate. `read` covers `get`/`findMany`/`query`/`count`. */
10
+ type PolicyOperation = "delete" | "insert" | "read" | "update";
11
+ /**
12
+ * A policy's `when` decision:
13
+ *
14
+ * - `WhereInput`: a row-shape predicate. On reads it is AND-merged into every
15
+ * query against the table — the row is invisible unless it matches. On writes
16
+ * it is evaluated against the candidate document (`insert`) or the pre-write
17
+ * row (`update`/`delete`); a mismatch denies the write with
18
+ * `LunoraError("FORBIDDEN")`. Same operator set as the SQL compiler
19
+ * (`eq`/`ne`/`in`/`notIn`/`lt`/`lte`/`gt`/`gte`/`isNull`/`contains` +
20
+ * `AND`/`OR`/`NOT`).
21
+ * - `true`: unrestricted. On reads no predicate is merged; on writes the row is
22
+ * allowed.
23
+ * - `false`: deny. On reads the table is forced to match zero rows (a sentinel
24
+ * predicate); on writes the operation throws `LunoraError("FORBIDDEN")`.
25
+ *
26
+ * Returning `undefined` opts this specific policy out (rare; useful when
27
+ * branching on `ctx.auth.roles`).
28
+ */
29
+ type PolicyDecision = WhereInput | boolean | undefined;
30
+ /**
31
+ * Relation-aware twin of {@link PolicyDecision}, parameterized over the
32
+ * generated `DataModel` (`DM`) + `Relations` (`REL`) maps and a table `T`. A
33
+ * read policy may now return a Prisma-style relation predicate (the
34
+ * `@lunora/do` pre-resolver resolves it via a semijoin), so the typed
35
+ * authoring surface accepts `WhereOf&lt;DM, REL, T>` — column predicates **and**
36
+ * `is`/`isNot`/`some`/`none`/`every` over `T`'s declared relations — in
37
+ * addition to the `boolean`/`undefined` decisions. Used by the project-bound
38
+ * `definePolicy` from `createPolicyDsl`.
39
+ */
40
+ type PolicyDecisionOf<DM, REL extends Record<keyof DM, object>, T extends keyof DM> = WhereOf<DM, REL, T> | boolean | undefined;
41
+ /**
42
+ * Relation-aware input for a project-bound `definePolicy` (see
43
+ * `createPolicyDsl`). `table` is constrained to a real table name and
44
+ * `when`'s return type is the table-specific {@link PolicyDecisionOf} — so an
45
+ * unknown table, a stray column, or a relation predicate naming a relation the
46
+ * table does not declare is a compile error rather than a silent runtime deny.
47
+ */
48
+ interface TypedDefinePolicyInput<DM, REL extends Record<keyof DM, object>, T extends keyof DM, Context = unknown, Identity = Record<string, unknown>> {
49
+ on: PolicyOperation;
50
+ table: T;
51
+ when: (context: PolicyContext<Context, Identity>) => PolicyDecisionOf<DM, REL, T>;
52
+ }
53
+ /**
54
+ * Context handed to a policy. `auth.roles` is the per-request role list,
55
+ * sourced from the identity resolver (better-auth claims today). `auth.can`
56
+ * answers whether any of those roles grants a permission (see
57
+ * {@link Permission} / {@link RlsOptions}). `row` is present only on write
58
+ * policies (`insert`/`update`/`delete`) — for `update` and `delete` it is the
59
+ * pre-write row; for `insert` it is the candidate document. `ctx` is the full
60
+ * procedure context the middleware closed over.
61
+ */
62
+ interface PolicyContext<Context = unknown, Identity = Record<string, unknown>> {
63
+ readonly auth: {
64
+ /**
65
+ * `true` when any of the request's `roles` grants `permission` (passed
66
+ * by {@link Permission} object or its `name`). Always `false` when no
67
+ * roles were handed to the middleware (`rls(policies, { roles })`), or
68
+ * when none of the request's roles lists the permission.
69
+ */
70
+ readonly can: (permission: Permission | string) => boolean;
71
+ /**
72
+ * The resolved identity, typed to the `Identity` type parameter bound on
73
+ * `createPolicyDsl` — e.g. the app's `defineIdentity(...)` claim type via
74
+ * the `InferIdentity` helper; otherwise the untyped claim bag.
75
+ * `undefined`/`null` when the request is anonymous.
76
+ */
77
+ readonly identity?: Identity | null;
78
+ readonly roles: ReadonlyArray<string>;
79
+ readonly userId: null | string;
80
+ };
81
+ readonly ctx: Context;
82
+ readonly row?: Record<string, unknown>;
83
+ }
84
+ /** A registered policy as stored in the policy table. */
85
+ interface Policy<Context = unknown> {
86
+ readonly on: PolicyOperation;
87
+ readonly table: string;
88
+ readonly when: (context: PolicyContext<Context>) => PolicyDecision;
89
+ }
90
+ /**
91
+ * Input accepted by `definePolicy`. The branded result is the same
92
+ * shape; we keep the input/output split so callers can read JSDoc on the
93
+ * constructor without the type re-exposing `Policy` internals.
94
+ */
95
+ interface DefinePolicyInput<Context = unknown> {
96
+ on: PolicyOperation;
97
+ /** Logical table name the policy applies to. */
98
+ table: string;
99
+ /**
100
+ * Decision function. Returning a `WhereInput` (read only) AND-merges the
101
+ * predicate; `true` allows; `false` denies; `undefined` skips this policy.
102
+ *
103
+ * NOTE: `count()` is **unsupported** on a policy-restricted table — the
104
+ * reader throws `LunoraError("COUNT_RLS_UNSUPPORTED")` (422). This mirrors
105
+ * kitcn's documented behavior.
106
+ */
107
+ when: (context: PolicyContext<Context>) => PolicyDecision;
108
+ }
109
+ /**
110
+ * A named, abstract capability a policy can check with `ctx.auth.can(...)`,
111
+ * instead of branching on raw role strings. Declare one with
112
+ * `definePermission`; grant it to a role via {@link Role.permissions};
113
+ * register the roles with the middleware via {@link RlsOptions.roles}.
114
+ */
115
+ interface Permission {
116
+ readonly description?: string;
117
+ readonly name: string;
118
+ }
119
+ /**
120
+ * A role declaration. Roles are string labels attached to the request's
121
+ * identity (via better-auth claims today). `permissions` lists the
122
+ * capabilities the role grants — at request time the middleware unions the
123
+ * permissions of every role in `ctx.auth.roles` so a policy can ask
124
+ * `ctx.auth.can(permission)` rather than enumerate roles.
125
+ */
126
+ interface Role {
127
+ readonly description?: string;
128
+ readonly name: string;
129
+ /** Permissions this role grants — by {@link Permission} object or bare name. */
130
+ readonly permissions?: ReadonlyArray<Permission | string>;
131
+ }
132
+ /**
133
+ * Options for the `rls(policies, options)` middleware. `roles` registers the
134
+ * role→permission grants that back `ctx.auth.can(...)`; a role not listed here
135
+ * grants no permissions (so `can` is conservative — it fails closed for
136
+ * unknown roles).
137
+ */
138
+ interface RlsOptions {
139
+ readonly roles?: ReadonlyArray<Role>;
140
+ }
141
+ export { DefinePolicyInput as D, PolicyOperation as P, Role as R, TypedDefinePolicyInput as T, WhereInput as W, Policy as a, Permission as b, RlsOptions as c, PolicyContext as d, PolicyDecision as e, PolicyDecisionOf as f };
@@ -1,11 +1,11 @@
1
- import { P as PolicyOperation, R as Role, a as Policy } from "../packem_shared/types.d-BB3pjV0m.mjs";
1
+ import { P as PolicyOperation, R as Role, a as Policy } from "../packem_shared/types.d-C4CMJK8x.mjs";
2
2
  import "../data-model.mjs";
3
3
  /**
4
- * The slice of a request identity a policy reads. Mirrors the
5
- * `PolicyContext.auth` shape the middleware builds at request time — every
6
- * field is optional and defaults the same way the middleware defaults it
7
- * (`userId`/`identity` → `null`, `roles` → `[]`).
8
- */
4
+ * The slice of a request identity a policy reads. Mirrors the
5
+ * `PolicyContext.auth` shape the middleware builds at request time — every
6
+ * field is optional and defaults the same way the middleware defaults it
7
+ * (`userId`/`identity` → `null`, `roles` → `[]`).
8
+ */
9
9
  interface TestIdentity {
10
10
  /** Raw identity claims a policy may branch on (`auth.identity.email`, …). */
11
11
  identity?: Record<string, unknown> | null;
@@ -17,32 +17,32 @@ interface TestIdentity {
17
17
  /** Options for {@link expectPolicy}. */
18
18
  interface ExpectPolicyOptions<Context = unknown> {
19
19
  /**
20
- * The procedure context a policy reads via `ctx` (e.g. `ctx.orgId`). Held
21
- * for the whole harness; pass a fresh `expectPolicy(..., { ctx })` for a
22
- * different context. Defaults to an empty object.
23
- */
20
+ * The procedure context a policy reads via `ctx` (e.g. `ctx.orgId`). Held
21
+ * for the whole harness; pass a fresh `expectPolicy(..., { ctx })` for a
22
+ * different context. Defaults to an empty object.
23
+ */
24
24
  ctx?: Context;
25
25
  /**
26
- * Role→permission grants backing `auth.can(...)` — the same registry passed
27
- * to `rls(policies, { roles })`. A role not listed here grants nothing, so
28
- * `can(...)` fails closed exactly as it does in production.
29
- */
26
+ * Role→permission grants backing `auth.can(...)` — the same registry passed
27
+ * to `rls(policies, { roles })`. A role not listed here grants nothing, so
28
+ * `can(...)` fails closed exactly as it does in production.
29
+ */
30
30
  roles?: ReadonlyArray<Role>;
31
31
  }
32
32
  /** A harness bound to one identity; answers can/cannot for an `(op, table, row)`. */
33
33
  interface BoundPolicyAssertion {
34
34
  /**
35
- * Would this identity be **allowed** the operation on `row`?
36
- *
37
- * - `read` — is `row` visible? `true` when the table has no read policy (unrestricted), or when the effective read `baseWhere` matches `row`.
38
- * - `insert` — is the candidate `row` allowed by the insert policies?
39
- * - `update` / `delete` — is the pre-write `row` allowed? For `update` pass `nextRow` to also assert the post-image (WITH CHECK) — a policy can't be satisfied by the old row while the patch reassigns it to another tenant.
40
- *
41
- * A table with **no** policy in the list is unguarded → always `true`
42
- * (mirrors the middleware passing such tables through unwrapped). A table
43
- * that participates but declares no policy for the write `op` denies
44
- * (default-DENY), exactly as the middleware does.
45
- */
35
+ * Would this identity be **allowed** the operation on `row`?
36
+ *
37
+ * - `read` — is `row` visible? `true` when the table has no read policy (unrestricted), or when the effective read `baseWhere` matches `row`.
38
+ * - `insert` — is the candidate `row` allowed by the insert policies?
39
+ * - `update` / `delete` — is the pre-write `row` allowed? For `update` pass `nextRow` to also assert the post-image (WITH CHECK) — a policy can't be satisfied by the old row while the patch reassigns it to another tenant.
40
+ *
41
+ * A table with **no** policy in the list is unguarded → always `true`
42
+ * (mirrors the middleware passing such tables through unwrapped). A table
43
+ * that participates but declares no policy for the write `op` denies
44
+ * (default-DENY), exactly as the middleware does.
45
+ */
46
46
  can: (op: PolicyOperation, table: string, row?: Record<string, unknown>, nextRow?: Record<string, unknown>) => boolean;
47
47
  /** Negation of {@link BoundPolicyAssertion.can} — reads more naturally in a denial test. */
48
48
  cannot: (op: PolicyOperation, table: string, row?: Record<string, unknown>, nextRow?: Record<string, unknown>) => boolean;
@@ -53,11 +53,11 @@ interface PolicyAssertion {
53
53
  as: (identity?: TestIdentity | null) => BoundPolicyAssertion;
54
54
  }
55
55
  /**
56
- * Build an in-process assertion harness over a policy set. Reuses the `rls()`
57
- * middleware's own evaluation primitives, so an assertion is faithful to
58
- * request-time behaviour by construction.
59
- * @param policies the policy list, typically from `definePolicies([...])`.
60
- * @param options role registry + procedure `ctx` (see {@link ExpectPolicyOptions}).
61
- */
56
+ * Build an in-process assertion harness over a policy set. Reuses the `rls()`
57
+ * middleware's own evaluation primitives, so an assertion is faithful to
58
+ * request-time behaviour by construction.
59
+ * @param policies the policy list, typically from `definePolicies([...])`.
60
+ * @param options role registry + procedure `ctx` (see {@link ExpectPolicyOptions}).
61
+ */
62
62
  declare const expectPolicy: <Context = unknown>(policies: ReadonlyArray<Policy<Context>>, options?: ExpectPolicyOptions<Context>) => PolicyAssertion;
63
63
  export { BoundPolicyAssertion, ExpectPolicyOptions, PolicyAssertion, TestIdentity, expectPolicy };
@@ -1,11 +1,11 @@
1
- import { P as PolicyOperation, R as Role, a as Policy } from "../packem_shared/types.d-Cxl6ndhm.js";
1
+ import { P as PolicyOperation, R as Role, a as Policy } from "../packem_shared/types.d-DdYF8E18.js";
2
2
  import "../data-model.js";
3
3
  /**
4
- * The slice of a request identity a policy reads. Mirrors the
5
- * `PolicyContext.auth` shape the middleware builds at request time — every
6
- * field is optional and defaults the same way the middleware defaults it
7
- * (`userId`/`identity` → `null`, `roles` → `[]`).
8
- */
4
+ * The slice of a request identity a policy reads. Mirrors the
5
+ * `PolicyContext.auth` shape the middleware builds at request time — every
6
+ * field is optional and defaults the same way the middleware defaults it
7
+ * (`userId`/`identity` → `null`, `roles` → `[]`).
8
+ */
9
9
  interface TestIdentity {
10
10
  /** Raw identity claims a policy may branch on (`auth.identity.email`, …). */
11
11
  identity?: Record<string, unknown> | null;
@@ -17,32 +17,32 @@ interface TestIdentity {
17
17
  /** Options for {@link expectPolicy}. */
18
18
  interface ExpectPolicyOptions<Context = unknown> {
19
19
  /**
20
- * The procedure context a policy reads via `ctx` (e.g. `ctx.orgId`). Held
21
- * for the whole harness; pass a fresh `expectPolicy(..., { ctx })` for a
22
- * different context. Defaults to an empty object.
23
- */
20
+ * The procedure context a policy reads via `ctx` (e.g. `ctx.orgId`). Held
21
+ * for the whole harness; pass a fresh `expectPolicy(..., { ctx })` for a
22
+ * different context. Defaults to an empty object.
23
+ */
24
24
  ctx?: Context;
25
25
  /**
26
- * Role→permission grants backing `auth.can(...)` — the same registry passed
27
- * to `rls(policies, { roles })`. A role not listed here grants nothing, so
28
- * `can(...)` fails closed exactly as it does in production.
29
- */
26
+ * Role→permission grants backing `auth.can(...)` — the same registry passed
27
+ * to `rls(policies, { roles })`. A role not listed here grants nothing, so
28
+ * `can(...)` fails closed exactly as it does in production.
29
+ */
30
30
  roles?: ReadonlyArray<Role>;
31
31
  }
32
32
  /** A harness bound to one identity; answers can/cannot for an `(op, table, row)`. */
33
33
  interface BoundPolicyAssertion {
34
34
  /**
35
- * Would this identity be **allowed** the operation on `row`?
36
- *
37
- * - `read` — is `row` visible? `true` when the table has no read policy (unrestricted), or when the effective read `baseWhere` matches `row`.
38
- * - `insert` — is the candidate `row` allowed by the insert policies?
39
- * - `update` / `delete` — is the pre-write `row` allowed? For `update` pass `nextRow` to also assert the post-image (WITH CHECK) — a policy can't be satisfied by the old row while the patch reassigns it to another tenant.
40
- *
41
- * A table with **no** policy in the list is unguarded → always `true`
42
- * (mirrors the middleware passing such tables through unwrapped). A table
43
- * that participates but declares no policy for the write `op` denies
44
- * (default-DENY), exactly as the middleware does.
45
- */
35
+ * Would this identity be **allowed** the operation on `row`?
36
+ *
37
+ * - `read` — is `row` visible? `true` when the table has no read policy (unrestricted), or when the effective read `baseWhere` matches `row`.
38
+ * - `insert` — is the candidate `row` allowed by the insert policies?
39
+ * - `update` / `delete` — is the pre-write `row` allowed? For `update` pass `nextRow` to also assert the post-image (WITH CHECK) — a policy can't be satisfied by the old row while the patch reassigns it to another tenant.
40
+ *
41
+ * A table with **no** policy in the list is unguarded → always `true`
42
+ * (mirrors the middleware passing such tables through unwrapped). A table
43
+ * that participates but declares no policy for the write `op` denies
44
+ * (default-DENY), exactly as the middleware does.
45
+ */
46
46
  can: (op: PolicyOperation, table: string, row?: Record<string, unknown>, nextRow?: Record<string, unknown>) => boolean;
47
47
  /** Negation of {@link BoundPolicyAssertion.can} — reads more naturally in a denial test. */
48
48
  cannot: (op: PolicyOperation, table: string, row?: Record<string, unknown>, nextRow?: Record<string, unknown>) => boolean;
@@ -53,11 +53,11 @@ interface PolicyAssertion {
53
53
  as: (identity?: TestIdentity | null) => BoundPolicyAssertion;
54
54
  }
55
55
  /**
56
- * Build an in-process assertion harness over a policy set. Reuses the `rls()`
57
- * middleware's own evaluation primitives, so an assertion is faithful to
58
- * request-time behaviour by construction.
59
- * @param policies the policy list, typically from `definePolicies([...])`.
60
- * @param options role registry + procedure `ctx` (see {@link ExpectPolicyOptions}).
61
- */
56
+ * Build an in-process assertion harness over a policy set. Reuses the `rls()`
57
+ * middleware's own evaluation primitives, so an assertion is faithful to
58
+ * request-time behaviour by construction.
59
+ * @param policies the policy list, typically from `definePolicies([...])`.
60
+ * @param options role registry + procedure `ctx` (see {@link ExpectPolicyOptions}).
61
+ */
62
62
  declare const expectPolicy: <Context = unknown>(policies: ReadonlyArray<Policy<Context>>, options?: ExpectPolicyOptions<Context>) => PolicyAssertion;
63
63
  export { BoundPolicyAssertion, ExpectPolicyOptions, PolicyAssertion, TestIdentity, expectPolicy };