wingbot 3.70.2 → 3.70.4-alpha.1

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 (2) hide show
  1. package/package.json +1 -1
  2. package/src/BuildRouter.js +38 -4
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "wingbot",
3
- "version": "3.70.2",
3
+ "version": "3.70.4-alpha.1",
4
4
  "description": "Enterprise Messaging Bot Conversation Engine",
5
5
  "main": "index.js",
6
6
  "type": "commonjs",
@@ -138,6 +138,11 @@ const DUMMY_ROUTE = { id: 0, path: null, resolvers: [] };
138
138
  * @prop {C} [configuration] - context data
139
139
  */
140
140
 
141
+ /**
142
+ * @callback NestedLinksMapFactory
143
+ * @returns {LinksMap}
144
+ */
145
+
141
146
  /**
142
147
  * @typedef {object} BotContextExtention
143
148
  * @prop {BlockMap} [nestedBlocksByStaticId]
@@ -155,6 +160,7 @@ const DUMMY_ROUTE = { id: 0, path: null, resolvers: [] };
155
160
  * @prop {boolean} [isRoot]
156
161
  * @prop {string} [staticBlockId]
157
162
  * @prop {Block[]} [blocks]
163
+ * @prop {NestedLinksMapFactory} [nestedLinksMapFactory]
158
164
  * @prop {object} [BuildRouter]
159
165
  * @prop {string|number} [resolverId] - only for text messages with random characters
160
166
  */
@@ -226,6 +232,9 @@ class BuildRouter extends Router {
226
232
  /** @type {LinksMap} */
227
233
  this._linksMap = new Map();
228
234
 
235
+ /** @type {LinksMap} */
236
+ this._nestedLinksMap = null;
237
+
229
238
  this._loadBotUrl = null;
230
239
 
231
240
  this._loadBotAuthorization = null;
@@ -512,7 +521,10 @@ class BuildRouter extends Router {
512
521
  buildWithSnapshot (blocks, setConfigTimestamp = Number.MAX_SAFE_INTEGER, lastmod = '-') {
513
522
  this._validateBlocks(blocks);
514
523
 
515
- Object.assign(this._resolvedContext, { blocks });
524
+ Object.assign(this._resolvedContext, {
525
+ blocks,
526
+ nestedBlocksByStaticId: null
527
+ });
516
528
 
517
529
  const rootBlock = blocks.find((block) => block.isRoot);
518
530
 
@@ -573,6 +585,7 @@ class BuildRouter extends Router {
573
585
  const [linksMap, nestedBlocksByStaticId] = this._createLinksMap(block);
574
586
  // @ts-ignore
575
587
  this._linksMap = linksMap;
588
+ this._nestedLinksMap = null;
576
589
 
577
590
  // @ts-ignore
578
591
  this._buildRoutes(block.routes, nestedBlocksByStaticId);
@@ -583,6 +596,20 @@ class BuildRouter extends Router {
583
596
  this.emit('rebuild');
584
597
  }
585
598
 
599
+ _getNestedLinksMap () {
600
+ if (!this._nestedLinksMap) {
601
+ /** @type {LinksMap} */
602
+ const linksMap = new Map();
603
+
604
+ for (const [from, to] of this._linksMap.entries()) {
605
+ linksMap.set(from, `../${to}`); // this._joinPaths('..', to)
606
+ }
607
+
608
+ this._nestedLinksMap = linksMap;
609
+ }
610
+ return this._nestedLinksMap;
611
+ }
612
+
586
613
  /**
587
614
  *
588
615
  * returns {[LinksMap, BlockMap]}
@@ -590,12 +617,18 @@ class BuildRouter extends Router {
590
617
  * @param {Block} block
591
618
  */
592
619
  _createLinksMap (block) {
593
- const { linksMap: prevLinksMap, blocks = [] } = this._resolvedContext;
620
+ const {
621
+ linksMap: prevLinksMap,
622
+ blocks = [],
623
+ nestedLinksMapFactory
624
+ } = this._resolvedContext;
594
625
 
595
626
  /** @type {LinksMap} */
596
- const linksMap = new Map();
627
+ const linksMap = nestedLinksMapFactory
628
+ ? nestedLinksMapFactory()
629
+ : new Map();
597
630
 
598
- if (prevLinksMap) {
631
+ if (prevLinksMap && !nestedLinksMapFactory) {
599
632
  for (const [from, to] of prevLinksMap.entries()) {
600
633
  linksMap.set(from, `../${to}`); // this._joinPaths('..', to)
601
634
  }
@@ -900,6 +933,7 @@ class BuildRouter extends Router {
900
933
  isLastMessage: lastMessageIndex === i && !buildInfo.notLastMessage,
901
934
  router: this,
902
935
  linksMap: this._linksMap,
936
+ nestedLinksMapFactory: this._getNestedLinksMap.bind(this),
903
937
  path: ctxPath,
904
938
  isFallback,
905
939
  isResponder,