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