@dotcms/client 0.0.1-alpha.37 → 0.0.1-alpha.39
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/.eslintrc.json +18 -0
- package/README.md +4 -4
- package/jest.config.ts +15 -0
- package/package.json +3 -15
- package/project.json +72 -0
- package/src/index.ts +30 -0
- package/src/lib/client/content/builders/collection/collection.spec.ts +515 -0
- package/src/lib/client/content/builders/collection/collection.ts +416 -0
- package/src/lib/client/content/content-api.ts +139 -0
- package/src/lib/client/content/shared/const.ts +15 -0
- package/src/lib/client/content/shared/types.ts +155 -0
- package/src/lib/client/content/shared/utils.ts +28 -0
- package/src/lib/client/models/index.ts +19 -0
- package/src/lib/client/models/types.ts +14 -0
- package/src/lib/client/sdk-js-client.spec.ts +483 -0
- package/src/lib/client/sdk-js-client.ts +442 -0
- package/src/lib/editor/listeners/listeners.spec.ts +119 -0
- package/src/lib/editor/listeners/listeners.ts +223 -0
- package/src/lib/editor/models/{client.model.d.ts → client.model.ts} +19 -16
- package/src/lib/editor/models/{editor.model.d.ts → editor.model.ts} +9 -5
- package/src/lib/editor/models/{listeners.model.d.ts → listeners.model.ts} +9 -6
- package/src/lib/editor/sdk-editor-vtl.ts +31 -0
- package/src/lib/editor/sdk-editor.spec.ts +116 -0
- package/src/lib/editor/sdk-editor.ts +105 -0
- package/src/lib/editor/utils/editor.utils.spec.ts +206 -0
- package/src/lib/editor/utils/editor.utils.ts +258 -0
- package/src/lib/query-builder/lucene-syntax/{Equals.d.ts → Equals.ts} +83 -18
- package/src/lib/query-builder/lucene-syntax/Field.ts +40 -0
- package/src/lib/query-builder/lucene-syntax/{NotOperand.d.ts → NotOperand.ts} +18 -6
- package/src/lib/query-builder/lucene-syntax/{Operand.d.ts → Operand.ts} +21 -7
- package/src/lib/query-builder/sdk-query-builder.spec.ts +159 -0
- package/src/lib/query-builder/sdk-query-builder.ts +87 -0
- package/src/lib/query-builder/utils/index.ts +179 -0
- package/src/lib/utils/graphql/transforms.spec.ts +150 -0
- package/src/lib/utils/graphql/transforms.ts +99 -0
- package/src/lib/utils/page/common-utils.spec.ts +37 -0
- package/src/lib/utils/page/common-utils.ts +64 -0
- package/tsconfig.json +22 -0
- package/tsconfig.lib.json +13 -0
- package/tsconfig.spec.json +9 -0
- package/index.cjs.d.ts +0 -1
- package/index.cjs.default.js +0 -1
- package/index.cjs.js +0 -1490
- package/index.cjs.mjs +0 -2
- package/index.esm.d.ts +0 -1
- package/index.esm.js +0 -1481
- package/src/index.d.ts +0 -6
- package/src/lib/client/content/builders/collection/collection.d.ts +0 -148
- package/src/lib/client/content/content-api.d.ts +0 -78
- package/src/lib/client/content/shared/const.d.ts +0 -3
- package/src/lib/client/content/shared/types.d.ts +0 -62
- package/src/lib/client/content/shared/utils.d.ts +0 -12
- package/src/lib/client/models/index.d.ts +0 -1
- package/src/lib/client/models/types.d.ts +0 -5
- package/src/lib/client/sdk-js-client.d.ts +0 -193
- package/src/lib/editor/listeners/listeners.d.ts +0 -46
- package/src/lib/editor/sdk-editor-vtl.d.ts +0 -6
- package/src/lib/editor/sdk-editor.d.ts +0 -29
- package/src/lib/editor/utils/editor.utils.d.ts +0 -83
- package/src/lib/query-builder/lucene-syntax/Field.d.ts +0 -23
- package/src/lib/query-builder/sdk-query-builder.d.ts +0 -42
- package/src/lib/query-builder/utils/index.d.ts +0 -91
- package/src/lib/utils/graphql/transforms.d.ts +0 -11
- package/src/lib/utils/page/common-utils.d.ts +0 -11
- /package/src/lib/query-builder/lucene-syntax/{index.d.ts → index.ts} +0 -0
- /package/src/lib/utils/{index.d.ts → index.ts} +0 -0
|
@@ -1,22 +1,34 @@
|
|
|
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
|
|
9
|
-
#
|
|
10
|
-
|
|
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
|
*
|
|
15
|
-
*
|
|
21
|
+
* @example
|
|
22
|
+
* ```typescript
|
|
23
|
+
* const notOperand = new NotOperand("+myField");
|
|
24
|
+
* notOperand.equals("myValue");
|
|
25
|
+
* ```
|
|
16
26
|
*
|
|
17
27
|
* @param {string} term - The term that should be included in the search.
|
|
18
28
|
* @return {*} {Equals} - An instance of Equals.
|
|
19
29
|
* @memberof NotOperand
|
|
20
30
|
*/
|
|
21
|
-
equals(term: string): Equals
|
|
31
|
+
equals(term: string): Equals {
|
|
32
|
+
return buildEquals(this.#query, term);
|
|
33
|
+
}
|
|
22
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
|
|
11
|
-
#
|
|
12
|
-
|
|
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
|
}
|
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
import { QueryBuilder } from './sdk-query-builder';
|
|
2
|
+
|
|
3
|
+
describe('QueryBuilder', () => {
|
|
4
|
+
let queryBuilder: QueryBuilder;
|
|
5
|
+
|
|
6
|
+
beforeEach(() => {
|
|
7
|
+
queryBuilder = new QueryBuilder();
|
|
8
|
+
});
|
|
9
|
+
|
|
10
|
+
it('should return a query with a simple term', () => {
|
|
11
|
+
const queryForBlogs = queryBuilder.field('contentType').equals('Blog').build();
|
|
12
|
+
|
|
13
|
+
expect(queryForBlogs).toBe('+contentType:Blog');
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
it('should return a query with multiple fields with a simple term ', () => {
|
|
17
|
+
const queryForBlogsInSuperCoolSite = queryBuilder
|
|
18
|
+
.field('contentType')
|
|
19
|
+
.equals('Blog')
|
|
20
|
+
.field('conhost')
|
|
21
|
+
.equals('my-super-cool-site')
|
|
22
|
+
.build();
|
|
23
|
+
|
|
24
|
+
expect(queryForBlogsInSuperCoolSite).toBe('+contentType:Blog +conhost:my-super-cool-site');
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
it("should return a query with an 'OR' operand", () => {
|
|
28
|
+
const queryForBlogsOrArticles = queryBuilder
|
|
29
|
+
.field('contentType')
|
|
30
|
+
.equals('Blog')
|
|
31
|
+
.or()
|
|
32
|
+
.equals('Article')
|
|
33
|
+
.build();
|
|
34
|
+
|
|
35
|
+
expect(queryForBlogsOrArticles).toBe('+contentType:Blog OR Article');
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
it("should return a query with an 'AND' operand", () => {
|
|
39
|
+
const queryForBlogsAndArticles = queryBuilder
|
|
40
|
+
.field('contentType')
|
|
41
|
+
.equals('Blog')
|
|
42
|
+
.and()
|
|
43
|
+
.equals('Article')
|
|
44
|
+
.build();
|
|
45
|
+
|
|
46
|
+
expect(queryForBlogsAndArticles).toBe('+contentType:Blog AND Article');
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
it("should return a query with a 'NOT' operand", () => {
|
|
50
|
+
const queryForSkiingTripsNotInSwissAlps = queryBuilder
|
|
51
|
+
.field('summary')
|
|
52
|
+
.equals('Skiing trip')
|
|
53
|
+
.not()
|
|
54
|
+
.equals('Swiss Alps')
|
|
55
|
+
.build();
|
|
56
|
+
|
|
57
|
+
expect(queryForSkiingTripsNotInSwissAlps).toBe('+summary:"Skiing trip" NOT "Swiss Alps"');
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
it('should return a query with an exclusion field', () => {
|
|
61
|
+
const queryForFootballBlogsWithoutMessi = queryBuilder
|
|
62
|
+
.field('contentType')
|
|
63
|
+
.equals('Blog')
|
|
64
|
+
.field('title')
|
|
65
|
+
.equals('Football')
|
|
66
|
+
.excludeField('summary')
|
|
67
|
+
.equals('Lionel Messi')
|
|
68
|
+
.build();
|
|
69
|
+
|
|
70
|
+
expect(queryForFootballBlogsWithoutMessi).toBe(
|
|
71
|
+
'+contentType:Blog +title:Football -summary:"Lionel Messi"'
|
|
72
|
+
);
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
it('should build a raw query from the query builder', () => {
|
|
76
|
+
const queryForBlogs = queryBuilder
|
|
77
|
+
.raw('+summary:Snowboard')
|
|
78
|
+
.not()
|
|
79
|
+
.equals('Swiss Alps')
|
|
80
|
+
.field('contentType')
|
|
81
|
+
.equals('Blog')
|
|
82
|
+
.build();
|
|
83
|
+
|
|
84
|
+
expect(queryForBlogs).toBe('+summary:Snowboard NOT "Swiss Alps" +contentType:Blog');
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
it('should return a query with a raw query appended', () => {
|
|
88
|
+
const queryForBlogs = queryBuilder
|
|
89
|
+
.field('contentType')
|
|
90
|
+
.equals('Blog')
|
|
91
|
+
.raw('+summary:Snowboard')
|
|
92
|
+
.not()
|
|
93
|
+
.equals('Swiss Alps')
|
|
94
|
+
.build();
|
|
95
|
+
|
|
96
|
+
expect(queryForBlogs).toBe('+contentType:Blog +summary:Snowboard NOT "Swiss Alps"');
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
it('should return a query with a raw query created with a queryBuilder appended and a term', () => {
|
|
100
|
+
const anotherQueryBuilder = new QueryBuilder();
|
|
101
|
+
|
|
102
|
+
const snowboardInCanada = anotherQueryBuilder
|
|
103
|
+
.field('summary')
|
|
104
|
+
.equals('Snowboard')
|
|
105
|
+
.field('country')
|
|
106
|
+
.equals('Canada')
|
|
107
|
+
.build();
|
|
108
|
+
|
|
109
|
+
const queryForBlogs = queryBuilder
|
|
110
|
+
.field('contentType')
|
|
111
|
+
.equals('Blog')
|
|
112
|
+
.raw(snowboardInCanada)
|
|
113
|
+
.build();
|
|
114
|
+
|
|
115
|
+
expect(queryForBlogs).toBe('+contentType:Blog +summary:Snowboard +country:Canada');
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
it('should return a query with all possible combinations', () => {
|
|
119
|
+
const blogOrActivity = queryBuilder
|
|
120
|
+
.field('contentType')
|
|
121
|
+
.equals('Blog')
|
|
122
|
+
.or()
|
|
123
|
+
.equals('Activity');
|
|
124
|
+
|
|
125
|
+
const customIdSiteOrCoolSite = blogOrActivity
|
|
126
|
+
.field('conhost')
|
|
127
|
+
.equals('48190c8c-42c4-46af-8d1a-0cd5db894797')
|
|
128
|
+
.or()
|
|
129
|
+
.equals('cool-site');
|
|
130
|
+
|
|
131
|
+
const englishAndSpanish = customIdSiteOrCoolSite
|
|
132
|
+
.field('languageId')
|
|
133
|
+
.equals('1')
|
|
134
|
+
.and()
|
|
135
|
+
.equals('2');
|
|
136
|
+
|
|
137
|
+
const notDeleted = englishAndSpanish.field('deleted').equals('false');
|
|
138
|
+
|
|
139
|
+
const currentlyWorking = notDeleted.field('working').equals('true');
|
|
140
|
+
|
|
141
|
+
const defaultVariant = currentlyWorking.field('variant').equals('default');
|
|
142
|
+
|
|
143
|
+
const snowboardOutsideSwissAlps = defaultVariant
|
|
144
|
+
.field('title')
|
|
145
|
+
.equals('Snowboard')
|
|
146
|
+
.excludeField('summary')
|
|
147
|
+
.equals('Swiss Alps');
|
|
148
|
+
|
|
149
|
+
const writtenByJohnDoe = snowboardOutsideSwissAlps.field('authors').equals('John Doe');
|
|
150
|
+
|
|
151
|
+
const withoutJaneDoeHelp = writtenByJohnDoe.not().equals('Jane Doe');
|
|
152
|
+
|
|
153
|
+
const query = withoutJaneDoeHelp.build();
|
|
154
|
+
|
|
155
|
+
expect(query).toBe(
|
|
156
|
+
'+contentType:Blog OR Activity +conhost:48190c8c-42c4-46af-8d1a-0cd5db894797 OR cool-site +languageId:1 AND 2 +deleted:false +working:true +variant:default +title:Snowboard -summary:"Swiss Alps" +authors:"John Doe" NOT "Jane Doe"'
|
|
157
|
+
);
|
|
158
|
+
});
|
|
159
|
+
});
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import { Equals, Field } from './lucene-syntax/index';
|
|
2
|
+
import { buildExcludeField, buildField, buildRawEquals } from './utils';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* 'QueryBuilder' Is a Typescript class that provides the ability to build a query string using the Lucene syntax in a more readable way.
|
|
6
|
+
* @example
|
|
7
|
+
* ```ts
|
|
8
|
+
* const qb = new QueryBuilder();
|
|
9
|
+
* const query = qb
|
|
10
|
+
* .field('contentType')
|
|
11
|
+
* .equals('Blog')
|
|
12
|
+
* .field('conhost')
|
|
13
|
+
* .equals('my-super-cool-site')
|
|
14
|
+
* .build(); // Output: `+contentType:Blog +conhost:my-super-cool-site"`
|
|
15
|
+
* ```
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* ```ts
|
|
19
|
+
* const qb = new QueryBuilder();
|
|
20
|
+
* const query = qb
|
|
21
|
+
* .field('contentType')
|
|
22
|
+
* .equals('Blog')
|
|
23
|
+
* .field('title')
|
|
24
|
+
* .equals('Football')
|
|
25
|
+
* .excludeField('summary')
|
|
26
|
+
* .equals('Lionel Messi')
|
|
27
|
+
* .build(); // Output: `+contentType:Blog +title:Football -summary:"Lionel Messi"`
|
|
28
|
+
* ```
|
|
29
|
+
* @export
|
|
30
|
+
* @class QueryBuilder
|
|
31
|
+
*/
|
|
32
|
+
export class QueryBuilder {
|
|
33
|
+
#query = '';
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* This method appends to the query a field that should be included in the search.
|
|
37
|
+
*
|
|
38
|
+
* @example
|
|
39
|
+
* ```ts
|
|
40
|
+
* const qb = new QueryBuilder();
|
|
41
|
+
* qb.field("+myField: ", "myValue"); // Current query: "+myField: myValue"
|
|
42
|
+
* ```
|
|
43
|
+
*
|
|
44
|
+
* @param {string} field - The field that should be included in the search.
|
|
45
|
+
* @return {*} {Field} - An instance of a Lucene Field. A field is a key used to search for a specific value in a document.
|
|
46
|
+
* @memberof QueryBuilder
|
|
47
|
+
*/
|
|
48
|
+
field(field: string): Field {
|
|
49
|
+
return buildField(this.#query, field);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* This method appends to the query a field that should be excluded from the search.
|
|
54
|
+
*
|
|
55
|
+
* @example
|
|
56
|
+
* ```ts
|
|
57
|
+
* const qb = new QueryBuilder();
|
|
58
|
+
* qb.excludeField("myField").equals("myValue"); // Current query: "-myField: myValue"
|
|
59
|
+
* ```
|
|
60
|
+
*
|
|
61
|
+
* @param {string} field - The field that should be excluded from the search.
|
|
62
|
+
* @return {*} {Field} - An instance of a Lucene Exclude Field. An exclude field is a key used to exclude for a specific value in a document.
|
|
63
|
+
* @memberof QueryBuilder
|
|
64
|
+
*/
|
|
65
|
+
excludeField(field: string): Field {
|
|
66
|
+
return buildExcludeField(this.#query, field);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* This method allows to pass a raw query string to the query builder.
|
|
71
|
+
* This raw query should end in Equals.
|
|
72
|
+
* This method is useful when you want to append a complex query or an already written query to the query builder.
|
|
73
|
+
*
|
|
74
|
+
* @example
|
|
75
|
+
* ```ts
|
|
76
|
+
* const qb = new QueryBuilder();
|
|
77
|
+
* qb.raw("+myField: value AND (someOtherValue OR anotherValue)"); // Current query: "+myField: value AND (someOtherValue OR anotherValue)"
|
|
78
|
+
* ```
|
|
79
|
+
*
|
|
80
|
+
* @param {string} query - A raw query string.
|
|
81
|
+
* @return {*} {Equals} - An instance of Equals. A term is a value used to search for a specific value in a document.
|
|
82
|
+
* @memberof QueryBuilder
|
|
83
|
+
*/
|
|
84
|
+
raw(query: string): Equals {
|
|
85
|
+
return buildRawEquals(this.#query, query);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
import { Equals } from '../lucene-syntax/Equals';
|
|
2
|
+
import { Field } from '../lucene-syntax/Field';
|
|
3
|
+
import { NotOperand } from '../lucene-syntax/NotOperand';
|
|
4
|
+
import { Operand } from '../lucene-syntax/Operand';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Enum for common Operands
|
|
8
|
+
*
|
|
9
|
+
* @export
|
|
10
|
+
* @enum {number}
|
|
11
|
+
*/
|
|
12
|
+
export enum OPERAND {
|
|
13
|
+
OR = 'OR',
|
|
14
|
+
AND = 'AND',
|
|
15
|
+
NOT = 'NOT'
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* This function removes extra spaces from a string.
|
|
20
|
+
*
|
|
21
|
+
* @example
|
|
22
|
+
* ```ts
|
|
23
|
+
* sanitizeQuery(" my query "); // Output: "my query"
|
|
24
|
+
* ```
|
|
25
|
+
*
|
|
26
|
+
* @export
|
|
27
|
+
* @param {string} str
|
|
28
|
+
* @return {*} {string}
|
|
29
|
+
*/
|
|
30
|
+
export function sanitizeQuery(str: string): string {
|
|
31
|
+
return str.replace(/\s{2,}/g, ' ').trim();
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* This function sanitizes a term by adding quotes if it contains spaces.
|
|
36
|
+
* In lucene, a term with spaces should be enclosed in quotes.
|
|
37
|
+
*
|
|
38
|
+
* @example
|
|
39
|
+
* ```ts
|
|
40
|
+
* sanitizePhrases(`my term`); // Output: `"my term"`
|
|
41
|
+
* sanitizePhrases(`myterm`); // Output: `myterm`
|
|
42
|
+
* ```
|
|
43
|
+
*
|
|
44
|
+
* @export
|
|
45
|
+
* @param {string} term
|
|
46
|
+
* @return {*} {string}
|
|
47
|
+
*/
|
|
48
|
+
export function sanitizePhrases(term: string): string {
|
|
49
|
+
return term.includes(' ') ? `"${term}"` : term;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* This function builds a term to be used in a lucene query.
|
|
54
|
+
* We need to sanitize the term before adding it to the query.
|
|
55
|
+
*
|
|
56
|
+
* @example
|
|
57
|
+
* ```ts
|
|
58
|
+
* const equals = buildEquals("+myField: ", "myValue"); // Current query: "+myField: myValue"
|
|
59
|
+
* ```
|
|
60
|
+
*
|
|
61
|
+
* @export
|
|
62
|
+
* @param {string} query
|
|
63
|
+
* @param {string} term
|
|
64
|
+
* @return {*} {Equals}
|
|
65
|
+
*/
|
|
66
|
+
export function buildEquals(query: string, term: string): Equals {
|
|
67
|
+
const newQuery = query + sanitizePhrases(term);
|
|
68
|
+
|
|
69
|
+
return new Equals(newQuery);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* This function builds a term to be used in a lucene query.
|
|
74
|
+
* We need to sanitize the raw query before adding it to the query.
|
|
75
|
+
*
|
|
76
|
+
* @example
|
|
77
|
+
* ```ts
|
|
78
|
+
* const query = "+myField: myValue";
|
|
79
|
+
* const field = buildRawEquals(query, "-myField2: myValue2"); // Current query: "+myField: myValue -myField2: myValue"
|
|
80
|
+
* ```
|
|
81
|
+
*
|
|
82
|
+
* @export
|
|
83
|
+
* @param {string} query
|
|
84
|
+
* @param {string} raw
|
|
85
|
+
* @return {*} {Equals}
|
|
86
|
+
*/
|
|
87
|
+
export function buildRawEquals(query: string, raw: string): Equals {
|
|
88
|
+
const newQuery = query + ` ${raw}`;
|
|
89
|
+
|
|
90
|
+
return new Equals(sanitizeQuery(newQuery));
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* This function builds a field to be used in a lucene query.
|
|
95
|
+
* We need to format the field before adding it to the query.
|
|
96
|
+
*
|
|
97
|
+
* @example
|
|
98
|
+
* ```ts
|
|
99
|
+
* const field = buildField("+myField: ", "myValue"); // Current query: "+myField: myValue"
|
|
100
|
+
* ```
|
|
101
|
+
*
|
|
102
|
+
* @export
|
|
103
|
+
* @param {string} query
|
|
104
|
+
* @param {string} field
|
|
105
|
+
* @return {*} {Field}
|
|
106
|
+
*/
|
|
107
|
+
export function buildField(query: string, field: string): Field {
|
|
108
|
+
const newQuery = query + ` +${field}:`;
|
|
109
|
+
|
|
110
|
+
return new Field(newQuery);
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
/**
|
|
114
|
+
* This function builds an exclude field to be used in a lucene query.
|
|
115
|
+
* We need to format the field before adding it to the query.
|
|
116
|
+
*
|
|
117
|
+
* @example
|
|
118
|
+
* ```ts
|
|
119
|
+
* const query = "+myField: myValue";
|
|
120
|
+
* const field = buildExcludeField(query, "myField2"); // Current query: "+myField: myValue -myField2:"
|
|
121
|
+
* ```
|
|
122
|
+
*
|
|
123
|
+
* @export
|
|
124
|
+
* @param {string} query
|
|
125
|
+
* @param {string} field
|
|
126
|
+
* @return {*} {Field}
|
|
127
|
+
*/
|
|
128
|
+
export function buildExcludeField(query: string, field: string): Field {
|
|
129
|
+
const newQuery = query + ` -${field}:`;
|
|
130
|
+
|
|
131
|
+
return new Field(newQuery);
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
/**
|
|
135
|
+
* This function builds an operand to be used in a lucene query.
|
|
136
|
+
* We need to format the operand before adding it to the query.
|
|
137
|
+
*
|
|
138
|
+
* @example
|
|
139
|
+
* <caption>E.g. Using the AND operand</caption>
|
|
140
|
+
* ```ts
|
|
141
|
+
* const query = "+myField: myValue";
|
|
142
|
+
* const field = buildOperand(query, OPERAND.AND); // Current query: "+myField: myValue AND"
|
|
143
|
+
* ```
|
|
144
|
+
* @example
|
|
145
|
+
* <caption>E.g. Using the OR operand</caption>
|
|
146
|
+
* ```ts
|
|
147
|
+
* const query = "+myField: myValue";
|
|
148
|
+
* const field = buildOperand(query, OPERAND.OR); // Current query: "+myField: myValue OR"
|
|
149
|
+
* ```
|
|
150
|
+
* @export
|
|
151
|
+
* @param {string} query
|
|
152
|
+
* @param {OPERAND} operand
|
|
153
|
+
* @return {*} {Operand}
|
|
154
|
+
*/
|
|
155
|
+
export function buildOperand(query: string, operand: OPERAND): Operand {
|
|
156
|
+
const newQuery = query + ` ${operand} `;
|
|
157
|
+
|
|
158
|
+
return new Operand(newQuery);
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
/**
|
|
162
|
+
* This function builds a NOT operand to be used in a lucene query.
|
|
163
|
+
* We need to format the operand before adding it to the query.
|
|
164
|
+
*
|
|
165
|
+
* @example
|
|
166
|
+
* ```ts
|
|
167
|
+
* const query = "+myField: myValue";
|
|
168
|
+
* const field = buildNotOperand(query); // Current query: "+myField: myValue NOT"
|
|
169
|
+
* ```
|
|
170
|
+
*
|
|
171
|
+
* @export
|
|
172
|
+
* @param {string} query
|
|
173
|
+
* @return {*} {NotOperand}
|
|
174
|
+
*/
|
|
175
|
+
export function buildNotOperand(query: string): NotOperand {
|
|
176
|
+
const newQuery = query + ` ${OPERAND.NOT} `;
|
|
177
|
+
|
|
178
|
+
return new NotOperand(newQuery);
|
|
179
|
+
}
|
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
import { graphqlToPageEntity } from './transforms';
|
|
2
|
+
|
|
3
|
+
const GRAPHQL_RESPONSE_MOCK = {
|
|
4
|
+
page: {
|
|
5
|
+
title: 'test2',
|
|
6
|
+
url: '/test2',
|
|
7
|
+
seodescription: null,
|
|
8
|
+
containers: [
|
|
9
|
+
{
|
|
10
|
+
path: '//demo.dotcms.com/application/containers/default/',
|
|
11
|
+
identifier: '69b3d24d-7e80-4be6-b04a-d352d16493ee',
|
|
12
|
+
containerStructures: [
|
|
13
|
+
{
|
|
14
|
+
id: '77ec7720-bad8-431c-a0a3-6443fe87af73'
|
|
15
|
+
},
|
|
16
|
+
{
|
|
17
|
+
id: '1e5372c4-9fff-4793-ad8a-a52558d0d395'
|
|
18
|
+
},
|
|
19
|
+
{
|
|
20
|
+
id: '461b6fad-04a8-49ba-b75b-6634799bc289'
|
|
21
|
+
},
|
|
22
|
+
{
|
|
23
|
+
id: '57b4a9de-4765-4c57-8a05-2a0a317ec546'
|
|
24
|
+
},
|
|
25
|
+
{
|
|
26
|
+
id: '342a83bf-040a-45a2-a4bc-defb0f1bf4eb'
|
|
27
|
+
},
|
|
28
|
+
{
|
|
29
|
+
id: '91a955a0-5c97-4fc3-91dd-f894e2f3dc54'
|
|
30
|
+
},
|
|
31
|
+
{
|
|
32
|
+
id: '71ded7c9deb5b05452824bb42b9aa9d5'
|
|
33
|
+
},
|
|
34
|
+
{
|
|
35
|
+
id: '86a06a2e-ba40-43d4-a3ad-3a870d43bfc1'
|
|
36
|
+
},
|
|
37
|
+
{
|
|
38
|
+
id: '7673e601-26d4-4dbc-b6ad-7028599df656'
|
|
39
|
+
},
|
|
40
|
+
{
|
|
41
|
+
id: '313498a4-5b57-4d9e-8d32-ef2d30f9e867'
|
|
42
|
+
}
|
|
43
|
+
],
|
|
44
|
+
containerContentlets: [
|
|
45
|
+
{
|
|
46
|
+
uuid: 'uuid-1562770692396',
|
|
47
|
+
contentlets: [
|
|
48
|
+
{
|
|
49
|
+
identifier: 'd9444fa005a10d555318d8b014e474d4'
|
|
50
|
+
}
|
|
51
|
+
]
|
|
52
|
+
}
|
|
53
|
+
]
|
|
54
|
+
}
|
|
55
|
+
],
|
|
56
|
+
host: {
|
|
57
|
+
hostName: 'demo.dotcms.com'
|
|
58
|
+
},
|
|
59
|
+
layout: {
|
|
60
|
+
title: 'default-template'
|
|
61
|
+
},
|
|
62
|
+
template: {
|
|
63
|
+
identifier: '31f4c794-c769-4929-9d5d-7c383408c65c'
|
|
64
|
+
},
|
|
65
|
+
urlContentMap: {
|
|
66
|
+
identifier: '31f4c794-c769-4929-9d5d-7c383408c74d'
|
|
67
|
+
},
|
|
68
|
+
viewAs: {
|
|
69
|
+
mode: 'LIVE'
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
const MOCK_PAGE_ENTITY = {
|
|
75
|
+
containers: {
|
|
76
|
+
'//demo.dotcms.com/application/containers/default/': {
|
|
77
|
+
container: {
|
|
78
|
+
identifier: '69b3d24d-7e80-4be6-b04a-d352d16493ee',
|
|
79
|
+
path: '//demo.dotcms.com/application/containers/default/'
|
|
80
|
+
},
|
|
81
|
+
containerStructures: [
|
|
82
|
+
{
|
|
83
|
+
id: '77ec7720-bad8-431c-a0a3-6443fe87af73'
|
|
84
|
+
},
|
|
85
|
+
{
|
|
86
|
+
id: '1e5372c4-9fff-4793-ad8a-a52558d0d395'
|
|
87
|
+
},
|
|
88
|
+
{
|
|
89
|
+
id: '461b6fad-04a8-49ba-b75b-6634799bc289'
|
|
90
|
+
},
|
|
91
|
+
{
|
|
92
|
+
id: '57b4a9de-4765-4c57-8a05-2a0a317ec546'
|
|
93
|
+
},
|
|
94
|
+
{
|
|
95
|
+
id: '342a83bf-040a-45a2-a4bc-defb0f1bf4eb'
|
|
96
|
+
},
|
|
97
|
+
{
|
|
98
|
+
id: '91a955a0-5c97-4fc3-91dd-f894e2f3dc54'
|
|
99
|
+
},
|
|
100
|
+
{
|
|
101
|
+
id: '71ded7c9deb5b05452824bb42b9aa9d5'
|
|
102
|
+
},
|
|
103
|
+
{
|
|
104
|
+
id: '86a06a2e-ba40-43d4-a3ad-3a870d43bfc1'
|
|
105
|
+
},
|
|
106
|
+
{
|
|
107
|
+
id: '7673e601-26d4-4dbc-b6ad-7028599df656'
|
|
108
|
+
},
|
|
109
|
+
{
|
|
110
|
+
id: '313498a4-5b57-4d9e-8d32-ef2d30f9e867'
|
|
111
|
+
}
|
|
112
|
+
],
|
|
113
|
+
contentlets: {
|
|
114
|
+
'uuid-1562770692396': [
|
|
115
|
+
{
|
|
116
|
+
identifier: 'd9444fa005a10d555318d8b014e474d4'
|
|
117
|
+
}
|
|
118
|
+
]
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
},
|
|
122
|
+
layout: {
|
|
123
|
+
title: 'default-template'
|
|
124
|
+
},
|
|
125
|
+
page: {
|
|
126
|
+
host: {
|
|
127
|
+
hostName: 'demo.dotcms.com'
|
|
128
|
+
},
|
|
129
|
+
seodescription: null,
|
|
130
|
+
title: 'test2',
|
|
131
|
+
url: '/test2'
|
|
132
|
+
},
|
|
133
|
+
urlContentMap: {
|
|
134
|
+
identifier: '31f4c794-c769-4929-9d5d-7c383408c74d'
|
|
135
|
+
},
|
|
136
|
+
template: {
|
|
137
|
+
identifier: '31f4c794-c769-4929-9d5d-7c383408c65c'
|
|
138
|
+
},
|
|
139
|
+
viewAs: {
|
|
140
|
+
mode: 'LIVE'
|
|
141
|
+
}
|
|
142
|
+
};
|
|
143
|
+
|
|
144
|
+
describe('GraphQL Parser', () => {
|
|
145
|
+
it('should return the correct page entity', () => {
|
|
146
|
+
const pageEntity = graphqlToPageEntity(GRAPHQL_RESPONSE_MOCK);
|
|
147
|
+
|
|
148
|
+
expect(pageEntity).toEqual(MOCK_PAGE_ENTITY);
|
|
149
|
+
});
|
|
150
|
+
});
|