@naylence/runtime 0.3.5-test.961 → 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.
@@ -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.961
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.961';
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
- if (typeof busMessage.senderId !== 'string' || busMessage.senderId.length === 0) {
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 (busMessage.senderId === this.connectorId) {
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: busMessage.senderId,
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(busMessage.senderId, payload)) {
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,7 +12011,7 @@ let BroadcastChannelConnector$2 = class BroadcastChannelConnector extends BaseAs
11914
12011
  const normalizedSenderId = typeof senderId === 'string' && senderId.length > 0
11915
12012
  ? senderId
11916
12013
  : undefined;
11917
- if (normalizedSenderId && normalizedSenderId !== this.connectorId) {
12014
+ if (normalizedSenderId && normalizedSenderId !== this.localNodeId) {
11918
12015
  logger$10.debug('broadcast_channel_duplicate_ack_bypass_non_self', {
11919
12016
  channel: this.channelName,
11920
12017
  connector_id: this.connectorId,
@@ -11954,7 +12051,7 @@ let BroadcastChannelConnector$2 = class BroadcastChannelConnector extends BaseAs
11954
12051
  return false;
11955
12052
  }
11956
12053
  const senderId = this._extractSenderIdFromInboxItem(item);
11957
- if (senderId && senderId !== this.connectorId) {
12054
+ if (senderId && senderId !== this.localNodeId) {
11958
12055
  logger$10.debug('broadcast_channel_duplicate_ack_bypass_non_self', {
11959
12056
  channel: this.channelName,
11960
12057
  connector_id: this.connectorId,
@@ -12050,6 +12147,34 @@ let BroadcastChannelConnector$2 = class BroadcastChannelConnector extends BaseAs
12050
12147
  });
12051
12148
  }
12052
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
+ }
12053
12178
  _trimSeenAcks(now) {
12054
12179
  while (this.seenAckOrder.length > 0) {
12055
12180
  const candidate = this.seenAckOrder[0];
@@ -30620,8 +30745,13 @@ class BroadcastChannelConnectorFactory extends ConnectorFactory {
30620
30745
  }
30621
30746
  const normalized = this._normalizeConfig(config);
30622
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
+ }
30623
30752
  const channelName = normalized.channelName ?? DEFAULT_CHANNEL$2;
30624
30753
  const inboxCapacity = normalized.inboxCapacity ?? DEFAULT_INBOX_CAPACITY$2;
30754
+ const resolvedTarget = this._normalizeTargetNodeId(options.initialTargetNodeId ?? normalized.initialTargetNodeId);
30625
30755
  const baseConfig = {
30626
30756
  drainTimeout: normalized.drainTimeout,
30627
30757
  flowControl: normalized.flowControl,
@@ -30636,6 +30766,8 @@ class BroadcastChannelConnectorFactory extends ConnectorFactory {
30636
30766
  type: BROADCAST_CHANNEL_CONNECTOR_TYPE$1,
30637
30767
  channelName,
30638
30768
  inboxCapacity,
30769
+ localNodeId,
30770
+ initialTargetNodeId: resolvedTarget,
30639
30771
  };
30640
30772
  const connector = new BroadcastChannelConnector(connectorConfig, baseConfig);
30641
30773
  if (options.authorization) {
@@ -30659,6 +30791,13 @@ class BroadcastChannelConnectorFactory extends ConnectorFactory {
30659
30791
  normalized.channelName = channel.trim();
30660
30792
  }
30661
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
+ }
30662
30801
  if (typeof capacity === 'number' &&
30663
30802
  Number.isFinite(capacity) &&
30664
30803
  capacity > 0) {
@@ -30702,6 +30841,19 @@ class BroadcastChannelConnectorFactory extends ConnectorFactory {
30702
30841
  normalized.inboxCapacity ?? DEFAULT_INBOX_CAPACITY$2;
30703
30842
  return normalized;
30704
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
+ }
30705
30857
  }
30706
30858
 
30707
30859
  var broadcastChannelConnectorFactory = /*#__PURE__*/Object.freeze({
@@ -32859,7 +33011,7 @@ class BroadcastChannelListener extends TransportListener {
32859
33011
  node: routingNode,
32860
33012
  });
32861
33013
  const selection = defaultGrantSelectionPolicy.selectCallbackGrant(selectionContext);
32862
- connectorConfig = this._grantToConnectorConfig(selection.grant);
33014
+ connectorConfig = this._grantToConnectorConfig(selection.grant, systemId);
32863
33015
  }
32864
33016
  catch (error) {
32865
33017
  logger$n.debug('broadcast_channel_listener_grant_selection_failed', {
@@ -32868,13 +33020,20 @@ class BroadcastChannelListener extends TransportListener {
32868
33020
  error: error instanceof Error ? error.message : String(error),
32869
33021
  });
32870
33022
  connectorConfig =
32871
- this._extractBroadcastConnectorConfig(frame) ??
32872
- {
33023
+ this._extractBroadcastConnectorConfig(frame, systemId) ??
33024
+ this._buildConnectorConfigForSystem(systemId, {
32873
33025
  type: BROADCAST_CHANNEL_CONNECTOR_TYPE$1,
32874
33026
  channelName: this._channelName,
32875
33027
  inboxCapacity: this._inboxCapacity,
32876
33028
  passive: true,
32877
- };
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;
32878
33037
  }
32879
33038
  try {
32880
33039
  const connector = await routingNode.createOriginConnector({
@@ -32900,7 +33059,7 @@ class BroadcastChannelListener extends TransportListener {
32900
33059
  return null;
32901
33060
  }
32902
33061
  }
32903
- _extractBroadcastConnectorConfig(frame) {
33062
+ _extractBroadcastConnectorConfig(frame, systemId) {
32904
33063
  const rawGrants = frame.callbackGrants;
32905
33064
  if (!Array.isArray(rawGrants)) {
32906
33065
  return null;
@@ -32911,7 +33070,10 @@ class BroadcastChannelListener extends TransportListener {
32911
33070
  (grant.type === BROADCAST_CHANNEL_CONNECTION_GRANT_TYPE ||
32912
33071
  grant.type === BROADCAST_CHANNEL_CONNECTOR_TYPE$1)) {
32913
33072
  try {
32914
- return this._grantToConnectorConfig(grant);
33073
+ if (grant.type === BROADCAST_CHANNEL_CONNECTOR_TYPE$1) {
33074
+ return this._buildConnectorConfigForSystem(systemId, grant);
33075
+ }
33076
+ return this._buildConnectorConfigForSystem(systemId, broadcastChannelGrantToConnectorConfig(grant));
32915
33077
  }
32916
33078
  catch (error) {
32917
33079
  logger$n.debug('broadcast_channel_listener_grant_normalization_failed', {
@@ -32922,31 +33084,87 @@ class BroadcastChannelListener extends TransportListener {
32922
33084
  }
32923
33085
  return null;
32924
33086
  }
32925
- _grantToConnectorConfig(grant) {
32926
- if (grant.type !== BROADCAST_CHANNEL_CONNECTOR_TYPE$1) {
32927
- if (grant.type === BROADCAST_CHANNEL_CONNECTION_GRANT_TYPE) {
32928
- return broadcastChannelGrantToConnectorConfig(grant);
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}`);
32929
33100
  }
32930
- throw new Error(`Unsupported grant type: ${grant.type}`);
33101
+ return this._buildConnectorConfigForSystem(systemId, normalized);
32931
33102
  }
32932
- const candidate = grant;
32933
- const config = {
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 {
32934
33142
  type: BROADCAST_CHANNEL_CONNECTOR_TYPE$1,
32935
- channelName: this._channelName,
32936
- inboxCapacity: this._inboxCapacity,
32937
- passive: true,
33143
+ channelName,
33144
+ inboxCapacity,
33145
+ passive: typeof passiveCandidate === 'boolean' ? passiveCandidate : true,
33146
+ initialWindow,
33147
+ localNodeId,
33148
+ initialTargetNodeId,
32938
33149
  };
32939
- const channelCandidate = candidate.channelName ?? candidate['channel_name'];
32940
- if (typeof channelCandidate === 'string' && channelCandidate.trim().length > 0) {
32941
- config.channelName = channelCandidate.trim();
33150
+ }
33151
+ _requireLocalNodeId() {
33152
+ if (!this._routingNode) {
33153
+ throw new Error('BroadcastChannelListener requires routing node context');
32942
33154
  }
32943
- const inboxCandidate = candidate.inboxCapacity ?? candidate['inbox_capacity'];
32944
- if (typeof inboxCandidate === 'number' &&
32945
- Number.isFinite(inboxCandidate) &&
32946
- inboxCandidate > 0) {
32947
- 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');
32948
33159
  }
32949
- return config;
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;
32950
33168
  }
32951
33169
  _monitorConnectorLifecycle(senderId, systemId, connector) {
32952
33170
  const maybeClosable = connector;