@dotcms/client 1.2.1 → 1.2.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dotcms/client",
3
- "version": "1.2.1",
3
+ "version": "1.2.2",
4
4
  "description": "Official JavaScript library for interacting with DotCMS REST APIs.",
5
5
  "repository": {
6
6
  "type": "git",
@@ -26,13 +26,13 @@
26
26
  "./package.json": "./package.json",
27
27
  ".": {
28
28
  "module": "./index.esm.js",
29
- "types": "./index.esm.d.ts",
29
+ "types": "./index.d.ts",
30
30
  "import": "./index.cjs.mjs",
31
31
  "default": "./index.cjs.js"
32
32
  },
33
33
  "./internal": {
34
34
  "module": "./internal.esm.js",
35
- "types": "./internal.esm.d.ts",
35
+ "types": "./internal.d.ts",
36
36
  "import": "./internal.cjs.mjs",
37
37
  "default": "./internal.cjs.js"
38
38
  }
@@ -55,5 +55,5 @@
55
55
  "homepage": "https://github.com/dotCMS/core/tree/main/core-web/libs/sdk/client/README.md",
56
56
  "module": "./index.esm.js",
57
57
  "main": "./index.cjs.js",
58
- "types": "./index.esm.d.ts"
58
+ "types": "./index.d.ts"
59
59
  }
@@ -1,6 +1,6 @@
1
1
  import { DotCMSClientConfig, DotRequestOptions, DotHttpClient, DotCMSAISearchParams, DotCMSBasicContentlet } from '@dotcms/types';
2
2
  import { AISearch } from './search/search';
3
- import { BaseApiClient } from '../base/base-api';
3
+ import { BaseApiClient } from '../base/api/base-api';
4
4
  /**
5
5
  * Client for interacting with the DotCMS AI API.
6
6
  * Provides methods to interact with AI features.
@@ -1,5 +1,5 @@
1
1
  import { DotCMSAISearchParams, DotCMSBasicContentlet, DotCMSClientConfig, DotErrorAISearch, DotHttpClient, DotRequestOptions, DotCMSAISearchResponse } from '@dotcms/types';
2
- import { BaseApiClient } from '../../base/base-api';
2
+ import { BaseApiClient } from '../../base/api/base-api';
3
3
  import { OnFullfilled, OnRejected } from '../shared/types';
4
4
  /**
5
5
  * Class for executing AI searches.
@@ -1,18 +1,19 @@
1
1
  import { DotCMSAISearchResponse, DotCMSBasicContentlet, DotErrorAISearch } from '@dotcms/types';
2
+ import { ThenableCallback } from '@dotcms/types/internal';
2
3
  /**
3
4
  * Callback for a fulfilled promise.
4
5
  *
5
6
  * @template T - The type of the response.
6
7
  * @callback OnFullfilled
7
8
  * @param {DotCMSAISearchResponse} value - The response value.
8
- * @returns {DotCMSAISearchResponse | PromiseLike<DotCMSAISearchResponse>} The processed response or a promise.
9
+ * @returns {DotCMSAISearchResponse | PromiseLike<DotCMSAISearchResponse> | void} The processed response or a promise.
9
10
  */
10
- export type OnFullfilled<T extends DotCMSBasicContentlet> = ((value: DotCMSAISearchResponse<T>) => DotCMSAISearchResponse<T> | PromiseLike<DotCMSAISearchResponse<T>>) | undefined | null;
11
+ export type OnFullfilled<T extends DotCMSBasicContentlet> = ThenableCallback<DotCMSAISearchResponse<T>>;
11
12
  /**
12
13
  * Callback for a rejected promise.
13
14
  *
14
15
  * @callback OnRejected
15
16
  * @param {DotErrorAISearch} error - The AI search error object.
16
- * @returns {DotErrorAISearch | PromiseLike<DotErrorAISearch>} The processed error or a promise.
17
+ * @returns {DotErrorAISearch | PromiseLike<DotErrorAISearch> | void} The processed error or a promise.
17
18
  */
18
- export type OnRejected = ((error: DotErrorAISearch) => DotErrorAISearch | PromiseLike<DotErrorAISearch>) | undefined | null;
19
+ export type OnRejected = ThenableCallback<DotErrorAISearch>;
@@ -0,0 +1,200 @@
1
+ import { DotHttpClient, DotRequestOptions, DotCMSClientConfig, DotErrorContent } from '@dotcms/types';
2
+ import { GetCollectionResponse, SortBy, GetCollectionRawResponse, OnFullfilled, OnRejected } from '../../content/shared/types';
3
+ import { BaseApiClient } from '../api/base-api';
4
+ /**
5
+ * Abstract base class for content builders that provides common functionality
6
+ * for querying content from the DotCMS Content API.
7
+ *
8
+ * This class extracts shared behavior between different builder implementations,
9
+ * including pagination, sorting, rendering, and response formatting.
10
+ *
11
+ * @export
12
+ * @abstract
13
+ * @class BaseBuilder
14
+ * @template T - The type of the content items (defaults to unknown)
15
+ */
16
+ export declare abstract class BaseBuilder<T = unknown> extends BaseApiClient {
17
+ #private;
18
+ /**
19
+ * Creates an instance of BaseBuilder.
20
+ *
21
+ * @param {object} params - Constructor parameters
22
+ * @param {DotRequestOptions} params.requestOptions - Options for the client request
23
+ * @param {DotCMSClientConfig} params.config - The client configuration
24
+ * @param {DotHttpClient} params.httpClient - HTTP client for making requests
25
+ * @memberof BaseBuilder
26
+ */
27
+ constructor(params: {
28
+ requestOptions: DotRequestOptions;
29
+ config: DotCMSClientConfig;
30
+ httpClient: DotHttpClient;
31
+ });
32
+ /**
33
+ * Returns the offset for pagination based on current page and limit.
34
+ *
35
+ * @readonly
36
+ * @protected
37
+ * @memberof BaseBuilder
38
+ */
39
+ protected get offset(): number;
40
+ /**
41
+ * Returns the sort query in the format: field order, field order, ...
42
+ *
43
+ * @readonly
44
+ * @protected
45
+ * @memberof BaseBuilder
46
+ */
47
+ protected get sort(): string | undefined;
48
+ /**
49
+ * Returns the full URL for the content API.
50
+ *
51
+ * @readonly
52
+ * @protected
53
+ * @memberof BaseBuilder
54
+ */
55
+ protected get url(): string;
56
+ /**
57
+ * Sets the maximum amount of content to fetch.
58
+ *
59
+ * @example
60
+ * ```typescript
61
+ * builder.limit(20);
62
+ * ```
63
+ *
64
+ * @param {number} limit - The maximum amount of content to fetch
65
+ * @return {this} The builder instance for method chaining
66
+ * @memberof BaseBuilder
67
+ */
68
+ limit(limit: number): this;
69
+ /**
70
+ * Sets the page number to fetch.
71
+ *
72
+ * @example
73
+ * ```typescript
74
+ * builder.page(2);
75
+ * ```
76
+ *
77
+ * @param {number} page - The page number to fetch
78
+ * @return {this} The builder instance for method chaining
79
+ * @memberof BaseBuilder
80
+ */
81
+ page(page: number): this;
82
+ /**
83
+ * Sorts the content by the specified fields and orders.
84
+ *
85
+ * @example
86
+ * ```typescript
87
+ * const sortBy = [
88
+ * { field: 'title', order: 'asc' },
89
+ * { field: 'modDate', order: 'desc' }
90
+ * ];
91
+ * builder.sortBy(sortBy);
92
+ * ```
93
+ *
94
+ * @param {SortBy[]} sortBy - Array of constraints to sort the content by
95
+ * @return {this} The builder instance for method chaining
96
+ * @memberof BaseBuilder
97
+ */
98
+ sortBy(sortBy: SortBy[]): this;
99
+ /**
100
+ * Setting this to true will server-side render (using velocity) any widgets
101
+ * that are returned by the content query.
102
+ *
103
+ * More information here: {@link https://www.dotcms.com/docs/latest/content-api-retrieval-and-querying#ParamsOptional}
104
+ *
105
+ * @example
106
+ * ```typescript
107
+ * builder.render();
108
+ * ```
109
+ *
110
+ * @return {this} The builder instance for method chaining
111
+ * @memberof BaseBuilder
112
+ */
113
+ render(): this;
114
+ /**
115
+ * Sets the depth of the relationships of the content.
116
+ * Specifies the depth of related content to return in the results.
117
+ *
118
+ * More information here: {@link https://www.dotcms.com/docs/latest/content-api-retrieval-and-querying#ParamsOptional}
119
+ *
120
+ * @example
121
+ * ```typescript
122
+ * builder.depth(2);
123
+ * ```
124
+ *
125
+ * @param {number} depth - The depth of the relationships of the content (0-3)
126
+ * @return {this} The builder instance for method chaining
127
+ * @throws {Error} When depth is not between 0 and 3
128
+ * @memberof BaseBuilder
129
+ */
130
+ depth(depth: number): this;
131
+ /**
132
+ * Executes the fetch and returns a promise that resolves to the content or rejects with an error.
133
+ *
134
+ * @example
135
+ * ```typescript
136
+ * builder
137
+ * .limit(10)
138
+ * .then((response) => console.log(response))
139
+ * .catch((error) => console.error(error));
140
+ * ```
141
+ *
142
+ * @example Using async/await
143
+ * ```typescript
144
+ * const response = await builder.limit(10);
145
+ * ```
146
+ *
147
+ * @param {OnFullfilled} [onfulfilled] - A callback that is called when the fetch is successful
148
+ * @param {OnRejected} [onrejected] - A callback that is called when the fetch fails
149
+ * @return {Promise<GetCollectionResponse<T> | DotErrorContent>} A promise that resolves to the content or rejects with an error
150
+ * @memberof BaseBuilder
151
+ */
152
+ then(onfulfilled?: OnFullfilled<T>, onrejected?: OnRejected): Promise<GetCollectionResponse<T> | DotErrorContent>;
153
+ /**
154
+ * Formats the response to the desired format.
155
+ *
156
+ * @protected
157
+ * @param {GetCollectionRawResponse<T>} data - The raw response data
158
+ * @return {GetCollectionResponse<T>} The formatted response
159
+ * @memberof BaseBuilder
160
+ */
161
+ protected formatResponse<T>(data: GetCollectionRawResponse<T>): GetCollectionResponse<T>;
162
+ /**
163
+ * Calls the content API to fetch the content.
164
+ *
165
+ * @protected
166
+ * @return {Promise<GetCollectionRawResponse<T>>} The fetch response data
167
+ * @throws {DotHttpError} When the HTTP request fails
168
+ * @memberof BaseBuilder
169
+ */
170
+ protected fetch(): Promise<GetCollectionRawResponse<T>>;
171
+ /**
172
+ * Wraps an error in a DotErrorContent instance with helpful context.
173
+ *
174
+ * @protected
175
+ * @param {unknown} error - The error to wrap
176
+ * @return {DotErrorContent} The wrapped error
177
+ * @memberof BaseBuilder
178
+ */
179
+ protected abstract wrapError(error: unknown): DotErrorContent;
180
+ /**
181
+ * Builds the final Lucene query string.
182
+ * Subclasses must implement this method to define their query building strategy.
183
+ *
184
+ * @protected
185
+ * @abstract
186
+ * @return {string} The final Lucene query string
187
+ * @memberof BaseBuilder
188
+ */
189
+ protected abstract buildFinalQuery(): string;
190
+ /**
191
+ * Gets the language ID for the query.
192
+ * Subclasses must implement this method to provide the language ID.
193
+ *
194
+ * @protected
195
+ * @abstract
196
+ * @return {number | string} The language ID
197
+ * @memberof BaseBuilder
198
+ */
199
+ protected abstract getLanguageId(): number | string | undefined;
200
+ }
@@ -1,6 +1,6 @@
1
1
  import { DotHttpClient, DotRequestOptions, DotCMSClientConfig, DotErrorContent } from '@dotcms/types';
2
- import { BaseApiClient } from '../../../base/base-api';
3
- import { GetCollectionResponse, BuildQuery, SortBy, OnFullfilled, OnRejected } from '../../shared/types';
2
+ import { BaseBuilder } from '../../../base/builder/base-builder';
3
+ import { BuildQuery } from '../../shared/types';
4
4
  /**
5
5
  * Creates a Builder to filter and fetch content from the content API for a specific content type.
6
6
  *
@@ -8,41 +8,23 @@ import { GetCollectionResponse, BuildQuery, SortBy, OnFullfilled, OnRejected } f
8
8
  * @class CollectionBuilder
9
9
  * @template T Represents the type of the content type to fetch. Defaults to unknown.
10
10
  */
11
- export declare class CollectionBuilder<T = unknown> extends BaseApiClient {
11
+ export declare class CollectionBuilder<T = unknown> extends BaseBuilder<T> {
12
12
  #private;
13
13
  /**
14
14
  * Creates an instance of CollectionBuilder.
15
- * @param {ClientOptions} requestOptions Options for the client request.
16
- * @param {DotCMSClientConfig} config The client configuration.
17
- * @param {string} contentType The content type to fetch.
18
- * @param {DotHttpClient} httpClient HTTP client for making requests.
15
+ * @param {object} params - Constructor parameters
16
+ * @param {DotRequestOptions} params.requestOptions - Options for the client request
17
+ * @param {DotCMSClientConfig} params.config - The client configuration
18
+ * @param {string} params.contentType - The content type to fetch
19
+ * @param {DotHttpClient} params.httpClient - HTTP client for making requests
19
20
  * @memberof CollectionBuilder
20
21
  */
21
- constructor(requestOptions: DotRequestOptions, config: DotCMSClientConfig, contentType: string, httpClient: DotHttpClient);
22
- /**
23
- * Returns the sort query in the format: field order, field order, ...
24
- *
25
- * @readonly
26
- * @private
27
- * @memberof CollectionBuilder
28
- */
29
- private get sort();
30
- /**
31
- * Returns the offset for pagination.
32
- *
33
- * @readonly
34
- * @private
35
- * @memberof CollectionBuilder
36
- */
37
- private get offset();
38
- /**
39
- * Returns the full URL for the content API.
40
- *
41
- * @readonly
42
- * @private
43
- * @memberof CollectionBuilder
44
- */
45
- private get url();
22
+ constructor(params: {
23
+ requestOptions: DotRequestOptions;
24
+ config: DotCMSClientConfig;
25
+ contentType: string;
26
+ httpClient: DotHttpClient;
27
+ });
46
28
  /**
47
29
  * Returns the current query built.
48
30
  *
@@ -66,47 +48,6 @@ export declare class CollectionBuilder<T = unknown> extends BaseApiClient {
66
48
  * @memberof CollectionBuilder
67
49
  */
68
50
  language(languageId: number | string): this;
69
- /**
70
- * Setting this to true will server side render (using velocity) any widgets that are returned by the content query.
71
- *
72
- * More information here: {@link https://www.dotcms.com/docs/latest/content-api-retrieval-and-querying#ParamsOptional}
73
- *
74
- * @return {CollectionBuilder} A CollectionBuilder instance.
75
- * @memberof CollectionBuilder
76
- */
77
- render(): this;
78
- /**
79
- * Sorts the content by the specified fields and orders.
80
- *
81
- * @example
82
- * ```typescript
83
- * const client = new DotCMSClient(config);
84
- * const collectionBuilder = client.content.getCollection("Blog");
85
- * const sortBy = [{ field: 'title', order: 'asc' }, { field: 'modDate', order: 'desc' }];
86
- * collectionBuilder("Blog").sortBy(sortBy);
87
- * ```
88
- *
89
- * @param {SortBy[]} sortBy Array of constraints to sort the content by.
90
- * @return {CollectionBuilder} A CollectionBuilder instance.
91
- * @memberof CollectionBuilder
92
- */
93
- sortBy(sortBy: SortBy[]): this;
94
- /**
95
- * Sets the maximum amount of content to fetch.
96
- *
97
- * @param {number} limit The maximum amount of content to fetch.
98
- * @return {CollectionBuilder} A CollectionBuilder instance.
99
- * @memberof CollectionBuilder
100
- */
101
- limit(limit: number): this;
102
- /**
103
- * Sets the page number to fetch.
104
- *
105
- * @param {number} page The page number to fetch.
106
- * @return {CollectionBuilder} A CollectionBuilder instance.
107
- * @memberof CollectionBuilder
108
- */
109
- page(page: number): this;
110
51
  /**
111
52
  * Filters the content by a Lucene query string.
112
53
  *
@@ -169,77 +110,37 @@ export declare class CollectionBuilder<T = unknown> extends BaseApiClient {
169
110
  */
170
111
  variant(variantId: string): this;
171
112
  /**
172
- * Sets the depth of the relationships of the content.
173
- * Specifies the depth of related content to return in the results.
174
- *
175
- * More information here: {@link https://www.dotcms.com/docs/latest/content-api-retrieval-and-querying#ParamsOptional}
176
- *
177
- * @example
178
- * ```ts
179
- * const client = new DotCMSClient(config);
180
- * const collectionBuilder = client.content.getCollection("Blog");
181
- * collectionBuilder
182
- * .depth(1)
183
- * .then((response) => // Your code here })
184
- * .catch((error) => // Your code here })
185
- * ```
113
+ * Wraps an error in a DotErrorContent instance with helpful context.
186
114
  *
187
- * @param {number} depth The depth of the relationships of the content.
188
- * @return {CollectionBuilder} A CollectionBuilder instance.
115
+ * @protected
116
+ * @param {unknown} error - The error to wrap
117
+ * @return {DotErrorContent} The wrapped error
189
118
  * @memberof CollectionBuilder
190
119
  */
191
- depth(depth: number): this;
120
+ protected wrapError(error: unknown): DotErrorContent;
192
121
  /**
193
- * Executes the fetch and returns a promise that resolves to the content or rejects with an error.
122
+ * Gets the language ID for the query.
194
123
  *
195
- * @example
196
- * ```ts
197
- * const client = new DotCMSClient(config);
198
- * const collectionBuilder = client.content.getCollection("Blog");
199
- * collectionBuilder
200
- * .limit(10)
201
- * .then((response) => // Your code here })
202
- * .catch((error) => // Your code here })
203
- * ```
204
- *
205
- * @param {OnFullfilled} [onfulfilled] A callback that is called when the fetch is successful.
206
- * @param {OnRejected} [onrejected] A callback that is called when the fetch fails.
207
- * @return {Promise<GetCollectionResponse<T> | DotErrorContent>} A promise that resolves to the content or rejects with an error.
124
+ * @protected
125
+ * @return {number | string} The language ID
208
126
  * @memberof CollectionBuilder
209
127
  */
210
- then(onfulfilled?: OnFullfilled<T>, onrejected?: OnRejected): Promise<GetCollectionResponse<T> | DotErrorContent>;
211
- /**
212
- * Formats the response to the desired format.
213
- *
214
- * @private
215
- * @param {GetCollectionRawResponse<T>} data The raw response data.
216
- * @return {GetCollectionResponse<T>} The formatted response.
217
- * @memberof CollectionBuilder
218
- */
219
- private formatResponse;
220
- /**
221
- * Calls the content API to fetch the content.
222
- *
223
- * @private
224
- * @return {Promise<GetCollectionRawResponse<T>>} The fetch response data.
225
- * @throws {DotHttpError} When the HTTP request fails.
226
- * @memberof CollectionBuilder
227
- */
228
- private fetch;
128
+ protected getLanguageId(): number | string;
229
129
  /**
230
130
  * Builds the final Lucene query string by combining the base query with required system constraints.
231
131
  *
232
132
  * This method constructs the complete query by:
233
133
  * 1. Adding language ID filter to ensure content matches the specified language
234
134
  * 2. Adding live/draft status filter based on the draft flag
235
- * 3. Optionally adding site ID constraint if conditions are met
135
+ * 3. Applying content type specific query sanitization
136
+ * 4. Optionally adding site ID constraint if conditions are met
236
137
  *
237
138
  * Site ID constraint is added only when:
238
139
  * - Query doesn't already contain a positive site constraint (+conhost)
239
140
  * - Query doesn't explicitly exclude the current site ID (-conhost:currentSiteId)
240
141
  * - Site ID is configured in the system
241
142
  *
242
- * @private
143
+ * @protected
243
144
  * @returns {string} The complete Lucene query string ready for the Content API
244
145
  * @memberof CollectionBuilder
245
146
  *
@@ -261,5 +162,5 @@ export declare class CollectionBuilder<T = unknown> extends BaseApiClient {
261
162
  * // Query: "+contentType:Blog -conhost:456"
262
163
  * // Returns: "+contentType:Blog -conhost:456 +languageId:1 +live:true +conhost:123" (site ID still added)
263
164
  */
264
- private getFinalQuery;
165
+ protected buildFinalQuery(): string;
265
166
  }
@@ -0,0 +1,75 @@
1
+ import { DotHttpClient, DotRequestOptions, DotCMSClientConfig, DotErrorContent } from '@dotcms/types';
2
+ import { BaseBuilder } from '../../../base/builder/base-builder';
3
+ /**
4
+ * Builder for executing raw Lucene queries against the DotCMS Content API.
5
+ *
6
+ * This builder provides direct access to Lucene query syntax while still
7
+ * offering common functionality like pagination, sorting, and language filtering.
8
+ *
9
+ * @export
10
+ * @class RawQueryBuilder
11
+ * @template T - The type of the content items (defaults to unknown)
12
+ */
13
+ export declare class RawQueryBuilder<T = unknown> extends BaseBuilder<T> {
14
+ #private;
15
+ /**
16
+ * Creates an instance of RawQueryBuilder.
17
+ *
18
+ * @param {object} params - Constructor parameters
19
+ * @param {DotRequestOptions} params.requestOptions - Options for the client request
20
+ * @param {DotCMSClientConfig} params.config - The client configuration
21
+ * @param {string} params.rawQuery - The raw Lucene query string
22
+ * @param {DotHttpClient} params.httpClient - HTTP client for making requests
23
+ * @memberof RawQueryBuilder
24
+ */
25
+ constructor(params: {
26
+ requestOptions: DotRequestOptions;
27
+ config: DotCMSClientConfig;
28
+ rawQuery: string;
29
+ httpClient: DotHttpClient;
30
+ });
31
+ /**
32
+ * Filters the content by the specified language ID.
33
+ *
34
+ * This sets the `languageId` request body field (it does not alter the raw Lucene query string).
35
+ *
36
+ * @example
37
+ * ```typescript
38
+ * const response = await client.content
39
+ * .query('+contentType:Blog +title:Hello')
40
+ * .language(1)
41
+ * .limit(10);
42
+ * ```
43
+ *
44
+ * @param {number | string} languageId The language ID to filter the content by.
45
+ * @return {RawQueryBuilder} A RawQueryBuilder instance.
46
+ * @memberof RawQueryBuilder
47
+ */
48
+ language(languageId: number | string): this;
49
+ /**
50
+ * Wraps an error in a DotErrorContent instance with helpful context.
51
+ *
52
+ * @protected
53
+ * @param {unknown} error - The error to wrap
54
+ * @return {DotErrorContent} The wrapped error
55
+ * @memberof RawQueryBuilder
56
+ */
57
+ protected wrapError(error: unknown): DotErrorContent;
58
+ /**
59
+ * @protected
60
+ * @return {number | string | undefined} Optional languageId to send in the request body.
61
+ * @memberof RawQueryBuilder
62
+ */
63
+ protected getLanguageId(): number | string | undefined;
64
+ /**
65
+ * Builds the final Lucene query string.
66
+ *
67
+ * Raw query is used as provided (only minimal sanitization is applied).
68
+ * No implicit constraints are added.
69
+ *
70
+ * @protected
71
+ * @return {string} The final Lucene query string
72
+ * @memberof RawQueryBuilder
73
+ */
74
+ protected buildFinalQuery(): string;
75
+ }
@@ -1,6 +1,7 @@
1
1
  import { DotRequestOptions, DotHttpClient, DotCMSClientConfig } from '@dotcms/types';
2
2
  import { CollectionBuilder } from './builders/collection/collection';
3
- import { BaseApiClient } from '../base/base-api';
3
+ import { RawQueryBuilder } from './builders/raw-query/raw-query.builder';
4
+ import { BaseApiClient } from '../base/api/base-api';
4
5
  /**
5
6
  * Creates a builder to filter and fetch a collection of content items.
6
7
  * @param contentType - The content type to retrieve.
@@ -124,4 +125,87 @@ export declare class Content extends BaseApiClient {
124
125
  *
125
126
  */
126
127
  getCollection<T = unknown>(contentType: string): CollectionBuilder<T>;
128
+ /**
129
+ * Executes a raw Lucene query with optional pagination, sorting, and rendering options.
130
+ *
131
+ * This method provides direct access to Lucene query syntax, giving you full control
132
+ * over query construction while still benefiting from common features like pagination,
133
+ * sorting, and error handling.
134
+ *
135
+ * **Important Notes:**
136
+ * - The raw query is used as-is (minimal sanitization only)
137
+ * - NO automatic field prefixing (unlike `getCollection()`)
138
+ * - NO implicit/system constraints are added (language, live/draft, site, variant, etc.)
139
+ * - If you need constraints, include them in the raw query string (e.g. `+contentType:Blog +languageId:1 +live:true`)
140
+ *
141
+ * @template T - The type of the content items (defaults to unknown)
142
+ * @param {string} rawQuery - Raw Lucene query string
143
+ * @return {RawQueryBuilder<T>} A RawQueryBuilder instance for chaining options
144
+ * @memberof Content
145
+ *
146
+ * @example Simple query with pagination
147
+ * ```typescript
148
+ * const response = await client.content
149
+ * .query('+contentType:Blog +title:"Hello World"')
150
+ * .limit(10)
151
+ * .page(1);
152
+ *
153
+ * console.log(response.contentlets);
154
+ * ```
155
+ *
156
+ * @example Complex query with all available options
157
+ * ```typescript
158
+ * const response = await client.content
159
+ * .query('+(contentType:Blog OR contentType:News) +tags:"technology" +languageId:1 +(live:false AND working:true AND deleted:false) +variant:legends-forceSensitive')
160
+ * .limit(20)
161
+ * .page(2)
162
+ * .sortBy([{ field: 'modDate', order: 'desc' }])
163
+ * .render()
164
+ * .depth(2);
165
+ *
166
+ * console.log(`Found ${response.total} items`);
167
+ * response.contentlets.forEach(item => console.log(item.title));
168
+ * ```
169
+ *
170
+ * @example Using TypeScript generics for type safety
171
+ * ```typescript
172
+ * interface BlogPost {
173
+ * title: string;
174
+ * author: string;
175
+ * publishDate: string;
176
+ * }
177
+ *
178
+ * const response = await client.content
179
+ * .query<BlogPost>('+contentType:Blog +author:"John Doe"')
180
+ * .limit(10);
181
+ *
182
+ * // TypeScript knows the type of contentlets
183
+ * response.contentlets.forEach(post => {
184
+ * console.log(post.title, post.author);
185
+ * });
186
+ * ```
187
+ *
188
+ * @example Error handling with helpful messages
189
+ * ```typescript
190
+ * try {
191
+ * const response = await client.content
192
+ * .query('+contentType:Blog +publishDate:[2024-01-01 TO 2024-12-31]');
193
+ * } catch (error) {
194
+ * if (error instanceof DotErrorContent) {
195
+ * console.error('Query failed:', error.message);
196
+ * console.error('Failed query:', error.query);
197
+ * }
198
+ * }
199
+ * ```
200
+ *
201
+ * @example Using Promise chain instead of async/await
202
+ * ```typescript
203
+ * client.content
204
+ * .query('+contentType:Blog')
205
+ * .limit(10)
206
+ * .then(response => console.log(response.contentlets))
207
+ * .catch(error => console.error(error));
208
+ * ```
209
+ */
210
+ query<T = unknown>(rawQuery: string): RawQueryBuilder<T>;
127
211
  }
@@ -1,4 +1,5 @@
1
1
  import { Contentlet, DotErrorContent } from '@dotcms/types';
2
+ import { ThenableCallback } from '@dotcms/types/internal';
2
3
  import { Equals } from '../builders/query/lucene-syntax';
3
4
  import { QueryBuilder } from '../builders/query/query';
4
5
  /**
@@ -28,17 +29,17 @@ export type BuildQuery = (qb: QueryBuilder) => Equals;
28
29
  * @template T - The type of the response.
29
30
  * @callback OnFullfilled
30
31
  * @param {GetCollectionResponse<T>} value - The response value.
31
- * @returns {GetCollectionResponse<T> | PromiseLike<GetCollectionResponse<T>>} The processed response or a promise.
32
+ * @returns {GetCollectionResponse<T> | PromiseLike<GetCollectionResponse<T>> | void} The processed response or a promise.
32
33
  */
33
- export type OnFullfilled<T> = ((value: GetCollectionResponse<T>) => GetCollectionResponse<T> | PromiseLike<GetCollectionResponse<T>>) | undefined | null;
34
+ export type OnFullfilled<T> = ThenableCallback<GetCollectionResponse<T>>;
34
35
  /**
35
36
  * Callback for a rejected promise.
36
37
  *
37
38
  * @callback OnRejected
38
39
  * @param {DotErrorContent} error - The content error object.
39
- * @returns {DotErrorContent | PromiseLike<DotErrorContent>} The processed error or a promise.
40
+ * @returns {DotErrorContent | PromiseLike<DotErrorContent> | void} The processed error or a promise.
40
41
  */
41
- export type OnRejected = ((error: DotErrorContent) => DotErrorContent | PromiseLike<DotErrorContent>) | undefined | null;
42
+ export type OnRejected = ThenableCallback<DotErrorContent>;
42
43
  /**
43
44
  * Response of the get collection method.
44
45
  *