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