pict-section-form 1.3.14 → 1.3.16

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.
Files changed (80) hide show
  1. package/docs/Injection_Conformance.md +137 -0
  2. package/docs/Providers.md +12 -7
  3. package/docs/_sidebar.md +3 -0
  4. package/docs/input_providers/016-facet-filter.md +106 -0
  5. package/docs/input_providers/README.md +1 -0
  6. package/example_applications/README.md +6 -0
  7. package/example_applications/facet_filter/.quackage.json +9 -0
  8. package/example_applications/facet_filter/Facet-Filter-Application.js +210 -0
  9. package/example_applications/facet_filter/Facet-Filter-Server.js +233 -0
  10. package/example_applications/facet_filter/Facet-Filter-Smoke-Runner.js +101 -0
  11. package/example_applications/facet_filter/FacetFilterData.json +44 -0
  12. package/example_applications/facet_filter/README-FacetFilter.md +70 -0
  13. package/example_applications/facet_filter/html/Facet-Filter-Smoke.js +128 -0
  14. package/example_applications/facet_filter/html/index.html +74 -0
  15. package/example_applications/facet_filter/package.json +27 -0
  16. package/example_applications/nested_distill_sandbox/Sandbox-Driver-Headlight.js +17 -0
  17. package/example_applications/nested_distill_sandbox/Sandbox-Driver.js +369 -0
  18. package/example_applications/nested_distill_sandbox/Sandbox-Runner.js +372 -0
  19. package/example_applications/nested_distill_sandbox/approaches/A1-tabular-trigger-group.js +67 -0
  20. package/example_applications/nested_distill_sandbox/approaches/A3-crossmap-selectoptionsrefresh.js +61 -0
  21. package/example_applications/nested_distill_sandbox/approaches/A4-graph-solvers-flat-list.js +53 -0
  22. package/example_applications/nested_distill_sandbox/approaches/A5-facet-filter.js +75 -0
  23. package/example_applications/nested_distill_sandbox/approaches/A5b-facet-filter-symmetric.js +15 -0
  24. package/example_applications/nested_distill_sandbox/approaches/A5h-facet-filter-headlight-picker.js +15 -0
  25. package/example_applications/nested_distill_sandbox/approaches/R0-original-jmf-manifest-headlight.js +27 -0
  26. package/example_applications/nested_distill_sandbox/approaches/R1-real-jmf-manifest-headlight.js +136 -0
  27. package/example_applications/nested_distill_sandbox/approaches/_Common.js +344 -0
  28. package/example_applications/nested_distill_sandbox/approaches/_Scenarios.js +262 -0
  29. package/package.json +6 -5
  30. package/source/providers/Pict-Provider-DynamicFormSolverBehaviors.js +73 -5
  31. package/source/providers/Pict-Provider-DynamicSolver.js +22 -2
  32. package/source/providers/Pict-Provider-ListDistilling.js +266 -1
  33. package/source/providers/Pict-Provider-MetaLists.js +16 -2
  34. package/source/providers/inputs/Pict-Provider-Input-FacetFilter.js +232 -0
  35. package/source/providers/inputs/Pict-Provider-Input-Select.js +41 -1
  36. package/source/views/Pict-View-Form-Metacontroller.js +690 -93
  37. package/test/Pict-Provider-DynamicFormSolverBehaviors-OrdinalScope_tests.js +105 -0
  38. package/test/Pict-Provider-ListDistilling-Facet_tests.js +375 -0
  39. package/test/Pict-View-Form-Metacontroller-DistinctManifest_tests.js +410 -0
  40. package/test/PictSectionForm-Injection-Conformance_tests.js +762 -0
  41. package/test/browser/Injection-Conformance-Differential-Scenario.js +346 -0
  42. package/test/browser/Injection-Conformance-EdgeCase-Scenario.js +168 -0
  43. package/test/browser/Injection-Conformance-Harness-Driver.js +538 -0
  44. package/test/browser/Injection-Conformance-Harness-Runner.js +487 -0
  45. package/test/browser/Injection-Conformance-Reconstitution-Scenario.js +191 -0
  46. package/test/browser/Injection-Conformance-Standalone-Scenario.js +114 -0
  47. package/test/fixtures/injection/Injection-Fixture-Cases.js +204 -0
  48. package/test/fixtures/injection/Injection-Fixture-Manifest.json +381 -0
  49. package/types/source/providers/Pict-Provider-DynamicFormSolverBehaviors.d.ts +110 -1
  50. package/types/source/providers/Pict-Provider-DynamicFormSolverBehaviors.d.ts.map +1 -1
  51. package/types/source/providers/Pict-Provider-DynamicSolver.d.ts.map +1 -1
  52. package/types/source/providers/Pict-Provider-DynamicTabularData.d.ts +17 -1
  53. package/types/source/providers/Pict-Provider-DynamicTabularData.d.ts.map +1 -1
  54. package/types/source/providers/Pict-Provider-InputExtension.d.ts +31 -0
  55. package/types/source/providers/Pict-Provider-InputExtension.d.ts.map +1 -1
  56. package/types/source/providers/Pict-Provider-ListDistilling.d.ts +90 -1
  57. package/types/source/providers/Pict-Provider-ListDistilling.d.ts.map +1 -1
  58. package/types/source/providers/Pict-Provider-MetaLists.d.ts.map +1 -1
  59. package/types/source/providers/inputs/Pict-Provider-Input-Chart-CSS.d.ts +16 -0
  60. package/types/source/providers/inputs/Pict-Provider-Input-Chart-CSS.d.ts.map +1 -0
  61. package/types/source/providers/inputs/Pict-Provider-Input-Chart.d.ts +47 -0
  62. package/types/source/providers/inputs/Pict-Provider-Input-Chart.d.ts.map +1 -1
  63. package/types/source/providers/inputs/Pict-Provider-Input-Diagram.d.ts +86 -0
  64. package/types/source/providers/inputs/Pict-Provider-Input-Diagram.d.ts.map +1 -1
  65. package/types/source/providers/inputs/Pict-Provider-Input-FacetFilter.d.ts +103 -0
  66. package/types/source/providers/inputs/Pict-Provider-Input-FacetFilter.d.ts.map +1 -0
  67. package/types/source/providers/inputs/Pict-Provider-Input-ObjectEditor.d.ts +128 -0
  68. package/types/source/providers/inputs/Pict-Provider-Input-ObjectEditor.d.ts.map +1 -0
  69. package/types/source/providers/inputs/Pict-Provider-Input-PreciseNumber.d.ts.map +1 -1
  70. package/types/source/providers/inputs/Pict-Provider-Input-Select.d.ts +12 -0
  71. package/types/source/providers/inputs/Pict-Provider-Input-Select.d.ts.map +1 -1
  72. package/types/source/providers/inputs/Pict-Provider-Input-TabGroupSelector.d.ts +10 -1
  73. package/types/source/providers/inputs/Pict-Provider-Input-TabGroupSelector.d.ts.map +1 -1
  74. package/types/source/providers/inputs/Pict-Provider-Input-TabSectionSelector.d.ts +10 -1
  75. package/types/source/providers/inputs/Pict-Provider-Input-TabSectionSelector.d.ts.map +1 -1
  76. package/types/source/providers/layouts/Pict-Layout-Tabular.d.ts +76 -4
  77. package/types/source/providers/layouts/Pict-Layout-Tabular.d.ts.map +1 -1
  78. package/types/source/views/Pict-View-DynamicForm.d.ts.map +1 -1
  79. package/types/source/views/Pict-View-Form-Metacontroller.d.ts +63 -2
  80. package/types/source/views/Pict-View-Form-Metacontroller.d.ts.map +1 -1
@@ -7,6 +7,30 @@ const libPictViewDynamicForm = require('./Pict-View-DynamicForm.js');
7
7
  // TODO: Manage view lifecycle internally, including destruction of views if they are flagged to not be needed.
8
8
  // Why? This allows us to dynamically add and remove sections without having to reload the application.
9
9
 
10
+ // Solver directives iterate: their headers name addresses to iterate over, and declare iteration variables
11
+ // that are locals of the expression rather than anything the manifest owns.
12
+ const SOLVER_DIRECTIVE_CODES = new Set([ 'SERIES', 'MONTECARLO', 'MAP', 'MULTIROWMAP' ]);
13
+
14
+ // Everything an injected copy of a manifest can say about itself, grouped by how createDistinctManifest has
15
+ // to translate it. These drive the translation below and are exported as the checklist the injection
16
+ // conformance tests measure fixture coverage against, so a new construct cannot be added in one place only.
17
+ const INJECTION_INPUT_SECTION_HASH_PROPERTIES = [ 'TabSectionSet', 'DefaultTabSectionHash' ];
18
+ const INJECTION_INPUT_GROUP_HASH_PROPERTIES = [ 'TabGroupSet', 'DefaultTabGroupHash' ];
19
+ const INJECTION_INPUT_SOLVER_PROPERTIES = [ 'ChartLabelsSolver', 'ChartConfigCorePrototype' ];
20
+ const INJECTION_INPUT_SOLVER_SET_PROPERTIES = [ { Property: 'ChartDatasetsSolvers', SolverProperty: 'DataSolver' } ];
21
+ const INJECTION_INPUT_ADDRESS_PROPERTIES = [ 'ChartLabelsAddress', 'ChartDatasetsAddress', 'ChartConfigCorePrototypeAddress' ];
22
+ const INJECTION_INPUT_TRIGGER_GROUP_PROPERTIES = [ 'AutofillTriggerGroup', 'TemplatedEntityLookup', 'TabularTriggerGroup' ];
23
+ // A trigger group hash held on its own rather than inside a trigger group configuration. Both sides of a
24
+ // trigger read the hash from their own configuration, so salting every carrier keeps a copy's triggers
25
+ // inside that copy.
26
+ const INJECTION_INPUT_TRIGGER_GROUP_HASH_PROPERTIES = [ 'TriggerGroupHash', 'EntityBundleTriggerGroup' ];
27
+ const INJECTION_INPUT_TEMPLATE_PROPERTIES = [ 'Template' ];
28
+ const INJECTION_INPUT_ENTITY_BUNDLE_PROPERTIES = [ 'EntitiesBundle' ];
29
+ const INJECTION_ENTITY_BUNDLE_ADDRESS_PROPERTIES = [ 'Destination' ];
30
+ const INJECTION_ENTITY_BUNDLE_TEMPLATE_PROPERTIES = [ 'Filter', 'EntityFilterTemplate' ];
31
+ const INJECTION_TRIGGER_GROUP_SOLVER_PROPERTIES = [ 'PreSolvers', 'PostSolvers' ];
32
+ const INJECTION_MANIFEST_CONSTRUCTS = [ 'Sections.Solvers', 'Sections.Groups.RecordSetAddress', 'Sections.Groups.RecordSetSolvers', 'ReferenceManifests', 'ValidationSolvers', 'Descriptors.DataAddress', 'Descriptors.Hash', 'Descriptors.PictForm.Section', 'Descriptors.PictForm.Group' ];
33
+
10
34
  const PENDING_ASYNC_OPERATION_TYPE = 'PendingAsyncOperation';
11
35
  const TRANSACTION_COMPLETE_CALLBACK_TYPE = 'onTransactionComplete';
12
36
  const READY_TO_FINALIZE_TYPE = 'ReadyToFinalize';
@@ -42,6 +66,12 @@ class PictFormMetacontroller extends libPictViewClass
42
66
  this.AutoSolveOnFirstRender = true;
43
67
  this.FirstRenderCompleted = false;
44
68
 
69
+ // The PictForm properties an injected manifest can carry a trigger group in, and those that carry a
70
+ // bare trigger group hash. A host that ships input providers of its own pushes its own carriers onto
71
+ // these, so they are salted along with the rest when a manifest is injected.
72
+ this.injectionTriggerGroupProperties = INJECTION_INPUT_TRIGGER_GROUP_PROPERTIES.slice();
73
+ this.injectionTriggerGroupHashProperties = INJECTION_INPUT_TRIGGER_GROUP_HASH_PROPERTIES.slice();
74
+
45
75
  // Destination address for entity comprehensions generated by the addComprehensionEntity solver
46
76
  // function. Resolves relative to the pict instance (so `AppData.X`, `Bundle.X`, etc. all work).
47
77
  // Override in code (`this.pict.views.PictFormMetacontroller.comprehensionDestinationAddress = '...'`)
@@ -108,10 +138,12 @@ class PictFormMetacontroller extends libPictViewClass
108
138
 
109
139
  gatherInitialBundle(fCallback)
110
140
  {
111
- if (this.manifestDescription && this.manifestDescription.InitialBundle)
141
+ // Runs before bootstrap has set manifestDescription, so fall back to the manifest bootstrap will use.
142
+ const tmpManifestDescription = this.manifestDescription || this.fable.settings.DefaultFormManifest;
143
+ if (tmpManifestDescription && Array.isArray(tmpManifestDescription.InitialBundle))
112
144
  {
113
- this.log.info(`Gathering initial bundle for ${this.manifestDescription.InitialBundle.length} entities.`);
114
- return this.pict.EntityProvider.gatherDataFromServer(this.manifestDescription.InitialBundle, (pError) =>
145
+ this.log.info(`Gathering initial bundle for ${tmpManifestDescription.InitialBundle.length} entities.`);
146
+ return this.pict.EntityProvider.gatherDataFromServer(tmpManifestDescription.InitialBundle, (pError) =>
115
147
  {
116
148
  // in case of an empty array, or all tasks being synchronous, wait for the next tick so we don't get event ordering problems
117
149
  setTimeout(() => fCallback(pError), 0);
@@ -302,49 +334,278 @@ class PictFormMetacontroller extends libPictViewClass
302
334
  {
303
335
  /** @type {Record<string, string>} */
304
336
  const tmpAddressTranslation = {};
337
+ /** @type {Record<string, string>} */
338
+ const tmpHashTranslation = {};
339
+ /** @type {Array<string>} */
340
+ const tmpCollisions = [];
341
+ /**
342
+ * @param {Record<string, string>} pTranslation - The map being filled.
343
+ * @param {string} pOriginal - What the reference was called before the copy was salted.
344
+ * @param {string} pTranslated - What it is called in this copy.
345
+ */
346
+ const addTranslation = (pTranslation, pOriginal, pTranslated) =>
347
+ {
348
+ if ((pOriginal in pTranslation) && (pTranslation[pOriginal] !== pTranslated))
349
+ {
350
+ tmpCollisions.push(`${pOriginal} -> ${pTranslation[pOriginal]} | ${pTranslated}`);
351
+ }
352
+ pTranslation[pOriginal] = pTranslated;
353
+ };
305
354
  for (const tmpSection of pManifest.Sections || [])
306
355
  {
307
356
  if (tmpSection.OriginalHash)
308
357
  {
309
- tmpAddressTranslation[tmpSection.OriginalHash] = tmpSection.Hash;
358
+ addTranslation(tmpAddressTranslation, tmpSection.OriginalHash, tmpSection.Hash);
310
359
  }
311
360
  for (const tmpGroup of tmpSection.Groups || [])
312
361
  {
313
362
  if (tmpGroup.OriginalHash)
314
363
  {
315
- tmpAddressTranslation[tmpGroup.OriginalHash] = tmpGroup.Hash;
364
+ addTranslation(tmpAddressTranslation, tmpGroup.OriginalHash, tmpGroup.Hash);
316
365
  }
317
366
  }
318
367
  }
319
- /** @type {Record<string, string>} */
320
- const tmpHashTranslation = {};
321
368
  for (const tmpDescriptor of Object.values(pManifest?.Descriptors || {}))
322
369
  {
323
370
  if (tmpDescriptor.OriginalDataAddress)
324
371
  {
325
- tmpAddressTranslation[tmpDescriptor.OriginalDataAddress] = tmpDescriptor.DataAddress;
372
+ addTranslation(tmpAddressTranslation, tmpDescriptor.OriginalDataAddress, tmpDescriptor.DataAddress);
326
373
  }
327
374
  if (tmpDescriptor.OriginalHash)
328
375
  {
329
- tmpHashTranslation[tmpDescriptor.OriginalHash] = tmpDescriptor.Hash;
376
+ addTranslation(tmpHashTranslation, tmpDescriptor.OriginalHash, tmpDescriptor.Hash);
330
377
  }
331
378
  }
379
+ if (tmpCollisions.length > 0)
380
+ {
381
+ // More than one copy of the same manifest is in here, so no single map can say what a name became.
382
+ // Build the translation from each copy as it is salted instead of from the form they were merged into.
383
+ this.pict.log.warn(`PictFormMetacontroller.buildManifestTranslations: ${tmpCollisions.length} reference(s) translate to more than one destination, so the last one wins. This manifest holds more than one injected copy.`, { Collisions: tmpCollisions.slice(0, 10) });
384
+ }
332
385
  return { AddressTranslation: tmpAddressTranslation, HashTranslation: tmpHashTranslation };
333
386
  }
334
387
 
388
+ /**
389
+ * Translates a reference to something the manifest owns -- an exact hash or address, or a reference that
390
+ * only starts with one (`Rows.length`, `Rows[0].Line`, `Crate.Items.length`), where the longest address
391
+ * the reference starts with wins.
392
+ *
393
+ * @param {string} pReference - The reference to translate.
394
+ * @param {Record<string, string>} pPrimaryTranslation - Consulted first: hashes for symbols, addresses for address-shaped references.
395
+ * @param {Record<string, string>} pSecondaryTranslation - Consulted second.
396
+ * @param {Record<string, string>} [pPrefixTranslation] - Addresses that a partial reference may start with.
397
+ *
398
+ * @return {string|null} The translated reference, or null when the manifest does not own it.
399
+ */
400
+ translateManifestReference(pReference, pPrimaryTranslation, pSecondaryTranslation, pPrefixTranslation)
401
+ {
402
+ if ((typeof(pReference) !== 'string') || (pReference.length === 0))
403
+ {
404
+ return null;
405
+ }
406
+ const tmpPrefixTranslation = pPrefixTranslation || { };
407
+ if (pReference in pPrimaryTranslation)
408
+ {
409
+ return pPrimaryTranslation[pReference];
410
+ }
411
+ if (pReference in pSecondaryTranslation)
412
+ {
413
+ return pSecondaryTranslation[pReference];
414
+ }
415
+ if (pReference in tmpPrefixTranslation)
416
+ {
417
+ return tmpPrefixTranslation[pReference];
418
+ }
419
+ for (let i = pReference.length - 1; i > 0; i--)
420
+ {
421
+ if ((pReference[i] !== '.') && (pReference[i] !== '['))
422
+ {
423
+ continue;
424
+ }
425
+ const tmpPrefix = pReference.substring(0, i);
426
+ if (tmpPrefix in tmpPrefixTranslation)
427
+ {
428
+ return `${tmpPrefixTranslation[tmpPrefix]}${pReference.substring(i)}`;
429
+ }
430
+ }
431
+ return null;
432
+ }
433
+
434
+ /**
435
+ * Finds the SERIES / MAP / MULTIROWMAP / MONTECARLO directive in a tokenized solver expression, if there
436
+ * is one, and reads its header the way the expression parser does: which header positions hold an address
437
+ * to iterate over (everything else in a header, keyword or not, is not a reference to translate -- notably
438
+ * the per-row property a MULTIROWMAP variable reads), and which names the body sees as iteration variables
439
+ * rather than as addresses.
440
+ *
441
+ * @param {Array<string>} pTokens - The raw tokens of the expression.
442
+ *
443
+ * @return {{ Code: string, HeaderStart: number, HeaderEnd: number, TranslateIndices: Set<number>, Locals: Set<string> }|null} null when the expression has no directive.
444
+ */
445
+ parseSolverDirectiveScope(pTokens)
446
+ {
447
+ let tmpDirectiveIndex = -1;
448
+ for (let i = 0; i < pTokens.length; i++)
449
+ {
450
+ if (SOLVER_DIRECTIVE_CODES.has(String(pTokens[i]).toUpperCase()) && ((i === 0) || (pTokens[i - 1] === '=') || (pTokens[i - 1] === '?=')))
451
+ {
452
+ tmpDirectiveIndex = i;
453
+ break;
454
+ }
455
+ }
456
+ if (tmpDirectiveIndex < 0)
457
+ {
458
+ return null;
459
+ }
460
+ const tmpHeaderEnd = pTokens.indexOf(':', tmpDirectiveIndex + 1);
461
+ if (tmpHeaderEnd < 0)
462
+ {
463
+ return null;
464
+ }
465
+ const tmpCode = String(pTokens[tmpDirectiveIndex]).toUpperCase();
466
+ const tmpTranslateIndices = new Set();
467
+ const tmpLocals = new Set([ 'stepIndex' ]);
468
+ if (tmpCode === 'SERIES')
469
+ {
470
+ tmpLocals.add('n');
471
+ tmpLocals.add('prev_n');
472
+ }
473
+ if (tmpCode === 'MULTIROWMAP')
474
+ {
475
+ tmpLocals.add('rowIndex');
476
+ }
477
+ for (let i = tmpDirectiveIndex + 1; i < tmpHeaderEnd; i++)
478
+ {
479
+ const tmpToken = String(pTokens[i]).toUpperCase();
480
+ const tmpPreviousToken = String(pTokens[i - 1]).toUpperCase();
481
+ if ((tmpCode === 'SERIES') && ((tmpPreviousToken === 'FROM') || (tmpPreviousToken === 'TO') || (tmpPreviousToken === 'STEP')))
482
+ {
483
+ tmpTranslateIndices.add(i);
484
+ continue;
485
+ }
486
+ if ((tmpToken !== 'VAR') && (tmpToken !== 'VARIABLE') && (tmpToken !== 'V'))
487
+ {
488
+ if ((tmpCode === 'MULTIROWMAP') && (tmpToken === 'ROWS') && (String(pTokens[i + 1]).toUpperCase() === 'FROM') && ((i + 2) < tmpHeaderEnd))
489
+ {
490
+ tmpTranslateIndices.add(i + 2);
491
+ }
492
+ continue;
493
+ }
494
+ const tmpVariableIndex = i + 1;
495
+ if (tmpVariableIndex >= tmpHeaderEnd)
496
+ {
497
+ continue;
498
+ }
499
+ tmpLocals.add(String(pTokens[tmpVariableIndex]));
500
+ if (tmpCode === 'MAP')
501
+ {
502
+ tmpLocals.add(`prev_${pTokens[tmpVariableIndex]}`);
503
+ if ((String(pTokens[tmpVariableIndex + 1]).toUpperCase() === 'FROM') && ((tmpVariableIndex + 2) < tmpHeaderEnd))
504
+ {
505
+ tmpTranslateIndices.add(tmpVariableIndex + 2);
506
+ }
507
+ }
508
+ }
509
+ return { Code: tmpCode, HeaderStart: tmpDirectiveIndex, HeaderEnd: tmpHeaderEnd, TranslateIndices: tmpTranslateIndices, Locals: tmpLocals };
510
+ }
511
+
512
+ /**
513
+ * Collects every trigger group an injected manifest declares and maps it onto a salted hash, so a change
514
+ * in one copy does not run the matching trigger group in another copy of the same manifest.
515
+ *
516
+ * A manifest that means to hear the form it is injected into lists those hashes in `SharedTriggerGroups`
517
+ * at its root; those are left alone.
518
+ *
519
+ * @param {Record<string, any>} pManifest - The manifest being copied.
520
+ * @param {string} pUUID - The salt appended to each hash.
521
+ *
522
+ * @return {Record<string, string>} Original trigger group hash to salted hash.
523
+ */
524
+ buildTriggerGroupTranslation(pManifest, pUUID)
525
+ {
526
+ /** @type {Record<string, string>} */
527
+ const tmpTriggerGroupTranslation = {};
528
+ const tmpSharedTriggerGroups = Array.isArray(pManifest.SharedTriggerGroups) ? pManifest.SharedTriggerGroups : [];
529
+ const tmpTriggerGroupProperties = this.injectionTriggerGroupProperties || INJECTION_INPUT_TRIGGER_GROUP_PROPERTIES;
530
+ const tmpTriggerGroupHashProperties = this.injectionTriggerGroupHashProperties || INJECTION_INPUT_TRIGGER_GROUP_HASH_PROPERTIES;
531
+ /**
532
+ * @param {any} pHash - A trigger group hash, or an array of them.
533
+ */
534
+ const addTriggerGroupHash = (pHash) =>
535
+ {
536
+ if (Array.isArray(pHash))
537
+ {
538
+ for (const tmpHash of pHash)
539
+ {
540
+ addTriggerGroupHash(tmpHash);
541
+ }
542
+ return;
543
+ }
544
+ if ((typeof(pHash) !== 'string') || (pHash.length === 0) || tmpSharedTriggerGroups.includes(pHash))
545
+ {
546
+ return;
547
+ }
548
+ tmpTriggerGroupTranslation[pHash] = `${pHash}_${pUUID}`;
549
+ };
550
+ /**
551
+ * @param {any} pPictForm - The PictForm configuration of an input.
552
+ */
553
+ const addInputTriggerGroupHashes = (pPictForm) =>
554
+ {
555
+ if (!pPictForm || (typeof(pPictForm) !== 'object'))
556
+ {
557
+ return;
558
+ }
559
+ for (const tmpTriggerGroupProperty of tmpTriggerGroupProperties)
560
+ {
561
+ const tmpTriggerGroupConfiguration = pPictForm[tmpTriggerGroupProperty];
562
+ const tmpTriggerGroups = Array.isArray(tmpTriggerGroupConfiguration) ? tmpTriggerGroupConfiguration : [ tmpTriggerGroupConfiguration ];
563
+ for (const tmpTriggerGroup of tmpTriggerGroups)
564
+ {
565
+ if (tmpTriggerGroup && (typeof(tmpTriggerGroup) === 'object'))
566
+ {
567
+ addTriggerGroupHash(tmpTriggerGroup.TriggerGroupHash);
568
+ }
569
+ }
570
+ }
571
+ for (const tmpTriggerGroupHashProperty of tmpTriggerGroupHashProperties)
572
+ {
573
+ addTriggerGroupHash(pPictForm[tmpTriggerGroupHashProperty]);
574
+ }
575
+ };
576
+ for (const tmpDescriptor of Object.values(pManifest.Descriptors || {}))
577
+ {
578
+ addInputTriggerGroupHashes(tmpDescriptor.PictForm);
579
+ }
580
+ for (const tmpReferenceManifest of Object.values(pManifest.ReferenceManifests || {}))
581
+ {
582
+ for (const tmpColumnDescriptor of Object.values(tmpReferenceManifest.Descriptors || {}))
583
+ {
584
+ addInputTriggerGroupHashes(tmpColumnDescriptor.PictForm);
585
+ }
586
+ }
587
+ return tmpTriggerGroupTranslation;
588
+ }
589
+
335
590
  /**
336
591
  * Rewrite a solver expression by tokenizing, replacing address/hash tokens, and recomposing.
337
592
  *
338
593
  * @param {string} pExpression - The solver expression string.
339
594
  * @param {Record<string, string>} pHashTranslation - A mapping of original hashes to new hashes for replacement.
340
595
  * @param {Record<string, string>} pAddressTranslation - A mapping of original addresses to new addresses for replacement.
596
+ * @param {{ PrefixAddressTranslation?: Record<string, string>, RowRelative?: boolean }} [pOptions] - PrefixAddressTranslation holds the addresses a partial reference may start with (defaults to pAddressTranslation); RowRelative marks an expression solved against a record of a record set rather than against the manifest.
341
597
  *
342
598
  * @return {string} The rewritten expression, or the original if no changes were made.
343
599
  */
344
- rewriteSolverExpression(pExpression, pHashTranslation, pAddressTranslation)
600
+ rewriteSolverExpression(pExpression, pHashTranslation, pAddressTranslation, pOptions)
345
601
  {
346
602
  const tmpHashTranslation = pHashTranslation || { };
347
603
  const tmpAddressTranslation = pAddressTranslation || { };
604
+ const tmpOptions = pOptions || { };
605
+ const tmpPrefixAddressTranslation = tmpOptions.PrefixAddressTranslation || tmpAddressTranslation;
606
+ // A record set solver is solved against one record of the set, so a bare reference in it names a column
607
+ // of that record; only references that are absolute can be ours to translate.
608
+ const tmpRowRelative = Boolean(tmpOptions.RowRelative);
348
609
 
349
610
  // Use the expression parser tokenizer for discrete token-based solver rewriting.
350
611
  // This avoids the regex word-boundary issues when hash and address are the same string.
@@ -356,11 +617,41 @@ class PictFormMetacontroller extends libPictViewClass
356
617
  return pExpression;
357
618
  }
358
619
 
620
+ /**
621
+ * @param {string} pReference - The reference held by the token.
622
+ * @param {boolean} pPreferHash - Whether a hash translation wins over an address translation.
623
+ * @param {boolean} pManifestRelative - Whether a bare reference resolves against the manifest.
624
+ *
625
+ * @return {string|null} The translated reference, or null when nothing matched.
626
+ */
627
+ const translateReference = (pReference, pPreferHash, pManifestRelative) =>
628
+ {
629
+ if (pManifestRelative)
630
+ {
631
+ const tmpTranslated = this.translateManifestReference(pReference, pPreferHash ? tmpHashTranslation : tmpAddressTranslation, pPreferHash ? tmpAddressTranslation : tmpHashTranslation, tmpPrefixAddressTranslation);
632
+ if (tmpTranslated !== null)
633
+ {
634
+ return tmpTranslated;
635
+ }
636
+ }
637
+ if (tmpMarshalDestination && pReference.startsWith(`${tmpMarshalDestination}.`))
638
+ {
639
+ // Behind the marshal destination the reference is an address, so addresses win over hashes.
640
+ const tmpTranslated = this.translateManifestReference(pReference.substring(tmpMarshalDestination.length + 1), tmpAddressTranslation, tmpHashTranslation, tmpPrefixAddressTranslation);
641
+ if (tmpTranslated !== null)
642
+ {
643
+ return `${tmpMarshalDestination}.${tmpTranslated}`;
644
+ }
645
+ }
646
+ return null;
647
+ };
648
+
359
649
  let tmpResultObject = {};
360
650
  tmpExpressionParser.tokenize(pExpression, tmpResultObject);
361
651
 
362
652
  let tmpTokens = Array.from(tmpResultObject.OriginalRawTokens);
363
653
  let tmpModified = false;
654
+ const tmpDirectiveScope = this.parseSolverDirectiveScope(tmpTokens);
364
655
 
365
656
  // Function context stack for tracking string parameters inside annotated functions
366
657
  let tmpFunctionStack = [];
@@ -371,6 +662,18 @@ class PictFormMetacontroller extends libPictViewClass
371
662
  let tmpToken = tmpTokens[i];
372
663
  let tmpTokenType = tmpExpressionParser.Tokenizer.getTokenType(tmpToken);
373
664
 
665
+ if (tmpDirectiveScope)
666
+ {
667
+ if ((i >= tmpDirectiveScope.HeaderStart) && (i <= tmpDirectiveScope.HeaderEnd) && !tmpDirectiveScope.TranslateIndices.has(i))
668
+ {
669
+ continue;
670
+ }
671
+ if ((i > tmpDirectiveScope.HeaderEnd) && tmpDirectiveScope.Locals.has(String(tmpToken).replace(/^\{|\}$/g, '').split(/[.[]/)[0]))
672
+ {
673
+ continue;
674
+ }
675
+ }
676
+
374
677
  // Track parenthesis depth and function context
375
678
  if (tmpToken === '(')
376
679
  {
@@ -407,29 +710,7 @@ class PictFormMetacontroller extends libPictViewClass
407
710
  // Token.Symbol -- check hash mappings then address mappings
408
711
  if (tmpTokenType === 'Token.Symbol')
409
712
  {
410
- let tmpReplacement = null;
411
-
412
- if (tmpToken in tmpHashTranslation)
413
- {
414
- tmpReplacement = tmpHashTranslation[tmpToken];
415
- }
416
- else if (tmpToken in tmpAddressTranslation)
417
- {
418
- tmpReplacement = tmpAddressTranslation[tmpToken];
419
- }
420
- // Check with viewMarshalDestination prefix stripped
421
- else if (tmpMarshalDestination && tmpToken.startsWith(tmpMarshalDestination + '.'))
422
- {
423
- let tmpStripped = tmpToken.substring(tmpMarshalDestination.length + 1);
424
- if (tmpStripped in tmpHashTranslation)
425
- {
426
- tmpReplacement = tmpMarshalDestination + '.' + tmpHashTranslation[tmpStripped];
427
- }
428
- else if (tmpStripped in tmpAddressTranslation)
429
- {
430
- tmpReplacement = tmpMarshalDestination + '.' + tmpAddressTranslation[tmpStripped];
431
- }
432
- }
713
+ const tmpReplacement = translateReference(tmpToken, true, !tmpRowRelative);
433
714
 
434
715
  if (tmpReplacement !== null)
435
716
  {
@@ -440,33 +721,11 @@ class PictFormMetacontroller extends libPictViewClass
440
721
  // Token.StateAddress -- extract inner address, check mappings with and without marshal prefix
441
722
  else if (tmpTokenType === 'Token.StateAddress')
442
723
  {
443
- let tmpInner = tmpToken.substring(1, tmpToken.length - 1);
444
- let tmpReplacement = null;
445
-
446
- if (tmpInner in tmpAddressTranslation)
447
- {
448
- tmpReplacement = '{' + tmpAddressTranslation[tmpInner] + '}';
449
- }
450
- else if (tmpInner in tmpHashTranslation)
451
- {
452
- tmpReplacement = '{' + tmpHashTranslation[tmpInner] + '}';
453
- }
454
- else if (tmpMarshalDestination && tmpInner.startsWith(tmpMarshalDestination + '.'))
455
- {
456
- let tmpStripped = tmpInner.substring(tmpMarshalDestination.length + 1);
457
- if (tmpStripped in tmpAddressTranslation)
458
- {
459
- tmpReplacement = '{' + tmpMarshalDestination + '.' + tmpAddressTranslation[tmpStripped] + '}';
460
- }
461
- else if (tmpStripped in tmpHashTranslation)
462
- {
463
- tmpReplacement = '{' + tmpMarshalDestination + '.' + tmpHashTranslation[tmpStripped] + '}';
464
- }
465
- }
724
+ const tmpReplacement = translateReference(tmpToken.substring(1, tmpToken.length - 1), false, !tmpRowRelative);
466
725
 
467
726
  if (tmpReplacement !== null)
468
727
  {
469
- tmpTokens[i] = tmpReplacement;
728
+ tmpTokens[i] = `{${tmpReplacement}}`;
470
729
  tmpModified = true;
471
730
  }
472
731
  }
@@ -478,34 +737,12 @@ class PictFormMetacontroller extends libPictViewClass
478
737
 
479
738
  if (tmpFuncEntry && Array.isArray(tmpFuncEntry.AddressParameterIndices) && tmpFuncEntry.AddressParameterIndices.includes(tmpCurrentFunc.paramIndex))
480
739
  {
481
- let tmpStringContent = tmpToken.substring(1, tmpToken.length - 1);
482
- let tmpReplacement = null;
483
-
484
- // Check hash mappings first (hash-style rewrite for string parameters)
485
- if (tmpStringContent in tmpHashTranslation)
486
- {
487
- tmpReplacement = '"' + tmpHashTranslation[tmpStringContent] + '"';
488
- }
489
- else if (tmpStringContent in tmpAddressTranslation)
490
- {
491
- tmpReplacement = '"' + tmpAddressTranslation[tmpStringContent] + '"';
492
- }
493
- else if (tmpMarshalDestination && tmpStringContent.startsWith(tmpMarshalDestination + '.'))
494
- {
495
- let tmpStripped = tmpStringContent.substring(tmpMarshalDestination.length + 1);
496
- if (tmpStripped in tmpHashTranslation)
497
- {
498
- tmpReplacement = '"' + tmpMarshalDestination + '.' + tmpHashTranslation[tmpStripped] + '"';
499
- }
500
- else if (tmpStripped in tmpAddressTranslation)
501
- {
502
- tmpReplacement = '"' + tmpMarshalDestination + '.' + tmpAddressTranslation[tmpStripped] + '"';
503
- }
504
- }
740
+ // String parameters name a hash or an absolute address, never a column of a record.
741
+ const tmpReplacement = translateReference(tmpToken.substring(1, tmpToken.length - 1), true, true);
505
742
 
506
743
  if (tmpReplacement !== null)
507
744
  {
508
- tmpTokens[i] = tmpReplacement;
745
+ tmpTokens[i] = `"${tmpReplacement}"`;
509
746
  tmpModified = true;
510
747
  }
511
748
  }
@@ -536,6 +773,14 @@ class PictFormMetacontroller extends libPictViewClass
536
773
  const tmpManifest = JSON.parse(JSON.stringify(pManifest));
537
774
  /** @type {Record<string, string>} */
538
775
  const tmpAddressTranslation = {};
776
+ /** @type {Record<string, string>} */
777
+ const tmpSectionTranslation = {};
778
+ /** @type {Record<string, string>} */
779
+ const tmpGroupTranslation = {};
780
+ /** @type {Record<string, string>} */
781
+ const tmpRecordSetTranslation = {};
782
+ /** @type {Record<string, string>} */
783
+ const tmpTriggerGroupTranslation = this.buildTriggerGroupTranslation(tmpManifest, tmpUUID);
539
784
  for (const tmpSection of tmpManifest.Sections || [])
540
785
  {
541
786
  if (!tmpSection.Hash)
@@ -545,6 +790,7 @@ class PictFormMetacontroller extends libPictViewClass
545
790
  tmpSection.OriginalHash = tmpSection.Hash;
546
791
  tmpSection.Hash = `${tmpSection.Hash}_${tmpUUID}`;
547
792
  tmpAddressTranslation[tmpSection.OriginalHash] = tmpSection.Hash;
793
+ tmpSectionTranslation[tmpSection.OriginalHash] = tmpSection.Hash;
548
794
  for (const tmpGroup of tmpSection.Groups || [])
549
795
  {
550
796
  if (!tmpGroup.Hash)
@@ -554,6 +800,14 @@ class PictFormMetacontroller extends libPictViewClass
554
800
  tmpGroup.OriginalHash = tmpGroup.Hash;
555
801
  tmpGroup.Hash = `${tmpGroup.Hash}_${tmpUUID}`;
556
802
  tmpAddressTranslation[tmpGroup.OriginalHash] = tmpGroup.Hash;
803
+ tmpGroupTranslation[tmpGroup.OriginalHash] = tmpGroup.Hash;
804
+ if (tmpGroup.RecordSetAddress)
805
+ {
806
+ const tmpRecordSetAddress = `${tmpUUID}.${tmpGroup.RecordSetAddress}`;
807
+ this.pict.log.info(`PictFormMetacontroller.createDistinctManifest: Updated group record set address from "${tmpGroup.RecordSetAddress}" to "${tmpRecordSetAddress}".`);
808
+ tmpRecordSetTranslation[tmpGroup.RecordSetAddress] = tmpRecordSetAddress;
809
+ tmpGroup.RecordSetAddress = tmpRecordSetAddress;
810
+ }
557
811
  }
558
812
  }
559
813
  /** @type {Record<string, ManifestDescriptor>} */
@@ -629,7 +883,7 @@ class PictFormMetacontroller extends libPictViewClass
629
883
  const tmpTranslatedAddress = tmpAddressTranslation[tmpIterAddress].replace(new RegExp(`^${escapeRegExp(tmpOriginalAddress)}\\b`, 'g'), tmpUpdatedAddress);
630
884
  if (tmpTranslatedAddress !== tmpAddressTranslation[tmpIterAddress])
631
885
  {
632
- this.pict.log.info(`DocumentDynamicSectionManager.createDistinctManifest: Updated address translation for "${tmpIterAddress}" from "${tmpAddressTranslation[tmpIterAddress]}" to "${tmpTranslatedAddress}".`);
886
+ this.pict.log.info(`PictFormMetacontroller.createDistinctManifest: Updated address translation for "${tmpIterAddress}" from "${tmpAddressTranslation[tmpIterAddress]}" to "${tmpTranslatedAddress}".`);
633
887
  tmpAddressTranslation[tmpIterAddress] = tmpTranslatedAddress;
634
888
  const [ tmpCurrentKey, tmpOriginalDescriptor ] = Object.entries(tmpManifest.Descriptors).find(([ pKey, pDescriptor ]) => pDescriptor.OriginalDataAddress === tmpIterAddress);
635
889
  tmpManifest.Descriptors[tmpCurrentKey].DataAddress = tmpTranslatedAddress;
@@ -642,14 +896,27 @@ class PictFormMetacontroller extends libPictViewClass
642
896
  }
643
897
  }
644
898
  }
899
+ // The addresses a partial reference (`Rows.length`, `Crate.Items[0]`) may start with: every address the
900
+ // manifest declares, plus the record set addresses, which have no descriptor of their own.
901
+ /** @type {Record<string, string>} */
902
+ const tmpPrefixAddressTranslation = Object.assign({}, tmpRecordSetTranslation);
903
+ for (const tmpDescriptor of Object.values(tmpManifest.Descriptors || {}))
904
+ {
905
+ if (tmpDescriptor.OriginalDataAddress)
906
+ {
907
+ tmpPrefixAddressTranslation[tmpDescriptor.OriginalDataAddress] = tmpDescriptor.DataAddress;
908
+ }
909
+ }
910
+
645
911
  /**
646
912
  * Rewrite a single solver entry (string or object with Expression property).
647
913
  *
648
914
  * @param {Array} pSolverArray - The array of solvers to rewrite in.
649
915
  * @param {number} pIndex - The index of the solver to rewrite.
650
916
  * @param {string} pLogPrefix - Logging prefix for identification.
917
+ * @param {{ RowRelative?: boolean }} [pSolverOptions] - Passed through to rewriteSolverExpression.
651
918
  */
652
- const rewriteSolverEntry = (pSolverArray, pIndex, pLogPrefix) =>
919
+ const rewriteSolverEntry = (pSolverArray, pIndex, pLogPrefix, pSolverOptions) =>
653
920
  {
654
921
  const tmpSolver = pSolverArray[pIndex];
655
922
  const tmpSolverExpression = typeof tmpSolver === 'string' ? tmpSolver : tmpSolver.Expression;
@@ -657,10 +924,10 @@ class PictFormMetacontroller extends libPictViewClass
657
924
  {
658
925
  return;
659
926
  }
660
- const tmpUpdatedSolver = this.rewriteSolverExpression(tmpSolverExpression, tmpHashTranslation, tmpAddressTranslation);
927
+ const tmpUpdatedSolver = this.rewriteSolverExpression(tmpSolverExpression, tmpHashTranslation, tmpAddressTranslation, Object.assign({ PrefixAddressTranslation: tmpPrefixAddressTranslation }, pSolverOptions));
661
928
  if (tmpUpdatedSolver !== tmpSolverExpression)
662
929
  {
663
- this.pict.log.info(`DocumentDynamicSectionManager.createDistinctManifest: Updated ${pLogPrefix} ${pIndex} from "${tmpSolverExpression}" to "${tmpUpdatedSolver}".`);
930
+ this.pict.log.info(`PictFormMetacontroller.createDistinctManifest: Updated ${pLogPrefix} ${pIndex} from "${tmpSolverExpression}" to "${tmpUpdatedSolver}".`);
664
931
  if (typeof tmpSolver === 'string')
665
932
  {
666
933
  pSolverArray[pIndex] = tmpUpdatedSolver;
@@ -683,20 +950,289 @@ class PictFormMetacontroller extends libPictViewClass
683
950
  }
684
951
  for (const tmpGroup of tmpSection.Groups || [])
685
952
  {
686
- if (tmpGroup.RecordSetAddress)
687
- {
688
- let tmpRecordSetAddress = `${tmpUUID}.${tmpGroup.RecordSetAddress}`;
689
- this.pict.log.info(`DocumentDynamicSectionManager.createDistinctManifest: Updated group record set address from "${tmpGroup.RecordSetAddress}" to "${tmpRecordSetAddress}".`);
690
- tmpGroup.RecordSetAddress = tmpRecordSetAddress;
691
- }
692
953
  if (Array.isArray(tmpGroup.RecordSetSolvers) && tmpGroup.RecordSetSolvers.length > 0)
693
954
  {
694
955
  for (let i = 0; i < tmpGroup.RecordSetSolvers.length; i++)
695
956
  {
696
- rewriteSolverEntry(tmpGroup.RecordSetSolvers, i, 'group solver reference');
957
+ rewriteSolverEntry(tmpGroup.RecordSetSolvers, i, 'group solver reference', { RowRelative: true });
958
+ }
959
+ }
960
+ }
961
+ }
962
+
963
+ /**
964
+ * @param {any} pValue - A hash, or an array of hashes.
965
+ * @param {Record<string, string>} pTranslation - The hashes this manifest owns.
966
+ *
967
+ * @return {any} The value, with any hash the manifest owns translated.
968
+ */
969
+ const translateHashReference = (pValue, pTranslation) =>
970
+ {
971
+ if (typeof(pValue) === 'string')
972
+ {
973
+ return (pValue in pTranslation) ? pTranslation[pValue] : pValue;
974
+ }
975
+ if (Array.isArray(pValue))
976
+ {
977
+ return pValue.map((pHash) => (((typeof(pHash) === 'string') && (pHash in pTranslation)) ? pTranslation[pHash] : pHash));
978
+ }
979
+ return pValue;
980
+ };
981
+
982
+ /**
983
+ * Configuration addresses resolve from the application root, so they are only ours when they point
984
+ * into the marshal destination.
985
+ *
986
+ * @param {any} pAddress - The configured address.
987
+ *
988
+ * @return {any} The address, nested into this injection when the manifest owns it.
989
+ */
990
+ const rewriteAbsoluteAddress = (pAddress) =>
991
+ {
992
+ const tmpMarshalDestination = this.viewMarshalDestination;
993
+ if ((typeof(pAddress) !== 'string') || !tmpMarshalDestination || !pAddress.startsWith(`${tmpMarshalDestination}.`))
994
+ {
995
+ return pAddress;
996
+ }
997
+ const tmpTranslated = this.translateManifestReference(pAddress.substring(tmpMarshalDestination.length + 1), tmpAddressTranslation, tmpHashTranslation, tmpPrefixAddressTranslation);
998
+ return (tmpTranslated === null) ? pAddress : `${tmpMarshalDestination}.${tmpTranslated}`;
999
+ };
1000
+
1001
+ /**
1002
+ * @param {any} pSolverExpression - A solver expression configured on an input.
1003
+ * @param {string} pLogPrefix - Logging prefix for identification.
1004
+ *
1005
+ * @return {any} The rewritten expression.
1006
+ */
1007
+ const rewriteSolverValue = (pSolverExpression, pLogPrefix) =>
1008
+ {
1009
+ if (typeof(pSolverExpression) !== 'string')
1010
+ {
1011
+ return pSolverExpression;
1012
+ }
1013
+ const tmpSolverContainer = [ pSolverExpression ];
1014
+ rewriteSolverEntry(tmpSolverContainer, 0, pLogPrefix);
1015
+ return tmpSolverContainer[0];
1016
+ };
1017
+
1018
+ /**
1019
+ * Input templates render against the marshal destination, so the addresses they reference are ours.
1020
+ *
1021
+ * @param {any} pTemplate - The configured template.
1022
+ *
1023
+ * @return {any} The template, with local addresses nested into this injection.
1024
+ */
1025
+ const rewriteTemplateAddresses = (pTemplate) =>
1026
+ {
1027
+ if (typeof(pTemplate) !== 'string')
1028
+ {
1029
+ return pTemplate;
1030
+ }
1031
+ const tmpMarshalDestination = this.viewMarshalDestination;
1032
+ const tmpTemplateRoots = [ 'Record.Data.' ];
1033
+ if (tmpMarshalDestination)
1034
+ {
1035
+ tmpTemplateRoots.push(`${tmpMarshalDestination}.`);
1036
+ }
1037
+ let tmpTemplate = pTemplate;
1038
+ for (const tmpTemplateRoot of tmpTemplateRoots)
1039
+ {
1040
+ tmpTemplate = tmpTemplate.replace(new RegExp(`${escapeRegExp(tmpTemplateRoot)}([A-Za-z0-9_$.[\\]]+)`, 'g'),
1041
+ (pMatch, pAddress) =>
1042
+ {
1043
+ const tmpTranslated = this.translateManifestReference(pAddress, tmpAddressTranslation, tmpHashTranslation, tmpPrefixAddressTranslation);
1044
+ return (tmpTranslated === null) ? pMatch : `${tmpTemplateRoot}${tmpTranslated}`;
1045
+ });
1046
+ }
1047
+ return tmpTemplate;
1048
+ };
1049
+
1050
+ /**
1051
+ * Entity bundles gather server data into an address, filtered by a template; both can point at
1052
+ * something this manifest owns.
1053
+ *
1054
+ * @param {any} pEntitiesBundle - The configured entity bundle array.
1055
+ */
1056
+ const rewriteEntitiesBundle = (pEntitiesBundle) =>
1057
+ {
1058
+ if (!Array.isArray(pEntitiesBundle))
1059
+ {
1060
+ return;
1061
+ }
1062
+ for (const tmpEntityBundle of pEntitiesBundle)
1063
+ {
1064
+ if (!tmpEntityBundle || (typeof(tmpEntityBundle) !== 'object'))
1065
+ {
1066
+ continue;
1067
+ }
1068
+ for (const tmpAddressProperty of INJECTION_ENTITY_BUNDLE_ADDRESS_PROPERTIES)
1069
+ {
1070
+ if (tmpEntityBundle[tmpAddressProperty])
1071
+ {
1072
+ tmpEntityBundle[tmpAddressProperty] = rewriteAbsoluteAddress(tmpEntityBundle[tmpAddressProperty]);
1073
+ }
1074
+ }
1075
+ for (const tmpTemplateProperty of INJECTION_ENTITY_BUNDLE_TEMPLATE_PROPERTIES)
1076
+ {
1077
+ if (tmpEntityBundle[tmpTemplateProperty])
1078
+ {
1079
+ tmpEntityBundle[tmpTemplateProperty] = rewriteTemplateAddresses(tmpEntityBundle[tmpTemplateProperty]);
1080
+ }
1081
+ }
1082
+ }
1083
+ };
1084
+
1085
+ /**
1086
+ * @param {any} pTriggerGroup - A trigger group configuration.
1087
+ */
1088
+ const rewriteTriggerGroup = (pTriggerGroup) =>
1089
+ {
1090
+ if (!pTriggerGroup || (typeof(pTriggerGroup) !== 'object'))
1091
+ {
1092
+ return;
1093
+ }
1094
+ for (const tmpTemplateProperty of INJECTION_INPUT_TEMPLATE_PROPERTIES)
1095
+ {
1096
+ if (pTriggerGroup[tmpTemplateProperty])
1097
+ {
1098
+ pTriggerGroup[tmpTemplateProperty] = rewriteTemplateAddresses(pTriggerGroup[tmpTemplateProperty]);
1099
+ }
1100
+ }
1101
+ for (const tmpEntityBundleProperty of INJECTION_INPUT_ENTITY_BUNDLE_PROPERTIES)
1102
+ {
1103
+ rewriteEntitiesBundle(pTriggerGroup[tmpEntityBundleProperty]);
1104
+ }
1105
+ for (const tmpSolverProperty of INJECTION_TRIGGER_GROUP_SOLVER_PROPERTIES)
1106
+ {
1107
+ if (Array.isArray(pTriggerGroup[tmpSolverProperty]))
1108
+ {
1109
+ for (let i = 0; i < pTriggerGroup[tmpSolverProperty].length; i++)
1110
+ {
1111
+ rewriteSolverEntry(pTriggerGroup[tmpSolverProperty], i, `trigger group ${tmpSolverProperty} reference`);
1112
+ }
1113
+ }
1114
+ }
1115
+ if (pTriggerGroup.TriggerAddress)
1116
+ {
1117
+ pTriggerGroup.TriggerAddress = rewriteAbsoluteAddress(pTriggerGroup.TriggerAddress);
1118
+ }
1119
+ if (pTriggerGroup.MarshalOnComplete && (typeof(pTriggerGroup.MarshalOnComplete) === 'object'))
1120
+ {
1121
+ pTriggerGroup.MarshalOnComplete.Section = translateHashReference(pTriggerGroup.MarshalOnComplete.Section, tmpSectionTranslation);
1122
+ pTriggerGroup.MarshalOnComplete.Input = translateHashReference(pTriggerGroup.MarshalOnComplete.Input, tmpHashTranslation);
1123
+ }
1124
+ pTriggerGroup.TriggerGroupHash = translateHashReference(pTriggerGroup.TriggerGroupHash, tmpTriggerGroupTranslation);
1125
+ };
1126
+
1127
+ /**
1128
+ * Trigger groups and entity bundles resolve against the section view and the application, so they name
1129
+ * things this manifest owns wherever the input carrying them lives.
1130
+ *
1131
+ * @param {any} pPictForm - The PictForm configuration of an input.
1132
+ */
1133
+ const rewriteInputTriggerConfiguration = (pPictForm) =>
1134
+ {
1135
+ for (const tmpTriggerGroupHashProperty of (this.injectionTriggerGroupHashProperties || INJECTION_INPUT_TRIGGER_GROUP_HASH_PROPERTIES))
1136
+ {
1137
+ if (pPictForm[tmpTriggerGroupHashProperty])
1138
+ {
1139
+ pPictForm[tmpTriggerGroupHashProperty] = translateHashReference(pPictForm[tmpTriggerGroupHashProperty], tmpTriggerGroupTranslation);
1140
+ }
1141
+ }
1142
+ for (const tmpTriggerGroupProperty of (this.injectionTriggerGroupProperties || INJECTION_INPUT_TRIGGER_GROUP_PROPERTIES))
1143
+ {
1144
+ const tmpTriggerGroupConfiguration = pPictForm[tmpTriggerGroupProperty];
1145
+ if (Array.isArray(tmpTriggerGroupConfiguration))
1146
+ {
1147
+ for (const tmpTriggerGroup of tmpTriggerGroupConfiguration)
1148
+ {
1149
+ rewriteTriggerGroup(tmpTriggerGroup);
1150
+ }
1151
+ }
1152
+ else if (tmpTriggerGroupConfiguration)
1153
+ {
1154
+ rewriteTriggerGroup(tmpTriggerGroupConfiguration);
1155
+ }
1156
+ }
1157
+ for (const tmpEntityBundleProperty of INJECTION_INPUT_ENTITY_BUNDLE_PROPERTIES)
1158
+ {
1159
+ rewriteEntitiesBundle(pPictForm[tmpEntityBundleProperty]);
1160
+ }
1161
+ };
1162
+
1163
+ // A record set column can carry a trigger group of its own, and those solvers are run against the
1164
+ // section view rather than against a record, so they name what this manifest owns. The column's hash
1165
+ // and address are relative to a record of the set, so they stay as they are.
1166
+ for (const tmpReferenceManifest of Object.values(tmpManifest.ReferenceManifests || {}))
1167
+ {
1168
+ for (const tmpColumnDescriptor of Object.values(tmpReferenceManifest.Descriptors || {}))
1169
+ {
1170
+ if (tmpColumnDescriptor.PictForm && (typeof(tmpColumnDescriptor.PictForm) === 'object'))
1171
+ {
1172
+ rewriteInputTriggerConfiguration(tmpColumnDescriptor.PictForm);
1173
+ }
1174
+ }
1175
+ }
1176
+
1177
+ for (const tmpDescriptor of Object.values(tmpManifest.Descriptors || {}))
1178
+ {
1179
+ const tmpPictForm = tmpDescriptor.PictForm;
1180
+ if (!tmpPictForm || (typeof(tmpPictForm) !== 'object'))
1181
+ {
1182
+ continue;
1183
+ }
1184
+ for (const tmpSectionHashProperty of INJECTION_INPUT_SECTION_HASH_PROPERTIES)
1185
+ {
1186
+ if (tmpPictForm[tmpSectionHashProperty])
1187
+ {
1188
+ tmpPictForm[tmpSectionHashProperty] = translateHashReference(tmpPictForm[tmpSectionHashProperty], tmpSectionTranslation);
1189
+ // A tab selector stores the hash of the tab it is on, so its default is one too.
1190
+ tmpDescriptor.Default = translateHashReference(tmpDescriptor.Default, tmpSectionTranslation);
1191
+ }
1192
+ }
1193
+ for (const tmpGroupHashProperty of INJECTION_INPUT_GROUP_HASH_PROPERTIES)
1194
+ {
1195
+ if (tmpPictForm[tmpGroupHashProperty])
1196
+ {
1197
+ tmpPictForm[tmpGroupHashProperty] = translateHashReference(tmpPictForm[tmpGroupHashProperty], tmpGroupTranslation);
1198
+ tmpDescriptor.Default = translateHashReference(tmpDescriptor.Default, tmpGroupTranslation);
1199
+ }
1200
+ }
1201
+ for (const tmpSolverProperty of INJECTION_INPUT_SOLVER_PROPERTIES)
1202
+ {
1203
+ if (tmpPictForm[tmpSolverProperty])
1204
+ {
1205
+ tmpPictForm[tmpSolverProperty] = rewriteSolverValue(tmpPictForm[tmpSolverProperty], `input ${tmpSolverProperty} reference`);
1206
+ }
1207
+ }
1208
+ for (const tmpSolverSetProperty of INJECTION_INPUT_SOLVER_SET_PROPERTIES)
1209
+ {
1210
+ if (Array.isArray(tmpPictForm[tmpSolverSetProperty.Property]))
1211
+ {
1212
+ for (const tmpSolverEntry of tmpPictForm[tmpSolverSetProperty.Property])
1213
+ {
1214
+ if (tmpSolverEntry && (typeof(tmpSolverEntry) === 'object') && tmpSolverEntry[tmpSolverSetProperty.SolverProperty])
1215
+ {
1216
+ tmpSolverEntry[tmpSolverSetProperty.SolverProperty] = rewriteSolverValue(tmpSolverEntry[tmpSolverSetProperty.SolverProperty], `input ${tmpSolverSetProperty.Property} reference`);
1217
+ }
697
1218
  }
698
1219
  }
699
1220
  }
1221
+ for (const tmpAddressProperty of INJECTION_INPUT_ADDRESS_PROPERTIES)
1222
+ {
1223
+ if (tmpPictForm[tmpAddressProperty])
1224
+ {
1225
+ tmpPictForm[tmpAddressProperty] = rewriteAbsoluteAddress(tmpPictForm[tmpAddressProperty]);
1226
+ }
1227
+ }
1228
+ rewriteInputTriggerConfiguration(tmpPictForm);
1229
+ for (const tmpTemplateProperty of INJECTION_INPUT_TEMPLATE_PROPERTIES)
1230
+ {
1231
+ if (tmpPictForm[tmpTemplateProperty])
1232
+ {
1233
+ tmpPictForm[tmpTemplateProperty] = rewriteTemplateAddresses(tmpPictForm[tmpTemplateProperty]);
1234
+ }
1235
+ }
700
1236
  }
701
1237
  if (Array.isArray(tmpManifest.ValidationSolvers))
702
1238
  {
@@ -1252,6 +1788,41 @@ class PictFormMetacontroller extends libPictViewClass
1252
1788
  }
1253
1789
  }
1254
1790
 
1791
+ /**
1792
+ * Appends the validation solvers of a manifest being added to the form onto the form's own, in order,
1793
+ * skipping any the form already holds so adding the same manifest again does not run its solvers twice.
1794
+ *
1795
+ * @param {Record<string, any>} pTargetManifest - The form's manifest description, which receives the solvers.
1796
+ * @param {Record<string, any>} pSourceManifest - The manifest being added to the form.
1797
+ *
1798
+ * @return {number} The number of validation solvers added.
1799
+ */
1800
+ mergeValidationSolvers(pTargetManifest, pSourceManifest)
1801
+ {
1802
+ if (!pTargetManifest || !pSourceManifest || !Array.isArray(pSourceManifest.ValidationSolvers) || (pSourceManifest.ValidationSolvers.length < 1))
1803
+ {
1804
+ return 0;
1805
+ }
1806
+ if (!Array.isArray(pTargetManifest.ValidationSolvers))
1807
+ {
1808
+ pTargetManifest.ValidationSolvers = [];
1809
+ }
1810
+ const tmpExistingSolvers = new Set(pTargetManifest.ValidationSolvers.map((pSolver) => JSON.stringify(pSolver)));
1811
+ let tmpAddedCount = 0;
1812
+ for (const tmpSolver of pSourceManifest.ValidationSolvers)
1813
+ {
1814
+ const tmpSolverKey = JSON.stringify(tmpSolver);
1815
+ if (tmpExistingSolvers.has(tmpSolverKey))
1816
+ {
1817
+ continue;
1818
+ }
1819
+ tmpExistingSolvers.add(tmpSolverKey);
1820
+ pTargetManifest.ValidationSolvers.push(JSON.parse(tmpSolverKey));
1821
+ ++tmpAddedCount;
1822
+ }
1823
+ return tmpAddedCount;
1824
+ }
1825
+
1255
1826
  /**
1256
1827
  * Clears out the manifest description set on the meta controller.
1257
1828
  */
@@ -1311,6 +1882,7 @@ class PictFormMetacontroller extends libPictViewClass
1311
1882
  }
1312
1883
  this.stashedManifestDescription.ReferenceManifests[tmpKey] = JSON.parse(JSON.stringify(this.manifestDescription.ReferenceManifests[tmpKey]));
1313
1884
  }
1885
+ this.mergeValidationSolvers(this.stashedManifestDescription, this.manifestDescription);
1314
1886
  let tmpInsertAtIndex = this.stashedManifestDescription.Sections.findIndex((pSection) => pSection.Hash == pAfterSectionHash);
1315
1887
  if (tmpInsertAtIndex < 0)
1316
1888
  {
@@ -1669,6 +2241,31 @@ class PictFormMetacontroller extends libPictViewClass
1669
2241
  }
1670
2242
 
1671
2243
  module.exports = PictFormMetacontroller;
2244
+
2245
+ /**
2246
+ * What createDistinctManifest translates when a manifest is injected, by kind. The injection conformance
2247
+ * tests measure fixture coverage against this, so adding a construct here without a fixture case fails.
2248
+ *
2249
+ * @type {Record<string, any>}
2250
+ */
2251
+ module.exports.InjectionTranslation = (
2252
+ {
2253
+ "InputSectionHashProperties": INJECTION_INPUT_SECTION_HASH_PROPERTIES,
2254
+ "InputGroupHashProperties": INJECTION_INPUT_GROUP_HASH_PROPERTIES,
2255
+ "InputSolverProperties": INJECTION_INPUT_SOLVER_PROPERTIES,
2256
+ "InputSolverSetProperties": INJECTION_INPUT_SOLVER_SET_PROPERTIES,
2257
+ "InputAddressProperties": INJECTION_INPUT_ADDRESS_PROPERTIES,
2258
+ "InputTriggerGroupProperties": INJECTION_INPUT_TRIGGER_GROUP_PROPERTIES,
2259
+ "InputTriggerGroupHashProperties": INJECTION_INPUT_TRIGGER_GROUP_HASH_PROPERTIES,
2260
+ "InputTemplateProperties": INJECTION_INPUT_TEMPLATE_PROPERTIES,
2261
+ "InputEntityBundleProperties": INJECTION_INPUT_ENTITY_BUNDLE_PROPERTIES,
2262
+ "EntityBundleAddressProperties": INJECTION_ENTITY_BUNDLE_ADDRESS_PROPERTIES,
2263
+ "EntityBundleTemplateProperties": INJECTION_ENTITY_BUNDLE_TEMPLATE_PROPERTIES,
2264
+ "TriggerGroupSolverProperties": INJECTION_TRIGGER_GROUP_SOLVER_PROPERTIES,
2265
+ "ManifestConstructs": INJECTION_MANIFEST_CONSTRUCTS,
2266
+ "SolverDirectiveCodes": Array.from(SOLVER_DIRECTIVE_CODES),
2267
+ });
2268
+
1672
2269
  /** @type {Record<string, any>} */
1673
2270
  module.exports.default_configuration = (
1674
2271
  {