@docupace/ihub-config 1.1.24 → 1.1.25-admin.1
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/config-extension.d.ts +58 -0
- package/dist/config-extension.d.ts.map +1 -1
- package/dist/config-extension.js +2 -0
- package/dist/config-extension.js.map +1 -1
- package/dist/config-service.d.ts +14 -4
- package/dist/config-service.d.ts.map +1 -1
- package/dist/config-service.js +431 -22
- package/dist/config-service.js.map +1 -1
- package/dist/mappers/config-mapper.d.ts.map +1 -1
- package/dist/mappers/config-mapper.js +1 -0
- package/dist/mappers/config-mapper.js.map +1 -1
- package/dist/model/graphs/config/fields.graphql +30 -0
- package/dist/model/graphs/config/menu.graphql +6 -0
- package/dist/model/graphs/config/page.graphql +8 -1
- package/dist/model/graphs/config/query.graphql +10 -1
- package/dist/model/graphs/config/selectOptions.graphql +1 -0
- package/dist/model/graphs/config/table.graphql +26 -0
- package/dist/types/graphql.d.ts +45 -15
- package/dist/types/graphql.d.ts.map +1 -1
- package/dist/types/graphql.js.map +1 -1
- package/model/graphs/config/fields.graphql +30 -0
- package/model/graphs/config/menu.graphql +6 -0
- package/model/graphs/config/page.graphql +8 -1
- package/model/graphs/config/query.graphql +10 -1
- package/model/graphs/config/selectOptions.graphql +1 -0
- package/model/graphs/config/table.graphql +26 -0
- package/package.json +5 -3
package/dist/config-service.js
CHANGED
|
@@ -11,8 +11,298 @@ import { builtInProviders } from './providers/index.js';
|
|
|
11
11
|
import { deepMergeResolvers, } from './resolvers/index.js';
|
|
12
12
|
import { dump, load } from 'js-yaml';
|
|
13
13
|
import { buildQuery } from '@docupace/ihub-core/query';
|
|
14
|
+
import jp from 'jsonpath';
|
|
14
15
|
const FULL_OBJECT_EXPRESSION_PATTERN = /^\${(.*?)}$/;
|
|
15
16
|
const INLINE_OBJECT_EXPRESSION_PATTERN = /\${(.*?)}/g;
|
|
17
|
+
function isNamedObjectArray(value) {
|
|
18
|
+
return (Array.isArray(value) &&
|
|
19
|
+
value.every((item) => item !== null &&
|
|
20
|
+
typeof item === 'object' &&
|
|
21
|
+
typeof item.name === 'string'));
|
|
22
|
+
}
|
|
23
|
+
// An override element counts as "self-contained" when it carries enough of
|
|
24
|
+
// its own definition to render on its own — a real attribute path (or paths)
|
|
25
|
+
// or a computed expression — as opposed to a thin `{ name, visible }`-style
|
|
26
|
+
// reference that only makes sense resolved against a base/predefined
|
|
27
|
+
// counterpart of the same name. `paths` (plural) is `Column`'s shape;
|
|
28
|
+
// `path` (singular) is `TableCriteria`'s — both must count, or a resolved
|
|
29
|
+
// filter-criterion `$ref` (which only ever has a singular `path`) is wrongly
|
|
30
|
+
// treated as a dangling reference and silently dropped, even though it just
|
|
31
|
+
// resolved successfully.
|
|
32
|
+
function isSelfContainedOverrideElement(item) {
|
|
33
|
+
const paths = item.paths;
|
|
34
|
+
return ((Array.isArray(paths) && paths.length > 0) ||
|
|
35
|
+
(typeof item.path === 'string' && item.path.length > 0) ||
|
|
36
|
+
(typeof item.expression === 'string' && item.expression.length > 0));
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Merge semantics for a config sub-path override against the value already
|
|
40
|
+
* at that JSONPath. Generic — used for any typename/sub-path the
|
|
41
|
+
* configPath/subPath mechanism resolves, not just `Table.columns`.
|
|
42
|
+
*
|
|
43
|
+
* When both the current value and the override value are arrays of objects
|
|
44
|
+
* each carrying a string `name`, override elements are merged onto their
|
|
45
|
+
* base counterpart by name (override wins per-attribute, everything else
|
|
46
|
+
* inherited) instead of the override replacing the array wholesale. This is
|
|
47
|
+
* what makes a saved override non-destructive:
|
|
48
|
+
* - Reordering falls out of the override array's own element order.
|
|
49
|
+
* - "Hiding" an element is an attribute override (e.g. `visible: false`) on
|
|
50
|
+
* an element that's still present, not a deletion.
|
|
51
|
+
* - A base element the override never mentions is appended unchanged, so a
|
|
52
|
+
* base element added later still surfaces for someone with an existing
|
|
53
|
+
* override, instead of being permanently absent from their frozen array.
|
|
54
|
+
* - An override element naming something not found in the base is kept
|
|
55
|
+
* as-is when it's self-contained (has its own path(s)/expression — e.g. a
|
|
56
|
+
* hand-authored column), or silently dropped when it's a thin reference
|
|
57
|
+
* whose target (e.g. a predefined column) no longer exists — this never
|
|
58
|
+
* throws; the stale reference just doesn't round-trip into the next save.
|
|
59
|
+
*
|
|
60
|
+
* Any other shape (scalars, plain objects, arrays without a `name` key) is
|
|
61
|
+
* returned untouched, so the caller's plain whole-value replace applies
|
|
62
|
+
* exactly as it did before this merge existed.
|
|
63
|
+
*/
|
|
64
|
+
function mergeSubPathOverrideValue(base, override) {
|
|
65
|
+
if (!isNamedObjectArray(override) || !isNamedObjectArray(base)) {
|
|
66
|
+
return override;
|
|
67
|
+
}
|
|
68
|
+
const baseByName = new Map(base.map((item) => [item.name, item]));
|
|
69
|
+
const merged = [];
|
|
70
|
+
const seenNames = new Set();
|
|
71
|
+
for (const overrideItem of override) {
|
|
72
|
+
// Guard against a corrupted/hand-edited override array carrying two
|
|
73
|
+
// elements with the same name — only the first is kept, so the merged
|
|
74
|
+
// result never has duplicate names.
|
|
75
|
+
if (seenNames.has(overrideItem.name)) {
|
|
76
|
+
continue;
|
|
77
|
+
}
|
|
78
|
+
seenNames.add(overrideItem.name);
|
|
79
|
+
const baseItem = baseByName.get(overrideItem.name);
|
|
80
|
+
if (baseItem) {
|
|
81
|
+
merged.push({ ...baseItem, ...overrideItem });
|
|
82
|
+
}
|
|
83
|
+
else if (isSelfContainedOverrideElement(overrideItem)) {
|
|
84
|
+
merged.push(overrideItem);
|
|
85
|
+
}
|
|
86
|
+
// else: a thin reference to a name that no longer resolves — drop it.
|
|
87
|
+
}
|
|
88
|
+
const mergedNames = new Set(merged.map((item) => item.name));
|
|
89
|
+
const untouchedBaseItems = base.filter((item) => !mergedNames.has(item.name));
|
|
90
|
+
return [...merged, ...untouchedBaseItems];
|
|
91
|
+
}
|
|
92
|
+
// Marks each element of a fully-folded named-object array with whether it
|
|
93
|
+
// would still show up — present *and* not hidden — without the layer stored
|
|
94
|
+
// at the identity's own scope tier (`withoutOwnScope`, the same
|
|
95
|
+
// broadest-to-narrowest fold as `mergedValue` minus that one layer; see
|
|
96
|
+
// `applyConfigPathOverride`, where both folds are computed).
|
|
97
|
+
//
|
|
98
|
+
// This drives two decisions in the editing client, both about what its own
|
|
99
|
+
// scope's override has to say explicitly to get the effect the user asked
|
|
100
|
+
// for:
|
|
101
|
+
// - Removing an entry: `inherited` means hiding it (`visible: false`) is
|
|
102
|
+
// required, since deleting it from this scope's override would just have
|
|
103
|
+
// the next resolution fold bring it back from a broader layer. Not
|
|
104
|
+
// inherited means a plain delete suffices.
|
|
105
|
+
// - Adding/re-showing an entry: not inherited means the client must pin
|
|
106
|
+
// `visible: true` on it, since the broader fold either doesn't have it at
|
|
107
|
+
// all or has it hidden — and per-attribute merge semantics would otherwise
|
|
108
|
+
// inherit that `visible: false` straight through this scope's own
|
|
109
|
+
// override, leaving the entry invisible no matter how it's re-added.
|
|
110
|
+
// Hidden-ness is folded into `inherited` (rather than reported as a separate
|
|
111
|
+
// flag) precisely because both decisions only ever care whether the entry
|
|
112
|
+
// would be *there*, and a broader-hidden entry is exactly as absent from the
|
|
113
|
+
// user's view as a missing one.
|
|
114
|
+
//
|
|
115
|
+
// Only stamps when both values are named-object arrays; any other shape
|
|
116
|
+
// (scalar, plain object, unnamed array) is returned unchanged, mirroring
|
|
117
|
+
// `mergeSubPathOverrideValue`'s own shape guard.
|
|
118
|
+
function stampInherited(mergedValue, withoutOwnScope) {
|
|
119
|
+
if (!isNamedObjectArray(mergedValue) ||
|
|
120
|
+
!isNamedObjectArray(withoutOwnScope)) {
|
|
121
|
+
return mergedValue;
|
|
122
|
+
}
|
|
123
|
+
const inheritedByName = new Map(withoutOwnScope.map((item) => [item.name, item]));
|
|
124
|
+
return mergedValue.map((item) => {
|
|
125
|
+
const counterpart = inheritedByName.get(item.name);
|
|
126
|
+
return {
|
|
127
|
+
...item,
|
|
128
|
+
inherited: !!counterpart && counterpart.visible !== false,
|
|
129
|
+
};
|
|
130
|
+
});
|
|
131
|
+
}
|
|
132
|
+
function isRefElement(item) {
|
|
133
|
+
return (item !== null &&
|
|
134
|
+
typeof item === 'object' &&
|
|
135
|
+
typeof item.$ref === 'string');
|
|
136
|
+
}
|
|
137
|
+
// Resolves a config-path override array element's fragment-only `$ref`
|
|
138
|
+
// (e.g. `"#$.predefinedColumns[?(@.name=='email')]"`) against `refRoot` —
|
|
139
|
+
// the config-path's own sibling fields, not another file. This is
|
|
140
|
+
// deliberately narrower than `template`'s YAML `$ref` (processed by
|
|
141
|
+
// `processReferencedObject`/`getRefConfig`, which loads another config
|
|
142
|
+
// file): an override-array `$ref` only ever supports the `#<jsonpath>`
|
|
143
|
+
// self-reference form, resolved with the already-vendored `jsonpath`
|
|
144
|
+
// package (the same one `applyConfigPathOverride` uses for `subPath`
|
|
145
|
+
// strings). A ref that doesn't start with `#`, resolves to nothing, or
|
|
146
|
+
// resolves to a non-object is treated the same as any other unresolved
|
|
147
|
+
// override reference elsewhere in this module — silently dropped rather
|
|
148
|
+
// than thrown, so a stale reference just doesn't round-trip into the next
|
|
149
|
+
// save. Multiple matches take the first, in JSONPath document order.
|
|
150
|
+
//
|
|
151
|
+
// The resolved object keeps the original fragment string under `ref` (not
|
|
152
|
+
// `$ref` — GraphQL field names can't start with `$`) rather than dropping
|
|
153
|
+
// it once resolved. Without this, a client re-saving the array unchanged
|
|
154
|
+
// (e.g. reordering a different column) would have no way to tell this
|
|
155
|
+
// element apart from a plain inline column and would flatten it back into
|
|
156
|
+
// a frozen copy on that save — exactly the staleness problem `$ref` exists
|
|
157
|
+
// to avoid. `Column.ref` (the GraphQL field) surfaces it back to the client
|
|
158
|
+
// so `docupace-ui-main` can keep re-emitting the same `$ref` indefinitely.
|
|
159
|
+
function resolveOverrideElementRef(item, refRoot) {
|
|
160
|
+
const ref = item.$ref;
|
|
161
|
+
if (!ref.startsWith('#')) {
|
|
162
|
+
return undefined;
|
|
163
|
+
}
|
|
164
|
+
const [match] = jp.query(refRoot, ref.slice(1));
|
|
165
|
+
if (match === null || typeof match !== 'object') {
|
|
166
|
+
return undefined;
|
|
167
|
+
}
|
|
168
|
+
const { $ref: _unusedRef, ...localOverrides } = item;
|
|
169
|
+
return {
|
|
170
|
+
...match,
|
|
171
|
+
...localOverrides,
|
|
172
|
+
ref,
|
|
173
|
+
};
|
|
174
|
+
}
|
|
175
|
+
// Expands any `$ref` elements of a config-path override array into the
|
|
176
|
+
// full object they point at (merged with whatever local attributes the
|
|
177
|
+
// element carries alongside `$ref`, e.g. `visible`) before the array is
|
|
178
|
+
// handed to `mergeSubPathOverrideValue`. Runs first so that a `{ $ref,
|
|
179
|
+
// visible }` stub — which has no `name` of its own — always arrives at the
|
|
180
|
+
// name-keyed merge as a proper named object; `mergeSubPathOverrideValue`
|
|
181
|
+
// itself needs no `$ref` awareness.
|
|
182
|
+
function expandRefOverrideElements(value, refRoot) {
|
|
183
|
+
if (!Array.isArray(value)) {
|
|
184
|
+
return value;
|
|
185
|
+
}
|
|
186
|
+
return value
|
|
187
|
+
.map((item) => isRefElement(item) ? resolveOverrideElementRef(item, refRoot) : item)
|
|
188
|
+
.filter((item) => item !== undefined);
|
|
189
|
+
}
|
|
190
|
+
// Builds the object a config-path override's `$ref` fragments resolve
|
|
191
|
+
// against: the config being overridden, overlaid with the *raw* (not yet
|
|
192
|
+
// merged) override value of every other simple top-level subPath in this
|
|
193
|
+
// same patch (e.g. `$.predefinedColumns`). Using the raw override value
|
|
194
|
+
// rather than depending on loop order elsewhere in
|
|
195
|
+
// `applyConfigPathOverride` means a `$.columns` override's `$ref` into
|
|
196
|
+
// `$.predefinedColumns` resolves correctly regardless of which subPath
|
|
197
|
+
// happens to be processed first. Only single-segment paths (`$.foo`) are
|
|
198
|
+
// overlaid — nested subPaths (`$.filter.criteria`) fall back to whatever
|
|
199
|
+
// value is already on `config`, which is fine since nothing currently
|
|
200
|
+
// needs to `$ref` into a nested subPath.
|
|
201
|
+
//
|
|
202
|
+
// `subPathPatch` (the `all` half of `SubPathOverrideLayers`) carries an
|
|
203
|
+
// *ordered* array of layers per jsonPath
|
|
204
|
+
// (broadest to narrowest — see `ConfigurationOverrideResult.subPaths`), not
|
|
205
|
+
// a single already-resolved value. The overlay uses only the narrowest
|
|
206
|
+
// (last) layer, same approximation as before cascading existed: a catalog
|
|
207
|
+
// like `$.predefinedColumns`/`$.predefinedFilters` is always saved as a full
|
|
208
|
+
// replacement at a single scope in practice (never a partial patch spread
|
|
209
|
+
// across tiers), so the narrowest present layer already *is* effectively
|
|
210
|
+
// the whole value — exactly what this overlay used before this function
|
|
211
|
+
// took an array at all.
|
|
212
|
+
function buildRefResolutionRoot(config, subPathPatch) {
|
|
213
|
+
const overlay = {};
|
|
214
|
+
for (const [jsonPath, layers] of Object.entries(subPathPatch)) {
|
|
215
|
+
const topLevelMatch = /^\$\.([^.[]+)$/.exec(jsonPath);
|
|
216
|
+
if (topLevelMatch && layers.length) {
|
|
217
|
+
overlay[topLevelMatch[1]] = layers[layers.length - 1];
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
return { ...config, ...overlay };
|
|
221
|
+
}
|
|
222
|
+
// Normalizes a provider's resolve() result into the pair of folds
|
|
223
|
+
// `applyConfigPathOverride` works with. `inherited` stays `null` (rather
|
|
224
|
+
// than defaulting to `{}`) when the provider doesn't report it, so the
|
|
225
|
+
// fallback there stays distinguishable from "reported, but this path has no
|
|
226
|
+
// broader layer".
|
|
227
|
+
function toSubPathOverrideLayers(override) {
|
|
228
|
+
if (!override.subPaths) {
|
|
229
|
+
return null;
|
|
230
|
+
}
|
|
231
|
+
return {
|
|
232
|
+
all: override.subPaths,
|
|
233
|
+
inherited: override.inheritedSubPaths ?? null,
|
|
234
|
+
};
|
|
235
|
+
}
|
|
236
|
+
// Folds one jsonPath's override layers onto the value currently at that
|
|
237
|
+
// location in `target`, and writes the result back in place.
|
|
238
|
+
//
|
|
239
|
+
// `layers` is ordered broadest to narrowest (general, tenant, role, user —
|
|
240
|
+
// see `ConfigurationOverrideResult.subPaths`), so folding them in order onto
|
|
241
|
+
// the current value cascades correctly: each layer only patches what it
|
|
242
|
+
// mentions, inheriting everything else from the fold so far.
|
|
243
|
+
//
|
|
244
|
+
// `inherited` drives the second fold — the same one minus the identity's
|
|
245
|
+
// own-scope layer, i.e. "what this identity would see with no override of
|
|
246
|
+
// its own", which is what `inherited` is stamped against. The provider
|
|
247
|
+
// reports those layers explicitly (`inheritedSubPaths`) because the tier a
|
|
248
|
+
// layer is stored at isn't recoverable from the values alone; dropping the
|
|
249
|
+
// last layer is only a fallback for a provider that doesn't, and is wrong
|
|
250
|
+
// whenever the identity has no row of its own yet (the layer dropped is then
|
|
251
|
+
// a broader one that very much still applies).
|
|
252
|
+
//
|
|
253
|
+
// Throws when `jsonPath` doesn't resolve to a settable location; the caller
|
|
254
|
+
// decides what to do with that.
|
|
255
|
+
function applySubPathOverrideLayers(target, jsonPath, layers, inherited, refRoot) {
|
|
256
|
+
const currentValue = jp.value(target, jsonPath);
|
|
257
|
+
const mergedValue = layers
|
|
258
|
+
.map((layer) => expandRefOverrideElements(layer, refRoot))
|
|
259
|
+
.reduce((base, override) => mergeSubPathOverrideValue(base, override), currentValue);
|
|
260
|
+
const inheritedLayers = inherited
|
|
261
|
+
? (inherited[jsonPath] ?? [])
|
|
262
|
+
: layers.slice(0, -1);
|
|
263
|
+
const withoutOwnScope = inheritedLayers
|
|
264
|
+
.map((layer) => expandRefOverrideElements(layer, refRoot))
|
|
265
|
+
.reduce((base, override) => mergeSubPathOverrideValue(base, override), currentValue);
|
|
266
|
+
const finalValue = stampInherited(mergedValue, withoutOwnScope);
|
|
267
|
+
const applied = jp.value(target, jsonPath, finalValue);
|
|
268
|
+
if (applied === undefined) {
|
|
269
|
+
throw new Error(`does not resolve to a settable location: "${jsonPath}"`);
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
// Deep-sets every stored sub-path override of `subPathPatch` onto a clone of
|
|
273
|
+
// `config`, returning the clone. `config` itself is never mutated.
|
|
274
|
+
function applySubPathOverrides(config, subPathPatch) {
|
|
275
|
+
// Built from the pre-clone config on purpose: `$ref` fragments resolve
|
|
276
|
+
// against the config as it was handed in, not against whatever earlier
|
|
277
|
+
// jsonPaths in this same loop have already written.
|
|
278
|
+
const refRoot = buildRefResolutionRoot(config, subPathPatch.all);
|
|
279
|
+
// Deep-clone once, up front — `jp.value` mutates its target in place, and
|
|
280
|
+
// a shallow `{ ...config }` per jsonPath only protects the top level. A
|
|
281
|
+
// nested subPath (e.g. `$.filter.criteria`) would otherwise still mutate
|
|
282
|
+
// `config.filter`, which is the *same* object reference as the original,
|
|
283
|
+
// potentially-shared config (e.g. reused across tables via
|
|
284
|
+
// `extend`/fragment composition). Config values are always plain JSON
|
|
285
|
+
// (from YAML/domain storage), so a JSON round-trip clone is sufficient and
|
|
286
|
+
// avoids `structuredClone`'s cross-realm `instanceof` pitfalls (its output
|
|
287
|
+
// fails `instanceof Object` checks — e.g. inside the `jsonpath` package —
|
|
288
|
+
// when the calling code runs in a different VM realm/context, as test
|
|
289
|
+
// sandboxes commonly do).
|
|
290
|
+
const result = JSON.parse(JSON.stringify(config));
|
|
291
|
+
for (const [jsonPath, layers] of Object.entries(subPathPatch.all)) {
|
|
292
|
+
// A single malformed override (an unparseable `$ref` JSONPath, or a
|
|
293
|
+
// jsonPath that doesn't resolve to a settable location) must not abort
|
|
294
|
+
// resolution of the rest of this config tree — that would take down the
|
|
295
|
+
// page for every user over one bad admin-authored row. Log and skip just
|
|
296
|
+
// this jsonPath instead.
|
|
297
|
+
try {
|
|
298
|
+
applySubPathOverrideLayers(result, jsonPath, layers, subPathPatch.inherited, refRoot);
|
|
299
|
+
}
|
|
300
|
+
catch (error) {
|
|
301
|
+
log.warn(`Skipping configuration override for "${result.configPath}" at "${jsonPath}": ${error.message}`);
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
return result;
|
|
305
|
+
}
|
|
16
306
|
export class ConfigFileStore {
|
|
17
307
|
localPath;
|
|
18
308
|
remotePath;
|
|
@@ -155,6 +445,7 @@ class ConfigService {
|
|
|
155
445
|
configInjectorResolvers;
|
|
156
446
|
providers;
|
|
157
447
|
resolvers;
|
|
448
|
+
configurationOverrideProvider;
|
|
158
449
|
constructor(model, configStores, extensionOptions = {}) {
|
|
159
450
|
this.configStores = configStores;
|
|
160
451
|
this.model = model;
|
|
@@ -167,6 +458,8 @@ class ConfigService {
|
|
|
167
458
|
this.resolvers = extensionOptions.resolvers
|
|
168
459
|
? { ...extensionOptions.resolvers }
|
|
169
460
|
: {};
|
|
461
|
+
this.configurationOverrideProvider =
|
|
462
|
+
extensionOptions.configurationOverrideProvider;
|
|
170
463
|
if (this.model) {
|
|
171
464
|
this.generateResolvers();
|
|
172
465
|
}
|
|
@@ -232,12 +525,34 @@ class ConfigService {
|
|
|
232
525
|
}
|
|
233
526
|
return processedData;
|
|
234
527
|
}
|
|
528
|
+
applyReferenceExtensions(processedData, referenceConfig) {
|
|
529
|
+
if (typeof referenceConfig?.extend !== 'object') {
|
|
530
|
+
return processedData;
|
|
531
|
+
}
|
|
532
|
+
const { extend } = referenceConfig;
|
|
533
|
+
for (const key in extend) {
|
|
534
|
+
const extensionValue = extend[key];
|
|
535
|
+
if (!Array.isArray(extensionValue)) {
|
|
536
|
+
throw new GraphQLError(`$ref.extend.${key} must be an array; received ${typeof extensionValue}`);
|
|
537
|
+
}
|
|
538
|
+
const baseValue = processedData[key];
|
|
539
|
+
if (baseValue === undefined) {
|
|
540
|
+
processedData[key] = extensionValue;
|
|
541
|
+
continue;
|
|
542
|
+
}
|
|
543
|
+
if (!Array.isArray(baseValue)) {
|
|
544
|
+
throw new GraphQLError(`$ref.extend.${key} can only extend an array property; "${key}" resolved to ${typeof baseValue}`);
|
|
545
|
+
}
|
|
546
|
+
processedData[key] = [...baseValue, ...extensionValue];
|
|
547
|
+
}
|
|
548
|
+
return processedData;
|
|
549
|
+
}
|
|
235
550
|
async processReferencedObject(configPath, obj, context, values) {
|
|
236
551
|
const referenceConfig = obj.$ref;
|
|
237
552
|
const refConfigPath = typeof referenceConfig === 'object' && referenceConfig.refPath
|
|
238
553
|
? referenceConfig.refPath
|
|
239
554
|
: referenceConfig;
|
|
240
|
-
const imageData = await this.processImageReference(refConfigPath);
|
|
555
|
+
const imageData = await this.processImageReference(refConfigPath, context);
|
|
241
556
|
if (imageData) {
|
|
242
557
|
return imageData;
|
|
243
558
|
}
|
|
@@ -246,6 +561,7 @@ class ConfigService {
|
|
|
246
561
|
? this.updatePathValues(referencedData, referenceConfig.path)
|
|
247
562
|
: referencedData;
|
|
248
563
|
processedData = this.applyReferenceOverrides(processedData, referenceConfig);
|
|
564
|
+
processedData = this.applyReferenceExtensions(processedData, referenceConfig);
|
|
249
565
|
processedData = await this.processObjectExpressions(processedData, values, context);
|
|
250
566
|
return this.processObject(configPath, processedData, context, values);
|
|
251
567
|
}
|
|
@@ -262,7 +578,16 @@ class ConfigService {
|
|
|
262
578
|
const builtInQueryResolvers = {
|
|
263
579
|
pages: () => ({
|
|
264
580
|
getPageConfig: async (obj, context) => {
|
|
265
|
-
|
|
581
|
+
// `impersonateRoleId`/`impersonateGeneral` are a plain
|
|
582
|
+
// pass-through onto context here — this engine never inspects
|
|
583
|
+
// identity itself; the host's resolveCurrentIdentity is what
|
|
584
|
+
// interprets them and enforces the admin-only restriction.
|
|
585
|
+
const impersonation = obj.impersonateRoleId
|
|
586
|
+
? { impersonateRoleId: obj.impersonateRoleId }
|
|
587
|
+
: obj.impersonateGeneral
|
|
588
|
+
? { impersonateGeneral: true }
|
|
589
|
+
: null;
|
|
590
|
+
const pageConfig = await this.getPageConfig(obj.path, impersonation ? { ...context, ...impersonation } : context, true, obj.context);
|
|
266
591
|
return pageConfig;
|
|
267
592
|
},
|
|
268
593
|
getAIConfig: async (obj, context) => {
|
|
@@ -346,29 +671,37 @@ class ConfigService {
|
|
|
346
671
|
return deepMergeResolvers(builtInMutationResolvers, hostMutationResolvers);
|
|
347
672
|
};
|
|
348
673
|
}
|
|
349
|
-
|
|
674
|
+
// Applies any stored config-path sub-path overrides across the whole
|
|
675
|
+
// config tree before processConfig's own recursive walk runs, so that
|
|
676
|
+
// overridden values (which may introduce new sub-config) still go
|
|
677
|
+
// through provider injection/__typename dispatch below.
|
|
678
|
+
//
|
|
679
|
+
// rootSubPathOverrides lets a caller that already resolved overrides for
|
|
680
|
+
// the root config (e.g. getConfigFromStore, which fetches the whole-object
|
|
681
|
+
// and sub-path overrides together in one round trip) hand them in directly
|
|
682
|
+
// instead of having the root node re-resolved a second time below; nested
|
|
683
|
+
// nodes discovered deeper in the tree are still resolved individually,
|
|
684
|
+
// since their configPaths aren't known until the tree has been loaded.
|
|
685
|
+
async processConfig(config, context, processProviders, rootSubPathOverrides) {
|
|
686
|
+
const overriddenConfig = await this.applyConfigPathOverride(config, context, processProviders, rootSubPathOverrides);
|
|
687
|
+
return this.processConfigTree(overriddenConfig, context, processProviders);
|
|
688
|
+
}
|
|
689
|
+
async processConfigTree(config, context, processProviders) {
|
|
350
690
|
if (!config) {
|
|
351
691
|
return config;
|
|
352
692
|
}
|
|
353
693
|
// Handle arrays
|
|
354
694
|
if (Array.isArray(config)) {
|
|
355
|
-
return Promise.all(config.map((item) => this.
|
|
695
|
+
return Promise.all(config.map((item) => this.processConfigTree(item, context, processProviders)));
|
|
356
696
|
}
|
|
357
697
|
// Handle objects
|
|
358
698
|
if (typeof config === 'object') {
|
|
359
699
|
// Recursively process all properties of config
|
|
360
700
|
let processedConfig = { ...config };
|
|
361
701
|
for (const key in processedConfig) {
|
|
362
|
-
processedConfig[key] = await this.
|
|
363
|
-
}
|
|
364
|
-
// First process the current object if it has __typename
|
|
365
|
-
if (processedConfig?.__typename && processProviders) {
|
|
366
|
-
const providerClass = this.providers[processedConfig.__typename];
|
|
367
|
-
if (providerClass) {
|
|
368
|
-
const provider = new providerClass();
|
|
369
|
-
processedConfig = await provider.processConfig(processedConfig, this, context);
|
|
370
|
-
}
|
|
702
|
+
processedConfig[key] = await this.processConfigTree(processedConfig[key], context, processProviders);
|
|
371
703
|
}
|
|
704
|
+
processedConfig = await this.applyTypenameProvider(processedConfig, context, processProviders);
|
|
372
705
|
return processedConfig;
|
|
373
706
|
}
|
|
374
707
|
if (processProviders) {
|
|
@@ -376,6 +709,59 @@ class ConfigService {
|
|
|
376
709
|
}
|
|
377
710
|
return config;
|
|
378
711
|
}
|
|
712
|
+
// Walks the whole config tree up front (pre-order) and, for every object
|
|
713
|
+
// that declares a configPath, deep-sets any stored sub-path overrides
|
|
714
|
+
// (JSONPath-addressed, e.g. "$.columns" or "$.filter.criteria").
|
|
715
|
+
//
|
|
716
|
+
// preFetchedSubPaths is only honored for the root node of the walk (the
|
|
717
|
+
// one being called with a defined third argument); nested calls always
|
|
718
|
+
// omit it so their own configPath gets resolved fresh.
|
|
719
|
+
async applyConfigPathOverride(config, context, processProviders, preFetchedSubPaths) {
|
|
720
|
+
if (!config) {
|
|
721
|
+
return config;
|
|
722
|
+
}
|
|
723
|
+
if (Array.isArray(config)) {
|
|
724
|
+
return Promise.all(config.map((item) => this.applyConfigPathOverride(item, context, processProviders)));
|
|
725
|
+
}
|
|
726
|
+
if (typeof config !== 'object') {
|
|
727
|
+
return config;
|
|
728
|
+
}
|
|
729
|
+
let result = config;
|
|
730
|
+
if (processProviders) {
|
|
731
|
+
const subPathPatch = await this.resolveSubPathOverrideLayers(result, context, preFetchedSubPaths);
|
|
732
|
+
if (subPathPatch) {
|
|
733
|
+
result = applySubPathOverrides(result, subPathPatch);
|
|
734
|
+
}
|
|
735
|
+
}
|
|
736
|
+
const overriddenEntries = await Promise.all(Object.entries(result).map(async ([key, value]) => [
|
|
737
|
+
key,
|
|
738
|
+
await this.applyConfigPathOverride(value, context, processProviders),
|
|
739
|
+
]));
|
|
740
|
+
return Object.fromEntries(overriddenEntries);
|
|
741
|
+
}
|
|
742
|
+
// Resolves the sub-path override layers that apply to `config`, unless the
|
|
743
|
+
// caller already fetched them (`preFetchedSubPaths`, honored for the root
|
|
744
|
+
// node of a walk — including when it is explicitly `null`).
|
|
745
|
+
async resolveSubPathOverrideLayers(config, context, preFetchedSubPaths) {
|
|
746
|
+
if (preFetchedSubPaths !== undefined) {
|
|
747
|
+
return preFetchedSubPaths;
|
|
748
|
+
}
|
|
749
|
+
if (!config.configPath || !this.configurationOverrideProvider) {
|
|
750
|
+
return null;
|
|
751
|
+
}
|
|
752
|
+
return toSubPathOverrideLayers(await this.configurationOverrideProvider.resolve(config.configPath, context));
|
|
753
|
+
}
|
|
754
|
+
async applyTypenameProvider(processedConfig, context, processProviders) {
|
|
755
|
+
if (!processedConfig?.__typename || !processProviders) {
|
|
756
|
+
return processedConfig;
|
|
757
|
+
}
|
|
758
|
+
const providerClass = this.providers[processedConfig.__typename];
|
|
759
|
+
if (!providerClass) {
|
|
760
|
+
return processedConfig;
|
|
761
|
+
}
|
|
762
|
+
const provider = new providerClass();
|
|
763
|
+
return await provider.processConfig(processedConfig, this, context);
|
|
764
|
+
}
|
|
379
765
|
async getRefConfig(configPath, refConfigPath, context, values) {
|
|
380
766
|
let fullPath;
|
|
381
767
|
if (refConfigPath.startsWith('.')) {
|
|
@@ -462,13 +848,21 @@ class ConfigService {
|
|
|
462
848
|
};
|
|
463
849
|
return await processValue(object);
|
|
464
850
|
}
|
|
465
|
-
async processImageReference(refConfigPath) {
|
|
851
|
+
async processImageReference(refConfigPath, context) {
|
|
466
852
|
const SUPPORTED_IMAGE_FORMATS = ['.jpg', '.jpeg', '.png', '.svg'];
|
|
467
853
|
// Check if the reference is an image file
|
|
468
854
|
const ext = path.extname(refConfigPath).toLowerCase();
|
|
469
855
|
if (!SUPPORTED_IMAGE_FORMATS.includes(ext)) {
|
|
470
856
|
return null;
|
|
471
857
|
}
|
|
858
|
+
const override = await this.configurationOverrideProvider?.resolve(refConfigPath, context);
|
|
859
|
+
if (override?.whole?.contentType) {
|
|
860
|
+
return {
|
|
861
|
+
data: override.whole.value,
|
|
862
|
+
mimeType: override.whole.contentType,
|
|
863
|
+
hash: createHash('sha256').update(override.whole.value).digest('hex'),
|
|
864
|
+
};
|
|
865
|
+
}
|
|
472
866
|
let standardStore;
|
|
473
867
|
for (const store of this.configStores) {
|
|
474
868
|
if (store instanceof ConfigFileStore) {
|
|
@@ -520,19 +914,33 @@ class ConfigService {
|
|
|
520
914
|
return 'application/octet-stream';
|
|
521
915
|
}
|
|
522
916
|
}
|
|
523
|
-
|
|
917
|
+
// Resolves the whole-object override and any sub-path overrides for
|
|
918
|
+
// configPath together, in one provider round trip, instead of fetching
|
|
919
|
+
// them separately at different points of the processing pipeline. The
|
|
920
|
+
// sub-path overrides are handed back alongside the config so callers can
|
|
921
|
+
// thread them into processConfig rather than re-resolving them later.
|
|
922
|
+
async getConfigFromStore(configPath, context) {
|
|
923
|
+
const override = await this.configurationOverrideProvider?.resolve(configPath, context);
|
|
924
|
+
const subPathOverrides = override
|
|
925
|
+
? toSubPathOverrideLayers(override)
|
|
926
|
+
: null;
|
|
927
|
+
if (override?.whole && !override.whole.contentType) {
|
|
928
|
+
return { config: load(override.whole.value), subPathOverrides };
|
|
929
|
+
}
|
|
524
930
|
const exceptions = [];
|
|
525
931
|
for (const [index, configStore] of this.configStores.entries()) {
|
|
526
932
|
try {
|
|
527
|
-
|
|
933
|
+
const config = await configStore.getConfig(configPath);
|
|
934
|
+
return { config, subPathOverrides };
|
|
528
935
|
}
|
|
529
936
|
catch (e) {
|
|
530
937
|
exceptions.push(e);
|
|
531
938
|
if (index == this.configStores.length - 1) {
|
|
532
|
-
throw new GraphQLError(`Config not found in path in any store: ${
|
|
939
|
+
throw new GraphQLError(`Config not found in path in any store: ${configPath}`, { originalError: exceptions });
|
|
533
940
|
}
|
|
534
941
|
}
|
|
535
942
|
}
|
|
943
|
+
return { config: undefined, subPathOverrides };
|
|
536
944
|
}
|
|
537
945
|
async hasConfig(configPath) {
|
|
538
946
|
return (await Promise.all(this.configStores.map((configStore) => configStore.hasConfig(configPath)))).some(Boolean);
|
|
@@ -542,9 +950,9 @@ class ConfigService {
|
|
|
542
950
|
return this.getDirectConfig(globalPath, context, values, processProviders);
|
|
543
951
|
}
|
|
544
952
|
async getDirectConfig(configPath, context, values, processProviders) {
|
|
545
|
-
const obj = await this.getConfigFromStore(configPath);
|
|
953
|
+
const { config: obj, subPathOverrides } = await this.getConfigFromStore(configPath, context);
|
|
546
954
|
const fullObj = await this.processObject(configPath, obj, context, values);
|
|
547
|
-
const processedObj = await this.processConfig(fullObj, context, processProviders);
|
|
955
|
+
const processedObj = await this.processConfig(fullObj, context, processProviders, subPathOverrides);
|
|
548
956
|
return processedObj;
|
|
549
957
|
}
|
|
550
958
|
async listDirectConfigs(configPath) {
|
|
@@ -895,21 +1303,22 @@ class ConfigService {
|
|
|
895
1303
|
}
|
|
896
1304
|
async getPageConfig(pagePath, context, processConfig, rulesContext) {
|
|
897
1305
|
const globalPath = path.join('global', 'pages', pagePath);
|
|
898
|
-
const obj = await this.getConfigFromStore(globalPath);
|
|
1306
|
+
const { config: obj, subPathOverrides } = await this.getConfigFromStore(globalPath, context);
|
|
899
1307
|
const fullObj = await this.processObject(globalPath, obj, context, null);
|
|
900
1308
|
const matchingRuleGroups = await this.getRuleGroups(rulesContext, context);
|
|
901
1309
|
const configToProcess = this.applyFieldRuleOverrides(fullObj, matchingRuleGroups);
|
|
902
|
-
return await this.processConfig(configToProcess, context, processConfig);
|
|
1310
|
+
return await this.processConfig(configToProcess, context, processConfig, subPathOverrides);
|
|
903
1311
|
}
|
|
904
1312
|
async init() {
|
|
905
1313
|
return Promise.all(this.configStores.map((configStore) => configStore.init()));
|
|
906
1314
|
}
|
|
907
1315
|
}
|
|
908
|
-
export const defaultConfigService = ({ model, configStores, configInjectorResolvers, providers, resolvers, }) => {
|
|
1316
|
+
export const defaultConfigService = ({ model, configStores, configInjectorResolvers, providers, resolvers, configurationOverrideProvider, }) => {
|
|
909
1317
|
const extensionOptions = {
|
|
910
1318
|
configInjectorResolvers,
|
|
911
1319
|
providers,
|
|
912
1320
|
resolvers,
|
|
1321
|
+
configurationOverrideProvider,
|
|
913
1322
|
};
|
|
914
1323
|
return new ConfigService(model, configStores.map((configStore) => new ConfigFileStore(configStore)), extensionOptions);
|
|
915
1324
|
};
|