@remkoj/optimizely-graph-functions 6.0.0-pre13 → 6.0.0-pre15
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/README.md +4 -0
- package/dist/_transform/injectComponentDocuments.d.ts +3 -0
- package/dist/_transform/injectComponentDocuments.js +72 -24
- package/dist/_transform/injectComponentDocuments.js.map +1 -1
- package/dist/_transform/injectPageQueries.d.ts +1 -0
- package/dist/_transform/injectPageQueries.js +40 -7
- package/dist/_transform/injectPageQueries.js.map +1 -1
- package/dist/_transform/injectSectionQueries.d.ts +1 -0
- package/dist/_transform/injectSectionQueries.js +27 -7
- package/dist/_transform/injectSectionQueries.js.map +1 -1
- package/dist/_transform/performInjections.js +2 -35
- package/dist/_transform/performInjections.js.map +1 -1
- package/dist/cms/index.d.ts +4 -10
- package/dist/cms/index.js +57 -24
- package/dist/cms/index.js.map +1 -1
- package/dist/contenttype-loader.d.ts +1 -48
- package/dist/contenttype-loader.js +21 -281
- package/dist/contenttype-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 +267 -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.js +4 -1
- package/dist/index.js.map +1 -1
- package/dist/preset.js +61 -36
- package/dist/preset.js.map +1 -1
- package/dist/transform.d.ts +3 -3
- package/dist/transform.js +6 -1
- package/dist/transform.js.map +1 -1
- package/package.json +20 -16
|
@@ -1,58 +1,11 @@
|
|
|
1
1
|
import { type Types } from '@graphql-codegen/plugin-helpers';
|
|
2
|
-
import type { IntegrationApi } from '@remkoj/optimizely-cms-api';
|
|
3
2
|
export * as Tools from './tools';
|
|
4
3
|
type LoaderConfig = {
|
|
4
|
+
cwd: string;
|
|
5
5
|
pluginContext?: {
|
|
6
6
|
[key: string]: any;
|
|
7
7
|
};
|
|
8
8
|
};
|
|
9
9
|
type LoaderFunction = (documentUri: string, config: LoaderConfig) => Promise<Types.DocumentFile | undefined | void>;
|
|
10
10
|
declare const ContentTypeLoader: LoaderFunction;
|
|
11
|
-
export type VirtualLocationOptions = {
|
|
12
|
-
forProperty: boolean;
|
|
13
|
-
type: 'fragment' | 'query';
|
|
14
|
-
};
|
|
15
|
-
export type VirtualLocationData = {
|
|
16
|
-
contentTypeBase: string;
|
|
17
|
-
contentTypeKey: string;
|
|
18
|
-
injectionTargets: Array<string>;
|
|
19
|
-
} & VirtualLocationOptions;
|
|
20
|
-
export declare function parseVirtualLocation(virtualPath: string): VirtualLocationData | undefined;
|
|
21
|
-
export declare function buildVirtualLocation(contentType: IntegrationApi.ContentType, options?: Partial<VirtualLocationOptions>): string | undefined;
|
|
22
|
-
/**
|
|
23
|
-
* Get the Graph Type for the Content Type
|
|
24
|
-
* @param contentType
|
|
25
|
-
* @returns
|
|
26
|
-
*/
|
|
27
|
-
export declare function getGraphType(contentType: IntegrationApi.ContentType): string;
|
|
28
|
-
export declare function getGraphPropertyType(contentType: IntegrationApi.ContentType): string;
|
|
29
|
-
export declare function parseBaseType(storedBaseType: string): string;
|
|
30
|
-
export declare function extractBaseType(contentType: IntegrationApi.ContentType, fallback?: string): string;
|
|
31
|
-
export declare enum ContentTypeTarget {
|
|
32
|
-
'SectionData' = "SectionData",
|
|
33
|
-
'PageData' = "PageData",
|
|
34
|
-
'MediaData' = "MediaData",
|
|
35
|
-
'ComponentData' = "ComponentData",
|
|
36
|
-
'ElementData' = "ElementData",
|
|
37
|
-
'SectionElementData' = "SectionElementData",
|
|
38
|
-
'FormElementData' = "FormElementData",
|
|
39
|
-
'BlockData' = "BlockData"
|
|
40
|
-
}
|
|
41
|
-
export declare function getContentTypeTargets(contentType: IntegrationApi.ContentType): ContentTypeTarget[];
|
|
42
|
-
export declare function buildGetQuery(contentType: IntegrationApi.ContentType, queryName?: string | ((defaultName: string) => string), propertyTracker?: PropertyCollisionTracker): string;
|
|
43
|
-
/**
|
|
44
|
-
* Retrieve a list of component keys that are referenced as property by this type
|
|
45
|
-
*
|
|
46
|
-
* @param contentType
|
|
47
|
-
* @returns
|
|
48
|
-
*/
|
|
49
|
-
export declare function getReferencedPropertyComponents(contentType: IntegrationApi.ContentType): string[];
|
|
50
|
-
export declare function getSlugFromKey(key: string): string;
|
|
51
|
-
/**
|
|
52
|
-
* Tracker for all properties, indexed by property name, then type
|
|
53
|
-
* for a list of all ContentTypes.
|
|
54
|
-
*/
|
|
55
|
-
export type PropertyCollisionTracker = Map<string, string>;
|
|
56
|
-
export declare function buildFragment(contentType: IntegrationApi.ContentType, fragmentName?: string | ((defaultName: string) => string), forProperty?: boolean, propertyTracker?: PropertyCollisionTracker): string;
|
|
57
|
-
export declare function buildProperty(propertyName: string, propertyConfig?: IntegrationApi.ContentTypeProperty, propertyTracker?: PropertyCollisionTracker): string | null;
|
|
58
11
|
export default ContentTypeLoader;
|
|
@@ -33,36 +33,34 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
33
33
|
};
|
|
34
34
|
})();
|
|
35
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
-
exports.
|
|
37
|
-
exports.parseVirtualLocation = parseVirtualLocation;
|
|
38
|
-
exports.buildVirtualLocation = buildVirtualLocation;
|
|
39
|
-
exports.getGraphType = getGraphType;
|
|
40
|
-
exports.getGraphPropertyType = getGraphPropertyType;
|
|
41
|
-
exports.parseBaseType = parseBaseType;
|
|
42
|
-
exports.extractBaseType = extractBaseType;
|
|
43
|
-
exports.getContentTypeTargets = getContentTypeTargets;
|
|
44
|
-
exports.buildGetQuery = buildGetQuery;
|
|
45
|
-
exports.getReferencedPropertyComponents = getReferencedPropertyComponents;
|
|
46
|
-
exports.getSlugFromKey = getSlugFromKey;
|
|
47
|
-
exports.buildFragment = buildFragment;
|
|
48
|
-
exports.buildProperty = buildProperty;
|
|
36
|
+
exports.Tools = void 0;
|
|
49
37
|
const graphql_1 = require("graphql");
|
|
50
38
|
const OptiCMS = __importStar(require("./cms"));
|
|
51
|
-
const
|
|
39
|
+
const generator_1 = require("./generator");
|
|
52
40
|
exports.Tools = __importStar(require("./tools"));
|
|
41
|
+
const collisionTracker = new generator_1.PropertyCollisionTracker();
|
|
53
42
|
const ContentTypeLoader = async (documentUri, config) => {
|
|
54
|
-
|
|
43
|
+
collisionTracker.cwd = config.cwd;
|
|
44
|
+
const parsedData = generator_1.VirtualLocation.parse(documentUri);
|
|
55
45
|
if (!parsedData)
|
|
56
46
|
return undefined;
|
|
57
47
|
const { type: loaderType, contentTypeBase: baseType, contentTypeKey, forProperty: isForProperty } = parsedData;
|
|
58
|
-
const
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
if (
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
48
|
+
const allContentTypes = await OptiCMS.getContentTypes();
|
|
49
|
+
const generator = new generator_1.DocumentGenerator(allContentTypes);
|
|
50
|
+
let rawSDL;
|
|
51
|
+
if (loaderType === "target") {
|
|
52
|
+
rawSDL = generator.buildInjectionTarget(`_${contentTypeKey}`);
|
|
53
|
+
}
|
|
54
|
+
else {
|
|
55
|
+
const contentType = await OptiCMS.getContentType(contentTypeKey);
|
|
56
|
+
if (!contentType)
|
|
57
|
+
throw new Error(`ContentType with key ${contentTypeKey} cannot be loaded (Base: ${baseType})`);
|
|
58
|
+
if (contentType.baseType !== baseType)
|
|
59
|
+
throw new Error(`ContentType base types don't match, expected ${baseType} but received ${contentType.baseType}`);
|
|
60
|
+
rawSDL = loaderType === 'fragment' ?
|
|
61
|
+
generator.buildFragment(contentType, (name) => '_' + name, isForProperty, collisionTracker) :
|
|
62
|
+
generator.buildGetQuery(contentType, (name) => '_' + name, collisionTracker);
|
|
63
|
+
}
|
|
66
64
|
return rawSDL ? {
|
|
67
65
|
document: (0, graphql_1.parse)(rawSDL),
|
|
68
66
|
location: documentUri,
|
|
@@ -70,263 +68,5 @@ const ContentTypeLoader = async (documentUri, config) => {
|
|
|
70
68
|
rawSDL
|
|
71
69
|
} : undefined;
|
|
72
70
|
};
|
|
73
|
-
const DefaultVirtualLocationOptions = { forProperty: false, type: 'fragment' };
|
|
74
|
-
function parseVirtualLocation(virtualPath) {
|
|
75
|
-
if (!virtualPath.startsWith('opti-cms:/'))
|
|
76
|
-
return undefined;
|
|
77
|
-
const virtualURL = new URL(virtualPath);
|
|
78
|
-
const [basePath, baseType, ctKey, ...targets] = virtualURL.pathname.split('/').filter(tools_1.isNonEmptyString);
|
|
79
|
-
// Validate the basepath
|
|
80
|
-
if (!['contenttypes', 'contentquery'].includes(basePath))
|
|
81
|
-
return undefined;
|
|
82
|
-
const type = basePath == "contenttypes" ? 'fragment' : 'query';
|
|
83
|
-
const forProperty = baseType.endsWith('.property');
|
|
84
|
-
const contentTypeBase = parseBaseType(forProperty ? baseType.substring(0, baseType.length - 9) : baseType);
|
|
85
|
-
const contentTypeKey = ctKey;
|
|
86
|
-
const injectionTargets = targets;
|
|
87
|
-
return { type, contentTypeBase, contentTypeKey, injectionTargets, forProperty };
|
|
88
|
-
}
|
|
89
|
-
function buildVirtualLocation(contentType, options) {
|
|
90
|
-
const { forProperty, type } = { ...DefaultVirtualLocationOptions, ...options };
|
|
91
|
-
const basePath = type == 'fragment' ? 'contenttypes' : 'contentquery';
|
|
92
|
-
const ctKey = contentType.key;
|
|
93
|
-
if (!ctKey || contentType.source === 'graph' || contentType.source === '_system')
|
|
94
|
-
return undefined;
|
|
95
|
-
const baseType = extractBaseType(contentType);
|
|
96
|
-
return forProperty ?
|
|
97
|
-
`opti-cms:/${basePath}/${baseType}.property/${ctKey}` :
|
|
98
|
-
`opti-cms:/${basePath}/${baseType}/${ctKey}/${getContentTypeTargets(contentType).join('/')}`;
|
|
99
|
-
}
|
|
100
|
-
/**
|
|
101
|
-
* Get the Graph Type for the Content Type
|
|
102
|
-
* @param contentType
|
|
103
|
-
* @returns
|
|
104
|
-
*/
|
|
105
|
-
function getGraphType(contentType) {
|
|
106
|
-
return contentType.key ? contentType.key : "_IContent";
|
|
107
|
-
}
|
|
108
|
-
function getGraphPropertyType(contentType) {
|
|
109
|
-
return (contentType.key ? contentType.key : "_IContent") + "Property";
|
|
110
|
-
}
|
|
111
|
-
function parseBaseType(storedBaseType) {
|
|
112
|
-
switch (storedBaseType.toLowerCase()) {
|
|
113
|
-
case 'section':
|
|
114
|
-
case 'media':
|
|
115
|
-
case 'component':
|
|
116
|
-
case 'experience':
|
|
117
|
-
case 'page':
|
|
118
|
-
return '_' + storedBaseType;
|
|
119
|
-
default:
|
|
120
|
-
return storedBaseType;
|
|
121
|
-
}
|
|
122
|
-
}
|
|
123
|
-
function extractBaseType(contentType, fallback = 'cms') {
|
|
124
|
-
return (contentType.baseType ?? fallback).replace(/^_+/, '');
|
|
125
|
-
}
|
|
126
|
-
var ContentTypeTarget;
|
|
127
|
-
(function (ContentTypeTarget) {
|
|
128
|
-
ContentTypeTarget["SectionData"] = "SectionData";
|
|
129
|
-
ContentTypeTarget["PageData"] = "PageData";
|
|
130
|
-
ContentTypeTarget["MediaData"] = "MediaData";
|
|
131
|
-
ContentTypeTarget["ComponentData"] = "ComponentData";
|
|
132
|
-
ContentTypeTarget["ElementData"] = "ElementData";
|
|
133
|
-
ContentTypeTarget["SectionElementData"] = "SectionElementData";
|
|
134
|
-
ContentTypeTarget["FormElementData"] = "FormElementData";
|
|
135
|
-
ContentTypeTarget["BlockData"] = "BlockData";
|
|
136
|
-
})(ContentTypeTarget || (exports.ContentTypeTarget = ContentTypeTarget = {}));
|
|
137
|
-
function getContentTypeTargets(contentType) {
|
|
138
|
-
if (!contentType.key || contentType.key.startsWith('graph:'))
|
|
139
|
-
return [];
|
|
140
|
-
const injections = [];
|
|
141
|
-
const baseType = extractBaseType(contentType);
|
|
142
|
-
switch (baseType) {
|
|
143
|
-
case 'section':
|
|
144
|
-
injections.push(ContentTypeTarget.SectionData);
|
|
145
|
-
break;
|
|
146
|
-
case 'page':
|
|
147
|
-
case 'experience':
|
|
148
|
-
injections.push(ContentTypeTarget.PageData);
|
|
149
|
-
break;
|
|
150
|
-
case 'media':
|
|
151
|
-
case 'video':
|
|
152
|
-
case 'image':
|
|
153
|
-
injections.push(ContentTypeTarget.MediaData);
|
|
154
|
-
break;
|
|
155
|
-
case 'component': {
|
|
156
|
-
const usage = contentType.compositionBehaviors ?? [];
|
|
157
|
-
const source = contentType.source;
|
|
158
|
-
if (!(source === '_server' && usage.length === 1 && usage[0] === 'formsElementEnabled'))
|
|
159
|
-
injections.push(ContentTypeTarget.ComponentData);
|
|
160
|
-
if (usage.includes('elementEnabled'))
|
|
161
|
-
injections.push(ContentTypeTarget.ElementData);
|
|
162
|
-
if (usage.includes('sectionEnabled'))
|
|
163
|
-
injections.push(ContentTypeTarget.SectionElementData);
|
|
164
|
-
if (usage.includes('formsElementEnabled'))
|
|
165
|
-
injections.push(ContentTypeTarget.FormElementData);
|
|
166
|
-
break;
|
|
167
|
-
}
|
|
168
|
-
default:
|
|
169
|
-
injections.push(ContentTypeTarget.BlockData);
|
|
170
|
-
break;
|
|
171
|
-
}
|
|
172
|
-
return injections;
|
|
173
|
-
}
|
|
174
|
-
function buildGetQuery(contentType, queryName, propertyTracker = new Map()) {
|
|
175
|
-
// Prepare
|
|
176
|
-
if (!contentType.key || contentType.source === 'graph')
|
|
177
|
-
return '';
|
|
178
|
-
const graphType = getGraphType(contentType);
|
|
179
|
-
const renderedQueryName = (0, tools_1.isNonEmptyString)(queryName) ? queryName :
|
|
180
|
-
(typeof queryName === 'function' ? queryName(`get${(0, tools_1.ucFirst)(graphType)}Data`) :
|
|
181
|
-
`get${(0, tools_1.ucFirst)(graphType)}Data`);
|
|
182
|
-
// Render properties
|
|
183
|
-
const properties = [];
|
|
184
|
-
for (const propName of Object.getOwnPropertyNames(contentType.properties ?? {}))
|
|
185
|
-
properties.push(buildProperty(propName, (contentType.properties || {})[propName], propertyTracker));
|
|
186
|
-
// Inject base type based defaults
|
|
187
|
-
if (contentType.baseType === "_experience")
|
|
188
|
-
properties.unshift("...ExperienceData");
|
|
189
|
-
//Render query
|
|
190
|
-
const query = `query ${renderedQueryName}($key: [String!]!, $locale: [Locales], $changeset: String, $variation: VariationInput, $version: String) {
|
|
191
|
-
data: ${graphType}(
|
|
192
|
-
ids: $key
|
|
193
|
-
locale: $locale
|
|
194
|
-
variation: $variation
|
|
195
|
-
where: { _metadata: { changeset: { eq: $changeset }, version: { eq: $version } } }
|
|
196
|
-
) {
|
|
197
|
-
total
|
|
198
|
-
item {
|
|
199
|
-
_metadata {
|
|
200
|
-
key
|
|
201
|
-
version
|
|
202
|
-
locale
|
|
203
|
-
changeset
|
|
204
|
-
variation
|
|
205
|
-
}
|
|
206
|
-
${properties.filter(tools_1.isNonEmptyString).join("\n ")}
|
|
207
|
-
}
|
|
208
|
-
}
|
|
209
|
-
}`;
|
|
210
|
-
return query;
|
|
211
|
-
}
|
|
212
|
-
/**
|
|
213
|
-
* Retrieve a list of component keys that are referenced as property by this type
|
|
214
|
-
*
|
|
215
|
-
* @param contentType
|
|
216
|
-
* @returns
|
|
217
|
-
*/
|
|
218
|
-
function getReferencedPropertyComponents(contentType) {
|
|
219
|
-
const properties = contentType.properties;
|
|
220
|
-
if (!properties)
|
|
221
|
-
return [];
|
|
222
|
-
return Object.getOwnPropertyNames(properties).reduce((referencedTypes, propertyKey) => {
|
|
223
|
-
if (properties[propertyKey].type == "component" && properties[propertyKey].contentType) {
|
|
224
|
-
referencedTypes.push(properties[propertyKey]?.contentType);
|
|
225
|
-
}
|
|
226
|
-
if (properties[propertyKey].type == "array" && properties[propertyKey].items?.type == "component" && properties[propertyKey].items?.contentType) {
|
|
227
|
-
referencedTypes.push(properties[propertyKey]?.items?.contentType);
|
|
228
|
-
}
|
|
229
|
-
return referencedTypes;
|
|
230
|
-
}, []);
|
|
231
|
-
}
|
|
232
|
-
function getSlugFromKey(key) {
|
|
233
|
-
let newKey = key.startsWith('_') ? (0, tools_1.ucFirst)(key.substring(1)) : key;
|
|
234
|
-
if (newKey.includes(":"))
|
|
235
|
-
newKey = newKey.split(":").map(x => (0, tools_1.ucFirst)(x)).join("");
|
|
236
|
-
return newKey;
|
|
237
|
-
}
|
|
238
|
-
function buildFragment(contentType, fragmentName, forProperty = false, propertyTracker = new Map()) {
|
|
239
|
-
if (!contentType.key)
|
|
240
|
-
return '';
|
|
241
|
-
const graphType = forProperty ? getGraphPropertyType(contentType) : getGraphType(contentType);
|
|
242
|
-
const graphFragmentName = (0, tools_1.isNonEmptyString)(fragmentName) ?
|
|
243
|
-
fragmentName : (typeof fragmentName === 'function' ? fragmentName((0, tools_1.ucFirst)(graphType) + "Data") : (0, tools_1.ucFirst)(graphType) + "Data");
|
|
244
|
-
// Inject all properties
|
|
245
|
-
const properties = [];
|
|
246
|
-
for (const propName of Object.getOwnPropertyNames(contentType.properties ?? {}))
|
|
247
|
-
properties.push(buildProperty(propName, (contentType.properties || {})[propName], propertyTracker));
|
|
248
|
-
// Inject base type based defaults
|
|
249
|
-
if (contentType.baseType === "_experience")
|
|
250
|
-
properties.push("...ExperienceData");
|
|
251
|
-
// Ensure that there's at least one property
|
|
252
|
-
if (properties.length === 0)
|
|
253
|
-
properties.unshift("__typename");
|
|
254
|
-
// Construct fragment rawSDL
|
|
255
|
-
return `fragment ${graphFragmentName} on ${graphType} {
|
|
256
|
-
${properties.filter(tools_1.isNonEmptyString).join("\n ")}
|
|
257
|
-
}`;
|
|
258
|
-
}
|
|
259
|
-
function buildProperty(propertyName, propertyConfig, propertyTracker = new Map()) {
|
|
260
|
-
const propertyItemConfig = propertyConfig?.type === 'array' ? propertyConfig?.items ?? propertyConfig : propertyConfig;
|
|
261
|
-
const propertyType = propertyItemConfig?.type ?? 'any';
|
|
262
|
-
// Ensure we don't have property naming collisions
|
|
263
|
-
let outputPropertyName = propertyName;
|
|
264
|
-
if (propertyTracker.has(propertyName)) {
|
|
265
|
-
if (propertyTracker.get(propertyName) != propertyType) {
|
|
266
|
-
outputPropertyName = `${propertyName}${(0, tools_1.ucFirst)(propertyType)}: ${propertyName}`;
|
|
267
|
-
}
|
|
268
|
-
}
|
|
269
|
-
else {
|
|
270
|
-
propertyTracker.set(propertyName, propertyType);
|
|
271
|
-
}
|
|
272
|
-
switch (propertyType) {
|
|
273
|
-
case 'url':
|
|
274
|
-
return outputPropertyName + " { type base default }";
|
|
275
|
-
case 'content': {
|
|
276
|
-
const pick = (propertyItemConfig?.allowedTypes ?? []);
|
|
277
|
-
if (pick.length == 0) {
|
|
278
|
-
return outputPropertyName + ` {
|
|
279
|
-
...IContentData
|
|
280
|
-
...BlockData
|
|
281
|
-
...ComponentData
|
|
282
|
-
}`;
|
|
283
|
-
}
|
|
284
|
-
else {
|
|
285
|
-
return outputPropertyName + ` {
|
|
286
|
-
...IContentData
|
|
287
|
-
${pick.map(x => {
|
|
288
|
-
return `...${getSlugFromKey(x)}Data`;
|
|
289
|
-
}).join("\n ")}
|
|
290
|
-
}`;
|
|
291
|
-
}
|
|
292
|
-
}
|
|
293
|
-
case 'richText':
|
|
294
|
-
return outputPropertyName + " { json }";
|
|
295
|
-
case 'component': {
|
|
296
|
-
const dataType = propertyItemConfig?.contentType;
|
|
297
|
-
if (!dataType)
|
|
298
|
-
return null; // Skip this property if the contentType isn't set
|
|
299
|
-
return outputPropertyName + ` { ...${dataType}PropertyData }`;
|
|
300
|
-
}
|
|
301
|
-
case 'link':
|
|
302
|
-
return outputPropertyName + ` {
|
|
303
|
-
title
|
|
304
|
-
text
|
|
305
|
-
target
|
|
306
|
-
url {
|
|
307
|
-
type
|
|
308
|
-
base
|
|
309
|
-
default
|
|
310
|
-
}
|
|
311
|
-
}`;
|
|
312
|
-
case 'contentReference': {
|
|
313
|
-
return outputPropertyName + ` {
|
|
314
|
-
key
|
|
315
|
-
url {
|
|
316
|
-
type
|
|
317
|
-
base
|
|
318
|
-
default
|
|
319
|
-
}
|
|
320
|
-
item @depend(on: "ContentReference.item") {
|
|
321
|
-
__typename
|
|
322
|
-
...CmpImageAssetInfo
|
|
323
|
-
...CmpVideoAssetInfo
|
|
324
|
-
}
|
|
325
|
-
}`;
|
|
326
|
-
}
|
|
327
|
-
default:
|
|
328
|
-
return outputPropertyName;
|
|
329
|
-
}
|
|
330
|
-
}
|
|
331
71
|
exports.default = ContentTypeLoader;
|
|
332
72
|
//# sourceMappingURL=contenttype-loader.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"contenttype-loader.js","sourceRoot":"","sources":["../src/contenttype-loader.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"contenttype-loader.js","sourceRoot":"","sources":["../src/contenttype-loader.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AACA,qCAA+B;AAC/B,+CAAgC;AAEhC,2CAA0F;AAE1F,iDAAgC;AAWhC,MAAM,gBAAgB,GAA6B,IAAI,oCAAwB,EAAE,CAAA;AAEjF,MAAM,iBAAiB,GAAmB,KAAK,EAAE,WAAW,EAAE,MAAM,EAAE,EAAE;IACtE,gBAAgB,CAAC,GAAG,GAAG,MAAM,CAAC,GAAG,CAAC;IAElC,MAAM,UAAU,GAAG,2BAAe,CAAC,KAAK,CAAC,WAAW,CAAC,CAAA;IACrD,IAAI,CAAC,UAAU;QACb,OAAO,SAAS,CAAA;IAElB,MAAM,EAAE,IAAI,EAAE,UAAU,EAAE,eAAe,EAAE,QAAQ,EAAE,cAAc,EAAE,WAAW,EAAE,aAAa,EAAE,GAAG,UAAU,CAAC;IAC/G,MAAM,eAAe,GAAG,MAAM,OAAO,CAAC,eAAe,EAAE,CAAC;IACxD,MAAM,SAAS,GAAG,IAAI,6BAAiB,CAAC,eAAe,CAAC,CAAC;IAEzD,IAAI,MAAwB,CAAC;IAC7B,IAAI,UAAU,KAAK,QAAQ,EAAE,CAAC;QAC5B,MAAM,GAAG,SAAS,CAAC,oBAAoB,CAAC,IAAK,cAAe,EAAE,CAAC,CAAA;IACjE,CAAC;SAAM,CAAC;QACN,MAAM,WAAW,GAAG,MAAM,OAAO,CAAC,cAAc,CAAC,cAAc,CAAC,CAAC;QACjE,IAAI,CAAC,WAAW;YACd,MAAM,IAAI,KAAK,CAAC,wBAAwB,cAAc,4BAA4B,QAAQ,GAAG,CAAC,CAAA;QAEhG,IAAI,WAAW,CAAC,QAAQ,KAAK,QAAQ;YACnC,MAAM,IAAI,KAAK,CAAC,gDAAgD,QAAQ,iBAAiB,WAAW,CAAC,QAAQ,EAAE,CAAC,CAAA;QAElH,MAAM,GAAG,UAAU,KAAK,UAAU,CAAC,CAAC;YAClC,SAAS,CAAC,aAAa,CAAC,WAAW,EAAE,CAAC,IAAI,EAAE,EAAE,CAAC,GAAG,GAAG,IAAI,EAAE,aAAa,EAAE,gBAAgB,CAAC,CAAC,CAAC;YAC7F,SAAS,CAAC,aAAa,CAAC,WAAW,EAAE,CAAC,IAAI,EAAE,EAAE,CAAC,GAAG,GAAG,IAAI,EAAE,gBAAgB,CAAC,CAAA;IAChF,CAAC;IAED,OAAO,MAAM,CAAC,CAAC,CAAC;QACd,QAAQ,EAAE,IAAA,eAAK,EAAC,MAAM,CAAC;QACvB,QAAQ,EAAE,WAAW;QACrB,IAAI,EAAE,WAAW;QACjB,MAAM;KACP,CAAC,CAAC,CAAC,SAAS,CAAA;AACf,CAAC,CAAA;AAGD,kBAAe,iBAAiB,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,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A;QAClB,OAAO,KAAK,CAAC,GAAG,CAAC,GAAG,CAAC,CAAA;IACvB,CAAC;IAED,MAAM,CAAC,GAAW;QAChB,IAAI,CAAC,WAAW,EAAE,CAAA;QAClB,MAAM,GAAG,GAAG,KAAK,CAAC,MAAM,CAAC,GAAG,CAAC,CAAA;QAC7B,IAAI,CAAC,UAAU,EAAE,CAAA;QACjB,OAAO,GAAG,CAAA;IACZ,CAAC;IAED,KAAK;QACH,IAAI,CAAC,WAAW,EAAE,CAAA;QAClB,KAAK,CAAC,KAAK,EAAE,CAAA;QACb,IAAI,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
|
+
}
|