@salesforce/lds-worker-api 1.229.0-dev2 → 1.229.0-dev4

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.
@@ -3841,7 +3841,7 @@ function createResourceParamsImpl(config, configMetadata) {
3841
3841
  }
3842
3842
  return resourceParams;
3843
3843
  }
3844
- // engine version: 0.145.2-6a13677c
3844
+ // engine version: 0.146.0-dev3-502c4337
3845
3845
 
3846
3846
  /**
3847
3847
  * Copyright (c) 2022, Salesforce, Inc.,
@@ -3968,7 +3968,7 @@ function withDefaultLuvio(callback) {
3968
3968
  }
3969
3969
  callbacks.push(callback);
3970
3970
  }
3971
- // version: 1.229.0-dev2-e9832aaff
3971
+ // version: 1.229.0-dev4-07d38781a
3972
3972
 
3973
3973
  // TODO [TD-0081508]: once that TD is fulfilled we can probably change this file
3974
3974
  function instrumentAdapter$1(createFunction, _metadata) {
@@ -15429,7 +15429,7 @@ function gql(literals, ...subs) {
15429
15429
  }
15430
15430
  return superResult;
15431
15431
  }
15432
- // version: 1.229.0-dev2-e9832aaff
15432
+ // version: 1.229.0-dev4-07d38781a
15433
15433
 
15434
15434
  function unwrap(data) {
15435
15435
  // The lwc-luvio bindings import a function from lwc called "unwrap".
@@ -15530,14 +15530,15 @@ function refreshData(data, dataToTuple, luvio) {
15530
15530
  return undefined;
15531
15531
  });
15532
15532
  }
15533
- const { isArray: isArray$8 } = Array;
15534
- const { stringify: stringify$9 } = JSON;
15535
15533
 
15536
15534
  function isPromise$1(value) {
15537
15535
  // check for Thenable due to test frameworks using custom Promise impls
15538
15536
  return value.then !== undefined;
15539
15537
  }
15540
15538
 
15539
+ const { isArray: isArray$8 } = Array;
15540
+ const { stringify: stringify$9 } = JSON;
15541
+
15541
15542
  /**
15542
15543
  * (Re)throws an error after adding a prefix to the message.
15543
15544
  *
@@ -16352,7 +16353,7 @@ function createGraphQLWireAdapterConstructor(luvio, adapter, metadata, astResolv
16352
16353
  const { apiFamily, name } = metadata;
16353
16354
  return createGraphQLWireAdapterConstructor$1(adapter, `${apiFamily}.${name}`, luvio, astResolver);
16354
16355
  }
16355
- // version: 1.229.0-dev2-e9832aaff
16356
+ // version: 1.229.0-dev4-07d38781a
16356
16357
 
16357
16358
  /**
16358
16359
  * Copyright (c) 2022, Salesforce, Inc.,
@@ -16451,7 +16452,7 @@ var TypeCheckShapes;
16451
16452
  TypeCheckShapes[TypeCheckShapes["Integer"] = 3] = "Integer";
16452
16453
  TypeCheckShapes[TypeCheckShapes["Unsupported"] = 4] = "Unsupported";
16453
16454
  })(TypeCheckShapes || (TypeCheckShapes = {}));
16454
- // engine version: 0.145.2-6a13677c
16455
+ // engine version: 0.146.0-dev3-502c4337
16455
16456
 
16456
16457
  const { keys: ObjectKeys$3, create: ObjectCreate$3 } = Object;
16457
16458
 
@@ -41168,7 +41169,7 @@ withDefaultLuvio((luvio) => {
41168
41169
  throttle(60, 60000, createLDSAdapter(luvio, 'notifyListInfoUpdateAvailable', notifyUpdateAvailableFactory$1));
41169
41170
  throttle(60, 60000, createLDSAdapter(luvio, 'notifyQuickActionDefaultsUpdateAvailable', notifyUpdateAvailableFactory));
41170
41171
  });
41171
- // version: 1.229.0-dev2-696fe5026
41172
+ // version: 1.229.0-dev4-4a7593877
41172
41173
 
41173
41174
  var caseSensitiveUserId = '005B0000000GR4OIAW';
41174
41175
 
@@ -41799,6 +41800,9 @@ function handleDurableStoreRejection(instrument) {
41799
41800
  }
41800
41801
 
41801
41802
  function isStoreEntryError(storeRecord) {
41803
+ if (!storeRecord || typeof storeRecord !== 'object') {
41804
+ return false;
41805
+ }
41802
41806
  return storeRecord.__type === 'error';
41803
41807
  }
41804
41808
 
@@ -49290,6 +49294,10 @@ function isOperationDefinitionNode(node) {
49290
49294
  return node.kind === 'OperationDefinition';
49291
49295
  }
49292
49296
 
49297
+ const POLYMORPHIC_PARENT_RELATIONSHIP = 'polymorphicParentRelationship';
49298
+ const PARENT_RELATIONSHIP = 'parentRelationship';
49299
+ const CHILD_RELATIONSHIP = 'childRelationship';
49300
+ const RECORD_QUERY = 'recordQuery';
49293
49301
  function requestsDraftsField(recordFieldNode) {
49294
49302
  if (!recordFieldNode.selectionSet)
49295
49303
  return false;
@@ -49305,18 +49313,41 @@ function isRecordQuery(recordQueryField) {
49305
49313
  directive.arguments
49306
49314
  .map((argument) => argument.value)
49307
49315
  .filter(isStringValueNode)
49308
- .some((categoryName) => categoryName.value === 'recordQuery'));
49316
+ .some((categoryName) => categoryName.value === RECORD_QUERY));
49309
49317
  });
49310
49318
  }
49311
49319
  return false;
49312
49320
  }
49313
- // finds field with 'recordQuery' and 'childRelationship' directive
49314
- function findNearestRecordQuery(ancestors) {
49315
- const recordQueryAncester = findNearestAncesterPath(ancestors, true).node;
49316
- return recordQueryAncester === undefined ? undefined : recordQueryAncester;
49321
+ // finds connection field with 'recordQuery' and 'childRelationship' directive.
49322
+ function findNearestConnection(ancestors) {
49323
+ const connectionAncestor = findNearestAncesterPath(ancestors, true).node;
49324
+ return connectionAncestor === undefined ? undefined : connectionAncestor;
49325
+ }
49326
+ // convinient method to find nearest connection with its path
49327
+ function findNearestConnectionWithPath(ancestors) {
49328
+ const closestAncestorPath = findNearestAncesterPath(ancestors, true);
49329
+ let connection = undefined;
49330
+ let connectionPath = undefined;
49331
+ if (closestAncestorPath.parentIndex > 0) {
49332
+ const connectionAncestor = closestAncestorPath.node;
49333
+ const connectionAncestors = ancestors.slice(0, closestAncestorPath.parentIndex);
49334
+ connection =
49335
+ connectionAncestor === undefined ? undefined : connectionAncestor;
49336
+ if (connection !== undefined) {
49337
+ const ancesterPath = findAncesterPath(connectionAncestors);
49338
+ connectionPath =
49339
+ ancesterPath === ''
49340
+ ? connection.name.value
49341
+ : `${ancesterPath}#${connection.name.value}`;
49342
+ }
49343
+ }
49344
+ return {
49345
+ connection,
49346
+ path: connectionPath,
49347
+ };
49317
49348
  }
49318
- // finds cloeset ancester. If 'parentRelationship' is allowed, it could be 'InlineFragmentNode' since it inherits the 'parent' relationship. 'InlineFragmentNode' makes sure that only one 'apiName' returns when tree is traversed.
49319
- function findNearestAncesterPath(ancestors, recordQueryOnly) {
49349
+ // finds closest ancestor. If node with 'parentRelationship' is the ancester, the end result could be 'InlineFragmentNode' since it inherits the 'parent' relationship. 'InlineFragmentNode' makes sure that only one 'apiName' returns when tree is traversed.
49350
+ function findNearestAncesterPath(ancestors, connectionOnly) {
49320
49351
  let recordQueryPath = { node: undefined, parentIndex: -1 };
49321
49352
  let relationship = '';
49322
49353
  for (let i = ancestors.length - 1; i >= 0; i--) {
@@ -49330,9 +49361,11 @@ function findNearestAncesterPath(ancestors, recordQueryOnly) {
49330
49361
  continue;
49331
49362
  for (let arg of directive.arguments) {
49332
49363
  if (arg.value &&
49333
- (arg.value.value === 'recordQuery' ||
49334
- arg.value.value === 'childRelationship' ||
49335
- (!recordQueryOnly && arg.value.value === 'parentRelationship'))) {
49364
+ (arg.value.value === RECORD_QUERY ||
49365
+ arg.value.value === CHILD_RELATIONSHIP ||
49366
+ (!connectionOnly &&
49367
+ (arg.value.value === PARENT_RELATIONSHIP ||
49368
+ arg.value.value === POLYMORPHIC_PARENT_RELATIONSHIP)))) {
49336
49369
  recordQueryPath = { node: node, parentIndex: i };
49337
49370
  relationship = arg.value.value;
49338
49371
  break;
@@ -49347,17 +49380,19 @@ function findNearestAncesterPath(ancestors, recordQueryOnly) {
49347
49380
  //checks if nearest ancester could be an inline fragment
49348
49381
  if (recordQueryPath.node !== undefined &&
49349
49382
  recordQueryPath.node.selectionSet &&
49350
- relationship === 'parentRelationship') {
49351
- //
49352
- if (recordQueryPath.node.selectionSet.selections.every(isInlineFragmentNode)) {
49353
- //
49354
- const inlineFragmentLoc = recordQueryPath.parentIndex + 2;
49355
- if (inlineFragmentLoc < ancestors.length && ancestors[inlineFragmentLoc]) {
49383
+ (relationship === PARENT_RELATIONSHIP || relationship === POLYMORPHIC_PARENT_RELATIONSHIP)) {
49384
+ // InlineFragment is usually 3 steps aways from its FieldNode parent within ancester hierarchy if it exists. The below search
49385
+ // is applied to adapt to future AST structure change
49386
+ let parentIndex = recordQueryPath.parentIndex + 1;
49387
+ while (parentIndex < ancestors.length) {
49388
+ if (isInlineFragmentNode(ancestors[parentIndex])) {
49356
49389
  recordQueryPath = {
49357
- node: ancestors[inlineFragmentLoc],
49358
- parentIndex: inlineFragmentLoc,
49390
+ node: ancestors[parentIndex],
49391
+ parentIndex,
49359
49392
  };
49393
+ break;
49360
49394
  }
49395
+ parentIndex++;
49361
49396
  }
49362
49397
  }
49363
49398
  return recordQueryPath;
@@ -49381,7 +49416,7 @@ function findAncesterPath(ancesters) {
49381
49416
  ? sectionPath
49382
49417
  : sectionPath === ''
49383
49418
  ? path
49384
- : `${sectionPath}_${path}`;
49419
+ : `${sectionPath}#${path}`;
49385
49420
  }
49386
49421
  }
49387
49422
  boundaryIndex = parentIndex;
@@ -49439,9 +49474,9 @@ function getRelation(node) {
49439
49474
  const relationships = args
49440
49475
  .map((arg) => arg.value)
49441
49476
  .filter(isStringValueNode)
49442
- .filter((valueNode) => valueNode.value === 'childRelationship' ||
49443
- valueNode.value === 'parentRelationship' ||
49444
- valueNode.value === 'polymorphicParentRelationship')
49477
+ .filter((valueNode) => valueNode.value === CHILD_RELATIONSHIP ||
49478
+ valueNode.value === PARENT_RELATIONSHIP ||
49479
+ valueNode.value === POLYMORPHIC_PARENT_RELATIONSHIP)
49445
49480
  .map((relationshipNode) => relationshipNode.value);
49446
49481
  if (relationships.length > 0) {
49447
49482
  return relationships[0];
@@ -49498,8 +49533,8 @@ function isFieldSpanning(node, parentNode) {
49498
49533
  */
49499
49534
  function isParentRelationship(node) {
49500
49535
  return (node &&
49501
- (isRelationship(node, 'parentRelationship') ||
49502
- isRelationship(node, 'polymorphicParentRelationship')));
49536
+ (isRelationship(node, PARENT_RELATIONSHIP) ||
49537
+ isRelationship(node, POLYMORPHIC_PARENT_RELATIONSHIP)));
49503
49538
  }
49504
49539
  /*
49505
49540
  checks if the InlineFragment spans
@@ -50591,7 +50626,7 @@ const parentRelationshipDirective = {
50591
50626
  },
50592
50627
  value: {
50593
50628
  kind: Kind.STRING,
50594
- value: 'parentRelationship',
50629
+ value: PARENT_RELATIONSHIP,
50595
50630
  block: false,
50596
50631
  },
50597
50632
  },
@@ -50605,8 +50640,8 @@ async function injectSyntheticFields(originalAST, objectInfoService, draftFuncti
50605
50640
  // example 2 'ServiceAppointment' -> ['Owner']; 'Owner' -> ['User', 'Group']
50606
50641
  const objectNodeInfoTree = {};
50607
50642
  // save the field path to apiName map
50608
- // example 1: 'ServiceAppointment' -> ['ServiceAppointment']; 'ServiceAppointment_Account' -> ['Account']; 'ServiceAppointment_Account_Owner' -> ['User']
50609
- const objectInfoApiMap = {};
50643
+ // example 1: 'ServiceAppointment' -> ['ServiceAppointment']; 'ServiceAppointment#ccount' -> ['Account']; 'ServiceAppointment#Account#Owner' -> ['User']
50644
+ const pathToObjectApiNamesMap = {};
50610
50645
  let startNodes = new Set();
50611
50646
  let totalNodes = new Set();
50612
50647
  let objectInfos = {};
@@ -50620,11 +50655,11 @@ async function injectSyntheticFields(originalAST, objectInfoService, draftFuncti
50620
50655
  visit(originalAST, {
50621
50656
  Argument: {
50622
50657
  enter(node, key, parent, path, ancestors) {
50623
- const recordQueryNode = findNearestRecordQuery(ancestors);
50624
- if (!recordQueryNode)
50658
+ const { connection: recordConnectionNode, path: ancesterPath } = findNearestConnectionWithPath(ancestors);
50659
+ if (!recordConnectionNode || !ancesterPath)
50625
50660
  return;
50626
- if (!objectNodeInfoTree[recordQueryNode.name.value]) {
50627
- objectNodeInfoTree[recordQueryNode.name.value] = [];
50661
+ if (!objectNodeInfoTree[ancesterPath]) {
50662
+ objectNodeInfoTree[ancesterPath] = [];
50628
50663
  }
50629
50664
  switch (node.name.value) {
50630
50665
  case 'orderBy':
@@ -50632,12 +50667,12 @@ async function injectSyntheticFields(originalAST, objectInfoService, draftFuncti
50632
50667
  if (node.value.kind !== 'ObjectValue') {
50633
50668
  return;
50634
50669
  }
50635
- totalNodes.add(recordQueryNode.name.value);
50670
+ totalNodes.add(ancesterPath);
50636
50671
  // 'childRelationship' node is not taken as the startNode of the 'NodeInfoTree' graph. The field scanning will construct the graph which lead here.
50637
- if (isRecordQuery(recordQueryNode)) {
50638
- startNodes.add(recordQueryNode.name.value);
50672
+ if (isRecordQuery(recordConnectionNode)) {
50673
+ startNodes.add(recordConnectionNode.name.value);
50639
50674
  }
50640
- growObjectFieldTree(objectNodeInfoTree, recordQueryNode.name.value, node.value, totalNodes, startNodes);
50675
+ growObjectFieldTree(objectNodeInfoTree, ancesterPath, node.value, totalNodes, startNodes);
50641
50676
  break;
50642
50677
  case 'scope':
50643
50678
  if (!isScopeArgumentNodeWithType(node, 'ASSIGNEDTOME', variables)) {
@@ -50652,17 +50687,16 @@ async function injectSyntheticFields(originalAST, objectInfoService, draftFuncti
50652
50687
  name: 'ServiceResources',
50653
50688
  });
50654
50689
  }
50655
- if (objectNodeInfoTree['ServiceResources'] === undefined) {
50656
- objectNodeInfoTree['ServiceResources'] = [];
50657
- }
50658
- if (!objectNodeInfoTree['ServiceResources'].some((child) => child.name === 'ServiceResource')) {
50659
- objectNodeInfoTree['ServiceResources'].push({
50660
- relation: 'parent',
50661
- name: 'ServiceResource',
50662
- });
50690
+ if (objectNodeInfoTree['ServiceAppointment#ServiceResources'] === undefined) {
50691
+ objectNodeInfoTree['ServiceAppointment#ServiceResources'] = [
50692
+ {
50693
+ relation: 'parent',
50694
+ name: 'ServiceResource',
50695
+ },
50696
+ ];
50663
50697
  }
50664
- if (objectNodeInfoTree['ServiceResource'] === undefined) {
50665
- objectNodeInfoTree['ServiceResource'] = [];
50698
+ if (objectNodeInfoTree['ServiceAppointment#ServiceResources#ServiceResource'] === undefined) {
50699
+ objectNodeInfoTree['ServiceAppointment#ServiceResources#ServiceResource'] = [];
50666
50700
  }
50667
50701
  break;
50668
50702
  default:
@@ -50676,7 +50710,7 @@ async function injectSyntheticFields(originalAST, objectInfoService, draftFuncti
50676
50710
  return;
50677
50711
  if (!node.selectionSet)
50678
50712
  return;
50679
- const recordQueryField = findNearestRecordQuery(ancestors);
50713
+ const recordQueryField = findNearestConnection(ancestors);
50680
50714
  //only injects fields for 'recordQuery' field. ignores the 'childRelationship' field since it will be traversed as the child of the 'recordQuery'
50681
50715
  if (isRecordQuery(recordQueryField) && recordQueryField) {
50682
50716
  totalNodes.add(recordQueryField.name.value);
@@ -50687,21 +50721,21 @@ async function injectSyntheticFields(originalAST, objectInfoService, draftFuncti
50687
50721
  },
50688
50722
  });
50689
50723
  if (objectInfoService && startNodes.size > 0) {
50690
- objectInfos = await resolveObjectInfos(objectNodeInfoTree, objectInfoApiMap, startNodes, objectInfoService);
50724
+ objectInfos = await resolveObjectInfos(objectNodeInfoTree, pathToObjectApiNamesMap, startNodes, objectInfoService);
50691
50725
  }
50692
50726
  // read pass; gather whats needed
50693
50727
  visit(originalAST, {
50694
50728
  Argument: {
50695
50729
  leave(node, key, parent, path, ancestors) {
50696
- const recordQueryField = findNearestRecordQuery(ancestors);
50730
+ const recordQueryField = findNearestConnection(ancestors);
50697
50731
  if (!recordQueryField)
50698
50732
  return;
50699
50733
  const ancestorPath = findAncesterPath(ancestors);
50700
50734
  if (!inlineFragmentSelections[ancestorPath]) {
50701
50735
  inlineFragmentSelections[ancestorPath] = [];
50702
50736
  }
50703
- const recordQueryApiName = objectInfoApiMap[ancestorPath]
50704
- ? objectInfoApiMap[ancestorPath][0]
50737
+ const recordQueryApiName = pathToObjectApiNamesMap[ancestorPath]
50738
+ ? pathToObjectApiNamesMap[ancestorPath][0]
50705
50739
  : recordQueryField.name.value;
50706
50740
  // The record node acts as the reference. The duplicated field in the record node is not injected
50707
50741
  const recordReferenceNode = [recordQueryField]
@@ -50715,7 +50749,7 @@ async function injectSyntheticFields(originalAST, objectInfoService, draftFuncti
50715
50749
  case 'scope':
50716
50750
  // Hanle 'MINE' field
50717
50751
  if (isScopeArgumentNodeWithType(node, 'MINE', variables)) {
50718
- if (isMineScopeAvailable(ancestorPath, objectInfoApiMap, objectInfos)) {
50752
+ if (isMineScopeAvailable(ancestorPath, pathToObjectApiNamesMap, objectInfos)) {
50719
50753
  // 'typeConditon' is added when the 'InlineFragmentNode' is appended at the write pass
50720
50754
  inlineFragmentSelections[ancestorPath].push(...mineFragmentSelections);
50721
50755
  }
@@ -50741,7 +50775,7 @@ async function injectSyntheticFields(originalAST, objectInfoService, draftFuncti
50741
50775
  case 'where': {
50742
50776
  inlineFragmentSelections[ancestorPath] = [
50743
50777
  ...inlineFragmentSelections[ancestorPath],
50744
- ...injectFilter(node, idState, ancestorPath, objectInfos, objectInfoApiMap, draftFunctions, recordReferenceNode),
50778
+ ...injectFilter(node, idState, ancestorPath, false, objectInfos, pathToObjectApiNamesMap, draftFunctions, recordReferenceNode),
50745
50779
  ];
50746
50780
  break;
50747
50781
  }
@@ -50757,7 +50791,7 @@ async function injectSyntheticFields(originalAST, objectInfoService, draftFuncti
50757
50791
  if (!node.selectionSet)
50758
50792
  return;
50759
50793
  // it could be 'recordQuery' or 'childRelationship'
50760
- const recordQueryField = findNearestRecordQuery(ancestors);
50794
+ const recordQueryField = findNearestConnection(ancestors);
50761
50795
  if (!recordQueryField)
50762
50796
  return;
50763
50797
  const ancestorPath = findAncesterPath(ancestors);
@@ -50769,7 +50803,7 @@ async function injectSyntheticFields(originalAST, objectInfoService, draftFuncti
50769
50803
  spanningSelections.push(selection);
50770
50804
  }
50771
50805
  }
50772
- const injectedFields = injectFields(spanningSelections, node, ancestors, objectInfos, objectInfoApiMap);
50806
+ const injectedFields = injectFields(spanningSelections, node, ancestorPath, ancestors, objectInfos, pathToObjectApiNamesMap);
50773
50807
  const mergedInjectedFields = mergeSelectionNodes$1(inlineFragmentSelections[ancestorPath], injectedFields);
50774
50808
  inlineFragmentSelections[ancestorPath] = mergedInjectedFields;
50775
50809
  },
@@ -50782,7 +50816,7 @@ async function injectSyntheticFields(originalAST, objectInfoService, draftFuncti
50782
50816
  // removes 'ServicesResources' query field node if 'assignedtome' scope shows up
50783
50817
  if (assignedtomeQueryFieldNode !== undefined &&
50784
50818
  node.name.value === 'ServiceResources') {
50785
- const serviceResourcesAncestor = findNearestRecordQuery(ancestors);
50819
+ const serviceResourcesAncestor = findNearestConnection(ancestors);
50786
50820
  if (serviceResourcesAncestor === assignedtomeQueryFieldNode) {
50787
50821
  return null;
50788
50822
  }
@@ -50791,7 +50825,7 @@ async function injectSyntheticFields(originalAST, objectInfoService, draftFuncti
50791
50825
  return;
50792
50826
  if (!node.selectionSet)
50793
50827
  return;
50794
- const recordQueryField = findNearestRecordQuery(ancestors);
50828
+ const recordQueryField = findNearestConnection(ancestors);
50795
50829
  if (!recordQueryField)
50796
50830
  return;
50797
50831
  const ancestorPath = findAncesterPath(ancestors);
@@ -50800,8 +50834,8 @@ async function injectSyntheticFields(originalAST, objectInfoService, draftFuncti
50800
50834
  return;
50801
50835
  //const recordQueryPath = findAncesterPath(ancestors);
50802
50836
  // 'apiName' has to be at index 0 since 'node' record type could only be of 'recordQuery' or 'childRelationship'. They can not have the 'InlineFragmentNode' as its children.
50803
- const recordQueryApiName = objectInfoApiMap[ancestorPath]
50804
- ? objectInfoApiMap[ancestorPath][0]
50837
+ const recordQueryApiName = pathToObjectApiNamesMap[ancestorPath]
50838
+ ? pathToObjectApiNamesMap[ancestorPath][0]
50805
50839
  : recordQueryField.name.value;
50806
50840
  const nodeWithFragments = {
50807
50841
  ...node,
@@ -50838,7 +50872,7 @@ async function injectSyntheticFields(originalAST, objectInfoService, draftFuncti
50838
50872
  if (node.name.value === 'where') {
50839
50873
  const ancestorPath = findAncesterPath(ancestors);
50840
50874
  if (idState.paths.includes(ancestorPath)) {
50841
- const apiName = objectInfoApiMap[ancestorPath][0];
50875
+ const apiName = pathToObjectApiNamesMap[ancestorPath][0];
50842
50876
  const objectInfo = objectInfos[apiName];
50843
50877
  const swappedIdFilter = swapIdField(node.value, objectInfo, false, idState, draftFunctions);
50844
50878
  return {
@@ -50904,8 +50938,8 @@ function swapIdField(filterFields, objectInfo, swapped, idState, draftFunctions)
50904
50938
  };
50905
50939
  }
50906
50940
  }
50907
- function isMineScopeAvailable(apiNamePath, objectInfoApiMap, objectInfos) {
50908
- const apiName = objectInfoApiMap[apiNamePath];
50941
+ function isMineScopeAvailable(apiNamePath, pathToObjectApiNamesMap, objectInfos) {
50942
+ const apiName = pathToObjectApiNamesMap[apiNamePath];
50909
50943
  if (!apiName)
50910
50944
  return false;
50911
50945
  const objectInfo = objectInfos[apiName[0]];
@@ -50994,15 +51028,16 @@ function growObjectFieldTree(tree, parentNode, entryNode, totalNodes, startNodes
50994
51028
  }
50995
51029
  // example: 'Account'
50996
51030
  const childNode = objectFieldNode.name.value;
51031
+ const childNodepath = `${parentNode}#${childNode}`;
50997
51032
  if (!tree[parentNode].some((child) => child.name === childNode)) {
50998
51033
  tree[parentNode].push({
50999
51034
  relation: 'parent',
51000
51035
  name: childNode,
51001
51036
  });
51002
- totalNodes.add(childNode);
51037
+ totalNodes.add(childNodepath);
51003
51038
  }
51004
51039
  // recursively go to deeper level of filter.
51005
- growObjectFieldTree(tree, childNode, objectFieldNode.value, totalNodes, startNodes);
51040
+ growObjectFieldTree(tree, childNodepath, objectFieldNode.value, totalNodes, startNodes);
51006
51041
  }
51007
51042
  }
51008
51043
  }
@@ -51037,19 +51072,20 @@ function growFieldTree(tree, parentSectionPath, entryNode, parentNode, totalNode
51037
51072
  }
51038
51073
  if (!tree[parentSectionPath].some((field) => field.name === fieldName)) {
51039
51074
  tree[parentSectionPath].push({
51040
- relation: relationType === 'parentRelationship' ||
51041
- relationType === 'polymorphicParentRelationship'
51075
+ relation: relationType === PARENT_RELATIONSHIP ||
51076
+ relationType === POLYMORPHIC_PARENT_RELATIONSHIP
51042
51077
  ? 'parent'
51043
51078
  : 'child',
51044
51079
  name: fieldName,
51045
51080
  });
51046
- totalNodes.add(fieldName);
51081
+ totalNodes.add(`${parentSectionPath}#${fieldName}`);
51047
51082
  }
51048
51083
  if (entryNode.selectionSet && entryNode.selectionSet.selections) {
51049
51084
  const childNodes = entryNode.selectionSet.selections.filter(isFieldOrInlineFragmentNode);
51050
51085
  // recursively build the traversal tree
51051
51086
  for (const child of childNodes) {
51052
- growFieldTree(tree, fieldName, child, entryNode, totalNodes, startNodes);
51087
+ const path = `${parentSectionPath}#${fieldName}`;
51088
+ growFieldTree(tree, path, child, entryNode, totalNodes, startNodes);
51053
51089
  }
51054
51090
  }
51055
51091
  }
@@ -51079,23 +51115,23 @@ function growFieldTree(tree, parentSectionPath, entryNode, parentNode, totalNode
51079
51115
  }
51080
51116
  if (!tree[parentSectionPath].some((field) => field.name === conditionName)) {
51081
51117
  tree[parentSectionPath].push({
51082
- relation: relationType === 'parentRelationship' ||
51083
- relationType === 'polymorphicParentRelationship'
51118
+ relation: relationType === PARENT_RELATIONSHIP ||
51119
+ relationType === POLYMORPHIC_PARENT_RELATIONSHIP
51084
51120
  ? 'parent'
51085
51121
  : 'child',
51086
51122
  name: conditionName,
51087
51123
  });
51088
- totalNodes.add(conditionName);
51124
+ const path = `${parentSectionPath}#${conditionName}`;
51125
+ totalNodes.add(path);
51089
51126
  }
51090
51127
  }
51091
51128
  }
51092
51129
  // dive deep immediately for 'InlineFragment'
51093
51130
  const childNodes = entryNode.selectionSet.selections.filter(isFieldOrInlineFragmentNode);
51131
+ const path = `${parentSectionPath}${entryNode.typeCondition ? '#' + entryNode.typeCondition.name.value : ''}`;
51094
51132
  // Navigates into InLineFragment
51095
51133
  for (const child of childNodes) {
51096
- growFieldTree(tree, entryNode.typeCondition
51097
- ? entryNode.typeCondition.name.value
51098
- : parentSectionPath, child, entryNode, totalNodes, startNodes);
51134
+ growFieldTree(tree, path, child, entryNode, totalNodes, startNodes);
51099
51135
  }
51100
51136
  }
51101
51137
  }
@@ -51107,7 +51143,7 @@ function growFieldTree(tree, parentSectionPath, entryNode, parentNode, totalNode
51107
51143
  * @param startNodes start nodes of the tree. It can be used to fetch ObjectInfo immediately
51108
51144
  * @param path
51109
51145
  */
51110
- async function resolveObjectInfos(objectInfotree, objectInfoApiMap, startNodes, objectInfoService) {
51146
+ async function resolveObjectInfos(objectInfotree, pathToObjectApiNamesMap, startNodes, objectInfoService) {
51111
51147
  let objectInfos;
51112
51148
  try {
51113
51149
  objectInfos = await objectInfoService.getObjectInfos(Array.from(startNodes));
@@ -51121,9 +51157,9 @@ async function resolveObjectInfos(objectInfotree, objectInfoApiMap, startNodes,
51121
51157
  throw new Error(`Unable to resolve ObjectInfo(s) for ${Array.from(startNodes)}`);
51122
51158
  }
51123
51159
  for (const startNode of startNodes) {
51124
- objectInfoApiMap[startNode] = [startNode];
51160
+ pathToObjectApiNamesMap[startNode] = [startNode];
51125
51161
  const children = objectInfotree[startNode];
51126
- const subObjectInfoMap = await fetchObjectInfos(objectInfotree, objectInfoApiMap, objectInfos, children, startNode, objectInfoService);
51162
+ const subObjectInfoMap = await fetchObjectInfos(objectInfotree, pathToObjectApiNamesMap, objectInfos, children, startNode, objectInfoService);
51127
51163
  objectInfos = { ...objectInfos, ...subObjectInfoMap };
51128
51164
  }
51129
51165
  return objectInfos;
@@ -51131,15 +51167,15 @@ async function resolveObjectInfos(objectInfotree, objectInfoApiMap, startNodes,
51131
51167
  // example 1: 'parentPath': 'ServiceAppointment', 'nodesAtSameLevel': ['Account']
51132
51168
  // example 2: 'parentPath': 'ServiceAppointment', 'nodesAtSameLevel': ['Owner'], this example has 2 apiName for the node 'Owner'
51133
51169
  // example 3: 'parentPath': 'ServiceAppointment_Owner', 'nodesAtSameLevel': ['User', 'Group']
51134
- async function fetchObjectInfos(objectInfotree, objectInfoApiMap, objectInfoMap, nodesAtSameLevel, parentPath, objectInfoService) {
51135
- const objectInfoApiNames = objectInfoApiMap[parentPath];
51170
+ async function fetchObjectInfos(objectInfotree, pathToObjectApiNamesMap, objectInfoMap, nodesAtSameLevel, parentPath, objectInfoService) {
51171
+ const objectInfoApiNames = pathToObjectApiNamesMap[parentPath];
51136
51172
  if (!objectInfoApiNames) {
51137
51173
  // eslint-disable-next-line
51138
51174
  throw new Error(`Object Info does not exist for ${parentPath}`);
51139
51175
  }
51140
51176
  const validObjectInfoNodes = [];
51141
51177
  let updatedObjectInfoMap = {};
51142
- // InlineFragment and polymorphic field support fits into this scenario ObjectInfoApiMap Entry: 'ServiceAppointment_Owner' -> ['User', 'Group']; ServiceAppointment_Owner_User' -> ['User']
51178
+ // InlineFragment and polymorphic field support fits into this scenario pathToObjectApiNamesMap Entry: 'ServiceAppointment#Owner' -> ['User', 'Group']; ServiceAppointment#Owner#User' -> ['User']
51143
51179
  if (objectInfoApiNames.length > 0 &&
51144
51180
  nodesAtSameLevel.length > 0 &&
51145
51181
  objectInfoApiNames.includes(nodesAtSameLevel[0].name)) {
@@ -51151,8 +51187,8 @@ async function fetchObjectInfos(objectInfotree, objectInfoApiMap, objectInfoMap,
51151
51187
  // eslint-disable-next-line
51152
51188
  throw new Error(`Condition ${field.name} does not exists for ${parentPath}`);
51153
51189
  }
51154
- const path = `${parentPath}_${field.name}`;
51155
- objectInfoApiMap[path] = [field.name];
51190
+ const path = `${parentPath}#${field.name}`;
51191
+ pathToObjectApiNamesMap[path] = [field.name];
51156
51192
  }
51157
51193
  validObjectInfoNodes.push(...nodesAtSameLevel);
51158
51194
  updatedObjectInfoMap = { ...objectInfoMap };
@@ -51167,7 +51203,7 @@ async function fetchObjectInfos(objectInfotree, objectInfoApiMap, objectInfoMap,
51167
51203
  let apiNames = [];
51168
51204
  for (const nodeInfo of nodesAtSameLevel) {
51169
51205
  const field = nodeInfo.name;
51170
- const path = `${parentPath}_${field}`;
51206
+ const path = `${parentPath}#${field}`;
51171
51207
  // Handle 'parentRelationship'
51172
51208
  if (nodeInfo.relation === 'parent') {
51173
51209
  const relationshipId = referenceIdFieldForRelationship(field);
@@ -51185,21 +51221,21 @@ async function fetchObjectInfos(objectInfotree, objectInfoApiMap, objectInfoMap,
51185
51221
  }
51186
51222
  }
51187
51223
  // This is a polymorphic field
51188
- if (fieldDefinition.referenceToInfos.length > 1 && objectInfotree[field]) {
51224
+ if (fieldDefinition.referenceToInfos.length > 1 && objectInfotree[path]) {
51189
51225
  // Fields needs to expand and heterogenous entity ObjectInfo needs to be fetched
51190
- const referencedNodeInfos = objectInfotree[field];
51226
+ const referencedNodeInfos = objectInfotree[path];
51191
51227
  const requestedApiNames = referencedNodeInfos.map((referenceNodeInfo) => referenceNodeInfo.name);
51192
51228
  // Fetches requested ObjectInfo only. Some entity's relation field could define more than 6 references. Only references show up in query need to be handled.
51193
- if (requestedApiNames.length > 0 && objectInfotree[field]) {
51229
+ if (requestedApiNames.length > 0 && objectInfotree[path]) {
51194
51230
  fieldDefinition.referenceToInfos
51195
51231
  .filter((referenceToInfo) => requestedApiNames.includes(referenceToInfo.apiName))
51196
51232
  .forEach((ref) => {
51197
- if (!objectInfoApiMap[path]) {
51198
- objectInfoApiMap[path] = [];
51233
+ if (!pathToObjectApiNamesMap[path]) {
51234
+ pathToObjectApiNamesMap[path] = [];
51199
51235
  }
51200
51236
  // 'ServiceAppointment_Owner' ->['User', 'Group']
51201
- if (!objectInfoApiMap[path].includes(ref.apiName)) {
51202
- objectInfoApiMap[path].push(ref.apiName);
51237
+ if (!pathToObjectApiNamesMap[path].includes(ref.apiName)) {
51238
+ pathToObjectApiNamesMap[path].push(ref.apiName);
51203
51239
  }
51204
51240
  if (!apiNames.includes(ref.apiName)) {
51205
51241
  apiNames.push(ref.apiName);
@@ -51209,11 +51245,11 @@ async function fetchObjectInfos(objectInfotree, objectInfoApiMap, objectInfoMap,
51209
51245
  }
51210
51246
  else if (fieldDefinition.referenceToInfos.length === 1) {
51211
51247
  const ref = fieldDefinition.referenceToInfos[0];
51212
- if (!objectInfoApiMap[path]) {
51213
- objectInfoApiMap[path] = [];
51248
+ if (!pathToObjectApiNamesMap[path]) {
51249
+ pathToObjectApiNamesMap[path] = [];
51214
51250
  }
51215
- if (!objectInfoApiMap[path].includes(ref.apiName)) {
51216
- objectInfoApiMap[path].push(ref.apiName);
51251
+ if (!pathToObjectApiNamesMap[path].includes(ref.apiName)) {
51252
+ pathToObjectApiNamesMap[path].push(ref.apiName);
51217
51253
  }
51218
51254
  if (!apiNames.includes(ref.apiName)) {
51219
51255
  apiNames.push(ref.apiName);
@@ -51224,11 +51260,11 @@ async function fetchObjectInfos(objectInfotree, objectInfoApiMap, objectInfoMap,
51224
51260
  // handles 'childRelationship'
51225
51261
  const childRelationship = parentObjectInfo.childRelationships.find((childRelationship) => childRelationship.relationshipName === field);
51226
51262
  if (childRelationship) {
51227
- if (!objectInfoApiMap[path]) {
51228
- objectInfoApiMap[path] = [];
51263
+ if (!pathToObjectApiNamesMap[path]) {
51264
+ pathToObjectApiNamesMap[path] = [];
51229
51265
  }
51230
- if (!objectInfoApiMap[path].includes(childRelationship.childObjectApiName)) {
51231
- objectInfoApiMap[path].push(childRelationship.childObjectApiName);
51266
+ if (!pathToObjectApiNamesMap[path].includes(childRelationship.childObjectApiName)) {
51267
+ pathToObjectApiNamesMap[path].push(childRelationship.childObjectApiName);
51232
51268
  }
51233
51269
  if (!apiNames.includes(childRelationship.childObjectApiName)) {
51234
51270
  apiNames.push(childRelationship.childObjectApiName);
@@ -51250,10 +51286,10 @@ async function fetchObjectInfos(objectInfotree, objectInfoApiMap, objectInfoMap,
51250
51286
  }
51251
51287
  for (const nodeInfo of validObjectInfoNodes) {
51252
51288
  const field = nodeInfo.name;
51253
- const subLevelFields = objectInfotree[field];
51254
- const path = `${parentPath}_${field}`;
51289
+ const path = `${parentPath}#${field}`;
51290
+ const subLevelFields = objectInfotree[path];
51255
51291
  if (subLevelFields && subLevelFields.length > 0) {
51256
- const subObjectInfos = await fetchObjectInfos(objectInfotree, objectInfoApiMap, updatedObjectInfoMap, subLevelFields, path, objectInfoService);
51292
+ const subObjectInfos = await fetchObjectInfos(objectInfotree, pathToObjectApiNamesMap, updatedObjectInfoMap, subLevelFields, path, objectInfoService);
51257
51293
  updatedObjectInfoMap = { ...updatedObjectInfoMap, ...subObjectInfos };
51258
51294
  }
51259
51295
  }
@@ -51268,27 +51304,29 @@ async function fetchObjectInfos(objectInfotree, objectInfoApiMap, objectInfoMap,
51268
51304
  * 'path' and 'queryNode' is 1 level above the 'filterNode'
51269
51305
  * @param filterNode filter node which needs to be injected. For example, 'State' ObjectFieldNode within filter 'where: { State: { eq: "Nova Scotia" }}'
51270
51306
  * @param idState ID state will be updated to determine if the ID fields in AST need to be swapped. The swapping happens later.
51271
- * @param path path to the current filterNode's parent. For example, path could be 'ServiceApointment' when filterNode is 'State'. If the path does not exist in 'objectInfoApiMap', parent node is not an field of relationship or recordQuery
51307
+ * @param parentPath path to the current filterNode's parent. For example, path could be 'ServiceApointment' when filterNode is 'State'. If the path does not exist in 'pathToObjectApiNamesMap', parent node is not an field of relationship or recordQuery
51308
+ * @param isParentPolymorphic true if parent points to a polymorphic field.
51272
51309
  * @param queryNode referece FieldNode which provides the information if 'filterNode' exist in it nor not.
51273
51310
  * @param objectInfos ObjectInfo map used in injection. If ObjectInfo misses or field does not exist in ObjectInfo, the error will be thrown
51274
- * @param objectInfoApiMap map used to locate the ObjectInfo. The key is path to a field, value is the ObjectInfo's apiName array. In the case of polymorphic fields, the apiName array have 2 or more elements. For example, 'ServiceAppointment' -> ['ServiceAppointment']; 'ServiceAppointment_Account' -> ['Account'], 'ServiceAppointment_Owner' -> ['User', 'Group'].
51311
+ * @param pathToObjectApiNamesMap map used to locate the ObjectInfo. The key is path to a field, value is the ObjectInfo's apiName array. In the case of polymorphic fields, the apiName array have 2 or more elements. For example, 'ServiceAppointment' -> ['ServiceAppointment']; 'ServiceAppointment_Account' -> ['Account'], 'ServiceAppointment_Owner' -> ['User', 'Group'].
51275
51312
  * @param draftFunctions functions for working with record ids that may be draft-created ids
51276
51313
  * @returns an array of nodes with injected fields
51277
51314
  */
51278
- function injectFilter(filterNode, idState, path, objectInfos, objectInfoApiMap, draftFunctions, queryNode) {
51315
+ function injectFilter(filterNode, idState, parentPath, isParentPolymorphic, objectInfos, pathToObjectApiNamesMap, draftFunctions, queryNode) {
51279
51316
  const injectedSelections = [];
51317
+ let isPolymorphicField = false;
51280
51318
  switch (filterNode.kind) {
51281
51319
  case Kind.ARGUMENT:
51282
51320
  if (filterNode.value.kind !== 'ObjectValue')
51283
51321
  return [];
51284
51322
  filterNode.value.fields.forEach((objectFieldNode) => {
51285
- let subResults = injectFilter(objectFieldNode, idState, path, objectInfos, objectInfoApiMap, draftFunctions, queryNode);
51323
+ let subResults = injectFilter(objectFieldNode, idState, parentPath, isParentPolymorphic, objectInfos, pathToObjectApiNamesMap, draftFunctions, queryNode);
51286
51324
  for (const subResult of subResults) {
51287
51325
  mergeOrAddToGroup(injectedSelections, subResult);
51288
51326
  }
51289
51327
  // multiple Ids might need to be swapped. remember their paths for faster write.
51290
51328
  if (idState.swapNeeded) {
51291
- idState.paths.push(path);
51329
+ idState.paths.push(parentPath);
51292
51330
  }
51293
51331
  });
51294
51332
  return injectedSelections;
@@ -51297,7 +51335,7 @@ function injectFilter(filterNode, idState, path, objectInfos, objectInfoApiMap,
51297
51335
  case Kind.LIST: {
51298
51336
  filterNode.value.values.filter(isObjectValueNode).forEach((objectValueNode) => {
51299
51337
  objectValueNode.fields.forEach((objectFieldNode) => {
51300
- const subResults = injectFilter(objectFieldNode, idState, path, objectInfos, objectInfoApiMap, draftFunctions, queryNode);
51338
+ const subResults = injectFilter(objectFieldNode, idState, parentPath, isParentPolymorphic, objectInfos, pathToObjectApiNamesMap, draftFunctions, queryNode);
51301
51339
  for (const subResult of subResults) {
51302
51340
  mergeOrAddToGroup(injectedSelections, subResult);
51303
51341
  }
@@ -51308,7 +51346,7 @@ function injectFilter(filterNode, idState, path, objectInfos, objectInfoApiMap,
51308
51346
  case Kind.OBJECT: {
51309
51347
  if (filterNode.name.value === 'not') {
51310
51348
  filterNode.value.fields.forEach((objectFieldNode) => {
51311
- const subResults = injectFilter(objectFieldNode, idState, path, objectInfos, objectInfoApiMap, draftFunctions, queryNode);
51349
+ const subResults = injectFilter(objectFieldNode, idState, parentPath, isParentPolymorphic, objectInfos, pathToObjectApiNamesMap, draftFunctions, queryNode);
51312
51350
  for (const subResult of subResults) {
51313
51351
  mergeOrAddToGroup(injectedSelections, subResult);
51314
51352
  }
@@ -51318,15 +51356,15 @@ function injectFilter(filterNode, idState, path, objectInfos, objectInfoApiMap,
51318
51356
  let apiNames = [];
51319
51357
  let isScalarField = false;
51320
51358
  //It is possible that this is a polymorphic field
51321
- apiNames = objectInfoApiMap[path];
51322
- // example: path: 'ServiceAppointment_LastModifiedDate'; filterNode: '{eq: {literal: LAST_WEEK}}'. queryNode: 'LastModifedDate { value}' FilterNode's parent has been verifed as a valid node
51359
+ apiNames = pathToObjectApiNamesMap[parentPath];
51360
+ // example: path: 'ServiceAppointment#LastModifiedDate'; filterNode: '{eq: {literal: LAST_WEEK}}'. queryNode: 'LastModifedDate { value}' FilterNode's parent has been verifed as a valid node
51323
51361
  if (apiNames === undefined) {
51324
51362
  isScalarField = true;
51325
51363
  }
51326
51364
  else {
51327
51365
  if (apiNames.some((apiName) => objectInfos[apiName] === undefined)) {
51328
51366
  // eslint-disable-next-line
51329
- throw new Error(`ObjectInfo is missing for ${path}`);
51367
+ throw new Error(`ObjectInfo is missing for ${parentPath}`);
51330
51368
  }
51331
51369
  }
51332
51370
  if (isScalarField) {
@@ -51348,29 +51386,19 @@ function injectFilter(filterNode, idState, path, objectInfos, objectInfoApiMap,
51348
51386
  }
51349
51387
  });
51350
51388
  let isSpanning = false;
51389
+ // if true, current node is a polymorphic concrete type node. For example, field node `User` under `Owner`
51351
51390
  let isInlineFragment = false;
51352
- let isPolymorphicField = false;
51353
51391
  let isTypeNameExisting = false;
51354
51392
  let curPath;
51355
51393
  let fieldName = filterNode.name.value;
51356
- curPath = `${path}_${fieldName}`;
51357
- if (objectInfoApiMap[curPath] && objectInfoApiMap[curPath].length > 0) {
51394
+ curPath = `${parentPath}#${fieldName}`;
51395
+ if (pathToObjectApiNamesMap[curPath] &&
51396
+ pathToObjectApiNamesMap[curPath].length > 0) {
51358
51397
  isSpanning = true;
51359
- if (objectInfoApiMap[curPath].length === 1) {
51360
- if (objectInfoApiMap[path] &&
51361
- objectInfoApiMap[path].length >= 1 &&
51362
- objectInfoApiMap[path].includes(objectInfoApiMap[curPath][0])) {
51363
- isInlineFragment = true;
51364
- }
51365
- }
51366
- // Checks if the current filter node is a polymorphic field. 'ServiceAppointment_Owner' --> ['User']; 'ServiceAppointment_Owner_User' --> ['User']
51367
- const childApiName = objectInfoApiMap[curPath][0];
51368
- const trialApiNames = objectInfoApiMap[`${curPath}_${childApiName}`];
51369
- if (trialApiNames !== undefined &&
51370
- trialApiNames.length === 1 &&
51371
- trialApiNames[0] === childApiName) {
51372
- isPolymorphicField = true;
51373
- }
51398
+ isInlineFragment =
51399
+ isParentPolymorphic &&
51400
+ pathToObjectApiNamesMap[curPath].length === 1;
51401
+ isPolymorphicField = isPolymorphicFieldPath(curPath, pathToObjectApiNamesMap, objectInfos);
51374
51402
  }
51375
51403
  // When filter node is at InLineFragment Level(a concrete entity of polymorphic field), query node is one level up. For example, ObjectFieldNode is ...{User:{...}}, queryNode is Owner:[User]
51376
51404
  if (isInlineFragment) {
@@ -51414,9 +51442,9 @@ function injectFilter(filterNode, idState, path, objectInfos, objectInfoApiMap,
51414
51442
  throw new Error(`Field ${fieldName} does not exist in ${apiNames[0]}`);
51415
51443
  }
51416
51444
  }
51417
- const objectInfoName = objectInfoApiMap[curPath] !== undefined
51418
- ? objectInfoApiMap[curPath][0]
51419
- : objectInfoApiMap[path][0];
51445
+ const objectInfoName = pathToObjectApiNamesMap[curPath] !== undefined
51446
+ ? pathToObjectApiNamesMap[curPath][0]
51447
+ : pathToObjectApiNamesMap[parentPath][0];
51420
51448
  const isIdField = isFieldAnIdField(filterNode.name.value, objectInfos[objectInfoName]);
51421
51449
  if (!isIdField) {
51422
51450
  let subSelectionNodes = [];
@@ -51428,7 +51456,7 @@ function injectFilter(filterNode, idState, path, objectInfos, objectInfoApiMap,
51428
51456
  updateIDInfo(subFieldNode, idState, draftFunctions);
51429
51457
  }
51430
51458
  // try injecting the fields within predicate no matter it has relation or not.
51431
- let subResults = injectFilter(subFieldNode, idState, curPath, objectInfos, objectInfoApiMap, draftFunctions, existingFields ? existingFields[0] : undefined);
51459
+ let subResults = injectFilter(subFieldNode, idState, curPath, isPolymorphicField, objectInfos, pathToObjectApiNamesMap, draftFunctions, existingFields ? existingFields[0] : undefined);
51432
51460
  subSelectionNodes = subSelectionNodes.concat(subResults);
51433
51461
  });
51434
51462
  if (!subFieldsHasId) {
@@ -51589,6 +51617,44 @@ function mergeOrAddToGroup(group, element) {
51589
51617
  }
51590
51618
  group.push(element);
51591
51619
  }
51620
+ // checks if the path points to a polymorphic field. For example, for the below `pathToObjectApiNamesMap`
51621
+ // {
51622
+ // 'ServiceAppointment' -> ['ServiceAppointment']
51623
+ // 'ServiceAppointment#Owner' --> ['User'],
51624
+ // 'ServiceAppointment#Owner#User' --> ['User']
51625
+ // }
51626
+ // path `ServiceAppointment#Owner` points to a polymorphic field, but path `ServiceAppointment#Owner#User` does not.
51627
+ function isPolymorphicFieldPath(path, pathToObjectApiNamesMap, objectInfos) {
51628
+ const lastSegmentIndex = path.lastIndexOf('#');
51629
+ if (lastSegmentIndex < 0) {
51630
+ return false;
51631
+ }
51632
+ const lastSegment = path.slice(lastSegmentIndex + 1);
51633
+ const parentApiPath = path.slice(0, lastSegmentIndex);
51634
+ if (pathToObjectApiNamesMap[parentApiPath] === undefined) {
51635
+ return false;
51636
+ }
51637
+ const parentObjectApiNames = pathToObjectApiNamesMap[parentApiPath];
51638
+ // If the last segment is a Polymorphic field, its immediate parent is a concrete object entity, which has 1 objectApiName mapped to the parent path in `pathToObjectApiNamesMap`.
51639
+ // For example, we like to check if `ServiceAppointment#Owner` path is polymorphic. The last segment is `Owner` and its parent `ServiceAppointment` has one element (which is also `ServiceAppointment`) array as its value.
51640
+ // Below are the entries in `pathToObjectApiNamesMap`
51641
+ // {
51642
+ // `ServiceAppointmen`t: [`ServiceAppointment`],
51643
+ // `ServiceAppointment#Owner`: [`User`, `Group`],
51644
+ // `ServiceAppointment#Owner#User`: [`User`],
51645
+ // `ServiceAppointment#Owner#Group`: [`Group`],
51646
+ // }
51647
+ if (parentObjectApiNames.length !== 1) {
51648
+ return false;
51649
+ }
51650
+ const parentObjectInfo = objectInfos[parentObjectApiNames[0]];
51651
+ const relationshipField = referenceIdFieldForRelationship(lastSegment);
51652
+ let fieldDefinition = parentObjectInfo.fields[relationshipField];
51653
+ if (fieldDefinition === undefined) {
51654
+ return false;
51655
+ }
51656
+ return fieldDefinition.polymorphicForeignKey;
51657
+ }
51592
51658
  function isFieldAnIdField(fieldName, objectInfo) {
51593
51659
  if (fieldName === 'Id')
51594
51660
  return true;
@@ -51641,10 +51707,10 @@ function updateIDInfo(fieldNode, idState, draftFunctions) {
51641
51707
  * @param parentNode parent node of param 1
51642
51708
  * @param ancestors ancester of param 1
51643
51709
  * @param objectInfos ObjectInfo map used in injection. If ObjectInfo misses or field does not exist in ObjectInfo, the error will be thrown
51644
- * @param objectInfoApiMap map used to locate the ObjectInfo. The key is path to a field, value is the ObjectInfo's apiName array. In the case of polymorphic fields, the apiName array have 2 or more elements. For example, 'ServiceAppointment' -> ['ServiceAppointment']; 'ServiceAppointment_Account' -> ['Account'], 'ServiceAppointment_Owner' -> ['User', 'Group'].
51710
+ * @param pathToObjectApiNamesMap map used to locate the ObjectInfo. The key is path to a field, value is the ObjectInfo's apiName array. In the case of polymorphic fields, the apiName array have 2 or more elements. For example, 'ServiceAppointment' -> ['ServiceAppointment']; 'ServiceAppointment#Account' -> ['Account'], 'ServiceAppointment#Owner' -> ['User', 'Group'].
51645
51711
  * @return injected SelectionNodes used to construct the InlineFragment.
51646
51712
  */
51647
- function injectFields(selections, parentNode, ancestors, objectInfos, objectInfoApiMap) {
51713
+ function injectFields(selections, parentNode, parentPath, ancestors, objectInfos, pathToObjectApiNamesMap) {
51648
51714
  /**
51649
51715
  * 1 parentship can return 2 FieldNode which need to be flattened
51650
51716
  * Concact: { ** Contact { ** ContactId {
@@ -51662,6 +51728,10 @@ function injectFields(selections, parentNode, ancestors, objectInfos, objectInfo
51662
51728
  if (!selection.selectionSet) {
51663
51729
  return selection;
51664
51730
  }
51731
+ const segment = isFieldNode(selection)
51732
+ ? selection.name.value
51733
+ : selection.typeCondition.name.value;
51734
+ const curPath = `${parentPath}#${segment}`;
51665
51735
  const spanningSubSelections = [];
51666
51736
  for (const subSelection of selection.selectionSet.selections) {
51667
51737
  if (isFieldSpanning(subSelection, selection)) {
@@ -51669,7 +51739,7 @@ function injectFields(selections, parentNode, ancestors, objectInfos, objectInfo
51669
51739
  }
51670
51740
  }
51671
51741
  // Handles multiple level field injection like 'ServiceAppointment' --> 'Account' --> 'Owner'
51672
- const subInjectedSelections = injectFields(spanningSubSelections, selection, ancestors, objectInfos, objectInfoApiMap);
51742
+ const subInjectedSelections = injectFields(spanningSubSelections, selection, curPath, ancestors, objectInfos, pathToObjectApiNamesMap);
51673
51743
  if (!selection.selectionSet) {
51674
51744
  return selection;
51675
51745
  }
@@ -51712,7 +51782,7 @@ function injectFields(selections, parentNode, ancestors, objectInfos, objectInfo
51712
51782
  }
51713
51783
  }
51714
51784
  // For polymorphic fields, the Id field is excluded.
51715
- const excludeId = selection.selectionSet.selections.every(isInlineFragmentNode);
51785
+ const excludeId = isPolymorphicFieldPath(curPath, pathToObjectApiNamesMap, objectInfos);
51716
51786
  const idSelection = [];
51717
51787
  if (!excludeId && !hasIdAlready) {
51718
51788
  idSelection.push({
@@ -51723,8 +51793,8 @@ function injectFields(selections, parentNode, ancestors, objectInfos, objectInfo
51723
51793
  },
51724
51794
  });
51725
51795
  }
51726
- // Inject '__typename' for polymorphic fields. '__typename' field acts as a reference to concrete type of a polymorphic field and is used to match JSON response with AST node. For more detail,
51727
- // please reference 'removeSyntheticFields'.
51796
+ // Inject '__typename' for InlineFragment. '__typename' field acts as a reference to concrete type of a polymorphic field or a standard field in the returned GQL response, which equals to
51797
+ // `typedCondition` of the InlineFragment in the query AST. It is used to match JSON response with AST node. For more detail, please reference 'removeSyntheticFields'.
51728
51798
  if (isInlineFragmentNode(selection) &&
51729
51799
  !selection.selectionSet.selections.find((selection) => isFieldNode(selection) && selection.name.value === '__typename')) {
51730
51800
  idSelection.push({
@@ -51758,7 +51828,7 @@ function injectFields(selections, parentNode, ancestors, objectInfos, objectInfo
51758
51828
  if (isFieldNode(parentNode) && parentNode.selectionSet && parentNode.name.value === 'node') {
51759
51829
  if (parentNode.selectionSet.selections
51760
51830
  .filter(isFieldOrInlineFragmentNode)
51761
- .some((selectionNode) => isRelationship(selectionNode, 'childRelationship'))) {
51831
+ .some((selectionNode) => isRelationship(selectionNode, CHILD_RELATIONSHIP))) {
51762
51832
  if (!parentNode.selectionSet.selections
51763
51833
  .filter(isFieldNode)
51764
51834
  .some((sibling) => sibling.name.value === 'Id')) {
@@ -51777,15 +51847,15 @@ function injectFields(selections, parentNode, ancestors, objectInfos, objectInfo
51777
51847
  if (parentInfo.parentIndex >= 0) {
51778
51848
  // example node { TimeSheetEntries { edges { node { Id }}}}
51779
51849
  const parent = parentInfo.node;
51780
- if (isRelationship(parent, 'childRelationship')) {
51850
+ if (isRelationship(parent, CHILD_RELATIONSHIP)) {
51781
51851
  const unVisitedAncestors = ancestors.slice(0, parentInfo.parentIndex);
51782
51852
  // path : "TimeSheet"
51783
51853
  const grandParentPath = findAncesterPath(unVisitedAncestors);
51784
- if (objectInfoApiMap &&
51785
- objectInfoApiMap[grandParentPath] &&
51854
+ if (pathToObjectApiNamesMap &&
51855
+ pathToObjectApiNamesMap[grandParentPath] &&
51786
51856
  objectInfos &&
51787
- objectInfos[objectInfoApiMap[grandParentPath][0]]) {
51788
- const grandParentObjectInfo = objectInfos[objectInfoApiMap[grandParentPath][0]];
51857
+ objectInfos[pathToObjectApiNamesMap[grandParentPath][0]]) {
51858
+ const grandParentObjectInfo = objectInfos[pathToObjectApiNamesMap[grandParentPath][0]];
51789
51859
  // exmaple "TimeSheetEntries"
51790
51860
  const parentFieldName = parent.name.value;
51791
51861
  const targetRelationship = grandParentObjectInfo.childRelationships.find((childRelationship) => {
@@ -51906,7 +51976,7 @@ const assignedToMeFragmentSelections = [
51906
51976
  },
51907
51977
  value: {
51908
51978
  kind: 'StringValue',
51909
- value: 'childRelationship',
51979
+ value: CHILD_RELATIONSHIP,
51910
51980
  block: false,
51911
51981
  },
51912
51982
  },
@@ -51998,7 +52068,7 @@ const assignedToMeFragmentSelections = [
51998
52068
  },
51999
52069
  value: {
52000
52070
  kind: 'StringValue',
52001
- value: 'parentRelationship',
52071
+ value: PARENT_RELATIONSHIP,
52002
52072
  block: false,
52003
52073
  },
52004
52074
  },
@@ -52135,7 +52205,9 @@ function handleNonArrayJsonProperty(selection, fieldName, jsonInput, jsonOutput)
52135
52205
  jsonOutput[fieldName] = null;
52136
52206
  return;
52137
52207
  }
52138
- jsonOutput[fieldName] = {};
52208
+ if (jsonOutput[fieldName] === undefined) {
52209
+ jsonOutput[fieldName] = {};
52210
+ }
52139
52211
  createUserJsonOutput(selection, jsonInput[fieldName], jsonOutput[fieldName]);
52140
52212
  }
52141
52213
  else {
@@ -57010,6 +57082,9 @@ class PrimingSession extends EventEmitter {
57010
57082
  this.ldsRecordRefresher = config.ldsRecordRefresher;
57011
57083
  this.networkWorkerPool = new AsyncWorkerPool(this.concurrency);
57012
57084
  this.useBatchGQL = ldsPrimingGraphqlBatch.isOpen({ fallback: false });
57085
+ if (this.useBatchGQL) {
57086
+ this.batchSize = this.batchSize / DEFAULT_GQL_QUERY_BATCH_SIZE;
57087
+ }
57013
57088
  this.conflictPool = new ConflictPool(config.store, this.objectInfoLoader);
57014
57089
  }
57015
57090
  // function that enqueues priming work
@@ -57866,7 +57941,7 @@ register({
57866
57941
  id: '@salesforce/lds-network-adapter',
57867
57942
  instrument: instrument$1,
57868
57943
  });
57869
- // version: 1.229.0-dev2-e9832aaff
57944
+ // version: 1.229.0-dev4-07d38781a
57870
57945
 
57871
57946
  const { create: create$2, keys: keys$2 } = Object;
57872
57947
  const { stringify: stringify$1, parse: parse$1 } = JSON;
@@ -72629,6 +72704,7 @@ function buildSelectionForField$7(source, reader, sel, variables, fragments, isC
72629
72704
  }
72630
72705
  if (fieldData === null) {
72631
72706
  reader.assignScalar(requestedFieldName, sink, fieldData);
72707
+ reader.exitPath();
72632
72708
  return sink;
72633
72709
  }
72634
72710
  const fieldType = getFieldType(sel);
@@ -76312,7 +76388,7 @@ register({
76312
76388
  configuration: { ...configurationForGraphQLAdapters },
76313
76389
  instrument,
76314
76390
  });
76315
- // version: 1.229.0-dev2-696fe5026
76391
+ // version: 1.229.0-dev4-4a7593877
76316
76392
 
76317
76393
  // On core the unstable adapters are re-exported with different names,
76318
76394
 
@@ -78559,7 +78635,7 @@ withDefaultLuvio((luvio) => {
78559
78635
  unstable_graphQL_imperative = createImperativeAdapter(luvio, createInstrumentedAdapter(ldsAdapter, adapterMetadata), adapterMetadata);
78560
78636
  graphQLImperative = ldsAdapter;
78561
78637
  });
78562
- // version: 1.229.0-dev2-696fe5026
78638
+ // version: 1.229.0-dev4-4a7593877
78563
78639
 
78564
78640
  var gqlApi = /*#__PURE__*/Object.freeze({
78565
78641
  __proto__: null,
@@ -79273,4 +79349,4 @@ const { luvio } = getRuntime();
79273
79349
  setDefaultLuvio({ luvio });
79274
79350
 
79275
79351
  export { createPrimingSession, draftManager, draftQueue, executeAdapter, executeMutatingAdapter, getImperativeAdapterNames, invokeAdapter, invokeAdapterWithDraftToReplace, invokeAdapterWithMetadata, nimbusDraftQueue, registerReportObserver, setMetadataTTL, setUiApiRecordTTL, subscribeToAdapter };
79276
- // version: 1.229.0-dev2-e9832aaff
79352
+ // version: 1.229.0-dev4-07d38781a