@remkoj/optimizely-graph-functions 6.0.0-pre1 → 6.0.0-pre11
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 +56 -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 +121 -0
- package/dist/_transform/handleDependDirective.js.map +1 -0
- package/dist/_transform/injectComponentDocuments.d.ts +13 -0
- package/dist/_transform/injectComponentDocuments.js +122 -0
- package/dist/_transform/injectComponentDocuments.js.map +1 -0
- package/dist/_transform/injectPageQueries.d.ts +4 -0
- package/dist/_transform/injectPageQueries.js +81 -0
- package/dist/_transform/injectPageQueries.js.map +1 -0
- package/dist/_transform/injectSectionQueries.d.ts +4 -0
- package/dist/_transform/injectSectionQueries.js +81 -0
- package/dist/_transform/injectSectionQueries.js.map +1 -0
- package/dist/_transform/normalizeFragmentNames.d.ts +12 -0
- package/dist/_transform/normalizeFragmentNames.js +75 -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 +225 -0
- package/dist/_transform/performInjections.js.map +1 -0
- package/dist/_transform/removeReferenceItem.d.ts +11 -0
- package/dist/_transform/removeReferenceItem.js +113 -0
- package/dist/_transform/removeReferenceItem.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 +17 -0
- package/dist/cms/index.js +88 -0
- package/dist/cms/index.js.map +1 -0
- package/dist/contenttype-loader.d.ts +58 -0
- package/dist/contenttype-loader.js +332 -0
- package/dist/contenttype-loader.js.map +1 -0
- package/dist/document-ast-plugin.d.ts +1 -0
- package/dist/document-ast-plugin.js +15 -0
- package/dist/document-ast-plugin.js.map +1 -0
- package/dist/documents/fragments.cms13.js +148 -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/index.d.ts +2 -5
- package/dist/index.js.map +1 -1
- package/dist/preset.d.ts +2 -4
- package/dist/preset.js +38 -43
- 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 +43 -58
- package/dist/transform.js.map +1 -1
- package/dist/types.d.ts +34 -0
- package/package.json +20 -13
|
@@ -0,0 +1,81 @@
|
|
|
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.injectSectionQueries = injectSectionQueries;
|
|
37
|
+
const graphql_1 = require("graphql");
|
|
38
|
+
const QueryGen = __importStar(require("../contenttype-loader"));
|
|
39
|
+
const OptiCMS = __importStar(require("../cms"));
|
|
40
|
+
const tools_1 = require("./tools");
|
|
41
|
+
async function injectSectionQueries(files, options) {
|
|
42
|
+
if (options.presetConfig.verbose)
|
|
43
|
+
console.log(`✨ [Optimizely] Generating page queries that have not been defined by the implementation`);
|
|
44
|
+
const existingQueries = (0, tools_1.getAllQueries)(files);
|
|
45
|
+
const existingTypes = (0, tools_1.getAllTypeNames)(options.schema);
|
|
46
|
+
const sectionTypes = OptiCMS.getAllContentTypes(undefined, 100, (ct) => {
|
|
47
|
+
if (ct.source == "graph")
|
|
48
|
+
return false;
|
|
49
|
+
return ["_section"].includes((ct.baseType || "").toLowerCase());
|
|
50
|
+
});
|
|
51
|
+
const newFiles = [];
|
|
52
|
+
for await (const sectionContentType of sectionTypes) {
|
|
53
|
+
const graphDataType = QueryGen.getGraphType(sectionContentType);
|
|
54
|
+
const queryName = `get${QueryGen.Tools.ucFirst(graphDataType)}Data`;
|
|
55
|
+
// Check if the type exists in the Schema, if not skip it
|
|
56
|
+
if (!existingTypes.includes(graphDataType)) {
|
|
57
|
+
if (options.presetConfig.verbose)
|
|
58
|
+
console.log(` - Skipping query generation for ${sectionContentType.key}, the schema does not contain the type ${graphDataType}`);
|
|
59
|
+
continue;
|
|
60
|
+
}
|
|
61
|
+
// Check if the query has already been defined, if so skip it
|
|
62
|
+
if (existingQueries.has(queryName)) {
|
|
63
|
+
if (options.presetConfig.verbose)
|
|
64
|
+
console.log(` - Skipping query generation for ${sectionContentType.key}, the project already includes a definition for ${queryName}`);
|
|
65
|
+
continue;
|
|
66
|
+
}
|
|
67
|
+
const rawSDL = QueryGen.buildGetQuery(sectionContentType, queryName);
|
|
68
|
+
const vLoc = QueryGen.buildVirtualLocation(sectionContentType, { type: 'query' });
|
|
69
|
+
if (options.presetConfig.verbose)
|
|
70
|
+
console.log(` - Generated query for ${sectionContentType.key} at ${vLoc}`);
|
|
71
|
+
newFiles.push({
|
|
72
|
+
rawSDL,
|
|
73
|
+
document: (0, graphql_1.parse)(rawSDL),
|
|
74
|
+
location: vLoc,
|
|
75
|
+
hash: vLoc
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
return [...files, ...newFiles];
|
|
79
|
+
}
|
|
80
|
+
exports.default = injectSectionQueries;
|
|
81
|
+
//# sourceMappingURL=injectSectionQueries.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"injectSectionQueries.js","sourceRoot":"","sources":["../../src/_transform/injectSectionQueries.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAOA,oDA8CC;AApDD,qCAA+B;AAC/B,gEAAiD;AACjD,gDAAiC;AAEjC,mCAAwD;AAEjD,KAAK,UAAU,o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CAAuC,kBAAkB,CAAC,GAAG,mDAAmD,SAAS,EAAE,CAAC,CAAA;YAC1I,SAAQ;QACV,CAAC;QAED,MAAM,MAAM,GAAG,QAAQ,CAAC,aAAa,CAAC,kBAAkB,EAAE,SAAS,CAAC,CAAA;QACpE,MAAM,IAAI,GAAG,QAAQ,CAAC,oBAAoB,CAAC,kBAAkB,EAAE,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC,CAAA;QACjF,IAAI,OAAO,CAAC,YAAY,CAAC,OAAO;YAC9B,OAAO,CAAC,GAAG,CAAC,6BAA6B,kBAAkB,CAAC,GAAG,OAAO,IAAI,EAAE,CAAC,CAAA;QAE/E,QAAQ,CAAC,IAAI,CAAC;YACZ,MAAM;YACN,QAAQ,EAAE,IAAA,eAAK,EAAC,MAAM,CAAC;YACvB,QAAQ,EAAE,IAAI;YACd,IAAI,EAAE,IAAI;SACX,CAAC,CAAA;IACJ,CAAC;IAED,OAAO,CAAC,GAAG,KAAK,EAAE,GAAG,QAAQ,CAAC,CAAA;AAChC,CAAC;AAED,kBAAe,oBAAoB,CAAA"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { Types } from '@graphql-codegen/plugin-helpers';
|
|
2
|
+
import type { PresetOptions } from '../types';
|
|
3
|
+
/**
|
|
4
|
+
* Allows the SDK to define fragments starting with an "_", for which:
|
|
5
|
+
* - If a fragment with the same name, without an "_" exists, will be removed
|
|
6
|
+
* - If such a fragment does not exist, it will be renamed to without a "_"
|
|
7
|
+
*
|
|
8
|
+
* @param files
|
|
9
|
+
* @param options
|
|
10
|
+
* @returns
|
|
11
|
+
*/
|
|
12
|
+
export declare function normalizeFragmentNames(files: Types.DocumentFile[], options: Types.PresetFnArgs<PresetOptions>): Types.DocumentFile[];
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.normalizeFragmentNames = normalizeFragmentNames;
|
|
4
|
+
const graphql_1 = require("graphql");
|
|
5
|
+
/**
|
|
6
|
+
* Allows the SDK to define fragments starting with an "_", for which:
|
|
7
|
+
* - If a fragment with the same name, without an "_" exists, will be removed
|
|
8
|
+
* - If such a fragment does not exist, it will be renamed to without a "_"
|
|
9
|
+
*
|
|
10
|
+
* @param files
|
|
11
|
+
* @param options
|
|
12
|
+
* @returns
|
|
13
|
+
*/
|
|
14
|
+
function normalizeFragmentNames(files, options) {
|
|
15
|
+
if (options.presetConfig.verbose)
|
|
16
|
+
console.log(`✨ [Optimizely] Making all internal fragments available, which have not be overridden by the project`);
|
|
17
|
+
// Filter & rename fragments
|
|
18
|
+
const allFragmentNames = files.reduce((list, file) => {
|
|
19
|
+
if (file.document)
|
|
20
|
+
(0, graphql_1.visit)(file.document, {
|
|
21
|
+
FragmentDefinition: {
|
|
22
|
+
enter(node) {
|
|
23
|
+
list.push(node.name.value);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
});
|
|
27
|
+
return list;
|
|
28
|
+
}, []);
|
|
29
|
+
const operations = allFragmentNames.reduce((prev, fragmentName) => {
|
|
30
|
+
if (fragmentName.startsWith('_')) {
|
|
31
|
+
if (allFragmentNames.includes(fragmentName.substring(1))) {
|
|
32
|
+
prev.toRemove.push(fragmentName);
|
|
33
|
+
}
|
|
34
|
+
else {
|
|
35
|
+
prev.toRename.push(fragmentName);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
return prev;
|
|
39
|
+
}, { toRename: [], toRemove: [] });
|
|
40
|
+
const filteredFiles = files.map(file => {
|
|
41
|
+
let isModified = false;
|
|
42
|
+
const newDocument = file.document ? (0, graphql_1.visit)(file.document, {
|
|
43
|
+
FragmentDefinition: {
|
|
44
|
+
enter(node) {
|
|
45
|
+
const nodeName = node.name.value;
|
|
46
|
+
if (operations.toRemove.includes(nodeName)) {
|
|
47
|
+
if (options.presetConfig.verbose)
|
|
48
|
+
console.log(` ⚠ Removing default fragment ${node.name.value.substring(1)} from the documents as it has been overridden.`);
|
|
49
|
+
isModified = true;
|
|
50
|
+
return null;
|
|
51
|
+
}
|
|
52
|
+
if (operations.toRename.includes(nodeName)) {
|
|
53
|
+
if (options.presetConfig.verbose)
|
|
54
|
+
console.log(` ⚠ Making default fragment ${node.name.value.substring(1)} available as it has not been overridden.`);
|
|
55
|
+
isModified = true;
|
|
56
|
+
return {
|
|
57
|
+
...node,
|
|
58
|
+
name: {
|
|
59
|
+
...node.name,
|
|
60
|
+
value: nodeName.substring(1)
|
|
61
|
+
}
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
}) : undefined;
|
|
67
|
+
return isModified ? {
|
|
68
|
+
...file,
|
|
69
|
+
rawSDL: newDocument ? (0, graphql_1.print)(newDocument) : undefined,
|
|
70
|
+
document: newDocument
|
|
71
|
+
} : file;
|
|
72
|
+
});
|
|
73
|
+
return filteredFiles;
|
|
74
|
+
}
|
|
75
|
+
//# sourceMappingURL=normalizeFragmentNames.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"normalizeFragmentNames.js","sourceRoot":"","sources":["../../src/_transform/normalizeFragmentNames.ts"],"names":[],"mappings":";;AAcA,wDA2DC;AAvED,qCAAsC;AAGtC;;;;;;;;GAQG;AACH,SAAgB,sBAAsB,CAAC,KAA2B,EAAE,OAA0C;IAC5G,IAAI,OAAO,CAAC,YAAY,CAAC,OAAO;QAC9B,OAAO,CAAC,GAAG,CAAC,qGAAqG,CAAC,CAAA;IAEpH,4BAA4B;IAC5B,MAAM,gBAAgB,GAAG,KAAK,CAAC,MAAM,CAAW,CAAC,IAAI,EAAE,IAAI,EAAE,EAAE;QAC7D,IAAI,IAAI,CAAC,QAAQ;YAAE,IAAA,eAAK,EAAC,IAAI,CAAC,QAAQ,EAAE;gBACtC,kBAAkB,EAAE;oBAClB,KAAK,CAAC,IAAI;wBACR,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,KA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OAAO,IAAI,CAAA;oBACb,CAAC;oBACD,IAAI,UAAU,CAAC,QAAQ,CAAC,QAAQ,CAAC,QAAQ,CAAC,EAAE,CAAC;wBAC3C,IAAI,OAAO,CAAC,YAAY,CAAC,OAAO;4BAC9B,OAAO,CAAC,GAAG,CAAC,+BAA+B,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC,CAAC,2CAA2C,CAAC,CAAA;wBACrH,UAAU,GAAG,IAAI,CAAA;wBACjB,OAAO;4BACL,GAAG,IAAI;4BACP,IAAI,EAAE;gCACJ,GAAG,IAAI,CAAC,IAAI;gCACZ,KAAK,EAAE,QAAQ,CAAC,SAAS,CAAC,CAAC,CAAC;6BAC7B;yBACwB,CAAA;oBAC7B,CAAC;gBACH,CAAC;aACF;SACF,CAAC,CAAC,CAAC,CAAC,SAAS,CAAA;QACd,OAAO,UAAU,CAAC,CAAC,CAAC;YAClB,GAAG,IAAI;YACP,MAAM,EAAE,WAAW,CAAC,CAAC,CAAC,IAAA,eAAK,EAAC,WAAW,CAAC,CAAC,CAAC,CAAC,SAAS;YACpD,QAAQ,EAAE,WAAW;SACA,CAAC,CAAC,CAAC,IAAI,CAAA;IAChC,CAAC,CAAC,CAAA;IACF,OAAO,aAAa,CAAA;AACtB,CAAC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { Types } from '@graphql-codegen/plugin-helpers';
|
|
2
|
+
import type { PresetOptions } from '../types';
|
|
3
|
+
/**
|
|
4
|
+
* Allows the SDK to define fragments starting with an "_", for which:
|
|
5
|
+
* - If a fragment with the same name, without an "_" exists, will be removed
|
|
6
|
+
* - If such a fragment does not exist, it will be renamed to without a "_"
|
|
7
|
+
*
|
|
8
|
+
* @param files
|
|
9
|
+
* @param options
|
|
10
|
+
* @returns
|
|
11
|
+
*/
|
|
12
|
+
export declare function normalizeQueryNames(files: Types.DocumentFile[], options: Types.PresetFnArgs<PresetOptions>): Types.DocumentFile[];
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.normalizeQueryNames = normalizeQueryNames;
|
|
4
|
+
const graphql_1 = require("graphql");
|
|
5
|
+
/**
|
|
6
|
+
* Allows the SDK to define fragments starting with an "_", for which:
|
|
7
|
+
* - If a fragment with the same name, without an "_" exists, will be removed
|
|
8
|
+
* - If such a fragment does not exist, it will be renamed to without a "_"
|
|
9
|
+
*
|
|
10
|
+
* @param files
|
|
11
|
+
* @param options
|
|
12
|
+
* @returns
|
|
13
|
+
*/
|
|
14
|
+
function normalizeQueryNames(files, options) {
|
|
15
|
+
if (options.presetConfig.verbose)
|
|
16
|
+
console.log(`✨ [Optimizely] Making all internal queries available, which have not be overridden by the project`);
|
|
17
|
+
// List all queries
|
|
18
|
+
const allQueryNames = files.reduce((list, file) => {
|
|
19
|
+
if (file.document)
|
|
20
|
+
(0, graphql_1.visit)(file.document, {
|
|
21
|
+
OperationDefinition: {
|
|
22
|
+
enter(node) {
|
|
23
|
+
if (node.operation == graphql_1.OperationTypeNode.QUERY && typeof (node.name?.value) == 'string' && node.name.value.length > 0)
|
|
24
|
+
list.push(node.name.value);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
});
|
|
28
|
+
return list;
|
|
29
|
+
}, []);
|
|
30
|
+
// Determine the operations for the internal queries
|
|
31
|
+
const operations = allQueryNames.reduce((prev, queryName) => {
|
|
32
|
+
if (queryName.startsWith('_')) {
|
|
33
|
+
if (allQueryNames.includes(queryName.substring(1))) {
|
|
34
|
+
prev.toRemove.push(queryName);
|
|
35
|
+
}
|
|
36
|
+
else {
|
|
37
|
+
prev.toRename.push(queryName);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
return prev;
|
|
41
|
+
}, { toRename: [], toRemove: [] });
|
|
42
|
+
// Update documents
|
|
43
|
+
const filteredFiles = files.map(file => {
|
|
44
|
+
let isModified = false;
|
|
45
|
+
const newDocument = file.document ? (0, graphql_1.visit)(file.document, {
|
|
46
|
+
OperationDefinition: {
|
|
47
|
+
enter(node) {
|
|
48
|
+
// Only process queries with a name and of operation type Query
|
|
49
|
+
if (node.name && node.operation === graphql_1.OperationTypeNode.QUERY) {
|
|
50
|
+
const nodeName = node.name.value;
|
|
51
|
+
// Remove query
|
|
52
|
+
if (operations.toRemove.includes(nodeName)) {
|
|
53
|
+
if (options.presetConfig.verbose)
|
|
54
|
+
console.log(` ⚠ Removing default query ${node.name.value.substring(1)} from the documents as it has been overridden.`);
|
|
55
|
+
isModified = true;
|
|
56
|
+
return null;
|
|
57
|
+
}
|
|
58
|
+
// Rename query
|
|
59
|
+
if (operations.toRename.includes(nodeName)) {
|
|
60
|
+
if (options.presetConfig.verbose)
|
|
61
|
+
console.log(` ⚠ Making default fragment ${node.name.value.substring(1)} available as it has not been overridden.`);
|
|
62
|
+
isModified = true;
|
|
63
|
+
return {
|
|
64
|
+
...node,
|
|
65
|
+
name: {
|
|
66
|
+
...node.name,
|
|
67
|
+
value: nodeName.substring(1)
|
|
68
|
+
}
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
}) : undefined;
|
|
75
|
+
return isModified ? {
|
|
76
|
+
...file,
|
|
77
|
+
rawSDL: newDocument ? (0, graphql_1.print)(newDocument) : undefined,
|
|
78
|
+
document: newDocument
|
|
79
|
+
} : file;
|
|
80
|
+
});
|
|
81
|
+
return filteredFiles;
|
|
82
|
+
}
|
|
83
|
+
//# sourceMappingURL=normalizeQueryNames.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"normalizeQueryNames.js","sourceRoot":"","sources":["../../src/_transform/normalizeQueryNames.ts"],"names":[],"mappings":";;AAcA,kDAuEC;AAnFD,qCAAyD;AAGzD;;;;;;;;GAQG;AACH,SAAgB,mBAAmB,CAAC,KAA2B,EAAE,OAA0C;IACzG,IAAI,OAAO,CAAC,YAA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,SAAS,CAAA;QACd,OAAO,UAAU,CAAC,CAAC,CAAC;YAClB,GAAG,IAAI;YACP,MAAM,EAAE,WAAW,CAAC,CAAC,CAAC,IAAA,eAAK,EAAC,WAAW,CAAC,CAAC,CAAC,CAAC,SAAS;YACpD,QAAQ,EAAE,WAAW;SACA,CAAC,CAAC,CAAC,IAAI,CAAA;IAChC,CAAC,CAAC,CAAA;IACF,OAAO,aAAa,CAAA;AACtB,CAAC"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.defaultOptions = void 0;
|
|
4
|
+
exports.pickTransformOptions = pickTransformOptions;
|
|
5
|
+
exports.defaultOptions = {
|
|
6
|
+
injections: [],
|
|
7
|
+
verbose: false,
|
|
8
|
+
recursion: true,
|
|
9
|
+
cleanup: true,
|
|
10
|
+
cmsClient: {}
|
|
11
|
+
};
|
|
12
|
+
function pickTransformOptions(options) {
|
|
13
|
+
return {
|
|
14
|
+
cleanup: options.cleanup ?? true,
|
|
15
|
+
injections: options.injections ?? [],
|
|
16
|
+
verbose: options.verbose ?? false,
|
|
17
|
+
recursion: options.recursion ?? true,
|
|
18
|
+
cmsClient: options.cmsClient ?? undefined
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
//# sourceMappingURL=options.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"options.js","sourceRoot":"","sources":["../../src/_transform/options.ts"],"names":[],"mappings":";;;AAUA,oDAQC;AAhBY,QAAA,cAAc,GAAyC;IAClE,UAAU,EAAE,EAAE;IACd,OAAO,EAAE,KAAK;IACd,SAAS,EAAE,IAAI;IACf,OAAO,EAAE,IAAI;IACb,SAAS,EAAE,EAAE;CACd,CAAA;AAED,SAAgB,oBAAoB,CAAC,OAA4B;IAC/D,OAAO;QACL,OAAO,EAAE,OAAO,CAAC,OAAO,IAAI,IAAI;QAChC,UAAU,EAAE,OAAO,CAAC,UAAU,IAAI,EAAE;QACpC,OAAO,EAAE,OAAO,CAAC,OAAO,IAAI,KAAK;QACjC,SAAS,EAAE,OAAO,CAAC,SAAS,IAAI,IAAI;QACpC,SAAS,EAAE,OAAO,CAAC,SAAS,IAAI,SAAS;KAC1C,CAAA;AACH,CAAC"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { Types } from '@graphql-codegen/plugin-helpers';
|
|
2
|
+
import { type FragmentDefinitionNode } from 'graphql';
|
|
3
|
+
import type { PresetOptions, Injection, TransformOptions } from '../types';
|
|
4
|
+
/**
|
|
5
|
+
* Check all fragments within the project and ensure that there's at least a fragment for every
|
|
6
|
+
* content type defined in Optimizely CMS. This assumes that when overriding the fragments the
|
|
7
|
+
* project will ensure that the injections are correct.
|
|
8
|
+
*
|
|
9
|
+
* @param files
|
|
10
|
+
* @param options
|
|
11
|
+
* @returns
|
|
12
|
+
*/
|
|
13
|
+
export declare function performInjections(files: Types.DocumentFile[], options: Types.PresetFnArgs<PresetOptions>): Promise<Types.DocumentFile[]>;
|
|
14
|
+
export default performInjections;
|
|
15
|
+
type TargetedFragementInfo = {
|
|
16
|
+
name: string;
|
|
17
|
+
contentType: string;
|
|
18
|
+
definition: FragmentDefinitionNode;
|
|
19
|
+
location?: string;
|
|
20
|
+
};
|
|
21
|
+
type TargetedFragments = Map<string, Array<TargetedFragementInfo>>;
|
|
22
|
+
export declare function getInjectionsByFile(file: Types.DocumentFile, injections: Injection[]): Array<Injection>;
|
|
23
|
+
export declare function getInjectionsByFragmentName(fragmentName: string, injections: Injection[]): Array<Injection>;
|
|
24
|
+
export declare function getComponentFragments(files: Types.DocumentFile[], { injections, verbose }: Readonly<Required<TransformOptions>>): Promise<TargetedFragments>;
|
|
@@ -0,0 +1,225 @@
|
|
|
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.performInjections = performInjections;
|
|
37
|
+
exports.getInjectionsByFile = getInjectionsByFile;
|
|
38
|
+
exports.getInjectionsByFragmentName = getInjectionsByFragmentName;
|
|
39
|
+
exports.getComponentFragments = getComponentFragments;
|
|
40
|
+
const graphql_1 = require("graphql");
|
|
41
|
+
const QueryGen = __importStar(require("../contenttype-loader"));
|
|
42
|
+
const options_1 = require("./options");
|
|
43
|
+
/**
|
|
44
|
+
* Check all fragments within the project and ensure that there's at least a fragment for every
|
|
45
|
+
* content type defined in Optimizely CMS. This assumes that when overriding the fragments the
|
|
46
|
+
* project will ensure that the injections are correct.
|
|
47
|
+
*
|
|
48
|
+
* @param files
|
|
49
|
+
* @param options
|
|
50
|
+
* @returns
|
|
51
|
+
*/
|
|
52
|
+
async function performInjections(files, options) {
|
|
53
|
+
if (options.presetConfig.verbose)
|
|
54
|
+
console.log(`✨ [Optimizely] Running injections into targeted components`);
|
|
55
|
+
// Create context
|
|
56
|
+
const config = { ...options_1.defaultOptions, ...(0, options_1.pickTransformOptions)(options.presetConfig) };
|
|
57
|
+
const componentFragments = await getComponentFragments(files, config);
|
|
58
|
+
// Get the names we actually need to inject into, and return when none are present
|
|
59
|
+
const intoNames = Array.from(componentFragments.keys());
|
|
60
|
+
if (intoNames.length == 0)
|
|
61
|
+
return files;
|
|
62
|
+
if (config.verbose)
|
|
63
|
+
intoNames.forEach(intoName => {
|
|
64
|
+
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 - ")}`);
|
|
65
|
+
});
|
|
66
|
+
function isTargetedSpread(node) {
|
|
67
|
+
return node.kind == graphql_1.Kind.FRAGMENT_SPREAD && intoNames.includes(node.name.value);
|
|
68
|
+
}
|
|
69
|
+
// Run the actual transformation
|
|
70
|
+
const transformedFiles = files.map(file => {
|
|
71
|
+
const document = file.document ? (0, graphql_1.visit)(file.document, {
|
|
72
|
+
// Replace the fragment occurances
|
|
73
|
+
SelectionSet: {
|
|
74
|
+
leave(node, key, parent, path, ancestors) {
|
|
75
|
+
// Get the parent name
|
|
76
|
+
const parentName = [...ancestors].reverse().filter(isFragmentOrOperation).at(0)?.name?.value;
|
|
77
|
+
// Get the sections that need to be added here, return if none found
|
|
78
|
+
const sectionsToAdd = node.selections.filter(isTargetedSpread).map(x => x.name.value);
|
|
79
|
+
if (sectionsToAdd.length == 0)
|
|
80
|
+
return;
|
|
81
|
+
// Debug output
|
|
82
|
+
if (config.verbose)
|
|
83
|
+
console.debug(` - Identified usage of fragment(s) ${sectionsToAdd.join(', ')} in ${parentName} (${file.location}), starting injection procedure`);
|
|
84
|
+
// Create context
|
|
85
|
+
const newSelections = [];
|
|
86
|
+
const existingSpreads = node.selections.filter(x => x.kind === graphql_1.Kind.FRAGMENT_SPREAD).map(x => x.name.value);
|
|
87
|
+
// Loop over the sections that must be processed
|
|
88
|
+
sectionsToAdd.forEach(sectionName => {
|
|
89
|
+
// Loop over the contents of each section
|
|
90
|
+
const addedSelections = (componentFragments.get(sectionName) ?? []).map(fragment => {
|
|
91
|
+
// Check if the spread already exist, and skip if it does exist
|
|
92
|
+
if (existingSpreads.includes(fragment.name))
|
|
93
|
+
return undefined;
|
|
94
|
+
// Add the current fragment to the list to prevent issues, with the same fragment being in multiple sections
|
|
95
|
+
existingSpreads.push(fragment.name);
|
|
96
|
+
return {
|
|
97
|
+
kind: graphql_1.Kind.FRAGMENT_SPREAD,
|
|
98
|
+
directives: [],
|
|
99
|
+
name: {
|
|
100
|
+
kind: graphql_1.Kind.NAME,
|
|
101
|
+
value: fragment.name
|
|
102
|
+
}
|
|
103
|
+
};
|
|
104
|
+
}).filter(isNotNullOrUndefined);
|
|
105
|
+
// Chick the fragments we've added
|
|
106
|
+
if (addedSelections.length > 0) {
|
|
107
|
+
if (config.verbose)
|
|
108
|
+
console.log(` - Added fragments ${addedSelections.map(a => a.name.value).join(', ')} adjacent to ${sectionName}`);
|
|
109
|
+
newSelections.push(...addedSelections);
|
|
110
|
+
}
|
|
111
|
+
});
|
|
112
|
+
// If there're no changes, just return the old fragment
|
|
113
|
+
if (newSelections.length == 0)
|
|
114
|
+
return;
|
|
115
|
+
// Build the new SelectionSet
|
|
116
|
+
const newNode = {
|
|
117
|
+
...node,
|
|
118
|
+
selections: [...node.selections, ...newSelections]
|
|
119
|
+
};
|
|
120
|
+
// If cleanup is disabled just return the new node
|
|
121
|
+
if (!config.cleanup || (Array.isArray(config.cleanup) && config.cleanup.length === 0))
|
|
122
|
+
return newNode;
|
|
123
|
+
// Filter the selections if cleanup is enabled
|
|
124
|
+
newNode.selections = newNode.selections.filter(selection => {
|
|
125
|
+
if (selection.kind !== graphql_1.Kind.FRAGMENT_SPREAD)
|
|
126
|
+
return true; // Allow all non-fragment spreads
|
|
127
|
+
if (config.cleanup && !Array.isArray(config.cleanup) && (sectionsToAdd.includes(selection.name.value) || ['PageData', 'BlockData'].includes(selection.name.value)))
|
|
128
|
+
return false; // Remove matching sections and PageData & BlockData, for any truethy, non-array value for cleanup
|
|
129
|
+
if (Array.isArray(config.cleanup) && config.cleanup.includes(selection.name.value))
|
|
130
|
+
return false; // Remove all explicitly listed fragment spreads
|
|
131
|
+
return true;
|
|
132
|
+
});
|
|
133
|
+
return newNode;
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
}) : undefined;
|
|
137
|
+
return {
|
|
138
|
+
...file,
|
|
139
|
+
document: document,
|
|
140
|
+
};
|
|
141
|
+
});
|
|
142
|
+
return transformedFiles;
|
|
143
|
+
}
|
|
144
|
+
exports.default = performInjections;
|
|
145
|
+
function getInjectionsByFile(file, injections) {
|
|
146
|
+
const applicableInjections = injections.filter(injection => !injection.pathRegex || (new RegExp(injection.pathRegex)).test(file.location ?? ""));
|
|
147
|
+
return applicableInjections ?? [];
|
|
148
|
+
}
|
|
149
|
+
function getInjectionsByFragmentName(fragmentName, injections) {
|
|
150
|
+
const matchingInjections = injections.filter(injection => !injection.nameRegex || (new RegExp(injection.nameRegex)).test(fragmentName));
|
|
151
|
+
return matchingInjections ?? [];
|
|
152
|
+
}
|
|
153
|
+
async function getComponentFragments(files, { injections, verbose }) {
|
|
154
|
+
// First process files based upon injection configuration
|
|
155
|
+
const newOutput = files.reduce((componentFragments, file) => {
|
|
156
|
+
if (!file.document)
|
|
157
|
+
return componentFragments; /// Stop if we don't have a document
|
|
158
|
+
// Check if this an internally generated fragment
|
|
159
|
+
const vLocInfo = file.location ? QueryGen.parseVirtualLocation(file.location) : undefined;
|
|
160
|
+
if (vLocInfo) {
|
|
161
|
+
// Only process the Virtual Location if it's for a non-property fragment with at least one injection target
|
|
162
|
+
if (vLocInfo.type !== 'fragment' || vLocInfo.forProperty || vLocInfo.injectionTargets.length == 0)
|
|
163
|
+
return componentFragments;
|
|
164
|
+
// Extract needed properties from the parsed URL
|
|
165
|
+
const { injectionTargets: targets, contentTypeKey } = vLocInfo;
|
|
166
|
+
// Walk the document to process all fragments in it
|
|
167
|
+
(0, graphql_1.visit)(file.document, {
|
|
168
|
+
FragmentDefinition: {
|
|
169
|
+
enter(node) {
|
|
170
|
+
targets.forEach(target => {
|
|
171
|
+
const currentFragments = (componentFragments.get(target) || []);
|
|
172
|
+
if (!currentFragments.some(cf => cf.name == node.name.value)) {
|
|
173
|
+
currentFragments.push({
|
|
174
|
+
name: node.name.value,
|
|
175
|
+
contentType: contentTypeKey,
|
|
176
|
+
definition: node,
|
|
177
|
+
location: file.location
|
|
178
|
+
});
|
|
179
|
+
componentFragments.set(target, currentFragments);
|
|
180
|
+
}
|
|
181
|
+
});
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
});
|
|
185
|
+
return componentFragments;
|
|
186
|
+
}
|
|
187
|
+
// Check if this file matches an injection
|
|
188
|
+
const applicableInjections = getInjectionsByFile(file, injections);
|
|
189
|
+
if (applicableInjections.length == 0)
|
|
190
|
+
return componentFragments; // Stop if we don't have a file or no injections for this file
|
|
191
|
+
// Process the document
|
|
192
|
+
(0, graphql_1.visit)(file.document, {
|
|
193
|
+
FragmentDefinition: {
|
|
194
|
+
enter(node) {
|
|
195
|
+
const matchingInjections = getInjectionsByFragmentName(node.name.value, applicableInjections);
|
|
196
|
+
matchingInjections.forEach(injection => {
|
|
197
|
+
const contentTypeKey = node.typeCondition.name.value;
|
|
198
|
+
const target = injection.into;
|
|
199
|
+
const currentFragments = (componentFragments.get(target) || []);
|
|
200
|
+
if (!currentFragments.some(cf => cf.name == node.name.value)) {
|
|
201
|
+
currentFragments.push({
|
|
202
|
+
name: node.name.value,
|
|
203
|
+
contentType: contentTypeKey,
|
|
204
|
+
definition: node,
|
|
205
|
+
location: file.location
|
|
206
|
+
});
|
|
207
|
+
componentFragments.set(target, currentFragments);
|
|
208
|
+
}
|
|
209
|
+
});
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
});
|
|
213
|
+
return componentFragments;
|
|
214
|
+
}, new Map());
|
|
215
|
+
return newOutput;
|
|
216
|
+
}
|
|
217
|
+
function isNotNullOrUndefined(toTest) {
|
|
218
|
+
return toTest !== null && toTest !== undefined;
|
|
219
|
+
}
|
|
220
|
+
function isFragmentOrOperation(x) {
|
|
221
|
+
if (Array.isArray(x) || x == undefined || x == null)
|
|
222
|
+
return false;
|
|
223
|
+
return x.kind == graphql_1.Kind.FRAGMENT_DEFINITION || x.kind == graphql_1.Kind.OPERATION_DEFINITION;
|
|
224
|
+
}
|
|
225
|
+
//# 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,gEAAiD;AAEjD,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,k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E,IAAI,CAAC,QAAQ;6BACxB,CAAC,CAAA;4BACF,kBAAkB,CAAC,GAAG,CAAC,MAAM,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,11 @@
|
|
|
1
|
+
import type { Types } from '@graphql-codegen/plugin-helpers';
|
|
2
|
+
import type { PresetOptions } from '../types';
|
|
3
|
+
/**
|
|
4
|
+
* Remove the "item" field in queries and fragments from the "ContentReference" type if it's not in the schema
|
|
5
|
+
*
|
|
6
|
+
* @param files
|
|
7
|
+
* @param options
|
|
8
|
+
* @returns
|
|
9
|
+
*/
|
|
10
|
+
export declare function removeReferenceItem(files: Types.DocumentFile[], options: Types.PresetFnArgs<PresetOptions>): Promise<Types.DocumentFile[]>;
|
|
11
|
+
export default removeReferenceItem;
|