@web-ts-toolkit/access-router 0.68.0 → 0.70.0
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/MIGRATION.md +35 -0
- package/README.md +61 -2
- package/advanced.d.mts +1 -1
- package/advanced.d.ts +1 -1
- package/advanced.js +5 -1
- package/advanced.mjs +5 -1
- package/index.d.mts +2 -2
- package/index.d.ts +2 -2
- package/index.js +284 -197
- package/index.mjs +284 -197
- package/package.json +3 -3
- package/{parsers-fSBARZSn.d.mts → parsers-DcYjda98.d.mts} +27 -2
- package/{parsers-fSBARZSn.d.ts → parsers-DcYjda98.d.ts} +27 -2
package/index.js
CHANGED
|
@@ -1115,7 +1115,11 @@ function copyAuthorizationValue(value, configuration = false) {
|
|
|
1115
1115
|
if (typeof input === "string") prepareTrustedOutputPayload(budget, input);
|
|
1116
1116
|
return input;
|
|
1117
1117
|
}
|
|
1118
|
-
if (import_node_util5.types.isProxy(input))
|
|
1118
|
+
if (import_node_util5.types.isProxy(input)) {
|
|
1119
|
+
const error2 = new ServiceAuthorizationError("proxy snapshot input");
|
|
1120
|
+
console.error("[access-router] Authorization snapshot rejected a Proxy", error2);
|
|
1121
|
+
throw error2;
|
|
1122
|
+
}
|
|
1119
1123
|
const ownedCatalog = configuration === true ? readOwnedAuthorizationCatalogWork(input) : void 0;
|
|
1120
1124
|
if (ownedCatalog) {
|
|
1121
1125
|
preloadTrustedOutputBudget(budget, depth + ownedCatalog.depth, ownedCatalog.slots - 1);
|
|
@@ -9500,7 +9504,12 @@ var Base = class {
|
|
|
9500
9504
|
genIDFilter(id) {
|
|
9501
9505
|
return this.requestCore.genIDFilter(this.modelName, id);
|
|
9502
9506
|
}
|
|
9503
|
-
/**
|
|
9507
|
+
/**
|
|
9508
|
+
* Request-only population: positional access (default read) admits source fields
|
|
9509
|
+
* and supplies the target default; descriptor access overrides only the target.
|
|
9510
|
+
* No document hooks, current document facts or captured parent output execution.
|
|
9511
|
+
* The only option, scopePath, uses response segments, never positional subPaths.
|
|
9512
|
+
*/
|
|
9504
9513
|
async genPopulate(access, populate, options = {}) {
|
|
9505
9514
|
assertFieldHelperCall("genPopulate", arguments.length, 3, options, "populate");
|
|
9506
9515
|
return this.requestCore.genPopulate(this.modelName, access, populate, options);
|
|
@@ -10484,7 +10493,7 @@ var Base = class {
|
|
|
10484
10493
|
|
|
10485
10494
|
// src/services/service.ts
|
|
10486
10495
|
var import_mongoose10 = require("mongoose");
|
|
10487
|
-
var
|
|
10496
|
+
var import_node_util21 = require("util");
|
|
10488
10497
|
var import_utils34 = require("@web-ts-toolkit/utils");
|
|
10489
10498
|
var import_just_diff = require("just-diff");
|
|
10490
10499
|
|
|
@@ -11173,14 +11182,13 @@ async function loadVirtualPopulateOutputRows(owner, inputs, plan, publicPopulate
|
|
|
11173
11182
|
}
|
|
11174
11183
|
|
|
11175
11184
|
// src/acl/output-field-filter.ts
|
|
11176
|
-
var
|
|
11185
|
+
var import_node_util19 = require("util");
|
|
11177
11186
|
var import_utils28 = require("@web-ts-toolkit/utils");
|
|
11178
11187
|
init_authorization_snapshot();
|
|
11179
11188
|
init_document_permissions_definition();
|
|
11180
11189
|
init_field_catalog();
|
|
11181
11190
|
|
|
11182
11191
|
// src/acl/output-field-policy.ts
|
|
11183
|
-
var import_node_util18 = require("util");
|
|
11184
11192
|
var import_utils27 = require("@web-ts-toolkit/utils");
|
|
11185
11193
|
init_output_work_ledger();
|
|
11186
11194
|
var fieldPolicies = /* @__PURE__ */ new WeakMap();
|
|
@@ -11327,7 +11335,7 @@ init_permissions_alias();
|
|
|
11327
11335
|
init_concurrency();
|
|
11328
11336
|
|
|
11329
11337
|
// src/acl/output-helper-many-admission.ts
|
|
11330
|
-
var
|
|
11338
|
+
var import_node_util18 = require("util");
|
|
11331
11339
|
init_authorization_snapshot();
|
|
11332
11340
|
init_field_catalog();
|
|
11333
11341
|
init_output_work_ledger();
|
|
@@ -11346,7 +11354,7 @@ var intrinsicObjectKeys = /* @__PURE__ */ new Set([
|
|
|
11346
11354
|
"toLocaleString"
|
|
11347
11355
|
]);
|
|
11348
11356
|
function exactRecord(value, keys2, label) {
|
|
11349
|
-
if (!value || typeof value !== "object" ||
|
|
11357
|
+
if (!value || typeof value !== "object" || import_node_util18.types.isProxy(value)) authorizationError(`invalid ${label}`);
|
|
11350
11358
|
const prototype = Object.getPrototypeOf(value);
|
|
11351
11359
|
if (prototype !== Object.prototype && prototype !== null) authorizationError(`invalid ${label} prototype`);
|
|
11352
11360
|
for (const key of keys2)
|
|
@@ -11387,7 +11395,7 @@ function exactRecord(value, keys2, label) {
|
|
|
11387
11395
|
return value;
|
|
11388
11396
|
}
|
|
11389
11397
|
function denseArray(value, maximum, label) {
|
|
11390
|
-
if (!value || typeof value !== "object" ||
|
|
11398
|
+
if (!value || typeof value !== "object" || import_node_util18.types.isProxy(value)) authorizationError(`invalid ${label}`);
|
|
11391
11399
|
if (!Array.isArray(value) || Object.getPrototypeOf(value) !== Array.prototype)
|
|
11392
11400
|
authorizationError(`${label} must be an ordinary dense Array`);
|
|
11393
11401
|
const length = Object.getOwnPropertyDescriptor(value, "length").value;
|
|
@@ -11616,7 +11624,7 @@ function prepareOutputValueCopy(plan) {
|
|
|
11616
11624
|
};
|
|
11617
11625
|
}
|
|
11618
11626
|
function copyAuthorizedReference(value, path, construction2, prepaid = false) {
|
|
11619
|
-
if (value && typeof value === "object" &&
|
|
11627
|
+
if (value && typeof value === "object" && import_node_util19.types.isProxy(value))
|
|
11620
11628
|
failTrustedOutputBudget(construction2.budget, new ServiceAuthorizationError("unsupported selected proxy"));
|
|
11621
11629
|
if (Array.isArray(value)) {
|
|
11622
11630
|
const entries = shallowTrustedOutputArray(value, construction2.budget, construction2.depth, prepaid);
|
|
@@ -11685,7 +11693,7 @@ function continueExistingOutput(value, stage, binding, owner, accept) {
|
|
|
11685
11693
|
readDocumentStage(stage, binding);
|
|
11686
11694
|
return accept(result2);
|
|
11687
11695
|
};
|
|
11688
|
-
if (!
|
|
11696
|
+
if (!import_node_util19.types.isPromise(value)) return checked(value);
|
|
11689
11697
|
readDocumentStage(stage, binding);
|
|
11690
11698
|
return trackPublicationWork(
|
|
11691
11699
|
owner,
|
|
@@ -11740,7 +11748,7 @@ function filterExistingOutput(source, plan, stage, construction2, owner, prepaid
|
|
|
11740
11748
|
const one = (value2, depth) => {
|
|
11741
11749
|
readDocumentStage(stage, binding);
|
|
11742
11750
|
visitTrustedOutput(construction2.budget, depth, 0);
|
|
11743
|
-
if (value2 && typeof value2 === "object" &&
|
|
11751
|
+
if (value2 && typeof value2 === "object" && import_node_util19.types.isProxy(value2))
|
|
11744
11752
|
failTrustedOutputBudget(construction2.budget, new ServiceAuthorizationError("unsupported selected proxy"));
|
|
11745
11753
|
if (Array.isArray(value2)) {
|
|
11746
11754
|
const entries = shallowTrustedOutputArray(value2, construction2.budget, depth, true);
|
|
@@ -11748,7 +11756,7 @@ function filterExistingOutput(source, plan, stage, construction2, owner, prepaid
|
|
|
11748
11756
|
const append = (start) => {
|
|
11749
11757
|
for (let index = start; index < entries.length; index++) {
|
|
11750
11758
|
const value3 = one(entries[index], depth + 1);
|
|
11751
|
-
if (
|
|
11759
|
+
if (import_node_util19.types.isPromise(value3))
|
|
11752
11760
|
return resume(value3, (result3) => {
|
|
11753
11761
|
values.push(result3 ?? null);
|
|
11754
11762
|
return append(index + 1);
|
|
@@ -11843,7 +11851,7 @@ function filterExistingOutput(source, plan, stage, construction2, owner, prepaid
|
|
|
11843
11851
|
const walk = (start) => {
|
|
11844
11852
|
for (let index = start; index < selected.length; index++) {
|
|
11845
11853
|
const value = fieldValue(selected[index]);
|
|
11846
|
-
if (
|
|
11854
|
+
if (import_node_util19.types.isPromise(value)) return resume(value, () => walk(index + 1));
|
|
11847
11855
|
}
|
|
11848
11856
|
return finish();
|
|
11849
11857
|
};
|
|
@@ -12000,7 +12008,7 @@ init_public_admission();
|
|
|
12000
12008
|
init_document();
|
|
12001
12009
|
|
|
12002
12010
|
// src/output/finalize-model-output.ts
|
|
12003
|
-
var
|
|
12011
|
+
var import_node_util20 = require("util");
|
|
12004
12012
|
var import_utils29 = require("@web-ts-toolkit/utils");
|
|
12005
12013
|
init_trusted_output_materialization();
|
|
12006
12014
|
init_authorization_snapshot();
|
|
@@ -12078,7 +12086,7 @@ function assertFinalizer(args) {
|
|
|
12078
12086
|
if (binding.request !== args.request || binding.modelName !== args.receivingModelName || access.virtualAccess !== args.virtualAccess || access.outputAccess !== args.outputAccess || access.docPermissionsAccess !== args.docPermissionsAccess || (binding.scopePath ?? []).join(".") !== (args.scopePath ?? args.plan.scopePath ?? []).filter((part) => part !== "sub").join("."))
|
|
12079
12087
|
authorizationError("finalizer call/model/scope/access mismatch");
|
|
12080
12088
|
}
|
|
12081
|
-
function
|
|
12089
|
+
function prepareFinalizer(args) {
|
|
12082
12090
|
assertFinalizer(args);
|
|
12083
12091
|
const configuration = readServiceFinalizerConfiguration(args.plan.authorization, args.plan.authorizationBinding);
|
|
12084
12092
|
const virtuals = scopeVirtuals(configuration.virtuals, args.scopePath ?? args.plan.scopePath ?? []);
|
|
@@ -12090,7 +12098,7 @@ function prepare(args) {
|
|
|
12090
12098
|
)
|
|
12091
12099
|
};
|
|
12092
12100
|
}
|
|
12093
|
-
async function
|
|
12101
|
+
async function finalizeOutputDocument(args, preparation2) {
|
|
12094
12102
|
assertFinalizer(args);
|
|
12095
12103
|
const plan = args.plan, binding = plan.authorizationBinding, authorization = plan.authorization;
|
|
12096
12104
|
const owner = args.publication ?? outputPublicationFor(authorization);
|
|
@@ -12111,7 +12119,7 @@ async function finalizeSingleDoc(args, prepared) {
|
|
|
12111
12119
|
failTrustedOutputBudget(budget, new ServiceAuthorizationError("cyclic selected document output"));
|
|
12112
12120
|
const nextLineage = new Set(lineage).add(source);
|
|
12113
12121
|
visitTrustedOutput(budget, depth, args.prepaid ? 0 : 1);
|
|
12114
|
-
await
|
|
12122
|
+
await preparation2.resolve({
|
|
12115
12123
|
authorization,
|
|
12116
12124
|
binding,
|
|
12117
12125
|
snapshot: source,
|
|
@@ -12166,11 +12174,11 @@ async function finalizeSingleDoc(args, prepared) {
|
|
|
12166
12174
|
lineage: nextLineage,
|
|
12167
12175
|
prepaid: true
|
|
12168
12176
|
};
|
|
12169
|
-
const childPreparation =
|
|
12177
|
+
const childPreparation = prepareFinalizer(base);
|
|
12170
12178
|
const one = async (value2, childDepth, childAddress, ancestors) => {
|
|
12171
12179
|
assertOutputPublication(owner);
|
|
12172
12180
|
visitTrustedOutput(budget, childDepth, 0);
|
|
12173
|
-
if (value2 && typeof value2 === "object" &&
|
|
12181
|
+
if (value2 && typeof value2 === "object" && import_node_util20.types.isProxy(value2))
|
|
12174
12182
|
failTrustedOutputBudget(budget, new ServiceAuthorizationError("unsupported selected proxy"));
|
|
12175
12183
|
if (Array.isArray(value2)) {
|
|
12176
12184
|
if (ancestors.has(value2))
|
|
@@ -12190,7 +12198,7 @@ async function finalizeSingleDoc(args, prepared) {
|
|
|
12190
12198
|
failTrustedOutputBudget(budget, new ServiceAuthorizationError("unsupported selected embedded value"));
|
|
12191
12199
|
return null;
|
|
12192
12200
|
}
|
|
12193
|
-
return
|
|
12201
|
+
return finalizeOutputDocument(
|
|
12194
12202
|
{
|
|
12195
12203
|
...base,
|
|
12196
12204
|
input: value2,
|
|
@@ -12220,7 +12228,7 @@ async function finalizeSingleDoc(args, prepared) {
|
|
|
12220
12228
|
}
|
|
12221
12229
|
for (const { path, value } of args.includeAttachments ?? [])
|
|
12222
12230
|
setTrustedOutputPath(working, path, value, budget, depth);
|
|
12223
|
-
for (const field of
|
|
12231
|
+
for (const field of preparation2.virtualNames) delete working[field];
|
|
12224
12232
|
const candidates = plan.candidates ?? [];
|
|
12225
12233
|
const hasDependencies = (dependsOn) => dependsOn.every((key) => Object.hasOwn(working, key) && working[key] !== void 0);
|
|
12226
12234
|
const needsView = candidates.some(
|
|
@@ -12335,7 +12343,7 @@ async function finalizeSingleDoc(args, prepared) {
|
|
|
12335
12343
|
);
|
|
12336
12344
|
}
|
|
12337
12345
|
if (args.completeOutput) await args.completeOutput(output, stage, construction2);
|
|
12338
|
-
else retainOutputMetadata(output, source,
|
|
12346
|
+
else retainOutputMetadata(output, source, preparation2.configuration, binding.scopePath ?? [], construction2);
|
|
12339
12347
|
readDocumentStage(stage, binding);
|
|
12340
12348
|
assertTrustedOutputBudget(budget);
|
|
12341
12349
|
assertOutputPublication(owner);
|
|
@@ -12347,7 +12355,7 @@ async function finalizeModelOutput(args) {
|
|
|
12347
12355
|
const owner = args.publication ?? outputPublicationFor(args.plan.authorization);
|
|
12348
12356
|
const work = async () => {
|
|
12349
12357
|
try {
|
|
12350
|
-
return await
|
|
12358
|
+
return await finalizeOutputDocument({ ...args, publication: owner }, prepareFinalizer(args));
|
|
12351
12359
|
} catch (error2) {
|
|
12352
12360
|
failOutputPublication(owner, error2);
|
|
12353
12361
|
throw error2;
|
|
@@ -12362,12 +12370,12 @@ async function finalizeModelOutputs(args) {
|
|
|
12362
12370
|
const owner = args.publication ?? outputPublicationFor(args.plan.authorization);
|
|
12363
12371
|
const work = async () => {
|
|
12364
12372
|
const base = { ...rest, input: void 0, publication: owner };
|
|
12365
|
-
const
|
|
12373
|
+
const preparation2 = prepareFinalizer(base);
|
|
12366
12374
|
const gate = getRequestWorkState(args.request, args.plan.authorizationBinding.runtime).hookGate;
|
|
12367
12375
|
return mapWithConcurrencyLimit(
|
|
12368
12376
|
inputs,
|
|
12369
12377
|
gate.limit,
|
|
12370
|
-
(input, index) =>
|
|
12378
|
+
(input, index) => finalizeOutputDocument(
|
|
12371
12379
|
{
|
|
12372
12380
|
...base,
|
|
12373
12381
|
input,
|
|
@@ -12376,7 +12384,7 @@ async function finalizeModelOutputs(args) {
|
|
|
12376
12384
|
completedReferences: rowReferences?.[index] ?? rest.completedReferences,
|
|
12377
12385
|
onFinalized: rest.onFinalized ? (output, context) => rest.onFinalized(output, context, index) : void 0
|
|
12378
12386
|
},
|
|
12379
|
-
|
|
12387
|
+
preparation2
|
|
12380
12388
|
),
|
|
12381
12389
|
(error2) => failOutputPublication(owner, error2)
|
|
12382
12390
|
);
|
|
@@ -12494,7 +12502,6 @@ async function finalizeSubdocumentRows(service, prepared, parent, rows2, populat
|
|
|
12494
12502
|
receivingModelName: state.binding.modelName,
|
|
12495
12503
|
inputs,
|
|
12496
12504
|
plan,
|
|
12497
|
-
snapshot: readServiceAuthorization(state.authorization, state.binding).configuration,
|
|
12498
12505
|
request: service.getServiceRequest(),
|
|
12499
12506
|
context,
|
|
12500
12507
|
...state.access,
|
|
@@ -12511,7 +12518,6 @@ function copySubdocumentParent(parent) {
|
|
|
12511
12518
|
}
|
|
12512
12519
|
|
|
12513
12520
|
// src/services/service.ts
|
|
12514
|
-
init_permissions_alias();
|
|
12515
12521
|
init_trusted_output_materialization();
|
|
12516
12522
|
init_document();
|
|
12517
12523
|
|
|
@@ -13420,6 +13426,53 @@ async function getParentDoc(service, id, sub, args, options) {
|
|
|
13420
13426
|
});
|
|
13421
13427
|
}
|
|
13422
13428
|
|
|
13429
|
+
// src/services/model-output-metadata.ts
|
|
13430
|
+
init_trusted_output_materialization();
|
|
13431
|
+
init_permissions_alias();
|
|
13432
|
+
function createModelOutputMetadataCompletion(args, binding, configuration, readFieldPermissionAccess, queryFieldPermissionAccess) {
|
|
13433
|
+
return async (output, stage, construction2) => {
|
|
13434
|
+
const { grants } = readDocumentStage(stage, binding);
|
|
13435
|
+
const source = getIncludeSource(args.doc);
|
|
13436
|
+
if (args.privateAssociationField) unsetTrustedOutputPath(output, args.privateAssociationField, args.budget);
|
|
13437
|
+
restoreIncludeOutput(args.doc, output, construction2);
|
|
13438
|
+
const field = configuration.documentPermissionField ?? "_permissions";
|
|
13439
|
+
unsetTrustedOutputPath(output, field, args.budget);
|
|
13440
|
+
removeGeneratedPermissionsAlias(output);
|
|
13441
|
+
if (configuration.stripPermissionsField) return;
|
|
13442
|
+
const exposed = configuration.exposedDocPermissionKeys;
|
|
13443
|
+
const metadata = {};
|
|
13444
|
+
const metadataDepth = construction2.depth + field.split(".").length;
|
|
13445
|
+
setTrustedOutputPath(output, field, metadata, args.budget, construction2.depth);
|
|
13446
|
+
if (args.includePermissions || args.includeFieldPermissions) {
|
|
13447
|
+
for (const key of Object.keys(grants)) {
|
|
13448
|
+
visitTrustedOutput(args.budget, metadataDepth + 1);
|
|
13449
|
+
if (!exposed || exposed.includes(key)) defineTrustedOutputValue(metadata, key, grants[key]);
|
|
13450
|
+
}
|
|
13451
|
+
}
|
|
13452
|
+
if (args.includeFieldPermissions && !configuration.disableFieldPermissions) {
|
|
13453
|
+
const rowAccess = readFieldPermissionAccess() ?? await queryFieldPermissionAccess([source._id], args.publication);
|
|
13454
|
+
const id = String(source._id);
|
|
13455
|
+
const map2 = async (access, allowed) => {
|
|
13456
|
+
visitTrustedOutput(args.budget, metadataDepth + 1);
|
|
13457
|
+
const paths = allowed ? await requestOutputFieldPaths(stage, binding, access, {
|
|
13458
|
+
budget: args.budget,
|
|
13459
|
+
depth: metadataDepth + 1
|
|
13460
|
+
}) : [];
|
|
13461
|
+
if (!paths.length) visitTrustedOutput(args.budget, metadataDepth + 2);
|
|
13462
|
+
return paths.length ? Object.fromEntries(paths.map((path) => [path, true])) : { $: "_" };
|
|
13463
|
+
};
|
|
13464
|
+
defineTrustedOutputValue(metadata, "_view", await map2("read", rowAccess.readIds?.has(id) ?? false));
|
|
13465
|
+
defineTrustedOutputValue(metadata, "_edit", await map2("update", rowAccess.updateIds?.has(id) ?? false));
|
|
13466
|
+
} else if (!args.includePermissions && !configuration.disableFieldPermissions) {
|
|
13467
|
+
visitTrustedOutput(args.budget, metadataDepth + 1, 2);
|
|
13468
|
+
visitTrustedOutput(args.budget, metadataDepth + 2, 2);
|
|
13469
|
+
defineTrustedOutputValue(metadata, "_view", { $: "_" });
|
|
13470
|
+
defineTrustedOutputValue(metadata, "_edit", { $: "_" });
|
|
13471
|
+
}
|
|
13472
|
+
attachPermissionsAlias(output, field);
|
|
13473
|
+
};
|
|
13474
|
+
}
|
|
13475
|
+
|
|
13423
13476
|
// src/services/service.ts
|
|
13424
13477
|
var assertModelDocument = (value, modelName, hookName) => {
|
|
13425
13478
|
if (isDocument2(value)) {
|
|
@@ -13473,13 +13526,17 @@ var Service = class extends Base {
|
|
|
13473
13526
|
rows2,
|
|
13474
13527
|
this.hookGate.limit,
|
|
13475
13528
|
(doc, index) => this.finalizePopulateForSingleDoc(
|
|
13529
|
+
// Receiving document and target entries.
|
|
13476
13530
|
doc,
|
|
13477
13531
|
populate,
|
|
13532
|
+
// Initiating execution and gates.
|
|
13478
13533
|
context,
|
|
13479
13534
|
state.access.operation,
|
|
13480
13535
|
this.hookGate.limit,
|
|
13481
13536
|
this.hookGate,
|
|
13537
|
+
// Parent authorization.
|
|
13482
13538
|
state.authorization,
|
|
13539
|
+
// Completed handoffs, receiving budget and publication.
|
|
13483
13540
|
references[index],
|
|
13484
13541
|
budgets2[index],
|
|
13485
13542
|
state.publication
|
|
@@ -13529,9 +13586,9 @@ var Service = class extends Base {
|
|
|
13529
13586
|
},
|
|
13530
13587
|
findOne: (execution, filter2, args, options) => this.findOnePrepared(execution, filter2, args, options),
|
|
13531
13588
|
findOneCondition: (execution, filter2, args, options) => this.#findOneConditionPrepared(execution, filter2, args, options),
|
|
13532
|
-
find: (execution, query, filter2, args, options
|
|
13533
|
-
updateOne: (execution, filter2, data, args, options
|
|
13534
|
-
create: (execution, data, args, options
|
|
13589
|
+
find: (execution, query, filter2, args, options) => this.findPrepared(execution, query, filter2, args, options),
|
|
13590
|
+
updateOne: (execution, filter2, data, args, options) => this.updateOnePrepared(execution, filter2, data, args, options),
|
|
13591
|
+
create: (execution, data, args, options) => this.createPrepared(execution, data, args, options),
|
|
13535
13592
|
exists: async (filter2, includeId) => {
|
|
13536
13593
|
const result2 = await this.model.exists(filter2);
|
|
13537
13594
|
return {
|
|
@@ -13742,7 +13799,6 @@ var Service = class extends Base {
|
|
|
13742
13799
|
receivingModelName: this.modelName,
|
|
13743
13800
|
input: args.doc,
|
|
13744
13801
|
plan,
|
|
13745
|
-
snapshot: configuration,
|
|
13746
13802
|
virtualAccess: access.virtualAccess,
|
|
13747
13803
|
outputAccess: access.outputAccess,
|
|
13748
13804
|
docPermissionsAccess: access.docPermissionsAccess,
|
|
@@ -13755,47 +13811,13 @@ var Service = class extends Base {
|
|
|
13755
13811
|
completedReferences: args.references,
|
|
13756
13812
|
includeAttachments: getIncludeAttachments(args.doc),
|
|
13757
13813
|
virtualPopulateRow: getVirtualPopulateRow(getIncludeOriginal(args.doc, authorization)),
|
|
13758
|
-
completeOutput:
|
|
13759
|
-
|
|
13760
|
-
|
|
13761
|
-
|
|
13762
|
-
|
|
13763
|
-
|
|
13764
|
-
|
|
13765
|
-
removeGeneratedPermissionsAlias(output);
|
|
13766
|
-
if (configuration.stripPermissionsField) return;
|
|
13767
|
-
const exposed = configuration.exposedDocPermissionKeys;
|
|
13768
|
-
const metadata = {};
|
|
13769
|
-
const metadataDepth = construction2.depth + field.split(".").length;
|
|
13770
|
-
setTrustedOutputPath(output, field, metadata, args.budget, construction2.depth);
|
|
13771
|
-
if (args.includePermissions || args.includeFieldPermissions) {
|
|
13772
|
-
for (const key of Object.keys(grants)) {
|
|
13773
|
-
visitTrustedOutput(args.budget, metadataDepth + 1);
|
|
13774
|
-
if (!exposed || exposed.includes(key)) defineTrustedOutputValue(metadata, key, grants[key]);
|
|
13775
|
-
}
|
|
13776
|
-
}
|
|
13777
|
-
if (args.includeFieldPermissions && !configuration.disableFieldPermissions) {
|
|
13778
|
-
const rowAccess = this.asServiceHookContext(context).fieldPermissionAccess ?? await this.getFieldPermissionAccess([source._id], args.publication);
|
|
13779
|
-
const id = String(source._id);
|
|
13780
|
-
const map2 = async (access2, allowed) => {
|
|
13781
|
-
visitTrustedOutput(args.budget, metadataDepth + 1);
|
|
13782
|
-
const paths = allowed ? await requestOutputFieldPaths(stage, binding, access2, {
|
|
13783
|
-
budget: args.budget,
|
|
13784
|
-
depth: metadataDepth + 1
|
|
13785
|
-
}) : [];
|
|
13786
|
-
if (!paths.length) visitTrustedOutput(args.budget, metadataDepth + 2);
|
|
13787
|
-
return paths.length ? Object.fromEntries(paths.map((path) => [path, true])) : { $: "_" };
|
|
13788
|
-
};
|
|
13789
|
-
defineTrustedOutputValue(metadata, "_view", await map2("read", rowAccess.readIds?.has(id) ?? false));
|
|
13790
|
-
defineTrustedOutputValue(metadata, "_edit", await map2("update", rowAccess.updateIds?.has(id) ?? false));
|
|
13791
|
-
} else if (!args.includePermissions && !configuration.disableFieldPermissions) {
|
|
13792
|
-
visitTrustedOutput(args.budget, metadataDepth + 1, 2);
|
|
13793
|
-
visitTrustedOutput(args.budget, metadataDepth + 2, 2);
|
|
13794
|
-
defineTrustedOutputValue(metadata, "_view", { $: "_" });
|
|
13795
|
-
defineTrustedOutputValue(metadata, "_edit", { $: "_" });
|
|
13796
|
-
}
|
|
13797
|
-
attachPermissionsAlias(output, field);
|
|
13798
|
-
},
|
|
13814
|
+
completeOutput: createModelOutputMetadataCompletion(
|
|
13815
|
+
args,
|
|
13816
|
+
binding,
|
|
13817
|
+
configuration,
|
|
13818
|
+
() => this.asServiceHookContext(context).fieldPermissionAccess,
|
|
13819
|
+
(ids, publication) => this.getFieldPermissionAccess(ids, publication)
|
|
13820
|
+
),
|
|
13799
13821
|
onFinalized: (_output, outputContext) => {
|
|
13800
13822
|
finalizedContext = outputContext;
|
|
13801
13823
|
}
|
|
@@ -13924,13 +13946,17 @@ var Service = class extends Base {
|
|
|
13924
13946
|
this.registerPopulateRecipients([{ doc: parentDoc, budget, publication }], populateEntries);
|
|
13925
13947
|
await runOutputPublication(publication, async () => {
|
|
13926
13948
|
await this.finalizePopulateForSingleDoc(
|
|
13949
|
+
// Receiving document and target entries.
|
|
13927
13950
|
parentDoc,
|
|
13928
13951
|
populateEntries,
|
|
13952
|
+
// Initiating execution and gates.
|
|
13929
13953
|
parentContext,
|
|
13930
13954
|
parentOperation,
|
|
13931
13955
|
limit,
|
|
13932
13956
|
gate,
|
|
13957
|
+
// Parent authorization.
|
|
13933
13958
|
void 0,
|
|
13959
|
+
// Completed handoffs, receiving budget and publication.
|
|
13934
13960
|
references,
|
|
13935
13961
|
budget,
|
|
13936
13962
|
publication
|
|
@@ -14013,7 +14039,11 @@ var Service = class extends Base {
|
|
|
14013
14039
|
assertPopulateAccess(targetAccess);
|
|
14014
14040
|
const sourceState = classifyEffectiveFieldAuthorization({
|
|
14015
14041
|
path: descriptor.path,
|
|
14016
|
-
rules: extractOutputFieldRules(
|
|
14042
|
+
rules: extractOutputFieldRules(
|
|
14043
|
+
captured.configuration.permissionSchema,
|
|
14044
|
+
descriptor.path,
|
|
14045
|
+
captured.access.outputAccess
|
|
14046
|
+
),
|
|
14017
14047
|
outputFields: captured.authorization.outputFields,
|
|
14018
14048
|
globalPermissions: getAuthorizationPermissions(state.authorization, state.binding),
|
|
14019
14049
|
modelPermissionPrefix: captured.configuration.modelPermissionPrefix
|
|
@@ -14088,10 +14118,10 @@ var Service = class extends Base {
|
|
|
14088
14118
|
if (value === null || value === void 0) return true;
|
|
14089
14119
|
if (typeof value === "string" || typeof value === "number" || typeof value === "bigint" || typeof value === "boolean")
|
|
14090
14120
|
return true;
|
|
14091
|
-
if (
|
|
14121
|
+
if (import_node_util21.types.isProxy(value)) return false;
|
|
14092
14122
|
let record3 = value;
|
|
14093
14123
|
for (let hops = 0; record3 && hops <= 100; hops++) {
|
|
14094
|
-
if (
|
|
14124
|
+
if (import_node_util21.types.isProxy(record3)) return false;
|
|
14095
14125
|
if (record3 === import_mongoose10.mongo.BSON.BSONValue.prototype) return true;
|
|
14096
14126
|
const slot = Object.getOwnPropertyDescriptor(record3, "_bsontype");
|
|
14097
14127
|
if (slot && "value" in slot) return typeof slot.value === "string";
|
|
@@ -14104,69 +14134,77 @@ var Service = class extends Base {
|
|
|
14104
14134
|
const original = getQueryReferenceOriginal(value, publication) ?? value;
|
|
14105
14135
|
return getVirtualPopulatePublicIdentity(value) ?? getVirtualPopulatePublicIdentity(original) ?? original;
|
|
14106
14136
|
}
|
|
14107
|
-
async finalizeSinglePopulateTarget(
|
|
14108
|
-
if (
|
|
14109
|
-
if (this.isScalarPopulateValue(
|
|
14110
|
-
const isDoc = !
|
|
14111
|
-
if (!isDoc)
|
|
14112
|
-
|
|
14137
|
+
async finalizeSinglePopulateTarget(targetValue, targetMeta, initiatingOperation, parentHookContext, hookLimit, sharedGate, sourceTarget = targetValue, receivingBudget, publication, parentAuthorization, receivingDepth = 1) {
|
|
14138
|
+
if (targetValue === null || targetValue === void 0) return targetValue;
|
|
14139
|
+
if (this.isScalarPopulateValue(targetValue)) return targetValue;
|
|
14140
|
+
const isDoc = !import_node_util21.types.isProxy(targetValue) && ((0, import_utils34.isPlainObject)(targetValue) || targetValue instanceof import_mongoose10.Document);
|
|
14141
|
+
if (!isDoc)
|
|
14142
|
+
failTrustedOutputBudget(receivingBudget, new ServiceAuthorizationError("unsupported populated target"));
|
|
14143
|
+
let cache = this.populateOutputCache.get(targetMeta);
|
|
14113
14144
|
if (!cache) {
|
|
14114
14145
|
cache = /* @__PURE__ */ new WeakMap();
|
|
14115
|
-
this.populateOutputCache.set(
|
|
14146
|
+
this.populateOutputCache.set(targetMeta, cache);
|
|
14116
14147
|
if (publication)
|
|
14117
14148
|
retainPublicationResource(publication, () => {
|
|
14118
|
-
this.populateOutputCache.delete(
|
|
14119
|
-
this.populateBudgetRecipients.delete(
|
|
14120
|
-
this.populateInputSlots.delete(
|
|
14121
|
-
this.populateInputArrays.delete(
|
|
14149
|
+
this.populateOutputCache.delete(targetMeta);
|
|
14150
|
+
this.populateBudgetRecipients.delete(targetMeta);
|
|
14151
|
+
this.populateInputSlots.delete(targetMeta);
|
|
14152
|
+
this.populateInputArrays.delete(targetMeta);
|
|
14122
14153
|
});
|
|
14123
14154
|
}
|
|
14124
|
-
const
|
|
14125
|
-
const
|
|
14126
|
-
const
|
|
14127
|
-
const
|
|
14128
|
-
if (!
|
|
14155
|
+
const sourceIdentity = sourceTarget && typeof sourceTarget === "object" ? sourceTarget : targetValue;
|
|
14156
|
+
const publicationOwner = publication ?? outputPublicationFor(targetMeta.plan.authorization);
|
|
14157
|
+
const targetIdentity = this.populateTargetIdentity(targetValue, publicationOwner);
|
|
14158
|
+
const receivingOccurrences = this.populateBudgetRecipients.get(targetMeta)?.get(targetIdentity);
|
|
14159
|
+
if (!receivingOccurrences?.some((edge) => edge.budget === receivingBudget && edge.depth === receivingDepth))
|
|
14129
14160
|
authorizationError("populate target requires preregistered receiving occurrences");
|
|
14130
|
-
const existing = cache.get(
|
|
14161
|
+
const existing = cache.get(targetIdentity);
|
|
14131
14162
|
if (existing) {
|
|
14132
|
-
const
|
|
14163
|
+
const cachedTargetOutput = await existing;
|
|
14133
14164
|
return materializeTrustedOutputValue(
|
|
14134
|
-
|
|
14135
|
-
|
|
14136
|
-
|
|
14165
|
+
cachedTargetOutput,
|
|
14166
|
+
targetMeta.plan.receivingModelName ?? "",
|
|
14167
|
+
receivingBudget,
|
|
14137
14168
|
{ keep: () => true },
|
|
14138
|
-
|
|
14169
|
+
receivingDepth
|
|
14139
14170
|
);
|
|
14140
14171
|
}
|
|
14141
14172
|
const targetContext = createModelOutputContext({
|
|
14142
|
-
modelName:
|
|
14143
|
-
operation:
|
|
14144
|
-
virtualAccess:
|
|
14145
|
-
outputAccess:
|
|
14146
|
-
docPermissionsAccess:
|
|
14147
|
-
resolvedQuery:
|
|
14173
|
+
modelName: targetMeta.targetModelName,
|
|
14174
|
+
operation: parentHookContext.operation ?? initiatingOperation,
|
|
14175
|
+
virtualAccess: targetMeta.virtualAccess,
|
|
14176
|
+
outputAccess: targetMeta.outputAccess,
|
|
14177
|
+
docPermissionsAccess: targetMeta.docPermissionsAccess,
|
|
14178
|
+
resolvedQuery: parentHookContext.resolvedQuery
|
|
14148
14179
|
});
|
|
14149
|
-
bindOutputPublication(
|
|
14150
|
-
const
|
|
14151
|
-
const
|
|
14152
|
-
receivingModelName:
|
|
14153
|
-
input: parentAuthorization && readServiceAuthorizationMode(parentAuthorization, getServiceExecutors(this).binding()) === "isolated" && readServiceAuthorizationMode(
|
|
14154
|
-
virtualAccess:
|
|
14155
|
-
outputAccess:
|
|
14156
|
-
docPermissionsAccess:
|
|
14180
|
+
bindOutputPublication(targetMeta.plan.authorization, publicationOwner);
|
|
14181
|
+
const targetConstructionBudget = createReceivingOutputBudget(receivingOccurrences);
|
|
14182
|
+
const pendingTargetOutput = finalizeModelOutput({
|
|
14183
|
+
receivingModelName: targetMeta.targetModelName,
|
|
14184
|
+
input: parentAuthorization && readServiceAuthorizationMode(parentAuthorization, getServiceExecutors(this).binding()) === "isolated" && readServiceAuthorizationMode(targetMeta.plan.authorization, targetMeta.plan.authorizationBinding) === "trusted" && !isWriteOutputAuthorization(targetMeta.plan.authorization, targetMeta.plan.authorizationBinding) ? copyDocumentView(targetValue) : targetValue,
|
|
14185
|
+
virtualAccess: targetMeta.virtualAccess,
|
|
14186
|
+
outputAccess: targetMeta.outputAccess,
|
|
14187
|
+
docPermissionsAccess: targetMeta.docPermissionsAccess,
|
|
14157
14188
|
scopePath: [],
|
|
14158
|
-
plan:
|
|
14159
|
-
snapshot: meta.snapshot,
|
|
14189
|
+
plan: targetMeta.plan,
|
|
14160
14190
|
request: this.req,
|
|
14161
14191
|
context: targetContext,
|
|
14162
|
-
operation:
|
|
14163
|
-
publication:
|
|
14164
|
-
outputBudget:
|
|
14165
|
-
virtualPopulateRow: getVirtualPopulateRow(
|
|
14192
|
+
operation: parentHookContext.operation ?? initiatingOperation,
|
|
14193
|
+
publication: publicationOwner,
|
|
14194
|
+
outputBudget: targetConstructionBudget,
|
|
14195
|
+
virtualPopulateRow: getVirtualPopulateRow(sourceIdentity) ?? getVirtualPopulateRow(
|
|
14196
|
+
getQueryReferenceOriginal(targetValue, publicationOwner) ?? targetValue
|
|
14197
|
+
)
|
|
14166
14198
|
});
|
|
14167
|
-
cache.set(
|
|
14168
|
-
const
|
|
14169
|
-
return materializeTrustedOutputValue(
|
|
14199
|
+
cache.set(targetIdentity, pendingTargetOutput);
|
|
14200
|
+
const finalizedTargetOutput = await pendingTargetOutput;
|
|
14201
|
+
return materializeTrustedOutputValue(
|
|
14202
|
+
finalizedTargetOutput,
|
|
14203
|
+
targetMeta.targetModelName,
|
|
14204
|
+
receivingBudget,
|
|
14205
|
+
{ keep: () => true },
|
|
14206
|
+
receivingDepth
|
|
14207
|
+
);
|
|
14170
14208
|
}
|
|
14171
14209
|
/** Register every actual receiving occurrence before a batched/shared target starts construction. */
|
|
14172
14210
|
registerPopulateRecipients(rows2, entries) {
|
|
@@ -14189,7 +14227,7 @@ var Service = class extends Base {
|
|
|
14189
14227
|
for (const row of rows2) {
|
|
14190
14228
|
const walk = (value, index, depth) => {
|
|
14191
14229
|
visitTrustedOutput(row.budget, depth, 0);
|
|
14192
|
-
if (value && typeof value === "object" &&
|
|
14230
|
+
if (value && typeof value === "object" && import_node_util21.types.isProxy(value))
|
|
14193
14231
|
failTrustedOutputBudget(row.budget, new ServiceAuthorizationError("unsupported selected proxy"));
|
|
14194
14232
|
if (Array.isArray(value)) {
|
|
14195
14233
|
const entries2 = shallowTrustedOutputArray(value, row.budget, depth);
|
|
@@ -14221,56 +14259,65 @@ var Service = class extends Base {
|
|
|
14221
14259
|
}
|
|
14222
14260
|
}
|
|
14223
14261
|
}
|
|
14224
|
-
async finalizePopulatePath(
|
|
14225
|
-
if (
|
|
14226
|
-
if (Array.isArray(
|
|
14227
|
-
const entries = this.populateInputArrays.get(
|
|
14262
|
+
async finalizePopulatePath(traversalValue, pathSegments, segmentIndex, targetMeta, initiatingOperation, parentHookContext, hookLimit, sharedGate, originalNode = traversalValue, completedReferences, receivingBudget, publication, parentAuthorization, outputAddress = []) {
|
|
14263
|
+
if (traversalValue === null || traversalValue === void 0) return;
|
|
14264
|
+
if (Array.isArray(traversalValue)) {
|
|
14265
|
+
const entries = this.populateInputArrays.get(targetMeta)?.get(traversalValue);
|
|
14228
14266
|
if (!entries) authorizationError("unregistered populate array");
|
|
14229
14267
|
for (const [index, el] of entries.entries()) {
|
|
14230
14268
|
await this.finalizePopulatePath(
|
|
14269
|
+
// Traversal value/path position: arrays do not consume a path segment.
|
|
14231
14270
|
el,
|
|
14232
|
-
|
|
14233
|
-
|
|
14234
|
-
|
|
14235
|
-
|
|
14236
|
-
|
|
14271
|
+
pathSegments,
|
|
14272
|
+
segmentIndex,
|
|
14273
|
+
// Target policy and initiating execution/gates.
|
|
14274
|
+
targetMeta,
|
|
14275
|
+
initiatingOperation,
|
|
14276
|
+
parentHookContext,
|
|
14237
14277
|
hookLimit,
|
|
14238
14278
|
sharedGate,
|
|
14239
|
-
|
|
14240
|
-
|
|
14241
|
-
budget
|
|
14279
|
+
// Original provenance.
|
|
14280
|
+
Array.isArray(originalNode) ? originalNode[index] : void 0,
|
|
14281
|
+
// Completed handoffs, receiving budget and publication.
|
|
14282
|
+
completedReferences,
|
|
14283
|
+
receivingBudget,
|
|
14242
14284
|
publication,
|
|
14285
|
+
// Parent authorization and receiving output address.
|
|
14243
14286
|
parentAuthorization,
|
|
14244
|
-
[...
|
|
14287
|
+
[...outputAddress, index]
|
|
14245
14288
|
);
|
|
14246
14289
|
}
|
|
14247
14290
|
return;
|
|
14248
14291
|
}
|
|
14249
|
-
if (typeof
|
|
14250
|
-
if (
|
|
14251
|
-
const key =
|
|
14252
|
-
let
|
|
14292
|
+
if (typeof traversalValue !== "object") return;
|
|
14293
|
+
if (segmentIndex >= pathSegments.length) return;
|
|
14294
|
+
const key = pathSegments[segmentIndex];
|
|
14295
|
+
let traversalChild;
|
|
14253
14296
|
let originalChild;
|
|
14254
|
-
const slots = this.populateInputSlots.get(
|
|
14297
|
+
const slots = this.populateInputSlots.get(targetMeta)?.get(traversalValue);
|
|
14255
14298
|
if (!slots?.has(key)) authorizationError("unregistered populate source slot");
|
|
14256
|
-
|
|
14257
|
-
originalChild =
|
|
14258
|
-
|
|
14299
|
+
traversalChild = slots.get(key);
|
|
14300
|
+
originalChild = traversalChild && typeof traversalChild === "object" ? getQueryReferenceOriginal(
|
|
14301
|
+
traversalChild,
|
|
14302
|
+
publication ?? outputPublicationFor(targetMeta.plan.authorization)
|
|
14303
|
+
) ?? traversalChild : traversalChild;
|
|
14304
|
+
if (traversalChild === void 0 || traversalChild === null) {
|
|
14259
14305
|
return;
|
|
14260
14306
|
}
|
|
14261
|
-
if (
|
|
14262
|
-
if (Array.isArray(
|
|
14263
|
-
const
|
|
14264
|
-
assertTrustedOutputBudget(
|
|
14307
|
+
if (segmentIndex === pathSegments.length - 1) {
|
|
14308
|
+
if (Array.isArray(traversalChild)) {
|
|
14309
|
+
const finalizeLeafValue = async (value, originalValue, depth) => {
|
|
14310
|
+
assertTrustedOutputBudget(receivingBudget);
|
|
14265
14311
|
if (Array.isArray(value)) {
|
|
14266
|
-
const entries = this.populateInputArrays.get(
|
|
14312
|
+
const entries = this.populateInputArrays.get(targetMeta)?.get(value);
|
|
14267
14313
|
if (!entries) authorizationError("unregistered populate array");
|
|
14268
14314
|
const output = [];
|
|
14269
14315
|
for (let index = 0; index < entries.length; index++)
|
|
14270
14316
|
defineTrustedOutputValue(
|
|
14271
14317
|
output,
|
|
14272
14318
|
String(index),
|
|
14273
|
-
await
|
|
14319
|
+
await finalizeLeafValue(
|
|
14320
|
+
// Traversed leaf, original provenance and receiving output depth.
|
|
14274
14321
|
entries[index],
|
|
14275
14322
|
Array.isArray(originalValue) ? originalValue[index] : void 0,
|
|
14276
14323
|
depth + 1
|
|
@@ -14279,84 +14326,106 @@ var Service = class extends Base {
|
|
|
14279
14326
|
return output;
|
|
14280
14327
|
}
|
|
14281
14328
|
if (this.isScalarPopulateValue(value))
|
|
14282
|
-
return copyAuthorizedReference(value, entryPath, { budget, depth }, true);
|
|
14329
|
+
return copyAuthorizedReference(value, entryPath, { budget: receivingBudget, depth }, true);
|
|
14283
14330
|
return this.finalizeSinglePopulateTarget(
|
|
14331
|
+
// Target value/policy and initiating execution/gates.
|
|
14284
14332
|
value,
|
|
14285
|
-
|
|
14286
|
-
|
|
14287
|
-
|
|
14333
|
+
targetMeta,
|
|
14334
|
+
initiatingOperation,
|
|
14335
|
+
parentHookContext,
|
|
14288
14336
|
hookLimit,
|
|
14289
14337
|
sharedGate,
|
|
14338
|
+
// Original provenance, never the finalized output.
|
|
14290
14339
|
originalValue,
|
|
14291
|
-
budget
|
|
14340
|
+
// Receiving budget/publication and independent parent authorization.
|
|
14341
|
+
receivingBudget,
|
|
14292
14342
|
publication,
|
|
14293
14343
|
parentAuthorization,
|
|
14344
|
+
// Receiving output depth, including nested arrays.
|
|
14294
14345
|
depth
|
|
14295
14346
|
);
|
|
14296
14347
|
};
|
|
14297
|
-
const entryPath = [...
|
|
14298
|
-
|
|
14348
|
+
const entryPath = [...outputAddress, key].join(".");
|
|
14349
|
+
completedReferences?.set(
|
|
14350
|
+
entryPath,
|
|
14351
|
+
await finalizeLeafValue(traversalChild, originalChild, outputAddress.length + 1)
|
|
14352
|
+
);
|
|
14299
14353
|
} else {
|
|
14300
|
-
if (this.isScalarPopulateValue(
|
|
14354
|
+
if (this.isScalarPopulateValue(traversalChild)) return;
|
|
14301
14355
|
const finalized = await this.finalizeSinglePopulateTarget(
|
|
14302
|
-
|
|
14303
|
-
|
|
14304
|
-
|
|
14305
|
-
|
|
14356
|
+
// Target value/policy and initiating execution/gates.
|
|
14357
|
+
traversalChild,
|
|
14358
|
+
targetMeta,
|
|
14359
|
+
initiatingOperation,
|
|
14360
|
+
parentHookContext,
|
|
14306
14361
|
hookLimit,
|
|
14307
14362
|
sharedGate,
|
|
14363
|
+
// Original provenance, never the finalized output.
|
|
14308
14364
|
originalChild,
|
|
14309
|
-
budget
|
|
14365
|
+
// Receiving budget/publication and independent parent authorization.
|
|
14366
|
+
receivingBudget,
|
|
14310
14367
|
publication,
|
|
14311
14368
|
parentAuthorization,
|
|
14312
|
-
|
|
14369
|
+
// Receiving output depth.
|
|
14370
|
+
outputAddress.length + 1
|
|
14313
14371
|
);
|
|
14314
|
-
|
|
14372
|
+
completedReferences?.set([...outputAddress, key].join("."), finalized);
|
|
14315
14373
|
}
|
|
14316
14374
|
} else {
|
|
14317
14375
|
await this.finalizePopulatePath(
|
|
14318
|
-
|
|
14319
|
-
|
|
14320
|
-
|
|
14321
|
-
|
|
14322
|
-
|
|
14323
|
-
|
|
14376
|
+
// Traversal value and next path position.
|
|
14377
|
+
traversalChild,
|
|
14378
|
+
pathSegments,
|
|
14379
|
+
segmentIndex + 1,
|
|
14380
|
+
// Target policy and initiating execution/gates.
|
|
14381
|
+
targetMeta,
|
|
14382
|
+
initiatingOperation,
|
|
14383
|
+
parentHookContext,
|
|
14324
14384
|
hookLimit,
|
|
14325
14385
|
sharedGate,
|
|
14386
|
+
// Original provenance.
|
|
14326
14387
|
originalChild,
|
|
14327
|
-
|
|
14328
|
-
|
|
14388
|
+
// Completed handoffs, receiving budget and publication.
|
|
14389
|
+
completedReferences,
|
|
14390
|
+
receivingBudget,
|
|
14329
14391
|
publication,
|
|
14392
|
+
// Parent authorization and receiving output address.
|
|
14330
14393
|
parentAuthorization,
|
|
14331
|
-
[...
|
|
14394
|
+
[...outputAddress, key]
|
|
14332
14395
|
);
|
|
14333
14396
|
}
|
|
14334
14397
|
}
|
|
14335
|
-
async finalizePopulateForSingleDoc(
|
|
14336
|
-
if (!
|
|
14398
|
+
async finalizePopulateForSingleDoc(receivingDocument, populateEntries, parentHookContext, initiatingOperation, hookLimit, sharedGate, parentAuthorization, completedReferences, receivingBudget, publication) {
|
|
14399
|
+
if (!receivingDocument || !Array.isArray(populateEntries) || populateEntries.length === 0) return;
|
|
14337
14400
|
for (const entry of populateEntries) {
|
|
14338
14401
|
if (!entry || typeof entry.path !== "string") continue;
|
|
14339
|
-
const
|
|
14340
|
-
if (!
|
|
14341
|
-
const
|
|
14342
|
-
if (
|
|
14402
|
+
const targetMeta = getPopulateTargetMeta(entry);
|
|
14403
|
+
if (!targetMeta) continue;
|
|
14404
|
+
const pathSegments = entry.path.split(".").filter(Boolean);
|
|
14405
|
+
if (pathSegments.length === 0) continue;
|
|
14343
14406
|
await this.finalizePopulatePath(
|
|
14344
|
-
|
|
14345
|
-
|
|
14407
|
+
// Traversal source and starting path position.
|
|
14408
|
+
getIncludeSource(receivingDocument),
|
|
14409
|
+
pathSegments,
|
|
14346
14410
|
0,
|
|
14347
|
-
|
|
14348
|
-
|
|
14349
|
-
|
|
14411
|
+
// Target policy and initiating execution/gates.
|
|
14412
|
+
targetMeta,
|
|
14413
|
+
initiatingOperation,
|
|
14414
|
+
parentHookContext,
|
|
14350
14415
|
hookLimit,
|
|
14351
14416
|
sharedGate,
|
|
14352
|
-
|
|
14353
|
-
|
|
14354
|
-
budget
|
|
14417
|
+
// Original provenance.
|
|
14418
|
+
getIncludeOriginal(receivingDocument, parentAuthorization),
|
|
14419
|
+
// Completed handoffs, receiving budget and publication.
|
|
14420
|
+
completedReferences,
|
|
14421
|
+
receivingBudget,
|
|
14355
14422
|
publication,
|
|
14423
|
+
// Parent authorization; the output address starts at its default root.
|
|
14356
14424
|
parentAuthorization
|
|
14357
14425
|
);
|
|
14358
14426
|
}
|
|
14359
14427
|
}
|
|
14428
|
+
// Eager log payloads only; callers retain query orchestration.
|
|
14360
14429
|
beginOp(op, filter2, extra) {
|
|
14361
14430
|
const startedAt = Date.now();
|
|
14362
14431
|
debug({
|
|
@@ -14602,13 +14671,17 @@ var Service = class extends Base {
|
|
|
14602
14671
|
if (Array.isArray(_populate) && _populate.length > 0) {
|
|
14603
14672
|
try {
|
|
14604
14673
|
await this.finalizePopulateForSingleDoc(
|
|
14674
|
+
// Receiving document and target entries.
|
|
14605
14675
|
doc,
|
|
14606
14676
|
_populate,
|
|
14677
|
+
// Initiating execution and gates.
|
|
14607
14678
|
context,
|
|
14608
14679
|
"read",
|
|
14609
14680
|
findOneHookLimit,
|
|
14610
14681
|
findOneGate,
|
|
14682
|
+
// Parent authorization.
|
|
14611
14683
|
state.authorization,
|
|
14684
|
+
// Completed handoffs, receiving budget and publication.
|
|
14612
14685
|
outputRow.references,
|
|
14613
14686
|
outputRow.budget,
|
|
14614
14687
|
outputRow.publication
|
|
@@ -14630,7 +14703,6 @@ var Service = class extends Base {
|
|
|
14630
14703
|
context,
|
|
14631
14704
|
includePermissions,
|
|
14632
14705
|
includeFieldPermissions,
|
|
14633
|
-
sharedGate: findOneGate,
|
|
14634
14706
|
stage: outputRow.stage,
|
|
14635
14707
|
budget: outputRow.budget,
|
|
14636
14708
|
publication: outputRow.publication,
|
|
@@ -14730,7 +14802,7 @@ var Service = class extends Base {
|
|
|
14730
14802
|
throw error2;
|
|
14731
14803
|
}
|
|
14732
14804
|
}
|
|
14733
|
-
async findPrepared(execution, preparedQuery, filter2, args, options
|
|
14805
|
+
async findPrepared(execution, preparedQuery, filter2, args, options) {
|
|
14734
14806
|
if (filter2 === false) return { success: false, kind: "error", code: "forbidden" /* Forbidden */, query: { filter: filter2 } };
|
|
14735
14807
|
const state = readServiceExecution(this, execution);
|
|
14736
14808
|
const virtualSnapshot = readServiceAuthorization(state.authorization, state.binding).configuration;
|
|
@@ -14890,13 +14962,17 @@ var Service = class extends Base {
|
|
|
14890
14962
|
this.asServiceHookContext(contexts[i]).fieldPermissionAccess = fieldPermissionAccess;
|
|
14891
14963
|
if (Array.isArray(filteredPopulate) && filteredPopulate.length > 0) {
|
|
14892
14964
|
await this.finalizePopulateForSingleDoc(
|
|
14965
|
+
// Receiving document and target entries.
|
|
14893
14966
|
doc,
|
|
14894
14967
|
filteredPopulate,
|
|
14968
|
+
// Initiating execution and gates.
|
|
14895
14969
|
contexts[i],
|
|
14896
14970
|
"list",
|
|
14897
14971
|
hookLimit,
|
|
14898
14972
|
sharedGate,
|
|
14973
|
+
// Parent authorization.
|
|
14899
14974
|
state.authorization,
|
|
14975
|
+
// Completed handoffs, receiving budget and publication.
|
|
14900
14976
|
outputRows2[i].references,
|
|
14901
14977
|
outputRows2[i].budget,
|
|
14902
14978
|
outputRows2[i].publication
|
|
@@ -14908,7 +14984,6 @@ var Service = class extends Base {
|
|
|
14908
14984
|
context: contexts[i],
|
|
14909
14985
|
includePermissions,
|
|
14910
14986
|
includeFieldPermissions,
|
|
14911
|
-
sharedGate,
|
|
14912
14987
|
privateAssociationField,
|
|
14913
14988
|
stage: outputRows2[i].stage,
|
|
14914
14989
|
budget: outputRows2[i].budget,
|
|
@@ -14957,7 +15032,7 @@ var Service = class extends Base {
|
|
|
14957
15032
|
throw error2;
|
|
14958
15033
|
}
|
|
14959
15034
|
}
|
|
14960
|
-
async createPrepared(execution, data, args, options
|
|
15035
|
+
async createPrepared(execution, data, args, options) {
|
|
14961
15036
|
assertModelInputComplexity(data, this.getRequestComplexity());
|
|
14962
15037
|
const state = readServiceExecution(this, execution);
|
|
14963
15038
|
const captured = readServiceAuthorization(state.authorization, state.binding);
|
|
@@ -15101,13 +15176,17 @@ var Service = class extends Base {
|
|
|
15101
15176
|
const doc = row.doc;
|
|
15102
15177
|
if (resolvedPopulate.length > 0) {
|
|
15103
15178
|
await this.finalizePopulateForSingleDoc(
|
|
15179
|
+
// Receiving document and target entries.
|
|
15104
15180
|
doc,
|
|
15105
15181
|
resolvedPopulate,
|
|
15182
|
+
// Initiating execution and gates.
|
|
15106
15183
|
contexts[index],
|
|
15107
15184
|
initiatingOperation,
|
|
15108
15185
|
hookLimit,
|
|
15109
15186
|
createGate,
|
|
15187
|
+
// Parent authorization.
|
|
15110
15188
|
outputState.authorization,
|
|
15189
|
+
// Completed handoffs, receiving budget and publication.
|
|
15111
15190
|
row.references,
|
|
15112
15191
|
row.budget,
|
|
15113
15192
|
row.publication
|
|
@@ -15119,7 +15198,6 @@ var Service = class extends Base {
|
|
|
15119
15198
|
context: contexts[index],
|
|
15120
15199
|
includePermissions,
|
|
15121
15200
|
includeFieldPermissions,
|
|
15122
|
-
sharedGate: createGate,
|
|
15123
15201
|
stage: row.stage,
|
|
15124
15202
|
budget: row.budget,
|
|
15125
15203
|
publication: row.publication,
|
|
@@ -15242,7 +15320,7 @@ var Service = class extends Base {
|
|
|
15242
15320
|
throw error2;
|
|
15243
15321
|
}
|
|
15244
15322
|
}
|
|
15245
|
-
async updateOnePrepared(execution, filter2, data, args, options
|
|
15323
|
+
async updateOnePrepared(execution, filter2, data, args, options) {
|
|
15246
15324
|
if (filter2 === false) return { success: false, kind: "error", code: "forbidden" /* Forbidden */, query: { filter: filter2 } };
|
|
15247
15325
|
assertModelInputComplexity(data, this.getRequestComplexity());
|
|
15248
15326
|
const state = readServiceExecution(this, execution);
|
|
@@ -15356,13 +15434,17 @@ var Service = class extends Base {
|
|
|
15356
15434
|
const updateHookLimit = this.getVirtualHookConcurrencyLimit();
|
|
15357
15435
|
const updateGate = this.hookGate;
|
|
15358
15436
|
await this.finalizePopulateForSingleDoc(
|
|
15437
|
+
// Receiving document and target entries.
|
|
15359
15438
|
row.doc,
|
|
15360
15439
|
_populate,
|
|
15440
|
+
// Initiating execution and gates.
|
|
15361
15441
|
context,
|
|
15362
15442
|
initiatingOperation,
|
|
15363
15443
|
updateHookLimit,
|
|
15364
15444
|
updateGate,
|
|
15445
|
+
// Parent authorization.
|
|
15365
15446
|
outputState.authorization,
|
|
15447
|
+
// Completed handoffs, receiving budget and publication.
|
|
15366
15448
|
row.references,
|
|
15367
15449
|
row.budget,
|
|
15368
15450
|
row.publication
|
|
@@ -17155,7 +17237,12 @@ var Core = class {
|
|
|
17155
17237
|
virtualNames
|
|
17156
17238
|
});
|
|
17157
17239
|
}
|
|
17158
|
-
/**
|
|
17240
|
+
/**
|
|
17241
|
+
* Request-only population: positional access admits source fields and supplies
|
|
17242
|
+
* the target default; descriptor access overrides only the target. No document
|
|
17243
|
+
* hooks, current document facts or captured parent output execution. Only named
|
|
17244
|
+
* response scopePath is supported; positional subPaths are removed.
|
|
17245
|
+
*/
|
|
17159
17246
|
async genPopulate(modelName, access = "read", _populate = null, options = {}) {
|
|
17160
17247
|
assertFieldHelperCall("genPopulate", arguments.length, 4, options, "populate");
|
|
17161
17248
|
const scopePath = requestFieldScope(options);
|
|
@@ -17201,7 +17288,7 @@ var Core = class {
|
|
|
17201
17288
|
const allowedParentPaths = await this.requestPopulateSelect(
|
|
17202
17289
|
sourceConfiguration,
|
|
17203
17290
|
permissions,
|
|
17204
|
-
|
|
17291
|
+
access,
|
|
17205
17292
|
[parentPath],
|
|
17206
17293
|
scopePath
|
|
17207
17294
|
);
|
|
@@ -17304,9 +17391,9 @@ var Core = class {
|
|
|
17304
17391
|
}
|
|
17305
17392
|
}
|
|
17306
17393
|
async prepare(modelName, allowedData, access, context) {
|
|
17307
|
-
const
|
|
17394
|
+
const prepare = getModelOption(modelName, `prepare.${access}`, null);
|
|
17308
17395
|
const permissions = this.getGlobalPermissions();
|
|
17309
|
-
return callHookChain(this.req,
|
|
17396
|
+
return callHookChain(this.req, prepare, allowedData, permissions, context);
|
|
17310
17397
|
}
|
|
17311
17398
|
async transform(modelName, doc, access, context) {
|
|
17312
17399
|
const transform = getModelOption(modelName, `transform.${access}`, null);
|