@dotcms/client 1.0.0 → 1.0.1

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.
Files changed (54) hide show
  1. package/.eslintrc.json +18 -0
  2. package/CLAUDE.md +253 -0
  3. package/MIGRATION.md +329 -0
  4. package/README.md +250 -434
  5. package/jest.config.ts +15 -0
  6. package/package.json +8 -25
  7. package/project.json +73 -0
  8. package/src/lib/client/client.spec.ts +147 -0
  9. package/src/lib/client/client.ts +125 -0
  10. package/src/lib/client/content/builders/collection/collection.spec.ts +514 -0
  11. package/src/lib/client/content/builders/collection/{collection.d.ts → collection.ts} +210 -19
  12. package/src/lib/client/content/builders/query/lucene-syntax/{Equals.d.ts → Equals.ts} +45 -11
  13. package/src/lib/client/content/builders/query/lucene-syntax/{Field.d.ts → Field.ts} +13 -5
  14. package/src/lib/client/content/builders/query/lucene-syntax/{NotOperand.d.ts → NotOperand.ts} +13 -5
  15. package/src/lib/client/content/builders/query/lucene-syntax/{Operand.d.ts → Operand.ts} +21 -7
  16. package/src/lib/client/content/builders/query/query.spec.ts +159 -0
  17. package/src/lib/client/content/builders/query/{query.d.ts → query.ts} +16 -5
  18. package/src/lib/client/content/builders/query/utils/{index.d.ts → index.ts} +49 -12
  19. package/src/lib/client/content/{content-api.d.ts → content-api.ts} +14 -4
  20. package/src/lib/client/content/shared/{const.d.ts → const.ts} +5 -3
  21. package/src/lib/client/content/shared/{types.d.ts → types.ts} +18 -2
  22. package/src/lib/client/content/shared/{utils.d.ts → utils.ts} +9 -1
  23. package/src/lib/client/models/{index.d.ts → index.ts} +8 -1
  24. package/src/lib/client/navigation/navigation-api.spec.ts +167 -0
  25. package/src/lib/client/navigation/navigation-api.ts +62 -0
  26. package/src/lib/client/page/page-api.spec.ts +359 -0
  27. package/src/lib/client/page/page-api.ts +197 -0
  28. package/src/lib/client/page/utils.ts +291 -0
  29. package/src/lib/utils/graphql/transforms.spec.ts +250 -0
  30. package/src/lib/utils/graphql/transforms.ts +128 -0
  31. package/tsconfig.json +22 -0
  32. package/tsconfig.lib.json +13 -0
  33. package/tsconfig.spec.json +9 -0
  34. package/index.cjs.d.ts +0 -1
  35. package/index.cjs.default.js +0 -1
  36. package/index.cjs.js +0 -1591
  37. package/index.cjs.mjs +0 -2
  38. package/index.esm.d.ts +0 -1
  39. package/index.esm.js +0 -1589
  40. package/internal.cjs.d.ts +0 -1
  41. package/internal.cjs.default.js +0 -1
  42. package/internal.cjs.js +0 -85
  43. package/internal.cjs.mjs +0 -2
  44. package/internal.esm.d.ts +0 -1
  45. package/internal.esm.js +0 -83
  46. package/src/lib/client/client.d.ts +0 -56
  47. package/src/lib/client/navigation/navigation-api.d.ts +0 -14
  48. package/src/lib/client/page/page-api.d.ts +0 -95
  49. package/src/lib/client/page/utils.d.ts +0 -41
  50. package/src/lib/utils/graphql/transforms.d.ts +0 -13
  51. /package/src/{index.d.ts → index.ts} +0 -0
  52. /package/src/{internal.d.ts → internal.ts} +0 -0
  53. /package/src/lib/client/content/builders/query/lucene-syntax/{index.d.ts → index.ts} +0 -0
  54. /package/src/lib/utils/{index.d.ts → index.ts} +0 -0
@@ -1,5 +1,19 @@
1
- import { GetCollectionResponse, BuildQuery, SortBy, GetCollectionError, OnFullfilled, OnRejected } from '../../shared/types';
1
+ import { CONTENT_API_URL } from '../../shared/const';
2
+ import {
3
+ GetCollectionResponse,
4
+ BuildQuery,
5
+ SortBy,
6
+ GetCollectionRawResponse,
7
+ GetCollectionError,
8
+ OnFullfilled,
9
+ OnRejected
10
+ } from '../../shared/types';
11
+ import { sanitizeQueryForContentType } from '../../shared/utils';
12
+ import { Equals } from '../query/lucene-syntax';
13
+ import { QueryBuilder } from '../query/query';
14
+
2
15
  export type ClientOptions = Omit<RequestInit, 'body' | 'method'>;
16
+
3
17
  /**
4
18
  * Creates a Builder to filter and fetch content from the content API for a specific content type.
5
19
  *
@@ -7,8 +21,22 @@ export type ClientOptions = Omit<RequestInit, 'body' | 'method'>;
7
21
  * @class CollectionBuilder
8
22
  * @template T Represents the type of the content type to fetch. Defaults to unknown.
9
23
  */
10
- export declare class CollectionBuilder<T = unknown> {
11
- #private;
24
+ export class CollectionBuilder<T = unknown> {
25
+ #page = 1;
26
+ #limit = 10;
27
+ #depth = 0;
28
+ #render = false;
29
+ #sortBy?: SortBy[];
30
+ #contentType: string;
31
+ #defaultQuery: Equals;
32
+ #query?: Equals;
33
+ #rawQuery?: string;
34
+ #languageId: number | string = 1;
35
+ #draft = false;
36
+
37
+ #serverUrl: string;
38
+ #requestOptions: ClientOptions;
39
+
12
40
  /**
13
41
  * Creates an instance of CollectionBuilder.
14
42
  * @param {ClientOptions} requestOptions Options for the client request.
@@ -16,7 +44,15 @@ export declare class CollectionBuilder<T = unknown> {
16
44
  * @param {string} contentType The content type to fetch.
17
45
  * @memberof CollectionBuilder
18
46
  */
19
- constructor(requestOptions: ClientOptions, serverUrl: string, contentType: string);
47
+ constructor(requestOptions: ClientOptions, serverUrl: string, contentType: string) {
48
+ this.#requestOptions = requestOptions;
49
+ this.#serverUrl = serverUrl;
50
+ this.#contentType = contentType;
51
+
52
+ // Build the default query with the contentType field
53
+ this.#defaultQuery = new QueryBuilder().field('contentType').equals(this.#contentType);
54
+ }
55
+
20
56
  /**
21
57
  * Returns the sort query in the format: field order, field order, ...
22
58
  *
@@ -24,7 +60,10 @@ export declare class CollectionBuilder<T = unknown> {
24
60
  * @private
25
61
  * @memberof CollectionBuilder
26
62
  */
27
- private get sort();
63
+ private get sort() {
64
+ return this.#sortBy?.map((sort) => `${sort.field} ${sort.order}`).join(',');
65
+ }
66
+
28
67
  /**
29
68
  * Returns the offset for pagination.
30
69
  *
@@ -32,7 +71,10 @@ export declare class CollectionBuilder<T = unknown> {
32
71
  * @private
33
72
  * @memberof CollectionBuilder
34
73
  */
35
- private get offset();
74
+ private get offset() {
75
+ return this.#limit * (this.#page - 1);
76
+ }
77
+
36
78
  /**
37
79
  * Returns the full URL for the content API.
38
80
  *
@@ -40,7 +82,10 @@ export declare class CollectionBuilder<T = unknown> {
40
82
  * @private
41
83
  * @memberof CollectionBuilder
42
84
  */
43
- private get url();
85
+ private get url() {
86
+ return `${this.#serverUrl}${CONTENT_API_URL}`;
87
+ }
88
+
44
89
  /**
45
90
  * Returns the current query built.
46
91
  *
@@ -48,7 +93,10 @@ export declare class CollectionBuilder<T = unknown> {
48
93
  * @private
49
94
  * @memberof CollectionBuilder
50
95
  */
51
- private get currentQuery();
96
+ private get currentQuery() {
97
+ return this.#query ?? this.#defaultQuery;
98
+ }
99
+
52
100
  /**
53
101
  * Filters the content by the specified language ID.
54
102
  *
@@ -63,7 +111,12 @@ export declare class CollectionBuilder<T = unknown> {
63
111
  * @return {CollectionBuilder} A CollectionBuilder instance.
64
112
  * @memberof CollectionBuilder
65
113
  */
66
- language(languageId: number | string): this;
114
+ language(languageId: number | string): this {
115
+ this.#languageId = languageId;
116
+
117
+ return this;
118
+ }
119
+
67
120
  /**
68
121
  * Setting this to true will server side render (using velocity) any widgets that are returned by the content query.
69
122
  *
@@ -72,7 +125,12 @@ export declare class CollectionBuilder<T = unknown> {
72
125
  * @return {CollectionBuilder} A CollectionBuilder instance.
73
126
  * @memberof CollectionBuilder
74
127
  */
75
- render(): this;
128
+ render(): this {
129
+ this.#render = true;
130
+
131
+ return this;
132
+ }
133
+
76
134
  /**
77
135
  * Sorts the content by the specified fields and orders.
78
136
  *
@@ -88,7 +146,12 @@ export declare class CollectionBuilder<T = unknown> {
88
146
  * @return {CollectionBuilder} A CollectionBuilder instance.
89
147
  * @memberof CollectionBuilder
90
148
  */
91
- sortBy(sortBy: SortBy[]): this;
149
+ sortBy(sortBy: SortBy[]): this {
150
+ this.#sortBy = sortBy;
151
+
152
+ return this;
153
+ }
154
+
92
155
  /**
93
156
  * Sets the maximum amount of content to fetch.
94
157
  *
@@ -96,7 +159,12 @@ export declare class CollectionBuilder<T = unknown> {
96
159
  * @return {CollectionBuilder} A CollectionBuilder instance.
97
160
  * @memberof CollectionBuilder
98
161
  */
99
- limit(limit: number): this;
162
+ limit(limit: number): this {
163
+ this.#limit = limit;
164
+
165
+ return this;
166
+ }
167
+
100
168
  /**
101
169
  * Sets the page number to fetch.
102
170
  *
@@ -104,7 +172,12 @@ export declare class CollectionBuilder<T = unknown> {
104
172
  * @return {CollectionBuilder} A CollectionBuilder instance.
105
173
  * @memberof CollectionBuilder
106
174
  */
107
- page(page: number): this;
175
+ page(page: number): this {
176
+ this.#page = page;
177
+
178
+ return this;
179
+ }
180
+
108
181
  /**
109
182
  * Filters the content by a Lucene query string.
110
183
  *
@@ -113,6 +186,7 @@ export declare class CollectionBuilder<T = unknown> {
113
186
  * @memberof CollectionBuilder
114
187
  */
115
188
  query(query: string): this;
189
+
116
190
  /**
117
191
  * Filters the content by building a query using a QueryBuilder function.
118
192
  *
@@ -130,6 +204,33 @@ export declare class CollectionBuilder<T = unknown> {
130
204
  * @memberof CollectionBuilder
131
205
  */
132
206
  query(buildQuery: BuildQuery): this;
207
+ query(arg: unknown): this {
208
+ if (typeof arg === 'string') {
209
+ this.#rawQuery = arg;
210
+
211
+ return this;
212
+ }
213
+
214
+ if (typeof arg !== 'function') {
215
+ throw new Error(
216
+ `Parameter for query method should be a buildQuery function or a string.\nExample:\nclient.content.getCollection('Activity').query((queryBuilder) => queryBuilder.field('title').equals('Hello World'))\nor\nclient.content.getCollection('Activity').query('+Activity.title:"Hello World"') \nSee documentation for more information.`
217
+ );
218
+ }
219
+
220
+ const builtQuery = arg(new QueryBuilder());
221
+
222
+ // This can be use in Javascript so we cannot rely on the type checking
223
+ if (builtQuery instanceof Equals) {
224
+ this.#query = builtQuery.raw(this.currentQuery.build());
225
+ } else {
226
+ throw new Error(
227
+ 'Provided query is not valid. A query should end in an equals method call.\nExample:\n(queryBuilder) => queryBuilder.field("title").equals("Hello World")\nSee documentation for more information.'
228
+ );
229
+ }
230
+
231
+ return this;
232
+ }
233
+
133
234
  /**
134
235
  * Retrieves draft content.
135
236
  * @example
@@ -145,7 +246,12 @@ export declare class CollectionBuilder<T = unknown> {
145
246
  * @return {CollectionBuilder} A CollectionBuilder instance.
146
247
  * @memberof CollectionBuilder
147
248
  */
148
- draft(): this;
249
+ draft(): this {
250
+ this.#draft = true;
251
+
252
+ return this;
253
+ }
254
+
149
255
  /**
150
256
  * Filters the content by a variant ID for [Experiments](https://www.dotcms.com/docs/latest/experiments-and-a-b-testing)
151
257
  *
@@ -165,7 +271,12 @@ export declare class CollectionBuilder<T = unknown> {
165
271
  * @return {CollectionBuilder} A CollectionBuilder instance.
166
272
  * @memberof CollectionBuilder
167
273
  */
168
- variant(variantId: string): this;
274
+ variant(variantId: string): this {
275
+ this.#query = this.currentQuery.field('variant').equals(variantId);
276
+
277
+ return this;
278
+ }
279
+
169
280
  /**
170
281
  * Sets the depth of the relationships of the content.
171
282
  * Specifies the depth of related content to return in the results.
@@ -186,7 +297,16 @@ export declare class CollectionBuilder<T = unknown> {
186
297
  * @return {CollectionBuilder} A CollectionBuilder instance.
187
298
  * @memberof CollectionBuilder
188
299
  */
189
- depth(depth: number): this;
300
+ depth(depth: number): this {
301
+ if (depth < 0 || depth > 3) {
302
+ throw new Error('Depth value must be between 0 and 3');
303
+ }
304
+
305
+ this.#depth = depth;
306
+
307
+ return this;
308
+ }
309
+
190
310
  /**
191
311
  * Executes the fetch and returns a promise that resolves to the content or rejects with an error.
192
312
  *
@@ -205,7 +325,30 @@ export declare class CollectionBuilder<T = unknown> {
205
325
  * @return {Promise<GetCollectionResponse<T> | GetCollectionError>} A promise that resolves to the content or rejects with an error.
206
326
  * @memberof CollectionBuilder
207
327
  */
208
- then(onfulfilled?: OnFullfilled<T>, onrejected?: OnRejected): Promise<GetCollectionResponse<T> | GetCollectionError>;
328
+ then(
329
+ onfulfilled?: OnFullfilled<T>,
330
+ onrejected?: OnRejected
331
+ ): Promise<GetCollectionResponse<T> | GetCollectionError> {
332
+ return this.fetch().then(async (response) => {
333
+ const data = await response.json();
334
+ if (response.ok) {
335
+ const formattedResponse = this.formatResponse<T>(data);
336
+
337
+ const finalResponse =
338
+ typeof onfulfilled === 'function'
339
+ ? onfulfilled(formattedResponse)
340
+ : formattedResponse;
341
+
342
+ return finalResponse;
343
+ } else {
344
+ return {
345
+ status: response.status,
346
+ ...data
347
+ };
348
+ }
349
+ }, onrejected);
350
+ }
351
+
209
352
  /**
210
353
  * Formats the response to the desired format.
211
354
  *
@@ -214,7 +357,25 @@ export declare class CollectionBuilder<T = unknown> {
214
357
  * @return {GetCollectionResponse<T>} The formatted response.
215
358
  * @memberof CollectionBuilder
216
359
  */
217
- private formatResponse;
360
+ private formatResponse<T>(data: GetCollectionRawResponse<T>): GetCollectionResponse<T> {
361
+ const contentlets = data.entity.jsonObjectView.contentlets;
362
+ const total = data.entity.resultsSize;
363
+
364
+ const mappedResponse: GetCollectionResponse<T> = {
365
+ contentlets,
366
+ total,
367
+ page: this.#page,
368
+ size: contentlets.length
369
+ };
370
+
371
+ return this.#sortBy
372
+ ? {
373
+ ...mappedResponse,
374
+ sortedBy: this.#sortBy
375
+ }
376
+ : mappedResponse;
377
+ }
378
+
218
379
  /**
219
380
  * Calls the content API to fetch the content.
220
381
  *
@@ -222,5 +383,35 @@ export declare class CollectionBuilder<T = unknown> {
222
383
  * @return {Promise<Response>} The fetch response.
223
384
  * @memberof CollectionBuilder
224
385
  */
225
- private fetch;
386
+ private fetch(): Promise<Response> {
387
+ const finalQuery = this.currentQuery
388
+ .field('languageId')
389
+ .equals(this.#languageId.toString())
390
+ .field('live')
391
+ .equals((!this.#draft).toString())
392
+ .build();
393
+
394
+ const sanitizedQuery = sanitizeQueryForContentType(finalQuery, this.#contentType);
395
+
396
+ const query = this.#rawQuery ? `${sanitizedQuery} ${this.#rawQuery}` : sanitizedQuery;
397
+
398
+ return fetch(this.url, {
399
+ ...this.#requestOptions,
400
+ method: 'POST',
401
+ headers: {
402
+ ...this.#requestOptions.headers,
403
+ 'Content-Type': 'application/json'
404
+ },
405
+ body: JSON.stringify({
406
+ query,
407
+ render: this.#render,
408
+ sort: this.sort,
409
+ limit: this.#limit,
410
+ offset: this.offset,
411
+ depth: this.#depth
412
+ //userId: This exist but we currently don't use it
413
+ //allCategoriesInfo: This exist but we currently don't use it
414
+ })
415
+ });
416
+ }
226
417
  }
@@ -1,6 +1,17 @@
1
1
  import { Field } from './Field';
2
2
  import { NotOperand } from './NotOperand';
3
3
  import { Operand } from './Operand';
4
+
5
+ import {
6
+ OPERAND,
7
+ buildExcludeField,
8
+ buildField,
9
+ buildNotOperand,
10
+ buildOperand,
11
+ buildRawEquals,
12
+ sanitizeQuery
13
+ } from '../utils';
14
+
4
15
  /**
5
16
  * 'Equal' Is a Typescript class that provides the ability to use terms in the lucene query string.
6
17
  * A term is a value used to search for a specific value in a document. It can be a word or a phrase.
@@ -10,10 +21,13 @@ import { Operand } from './Operand';
10
21
  * @export
11
22
  * @class Equal
12
23
  */
13
- export declare class Equals {
14
- #private;
15
- private query;
16
- constructor(query: string);
24
+ export class Equals {
25
+ #query = '';
26
+
27
+ constructor(private query: string) {
28
+ this.#query = this.query;
29
+ }
30
+
17
31
  /**
18
32
  * This method appends to the query a term that should be excluded in the search.
19
33
  *
@@ -27,7 +41,10 @@ export declare class Equals {
27
41
  * @return {*} {Field} - An instance of a Lucene Field. A field is a key used to search for a specific value in a document.
28
42
  * @memberof Equal
29
43
  */
30
- excludeField(field: string): Field;
44
+ excludeField(field: string): Field {
45
+ return buildExcludeField(this.#query, field);
46
+ }
47
+
31
48
  /**
32
49
  * This method appends to the query a field that should be included in the search.
33
50
  *
@@ -40,7 +57,10 @@ export declare class Equals {
40
57
  * @return {*} {Field} - An instance of a Lucene Field. A field is a key used to search for a specific value in a document.
41
58
  * @memberof Equal
42
59
  */
43
- field(field: string): Field;
60
+ field(field: string): Field {
61
+ return buildField(this.#query, field);
62
+ }
63
+
44
64
  /**
45
65
  * This method appends to the query an operand to use logic operators in the query.
46
66
  *
@@ -54,7 +74,10 @@ export declare class Equals {
54
74
  * @return {*} {Operand} - An instance of a Lucene Operand. An operand is a logical operator used to combine terms or phrases in a query.
55
75
  * @memberof Equal
56
76
  */
57
- or(): Operand;
77
+ or(): Operand {
78
+ return buildOperand(this.#query, OPERAND.OR);
79
+ }
80
+
58
81
  /**
59
82
  * This method appends to the query an operand to use logic operators in the query.
60
83
  *
@@ -67,7 +90,10 @@ export declare class Equals {
67
90
  * @return {*} {Operand} - An instance of a Lucene Operand. An operand is a logical operator used to combine terms or phrases in a query.
68
91
  * @memberof Equal
69
92
  */
70
- and(): Operand;
93
+ and(): Operand {
94
+ return buildOperand(this.#query, OPERAND.AND);
95
+ }
96
+
71
97
  /**
72
98
  * This method appends to the query an operand to use logic operators in the query.
73
99
  *
@@ -80,7 +106,10 @@ export declare class Equals {
80
106
  * @return {*} {NotOperand} - An instance of a Lucene Not Operand. A not operand is a logical operator used to exclude terms or phrases in a query.
81
107
  * @memberof Equal
82
108
  */
83
- not(): NotOperand;
109
+ not(): NotOperand {
110
+ return buildNotOperand(this.#query);
111
+ }
112
+
84
113
  /**
85
114
  * This method allows to pass a raw query string to the query builder.
86
115
  * This raw query should end in a Lucene Equal.
@@ -97,7 +126,10 @@ export declare class Equals {
97
126
  * @return {*} {Equal} - An instance of a Lucene Equal. A term is a value used to search for a specific value in a document.
98
127
  * @memberof QueryBuilder
99
128
  */
100
- raw(query: string): Equals;
129
+ raw(query: string): Equals {
130
+ return buildRawEquals(this.#query, query);
131
+ }
132
+
101
133
  /**
102
134
  * This method returns the final query string.
103
135
  *
@@ -110,5 +142,7 @@ export declare class Equals {
110
142
  * @return {*} {string} - The final query string.
111
143
  * @memberof Equal
112
144
  */
113
- build(): string;
145
+ build(): string {
146
+ return sanitizeQuery(this.#query);
147
+ }
114
148
  }
@@ -1,4 +1,7 @@
1
1
  import { Equals } from './Equals';
2
+
3
+ import { buildEquals } from '../utils';
4
+
2
5
  /**
3
6
  * The `Field` class is used to build a query with a specific field.
4
7
  * A Lucene Field is a key used to search for a specific value in a document.
@@ -6,15 +9,18 @@ import { Equals } from './Equals';
6
9
  * @export
7
10
  * @class Field
8
11
  */
9
- export declare class Field {
10
- #private;
11
- private query;
12
+ export class Field {
13
+ #query = '';
14
+
12
15
  /**
13
16
  * Creates an instance of the `Field` class.
14
17
  *
15
18
  * @param {string} query - The initial query string.
16
19
  */
17
- constructor(query: string);
20
+ constructor(private query: string) {
21
+ this.#query = this.query;
22
+ }
23
+
18
24
  /**
19
25
  * Appends a term to the query that should be included in the search.
20
26
  *
@@ -28,5 +34,7 @@ export declare class Field {
28
34
  * @return {Equals} - An instance of `Equals`.
29
35
  * @memberof Field
30
36
  */
31
- equals(term: string): Equals;
37
+ equals(term: string): Equals {
38
+ return buildEquals(this.#query, term);
39
+ }
32
40
  }
@@ -1,14 +1,20 @@
1
1
  import { Equals } from './Equals';
2
+
3
+ import { buildEquals } from '../utils';
4
+
2
5
  /**
3
6
  * 'NotOperand' Is a Typescript class that provides the ability to use the NOT operand in the lucene query string.
4
7
  *
5
8
  * @export
6
9
  * @class NotOperand
7
10
  */
8
- export declare class NotOperand {
9
- #private;
10
- private query;
11
- constructor(query: string);
11
+ export class NotOperand {
12
+ #query = '';
13
+
14
+ constructor(private query: string) {
15
+ this.#query = this.query;
16
+ }
17
+
12
18
  /**
13
19
  * This method appends to the query a term that should be included in the search.
14
20
  *
@@ -22,5 +28,7 @@ export declare class NotOperand {
22
28
  * @return {*} {Equals} - An instance of Equals.
23
29
  * @memberof NotOperand
24
30
  */
25
- equals(term: string): Equals;
31
+ equals(term: string): Equals {
32
+ return buildEquals(this.#query, term);
33
+ }
26
34
  }
@@ -1,5 +1,8 @@
1
1
  import { Equals } from './Equals';
2
2
  import { Field } from './Field';
3
+
4
+ import { buildExcludeField, buildField, buildEquals } from '../utils';
5
+
3
6
  /**
4
7
  * 'Operand' Is a Typescript class that provides the ability to use operands in the lucene query string.}
5
8
  * An operand is a logical operator used to join two or more conditions in a query.
@@ -7,10 +10,13 @@ import { Field } from './Field';
7
10
  * @export
8
11
  * @class Operand
9
12
  */
10
- export declare class Operand {
11
- #private;
12
- private query;
13
- constructor(query: string);
13
+ export class Operand {
14
+ #query = '';
15
+
16
+ constructor(private query: string) {
17
+ this.#query = this.query;
18
+ }
19
+
14
20
  /**
15
21
  * This method appends to the query a term that should be excluded in the search.
16
22
  *
@@ -20,7 +26,10 @@ export declare class Operand {
20
26
  * @return {*} {Field} - An instance of a Lucene Field. A field is a key used to search for a specific value in a document.
21
27
  * @memberof Operand
22
28
  */
23
- excludeField(field: string): Field;
29
+ excludeField(field: string): Field {
30
+ return buildExcludeField(this.#query, field);
31
+ }
32
+
24
33
  /**
25
34
  * This method appends to the query a field that should be included in the search.
26
35
  *
@@ -30,7 +39,10 @@ export declare class Operand {
30
39
  * @return {*} {Field} - An instance of a Lucene Field. A field is a key used to search for a specific value in a document.
31
40
  * @memberof Operand
32
41
  */
33
- field(field: string): Field;
42
+ field(field: string): Field {
43
+ return buildField(this.#query, field);
44
+ }
45
+
34
46
  /**
35
47
  * This method appends to the query a term that should be included in the search.
36
48
  *
@@ -40,5 +52,7 @@ export declare class Operand {
40
52
  * @return {*} {Equals} - An instance of Equals.
41
53
  * @memberof Operand
42
54
  */
43
- equals(term: string): Equals;
55
+ equals(term: string): Equals {
56
+ return buildEquals(this.#query, term);
57
+ }
44
58
  }