-
Notifications
You must be signed in to change notification settings - Fork 52
Expand file tree
/
Copy pathmarklogic.d.ts
More file actions
590 lines (541 loc) · 21.3 KB
/
marklogic.d.ts
File metadata and controls
590 lines (541 loc) · 21.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
/*
* Copyright (c) 2015-2026 Progress Software Corporation and/or its subsidiaries or affiliates. All Rights Reserved.
*/
// Type definitions for marklogic
// Project: https://github.com/marklogic/node-client-api
// Documentation: https://docs.marklogic.com/guide/node-dev
/**
* MarkLogic Node.js Client API
*
* IMPORTANT: This library uses CommonJS exports. Import patterns:
*
* For TypeScript/ES Modules:
* import marklogic from 'marklogic'; // Preferred
* const db = marklogic.createDatabaseClient({...});
*
* For CommonJS:
* const marklogic = require('marklogic');
* const db = marklogic.createDatabaseClient({...});
*/
declare module 'marklogic' {
/**
* Configuration object for creating a database client.
* Used by the createDatabaseClient function to establish connection parameters.
*/
export interface DatabaseClientConfig {
/** The host with the REST server for the database (defaults to 'localhost') */
host?: string;
/** The port with the REST server for the database (defaults to 8000) */
port?: number;
/** The user with permission to access the database */
user?: string;
/** The password for the user with permission to access the database */
password?: string;
/** The name of the database to access (defaults to the database for the REST server) */
database?: string;
/** The authentication type (defaults to 'digest') */
authType?: 'basic' | 'digest' | 'application-level' | 'certificate' | 'kerberos' | 'saml' | 'cloud';
/** Whether the REST server uses SSL (defaults to false) */
ssl?: boolean;
/** The trusted certificate(s), if required for SSL */
ca?: string | string[] | Buffer | Buffer[];
/** The public x509 certificate to use for SSL */
cert?: string | Buffer;
/** The private key to use for SSL */
key?: string | Buffer;
/** The public x509 certificate and private key as a single PKCS12 file to use for SSL */
pfx?: Buffer;
/** The passphrase for the PKCS12 file or private key */
passphrase?: string;
/** Whether to reject unauthorized SSL certificates (defaults to true) */
rejectUnauthorized?: boolean;
/** The SAML token to use for authentication with the REST server */
token?: string;
/** Connection pooling agent */
agent?: any;
/** API version to use */
apiVersion?: string;
}
/**
* Result object returned by checkConnection method.
*/
export interface ConnectionCheckResult {
/** Whether the connection was successful */
connected: boolean;
/** HTTP status code if connection failed */
httpStatusCode?: number;
/** HTTP status message if connection failed */
httpStatusMessage?: string;
}
/**
* Generic document content type - can be JSON, XML, text, or binary
*/
export type DocumentContent = any;
/**
* A document descriptor for reading or writing documents.
*/
export interface DocumentDescriptor {
/** The URI identifier for the document */
uri: string;
/** The content of the document (JSON, XML, text, or Buffer for binary) */
content?: DocumentContent;
/** The MIME type of the document */
contentType?: string;
/** Collections to which the document belongs */
collections?: string | string[];
/** Permissions controlling document access */
permissions?: Array<{
'role-name': string;
capabilities: string[];
}>;
/** Properties (metadata) for the document */
properties?: Record<string, any>;
/** Quality ranking for the document */
quality?: number;
/** Metadata values for the document */
metadataValues?: Record<string, any>;
}
/**
* Result from a probe operation indicating if a document exists.
*/
export interface ProbeResult {
/** The URI of the document */
uri: string;
/** Whether the document exists */
exists: boolean;
/** Content type if document exists */
contentType?: string;
/** Content length if document exists */
contentLength?: number;
}
/**
* Result from a remove operation.
*/
export interface RemoveResult {
/** Array of removed document URIs */
uris: string[];
/** Whether documents were removed */
removed: boolean;
/** System time of the operation */
systemTime?: string;
}
/**
* A timestamp object representing a point in time on the server.
* Used for point-in-time queries and operations.
* @since 2.1.1
*/
export interface Timestamp {
/** The timestamp value as a string */
value: string | null;
}
/**
* Result value from eval, xqueryEval, or invoke operations.
* Each returned value includes format, datatype, and the actual value.
*/
export interface EvalResult {
/** Format of the value: 'json', 'xml', 'text', or 'binary' */
format: 'json' | 'xml' | 'text' | 'binary';
/** Datatype of the value (e.g., 'node()', 'string', 'boolean', 'integer') */
datatype: string;
/** The actual value (type depends on format and datatype) */
value: any;
}
/**
* Result from a removeAll operation.
*/
export interface RemoveAllResult {
/** Always false (indicates removal operation completed) */
exists: boolean;
/** Collection that was removed (if specified) */
collection?: string;
/** Directory that was removed (if specified) */
directory?: string;
/** Whether all documents were removed */
allDocuments?: boolean;
}
/**
* Result from a protect operation on a temporal document.
*/
export interface ProtectResult {
/** The URI of the protected document */
uri: string;
/** The temporal collection name */
temporalCollection: string;
/** The protection level (noWipe, noDelete, or noUpdate) */
level: string;
}
/**
* Result from a wipe operation on a temporal document.
*/
export interface WipeResult {
/** The URI of the wiped document */
uri: string;
/** The temporal collection name */
temporalCollection: string;
/** Whether the document was wiped */
wiped: boolean;
}
/**
* Result from advancing LSQT on a temporal collection.
*/
export interface AdvanceLsqtResult {
/** The new Last Stable Query Time */
lsqt: string;
}
/**
* Result from a patch operation.
*/
export interface PatchResult {
/** The URI of the patched document */
uri: string;
}
/**
* Result from a write operation.
*/
export interface WriteResult {
/** Array of document descriptors with URIs of written documents */
documents: DocumentDescriptor[];
/** System time of the operation */
systemTime?: string;
}
/**
* Documents interface for reading and writing documents.
*/
export interface Documents {
/**
* Checks whether a document exists.
* @param uri - The URI of the document to check
* @returns A result provider that resolves to probe result
*/
probe(uri: string): ResultProvider<ProbeResult>;
/**
* Reads one or more documents.
* @param uris - A URI string or array of URI strings
* @returns A result provider that resolves to an array of document descriptors
*/
read(uris: string | string[]): ResultProvider<DocumentDescriptor[]>;
/**
* Writes one or more documents.
* @param documents - A document descriptor or array of document descriptors
* @returns A result provider that resolves to a write result with document URIs
*/
write(documents: DocumentDescriptor | DocumentDescriptor[]): ResultProvider<WriteResult>;
/**
* Writes one or more documents with additional parameters.
* @param params - Configuration object with documents and optional parameters
* @returns A result provider that resolves to a write result with document URIs
*/
write(params: {
/** The document(s) to write */
documents: DocumentDescriptor | DocumentDescriptor[];
/** Categories of information to write */
categories?: string | string[];
/** Transaction id or Transaction object */
txid?: string | object;
/** Transform to apply on the server */
transform?: string | object;
/** Forest name to write to */
forestName?: string;
/** Temporal collection for temporal documents */
temporalCollection?: string;
/** System time for temporal documents (ISO 8601 string or Date object) */
systemTime?: string | Date;
}): ResultProvider<WriteResult>;
/**
* Removes one or more documents.
* @param uris - A URI string or array of URI strings
* @returns A result provider that resolves to a remove result
*/
remove(uris: string | string[]): ResultProvider<RemoveResult>;
/**
* Removes all documents in a collection, directory, or database.
* Requires rest-admin role to delete all documents, rest-writer role otherwise.
* @param params - Configuration object with collection, directory, all, or txid properties
* @returns A result provider that resolves to a remove all result
*/
removeAll(params: {
/** The collection whose documents should be deleted */
collection?: string;
/** A directory whose documents should be deleted */
directory?: string;
/** Delete all documents (requires rest-admin role) */
all?: boolean;
/** Transaction id or Transaction object */
txid?: string | object;
}): ResultProvider<RemoveAllResult>;
/**
* Protects a temporal document from certain operations.
* Must specify either duration or expireTime.
* @param params - Configuration object with either duration or expireTime
* @returns A result provider that resolves to protect result
*/
protect(params: {
/** The URI of the temporal document */
uri: string;
/** The temporal collection name */
temporalCollection: string;
/** Protection level: 'noWipe' | 'noDelete' | 'noUpdate' (default: 'noDelete') */
level?: string;
/** Archive path for the document */
archivePath?: string;
} & (
{ /** Duration as XSD duration string (e.g., 'P30D') */ duration: string; expireTime?: never; } |
{ /** Expire time (alternative to duration) */ expireTime: string; duration?: never; }
)): ResultProvider<ProtectResult>;
/**
* Deletes all versions of a temporal document.
* @param params - Configuration object with uri and temporalCollection
* @returns A result provider that resolves to wipe result
*/
wipe(params: {
/** The URI of the temporal document to wipe */
uri: string;
/** The temporal collection name */
temporalCollection: string;
}): ResultProvider<WipeResult>;
/**
* Advances the LSQT (Last Stable Query Time) of a temporal collection.
* @param params - Configuration object or temporal collection name
* @returns A result provider that resolves to the new LSQT
*/
advanceLsqt(params: string | {
/** The temporal collection name */
temporalCollection: string;
/** Lag in seconds to subtract from maximum system start time */
lag?: number;
}): ResultProvider<AdvanceLsqtResult>;
/**
* Creates a writable stream for writing large documents (typically binary) in incremental chunks.
* The document descriptor should NOT include a content property - content is written via the stream.
* @param document - Document descriptor without content property
* @returns A WritableStream with a result() method for tracking completion
*/
createWriteStream(document: {
/** The URI for the document to write to the database */
uri: string;
/** Collections to which the document should belong */
collections?: string[];
/** Permissions controlling document access */
permissions?: Array<{ roleName: string; capabilities: string[] }>;
/** Additional properties of the document */
properties?: object;
/** Weight to increase or decrease document rank */
quality?: number;
/** Metadata values of the document */
metadataValues?: object;
/** Version identifier for optimistic locking */
versionId?: number;
/** Transaction id or Transaction object */
txid?: string | object;
/** Transform extension name or [name, params] array */
transform?: string | [string, object];
/** Content type of the document */
contentType?: string;
}): NodeJS.WritableStream & ResultProvider<WriteResult>;
/**
* Applies changes to a document using patch operations.
* @param params - Configuration object with uri and operations
* @returns A result provider that resolves to patch result
*/
patch(params: {
/** The URI of the document to patch */
uri: string;
/** Patch operations (from patchBuilder) or raw patch string/Buffer */
operations: any[] | string | Buffer;
/** Categories of information to modify (typically 'content') */
categories?: string | string[];
/** Temporal collection name (for temporal documents) */
temporalCollection?: string;
/** Temporal document URI */
temporalDocument?: string;
/** Source document URI */
sourceDocument?: string;
/** Transaction id or Transaction object */
txid?: string | object;
/** Version identifier for optimistic locking */
versionId?: string;
/** Format: 'json' or 'xml' */
format?: string;
}): ResultProvider<PatchResult>;
/**
* Applies changes to a document using patch operations.
* @param uri - The URI of the document to patch
* @param operations - One or more patch operations from patchBuilder
* @returns A result provider that resolves to patch result
*/
patch(uri: string, ...operations: any[]): ResultProvider<PatchResult>;
}
/**
* A database client object returned by createDatabaseClient.
* Provides access to document, graph, and query operations.
*/
export interface DatabaseClient {
/**
* Documents interface for reading and writing documents.
* @since 1.0
*/
documents: Documents;
/**
* Tests if a connection is successful.
* Call .result() to get a promise.
* @since 2.1
* @returns A result provider with a result() method
*/
checkConnection(): ResultProvider<ConnectionCheckResult>;
/**
* Creates one or more JSON documents for a collection.
* The server assigns URI identifiers to the documents.
* This is a simplified convenience method - use documents.write() for more control.
* @since 1.0
* @param collection - The collection name for the documents
* @param content - The JSON content object(s) for the documents
* @returns A result provider that resolves to an array of assigned URIs
*/
createCollection(collection: string, ...content: any[]): ResultProvider<string[]>;
/**
* Probes whether a document exists.
* This is a simplified convenience method - use documents.probe() for more information.
* @since 1.0
* @param uri - The URI of the document to check
* @returns A result provider that resolves to a boolean
*/
probe(uri: string): ResultProvider<boolean>;
/**
* Queries documents in a collection.
* This is a simplified convenience method - use documents.query() for more control.
* @since 1.0
* @param collection - The collection name
* @param query - Optional query built by queryBuilder
* @returns A result provider that resolves to an array of document content
*/
queryCollection(collection: string, query?: any): ResultProvider<DocumentContent[]>;
/**
* Reads one or more documents, returning just the content.
* This is a simplified convenience method - use documents.read() for metadata too.
* @since 1.0
* @param uris - One or more document URIs
* @returns A result provider that resolves to an array of document content
*/
read(...uris: string[]): ResultProvider<DocumentContent[]>;
/**
* Removes one or more documents.
* This is a simplified convenience method - use documents.remove() for more control.
* @since 1.0
* @param uris - One or more document URIs to remove
* @returns A result provider that resolves to an array of removed URIs
*/
remove(...uris: string[]): ResultProvider<string[]>;
/**
* Removes all documents in a collection.
* This is a simplified convenience method - use documents.removeAll() for more options.
* @since 1.0
* @param collection - The collection whose documents should be deleted
* @returns A result provider that resolves to the collection name
*/
removeCollection(collection: string): ResultProvider<string>;
/**
* Writes documents to a collection using a URI-to-content mapping.
* This is a simplified convenience method - use documents.write() for more control.
* @since 1.0
* @param collection - The collection name for the documents
* @param documents - An object mapping URIs to document content
* @returns A result provider that resolves to an array of written URIs
*/
writeCollection(collection: string, documents: Record<string, DocumentContent>): ResultProvider<string[]>;
/**
* Creates a timestamp object for point-in-time operations.
* @since 2.1.1
* @param value - Optional timestamp value as a string
* @returns A Timestamp object
*/
createTimestamp(value?: string): Timestamp;
/**
* Evaluates JavaScript code on the server.
* The user must have permission to evaluate code and execute the actions performed.
* @since 1.0
* @param source - The JavaScript source code to evaluate
* @param variables - Optional object with variable name-value pairs
* @param txid - Optional transaction ID or Transaction object
* @returns A result provider that resolves to an array of EvalResult objects
*/
eval(source: string, variables?: Record<string, any>, txid?: string | object): ResultProvider<EvalResult[]>;
/**
* Evaluates XQuery code on the server.
* The user must have permission to evaluate code and execute the actions performed.
* @since 1.0
* @param source - The XQuery source code to evaluate
* @param variables - Optional object with variable name-value pairs (keys may use Clark notation)
* @param txid - Optional transaction ID or Transaction object
* @returns A result provider that resolves to an array of EvalResult objects
*/
xqueryEval(source: string, variables?: Record<string, any>, txid?: string | object): ResultProvider<EvalResult[]>;
/**
* Invokes a JavaScript or XQuery module on the server.
* The module must have been installed previously (typically with config.extlibs.write()).
* @since 1.0
* @param path - The path of the module in the modules database
* @param variables - Optional object with variable name-value pairs
* @param txid - Optional transaction ID or Transaction object
* @returns A result provider that resolves to an array of EvalResult objects
*/
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.
* @since 3.0.0
*/
release(): void;
}
/**
* A result provider that wraps asynchronous operations.
* Call .result() to get a Promise for the result.
*/
export interface ResultProvider<T> {
/**
* Gets a promise for the operation result.
* @param onFulfilled - Optional callback for success
* @param onRejected - Optional callback for errors
* @returns A promise that resolves to the result
*/
result(onFulfilled?: (value: T) => void, onRejected?: (reason: any) => void): Promise<T>;
}
/**
* Creates a DatabaseClient object for accessing a database.
* @param config - Configuration for connecting to the database
* @returns A DatabaseClient object for performing database operations
*/
export function createDatabaseClient(config: DatabaseClientConfig): DatabaseClient;
/**
* Releases a client and destroys its agent.
* This is a standalone function equivalent to calling client.release().
* @since 3.0.0
* @param client - The DatabaseClient to release
*/
export function releaseClient(client: DatabaseClient): void;
const marklogic: {
createDatabaseClient: typeof createDatabaseClient;
releaseClient: typeof releaseClient;
};
export default marklogic;
}