@remkoj/optimizely-graph-functions 6.0.0-pre8 → 6.0.0-rc.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +12 -12
- package/README.md +60 -14
- package/dist/_transform/cleanFragments.d.ts +10 -0
- package/dist/_transform/cleanFragments.js +39 -0
- package/dist/_transform/cleanFragments.js.map +1 -0
- package/dist/_transform/cleanSpreads.d.ts +10 -0
- package/dist/_transform/cleanSpreads.js +36 -0
- package/dist/_transform/cleanSpreads.js.map +1 -0
- package/dist/_transform/handleDependDirective.d.ts +11 -0
- package/dist/_transform/handleDependDirective.js +128 -0
- package/dist/_transform/handleDependDirective.js.map +1 -0
- package/dist/_transform/injectComponentDocuments.d.ts +16 -0
- package/dist/_transform/injectComponentDocuments.js +177 -0
- package/dist/_transform/injectComponentDocuments.js.map +1 -0
- package/dist/_transform/injectPageQueries.d.ts +5 -0
- package/dist/_transform/injectPageQueries.js +114 -0
- package/dist/_transform/injectPageQueries.js.map +1 -0
- package/dist/_transform/injectSectionQueries.d.ts +5 -0
- package/dist/_transform/injectSectionQueries.js +128 -0
- package/dist/_transform/injectSectionQueries.js.map +1 -0
- package/dist/_transform/normalizeFragmentNames.d.ts +12 -0
- package/dist/_transform/normalizeFragmentNames.js +77 -0
- package/dist/_transform/normalizeFragmentNames.js.map +1 -0
- package/dist/_transform/normalizeQueryNames.d.ts +12 -0
- package/dist/_transform/normalizeQueryNames.js +83 -0
- package/dist/_transform/normalizeQueryNames.js.map +1 -0
- package/dist/_transform/options.d.ts +3 -0
- package/dist/_transform/options.js +21 -0
- package/dist/_transform/options.js.map +1 -0
- package/dist/_transform/performInjections.d.ts +24 -0
- package/dist/_transform/performInjections.js +192 -0
- package/dist/_transform/performInjections.js.map +1 -0
- package/dist/_transform/tools.d.ts +34 -0
- package/dist/_transform/tools.js +103 -0
- package/dist/_transform/tools.js.map +1 -0
- package/dist/cms/index.d.ts +11 -0
- package/dist/cms/index.js +121 -0
- package/dist/cms/index.js.map +1 -0
- package/dist/contenttype-loader.d.ts +11 -0
- package/dist/contenttype-loader.js +72 -0
- package/dist/contenttype-loader.js.map +1 -0
- package/dist/documents/fragments.cms13.js +147 -39
- package/dist/documents/fragments.cms13.js.map +1 -1
- package/dist/documents/queries.cms13.js +9 -3
- package/dist/documents/queries.cms13.js.map +1 -1
- package/dist/embedded-loader.js +31 -16
- package/dist/embedded-loader.js.map +1 -1
- package/dist/generator/collision-tracker.d.ts +22 -0
- package/dist/generator/collision-tracker.js +103 -0
- package/dist/generator/collision-tracker.js.map +1 -0
- package/dist/generator/generator.d.ts +77 -0
- package/dist/generator/generator.js +272 -0
- package/dist/generator/generator.js.map +1 -0
- package/dist/generator/index.d.ts +3 -0
- package/dist/generator/index.js +42 -0
- package/dist/generator/index.js.map +1 -0
- package/dist/generator/virtual-location.d.ts +41 -0
- package/dist/generator/virtual-location.js +139 -0
- package/dist/generator/virtual-location.js.map +1 -0
- package/dist/index.d.ts +2 -5
- package/dist/index.js +4 -1
- package/dist/index.js.map +1 -1
- package/dist/preset.d.ts +2 -4
- package/dist/preset.js +112 -73
- package/dist/preset.js.map +1 -1
- package/dist/tools.d.ts +4 -0
- package/dist/tools.js +20 -0
- package/dist/tools.js.map +1 -0
- package/dist/transform.d.ts +12 -1
- package/dist/transform.js +48 -58
- package/dist/transform.js.map +1 -1
- package/dist/types.d.ts +23 -0
- package/package.json +27 -21
|
@@ -1,83 +1,170 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.default = [
|
|
4
|
-
`fragment
|
|
4
|
+
`fragment _IContentData on _IContent
|
|
5
5
|
{
|
|
6
6
|
_metadata {
|
|
7
|
-
|
|
7
|
+
key
|
|
8
|
+
locale
|
|
9
|
+
types
|
|
10
|
+
displayName
|
|
11
|
+
version
|
|
12
|
+
changeset
|
|
13
|
+
variation
|
|
14
|
+
url {
|
|
15
|
+
type
|
|
16
|
+
base
|
|
17
|
+
default
|
|
18
|
+
}
|
|
8
19
|
}
|
|
9
20
|
_type: __typename
|
|
10
21
|
}`,
|
|
11
|
-
`fragment
|
|
22
|
+
`fragment _IElementData on _IComponent {
|
|
12
23
|
_metadata {
|
|
13
|
-
|
|
24
|
+
key
|
|
25
|
+
locale
|
|
26
|
+
types
|
|
27
|
+
displayName
|
|
28
|
+
version
|
|
29
|
+
url {
|
|
30
|
+
type
|
|
31
|
+
base
|
|
32
|
+
default
|
|
33
|
+
}
|
|
14
34
|
}
|
|
15
35
|
_type: __typename
|
|
16
36
|
}`,
|
|
17
|
-
`fragment
|
|
18
|
-
...IElementData
|
|
19
|
-
}`,
|
|
20
|
-
`fragment BlockData on _IComponent {
|
|
21
|
-
...IContentData
|
|
22
|
-
}`,
|
|
23
|
-
`fragment PageData on _IContent {
|
|
24
|
-
...IContentData
|
|
25
|
-
}`,
|
|
26
|
-
`fragment LinkData on ContentUrl {
|
|
37
|
+
`fragment _LinkData on ContentUrl {
|
|
27
38
|
type
|
|
28
39
|
base
|
|
29
40
|
default
|
|
30
41
|
}`,
|
|
31
|
-
`fragment
|
|
42
|
+
`fragment _ReferenceData on ContentReference {
|
|
32
43
|
key
|
|
33
44
|
url {
|
|
34
|
-
|
|
45
|
+
type
|
|
46
|
+
base
|
|
47
|
+
default
|
|
35
48
|
}
|
|
36
49
|
}`,
|
|
37
|
-
`fragment
|
|
50
|
+
`fragment _IContentInfo on IContentMetadata {
|
|
38
51
|
key
|
|
39
52
|
locale
|
|
40
53
|
types
|
|
41
54
|
displayName
|
|
42
55
|
version
|
|
43
56
|
url {
|
|
44
|
-
|
|
57
|
+
type
|
|
58
|
+
base
|
|
59
|
+
default
|
|
45
60
|
}
|
|
46
61
|
}`,
|
|
47
|
-
`fragment
|
|
62
|
+
`fragment _IContentListItem on _IContent {
|
|
48
63
|
...IContentData
|
|
49
64
|
}`,
|
|
50
|
-
`fragment
|
|
65
|
+
`fragment _ExperienceData on _IExperience {
|
|
66
|
+
composition {
|
|
67
|
+
...CompositionNodeData
|
|
68
|
+
nodes {
|
|
69
|
+
...CompositionNodeData
|
|
70
|
+
... on CompositionComponentNode {
|
|
71
|
+
component {
|
|
72
|
+
...IContentData
|
|
73
|
+
...SectionElementData
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
... on CompositionStructureNode {
|
|
77
|
+
nodes {
|
|
78
|
+
...CompositionNodeData
|
|
79
|
+
... on CompositionStructureNode {
|
|
80
|
+
nodes {
|
|
81
|
+
...CompositionNodeData
|
|
82
|
+
... on CompositionStructureNode {
|
|
83
|
+
nodes {
|
|
84
|
+
...CompositionNodeData
|
|
85
|
+
... on CompositionComponentNode {
|
|
86
|
+
component {
|
|
87
|
+
...IContentData
|
|
88
|
+
...BlockData
|
|
89
|
+
...ElementData
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
... on CompositionStructureNode {
|
|
93
|
+
nodes {
|
|
94
|
+
...CompositionNodeData
|
|
95
|
+
... on CompositionComponentNode {
|
|
96
|
+
component {
|
|
97
|
+
...IContentData
|
|
98
|
+
...FormElementData
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
component {
|
|
109
|
+
...IContentData
|
|
110
|
+
...SectionData
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
}`,
|
|
116
|
+
`fragment _SectionCompositionData on _ISection {
|
|
51
117
|
composition {
|
|
52
|
-
# Experience level
|
|
53
118
|
...CompositionNodeData
|
|
54
119
|
nodes {
|
|
55
|
-
# Section level
|
|
56
120
|
...CompositionNodeData
|
|
57
|
-
... on
|
|
121
|
+
... on CompositionStructureNode {
|
|
58
122
|
nodes {
|
|
59
|
-
# Row level
|
|
60
123
|
...CompositionNodeData
|
|
61
|
-
... on
|
|
124
|
+
... on CompositionStructureNode {
|
|
62
125
|
nodes {
|
|
63
|
-
# Column level
|
|
64
126
|
...CompositionNodeData
|
|
65
|
-
... on
|
|
127
|
+
... on CompositionComponentNode {
|
|
128
|
+
component {
|
|
129
|
+
...IContentData
|
|
130
|
+
...BlockData
|
|
131
|
+
...ElementData
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
... on CompositionStructureNode {
|
|
66
135
|
nodes {
|
|
67
|
-
# Element level
|
|
68
136
|
...CompositionNodeData
|
|
69
|
-
...
|
|
137
|
+
... on CompositionComponentNode {
|
|
138
|
+
component {
|
|
139
|
+
...IContentData
|
|
140
|
+
...FormElementData
|
|
141
|
+
}
|
|
142
|
+
}
|
|
70
143
|
}
|
|
71
144
|
}
|
|
72
145
|
}
|
|
73
146
|
}
|
|
74
147
|
}
|
|
75
148
|
}
|
|
76
|
-
...CompositionComponentNodeData
|
|
77
149
|
}
|
|
78
150
|
}
|
|
79
151
|
}`,
|
|
80
|
-
`fragment
|
|
152
|
+
`fragment _CompositionStructureNode on ICompositionStructureNode {
|
|
153
|
+
nodes {
|
|
154
|
+
...CompositionNodeData
|
|
155
|
+
...CompositionStructureNode
|
|
156
|
+
...CompositionComponentNode
|
|
157
|
+
}
|
|
158
|
+
}`,
|
|
159
|
+
`fragment _CompositionComponentNode on CompositionComponentNode {
|
|
160
|
+
component {
|
|
161
|
+
...IContentData
|
|
162
|
+
...BlockData
|
|
163
|
+
...ElementData
|
|
164
|
+
...FormElementData
|
|
165
|
+
}
|
|
166
|
+
}`,
|
|
167
|
+
`fragment _CompositionNodeData on ICompositionNode {
|
|
81
168
|
name: displayName
|
|
82
169
|
layoutType: nodeType
|
|
83
170
|
type
|
|
@@ -88,18 +175,39 @@ exports.default = [
|
|
|
88
175
|
value
|
|
89
176
|
}
|
|
90
177
|
}`,
|
|
91
|
-
`fragment
|
|
92
|
-
component {
|
|
93
|
-
...BlockData
|
|
94
|
-
...ElementData
|
|
95
|
-
}
|
|
96
|
-
}`,
|
|
97
|
-
`fragment LinkItemData on Link {
|
|
178
|
+
`fragment _LinkItemData on Link {
|
|
98
179
|
title
|
|
99
180
|
text
|
|
100
181
|
target
|
|
101
182
|
url {
|
|
102
|
-
|
|
183
|
+
type
|
|
184
|
+
base
|
|
185
|
+
default
|
|
186
|
+
}
|
|
187
|
+
}`,
|
|
188
|
+
`fragment _CmpImageAssetInfo on cmp_PublicImageAsset {
|
|
189
|
+
__typename
|
|
190
|
+
Title
|
|
191
|
+
AltText
|
|
192
|
+
Width
|
|
193
|
+
Height
|
|
194
|
+
Url
|
|
195
|
+
Renditions {
|
|
196
|
+
Name
|
|
197
|
+
Width
|
|
198
|
+
Height
|
|
199
|
+
Url
|
|
200
|
+
}
|
|
201
|
+
}`,
|
|
202
|
+
`fragment _CmpVideoAssetInfo on cmp_PublicVideoAsset {
|
|
203
|
+
Title
|
|
204
|
+
AltText
|
|
205
|
+
Url
|
|
206
|
+
Renditions {
|
|
207
|
+
Name
|
|
208
|
+
Width
|
|
209
|
+
Height
|
|
210
|
+
Url
|
|
103
211
|
}
|
|
104
212
|
}`
|
|
105
213
|
];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fragments.cms13.js","sourceRoot":"","sources":["../../src/documents/fragments.cms13.ts"],"names":[],"mappings":";;AAAA,kBAAe;IACb
|
|
1
|
+
{"version":3,"file":"fragments.cms13.js","sourceRoot":"","sources":["../../src/documents/fragments.cms13.ts"],"names":[],"mappings":";;AAAA,kBAAe;IACb;;;;;;;;;;;;;;;;;EAiBA;IACA;;;;;;;;;;;;;;EAcA;IACA;;;;EAIA;IACA;;;;;;;EAOA;IACA;;;;;;;;;;;EAWA;IACA;;EAEA;IACA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAkDA;IACA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAmCA;IACA;;;;;;EAMA;IACA;;;;;;;EAOA;IACA;;;;;;;;;;EAUA;IACA;;;;;;;;;EASA;IACF;;;;;;;;;;;;;EAaE;IACF;;;;;;;;;;EAUE;CACD,CAAA"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.default = [
|
|
4
|
-
`query
|
|
4
|
+
`query _getContentById($key: String!, $version: String, $locale: [Locales!], $path: String = "-", $domain: String, $changeset: String) {
|
|
5
5
|
content: _Content(
|
|
6
6
|
variation: { include: ALL }
|
|
7
7
|
where: {
|
|
@@ -23,10 +23,15 @@ exports.default = [
|
|
|
23
23
|
...IContentData
|
|
24
24
|
...BlockData
|
|
25
25
|
...PageData
|
|
26
|
+
...ElementData
|
|
27
|
+
...ComponentData
|
|
28
|
+
...SectionData
|
|
29
|
+
...FormElementData
|
|
30
|
+
...SectionCompositionData
|
|
26
31
|
}
|
|
27
32
|
}
|
|
28
33
|
}`,
|
|
29
|
-
`query
|
|
34
|
+
`query _getContentByPath($path: [String!]!, $locale: [Locales!], $siteId: String, $changeset: String = null, $variation: VariationInput) {
|
|
30
35
|
content: _Content(
|
|
31
36
|
where: {
|
|
32
37
|
_metadata: {
|
|
@@ -35,6 +40,7 @@ exports.default = [
|
|
|
35
40
|
}
|
|
36
41
|
}
|
|
37
42
|
locale: $locale
|
|
43
|
+
variation:$variation
|
|
38
44
|
) {
|
|
39
45
|
total
|
|
40
46
|
items: item {
|
|
@@ -43,7 +49,7 @@ exports.default = [
|
|
|
43
49
|
}
|
|
44
50
|
}
|
|
45
51
|
}`,
|
|
46
|
-
`query
|
|
52
|
+
`query _getContentType($key: String!, $version: String, $locale: [Locales!], $path: String = "-", $domain: String) {
|
|
47
53
|
content: _Content(
|
|
48
54
|
variation: { include: ALL }
|
|
49
55
|
where: {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"queries.cms13.js","sourceRoot":"","sources":["../../src/documents/queries.cms13.ts"],"names":[],"mappings":";;AAAA,kBAAe;IACb
|
|
1
|
+
{"version":3,"file":"queries.cms13.js","sourceRoot":"","sources":["../../src/documents/queries.cms13.ts"],"names":[],"mappings":";;AAAA,kBAAe;IACb;;;;;;;;;;;;;;;;;;;;;;;;;;;;;MA6BI;IACJ;;;;;;;;;;;;;;;;;MAiBI;IACJ;;;;;;;;;;;;;;;;;;MAkBI;CACL,CAAA"}
|
package/dist/embedded-loader.js
CHANGED
|
@@ -14,24 +14,39 @@ const EmbeddedLoader = async (documentUri, config) => {
|
|
|
14
14
|
const docId = new URL(documentUri);
|
|
15
15
|
if (docId.protocol != "opti-cms:")
|
|
16
16
|
throw new Error("[Optimizely Graph Functions - Embedded Documents] Unsupported protocol, only the \"opti-cms:\" protocol is supported");
|
|
17
|
-
|
|
17
|
+
try {
|
|
18
|
+
const parsed = docId.pathname.split('/').filter(x => x && x.length > 0);
|
|
19
|
+
const requireTarget = `./documents/${parsed.at(0) ?? 'undefined'}.cms${parsed.at(1) ?? '13'}`;
|
|
20
|
+
const rawData = require(requireTarget).default;
|
|
21
|
+
return generateDocument(rawData, documentUri);
|
|
22
|
+
}
|
|
23
|
+
catch (e) {
|
|
24
|
+
console.error(e);
|
|
25
|
+
throw e;
|
|
26
|
+
}
|
|
27
|
+
/*
|
|
28
|
+
let rawData: string | string[] | undefined;
|
|
18
29
|
switch (docId.pathname) {
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
30
|
+
case "/fragments/13":
|
|
31
|
+
rawData = require("./documents/fragments.cms13").default
|
|
32
|
+
break
|
|
33
|
+
|
|
34
|
+
case "/queries/13":
|
|
35
|
+
rawData = require("./documents/queries.cms13").default
|
|
36
|
+
break
|
|
37
|
+
|
|
38
|
+
case "/fragments/12":
|
|
39
|
+
rawData = require("./documents/fragments.cms12").default
|
|
40
|
+
break
|
|
41
|
+
|
|
42
|
+
case "/queries/12":
|
|
43
|
+
rawData = require("./documents/queries.cms12").default
|
|
44
|
+
break
|
|
45
|
+
|
|
46
|
+
default:
|
|
47
|
+
throw new Error(`[Optimizely Graph Functions - Embedded Documents] Path not found: ${docId.pathname}`)
|
|
33
48
|
}
|
|
34
|
-
return generateDocument(rawData, documentUri)
|
|
49
|
+
return generateDocument(rawData, documentUri)*/
|
|
35
50
|
};
|
|
36
51
|
function generateDocument(rawData, location) {
|
|
37
52
|
if (rawData == undefined)
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"embedded-loader.js","sourceRoot":"","sources":["../src/embedded-loader.ts"],"names":[],"mappings":";;AACA,qCAA+B;AAU/B;;;;;;;;GAQG;AACH,MAAM,cAAc,
|
|
1
|
+
{"version":3,"file":"embedded-loader.js","sourceRoot":"","sources":["../src/embedded-loader.ts"],"names":[],"mappings":";;AACA,qCAA+B;AAU/B;;;;;;;;GAQG;AACH,MAAM,cAAc,GAAmB,KAAK,EAAE,WAAW,EAAE,MAAM,EAAE,EAAE;IACnE,MAAM,KAAK,GAAG,IAAI,GAAG,CAAC,WAAW,CAAC,CAAA;IAClC,IAAI,KAAK,CAAC,QAAQ,IAAI,WAAW;QAC/B,MAAM,IAAI,KAAK,CAAC,sHAAsH,CAAC,CAAA;IAEzI,IAAI,CAAC;QACH,MAAM,MAAM,GAAG,KAAK,CAAC,QAAQ,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,IAAI,CAAC,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;QACxE,MAAM,aAAa,GAAG,eAAe,MAAM,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,WAAW,OAAO,MAAM,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,IAAI,EAAE,CAAC;QAC9F,MAAM,OAAO,GAAG,OAAO,CAAC,aAAa,CAAC,CAAC,OAAO,CAAA;QAC9C,OAAO,gBAAgB,CAAC,OAAO,EAAE,WAAW,CAAC,CAAA;IAC/C,CAAC;IAAC,OAAO,CAAC,EAAE,CAAC;QACX,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,CAAA;QAChB,MAAM,CAAC,CAAA;IACT,CAAC;IACD;;;;;;;;;;;;;;;;;;;;;;mDAsB+C;AACjD,CAAC,CAAA;AAED,SAAS,gBAAgB,CAAC,OAAsC,EAAE,QAAiB;IACjF,IAAI,OAAO,IAAI,SAAS;QACtB,OAAO,SAAS,CAAA;IAClB,MAAM,MAAM,GAAG,KAAK,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,OAAO,CAAA;IACtE,MAAM,QAAQ,GAAG,IAAA,eAAK,EAAC,MAAM,CAAC,CAAA;IAE9B,OAAO;QACL,QAAQ;QACR,QAAQ;QACR,MAAM;QACN,IAAI,EAAE,QAAQ;KACf,CAAA;AACH,CAAC;AAED,kBAAe,cAAc,CAAA"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tracker for all properties, indexed by property name, then type
|
|
3
|
+
* for a list of all ContentTypes. This uses a lock file to remember
|
|
4
|
+
* any collision resolutions done by the code generation.
|
|
5
|
+
*/
|
|
6
|
+
export declare class PropertyCollisionTracker extends Map<string, string> {
|
|
7
|
+
private _cwd;
|
|
8
|
+
private _ready;
|
|
9
|
+
set cwd(newValue: string | undefined);
|
|
10
|
+
get cwd(): string | undefined;
|
|
11
|
+
constructor(cwd?: string);
|
|
12
|
+
private ensureReady;
|
|
13
|
+
private updateLock;
|
|
14
|
+
private readLock;
|
|
15
|
+
private isMapData;
|
|
16
|
+
has(key: string): boolean;
|
|
17
|
+
set(key: string, value: string): this;
|
|
18
|
+
get(key: string): string | undefined;
|
|
19
|
+
delete(key: string): boolean;
|
|
20
|
+
clear(): void;
|
|
21
|
+
}
|
|
22
|
+
export default PropertyCollisionTracker;
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.PropertyCollisionTracker = void 0;
|
|
7
|
+
const node_path_1 = __importDefault(require("node:path"));
|
|
8
|
+
const node_fs_1 = __importDefault(require("node:fs"));
|
|
9
|
+
/**
|
|
10
|
+
* Tracker for all properties, indexed by property name, then type
|
|
11
|
+
* for a list of all ContentTypes. This uses a lock file to remember
|
|
12
|
+
* any collision resolutions done by the code generation.
|
|
13
|
+
*/
|
|
14
|
+
class PropertyCollisionTracker extends Map {
|
|
15
|
+
set cwd(newValue) {
|
|
16
|
+
if (newValue !== this._cwd) {
|
|
17
|
+
this._cwd = newValue;
|
|
18
|
+
super.clear();
|
|
19
|
+
if (newValue === undefined) {
|
|
20
|
+
this._ready = false;
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
23
|
+
this.readLock();
|
|
24
|
+
this._ready = true;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
get cwd() {
|
|
28
|
+
return this._cwd;
|
|
29
|
+
}
|
|
30
|
+
constructor(cwd) {
|
|
31
|
+
super();
|
|
32
|
+
this._ready = false;
|
|
33
|
+
this.cwd = cwd;
|
|
34
|
+
}
|
|
35
|
+
ensureReady() {
|
|
36
|
+
if (!this._ready)
|
|
37
|
+
throw new Error("NOT READY");
|
|
38
|
+
}
|
|
39
|
+
updateLock() {
|
|
40
|
+
if (!this._cwd)
|
|
41
|
+
throw new Error("Working directory unknown");
|
|
42
|
+
const file = node_path_1.default.join(this._cwd, '.opti-props.lock');
|
|
43
|
+
const data = [];
|
|
44
|
+
for (const [entryKey, entryValue] of super.entries())
|
|
45
|
+
data.push({ propertyName: entryKey, propertyType: entryValue });
|
|
46
|
+
const raw = JSON.stringify(data, undefined, ' ');
|
|
47
|
+
node_fs_1.default.writeFileSync(file, raw, { encoding: 'utf-8' });
|
|
48
|
+
}
|
|
49
|
+
readLock() {
|
|
50
|
+
try {
|
|
51
|
+
if (!this._cwd)
|
|
52
|
+
throw new Error("Working directory unknown");
|
|
53
|
+
const file = node_path_1.default.join(this._cwd, '.opti-props.lock');
|
|
54
|
+
const raw = node_fs_1.default.readFileSync(file, { encoding: 'utf-8' });
|
|
55
|
+
const data = raw.length > 0 ? JSON.parse(raw) : [];
|
|
56
|
+
if (!Array.isArray(data))
|
|
57
|
+
throw new Error(`Invalid lock file at ${file}`);
|
|
58
|
+
for (const itm of data.filter(this.isMapData))
|
|
59
|
+
super.set(itm.propertyName, itm.propertyType);
|
|
60
|
+
}
|
|
61
|
+
catch (e) {
|
|
62
|
+
if (e.code === 'ENOENT')
|
|
63
|
+
return [];
|
|
64
|
+
throw e;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
isMapData(v) {
|
|
68
|
+
if (typeof (v) !== 'object' || v === null)
|
|
69
|
+
return false;
|
|
70
|
+
return typeof (v.propertyName) === 'string' && typeof (v.propertyType) === 'string';
|
|
71
|
+
}
|
|
72
|
+
has(key) {
|
|
73
|
+
this.ensureReady();
|
|
74
|
+
return super.has(key);
|
|
75
|
+
}
|
|
76
|
+
set(key, value) {
|
|
77
|
+
this.ensureReady();
|
|
78
|
+
const cv = super.get(key);
|
|
79
|
+
if (cv !== value) {
|
|
80
|
+
super.set(key, value);
|
|
81
|
+
this.updateLock();
|
|
82
|
+
}
|
|
83
|
+
return this;
|
|
84
|
+
}
|
|
85
|
+
get(key) {
|
|
86
|
+
this.ensureReady();
|
|
87
|
+
return super.get(key);
|
|
88
|
+
}
|
|
89
|
+
delete(key) {
|
|
90
|
+
this.ensureReady();
|
|
91
|
+
const res = super.delete(key);
|
|
92
|
+
this.updateLock();
|
|
93
|
+
return res;
|
|
94
|
+
}
|
|
95
|
+
clear() {
|
|
96
|
+
this.ensureReady();
|
|
97
|
+
super.clear();
|
|
98
|
+
this.updateLock();
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
exports.PropertyCollisionTracker = PropertyCollisionTracker;
|
|
102
|
+
exports.default = PropertyCollisionTracker;
|
|
103
|
+
//# sourceMappingURL=collision-tracker.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"collision-tracker.js","sourceRoot":"","sources":["../../src/generator/collision-tracker.ts"],"names":[],"mappings":";;;;;;AAAA,0DAA6B;AAC7B,sDAAwB;AAExB;;;;GAIG;AACH,MAAa,wBAAyB,SAAQ,GAAkB;IAI9D,IAAW,GAAG,CAAC,QAA4B;QAEzC,IAAI,QAAQ,KAAK,IAAI,CAAC,IAAI,EAAE,CAAC;YAC3B,IAAI,CAAC,IAAI,GAAG,QAAQ,CAAA;YACpB,KAAK,CAAC,KAAK,EAAE,CAAC;YACd,IAAI,QAAQ,KAAK,SAAS,EAAE,CAAC;gBAC3B,IAAI,CAAC,MAAM,GAAG,KAAK,CAAC;gBACpB,OAAM;YACR,CAAC;YAED,IAAI,CAAC,QAAQ,EAAE,CAAC;YAChB,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC;QACrB,CAAC;IACH,CAAC;IAED,IAAW,GAAG;QACZ,OAAO,IAAI,CAAC,IAAI,CAAA;IAClB,CAAC;IAED,YAAmB,GAAY;QAE7B,KAAK,EAAE,CAAA;QAvBD,WAAM,GAAY,KAAK,CAAC;QAwB9B,IAAI,CAAC,GAAG,GAAG,GAAG,CAAA;IAChB,CAAC;IAEO,WAAW;QAEjB,IAAI,CAAC,IAAI,CAAC,MAAM;YACd,MAAM,IAAI,KAAK,CAAC,WAAW,CAAC,CAAA;IAChC,CAAC;IAEO,UAAU;QAEhB,IAAI,CAAC,IAAI,CAAC,IAAI;YACZ,MAAM,IAAI,KAAK,CAAC,2BAA2B,CAAC,CAAC;QAC/C,MAAM,IAAI,GAAG,mBAAI,CAAC,IAAI,CAAC,IAAI,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,CAAC,UAAU,EAAE,CAAA;IACnB,CAAC;CACF;AAzGD,4DAyGC;AAED,kBAAe,wBAAwB,CAAA"}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { type IntegrationApi } from '@remkoj/optimizely-cms-api';
|
|
2
|
+
/**
|
|
3
|
+
* Generate GraphQL fragments and queries for Optimizely Graph,
|
|
4
|
+
* based upon the content type definitions within an Optimizely
|
|
5
|
+
* CMS instance.
|
|
6
|
+
*/
|
|
7
|
+
export declare class DocumentGenerator {
|
|
8
|
+
protected _allContentTypes: Map<string, IntegrationApi.ContentType>;
|
|
9
|
+
constructor(allContentTypes?: Map<string, IntegrationApi.ContentType>);
|
|
10
|
+
/**
|
|
11
|
+
* Get the Graph Type for the Content Type, this imitates the logic
|
|
12
|
+
* within Optimizely CMS to transform a ContentType key into a type
|
|
13
|
+
* within Optimizely Graph.
|
|
14
|
+
*
|
|
15
|
+
* @param contentType
|
|
16
|
+
* @returns
|
|
17
|
+
*/
|
|
18
|
+
getGraphType(contentType: IntegrationApi.ContentType | string): string;
|
|
19
|
+
/**
|
|
20
|
+
* Get the Graph Type for the Content Type, when it's used as a property,
|
|
21
|
+
* this imitates the logic within Optimizely CMS to transform a ContentType
|
|
22
|
+
* key into a type within Optimizely Graph.
|
|
23
|
+
*
|
|
24
|
+
* @param contentType
|
|
25
|
+
* @returns
|
|
26
|
+
*/
|
|
27
|
+
getGraphPropertyType(contentType: IntegrationApi.ContentType | string): string;
|
|
28
|
+
/**
|
|
29
|
+
* Retrieve the default name for the data query for the given content type
|
|
30
|
+
*
|
|
31
|
+
* @param contentType
|
|
32
|
+
* @returns
|
|
33
|
+
*/
|
|
34
|
+
getDefaultQueryName(contentType: IntegrationApi.ContentType | string): string;
|
|
35
|
+
/**
|
|
36
|
+
* Retrieve the default name for the data fragment for the given content type
|
|
37
|
+
*
|
|
38
|
+
* @param contentType
|
|
39
|
+
* @returns
|
|
40
|
+
*/
|
|
41
|
+
getDefaultFragmentName(contentType: IntegrationApi.ContentType | string): string;
|
|
42
|
+
/**
|
|
43
|
+
* Retrieve the default name for the fragment when the content type is used as
|
|
44
|
+
* property
|
|
45
|
+
*
|
|
46
|
+
* @param contentType
|
|
47
|
+
* @returns
|
|
48
|
+
*/
|
|
49
|
+
getDefaultPropertyFragmentName(contentType: IntegrationApi.ContentType | string): string;
|
|
50
|
+
private getSlugFromKey;
|
|
51
|
+
/**
|
|
52
|
+
* Build the GraphQL fragment that is used as injection target
|
|
53
|
+
*
|
|
54
|
+
* @param injectionTarget
|
|
55
|
+
* @returns
|
|
56
|
+
*/
|
|
57
|
+
buildInjectionTarget(injectionTarget: string): string;
|
|
58
|
+
/**
|
|
59
|
+
* Build a query to retrieve the data for a specific content type by identifier
|
|
60
|
+
*
|
|
61
|
+
* @param contentType
|
|
62
|
+
* @param queryName
|
|
63
|
+
* @param propertyTracker
|
|
64
|
+
* @returns
|
|
65
|
+
*/
|
|
66
|
+
buildGetQuery(contentType: IntegrationApi.ContentType, queryName?: string | ((defaultName: string) => string), propertyTracker?: Map<string, string>): string;
|
|
67
|
+
buildFragment(contentType: IntegrationApi.ContentType, fragmentName?: string | ((defaultName: string) => string), forProperty?: boolean, propertyTracker?: Map<string, string>): string;
|
|
68
|
+
/**
|
|
69
|
+
* Retrieve a list of component keys that are referenced as property by this type
|
|
70
|
+
*
|
|
71
|
+
* @param contentType
|
|
72
|
+
* @returns
|
|
73
|
+
*/
|
|
74
|
+
static getReferencedPropertyComponents(contentType: IntegrationApi.ContentType): string[];
|
|
75
|
+
protected buildProperty(propertyName: string, propertyConfig?: IntegrationApi.ContentTypeProperty, propertyTracker?: Map<string, string>): string | null;
|
|
76
|
+
protected getTypeKeysFor(contentTypeRestriction: string): string | string[];
|
|
77
|
+
}
|