@lolyjs/core 0.2.0-alpha.24 → 0.2.0-alpha.26

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/cli.js CHANGED
@@ -13642,7 +13642,7 @@ var DEFAULT_REALTIME_CONFIG = {
13642
13642
  burst: 60
13643
13643
  },
13644
13644
  logging: {
13645
- level: "info",
13645
+ level: process.env.NODE_ENV === "production" ? "warn" : "info",
13646
13646
  pretty: process.env.NODE_ENV !== "production"
13647
13647
  }
13648
13648
  };
@@ -17078,7 +17078,6 @@ async function executeGuard(guardFn, ctx) {
17078
17078
  const guardCtx = {
17079
17079
  user: ctx.user,
17080
17080
  req: ctx.req,
17081
- socket: ctx.socket,
17082
17081
  namespace: ctx.pathname
17083
17082
  };
17084
17083
  const result = await guardFn(guardCtx);
@@ -17113,13 +17112,24 @@ function validateSchema(schema, data) {
17113
17112
  }
17114
17113
 
17115
17114
  // modules/realtime/logging/index.ts
17116
- function createWssLogger(namespace, socket, baseLogger) {
17115
+ var LOG_LEVELS = {
17116
+ debug: 0,
17117
+ info: 1,
17118
+ warn: 2,
17119
+ error: 3
17120
+ };
17121
+ function createWssLogger(namespace, socket, baseLogger, minLevel = "info") {
17117
17122
  const context = {
17118
17123
  namespace,
17119
17124
  socketId: socket.id,
17120
17125
  userId: socket.data?.user?.id || null
17121
17126
  };
17127
+ const minLevelNum = LOG_LEVELS[minLevel] ?? LOG_LEVELS.info;
17122
17128
  const log = (level, message, meta) => {
17129
+ const levelNum = LOG_LEVELS[level] ?? LOG_LEVELS.info;
17130
+ if (levelNum < minLevelNum) {
17131
+ return;
17132
+ }
17123
17133
  const fullMeta = {
17124
17134
  ...context,
17125
17135
  ...meta,
@@ -17185,9 +17195,6 @@ var generateActions = (socket, namespace, presence) => {
17185
17195
  return {
17186
17196
  emit: async (event, payload) => {
17187
17197
  if (!presence) {
17188
- console.warn(
17189
- "[loly:realtime] toUser() requires presence manager. Make sure realtime is properly configured."
17190
- );
17191
17198
  return;
17192
17199
  }
17193
17200
  const socketIds = await presence.getSocketsForUser(userId);
@@ -17290,19 +17297,12 @@ async function setupWssEvents(options) {
17290
17297
  const subClient = pubClient.duplicate();
17291
17298
  io.adapter(createAdapter(pubClient, subClient));
17292
17299
  } catch (error) {
17293
- console.error(
17294
- "[loly:realtime] Failed to setup Redis adapter:",
17295
- error instanceof Error ? error.message : String(error)
17296
- );
17297
17300
  throw error;
17298
17301
  }
17299
17302
  }
17300
17303
  for (const wssRoute of wssRoutes) {
17301
17304
  const normalized = wssRoute.normalized;
17302
17305
  if (!normalized) {
17303
- console.warn(
17304
- `[loly:realtime] Skipping route ${wssRoute.pattern}: No normalized route definition`
17305
- );
17306
17306
  continue;
17307
17307
  }
17308
17308
  let namespacePath = normalized.namespace || wssRoute.pattern.replace(/^\/wss/, "");
@@ -17313,12 +17313,11 @@ async function setupWssEvents(options) {
17313
17313
  namespacePath = "/";
17314
17314
  }
17315
17315
  const namespace = io.of(namespacePath);
17316
- console.log(`[loly:realtime] Registered namespace: ${namespacePath} (from pattern: ${wssRoute.pattern})`);
17317
17316
  namespace.on("connection", async (socket) => {
17318
- console.log(`[loly:realtime] Client connected to namespace ${namespacePath}, socket: ${socket.id}`);
17319
17317
  const requestId = generateRequestId();
17320
17318
  socket.requestId = requestId;
17321
- const log = createWssLogger(namespacePath, socket);
17319
+ const logLevel = realtimeConfig.logging?.level || (process.env.NODE_ENV === "production" ? "warn" : "info");
17320
+ const log = createWssLogger(namespacePath, socket, void 0, logLevel);
17322
17321
  try {
17323
17322
  const user = await executeAuth(normalized.auth, socket, namespacePath);
17324
17323
  socket.data = socket.data || {};
@@ -17327,8 +17326,6 @@ async function setupWssEvents(options) {
17327
17326
  await presence.addSocketForUser(String(user.id), socket.id);
17328
17327
  }
17329
17328
  const baseCtx = {
17330
- socket,
17331
- io: namespace.server,
17332
17329
  req: {
17333
17330
  headers: socket.handshake.headers,
17334
17331
  ip: socket.handshake.address,
@@ -17355,7 +17352,8 @@ async function setupWssEvents(options) {
17355
17352
  socket.on(eventName, async (data) => {
17356
17353
  const eventRequestId = generateRequestId();
17357
17354
  socket.requestId = eventRequestId;
17358
- const eventLog = createWssLogger(namespacePath, socket);
17355
+ const eventLogLevel = realtimeConfig.logging?.level || (process.env.NODE_ENV === "production" ? "warn" : "info");
17356
+ const eventLog = createWssLogger(namespacePath, socket, void 0, eventLogLevel);
17359
17357
  eventLog.debug(`Event received: ${eventName}`, { data });
17360
17358
  try {
17361
17359
  const ctx = {
@@ -17413,7 +17411,8 @@ async function setupWssEvents(options) {
17413
17411
  await eventDef.handler(ctx);
17414
17412
  eventLog.debug(`Event handled: ${eventName}`);
17415
17413
  } catch (error) {
17416
- const errorLog = createWssLogger(namespacePath, socket);
17414
+ const errorLogLevel = realtimeConfig.logging?.level || (process.env.NODE_ENV === "production" ? "warn" : "info");
17415
+ const errorLog = createWssLogger(namespacePath, socket, void 0, errorLogLevel);
17417
17416
  errorLog.error(`Error handling event ${eventName}`, {
17418
17417
  error: error instanceof Error ? error.message : String(error),
17419
17418
  stack: error instanceof Error ? error.stack : void 0
@@ -17433,9 +17432,10 @@ async function setupWssEvents(options) {
17433
17432
  }
17434
17433
  if (normalized.onDisconnect) {
17435
17434
  try {
17435
+ const disconnectLogLevel = realtimeConfig.logging?.level || (process.env.NODE_ENV === "production" ? "warn" : "info");
17436
17436
  const disconnectCtx = {
17437
17437
  ...baseCtx,
17438
- log: createWssLogger(namespacePath, socket)
17438
+ log: createWssLogger(namespacePath, socket, void 0, disconnectLogLevel)
17439
17439
  };
17440
17440
  await normalized.onDisconnect(disconnectCtx, reason);
17441
17441
  } catch (error) {