shutro 0.3.3 → 0.3.4

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.
@@ -26,6 +26,8 @@ import { availableTransitions, runTransition } from './transitions.js';
26
26
  import { companyValue } from './values.js';
27
27
  import { assertExpected, createRecords, flushDirty, unlinkRecords, writeRecords, } from './writes.js';
28
28
  const CHUNK = 1000;
29
+ /** The alias of the parent's id in batched x2many loads: no column can have it (a target's own `parent_id` did, issue #33). */
30
+ const PARENT_KEY = '__shutro_parent';
29
31
  /** @internal */
30
32
  export function createRecordCache() {
31
33
  return { records: new Map(), currencies: new Map(), uoms: new Map() };
@@ -241,15 +243,15 @@ async function fetchX2Many(loader, model, key, parents, sub, user = false) {
241
243
  let rows;
242
244
  if (field.kind === 'one2many') {
243
245
  const inverse = sql.id(target.columns[field.inverseField ?? ''] ?? '');
244
- rows = await loader.internals.query(compile(sql `SELECT ${t}.${inverse} AS ${sql.id('parent_id')}, ${columns} FROM ${sourceOf(loader.internals, target)} AS ${t} WHERE ${t}.${inverse} = ANY(${chunk})${scope} ORDER BY ${order}`));
246
+ rows = await loader.internals.query(compile(sql `SELECT ${t}.${inverse} AS ${sql.id(PARENT_KEY)}, ${columns} FROM ${sourceOf(loader.internals, target)} AS ${t} WHERE ${t}.${inverse} = ANY(${chunk})${scope} ORDER BY ${order}`));
245
247
  }
246
248
  else {
247
249
  const j = junctionTable(model, field, target);
248
- rows = await loader.internals.query(compile(sql `SELECT ${sql.id('rel', j.sourceColumn)} AS ${sql.id('parent_id')}, ${columns} FROM ${sql.id(j.table)} AS ${sql.id('rel')} INNER JOIN ${sql.id(target.table)} AS ${t} ON ${t}.${sql.id('id')} = ${sql.id('rel', j.targetColumn)} WHERE ${sql.id('rel', j.sourceColumn)} = ANY(${chunk})${scope} ORDER BY ${order}`));
250
+ rows = await loader.internals.query(compile(sql `SELECT ${sql.id('rel', j.sourceColumn)} AS ${sql.id(PARENT_KEY)}, ${columns} FROM ${sql.id(j.table)} AS ${sql.id('rel')} INNER JOIN ${sql.id(target.table)} AS ${t} ON ${t}.${sql.id('id')} = ${sql.id('rel', j.targetColumn)} WHERE ${sql.id('rel', j.sourceColumn)} = ANY(${chunk})${scope} ORDER BY ${order}`));
249
251
  }
250
252
  for (const row of rows) {
251
253
  const childId = hydrate(loader, target, row, wanted);
252
- children.get(Number(row['parent_id']))?.push(childId);
254
+ children.get(Number(row[PARENT_KEY]))?.push(childId);
253
255
  }
254
256
  }
255
257
  for (const [parent, ids] of children)
@@ -107,7 +107,10 @@ export function canField(internals, model, key, kind) {
107
107
  if (field === undefined ||
108
108
  internals.env.su ||
109
109
  internals.env.administrator ||
110
- !internals.registry.security.enforce)
110
+ !internals.registry.security.enforce ||
111
+ // A compute is the engine's: it reads what it needs for any user (issue #34). Its result is still hidden from
112
+ // readers by the field's own groups: projections and onchange results filter outside the compute.
113
+ internals.compute.computing.size > 0)
111
114
  return true;
112
115
  if (fieldAllowed(fieldGroupsOf(internals, model, key), internals.env.groups, kind))
113
116
  return true;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "shutro",
3
- "version": "0.3.3",
3
+ "version": "0.3.4",
4
4
  "description": "The ORM built for business software: type-safe, secure-by-default, multi-company, audit-ready PostgreSQL ORM for Node.js and TypeScript.",
5
5
  "keywords": [
6
6
  "orm",