@naylence/runtime 0.3.5-test.956 → 0.3.5-test.958

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.
@@ -98,12 +98,12 @@ installProcessEnvShim();
98
98
  // --- END ENV SHIM ---
99
99
 
100
100
  // This file is auto-generated during build - do not edit manually
101
- // Generated from package.json version: 0.3.5-test.956
101
+ // Generated from package.json version: 0.3.5-test.958
102
102
  /**
103
103
  * The package version, injected at build time.
104
104
  * @internal
105
105
  */
106
- const VERSION = '0.3.5-test.956';
106
+ const VERSION = '0.3.5-test.958';
107
107
 
108
108
  /**
109
109
  * Fame protocol specific error classes with WebSocket close codes and proper inheritance.
@@ -1358,28 +1358,38 @@ class TaskSpawner {
1358
1358
  }
1359
1359
  }
1360
1360
 
1361
+ // import { getLogger } from './logging.js';
1362
+ // const logger = getLogger('naylence.fame.util.lock');
1361
1363
  class AsyncLock {
1362
1364
  constructor() {
1363
- this.tail = Promise.resolve();
1365
+ this.queue = Promise.resolve();
1364
1366
  }
1365
- async runExclusive(operation) {
1367
+ async acquire(task) {
1368
+ const currentQueue = this.queue;
1366
1369
  let release;
1367
- const next = new Promise((resolve) => {
1370
+ const nextPromise = new Promise((resolve) => {
1368
1371
  release = resolve;
1369
1372
  });
1370
- const previous = this.tail;
1371
- this.tail = previous.then(() => next, () => next);
1372
- await previous;
1373
+ // Chain the new promise to the queue
1374
+ this.queue = this.queue.then(() => nextPromise, () => nextPromise);
1375
+ // Wait for the previous task to complete
1376
+ // logger.debug('waiting_for_lock');
1377
+ await currentQueue;
1378
+ // logger.debug('lock_acquired');
1373
1379
  try {
1374
- return await operation();
1380
+ return await task();
1375
1381
  }
1376
1382
  finally {
1377
1383
  release();
1384
+ // logger.debug('lock_released');
1378
1385
  }
1379
1386
  }
1387
+ async runExclusive(task) {
1388
+ return this.acquire(task);
1389
+ }
1380
1390
  }
1381
1391
  async function withLock(lock, operation) {
1382
- return await lock.runExclusive(operation);
1392
+ return await lock.acquire(operation);
1383
1393
  }
1384
1394
 
1385
1395
  /**
@@ -2447,8 +2457,15 @@ class FlowController {
2447
2457
  // Create a notifier promise
2448
2458
  const notifierPromise = (async () => {
2449
2459
  try {
2450
- // Use setImmediate to defer to next tick (similar to asyncio scheduling)
2451
- await new Promise((resolve) => setImmediate(resolve));
2460
+ // Use setImmediate/setTimeout to defer to next tick (similar to asyncio scheduling)
2461
+ await new Promise((resolve) => {
2462
+ if (typeof setImmediate === 'function') {
2463
+ setImmediate(resolve);
2464
+ }
2465
+ else {
2466
+ setTimeout(resolve, 0);
2467
+ }
2468
+ });
2452
2469
  condition.notifyAll();
2453
2470
  }
2454
2471
  finally {
@@ -2507,22 +2524,24 @@ class FlowController {
2507
2524
  current_balance: this.credits.get(flowId),
2508
2525
  });
2509
2526
  while (this.credits.get(flowId) <= 0) {
2510
- logger$1b.debug('flow_controller_waiting_for_credit', {
2527
+ logger$1b.debug('flow_controller_waiting_for_credits', {
2511
2528
  flow_id: flowId,
2529
+ current_balance: this.credits.get(flowId),
2512
2530
  });
2513
2531
  await condition.wait();
2514
- logger$1b.debug('flow_controller_woke_with_credit', {
2515
- flow_id: flowId,
2516
- balance_after_wake: this.credits.get(flowId),
2517
- });
2518
2532
  }
2519
- const current = this.credits.get(flowId);
2520
- this.credits.set(flowId, current - 1);
2521
- logger$1b.debug('flow_controller_credit_consumed', {
2533
+ const newBalance = this.credits.get(flowId) - 1;
2534
+ this.credits.set(flowId, newBalance);
2535
+ logger$1b.debug('flow_controller_acquire_success', {
2522
2536
  flow_id: flowId,
2523
- prev_balance: current,
2524
- remaining_balance: current - 1,
2537
+ new_balance: newBalance,
2525
2538
  });
2539
+ if (newBalance <= this.lowWatermark) {
2540
+ logger$1b.debug('flow_controller_acquire_below_low_watermark', {
2541
+ flow_id: flowId,
2542
+ low_watermark: this.lowWatermark,
2543
+ });
2544
+ }
2526
2545
  }
2527
2546
  /**
2528
2547
  * Consume *credits* immediately (non-blocking).
@@ -11096,8 +11115,15 @@ class UpstreamSessionManager extends TaskSpawner {
11096
11115
  if (!envelope) {
11097
11116
  continue;
11098
11117
  }
11118
+ logger$Z.debug('upstream_pump_sending_envelope', {
11119
+ envelopeId: envelope.id,
11120
+ type: envelope.frame?.type,
11121
+ });
11099
11122
  try {
11100
11123
  await connector.send(envelope);
11124
+ logger$Z.debug('upstream_pump_sent_envelope', {
11125
+ envelopeId: envelope.id,
11126
+ });
11101
11127
  }
11102
11128
  catch (error) {
11103
11129
  if (error instanceof FameMessageTooLarge) {
@@ -19955,6 +19981,9 @@ class WebSocketConnector extends BaseAsyncConnector {
19955
19981
  // Browser WebSocket or Node.js ws client
19956
19982
  this._websocket.send(data);
19957
19983
  }
19984
+ logger$H.debug('websocket_sent_bytes', {
19985
+ byte_length: data.length,
19986
+ });
19958
19987
  }
19959
19988
  catch (error) {
19960
19989
  // Handle WebSocket disconnection errors
@@ -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.956
99
+ // Generated from package.json version: 0.3.5-test.958
100
100
  /**
101
101
  * The package version, injected at build time.
102
102
  * @internal
103
103
  */
104
- const VERSION = '0.3.5-test.956';
104
+ const VERSION = '0.3.5-test.958';
105
105
 
106
106
  /**
107
107
  * Fame protocol specific error classes with WebSocket close codes and proper inheritance.
@@ -1356,28 +1356,38 @@ class TaskSpawner {
1356
1356
  }
1357
1357
  }
1358
1358
 
1359
+ // import { getLogger } from './logging.js';
1360
+ // const logger = getLogger('naylence.fame.util.lock');
1359
1361
  class AsyncLock {
1360
1362
  constructor() {
1361
- this.tail = Promise.resolve();
1363
+ this.queue = Promise.resolve();
1362
1364
  }
1363
- async runExclusive(operation) {
1365
+ async acquire(task) {
1366
+ const currentQueue = this.queue;
1364
1367
  let release;
1365
- const next = new Promise((resolve) => {
1368
+ const nextPromise = new Promise((resolve) => {
1366
1369
  release = resolve;
1367
1370
  });
1368
- const previous = this.tail;
1369
- this.tail = previous.then(() => next, () => next);
1370
- await previous;
1371
+ // Chain the new promise to the queue
1372
+ this.queue = this.queue.then(() => nextPromise, () => nextPromise);
1373
+ // Wait for the previous task to complete
1374
+ // logger.debug('waiting_for_lock');
1375
+ await currentQueue;
1376
+ // logger.debug('lock_acquired');
1371
1377
  try {
1372
- return await operation();
1378
+ return await task();
1373
1379
  }
1374
1380
  finally {
1375
1381
  release();
1382
+ // logger.debug('lock_released');
1376
1383
  }
1377
1384
  }
1385
+ async runExclusive(task) {
1386
+ return this.acquire(task);
1387
+ }
1378
1388
  }
1379
1389
  async function withLock(lock, operation) {
1380
- return await lock.runExclusive(operation);
1390
+ return await lock.acquire(operation);
1381
1391
  }
1382
1392
 
1383
1393
  /**
@@ -2445,8 +2455,15 @@ class FlowController {
2445
2455
  // Create a notifier promise
2446
2456
  const notifierPromise = (async () => {
2447
2457
  try {
2448
- // Use setImmediate to defer to next tick (similar to asyncio scheduling)
2449
- await new Promise((resolve) => setImmediate(resolve));
2458
+ // Use setImmediate/setTimeout to defer to next tick (similar to asyncio scheduling)
2459
+ await new Promise((resolve) => {
2460
+ if (typeof setImmediate === 'function') {
2461
+ setImmediate(resolve);
2462
+ }
2463
+ else {
2464
+ setTimeout(resolve, 0);
2465
+ }
2466
+ });
2450
2467
  condition.notifyAll();
2451
2468
  }
2452
2469
  finally {
@@ -2505,22 +2522,24 @@ class FlowController {
2505
2522
  current_balance: this.credits.get(flowId),
2506
2523
  });
2507
2524
  while (this.credits.get(flowId) <= 0) {
2508
- logger$1b.debug('flow_controller_waiting_for_credit', {
2525
+ logger$1b.debug('flow_controller_waiting_for_credits', {
2509
2526
  flow_id: flowId,
2527
+ current_balance: this.credits.get(flowId),
2510
2528
  });
2511
2529
  await condition.wait();
2512
- logger$1b.debug('flow_controller_woke_with_credit', {
2513
- flow_id: flowId,
2514
- balance_after_wake: this.credits.get(flowId),
2515
- });
2516
2530
  }
2517
- const current = this.credits.get(flowId);
2518
- this.credits.set(flowId, current - 1);
2519
- logger$1b.debug('flow_controller_credit_consumed', {
2531
+ const newBalance = this.credits.get(flowId) - 1;
2532
+ this.credits.set(flowId, newBalance);
2533
+ logger$1b.debug('flow_controller_acquire_success', {
2520
2534
  flow_id: flowId,
2521
- prev_balance: current,
2522
- remaining_balance: current - 1,
2535
+ new_balance: newBalance,
2523
2536
  });
2537
+ if (newBalance <= this.lowWatermark) {
2538
+ logger$1b.debug('flow_controller_acquire_below_low_watermark', {
2539
+ flow_id: flowId,
2540
+ low_watermark: this.lowWatermark,
2541
+ });
2542
+ }
2524
2543
  }
2525
2544
  /**
2526
2545
  * Consume *credits* immediately (non-blocking).
@@ -11094,8 +11113,15 @@ class UpstreamSessionManager extends TaskSpawner {
11094
11113
  if (!envelope) {
11095
11114
  continue;
11096
11115
  }
11116
+ logger$Z.debug('upstream_pump_sending_envelope', {
11117
+ envelopeId: envelope.id,
11118
+ type: envelope.frame?.type,
11119
+ });
11097
11120
  try {
11098
11121
  await connector.send(envelope);
11122
+ logger$Z.debug('upstream_pump_sent_envelope', {
11123
+ envelopeId: envelope.id,
11124
+ });
11099
11125
  }
11100
11126
  catch (error) {
11101
11127
  if (error instanceof FameMessageTooLarge) {
@@ -19953,6 +19979,9 @@ class WebSocketConnector extends BaseAsyncConnector {
19953
19979
  // Browser WebSocket or Node.js ws client
19954
19980
  this._websocket.send(data);
19955
19981
  }
19982
+ logger$H.debug('websocket_sent_bytes', {
19983
+ byte_length: data.length,
19984
+ });
19956
19985
  }
19957
19986
  catch (error) {
19958
19987
  // Handle WebSocket disconnection errors
@@ -118,8 +118,15 @@ class FlowController {
118
118
  // Create a notifier promise
119
119
  const notifierPromise = (async () => {
120
120
  try {
121
- // Use setImmediate to defer to next tick (similar to asyncio scheduling)
122
- await new Promise((resolve) => setImmediate(resolve));
121
+ // Use setImmediate/setTimeout to defer to next tick (similar to asyncio scheduling)
122
+ await new Promise((resolve) => {
123
+ if (typeof setImmediate === 'function') {
124
+ setImmediate(resolve);
125
+ }
126
+ else {
127
+ setTimeout(resolve, 0);
128
+ }
129
+ });
123
130
  condition.notifyAll();
124
131
  }
125
132
  finally {
@@ -178,22 +185,24 @@ class FlowController {
178
185
  current_balance: this.credits.get(flowId),
179
186
  });
180
187
  while (this.credits.get(flowId) <= 0) {
181
- logger.debug('flow_controller_waiting_for_credit', {
188
+ logger.debug('flow_controller_waiting_for_credits', {
182
189
  flow_id: flowId,
190
+ current_balance: this.credits.get(flowId),
183
191
  });
184
192
  await condition.wait();
185
- logger.debug('flow_controller_woke_with_credit', {
186
- flow_id: flowId,
187
- balance_after_wake: this.credits.get(flowId),
188
- });
189
193
  }
190
- const current = this.credits.get(flowId);
191
- this.credits.set(flowId, current - 1);
192
- logger.debug('flow_controller_credit_consumed', {
194
+ const newBalance = this.credits.get(flowId) - 1;
195
+ this.credits.set(flowId, newBalance);
196
+ logger.debug('flow_controller_acquire_success', {
193
197
  flow_id: flowId,
194
- prev_balance: current,
195
- remaining_balance: current - 1,
198
+ new_balance: newBalance,
196
199
  });
200
+ if (newBalance <= this.lowWatermark) {
201
+ logger.debug('flow_controller_acquire_below_low_watermark', {
202
+ flow_id: flowId,
203
+ low_watermark: this.lowWatermark,
204
+ });
205
+ }
197
206
  }
198
207
  /**
199
208
  * Consume *credits* immediately (non-blocking).
@@ -143,6 +143,9 @@ class WebSocketConnector extends base_async_connector_js_1.BaseAsyncConnector {
143
143
  // Browser WebSocket or Node.js ws client
144
144
  this._websocket.send(data);
145
145
  }
146
+ logger.debug('websocket_sent_bytes', {
147
+ byte_length: data.length,
148
+ });
146
149
  }
147
150
  catch (error) {
148
151
  // Handle WebSocket disconnection errors
@@ -601,8 +601,15 @@ class UpstreamSessionManager extends task_spawner_js_1.TaskSpawner {
601
601
  if (!envelope) {
602
602
  continue;
603
603
  }
604
+ logger.debug('upstream_pump_sending_envelope', {
605
+ envelopeId: envelope.id,
606
+ type: envelope.frame?.type,
607
+ });
604
608
  try {
605
609
  await connector.send(envelope);
610
+ logger.debug('upstream_pump_sent_envelope', {
611
+ envelopeId: envelope.id,
612
+ });
606
613
  }
607
614
  catch (error) {
608
615
  if (error instanceof errors_js_1.FameMessageTooLarge) {
@@ -1,28 +1,38 @@
1
1
  "use strict";
2
+ // import { getLogger } from './logging.js';
2
3
  Object.defineProperty(exports, "__esModule", { value: true });
3
4
  exports.AsyncLock = void 0;
4
5
  exports.withLock = withLock;
6
+ // const logger = getLogger('naylence.fame.util.lock');
5
7
  class AsyncLock {
6
8
  constructor() {
7
- this.tail = Promise.resolve();
9
+ this.queue = Promise.resolve();
8
10
  }
9
- async runExclusive(operation) {
11
+ async acquire(task) {
12
+ const currentQueue = this.queue;
10
13
  let release;
11
- const next = new Promise((resolve) => {
14
+ const nextPromise = new Promise((resolve) => {
12
15
  release = resolve;
13
16
  });
14
- const previous = this.tail;
15
- this.tail = previous.then(() => next, () => next);
16
- await previous;
17
+ // Chain the new promise to the queue
18
+ this.queue = this.queue.then(() => nextPromise, () => nextPromise);
19
+ // Wait for the previous task to complete
20
+ // logger.debug('waiting_for_lock');
21
+ await currentQueue;
22
+ // logger.debug('lock_acquired');
17
23
  try {
18
- return await operation();
24
+ return await task();
19
25
  }
20
26
  finally {
21
27
  release();
28
+ // logger.debug('lock_released');
22
29
  }
23
30
  }
31
+ async runExclusive(task) {
32
+ return this.acquire(task);
33
+ }
24
34
  }
25
35
  exports.AsyncLock = AsyncLock;
26
36
  async function withLock(lock, operation) {
27
- return await lock.runExclusive(operation);
37
+ return await lock.acquire(operation);
28
38
  }
@@ -1,10 +1,10 @@
1
1
  "use strict";
2
2
  // This file is auto-generated during build - do not edit manually
3
- // Generated from package.json version: 0.3.5-test.956
3
+ // Generated from package.json version: 0.3.5-test.958
4
4
  Object.defineProperty(exports, "__esModule", { value: true });
5
5
  exports.VERSION = void 0;
6
6
  /**
7
7
  * The package version, injected at build time.
8
8
  * @internal
9
9
  */
10
- exports.VERSION = '0.3.5-test.956';
10
+ exports.VERSION = '0.3.5-test.958';
@@ -115,8 +115,15 @@ export class FlowController {
115
115
  // Create a notifier promise
116
116
  const notifierPromise = (async () => {
117
117
  try {
118
- // Use setImmediate to defer to next tick (similar to asyncio scheduling)
119
- await new Promise((resolve) => setImmediate(resolve));
118
+ // Use setImmediate/setTimeout to defer to next tick (similar to asyncio scheduling)
119
+ await new Promise((resolve) => {
120
+ if (typeof setImmediate === 'function') {
121
+ setImmediate(resolve);
122
+ }
123
+ else {
124
+ setTimeout(resolve, 0);
125
+ }
126
+ });
120
127
  condition.notifyAll();
121
128
  }
122
129
  finally {
@@ -175,22 +182,24 @@ export class FlowController {
175
182
  current_balance: this.credits.get(flowId),
176
183
  });
177
184
  while (this.credits.get(flowId) <= 0) {
178
- logger.debug('flow_controller_waiting_for_credit', {
185
+ logger.debug('flow_controller_waiting_for_credits', {
179
186
  flow_id: flowId,
187
+ current_balance: this.credits.get(flowId),
180
188
  });
181
189
  await condition.wait();
182
- logger.debug('flow_controller_woke_with_credit', {
183
- flow_id: flowId,
184
- balance_after_wake: this.credits.get(flowId),
185
- });
186
190
  }
187
- const current = this.credits.get(flowId);
188
- this.credits.set(flowId, current - 1);
189
- logger.debug('flow_controller_credit_consumed', {
191
+ const newBalance = this.credits.get(flowId) - 1;
192
+ this.credits.set(flowId, newBalance);
193
+ logger.debug('flow_controller_acquire_success', {
190
194
  flow_id: flowId,
191
- prev_balance: current,
192
- remaining_balance: current - 1,
195
+ new_balance: newBalance,
193
196
  });
197
+ if (newBalance <= this.lowWatermark) {
198
+ logger.debug('flow_controller_acquire_below_low_watermark', {
199
+ flow_id: flowId,
200
+ low_watermark: this.lowWatermark,
201
+ });
202
+ }
194
203
  }
195
204
  /**
196
205
  * Consume *credits* immediately (non-blocking).
@@ -140,6 +140,9 @@ export class WebSocketConnector extends BaseAsyncConnector {
140
140
  // Browser WebSocket or Node.js ws client
141
141
  this._websocket.send(data);
142
142
  }
143
+ logger.debug('websocket_sent_bytes', {
144
+ byte_length: data.length,
145
+ });
143
146
  }
144
147
  catch (error) {
145
148
  // Handle WebSocket disconnection errors
@@ -598,8 +598,15 @@ export class UpstreamSessionManager extends TaskSpawner {
598
598
  if (!envelope) {
599
599
  continue;
600
600
  }
601
+ logger.debug('upstream_pump_sending_envelope', {
602
+ envelopeId: envelope.id,
603
+ type: envelope.frame?.type,
604
+ });
601
605
  try {
602
606
  await connector.send(envelope);
607
+ logger.debug('upstream_pump_sent_envelope', {
608
+ envelopeId: envelope.id,
609
+ });
603
610
  }
604
611
  catch (error) {
605
612
  if (error instanceof FameMessageTooLarge) {
@@ -1,23 +1,33 @@
1
+ // import { getLogger } from './logging.js';
2
+ // const logger = getLogger('naylence.fame.util.lock');
1
3
  export class AsyncLock {
2
4
  constructor() {
3
- this.tail = Promise.resolve();
5
+ this.queue = Promise.resolve();
4
6
  }
5
- async runExclusive(operation) {
7
+ async acquire(task) {
8
+ const currentQueue = this.queue;
6
9
  let release;
7
- const next = new Promise((resolve) => {
10
+ const nextPromise = new Promise((resolve) => {
8
11
  release = resolve;
9
12
  });
10
- const previous = this.tail;
11
- this.tail = previous.then(() => next, () => next);
12
- await previous;
13
+ // Chain the new promise to the queue
14
+ this.queue = this.queue.then(() => nextPromise, () => nextPromise);
15
+ // Wait for the previous task to complete
16
+ // logger.debug('waiting_for_lock');
17
+ await currentQueue;
18
+ // logger.debug('lock_acquired');
13
19
  try {
14
- return await operation();
20
+ return await task();
15
21
  }
16
22
  finally {
17
23
  release();
24
+ // logger.debug('lock_released');
18
25
  }
19
26
  }
27
+ async runExclusive(task) {
28
+ return this.acquire(task);
29
+ }
20
30
  }
21
31
  export async function withLock(lock, operation) {
22
- return await lock.runExclusive(operation);
32
+ return await lock.acquire(operation);
23
33
  }
@@ -1,7 +1,7 @@
1
1
  // This file is auto-generated during build - do not edit manually
2
- // Generated from package.json version: 0.3.5-test.956
2
+ // Generated from package.json version: 0.3.5-test.958
3
3
  /**
4
4
  * The package version, injected at build time.
5
5
  * @internal
6
6
  */
7
- export const VERSION = '0.3.5-test.956';
7
+ export const VERSION = '0.3.5-test.958';
@@ -14,12 +14,12 @@ var fastify = require('fastify');
14
14
  var websocketPlugin = require('@fastify/websocket');
15
15
 
16
16
  // This file is auto-generated during build - do not edit manually
17
- // Generated from package.json version: 0.3.5-test.956
17
+ // Generated from package.json version: 0.3.5-test.958
18
18
  /**
19
19
  * The package version, injected at build time.
20
20
  * @internal
21
21
  */
22
- const VERSION = '0.3.5-test.956';
22
+ const VERSION = '0.3.5-test.958';
23
23
 
24
24
  /**
25
25
  * Fame protocol specific error classes with WebSocket close codes and proper inheritance.
@@ -1274,28 +1274,38 @@ class TaskSpawner {
1274
1274
  }
1275
1275
  }
1276
1276
 
1277
+ // import { getLogger } from './logging.js';
1278
+ // const logger = getLogger('naylence.fame.util.lock');
1277
1279
  class AsyncLock {
1278
1280
  constructor() {
1279
- this.tail = Promise.resolve();
1281
+ this.queue = Promise.resolve();
1280
1282
  }
1281
- async runExclusive(operation) {
1283
+ async acquire(task) {
1284
+ const currentQueue = this.queue;
1282
1285
  let release;
1283
- const next = new Promise((resolve) => {
1286
+ const nextPromise = new Promise((resolve) => {
1284
1287
  release = resolve;
1285
1288
  });
1286
- const previous = this.tail;
1287
- this.tail = previous.then(() => next, () => next);
1288
- await previous;
1289
+ // Chain the new promise to the queue
1290
+ this.queue = this.queue.then(() => nextPromise, () => nextPromise);
1291
+ // Wait for the previous task to complete
1292
+ // logger.debug('waiting_for_lock');
1293
+ await currentQueue;
1294
+ // logger.debug('lock_acquired');
1289
1295
  try {
1290
- return await operation();
1296
+ return await task();
1291
1297
  }
1292
1298
  finally {
1293
1299
  release();
1300
+ // logger.debug('lock_released');
1294
1301
  }
1295
1302
  }
1303
+ async runExclusive(task) {
1304
+ return this.acquire(task);
1305
+ }
1296
1306
  }
1297
1307
  async function withLock(lock, operation) {
1298
- return await lock.runExclusive(operation);
1308
+ return await lock.acquire(operation);
1299
1309
  }
1300
1310
 
1301
1311
  /**
@@ -2363,8 +2373,15 @@ class FlowController {
2363
2373
  // Create a notifier promise
2364
2374
  const notifierPromise = (async () => {
2365
2375
  try {
2366
- // Use setImmediate to defer to next tick (similar to asyncio scheduling)
2367
- await new Promise((resolve) => setImmediate(resolve));
2376
+ // Use setImmediate/setTimeout to defer to next tick (similar to asyncio scheduling)
2377
+ await new Promise((resolve) => {
2378
+ if (typeof setImmediate === 'function') {
2379
+ setImmediate(resolve);
2380
+ }
2381
+ else {
2382
+ setTimeout(resolve, 0);
2383
+ }
2384
+ });
2368
2385
  condition.notifyAll();
2369
2386
  }
2370
2387
  finally {
@@ -2423,22 +2440,24 @@ class FlowController {
2423
2440
  current_balance: this.credits.get(flowId),
2424
2441
  });
2425
2442
  while (this.credits.get(flowId) <= 0) {
2426
- logger$1b.debug('flow_controller_waiting_for_credit', {
2443
+ logger$1b.debug('flow_controller_waiting_for_credits', {
2427
2444
  flow_id: flowId,
2445
+ current_balance: this.credits.get(flowId),
2428
2446
  });
2429
2447
  await condition.wait();
2430
- logger$1b.debug('flow_controller_woke_with_credit', {
2431
- flow_id: flowId,
2432
- balance_after_wake: this.credits.get(flowId),
2433
- });
2434
2448
  }
2435
- const current = this.credits.get(flowId);
2436
- this.credits.set(flowId, current - 1);
2437
- logger$1b.debug('flow_controller_credit_consumed', {
2449
+ const newBalance = this.credits.get(flowId) - 1;
2450
+ this.credits.set(flowId, newBalance);
2451
+ logger$1b.debug('flow_controller_acquire_success', {
2438
2452
  flow_id: flowId,
2439
- prev_balance: current,
2440
- remaining_balance: current - 1,
2453
+ new_balance: newBalance,
2441
2454
  });
2455
+ if (newBalance <= this.lowWatermark) {
2456
+ logger$1b.debug('flow_controller_acquire_below_low_watermark', {
2457
+ flow_id: flowId,
2458
+ low_watermark: this.lowWatermark,
2459
+ });
2460
+ }
2442
2461
  }
2443
2462
  /**
2444
2463
  * Consume *credits* immediately (non-blocking).
@@ -11012,8 +11031,15 @@ class UpstreamSessionManager extends TaskSpawner {
11012
11031
  if (!envelope) {
11013
11032
  continue;
11014
11033
  }
11034
+ logger$Z.debug('upstream_pump_sending_envelope', {
11035
+ envelopeId: envelope.id,
11036
+ type: envelope.frame?.type,
11037
+ });
11015
11038
  try {
11016
11039
  await connector.send(envelope);
11040
+ logger$Z.debug('upstream_pump_sent_envelope', {
11041
+ envelopeId: envelope.id,
11042
+ });
11017
11043
  }
11018
11044
  catch (error) {
11019
11045
  if (error instanceof FameMessageTooLarge) {
@@ -19871,6 +19897,9 @@ class WebSocketConnector extends BaseAsyncConnector {
19871
19897
  // Browser WebSocket or Node.js ws client
19872
19898
  this._websocket.send(data);
19873
19899
  }
19900
+ logger$H.debug('websocket_sent_bytes', {
19901
+ byte_length: data.length,
19902
+ });
19874
19903
  }
19875
19904
  catch (error) {
19876
19905
  // Handle WebSocket disconnection errors
@@ -13,12 +13,12 @@ import fastify from 'fastify';
13
13
  import websocketPlugin from '@fastify/websocket';
14
14
 
15
15
  // This file is auto-generated during build - do not edit manually
16
- // Generated from package.json version: 0.3.5-test.956
16
+ // Generated from package.json version: 0.3.5-test.958
17
17
  /**
18
18
  * The package version, injected at build time.
19
19
  * @internal
20
20
  */
21
- const VERSION = '0.3.5-test.956';
21
+ const VERSION = '0.3.5-test.958';
22
22
 
23
23
  /**
24
24
  * Fame protocol specific error classes with WebSocket close codes and proper inheritance.
@@ -1273,28 +1273,38 @@ class TaskSpawner {
1273
1273
  }
1274
1274
  }
1275
1275
 
1276
+ // import { getLogger } from './logging.js';
1277
+ // const logger = getLogger('naylence.fame.util.lock');
1276
1278
  class AsyncLock {
1277
1279
  constructor() {
1278
- this.tail = Promise.resolve();
1280
+ this.queue = Promise.resolve();
1279
1281
  }
1280
- async runExclusive(operation) {
1282
+ async acquire(task) {
1283
+ const currentQueue = this.queue;
1281
1284
  let release;
1282
- const next = new Promise((resolve) => {
1285
+ const nextPromise = new Promise((resolve) => {
1283
1286
  release = resolve;
1284
1287
  });
1285
- const previous = this.tail;
1286
- this.tail = previous.then(() => next, () => next);
1287
- await previous;
1288
+ // Chain the new promise to the queue
1289
+ this.queue = this.queue.then(() => nextPromise, () => nextPromise);
1290
+ // Wait for the previous task to complete
1291
+ // logger.debug('waiting_for_lock');
1292
+ await currentQueue;
1293
+ // logger.debug('lock_acquired');
1288
1294
  try {
1289
- return await operation();
1295
+ return await task();
1290
1296
  }
1291
1297
  finally {
1292
1298
  release();
1299
+ // logger.debug('lock_released');
1293
1300
  }
1294
1301
  }
1302
+ async runExclusive(task) {
1303
+ return this.acquire(task);
1304
+ }
1295
1305
  }
1296
1306
  async function withLock(lock, operation) {
1297
- return await lock.runExclusive(operation);
1307
+ return await lock.acquire(operation);
1298
1308
  }
1299
1309
 
1300
1310
  /**
@@ -2362,8 +2372,15 @@ class FlowController {
2362
2372
  // Create a notifier promise
2363
2373
  const notifierPromise = (async () => {
2364
2374
  try {
2365
- // Use setImmediate to defer to next tick (similar to asyncio scheduling)
2366
- await new Promise((resolve) => setImmediate(resolve));
2375
+ // Use setImmediate/setTimeout to defer to next tick (similar to asyncio scheduling)
2376
+ await new Promise((resolve) => {
2377
+ if (typeof setImmediate === 'function') {
2378
+ setImmediate(resolve);
2379
+ }
2380
+ else {
2381
+ setTimeout(resolve, 0);
2382
+ }
2383
+ });
2367
2384
  condition.notifyAll();
2368
2385
  }
2369
2386
  finally {
@@ -2422,22 +2439,24 @@ class FlowController {
2422
2439
  current_balance: this.credits.get(flowId),
2423
2440
  });
2424
2441
  while (this.credits.get(flowId) <= 0) {
2425
- logger$1b.debug('flow_controller_waiting_for_credit', {
2442
+ logger$1b.debug('flow_controller_waiting_for_credits', {
2426
2443
  flow_id: flowId,
2444
+ current_balance: this.credits.get(flowId),
2427
2445
  });
2428
2446
  await condition.wait();
2429
- logger$1b.debug('flow_controller_woke_with_credit', {
2430
- flow_id: flowId,
2431
- balance_after_wake: this.credits.get(flowId),
2432
- });
2433
2447
  }
2434
- const current = this.credits.get(flowId);
2435
- this.credits.set(flowId, current - 1);
2436
- logger$1b.debug('flow_controller_credit_consumed', {
2448
+ const newBalance = this.credits.get(flowId) - 1;
2449
+ this.credits.set(flowId, newBalance);
2450
+ logger$1b.debug('flow_controller_acquire_success', {
2437
2451
  flow_id: flowId,
2438
- prev_balance: current,
2439
- remaining_balance: current - 1,
2452
+ new_balance: newBalance,
2440
2453
  });
2454
+ if (newBalance <= this.lowWatermark) {
2455
+ logger$1b.debug('flow_controller_acquire_below_low_watermark', {
2456
+ flow_id: flowId,
2457
+ low_watermark: this.lowWatermark,
2458
+ });
2459
+ }
2441
2460
  }
2442
2461
  /**
2443
2462
  * Consume *credits* immediately (non-blocking).
@@ -11011,8 +11030,15 @@ class UpstreamSessionManager extends TaskSpawner {
11011
11030
  if (!envelope) {
11012
11031
  continue;
11013
11032
  }
11033
+ logger$Z.debug('upstream_pump_sending_envelope', {
11034
+ envelopeId: envelope.id,
11035
+ type: envelope.frame?.type,
11036
+ });
11014
11037
  try {
11015
11038
  await connector.send(envelope);
11039
+ logger$Z.debug('upstream_pump_sent_envelope', {
11040
+ envelopeId: envelope.id,
11041
+ });
11016
11042
  }
11017
11043
  catch (error) {
11018
11044
  if (error instanceof FameMessageTooLarge) {
@@ -19870,6 +19896,9 @@ class WebSocketConnector extends BaseAsyncConnector {
19870
19896
  // Browser WebSocket or Node.js ws client
19871
19897
  this._websocket.send(data);
19872
19898
  }
19899
+ logger$H.debug('websocket_sent_bytes', {
19900
+ byte_length: data.length,
19901
+ });
19873
19902
  }
19874
19903
  catch (error) {
19875
19904
  // Handle WebSocket disconnection errors
@@ -1277,8 +1277,15 @@ class FlowController {
1277
1277
  // Create a notifier promise
1278
1278
  const notifierPromise = (async () => {
1279
1279
  try {
1280
- // Use setImmediate to defer to next tick (similar to asyncio scheduling)
1281
- await new Promise((resolve) => setImmediate(resolve));
1280
+ // Use setImmediate/setTimeout to defer to next tick (similar to asyncio scheduling)
1281
+ await new Promise((resolve) => {
1282
+ if (typeof setImmediate === 'function') {
1283
+ setImmediate(resolve);
1284
+ }
1285
+ else {
1286
+ setTimeout(resolve, 0);
1287
+ }
1288
+ });
1282
1289
  condition.notifyAll();
1283
1290
  }
1284
1291
  finally {
@@ -1337,22 +1344,24 @@ class FlowController {
1337
1344
  current_balance: this.credits.get(flowId),
1338
1345
  });
1339
1346
  while (this.credits.get(flowId) <= 0) {
1340
- logger$1g.debug('flow_controller_waiting_for_credit', {
1347
+ logger$1g.debug('flow_controller_waiting_for_credits', {
1341
1348
  flow_id: flowId,
1349
+ current_balance: this.credits.get(flowId),
1342
1350
  });
1343
1351
  await condition.wait();
1344
- logger$1g.debug('flow_controller_woke_with_credit', {
1345
- flow_id: flowId,
1346
- balance_after_wake: this.credits.get(flowId),
1347
- });
1348
1352
  }
1349
- const current = this.credits.get(flowId);
1350
- this.credits.set(flowId, current - 1);
1351
- logger$1g.debug('flow_controller_credit_consumed', {
1353
+ const newBalance = this.credits.get(flowId) - 1;
1354
+ this.credits.set(flowId, newBalance);
1355
+ logger$1g.debug('flow_controller_acquire_success', {
1352
1356
  flow_id: flowId,
1353
- prev_balance: current,
1354
- remaining_balance: current - 1,
1357
+ new_balance: newBalance,
1355
1358
  });
1359
+ if (newBalance <= this.lowWatermark) {
1360
+ logger$1g.debug('flow_controller_acquire_below_low_watermark', {
1361
+ flow_id: flowId,
1362
+ low_watermark: this.lowWatermark,
1363
+ });
1364
+ }
1356
1365
  }
1357
1366
  /**
1358
1367
  * Consume *credits* immediately (non-blocking).
@@ -2780,6 +2789,9 @@ class WebSocketConnector extends BaseAsyncConnector {
2780
2789
  // Browser WebSocket or Node.js ws client
2781
2790
  this._websocket.send(data);
2782
2791
  }
2792
+ logger$1e.debug('websocket_sent_bytes', {
2793
+ byte_length: data.length,
2794
+ });
2783
2795
  }
2784
2796
  catch (error) {
2785
2797
  // Handle WebSocket disconnection errors
@@ -5108,28 +5120,38 @@ class EncryptedStorageProviderBase {
5108
5120
  }
5109
5121
  }
5110
5122
 
5123
+ // import { getLogger } from './logging.js';
5124
+ // const logger = getLogger('naylence.fame.util.lock');
5111
5125
  class AsyncLock {
5112
5126
  constructor() {
5113
- this.tail = Promise.resolve();
5127
+ this.queue = Promise.resolve();
5114
5128
  }
5115
- async runExclusive(operation) {
5129
+ async acquire(task) {
5130
+ const currentQueue = this.queue;
5116
5131
  let release;
5117
- const next = new Promise((resolve) => {
5132
+ const nextPromise = new Promise((resolve) => {
5118
5133
  release = resolve;
5119
5134
  });
5120
- const previous = this.tail;
5121
- this.tail = previous.then(() => next, () => next);
5122
- await previous;
5135
+ // Chain the new promise to the queue
5136
+ this.queue = this.queue.then(() => nextPromise, () => nextPromise);
5137
+ // Wait for the previous task to complete
5138
+ // logger.debug('waiting_for_lock');
5139
+ await currentQueue;
5140
+ // logger.debug('lock_acquired');
5123
5141
  try {
5124
- return await operation();
5142
+ return await task();
5125
5143
  }
5126
5144
  finally {
5127
5145
  release();
5146
+ // logger.debug('lock_released');
5128
5147
  }
5129
5148
  }
5149
+ async runExclusive(task) {
5150
+ return this.acquire(task);
5151
+ }
5130
5152
  }
5131
5153
  async function withLock(lock, operation) {
5132
- return await lock.runExclusive(operation);
5154
+ return await lock.acquire(operation);
5133
5155
  }
5134
5156
 
5135
5157
  const logger$1b = getLogger('naylence.fame.storage.sqlite_storage_provider');
@@ -5516,12 +5538,12 @@ for (const [name, config] of Object.entries(SQLITE_PROFILES)) {
5516
5538
  }
5517
5539
 
5518
5540
  // This file is auto-generated during build - do not edit manually
5519
- // Generated from package.json version: 0.3.5-test.956
5541
+ // Generated from package.json version: 0.3.5-test.958
5520
5542
  /**
5521
5543
  * The package version, injected at build time.
5522
5544
  * @internal
5523
5545
  */
5524
- const VERSION = '0.3.5-test.956';
5546
+ const VERSION = '0.3.5-test.958';
5525
5547
 
5526
5548
  /**
5527
5549
  * Fame errors module - Fame protocol specific error classes
@@ -12704,8 +12726,15 @@ class UpstreamSessionManager extends TaskSpawner {
12704
12726
  if (!envelope) {
12705
12727
  continue;
12706
12728
  }
12729
+ logger$$.debug('upstream_pump_sending_envelope', {
12730
+ envelopeId: envelope.id,
12731
+ type: envelope.frame?.type,
12732
+ });
12707
12733
  try {
12708
12734
  await connector.send(envelope);
12735
+ logger$$.debug('upstream_pump_sent_envelope', {
12736
+ envelopeId: envelope.id,
12737
+ });
12709
12738
  }
12710
12739
  catch (error) {
12711
12740
  if (error instanceof FameMessageTooLarge) {
@@ -1276,8 +1276,15 @@ class FlowController {
1276
1276
  // Create a notifier promise
1277
1277
  const notifierPromise = (async () => {
1278
1278
  try {
1279
- // Use setImmediate to defer to next tick (similar to asyncio scheduling)
1280
- await new Promise((resolve) => setImmediate(resolve));
1279
+ // Use setImmediate/setTimeout to defer to next tick (similar to asyncio scheduling)
1280
+ await new Promise((resolve) => {
1281
+ if (typeof setImmediate === 'function') {
1282
+ setImmediate(resolve);
1283
+ }
1284
+ else {
1285
+ setTimeout(resolve, 0);
1286
+ }
1287
+ });
1281
1288
  condition.notifyAll();
1282
1289
  }
1283
1290
  finally {
@@ -1336,22 +1343,24 @@ class FlowController {
1336
1343
  current_balance: this.credits.get(flowId),
1337
1344
  });
1338
1345
  while (this.credits.get(flowId) <= 0) {
1339
- logger$1g.debug('flow_controller_waiting_for_credit', {
1346
+ logger$1g.debug('flow_controller_waiting_for_credits', {
1340
1347
  flow_id: flowId,
1348
+ current_balance: this.credits.get(flowId),
1341
1349
  });
1342
1350
  await condition.wait();
1343
- logger$1g.debug('flow_controller_woke_with_credit', {
1344
- flow_id: flowId,
1345
- balance_after_wake: this.credits.get(flowId),
1346
- });
1347
1351
  }
1348
- const current = this.credits.get(flowId);
1349
- this.credits.set(flowId, current - 1);
1350
- logger$1g.debug('flow_controller_credit_consumed', {
1352
+ const newBalance = this.credits.get(flowId) - 1;
1353
+ this.credits.set(flowId, newBalance);
1354
+ logger$1g.debug('flow_controller_acquire_success', {
1351
1355
  flow_id: flowId,
1352
- prev_balance: current,
1353
- remaining_balance: current - 1,
1356
+ new_balance: newBalance,
1354
1357
  });
1358
+ if (newBalance <= this.lowWatermark) {
1359
+ logger$1g.debug('flow_controller_acquire_below_low_watermark', {
1360
+ flow_id: flowId,
1361
+ low_watermark: this.lowWatermark,
1362
+ });
1363
+ }
1355
1364
  }
1356
1365
  /**
1357
1366
  * Consume *credits* immediately (non-blocking).
@@ -2779,6 +2788,9 @@ class WebSocketConnector extends BaseAsyncConnector {
2779
2788
  // Browser WebSocket or Node.js ws client
2780
2789
  this._websocket.send(data);
2781
2790
  }
2791
+ logger$1e.debug('websocket_sent_bytes', {
2792
+ byte_length: data.length,
2793
+ });
2782
2794
  }
2783
2795
  catch (error) {
2784
2796
  // Handle WebSocket disconnection errors
@@ -5107,28 +5119,38 @@ class EncryptedStorageProviderBase {
5107
5119
  }
5108
5120
  }
5109
5121
 
5122
+ // import { getLogger } from './logging.js';
5123
+ // const logger = getLogger('naylence.fame.util.lock');
5110
5124
  class AsyncLock {
5111
5125
  constructor() {
5112
- this.tail = Promise.resolve();
5126
+ this.queue = Promise.resolve();
5113
5127
  }
5114
- async runExclusive(operation) {
5128
+ async acquire(task) {
5129
+ const currentQueue = this.queue;
5115
5130
  let release;
5116
- const next = new Promise((resolve) => {
5131
+ const nextPromise = new Promise((resolve) => {
5117
5132
  release = resolve;
5118
5133
  });
5119
- const previous = this.tail;
5120
- this.tail = previous.then(() => next, () => next);
5121
- await previous;
5134
+ // Chain the new promise to the queue
5135
+ this.queue = this.queue.then(() => nextPromise, () => nextPromise);
5136
+ // Wait for the previous task to complete
5137
+ // logger.debug('waiting_for_lock');
5138
+ await currentQueue;
5139
+ // logger.debug('lock_acquired');
5122
5140
  try {
5123
- return await operation();
5141
+ return await task();
5124
5142
  }
5125
5143
  finally {
5126
5144
  release();
5145
+ // logger.debug('lock_released');
5127
5146
  }
5128
5147
  }
5148
+ async runExclusive(task) {
5149
+ return this.acquire(task);
5150
+ }
5129
5151
  }
5130
5152
  async function withLock(lock, operation) {
5131
- return await lock.runExclusive(operation);
5153
+ return await lock.acquire(operation);
5132
5154
  }
5133
5155
 
5134
5156
  const logger$1b = getLogger('naylence.fame.storage.sqlite_storage_provider');
@@ -5515,12 +5537,12 @@ for (const [name, config] of Object.entries(SQLITE_PROFILES)) {
5515
5537
  }
5516
5538
 
5517
5539
  // This file is auto-generated during build - do not edit manually
5518
- // Generated from package.json version: 0.3.5-test.956
5540
+ // Generated from package.json version: 0.3.5-test.958
5519
5541
  /**
5520
5542
  * The package version, injected at build time.
5521
5543
  * @internal
5522
5544
  */
5523
- const VERSION = '0.3.5-test.956';
5545
+ const VERSION = '0.3.5-test.958';
5524
5546
 
5525
5547
  /**
5526
5548
  * Fame errors module - Fame protocol specific error classes
@@ -12703,8 +12725,15 @@ class UpstreamSessionManager extends TaskSpawner {
12703
12725
  if (!envelope) {
12704
12726
  continue;
12705
12727
  }
12728
+ logger$$.debug('upstream_pump_sending_envelope', {
12729
+ envelopeId: envelope.id,
12730
+ type: envelope.frame?.type,
12731
+ });
12706
12732
  try {
12707
12733
  await connector.send(envelope);
12734
+ logger$$.debug('upstream_pump_sent_envelope', {
12735
+ envelopeId: envelope.id,
12736
+ });
12708
12737
  }
12709
12738
  catch (error) {
12710
12739
  if (error instanceof FameMessageTooLarge) {
@@ -1,5 +1,6 @@
1
1
  export declare class AsyncLock {
2
- private tail;
3
- runExclusive<T>(operation: () => Promise<T> | T): Promise<T>;
2
+ private queue;
3
+ acquire<T>(task: () => Promise<T> | T): Promise<T>;
4
+ runExclusive<T>(task: () => Promise<T> | T): Promise<T>;
4
5
  }
5
6
  export declare function withLock<T>(lock: AsyncLock, operation: () => Promise<T> | T): Promise<T>;
@@ -2,4 +2,4 @@
2
2
  * The package version, injected at build time.
3
3
  * @internal
4
4
  */
5
- export declare const VERSION = "0.3.5-test.956";
5
+ export declare const VERSION = "0.3.5-test.958";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@naylence/runtime",
3
- "version": "0.3.5-test.956",
3
+ "version": "0.3.5-test.958",
4
4
  "type": "module",
5
5
  "description": "Naylence Runtime - Complete TypeScript runtime",
6
6
  "author": "Naylence Dev <naylencedev@gmail.com>",