@dotcms/client 0.0.1-alpha.18 → 0.0.1-alpha.19
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 +1 -1
- package/src/index.d.ts +1 -0
- package/src/index.js +1 -0
- package/src/index.js.map +1 -1
- package/src/lib/client/content/builders/collection/collection.d.ts +146 -0
- package/src/lib/client/content/builders/collection/collection.js +254 -0
- package/src/lib/client/content/builders/collection/collection.js.map +1 -0
- package/src/lib/client/content/content-api.d.ts +64 -7
- package/src/lib/client/content/content-api.js +70 -7
- package/src/lib/client/content/content-api.js.map +1 -1
- package/src/lib/client/content/shared/types.d.ts +17 -2
- package/src/lib/utils/graphql-parser.d.ts +12 -0
- package/src/lib/utils/graphql-parser.js +43 -0
- package/src/lib/utils/graphql-parser.js.map +1 -0
- package/src/lib/utils/index.d.ts +1 -0
- package/src/lib/utils/index.js +2 -0
- package/src/lib/utils/index.js.map +1 -0
- package/src/lib/client/content/methods/get-collection/get-collection.d.ts +0 -119
- package/src/lib/client/content/methods/get-collection/get-collection.js +0 -229
- package/src/lib/client/content/methods/get-collection/get-collection.js.map +0 -1
package/package.json
CHANGED
package/src/index.d.ts
CHANGED
package/src/index.js
CHANGED
package/src/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../libs/sdk/client/src/index.ts"],"names":[],"mappings":"AAAA,cAAc,4BAA4B,CAAC;AAC3C,cAAc,yBAAyB,CAAC;AACxC,cAAc,kCAAkC,CAAC;AACjD,cAAc,kCAAkC,CAAC;AACjD,cAAc,uCAAuC,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../libs/sdk/client/src/index.ts"],"names":[],"mappings":"AAAA,cAAc,4BAA4B,CAAC;AAC3C,cAAc,yBAAyB,CAAC;AACxC,cAAc,kCAAkC,CAAC;AACjD,cAAc,kCAAkC,CAAC;AACjD,cAAc,uCAAuC,CAAC;AACtD,cAAc,aAAa,CAAC"}
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
import { ClientOptions } from '../../../sdk-js-client';
|
|
2
|
+
import { GetCollectionResponse, BuildQuery, SortBy, GetCollectionError, OnFullfilled, OnRejected } from '../../shared/types';
|
|
3
|
+
/**
|
|
4
|
+
* Creates a Builder to filter and fetch content from the content API for an specific content type
|
|
5
|
+
*
|
|
6
|
+
* @export
|
|
7
|
+
* @class CollectionBuilder
|
|
8
|
+
* @template T Represents the type of the content type to fetch. Defaults to unknown
|
|
9
|
+
*/
|
|
10
|
+
export declare class CollectionBuilder<T = unknown> {
|
|
11
|
+
#private;
|
|
12
|
+
constructor(requestOptions: ClientOptions, serverUrl: string, contentType: string);
|
|
13
|
+
/**
|
|
14
|
+
* This method returns the sort query in this format: field order, field order, ...
|
|
15
|
+
*
|
|
16
|
+
* @readonly
|
|
17
|
+
* @private
|
|
18
|
+
* @memberof CollectionBuilder
|
|
19
|
+
*/
|
|
20
|
+
private get sort();
|
|
21
|
+
private get offset();
|
|
22
|
+
private get url();
|
|
23
|
+
/**
|
|
24
|
+
* This method returns the current query built
|
|
25
|
+
*
|
|
26
|
+
* @readonly
|
|
27
|
+
* @private
|
|
28
|
+
* @memberof CollectionBuilder
|
|
29
|
+
*/
|
|
30
|
+
private get currentQuery();
|
|
31
|
+
/**
|
|
32
|
+
* Takes a language id and filters the content by that language
|
|
33
|
+
*
|
|
34
|
+
*
|
|
35
|
+
* @param {number | string} languageId The language id to filter the content by
|
|
36
|
+
* @return {CollectionBuilder} CollectionBuilder - A CollectionBuilder instance
|
|
37
|
+
* @memberof CollectionBuilder
|
|
38
|
+
*/
|
|
39
|
+
language(languageId: number | string): this;
|
|
40
|
+
/**
|
|
41
|
+
* The retrieved content will have the rendered HTML
|
|
42
|
+
*
|
|
43
|
+
* @return {CollectionBuilder} CollectionBuilder - A CollectionBuilder instance
|
|
44
|
+
* @memberof CollectionBuilder
|
|
45
|
+
*/
|
|
46
|
+
render(): this;
|
|
47
|
+
/**
|
|
48
|
+
* Takes an array of constrains to sort the content by field an specific order
|
|
49
|
+
*
|
|
50
|
+
* @example
|
|
51
|
+
* ```javascript
|
|
52
|
+
* // This will sort the content by title in ascending order
|
|
53
|
+
* // and by modDate in descending order
|
|
54
|
+
* const sortBy = [{ field: 'title', order: 'asc' }, { field: 'modDate', order: 'desc' }]
|
|
55
|
+
*
|
|
56
|
+
* client.content.getCollection("Blog").sortBy(sortBy)
|
|
57
|
+
*```
|
|
58
|
+
*
|
|
59
|
+
* @param {SortBy[]} sortBy Array of constrains to sort the content by
|
|
60
|
+
* @return {CollectionBuilder} CollectionBuilder - A CollectionBuilder instance
|
|
61
|
+
* @memberof CollectionBuilder
|
|
62
|
+
*/
|
|
63
|
+
sortBy(sortBy: SortBy[]): this;
|
|
64
|
+
/**
|
|
65
|
+
* Takes a number that represents the max amount of content to fetch
|
|
66
|
+
*
|
|
67
|
+
* `limit` is set to 10 by default
|
|
68
|
+
*
|
|
69
|
+
* @param {number} limit The max amount of content to fetch
|
|
70
|
+
* @return {CollectionBuilder} CollectionBuilder - A CollectionBuilder instance
|
|
71
|
+
* @memberof CollectionBuilder
|
|
72
|
+
*/
|
|
73
|
+
limit(limit: number): this;
|
|
74
|
+
/**
|
|
75
|
+
* Takes a number that represents the page to fetch
|
|
76
|
+
*
|
|
77
|
+
* @param {number} page The page to fetch
|
|
78
|
+
* @return {CollectionBuilder} CollectionBuilder - A CollectionBuilder instance
|
|
79
|
+
* @memberof CollectionBuilder
|
|
80
|
+
*/
|
|
81
|
+
page(page: number): this;
|
|
82
|
+
/**
|
|
83
|
+
* Takes a string that represents a {@link https://www.dotcms.com/docs/latest/content-search-syntax#Lucene Lucene Query} that is used to filter the content to fetch.
|
|
84
|
+
*
|
|
85
|
+
* The string is not validated, so be cautious when using it.
|
|
86
|
+
*
|
|
87
|
+
* @param {string} query A {@link https://www.dotcms.com/docs/latest/content-search-syntax#Lucene Lucene Query} String
|
|
88
|
+
* @return {CollectionBuilder} CollectionBuilder - A CollectionBuilder instance
|
|
89
|
+
* @memberof CollectionBuilder
|
|
90
|
+
*/
|
|
91
|
+
query(query: string): this;
|
|
92
|
+
/**
|
|
93
|
+
* Takes a function that recieves a QueryBuilder to buid a query for content filtering.
|
|
94
|
+
* @example
|
|
95
|
+
*```javascript
|
|
96
|
+
* // This will filter the content by title equals 'Hello World' or 'Hello World 2'
|
|
97
|
+
* client.content.getCollection("Activity").query((queryBuilder) =>
|
|
98
|
+
* queryBuilder.field('title').equals('Hello World').or().equals('Hello World 2')
|
|
99
|
+
* );
|
|
100
|
+
*```
|
|
101
|
+
* @param {BuildQuery} buildQuery A function that receives a QueryBuilder instance and returns a valid query
|
|
102
|
+
* @return {CollectionBuilder} CollectionBuilder - A CollectionBuilder instance
|
|
103
|
+
* @memberof CollectionBuilder
|
|
104
|
+
*/
|
|
105
|
+
query(buildQuery: BuildQuery): this;
|
|
106
|
+
/**
|
|
107
|
+
* The retrieved content will be draft content
|
|
108
|
+
*
|
|
109
|
+
* The default value is false to fetch content that is not on draft
|
|
110
|
+
*
|
|
111
|
+
* @return {CollectionBuilder} CollectionBuilder - A CollectionBuilder instance
|
|
112
|
+
* @memberof CollectionBuilder
|
|
113
|
+
*/
|
|
114
|
+
draft(): this;
|
|
115
|
+
/**
|
|
116
|
+
* Takes a string that represents a variant ID of content created with the {@link https://www.dotcms.com/docs/latest/experiments-and-a-b-testing A/B Testing} feature
|
|
117
|
+
*
|
|
118
|
+
* `variantId` defaults to "DEFAULT" to fetch content that is not part of an A/B test
|
|
119
|
+
*
|
|
120
|
+
* @param {string} variantId A string that represents a variant ID
|
|
121
|
+
* @return {CollectionBuilder} CollectionBuilder - A CollectionBuilder instance
|
|
122
|
+
* @memberof CollectionBuilder
|
|
123
|
+
*/
|
|
124
|
+
variant(variantId: string): this;
|
|
125
|
+
/**
|
|
126
|
+
* Takes a number that represents the depth of the relationships of a content
|
|
127
|
+
*
|
|
128
|
+
* The `depth` is set to 0 by default and the max supported value is 3.
|
|
129
|
+
*
|
|
130
|
+
* @param {number} depth The depth of the relationships of a content
|
|
131
|
+
* @return {CollectionBuilder} CollectionBuilder - A CollectionBuilder instance
|
|
132
|
+
* @memberof CollectionBuilder
|
|
133
|
+
*/
|
|
134
|
+
depth(depth: number): this;
|
|
135
|
+
/**
|
|
136
|
+
* Executes the fetch and returns a promise that resolves to the content or rejects to an error
|
|
137
|
+
*
|
|
138
|
+
* @param {OnFullfilled} [onfulfilled] A callback that is called when the fetch is successful
|
|
139
|
+
* @param {OnRejected} [onrejected] A callback that is called when the fetch fails
|
|
140
|
+
* @return {Promise<GetCollectionResponse<T> | GetCollectionError>} A promise that resolves to the content or rejects to an error
|
|
141
|
+
* @memberof CollectionBuilder
|
|
142
|
+
*/
|
|
143
|
+
then(onfulfilled?: OnFullfilled<T>, onrejected?: OnRejected): Promise<GetCollectionResponse<T> | GetCollectionError>;
|
|
144
|
+
private formatResponse;
|
|
145
|
+
private fetch;
|
|
146
|
+
}
|
|
@@ -0,0 +1,254 @@
|
|
|
1
|
+
var _CollectionBuilder_page, _CollectionBuilder_limit, _CollectionBuilder_depth, _CollectionBuilder_render, _CollectionBuilder_sortBy, _CollectionBuilder_contentType, _CollectionBuilder_defaultQuery, _CollectionBuilder_query, _CollectionBuilder_rawQuery, _CollectionBuilder_serverUrl, _CollectionBuilder_requestOptions;
|
|
2
|
+
import { __classPrivateFieldGet, __classPrivateFieldSet } from "tslib";
|
|
3
|
+
import { Equals } from '../../../../query-builder/lucene-syntax';
|
|
4
|
+
import { QueryBuilder } from '../../../../query-builder/sdk-query-builder';
|
|
5
|
+
import { CONTENT_API_URL } from '../../shared/const';
|
|
6
|
+
import { sanitizeQueryForContentType } from '../../shared/utils';
|
|
7
|
+
/**
|
|
8
|
+
* Creates a Builder to filter and fetch content from the content API for an specific content type
|
|
9
|
+
*
|
|
10
|
+
* @export
|
|
11
|
+
* @class CollectionBuilder
|
|
12
|
+
* @template T Represents the type of the content type to fetch. Defaults to unknown
|
|
13
|
+
*/
|
|
14
|
+
export class CollectionBuilder {
|
|
15
|
+
constructor(requestOptions, serverUrl, contentType) {
|
|
16
|
+
_CollectionBuilder_page.set(this, 1);
|
|
17
|
+
_CollectionBuilder_limit.set(this, 10);
|
|
18
|
+
_CollectionBuilder_depth.set(this, 0);
|
|
19
|
+
_CollectionBuilder_render.set(this, false);
|
|
20
|
+
_CollectionBuilder_sortBy.set(this, void 0);
|
|
21
|
+
_CollectionBuilder_contentType.set(this, void 0);
|
|
22
|
+
_CollectionBuilder_defaultQuery.set(this, void 0);
|
|
23
|
+
_CollectionBuilder_query.set(this, void 0);
|
|
24
|
+
_CollectionBuilder_rawQuery.set(this, void 0);
|
|
25
|
+
_CollectionBuilder_serverUrl.set(this, void 0);
|
|
26
|
+
_CollectionBuilder_requestOptions.set(this, void 0);
|
|
27
|
+
__classPrivateFieldSet(this, _CollectionBuilder_requestOptions, requestOptions, "f");
|
|
28
|
+
__classPrivateFieldSet(this, _CollectionBuilder_serverUrl, serverUrl, "f");
|
|
29
|
+
__classPrivateFieldSet(this, _CollectionBuilder_contentType, contentType, "f");
|
|
30
|
+
// We need to build the default query with the contentType field
|
|
31
|
+
__classPrivateFieldSet(this, _CollectionBuilder_defaultQuery, new QueryBuilder().field('contentType').equals(__classPrivateFieldGet(this, _CollectionBuilder_contentType, "f")), "f");
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* This method returns the sort query in this format: field order, field order, ...
|
|
35
|
+
*
|
|
36
|
+
* @readonly
|
|
37
|
+
* @private
|
|
38
|
+
* @memberof CollectionBuilder
|
|
39
|
+
*/
|
|
40
|
+
get sort() {
|
|
41
|
+
return __classPrivateFieldGet(this, _CollectionBuilder_sortBy, "f")?.map((sort) => `${sort.field} ${sort.order}`).join(',');
|
|
42
|
+
}
|
|
43
|
+
get offset() {
|
|
44
|
+
// This could end in an empty response
|
|
45
|
+
return __classPrivateFieldGet(this, _CollectionBuilder_limit, "f") * (__classPrivateFieldGet(this, _CollectionBuilder_page, "f") - 1);
|
|
46
|
+
}
|
|
47
|
+
get url() {
|
|
48
|
+
return `${__classPrivateFieldGet(this, _CollectionBuilder_serverUrl, "f")}${CONTENT_API_URL}`;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* This method returns the current query built
|
|
52
|
+
*
|
|
53
|
+
* @readonly
|
|
54
|
+
* @private
|
|
55
|
+
* @memberof CollectionBuilder
|
|
56
|
+
*/
|
|
57
|
+
get currentQuery() {
|
|
58
|
+
return __classPrivateFieldGet(this, _CollectionBuilder_query, "f") ?? __classPrivateFieldGet(this, _CollectionBuilder_defaultQuery, "f");
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Takes a language id and filters the content by that language
|
|
62
|
+
*
|
|
63
|
+
*
|
|
64
|
+
* @param {number | string} languageId The language id to filter the content by
|
|
65
|
+
* @return {CollectionBuilder} CollectionBuilder - A CollectionBuilder instance
|
|
66
|
+
* @memberof CollectionBuilder
|
|
67
|
+
*/
|
|
68
|
+
language(languageId) {
|
|
69
|
+
__classPrivateFieldSet(this, _CollectionBuilder_query, this.currentQuery.field('languageId').equals(languageId.toString()), "f");
|
|
70
|
+
return this;
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* The retrieved content will have the rendered HTML
|
|
74
|
+
*
|
|
75
|
+
* @return {CollectionBuilder} CollectionBuilder - A CollectionBuilder instance
|
|
76
|
+
* @memberof CollectionBuilder
|
|
77
|
+
*/
|
|
78
|
+
render() {
|
|
79
|
+
__classPrivateFieldSet(this, _CollectionBuilder_render, true, "f");
|
|
80
|
+
return this;
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Takes an array of constrains to sort the content by field an specific order
|
|
84
|
+
*
|
|
85
|
+
* @example
|
|
86
|
+
* ```javascript
|
|
87
|
+
* // This will sort the content by title in ascending order
|
|
88
|
+
* // and by modDate in descending order
|
|
89
|
+
* const sortBy = [{ field: 'title', order: 'asc' }, { field: 'modDate', order: 'desc' }]
|
|
90
|
+
*
|
|
91
|
+
* client.content.getCollection("Blog").sortBy(sortBy)
|
|
92
|
+
*```
|
|
93
|
+
*
|
|
94
|
+
* @param {SortBy[]} sortBy Array of constrains to sort the content by
|
|
95
|
+
* @return {CollectionBuilder} CollectionBuilder - A CollectionBuilder instance
|
|
96
|
+
* @memberof CollectionBuilder
|
|
97
|
+
*/
|
|
98
|
+
sortBy(sortBy) {
|
|
99
|
+
__classPrivateFieldSet(this, _CollectionBuilder_sortBy, sortBy, "f");
|
|
100
|
+
return this;
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* Takes a number that represents the max amount of content to fetch
|
|
104
|
+
*
|
|
105
|
+
* `limit` is set to 10 by default
|
|
106
|
+
*
|
|
107
|
+
* @param {number} limit The max amount of content to fetch
|
|
108
|
+
* @return {CollectionBuilder} CollectionBuilder - A CollectionBuilder instance
|
|
109
|
+
* @memberof CollectionBuilder
|
|
110
|
+
*/
|
|
111
|
+
limit(limit) {
|
|
112
|
+
__classPrivateFieldSet(this, _CollectionBuilder_limit, limit, "f");
|
|
113
|
+
return this;
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* Takes a number that represents the page to fetch
|
|
117
|
+
*
|
|
118
|
+
* @param {number} page The page to fetch
|
|
119
|
+
* @return {CollectionBuilder} CollectionBuilder - A CollectionBuilder instance
|
|
120
|
+
* @memberof CollectionBuilder
|
|
121
|
+
*/
|
|
122
|
+
page(page) {
|
|
123
|
+
__classPrivateFieldSet(this, _CollectionBuilder_page, page, "f");
|
|
124
|
+
return this;
|
|
125
|
+
}
|
|
126
|
+
query(arg) {
|
|
127
|
+
if (typeof arg === 'string') {
|
|
128
|
+
__classPrivateFieldSet(this, _CollectionBuilder_rawQuery, arg, "f");
|
|
129
|
+
return this;
|
|
130
|
+
}
|
|
131
|
+
if (typeof arg !== 'function') {
|
|
132
|
+
throw new Error(`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.`);
|
|
133
|
+
}
|
|
134
|
+
const builtQuery = arg(new QueryBuilder());
|
|
135
|
+
// This can be use in Javascript so we cannot rely on the type checking
|
|
136
|
+
if (builtQuery instanceof Equals) {
|
|
137
|
+
__classPrivateFieldSet(this, _CollectionBuilder_query, builtQuery.raw(this.currentQuery.build()), "f");
|
|
138
|
+
}
|
|
139
|
+
else {
|
|
140
|
+
throw new Error('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.');
|
|
141
|
+
}
|
|
142
|
+
return this;
|
|
143
|
+
}
|
|
144
|
+
/**
|
|
145
|
+
* The retrieved content will be draft content
|
|
146
|
+
*
|
|
147
|
+
* The default value is false to fetch content that is not on draft
|
|
148
|
+
*
|
|
149
|
+
* @return {CollectionBuilder} CollectionBuilder - A CollectionBuilder instance
|
|
150
|
+
* @memberof CollectionBuilder
|
|
151
|
+
*/
|
|
152
|
+
draft() {
|
|
153
|
+
__classPrivateFieldSet(this, _CollectionBuilder_query, this.currentQuery.field('live').equals(false.toString()), "f");
|
|
154
|
+
return this;
|
|
155
|
+
}
|
|
156
|
+
/**
|
|
157
|
+
* Takes a string that represents a variant ID of content created with the {@link https://www.dotcms.com/docs/latest/experiments-and-a-b-testing A/B Testing} feature
|
|
158
|
+
*
|
|
159
|
+
* `variantId` defaults to "DEFAULT" to fetch content that is not part of an A/B test
|
|
160
|
+
*
|
|
161
|
+
* @param {string} variantId A string that represents a variant ID
|
|
162
|
+
* @return {CollectionBuilder} CollectionBuilder - A CollectionBuilder instance
|
|
163
|
+
* @memberof CollectionBuilder
|
|
164
|
+
*/
|
|
165
|
+
variant(variantId) {
|
|
166
|
+
__classPrivateFieldSet(this, _CollectionBuilder_query, this.currentQuery.field('variant').equals(variantId), "f");
|
|
167
|
+
return this;
|
|
168
|
+
}
|
|
169
|
+
/**
|
|
170
|
+
* Takes a number that represents the depth of the relationships of a content
|
|
171
|
+
*
|
|
172
|
+
* The `depth` is set to 0 by default and the max supported value is 3.
|
|
173
|
+
*
|
|
174
|
+
* @param {number} depth The depth of the relationships of a content
|
|
175
|
+
* @return {CollectionBuilder} CollectionBuilder - A CollectionBuilder instance
|
|
176
|
+
* @memberof CollectionBuilder
|
|
177
|
+
*/
|
|
178
|
+
depth(depth) {
|
|
179
|
+
if (depth < 0 || depth > 3) {
|
|
180
|
+
throw new Error('Depth value must be between 0 and 3');
|
|
181
|
+
}
|
|
182
|
+
__classPrivateFieldSet(this, _CollectionBuilder_depth, depth, "f");
|
|
183
|
+
return this;
|
|
184
|
+
}
|
|
185
|
+
/**
|
|
186
|
+
* Executes the fetch and returns a promise that resolves to the content or rejects to an error
|
|
187
|
+
*
|
|
188
|
+
* @param {OnFullfilled} [onfulfilled] A callback that is called when the fetch is successful
|
|
189
|
+
* @param {OnRejected} [onrejected] A callback that is called when the fetch fails
|
|
190
|
+
* @return {Promise<GetCollectionResponse<T> | GetCollectionError>} A promise that resolves to the content or rejects to an error
|
|
191
|
+
* @memberof CollectionBuilder
|
|
192
|
+
*/
|
|
193
|
+
then(onfulfilled, onrejected) {
|
|
194
|
+
return this.fetch().then(async (response) => {
|
|
195
|
+
const data = await response.json();
|
|
196
|
+
if (response.ok) {
|
|
197
|
+
const formattedResponse = this.formatResponse(data);
|
|
198
|
+
const finalResponse = typeof onfulfilled === 'function'
|
|
199
|
+
? onfulfilled(formattedResponse)
|
|
200
|
+
: formattedResponse;
|
|
201
|
+
return finalResponse;
|
|
202
|
+
}
|
|
203
|
+
else {
|
|
204
|
+
// Fetch does not reject on server errors, so we only have to bubble up the error as a normal fetch
|
|
205
|
+
return {
|
|
206
|
+
status: response.status,
|
|
207
|
+
...data
|
|
208
|
+
};
|
|
209
|
+
}
|
|
210
|
+
}, onrejected);
|
|
211
|
+
}
|
|
212
|
+
// Formats the response to the desired format
|
|
213
|
+
formatResponse(data) {
|
|
214
|
+
const contentlets = data.entity.jsonObjectView.contentlets;
|
|
215
|
+
const total = data.entity.resultsSize;
|
|
216
|
+
const mappedResponse = {
|
|
217
|
+
contentlets,
|
|
218
|
+
total,
|
|
219
|
+
page: __classPrivateFieldGet(this, _CollectionBuilder_page, "f"),
|
|
220
|
+
size: contentlets.length
|
|
221
|
+
};
|
|
222
|
+
return __classPrivateFieldGet(this, _CollectionBuilder_sortBy, "f")
|
|
223
|
+
? {
|
|
224
|
+
...mappedResponse,
|
|
225
|
+
sortedBy: __classPrivateFieldGet(this, _CollectionBuilder_sortBy, "f")
|
|
226
|
+
}
|
|
227
|
+
: mappedResponse;
|
|
228
|
+
}
|
|
229
|
+
// Calls the content API to fetch the content
|
|
230
|
+
fetch() {
|
|
231
|
+
const sanitizedQuery = sanitizeQueryForContentType(this.currentQuery.build(), __classPrivateFieldGet(this, _CollectionBuilder_contentType, "f"));
|
|
232
|
+
const query = __classPrivateFieldGet(this, _CollectionBuilder_rawQuery, "f") ? `${sanitizedQuery} ${__classPrivateFieldGet(this, _CollectionBuilder_rawQuery, "f")}` : sanitizedQuery;
|
|
233
|
+
return fetch(this.url, {
|
|
234
|
+
...__classPrivateFieldGet(this, _CollectionBuilder_requestOptions, "f"),
|
|
235
|
+
method: 'POST',
|
|
236
|
+
headers: {
|
|
237
|
+
...__classPrivateFieldGet(this, _CollectionBuilder_requestOptions, "f").headers,
|
|
238
|
+
'Content-Type': 'application/json'
|
|
239
|
+
},
|
|
240
|
+
body: JSON.stringify({
|
|
241
|
+
query,
|
|
242
|
+
render: __classPrivateFieldGet(this, _CollectionBuilder_render, "f"),
|
|
243
|
+
sort: this.sort,
|
|
244
|
+
limit: __classPrivateFieldGet(this, _CollectionBuilder_limit, "f"),
|
|
245
|
+
offset: this.offset,
|
|
246
|
+
depth: __classPrivateFieldGet(this, _CollectionBuilder_depth, "f")
|
|
247
|
+
//userId: This exist but we currently don't use it
|
|
248
|
+
//allCategoriesInfo: This exist but we currently don't use it
|
|
249
|
+
})
|
|
250
|
+
});
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
_CollectionBuilder_page = new WeakMap(), _CollectionBuilder_limit = new WeakMap(), _CollectionBuilder_depth = new WeakMap(), _CollectionBuilder_render = new WeakMap(), _CollectionBuilder_sortBy = new WeakMap(), _CollectionBuilder_contentType = new WeakMap(), _CollectionBuilder_defaultQuery = new WeakMap(), _CollectionBuilder_query = new WeakMap(), _CollectionBuilder_rawQuery = new WeakMap(), _CollectionBuilder_serverUrl = new WeakMap(), _CollectionBuilder_requestOptions = new WeakMap();
|
|
254
|
+
//# sourceMappingURL=collection.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"collection.js","sourceRoot":"","sources":["../../../../../../../../../../libs/sdk/client/src/lib/client/content/builders/collection/collection.ts"],"names":[],"mappings":";;AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,yCAAyC,CAAC;AACjE,OAAO,EAAE,YAAY,EAAE,MAAM,6CAA6C,CAAC;AAE3E,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AAUrD,OAAO,EAAE,2BAA2B,EAAE,MAAM,oBAAoB,CAAC;AAEjE;;;;;;GAMG;AACH,MAAM,OAAO,iBAAiB;IAc1B,YAAY,cAA6B,EAAE,SAAiB,EAAE,WAAmB;QAbjF,kCAAQ,CAAC,EAAC;QACV,mCAAS,EAAE,EAAC;QACZ,mCAAS,CAAC,EAAC;QACX,oCAAU,KAAK,EAAC;QAChB,4CAAmB;QACnB,iDAAqB;QACrB,kDAAsB;QACtB,2CAAgB;QAChB,8CAAmB;QAEnB,+CAAmB;QACnB,oDAA+B;QAG3B,uBAAA,IAAI,qCAAmB,cAAc,MAAA,CAAC;QACtC,uBAAA,IAAI,gCAAc,SAAS,MAAA,CAAC;QAE5B,uBAAA,IAAI,kCAAgB,WAAW,MAAA,CAAC;QAEhC,gEAAgE;QAChE,uBAAA,IAAI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,uBAAA,IAAI,iCAAQ;aACzB;YACH,CAAC,CAAC,cAAc,CAAC;IACzB,CAAC;IAED,6CAA6C;IACrC,KAAK;QACT,MAAM,cAAc,GAAG,2BAA2B,CAC9C,IAAI,CAAC,YAAY,CAAC,KAAK,EAAE,EACzB,uBAAA,IAAI,sCAAa,CACpB,CAAC;QAEF,MAAM,KAAK,GAAG,uBAAA,IAAI,mCAAU,CAAC,CAAC,CAAC,GAAG,cAAc,IAAI,uBAAA,IAAI,mCAAU,EAAE,CAAC,CAAC,CAAC,cAAc,CAAC;QAEtF,OAAO,KAAK,CAAC,IAAI,CAAC,GAAG,EAAE;YACnB,GAAG,uBAAA,IAAI,yCAAgB;YACvB,MAAM,EAAE,MAAM;YACd,OAAO,EAAE;gBACL,GAAG,uBAAA,IAAI,yCAAgB,CAAC,OAAO;gBAC/B,cAAc,EAAE,kBAAkB;aACrC;YACD,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC;gBACjB,KAAK;gBACL,MAAM,EAAE,uBAAA,IAAI,iCAAQ;gBACpB,IAAI,EAAE,IAAI,CAAC,IAAI;gBACf,KAAK,EAAE,uBAAA,IAAI,gCAAO;gBAClB,MAAM,EAAE,IAAI,CAAC,MAAM;gBACnB,KAAK,EAAE,uBAAA,IAAI,gCAAO;gBAClB,kDAAkD;gBAClD,6DAA6D;aAChE,CAAC;SACL,CAAC,CAAC;IACP,CAAC;CACJ"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { CollectionBuilder } from './builders/collection/collection';
|
|
2
2
|
import { ClientOptions } from '../sdk-js-client';
|
|
3
3
|
/**
|
|
4
4
|
* Content classs exposes the content api methods
|
|
@@ -7,15 +7,72 @@ import { ClientOptions } from '../sdk-js-client';
|
|
|
7
7
|
* @class Content
|
|
8
8
|
*/
|
|
9
9
|
export declare class Content {
|
|
10
|
-
private
|
|
11
|
-
private serverUrl;
|
|
10
|
+
#private;
|
|
12
11
|
constructor(requestOptions: ClientOptions, serverUrl: string);
|
|
13
12
|
/**
|
|
14
|
-
*
|
|
13
|
+
* Takes a content type and returns a builder to filter and fetch the collection
|
|
15
14
|
*
|
|
16
|
-
* @
|
|
17
|
-
*
|
|
15
|
+
* @example
|
|
16
|
+
* ```javascript
|
|
17
|
+
* // Using await and async
|
|
18
|
+
* const collectionResponse = await client.content
|
|
19
|
+
* .getCollection('Blog')
|
|
20
|
+
* .limit(10)
|
|
21
|
+
* .page(2)
|
|
22
|
+
* .sortBy([{ field: 'title', order: 'asc' }])
|
|
23
|
+
* .query((queryBuilder) => queryBuilder.field('author').equals('John Doe'))
|
|
24
|
+
* .depth(1);
|
|
25
|
+
* ```
|
|
26
|
+
* @example
|
|
27
|
+
* ```javascript
|
|
28
|
+
* // Using then and catch
|
|
29
|
+
* client.content
|
|
30
|
+
* .getCollection('Blog')
|
|
31
|
+
* .limit(10)
|
|
32
|
+
* .page(2)
|
|
33
|
+
* .sortBy([{ field: 'title', order: 'asc' }])
|
|
34
|
+
* .query((queryBuilder) => queryBuilder.field('author').equals('John Doe'))
|
|
35
|
+
* .depth(1)
|
|
36
|
+
* .then((response) => {
|
|
37
|
+
* console.log(response.contentlets);
|
|
38
|
+
* })
|
|
39
|
+
* .catch((error) => {
|
|
40
|
+
* console.error(error);
|
|
41
|
+
* });
|
|
42
|
+
* ```
|
|
43
|
+
* @example
|
|
44
|
+
* ```typescript
|
|
45
|
+
* // Using an specific type for your content
|
|
46
|
+
*
|
|
47
|
+
* type Blog = {
|
|
48
|
+
* summary: string;
|
|
49
|
+
* author: string;
|
|
50
|
+
* title: string;
|
|
51
|
+
* };
|
|
52
|
+
*
|
|
53
|
+
* client.content
|
|
54
|
+
* .getCollection<Blog>('Blog')
|
|
55
|
+
* .limit(10)
|
|
56
|
+
* .page(2)
|
|
57
|
+
* .sortBy([{ field: 'title', order: 'asc' }])
|
|
58
|
+
* .query((queryBuilder) => queryBuilder.field('author').equals('John Doe'))
|
|
59
|
+
* .depth(1)
|
|
60
|
+
* .then((response) => {
|
|
61
|
+
* response.contentlets.forEach((blog) => {
|
|
62
|
+
* console.log(blog.title);
|
|
63
|
+
* console.log(blog.author);
|
|
64
|
+
* console.log(blog.summary);
|
|
65
|
+
* });
|
|
66
|
+
* })
|
|
67
|
+
* .catch((error) => {
|
|
68
|
+
* console.error(error);
|
|
69
|
+
* });
|
|
70
|
+
* ```
|
|
71
|
+
*
|
|
72
|
+
* @param {string} contentType The content type to get the collection
|
|
73
|
+
* @return {CollectionBuilder} CollectionBuilder to filter and fetch the collection
|
|
74
|
+
* @template T Represents the type of the content type to fetch. Defaults to unknown
|
|
18
75
|
* @memberof Content
|
|
19
76
|
*/
|
|
20
|
-
getCollection(contentType: string):
|
|
77
|
+
getCollection<T = unknown>(contentType: string): CollectionBuilder<T>;
|
|
21
78
|
}
|
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
|
|
1
|
+
var _Content_requestOptions, _Content_serverUrl;
|
|
2
|
+
import { __classPrivateFieldGet, __classPrivateFieldSet } from "tslib";
|
|
3
|
+
import { CollectionBuilder } from './builders/collection/collection';
|
|
2
4
|
/**
|
|
3
5
|
* Content classs exposes the content api methods
|
|
4
6
|
*
|
|
@@ -7,18 +9,79 @@ import { GetCollection } from './methods/get-collection/get-collection';
|
|
|
7
9
|
*/
|
|
8
10
|
export class Content {
|
|
9
11
|
constructor(requestOptions, serverUrl) {
|
|
10
|
-
this
|
|
11
|
-
this
|
|
12
|
+
_Content_requestOptions.set(this, void 0);
|
|
13
|
+
_Content_serverUrl.set(this, void 0);
|
|
14
|
+
__classPrivateFieldSet(this, _Content_requestOptions, requestOptions, "f");
|
|
15
|
+
__classPrivateFieldSet(this, _Content_serverUrl, serverUrl, "f");
|
|
12
16
|
}
|
|
13
17
|
/**
|
|
14
|
-
*
|
|
18
|
+
* Takes a content type and returns a builder to filter and fetch the collection
|
|
15
19
|
*
|
|
16
|
-
* @
|
|
17
|
-
*
|
|
20
|
+
* @example
|
|
21
|
+
* ```javascript
|
|
22
|
+
* // Using await and async
|
|
23
|
+
* const collectionResponse = await client.content
|
|
24
|
+
* .getCollection('Blog')
|
|
25
|
+
* .limit(10)
|
|
26
|
+
* .page(2)
|
|
27
|
+
* .sortBy([{ field: 'title', order: 'asc' }])
|
|
28
|
+
* .query((queryBuilder) => queryBuilder.field('author').equals('John Doe'))
|
|
29
|
+
* .depth(1);
|
|
30
|
+
* ```
|
|
31
|
+
* @example
|
|
32
|
+
* ```javascript
|
|
33
|
+
* // Using then and catch
|
|
34
|
+
* client.content
|
|
35
|
+
* .getCollection('Blog')
|
|
36
|
+
* .limit(10)
|
|
37
|
+
* .page(2)
|
|
38
|
+
* .sortBy([{ field: 'title', order: 'asc' }])
|
|
39
|
+
* .query((queryBuilder) => queryBuilder.field('author').equals('John Doe'))
|
|
40
|
+
* .depth(1)
|
|
41
|
+
* .then((response) => {
|
|
42
|
+
* console.log(response.contentlets);
|
|
43
|
+
* })
|
|
44
|
+
* .catch((error) => {
|
|
45
|
+
* console.error(error);
|
|
46
|
+
* });
|
|
47
|
+
* ```
|
|
48
|
+
* @example
|
|
49
|
+
* ```typescript
|
|
50
|
+
* // Using an specific type for your content
|
|
51
|
+
*
|
|
52
|
+
* type Blog = {
|
|
53
|
+
* summary: string;
|
|
54
|
+
* author: string;
|
|
55
|
+
* title: string;
|
|
56
|
+
* };
|
|
57
|
+
*
|
|
58
|
+
* client.content
|
|
59
|
+
* .getCollection<Blog>('Blog')
|
|
60
|
+
* .limit(10)
|
|
61
|
+
* .page(2)
|
|
62
|
+
* .sortBy([{ field: 'title', order: 'asc' }])
|
|
63
|
+
* .query((queryBuilder) => queryBuilder.field('author').equals('John Doe'))
|
|
64
|
+
* .depth(1)
|
|
65
|
+
* .then((response) => {
|
|
66
|
+
* response.contentlets.forEach((blog) => {
|
|
67
|
+
* console.log(blog.title);
|
|
68
|
+
* console.log(blog.author);
|
|
69
|
+
* console.log(blog.summary);
|
|
70
|
+
* });
|
|
71
|
+
* })
|
|
72
|
+
* .catch((error) => {
|
|
73
|
+
* console.error(error);
|
|
74
|
+
* });
|
|
75
|
+
* ```
|
|
76
|
+
*
|
|
77
|
+
* @param {string} contentType The content type to get the collection
|
|
78
|
+
* @return {CollectionBuilder} CollectionBuilder to filter and fetch the collection
|
|
79
|
+
* @template T Represents the type of the content type to fetch. Defaults to unknown
|
|
18
80
|
* @memberof Content
|
|
19
81
|
*/
|
|
20
82
|
getCollection(contentType) {
|
|
21
|
-
return new
|
|
83
|
+
return new CollectionBuilder(__classPrivateFieldGet(this, _Content_requestOptions, "f"), __classPrivateFieldGet(this, _Content_serverUrl, "f"), contentType);
|
|
22
84
|
}
|
|
23
85
|
}
|
|
86
|
+
_Content_requestOptions = new WeakMap(), _Content_serverUrl = new WeakMap();
|
|
24
87
|
//# sourceMappingURL=content-api.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"content-api.js","sourceRoot":"","sources":["../../../../../../../../libs/sdk/client/src/lib/client/content/content-api.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"content-api.js","sourceRoot":"","sources":["../../../../../../../../libs/sdk/client/src/lib/client/content/content-api.ts"],"names":[],"mappings":";;AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,kCAAkC,CAAC;AAIrE;;;;;GAKG;AACH,MAAM,OAAO,OAAO;IAIhB,YAAY,cAA6B,EAAE,SAAiB;QAH5D,0CAA+B;QAC/B,qCAAmB;QAGf,uBAAA,IAAI,2BAAmB,cAAc,MAAA,CAAC;QACtC,uBAAA,IAAI,sBAAc,SAAS,MAAA,CAAC;IAChC,CAAC;IAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAgEG;IACH,aAAa,CAAc,WAAmB;QAC1C,OAAO,IAAI,iBAAiB,CAAI,uBAAA,IAAI,+BAAgB,EAAE,uBAAA,IAAI,0BAAW,EAAE,WAAW,CAAC,CAAC;IACxF,CAAC;CACJ"}
|
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
import { Equals } from '../../../query-builder/lucene-syntax
|
|
1
|
+
import { Equals } from '../../../query-builder/lucene-syntax';
|
|
2
|
+
import { QueryBuilder } from '../../../query-builder/sdk-query-builder';
|
|
2
3
|
export type SortBy = {
|
|
3
4
|
field: string;
|
|
4
5
|
order: 'asc' | 'desc';
|
|
5
6
|
};
|
|
6
|
-
export type
|
|
7
|
+
export type BuildQuery = (qb: QueryBuilder) => Equals;
|
|
7
8
|
export interface ContentTypeMainFields {
|
|
8
9
|
hostName: string;
|
|
9
10
|
modDate: string;
|
|
@@ -38,6 +39,8 @@ export interface ContentTypeMainFields {
|
|
|
38
39
|
variant: string;
|
|
39
40
|
}
|
|
40
41
|
export type Contentlet<T> = T & ContentTypeMainFields;
|
|
42
|
+
export type OnFullfilled<T> = ((value: GetCollectionResponse<T>) => GetCollectionResponse<T> | PromiseLike<GetCollectionResponse<T>> | void) | undefined | null;
|
|
43
|
+
export type OnRejected = ((error: GetCollectionError) => GetCollectionError | PromiseLike<GetCollectionError> | void) | undefined | null;
|
|
41
44
|
export interface GetCollectionResponse<T> {
|
|
42
45
|
contentlets: Contentlet<T>[];
|
|
43
46
|
page: number;
|
|
@@ -45,3 +48,15 @@ export interface GetCollectionResponse<T> {
|
|
|
45
48
|
total: number;
|
|
46
49
|
sortedBy?: SortBy[];
|
|
47
50
|
}
|
|
51
|
+
export interface GetCollectionRawResponse<T> {
|
|
52
|
+
entity: {
|
|
53
|
+
jsonObjectView: {
|
|
54
|
+
contentlets: Contentlet<T>[];
|
|
55
|
+
};
|
|
56
|
+
resultsSize: number;
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
export interface GetCollectionError {
|
|
60
|
+
status: number;
|
|
61
|
+
[key: string]: unknown;
|
|
62
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export declare const graphqlToPageEntity: ({ page }: {
|
|
2
|
+
page: Record<string, unknown>;
|
|
3
|
+
}) => {
|
|
4
|
+
layout: unknown;
|
|
5
|
+
template: unknown;
|
|
6
|
+
viewAs: unknown;
|
|
7
|
+
urlContentMap: unknown;
|
|
8
|
+
page: {
|
|
9
|
+
[x: string]: unknown;
|
|
10
|
+
};
|
|
11
|
+
containers: Record<string, unknown>;
|
|
12
|
+
};
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
// For now, we are not typing the functions in this file
|
|
2
|
+
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
3
|
+
export const graphqlToPageEntity = ({ page }) => {
|
|
4
|
+
const { layout, template, containers, urlContentMap, viewAs, ...pageAsset } = page;
|
|
5
|
+
return {
|
|
6
|
+
layout,
|
|
7
|
+
template,
|
|
8
|
+
viewAs,
|
|
9
|
+
urlContentMap,
|
|
10
|
+
page: pageAsset,
|
|
11
|
+
containers: parseContainers(containers)
|
|
12
|
+
};
|
|
13
|
+
};
|
|
14
|
+
const parseContainers = (containers = []) => {
|
|
15
|
+
return containers.reduce((acc, container) => {
|
|
16
|
+
const { path, identifier, containerStructures, containerContentlets, ...rest } = container;
|
|
17
|
+
const key = (path || identifier);
|
|
18
|
+
acc[key] = {
|
|
19
|
+
containerStructures,
|
|
20
|
+
container: {
|
|
21
|
+
path,
|
|
22
|
+
identifier,
|
|
23
|
+
...rest
|
|
24
|
+
},
|
|
25
|
+
contentlets: parseContentletsToUuidMap(containerContentlets)
|
|
26
|
+
};
|
|
27
|
+
return acc;
|
|
28
|
+
}, {});
|
|
29
|
+
};
|
|
30
|
+
const parseContentletsToUuidMap = (containerContentlets) => {
|
|
31
|
+
return containerContentlets.reduce((acc, containerContentlet) => {
|
|
32
|
+
const { uuid, contentlets } = containerContentlet;
|
|
33
|
+
// TODO: This is a temporary solution, we need to find a better way to handle this.
|
|
34
|
+
acc[uuid] = contentlets.map(({ _map = {}, ...rest }) => {
|
|
35
|
+
return {
|
|
36
|
+
..._map,
|
|
37
|
+
...rest
|
|
38
|
+
};
|
|
39
|
+
});
|
|
40
|
+
return acc;
|
|
41
|
+
}, {});
|
|
42
|
+
};
|
|
43
|
+
//# sourceMappingURL=graphql-parser.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"graphql-parser.js","sourceRoot":"","sources":["../../../../../../../libs/sdk/client/src/lib/utils/graphql-parser.ts"],"names":[],"mappings":"AAAA,wDAAwD;AACxD,uDAAuD;AACvD,MAAM,CAAC,MAAM,mBAAmB,GAAG,CAAC,EAAE,IAAI,EAAqC,EAAE,EAAE;IAC/E,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,UAAU,EAAE,aAAa,EAAE,MAAM,EAAE,GAAG,SAAS,EAAE,GAAG,IAAI,CAAC;IAEnF,OAAO;QACH,MAAM;QACN,QAAQ;QACR,MAAM;QACN,aAAa;QACb,IAAI,EAAE,SAAS;QACf,UAAU,EAAE,eAAe,CAAC,UAAgB,CAAC;KAChD,CAAC;AACN,CAAC,CAAC;AAEF,MAAM,eAAe,GAAG,CAAC,UAAU,GAAG,EAAE,EAAE,EAAE;IACxC,OAAO,UAAU,CAAC,MAAM,CAAC,CAAC,GAA4B,EAAE,SAAkC,EAAE,EAAE;QAC1F,MAAM,EAAE,IAAI,EAAE,UAAU,EAAE,mBAAmB,EAAE,oBAAoB,EAAE,GAAG,IAAI,EAAE,GAAG,SAAS,CAAC;QAE3F,MAAM,GAAG,GAAG,CAAC,IAAI,IAAI,UAAU,CAAW,CAAC;QAE3C,GAAG,CAAC,GAAG,CAAC,GAAG;YACP,mBAAmB;YACnB,SAAS,EAAE;gBACP,IAAI;gBACJ,UAAU;gBACV,GAAG,IAAI;aACV;YACD,WAAW,EAAE,yBAAyB,CAAC,oBAA0B,CAAC;SACrE,CAAC;QAEF,OAAO,GAAG,CAAC;IACf,CAAC,EAAE,EAAE,CAAC,CAAC;AACX,CAAC,CAAC;AAEF,MAAM,yBAAyB,GAAG,CAAC,oBAA2B,EAAE,EAAE;IAC9D,OAAO,oBAAoB,CAAC,MAAM,CAAC,CAAC,GAAG,EAAE,mBAAmB,EAAE,EAAE;QAC5D,MAAM,EAAE,IAAI,EAAE,WAAW,EAAE,GAAG,mBAAmB,CAAC;QAElD,mFAAmF;QACnF,GAAG,CAAC,IAAI,CAAC,GAAG,WAAW,CAAC,GAAG,CAAC,CAAC,EAAE,IAAI,GAAG,EAAE,EAAE,GAAG,IAAI,EAAE,EAAE,EAAE;YACnD,OAAO;gBACH,GAAG,IAAI;gBACP,GAAG,IAAI;aACV,CAAC;QACN,CAAC,CAAC,CAAC;QAEH,OAAO,GAAG,CAAC;IACf,CAAC,EAAE,EAAS,CAAC,CAAC;AAClB,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './graphql-parser';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../../../libs/sdk/client/src/lib/utils/index.ts"],"names":[],"mappings":"AAAA,cAAc,kBAAkB,CAAC"}
|
|
@@ -1,119 +0,0 @@
|
|
|
1
|
-
import { ClientOptions } from '../../../sdk-js-client';
|
|
2
|
-
import { GetCollectionResponse, QueryBuilderCallback, SortBy } from '../../shared/types';
|
|
3
|
-
/**
|
|
4
|
-
* 'GetCollection' Is a Typescript class that provides the ability build a query to get a collection of content.
|
|
5
|
-
*
|
|
6
|
-
* @export
|
|
7
|
-
* @class GetCollection
|
|
8
|
-
*/
|
|
9
|
-
export declare class GetCollection {
|
|
10
|
-
#private;
|
|
11
|
-
constructor(requestOptions: ClientOptions, serverUrl: string, contentType: string);
|
|
12
|
-
/**
|
|
13
|
-
* This method returns the sort query in this format: field order, field order, ...
|
|
14
|
-
*
|
|
15
|
-
* @readonly
|
|
16
|
-
* @private
|
|
17
|
-
* @memberof GetCollection
|
|
18
|
-
*/
|
|
19
|
-
private get sort();
|
|
20
|
-
private get offset();
|
|
21
|
-
private get url();
|
|
22
|
-
/**
|
|
23
|
-
* This method returns the current query built
|
|
24
|
-
*
|
|
25
|
-
* @readonly
|
|
26
|
-
* @private
|
|
27
|
-
* @memberof GetCollection
|
|
28
|
-
*/
|
|
29
|
-
private get currentQuery();
|
|
30
|
-
/**
|
|
31
|
-
* This method allows to filter the content by language.
|
|
32
|
-
*
|
|
33
|
-
* @param {number} language
|
|
34
|
-
* @return {*} {this}
|
|
35
|
-
* @memberof GetCollection
|
|
36
|
-
*/
|
|
37
|
-
language(language: number): this;
|
|
38
|
-
/**
|
|
39
|
-
* This method allows you to fetch the render version of the content
|
|
40
|
-
*
|
|
41
|
-
* @param {boolean} render
|
|
42
|
-
* @return {*} {this}
|
|
43
|
-
* @memberof GetCollection
|
|
44
|
-
*/
|
|
45
|
-
render(render: boolean): this;
|
|
46
|
-
/**
|
|
47
|
-
* This method allows you to sort the content by field
|
|
48
|
-
*
|
|
49
|
-
* @param {SortBy[]} sortBy
|
|
50
|
-
* @return {*} {this}
|
|
51
|
-
* @memberof GetCollection
|
|
52
|
-
*/
|
|
53
|
-
sortBy(sortBy: SortBy[]): this;
|
|
54
|
-
/**
|
|
55
|
-
* This method allows you to limit the number of content to fetch
|
|
56
|
-
*
|
|
57
|
-
* @param {number} limit
|
|
58
|
-
* @return {*} {this}
|
|
59
|
-
* @memberof GetCollection
|
|
60
|
-
*/
|
|
61
|
-
limit(limit: number): this;
|
|
62
|
-
/**
|
|
63
|
-
* This method allows you to set the page of the content to fetch
|
|
64
|
-
*
|
|
65
|
-
* @param {number} page
|
|
66
|
-
* @return {*} {this}
|
|
67
|
-
* @memberof GetCollection
|
|
68
|
-
*/
|
|
69
|
-
page(page: number): this;
|
|
70
|
-
/**
|
|
71
|
-
* This method allows you to set a lucene query to filter the content using the Lucene Query Builder.
|
|
72
|
-
* All fields will be formatted to: +contentTypeVar.field: value
|
|
73
|
-
*
|
|
74
|
-
* @param {QueryBuilderCallback} queryBuilderCallback
|
|
75
|
-
* @return {*} {this}
|
|
76
|
-
* @memberof GetCollection
|
|
77
|
-
*/
|
|
78
|
-
query(queryBuilderCallback: QueryBuilderCallback): this;
|
|
79
|
-
/**
|
|
80
|
-
* This method allows you to set a raw lucene query to filter the content
|
|
81
|
-
*
|
|
82
|
-
* @param {string} query
|
|
83
|
-
* @return {*} {this}
|
|
84
|
-
* @memberof GetCollection
|
|
85
|
-
*/
|
|
86
|
-
rawQuery(query: string): this;
|
|
87
|
-
/**
|
|
88
|
-
* This method allows you to fetch draft content
|
|
89
|
-
*
|
|
90
|
-
* @param {boolean} draft
|
|
91
|
-
* @return {*} {this}
|
|
92
|
-
* @memberof GetCollection
|
|
93
|
-
*/
|
|
94
|
-
draft(draft: boolean): this;
|
|
95
|
-
/**
|
|
96
|
-
* This method allows you to filter content by experiment variant
|
|
97
|
-
*
|
|
98
|
-
* @param {string} variant
|
|
99
|
-
* @return {*} {this}
|
|
100
|
-
* @memberof GetCollection
|
|
101
|
-
*/
|
|
102
|
-
variant(variant: string): this;
|
|
103
|
-
/**
|
|
104
|
-
* This method allows you to set the depth of the relationships in the content
|
|
105
|
-
*
|
|
106
|
-
* @param {number} depth
|
|
107
|
-
* @return {*} {this}
|
|
108
|
-
* @memberof GetCollection
|
|
109
|
-
*/
|
|
110
|
-
depth(depth: number): this;
|
|
111
|
-
/**
|
|
112
|
-
* This method returns the result of the fetch using the query built.
|
|
113
|
-
*
|
|
114
|
-
* @template T
|
|
115
|
-
* @return {*} {Promise<GetCollectionResponse<T>>}
|
|
116
|
-
* @memberof GetCollection
|
|
117
|
-
*/
|
|
118
|
-
fetch<T>(): Promise<GetCollectionResponse<T>>;
|
|
119
|
-
}
|
|
@@ -1,229 +0,0 @@
|
|
|
1
|
-
var _GetCollection_page, _GetCollection_limit, _GetCollection_depth, _GetCollection_render, _GetCollection_sortBy, _GetCollection_contentType, _GetCollection_defaultQuery, _GetCollection_query, _GetCollection_rawQuery, _GetCollection_serverUrl, _GetCollection_requestOptions;
|
|
2
|
-
import { __classPrivateFieldGet, __classPrivateFieldSet } from "tslib";
|
|
3
|
-
import { Equals } from '../../../../query-builder/lucene-syntax';
|
|
4
|
-
import { QueryBuilder } from '../../../../query-builder/sdk-query-builder';
|
|
5
|
-
import { CONTENT_API_URL } from '../../shared/const';
|
|
6
|
-
import { sanitizeQueryForContentType } from '../../shared/utils';
|
|
7
|
-
/**
|
|
8
|
-
* 'GetCollection' Is a Typescript class that provides the ability build a query to get a collection of content.
|
|
9
|
-
*
|
|
10
|
-
* @export
|
|
11
|
-
* @class GetCollection
|
|
12
|
-
*/
|
|
13
|
-
export class GetCollection {
|
|
14
|
-
constructor(requestOptions, serverUrl, contentType) {
|
|
15
|
-
_GetCollection_page.set(this, 1);
|
|
16
|
-
_GetCollection_limit.set(this, 10);
|
|
17
|
-
_GetCollection_depth.set(this, 0);
|
|
18
|
-
_GetCollection_render.set(this, false);
|
|
19
|
-
_GetCollection_sortBy.set(this, void 0);
|
|
20
|
-
_GetCollection_contentType.set(this, void 0);
|
|
21
|
-
_GetCollection_defaultQuery.set(this, void 0);
|
|
22
|
-
_GetCollection_query.set(this, void 0);
|
|
23
|
-
_GetCollection_rawQuery.set(this, void 0);
|
|
24
|
-
_GetCollection_serverUrl.set(this, void 0);
|
|
25
|
-
_GetCollection_requestOptions.set(this, void 0);
|
|
26
|
-
__classPrivateFieldSet(this, _GetCollection_requestOptions, requestOptions, "f");
|
|
27
|
-
__classPrivateFieldSet(this, _GetCollection_serverUrl, serverUrl, "f");
|
|
28
|
-
__classPrivateFieldSet(this, _GetCollection_contentType, contentType, "f");
|
|
29
|
-
// We need to build the default query with the contentType field
|
|
30
|
-
__classPrivateFieldSet(this, _GetCollection_defaultQuery, new QueryBuilder().field('contentType').equals(__classPrivateFieldGet(this, _GetCollection_contentType, "f")), "f");
|
|
31
|
-
}
|
|
32
|
-
/**
|
|
33
|
-
* This method returns the sort query in this format: field order, field order, ...
|
|
34
|
-
*
|
|
35
|
-
* @readonly
|
|
36
|
-
* @private
|
|
37
|
-
* @memberof GetCollection
|
|
38
|
-
*/
|
|
39
|
-
get sort() {
|
|
40
|
-
return __classPrivateFieldGet(this, _GetCollection_sortBy, "f")?.map((sort) => `${sort.field} ${sort.order}`).join(',');
|
|
41
|
-
}
|
|
42
|
-
get offset() {
|
|
43
|
-
// This could end in an empty response
|
|
44
|
-
return __classPrivateFieldGet(this, _GetCollection_limit, "f") * (__classPrivateFieldGet(this, _GetCollection_page, "f") - 1);
|
|
45
|
-
}
|
|
46
|
-
get url() {
|
|
47
|
-
return `${__classPrivateFieldGet(this, _GetCollection_serverUrl, "f")}${CONTENT_API_URL}`;
|
|
48
|
-
}
|
|
49
|
-
/**
|
|
50
|
-
* This method returns the current query built
|
|
51
|
-
*
|
|
52
|
-
* @readonly
|
|
53
|
-
* @private
|
|
54
|
-
* @memberof GetCollection
|
|
55
|
-
*/
|
|
56
|
-
get currentQuery() {
|
|
57
|
-
return __classPrivateFieldGet(this, _GetCollection_query, "f") ?? __classPrivateFieldGet(this, _GetCollection_defaultQuery, "f");
|
|
58
|
-
}
|
|
59
|
-
/**
|
|
60
|
-
* This method allows to filter the content by language.
|
|
61
|
-
*
|
|
62
|
-
* @param {number} language
|
|
63
|
-
* @return {*} {this}
|
|
64
|
-
* @memberof GetCollection
|
|
65
|
-
*/
|
|
66
|
-
language(language) {
|
|
67
|
-
__classPrivateFieldSet(this, _GetCollection_query, this.currentQuery.field('languageId').equals(language.toString()), "f");
|
|
68
|
-
return this;
|
|
69
|
-
}
|
|
70
|
-
/**
|
|
71
|
-
* This method allows you to fetch the render version of the content
|
|
72
|
-
*
|
|
73
|
-
* @param {boolean} render
|
|
74
|
-
* @return {*} {this}
|
|
75
|
-
* @memberof GetCollection
|
|
76
|
-
*/
|
|
77
|
-
render(render) {
|
|
78
|
-
__classPrivateFieldSet(this, _GetCollection_render, render, "f");
|
|
79
|
-
return this;
|
|
80
|
-
}
|
|
81
|
-
/**
|
|
82
|
-
* This method allows you to sort the content by field
|
|
83
|
-
*
|
|
84
|
-
* @param {SortBy[]} sortBy
|
|
85
|
-
* @return {*} {this}
|
|
86
|
-
* @memberof GetCollection
|
|
87
|
-
*/
|
|
88
|
-
sortBy(sortBy) {
|
|
89
|
-
__classPrivateFieldSet(this, _GetCollection_sortBy, sortBy, "f");
|
|
90
|
-
return this;
|
|
91
|
-
}
|
|
92
|
-
/**
|
|
93
|
-
* This method allows you to limit the number of content to fetch
|
|
94
|
-
*
|
|
95
|
-
* @param {number} limit
|
|
96
|
-
* @return {*} {this}
|
|
97
|
-
* @memberof GetCollection
|
|
98
|
-
*/
|
|
99
|
-
limit(limit) {
|
|
100
|
-
__classPrivateFieldSet(this, _GetCollection_limit, limit, "f");
|
|
101
|
-
return this;
|
|
102
|
-
}
|
|
103
|
-
/**
|
|
104
|
-
* This method allows you to set the page of the content to fetch
|
|
105
|
-
*
|
|
106
|
-
* @param {number} page
|
|
107
|
-
* @return {*} {this}
|
|
108
|
-
* @memberof GetCollection
|
|
109
|
-
*/
|
|
110
|
-
page(page) {
|
|
111
|
-
__classPrivateFieldSet(this, _GetCollection_page, page, "f");
|
|
112
|
-
return this;
|
|
113
|
-
}
|
|
114
|
-
/**
|
|
115
|
-
* This method allows you to set a lucene query to filter the content using the Lucene Query Builder.
|
|
116
|
-
* All fields will be formatted to: +contentTypeVar.field: value
|
|
117
|
-
*
|
|
118
|
-
* @param {QueryBuilderCallback} queryBuilderCallback
|
|
119
|
-
* @return {*} {this}
|
|
120
|
-
* @memberof GetCollection
|
|
121
|
-
*/
|
|
122
|
-
query(queryBuilderCallback) {
|
|
123
|
-
const queryResult = queryBuilderCallback(this.currentQuery);
|
|
124
|
-
// This can be use in Javascript so we cannot rely on the type checking
|
|
125
|
-
if (queryResult instanceof Equals) {
|
|
126
|
-
__classPrivateFieldSet(this, _GetCollection_query, queryResult, "f");
|
|
127
|
-
}
|
|
128
|
-
else {
|
|
129
|
-
throw new Error('The query builder callback should return an Equals instance');
|
|
130
|
-
}
|
|
131
|
-
return this;
|
|
132
|
-
}
|
|
133
|
-
/**
|
|
134
|
-
* This method allows you to set a raw lucene query to filter the content
|
|
135
|
-
*
|
|
136
|
-
* @param {string} query
|
|
137
|
-
* @return {*} {this}
|
|
138
|
-
* @memberof GetCollection
|
|
139
|
-
*/
|
|
140
|
-
rawQuery(query) {
|
|
141
|
-
__classPrivateFieldSet(this, _GetCollection_rawQuery, query, "f");
|
|
142
|
-
return this;
|
|
143
|
-
}
|
|
144
|
-
/**
|
|
145
|
-
* This method allows you to fetch draft content
|
|
146
|
-
*
|
|
147
|
-
* @param {boolean} draft
|
|
148
|
-
* @return {*} {this}
|
|
149
|
-
* @memberof GetCollection
|
|
150
|
-
*/
|
|
151
|
-
draft(draft) {
|
|
152
|
-
__classPrivateFieldSet(this, _GetCollection_query, this.currentQuery.field('live').equals((!draft).toString()), "f");
|
|
153
|
-
return this;
|
|
154
|
-
}
|
|
155
|
-
/**
|
|
156
|
-
* This method allows you to filter content by experiment variant
|
|
157
|
-
*
|
|
158
|
-
* @param {string} variant
|
|
159
|
-
* @return {*} {this}
|
|
160
|
-
* @memberof GetCollection
|
|
161
|
-
*/
|
|
162
|
-
variant(variant) {
|
|
163
|
-
__classPrivateFieldSet(this, _GetCollection_query, this.currentQuery.field('variant').equals(variant), "f");
|
|
164
|
-
return this;
|
|
165
|
-
}
|
|
166
|
-
/**
|
|
167
|
-
* This method allows you to set the depth of the relationships in the content
|
|
168
|
-
*
|
|
169
|
-
* @param {number} depth
|
|
170
|
-
* @return {*} {this}
|
|
171
|
-
* @memberof GetCollection
|
|
172
|
-
*/
|
|
173
|
-
depth(depth) {
|
|
174
|
-
__classPrivateFieldSet(this, _GetCollection_depth, depth, "f");
|
|
175
|
-
return this;
|
|
176
|
-
}
|
|
177
|
-
/**
|
|
178
|
-
* This method returns the result of the fetch using the query built.
|
|
179
|
-
*
|
|
180
|
-
* @template T
|
|
181
|
-
* @return {*} {Promise<GetCollectionResponse<T>>}
|
|
182
|
-
* @memberof GetCollection
|
|
183
|
-
*/
|
|
184
|
-
async fetch() {
|
|
185
|
-
const sanitizedQuery = sanitizeQueryForContentType(this.currentQuery.build(), __classPrivateFieldGet(this, _GetCollection_contentType, "f"));
|
|
186
|
-
const query = __classPrivateFieldGet(this, _GetCollection_rawQuery, "f") ? `${sanitizedQuery} ${__classPrivateFieldGet(this, _GetCollection_rawQuery, "f")}` : sanitizedQuery;
|
|
187
|
-
return fetch(this.url, {
|
|
188
|
-
...__classPrivateFieldGet(this, _GetCollection_requestOptions, "f"),
|
|
189
|
-
method: 'POST',
|
|
190
|
-
headers: {
|
|
191
|
-
...__classPrivateFieldGet(this, _GetCollection_requestOptions, "f").headers,
|
|
192
|
-
'Content-Type': 'application/json'
|
|
193
|
-
},
|
|
194
|
-
body: JSON.stringify({
|
|
195
|
-
query,
|
|
196
|
-
render: __classPrivateFieldGet(this, _GetCollection_render, "f"),
|
|
197
|
-
sort: this.sort,
|
|
198
|
-
limit: __classPrivateFieldGet(this, _GetCollection_limit, "f"),
|
|
199
|
-
offset: this.offset,
|
|
200
|
-
depth: __classPrivateFieldGet(this, _GetCollection_depth, "f")
|
|
201
|
-
//userId: This exist but we currently don't use it
|
|
202
|
-
//allCategoriesInfo: This exist but we currently don't use it
|
|
203
|
-
})
|
|
204
|
-
}).then(async (response) => {
|
|
205
|
-
if (response.ok) {
|
|
206
|
-
const data = await response.json();
|
|
207
|
-
const contentlets = data.entity.jsonObjectView.contentlets;
|
|
208
|
-
const total = data.entity.resultsSize;
|
|
209
|
-
const mappedResponse = {
|
|
210
|
-
contentlets,
|
|
211
|
-
total,
|
|
212
|
-
page: __classPrivateFieldGet(this, _GetCollection_page, "f"),
|
|
213
|
-
size: contentlets.length
|
|
214
|
-
};
|
|
215
|
-
return __classPrivateFieldGet(this, _GetCollection_sortBy, "f")
|
|
216
|
-
? {
|
|
217
|
-
...mappedResponse,
|
|
218
|
-
sortedBy: __classPrivateFieldGet(this, _GetCollection_sortBy, "f")
|
|
219
|
-
}
|
|
220
|
-
: mappedResponse;
|
|
221
|
-
}
|
|
222
|
-
else {
|
|
223
|
-
return response.json();
|
|
224
|
-
}
|
|
225
|
-
}, (error) => error);
|
|
226
|
-
}
|
|
227
|
-
}
|
|
228
|
-
_GetCollection_page = new WeakMap(), _GetCollection_limit = new WeakMap(), _GetCollection_depth = new WeakMap(), _GetCollection_render = new WeakMap(), _GetCollection_sortBy = new WeakMap(), _GetCollection_contentType = new WeakMap(), _GetCollection_defaultQuery = new WeakMap(), _GetCollection_query = new WeakMap(), _GetCollection_rawQuery = new WeakMap(), _GetCollection_serverUrl = new WeakMap(), _GetCollection_requestOptions = new WeakMap();
|
|
229
|
-
//# sourceMappingURL=get-collection.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"get-collection.js","sourceRoot":"","sources":["../../../../../../../../../../libs/sdk/client/src/lib/client/content/methods/get-collection/get-collection.ts"],"names":[],"mappings":";;AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,yCAAyC,CAAC;AACjE,OAAO,EAAE,YAAY,EAAE,MAAM,6CAA6C,CAAC;AAE3E,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AAErD,OAAO,EAAE,2BAA2B,EAAE,MAAM,oBAAoB,CAAC;AAEjE;;;;;GAKG;AACH,MAAM,OAAO,aAAa;IActB,YAAY,cAA6B,EAAE,SAAiB,EAAE,WAAmB;QAbjF,8BAAQ,CAAC,EAAC;QACV,+BAAS,EAAE,EAAC;QACZ,+BAAS,CAAC,EAAC;QACX,gCAAU,KAAK,EAAC;QAChB,wCAAmB;QACnB,6CAAqB;QACrB,8CAAsB;QACtB,uCAAgB;QAChB,0CAAmB;QAEnB,2CAAmB;QACnB,gDAA+B;QAG3B,uBAAA,IAAI,iCAAmB,cAAc,MAAA,CAAC;QACtC,uBAAA,IAAI,4BAAc,SAAS,MAAA,CAAC;QAE5B,uBAAA,IAAI,8BAAgB,WAAW,MAAA,CAAC;QAEhC,gEAAgE;QAChE,uBAAA,IAAI,+BAAiB,IAAI,YAAY,EAAE,CAAC,KAAK,CAAC,aAAa,CAAC,CAAC,MAAM,CAAC,u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