@naylence/runtime 0.3.5-test.960 → 0.3.5-test.962
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/dist/browser/index.cjs +269 -31
- package/dist/browser/index.mjs +269 -31
- package/dist/cjs/naylence/fame/connector/broadcast-channel-connector-factory.js +27 -0
- package/dist/cjs/naylence/fame/connector/broadcast-channel-connector.browser.js +149 -4
- package/dist/cjs/naylence/fame/connector/broadcast-channel-listener.js +91 -25
- package/dist/cjs/version.js +2 -2
- package/dist/esm/naylence/fame/connector/broadcast-channel-connector-factory.js +27 -0
- package/dist/esm/naylence/fame/connector/broadcast-channel-connector.browser.js +149 -4
- package/dist/esm/naylence/fame/connector/broadcast-channel-listener.js +91 -25
- package/dist/esm/version.js +2 -2
- package/dist/node/index.cjs +269 -31
- package/dist/node/index.mjs +269 -31
- package/dist/node/node.cjs +269 -31
- package/dist/node/node.mjs +269 -31
- package/dist/types/naylence/fame/connector/broadcast-channel-connector-factory.d.ts +5 -0
- package/dist/types/naylence/fame/connector/broadcast-channel-connector.browser.d.ts +10 -0
- package/dist/types/naylence/fame/connector/broadcast-channel-connector.node.d.ts +1 -6
- package/dist/types/naylence/fame/connector/broadcast-channel-listener.d.ts +3 -0
- package/dist/types/naylence/fame/grants/broadcast-channel-connection-grant.d.ts +1 -1
- package/dist/types/version.d.ts +1 -1
- package/package.json +1 -1
package/dist/node/node.cjs
CHANGED
|
@@ -5563,12 +5563,12 @@ for (const [name, config] of Object.entries(SQLITE_PROFILES)) {
|
|
|
5563
5563
|
}
|
|
5564
5564
|
|
|
5565
5565
|
// This file is auto-generated during build - do not edit manually
|
|
5566
|
-
// Generated from package.json version: 0.3.5-test.
|
|
5566
|
+
// Generated from package.json version: 0.3.5-test.962
|
|
5567
5567
|
/**
|
|
5568
5568
|
* The package version, injected at build time.
|
|
5569
5569
|
* @internal
|
|
5570
5570
|
*/
|
|
5571
|
-
const VERSION = '0.3.5-test.
|
|
5571
|
+
const VERSION = '0.3.5-test.962';
|
|
5572
5572
|
|
|
5573
5573
|
/**
|
|
5574
5574
|
* Fame errors module - Fame protocol specific error classes
|
|
@@ -11599,6 +11599,26 @@ let BroadcastChannelConnector$2 = class BroadcastChannelConnector extends BaseAs
|
|
|
11599
11599
|
}
|
|
11600
11600
|
return null;
|
|
11601
11601
|
}
|
|
11602
|
+
static normalizeNodeId(value) {
|
|
11603
|
+
if (typeof value !== 'string') {
|
|
11604
|
+
return null;
|
|
11605
|
+
}
|
|
11606
|
+
const trimmed = value.trim();
|
|
11607
|
+
return trimmed.length > 0 ? trimmed : null;
|
|
11608
|
+
}
|
|
11609
|
+
static normalizeTargetNodeId(value) {
|
|
11610
|
+
if (typeof value !== 'string') {
|
|
11611
|
+
return undefined;
|
|
11612
|
+
}
|
|
11613
|
+
const trimmed = value.trim();
|
|
11614
|
+
if (trimmed.length === 0) {
|
|
11615
|
+
return undefined;
|
|
11616
|
+
}
|
|
11617
|
+
if (trimmed === '*') {
|
|
11618
|
+
return '*';
|
|
11619
|
+
}
|
|
11620
|
+
return trimmed;
|
|
11621
|
+
}
|
|
11602
11622
|
constructor(config, baseConfig = {}) {
|
|
11603
11623
|
ensureBroadcastEnvironment();
|
|
11604
11624
|
super(baseConfig);
|
|
@@ -11621,10 +11641,18 @@ let BroadcastChannelConnector$2 = class BroadcastChannelConnector extends BaseAs
|
|
|
11621
11641
|
this.inbox = new BoundedAsyncQueue(preferredCapacity);
|
|
11622
11642
|
this.inboxCapacity = preferredCapacity;
|
|
11623
11643
|
this.connectorId = BroadcastChannelConnector.generateConnectorId();
|
|
11644
|
+
const normalizedLocalNodeId = BroadcastChannelConnector.normalizeNodeId(config.localNodeId);
|
|
11645
|
+
if (!normalizedLocalNodeId) {
|
|
11646
|
+
throw new Error('BroadcastChannelConnector requires a non-empty localNodeId');
|
|
11647
|
+
}
|
|
11648
|
+
this.localNodeId = normalizedLocalNodeId;
|
|
11649
|
+
this.targetNodeId = BroadcastChannelConnector.normalizeTargetNodeId(config.initialTargetNodeId);
|
|
11624
11650
|
this.channel = new BroadcastChannel(this.channelName);
|
|
11625
11651
|
logger$10.debug('broadcast_channel_connector_created', {
|
|
11626
11652
|
channel: this.channelName,
|
|
11627
11653
|
connector_id: this.connectorId,
|
|
11654
|
+
local_node_id: this.localNodeId,
|
|
11655
|
+
target_node_id: this.targetNodeId ?? null,
|
|
11628
11656
|
inbox_capacity: preferredCapacity,
|
|
11629
11657
|
timestamp: new Date().toISOString(),
|
|
11630
11658
|
});
|
|
@@ -11646,15 +11674,32 @@ let BroadcastChannelConnector$2 = class BroadcastChannelConnector extends BaseAs
|
|
|
11646
11674
|
? message.constructor?.name ?? typeof message
|
|
11647
11675
|
: typeof message,
|
|
11648
11676
|
has_sender_id: Boolean(message?.senderId),
|
|
11677
|
+
has_sender_node_id: Boolean(message?.senderNodeId),
|
|
11649
11678
|
});
|
|
11650
11679
|
if (!message || typeof message !== 'object') {
|
|
11651
11680
|
return;
|
|
11652
11681
|
}
|
|
11653
11682
|
const busMessage = message;
|
|
11654
|
-
|
|
11683
|
+
const senderNodeId = BroadcastChannelConnector.normalizeNodeId(busMessage.senderNodeId);
|
|
11684
|
+
if (!senderNodeId) {
|
|
11685
|
+
logger$10.debug('broadcast_channel_message_rejected', {
|
|
11686
|
+
channel: this.channelName,
|
|
11687
|
+
connector_id: this.connectorId,
|
|
11688
|
+
reason: 'missing_sender_node_id',
|
|
11689
|
+
});
|
|
11655
11690
|
return;
|
|
11656
11691
|
}
|
|
11657
|
-
if (
|
|
11692
|
+
if (senderNodeId === this.localNodeId) {
|
|
11693
|
+
logger$10.debug('broadcast_channel_message_rejected', {
|
|
11694
|
+
channel: this.channelName,
|
|
11695
|
+
connector_id: this.connectorId,
|
|
11696
|
+
reason: 'self_echo',
|
|
11697
|
+
sender_node_id: senderNodeId,
|
|
11698
|
+
});
|
|
11699
|
+
return;
|
|
11700
|
+
}
|
|
11701
|
+
const incomingTargetNodeId = BroadcastChannelConnector.normalizeTargetNodeId(busMessage.targetNodeId);
|
|
11702
|
+
if (!this._shouldAcceptMessageFromBus(senderNodeId, incomingTargetNodeId)) {
|
|
11658
11703
|
return;
|
|
11659
11704
|
}
|
|
11660
11705
|
const payload = BroadcastChannelConnector.coercePayload(busMessage.payload);
|
|
@@ -11668,11 +11713,13 @@ let BroadcastChannelConnector$2 = class BroadcastChannelConnector extends BaseAs
|
|
|
11668
11713
|
}
|
|
11669
11714
|
logger$10.debug('broadcast_channel_message_received', {
|
|
11670
11715
|
channel: this.channelName,
|
|
11671
|
-
sender_id:
|
|
11716
|
+
sender_id: message?.senderId,
|
|
11717
|
+
sender_node_id: senderNodeId,
|
|
11718
|
+
target_node_id: incomingTargetNodeId ?? null,
|
|
11672
11719
|
connector_id: this.connectorId,
|
|
11673
11720
|
payload_length: payload.byteLength,
|
|
11674
11721
|
});
|
|
11675
|
-
if (this._shouldSkipDuplicateAck(
|
|
11722
|
+
if (this._shouldSkipDuplicateAck(senderNodeId, payload)) {
|
|
11676
11723
|
return;
|
|
11677
11724
|
}
|
|
11678
11725
|
try {
|
|
@@ -11816,12 +11863,17 @@ let BroadcastChannelConnector$2 = class BroadcastChannelConnector extends BaseAs
|
|
|
11816
11863
|
}
|
|
11817
11864
|
async _transportSendBytes(data) {
|
|
11818
11865
|
ensureBroadcastEnvironment();
|
|
11866
|
+
const targetNodeId = this.targetNodeId ?? '*';
|
|
11819
11867
|
logger$10.debug('broadcast_channel_message_sending', {
|
|
11820
11868
|
channel: this.channelName,
|
|
11821
11869
|
sender_id: this.connectorId,
|
|
11870
|
+
sender_node_id: this.localNodeId,
|
|
11871
|
+
target_node_id: targetNodeId,
|
|
11822
11872
|
});
|
|
11823
11873
|
this.channel.postMessage({
|
|
11824
11874
|
senderId: this.connectorId,
|
|
11875
|
+
senderNodeId: this.localNodeId,
|
|
11876
|
+
targetNodeId,
|
|
11825
11877
|
payload: data,
|
|
11826
11878
|
});
|
|
11827
11879
|
}
|
|
@@ -11884,6 +11936,51 @@ let BroadcastChannelConnector$2 = class BroadcastChannelConnector extends BaseAs
|
|
|
11884
11936
|
}
|
|
11885
11937
|
return rawOrEnvelope;
|
|
11886
11938
|
}
|
|
11939
|
+
_isWildcardTarget() {
|
|
11940
|
+
return this.targetNodeId === '*' || typeof this.targetNodeId === 'undefined';
|
|
11941
|
+
}
|
|
11942
|
+
_shouldAcceptMessageFromBus(senderNodeId, targetNodeId) {
|
|
11943
|
+
if (this._isWildcardTarget()) {
|
|
11944
|
+
if (targetNodeId && targetNodeId !== '*') {
|
|
11945
|
+
logger$10.debug('broadcast_channel_message_rejected', {
|
|
11946
|
+
channel: this.channelName,
|
|
11947
|
+
connector_id: this.connectorId,
|
|
11948
|
+
reason: 'wildcard_target_mismatch',
|
|
11949
|
+
sender_node_id: senderNodeId,
|
|
11950
|
+
target_node_id: targetNodeId,
|
|
11951
|
+
local_node_id: this.localNodeId,
|
|
11952
|
+
});
|
|
11953
|
+
return false;
|
|
11954
|
+
}
|
|
11955
|
+
return true;
|
|
11956
|
+
}
|
|
11957
|
+
const expectedSender = this.targetNodeId;
|
|
11958
|
+
if (expectedSender && expectedSender !== '*' && senderNodeId !== expectedSender) {
|
|
11959
|
+
logger$10.debug('broadcast_channel_message_rejected', {
|
|
11960
|
+
channel: this.channelName,
|
|
11961
|
+
connector_id: this.connectorId,
|
|
11962
|
+
reason: 'unexpected_sender',
|
|
11963
|
+
expected_sender_node_id: expectedSender,
|
|
11964
|
+
sender_node_id: senderNodeId,
|
|
11965
|
+
local_node_id: this.localNodeId,
|
|
11966
|
+
});
|
|
11967
|
+
return false;
|
|
11968
|
+
}
|
|
11969
|
+
if (targetNodeId &&
|
|
11970
|
+
targetNodeId !== '*' &&
|
|
11971
|
+
targetNodeId !== this.localNodeId) {
|
|
11972
|
+
logger$10.debug('broadcast_channel_message_rejected', {
|
|
11973
|
+
channel: this.channelName,
|
|
11974
|
+
connector_id: this.connectorId,
|
|
11975
|
+
reason: 'unexpected_target',
|
|
11976
|
+
sender_node_id: senderNodeId,
|
|
11977
|
+
target_node_id: targetNodeId,
|
|
11978
|
+
local_node_id: this.localNodeId,
|
|
11979
|
+
});
|
|
11980
|
+
return false;
|
|
11981
|
+
}
|
|
11982
|
+
return true;
|
|
11983
|
+
}
|
|
11887
11984
|
_describeInboxItem(item) {
|
|
11888
11985
|
if (item instanceof Uint8Array) {
|
|
11889
11986
|
return 'bytes';
|
|
@@ -11914,6 +12011,16 @@ let BroadcastChannelConnector$2 = class BroadcastChannelConnector extends BaseAs
|
|
|
11914
12011
|
const normalizedSenderId = typeof senderId === 'string' && senderId.length > 0
|
|
11915
12012
|
? senderId
|
|
11916
12013
|
: undefined;
|
|
12014
|
+
if (normalizedSenderId && normalizedSenderId !== this.localNodeId) {
|
|
12015
|
+
logger$10.debug('broadcast_channel_duplicate_ack_bypass_non_self', {
|
|
12016
|
+
channel: this.channelName,
|
|
12017
|
+
connector_id: this.connectorId,
|
|
12018
|
+
sender_id: normalizedSenderId,
|
|
12019
|
+
dedup_key: dedupKey,
|
|
12020
|
+
source: 'listener',
|
|
12021
|
+
});
|
|
12022
|
+
return false;
|
|
12023
|
+
}
|
|
11917
12024
|
logger$10.debug('broadcast_channel_duplicate_ack_check', {
|
|
11918
12025
|
channel: this.channelName,
|
|
11919
12026
|
connector_id: this.connectorId,
|
|
@@ -11944,6 +12051,16 @@ let BroadcastChannelConnector$2 = class BroadcastChannelConnector extends BaseAs
|
|
|
11944
12051
|
return false;
|
|
11945
12052
|
}
|
|
11946
12053
|
const senderId = this._extractSenderIdFromInboxItem(item);
|
|
12054
|
+
if (senderId && senderId !== this.localNodeId) {
|
|
12055
|
+
logger$10.debug('broadcast_channel_duplicate_ack_bypass_non_self', {
|
|
12056
|
+
channel: this.channelName,
|
|
12057
|
+
connector_id: this.connectorId,
|
|
12058
|
+
sender_id: senderId,
|
|
12059
|
+
dedup_key: dedupKey,
|
|
12060
|
+
source: 'inbox_item',
|
|
12061
|
+
});
|
|
12062
|
+
return false;
|
|
12063
|
+
}
|
|
11947
12064
|
logger$10.debug('broadcast_channel_duplicate_ack_check', {
|
|
11948
12065
|
channel: this.channelName,
|
|
11949
12066
|
connector_id: this.connectorId,
|
|
@@ -12030,6 +12147,34 @@ let BroadcastChannelConnector$2 = class BroadcastChannelConnector extends BaseAs
|
|
|
12030
12147
|
});
|
|
12031
12148
|
}
|
|
12032
12149
|
}
|
|
12150
|
+
setTargetNodeId(nodeId) {
|
|
12151
|
+
const normalized = BroadcastChannelConnector.normalizeNodeId(nodeId);
|
|
12152
|
+
if (!normalized) {
|
|
12153
|
+
throw new Error('BroadcastChannelConnector target node id must be a non-empty string');
|
|
12154
|
+
}
|
|
12155
|
+
if (normalized === '*') {
|
|
12156
|
+
this.setWildcardTarget();
|
|
12157
|
+
return;
|
|
12158
|
+
}
|
|
12159
|
+
this.targetNodeId = normalized;
|
|
12160
|
+
logger$10.debug('broadcast_channel_target_updated', {
|
|
12161
|
+
channel: this.channelName,
|
|
12162
|
+
connector_id: this.connectorId,
|
|
12163
|
+
local_node_id: this.localNodeId,
|
|
12164
|
+
target_node_id: this.targetNodeId,
|
|
12165
|
+
target_mode: 'direct',
|
|
12166
|
+
});
|
|
12167
|
+
}
|
|
12168
|
+
setWildcardTarget() {
|
|
12169
|
+
this.targetNodeId = '*';
|
|
12170
|
+
logger$10.debug('broadcast_channel_target_updated', {
|
|
12171
|
+
channel: this.channelName,
|
|
12172
|
+
connector_id: this.connectorId,
|
|
12173
|
+
local_node_id: this.localNodeId,
|
|
12174
|
+
target_node_id: this.targetNodeId,
|
|
12175
|
+
target_mode: 'wildcard',
|
|
12176
|
+
});
|
|
12177
|
+
}
|
|
12033
12178
|
_trimSeenAcks(now) {
|
|
12034
12179
|
while (this.seenAckOrder.length > 0) {
|
|
12035
12180
|
const candidate = this.seenAckOrder[0];
|
|
@@ -30600,8 +30745,13 @@ class BroadcastChannelConnectorFactory extends ConnectorFactory {
|
|
|
30600
30745
|
}
|
|
30601
30746
|
const normalized = this._normalizeConfig(config);
|
|
30602
30747
|
const options = (factoryArgs[0] ?? {});
|
|
30748
|
+
const localNodeId = this._normalizeNodeId(options.localNodeId);
|
|
30749
|
+
if (!localNodeId) {
|
|
30750
|
+
throw new Error('BroadcastChannelConnectorFactory requires a localNodeId in create() options');
|
|
30751
|
+
}
|
|
30603
30752
|
const channelName = normalized.channelName ?? DEFAULT_CHANNEL$2;
|
|
30604
30753
|
const inboxCapacity = normalized.inboxCapacity ?? DEFAULT_INBOX_CAPACITY$2;
|
|
30754
|
+
const resolvedTarget = this._normalizeTargetNodeId(options.initialTargetNodeId ?? normalized.initialTargetNodeId);
|
|
30605
30755
|
const baseConfig = {
|
|
30606
30756
|
drainTimeout: normalized.drainTimeout,
|
|
30607
30757
|
flowControl: normalized.flowControl,
|
|
@@ -30616,6 +30766,8 @@ class BroadcastChannelConnectorFactory extends ConnectorFactory {
|
|
|
30616
30766
|
type: BROADCAST_CHANNEL_CONNECTOR_TYPE$1,
|
|
30617
30767
|
channelName,
|
|
30618
30768
|
inboxCapacity,
|
|
30769
|
+
localNodeId,
|
|
30770
|
+
initialTargetNodeId: resolvedTarget,
|
|
30619
30771
|
};
|
|
30620
30772
|
const connector = new BroadcastChannelConnector(connectorConfig, baseConfig);
|
|
30621
30773
|
if (options.authorization) {
|
|
@@ -30639,6 +30791,13 @@ class BroadcastChannelConnectorFactory extends ConnectorFactory {
|
|
|
30639
30791
|
normalized.channelName = channel.trim();
|
|
30640
30792
|
}
|
|
30641
30793
|
const capacity = candidate.inboxCapacity ?? candidate['inbox_capacity'];
|
|
30794
|
+
const initialTargetNodeId = candidate.initialTargetNodeId ?? candidate['initial_target_node_id'];
|
|
30795
|
+
if (typeof initialTargetNodeId === 'string' && initialTargetNodeId.trim().length > 0) {
|
|
30796
|
+
normalized.initialTargetNodeId = initialTargetNodeId.trim();
|
|
30797
|
+
}
|
|
30798
|
+
else if (initialTargetNodeId === '*') {
|
|
30799
|
+
normalized.initialTargetNodeId = '*';
|
|
30800
|
+
}
|
|
30642
30801
|
if (typeof capacity === 'number' &&
|
|
30643
30802
|
Number.isFinite(capacity) &&
|
|
30644
30803
|
capacity > 0) {
|
|
@@ -30682,6 +30841,19 @@ class BroadcastChannelConnectorFactory extends ConnectorFactory {
|
|
|
30682
30841
|
normalized.inboxCapacity ?? DEFAULT_INBOX_CAPACITY$2;
|
|
30683
30842
|
return normalized;
|
|
30684
30843
|
}
|
|
30844
|
+
_normalizeNodeId(value) {
|
|
30845
|
+
if (typeof value !== 'string') {
|
|
30846
|
+
return null;
|
|
30847
|
+
}
|
|
30848
|
+
const trimmed = value.trim();
|
|
30849
|
+
return trimmed.length > 0 ? trimmed : null;
|
|
30850
|
+
}
|
|
30851
|
+
_normalizeTargetNodeId(value) {
|
|
30852
|
+
if (value === '*') {
|
|
30853
|
+
return '*';
|
|
30854
|
+
}
|
|
30855
|
+
return this._normalizeNodeId(value) ?? '*';
|
|
30856
|
+
}
|
|
30685
30857
|
}
|
|
30686
30858
|
|
|
30687
30859
|
var broadcastChannelConnectorFactory = /*#__PURE__*/Object.freeze({
|
|
@@ -32839,7 +33011,7 @@ class BroadcastChannelListener extends TransportListener {
|
|
|
32839
33011
|
node: routingNode,
|
|
32840
33012
|
});
|
|
32841
33013
|
const selection = defaultGrantSelectionPolicy.selectCallbackGrant(selectionContext);
|
|
32842
|
-
connectorConfig = this._grantToConnectorConfig(selection.grant);
|
|
33014
|
+
connectorConfig = this._grantToConnectorConfig(selection.grant, systemId);
|
|
32843
33015
|
}
|
|
32844
33016
|
catch (error) {
|
|
32845
33017
|
logger$n.debug('broadcast_channel_listener_grant_selection_failed', {
|
|
@@ -32848,13 +33020,20 @@ class BroadcastChannelListener extends TransportListener {
|
|
|
32848
33020
|
error: error instanceof Error ? error.message : String(error),
|
|
32849
33021
|
});
|
|
32850
33022
|
connectorConfig =
|
|
32851
|
-
this._extractBroadcastConnectorConfig(frame) ??
|
|
32852
|
-
{
|
|
33023
|
+
this._extractBroadcastConnectorConfig(frame, systemId) ??
|
|
33024
|
+
this._buildConnectorConfigForSystem(systemId, {
|
|
32853
33025
|
type: BROADCAST_CHANNEL_CONNECTOR_TYPE$1,
|
|
32854
33026
|
channelName: this._channelName,
|
|
32855
33027
|
inboxCapacity: this._inboxCapacity,
|
|
32856
33028
|
passive: true,
|
|
32857
|
-
};
|
|
33029
|
+
});
|
|
33030
|
+
}
|
|
33031
|
+
if (!connectorConfig) {
|
|
33032
|
+
logger$n.error('broadcast_channel_listener_missing_connector_config', {
|
|
33033
|
+
sender_id: params.senderId,
|
|
33034
|
+
system_id: systemId,
|
|
33035
|
+
});
|
|
33036
|
+
return null;
|
|
32858
33037
|
}
|
|
32859
33038
|
try {
|
|
32860
33039
|
const connector = await routingNode.createOriginConnector({
|
|
@@ -32880,7 +33059,7 @@ class BroadcastChannelListener extends TransportListener {
|
|
|
32880
33059
|
return null;
|
|
32881
33060
|
}
|
|
32882
33061
|
}
|
|
32883
|
-
_extractBroadcastConnectorConfig(frame) {
|
|
33062
|
+
_extractBroadcastConnectorConfig(frame, systemId) {
|
|
32884
33063
|
const rawGrants = frame.callbackGrants;
|
|
32885
33064
|
if (!Array.isArray(rawGrants)) {
|
|
32886
33065
|
return null;
|
|
@@ -32891,7 +33070,10 @@ class BroadcastChannelListener extends TransportListener {
|
|
|
32891
33070
|
(grant.type === BROADCAST_CHANNEL_CONNECTION_GRANT_TYPE ||
|
|
32892
33071
|
grant.type === BROADCAST_CHANNEL_CONNECTOR_TYPE$1)) {
|
|
32893
33072
|
try {
|
|
32894
|
-
|
|
33073
|
+
if (grant.type === BROADCAST_CHANNEL_CONNECTOR_TYPE$1) {
|
|
33074
|
+
return this._buildConnectorConfigForSystem(systemId, grant);
|
|
33075
|
+
}
|
|
33076
|
+
return this._buildConnectorConfigForSystem(systemId, broadcastChannelGrantToConnectorConfig(grant));
|
|
32895
33077
|
}
|
|
32896
33078
|
catch (error) {
|
|
32897
33079
|
logger$n.debug('broadcast_channel_listener_grant_normalization_failed', {
|
|
@@ -32902,31 +33084,87 @@ class BroadcastChannelListener extends TransportListener {
|
|
|
32902
33084
|
}
|
|
32903
33085
|
return null;
|
|
32904
33086
|
}
|
|
32905
|
-
_grantToConnectorConfig(grant) {
|
|
32906
|
-
if (grant.type
|
|
32907
|
-
|
|
32908
|
-
|
|
33087
|
+
_grantToConnectorConfig(grant, systemId) {
|
|
33088
|
+
if (grant.type === BROADCAST_CHANNEL_CONNECTOR_TYPE$1) {
|
|
33089
|
+
return this._buildConnectorConfigForSystem(systemId, grant);
|
|
33090
|
+
}
|
|
33091
|
+
if (grant.type === BROADCAST_CHANNEL_CONNECTION_GRANT_TYPE) {
|
|
33092
|
+
return this._buildConnectorConfigForSystem(systemId, broadcastChannelGrantToConnectorConfig(grant));
|
|
33093
|
+
}
|
|
33094
|
+
if ('toConnectorConfig' in grant &&
|
|
33095
|
+
typeof grant.toConnectorConfig ===
|
|
33096
|
+
'function') {
|
|
33097
|
+
const normalized = grant.toConnectorConfig();
|
|
33098
|
+
if (normalized.type !== BROADCAST_CHANNEL_CONNECTOR_TYPE$1) {
|
|
33099
|
+
throw new Error(`Unsupported grant connector type: ${normalized.type}`);
|
|
32909
33100
|
}
|
|
32910
|
-
|
|
33101
|
+
return this._buildConnectorConfigForSystem(systemId, normalized);
|
|
32911
33102
|
}
|
|
32912
|
-
|
|
32913
|
-
|
|
33103
|
+
throw new Error(`Unsupported grant type: ${grant.type}`);
|
|
33104
|
+
}
|
|
33105
|
+
_buildConnectorConfigForSystem(systemId, baseConfig) {
|
|
33106
|
+
const localNodeId = this._requireLocalNodeId();
|
|
33107
|
+
const targetSystemId = this._normalizeNodeId(systemId);
|
|
33108
|
+
if (!targetSystemId) {
|
|
33109
|
+
throw new Error('BroadcastChannelListener requires a valid system id');
|
|
33110
|
+
}
|
|
33111
|
+
const candidate = baseConfig ?? null;
|
|
33112
|
+
const channelCandidate = candidate && 'channelName' in candidate
|
|
33113
|
+
? candidate.channelName
|
|
33114
|
+
: undefined;
|
|
33115
|
+
const inboxCandidate = candidate && 'inboxCapacity' in candidate
|
|
33116
|
+
? candidate.inboxCapacity
|
|
33117
|
+
: undefined;
|
|
33118
|
+
const initialWindowCandidate = candidate && 'initialWindow' in candidate
|
|
33119
|
+
? candidate.initialWindow
|
|
33120
|
+
: undefined;
|
|
33121
|
+
const passiveCandidate = candidate && 'passive' in candidate
|
|
33122
|
+
? candidate.passive
|
|
33123
|
+
: undefined;
|
|
33124
|
+
const targetCandidate = candidate && 'initialTargetNodeId' in candidate
|
|
33125
|
+
? candidate.initialTargetNodeId
|
|
33126
|
+
: undefined;
|
|
33127
|
+
const channelName = typeof channelCandidate === 'string' && channelCandidate.trim().length > 0
|
|
33128
|
+
? channelCandidate.trim()
|
|
33129
|
+
: this._channelName;
|
|
33130
|
+
const inboxCapacity = typeof inboxCandidate === 'number' &&
|
|
33131
|
+
Number.isFinite(inboxCandidate) &&
|
|
33132
|
+
inboxCandidate > 0
|
|
33133
|
+
? Math.floor(inboxCandidate)
|
|
33134
|
+
: this._inboxCapacity;
|
|
33135
|
+
const initialWindow = typeof initialWindowCandidate === 'number' &&
|
|
33136
|
+
Number.isFinite(initialWindowCandidate) &&
|
|
33137
|
+
initialWindowCandidate > 0
|
|
33138
|
+
? Math.floor(initialWindowCandidate)
|
|
33139
|
+
: undefined;
|
|
33140
|
+
const initialTargetNodeId = this._normalizeNodeId(targetCandidate) ?? targetSystemId;
|
|
33141
|
+
return {
|
|
32914
33142
|
type: BROADCAST_CHANNEL_CONNECTOR_TYPE$1,
|
|
32915
|
-
channelName
|
|
32916
|
-
inboxCapacity
|
|
32917
|
-
passive: true,
|
|
33143
|
+
channelName,
|
|
33144
|
+
inboxCapacity,
|
|
33145
|
+
passive: typeof passiveCandidate === 'boolean' ? passiveCandidate : true,
|
|
33146
|
+
initialWindow,
|
|
33147
|
+
localNodeId,
|
|
33148
|
+
initialTargetNodeId,
|
|
32918
33149
|
};
|
|
32919
|
-
|
|
32920
|
-
|
|
32921
|
-
|
|
33150
|
+
}
|
|
33151
|
+
_requireLocalNodeId() {
|
|
33152
|
+
if (!this._routingNode) {
|
|
33153
|
+
throw new Error('BroadcastChannelListener requires routing node context');
|
|
32922
33154
|
}
|
|
32923
|
-
const
|
|
32924
|
-
|
|
32925
|
-
|
|
32926
|
-
|
|
32927
|
-
config.inboxCapacity = Math.floor(inboxCandidate);
|
|
33155
|
+
const normalized = this._normalizeNodeId(this._routingNode.sid) ??
|
|
33156
|
+
this._normalizeNodeId(this._routingNode.id);
|
|
33157
|
+
if (!normalized) {
|
|
33158
|
+
throw new Error('BroadcastChannelListener requires routing node with a stable identifier');
|
|
32928
33159
|
}
|
|
32929
|
-
return
|
|
33160
|
+
return normalized;
|
|
33161
|
+
}
|
|
33162
|
+
_normalizeNodeId(value) {
|
|
33163
|
+
if (typeof value !== 'string') {
|
|
33164
|
+
return null;
|
|
33165
|
+
}
|
|
33166
|
+
const trimmed = value.trim();
|
|
33167
|
+
return trimmed.length > 0 ? trimmed : null;
|
|
32930
33168
|
}
|
|
32931
33169
|
_monitorConnectorLifecycle(senderId, systemId, connector) {
|
|
32932
33170
|
const maybeClosable = connector;
|