@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/browser/index.mjs
CHANGED
|
@@ -96,12 +96,12 @@ installProcessEnvShim();
|
|
|
96
96
|
// --- END ENV SHIM ---
|
|
97
97
|
|
|
98
98
|
// This file is auto-generated during build - do not edit manually
|
|
99
|
-
// Generated from package.json version: 0.3.5-test.
|
|
99
|
+
// Generated from package.json version: 0.3.5-test.962
|
|
100
100
|
/**
|
|
101
101
|
* The package version, injected at build time.
|
|
102
102
|
* @internal
|
|
103
103
|
*/
|
|
104
|
-
const VERSION = '0.3.5-test.
|
|
104
|
+
const VERSION = '0.3.5-test.962';
|
|
105
105
|
|
|
106
106
|
/**
|
|
107
107
|
* Fame protocol specific error classes with WebSocket close codes and proper inheritance.
|
|
@@ -9944,6 +9944,26 @@ let BroadcastChannelConnector$2 = class BroadcastChannelConnector extends BaseAs
|
|
|
9944
9944
|
}
|
|
9945
9945
|
return null;
|
|
9946
9946
|
}
|
|
9947
|
+
static normalizeNodeId(value) {
|
|
9948
|
+
if (typeof value !== 'string') {
|
|
9949
|
+
return null;
|
|
9950
|
+
}
|
|
9951
|
+
const trimmed = value.trim();
|
|
9952
|
+
return trimmed.length > 0 ? trimmed : null;
|
|
9953
|
+
}
|
|
9954
|
+
static normalizeTargetNodeId(value) {
|
|
9955
|
+
if (typeof value !== 'string') {
|
|
9956
|
+
return undefined;
|
|
9957
|
+
}
|
|
9958
|
+
const trimmed = value.trim();
|
|
9959
|
+
if (trimmed.length === 0) {
|
|
9960
|
+
return undefined;
|
|
9961
|
+
}
|
|
9962
|
+
if (trimmed === '*') {
|
|
9963
|
+
return '*';
|
|
9964
|
+
}
|
|
9965
|
+
return trimmed;
|
|
9966
|
+
}
|
|
9947
9967
|
constructor(config, baseConfig = {}) {
|
|
9948
9968
|
ensureBroadcastEnvironment();
|
|
9949
9969
|
super(baseConfig);
|
|
@@ -9966,10 +9986,18 @@ let BroadcastChannelConnector$2 = class BroadcastChannelConnector extends BaseAs
|
|
|
9966
9986
|
this.inbox = new BoundedAsyncQueue(preferredCapacity);
|
|
9967
9987
|
this.inboxCapacity = preferredCapacity;
|
|
9968
9988
|
this.connectorId = BroadcastChannelConnector.generateConnectorId();
|
|
9989
|
+
const normalizedLocalNodeId = BroadcastChannelConnector.normalizeNodeId(config.localNodeId);
|
|
9990
|
+
if (!normalizedLocalNodeId) {
|
|
9991
|
+
throw new Error('BroadcastChannelConnector requires a non-empty localNodeId');
|
|
9992
|
+
}
|
|
9993
|
+
this.localNodeId = normalizedLocalNodeId;
|
|
9994
|
+
this.targetNodeId = BroadcastChannelConnector.normalizeTargetNodeId(config.initialTargetNodeId);
|
|
9969
9995
|
this.channel = new BroadcastChannel(this.channelName);
|
|
9970
9996
|
logger$_.debug('broadcast_channel_connector_created', {
|
|
9971
9997
|
channel: this.channelName,
|
|
9972
9998
|
connector_id: this.connectorId,
|
|
9999
|
+
local_node_id: this.localNodeId,
|
|
10000
|
+
target_node_id: this.targetNodeId ?? null,
|
|
9973
10001
|
inbox_capacity: preferredCapacity,
|
|
9974
10002
|
timestamp: new Date().toISOString(),
|
|
9975
10003
|
});
|
|
@@ -9991,15 +10019,32 @@ let BroadcastChannelConnector$2 = class BroadcastChannelConnector extends BaseAs
|
|
|
9991
10019
|
? message.constructor?.name ?? typeof message
|
|
9992
10020
|
: typeof message,
|
|
9993
10021
|
has_sender_id: Boolean(message?.senderId),
|
|
10022
|
+
has_sender_node_id: Boolean(message?.senderNodeId),
|
|
9994
10023
|
});
|
|
9995
10024
|
if (!message || typeof message !== 'object') {
|
|
9996
10025
|
return;
|
|
9997
10026
|
}
|
|
9998
10027
|
const busMessage = message;
|
|
9999
|
-
|
|
10028
|
+
const senderNodeId = BroadcastChannelConnector.normalizeNodeId(busMessage.senderNodeId);
|
|
10029
|
+
if (!senderNodeId) {
|
|
10030
|
+
logger$_.debug('broadcast_channel_message_rejected', {
|
|
10031
|
+
channel: this.channelName,
|
|
10032
|
+
connector_id: this.connectorId,
|
|
10033
|
+
reason: 'missing_sender_node_id',
|
|
10034
|
+
});
|
|
10000
10035
|
return;
|
|
10001
10036
|
}
|
|
10002
|
-
if (
|
|
10037
|
+
if (senderNodeId === this.localNodeId) {
|
|
10038
|
+
logger$_.debug('broadcast_channel_message_rejected', {
|
|
10039
|
+
channel: this.channelName,
|
|
10040
|
+
connector_id: this.connectorId,
|
|
10041
|
+
reason: 'self_echo',
|
|
10042
|
+
sender_node_id: senderNodeId,
|
|
10043
|
+
});
|
|
10044
|
+
return;
|
|
10045
|
+
}
|
|
10046
|
+
const incomingTargetNodeId = BroadcastChannelConnector.normalizeTargetNodeId(busMessage.targetNodeId);
|
|
10047
|
+
if (!this._shouldAcceptMessageFromBus(senderNodeId, incomingTargetNodeId)) {
|
|
10003
10048
|
return;
|
|
10004
10049
|
}
|
|
10005
10050
|
const payload = BroadcastChannelConnector.coercePayload(busMessage.payload);
|
|
@@ -10013,11 +10058,13 @@ let BroadcastChannelConnector$2 = class BroadcastChannelConnector extends BaseAs
|
|
|
10013
10058
|
}
|
|
10014
10059
|
logger$_.debug('broadcast_channel_message_received', {
|
|
10015
10060
|
channel: this.channelName,
|
|
10016
|
-
sender_id:
|
|
10061
|
+
sender_id: message?.senderId,
|
|
10062
|
+
sender_node_id: senderNodeId,
|
|
10063
|
+
target_node_id: incomingTargetNodeId ?? null,
|
|
10017
10064
|
connector_id: this.connectorId,
|
|
10018
10065
|
payload_length: payload.byteLength,
|
|
10019
10066
|
});
|
|
10020
|
-
if (this._shouldSkipDuplicateAck(
|
|
10067
|
+
if (this._shouldSkipDuplicateAck(senderNodeId, payload)) {
|
|
10021
10068
|
return;
|
|
10022
10069
|
}
|
|
10023
10070
|
try {
|
|
@@ -10161,12 +10208,17 @@ let BroadcastChannelConnector$2 = class BroadcastChannelConnector extends BaseAs
|
|
|
10161
10208
|
}
|
|
10162
10209
|
async _transportSendBytes(data) {
|
|
10163
10210
|
ensureBroadcastEnvironment();
|
|
10211
|
+
const targetNodeId = this.targetNodeId ?? '*';
|
|
10164
10212
|
logger$_.debug('broadcast_channel_message_sending', {
|
|
10165
10213
|
channel: this.channelName,
|
|
10166
10214
|
sender_id: this.connectorId,
|
|
10215
|
+
sender_node_id: this.localNodeId,
|
|
10216
|
+
target_node_id: targetNodeId,
|
|
10167
10217
|
});
|
|
10168
10218
|
this.channel.postMessage({
|
|
10169
10219
|
senderId: this.connectorId,
|
|
10220
|
+
senderNodeId: this.localNodeId,
|
|
10221
|
+
targetNodeId,
|
|
10170
10222
|
payload: data,
|
|
10171
10223
|
});
|
|
10172
10224
|
}
|
|
@@ -10229,6 +10281,51 @@ let BroadcastChannelConnector$2 = class BroadcastChannelConnector extends BaseAs
|
|
|
10229
10281
|
}
|
|
10230
10282
|
return rawOrEnvelope;
|
|
10231
10283
|
}
|
|
10284
|
+
_isWildcardTarget() {
|
|
10285
|
+
return this.targetNodeId === '*' || typeof this.targetNodeId === 'undefined';
|
|
10286
|
+
}
|
|
10287
|
+
_shouldAcceptMessageFromBus(senderNodeId, targetNodeId) {
|
|
10288
|
+
if (this._isWildcardTarget()) {
|
|
10289
|
+
if (targetNodeId && targetNodeId !== '*') {
|
|
10290
|
+
logger$_.debug('broadcast_channel_message_rejected', {
|
|
10291
|
+
channel: this.channelName,
|
|
10292
|
+
connector_id: this.connectorId,
|
|
10293
|
+
reason: 'wildcard_target_mismatch',
|
|
10294
|
+
sender_node_id: senderNodeId,
|
|
10295
|
+
target_node_id: targetNodeId,
|
|
10296
|
+
local_node_id: this.localNodeId,
|
|
10297
|
+
});
|
|
10298
|
+
return false;
|
|
10299
|
+
}
|
|
10300
|
+
return true;
|
|
10301
|
+
}
|
|
10302
|
+
const expectedSender = this.targetNodeId;
|
|
10303
|
+
if (expectedSender && expectedSender !== '*' && senderNodeId !== expectedSender) {
|
|
10304
|
+
logger$_.debug('broadcast_channel_message_rejected', {
|
|
10305
|
+
channel: this.channelName,
|
|
10306
|
+
connector_id: this.connectorId,
|
|
10307
|
+
reason: 'unexpected_sender',
|
|
10308
|
+
expected_sender_node_id: expectedSender,
|
|
10309
|
+
sender_node_id: senderNodeId,
|
|
10310
|
+
local_node_id: this.localNodeId,
|
|
10311
|
+
});
|
|
10312
|
+
return false;
|
|
10313
|
+
}
|
|
10314
|
+
if (targetNodeId &&
|
|
10315
|
+
targetNodeId !== '*' &&
|
|
10316
|
+
targetNodeId !== this.localNodeId) {
|
|
10317
|
+
logger$_.debug('broadcast_channel_message_rejected', {
|
|
10318
|
+
channel: this.channelName,
|
|
10319
|
+
connector_id: this.connectorId,
|
|
10320
|
+
reason: 'unexpected_target',
|
|
10321
|
+
sender_node_id: senderNodeId,
|
|
10322
|
+
target_node_id: targetNodeId,
|
|
10323
|
+
local_node_id: this.localNodeId,
|
|
10324
|
+
});
|
|
10325
|
+
return false;
|
|
10326
|
+
}
|
|
10327
|
+
return true;
|
|
10328
|
+
}
|
|
10232
10329
|
_describeInboxItem(item) {
|
|
10233
10330
|
if (item instanceof Uint8Array) {
|
|
10234
10331
|
return 'bytes';
|
|
@@ -10259,6 +10356,16 @@ let BroadcastChannelConnector$2 = class BroadcastChannelConnector extends BaseAs
|
|
|
10259
10356
|
const normalizedSenderId = typeof senderId === 'string' && senderId.length > 0
|
|
10260
10357
|
? senderId
|
|
10261
10358
|
: undefined;
|
|
10359
|
+
if (normalizedSenderId && normalizedSenderId !== this.localNodeId) {
|
|
10360
|
+
logger$_.debug('broadcast_channel_duplicate_ack_bypass_non_self', {
|
|
10361
|
+
channel: this.channelName,
|
|
10362
|
+
connector_id: this.connectorId,
|
|
10363
|
+
sender_id: normalizedSenderId,
|
|
10364
|
+
dedup_key: dedupKey,
|
|
10365
|
+
source: 'listener',
|
|
10366
|
+
});
|
|
10367
|
+
return false;
|
|
10368
|
+
}
|
|
10262
10369
|
logger$_.debug('broadcast_channel_duplicate_ack_check', {
|
|
10263
10370
|
channel: this.channelName,
|
|
10264
10371
|
connector_id: this.connectorId,
|
|
@@ -10289,6 +10396,16 @@ let BroadcastChannelConnector$2 = class BroadcastChannelConnector extends BaseAs
|
|
|
10289
10396
|
return false;
|
|
10290
10397
|
}
|
|
10291
10398
|
const senderId = this._extractSenderIdFromInboxItem(item);
|
|
10399
|
+
if (senderId && senderId !== this.localNodeId) {
|
|
10400
|
+
logger$_.debug('broadcast_channel_duplicate_ack_bypass_non_self', {
|
|
10401
|
+
channel: this.channelName,
|
|
10402
|
+
connector_id: this.connectorId,
|
|
10403
|
+
sender_id: senderId,
|
|
10404
|
+
dedup_key: dedupKey,
|
|
10405
|
+
source: 'inbox_item',
|
|
10406
|
+
});
|
|
10407
|
+
return false;
|
|
10408
|
+
}
|
|
10292
10409
|
logger$_.debug('broadcast_channel_duplicate_ack_check', {
|
|
10293
10410
|
channel: this.channelName,
|
|
10294
10411
|
connector_id: this.connectorId,
|
|
@@ -10375,6 +10492,34 @@ let BroadcastChannelConnector$2 = class BroadcastChannelConnector extends BaseAs
|
|
|
10375
10492
|
});
|
|
10376
10493
|
}
|
|
10377
10494
|
}
|
|
10495
|
+
setTargetNodeId(nodeId) {
|
|
10496
|
+
const normalized = BroadcastChannelConnector.normalizeNodeId(nodeId);
|
|
10497
|
+
if (!normalized) {
|
|
10498
|
+
throw new Error('BroadcastChannelConnector target node id must be a non-empty string');
|
|
10499
|
+
}
|
|
10500
|
+
if (normalized === '*') {
|
|
10501
|
+
this.setWildcardTarget();
|
|
10502
|
+
return;
|
|
10503
|
+
}
|
|
10504
|
+
this.targetNodeId = normalized;
|
|
10505
|
+
logger$_.debug('broadcast_channel_target_updated', {
|
|
10506
|
+
channel: this.channelName,
|
|
10507
|
+
connector_id: this.connectorId,
|
|
10508
|
+
local_node_id: this.localNodeId,
|
|
10509
|
+
target_node_id: this.targetNodeId,
|
|
10510
|
+
target_mode: 'direct',
|
|
10511
|
+
});
|
|
10512
|
+
}
|
|
10513
|
+
setWildcardTarget() {
|
|
10514
|
+
this.targetNodeId = '*';
|
|
10515
|
+
logger$_.debug('broadcast_channel_target_updated', {
|
|
10516
|
+
channel: this.channelName,
|
|
10517
|
+
connector_id: this.connectorId,
|
|
10518
|
+
local_node_id: this.localNodeId,
|
|
10519
|
+
target_node_id: this.targetNodeId,
|
|
10520
|
+
target_mode: 'wildcard',
|
|
10521
|
+
});
|
|
10522
|
+
}
|
|
10378
10523
|
_trimSeenAcks(now) {
|
|
10379
10524
|
while (this.seenAckOrder.length > 0) {
|
|
10380
10525
|
const candidate = this.seenAckOrder[0];
|
|
@@ -28911,8 +29056,13 @@ class BroadcastChannelConnectorFactory extends ConnectorFactory {
|
|
|
28911
29056
|
}
|
|
28912
29057
|
const normalized = this._normalizeConfig(config);
|
|
28913
29058
|
const options = (factoryArgs[0] ?? {});
|
|
29059
|
+
const localNodeId = this._normalizeNodeId(options.localNodeId);
|
|
29060
|
+
if (!localNodeId) {
|
|
29061
|
+
throw new Error('BroadcastChannelConnectorFactory requires a localNodeId in create() options');
|
|
29062
|
+
}
|
|
28914
29063
|
const channelName = normalized.channelName ?? DEFAULT_CHANNEL$4;
|
|
28915
29064
|
const inboxCapacity = normalized.inboxCapacity ?? DEFAULT_INBOX_CAPACITY$4;
|
|
29065
|
+
const resolvedTarget = this._normalizeTargetNodeId(options.initialTargetNodeId ?? normalized.initialTargetNodeId);
|
|
28916
29066
|
const baseConfig = {
|
|
28917
29067
|
drainTimeout: normalized.drainTimeout,
|
|
28918
29068
|
flowControl: normalized.flowControl,
|
|
@@ -28927,6 +29077,8 @@ class BroadcastChannelConnectorFactory extends ConnectorFactory {
|
|
|
28927
29077
|
type: BROADCAST_CHANNEL_CONNECTOR_TYPE,
|
|
28928
29078
|
channelName,
|
|
28929
29079
|
inboxCapacity,
|
|
29080
|
+
localNodeId,
|
|
29081
|
+
initialTargetNodeId: resolvedTarget,
|
|
28930
29082
|
};
|
|
28931
29083
|
const connector = new BroadcastChannelConnector(connectorConfig, baseConfig);
|
|
28932
29084
|
if (options.authorization) {
|
|
@@ -28950,6 +29102,13 @@ class BroadcastChannelConnectorFactory extends ConnectorFactory {
|
|
|
28950
29102
|
normalized.channelName = channel.trim();
|
|
28951
29103
|
}
|
|
28952
29104
|
const capacity = candidate.inboxCapacity ?? candidate['inbox_capacity'];
|
|
29105
|
+
const initialTargetNodeId = candidate.initialTargetNodeId ?? candidate['initial_target_node_id'];
|
|
29106
|
+
if (typeof initialTargetNodeId === 'string' && initialTargetNodeId.trim().length > 0) {
|
|
29107
|
+
normalized.initialTargetNodeId = initialTargetNodeId.trim();
|
|
29108
|
+
}
|
|
29109
|
+
else if (initialTargetNodeId === '*') {
|
|
29110
|
+
normalized.initialTargetNodeId = '*';
|
|
29111
|
+
}
|
|
28953
29112
|
if (typeof capacity === 'number' &&
|
|
28954
29113
|
Number.isFinite(capacity) &&
|
|
28955
29114
|
capacity > 0) {
|
|
@@ -28993,6 +29152,19 @@ class BroadcastChannelConnectorFactory extends ConnectorFactory {
|
|
|
28993
29152
|
normalized.inboxCapacity ?? DEFAULT_INBOX_CAPACITY$4;
|
|
28994
29153
|
return normalized;
|
|
28995
29154
|
}
|
|
29155
|
+
_normalizeNodeId(value) {
|
|
29156
|
+
if (typeof value !== 'string') {
|
|
29157
|
+
return null;
|
|
29158
|
+
}
|
|
29159
|
+
const trimmed = value.trim();
|
|
29160
|
+
return trimmed.length > 0 ? trimmed : null;
|
|
29161
|
+
}
|
|
29162
|
+
_normalizeTargetNodeId(value) {
|
|
29163
|
+
if (value === '*') {
|
|
29164
|
+
return '*';
|
|
29165
|
+
}
|
|
29166
|
+
return this._normalizeNodeId(value) ?? '*';
|
|
29167
|
+
}
|
|
28996
29168
|
}
|
|
28997
29169
|
|
|
28998
29170
|
var broadcastChannelConnectorFactory = /*#__PURE__*/Object.freeze({
|
|
@@ -30096,7 +30268,7 @@ class BroadcastChannelListener extends TransportListener {
|
|
|
30096
30268
|
node: routingNode,
|
|
30097
30269
|
});
|
|
30098
30270
|
const selection = defaultGrantSelectionPolicy.selectCallbackGrant(selectionContext);
|
|
30099
|
-
connectorConfig = this._grantToConnectorConfig(selection.grant);
|
|
30271
|
+
connectorConfig = this._grantToConnectorConfig(selection.grant, systemId);
|
|
30100
30272
|
}
|
|
30101
30273
|
catch (error) {
|
|
30102
30274
|
logger$o.debug('broadcast_channel_listener_grant_selection_failed', {
|
|
@@ -30105,13 +30277,20 @@ class BroadcastChannelListener extends TransportListener {
|
|
|
30105
30277
|
error: error instanceof Error ? error.message : String(error),
|
|
30106
30278
|
});
|
|
30107
30279
|
connectorConfig =
|
|
30108
|
-
this._extractBroadcastConnectorConfig(frame) ??
|
|
30109
|
-
{
|
|
30280
|
+
this._extractBroadcastConnectorConfig(frame, systemId) ??
|
|
30281
|
+
this._buildConnectorConfigForSystem(systemId, {
|
|
30110
30282
|
type: BROADCAST_CHANNEL_CONNECTOR_TYPE,
|
|
30111
30283
|
channelName: this._channelName,
|
|
30112
30284
|
inboxCapacity: this._inboxCapacity,
|
|
30113
30285
|
passive: true,
|
|
30114
|
-
};
|
|
30286
|
+
});
|
|
30287
|
+
}
|
|
30288
|
+
if (!connectorConfig) {
|
|
30289
|
+
logger$o.error('broadcast_channel_listener_missing_connector_config', {
|
|
30290
|
+
sender_id: params.senderId,
|
|
30291
|
+
system_id: systemId,
|
|
30292
|
+
});
|
|
30293
|
+
return null;
|
|
30115
30294
|
}
|
|
30116
30295
|
try {
|
|
30117
30296
|
const connector = await routingNode.createOriginConnector({
|
|
@@ -30137,7 +30316,7 @@ class BroadcastChannelListener extends TransportListener {
|
|
|
30137
30316
|
return null;
|
|
30138
30317
|
}
|
|
30139
30318
|
}
|
|
30140
|
-
_extractBroadcastConnectorConfig(frame) {
|
|
30319
|
+
_extractBroadcastConnectorConfig(frame, systemId) {
|
|
30141
30320
|
const rawGrants = frame.callbackGrants;
|
|
30142
30321
|
if (!Array.isArray(rawGrants)) {
|
|
30143
30322
|
return null;
|
|
@@ -30148,7 +30327,10 @@ class BroadcastChannelListener extends TransportListener {
|
|
|
30148
30327
|
(grant.type === BROADCAST_CHANNEL_CONNECTION_GRANT_TYPE ||
|
|
30149
30328
|
grant.type === BROADCAST_CHANNEL_CONNECTOR_TYPE)) {
|
|
30150
30329
|
try {
|
|
30151
|
-
|
|
30330
|
+
if (grant.type === BROADCAST_CHANNEL_CONNECTOR_TYPE) {
|
|
30331
|
+
return this._buildConnectorConfigForSystem(systemId, grant);
|
|
30332
|
+
}
|
|
30333
|
+
return this._buildConnectorConfigForSystem(systemId, broadcastChannelGrantToConnectorConfig(grant));
|
|
30152
30334
|
}
|
|
30153
30335
|
catch (error) {
|
|
30154
30336
|
logger$o.debug('broadcast_channel_listener_grant_normalization_failed', {
|
|
@@ -30159,31 +30341,87 @@ class BroadcastChannelListener extends TransportListener {
|
|
|
30159
30341
|
}
|
|
30160
30342
|
return null;
|
|
30161
30343
|
}
|
|
30162
|
-
_grantToConnectorConfig(grant) {
|
|
30163
|
-
if (grant.type
|
|
30164
|
-
|
|
30165
|
-
|
|
30344
|
+
_grantToConnectorConfig(grant, systemId) {
|
|
30345
|
+
if (grant.type === BROADCAST_CHANNEL_CONNECTOR_TYPE) {
|
|
30346
|
+
return this._buildConnectorConfigForSystem(systemId, grant);
|
|
30347
|
+
}
|
|
30348
|
+
if (grant.type === BROADCAST_CHANNEL_CONNECTION_GRANT_TYPE) {
|
|
30349
|
+
return this._buildConnectorConfigForSystem(systemId, broadcastChannelGrantToConnectorConfig(grant));
|
|
30350
|
+
}
|
|
30351
|
+
if ('toConnectorConfig' in grant &&
|
|
30352
|
+
typeof grant.toConnectorConfig ===
|
|
30353
|
+
'function') {
|
|
30354
|
+
const normalized = grant.toConnectorConfig();
|
|
30355
|
+
if (normalized.type !== BROADCAST_CHANNEL_CONNECTOR_TYPE) {
|
|
30356
|
+
throw new Error(`Unsupported grant connector type: ${normalized.type}`);
|
|
30166
30357
|
}
|
|
30167
|
-
|
|
30358
|
+
return this._buildConnectorConfigForSystem(systemId, normalized);
|
|
30168
30359
|
}
|
|
30169
|
-
|
|
30170
|
-
|
|
30360
|
+
throw new Error(`Unsupported grant type: ${grant.type}`);
|
|
30361
|
+
}
|
|
30362
|
+
_buildConnectorConfigForSystem(systemId, baseConfig) {
|
|
30363
|
+
const localNodeId = this._requireLocalNodeId();
|
|
30364
|
+
const targetSystemId = this._normalizeNodeId(systemId);
|
|
30365
|
+
if (!targetSystemId) {
|
|
30366
|
+
throw new Error('BroadcastChannelListener requires a valid system id');
|
|
30367
|
+
}
|
|
30368
|
+
const candidate = baseConfig ?? null;
|
|
30369
|
+
const channelCandidate = candidate && 'channelName' in candidate
|
|
30370
|
+
? candidate.channelName
|
|
30371
|
+
: undefined;
|
|
30372
|
+
const inboxCandidate = candidate && 'inboxCapacity' in candidate
|
|
30373
|
+
? candidate.inboxCapacity
|
|
30374
|
+
: undefined;
|
|
30375
|
+
const initialWindowCandidate = candidate && 'initialWindow' in candidate
|
|
30376
|
+
? candidate.initialWindow
|
|
30377
|
+
: undefined;
|
|
30378
|
+
const passiveCandidate = candidate && 'passive' in candidate
|
|
30379
|
+
? candidate.passive
|
|
30380
|
+
: undefined;
|
|
30381
|
+
const targetCandidate = candidate && 'initialTargetNodeId' in candidate
|
|
30382
|
+
? candidate.initialTargetNodeId
|
|
30383
|
+
: undefined;
|
|
30384
|
+
const channelName = typeof channelCandidate === 'string' && channelCandidate.trim().length > 0
|
|
30385
|
+
? channelCandidate.trim()
|
|
30386
|
+
: this._channelName;
|
|
30387
|
+
const inboxCapacity = typeof inboxCandidate === 'number' &&
|
|
30388
|
+
Number.isFinite(inboxCandidate) &&
|
|
30389
|
+
inboxCandidate > 0
|
|
30390
|
+
? Math.floor(inboxCandidate)
|
|
30391
|
+
: this._inboxCapacity;
|
|
30392
|
+
const initialWindow = typeof initialWindowCandidate === 'number' &&
|
|
30393
|
+
Number.isFinite(initialWindowCandidate) &&
|
|
30394
|
+
initialWindowCandidate > 0
|
|
30395
|
+
? Math.floor(initialWindowCandidate)
|
|
30396
|
+
: undefined;
|
|
30397
|
+
const initialTargetNodeId = this._normalizeNodeId(targetCandidate) ?? targetSystemId;
|
|
30398
|
+
return {
|
|
30171
30399
|
type: BROADCAST_CHANNEL_CONNECTOR_TYPE,
|
|
30172
|
-
channelName
|
|
30173
|
-
inboxCapacity
|
|
30174
|
-
passive: true,
|
|
30400
|
+
channelName,
|
|
30401
|
+
inboxCapacity,
|
|
30402
|
+
passive: typeof passiveCandidate === 'boolean' ? passiveCandidate : true,
|
|
30403
|
+
initialWindow,
|
|
30404
|
+
localNodeId,
|
|
30405
|
+
initialTargetNodeId,
|
|
30175
30406
|
};
|
|
30176
|
-
|
|
30177
|
-
|
|
30178
|
-
|
|
30407
|
+
}
|
|
30408
|
+
_requireLocalNodeId() {
|
|
30409
|
+
if (!this._routingNode) {
|
|
30410
|
+
throw new Error('BroadcastChannelListener requires routing node context');
|
|
30179
30411
|
}
|
|
30180
|
-
const
|
|
30181
|
-
|
|
30182
|
-
|
|
30183
|
-
|
|
30184
|
-
config.inboxCapacity = Math.floor(inboxCandidate);
|
|
30412
|
+
const normalized = this._normalizeNodeId(this._routingNode.sid) ??
|
|
30413
|
+
this._normalizeNodeId(this._routingNode.id);
|
|
30414
|
+
if (!normalized) {
|
|
30415
|
+
throw new Error('BroadcastChannelListener requires routing node with a stable identifier');
|
|
30185
30416
|
}
|
|
30186
|
-
return
|
|
30417
|
+
return normalized;
|
|
30418
|
+
}
|
|
30419
|
+
_normalizeNodeId(value) {
|
|
30420
|
+
if (typeof value !== 'string') {
|
|
30421
|
+
return null;
|
|
30422
|
+
}
|
|
30423
|
+
const trimmed = value.trim();
|
|
30424
|
+
return trimmed.length > 0 ? trimmed : null;
|
|
30187
30425
|
}
|
|
30188
30426
|
_monitorConnectorLifecycle(senderId, systemId, connector) {
|
|
30189
30427
|
const maybeClosable = connector;
|
|
@@ -75,8 +75,13 @@ class BroadcastChannelConnectorFactory extends connector_factory_js_1.ConnectorF
|
|
|
75
75
|
}
|
|
76
76
|
const normalized = this._normalizeConfig(config);
|
|
77
77
|
const options = (factoryArgs[0] ?? {});
|
|
78
|
+
const localNodeId = this._normalizeNodeId(options.localNodeId);
|
|
79
|
+
if (!localNodeId) {
|
|
80
|
+
throw new Error('BroadcastChannelConnectorFactory requires a localNodeId in create() options');
|
|
81
|
+
}
|
|
78
82
|
const channelName = normalized.channelName ?? DEFAULT_CHANNEL;
|
|
79
83
|
const inboxCapacity = normalized.inboxCapacity ?? DEFAULT_INBOX_CAPACITY;
|
|
84
|
+
const resolvedTarget = this._normalizeTargetNodeId(options.initialTargetNodeId ?? normalized.initialTargetNodeId);
|
|
80
85
|
const baseConfig = {
|
|
81
86
|
drainTimeout: normalized.drainTimeout,
|
|
82
87
|
flowControl: normalized.flowControl,
|
|
@@ -91,6 +96,8 @@ class BroadcastChannelConnectorFactory extends connector_factory_js_1.ConnectorF
|
|
|
91
96
|
type: broadcast_channel_connector_js_1.BROADCAST_CHANNEL_CONNECTOR_TYPE,
|
|
92
97
|
channelName,
|
|
93
98
|
inboxCapacity,
|
|
99
|
+
localNodeId,
|
|
100
|
+
initialTargetNodeId: resolvedTarget,
|
|
94
101
|
};
|
|
95
102
|
const connector = new broadcast_channel_connector_js_1.BroadcastChannelConnector(connectorConfig, baseConfig);
|
|
96
103
|
if (options.authorization) {
|
|
@@ -114,6 +121,13 @@ class BroadcastChannelConnectorFactory extends connector_factory_js_1.ConnectorF
|
|
|
114
121
|
normalized.channelName = channel.trim();
|
|
115
122
|
}
|
|
116
123
|
const capacity = candidate.inboxCapacity ?? candidate['inbox_capacity'];
|
|
124
|
+
const initialTargetNodeId = candidate.initialTargetNodeId ?? candidate['initial_target_node_id'];
|
|
125
|
+
if (typeof initialTargetNodeId === 'string' && initialTargetNodeId.trim().length > 0) {
|
|
126
|
+
normalized.initialTargetNodeId = initialTargetNodeId.trim();
|
|
127
|
+
}
|
|
128
|
+
else if (initialTargetNodeId === '*') {
|
|
129
|
+
normalized.initialTargetNodeId = '*';
|
|
130
|
+
}
|
|
117
131
|
if (typeof capacity === 'number' &&
|
|
118
132
|
Number.isFinite(capacity) &&
|
|
119
133
|
capacity > 0) {
|
|
@@ -157,6 +171,19 @@ class BroadcastChannelConnectorFactory extends connector_factory_js_1.ConnectorF
|
|
|
157
171
|
normalized.inboxCapacity ?? DEFAULT_INBOX_CAPACITY;
|
|
158
172
|
return normalized;
|
|
159
173
|
}
|
|
174
|
+
_normalizeNodeId(value) {
|
|
175
|
+
if (typeof value !== 'string') {
|
|
176
|
+
return null;
|
|
177
|
+
}
|
|
178
|
+
const trimmed = value.trim();
|
|
179
|
+
return trimmed.length > 0 ? trimmed : null;
|
|
180
|
+
}
|
|
181
|
+
_normalizeTargetNodeId(value) {
|
|
182
|
+
if (value === '*') {
|
|
183
|
+
return '*';
|
|
184
|
+
}
|
|
185
|
+
return this._normalizeNodeId(value) ?? '*';
|
|
186
|
+
}
|
|
160
187
|
}
|
|
161
188
|
exports.BroadcastChannelConnectorFactory = BroadcastChannelConnectorFactory;
|
|
162
189
|
exports.default = BroadcastChannelConnectorFactory;
|