From a5442e36306703cd98cc3ab87c8d0c3d157e6b48 Mon Sep 17 00:00:00 2001 From: Rob Rudin Date: Tue, 25 Nov 2025 17:56:57 -0500 Subject: [PATCH] MLE-25617 Two more client-level TS methods --- marklogic.d.ts | 23 ++++++++++ .../dbclient-convenience-runtime.test.ts | 43 ++++++++++++++++++ ...ent-setLogger-setAuthToken-compile.test.ts | 44 +++++++++++++++++++ 3 files changed, 110 insertions(+) create mode 100644 test-typescript/dbclient-setLogger-setAuthToken-compile.test.ts diff --git a/marklogic.d.ts b/marklogic.d.ts index 0c606ef9..7b65dcb1 100644 --- a/marklogic.d.ts +++ b/marklogic.d.ts @@ -521,6 +521,29 @@ declare module 'marklogic' { */ invoke(path: string, variables?: Record, txid?: string | object): ResultProvider; + /** + * Configures logging for database interactions with a logger object. + * @since 1.0 + * @param logger - A logger object with debug(), info(), warn(), and error() methods (e.g., Bunyan or Winston) + * @param isErrorFirst - Whether to log errors as the first parameter (true for Bunyan, false for Winston). Defaults to false. + */ + setLogger(logger: any, isErrorFirst?: boolean): void; + /** + * Sets the logging level for an existing ConsoleLogger. + * @since 1.0 + * @param level - The logging level to set + */ + setLogger(level: 'debug' | 'info' | 'warn' | 'error' | 'silent'): void; + + /** + * Updates the SAML authentication token for subsequent requests. + * Only supported for clients created with authType: 'saml'. + * @since 2.2.0 + * @param token - The new SAML authentication token + * @throws Error if the client is not using SAML authentication + */ + setAuthToken(token: string): void; + /** * Releases the client and destroys the agent. * Call this method when you're done with the client to free up resources. diff --git a/test-typescript/dbclient-convenience-runtime.test.ts b/test-typescript/dbclient-convenience-runtime.test.ts index 3aff4d06..2e5fdf5c 100644 --- a/test-typescript/dbclient-convenience-runtime.test.ts +++ b/test-typescript/dbclient-convenience-runtime.test.ts @@ -158,4 +158,47 @@ describe('DatabaseClient convenience methods runtime validation', function() { results[0].should.have.property('value'); results[0].value.should.be.a.String(); }); + + + + it('should use setLogger with a level string', async function() { + // Set logger to 'info' level + client.setLogger('info'); + + // Write a test document + await client.documents.write({ + uri: '/test-typescript/setlogger-test.json', + content: { test: 'setLogger' } + }).result(); + + // Verify client is still functional after setting logger + const exists = await client.probe('/test-typescript/setlogger-test.json').result(); + exists.should.be.a.Boolean(); + exists.should.equal(true); + }); + + it('should use setLogger with a logger object', async function() { + // Create a simple logger object + const testLogger = { + debug: (msg: string) => console.log('DEBUG:', msg), + info: (msg: string) => console.log('INFO:', msg), + warn: (msg: string) => console.log('WARN:', msg), + error: (msg: string) => console.log('ERROR:', msg) + }; + + // Set logger with object + client.setLogger(testLogger, false); + + // Write a test document + await client.documents.write({ + uri: '/test-typescript/setlogger-test2.json', + content: { test: 'setLogger with object' } + }).result(); + + // Verify client is still functional after setting logger + const exists = await client.probe('/test-typescript/setlogger-test2.json').result(); + exists.should.be.a.Boolean(); + exists.should.equal(true); + }); + }); diff --git a/test-typescript/dbclient-setLogger-setAuthToken-compile.test.ts b/test-typescript/dbclient-setLogger-setAuthToken-compile.test.ts new file mode 100644 index 00000000..2dda4f59 --- /dev/null +++ b/test-typescript/dbclient-setLogger-setAuthToken-compile.test.ts @@ -0,0 +1,44 @@ +/* +* Copyright (c) 2015-2025 Progress Software Corporation and/or its subsidiaries or affiliates. All Rights Reserved. +*/ + +/** + * Compile-time type checking tests for setLogger and setAuthToken. + * These tests verify TypeScript type definitions but don't execute. + */ + +/// + +import type { DatabaseClient } from 'marklogic'; + +const marklogic = require('../lib/marklogic.js'); + +const db: DatabaseClient = marklogic.createDatabaseClient({ + host: 'localhost', + port: 8000, + user: 'admin', + password: 'admin' +}); + +// Test setLogger with logger object +const bunyanLogger = { + debug: (msg: string) => console.log(msg), + info: (msg: string) => console.log(msg), + warn: (msg: string) => console.log(msg), + error: (msg: string) => console.log(msg) +}; +db.setLogger(bunyanLogger); +db.setLogger(bunyanLogger, true); // error-first (Bunyan style) +db.setLogger(bunyanLogger, false); // error-last (Winston style) + +// Test setLogger with level string +db.setLogger('debug'); +db.setLogger('info'); +db.setLogger('warn'); +db.setLogger('error'); +db.setLogger('silent'); + +// Test setAuthToken +db.setAuthToken('new-saml-token-string'); + +console.log('Compile-time tests pass for setLogger and setAuthToken');