@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
|
@@ -0,0 +1,272 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DocumentGenerator = void 0;
|
|
4
|
+
const tools_1 = require("../tools");
|
|
5
|
+
/**
|
|
6
|
+
* Generate GraphQL fragments and queries for Optimizely Graph,
|
|
7
|
+
* based upon the content type definitions within an Optimizely
|
|
8
|
+
* CMS instance.
|
|
9
|
+
*/
|
|
10
|
+
class DocumentGenerator {
|
|
11
|
+
constructor(allContentTypes) {
|
|
12
|
+
this._allContentTypes = allContentTypes ?? new Map();
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Get the Graph Type for the Content Type, this imitates the logic
|
|
16
|
+
* within Optimizely CMS to transform a ContentType key into a type
|
|
17
|
+
* within Optimizely Graph.
|
|
18
|
+
*
|
|
19
|
+
* @param contentType
|
|
20
|
+
* @returns
|
|
21
|
+
*/
|
|
22
|
+
getGraphType(contentType) {
|
|
23
|
+
const itemKey = ((0, tools_1.isNonEmptyString)(contentType) ? contentType : contentType?.key) ?? "_IContent";
|
|
24
|
+
return itemKey;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Get the Graph Type for the Content Type, when it's used as a property,
|
|
28
|
+
* this imitates the logic within Optimizely CMS to transform a ContentType
|
|
29
|
+
* key into a type within Optimizely Graph.
|
|
30
|
+
*
|
|
31
|
+
* @param contentType
|
|
32
|
+
* @returns
|
|
33
|
+
*/
|
|
34
|
+
getGraphPropertyType(contentType) {
|
|
35
|
+
return this.getGraphType(contentType) + "Property";
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Retrieve the default name for the data query for the given content type
|
|
39
|
+
*
|
|
40
|
+
* @param contentType
|
|
41
|
+
* @returns
|
|
42
|
+
*/
|
|
43
|
+
getDefaultQueryName(contentType) {
|
|
44
|
+
const graphType = this.getGraphType(contentType);
|
|
45
|
+
return `get${this.getSlugFromKey(graphType)}Data`;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Retrieve the default name for the data fragment for the given content type
|
|
49
|
+
*
|
|
50
|
+
* @param contentType
|
|
51
|
+
* @returns
|
|
52
|
+
*/
|
|
53
|
+
getDefaultFragmentName(contentType) {
|
|
54
|
+
const graphType = this.getGraphType(contentType);
|
|
55
|
+
return this.getSlugFromKey(graphType) + "Data";
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Retrieve the default name for the fragment when the content type is used as
|
|
59
|
+
* property
|
|
60
|
+
*
|
|
61
|
+
* @param contentType
|
|
62
|
+
* @returns
|
|
63
|
+
*/
|
|
64
|
+
getDefaultPropertyFragmentName(contentType) {
|
|
65
|
+
const graphPropertyType = this.getGraphPropertyType(contentType);
|
|
66
|
+
return this.getSlugFromKey(graphPropertyType) + "Data";
|
|
67
|
+
}
|
|
68
|
+
getSlugFromKey(key) {
|
|
69
|
+
let newKey = key.startsWith('_') ? (0, tools_1.ucFirst)(key.substring(1)) : key;
|
|
70
|
+
if (newKey.includes(":"))
|
|
71
|
+
newKey = newKey.split(":").map(x => (0, tools_1.ucFirst)(x)).join("");
|
|
72
|
+
return newKey;
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Build the GraphQL fragment that is used as injection target
|
|
76
|
+
*
|
|
77
|
+
* @param injectionTarget
|
|
78
|
+
* @returns
|
|
79
|
+
*/
|
|
80
|
+
buildInjectionTarget(injectionTarget) {
|
|
81
|
+
return `fragment ${injectionTarget} on _IContent { ...IContentData }`;
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Build a query to retrieve the data for a specific content type by identifier
|
|
85
|
+
*
|
|
86
|
+
* @param contentType
|
|
87
|
+
* @param queryName
|
|
88
|
+
* @param propertyTracker
|
|
89
|
+
* @returns
|
|
90
|
+
*/
|
|
91
|
+
buildGetQuery(contentType, queryName, propertyTracker = new Map()) {
|
|
92
|
+
// Prepare
|
|
93
|
+
if (!contentType.key || contentType.source === 'graph')
|
|
94
|
+
return '';
|
|
95
|
+
const graphType = this.getGraphType(contentType);
|
|
96
|
+
const renderedQueryName = (0, tools_1.isNonEmptyString)(queryName) ? queryName :
|
|
97
|
+
(typeof queryName === 'function' ?
|
|
98
|
+
queryName(this.getDefaultQueryName(contentType)) :
|
|
99
|
+
this.getDefaultQueryName(contentType));
|
|
100
|
+
// Render properties
|
|
101
|
+
const properties = [];
|
|
102
|
+
for (const propName of Object.getOwnPropertyNames(contentType.properties ?? {}))
|
|
103
|
+
properties.push(this.buildProperty(propName, (contentType.properties || {})[propName], propertyTracker));
|
|
104
|
+
// Inject base type based defaults
|
|
105
|
+
if (contentType.baseType === "_experience")
|
|
106
|
+
properties.unshift("...ExperienceData");
|
|
107
|
+
if (contentType.baseType === "_section")
|
|
108
|
+
properties.unshift("...SectionCompositionData");
|
|
109
|
+
//Render query
|
|
110
|
+
const query = `query ${renderedQueryName}($key: [String!]!, $locale: [Locales], $changeset: String, $variation: VariationInput, $version: String) {
|
|
111
|
+
data: ${graphType}(
|
|
112
|
+
ids: $key
|
|
113
|
+
locale: $locale
|
|
114
|
+
variation: $variation
|
|
115
|
+
where: { _metadata: { changeset: { eq: $changeset }, version: { eq: $version } } }
|
|
116
|
+
) {
|
|
117
|
+
total
|
|
118
|
+
item {
|
|
119
|
+
_metadata {
|
|
120
|
+
key
|
|
121
|
+
version
|
|
122
|
+
locale
|
|
123
|
+
changeset
|
|
124
|
+
variation
|
|
125
|
+
}
|
|
126
|
+
${properties.filter(tools_1.isNonEmptyString).join("\n ")}
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
}`;
|
|
130
|
+
return query;
|
|
131
|
+
}
|
|
132
|
+
buildFragment(contentType, fragmentName, forProperty = false, propertyTracker = new Map()) {
|
|
133
|
+
if (!contentType.key)
|
|
134
|
+
return '';
|
|
135
|
+
const graphType = forProperty ? this.getGraphPropertyType(contentType) : this.getGraphType(contentType);
|
|
136
|
+
const defaultFragmentName = forProperty ? this.getDefaultPropertyFragmentName(contentType) : this.getDefaultFragmentName(contentType);
|
|
137
|
+
const graphFragmentName = (0, tools_1.isNonEmptyString)(fragmentName) ?
|
|
138
|
+
fragmentName : (typeof fragmentName === 'function' ? fragmentName(defaultFragmentName) : defaultFragmentName);
|
|
139
|
+
// Inject all properties
|
|
140
|
+
const properties = [];
|
|
141
|
+
for (const propName of Object.getOwnPropertyNames(contentType.properties ?? {}))
|
|
142
|
+
properties.push(this.buildProperty(propName, (contentType.properties || {})[propName], propertyTracker));
|
|
143
|
+
// Inject base type based defaults
|
|
144
|
+
if (contentType.baseType === "_experience")
|
|
145
|
+
properties.push("...ExperienceData");
|
|
146
|
+
// Ensure that there's at least one property
|
|
147
|
+
if (properties.filter(tools_1.isNonEmptyString).length === 0)
|
|
148
|
+
properties.unshift("__typename");
|
|
149
|
+
// Construct fragment rawSDL
|
|
150
|
+
return `fragment ${graphFragmentName} on ${graphType} {
|
|
151
|
+
${properties.filter(tools_1.isNonEmptyString).join("\n ")}
|
|
152
|
+
}`;
|
|
153
|
+
}
|
|
154
|
+
/**
|
|
155
|
+
* Retrieve a list of component keys that are referenced as property by this type
|
|
156
|
+
*
|
|
157
|
+
* @param contentType
|
|
158
|
+
* @returns
|
|
159
|
+
*/
|
|
160
|
+
static getReferencedPropertyComponents(contentType) {
|
|
161
|
+
const properties = contentType.properties;
|
|
162
|
+
if (!properties)
|
|
163
|
+
return [];
|
|
164
|
+
return Object.getOwnPropertyNames(properties).reduce((referencedTypes, propertyKey) => {
|
|
165
|
+
if (properties[propertyKey].type == "component" && properties[propertyKey].contentType) {
|
|
166
|
+
referencedTypes.push(properties[propertyKey]?.contentType);
|
|
167
|
+
}
|
|
168
|
+
if (properties[propertyKey].type == "array" && properties[propertyKey].items?.type == "component" && properties[propertyKey].items?.contentType) {
|
|
169
|
+
referencedTypes.push(properties[propertyKey]?.items?.contentType);
|
|
170
|
+
}
|
|
171
|
+
return referencedTypes;
|
|
172
|
+
}, []);
|
|
173
|
+
}
|
|
174
|
+
buildProperty(propertyName, propertyConfig, propertyTracker = new Map()) {
|
|
175
|
+
// Skip all disabled properties
|
|
176
|
+
if (propertyConfig?.indexingType === "disabled")
|
|
177
|
+
return null;
|
|
178
|
+
// Get type information rendering
|
|
179
|
+
const propertyItemConfig = propertyConfig?.type === 'array' ? propertyConfig?.items ?? propertyConfig : propertyConfig;
|
|
180
|
+
const propertyType = propertyItemConfig?.type ?? 'any';
|
|
181
|
+
// Ensure we don't have property naming collisions
|
|
182
|
+
let outputPropertyName = propertyName;
|
|
183
|
+
if (propertyTracker.has(propertyName)) {
|
|
184
|
+
if (propertyTracker.get(propertyName) != propertyType) {
|
|
185
|
+
outputPropertyName = `${propertyName}${(0, tools_1.ucFirst)(propertyType)}: ${propertyName}`;
|
|
186
|
+
propertyTracker.set(`${propertyName}${(0, tools_1.ucFirst)(propertyType)}`, propertyType);
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
else {
|
|
190
|
+
propertyTracker.set(propertyName, propertyType);
|
|
191
|
+
}
|
|
192
|
+
// Render property
|
|
193
|
+
switch (propertyType) {
|
|
194
|
+
case 'url':
|
|
195
|
+
return outputPropertyName + " { type base default }";
|
|
196
|
+
case 'content': {
|
|
197
|
+
// Resolve allowed/restricted
|
|
198
|
+
const allowedTypes = (propertyItemConfig?.allowedTypes ?? []);
|
|
199
|
+
const restrictedTypes = (propertyItemConfig?.restrictedTypes ?? []);
|
|
200
|
+
const pickFrom = allowedTypes.flatMap(tn => this.getTypeKeysFor(tn));
|
|
201
|
+
const restrictBy = restrictedTypes.flatMap(tn => this.getTypeKeysFor(tn));
|
|
202
|
+
// Prepare data
|
|
203
|
+
const allowAny = pickFrom.length == 0 && restrictBy.length == 0;
|
|
204
|
+
const spreads = new Set();
|
|
205
|
+
spreads.add('IContentData');
|
|
206
|
+
if (allowAny) {
|
|
207
|
+
['BlockData', 'ComponentData'].forEach(x => spreads.add(x));
|
|
208
|
+
}
|
|
209
|
+
else {
|
|
210
|
+
const base = pickFrom.length > 0 ? pickFrom : Array.from(this._allContentTypes.keys());
|
|
211
|
+
const filtered = base.filter(x => !restrictBy.includes(x));
|
|
212
|
+
filtered.forEach(typeName => spreads.add(this.getDefaultFragmentName(typeName)));
|
|
213
|
+
}
|
|
214
|
+
return `${outputPropertyName} {\n ${Array.from(spreads).map(spread => `...${spread}`).join('\n ')} \n}`;
|
|
215
|
+
}
|
|
216
|
+
case 'richText':
|
|
217
|
+
return outputPropertyName + " { json }";
|
|
218
|
+
case 'component': {
|
|
219
|
+
const dataType = propertyItemConfig?.contentType;
|
|
220
|
+
if (!dataType)
|
|
221
|
+
return null; // Skip this property if the contentType isn't set
|
|
222
|
+
return outputPropertyName + ` { ...${dataType}PropertyData }`;
|
|
223
|
+
}
|
|
224
|
+
case 'link':
|
|
225
|
+
return outputPropertyName + ` {
|
|
226
|
+
title
|
|
227
|
+
text
|
|
228
|
+
target
|
|
229
|
+
url {
|
|
230
|
+
type
|
|
231
|
+
base
|
|
232
|
+
default
|
|
233
|
+
}
|
|
234
|
+
}`;
|
|
235
|
+
case 'contentReference': {
|
|
236
|
+
return outputPropertyName + ` {
|
|
237
|
+
key
|
|
238
|
+
url {
|
|
239
|
+
type
|
|
240
|
+
base
|
|
241
|
+
default
|
|
242
|
+
}
|
|
243
|
+
item @depend(on: "ContentReference.item") {
|
|
244
|
+
__typename
|
|
245
|
+
...CmpImageAssetInfo
|
|
246
|
+
...CmpVideoAssetInfo
|
|
247
|
+
}
|
|
248
|
+
}`;
|
|
249
|
+
}
|
|
250
|
+
default:
|
|
251
|
+
return outputPropertyName;
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
getTypeKeysFor(contentTypeRestriction) {
|
|
255
|
+
if (this._allContentTypes.size === 0)
|
|
256
|
+
return contentTypeRestriction;
|
|
257
|
+
const allTypes = [];
|
|
258
|
+
// Add type if it exists
|
|
259
|
+
if (this._allContentTypes.has(contentTypeRestriction))
|
|
260
|
+
allTypes.push(contentTypeRestriction);
|
|
261
|
+
// Add children
|
|
262
|
+
this._allContentTypes.forEach((contentType, contentTypeKey) => {
|
|
263
|
+
if (contentType.baseType === contentTypeRestriction) {
|
|
264
|
+
const baseRestrictions = this.getTypeKeysFor(contentTypeKey);
|
|
265
|
+
allTypes.push(...baseRestrictions);
|
|
266
|
+
}
|
|
267
|
+
});
|
|
268
|
+
return allTypes;
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
exports.DocumentGenerator = DocumentGenerator;
|
|
272
|
+
//# sourceMappingURL=generator.js.map
|
|
@@ -0,0 +1 @@
|
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AI,CAAC,GAAG,gBAAgB,CAAC,CAAA;YACpC,CAAC;QACH,CAAC,CAAC,CAAA;QAEF,OAAO,QAAQ,CAAC;IAClB,CAAC;CACF;AAlSD,8CAkSC"}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.VirtualLocation = exports.DocumentGenerator = exports.PropertyCollisionTracker = void 0;
|
|
37
|
+
var collision_tracker_1 = require("./collision-tracker");
|
|
38
|
+
Object.defineProperty(exports, "PropertyCollisionTracker", { enumerable: true, get: function () { return collision_tracker_1.PropertyCollisionTracker; } });
|
|
39
|
+
var generator_1 = require("./generator");
|
|
40
|
+
Object.defineProperty(exports, "DocumentGenerator", { enumerable: true, get: function () { return generator_1.DocumentGenerator; } });
|
|
41
|
+
exports.VirtualLocation = __importStar(require("./virtual-location"));
|
|
42
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/generator/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,yDAA8D;AAArD,6HAAA,wBAAwB,OAAA;AACjC,yCAA+C;AAAtC,8GAAA,iBAAiB,OAAA;AAC1B,sEAAqD"}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import type { IntegrationApi } from "@remkoj/optimizely-cms-api";
|
|
2
|
+
export type VirtualLocationOptions = {
|
|
3
|
+
forProperty: boolean;
|
|
4
|
+
type: 'fragment' | 'query' | 'target';
|
|
5
|
+
};
|
|
6
|
+
export type VirtualLocationData = {
|
|
7
|
+
contentTypeBase: string;
|
|
8
|
+
contentTypeKey: string;
|
|
9
|
+
injectionTargets: Array<string>;
|
|
10
|
+
} & VirtualLocationOptions;
|
|
11
|
+
/**
|
|
12
|
+
* The list of injection targets where fragments may be injected within the
|
|
13
|
+
* default queries.
|
|
14
|
+
*/
|
|
15
|
+
export declare enum ContentTypeTarget {
|
|
16
|
+
'SectionData' = "SectionData",
|
|
17
|
+
'PageData' = "PageData",
|
|
18
|
+
'MediaData' = "MediaData",
|
|
19
|
+
'ComponentData' = "ComponentData",
|
|
20
|
+
'ElementData' = "ElementData",
|
|
21
|
+
'SectionElementData' = "SectionElementData",
|
|
22
|
+
'FormElementData' = "FormElementData",
|
|
23
|
+
'BlockData' = "BlockData"
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Get a list of names of all supported injection targets, where fragments may be
|
|
27
|
+
* injected within the default queries.
|
|
28
|
+
*
|
|
29
|
+
* @returns The list of names
|
|
30
|
+
*/
|
|
31
|
+
export declare function getInjectionTargets(): string[];
|
|
32
|
+
/**
|
|
33
|
+
* Take an `opti-cms:/` virtual path and parse it to get the configuraiton of
|
|
34
|
+
* the fragment/query to be generated.
|
|
35
|
+
*
|
|
36
|
+
* @param virtualPath The virtual path
|
|
37
|
+
* @returns The fragment/query configuration
|
|
38
|
+
*/
|
|
39
|
+
export declare function parse(virtualPath: string): VirtualLocationData | undefined;
|
|
40
|
+
export declare function build(injectionFragment: string): string;
|
|
41
|
+
export declare function build(contentType: IntegrationApi.ContentType, options?: Partial<VirtualLocationOptions>): string | undefined;
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ContentTypeTarget = void 0;
|
|
4
|
+
exports.getInjectionTargets = getInjectionTargets;
|
|
5
|
+
exports.parse = parse;
|
|
6
|
+
exports.build = build;
|
|
7
|
+
const tools_1 = require("../tools");
|
|
8
|
+
const DefaultVirtualLocationOptions = { forProperty: false, type: 'fragment' };
|
|
9
|
+
/**
|
|
10
|
+
* The list of injection targets where fragments may be injected within the
|
|
11
|
+
* default queries.
|
|
12
|
+
*/
|
|
13
|
+
var ContentTypeTarget;
|
|
14
|
+
(function (ContentTypeTarget) {
|
|
15
|
+
ContentTypeTarget["SectionData"] = "SectionData";
|
|
16
|
+
ContentTypeTarget["PageData"] = "PageData";
|
|
17
|
+
ContentTypeTarget["MediaData"] = "MediaData";
|
|
18
|
+
ContentTypeTarget["ComponentData"] = "ComponentData";
|
|
19
|
+
ContentTypeTarget["ElementData"] = "ElementData";
|
|
20
|
+
ContentTypeTarget["SectionElementData"] = "SectionElementData";
|
|
21
|
+
ContentTypeTarget["FormElementData"] = "FormElementData";
|
|
22
|
+
ContentTypeTarget["BlockData"] = "BlockData";
|
|
23
|
+
})(ContentTypeTarget || (exports.ContentTypeTarget = ContentTypeTarget = {}));
|
|
24
|
+
/**
|
|
25
|
+
* Get a list of names of all supported injection targets, where fragments may be
|
|
26
|
+
* injected within the default queries.
|
|
27
|
+
*
|
|
28
|
+
* @returns The list of names
|
|
29
|
+
*/
|
|
30
|
+
function getInjectionTargets() {
|
|
31
|
+
return Object.getOwnPropertyNames(ContentTypeTarget);
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Take an `opti-cms:/` virtual path and parse it to get the configuraiton of
|
|
35
|
+
* the fragment/query to be generated.
|
|
36
|
+
*
|
|
37
|
+
* @param virtualPath The virtual path
|
|
38
|
+
* @returns The fragment/query configuration
|
|
39
|
+
*/
|
|
40
|
+
function parse(virtualPath) {
|
|
41
|
+
if (!virtualPath.startsWith('opti-cms:/'))
|
|
42
|
+
return undefined;
|
|
43
|
+
const virtualURL = new URL(virtualPath);
|
|
44
|
+
const [basePath, baseType, ctKey, ...targets] = virtualURL.pathname.split('/').filter(tools_1.isNonEmptyString);
|
|
45
|
+
// Validate the basepath
|
|
46
|
+
if (!['contenttypes', 'contentquery', 'injectiontarget'].includes(basePath))
|
|
47
|
+
return undefined;
|
|
48
|
+
if (basePath === 'injectiontarget') {
|
|
49
|
+
return {
|
|
50
|
+
type: 'target',
|
|
51
|
+
contentTypeBase: '',
|
|
52
|
+
contentTypeKey: baseType,
|
|
53
|
+
forProperty: false,
|
|
54
|
+
injectionTargets: []
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
const type = basePath == "contenttypes" ? 'fragment' : 'query';
|
|
58
|
+
const forProperty = baseType.endsWith('.property');
|
|
59
|
+
const contentTypeBase = parseBaseType(forProperty ? baseType.substring(0, baseType.length - 9) : baseType);
|
|
60
|
+
const contentTypeKey = ctKey;
|
|
61
|
+
const injectionTargets = targets;
|
|
62
|
+
return { type, contentTypeBase, contentTypeKey, injectionTargets, forProperty };
|
|
63
|
+
}
|
|
64
|
+
function build(contentType, options) {
|
|
65
|
+
if (typeof (contentType) === 'string')
|
|
66
|
+
return `opti-cms:/injectiontarget/${contentType}`;
|
|
67
|
+
const { forProperty, type } = { ...DefaultVirtualLocationOptions, ...options };
|
|
68
|
+
const basePath = type == 'fragment' ? 'contenttypes' : 'contentquery';
|
|
69
|
+
const ctKey = contentType.key;
|
|
70
|
+
if (!ctKey || contentType.source === 'graph' || ctKey === 'SysContentFolder' || isContract(contentType))
|
|
71
|
+
return undefined;
|
|
72
|
+
const baseType = extractBaseType(contentType);
|
|
73
|
+
return forProperty ?
|
|
74
|
+
`opti-cms:/${basePath}/${baseType}.property/${ctKey}` :
|
|
75
|
+
`opti-cms:/${basePath}/${baseType}/${ctKey}/${getContentTypeTargets(contentType).join('/')}`;
|
|
76
|
+
}
|
|
77
|
+
function hasContractInfo(toTest) {
|
|
78
|
+
if (typeof (toTest) !== 'object' || toTest === null)
|
|
79
|
+
return false;
|
|
80
|
+
return typeof (toTest.isContract) === 'boolean';
|
|
81
|
+
}
|
|
82
|
+
function isContract(contentType) {
|
|
83
|
+
return hasContractInfo(contentType) ? contentType.isContract : false;
|
|
84
|
+
}
|
|
85
|
+
function parseBaseType(storedBaseType) {
|
|
86
|
+
switch (storedBaseType.toLowerCase()) {
|
|
87
|
+
case 'section':
|
|
88
|
+
case 'media':
|
|
89
|
+
case 'component':
|
|
90
|
+
case 'experience':
|
|
91
|
+
case 'page':
|
|
92
|
+
case 'image':
|
|
93
|
+
case 'video':
|
|
94
|
+
return '_' + storedBaseType;
|
|
95
|
+
default:
|
|
96
|
+
return storedBaseType;
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
function extractBaseType(contentType, fallback = 'cms') {
|
|
100
|
+
return (contentType.baseType ?? fallback).replace(/^_+/, '');
|
|
101
|
+
}
|
|
102
|
+
function getContentTypeTargets(contentType) {
|
|
103
|
+
if (!contentType.key || contentType.key.startsWith('graph:'))
|
|
104
|
+
return [];
|
|
105
|
+
const injections = [];
|
|
106
|
+
const baseType = extractBaseType(contentType);
|
|
107
|
+
switch (baseType) {
|
|
108
|
+
case 'section':
|
|
109
|
+
injections.push(ContentTypeTarget.SectionData);
|
|
110
|
+
break;
|
|
111
|
+
case 'page':
|
|
112
|
+
case 'experience':
|
|
113
|
+
injections.push(ContentTypeTarget.PageData);
|
|
114
|
+
break;
|
|
115
|
+
case 'media':
|
|
116
|
+
case 'video':
|
|
117
|
+
case 'image':
|
|
118
|
+
injections.push(ContentTypeTarget.MediaData);
|
|
119
|
+
break;
|
|
120
|
+
case 'component': {
|
|
121
|
+
const usage = contentType.compositionBehaviors ?? [];
|
|
122
|
+
const source = contentType.source;
|
|
123
|
+
if (!(source === '_server' && usage.length === 1 && usage[0] === 'formsElementEnabled'))
|
|
124
|
+
injections.push(ContentTypeTarget.ComponentData);
|
|
125
|
+
if (usage.includes('elementEnabled'))
|
|
126
|
+
injections.push(ContentTypeTarget.ElementData);
|
|
127
|
+
if (usage.includes('sectionEnabled'))
|
|
128
|
+
injections.push(ContentTypeTarget.SectionElementData);
|
|
129
|
+
if (usage.includes('formsElementEnabled'))
|
|
130
|
+
injections.push(ContentTypeTarget.FormElementData);
|
|
131
|
+
break;
|
|
132
|
+
}
|
|
133
|
+
default:
|
|
134
|
+
injections.push(ContentTypeTarget.BlockData);
|
|
135
|
+
break;
|
|
136
|
+
}
|
|
137
|
+
return injections;
|
|
138
|
+
}
|
|
139
|
+
//# sourceMappingURL=virtual-location.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"virtual-location.js","sourceRoot":"","sources":["../../src/generator/virtual-location.ts"],"names":[],"mappings":";;;AA4BA,kDAEC;AASD,sBA0BC;AAID,sBAaC;AAjFD,oCAA2C;AAI3C,MAAM,6BAA6B,G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Query?: boolean;
|
|
5
|
-
clientPath?: string;
|
|
6
|
-
};
|
|
2
|
+
import type { PluginOptions } from './types';
|
|
3
|
+
export type { PluginOptions } from './types';
|
|
7
4
|
export declare const DefaultFunctions: string[];
|
|
8
5
|
export declare function pickPluginOptions(options: Record<string, any>): PluginOptions;
|
|
9
6
|
/**
|
package/dist/index.js
CHANGED
|
@@ -45,7 +45,8 @@ const plugin = async (schema, documents, config, info) => {
|
|
|
45
45
|
// Read the functions to fully build & extend
|
|
46
46
|
const functions = config.functions || [];
|
|
47
47
|
if (functions.length == 0)
|
|
48
|
-
return
|
|
48
|
+
return `// NO FUNCTIONS TO BE EXPORTED
|
|
49
|
+
export const EXPORTED_FUNCTIONS = 0;`;
|
|
49
50
|
// Output the functions
|
|
50
51
|
const docs = (0, graphql_1.concatAST)(documents.map(x => x.document).filter(utils_1.isNotNullOrUndefined));
|
|
51
52
|
const output = functions.map(fn => {
|
|
@@ -76,6 +77,8 @@ const plugin = async (schema, documents, config, info) => {
|
|
|
76
77
|
prepend.push(`import type * as Types from './graphql'`);
|
|
77
78
|
prepend.push("\n");
|
|
78
79
|
append.push("\n");
|
|
80
|
+
append.push(`export const EXPORTED_FUNCTIONS = ${functions.length};`);
|
|
81
|
+
append.push("\n");
|
|
79
82
|
return { prepend, content: output.join("\n"), append };
|
|
80
83
|
};
|
|
81
84
|
exports.plugin = plugin;
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AASA,8CAOC;AAfD,qCAA0J;AAC1J,mCAA8C;AAKjC,QAAA,gBAAgB,GAAG,CAAC,gBAAgB,EAAE,kBAAkB,EAAE,gBAAgB,CAAC,CAAA;AAExF,SAAgB,iBAAiB,CAAC,OAA4B;IAC5D,OAAO;QACL,GAAG,CAAC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AC;oBACvC,SAAS,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;YACxB,CAAC;SACF;KACF,CAAC,CAAA;IAEF,qDAAqD;IACrD,MAAM,YAAY,GAA6B,EAAE,CAAA;IACjD,MAAM,sBAAsB,GAAG,CAAC,GAAG,kBAAkB,EAAE,GAAG,SAAS,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAA;IAC3F,SAAS,CAAC,OAAO,CAAC,QAAQ,CAAC,EAAE;QAC3B,2GAA2G;QAC3G,MAAM,eAAe,GAAG,CAAC,GAAG,sBAAsB,EAAE,GAAG,YAAY,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAA;QAE3F,yBAAyB;QACzB,MAAM,oBAAoB,GAAG,cAAc,CAAC,QAAQ,EAAE,QAAQ,EAAE,eAAe,CAAC,CAAA;QAChF,YAAY,CAAC,IAAI,CAAC,GAAG,oBAAoB,CAAC,CAAA;IAC5C,CAAC,CAAC,CAAA;IACF,OAAO,CAAC,GAAG,SAAS,EAAE,GAAG,YAAY,CAAC,CAAA;AACxC,CAAC;AAED,kBAAe,EAAE,QAAQ,EAAR,gBAAQ,EAAE,MAAM,EAAN,cAAM,EAAkC,CAAA"}
|
package/dist/preset.d.ts
CHANGED
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
import { type Types } from '@graphql-codegen/plugin-helpers';
|
|
2
|
-
import
|
|
3
|
-
|
|
4
|
-
import { type TransformOptions } from './types';
|
|
5
|
-
export type PresetOptions = ClientPresetOptions & PluginOptions & TransformOptions;
|
|
2
|
+
import type { PresetOptions } from './types';
|
|
3
|
+
export type { PresetOptions } from './types';
|
|
6
4
|
export declare const preset: Types.OutputPreset<PresetOptions>;
|
|
7
5
|
export default preset;
|