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