@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.mjs
CHANGED
|
@@ -1097,7 +1097,11 @@ function copyAuthorizationValue(value, configuration = false) {
|
|
|
1097
1097
|
if (typeof input === "string") prepareTrustedOutputPayload(budget, input);
|
|
1098
1098
|
return input;
|
|
1099
1099
|
}
|
|
1100
|
-
if (types5.isProxy(input))
|
|
1100
|
+
if (types5.isProxy(input)) {
|
|
1101
|
+
const error2 = new ServiceAuthorizationError("proxy snapshot input");
|
|
1102
|
+
console.error("[access-router] Authorization snapshot rejected a Proxy", error2);
|
|
1103
|
+
throw error2;
|
|
1104
|
+
}
|
|
1101
1105
|
const ownedCatalog = configuration === true ? readOwnedAuthorizationCatalogWork(input) : void 0;
|
|
1102
1106
|
if (ownedCatalog) {
|
|
1103
1107
|
preloadTrustedOutputBudget(budget, depth + ownedCatalog.depth, ownedCatalog.slots - 1);
|
|
@@ -9470,7 +9474,12 @@ var Base = class {
|
|
|
9470
9474
|
genIDFilter(id) {
|
|
9471
9475
|
return this.requestCore.genIDFilter(this.modelName, id);
|
|
9472
9476
|
}
|
|
9473
|
-
/**
|
|
9477
|
+
/**
|
|
9478
|
+
* Request-only population: positional access (default read) admits source fields
|
|
9479
|
+
* and supplies the target default; descriptor access overrides only the target.
|
|
9480
|
+
* No document hooks, current document facts or captured parent output execution.
|
|
9481
|
+
* The only option, scopePath, uses response segments, never positional subPaths.
|
|
9482
|
+
*/
|
|
9474
9483
|
async genPopulate(access, populate, options = {}) {
|
|
9475
9484
|
assertFieldHelperCall("genPopulate", arguments.length, 3, options, "populate");
|
|
9476
9485
|
return this.requestCore.genPopulate(this.modelName, access, populate, options);
|
|
@@ -10454,7 +10463,7 @@ var Base = class {
|
|
|
10454
10463
|
|
|
10455
10464
|
// src/services/service.ts
|
|
10456
10465
|
import { Document as Document5, mongo as mongo7 } from "mongoose";
|
|
10457
|
-
import { types as
|
|
10466
|
+
import { types as types18 } from "util";
|
|
10458
10467
|
import {
|
|
10459
10468
|
castArray as castArray3,
|
|
10460
10469
|
compact as compact2,
|
|
@@ -11153,14 +11162,13 @@ async function loadVirtualPopulateOutputRows(owner, inputs, plan, publicPopulate
|
|
|
11153
11162
|
}
|
|
11154
11163
|
|
|
11155
11164
|
// src/acl/output-field-filter.ts
|
|
11156
|
-
import { types as
|
|
11165
|
+
import { types as types16 } from "util";
|
|
11157
11166
|
import { isPlainObject as isPlainObject23 } from "@web-ts-toolkit/utils";
|
|
11158
11167
|
init_authorization_snapshot();
|
|
11159
11168
|
init_document_permissions_definition();
|
|
11160
11169
|
init_field_catalog();
|
|
11161
11170
|
|
|
11162
11171
|
// src/acl/output-field-policy.ts
|
|
11163
|
-
import { types as types15 } from "util";
|
|
11164
11172
|
import { isPlainObject as isPlainObject22 } from "@web-ts-toolkit/utils";
|
|
11165
11173
|
init_output_work_ledger();
|
|
11166
11174
|
var fieldPolicies = /* @__PURE__ */ new WeakMap();
|
|
@@ -11308,7 +11316,7 @@ init_concurrency();
|
|
|
11308
11316
|
|
|
11309
11317
|
// src/acl/output-helper-many-admission.ts
|
|
11310
11318
|
init_authorization_snapshot();
|
|
11311
|
-
import { types as
|
|
11319
|
+
import { types as types15 } from "util";
|
|
11312
11320
|
init_field_catalog();
|
|
11313
11321
|
init_output_work_ledger();
|
|
11314
11322
|
var intrinsicObjectKeys = /* @__PURE__ */ new Set([
|
|
@@ -11326,7 +11334,7 @@ var intrinsicObjectKeys = /* @__PURE__ */ new Set([
|
|
|
11326
11334
|
"toLocaleString"
|
|
11327
11335
|
]);
|
|
11328
11336
|
function exactRecord(value, keys2, label) {
|
|
11329
|
-
if (!value || typeof value !== "object" ||
|
|
11337
|
+
if (!value || typeof value !== "object" || types15.isProxy(value)) authorizationError(`invalid ${label}`);
|
|
11330
11338
|
const prototype = Object.getPrototypeOf(value);
|
|
11331
11339
|
if (prototype !== Object.prototype && prototype !== null) authorizationError(`invalid ${label} prototype`);
|
|
11332
11340
|
for (const key of keys2)
|
|
@@ -11367,7 +11375,7 @@ function exactRecord(value, keys2, label) {
|
|
|
11367
11375
|
return value;
|
|
11368
11376
|
}
|
|
11369
11377
|
function denseArray(value, maximum, label) {
|
|
11370
|
-
if (!value || typeof value !== "object" ||
|
|
11378
|
+
if (!value || typeof value !== "object" || types15.isProxy(value)) authorizationError(`invalid ${label}`);
|
|
11371
11379
|
if (!Array.isArray(value) || Object.getPrototypeOf(value) !== Array.prototype)
|
|
11372
11380
|
authorizationError(`${label} must be an ordinary dense Array`);
|
|
11373
11381
|
const length = Object.getOwnPropertyDescriptor(value, "length").value;
|
|
@@ -11596,7 +11604,7 @@ function prepareOutputValueCopy(plan) {
|
|
|
11596
11604
|
};
|
|
11597
11605
|
}
|
|
11598
11606
|
function copyAuthorizedReference(value, path, construction2, prepaid = false) {
|
|
11599
|
-
if (value && typeof value === "object" &&
|
|
11607
|
+
if (value && typeof value === "object" && types16.isProxy(value))
|
|
11600
11608
|
failTrustedOutputBudget(construction2.budget, new ServiceAuthorizationError("unsupported selected proxy"));
|
|
11601
11609
|
if (Array.isArray(value)) {
|
|
11602
11610
|
const entries = shallowTrustedOutputArray(value, construction2.budget, construction2.depth, prepaid);
|
|
@@ -11665,7 +11673,7 @@ function continueExistingOutput(value, stage, binding, owner, accept) {
|
|
|
11665
11673
|
readDocumentStage(stage, binding);
|
|
11666
11674
|
return accept(result2);
|
|
11667
11675
|
};
|
|
11668
|
-
if (!
|
|
11676
|
+
if (!types16.isPromise(value)) return checked(value);
|
|
11669
11677
|
readDocumentStage(stage, binding);
|
|
11670
11678
|
return trackPublicationWork(
|
|
11671
11679
|
owner,
|
|
@@ -11720,7 +11728,7 @@ function filterExistingOutput(source, plan, stage, construction2, owner, prepaid
|
|
|
11720
11728
|
const one = (value2, depth) => {
|
|
11721
11729
|
readDocumentStage(stage, binding);
|
|
11722
11730
|
visitTrustedOutput(construction2.budget, depth, 0);
|
|
11723
|
-
if (value2 && typeof value2 === "object" &&
|
|
11731
|
+
if (value2 && typeof value2 === "object" && types16.isProxy(value2))
|
|
11724
11732
|
failTrustedOutputBudget(construction2.budget, new ServiceAuthorizationError("unsupported selected proxy"));
|
|
11725
11733
|
if (Array.isArray(value2)) {
|
|
11726
11734
|
const entries = shallowTrustedOutputArray(value2, construction2.budget, depth, true);
|
|
@@ -11728,7 +11736,7 @@ function filterExistingOutput(source, plan, stage, construction2, owner, prepaid
|
|
|
11728
11736
|
const append = (start) => {
|
|
11729
11737
|
for (let index = start; index < entries.length; index++) {
|
|
11730
11738
|
const value3 = one(entries[index], depth + 1);
|
|
11731
|
-
if (
|
|
11739
|
+
if (types16.isPromise(value3))
|
|
11732
11740
|
return resume(value3, (result3) => {
|
|
11733
11741
|
values.push(result3 ?? null);
|
|
11734
11742
|
return append(index + 1);
|
|
@@ -11823,7 +11831,7 @@ function filterExistingOutput(source, plan, stage, construction2, owner, prepaid
|
|
|
11823
11831
|
const walk = (start) => {
|
|
11824
11832
|
for (let index = start; index < selected.length; index++) {
|
|
11825
11833
|
const value = fieldValue(selected[index]);
|
|
11826
|
-
if (
|
|
11834
|
+
if (types16.isPromise(value)) return resume(value, () => walk(index + 1));
|
|
11827
11835
|
}
|
|
11828
11836
|
return finish();
|
|
11829
11837
|
};
|
|
@@ -11980,7 +11988,7 @@ init_public_admission();
|
|
|
11980
11988
|
init_document();
|
|
11981
11989
|
|
|
11982
11990
|
// src/output/finalize-model-output.ts
|
|
11983
|
-
import { types as
|
|
11991
|
+
import { types as types17 } from "util";
|
|
11984
11992
|
import { isPlainObject as isPlainObject24 } from "@web-ts-toolkit/utils";
|
|
11985
11993
|
init_trusted_output_materialization();
|
|
11986
11994
|
init_authorization_snapshot();
|
|
@@ -12058,7 +12066,7 @@ function assertFinalizer(args) {
|
|
|
12058
12066
|
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("."))
|
|
12059
12067
|
authorizationError("finalizer call/model/scope/access mismatch");
|
|
12060
12068
|
}
|
|
12061
|
-
function
|
|
12069
|
+
function prepareFinalizer(args) {
|
|
12062
12070
|
assertFinalizer(args);
|
|
12063
12071
|
const configuration = readServiceFinalizerConfiguration(args.plan.authorization, args.plan.authorizationBinding);
|
|
12064
12072
|
const virtuals = scopeVirtuals(configuration.virtuals, args.scopePath ?? args.plan.scopePath ?? []);
|
|
@@ -12070,7 +12078,7 @@ function prepare(args) {
|
|
|
12070
12078
|
)
|
|
12071
12079
|
};
|
|
12072
12080
|
}
|
|
12073
|
-
async function
|
|
12081
|
+
async function finalizeOutputDocument(args, preparation2) {
|
|
12074
12082
|
assertFinalizer(args);
|
|
12075
12083
|
const plan = args.plan, binding = plan.authorizationBinding, authorization = plan.authorization;
|
|
12076
12084
|
const owner = args.publication ?? outputPublicationFor(authorization);
|
|
@@ -12091,7 +12099,7 @@ async function finalizeSingleDoc(args, prepared) {
|
|
|
12091
12099
|
failTrustedOutputBudget(budget, new ServiceAuthorizationError("cyclic selected document output"));
|
|
12092
12100
|
const nextLineage = new Set(lineage).add(source);
|
|
12093
12101
|
visitTrustedOutput(budget, depth, args.prepaid ? 0 : 1);
|
|
12094
|
-
await
|
|
12102
|
+
await preparation2.resolve({
|
|
12095
12103
|
authorization,
|
|
12096
12104
|
binding,
|
|
12097
12105
|
snapshot: source,
|
|
@@ -12146,11 +12154,11 @@ async function finalizeSingleDoc(args, prepared) {
|
|
|
12146
12154
|
lineage: nextLineage,
|
|
12147
12155
|
prepaid: true
|
|
12148
12156
|
};
|
|
12149
|
-
const childPreparation =
|
|
12157
|
+
const childPreparation = prepareFinalizer(base);
|
|
12150
12158
|
const one = async (value2, childDepth, childAddress, ancestors) => {
|
|
12151
12159
|
assertOutputPublication(owner);
|
|
12152
12160
|
visitTrustedOutput(budget, childDepth, 0);
|
|
12153
|
-
if (value2 && typeof value2 === "object" &&
|
|
12161
|
+
if (value2 && typeof value2 === "object" && types17.isProxy(value2))
|
|
12154
12162
|
failTrustedOutputBudget(budget, new ServiceAuthorizationError("unsupported selected proxy"));
|
|
12155
12163
|
if (Array.isArray(value2)) {
|
|
12156
12164
|
if (ancestors.has(value2))
|
|
@@ -12170,7 +12178,7 @@ async function finalizeSingleDoc(args, prepared) {
|
|
|
12170
12178
|
failTrustedOutputBudget(budget, new ServiceAuthorizationError("unsupported selected embedded value"));
|
|
12171
12179
|
return null;
|
|
12172
12180
|
}
|
|
12173
|
-
return
|
|
12181
|
+
return finalizeOutputDocument(
|
|
12174
12182
|
{
|
|
12175
12183
|
...base,
|
|
12176
12184
|
input: value2,
|
|
@@ -12200,7 +12208,7 @@ async function finalizeSingleDoc(args, prepared) {
|
|
|
12200
12208
|
}
|
|
12201
12209
|
for (const { path, value } of args.includeAttachments ?? [])
|
|
12202
12210
|
setTrustedOutputPath(working, path, value, budget, depth);
|
|
12203
|
-
for (const field of
|
|
12211
|
+
for (const field of preparation2.virtualNames) delete working[field];
|
|
12204
12212
|
const candidates = plan.candidates ?? [];
|
|
12205
12213
|
const hasDependencies = (dependsOn) => dependsOn.every((key) => Object.hasOwn(working, key) && working[key] !== void 0);
|
|
12206
12214
|
const needsView = candidates.some(
|
|
@@ -12315,7 +12323,7 @@ async function finalizeSingleDoc(args, prepared) {
|
|
|
12315
12323
|
);
|
|
12316
12324
|
}
|
|
12317
12325
|
if (args.completeOutput) await args.completeOutput(output, stage, construction2);
|
|
12318
|
-
else retainOutputMetadata(output, source,
|
|
12326
|
+
else retainOutputMetadata(output, source, preparation2.configuration, binding.scopePath ?? [], construction2);
|
|
12319
12327
|
readDocumentStage(stage, binding);
|
|
12320
12328
|
assertTrustedOutputBudget(budget);
|
|
12321
12329
|
assertOutputPublication(owner);
|
|
@@ -12327,7 +12335,7 @@ async function finalizeModelOutput(args) {
|
|
|
12327
12335
|
const owner = args.publication ?? outputPublicationFor(args.plan.authorization);
|
|
12328
12336
|
const work = async () => {
|
|
12329
12337
|
try {
|
|
12330
|
-
return await
|
|
12338
|
+
return await finalizeOutputDocument({ ...args, publication: owner }, prepareFinalizer(args));
|
|
12331
12339
|
} catch (error2) {
|
|
12332
12340
|
failOutputPublication(owner, error2);
|
|
12333
12341
|
throw error2;
|
|
@@ -12342,12 +12350,12 @@ async function finalizeModelOutputs(args) {
|
|
|
12342
12350
|
const owner = args.publication ?? outputPublicationFor(args.plan.authorization);
|
|
12343
12351
|
const work = async () => {
|
|
12344
12352
|
const base = { ...rest, input: void 0, publication: owner };
|
|
12345
|
-
const
|
|
12353
|
+
const preparation2 = prepareFinalizer(base);
|
|
12346
12354
|
const gate = getRequestWorkState(args.request, args.plan.authorizationBinding.runtime).hookGate;
|
|
12347
12355
|
return mapWithConcurrencyLimit(
|
|
12348
12356
|
inputs,
|
|
12349
12357
|
gate.limit,
|
|
12350
|
-
(input, index) =>
|
|
12358
|
+
(input, index) => finalizeOutputDocument(
|
|
12351
12359
|
{
|
|
12352
12360
|
...base,
|
|
12353
12361
|
input,
|
|
@@ -12356,7 +12364,7 @@ async function finalizeModelOutputs(args) {
|
|
|
12356
12364
|
completedReferences: rowReferences?.[index] ?? rest.completedReferences,
|
|
12357
12365
|
onFinalized: rest.onFinalized ? (output, context) => rest.onFinalized(output, context, index) : void 0
|
|
12358
12366
|
},
|
|
12359
|
-
|
|
12367
|
+
preparation2
|
|
12360
12368
|
),
|
|
12361
12369
|
(error2) => failOutputPublication(owner, error2)
|
|
12362
12370
|
);
|
|
@@ -12474,7 +12482,6 @@ async function finalizeSubdocumentRows(service, prepared, parent, rows2, populat
|
|
|
12474
12482
|
receivingModelName: state.binding.modelName,
|
|
12475
12483
|
inputs,
|
|
12476
12484
|
plan,
|
|
12477
|
-
snapshot: readServiceAuthorization(state.authorization, state.binding).configuration,
|
|
12478
12485
|
request: service.getServiceRequest(),
|
|
12479
12486
|
context,
|
|
12480
12487
|
...state.access,
|
|
@@ -12491,7 +12498,6 @@ function copySubdocumentParent(parent) {
|
|
|
12491
12498
|
}
|
|
12492
12499
|
|
|
12493
12500
|
// src/services/service.ts
|
|
12494
|
-
init_permissions_alias();
|
|
12495
12501
|
init_trusted_output_materialization();
|
|
12496
12502
|
init_document();
|
|
12497
12503
|
|
|
@@ -13400,6 +13406,53 @@ async function getParentDoc(service, id, sub, args, options) {
|
|
|
13400
13406
|
});
|
|
13401
13407
|
}
|
|
13402
13408
|
|
|
13409
|
+
// src/services/model-output-metadata.ts
|
|
13410
|
+
init_trusted_output_materialization();
|
|
13411
|
+
init_permissions_alias();
|
|
13412
|
+
function createModelOutputMetadataCompletion(args, binding, configuration, readFieldPermissionAccess, queryFieldPermissionAccess) {
|
|
13413
|
+
return async (output, stage, construction2) => {
|
|
13414
|
+
const { grants } = readDocumentStage(stage, binding);
|
|
13415
|
+
const source = getIncludeSource(args.doc);
|
|
13416
|
+
if (args.privateAssociationField) unsetTrustedOutputPath(output, args.privateAssociationField, args.budget);
|
|
13417
|
+
restoreIncludeOutput(args.doc, output, construction2);
|
|
13418
|
+
const field = configuration.documentPermissionField ?? "_permissions";
|
|
13419
|
+
unsetTrustedOutputPath(output, field, args.budget);
|
|
13420
|
+
removeGeneratedPermissionsAlias(output);
|
|
13421
|
+
if (configuration.stripPermissionsField) return;
|
|
13422
|
+
const exposed = configuration.exposedDocPermissionKeys;
|
|
13423
|
+
const metadata = {};
|
|
13424
|
+
const metadataDepth = construction2.depth + field.split(".").length;
|
|
13425
|
+
setTrustedOutputPath(output, field, metadata, args.budget, construction2.depth);
|
|
13426
|
+
if (args.includePermissions || args.includeFieldPermissions) {
|
|
13427
|
+
for (const key of Object.keys(grants)) {
|
|
13428
|
+
visitTrustedOutput(args.budget, metadataDepth + 1);
|
|
13429
|
+
if (!exposed || exposed.includes(key)) defineTrustedOutputValue(metadata, key, grants[key]);
|
|
13430
|
+
}
|
|
13431
|
+
}
|
|
13432
|
+
if (args.includeFieldPermissions && !configuration.disableFieldPermissions) {
|
|
13433
|
+
const rowAccess = readFieldPermissionAccess() ?? await queryFieldPermissionAccess([source._id], args.publication);
|
|
13434
|
+
const id = String(source._id);
|
|
13435
|
+
const map2 = async (access, allowed) => {
|
|
13436
|
+
visitTrustedOutput(args.budget, metadataDepth + 1);
|
|
13437
|
+
const paths = allowed ? await requestOutputFieldPaths(stage, binding, access, {
|
|
13438
|
+
budget: args.budget,
|
|
13439
|
+
depth: metadataDepth + 1
|
|
13440
|
+
}) : [];
|
|
13441
|
+
if (!paths.length) visitTrustedOutput(args.budget, metadataDepth + 2);
|
|
13442
|
+
return paths.length ? Object.fromEntries(paths.map((path) => [path, true])) : { $: "_" };
|
|
13443
|
+
};
|
|
13444
|
+
defineTrustedOutputValue(metadata, "_view", await map2("read", rowAccess.readIds?.has(id) ?? false));
|
|
13445
|
+
defineTrustedOutputValue(metadata, "_edit", await map2("update", rowAccess.updateIds?.has(id) ?? false));
|
|
13446
|
+
} else if (!args.includePermissions && !configuration.disableFieldPermissions) {
|
|
13447
|
+
visitTrustedOutput(args.budget, metadataDepth + 1, 2);
|
|
13448
|
+
visitTrustedOutput(args.budget, metadataDepth + 2, 2);
|
|
13449
|
+
defineTrustedOutputValue(metadata, "_view", { $: "_" });
|
|
13450
|
+
defineTrustedOutputValue(metadata, "_edit", { $: "_" });
|
|
13451
|
+
}
|
|
13452
|
+
attachPermissionsAlias(output, field);
|
|
13453
|
+
};
|
|
13454
|
+
}
|
|
13455
|
+
|
|
13403
13456
|
// src/services/service.ts
|
|
13404
13457
|
var assertModelDocument = (value, modelName, hookName) => {
|
|
13405
13458
|
if (isDocument2(value)) {
|
|
@@ -13453,13 +13506,17 @@ var Service = class extends Base {
|
|
|
13453
13506
|
rows2,
|
|
13454
13507
|
this.hookGate.limit,
|
|
13455
13508
|
(doc, index) => this.finalizePopulateForSingleDoc(
|
|
13509
|
+
// Receiving document and target entries.
|
|
13456
13510
|
doc,
|
|
13457
13511
|
populate,
|
|
13512
|
+
// Initiating execution and gates.
|
|
13458
13513
|
context,
|
|
13459
13514
|
state.access.operation,
|
|
13460
13515
|
this.hookGate.limit,
|
|
13461
13516
|
this.hookGate,
|
|
13517
|
+
// Parent authorization.
|
|
13462
13518
|
state.authorization,
|
|
13519
|
+
// Completed handoffs, receiving budget and publication.
|
|
13463
13520
|
references[index],
|
|
13464
13521
|
budgets2[index],
|
|
13465
13522
|
state.publication
|
|
@@ -13509,9 +13566,9 @@ var Service = class extends Base {
|
|
|
13509
13566
|
},
|
|
13510
13567
|
findOne: (execution, filter2, args, options) => this.findOnePrepared(execution, filter2, args, options),
|
|
13511
13568
|
findOneCondition: (execution, filter2, args, options) => this.#findOneConditionPrepared(execution, filter2, args, options),
|
|
13512
|
-
find: (execution, query, filter2, args, options
|
|
13513
|
-
updateOne: (execution, filter2, data, args, options
|
|
13514
|
-
create: (execution, data, args, options
|
|
13569
|
+
find: (execution, query, filter2, args, options) => this.findPrepared(execution, query, filter2, args, options),
|
|
13570
|
+
updateOne: (execution, filter2, data, args, options) => this.updateOnePrepared(execution, filter2, data, args, options),
|
|
13571
|
+
create: (execution, data, args, options) => this.createPrepared(execution, data, args, options),
|
|
13515
13572
|
exists: async (filter2, includeId) => {
|
|
13516
13573
|
const result2 = await this.model.exists(filter2);
|
|
13517
13574
|
return {
|
|
@@ -13722,7 +13779,6 @@ var Service = class extends Base {
|
|
|
13722
13779
|
receivingModelName: this.modelName,
|
|
13723
13780
|
input: args.doc,
|
|
13724
13781
|
plan,
|
|
13725
|
-
snapshot: configuration,
|
|
13726
13782
|
virtualAccess: access.virtualAccess,
|
|
13727
13783
|
outputAccess: access.outputAccess,
|
|
13728
13784
|
docPermissionsAccess: access.docPermissionsAccess,
|
|
@@ -13735,47 +13791,13 @@ var Service = class extends Base {
|
|
|
13735
13791
|
completedReferences: args.references,
|
|
13736
13792
|
includeAttachments: getIncludeAttachments(args.doc),
|
|
13737
13793
|
virtualPopulateRow: getVirtualPopulateRow(getIncludeOriginal(args.doc, authorization)),
|
|
13738
|
-
completeOutput:
|
|
13739
|
-
|
|
13740
|
-
|
|
13741
|
-
|
|
13742
|
-
|
|
13743
|
-
|
|
13744
|
-
|
|
13745
|
-
removeGeneratedPermissionsAlias(output);
|
|
13746
|
-
if (configuration.stripPermissionsField) return;
|
|
13747
|
-
const exposed = configuration.exposedDocPermissionKeys;
|
|
13748
|
-
const metadata = {};
|
|
13749
|
-
const metadataDepth = construction2.depth + field.split(".").length;
|
|
13750
|
-
setTrustedOutputPath(output, field, metadata, args.budget, construction2.depth);
|
|
13751
|
-
if (args.includePermissions || args.includeFieldPermissions) {
|
|
13752
|
-
for (const key of Object.keys(grants)) {
|
|
13753
|
-
visitTrustedOutput(args.budget, metadataDepth + 1);
|
|
13754
|
-
if (!exposed || exposed.includes(key)) defineTrustedOutputValue(metadata, key, grants[key]);
|
|
13755
|
-
}
|
|
13756
|
-
}
|
|
13757
|
-
if (args.includeFieldPermissions && !configuration.disableFieldPermissions) {
|
|
13758
|
-
const rowAccess = this.asServiceHookContext(context).fieldPermissionAccess ?? await this.getFieldPermissionAccess([source._id], args.publication);
|
|
13759
|
-
const id = String(source._id);
|
|
13760
|
-
const map2 = async (access2, allowed) => {
|
|
13761
|
-
visitTrustedOutput(args.budget, metadataDepth + 1);
|
|
13762
|
-
const paths = allowed ? await requestOutputFieldPaths(stage, binding, access2, {
|
|
13763
|
-
budget: args.budget,
|
|
13764
|
-
depth: metadataDepth + 1
|
|
13765
|
-
}) : [];
|
|
13766
|
-
if (!paths.length) visitTrustedOutput(args.budget, metadataDepth + 2);
|
|
13767
|
-
return paths.length ? Object.fromEntries(paths.map((path) => [path, true])) : { $: "_" };
|
|
13768
|
-
};
|
|
13769
|
-
defineTrustedOutputValue(metadata, "_view", await map2("read", rowAccess.readIds?.has(id) ?? false));
|
|
13770
|
-
defineTrustedOutputValue(metadata, "_edit", await map2("update", rowAccess.updateIds?.has(id) ?? false));
|
|
13771
|
-
} else if (!args.includePermissions && !configuration.disableFieldPermissions) {
|
|
13772
|
-
visitTrustedOutput(args.budget, metadataDepth + 1, 2);
|
|
13773
|
-
visitTrustedOutput(args.budget, metadataDepth + 2, 2);
|
|
13774
|
-
defineTrustedOutputValue(metadata, "_view", { $: "_" });
|
|
13775
|
-
defineTrustedOutputValue(metadata, "_edit", { $: "_" });
|
|
13776
|
-
}
|
|
13777
|
-
attachPermissionsAlias(output, field);
|
|
13778
|
-
},
|
|
13794
|
+
completeOutput: createModelOutputMetadataCompletion(
|
|
13795
|
+
args,
|
|
13796
|
+
binding,
|
|
13797
|
+
configuration,
|
|
13798
|
+
() => this.asServiceHookContext(context).fieldPermissionAccess,
|
|
13799
|
+
(ids, publication) => this.getFieldPermissionAccess(ids, publication)
|
|
13800
|
+
),
|
|
13779
13801
|
onFinalized: (_output, outputContext) => {
|
|
13780
13802
|
finalizedContext = outputContext;
|
|
13781
13803
|
}
|
|
@@ -13904,13 +13926,17 @@ var Service = class extends Base {
|
|
|
13904
13926
|
this.registerPopulateRecipients([{ doc: parentDoc, budget, publication }], populateEntries);
|
|
13905
13927
|
await runOutputPublication(publication, async () => {
|
|
13906
13928
|
await this.finalizePopulateForSingleDoc(
|
|
13929
|
+
// Receiving document and target entries.
|
|
13907
13930
|
parentDoc,
|
|
13908
13931
|
populateEntries,
|
|
13932
|
+
// Initiating execution and gates.
|
|
13909
13933
|
parentContext,
|
|
13910
13934
|
parentOperation,
|
|
13911
13935
|
limit,
|
|
13912
13936
|
gate,
|
|
13937
|
+
// Parent authorization.
|
|
13913
13938
|
void 0,
|
|
13939
|
+
// Completed handoffs, receiving budget and publication.
|
|
13914
13940
|
references,
|
|
13915
13941
|
budget,
|
|
13916
13942
|
publication
|
|
@@ -13993,7 +14019,11 @@ var Service = class extends Base {
|
|
|
13993
14019
|
assertPopulateAccess(targetAccess);
|
|
13994
14020
|
const sourceState = classifyEffectiveFieldAuthorization({
|
|
13995
14021
|
path: descriptor.path,
|
|
13996
|
-
rules: extractOutputFieldRules(
|
|
14022
|
+
rules: extractOutputFieldRules(
|
|
14023
|
+
captured.configuration.permissionSchema,
|
|
14024
|
+
descriptor.path,
|
|
14025
|
+
captured.access.outputAccess
|
|
14026
|
+
),
|
|
13997
14027
|
outputFields: captured.authorization.outputFields,
|
|
13998
14028
|
globalPermissions: getAuthorizationPermissions(state.authorization, state.binding),
|
|
13999
14029
|
modelPermissionPrefix: captured.configuration.modelPermissionPrefix
|
|
@@ -14068,10 +14098,10 @@ var Service = class extends Base {
|
|
|
14068
14098
|
if (value === null || value === void 0) return true;
|
|
14069
14099
|
if (typeof value === "string" || typeof value === "number" || typeof value === "bigint" || typeof value === "boolean")
|
|
14070
14100
|
return true;
|
|
14071
|
-
if (
|
|
14101
|
+
if (types18.isProxy(value)) return false;
|
|
14072
14102
|
let record3 = value;
|
|
14073
14103
|
for (let hops = 0; record3 && hops <= 100; hops++) {
|
|
14074
|
-
if (
|
|
14104
|
+
if (types18.isProxy(record3)) return false;
|
|
14075
14105
|
if (record3 === mongo7.BSON.BSONValue.prototype) return true;
|
|
14076
14106
|
const slot = Object.getOwnPropertyDescriptor(record3, "_bsontype");
|
|
14077
14107
|
if (slot && "value" in slot) return typeof slot.value === "string";
|
|
@@ -14084,69 +14114,77 @@ var Service = class extends Base {
|
|
|
14084
14114
|
const original = getQueryReferenceOriginal(value, publication) ?? value;
|
|
14085
14115
|
return getVirtualPopulatePublicIdentity(value) ?? getVirtualPopulatePublicIdentity(original) ?? original;
|
|
14086
14116
|
}
|
|
14087
|
-
async finalizeSinglePopulateTarget(
|
|
14088
|
-
if (
|
|
14089
|
-
if (this.isScalarPopulateValue(
|
|
14090
|
-
const isDoc = !
|
|
14091
|
-
if (!isDoc)
|
|
14092
|
-
|
|
14117
|
+
async finalizeSinglePopulateTarget(targetValue, targetMeta, initiatingOperation, parentHookContext, hookLimit, sharedGate, sourceTarget = targetValue, receivingBudget, publication, parentAuthorization, receivingDepth = 1) {
|
|
14118
|
+
if (targetValue === null || targetValue === void 0) return targetValue;
|
|
14119
|
+
if (this.isScalarPopulateValue(targetValue)) return targetValue;
|
|
14120
|
+
const isDoc = !types18.isProxy(targetValue) && (isPlainObject27(targetValue) || targetValue instanceof Document5);
|
|
14121
|
+
if (!isDoc)
|
|
14122
|
+
failTrustedOutputBudget(receivingBudget, new ServiceAuthorizationError("unsupported populated target"));
|
|
14123
|
+
let cache = this.populateOutputCache.get(targetMeta);
|
|
14093
14124
|
if (!cache) {
|
|
14094
14125
|
cache = /* @__PURE__ */ new WeakMap();
|
|
14095
|
-
this.populateOutputCache.set(
|
|
14126
|
+
this.populateOutputCache.set(targetMeta, cache);
|
|
14096
14127
|
if (publication)
|
|
14097
14128
|
retainPublicationResource(publication, () => {
|
|
14098
|
-
this.populateOutputCache.delete(
|
|
14099
|
-
this.populateBudgetRecipients.delete(
|
|
14100
|
-
this.populateInputSlots.delete(
|
|
14101
|
-
this.populateInputArrays.delete(
|
|
14129
|
+
this.populateOutputCache.delete(targetMeta);
|
|
14130
|
+
this.populateBudgetRecipients.delete(targetMeta);
|
|
14131
|
+
this.populateInputSlots.delete(targetMeta);
|
|
14132
|
+
this.populateInputArrays.delete(targetMeta);
|
|
14102
14133
|
});
|
|
14103
14134
|
}
|
|
14104
|
-
const
|
|
14105
|
-
const
|
|
14106
|
-
const
|
|
14107
|
-
const
|
|
14108
|
-
if (!
|
|
14135
|
+
const sourceIdentity = sourceTarget && typeof sourceTarget === "object" ? sourceTarget : targetValue;
|
|
14136
|
+
const publicationOwner = publication ?? outputPublicationFor(targetMeta.plan.authorization);
|
|
14137
|
+
const targetIdentity = this.populateTargetIdentity(targetValue, publicationOwner);
|
|
14138
|
+
const receivingOccurrences = this.populateBudgetRecipients.get(targetMeta)?.get(targetIdentity);
|
|
14139
|
+
if (!receivingOccurrences?.some((edge) => edge.budget === receivingBudget && edge.depth === receivingDepth))
|
|
14109
14140
|
authorizationError("populate target requires preregistered receiving occurrences");
|
|
14110
|
-
const existing = cache.get(
|
|
14141
|
+
const existing = cache.get(targetIdentity);
|
|
14111
14142
|
if (existing) {
|
|
14112
|
-
const
|
|
14143
|
+
const cachedTargetOutput = await existing;
|
|
14113
14144
|
return materializeTrustedOutputValue(
|
|
14114
|
-
|
|
14115
|
-
|
|
14116
|
-
|
|
14145
|
+
cachedTargetOutput,
|
|
14146
|
+
targetMeta.plan.receivingModelName ?? "",
|
|
14147
|
+
receivingBudget,
|
|
14117
14148
|
{ keep: () => true },
|
|
14118
|
-
|
|
14149
|
+
receivingDepth
|
|
14119
14150
|
);
|
|
14120
14151
|
}
|
|
14121
14152
|
const targetContext = createModelOutputContext({
|
|
14122
|
-
modelName:
|
|
14123
|
-
operation:
|
|
14124
|
-
virtualAccess:
|
|
14125
|
-
outputAccess:
|
|
14126
|
-
docPermissionsAccess:
|
|
14127
|
-
resolvedQuery:
|
|
14153
|
+
modelName: targetMeta.targetModelName,
|
|
14154
|
+
operation: parentHookContext.operation ?? initiatingOperation,
|
|
14155
|
+
virtualAccess: targetMeta.virtualAccess,
|
|
14156
|
+
outputAccess: targetMeta.outputAccess,
|
|
14157
|
+
docPermissionsAccess: targetMeta.docPermissionsAccess,
|
|
14158
|
+
resolvedQuery: parentHookContext.resolvedQuery
|
|
14128
14159
|
});
|
|
14129
|
-
bindOutputPublication(
|
|
14130
|
-
const
|
|
14131
|
-
const
|
|
14132
|
-
receivingModelName:
|
|
14133
|
-
input: parentAuthorization && readServiceAuthorizationMode(parentAuthorization, getServiceExecutors(this).binding()) === "isolated" && readServiceAuthorizationMode(
|
|
14134
|
-
virtualAccess:
|
|
14135
|
-
outputAccess:
|
|
14136
|
-
docPermissionsAccess:
|
|
14160
|
+
bindOutputPublication(targetMeta.plan.authorization, publicationOwner);
|
|
14161
|
+
const targetConstructionBudget = createReceivingOutputBudget(receivingOccurrences);
|
|
14162
|
+
const pendingTargetOutput = finalizeModelOutput({
|
|
14163
|
+
receivingModelName: targetMeta.targetModelName,
|
|
14164
|
+
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,
|
|
14165
|
+
virtualAccess: targetMeta.virtualAccess,
|
|
14166
|
+
outputAccess: targetMeta.outputAccess,
|
|
14167
|
+
docPermissionsAccess: targetMeta.docPermissionsAccess,
|
|
14137
14168
|
scopePath: [],
|
|
14138
|
-
plan:
|
|
14139
|
-
snapshot: meta.snapshot,
|
|
14169
|
+
plan: targetMeta.plan,
|
|
14140
14170
|
request: this.req,
|
|
14141
14171
|
context: targetContext,
|
|
14142
|
-
operation:
|
|
14143
|
-
publication:
|
|
14144
|
-
outputBudget:
|
|
14145
|
-
virtualPopulateRow: getVirtualPopulateRow(
|
|
14172
|
+
operation: parentHookContext.operation ?? initiatingOperation,
|
|
14173
|
+
publication: publicationOwner,
|
|
14174
|
+
outputBudget: targetConstructionBudget,
|
|
14175
|
+
virtualPopulateRow: getVirtualPopulateRow(sourceIdentity) ?? getVirtualPopulateRow(
|
|
14176
|
+
getQueryReferenceOriginal(targetValue, publicationOwner) ?? targetValue
|
|
14177
|
+
)
|
|
14146
14178
|
});
|
|
14147
|
-
cache.set(
|
|
14148
|
-
const
|
|
14149
|
-
return materializeTrustedOutputValue(
|
|
14179
|
+
cache.set(targetIdentity, pendingTargetOutput);
|
|
14180
|
+
const finalizedTargetOutput = await pendingTargetOutput;
|
|
14181
|
+
return materializeTrustedOutputValue(
|
|
14182
|
+
finalizedTargetOutput,
|
|
14183
|
+
targetMeta.targetModelName,
|
|
14184
|
+
receivingBudget,
|
|
14185
|
+
{ keep: () => true },
|
|
14186
|
+
receivingDepth
|
|
14187
|
+
);
|
|
14150
14188
|
}
|
|
14151
14189
|
/** Register every actual receiving occurrence before a batched/shared target starts construction. */
|
|
14152
14190
|
registerPopulateRecipients(rows2, entries) {
|
|
@@ -14169,7 +14207,7 @@ var Service = class extends Base {
|
|
|
14169
14207
|
for (const row of rows2) {
|
|
14170
14208
|
const walk = (value, index, depth) => {
|
|
14171
14209
|
visitTrustedOutput(row.budget, depth, 0);
|
|
14172
|
-
if (value && typeof value === "object" &&
|
|
14210
|
+
if (value && typeof value === "object" && types18.isProxy(value))
|
|
14173
14211
|
failTrustedOutputBudget(row.budget, new ServiceAuthorizationError("unsupported selected proxy"));
|
|
14174
14212
|
if (Array.isArray(value)) {
|
|
14175
14213
|
const entries2 = shallowTrustedOutputArray(value, row.budget, depth);
|
|
@@ -14201,56 +14239,65 @@ var Service = class extends Base {
|
|
|
14201
14239
|
}
|
|
14202
14240
|
}
|
|
14203
14241
|
}
|
|
14204
|
-
async finalizePopulatePath(
|
|
14205
|
-
if (
|
|
14206
|
-
if (Array.isArray(
|
|
14207
|
-
const entries = this.populateInputArrays.get(
|
|
14242
|
+
async finalizePopulatePath(traversalValue, pathSegments, segmentIndex, targetMeta, initiatingOperation, parentHookContext, hookLimit, sharedGate, originalNode = traversalValue, completedReferences, receivingBudget, publication, parentAuthorization, outputAddress = []) {
|
|
14243
|
+
if (traversalValue === null || traversalValue === void 0) return;
|
|
14244
|
+
if (Array.isArray(traversalValue)) {
|
|
14245
|
+
const entries = this.populateInputArrays.get(targetMeta)?.get(traversalValue);
|
|
14208
14246
|
if (!entries) authorizationError("unregistered populate array");
|
|
14209
14247
|
for (const [index, el] of entries.entries()) {
|
|
14210
14248
|
await this.finalizePopulatePath(
|
|
14249
|
+
// Traversal value/path position: arrays do not consume a path segment.
|
|
14211
14250
|
el,
|
|
14212
|
-
|
|
14213
|
-
|
|
14214
|
-
|
|
14215
|
-
|
|
14216
|
-
|
|
14251
|
+
pathSegments,
|
|
14252
|
+
segmentIndex,
|
|
14253
|
+
// Target policy and initiating execution/gates.
|
|
14254
|
+
targetMeta,
|
|
14255
|
+
initiatingOperation,
|
|
14256
|
+
parentHookContext,
|
|
14217
14257
|
hookLimit,
|
|
14218
14258
|
sharedGate,
|
|
14219
|
-
|
|
14220
|
-
|
|
14221
|
-
budget
|
|
14259
|
+
// Original provenance.
|
|
14260
|
+
Array.isArray(originalNode) ? originalNode[index] : void 0,
|
|
14261
|
+
// Completed handoffs, receiving budget and publication.
|
|
14262
|
+
completedReferences,
|
|
14263
|
+
receivingBudget,
|
|
14222
14264
|
publication,
|
|
14265
|
+
// Parent authorization and receiving output address.
|
|
14223
14266
|
parentAuthorization,
|
|
14224
|
-
[...
|
|
14267
|
+
[...outputAddress, index]
|
|
14225
14268
|
);
|
|
14226
14269
|
}
|
|
14227
14270
|
return;
|
|
14228
14271
|
}
|
|
14229
|
-
if (typeof
|
|
14230
|
-
if (
|
|
14231
|
-
const key =
|
|
14232
|
-
let
|
|
14272
|
+
if (typeof traversalValue !== "object") return;
|
|
14273
|
+
if (segmentIndex >= pathSegments.length) return;
|
|
14274
|
+
const key = pathSegments[segmentIndex];
|
|
14275
|
+
let traversalChild;
|
|
14233
14276
|
let originalChild;
|
|
14234
|
-
const slots = this.populateInputSlots.get(
|
|
14277
|
+
const slots = this.populateInputSlots.get(targetMeta)?.get(traversalValue);
|
|
14235
14278
|
if (!slots?.has(key)) authorizationError("unregistered populate source slot");
|
|
14236
|
-
|
|
14237
|
-
originalChild =
|
|
14238
|
-
|
|
14279
|
+
traversalChild = slots.get(key);
|
|
14280
|
+
originalChild = traversalChild && typeof traversalChild === "object" ? getQueryReferenceOriginal(
|
|
14281
|
+
traversalChild,
|
|
14282
|
+
publication ?? outputPublicationFor(targetMeta.plan.authorization)
|
|
14283
|
+
) ?? traversalChild : traversalChild;
|
|
14284
|
+
if (traversalChild === void 0 || traversalChild === null) {
|
|
14239
14285
|
return;
|
|
14240
14286
|
}
|
|
14241
|
-
if (
|
|
14242
|
-
if (Array.isArray(
|
|
14243
|
-
const
|
|
14244
|
-
assertTrustedOutputBudget(
|
|
14287
|
+
if (segmentIndex === pathSegments.length - 1) {
|
|
14288
|
+
if (Array.isArray(traversalChild)) {
|
|
14289
|
+
const finalizeLeafValue = async (value, originalValue, depth) => {
|
|
14290
|
+
assertTrustedOutputBudget(receivingBudget);
|
|
14245
14291
|
if (Array.isArray(value)) {
|
|
14246
|
-
const entries = this.populateInputArrays.get(
|
|
14292
|
+
const entries = this.populateInputArrays.get(targetMeta)?.get(value);
|
|
14247
14293
|
if (!entries) authorizationError("unregistered populate array");
|
|
14248
14294
|
const output = [];
|
|
14249
14295
|
for (let index = 0; index < entries.length; index++)
|
|
14250
14296
|
defineTrustedOutputValue(
|
|
14251
14297
|
output,
|
|
14252
14298
|
String(index),
|
|
14253
|
-
await
|
|
14299
|
+
await finalizeLeafValue(
|
|
14300
|
+
// Traversed leaf, original provenance and receiving output depth.
|
|
14254
14301
|
entries[index],
|
|
14255
14302
|
Array.isArray(originalValue) ? originalValue[index] : void 0,
|
|
14256
14303
|
depth + 1
|
|
@@ -14259,84 +14306,106 @@ var Service = class extends Base {
|
|
|
14259
14306
|
return output;
|
|
14260
14307
|
}
|
|
14261
14308
|
if (this.isScalarPopulateValue(value))
|
|
14262
|
-
return copyAuthorizedReference(value, entryPath, { budget, depth }, true);
|
|
14309
|
+
return copyAuthorizedReference(value, entryPath, { budget: receivingBudget, depth }, true);
|
|
14263
14310
|
return this.finalizeSinglePopulateTarget(
|
|
14311
|
+
// Target value/policy and initiating execution/gates.
|
|
14264
14312
|
value,
|
|
14265
|
-
|
|
14266
|
-
|
|
14267
|
-
|
|
14313
|
+
targetMeta,
|
|
14314
|
+
initiatingOperation,
|
|
14315
|
+
parentHookContext,
|
|
14268
14316
|
hookLimit,
|
|
14269
14317
|
sharedGate,
|
|
14318
|
+
// Original provenance, never the finalized output.
|
|
14270
14319
|
originalValue,
|
|
14271
|
-
budget
|
|
14320
|
+
// Receiving budget/publication and independent parent authorization.
|
|
14321
|
+
receivingBudget,
|
|
14272
14322
|
publication,
|
|
14273
14323
|
parentAuthorization,
|
|
14324
|
+
// Receiving output depth, including nested arrays.
|
|
14274
14325
|
depth
|
|
14275
14326
|
);
|
|
14276
14327
|
};
|
|
14277
|
-
const entryPath = [...
|
|
14278
|
-
|
|
14328
|
+
const entryPath = [...outputAddress, key].join(".");
|
|
14329
|
+
completedReferences?.set(
|
|
14330
|
+
entryPath,
|
|
14331
|
+
await finalizeLeafValue(traversalChild, originalChild, outputAddress.length + 1)
|
|
14332
|
+
);
|
|
14279
14333
|
} else {
|
|
14280
|
-
if (this.isScalarPopulateValue(
|
|
14334
|
+
if (this.isScalarPopulateValue(traversalChild)) return;
|
|
14281
14335
|
const finalized = await this.finalizeSinglePopulateTarget(
|
|
14282
|
-
|
|
14283
|
-
|
|
14284
|
-
|
|
14285
|
-
|
|
14336
|
+
// Target value/policy and initiating execution/gates.
|
|
14337
|
+
traversalChild,
|
|
14338
|
+
targetMeta,
|
|
14339
|
+
initiatingOperation,
|
|
14340
|
+
parentHookContext,
|
|
14286
14341
|
hookLimit,
|
|
14287
14342
|
sharedGate,
|
|
14343
|
+
// Original provenance, never the finalized output.
|
|
14288
14344
|
originalChild,
|
|
14289
|
-
budget
|
|
14345
|
+
// Receiving budget/publication and independent parent authorization.
|
|
14346
|
+
receivingBudget,
|
|
14290
14347
|
publication,
|
|
14291
14348
|
parentAuthorization,
|
|
14292
|
-
|
|
14349
|
+
// Receiving output depth.
|
|
14350
|
+
outputAddress.length + 1
|
|
14293
14351
|
);
|
|
14294
|
-
|
|
14352
|
+
completedReferences?.set([...outputAddress, key].join("."), finalized);
|
|
14295
14353
|
}
|
|
14296
14354
|
} else {
|
|
14297
14355
|
await this.finalizePopulatePath(
|
|
14298
|
-
|
|
14299
|
-
|
|
14300
|
-
|
|
14301
|
-
|
|
14302
|
-
|
|
14303
|
-
|
|
14356
|
+
// Traversal value and next path position.
|
|
14357
|
+
traversalChild,
|
|
14358
|
+
pathSegments,
|
|
14359
|
+
segmentIndex + 1,
|
|
14360
|
+
// Target policy and initiating execution/gates.
|
|
14361
|
+
targetMeta,
|
|
14362
|
+
initiatingOperation,
|
|
14363
|
+
parentHookContext,
|
|
14304
14364
|
hookLimit,
|
|
14305
14365
|
sharedGate,
|
|
14366
|
+
// Original provenance.
|
|
14306
14367
|
originalChild,
|
|
14307
|
-
|
|
14308
|
-
|
|
14368
|
+
// Completed handoffs, receiving budget and publication.
|
|
14369
|
+
completedReferences,
|
|
14370
|
+
receivingBudget,
|
|
14309
14371
|
publication,
|
|
14372
|
+
// Parent authorization and receiving output address.
|
|
14310
14373
|
parentAuthorization,
|
|
14311
|
-
[...
|
|
14374
|
+
[...outputAddress, key]
|
|
14312
14375
|
);
|
|
14313
14376
|
}
|
|
14314
14377
|
}
|
|
14315
|
-
async finalizePopulateForSingleDoc(
|
|
14316
|
-
if (!
|
|
14378
|
+
async finalizePopulateForSingleDoc(receivingDocument, populateEntries, parentHookContext, initiatingOperation, hookLimit, sharedGate, parentAuthorization, completedReferences, receivingBudget, publication) {
|
|
14379
|
+
if (!receivingDocument || !Array.isArray(populateEntries) || populateEntries.length === 0) return;
|
|
14317
14380
|
for (const entry of populateEntries) {
|
|
14318
14381
|
if (!entry || typeof entry.path !== "string") continue;
|
|
14319
|
-
const
|
|
14320
|
-
if (!
|
|
14321
|
-
const
|
|
14322
|
-
if (
|
|
14382
|
+
const targetMeta = getPopulateTargetMeta(entry);
|
|
14383
|
+
if (!targetMeta) continue;
|
|
14384
|
+
const pathSegments = entry.path.split(".").filter(Boolean);
|
|
14385
|
+
if (pathSegments.length === 0) continue;
|
|
14323
14386
|
await this.finalizePopulatePath(
|
|
14324
|
-
|
|
14325
|
-
|
|
14387
|
+
// Traversal source and starting path position.
|
|
14388
|
+
getIncludeSource(receivingDocument),
|
|
14389
|
+
pathSegments,
|
|
14326
14390
|
0,
|
|
14327
|
-
|
|
14328
|
-
|
|
14329
|
-
|
|
14391
|
+
// Target policy and initiating execution/gates.
|
|
14392
|
+
targetMeta,
|
|
14393
|
+
initiatingOperation,
|
|
14394
|
+
parentHookContext,
|
|
14330
14395
|
hookLimit,
|
|
14331
14396
|
sharedGate,
|
|
14332
|
-
|
|
14333
|
-
|
|
14334
|
-
budget
|
|
14397
|
+
// Original provenance.
|
|
14398
|
+
getIncludeOriginal(receivingDocument, parentAuthorization),
|
|
14399
|
+
// Completed handoffs, receiving budget and publication.
|
|
14400
|
+
completedReferences,
|
|
14401
|
+
receivingBudget,
|
|
14335
14402
|
publication,
|
|
14403
|
+
// Parent authorization; the output address starts at its default root.
|
|
14336
14404
|
parentAuthorization
|
|
14337
14405
|
);
|
|
14338
14406
|
}
|
|
14339
14407
|
}
|
|
14408
|
+
// Eager log payloads only; callers retain query orchestration.
|
|
14340
14409
|
beginOp(op, filter2, extra) {
|
|
14341
14410
|
const startedAt = Date.now();
|
|
14342
14411
|
debug({
|
|
@@ -14582,13 +14651,17 @@ var Service = class extends Base {
|
|
|
14582
14651
|
if (Array.isArray(_populate) && _populate.length > 0) {
|
|
14583
14652
|
try {
|
|
14584
14653
|
await this.finalizePopulateForSingleDoc(
|
|
14654
|
+
// Receiving document and target entries.
|
|
14585
14655
|
doc,
|
|
14586
14656
|
_populate,
|
|
14657
|
+
// Initiating execution and gates.
|
|
14587
14658
|
context,
|
|
14588
14659
|
"read",
|
|
14589
14660
|
findOneHookLimit,
|
|
14590
14661
|
findOneGate,
|
|
14662
|
+
// Parent authorization.
|
|
14591
14663
|
state.authorization,
|
|
14664
|
+
// Completed handoffs, receiving budget and publication.
|
|
14592
14665
|
outputRow.references,
|
|
14593
14666
|
outputRow.budget,
|
|
14594
14667
|
outputRow.publication
|
|
@@ -14610,7 +14683,6 @@ var Service = class extends Base {
|
|
|
14610
14683
|
context,
|
|
14611
14684
|
includePermissions,
|
|
14612
14685
|
includeFieldPermissions,
|
|
14613
|
-
sharedGate: findOneGate,
|
|
14614
14686
|
stage: outputRow.stage,
|
|
14615
14687
|
budget: outputRow.budget,
|
|
14616
14688
|
publication: outputRow.publication,
|
|
@@ -14710,7 +14782,7 @@ var Service = class extends Base {
|
|
|
14710
14782
|
throw error2;
|
|
14711
14783
|
}
|
|
14712
14784
|
}
|
|
14713
|
-
async findPrepared(execution, preparedQuery, filter2, args, options
|
|
14785
|
+
async findPrepared(execution, preparedQuery, filter2, args, options) {
|
|
14714
14786
|
if (filter2 === false) return { success: false, kind: "error", code: "forbidden" /* Forbidden */, query: { filter: filter2 } };
|
|
14715
14787
|
const state = readServiceExecution(this, execution);
|
|
14716
14788
|
const virtualSnapshot = readServiceAuthorization(state.authorization, state.binding).configuration;
|
|
@@ -14870,13 +14942,17 @@ var Service = class extends Base {
|
|
|
14870
14942
|
this.asServiceHookContext(contexts[i]).fieldPermissionAccess = fieldPermissionAccess;
|
|
14871
14943
|
if (Array.isArray(filteredPopulate) && filteredPopulate.length > 0) {
|
|
14872
14944
|
await this.finalizePopulateForSingleDoc(
|
|
14945
|
+
// Receiving document and target entries.
|
|
14873
14946
|
doc,
|
|
14874
14947
|
filteredPopulate,
|
|
14948
|
+
// Initiating execution and gates.
|
|
14875
14949
|
contexts[i],
|
|
14876
14950
|
"list",
|
|
14877
14951
|
hookLimit,
|
|
14878
14952
|
sharedGate,
|
|
14953
|
+
// Parent authorization.
|
|
14879
14954
|
state.authorization,
|
|
14955
|
+
// Completed handoffs, receiving budget and publication.
|
|
14880
14956
|
outputRows2[i].references,
|
|
14881
14957
|
outputRows2[i].budget,
|
|
14882
14958
|
outputRows2[i].publication
|
|
@@ -14888,7 +14964,6 @@ var Service = class extends Base {
|
|
|
14888
14964
|
context: contexts[i],
|
|
14889
14965
|
includePermissions,
|
|
14890
14966
|
includeFieldPermissions,
|
|
14891
|
-
sharedGate,
|
|
14892
14967
|
privateAssociationField,
|
|
14893
14968
|
stage: outputRows2[i].stage,
|
|
14894
14969
|
budget: outputRows2[i].budget,
|
|
@@ -14937,7 +15012,7 @@ var Service = class extends Base {
|
|
|
14937
15012
|
throw error2;
|
|
14938
15013
|
}
|
|
14939
15014
|
}
|
|
14940
|
-
async createPrepared(execution, data, args, options
|
|
15015
|
+
async createPrepared(execution, data, args, options) {
|
|
14941
15016
|
assertModelInputComplexity(data, this.getRequestComplexity());
|
|
14942
15017
|
const state = readServiceExecution(this, execution);
|
|
14943
15018
|
const captured = readServiceAuthorization(state.authorization, state.binding);
|
|
@@ -15081,13 +15156,17 @@ var Service = class extends Base {
|
|
|
15081
15156
|
const doc = row.doc;
|
|
15082
15157
|
if (resolvedPopulate.length > 0) {
|
|
15083
15158
|
await this.finalizePopulateForSingleDoc(
|
|
15159
|
+
// Receiving document and target entries.
|
|
15084
15160
|
doc,
|
|
15085
15161
|
resolvedPopulate,
|
|
15162
|
+
// Initiating execution and gates.
|
|
15086
15163
|
contexts[index],
|
|
15087
15164
|
initiatingOperation,
|
|
15088
15165
|
hookLimit,
|
|
15089
15166
|
createGate,
|
|
15167
|
+
// Parent authorization.
|
|
15090
15168
|
outputState.authorization,
|
|
15169
|
+
// Completed handoffs, receiving budget and publication.
|
|
15091
15170
|
row.references,
|
|
15092
15171
|
row.budget,
|
|
15093
15172
|
row.publication
|
|
@@ -15099,7 +15178,6 @@ var Service = class extends Base {
|
|
|
15099
15178
|
context: contexts[index],
|
|
15100
15179
|
includePermissions,
|
|
15101
15180
|
includeFieldPermissions,
|
|
15102
|
-
sharedGate: createGate,
|
|
15103
15181
|
stage: row.stage,
|
|
15104
15182
|
budget: row.budget,
|
|
15105
15183
|
publication: row.publication,
|
|
@@ -15222,7 +15300,7 @@ var Service = class extends Base {
|
|
|
15222
15300
|
throw error2;
|
|
15223
15301
|
}
|
|
15224
15302
|
}
|
|
15225
|
-
async updateOnePrepared(execution, filter2, data, args, options
|
|
15303
|
+
async updateOnePrepared(execution, filter2, data, args, options) {
|
|
15226
15304
|
if (filter2 === false) return { success: false, kind: "error", code: "forbidden" /* Forbidden */, query: { filter: filter2 } };
|
|
15227
15305
|
assertModelInputComplexity(data, this.getRequestComplexity());
|
|
15228
15306
|
const state = readServiceExecution(this, execution);
|
|
@@ -15336,13 +15414,17 @@ var Service = class extends Base {
|
|
|
15336
15414
|
const updateHookLimit = this.getVirtualHookConcurrencyLimit();
|
|
15337
15415
|
const updateGate = this.hookGate;
|
|
15338
15416
|
await this.finalizePopulateForSingleDoc(
|
|
15417
|
+
// Receiving document and target entries.
|
|
15339
15418
|
row.doc,
|
|
15340
15419
|
_populate,
|
|
15420
|
+
// Initiating execution and gates.
|
|
15341
15421
|
context,
|
|
15342
15422
|
initiatingOperation,
|
|
15343
15423
|
updateHookLimit,
|
|
15344
15424
|
updateGate,
|
|
15425
|
+
// Parent authorization.
|
|
15345
15426
|
outputState.authorization,
|
|
15427
|
+
// Completed handoffs, receiving budget and publication.
|
|
15346
15428
|
row.references,
|
|
15347
15429
|
row.budget,
|
|
15348
15430
|
row.publication
|
|
@@ -17135,7 +17217,12 @@ var Core = class {
|
|
|
17135
17217
|
virtualNames
|
|
17136
17218
|
});
|
|
17137
17219
|
}
|
|
17138
|
-
/**
|
|
17220
|
+
/**
|
|
17221
|
+
* Request-only population: positional access admits source fields and supplies
|
|
17222
|
+
* the target default; descriptor access overrides only the target. No document
|
|
17223
|
+
* hooks, current document facts or captured parent output execution. Only named
|
|
17224
|
+
* response scopePath is supported; positional subPaths are removed.
|
|
17225
|
+
*/
|
|
17139
17226
|
async genPopulate(modelName, access = "read", _populate = null, options = {}) {
|
|
17140
17227
|
assertFieldHelperCall("genPopulate", arguments.length, 4, options, "populate");
|
|
17141
17228
|
const scopePath = requestFieldScope(options);
|
|
@@ -17181,7 +17268,7 @@ var Core = class {
|
|
|
17181
17268
|
const allowedParentPaths = await this.requestPopulateSelect(
|
|
17182
17269
|
sourceConfiguration,
|
|
17183
17270
|
permissions,
|
|
17184
|
-
|
|
17271
|
+
access,
|
|
17185
17272
|
[parentPath],
|
|
17186
17273
|
scopePath
|
|
17187
17274
|
);
|
|
@@ -17284,9 +17371,9 @@ var Core = class {
|
|
|
17284
17371
|
}
|
|
17285
17372
|
}
|
|
17286
17373
|
async prepare(modelName, allowedData, access, context) {
|
|
17287
|
-
const
|
|
17374
|
+
const prepare = getModelOption(modelName, `prepare.${access}`, null);
|
|
17288
17375
|
const permissions = this.getGlobalPermissions();
|
|
17289
|
-
return callHookChain(this.req,
|
|
17376
|
+
return callHookChain(this.req, prepare, allowedData, permissions, context);
|
|
17290
17377
|
}
|
|
17291
17378
|
async transform(modelName, doc, access, context) {
|
|
17292
17379
|
const transform = getModelOption(modelName, `transform.${access}`, null);
|