@dotcms/client 1.0.1 → 1.0.2-next.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (51) hide show
  1. package/index.cjs.d.ts +1 -0
  2. package/index.cjs.default.js +1 -0
  3. package/index.cjs.js +1592 -0
  4. package/index.cjs.mjs +2 -0
  5. package/index.esm.d.ts +1 -0
  6. package/index.esm.js +1590 -0
  7. package/internal.cjs.d.ts +1 -0
  8. package/internal.cjs.default.js +1 -0
  9. package/internal.cjs.js +85 -0
  10. package/internal.cjs.mjs +2 -0
  11. package/internal.esm.d.ts +1 -0
  12. package/internal.esm.js +83 -0
  13. package/package.json +24 -7
  14. package/src/lib/client/client.d.ts +56 -0
  15. package/src/lib/client/content/builders/collection/{collection.ts → collection.d.ts} +19 -210
  16. package/src/lib/client/content/builders/query/lucene-syntax/{Equals.ts → Equals.d.ts} +11 -45
  17. package/src/lib/client/content/builders/query/lucene-syntax/{Field.ts → Field.d.ts} +5 -13
  18. package/src/lib/client/content/builders/query/lucene-syntax/{NotOperand.ts → NotOperand.d.ts} +5 -13
  19. package/src/lib/client/content/builders/query/lucene-syntax/{Operand.ts → Operand.d.ts} +7 -21
  20. package/src/lib/client/content/builders/query/{query.ts → query.d.ts} +5 -16
  21. package/src/lib/client/content/builders/query/utils/{index.ts → index.d.ts} +12 -49
  22. package/src/lib/client/content/{content-api.ts → content-api.d.ts} +4 -14
  23. package/src/lib/client/content/shared/{const.ts → const.d.ts} +3 -5
  24. package/src/lib/client/content/shared/{types.ts → types.d.ts} +2 -18
  25. package/src/lib/client/content/shared/{utils.ts → utils.d.ts} +1 -9
  26. package/src/lib/client/models/{index.ts → index.d.ts} +1 -8
  27. package/src/lib/client/navigation/navigation-api.d.ts +14 -0
  28. package/src/lib/client/page/page-api.d.ts +95 -0
  29. package/src/lib/client/page/utils.d.ts +41 -0
  30. package/src/lib/utils/graphql/transforms.d.ts +13 -0
  31. package/.eslintrc.json +0 -18
  32. package/jest.config.ts +0 -15
  33. package/project.json +0 -73
  34. package/src/lib/client/client.spec.ts +0 -147
  35. package/src/lib/client/client.ts +0 -125
  36. package/src/lib/client/content/builders/collection/collection.spec.ts +0 -514
  37. package/src/lib/client/content/builders/query/query.spec.ts +0 -159
  38. package/src/lib/client/navigation/navigation-api.spec.ts +0 -167
  39. package/src/lib/client/navigation/navigation-api.ts +0 -62
  40. package/src/lib/client/page/page-api.spec.ts +0 -359
  41. package/src/lib/client/page/page-api.ts +0 -197
  42. package/src/lib/client/page/utils.ts +0 -291
  43. package/src/lib/utils/graphql/transforms.spec.ts +0 -250
  44. package/src/lib/utils/graphql/transforms.ts +0 -128
  45. package/tsconfig.json +0 -22
  46. package/tsconfig.lib.json +0 -13
  47. package/tsconfig.spec.json +0 -9
  48. /package/src/{index.ts → index.d.ts} +0 -0
  49. /package/src/{internal.ts → internal.d.ts} +0 -0
  50. /package/src/lib/client/content/builders/query/lucene-syntax/{index.ts → index.d.ts} +0 -0
  51. /package/src/lib/utils/{index.ts → index.d.ts} +0 -0
@@ -1,250 +0,0 @@
1
- import { DotCMSGraphQLPageResponse } from '@dotcms/types';
2
-
3
- import { graphqlToPageEntity } from './transforms';
4
-
5
- const GRAPHQL_RESPONSE_MOCK = {
6
- page: {
7
- title: 'test2',
8
- url: '/test2',
9
- seodescription: null,
10
- containers: [
11
- {
12
- path: '//demo.dotcms.com/application/containers/default/',
13
- identifier: '69b3d24d-7e80-4be6-b04a-d352d16493ee',
14
- containerStructures: [
15
- {
16
- id: '77ec7720-bad8-431c-a0a3-6443fe87af73'
17
- },
18
- {
19
- id: '1e5372c4-9fff-4793-ad8a-a52558d0d395'
20
- },
21
- {
22
- id: '461b6fad-04a8-49ba-b75b-6634799bc289'
23
- },
24
- {
25
- id: '57b4a9de-4765-4c57-8a05-2a0a317ec546'
26
- },
27
- {
28
- id: '342a83bf-040a-45a2-a4bc-defb0f1bf4eb'
29
- },
30
- {
31
- id: '91a955a0-5c97-4fc3-91dd-f894e2f3dc54'
32
- },
33
- {
34
- id: '71ded7c9deb5b05452824bb42b9aa9d5'
35
- },
36
- {
37
- id: '86a06a2e-ba40-43d4-a3ad-3a870d43bfc1'
38
- },
39
- {
40
- id: '7673e601-26d4-4dbc-b6ad-7028599df656'
41
- },
42
- {
43
- id: '313498a4-5b57-4d9e-8d32-ef2d30f9e867'
44
- }
45
- ],
46
- containerContentlets: [
47
- {
48
- uuid: 'uuid-1562770692396',
49
- contentlets: [
50
- {
51
- identifier: 'd9444fa005a10d555318d8b014e474d4'
52
- }
53
- ]
54
- }
55
- ]
56
- }
57
- ],
58
- host: {
59
- hostName: 'demo.dotcms.com'
60
- },
61
- layout: {
62
- title: 'default-template'
63
- },
64
- template: {
65
- identifier: '31f4c794-c769-4929-9d5d-7c383408c65c'
66
- },
67
- urlContentMap: {
68
- _map: {
69
- identifier: '31f4c794-c769-4929-9d5d-7c383408c74d'
70
- }
71
- },
72
- viewAs: {
73
- mode: 'LIVE'
74
- },
75
- runningExperimentId: '123',
76
- vanityUrl: {
77
- action: 200,
78
- uri: '/test2',
79
- forwardTo: '/test2'
80
- }
81
- }
82
- };
83
-
84
- const MOCK_PAGE_ENTITY = {
85
- containers: {
86
- '//demo.dotcms.com/application/containers/default/': {
87
- container: {
88
- identifier: '69b3d24d-7e80-4be6-b04a-d352d16493ee',
89
- path: '//demo.dotcms.com/application/containers/default/'
90
- },
91
- containerStructures: [
92
- {
93
- id: '77ec7720-bad8-431c-a0a3-6443fe87af73'
94
- },
95
- {
96
- id: '1e5372c4-9fff-4793-ad8a-a52558d0d395'
97
- },
98
- {
99
- id: '461b6fad-04a8-49ba-b75b-6634799bc289'
100
- },
101
- {
102
- id: '57b4a9de-4765-4c57-8a05-2a0a317ec546'
103
- },
104
- {
105
- id: '342a83bf-040a-45a2-a4bc-defb0f1bf4eb'
106
- },
107
- {
108
- id: '91a955a0-5c97-4fc3-91dd-f894e2f3dc54'
109
- },
110
- {
111
- id: '71ded7c9deb5b05452824bb42b9aa9d5'
112
- },
113
- {
114
- id: '86a06a2e-ba40-43d4-a3ad-3a870d43bfc1'
115
- },
116
- {
117
- id: '7673e601-26d4-4dbc-b6ad-7028599df656'
118
- },
119
- {
120
- id: '313498a4-5b57-4d9e-8d32-ef2d30f9e867'
121
- }
122
- ],
123
- contentlets: {
124
- 'uuid-1562770692396': [
125
- {
126
- identifier: 'd9444fa005a10d555318d8b014e474d4'
127
- }
128
- ]
129
- }
130
- }
131
- },
132
- layout: {
133
- title: 'default-template'
134
- },
135
- page: {
136
- seodescription: null,
137
- title: 'test2',
138
- url: '/test2'
139
- },
140
- urlContentMap: {
141
- identifier: '31f4c794-c769-4929-9d5d-7c383408c74d'
142
- },
143
- template: {
144
- identifier: '31f4c794-c769-4929-9d5d-7c383408c65c'
145
- },
146
- viewAs: {
147
- mode: 'LIVE'
148
- },
149
- site: {
150
- hostName: 'demo.dotcms.com'
151
- },
152
- vanityUrl: {
153
- action: 200,
154
- uri: '/test2',
155
- forwardTo: '/test2'
156
- },
157
- runningExperimentId: '123'
158
- };
159
-
160
- describe('GraphQL Parser', () => {
161
- it('should return the correct page entity', () => {
162
- const pageEntity = graphqlToPageEntity(
163
- GRAPHQL_RESPONSE_MOCK as unknown as DotCMSGraphQLPageResponse
164
- );
165
-
166
- expect(pageEntity).toEqual(MOCK_PAGE_ENTITY);
167
- });
168
-
169
- it('should transform _map properties correctly', () => {
170
- const graphqlResponse = {
171
- page: {
172
- title: 'map-test',
173
- url: '/map-test',
174
- _map: {
175
- customField: 'custom value'
176
- },
177
- urlContentMap: {
178
- _map: {
179
- mapField: 'map value',
180
- identifier: 'test-id',
181
- someNestedField: {
182
- nestedField: 'nested value'
183
- }
184
- }
185
- },
186
- containers: [
187
- {
188
- path: '//test/container/',
189
- identifier: 'test-container-id',
190
- containerContentlets: [
191
- {
192
- uuid: 'test-uuid',
193
- contentlets: [
194
- {
195
- _map: {
196
- identifier: 'test-contentlet-id',
197
- contentletField: 'contentlet value'
198
- }
199
- }
200
- ]
201
- }
202
- ]
203
- }
204
- ]
205
- }
206
- };
207
-
208
- const expectedResult = {
209
- page: {
210
- title: 'map-test',
211
- url: '/map-test',
212
- customField: 'custom value'
213
- },
214
- urlContentMap: {
215
- identifier: 'test-id',
216
- mapField: 'map value',
217
- someNestedField: {
218
- nestedField: 'nested value'
219
- }
220
- },
221
- containers: {
222
- '//test/container/': {
223
- container: {
224
- path: '//test/container/',
225
- identifier: 'test-container-id'
226
- },
227
- containerStructures: undefined,
228
- contentlets: {
229
- 'test-uuid': [
230
- {
231
- identifier: 'test-contentlet-id',
232
- contentletField: 'contentlet value'
233
- }
234
- ]
235
- }
236
- }
237
- }
238
- };
239
-
240
- const pageEntity = graphqlToPageEntity(
241
- graphqlResponse as unknown as DotCMSGraphQLPageResponse
242
- );
243
-
244
- expect(pageEntity?.page).toEqual(expectedResult.page);
245
- expect(pageEntity?.urlContentMap).toEqual(expectedResult.urlContentMap);
246
- expect(pageEntity?.containers['//test/container/'].contentlets['test-uuid'][0]).toEqual(
247
- expectedResult.containers['//test/container/'].contentlets['test-uuid'][0]
248
- );
249
- });
250
- });
@@ -1,128 +0,0 @@
1
- /* eslint-disable @typescript-eslint/no-explicit-any */
2
-
3
- import {
4
- DotCMSBasicContentlet,
5
- DotCMSGraphQLPageContainer,
6
- DotCMSGraphQLPageResponse,
7
- DotCMSPageAssetContainers,
8
- DotCMSPageContainerContentlets,
9
- DotCMSPage,
10
- DotCMSPageAsset,
11
- DotCMSContainer
12
- } from '@dotcms/types';
13
-
14
- /**
15
- * Transforms a GraphQL Page response to a Page Entity.
16
- *
17
- * @param {GraphQLPageResponse} graphQLPageResponse - The GraphQL Page response object.
18
- * @returns {object|null} The transformed Page Entity or null if the page is not present.
19
- *
20
- * @example
21
- * ```ts
22
- * const pageEntity = graphqlToPageEntity(graphQLPageResponse);
23
- * ```
24
- */
25
- export const graphqlToPageEntity = (
26
- graphQLPageResponse: DotCMSGraphQLPageResponse
27
- ): DotCMSPageAsset | null => {
28
- const { page } = graphQLPageResponse;
29
-
30
- // If there is no page, return null
31
- if (!page) {
32
- return null;
33
- }
34
-
35
- const {
36
- layout,
37
- template,
38
- containers,
39
- urlContentMap,
40
- viewAs,
41
- host,
42
- vanityUrl,
43
- runningExperimentId,
44
- _map,
45
- ...pageAsset
46
- } = page;
47
- const data = (_map || {}) as Record<string, unknown>;
48
-
49
- const typedPageAsset = pageAsset as unknown as DotCMSPage;
50
-
51
- // To prevent type errors, we cast the urlContentMap to an object
52
- const urlContentMapObject = urlContentMap;
53
-
54
- // Extract the _map data from the urlContentMap object
55
- const urlContentMapData = urlContentMapObject?.['_map'];
56
-
57
- return {
58
- layout,
59
- template,
60
- viewAs,
61
- vanityUrl,
62
- runningExperimentId,
63
- site: host,
64
- urlContentMap: urlContentMapData,
65
- containers: parseContainers(containers as []),
66
- page: {
67
- ...data,
68
- ...typedPageAsset
69
- }
70
- };
71
- };
72
-
73
- /**
74
- * Parses the containers from the GraphQL response.
75
- *
76
- * @param {DotCMSGraphQLPageContainer[]} [containers=[]] - The containers array from the GraphQL response.
77
- * @returns {DotCMSPageAssetContainers} The parsed containers.
78
- */
79
- const parseContainers = (
80
- containers: DotCMSGraphQLPageContainer[] = []
81
- ): DotCMSPageAssetContainers => {
82
- return containers.reduce(
83
- (acc: DotCMSPageAssetContainers, container: DotCMSGraphQLPageContainer) => {
84
- const { path, identifier, containerStructures, containerContentlets, ...rest } =
85
- container;
86
-
87
- const key = (path || identifier) as string;
88
-
89
- acc[key] = {
90
- containerStructures,
91
- container: {
92
- path,
93
- identifier,
94
- ...rest
95
- } as DotCMSContainer,
96
- contentlets: parseContentletsToUuidMap(containerContentlets as [])
97
- };
98
-
99
- return acc;
100
- },
101
- {}
102
- );
103
- };
104
-
105
- /**
106
- * Parses the contentlets from the GraphQL response.
107
- *
108
- * @param {Array<Record<string, unknown>>} containerContentlets - The contentlets array from the GraphQL response.
109
- * @returns {Record<string, Array<Record<string, unknown>>>} The parsed contentlets mapped by UUID.
110
- */
111
- const parseContentletsToUuidMap = (containerContentlets: DotCMSPageContainerContentlets[] = []) => {
112
- return containerContentlets.reduce(
113
- (acc, containerContentlet) => {
114
- const { uuid, contentlets } = containerContentlet;
115
-
116
- // TODO: This is a temporary solution, we need to find a better way to handle this.
117
- acc[uuid] = contentlets.map(({ _map = {}, ...rest }) => {
118
- return {
119
- ...(_map as Record<string, unknown>),
120
- ...rest
121
- };
122
- });
123
-
124
- return acc;
125
- },
126
- {} as Record<string, DotCMSBasicContentlet[]>
127
- );
128
- };
package/tsconfig.json DELETED
@@ -1,22 +0,0 @@
1
- {
2
- "extends": "../../../tsconfig.base.json",
3
- "compilerOptions": {
4
- "module": "ESNext",
5
- "forceConsistentCasingInFileNames": true,
6
- "strict": true,
7
- "noImplicitOverride": true,
8
- "noPropertyAccessFromIndexSignature": true,
9
- "noImplicitReturns": true,
10
- "noFallthroughCasesInSwitch": true
11
- },
12
- "files": [],
13
- "include": [],
14
- "references": [
15
- {
16
- "path": "./tsconfig.lib.json"
17
- },
18
- {
19
- "path": "./tsconfig.spec.json"
20
- }
21
- ]
22
- }
package/tsconfig.lib.json DELETED
@@ -1,13 +0,0 @@
1
- {
2
- "extends": "./tsconfig.json",
3
- "compilerOptions": {
4
- "outDir": "../../../dist/out-tsc",
5
- "declaration": true,
6
- "types": [""],
7
- "target": "es2020",
8
- "module": "es2020",
9
- "moduleResolution": "node"
10
- },
11
- "include": ["src/**/*.ts"],
12
- "exclude": ["jest.config.ts", "src/**/*.spec.ts", "src/**/*.test.ts"]
13
- }
@@ -1,9 +0,0 @@
1
- {
2
- "extends": "./tsconfig.json",
3
- "compilerOptions": {
4
- "outDir": "../../../dist/out-tsc",
5
- "module": "commonjs",
6
- "types": ["jest", "node"]
7
- },
8
- "include": ["jest.config.ts", "src/**/*.test.ts", "src/**/*.spec.ts", "src/**/*.d.ts"]
9
- }
File without changes
File without changes
File without changes