@venizia/ignis-connectors 0.4.1 → 0.4.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/dist/cjs/common/scope-filter.d.ts +1 -1
- package/dist/cjs/common/scope-filter.d.ts.map +1 -1
- package/dist/cjs/common/scope-filter.js +33 -7
- package/dist/cjs/common/scope-filter.js.map +1 -1
- package/dist/cjs/relational/core/repositories/common/scope-write-guard.d.ts +50 -0
- package/dist/cjs/relational/core/repositories/common/scope-write-guard.d.ts.map +1 -0
- package/dist/cjs/relational/core/repositories/common/scope-write-guard.js +248 -0
- package/dist/cjs/relational/core/repositories/common/scope-write-guard.js.map +1 -0
- package/dist/cjs/relational/core/repositories/core/base.d.ts +19 -4
- package/dist/cjs/relational/core/repositories/core/base.d.ts.map +1 -1
- package/dist/cjs/relational/core/repositories/core/base.js +28 -4
- package/dist/cjs/relational/core/repositories/core/base.js.map +1 -1
- package/dist/cjs/relational/core/repositories/core/persistable.d.ts.map +1 -1
- package/dist/cjs/relational/core/repositories/core/persistable.js +6 -1
- package/dist/cjs/relational/core/repositories/core/persistable.js.map +1 -1
- package/dist/cjs/relational/core/repositories/dialect/filter.d.ts +2 -2
- package/dist/cjs/relational/core/repositories/dialect/filter.js +3 -3
- package/dist/cjs/relational/core/repositories/dialect/filter.js.map +1 -1
- package/dist/cjs/relational/core/repositories/sqls/recursive-tree.d.ts +9 -0
- package/dist/cjs/relational/core/repositories/sqls/recursive-tree.d.ts.map +1 -1
- package/dist/cjs/relational/core/repositories/sqls/recursive-tree.js +14 -3
- package/dist/cjs/relational/core/repositories/sqls/recursive-tree.js.map +1 -1
- package/dist/cjs/search/core/controllers/abstract.d.ts +4 -0
- package/dist/cjs/search/core/controllers/abstract.d.ts.map +1 -1
- package/dist/cjs/search/core/controllers/abstract.js +15 -1
- package/dist/cjs/search/core/controllers/abstract.js.map +1 -1
- package/dist/cjs/search/core/controllers/factory.d.ts +14 -0
- package/dist/cjs/search/core/controllers/factory.d.ts.map +1 -1
- package/dist/cjs/search/core/controllers/factory.js +7 -1
- package/dist/cjs/search/core/controllers/factory.js.map +1 -1
- package/dist/cjs/search/core/controllers/scope.d.ts +28 -0
- package/dist/cjs/search/core/controllers/scope.d.ts.map +1 -0
- package/dist/cjs/search/core/controllers/scope.js +68 -0
- package/dist/cjs/search/core/controllers/scope.js.map +1 -0
- package/dist/esm/common/scope-filter.d.ts +1 -1
- package/dist/esm/common/scope-filter.d.ts.map +1 -1
- package/dist/esm/common/scope-filter.js +34 -8
- package/dist/esm/common/scope-filter.js.map +1 -1
- package/dist/esm/relational/core/repositories/common/scope-write-guard.d.ts +50 -0
- package/dist/esm/relational/core/repositories/common/scope-write-guard.d.ts.map +1 -0
- package/dist/esm/relational/core/repositories/common/scope-write-guard.js +244 -0
- package/dist/esm/relational/core/repositories/common/scope-write-guard.js.map +1 -0
- package/dist/esm/relational/core/repositories/core/base.d.ts +19 -4
- package/dist/esm/relational/core/repositories/core/base.d.ts.map +1 -1
- package/dist/esm/relational/core/repositories/core/base.js +28 -4
- package/dist/esm/relational/core/repositories/core/base.js.map +1 -1
- package/dist/esm/relational/core/repositories/core/persistable.d.ts.map +1 -1
- package/dist/esm/relational/core/repositories/core/persistable.js +6 -1
- package/dist/esm/relational/core/repositories/core/persistable.js.map +1 -1
- package/dist/esm/relational/core/repositories/dialect/filter.d.ts +2 -2
- package/dist/esm/relational/core/repositories/dialect/filter.js +3 -3
- package/dist/esm/relational/core/repositories/dialect/filter.js.map +1 -1
- package/dist/esm/relational/core/repositories/sqls/recursive-tree.d.ts +9 -0
- package/dist/esm/relational/core/repositories/sqls/recursive-tree.d.ts.map +1 -1
- package/dist/esm/relational/core/repositories/sqls/recursive-tree.js +15 -4
- package/dist/esm/relational/core/repositories/sqls/recursive-tree.js.map +1 -1
- package/dist/esm/search/core/controllers/abstract.d.ts +4 -0
- package/dist/esm/search/core/controllers/abstract.d.ts.map +1 -1
- package/dist/esm/search/core/controllers/abstract.js +15 -1
- package/dist/esm/search/core/controllers/abstract.js.map +1 -1
- package/dist/esm/search/core/controllers/factory.d.ts +14 -0
- package/dist/esm/search/core/controllers/factory.d.ts.map +1 -1
- package/dist/esm/search/core/controllers/factory.js +7 -1
- package/dist/esm/search/core/controllers/factory.js.map +1 -1
- package/dist/esm/search/core/controllers/scope.d.ts +28 -0
- package/dist/esm/search/core/controllers/scope.d.ts.map +1 -0
- package/dist/esm/search/core/controllers/scope.js +64 -0
- package/dist/esm/search/core/controllers/scope.js.map +1 -0
- package/package.json +6 -6
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Refuses to boot when `settings.
|
|
2
|
+
* Refuses to boot when `settings.access` is declared where it cannot be honoured. Both cases
|
|
3
3
|
* are silent at runtime and fail in OPPOSITE directions: a search-backed model returns more rows,
|
|
4
4
|
* a context-less one returns none. The caller supplies `asyncContextEnabled` so no application
|
|
5
5
|
* config type reaches into this tier.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"scope-filter.d.ts","sourceRoot":"","sources":["../../../src/common/scope-filter.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"scope-filter.d.ts","sourceRoot":"","sources":["../../../src/common/scope-filter.ts"],"names":[],"mappings":"AAMA;;;;;GAKG;AACH,eAAO,MAAM,0BAA0B,GAAI,MAAM;IAAE,mBAAmB,EAAE,OAAO,CAAA;CAAE,KAAG,IA2EnF,CAAC"}
|
|
@@ -5,8 +5,9 @@ const common_1 = require("@venizia/ignis-helpers/common");
|
|
|
5
5
|
const core_1 = require("@venizia/ignis-helpers/core");
|
|
6
6
|
const ignis_kernel_1 = require("@venizia/ignis-kernel");
|
|
7
7
|
const models_1 = require("../search/core/models");
|
|
8
|
+
const drizzle_orm_1 = require("drizzle-orm");
|
|
8
9
|
/**
|
|
9
|
-
* Refuses to boot when `settings.
|
|
10
|
+
* Refuses to boot when `settings.access` is declared where it cannot be honoured. Both cases
|
|
10
11
|
* are silent at runtime and fail in OPPOSITE directions: a search-backed model returns more rows,
|
|
11
12
|
* a context-less one returns none. The caller supplies `asyncContextEnabled` so no application
|
|
12
13
|
* config type reaches into this tier.
|
|
@@ -15,8 +16,9 @@ const assertScopeFilterSupported = (opts) => {
|
|
|
15
16
|
const models = ignis_kernel_1.MetadataRegistry.getInstance().getAllModels();
|
|
16
17
|
const searchBacked = [];
|
|
17
18
|
const withoutAmbientContext = [];
|
|
19
|
+
const invalidWriteGuard = [];
|
|
18
20
|
for (const [name, entry] of models) {
|
|
19
|
-
if (!entry.metadata?.settings?.
|
|
21
|
+
if (!entry.metadata?.settings?.access) {
|
|
20
22
|
continue;
|
|
21
23
|
}
|
|
22
24
|
const modelClass = (0, common_1.resolveValue)({ value: entry.target });
|
|
@@ -27,24 +29,48 @@ const assertScopeFilterSupported = (opts) => {
|
|
|
27
29
|
if (!opts.asyncContextEnabled) {
|
|
28
30
|
withoutAmbientContext.push(name);
|
|
29
31
|
}
|
|
32
|
+
const { columns, write } = entry.metadata.settings.access;
|
|
33
|
+
const writeGuard = write?.mode;
|
|
34
|
+
if (writeGuard !== undefined && !ignis_kernel_1.ScopeWriteGuards.isValid(writeGuard)) {
|
|
35
|
+
invalidWriteGuard.push(`${name}: write.mode '${String(writeGuard)}' is not reject or assign`);
|
|
36
|
+
}
|
|
37
|
+
if (columns !== undefined) {
|
|
38
|
+
const schema = modelClass.schema;
|
|
39
|
+
const known = (0, drizzle_orm_1.is)(schema, drizzle_orm_1.Table) ? Object.keys((0, drizzle_orm_1.getTableColumns)(schema)) : undefined;
|
|
40
|
+
const unknown = columns.filter((column) => known !== undefined && !known.includes(column));
|
|
41
|
+
if (!Array.isArray(columns) || columns.length === 0) {
|
|
42
|
+
invalidWriteGuard.push(`${name}: columns must be a non-empty list of property names`);
|
|
43
|
+
}
|
|
44
|
+
else if (unknown.length > 0) {
|
|
45
|
+
invalidWriteGuard.push(`${name}: columns names ${unknown.join(', ')}, which the model does not have`);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
30
48
|
}
|
|
31
49
|
if (searchBacked.length > 0) {
|
|
32
50
|
throw (0, core_1.getError)({
|
|
33
51
|
message: [
|
|
34
|
-
`[assertScopeFilterSupported] settings.
|
|
52
|
+
`[assertScopeFilterSupported] settings.access on a search-backed model | models: ${searchBacked.join(', ')}`,
|
|
35
53
|
'Search repositories never read this setting, so no row scope is applied.',
|
|
36
54
|
'Unlike the relational path, a missing scope here returns MORE rows rather than none - nothing fails, the result is just wider.',
|
|
37
|
-
'Scope the search query in the application, and remove settings.
|
|
55
|
+
'Scope the search query in the application, and remove settings.access from the model.',
|
|
56
|
+
].join(' | '),
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
if (invalidWriteGuard.length > 0) {
|
|
60
|
+
throw (0, core_1.getError)({
|
|
61
|
+
message: [
|
|
62
|
+
`[assertScopeFilterSupported] invalid settings.access write guard | ${invalidWriteGuard.join(' | ')}`,
|
|
63
|
+
'write.mode is reject or assign; columns, when declared, names properties of the model.',
|
|
38
64
|
].join(' | '),
|
|
39
65
|
});
|
|
40
66
|
}
|
|
41
67
|
if (withoutAmbientContext.length > 0) {
|
|
42
68
|
throw (0, core_1.getError)({
|
|
43
69
|
message: [
|
|
44
|
-
`[assertScopeFilterSupported] settings.
|
|
45
|
-
'
|
|
70
|
+
`[assertScopeFilterSupported] settings.access declared while asyncContext.enable is false | models: ${withoutAmbientContext.join(', ')}`,
|
|
71
|
+
'access.resolve() takes no arguments, so the ambient request context is its only input.',
|
|
46
72
|
'With no context store every resolve() returns undefined, onMissing denies by default, and EVERY query on these models matches zero rows - with nothing naming the flag as the cause.',
|
|
47
|
-
'Set asyncContext.enable to true, or remove settings.
|
|
73
|
+
'Set asyncContext.enable to true, or remove settings.access.',
|
|
48
74
|
].join(' | '),
|
|
49
75
|
});
|
|
50
76
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"scope-filter.js","sourceRoot":"","sources":["../../../src/common/scope-filter.ts"],"names":[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AAM,GAAG,CAAC,EAAE,CAAC;QACjC,MAAM,IAAA,eAAQ,EAAC;YACb,OAAO,EAAE;gBACP,sEAAsE,iBAAiB,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE;gBACrG,wFAAwF;aACzF,CAAC,IAAI,CAAC,KAAK,CAAC;SACd,CAAC,CAAC;IACL,CAAC;IAED,IAAI,qBAAqB,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QACrC,MAAM,IAAA,eAAQ,EAAC;YACb,OAAO,EAAE;gBACP,sGAAsG,qBAAqB,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE;gBACxI,wFAAwF;gBACxF,sLAAsL;gBACtL,6DAA6D;aAC9D,CAAC,IAAI,CAAC,KAAK,CAAC;SACd,CAAC,CAAC;IACL,CAAC;AACH,CAAC,CAAC;AA3EW,QAAA,0BAA0B,8BA2ErC","sourcesContent":["import { resolveValue } from '@venizia/ignis-helpers/common';\nimport { getError } from '@venizia/ignis-helpers/core';\nimport { MetadataRegistry, ScopeWriteGuards } from '@venizia/ignis-kernel';\nimport { BaseSearchEntity } from '@/search/core/models';\nimport { getTableColumns, is, Table } from 'drizzle-orm';\n\n/**\n * Refuses to boot when `settings.access` is declared where it cannot be honoured. Both cases\n * are silent at runtime and fail in OPPOSITE directions: a search-backed model returns more rows,\n * a context-less one returns none. The caller supplies `asyncContextEnabled` so no application\n * config type reaches into this tier.\n */\nexport const assertScopeFilterSupported = (opts: { asyncContextEnabled: boolean }): void => {\n const models = MetadataRegistry.getInstance().getAllModels();\n\n const searchBacked: string[] = [];\n const withoutAmbientContext: string[] = [];\n const invalidWriteGuard: string[] = [];\n\n for (const [name, entry] of models) {\n if (!entry.metadata?.settings?.access) {\n continue;\n }\n\n const modelClass = resolveValue({ value: entry.target });\n\n if (modelClass === BaseSearchEntity || modelClass.prototype instanceof BaseSearchEntity) {\n searchBacked.push(name);\n continue;\n }\n\n if (!opts.asyncContextEnabled) {\n withoutAmbientContext.push(name);\n }\n\n const { columns, write } = entry.metadata.settings.access;\n const writeGuard = write?.mode;\n\n if (writeGuard !== undefined && !ScopeWriteGuards.isValid(writeGuard)) {\n invalidWriteGuard.push(`${name}: write.mode '${String(writeGuard)}' is not reject or assign`);\n }\n\n if (columns !== undefined) {\n const schema = (modelClass as { schema?: unknown }).schema;\n const known = is(schema, Table) ? Object.keys(getTableColumns(schema)) : undefined;\n const unknown = columns.filter((column) => known !== undefined && !known.includes(column));\n\n if (!Array.isArray(columns) || columns.length === 0) {\n invalidWriteGuard.push(`${name}: columns must be a non-empty list of property names`);\n } else if (unknown.length > 0) {\n invalidWriteGuard.push(\n `${name}: columns names ${unknown.join(', ')}, which the model does not have`,\n );\n }\n }\n }\n\n if (searchBacked.length > 0) {\n throw getError({\n message: [\n `[assertScopeFilterSupported] settings.access on a search-backed model | models: ${searchBacked.join(', ')}`,\n 'Search repositories never read this setting, so no row scope is applied.',\n 'Unlike the relational path, a missing scope here returns MORE rows rather than none - nothing fails, the result is just wider.',\n 'Scope the search query in the application, and remove settings.access from the model.',\n ].join(' | '),\n });\n }\n\n if (invalidWriteGuard.length > 0) {\n throw getError({\n message: [\n `[assertScopeFilterSupported] invalid settings.access write guard | ${invalidWriteGuard.join(' | ')}`,\n 'write.mode is reject or assign; columns, when declared, names properties of the model.',\n ].join(' | '),\n });\n }\n\n if (withoutAmbientContext.length > 0) {\n throw getError({\n message: [\n `[assertScopeFilterSupported] settings.access declared while asyncContext.enable is false | models: ${withoutAmbientContext.join(', ')}`,\n 'access.resolve() takes no arguments, so the ambient request context is its only input.',\n 'With no context store every resolve() returns undefined, onMissing denies by default, and EVERY query on these models matches zero rows - with nothing naming the flag as the cause.',\n 'Set asyncContext.enable to true, or remove settings.access.',\n ].join(' | '),\n });\n }\n};\n"]}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import type { IModelAccessSettings, TWhere } from '@venizia/ignis-kernel';
|
|
2
|
+
/** The allowed values per scope column, each normalised so `1` and `'1'` and equal dates compare equal. */
|
|
3
|
+
type TConstraints = Map<string, Set<string | null>>;
|
|
4
|
+
type TExtraction = {
|
|
5
|
+
isVerifiable: true;
|
|
6
|
+
constraints: TConstraints;
|
|
7
|
+
} | {
|
|
8
|
+
isVerifiable: false;
|
|
9
|
+
reason: string;
|
|
10
|
+
};
|
|
11
|
+
/**
|
|
12
|
+
* The write side of `@model` settings.access. The resolved scope is a `where`; the guard reads
|
|
13
|
+
* from it the columns it constrains and the values it allows, and holds every written row to them.
|
|
14
|
+
*
|
|
15
|
+
* Only shapes that can be checked are read: a column equal to a scalar or `null`, `{ eq }`, `{ inq }`
|
|
16
|
+
* (or `in`), an array, `and` of those, and an `or` whose branches all constrain the same column. Anything
|
|
17
|
+
* else - an `or` over several columns, ranges, `like`, a nested path - makes
|
|
18
|
+
* the scope unverifiable, and the write is refused with its own message instead of being skipped.
|
|
19
|
+
*/
|
|
20
|
+
export declare class ScopeWriteGuard {
|
|
21
|
+
static extractConstraints(opts: {
|
|
22
|
+
where: TWhere;
|
|
23
|
+
}): TExtraction;
|
|
24
|
+
/** Adds the where's constraints to `constraints`; returns the reason it cannot be verified, if any. */
|
|
25
|
+
private static collect;
|
|
26
|
+
/**
|
|
27
|
+
* An `or` is checkable only when every branch constrains the same single column with a scalar,
|
|
28
|
+
* `null`, `eq`, `in` or `inq`: the allowed values are then the union of the branches. This is the
|
|
29
|
+
* shared-rows scope, `{ or: [{ merchantId: { in: ids } }, { merchantId: null }] }`. Any other `or`
|
|
30
|
+
* (several columns, ranges, nested `and` or `or`) cannot be checked.
|
|
31
|
+
*/
|
|
32
|
+
private static unionOfBranches;
|
|
33
|
+
/** The values one column's condition allows, or a string naming why it cannot be checked. */
|
|
34
|
+
private static allowedValues;
|
|
35
|
+
/**
|
|
36
|
+
* Holds `rows` to the scope `settings.resolve()` returns now. Returns the rows to write: the same
|
|
37
|
+
* objects when nothing changes, copies with the scope columns filled in for `assign`. Throws, and
|
|
38
|
+
* so writes nothing, when any row is outside the scope.
|
|
39
|
+
*/
|
|
40
|
+
static apply<Row extends Record<string, unknown>>(opts: {
|
|
41
|
+
settings: IModelAccessSettings;
|
|
42
|
+
model: string;
|
|
43
|
+
rows: Row[];
|
|
44
|
+
operation: 'create' | 'update';
|
|
45
|
+
}): Row[];
|
|
46
|
+
/** Names the model and the column, never a value: the caller may be a request. */
|
|
47
|
+
private static denied;
|
|
48
|
+
}
|
|
49
|
+
export {};
|
|
50
|
+
//# sourceMappingURL=scope-write-guard.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"scope-write-guard.d.ts","sourceRoot":"","sources":["../../../../../../src/relational/core/repositories/common/scope-write-guard.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,EAAE,MAAM,uBAAuB,CAAC;AAK1E,2GAA2G;AAC3G,KAAK,YAAY,GAAG,GAAG,CAAC,MAAM,EAAE,GAAG,CAAC,MAAM,GAAG,IAAI,CAAC,CAAC,CAAC;AAEpD,KAAK,WAAW,GACZ;IAAE,YAAY,EAAE,IAAI,CAAC;IAAC,WAAW,EAAE,YAAY,CAAA;CAAE,GACjD;IAAE,YAAY,EAAE,KAAK,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,CAAC;AAwB5C;;;;;;;;GAQG;AACH,qBAAa,eAAe;IAC1B,MAAM,CAAC,kBAAkB,CAAC,IAAI,EAAE;QAAE,KAAK,EAAE,MAAM,CAAA;KAAE,GAAG,WAAW;IAY/D,uGAAuG;IACvG,OAAO,CAAC,MAAM,CAAC,OAAO;IAuDtB;;;;;OAKG;IACH,OAAO,CAAC,MAAM,CAAC,eAAe;IAuC9B,6FAA6F;IAC7F,OAAO,CAAC,MAAM,CAAC,aAAa;IAyC5B;;;;OAIG;IACH,MAAM,CAAC,KAAK,CAAC,GAAG,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,IAAI,EAAE;QACtD,QAAQ,EAAE,oBAAoB,CAAC;QAC/B,KAAK,EAAE,MAAM,CAAC;QACd,IAAI,EAAE,GAAG,EAAE,CAAC;QACZ,SAAS,EAAE,QAAQ,GAAG,QAAQ,CAAC;KAChC,GAAG,GAAG,EAAE;IAkGT,kFAAkF;IAClF,OAAO,CAAC,MAAM,CAAC,MAAM;CAkBtB"}
|
|
@@ -0,0 +1,248 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ScopeWriteGuard = void 0;
|
|
4
|
+
const core_1 = require("@venizia/ignis-helpers/core");
|
|
5
|
+
const ignis_kernel_1 = require("@venizia/ignis-kernel");
|
|
6
|
+
const common_1 = require("@venizia/ignis-helpers/common");
|
|
7
|
+
const WRITE_DENIED_STATUS = common_1.HTTP.ResultCodes.RS_4.Forbidden;
|
|
8
|
+
const isScalar = (value) => {
|
|
9
|
+
return (value === null ||
|
|
10
|
+
value instanceof Date ||
|
|
11
|
+
['string', 'number', 'bigint', 'boolean'].includes(typeof value));
|
|
12
|
+
};
|
|
13
|
+
const normalise = (value) => {
|
|
14
|
+
if (value === null) {
|
|
15
|
+
return null;
|
|
16
|
+
}
|
|
17
|
+
return value instanceof Date ? value.toISOString() : String(value);
|
|
18
|
+
};
|
|
19
|
+
const intersect = (opts) => {
|
|
20
|
+
return new Set([...opts.left].filter((value) => opts.right.has(value)));
|
|
21
|
+
};
|
|
22
|
+
/**
|
|
23
|
+
* The write side of `@model` settings.access. The resolved scope is a `where`; the guard reads
|
|
24
|
+
* from it the columns it constrains and the values it allows, and holds every written row to them.
|
|
25
|
+
*
|
|
26
|
+
* Only shapes that can be checked are read: a column equal to a scalar or `null`, `{ eq }`, `{ inq }`
|
|
27
|
+
* (or `in`), an array, `and` of those, and an `or` whose branches all constrain the same column. Anything
|
|
28
|
+
* else - an `or` over several columns, ranges, `like`, a nested path - makes
|
|
29
|
+
* the scope unverifiable, and the write is refused with its own message instead of being skipped.
|
|
30
|
+
*/
|
|
31
|
+
class ScopeWriteGuard {
|
|
32
|
+
static extractConstraints(opts) {
|
|
33
|
+
const constraints = new Map();
|
|
34
|
+
const reason = ScopeWriteGuard.collect({
|
|
35
|
+
where: opts.where,
|
|
36
|
+
constraints,
|
|
37
|
+
});
|
|
38
|
+
return reason === undefined
|
|
39
|
+
? { isVerifiable: true, constraints }
|
|
40
|
+
: { isVerifiable: false, reason };
|
|
41
|
+
}
|
|
42
|
+
/** Adds the where's constraints to `constraints`; returns the reason it cannot be verified, if any. */
|
|
43
|
+
static collect(opts) {
|
|
44
|
+
const { where, constraints } = opts;
|
|
45
|
+
for (const [key, value] of Object.entries(where)) {
|
|
46
|
+
if (key === 'and') {
|
|
47
|
+
if (!Array.isArray(value)) {
|
|
48
|
+
return "'and' is not a list";
|
|
49
|
+
}
|
|
50
|
+
for (const part of value) {
|
|
51
|
+
const reason = ScopeWriteGuard.collect({
|
|
52
|
+
where: part,
|
|
53
|
+
constraints,
|
|
54
|
+
});
|
|
55
|
+
if (reason !== undefined) {
|
|
56
|
+
return reason;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
continue;
|
|
60
|
+
}
|
|
61
|
+
if (key === 'or') {
|
|
62
|
+
const union = ScopeWriteGuard.unionOfBranches({ branches: value });
|
|
63
|
+
if (typeof union === 'string') {
|
|
64
|
+
return union;
|
|
65
|
+
}
|
|
66
|
+
const existing = constraints.get(union.column);
|
|
67
|
+
constraints.set(union.column, existing ? intersect({ left: existing, right: union.allowed }) : union.allowed);
|
|
68
|
+
continue;
|
|
69
|
+
}
|
|
70
|
+
if (key.includes('.')) {
|
|
71
|
+
return `the nested path '${key}' cannot be checked on a write`;
|
|
72
|
+
}
|
|
73
|
+
const allowed = ScopeWriteGuard.allowedValues({ value });
|
|
74
|
+
if (typeof allowed === 'string') {
|
|
75
|
+
return `column '${key}': ${allowed}`;
|
|
76
|
+
}
|
|
77
|
+
const existing = constraints.get(key);
|
|
78
|
+
constraints.set(key, existing ? intersect({ left: existing, right: allowed }) : allowed);
|
|
79
|
+
}
|
|
80
|
+
return undefined;
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* An `or` is checkable only when every branch constrains the same single column with a scalar,
|
|
84
|
+
* `null`, `eq`, `in` or `inq`: the allowed values are then the union of the branches. This is the
|
|
85
|
+
* shared-rows scope, `{ or: [{ merchantId: { in: ids } }, { merchantId: null }] }`. Any other `or`
|
|
86
|
+
* (several columns, ranges, nested `and` or `or`) cannot be checked.
|
|
87
|
+
*/
|
|
88
|
+
static unionOfBranches(opts) {
|
|
89
|
+
const { branches } = opts;
|
|
90
|
+
if (!Array.isArray(branches) || branches.length === 0) {
|
|
91
|
+
return "'or' is not a list";
|
|
92
|
+
}
|
|
93
|
+
let column;
|
|
94
|
+
const allowed = new Set();
|
|
95
|
+
for (const branch of branches) {
|
|
96
|
+
const entries = Object.entries((branch ?? {}));
|
|
97
|
+
if (entries.length !== 1) {
|
|
98
|
+
return "an 'or' branch with several conditions cannot be checked on a write";
|
|
99
|
+
}
|
|
100
|
+
const [key, value] = entries[0];
|
|
101
|
+
if (key === 'and' || key === 'or' || key.includes('.')) {
|
|
102
|
+
return `an 'or' branch over '${key}' cannot be checked on a write`;
|
|
103
|
+
}
|
|
104
|
+
if (column !== undefined && column !== key) {
|
|
105
|
+
return "an 'or' over different columns cannot be checked on a write";
|
|
106
|
+
}
|
|
107
|
+
column = key;
|
|
108
|
+
const values = ScopeWriteGuard.allowedValues({ value });
|
|
109
|
+
if (typeof values === 'string') {
|
|
110
|
+
return `column '${key}': ${values}`;
|
|
111
|
+
}
|
|
112
|
+
values.forEach((entry) => allowed.add(entry));
|
|
113
|
+
}
|
|
114
|
+
return { column: column, allowed };
|
|
115
|
+
}
|
|
116
|
+
/** The values one column's condition allows, or a string naming why it cannot be checked. */
|
|
117
|
+
static allowedValues(opts) {
|
|
118
|
+
const { value } = opts;
|
|
119
|
+
if (isScalar(value)) {
|
|
120
|
+
return new Set([normalise(value)]);
|
|
121
|
+
}
|
|
122
|
+
if (Array.isArray(value)) {
|
|
123
|
+
return value.every(isScalar)
|
|
124
|
+
? new Set(value.map(normalise))
|
|
125
|
+
: 'a list with a non-scalar entry';
|
|
126
|
+
}
|
|
127
|
+
if (typeof value !== 'object' || value === undefined) {
|
|
128
|
+
return 'an unsupported condition';
|
|
129
|
+
}
|
|
130
|
+
const operators = Object.keys(value);
|
|
131
|
+
if (operators.length !== 1) {
|
|
132
|
+
return `a condition with ${operators.length} operators cannot be checked on a write`;
|
|
133
|
+
}
|
|
134
|
+
const [operator] = operators;
|
|
135
|
+
const operand = value[operator];
|
|
136
|
+
if (operator === ignis_kernel_1.QueryOperators.EQ && isScalar(operand)) {
|
|
137
|
+
return new Set([normalise(operand)]);
|
|
138
|
+
}
|
|
139
|
+
if ((operator === ignis_kernel_1.QueryOperators.INQ || operator === ignis_kernel_1.QueryOperators.IN) &&
|
|
140
|
+
Array.isArray(operand)) {
|
|
141
|
+
return operand.every(isScalar)
|
|
142
|
+
? new Set(operand.map(normalise))
|
|
143
|
+
: 'a list with a non-scalar entry';
|
|
144
|
+
}
|
|
145
|
+
return `the operator '${operator}' cannot be checked on a write`;
|
|
146
|
+
}
|
|
147
|
+
/**
|
|
148
|
+
* Holds `rows` to the scope `settings.resolve()` returns now. Returns the rows to write: the same
|
|
149
|
+
* objects when nothing changes, copies with the scope columns filled in for `assign`. Throws, and
|
|
150
|
+
* so writes nothing, when any row is outside the scope.
|
|
151
|
+
*/
|
|
152
|
+
static apply(opts) {
|
|
153
|
+
const { settings, model, rows, operation } = opts;
|
|
154
|
+
const scope = settings.resolve();
|
|
155
|
+
if (scope === ignis_kernel_1.ScopeFilters.UNRESTRICTED) {
|
|
156
|
+
return rows;
|
|
157
|
+
}
|
|
158
|
+
if (scope === null || scope === undefined) {
|
|
159
|
+
// An update is already confined by the scoped `where`, which under `deny` matches no row; the
|
|
160
|
+
// guard adds nothing there. A create has no such `where`, so an unresolved scope refuses it.
|
|
161
|
+
if (settings.onMissing === ignis_kernel_1.ScopeFilterMissingBehaviors.ALLOW || operation === 'update') {
|
|
162
|
+
return rows;
|
|
163
|
+
}
|
|
164
|
+
throw ScopeWriteGuard.denied({
|
|
165
|
+
model,
|
|
166
|
+
operation,
|
|
167
|
+
detail: 'no scope could be resolved for this caller',
|
|
168
|
+
});
|
|
169
|
+
}
|
|
170
|
+
const extraction = ScopeWriteGuard.extractConstraints({ where: scope });
|
|
171
|
+
if (!extraction.isVerifiable) {
|
|
172
|
+
throw ScopeWriteGuard.denied({
|
|
173
|
+
model,
|
|
174
|
+
operation,
|
|
175
|
+
detail: `the resolved scope cannot be verified on a write | ${extraction.reason}`,
|
|
176
|
+
});
|
|
177
|
+
}
|
|
178
|
+
const { constraints } = extraction;
|
|
179
|
+
const declared = settings.columns;
|
|
180
|
+
if (declared) {
|
|
181
|
+
const undeclared = [...constraints.keys()].find((column) => !declared.includes(column));
|
|
182
|
+
if (undeclared !== undefined) {
|
|
183
|
+
throw ScopeWriteGuard.denied({
|
|
184
|
+
model,
|
|
185
|
+
operation,
|
|
186
|
+
detail: `the resolved scope constrains column '${undeclared}', which access.columns does not declare`,
|
|
187
|
+
});
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
const isAssign = settings.write?.mode === ignis_kernel_1.ScopeWriteGuards.ASSIGN && operation === 'create';
|
|
191
|
+
const sharedRows = settings.write?.sharedRows === true;
|
|
192
|
+
return rows.map((row) => {
|
|
193
|
+
let result = row;
|
|
194
|
+
for (const [column, allowed] of constraints) {
|
|
195
|
+
const value = row[column];
|
|
196
|
+
if (value === undefined) {
|
|
197
|
+
if (operation === 'update') {
|
|
198
|
+
continue;
|
|
199
|
+
}
|
|
200
|
+
// `assign` first: stamping gives the row an owner, which is safer than leaving it shared.
|
|
201
|
+
const only = allowed.size === 1 ? [...allowed][0] : undefined;
|
|
202
|
+
if (isAssign && only !== undefined && only !== null) {
|
|
203
|
+
result = { ...result, [column]: only };
|
|
204
|
+
continue;
|
|
205
|
+
}
|
|
206
|
+
// Absent means the database default, usually `null`, so it is held to the `null` rule.
|
|
207
|
+
if (sharedRows) {
|
|
208
|
+
continue;
|
|
209
|
+
}
|
|
210
|
+
throw ScopeWriteGuard.denied({
|
|
211
|
+
model,
|
|
212
|
+
operation,
|
|
213
|
+
column,
|
|
214
|
+
detail: 'the scope column is missing',
|
|
215
|
+
});
|
|
216
|
+
}
|
|
217
|
+
const normalised = isScalar(value) ? normalise(value) : undefined;
|
|
218
|
+
// A `null` branch in the scope lets this caller READ shared rows. Writing one (or moving a
|
|
219
|
+
// row into the shared set) is a separate permission: only `sharedRows` grants it.
|
|
220
|
+
const isOutside = normalised === null ? !sharedRows : !allowed.has(normalised);
|
|
221
|
+
if (normalised === undefined || isOutside) {
|
|
222
|
+
throw ScopeWriteGuard.denied({
|
|
223
|
+
model,
|
|
224
|
+
operation,
|
|
225
|
+
column,
|
|
226
|
+
detail: 'the value is outside the resolved scope',
|
|
227
|
+
});
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
return result;
|
|
231
|
+
});
|
|
232
|
+
}
|
|
233
|
+
/** Names the model and the column, never a value: the caller may be a request. */
|
|
234
|
+
static denied(opts) {
|
|
235
|
+
const { model, operation, column, detail } = opts;
|
|
236
|
+
return (0, core_1.getError)({
|
|
237
|
+
statusCode: WRITE_DENIED_STATUS,
|
|
238
|
+
messageCode: ignis_kernel_1.RepositoryErrorCodes.SCOPE_WRITE_DENIED,
|
|
239
|
+
message: [
|
|
240
|
+
`[${operation}] write refused by the access scope | entity: ${model}`,
|
|
241
|
+
...(column ? [`column: ${column}`] : []),
|
|
242
|
+
detail,
|
|
243
|
+
].join(' | '),
|
|
244
|
+
});
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
exports.ScopeWriteGuard = ScopeWriteGuard;
|
|
248
|
+
//# 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.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AAU,KAAK,SAAS,IAAI,SAAS,EAAE,CAAC;oBAC1C,MAAM,eAAe,CAAC,MAAM,CAAC;wBAC3B,KAAK;wBACL,SAAS;wBACT,MAAM;wBACN,MAAM,EAAE,yCAAyC;qBAClD,CAAC,CAAC;gBACL,CAAC;YACH,CAAC;YAED,OAAO,MAAM,CAAC;QAChB,CAAC,CAAC,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,IAAA,eAAQ,EAAC;YACd,UAAU,EAAE,mBAAmB;YAC/B,WAAW,EAAE,mCAAoB,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;AA3RD,0CA2RC","sourcesContent":["import { 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';\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\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 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 * 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: 'create' | 'update';\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 (settings.onMissing === ScopeFilterMissingBehaviors.ALLOW || operation === 'update') {\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,4 @@
|
|
|
1
|
-
import type { IdType, IExtraOptions, IPersistableRepository,
|
|
1
|
+
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
2
|
import { AbstractRepository } from '@venizia/ignis-kernel';
|
|
3
3
|
import type { IRelationalDataSource } from '../../datasources/common';
|
|
4
4
|
import type { BaseRelationalEntity, TTableInsert, TTableObject, TTableSchemaWithId } from '../../models';
|
|
@@ -45,10 +45,25 @@ export declare abstract class RelationalBaseRepository<EntitySchema extends TTab
|
|
|
45
45
|
getDefaultFilter(): TFilter | undefined;
|
|
46
46
|
getDefaultLimit(): number | undefined;
|
|
47
47
|
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
48
|
/**
|
|
51
|
-
*
|
|
49
|
+
* The model's `access` settings. Same override seam as `getDefaultFilter()` - a repository with no
|
|
50
|
+
* resolvable `@model` entity (a synthetic test double, a hand-built stub) overrides this to avoid
|
|
51
|
+
* touching `modelSettings`/`entity` at all. The name is kept from before `scopeFilter` became
|
|
52
|
+
* `access`, so an existing override keeps working.
|
|
53
|
+
*/
|
|
54
|
+
getScopeFilterSettings(): 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: 'create' | 'update';
|
|
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
|
*
|
|
@@ -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,wBAAwB,EACxB,sBAAsB,EACtB,wBAAwB,EACxB,+BAA+B,EAChC,MAAM,WAAW,CAAC;
|
|
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,YAA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Y,GAAG;YAAE,YAAY,EAAE,KAAK,CAAC;YAAC,KAAK,CAAC,EAAE,OAAO,CAAA;SAAE,CAAC;KAClE,GAAG,OAAO,CAAC,MAAM,GAAG;QAAE,IAAI,EAAE,SAAS,GAAG,IAAI,CAAA;KAAE,CAAC;IACvC,QAAQ,CAAC,CAAC,GAAG,UAAU,EAAE,IAAI,EAAE;QACtC,KAAK,CAAC,EAAE,MAAM,CAAC,UAAU,CAAC,CAAC;QAC3B,OAAO,CAAC,EAAE,YAAY,GAAG;YAAE,YAAY,CAAC,EAAE,IAAI,CAAC;YAAC,KAAK,CAAC,EAAE,OAAO,CAAA;SAAE,CAAC;KACnE,GAAG,OAAO,CAAC,MAAM,GAAG;QAAE,IAAI,EAAE,KAAK,CAAC,CAAC,CAAC,CAAA;KAAE,CAAC;CAazC"}
|
|
@@ -7,6 +7,7 @@ const transaction_state_1 = require("../../datasources/transaction-state");
|
|
|
7
7
|
const core_1 = require("@venizia/ignis-helpers/core");
|
|
8
8
|
const drizzle_orm_1 = require("drizzle-orm");
|
|
9
9
|
const common_2 = require("../common");
|
|
10
|
+
const scope_write_guard_1 = require("../common/scope-write-guard");
|
|
10
11
|
/** 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. */
|
|
11
12
|
class RelationalBaseRepository extends ignis_kernel_1.AbstractRepository {
|
|
12
13
|
/**
|
|
@@ -83,7 +84,7 @@ class RelationalBaseRepository extends ignis_kernel_1.AbstractRepository {
|
|
|
83
84
|
return this._visibleColumns;
|
|
84
85
|
}
|
|
85
86
|
getDefaultFilter() {
|
|
86
|
-
return this.modelSettings?.
|
|
87
|
+
return this.modelSettings?.query?.filter;
|
|
87
88
|
}
|
|
88
89
|
getDefaultLimit() {
|
|
89
90
|
return this.defaultLimit;
|
|
@@ -92,12 +93,35 @@ class RelationalBaseRepository extends ignis_kernel_1.AbstractRepository {
|
|
|
92
93
|
const defaultFilter = this.getDefaultFilter();
|
|
93
94
|
return defaultFilter !== undefined && Object.keys(defaultFilter).length > 0;
|
|
94
95
|
}
|
|
95
|
-
/**
|
|
96
|
+
/**
|
|
97
|
+
* The model's `access` settings. Same override seam as `getDefaultFilter()` - a repository with no
|
|
98
|
+
* resolvable `@model` entity (a synthetic test double, a hand-built stub) overrides this to avoid
|
|
99
|
+
* touching `modelSettings`/`entity` at all. The name is kept from before `scopeFilter` became
|
|
100
|
+
* `access`, so an existing override keeps working.
|
|
101
|
+
*/
|
|
96
102
|
getScopeFilterSettings() {
|
|
97
|
-
return this.modelSettings?.
|
|
103
|
+
return this.modelSettings?.access;
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* Holds written rows to the resolved row scope (`access.write`): refuses a row outside
|
|
107
|
+
* it, and for `assign` returns copies with the scope columns filled in. Nothing is written when it
|
|
108
|
+
* throws. Like the read scope, it is not skippable by `shouldSkipDefaultFilter`; a caller that is
|
|
109
|
+
* trusted to write across scopes resolves to `ScopeFilters.UNRESTRICTED`.
|
|
110
|
+
*/
|
|
111
|
+
guardScopedWrite(opts) {
|
|
112
|
+
const settings = this.getScopeFilterSettings();
|
|
113
|
+
if (!settings) {
|
|
114
|
+
return opts.rows;
|
|
115
|
+
}
|
|
116
|
+
return scope_write_guard_1.ScopeWriteGuard.apply({
|
|
117
|
+
settings,
|
|
118
|
+
model: this.entity.name,
|
|
119
|
+
rows: opts.rows,
|
|
120
|
+
operation: opts.operation,
|
|
121
|
+
});
|
|
98
122
|
}
|
|
99
123
|
/**
|
|
100
|
-
* Row scope from `@model` settings.
|
|
124
|
+
* Row scope from `@model` settings.access - AND-composed like a default filter, but never
|
|
101
125
|
* skippable via `shouldSkipDefaultFilter`: that flag serves `restore()`'s deliberate reach past
|
|
102
126
|
* soft-delete, which must not also reach past tenant/ownership scoping.
|
|
103
127
|
*
|