shutro 0.3.3 → 0.3.5
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(
|
|
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(
|
|
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[
|
|
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;
|
|
@@ -734,7 +734,12 @@ async function applyCommands(host, model, parentId, key, commands, mode) {
|
|
|
734
734
|
}
|
|
735
735
|
parentValues.set(key, [...current]);
|
|
736
736
|
internals.trigger(model.name, key, [parentId]);
|
|
737
|
+
// The junction table changed: a change event names the key, even when no column of the row was written (a write
|
|
738
|
+
// with scalars too merges its keys into the same event).
|
|
739
|
+
if (mode === 'write' && !sameIds(linked, current))
|
|
740
|
+
recordChange(internals, model, 'write', [parentId], [key]);
|
|
737
741
|
}
|
|
742
|
+
const sameIds = (a, b) => a.length === b.size && a.every((id) => b.has(id));
|
|
738
743
|
// -------------------------------------------------------------------------------------------------- flush
|
|
739
744
|
/** Writes dirty records of `modelName` (or all models) in one `UPDATE … FROM unnest(...)` per (model, field set). */
|
|
740
745
|
export async function flushDirty(host, modelName) {
|
package/package.json
CHANGED