Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions marklogic.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -521,6 +521,29 @@ declare module 'marklogic' {
*/
invoke(path: string, variables?: Record<string, any>, txid?: string | object): ResultProvider<EvalResult[]>;

/**
* 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.
Expand Down
43 changes: 43 additions & 0 deletions test-typescript/dbclient-convenience-runtime.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -158,4 +158,47 @@ describe('DatabaseClient convenience methods runtime validation', function() {
results[0].should.have.property('value');
results[0].value.should.be.a.String();
});



Copy link

Copilot AI Nov 25, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] Remove excessive blank lines. There should be at most one blank line between test cases for consistency with the rest of the file.

Suggested change

Copilot uses AI. Check for mistakes.
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);
});

});
44 changes: 44 additions & 0 deletions test-typescript/dbclient-setLogger-setAuthToken-compile.test.ts
Original file line number Diff line number Diff line change
@@ -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.
*/

/// <reference path="../marklogic.d.ts" />

import type { DatabaseClient } from 'marklogic';

const marklogic = require('../lib/marklogic.js');
Copy link

Copilot AI Nov 25, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mixing import type with require is inconsistent. Consider using import for the module on line 10 instead of require, or remove the type-only import and use type assertions instead. This ensures consistency in import style throughout the file.

Suggested change
const marklogic = require('../lib/marklogic.js');
import * as marklogic from '../lib/marklogic.js';

Copilot uses AI. Check for mistakes.

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');
Loading