uql-orm 0.115.0 → 0.115.2

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/README.md CHANGED
@@ -143,7 +143,7 @@ const posts = await pool.findMany(Post, {
143
143
 
144
144
  The result is typed to what the query selected: `posts[0].author?.email` compiles, `posts[0].likes` does not.
145
145
 
146
- The same queries run from the browser too: [serve them over HTTP, tRPC or oRPC](https://uql-orm.dev/http), each field exposed as you declare, scoped to the signed-in user by [filters no `$where` can widen](https://uql-orm.dev/multi-tenancy).
146
+ The same queries run from the browser too: [serve them over HTTP, tRPC or oRPC](https://uql-orm.dev/http), each field exposed as its `wire` declares, held to the signed-in user by [row-level policies](https://uql-orm.dev/multi-tenancy) no call can turn off.
147
147
 
148
148
  ## Why UQL?
149
149
 
@@ -151,7 +151,7 @@ The same queries run from the browser too: [serve them over HTTP, tRPC or oRPC](
151
151
  - **Type-safe to the leaf, nothing to generate.** Every key is checked against your entity, down into populated relations and [JSON/JSONB](https://uql-orm.dev/querying/json) dot-paths, so `$like` on a numeric column is a compile error. No `.prisma` file, no generated client.
152
152
  - **Decorators or plain data, your call.** An entity is a class with [standard TC39 decorators](https://uql-orm.dev/entities/basic), or plain data via [`defineEntity`](https://uql-orm.dev/entities/define-entity), its row type derived. Both are typed the same, mix in one project, and need no compiler flags or `reflect-metadata`.
153
153
  - **Light.** Zero runtime dependencies and every dialect in one package, yet `uql-orm/postgres` is about 49 kB gzipped. See [what we deleted to get there](https://uql-orm.dev/blog/zero-dependencies).
154
- - **The hard things are built in.** [Semantic and vector search](https://uql-orm.dev/ai-semantic-search), [multi-tenant filters you cannot bypass by accident](https://uql-orm.dev/multi-tenancy), [soft-delete with restore](https://uql-orm.dev/entities/soft-delete), [streaming](https://uql-orm.dev/querying/streaming), and [drift checks](https://uql-orm.dev/migrations) that catch a database that no longer matches.
154
+ - **The hard things are built in.** [Semantic and vector search](https://uql-orm.dev/ai-semantic-search), [row-level policies](https://uql-orm.dev/multi-tenancy) holding every read and write on every engine, or enforced by Postgres's own row-level security, [soft-delete with restore](https://uql-orm.dev/entities/soft-delete), [streaming](https://uql-orm.dev/querying/streaming), and [drift checks](https://uql-orm.dev/migrations) that catch a database that no longer matches.
155
155
  - **SQL when you need it.** [`sql()`](https://uql-orm.dev/querying/raw-sql) fits anywhere a value or a field goes, [computed fields](https://uql-orm.dev/entities/computed-fields) are SQL you can filter and sort on, and a migration can be plain SQL.
156
156
  - **The fastest ORM.** On a full PostgreSQL round trip it adds the least over hand-written driver code of any ORM in our open-source [benchmark](https://github.com/rogerpadilla/ts-orm-benchmark), on Bun and Node alike. The same benchmark [scores the types](https://github.com/rogerpadilla/ts-orm-benchmark#type-safety) by compiling ordinary mistakes in each ORM's API: UQL is the only one that catches them all.
157
157
 
@@ -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.2",
7
7
  "type": "module",
8
8
  "engines": {
9
9
  "node": ">=22.18"