uql-orm 0.115.0 → 0.115.1

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.
@@ -191,13 +191,22 @@ export function policiesOf(policies) {
191
191
  ? policies
192
192
  : [...policies, { effect: 'allow', ops: POLICY_OPS, where: {}, name: EVERY_ROW_POLICY }];
193
193
  }
194
- /** The rows the `allow`s holding `access` reach and every `must` holds, each policy read by `pick`. */
195
- function joined(meta, declared, access, context, pick) {
196
- const policies = policiesOf(declared).filter((policy) => policy.ops.includes(access) && holdsWhen(policy.when, context));
194
+ /**
195
+ * The rows every statement in `accesses` may reach: each `must` holding one, and for each, an `allow` holding it,
196
+ * statements the same allows hold ORing them in once.
197
+ */
198
+ function joined(meta, declared, accesses, context, pick) {
199
+ const policies = policiesOf(declared).filter((policy) => accesses.some((access) => policy.ops.includes(access)) && holdsWhen(policy.when, context));
197
200
  const read = fromContext(context);
198
- const bound = (policy) => bindContext(meta, pick(policy), read);
199
- const allows = orBound(policies.filter((policy) => policy.effect === 'allow').map(bound));
200
- return andBound([...policies.filter((policy) => policy.effect === 'must').map(bound), allows]);
201
+ const bound = policies.map((policy) => bindContext(meta, pick(policy), read));
202
+ const allowSets = new Map(accesses.map((access) => {
203
+ const set = policies.flatMap((policy, at) => policy.effect === 'allow' && policy.ops.includes(access) ? [at] : []);
204
+ return [set.join(), set];
205
+ }));
206
+ return andBound([
207
+ ...bound.filter((_, at) => policies[at].effect === 'must'),
208
+ ...[...allowSets.values()].map((set) => orBound(set.map((at) => bound[at]))),
209
+ ]);
201
210
  }
202
211
  /**
203
212
  * The rows a statement doing `access` may reach under `context`, `undefined` for an entity with no policies. An update
@@ -205,17 +214,13 @@ function joined(meta, declared, access, context, pick) {
205
214
  */
206
215
  export function policyScope(meta, access, context) {
207
216
  const { policies } = meta;
208
- if (!policies?.length) {
209
- return undefined;
210
- }
211
- const read = joined(meta, policies, 'read', context, (policy) => policy.where);
212
- return access === 'read' ? read : andBound([read, joined(meta, policies, access, context, (policy) => policy.where)]);
217
+ return policies?.length ? joined(meta, policies, ['read', access], context, (policy) => policy.where) : undefined;
213
218
  }
214
219
  /** What a row an insert or an update writes must hold under `context`, `undefined` for an entity with no policies. */
215
220
  export function policyCheck(meta, access, context) {
216
221
  const { policies } = meta;
217
222
  return policies?.length
218
- ? joined(meta, policies, access, context, (policy) => policy.check ?? policy.where)
223
+ ? joined(meta, policies, [access], context, (policy) => policy.check ?? policy.where)
219
224
  : undefined;
220
225
  }
221
226
  /**
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "homepage": "https://uql-orm.dev",
4
4
  "description": "JSON-native TypeScript ORM for Bun, Browsers, Edge, Node, Workers. Supports PostgreSQL, PGlite, MySQL, MariaDB, SQLite, CockroachDB, SQL Server, Turso, Neon, Cloudflare D1 and MongoDB. Queries are plain JSON, typed to the leaf.",
5
5
  "license": "MIT",
6
- "version": "0.115.0",
6
+ "version": "0.115.1",
7
7
  "type": "module",
8
8
  "engines": {
9
9
  "node": ">=22.18"