@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,192 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.performInjections = performInjections;
|
|
4
|
+
exports.getInjectionsByFile = getInjectionsByFile;
|
|
5
|
+
exports.getInjectionsByFragmentName = getInjectionsByFragmentName;
|
|
6
|
+
exports.getComponentFragments = getComponentFragments;
|
|
7
|
+
const graphql_1 = require("graphql");
|
|
8
|
+
const generator_1 = require("../generator");
|
|
9
|
+
const options_1 = require("./options");
|
|
10
|
+
/**
|
|
11
|
+
* Check all fragments within the project and ensure that there's at least a fragment for every
|
|
12
|
+
* content type defined in Optimizely CMS. This assumes that when overriding the fragments the
|
|
13
|
+
* project will ensure that the injections are correct.
|
|
14
|
+
*
|
|
15
|
+
* @param files
|
|
16
|
+
* @param options
|
|
17
|
+
* @returns
|
|
18
|
+
*/
|
|
19
|
+
async function performInjections(files, options) {
|
|
20
|
+
if (options.presetConfig.verbose)
|
|
21
|
+
console.log(`✨ [Optimizely] Running injections into targeted components`);
|
|
22
|
+
// Create context
|
|
23
|
+
const config = { ...options_1.defaultOptions, ...(0, options_1.pickTransformOptions)(options.presetConfig) };
|
|
24
|
+
const componentFragments = await getComponentFragments(files, config);
|
|
25
|
+
// Get the names we actually need to inject into, and return when none are present
|
|
26
|
+
const intoNames = Array.from(componentFragments.keys());
|
|
27
|
+
if (intoNames.length == 0)
|
|
28
|
+
return files;
|
|
29
|
+
if (config.verbose)
|
|
30
|
+
intoNames.forEach(intoName => {
|
|
31
|
+
console.debug(` - Will update queries & fragments using the fragment ${intoName} to also use the fragments:\n - ${(componentFragments.get(intoName) ?? []).map(x => `${x.name} (${x.location})`).join("\n - ")}`);
|
|
32
|
+
});
|
|
33
|
+
function isTargetedSpread(node) {
|
|
34
|
+
return node.kind == graphql_1.Kind.FRAGMENT_SPREAD && intoNames.includes(node.name.value);
|
|
35
|
+
}
|
|
36
|
+
// Run the actual transformation
|
|
37
|
+
const transformedFiles = files.map(file => {
|
|
38
|
+
const document = file.document ? (0, graphql_1.visit)(file.document, {
|
|
39
|
+
// Replace the fragment occurances
|
|
40
|
+
SelectionSet: {
|
|
41
|
+
leave(node, key, parent, path, ancestors) {
|
|
42
|
+
// Get the parent name
|
|
43
|
+
const parentName = [...ancestors].reverse().filter(isFragmentOrOperation).at(0)?.name?.value;
|
|
44
|
+
// Get the sections that need to be added here, return if none found
|
|
45
|
+
const sectionsToAdd = node.selections.filter(isTargetedSpread).map(x => x.name.value);
|
|
46
|
+
if (sectionsToAdd.length == 0)
|
|
47
|
+
return;
|
|
48
|
+
// Debug output
|
|
49
|
+
if (config.verbose)
|
|
50
|
+
console.debug(` - Identified usage of fragment(s) ${sectionsToAdd.join(', ')} in ${parentName} (${file.location}), starting injection procedure`);
|
|
51
|
+
// Create context
|
|
52
|
+
const newSelections = [];
|
|
53
|
+
const existingSpreads = node.selections.filter(x => x.kind === graphql_1.Kind.FRAGMENT_SPREAD).map(x => x.name.value);
|
|
54
|
+
// Loop over the sections that must be processed
|
|
55
|
+
sectionsToAdd.forEach(sectionName => {
|
|
56
|
+
// Loop over the contents of each section
|
|
57
|
+
const addedSelections = (componentFragments.get(sectionName) ?? []).map(fragment => {
|
|
58
|
+
// Check if the spread already exist, and skip if it does exist
|
|
59
|
+
if (existingSpreads.includes(fragment.name))
|
|
60
|
+
return undefined;
|
|
61
|
+
// Add the current fragment to the list to prevent issues, with the same fragment being in multiple sections
|
|
62
|
+
existingSpreads.push(fragment.name);
|
|
63
|
+
return {
|
|
64
|
+
kind: graphql_1.Kind.FRAGMENT_SPREAD,
|
|
65
|
+
directives: [],
|
|
66
|
+
name: {
|
|
67
|
+
kind: graphql_1.Kind.NAME,
|
|
68
|
+
value: fragment.name
|
|
69
|
+
}
|
|
70
|
+
};
|
|
71
|
+
}).filter(isNotNullOrUndefined);
|
|
72
|
+
// Chick the fragments we've added
|
|
73
|
+
if (addedSelections.length > 0) {
|
|
74
|
+
if (config.verbose)
|
|
75
|
+
console.log(` - Added fragments ${addedSelections.map(a => a.name.value).join(', ')} adjacent to ${sectionName}`);
|
|
76
|
+
newSelections.push(...addedSelections);
|
|
77
|
+
}
|
|
78
|
+
});
|
|
79
|
+
// If there're no changes, just return the old fragment
|
|
80
|
+
if (newSelections.length == 0)
|
|
81
|
+
return;
|
|
82
|
+
// Build the new SelectionSet
|
|
83
|
+
const newNode = {
|
|
84
|
+
...node,
|
|
85
|
+
selections: [...node.selections, ...newSelections]
|
|
86
|
+
};
|
|
87
|
+
// If cleanup is disabled just return the new node
|
|
88
|
+
if (!config.cleanup || (Array.isArray(config.cleanup) && config.cleanup.length === 0))
|
|
89
|
+
return newNode;
|
|
90
|
+
// Filter the selections if cleanup is enabled
|
|
91
|
+
newNode.selections = newNode.selections.filter(selection => {
|
|
92
|
+
if (selection.kind !== graphql_1.Kind.FRAGMENT_SPREAD)
|
|
93
|
+
return true; // Allow all non-fragment spreads
|
|
94
|
+
if (config.cleanup && !Array.isArray(config.cleanup) && (sectionsToAdd.includes(selection.name.value) || ['PageData', 'BlockData'].includes(selection.name.value)))
|
|
95
|
+
return false; // Remove matching sections and PageData & BlockData, for any truethy, non-array value for cleanup
|
|
96
|
+
if (Array.isArray(config.cleanup) && config.cleanup.includes(selection.name.value))
|
|
97
|
+
return false; // Remove all explicitly listed fragment spreads
|
|
98
|
+
return true;
|
|
99
|
+
});
|
|
100
|
+
return newNode;
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
}) : undefined;
|
|
104
|
+
return {
|
|
105
|
+
...file,
|
|
106
|
+
document: document,
|
|
107
|
+
};
|
|
108
|
+
});
|
|
109
|
+
return transformedFiles;
|
|
110
|
+
}
|
|
111
|
+
exports.default = performInjections;
|
|
112
|
+
function getInjectionsByFile(file, injections) {
|
|
113
|
+
const applicableInjections = injections.filter(injection => !injection.pathRegex || (new RegExp(injection.pathRegex)).test(file.location ?? ""));
|
|
114
|
+
return applicableInjections ?? [];
|
|
115
|
+
}
|
|
116
|
+
function getInjectionsByFragmentName(fragmentName, injections) {
|
|
117
|
+
const matchingInjections = injections.filter(injection => !injection.nameRegex || (new RegExp(injection.nameRegex)).test(fragmentName));
|
|
118
|
+
return matchingInjections ?? [];
|
|
119
|
+
}
|
|
120
|
+
async function getComponentFragments(files, { injections, verbose }) {
|
|
121
|
+
// First process files based upon injection configuration
|
|
122
|
+
const newOutput = files.reduce((componentFragments, file) => {
|
|
123
|
+
if (!file.document)
|
|
124
|
+
return componentFragments; /// Stop if we don't have a document
|
|
125
|
+
// Check if this an internally generated fragment
|
|
126
|
+
const vLocInfo = file.location ? generator_1.VirtualLocation.parse(file.location) : undefined;
|
|
127
|
+
if (vLocInfo) {
|
|
128
|
+
// Only process the Virtual Location if it's for a non-property fragment with at least one injection target
|
|
129
|
+
if (vLocInfo.type !== 'fragment' || vLocInfo.forProperty || vLocInfo.injectionTargets.length == 0)
|
|
130
|
+
return componentFragments;
|
|
131
|
+
// Extract needed properties from the parsed URL
|
|
132
|
+
const { injectionTargets: targets, contentTypeKey } = vLocInfo;
|
|
133
|
+
// Walk the document to process all fragments in it
|
|
134
|
+
(0, graphql_1.visit)(file.document, {
|
|
135
|
+
FragmentDefinition: {
|
|
136
|
+
enter(node) {
|
|
137
|
+
targets.forEach(target => {
|
|
138
|
+
const currentFragments = (componentFragments.get(target) || []);
|
|
139
|
+
if (!currentFragments.some(cf => cf.name == node.name.value)) {
|
|
140
|
+
currentFragments.push({
|
|
141
|
+
name: node.name.value,
|
|
142
|
+
contentType: contentTypeKey,
|
|
143
|
+
definition: node,
|
|
144
|
+
location: file.location
|
|
145
|
+
});
|
|
146
|
+
componentFragments.set(target, currentFragments);
|
|
147
|
+
}
|
|
148
|
+
});
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
});
|
|
152
|
+
return componentFragments;
|
|
153
|
+
}
|
|
154
|
+
// Check if this file matches an injection
|
|
155
|
+
const applicableInjections = getInjectionsByFile(file, injections);
|
|
156
|
+
if (applicableInjections.length == 0)
|
|
157
|
+
return componentFragments; // Stop if we don't have a file or no injections for this file
|
|
158
|
+
// Process the document
|
|
159
|
+
(0, graphql_1.visit)(file.document, {
|
|
160
|
+
FragmentDefinition: {
|
|
161
|
+
enter(node) {
|
|
162
|
+
const matchingInjections = getInjectionsByFragmentName(node.name.value, applicableInjections);
|
|
163
|
+
matchingInjections.forEach(injection => {
|
|
164
|
+
const contentTypeKey = node.typeCondition.name.value;
|
|
165
|
+
const target = injection.into;
|
|
166
|
+
const currentFragments = (componentFragments.get(target) || []);
|
|
167
|
+
if (!currentFragments.some(cf => cf.name == node.name.value)) {
|
|
168
|
+
currentFragments.push({
|
|
169
|
+
name: node.name.value,
|
|
170
|
+
contentType: contentTypeKey,
|
|
171
|
+
definition: node,
|
|
172
|
+
location: file.location
|
|
173
|
+
});
|
|
174
|
+
componentFragments.set(target, currentFragments);
|
|
175
|
+
}
|
|
176
|
+
});
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
});
|
|
180
|
+
return componentFragments;
|
|
181
|
+
}, new Map());
|
|
182
|
+
return newOutput;
|
|
183
|
+
}
|
|
184
|
+
function isNotNullOrUndefined(toTest) {
|
|
185
|
+
return toTest !== null && toTest !== undefined;
|
|
186
|
+
}
|
|
187
|
+
function isFragmentOrOperation(x) {
|
|
188
|
+
if (Array.isArray(x) || x == undefined || x == null)
|
|
189
|
+
return false;
|
|
190
|
+
return x.kind == graphql_1.Kind.FRAGMENT_DEFINITION || x.kind == graphql_1.Kind.OPERATION_DEFINITION;
|
|
191
|
+
}
|
|
192
|
+
//# sourceMappingURL=performInjections.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"performInjections.js","sourceRoot":"","sources":["../../src/_transform/performInjections.ts"],"names":[],"mappings":";;AAeA,8CA2GC;AAYD,kDAGC;AAED,kEAGC;AAED,sDAqEC;AApND,qCAAkL;AAClL,4CAA8C;AAE9C,uCAAgE;AAEhE;;;;;;;;GAQG;AACI,KAAK,UAAU,iBAAiB,CAAC,KAA2B,EAAE,OAA0C;IAC7G,IAAI,OAAO,CAAC,YAAY,CAAC,OAAO;QAC9B,OAAO,CAAC,GAAG,CAAC,4DAA4D,CAAC,CAAA;IAE3E,iBAAiB;IACjB,MAAM,MAAM,GAAyC,EAAE,GAAG,wBAAc,EAAE,GAAG,IAAA,8BAAoB,EAAC,OAAO,CAAC,YAAY,CAAC,EAAE,CAAC;IAC1H,MAAM,kBAAkB,GAAG,MAAM,qBAAqB,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC;IAEtE,kF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AM,EAAE,gBAAgB,CAAC,CAAA;wBAClD,CAAC;oBACH,CAAC,CAAC,CAAA;gBACJ,CAAC;aACF;SACF,CAAC,CAAA;QACF,OAAO,kBAAkB,CAAA;IAC3B,CAAC,EAAE,IAAI,GAAG,EAAwC,CAAC,CAAA;IAEnD,OAAO,SAAS,CAAA;AAClB,CAAC;AAED,SAAS,oBAAoB,CAAI,MAAiB;IAChD,OAAO,MAAM,KAAK,IAAI,IAAI,MAAM,KAAK,SAAS,CAAA;AAChD,CAAC;AACD,SAAS,qBAAqB,CAAC,CAAmD;IAChF,IAAI,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,SAAS,IAAI,CAAC,IAAI,IAAI;QACjD,OAAO,KAAK,CAAA;IACd,OAAQ,CAAa,CAAC,IAAI,IAAI,cAAI,CAAC,mBAAmB,IAAK,CAAa,CAAC,IAAI,IAAI,cAAI,CAAC,oBAAoB,CAAA;AAC5G,CAAC"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import type { Types } from '@graphql-codegen/plugin-helpers';
|
|
2
|
+
import { type DocumentNode } from 'graphql';
|
|
3
|
+
export type DocumentSet = Types.DocumentFile[];
|
|
4
|
+
export type FragmentMetaData = {
|
|
5
|
+
fragmentName: string;
|
|
6
|
+
targetType: string;
|
|
7
|
+
location?: string;
|
|
8
|
+
};
|
|
9
|
+
export type FragmentMetaDataList = Array<FragmentMetaData> & {
|
|
10
|
+
get(targetType: string): FragmentMetaData | undefined;
|
|
11
|
+
has(targetType: string): boolean;
|
|
12
|
+
hasForType(targetType: string): boolean;
|
|
13
|
+
forType(targetType: string): FragmentMetaDataList;
|
|
14
|
+
};
|
|
15
|
+
export declare function getAllFragments(files: DocumentSet): FragmentMetaDataList;
|
|
16
|
+
export type QueryMetaData = {
|
|
17
|
+
queryName: string;
|
|
18
|
+
targetTypes: Array<string>;
|
|
19
|
+
location?: string;
|
|
20
|
+
};
|
|
21
|
+
export type QueryMetaDataList = Array<QueryMetaData> & {
|
|
22
|
+
get(queryName: string): QueryMetaData | undefined;
|
|
23
|
+
has(queryName: string): boolean;
|
|
24
|
+
hasForType(targetType: string): boolean;
|
|
25
|
+
forType(targetType: string): QueryMetaDataList;
|
|
26
|
+
};
|
|
27
|
+
/**
|
|
28
|
+
* Retrieve the metadata from all queries that are defined in the provided DocumentSet
|
|
29
|
+
*
|
|
30
|
+
* @param files
|
|
31
|
+
* @returns
|
|
32
|
+
*/
|
|
33
|
+
export declare function getAllQueries(files: DocumentSet): QueryMetaDataList;
|
|
34
|
+
export declare function getAllTypeNames(schema: DocumentNode): string[];
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getAllFragments = getAllFragments;
|
|
4
|
+
exports.getAllQueries = getAllQueries;
|
|
5
|
+
exports.getAllTypeNames = getAllTypeNames;
|
|
6
|
+
const graphql_1 = require("graphql");
|
|
7
|
+
function createFragmentMetaDataList(initialItems) {
|
|
8
|
+
const list = [...(initialItems || [])];
|
|
9
|
+
list.hasForType = (function (targetType) {
|
|
10
|
+
return this.some(x => x.targetType === targetType);
|
|
11
|
+
}).bind(list);
|
|
12
|
+
list.forType = (function (targetType) {
|
|
13
|
+
return createFragmentMetaDataList(this.filter(x => x.targetType === targetType));
|
|
14
|
+
}).bind(list);
|
|
15
|
+
list.get = (function (fragmentName) {
|
|
16
|
+
return this.find(x => x.fragmentName === fragmentName);
|
|
17
|
+
}).bind(list);
|
|
18
|
+
list.has = (function (fragmentName) {
|
|
19
|
+
return this.some(x => x.fragmentName === fragmentName);
|
|
20
|
+
}).bind(list);
|
|
21
|
+
return list;
|
|
22
|
+
}
|
|
23
|
+
function getAllFragments(files) {
|
|
24
|
+
const fragmentList = files.reduce((list, file) => {
|
|
25
|
+
if (file.document)
|
|
26
|
+
(0, graphql_1.visit)(file.document, {
|
|
27
|
+
FragmentDefinition: {
|
|
28
|
+
enter(node) {
|
|
29
|
+
list.push({
|
|
30
|
+
fragmentName: node.name.value,
|
|
31
|
+
targetType: node.typeCondition.name.value,
|
|
32
|
+
location: file.location
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
});
|
|
37
|
+
return list;
|
|
38
|
+
}, []);
|
|
39
|
+
return createFragmentMetaDataList(fragmentList);
|
|
40
|
+
}
|
|
41
|
+
function createQueryMetaDataList(initialItems) {
|
|
42
|
+
const list = [...(initialItems || [])];
|
|
43
|
+
list.hasForType = (function (targetType) {
|
|
44
|
+
return this.some(x => x.targetTypes.includes(targetType));
|
|
45
|
+
}).bind(list);
|
|
46
|
+
list.forType = (function (targetType) {
|
|
47
|
+
return createQueryMetaDataList(this.filter(x => x.targetTypes.includes(targetType)));
|
|
48
|
+
}).bind(list);
|
|
49
|
+
list.get = (function (queryName) {
|
|
50
|
+
return this.find(x => x.queryName === queryName);
|
|
51
|
+
}).bind(list);
|
|
52
|
+
list.has = (function (queryName) {
|
|
53
|
+
return this.some(x => x.queryName === queryName);
|
|
54
|
+
}).bind(list);
|
|
55
|
+
return list;
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Retrieve the metadata from all queries that are defined in the provided DocumentSet
|
|
59
|
+
*
|
|
60
|
+
* @param files
|
|
61
|
+
* @returns
|
|
62
|
+
*/
|
|
63
|
+
function getAllQueries(files) {
|
|
64
|
+
const queryList = files.reduce((list, file) => {
|
|
65
|
+
if (file?.document)
|
|
66
|
+
(0, graphql_1.visit)(file.document, {
|
|
67
|
+
OperationDefinition: {
|
|
68
|
+
enter(node) {
|
|
69
|
+
if (node.operation !== 'query')
|
|
70
|
+
return;
|
|
71
|
+
const queryName = node.name?.value;
|
|
72
|
+
if (!queryName)
|
|
73
|
+
return;
|
|
74
|
+
const metaData = {
|
|
75
|
+
queryName,
|
|
76
|
+
targetTypes: node.selectionSet.selections.filter(x => x.kind == 'Field').map(x => x.name.value),
|
|
77
|
+
location: file.location
|
|
78
|
+
};
|
|
79
|
+
list.push(metaData);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
});
|
|
83
|
+
return list;
|
|
84
|
+
}, []);
|
|
85
|
+
return createQueryMetaDataList(queryList);
|
|
86
|
+
}
|
|
87
|
+
function getAllTypeNames(schema) {
|
|
88
|
+
const names = [];
|
|
89
|
+
(0, graphql_1.visit)(schema, {
|
|
90
|
+
ObjectTypeDefinition: {
|
|
91
|
+
enter(node) {
|
|
92
|
+
names.push(node.name.value);
|
|
93
|
+
}
|
|
94
|
+
},
|
|
95
|
+
InterfaceTypeDefinition: {
|
|
96
|
+
enter(node) {
|
|
97
|
+
names.push(node.name.value);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
});
|
|
101
|
+
return names;
|
|
102
|
+
}
|
|
103
|
+
//# sourceMappingURL=tools.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tools.js","sourceRoot":"","sources":["../../src/_transform/tools.ts"],"names":[],"mappings":";;AAqCA,0CAgBC;AAwCD,sCAsBC;AAED,0CAeC;AAnID,qCAA+D;AAiB/D,SAAS,0BAA0B,CAAC,YAAsC;IACxE,MAAM,IAAI,GAAG,CAAC,GAAG,CAAC,YAAY,IAAI,EAAE,CAAC,CAAoC,CAAC;IAE1E,IAAI,CAAC,UAAU,GAAG,CAAC,UAAoC,UAAkB;QACvE,OAAO,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,UAAU,KAAK,UAAU,CAAC,CAAA;IACpD,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IACd,IAAI,CAAC,OAAO,GAAG,CAAC,UAAoC,UAAkB;QACpE,OAAO,0BAA0B,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,UAAU,KAAK,UAAU,CAAC,CAAC,CAAA;IAClF,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;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I,CAAC,SAAS;4BACZ,OAAO;wBACT,MAAM,QAAQ,GAAkB;4BAC9B,SAAS;4BACT,WAAW,EAAE,IAAI,CAAC,YAAY,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,IAAI,OAAO,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC;4BAC/F,QAAQ,EAAE,IAAI,CAAC,QAAQ;yBACxB,CAAA;wBACD,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAA;oBACrB,CAAC;iBACF;aACF,CAAC,CAAA;QACF,OAAO,IAAI,CAAA;IACb,CAAC,EAAE,EAAE,CAAC,CAAA;IACN,OAAO,uBAAuB,CAAC,SAAS,CAAC,CAAA;AAC3C,CAAC;AAED,SAAgB,eAAe,CAAC,MAAoB;IAClD,MAAM,KAAK,GAAa,EAAE,CAAC;IAC3B,IAAA,eAAK,EAAC,MAAM,EAAE;QACZ,oBAAoB,EAAE;YACpB,KAAK,CAAC,IAAI;gBACR,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,CAAA;YAC7B,CAAC;SACF;QACD,uBAAuB,EAAE;YACvB,KAAK,CAAC,IAAI;gBACR,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,CAAA;YAC7B,CAAC;SACF;KACF,CAAC,CAAA;IACF,OAAO,KAAK,CAAA;AACd,CAAC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { IntegrationApi, CmsIntegrationApiClient, CmsIntegrationApiOptions } from "@remkoj/optimizely-cms-api";
|
|
2
|
+
export declare function contentTypeToFragmentName(contentType: IntegrationApi.ContentType, forProperty?: boolean): string | undefined;
|
|
3
|
+
export declare function fragmentNameToContentType(fragmentName: string): {
|
|
4
|
+
contentType: string;
|
|
5
|
+
baseType: string;
|
|
6
|
+
forProperty: boolean;
|
|
7
|
+
};
|
|
8
|
+
export type ContentTypeFilter = (contentType: IntegrationApi.ContentType) => Promise<boolean> | boolean;
|
|
9
|
+
export declare function getContentTypes(configOrClient?: CmsIntegrationApiOptions | CmsIntegrationApiClient, filter?: ContentTypeFilter): Promise<Map<string, IntegrationApi.ContentType>>;
|
|
10
|
+
export declare function getContentTypesList(configOrClient?: CmsIntegrationApiOptions | CmsIntegrationApiClient, filter?: ContentTypeFilter): Promise<Array<IntegrationApi.ContentType>>;
|
|
11
|
+
export declare function getContentType(contentTypeKey: string, clientOrConfig?: CmsIntegrationApiClient | CmsIntegrationApiOptions): Promise<IntegrationApi.ContentType | undefined>;
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.contentTypeToFragmentName = contentTypeToFragmentName;
|
|
4
|
+
exports.fragmentNameToContentType = fragmentNameToContentType;
|
|
5
|
+
exports.getContentTypes = getContentTypes;
|
|
6
|
+
exports.getContentTypesList = getContentTypesList;
|
|
7
|
+
exports.getContentType = getContentType;
|
|
8
|
+
const optimizely_cms_api_1 = require("@remkoj/optimizely-cms-api");
|
|
9
|
+
const node_object_hash_1 = require("node-object-hash");
|
|
10
|
+
const tools_1 = require("../tools");
|
|
11
|
+
function contentTypeToFragmentName(contentType, forProperty = false) {
|
|
12
|
+
const contentTypeKey = contentType.key;
|
|
13
|
+
const contentTypeBase = forProperty ? (0, tools_1.ucFirst)((0, tools_1.trimStart)(contentType.baseType ?? '', '_')) : 'Property';
|
|
14
|
+
if (!contentTypeKey)
|
|
15
|
+
return undefined;
|
|
16
|
+
return contentTypeKey + '_' + contentTypeBase + 'Data';
|
|
17
|
+
}
|
|
18
|
+
function fragmentNameToContentType(fragmentName) {
|
|
19
|
+
const result = fragmentName.match(/^([A-Za-z][_0-9A-Za-z]+?)(_([A-Za-z][0-9A-Za-z]+)|_){0,1}Data$/);
|
|
20
|
+
const contentTypeKey = result?.at(1)?.endsWith('Property') ? result.at(1)?.substring(0, Math.max((result.at(1)?.length ?? 0) - 8, 0)) : result?.at(1);
|
|
21
|
+
const contentTypeBase = (result?.at(3) === 'Property' ? 'Component' : result?.at(3)) ?? 'Component';
|
|
22
|
+
if (!contentTypeKey)
|
|
23
|
+
throw new Error("Unable to determine ContentType from fragment: " + fragmentName);
|
|
24
|
+
const forProperty = (result?.at(3) === 'Property' || (!result?.at(3) && result?.at(1)?.endsWith('Property'))) || false;
|
|
25
|
+
return {
|
|
26
|
+
contentType: contentTypeKey,
|
|
27
|
+
baseType: '_' + (0, tools_1.lcFirst)(contentTypeBase),
|
|
28
|
+
forProperty
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
const DefaultContentTypeFilter = () => true;
|
|
32
|
+
/**
|
|
33
|
+
* Retrieve all content types as an Async Generator, allowing processing of entries whilest they are being loaded from the CMS instance.
|
|
34
|
+
*
|
|
35
|
+
* @param clientOrConfig
|
|
36
|
+
* @param pageSize
|
|
37
|
+
* @param filter
|
|
38
|
+
*/
|
|
39
|
+
async function* getAllContentTypes(clientOrConfig, pageSize = 25, filter = DefaultContentTypeFilter) {
|
|
40
|
+
const client = (0, optimizely_cms_api_1.isClientInstance)(clientOrConfig) ? clientOrConfig : await getClient(clientOrConfig);
|
|
41
|
+
let requestPageSize = pageSize;
|
|
42
|
+
let requestPageIndex = 0;
|
|
43
|
+
let totalItemCount = 0;
|
|
44
|
+
let totalPages = 0;
|
|
45
|
+
do {
|
|
46
|
+
const resultsPage = await client.contentTypesList({ query: { pageIndex: requestPageIndex, pageSize: requestPageSize } }).catch((_) => {
|
|
47
|
+
return {
|
|
48
|
+
items: [],
|
|
49
|
+
totalItemCount: 0,
|
|
50
|
+
pageIndex: requestPageIndex,
|
|
51
|
+
pageSize: requestPageSize
|
|
52
|
+
};
|
|
53
|
+
});
|
|
54
|
+
// Calculate fields for next page
|
|
55
|
+
totalItemCount = resultsPage.totalItemCount ?? 0;
|
|
56
|
+
requestPageSize = resultsPage.pageSize ?? 0;
|
|
57
|
+
requestPageIndex = (resultsPage.pageIndex ?? 0) + 1;
|
|
58
|
+
totalPages = resultsPage.totalItemCount && resultsPage.pageSize ? Math.ceil(totalItemCount / requestPageSize) : 0;
|
|
59
|
+
// Yield items
|
|
60
|
+
for (const contentType of (resultsPage.items ?? [])) {
|
|
61
|
+
if (await filter(contentType))
|
|
62
|
+
yield contentType;
|
|
63
|
+
}
|
|
64
|
+
} while (requestPageIndex < totalPages);
|
|
65
|
+
}
|
|
66
|
+
async function getAllContentTypesMap(clientOrConfig, pageSize = 25, filter = DefaultContentTypeFilter) {
|
|
67
|
+
const contentTypeMap = new Map();
|
|
68
|
+
const allContentTypes = getAllContentTypes(clientOrConfig, pageSize, filter);
|
|
69
|
+
for await (const ct of allContentTypes) {
|
|
70
|
+
if (ct.key)
|
|
71
|
+
contentTypeMap.set(ct.key, ct);
|
|
72
|
+
}
|
|
73
|
+
return contentTypeMap;
|
|
74
|
+
}
|
|
75
|
+
var hasher = (0, node_object_hash_1.hasher)({ sort: true, coerce: true });
|
|
76
|
+
const clientByHash = new Map();
|
|
77
|
+
const contentTypeList = new Map();
|
|
78
|
+
function getContentTypes(configOrClient, filter) {
|
|
79
|
+
const config = ((0, optimizely_cms_api_1.isClientInstance)(configOrClient) ? configOrClient._config : configOrClient);
|
|
80
|
+
const hash = hasher.hash(config ?? {});
|
|
81
|
+
let list = contentTypeList.get(hash);
|
|
82
|
+
if (!list) {
|
|
83
|
+
list = getAllContentTypesMap(configOrClient, 100);
|
|
84
|
+
contentTypeList.set(hash, list);
|
|
85
|
+
}
|
|
86
|
+
if (filter)
|
|
87
|
+
return list.then(contentTypeMap => {
|
|
88
|
+
const filteredMap = new Map();
|
|
89
|
+
contentTypeMap.forEach((contentType, contentTypeKey) => {
|
|
90
|
+
if (filter(contentType))
|
|
91
|
+
filteredMap.set(contentTypeKey, contentType);
|
|
92
|
+
});
|
|
93
|
+
return filteredMap;
|
|
94
|
+
});
|
|
95
|
+
return list;
|
|
96
|
+
}
|
|
97
|
+
async function getContentTypesList(configOrClient, filter) {
|
|
98
|
+
const types = await getContentTypes(configOrClient, filter);
|
|
99
|
+
return Array.from(types.values());
|
|
100
|
+
}
|
|
101
|
+
async function getContentType(contentTypeKey, clientOrConfig) {
|
|
102
|
+
const types = await getContentTypes(clientOrConfig);
|
|
103
|
+
return types.get(contentTypeKey);
|
|
104
|
+
}
|
|
105
|
+
function getClient(config) {
|
|
106
|
+
const configHash = hasher.hash(config ?? {});
|
|
107
|
+
let client = clientByHash.get(configHash);
|
|
108
|
+
if (!client) {
|
|
109
|
+
client = new Promise((resolve, reject) => {
|
|
110
|
+
const cms_client = (0, optimizely_cms_api_1.createClient)(config);
|
|
111
|
+
cms_client.getInstanceInfo().then(() => {
|
|
112
|
+
resolve(cms_client);
|
|
113
|
+
}).catch(e => {
|
|
114
|
+
reject(e);
|
|
115
|
+
});
|
|
116
|
+
});
|
|
117
|
+
clientByHash.set(configHash, client);
|
|
118
|
+
}
|
|
119
|
+
return client;
|
|
120
|
+
}
|
|
121
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/cms/index.ts"],"names":[],"mappings":";;AAKA,8DAMC;AAED,8DAYC;AAkED,0CAkBC;AAED,kDAIC;AAED,wCAGC;AAvHD,mEAA4E;AAC5E,uDAA0D;AAC1D,oCAAsD;AAEtD,SAAgB,yBAAyB,CAAC,WAAuC,EAAE,cAAuB,KAAK;IAC7G,MAAM,cAAc,GAAG,WAAW,CAAC,GAAG,CAAA;IACtC,MAAM,eAAe,GAAG,WAAW,CAAC,CAAC,CAAC,IAAA,eAAO,EAAC,IAAA,iBAAS,EAAC,WAAW,CAAC,QAAQ,IAAI,EAAE,EAAE,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,UAAU,CAAA;IACtG,IAAI,CAAC,cAAc;QACjB,OAAO,SAAS,CAAA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,CAAC,CAAA;YACrB,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE;gBACX,MAAM,CAAC,CAAC,CAAC,CAAA;YACX,CAAC,CAAC,CAAA;QACJ,CAAC,CAAC,CAAA;QACF,YAAY,CAAC,GAAG,CAAC,UAAU,EAAE,MAAM,CAAC,CAAA;IACtC,CAAC;IACD,OAAO,MAAM,CAAA;AACf,CAAC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { type Types } from '@graphql-codegen/plugin-helpers';
|
|
2
|
+
export * as Tools from './tools';
|
|
3
|
+
type LoaderConfig = {
|
|
4
|
+
cwd: string;
|
|
5
|
+
pluginContext?: {
|
|
6
|
+
[key: string]: any;
|
|
7
|
+
};
|
|
8
|
+
};
|
|
9
|
+
type LoaderFunction = (documentUri: string, config: LoaderConfig) => Promise<Types.DocumentFile | undefined | void>;
|
|
10
|
+
declare const ContentTypeLoader: LoaderFunction;
|
|
11
|
+
export default ContentTypeLoader;
|
|
@@ -0,0 +1,72 @@
|
|
|
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.Tools = void 0;
|
|
37
|
+
const graphql_1 = require("graphql");
|
|
38
|
+
const OptiCMS = __importStar(require("./cms"));
|
|
39
|
+
const generator_1 = require("./generator");
|
|
40
|
+
exports.Tools = __importStar(require("./tools"));
|
|
41
|
+
const collisionTracker = new generator_1.PropertyCollisionTracker();
|
|
42
|
+
const ContentTypeLoader = async (documentUri, config) => {
|
|
43
|
+
collisionTracker.cwd = config.cwd;
|
|
44
|
+
const parsedData = generator_1.VirtualLocation.parse(documentUri);
|
|
45
|
+
if (!parsedData)
|
|
46
|
+
return undefined;
|
|
47
|
+
const { type: loaderType, contentTypeBase: baseType, contentTypeKey, forProperty: isForProperty } = parsedData;
|
|
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
|
+
}
|
|
64
|
+
return rawSDL ? {
|
|
65
|
+
document: (0, graphql_1.parse)(rawSDL),
|
|
66
|
+
location: documentUri,
|
|
67
|
+
hash: documentUri,
|
|
68
|
+
rawSDL
|
|
69
|
+
} : undefined;
|
|
70
|
+
};
|
|
71
|
+
exports.default = ContentTypeLoader;
|
|
72
|
+
//# sourceMappingURL=contenttype-loader.js.map
|
|
@@ -0,0 +1 @@
|
|
|
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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