@venizia/ignis-connectors 0.4.1 → 0.4.3

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.
Files changed (170) hide show
  1. package/README.md +2 -2
  2. package/dist/cjs/common/scope-filter.d.ts +1 -1
  3. package/dist/cjs/common/scope-filter.d.ts.map +1 -1
  4. package/dist/cjs/common/scope-filter.js +33 -7
  5. package/dist/cjs/common/scope-filter.js.map +1 -1
  6. package/dist/cjs/http/common/constants.d.ts +11 -0
  7. package/dist/cjs/http/common/constants.d.ts.map +1 -0
  8. package/dist/cjs/http/common/constants.js +14 -0
  9. package/dist/cjs/http/common/constants.js.map +1 -0
  10. package/dist/cjs/http/common/wire.d.ts +2 -1
  11. package/dist/cjs/http/common/wire.d.ts.map +1 -1
  12. package/dist/cjs/http/common/wire.js +2 -1
  13. package/dist/cjs/http/common/wire.js.map +1 -1
  14. package/dist/cjs/http/datasource.d.ts +2 -1
  15. package/dist/cjs/http/datasource.d.ts.map +1 -1
  16. package/dist/cjs/http/datasource.js +2 -1
  17. package/dist/cjs/http/datasource.js.map +1 -1
  18. package/dist/cjs/http/index.d.ts +1 -0
  19. package/dist/cjs/http/index.d.ts.map +1 -1
  20. package/dist/cjs/http/index.js +1 -0
  21. package/dist/cjs/http/index.js.map +1 -1
  22. package/dist/cjs/http/repository.d.ts.map +1 -1
  23. package/dist/cjs/http/repository.js +5 -4
  24. package/dist/cjs/http/repository.js.map +1 -1
  25. package/dist/cjs/relational/core/repositories/common/constants.d.ts +11 -0
  26. package/dist/cjs/relational/core/repositories/common/constants.d.ts.map +1 -0
  27. package/dist/cjs/relational/core/repositories/common/constants.js +14 -0
  28. package/dist/cjs/relational/core/repositories/common/constants.js.map +1 -0
  29. package/dist/cjs/relational/core/repositories/common/index.d.ts +1 -0
  30. package/dist/cjs/relational/core/repositories/common/index.d.ts.map +1 -1
  31. package/dist/cjs/relational/core/repositories/common/index.js +1 -0
  32. package/dist/cjs/relational/core/repositories/common/index.js.map +1 -1
  33. package/dist/cjs/relational/core/repositories/common/scope-write-guard.d.ts +71 -0
  34. package/dist/cjs/relational/core/repositories/common/scope-write-guard.d.ts.map +1 -0
  35. package/dist/cjs/relational/core/repositories/common/scope-write-guard.js +377 -0
  36. package/dist/cjs/relational/core/repositories/common/scope-write-guard.js.map +1 -0
  37. package/dist/cjs/relational/core/repositories/core/base.d.ts +22 -4
  38. package/dist/cjs/relational/core/repositories/core/base.d.ts.map +1 -1
  39. package/dist/cjs/relational/core/repositories/core/base.js +49 -10
  40. package/dist/cjs/relational/core/repositories/core/base.js.map +1 -1
  41. package/dist/cjs/relational/core/repositories/core/persistable.d.ts.map +1 -1
  42. package/dist/cjs/relational/core/repositories/core/persistable.js +8 -1
  43. package/dist/cjs/relational/core/repositories/core/persistable.js.map +1 -1
  44. package/dist/cjs/relational/core/repositories/dialect/filter.d.ts +2 -2
  45. package/dist/cjs/relational/core/repositories/dialect/filter.js +3 -3
  46. package/dist/cjs/relational/core/repositories/dialect/filter.js.map +1 -1
  47. package/dist/cjs/relational/core/repositories/sqls/recursive-tree.d.ts +9 -0
  48. package/dist/cjs/relational/core/repositories/sqls/recursive-tree.d.ts.map +1 -1
  49. package/dist/cjs/relational/core/repositories/sqls/recursive-tree.js +14 -3
  50. package/dist/cjs/relational/core/repositories/sqls/recursive-tree.js.map +1 -1
  51. package/dist/cjs/relational/postgres/models/common/constants.d.ts +11 -0
  52. package/dist/cjs/relational/postgres/models/common/constants.d.ts.map +1 -0
  53. package/dist/cjs/relational/postgres/models/common/constants.js +14 -0
  54. package/dist/cjs/relational/postgres/models/common/constants.js.map +1 -0
  55. package/dist/cjs/relational/postgres/models/common/index.d.ts +1 -0
  56. package/dist/cjs/relational/postgres/models/common/index.d.ts.map +1 -1
  57. package/dist/cjs/relational/postgres/models/common/index.js +1 -0
  58. package/dist/cjs/relational/postgres/models/common/index.js.map +1 -1
  59. package/dist/cjs/relational/postgres/models/common/types/enrichers.d.ts +5 -3
  60. package/dist/cjs/relational/postgres/models/common/types/enrichers.d.ts.map +1 -1
  61. package/dist/cjs/relational/postgres/models/common/types/enrichers.js.map +1 -1
  62. package/dist/cjs/relational/postgres/models/enrichers/principal.enricher.d.ts +4 -3
  63. package/dist/cjs/relational/postgres/models/enrichers/principal.enricher.d.ts.map +1 -1
  64. package/dist/cjs/relational/postgres/models/enrichers/principal.enricher.js.map +1 -1
  65. package/dist/cjs/relational/sqlite/models/common/types/enrichers.d.ts +3 -2
  66. package/dist/cjs/relational/sqlite/models/common/types/enrichers.d.ts.map +1 -1
  67. package/dist/cjs/relational/sqlite/models/common/types/enrichers.js.map +1 -1
  68. package/dist/cjs/relational/sqlite/models/enrichers/principal.enricher.d.ts +4 -3
  69. package/dist/cjs/relational/sqlite/models/enrichers/principal.enricher.d.ts.map +1 -1
  70. package/dist/cjs/relational/sqlite/models/enrichers/principal.enricher.js.map +1 -1
  71. package/dist/cjs/search/core/controllers/abstract.d.ts +4 -0
  72. package/dist/cjs/search/core/controllers/abstract.d.ts.map +1 -1
  73. package/dist/cjs/search/core/controllers/abstract.js +15 -1
  74. package/dist/cjs/search/core/controllers/abstract.js.map +1 -1
  75. package/dist/cjs/search/core/controllers/factory.d.ts +15 -1
  76. package/dist/cjs/search/core/controllers/factory.d.ts.map +1 -1
  77. package/dist/cjs/search/core/controllers/factory.js +7 -1
  78. package/dist/cjs/search/core/controllers/factory.js.map +1 -1
  79. package/dist/cjs/search/core/controllers/index.d.ts +1 -0
  80. package/dist/cjs/search/core/controllers/index.d.ts.map +1 -1
  81. package/dist/cjs/search/core/controllers/index.js.map +1 -1
  82. package/dist/cjs/search/core/controllers/scope.d.ts +28 -0
  83. package/dist/cjs/search/core/controllers/scope.d.ts.map +1 -0
  84. package/dist/cjs/search/core/controllers/scope.js +68 -0
  85. package/dist/cjs/search/core/controllers/scope.js.map +1 -0
  86. package/dist/esm/common/scope-filter.d.ts +1 -1
  87. package/dist/esm/common/scope-filter.d.ts.map +1 -1
  88. package/dist/esm/common/scope-filter.js +34 -8
  89. package/dist/esm/common/scope-filter.js.map +1 -1
  90. package/dist/esm/http/common/constants.d.ts +11 -0
  91. package/dist/esm/http/common/constants.d.ts.map +1 -0
  92. package/dist/esm/http/common/constants.js +10 -0
  93. package/dist/esm/http/common/constants.js.map +1 -0
  94. package/dist/esm/http/common/wire.d.ts +2 -1
  95. package/dist/esm/http/common/wire.d.ts.map +1 -1
  96. package/dist/esm/http/common/wire.js +2 -1
  97. package/dist/esm/http/common/wire.js.map +1 -1
  98. package/dist/esm/http/datasource.d.ts +2 -1
  99. package/dist/esm/http/datasource.d.ts.map +1 -1
  100. package/dist/esm/http/datasource.js +2 -1
  101. package/dist/esm/http/datasource.js.map +1 -1
  102. package/dist/esm/http/index.d.ts +1 -0
  103. package/dist/esm/http/index.d.ts.map +1 -1
  104. package/dist/esm/http/index.js +1 -0
  105. package/dist/esm/http/index.js.map +1 -1
  106. package/dist/esm/http/repository.d.ts.map +1 -1
  107. package/dist/esm/http/repository.js +5 -4
  108. package/dist/esm/http/repository.js.map +1 -1
  109. package/dist/esm/relational/core/repositories/common/constants.d.ts +11 -0
  110. package/dist/esm/relational/core/repositories/common/constants.d.ts.map +1 -0
  111. package/dist/esm/relational/core/repositories/common/constants.js +10 -0
  112. package/dist/esm/relational/core/repositories/common/constants.js.map +1 -0
  113. package/dist/esm/relational/core/repositories/common/index.d.ts +1 -0
  114. package/dist/esm/relational/core/repositories/common/index.d.ts.map +1 -1
  115. package/dist/esm/relational/core/repositories/common/index.js +1 -0
  116. package/dist/esm/relational/core/repositories/common/index.js.map +1 -1
  117. package/dist/esm/relational/core/repositories/common/scope-write-guard.d.ts +71 -0
  118. package/dist/esm/relational/core/repositories/common/scope-write-guard.d.ts.map +1 -0
  119. package/dist/esm/relational/core/repositories/common/scope-write-guard.js +373 -0
  120. package/dist/esm/relational/core/repositories/common/scope-write-guard.js.map +1 -0
  121. package/dist/esm/relational/core/repositories/core/base.d.ts +22 -4
  122. package/dist/esm/relational/core/repositories/core/base.d.ts.map +1 -1
  123. package/dist/esm/relational/core/repositories/core/base.js +49 -10
  124. package/dist/esm/relational/core/repositories/core/base.js.map +1 -1
  125. package/dist/esm/relational/core/repositories/core/persistable.d.ts.map +1 -1
  126. package/dist/esm/relational/core/repositories/core/persistable.js +8 -1
  127. package/dist/esm/relational/core/repositories/core/persistable.js.map +1 -1
  128. package/dist/esm/relational/core/repositories/dialect/filter.d.ts +2 -2
  129. package/dist/esm/relational/core/repositories/dialect/filter.js +3 -3
  130. package/dist/esm/relational/core/repositories/dialect/filter.js.map +1 -1
  131. package/dist/esm/relational/core/repositories/sqls/recursive-tree.d.ts +9 -0
  132. package/dist/esm/relational/core/repositories/sqls/recursive-tree.d.ts.map +1 -1
  133. package/dist/esm/relational/core/repositories/sqls/recursive-tree.js +15 -4
  134. package/dist/esm/relational/core/repositories/sqls/recursive-tree.js.map +1 -1
  135. package/dist/esm/relational/postgres/models/common/constants.d.ts +11 -0
  136. package/dist/esm/relational/postgres/models/common/constants.d.ts.map +1 -0
  137. package/dist/esm/relational/postgres/models/common/constants.js +10 -0
  138. package/dist/esm/relational/postgres/models/common/constants.js.map +1 -0
  139. package/dist/esm/relational/postgres/models/common/index.d.ts +1 -0
  140. package/dist/esm/relational/postgres/models/common/index.d.ts.map +1 -1
  141. package/dist/esm/relational/postgres/models/common/index.js +1 -0
  142. package/dist/esm/relational/postgres/models/common/index.js.map +1 -1
  143. package/dist/esm/relational/postgres/models/common/types/enrichers.d.ts +5 -3
  144. package/dist/esm/relational/postgres/models/common/types/enrichers.d.ts.map +1 -1
  145. package/dist/esm/relational/postgres/models/common/types/enrichers.js.map +1 -1
  146. package/dist/esm/relational/postgres/models/enrichers/principal.enricher.d.ts +4 -3
  147. package/dist/esm/relational/postgres/models/enrichers/principal.enricher.d.ts.map +1 -1
  148. package/dist/esm/relational/postgres/models/enrichers/principal.enricher.js.map +1 -1
  149. package/dist/esm/relational/sqlite/models/common/types/enrichers.d.ts +3 -2
  150. package/dist/esm/relational/sqlite/models/common/types/enrichers.d.ts.map +1 -1
  151. package/dist/esm/relational/sqlite/models/common/types/enrichers.js.map +1 -1
  152. package/dist/esm/relational/sqlite/models/enrichers/principal.enricher.d.ts +4 -3
  153. package/dist/esm/relational/sqlite/models/enrichers/principal.enricher.d.ts.map +1 -1
  154. package/dist/esm/relational/sqlite/models/enrichers/principal.enricher.js.map +1 -1
  155. package/dist/esm/search/core/controllers/abstract.d.ts +4 -0
  156. package/dist/esm/search/core/controllers/abstract.d.ts.map +1 -1
  157. package/dist/esm/search/core/controllers/abstract.js +15 -1
  158. package/dist/esm/search/core/controllers/abstract.js.map +1 -1
  159. package/dist/esm/search/core/controllers/factory.d.ts +15 -1
  160. package/dist/esm/search/core/controllers/factory.d.ts.map +1 -1
  161. package/dist/esm/search/core/controllers/factory.js +7 -1
  162. package/dist/esm/search/core/controllers/factory.js.map +1 -1
  163. package/dist/esm/search/core/controllers/index.d.ts +1 -0
  164. package/dist/esm/search/core/controllers/index.d.ts.map +1 -1
  165. package/dist/esm/search/core/controllers/index.js.map +1 -1
  166. package/dist/esm/search/core/controllers/scope.d.ts +28 -0
  167. package/dist/esm/search/core/controllers/scope.d.ts.map +1 -0
  168. package/dist/esm/search/core/controllers/scope.js +64 -0
  169. package/dist/esm/search/core/controllers/scope.js.map +1 -0
  170. package/package.json +6 -6
@@ -0,0 +1,373 @@
1
+ import { ScopeWriteOperations } from './constants.js';
2
+ import { getError } from '@venizia/ignis-helpers/core';
3
+ import { QueryOperators, RepositoryErrorCodes, ScopeFilterMissingBehaviors, ScopeFilters, ScopeWriteGuards, } from '@venizia/ignis-kernel';
4
+ import { HTTP } from '@venizia/ignis-helpers/common';
5
+ import { ScopeFilterDenial } from './scope-filter.js';
6
+ const WRITE_DENIED_STATUS = HTTP.ResultCodes.RS_4.Forbidden;
7
+ const isScalar = (value) => {
8
+ return (value === null ||
9
+ value instanceof Date ||
10
+ ['string', 'number', 'bigint', 'boolean'].includes(typeof value));
11
+ };
12
+ const isRecord = (value) => {
13
+ return typeof value === 'object' && value !== null && !Array.isArray(value);
14
+ };
15
+ const normalise = (value) => {
16
+ if (value === null) {
17
+ return null;
18
+ }
19
+ return value instanceof Date ? value.toISOString() : String(value);
20
+ };
21
+ const intersect = (opts) => {
22
+ return new Set([...opts.left].filter((value) => opts.right.has(value)));
23
+ };
24
+ /**
25
+ * The write side of `@model` settings.access. The resolved scope is a `where`; the guard reads
26
+ * from it the columns it constrains and the values it allows, and holds every written row to them.
27
+ *
28
+ * Only shapes that can be checked are read: a column equal to a scalar or `null`, `{ eq }`, `{ inq }`
29
+ * (or `in`), an array, `and` of those, and an `or` whose branches all constrain the same column. Anything
30
+ * else - an `or` over several columns, ranges, `like`, a nested path - makes
31
+ * the scope unverifiable, and the write is refused with its own message instead of being skipped.
32
+ */
33
+ export class ScopeWriteGuard {
34
+ static extractConstraints(opts) {
35
+ const constraints = new Map();
36
+ const reason = ScopeWriteGuard.collect({
37
+ where: opts.where,
38
+ constraints,
39
+ });
40
+ return reason === undefined
41
+ ? { isVerifiable: true, constraints }
42
+ : { isVerifiable: false, reason };
43
+ }
44
+ /** Adds the where's constraints to `constraints`; returns the reason it cannot be verified, if any. */
45
+ static collect(opts) {
46
+ const { where, constraints } = opts;
47
+ for (const [key, value] of Object.entries(where)) {
48
+ if (key === 'and') {
49
+ if (!Array.isArray(value)) {
50
+ return "'and' is not a list";
51
+ }
52
+ for (const part of value) {
53
+ const reason = ScopeWriteGuard.collect({
54
+ where: part,
55
+ constraints,
56
+ });
57
+ if (reason !== undefined) {
58
+ return reason;
59
+ }
60
+ }
61
+ continue;
62
+ }
63
+ if (key === 'or') {
64
+ const union = ScopeWriteGuard.unionOfBranches({ branches: value });
65
+ if (typeof union === 'string') {
66
+ return union;
67
+ }
68
+ const existing = constraints.get(union.column);
69
+ constraints.set(union.column, existing ? intersect({ left: existing, right: union.allowed }) : union.allowed);
70
+ continue;
71
+ }
72
+ if (key.includes('.')) {
73
+ return `the nested path '${key}' cannot be checked on a write`;
74
+ }
75
+ const allowed = ScopeWriteGuard.allowedValues({ value });
76
+ if (typeof allowed === 'string') {
77
+ return `column '${key}': ${allowed}`;
78
+ }
79
+ const existing = constraints.get(key);
80
+ constraints.set(key, existing ? intersect({ left: existing, right: allowed }) : allowed);
81
+ }
82
+ return undefined;
83
+ }
84
+ /**
85
+ * An `or` is checkable only when every branch constrains the same single column with a scalar,
86
+ * `null`, `eq`, `in` or `inq`: the allowed values are then the union of the branches. This is the
87
+ * shared-rows scope, `{ or: [{ merchantId: { in: ids } }, { merchantId: null }] }`. Any other `or`
88
+ * (several columns, ranges, nested `and` or `or`) cannot be checked.
89
+ */
90
+ static unionOfBranches(opts) {
91
+ const { branches } = opts;
92
+ if (!Array.isArray(branches) || branches.length === 0) {
93
+ return "'or' is not a list";
94
+ }
95
+ let column;
96
+ const allowed = new Set();
97
+ for (const branch of branches) {
98
+ const entries = Object.entries((branch ?? {}));
99
+ if (entries.length !== 1) {
100
+ return "an 'or' branch with several conditions cannot be checked on a write";
101
+ }
102
+ const [key, value] = entries[0];
103
+ if (key === 'and' || key === 'or' || key.includes('.')) {
104
+ return `an 'or' branch over '${key}' cannot be checked on a write`;
105
+ }
106
+ if (column !== undefined && column !== key) {
107
+ return "an 'or' over different columns cannot be checked on a write";
108
+ }
109
+ column = key;
110
+ const values = ScopeWriteGuard.allowedValues({ value });
111
+ if (typeof values === 'string') {
112
+ return `column '${key}': ${values}`;
113
+ }
114
+ values.forEach((entry) => allowed.add(entry));
115
+ }
116
+ return { column: column, allowed };
117
+ }
118
+ /** The values one column's condition allows, or a string naming why it cannot be checked. */
119
+ static allowedValues(opts) {
120
+ const { value } = opts;
121
+ if (isScalar(value)) {
122
+ return new Set([normalise(value)]);
123
+ }
124
+ if (Array.isArray(value)) {
125
+ return value.every(isScalar)
126
+ ? new Set(value.map(normalise))
127
+ : 'a list with a non-scalar entry';
128
+ }
129
+ if (typeof value !== 'object' || value === undefined) {
130
+ return 'an unsupported condition';
131
+ }
132
+ const operators = Object.keys(value);
133
+ if (operators.length !== 1) {
134
+ return `a condition with ${operators.length} operators cannot be checked on a write`;
135
+ }
136
+ const [operator] = operators;
137
+ const operand = value[operator];
138
+ if (operator === QueryOperators.EQ && isScalar(operand)) {
139
+ return new Set([normalise(operand)]);
140
+ }
141
+ if ((operator === QueryOperators.INQ || operator === QueryOperators.IN) &&
142
+ Array.isArray(operand)) {
143
+ return operand.every(isScalar)
144
+ ? new Set(operand.map(normalise))
145
+ : 'a list with a non-scalar entry';
146
+ }
147
+ return `the operator '${operator}' cannot be checked on a write`;
148
+ }
149
+ /**
150
+ * The scope as a MUTATION `where` (update, delete, soft delete, restore). A scope with a `null`
151
+ * branch - `{ or: [{ merchantId: { in: ids } }, { merchantId: null }] }` - lets the caller READ the
152
+ * shared rows. Changing or deleting one is the same permission as creating one, `write.sharedRows`,
153
+ * so without it the `null` branch is removed and only the caller's own rows match. With
154
+ * `sharedRows` the scope is returned as it is.
155
+ *
156
+ * Only the shapes the write guard can read are narrowed. Any other shape cannot be shown to exclude
157
+ * the shared rows, so the mutation is refused, as an update with a payload already is.
158
+ */
159
+ static mutationWhere(opts) {
160
+ const { settings, model, operation, scopeWhere } = opts;
161
+ if (settings.write?.sharedRows === true) {
162
+ return scopeWhere;
163
+ }
164
+ const narrowed = ScopeWriteGuard.withoutShared({ where: scopeWhere });
165
+ if (narrowed.kind === 'unverifiable') {
166
+ throw ScopeWriteGuard.denied({
167
+ model,
168
+ operation,
169
+ detail: `the resolved scope cannot be verified on a write | ${narrowed.reason}`,
170
+ });
171
+ }
172
+ return narrowed.kind === 'none' ? ScopeFilterDenial.where() : narrowed.where;
173
+ }
174
+ /** `where` with every `null` the scope allows removed; `none` when nothing but `null` was allowed. */
175
+ static withoutShared(opts) {
176
+ const result = {};
177
+ for (const [key, value] of Object.entries(opts.where)) {
178
+ if (key === 'and' || key === 'or') {
179
+ if (!Array.isArray(value) || (key === 'or' && value.length === 0)) {
180
+ return { kind: 'unverifiable', reason: `'${key}' is not a list` };
181
+ }
182
+ // An 'or' is read only when every branch constrains the same column, as the guard reads it: a branch over another column
183
+ // could match a shared row without a null in sight.
184
+ if (key === 'or') {
185
+ const union = ScopeWriteGuard.unionOfBranches({ branches: value });
186
+ if (typeof union === 'string') {
187
+ return { kind: 'unverifiable', reason: union };
188
+ }
189
+ }
190
+ const kept = [];
191
+ for (const part of value) {
192
+ const narrowed = ScopeWriteGuard.withoutShared({ where: isRecord(part) ? part : {} });
193
+ if (narrowed.kind === 'unverifiable') {
194
+ return narrowed;
195
+ }
196
+ if (narrowed.kind === 'none') {
197
+ // One impossible 'and' part makes the whole 'and' impossible; an impossible 'or' branch just drops out.
198
+ if (key === 'and') {
199
+ return narrowed;
200
+ }
201
+ continue;
202
+ }
203
+ kept.push(narrowed.where);
204
+ }
205
+ if (key === 'or' && kept.length === 0) {
206
+ return { kind: 'none' };
207
+ }
208
+ result[key] = kept;
209
+ continue;
210
+ }
211
+ if (key.includes('.')) {
212
+ return {
213
+ kind: 'unverifiable',
214
+ reason: `the nested path '${key}' cannot be checked on a write`,
215
+ };
216
+ }
217
+ const narrowed = ScopeWriteGuard.conditionWithoutNull({ value });
218
+ if (narrowed.kind !== 'condition') {
219
+ return narrowed.kind === 'none'
220
+ ? { kind: 'none' }
221
+ : { kind: 'unverifiable', reason: `column '${key}': ${narrowed.reason}` };
222
+ }
223
+ result[key] = narrowed.value;
224
+ }
225
+ return { kind: 'where', where: result };
226
+ }
227
+ /** One column's condition without its `null` values, reading the same shapes `allowedValues` reads. */
228
+ static conditionWithoutNull(opts) {
229
+ const { value } = opts;
230
+ const list = (entries) => {
231
+ if (!entries.every(isScalar)) {
232
+ return { kind: 'unverifiable', reason: 'a list with a non-scalar entry' };
233
+ }
234
+ const kept = entries.filter((entry) => entry !== null);
235
+ return kept.length === 0
236
+ ? { kind: 'none' }
237
+ : { kind: 'condition', value: kept };
238
+ };
239
+ if (isScalar(value)) {
240
+ return value === null ? { kind: 'none' } : { kind: 'condition', value };
241
+ }
242
+ if (Array.isArray(value)) {
243
+ return list(value);
244
+ }
245
+ if (!isRecord(value)) {
246
+ return { kind: 'unverifiable', reason: 'an unsupported condition' };
247
+ }
248
+ const operators = Object.keys(value);
249
+ if (operators.length !== 1) {
250
+ return {
251
+ kind: 'unverifiable',
252
+ reason: `a condition with ${operators.length} operators cannot be checked on a write`,
253
+ };
254
+ }
255
+ const [operator] = operators;
256
+ const operand = value[operator];
257
+ if (operator === QueryOperators.EQ && isScalar(operand)) {
258
+ return operand === null ? { kind: 'none' } : { kind: 'condition', value };
259
+ }
260
+ if ((operator === QueryOperators.INQ || operator === QueryOperators.IN) &&
261
+ Array.isArray(operand)) {
262
+ const narrowed = list(operand);
263
+ return narrowed.kind === 'condition'
264
+ ? { kind: 'condition', value: { [operator]: narrowed.value } }
265
+ : narrowed;
266
+ }
267
+ return {
268
+ kind: 'unverifiable',
269
+ reason: `the operator '${operator}' cannot be checked on a write`,
270
+ };
271
+ }
272
+ /**
273
+ * Holds `rows` to the scope `settings.resolve()` returns now. Returns the rows to write: the same
274
+ * objects when nothing changes, copies with the scope columns filled in for `assign`. Throws, and
275
+ * so writes nothing, when any row is outside the scope.
276
+ */
277
+ static apply(opts) {
278
+ const { settings, model, rows, operation } = opts;
279
+ const scope = settings.resolve();
280
+ if (scope === ScopeFilters.UNRESTRICTED) {
281
+ return rows;
282
+ }
283
+ if (scope === null || scope === undefined) {
284
+ // An update is already confined by the scoped `where`, which under `deny` matches no row; the
285
+ // guard adds nothing there. A create has no such `where`, so an unresolved scope refuses it.
286
+ if (settings.onMissing === ScopeFilterMissingBehaviors.ALLOW ||
287
+ operation === ScopeWriteOperations.UPDATE) {
288
+ return rows;
289
+ }
290
+ throw ScopeWriteGuard.denied({
291
+ model,
292
+ operation,
293
+ detail: 'no scope could be resolved for this caller',
294
+ });
295
+ }
296
+ const extraction = ScopeWriteGuard.extractConstraints({ where: scope });
297
+ if (!extraction.isVerifiable) {
298
+ throw ScopeWriteGuard.denied({
299
+ model,
300
+ operation,
301
+ detail: `the resolved scope cannot be verified on a write | ${extraction.reason}`,
302
+ });
303
+ }
304
+ const { constraints } = extraction;
305
+ const declared = settings.columns;
306
+ if (declared) {
307
+ const undeclared = [...constraints.keys()].find((column) => !declared.includes(column));
308
+ if (undeclared !== undefined) {
309
+ throw ScopeWriteGuard.denied({
310
+ model,
311
+ operation,
312
+ detail: `the resolved scope constrains column '${undeclared}', which access.columns does not declare`,
313
+ });
314
+ }
315
+ }
316
+ const isAssign = settings.write?.mode === ScopeWriteGuards.ASSIGN && operation === 'create';
317
+ const sharedRows = settings.write?.sharedRows === true;
318
+ return rows.map((row) => {
319
+ let result = row;
320
+ for (const [column, allowed] of constraints) {
321
+ const value = row[column];
322
+ if (value === undefined) {
323
+ if (operation === 'update') {
324
+ continue;
325
+ }
326
+ // `assign` first: stamping gives the row an owner, which is safer than leaving it shared.
327
+ const only = allowed.size === 1 ? [...allowed][0] : undefined;
328
+ if (isAssign && only !== undefined && only !== null) {
329
+ result = { ...result, [column]: only };
330
+ continue;
331
+ }
332
+ // Absent means the database default, usually `null`, so it is held to the `null` rule.
333
+ if (sharedRows) {
334
+ continue;
335
+ }
336
+ throw ScopeWriteGuard.denied({
337
+ model,
338
+ operation,
339
+ column,
340
+ detail: 'the scope column is missing',
341
+ });
342
+ }
343
+ const normalised = isScalar(value) ? normalise(value) : undefined;
344
+ // A `null` branch in the scope lets this caller READ shared rows. Writing one (or moving a
345
+ // row into the shared set) is a separate permission: only `sharedRows` grants it.
346
+ const isOutside = normalised === null ? !sharedRows : !allowed.has(normalised);
347
+ if (normalised === undefined || isOutside) {
348
+ throw ScopeWriteGuard.denied({
349
+ model,
350
+ operation,
351
+ column,
352
+ detail: 'the value is outside the resolved scope',
353
+ });
354
+ }
355
+ }
356
+ return result;
357
+ });
358
+ }
359
+ /** Names the model and the column, never a value: the caller may be a request. */
360
+ static denied(opts) {
361
+ const { model, operation, column, detail } = opts;
362
+ return getError({
363
+ statusCode: WRITE_DENIED_STATUS,
364
+ messageCode: RepositoryErrorCodes.SCOPE_WRITE_DENIED,
365
+ message: [
366
+ `[${operation}] write refused by the access scope | entity: ${model}`,
367
+ ...(column ? [`column: ${column}`] : []),
368
+ detail,
369
+ ].join(' | '),
370
+ });
371
+ }
372
+ }
373
+ //# sourceMappingURL=scope-write-guard.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"scope-write-guard.js","sourceRoot":"","sources":["../../../../../../src/relational/core/repositories/common/scope-write-guard.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAA6B,MAAM,aAAa,CAAC;AAC9E,OAAO,EAAE,QAAQ,EAAE,MAAM,6BAA6B,CAAC;AACvD,OAAO,EACL,cAAc,EACd,oBAAoB,EACpB,2BAA2B,EAC3B,YAAY,EACZ,gBAAgB,GACjB,MAAM,uBAAuB,CAAC;AAE/B,OAAO,EAAE,IAAI,EAAE,MAAM,+BAA+B,CAAC;AACrD,OAAO,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AAiBnD,MAAM,mBAAmB,GAAG,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,SAAS,CAAC;AAE5D,MAAM,QAAQ,GAAG,CAAC,KAAc,EAAoB,EAAE;IACpD,OAAO,CACL,KAAK,KAAK,IAAI;QACd,KAAK,YAAY,IAAI;QACrB,CAAC,QAAQ,EAAE,QAAQ,EAAE,QAAQ,EAAE,SAAS,CAAC,CAAC,QAAQ,CAAC,OAAO,KAAK,CAAC,CACjE,CAAC;AACJ,CAAC,CAAC;AAEF,MAAM,QAAQ,GAAG,CAAC,KAAc,EAAoC,EAAE;IACpE,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;AAC9E,CAAC,CAAC;AAEF,MAAM,SAAS,GAAG,CAAC,KAAc,EAAiB,EAAE;IAClD,IAAI,KAAK,KAAK,IAAI,EAAE,CAAC;Q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AAC,CAAC;IACL,CAAC;IAED,kFAAkF;IAC1E,MAAM,CAAC,MAAM,CAAC,IAKrB;QACC,MAAM,EAAE,KAAK,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM,EAAE,GAAG,IAAI,CAAC;QAElD,OAAO,QAAQ,CAAC;YACd,UAAU,EAAE,mBAAmB;YAC/B,WAAW,EAAE,oBAAoB,CAAC,kBAAkB;YACpD,OAAO,EAAE;gBACP,IAAI,SAAS,iDAAiD,KAAK,EAAE;gBACrE,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,WAAW,MAAM,EAAE,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;gBACxC,MAAM;aACP,CAAC,IAAI,CAAC,KAAK,CAAC;SACd,CAAC,CAAC;IACL,CAAC;CACF","sourcesContent":["import { ScopeWriteOperations, type TScopeWriteOperation } from './constants';\nimport { getError } from '@venizia/ignis-helpers/core';\nimport {\n QueryOperators,\n RepositoryErrorCodes,\n ScopeFilterMissingBehaviors,\n ScopeFilters,\n ScopeWriteGuards,\n} from '@venizia/ignis-kernel';\nimport type { IModelAccessSettings, TWhere } from '@venizia/ignis-kernel';\nimport { HTTP } from '@venizia/ignis-helpers/common';\nimport { ScopeFilterDenial } from './scope-filter';\n\ntype TScalar = string | number | bigint | boolean | Date | null;\n\n/** The allowed values per scope column, each normalised so `1` and `'1'` and equal dates compare equal. */\ntype TConstraints = Map<string, Set<string | null>>;\n\ntype TExtraction =\n | { isVerifiable: true; constraints: TConstraints }\n | { isVerifiable: false; reason: string };\n\n/** What the scope becomes for a write: a `where`, no row at all, or a shape that cannot be narrowed. */\ntype TNarrowed =\n | { kind: 'where'; where: TWhere }\n | { kind: 'none' }\n | { kind: 'unverifiable'; reason: string };\n\nconst WRITE_DENIED_STATUS = HTTP.ResultCodes.RS_4.Forbidden;\n\nconst isScalar = (value: unknown): value is TScalar => {\n return (\n value === null ||\n value instanceof Date ||\n ['string', 'number', 'bigint', 'boolean'].includes(typeof value)\n );\n};\n\nconst isRecord = (value: unknown): value is Record<string, unknown> => {\n return typeof value === 'object' && value !== null && !Array.isArray(value);\n};\n\nconst normalise = (value: TScalar): string | null => {\n if (value === null) {\n return null;\n }\n\n return value instanceof Date ? value.toISOString() : String(value);\n};\n\nconst intersect = (opts: { left: Set<string | null>; right: Set<string | null> }) => {\n return new Set([...opts.left].filter((value) => opts.right.has(value)));\n};\n\n/**\n * The write side of `@model` settings.access. The resolved scope is a `where`; the guard reads\n * from it the columns it constrains and the values it allows, and holds every written row to them.\n *\n * Only shapes that can be checked are read: a column equal to a scalar or `null`, `{ eq }`, `{ inq }`\n * (or `in`), an array, `and` of those, and an `or` whose branches all constrain the same column. Anything\n * else - an `or` over several columns, ranges, `like`, a nested path - makes\n * the scope unverifiable, and the write is refused with its own message instead of being skipped.\n */\nexport class ScopeWriteGuard {\n static extractConstraints(opts: { where: TWhere }): TExtraction {\n const constraints: TConstraints = new Map();\n const reason = ScopeWriteGuard.collect({\n where: opts.where as Record<string, unknown>,\n constraints,\n });\n\n return reason === undefined\n ? { isVerifiable: true, constraints }\n : { isVerifiable: false, reason };\n }\n\n /** Adds the where's constraints to `constraints`; returns the reason it cannot be verified, if any. */\n private static collect(opts: {\n where: Record<string, unknown>;\n constraints: TConstraints;\n }): string | undefined {\n const { where, constraints } = opts;\n\n for (const [key, value] of Object.entries(where)) {\n if (key === 'and') {\n if (!Array.isArray(value)) {\n return \"'and' is not a list\";\n }\n\n for (const part of value) {\n const reason = ScopeWriteGuard.collect({\n where: part as Record<string, unknown>,\n constraints,\n });\n if (reason !== undefined) {\n return reason;\n }\n }\n\n continue;\n }\n\n if (key === 'or') {\n const union = ScopeWriteGuard.unionOfBranches({ branches: value });\n if (typeof union === 'string') {\n return union;\n }\n\n const existing = constraints.get(union.column);\n constraints.set(\n union.column,\n existing ? intersect({ left: existing, right: union.allowed }) : union.allowed,\n );\n continue;\n }\n\n if (key.includes('.')) {\n return `the nested path '${key}' cannot be checked on a write`;\n }\n\n const allowed = ScopeWriteGuard.allowedValues({ value });\n if (typeof allowed === 'string') {\n return `column '${key}': ${allowed}`;\n }\n\n const existing = constraints.get(key);\n constraints.set(key, existing ? intersect({ left: existing, right: allowed }) : allowed);\n }\n\n return undefined;\n }\n\n /**\n * An `or` is checkable only when every branch constrains the same single column with a scalar,\n * `null`, `eq`, `in` or `inq`: the allowed values are then the union of the branches. This is the\n * shared-rows scope, `{ or: [{ merchantId: { in: ids } }, { merchantId: null }] }`. Any other `or`\n * (several columns, ranges, nested `and` or `or`) cannot be checked.\n */\n private static unionOfBranches(opts: {\n branches: unknown;\n }): { column: string; allowed: Set<string | null> } | string {\n const { branches } = opts;\n\n if (!Array.isArray(branches) || branches.length === 0) {\n return \"'or' is not a list\";\n }\n\n let column: string | undefined;\n const allowed = new Set<string | null>();\n\n for (const branch of branches) {\n const entries = Object.entries((branch ?? {}) as Record<string, unknown>);\n if (entries.length !== 1) {\n return \"an 'or' branch with several conditions cannot be checked on a write\";\n }\n\n const [key, value] = entries[0];\n if (key === 'and' || key === 'or' || key.includes('.')) {\n return `an 'or' branch over '${key}' cannot be checked on a write`;\n }\n\n if (column !== undefined && column !== key) {\n return \"an 'or' over different columns cannot be checked on a write\";\n }\n\n column = key;\n const values = ScopeWriteGuard.allowedValues({ value });\n if (typeof values === 'string') {\n return `column '${key}': ${values}`;\n }\n\n values.forEach((entry) => allowed.add(entry));\n }\n\n return { column: column as string, allowed };\n }\n\n /** The values one column's condition allows, or a string naming why it cannot be checked. */\n private static allowedValues(opts: { value: unknown }): Set<string | null> | string {\n const { value } = opts;\n\n if (isScalar(value)) {\n return new Set([normalise(value)]);\n }\n\n if (Array.isArray(value)) {\n return value.every(isScalar)\n ? new Set(value.map(normalise))\n : 'a list with a non-scalar entry';\n }\n\n if (typeof value !== 'object' || value === undefined) {\n return 'an unsupported condition';\n }\n\n const operators = Object.keys(value as object);\n if (operators.length !== 1) {\n return `a condition with ${operators.length} operators cannot be checked on a write`;\n }\n\n const [operator] = operators;\n const operand = (value as Record<string, unknown>)[operator];\n\n if (operator === QueryOperators.EQ && isScalar(operand)) {\n return new Set([normalise(operand)]);\n }\n\n if (\n (operator === QueryOperators.INQ || operator === QueryOperators.IN) &&\n Array.isArray(operand)\n ) {\n return operand.every(isScalar)\n ? new Set(operand.map(normalise))\n : 'a list with a non-scalar entry';\n }\n\n return `the operator '${operator}' cannot be checked on a write`;\n }\n\n /**\n * The scope as a MUTATION `where` (update, delete, soft delete, restore). A scope with a `null`\n * branch - `{ or: [{ merchantId: { in: ids } }, { merchantId: null }] }` - lets the caller READ the\n * shared rows. Changing or deleting one is the same permission as creating one, `write.sharedRows`,\n * so without it the `null` branch is removed and only the caller's own rows match. With\n * `sharedRows` the scope is returned as it is.\n *\n * Only the shapes the write guard can read are narrowed. Any other shape cannot be shown to exclude\n * the shared rows, so the mutation is refused, as an update with a payload already is.\n */\n static mutationWhere(opts: {\n settings: IModelAccessSettings;\n model: string;\n operation: string;\n scopeWhere: TWhere;\n }): TWhere {\n const { settings, model, operation, scopeWhere } = opts;\n\n if (settings.write?.sharedRows === true) {\n return scopeWhere;\n }\n\n const narrowed = ScopeWriteGuard.withoutShared({ where: scopeWhere });\n\n if (narrowed.kind === 'unverifiable') {\n throw ScopeWriteGuard.denied({\n model,\n operation,\n detail: `the resolved scope cannot be verified on a write | ${narrowed.reason}`,\n });\n }\n\n return narrowed.kind === 'none' ? ScopeFilterDenial.where() : narrowed.where;\n }\n\n /** `where` with every `null` the scope allows removed; `none` when nothing but `null` was allowed. */\n private static withoutShared(opts: { where: TWhere }): TNarrowed {\n const result: TWhere = {};\n\n for (const [key, value] of Object.entries(opts.where)) {\n if (key === 'and' || key === 'or') {\n if (!Array.isArray(value) || (key === 'or' && value.length === 0)) {\n return { kind: 'unverifiable', reason: `'${key}' is not a list` };\n }\n\n // An 'or' is read only when every branch constrains the same column, as the guard reads it: a branch over another column\n // could match a shared row without a null in sight.\n if (key === 'or') {\n const union = ScopeWriteGuard.unionOfBranches({ branches: value });\n if (typeof union === 'string') {\n return { kind: 'unverifiable', reason: union };\n }\n }\n\n const kept: TWhere[] = [];\n for (const part of value) {\n const narrowed = ScopeWriteGuard.withoutShared({ where: isRecord(part) ? part : {} });\n\n if (narrowed.kind === 'unverifiable') {\n return narrowed;\n }\n\n if (narrowed.kind === 'none') {\n // One impossible 'and' part makes the whole 'and' impossible; an impossible 'or' branch just drops out.\n if (key === 'and') {\n return narrowed;\n }\n continue;\n }\n\n kept.push(narrowed.where);\n }\n\n if (key === 'or' && kept.length === 0) {\n return { kind: 'none' };\n }\n\n result[key] = kept;\n continue;\n }\n\n if (key.includes('.')) {\n return {\n kind: 'unverifiable',\n reason: `the nested path '${key}' cannot be checked on a write`,\n };\n }\n\n const narrowed = ScopeWriteGuard.conditionWithoutNull({ value });\n if (narrowed.kind !== 'condition') {\n return narrowed.kind === 'none'\n ? { kind: 'none' }\n : { kind: 'unverifiable', reason: `column '${key}': ${narrowed.reason}` };\n }\n\n result[key] = narrowed.value;\n }\n\n return { kind: 'where', where: result };\n }\n\n /** One column's condition without its `null` values, reading the same shapes `allowedValues` reads. */\n private static conditionWithoutNull(opts: {\n value: unknown;\n }):\n | { kind: 'condition'; value: unknown }\n | { kind: 'none' }\n | { kind: 'unverifiable'; reason: string } {\n const { value } = opts;\n\n const list = (entries: unknown[]) => {\n if (!entries.every(isScalar)) {\n return { kind: 'unverifiable' as const, reason: 'a list with a non-scalar entry' };\n }\n\n const kept = entries.filter((entry) => entry !== null);\n return kept.length === 0\n ? { kind: 'none' as const }\n : { kind: 'condition' as const, value: kept };\n };\n\n if (isScalar(value)) {\n return value === null ? { kind: 'none' } : { kind: 'condition', value };\n }\n\n if (Array.isArray(value)) {\n return list(value);\n }\n\n if (!isRecord(value)) {\n return { kind: 'unverifiable', reason: 'an unsupported condition' };\n }\n\n const operators = Object.keys(value);\n if (operators.length !== 1) {\n return {\n kind: 'unverifiable',\n reason: `a condition with ${operators.length} operators cannot be checked on a write`,\n };\n }\n\n const [operator] = operators;\n const operand = value[operator];\n\n if (operator === QueryOperators.EQ && isScalar(operand)) {\n return operand === null ? { kind: 'none' } : { kind: 'condition', value };\n }\n\n if (\n (operator === QueryOperators.INQ || operator === QueryOperators.IN) &&\n Array.isArray(operand)\n ) {\n const narrowed = list(operand);\n return narrowed.kind === 'condition'\n ? { kind: 'condition', value: { [operator]: narrowed.value } }\n : narrowed;\n }\n\n return {\n kind: 'unverifiable',\n reason: `the operator '${operator}' cannot be checked on a write`,\n };\n }\n\n /**\n * Holds `rows` to the scope `settings.resolve()` returns now. Returns the rows to write: the same\n * objects when nothing changes, copies with the scope columns filled in for `assign`. Throws, and\n * so writes nothing, when any row is outside the scope.\n */\n static apply<Row extends Record<string, unknown>>(opts: {\n settings: IModelAccessSettings;\n model: string;\n rows: Row[];\n operation: TScopeWriteOperation;\n }): Row[] {\n const { settings, model, rows, operation } = opts;\n const scope = settings.resolve();\n\n if (scope === ScopeFilters.UNRESTRICTED) {\n return rows;\n }\n\n if (scope === null || scope === undefined) {\n // An update is already confined by the scoped `where`, which under `deny` matches no row; the\n // guard adds nothing there. A create has no such `where`, so an unresolved scope refuses it.\n if (\n settings.onMissing === ScopeFilterMissingBehaviors.ALLOW ||\n operation === ScopeWriteOperations.UPDATE\n ) {\n return rows;\n }\n\n throw ScopeWriteGuard.denied({\n model,\n operation,\n detail: 'no scope could be resolved for this caller',\n });\n }\n\n const extraction = ScopeWriteGuard.extractConstraints({ where: scope });\n if (!extraction.isVerifiable) {\n throw ScopeWriteGuard.denied({\n model,\n operation,\n detail: `the resolved scope cannot be verified on a write | ${extraction.reason}`,\n });\n }\n\n const { constraints } = extraction;\n const declared = settings.columns;\n\n if (declared) {\n const undeclared = [...constraints.keys()].find((column) => !declared.includes(column));\n if (undeclared !== undefined) {\n throw ScopeWriteGuard.denied({\n model,\n operation,\n detail: `the resolved scope constrains column '${undeclared}', which access.columns does not declare`,\n });\n }\n }\n\n const isAssign = settings.write?.mode === ScopeWriteGuards.ASSIGN && operation === 'create';\n const sharedRows = settings.write?.sharedRows === true;\n\n return rows.map((row) => {\n let result = row;\n\n for (const [column, allowed] of constraints) {\n const value = (row as Record<string, unknown>)[column];\n\n if (value === undefined) {\n if (operation === 'update') {\n continue;\n }\n\n // `assign` first: stamping gives the row an owner, which is safer than leaving it shared.\n const only = allowed.size === 1 ? [...allowed][0] : undefined;\n if (isAssign && only !== undefined && only !== null) {\n result = { ...result, [column]: only };\n continue;\n }\n\n // Absent means the database default, usually `null`, so it is held to the `null` rule.\n if (sharedRows) {\n continue;\n }\n\n throw ScopeWriteGuard.denied({\n model,\n operation,\n column,\n detail: 'the scope column is missing',\n });\n }\n\n const normalised = isScalar(value) ? normalise(value) : undefined;\n // A `null` branch in the scope lets this caller READ shared rows. Writing one (or moving a\n // row into the shared set) is a separate permission: only `sharedRows` grants it.\n const isOutside = normalised === null ? !sharedRows : !allowed.has(normalised as string);\n\n if (normalised === undefined || isOutside) {\n throw ScopeWriteGuard.denied({\n model,\n operation,\n column,\n detail: 'the value is outside the resolved scope',\n });\n }\n }\n\n return result;\n });\n }\n\n /** Names the model and the column, never a value: the caller may be a request. */\n private static denied(opts: {\n model: string;\n operation: string;\n column?: string;\n detail: string;\n }) {\n const { model, operation, column, detail } = opts;\n\n return getError({\n statusCode: WRITE_DENIED_STATUS,\n messageCode: RepositoryErrorCodes.SCOPE_WRITE_DENIED,\n message: [\n `[${operation}] write refused by the access scope | entity: ${model}`,\n ...(column ? [`column: ${column}`] : []),\n detail,\n ].join(' | '),\n });\n }\n}\n"]}
@@ -1,4 +1,5 @@
1
- import type { IdType, IExtraOptions, IPersistableRepository, IScopeFilterSettings, ITransaction, TCount, TByIdFilter, TDataRange, TDrizzleQueryOptions, TFields, TFilter, TFindOneOptions, TFindOptions, TFindRangeOptions, TLockOptions, TRepositoryOperationScope, TRow, TWhere } from '@venizia/ignis-kernel';
1
+ import type { TScopeWriteOperation } from '../common/constants.js';
2
+ import type { IdType, IExtraOptions, IPersistableRepository, IModelAccessSettings, ITransaction, TCount, TByIdFilter, TDataRange, TDrizzleQueryOptions, TFields, TFilter, TFindOneOptions, TFindOptions, TFindRangeOptions, TLockOptions, TRepositoryOperationScope, TRow, TWhere } from '@venizia/ignis-kernel';
2
3
  import { AbstractRepository } from '@venizia/ignis-kernel';
3
4
  import type { IRelationalDataSource } from '../../datasources/common/index.js';
4
5
  import type { BaseRelationalEntity, TTableInsert, TTableObject, TTableSchemaWithId } from '../../models/index.js';
@@ -45,10 +46,24 @@ export declare abstract class RelationalBaseRepository<EntitySchema extends TTab
45
46
  getDefaultFilter(): TFilter | undefined;
46
47
  getDefaultLimit(): number | undefined;
47
48
  hasDefaultFilter(): boolean;
48
- /** Same override seam as `getDefaultFilter()` - a repository with no resolvable `@model` entity (a synthetic test double, a hand-built stub) overrides this to avoid touching `modelSettings`/`entity` at all. */
49
- getScopeFilterSettings(): IScopeFilterSettings | undefined;
50
49
  /**
51
- * Row scope from `@model` settings.scopeFilter - AND-composed like a default filter, but never
50
+ * The model's `access` settings. Same override seam as `getDefaultFilter()` - a repository with no
51
+ * resolvable `@model` entity (a synthetic test double, a hand-built stub) overrides this to avoid
52
+ * touching `modelSettings`/`entity` at all.
53
+ */
54
+ getAccessSettings(): IModelAccessSettings | undefined;
55
+ /**
56
+ * Holds written rows to the resolved row scope (`access.write`): refuses a row outside
57
+ * it, and for `assign` returns copies with the scope columns filled in. Nothing is written when it
58
+ * throws. Like the read scope, it is not skippable by `shouldSkipDefaultFilter`; a caller that is
59
+ * trusted to write across scopes resolves to `ScopeFilters.UNRESTRICTED`.
60
+ */
61
+ protected guardScopedWrite<Row extends Record<string, unknown>>(opts: {
62
+ rows: Row[];
63
+ operation: TScopeWriteOperation;
64
+ }): Row[];
65
+ /**
66
+ * Row scope from `@model` settings.access - AND-composed like a default filter, but never
52
67
  * skippable via `shouldSkipDefaultFilter`: that flag serves `restore()`'s deliberate reach past
53
68
  * soft-delete, which must not also reach past tenant/ownership scoping.
54
69
  *
@@ -60,12 +75,15 @@ export declare abstract class RelationalBaseRepository<EntitySchema extends TTab
60
75
  protected applyScopeFilter<DO = any>(opts: {
61
76
  userFilter?: TFilter<DO>;
62
77
  dangerouslySkipScopeFilter?: boolean;
78
+ mutation?: string;
63
79
  }): TFilter<DO>;
64
80
  /** Merges default filter with user filter. Skippable via shouldSkipDefaultFilter - the row scope from applyScopeFilter is not. */
65
81
  applyDefaultFilter<DO = any>(opts: {
66
82
  userFilter?: TFilter<DO>;
67
83
  shouldSkipDefaultFilter?: boolean;
68
84
  dangerouslySkipScopeFilter?: boolean;
85
+ /** The name of the write (`update`, `delete`) when the filter selects rows to change: the row scope then leaves out the shared rows unless `write.sharedRows`. */
86
+ mutation?: string;
69
87
  }): TFilter<DO>;
70
88
  beginTransaction(opts?: TRelationalTransactionOptionsOf<TDataSource>): Promise<TRelationalTransactionOf<TDataSource>>;
71
89
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"base.d.ts","sourceRoot":"","sources":["../../../../../../src/relational/core/repositories/core/base.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,MAAM,EACN,aAAa,EACb,sBAAsB,EACtB,oBAAoB,EACpB,YAAY,EACZ,MAAM,EACN,WAAW,EACX,UAAU,EACV,oBAAoB,EACpB,OAAO,EACP,OAAO,EACP,eAAe,EACf,YAAY,EACZ,iBAAiB,EACjB,YAAY,EACZ,yBAAyB,EACzB,IAAI,EACJ,MAAM,EACP,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EACL,kBAAkB,EAGnB,MAAM,uBAAuB,CAAC;AAE/B,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,sCAAsC,CAAC;AAGlF,OAAO,KAAK,EACV,oBAAoB,EACpB,YAAY,EACZ,YAAY,EACZ,kBAAkB,EACnB,MAAM,0BAA0B,CAAC;AAClC,OAAO,KAAK,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,+BAA+B,CAAC;AAGvE,OAAO,KAAK,EACV,uBAAuB,EACvB,uBAAuB,EACvB,wBAA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,CAAA;SAAE,CAAC;KACnE,GAAG,OAAO,CAAC,MAAM,GAAG;QAAE,IAAI,EAAE,KAAK,CAAC,CAAC,CAAC,CAAA;KAAE,CAAC;CAazC"}
1
+ {"version":3,"file":"base.d.ts","sourceRoot":"","sources":["../../../../../../src/relational/core/repositories/core/base.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,qBAAqB,CAAC;AAChE,OAAO,KAAK,EACV,MAAM,EACN,aAAa,EACb,sBAAsB,EACtB,oBAAoB,EACpB,YAAY,EACZ,MAAM,EACN,WAAW,EACX,UAAU,EACV,oBAAoB,EACpB,OAAO,EACP,OAAO,EACP,eAAe,EACf,YAAY,EACZ,iBAAiB,EACjB,YAAY,EACZ,yBAAyB,EACzB,IAAI,EACJ,MAAM,EACP,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EACL,kBAAkB,EAGnB,MAAM,uBAAuB,CAAC;AAE/B,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,sCAAsC,CAAC;AAGlF,OAAO,KAAK,EACV,oBAAoB,EACpB,YAAY,EACZ,YAAY,EACZ,kBAAkB,EACnB,MAAM,0BAA0B,CAAC;AAClC,OAAO,KAAK,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,+BAA+B,CAAC;AAGvE,OAAO,KAAK,EACV,uBAAuB,EACvB,uBAAuB,EACvB,wBAAwB,EACxB,sBAAsB,EACtB,wBAAwB,EACxB,+BAA+B,EAChC,MAAM,WAAW,CAAC;AAInB,iTAAiT;AACjT,8BAAsB,wBAAwB,CAC5C,YAAY,SAAS,kBAAkB,GAAG,kBAAkB,EAC5D,UAAU,SAAS,YAAY,CAAC,YAAY,CAAC,GAAG,YAAY,CAAC,YAAY,CAAC,EAC1E,aAAa,SAAS,YAAY,CAAC,YAAY,CAAC,GAAG,YAAY,CAAC,YAAY,CAAC,EAC7E,YAAY,SAAS,aAAa,GAAG,uBAAuB,EAC5D,WAAW,SAAS,qBAAqB,G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E,KAAK,CAAC,CAAC,CAAC,CAAA;KAAE,CAAC;CAazC"}
@@ -4,6 +4,7 @@ import { isTransactionCommitted } from '../../datasources/transaction-state.js';
4
4
  import { getError } from '@venizia/ignis-helpers/core';
5
5
  import { getTableColumns } from 'drizzle-orm';
6
6
  import { ScopeFilterDenial } from '../common/index.js';
7
+ import { ScopeWriteGuard } from '../common/scope-write-guard.js';
7
8
  /** Relational implementation of `AbstractRepository`: adds the query dialect + hidden-column exclusion on top of the neutral base, and reaches the database only through `IRelationalQueryExecutor`. Both engine-facing parameters default to the neutral SQL contracts; an engine binds them by subclassing. */
8
9
  export class RelationalBaseRepository extends AbstractRepository {
9
10
  /**
@@ -80,7 +81,7 @@ export class RelationalBaseRepository extends AbstractRepository {
80
81
  return this._visibleColumns;
81
82
  }
82
83
  getDefaultFilter() {
83
- return this.modelSettings?.defaultFilter;
84
+ return this.modelSettings?.query?.filter;
84
85
  }
85
86
  getDefaultLimit() {
86
87
  return this.defaultLimit;
@@ -89,12 +90,34 @@ export class RelationalBaseRepository extends AbstractRepository {
89
90
  const defaultFilter = this.getDefaultFilter();
90
91
  return defaultFilter !== undefined && Object.keys(defaultFilter).length > 0;
91
92
  }
92
- /** Same override seam as `getDefaultFilter()` - a repository with no resolvable `@model` entity (a synthetic test double, a hand-built stub) overrides this to avoid touching `modelSettings`/`entity` at all. */
93
- getScopeFilterSettings() {
94
- return this.modelSettings?.scopeFilter;
93
+ /**
94
+ * The model's `access` settings. Same override seam as `getDefaultFilter()` - a repository with no
95
+ * resolvable `@model` entity (a synthetic test double, a hand-built stub) overrides this to avoid
96
+ * touching `modelSettings`/`entity` at all.
97
+ */
98
+ getAccessSettings() {
99
+ return this.modelSettings?.access;
95
100
  }
96
101
  /**
97
- * Row scope from `@model` settings.scopeFilter - AND-composed like a default filter, but never
102
+ * Holds written rows to the resolved row scope (`access.write`): refuses a row outside
103
+ * it, and for `assign` returns copies with the scope columns filled in. Nothing is written when it
104
+ * throws. Like the read scope, it is not skippable by `shouldSkipDefaultFilter`; a caller that is
105
+ * trusted to write across scopes resolves to `ScopeFilters.UNRESTRICTED`.
106
+ */
107
+ guardScopedWrite(opts) {
108
+ const settings = this.getAccessSettings();
109
+ if (!settings) {
110
+ return opts.rows;
111
+ }
112
+ return ScopeWriteGuard.apply({
113
+ settings,
114
+ model: this.entity.name,
115
+ rows: opts.rows,
116
+ operation: opts.operation,
117
+ });
118
+ }
119
+ /**
120
+ * Row scope from `@model` settings.access - AND-composed like a default filter, but never
98
121
  * skippable via `shouldSkipDefaultFilter`: that flag serves `restore()`'s deliberate reach past
99
122
  * soft-delete, which must not also reach past tenant/ownership scoping.
100
123
  *
@@ -104,11 +127,11 @@ export class RelationalBaseRepository extends AbstractRepository {
104
127
  * reviewed at the repository - never inferable from a request.
105
128
  */
106
129
  applyScopeFilter(opts) {
107
- const { userFilter, dangerouslySkipScopeFilter } = opts;
130
+ const { userFilter, dangerouslySkipScopeFilter, mutation } = opts;
108
131
  if (dangerouslySkipScopeFilter) {
109
132
  return userFilter ?? {};
110
133
  }
111
- const scopeFilterSettings = this.getScopeFilterSettings();
134
+ const scopeFilterSettings = this.getAccessSettings();
112
135
  if (!scopeFilterSettings) {
113
136
  return userFilter ?? {};
114
137
  }
@@ -120,7 +143,19 @@ export class RelationalBaseRepository extends AbstractRepository {
120
143
  return userFilter ?? {};
121
144
  }
122
145
  if (scopeWhere !== null && scopeWhere !== undefined) {
123
- return this.queryDialect.mergeFilter({ defaultFilter: { where: scopeWhere }, userFilter });
146
+ // A write reaches only the rows it may write: the shared (null) rows a read scope allows need `write.sharedRows`.
147
+ const effectiveWhere = mutation === undefined
148
+ ? scopeWhere
149
+ : ScopeWriteGuard.mutationWhere({
150
+ settings: scopeFilterSettings,
151
+ model: this.entity.name,
152
+ operation: mutation,
153
+ scopeWhere,
154
+ });
155
+ return this.queryDialect.mergeFilter({
156
+ defaultFilter: { where: effectiveWhere },
157
+ userFilter,
158
+ });
124
159
  }
125
160
  if (scopeFilterSettings.onMissing === ScopeFilterMissingBehaviors.ALLOW) {
126
161
  return userFilter ?? {};
@@ -134,8 +169,12 @@ export class RelationalBaseRepository extends AbstractRepository {
134
169
  }
135
170
  /** Merges default filter with user filter. Skippable via shouldSkipDefaultFilter - the row scope from applyScopeFilter is not. */
136
171
  applyDefaultFilter(opts) {
137
- const { userFilter, shouldSkipDefaultFilter, dangerouslySkipScopeFilter } = opts;
138
- const scopedFilter = this.applyScopeFilter({ userFilter, dangerouslySkipScopeFilter });
172
+ const { userFilter, shouldSkipDefaultFilter, dangerouslySkipScopeFilter, mutation } = opts;
173
+ const scopedFilter = this.applyScopeFilter({
174
+ userFilter,
175
+ dangerouslySkipScopeFilter,
176
+ mutation,
177
+ });
139
178
  if (shouldSkipDefaultFilter) {
140
179
  return scopedFilter;
141
180
  }