Skip to content

Commit f9dfe16

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

File tree

3 files changed

+89
-0
lines changed

3 files changed

+89
-0
lines changed

marklogic.d.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -521,6 +521,24 @@ 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.
526+
* Can accept either a logger object (e.g., Bunyan or Winston) or a logging level string.
527+
* @since 1.0
528+
* @param logger - A logger object with debug(), info(), warn(), and error() methods, or a logging level string
529+
* @param isErrorFirst - Whether to log errors as the first parameter (true for Bunyan, false for Winston). Defaults to false. Only used when logger is an object.
530+
*/
531+
setLogger(logger: any | 'debug' | 'info' | 'warn' | 'error' | 'silent', isErrorFirst?: boolean): void;
532+
533+
/**
534+
* Updates the SAML authentication token for subsequent requests.
535+
* Only supported for clients created with authType: 'saml'.
536+
* @since 2.2.0
537+
* @param token - The new SAML authentication token
538+
* @throws Error if the client is not using SAML authentication
539+
*/
540+
setAuthToken(token: string): void;
541+
524542
/**
525543
* Releases the client and destroys the agent.
526544
* Call this method when you're done with the client to free up resources.

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

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,4 +158,35 @@ 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+
// Verify client is still functional after setting logger
169+
const result = await client.probe(testUri).result();
170+
result.should.have.property('exists');
171+
result.should.have.property('uri');
172+
});
173+
174+
it('should use setLogger with a logger object', async function() {
175+
// Create a simple logger object
176+
const testLogger = {
177+
debug: (msg: string) => console.log('DEBUG:', msg),
178+
info: (msg: string) => console.log('INFO:', msg),
179+
warn: (msg: string) => console.log('WARN:', msg),
180+
error: (msg: string) => console.log('ERROR:', msg)
181+
};
182+
183+
// Set logger with object
184+
client.setLogger(testLogger, false);
185+
186+
// Verify client is still functional after setting logger
187+
const result = await client.probe(testUri).result();
188+
result.should.have.property('exists');
189+
result.should.have.property('uri');
190+
});
191+
161192
});
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
/**
2+
* Compile-time type checking tests for setLogger and setAuthToken.
3+
* These tests verify TypeScript type definitions but don't execute.
4+
*/
5+
6+
/// <reference path="../marklogic.d.ts" />
7+
8+
import type { DatabaseClient } from 'marklogic';
9+
10+
const marklogic = require('../lib/marklogic.js');
11+
12+
const db: DatabaseClient = marklogic.createDatabaseClient({
13+
host: 'localhost',
14+
port: 8000,
15+
user: 'admin',
16+
password: 'admin'
17+
});
18+
19+
// Test setLogger with logger object
20+
const bunyanLogger = {
21+
debug: (msg: string) => console.log(msg),
22+
info: (msg: string) => console.log(msg),
23+
warn: (msg: string) => console.log(msg),
24+
error: (msg: string) => console.log(msg)
25+
};
26+
db.setLogger(bunyanLogger);
27+
db.setLogger(bunyanLogger, true); // error-first (Bunyan style)
28+
db.setLogger(bunyanLogger, false); // error-last (Winston style)
29+
30+
// Test setLogger with level string
31+
db.setLogger('debug');
32+
db.setLogger('info');
33+
db.setLogger('warn');
34+
db.setLogger('error');
35+
db.setLogger('silent');
36+
37+
// Test setAuthToken
38+
db.setAuthToken('new-saml-token-string');
39+
40+
console.log('Compile-time tests pass for setLogger and setAuthToken');

0 commit comments

Comments
 (0)