Skip to content

Commit bec0606

Browse files
committed
Wrapped Client in a namespace cdplogger.Client
1 parent 1b3465a commit bec0606

5 files changed

Lines changed: 22 additions & 20 deletions

File tree

client.js

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ const WebSocket = require('ws');
22
const root = require('./generated/containerPb.js');
33
const Container = root.DBMessaging.Protobuf.Container;
44
const CDPValueType = root.ICD.Protobuf.CDPValueType;
5+
const EventQuery = root.DBMessaging.Protobuf.EventQuery;
6+
57

68
/**
79
* A client for interacting with a CDP Logger or LogServer via WebSocket.
@@ -14,7 +16,7 @@ const CDPValueType = root.ICD.Protobuf.CDPValueType;
1416
class Client {
1517
// Defined property names to use instead of ambiguous numbers.
1618
static EventQueryFlags = Object.freeze({
17-
None: 0, // Client.EventQueryFlags.None === 0
19+
None: 0, // cdplogger.Client.EventQueryFlags.None === 0
1820
NewestFirst: 1,
1921
TimeRangeBeginExclusive: 2,
2022
TimeRangeEndExclusive: 4,
@@ -288,11 +290,11 @@ class Client {
288290
* dataConditions: {
289291
* Text: ["Invalid or missing feature license detected."],
290292
* // Multiple data conditions can be specified:
291-
* Level: { value: "ERROR", matchType: Client.MatchType.Exact }
293+
* Level: { value: "ERROR", matchType: cdplogger.Client.MatchType.Exact }
292294
* },
293295
* limit: 100,
294296
* offset: 0,
295-
* flags: Client.EventQueryFlags.NewestFirst
297+
* flags: cdplogger.Client.EventQueryFlags.NewestFirst
296298
* });
297299
*
298300
* @param {Object} query - A simple plain object representing the EventQuery.
@@ -1016,9 +1018,6 @@ class Client {
10161018
// Validate the query object before building the EventQuery.
10171019
this._validateEventQuery(query);
10181020

1019-
const root = require('./generated/containerPb.js');
1020-
const { EventQuery } = root.DBMessaging.Protobuf;
1021-
10221021
// Conditionally include these fields only if the user has set them
10231022
const optionalFields = [
10241023
"timeRangeBegin",
@@ -1119,4 +1118,7 @@ class Client {
11191118
}
11201119
}
11211120

1122-
module.exports = Client;
1121+
const cdplogger = {};
1122+
cdplogger.Client = Client;
1123+
1124+
module.exports = cdplogger;

examples/event.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
// event.js
22
// An example script to see filtered events
33

4-
const Client = require('../client');
4+
const cdplogger = require('../client');
55

66
async function main() {
7-
const client = new Client('ws://127.0.0.1:17000', false);
7+
const client = new cdplogger.Client('ws://127.0.0.1:17000', false);
88

99
try {
1010
console.log("Waiting for connection to establish...");
@@ -16,15 +16,15 @@ async function main() {
1616
senderConditions: [
1717
{
1818
value: "CDPLoggerDemoApp.InvalidLicense",
19-
matchType: Client.MatchType.Exact
19+
matchType: cdplogger.Client.MatchType.Exact
2020
}
2121
],
2222
dataConditions: {
2323
"Text": {
2424
value: "*", // Wildcard condition for Text field
2525
}
2626
},
27-
flags: Client.EventQueryFlags.NewestFirst | Client.EventQueryFlags.UseLogStampForTimeRange,
27+
flags: cdplogger.Client.EventQueryFlags.NewestFirst | cdplogger.Client.EventQueryFlags.UseLogStampForTimeRange,
2828
limit: 10, // Request a maximum of 10 events
2929
offset: 0 // Starting at the beginning
3030
};

examples/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// Example demonstration including an events query for a specific time range (UTC 9:40)
33

44
global.WebSocket = require('ws');
5-
const Client = require('../client');
5+
const cdplogger = require('../client');
66

77
// Print the node information (name, routing, and tags)
88
function printLoggedNodes() {
@@ -64,7 +64,7 @@ async function main() {
6464
}
6565

6666
// Create a new client instance. (In this example, autoReconnect is disabled.)
67-
const client = new Client('ws://127.0.0.1:17000', false);
67+
const client = new cdplogger.Client('ws://127.0.0.1:17000', false);
6868

6969
// Instead of overriding ws.onopen (which may cancel internal logic),
7070
// add an event listener so that _onOpen is still called.

test/client.test.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
11
/*global WebSocket*/
22
global.WebSocket = require('ws');
3-
const Client = require('../client');
3+
const cdplogger = require('../client');
44
const fakeData = require('./fakeData');
55

66
describe('ClientTester', () => {
77
let client;
88
beforeEach(() => {
99
// Override _connect to return a fake ws object that doesn't actually connect.
10-
Client.prototype._connect = function(url) {
10+
cdplogger.Client.prototype._connect = function(url) {
1111
return {
1212
_url: url,
1313
close: jest.fn(),
1414
send: jest.fn()
1515
};
1616
};
1717
// Create a new client instance.
18-
client = new Client('127.0.0.1:17000', true);
18+
client = new cdplogger.Client('127.0.0.1:17000', true);
1919
// By default, disable time sync for most tests.
2020
client.setEnableTimeSync(false);
2121
// Adjust lastTimeRequest so that a new time request would normally be triggered.

test/testTimeSync.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// testTimeSync.js
2-
const Client = require('../client');
2+
const cdplogger = require('../client');
33
const fakeData = require('./fakeData');
44

55
// Override WebSocket with a dummy that provides a send() method.
@@ -15,8 +15,8 @@ global.WebSocket = class {
1515
// --- Capture Request IDs for time sync vs. API calls ---
1616
let capturedTimeSyncRequestId = null;
1717
let capturedApiRequestId = null;
18-
const originalGetRequestId = Client.prototype._getRequestId;
19-
Client.prototype._getRequestId = function() {
18+
const originalGetRequestId = cdplogger.Client.prototype._getRequestId;
19+
cdplogger.Client.prototype._getRequestId = function() {
2020
const id = originalGetRequestId.call(this);
2121
if (capturedTimeSyncRequestId === null) {
2222
capturedTimeSyncRequestId = id;
@@ -77,7 +77,7 @@ async function runThrough(methodName, callFunc, simulateResponse) {
7777

7878
async function runTest() {
7979
// Create a new client instance.
80-
client = new Client('127.0.0.1:17000', true);
80+
client = new cdplogger.Client('127.0.0.1:17000', true);
8181

8282
// Override _sendTimeRequest to simulate a server time response with variable delay.
8383
client._sendTimeRequest = function (requestId) {

0 commit comments

Comments
 (0)