Skip to content

Commit a5442e3

Browse files
committed
MLE-25617 Two more client-level TS methods
1 parent 9ecf413 commit a5442e3

File tree

3 files changed

+110
-0
lines changed

3 files changed

+110
-0
lines changed

marklogic.d.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -521,6 +521,29 @@ declare module 'marklogic' {
521521
*/
522522
invoke(path: string, variables?: Record<string, any>, txid?: string | object): ResultProvider<EvalResult[]>;
523523

524+
/**
525+
* Configures logging for database interactions with a logger object.
526+
* @since 1.0
527+
* @param logger - A logger object with debug(), info(), warn(), and error() methods (e.g., Bunyan or Winston)
528+
* @param isErrorFirst - Whether to log errors as the first parameter (true for Bunyan, false for Winston). Defaults to false.
529+
*/
530+
setLogger(logger: any, isErrorFirst?: boolean): void;
531+
/**
532+
* Sets the logging level for an existing ConsoleLogger.
533+
* @since 1.0
534+
* @param level - The logging level to set
535+
*/
536+
setLogger(level: 'debug' | 'info' | 'warn' | 'error' | 'silent'): void;
537+
538+
/**
539+
* Updates the SAML authentication token for subsequent requests.
540+
* Only supported for clients created with authType: 'saml'.
541+
* @since 2.2.0
542+
* @param token - The new SAML authentication token
543+
* @throws Error if the client is not using SAML authentication
544+
*/
545+
setAuthToken(token: string): void;
546+
524547
/**
525548
* Releases the client and destroys the agent.
526549
* Call this method when you're done with the client to free up resources.

test-typescript/dbclient-convenience-runtime.test.ts

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,4 +158,47 @@ describe('DatabaseClient convenience methods runtime validation', function() {
158158
results[0].should.have.property('value');
159159
results[0].value.should.be.a.String();
160160
});
161+
162+
163+
164+
it('should use setLogger with a level string', async function() {
165+
// Set logger to 'info' level
166+
client.setLogger('info');
167+
168+
// Write a test document
169+
await client.documents.write({
170+
uri: '/test-typescript/setlogger-test.json',
171+
content: { test: 'setLogger' }
172+
}).result();
173+
174+
// Verify client is still functional after setting logger
175+
const exists = await client.probe('/test-typescript/setlogger-test.json').result();
176+
exists.should.be.a.Boolean();
177+
exists.should.equal(true);
178+
});
179+
180+
it('should use setLogger with a logger object', async function() {
181+
// Create a simple logger object
182+
const testLogger = {
183+
debug: (msg: string) => console.log('DEBUG:', msg),
184+
info: (msg: string) => console.log('INFO:', msg),
185+
warn: (msg: string) => console.log('WARN:', msg),
186+
error: (msg: string) => console.log('ERROR:', msg)
187+
};
188+
189+
// Set logger with object
190+
client.setLogger(testLogger, false);
191+
192+
// Write a test document
193+
await client.documents.write({
194+
uri: '/test-typescript/setlogger-test2.json',
195+
content: { test: 'setLogger with object' }
196+
}).result();
197+
198+
// Verify client is still functional after setting logger
199+
const exists = await client.probe('/test-typescript/setlogger-test2.json').result();
200+
exists.should.be.a.Boolean();
201+
exists.should.equal(true);
202+
});
203+
161204
});
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/*
2+
* Copyright (c) 2015-2025 Progress Software Corporation and/or its subsidiaries or affiliates. All Rights Reserved.
3+
*/
4+
5+
/**
6+
* Compile-time type checking tests for setLogger and setAuthToken.
7+
* These tests verify TypeScript type definitions but don't execute.
8+
*/
9+
10+
/// <reference path="../marklogic.d.ts" />
11+
12+
import type { DatabaseClient } from 'marklogic';
13+
14+
const marklogic = require('../lib/marklogic.js');
15+
16+
const db: DatabaseClient = marklogic.createDatabaseClient({
17+
host: 'localhost',
18+
port: 8000,
19+
user: 'admin',
20+
password: 'admin'
21+
});
22+
23+
// Test setLogger with logger object
24+
const bunyanLogger = {
25+
debug: (msg: string) => console.log(msg),
26+
info: (msg: string) => console.log(msg),
27+
warn: (msg: string) => console.log(msg),
28+
error: (msg: string) => console.log(msg)
29+
};
30+
db.setLogger(bunyanLogger);
31+
db.setLogger(bunyanLogger, true); // error-first (Bunyan style)
32+
db.setLogger(bunyanLogger, false); // error-last (Winston style)
33+
34+
// Test setLogger with level string
35+
db.setLogger('debug');
36+
db.setLogger('info');
37+
db.setLogger('warn');
38+
db.setLogger('error');
39+
db.setLogger('silent');
40+
41+
// Test setAuthToken
42+
db.setAuthToken('new-saml-token-string');
43+
44+
console.log('Compile-time tests pass for setLogger and setAuthToken');

0 commit comments

Comments
 (0)