@remkoj/optimizely-graph-functions 5.1.5 → 6.0.0-pre10

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.
Files changed (55) hide show
  1. package/dist/_transform/cleanFragments.d.ts +10 -0
  2. package/dist/_transform/cleanFragments.js +39 -0
  3. package/dist/_transform/cleanFragments.js.map +1 -0
  4. package/dist/_transform/cleanSpreads.d.ts +10 -0
  5. package/dist/_transform/cleanSpreads.js +36 -0
  6. package/dist/_transform/cleanSpreads.js.map +1 -0
  7. package/dist/_transform/injectComponentDocuments.d.ts +13 -0
  8. package/dist/_transform/injectComponentDocuments.js +122 -0
  9. package/dist/_transform/injectComponentDocuments.js.map +1 -0
  10. package/dist/_transform/injectPageQueries.d.ts +4 -0
  11. package/dist/_transform/injectPageQueries.js +81 -0
  12. package/dist/_transform/injectPageQueries.js.map +1 -0
  13. package/dist/_transform/injectSectionQueries.d.ts +4 -0
  14. package/dist/_transform/injectSectionQueries.js +81 -0
  15. package/dist/_transform/injectSectionQueries.js.map +1 -0
  16. package/dist/_transform/normalizeFragmentNames.d.ts +12 -0
  17. package/dist/_transform/normalizeFragmentNames.js +75 -0
  18. package/dist/_transform/normalizeFragmentNames.js.map +1 -0
  19. package/dist/_transform/normalizeQueryNames.d.ts +12 -0
  20. package/dist/_transform/normalizeQueryNames.js +83 -0
  21. package/dist/_transform/normalizeQueryNames.js.map +1 -0
  22. package/dist/_transform/options.d.ts +3 -0
  23. package/dist/_transform/options.js +21 -0
  24. package/dist/_transform/options.js.map +1 -0
  25. package/dist/_transform/performInjections.d.ts +24 -0
  26. package/dist/_transform/performInjections.js +225 -0
  27. package/dist/_transform/performInjections.js.map +1 -0
  28. package/dist/_transform/tools.d.ts +34 -0
  29. package/dist/_transform/tools.js +103 -0
  30. package/dist/_transform/tools.js.map +1 -0
  31. package/dist/cms/index.d.ts +17 -0
  32. package/dist/cms/index.js +88 -0
  33. package/dist/cms/index.js.map +1 -0
  34. package/dist/contenttype-loader.d.ts +58 -0
  35. package/dist/contenttype-loader.js +332 -0
  36. package/dist/contenttype-loader.js.map +1 -0
  37. package/dist/documents/fragments.cms13.js +143 -42
  38. package/dist/documents/fragments.cms13.js.map +1 -1
  39. package/dist/documents/queries.cms13.js +9 -3
  40. package/dist/documents/queries.cms13.js.map +1 -1
  41. package/dist/embedded-loader.js +31 -16
  42. package/dist/embedded-loader.js.map +1 -1
  43. package/dist/index.d.ts +2 -5
  44. package/dist/index.js.map +1 -1
  45. package/dist/preset.d.ts +2 -4
  46. package/dist/preset.js +16 -42
  47. package/dist/preset.js.map +1 -1
  48. package/dist/tools.d.ts +4 -0
  49. package/dist/tools.js +20 -0
  50. package/dist/tools.js.map +1 -0
  51. package/dist/transform.d.ts +11 -1
  52. package/dist/transform.js +41 -58
  53. package/dist/transform.js.map +1 -1
  54. package/dist/types.d.ts +23 -0
  55. package/package.json +21 -21
@@ -0,0 +1,10 @@
1
+ import { type Types } from '@graphql-codegen/plugin-helpers';
2
+ import type { PresetOptions } from '../types';
3
+ /**
4
+ * Remove all fragments that target a type that is not present in the Schema
5
+ *
6
+ * @param files
7
+ * @param options
8
+ * @returns
9
+ */
10
+ export declare function cleanFragments(files: Types.DocumentFile[], options: Types.PresetFnArgs<PresetOptions>): Types.DocumentFile[];
@@ -0,0 +1,39 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.cleanFragments = cleanFragments;
4
+ const graphql_1 = require("graphql");
5
+ /**
6
+ * Remove all fragments that target a type that is not present in the Schema
7
+ *
8
+ * @param files
9
+ * @param options
10
+ * @returns
11
+ */
12
+ function cleanFragments(files, options) {
13
+ if (options.presetConfig.verbose)
14
+ console.log(`✨ [Optimizely] Removing fragments that target non-existing types from the documents`);
15
+ return files.map(doc => {
16
+ if (doc.document) {
17
+ let isModified = false;
18
+ const newDocument = (0, graphql_1.visit)(doc.document, {
19
+ FragmentDefinition: {
20
+ enter: (node) => {
21
+ if (!options.schema.definitions.some(x => (x.kind == graphql_1.Kind.OBJECT_TYPE_DEFINITION || x.kind == graphql_1.Kind.INTERFACE_TYPE_DEFINITION) && x.name.value == node.typeCondition.name.value)) {
22
+ if (options.presetConfig.verbose)
23
+ console.log(`⚠ Removing fragment ${node.name.value} from the documents, as its target ${node.typeCondition.name.value} is not available in the schema`);
24
+ isModified = true;
25
+ return null;
26
+ }
27
+ }
28
+ }
29
+ });
30
+ return isModified ? {
31
+ ...doc,
32
+ rawSDL: (0, graphql_1.print)(newDocument),
33
+ document: newDocument
34
+ } : doc;
35
+ }
36
+ return doc;
37
+ });
38
+ }
39
+ //# sourceMappingURL=cleanFragments.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cleanFragments.js","sourceRoot":"","sources":["../../src/_transform/cleanFragments.ts"],"names":[],"mappings":";;AAWA,wCA0BC;AApCD,qCAAmD;AAGnD;;;;;;GAMG;AACH,SAAgB,cAAc,CAAC,KAA2B,EAAE,OAA0C;IACpG,IAAI,OAAO,CAAC,YAAY,CAAC,OAAO;QAC9B,OAAO,CAAC,GAAG,CAAC,qFAAqF,CAAC,CAAA;IACpG,OAAO,KAAK,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE;QACrB,IAAI,GAAG,CAAC,QAAQ,EAAE,CAAC;YACjB,IAAI,UAAU,GAAG,KAAK,CAAA;YACtB,MAAM,WAAW,GAAG,IAAA,eAAK,EAAC,GAAG,CAAC,QAAQ,EAAE;gBACtC,kBAAkB,EAAE;oBAClB,KAAK,EAAE,CAAC,IAAI,EAAE,EAAE;wBACd,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,IAAI,IAAI,cAAI,CAAC,sBAAsB,IAAI,CAAC,CAAC,IAAI,IAAI,cAAI,CAAC,yBAAyB,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,KAAK,IAAI,IAAI,CAAC,aAAa,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC;4BAChL,IAAI,OAAO,CAAC,YAAY,CAAC,OAAO;gCAC9B,OAAO,CAAC,GAAG,CAAC,uBAAuB,IAAI,CAAC,IAAI,CAAC,KAAK,sCAAsC,IAAI,CAAC,aAAa,CAAC,IAAI,CAAC,KAAK,iCAAiC,CAAC,CAAA;4BACzJ,UAAU,GAAG,IAAI,CAAA;4BACjB,OAAO,IAAI,CAAA;wBACb,CAAC;oBACH,CAAC;iBACF;aACF,CAAC,CAAA;YACF,OAAO,UAAU,CAAC,CAAC,CAAC;gBAClB,GAAG,GAAG;gBACN,MAAM,EAAE,IAAA,eAAK,EAAC,WAAW,CAAC;gBAC1B,QAAQ,EAAE,WAAW;aACtB,CAAC,CAAC,CAAC,GAAG,CAAA;QACT,CAAC;QACD,OAAO,GAAG,CAAA;IACZ,CAAC,CAAC,CAAA;AACJ,CAAC"}
@@ -0,0 +1,10 @@
1
+ import { type Types } from '@graphql-codegen/plugin-helpers';
2
+ import type { PresetOptions } from '../types';
3
+ /**
4
+ * Remove all fragment spreads that target non-existing fragments from the documents.
5
+ *
6
+ * @param files
7
+ * @param options
8
+ * @returns
9
+ */
10
+ export declare function cleanFragmentSpreads(files: Types.DocumentFile[], options: Types.PresetFnArgs<PresetOptions>): Types.DocumentFile[];
@@ -0,0 +1,36 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.cleanFragmentSpreads = cleanFragmentSpreads;
4
+ const graphql_1 = require("graphql");
5
+ const tools_1 = require("./tools");
6
+ /**
7
+ * Remove all fragment spreads that target non-existing fragments from the documents.
8
+ *
9
+ * @param files
10
+ * @param options
11
+ * @returns
12
+ */
13
+ function cleanFragmentSpreads(files, options) {
14
+ const allFragments = (0, tools_1.getAllFragments)(files);
15
+ return files.map(file => {
16
+ if (!file.document)
17
+ return file;
18
+ let isModified = false;
19
+ const newDocument = (0, graphql_1.visit)(file.document, {
20
+ FragmentSpread: {
21
+ enter: (node) => {
22
+ if (!allFragments.some(x => x.fragmentName === node.name.value)) {
23
+ isModified = true;
24
+ return null;
25
+ }
26
+ }
27
+ }
28
+ });
29
+ return isModified ? {
30
+ ...file,
31
+ rawSDL: (0, graphql_1.print)(newDocument),
32
+ document: newDocument
33
+ } : file;
34
+ });
35
+ }
36
+ //# sourceMappingURL=cleanSpreads.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cleanSpreads.js","sourceRoot":"","sources":["../../src/_transform/cleanSpreads.ts"],"names":[],"mappings":";;AAYA,oDAwBC;AAnCD,qCAAmD;AAEnD,mCAAyC;AAEzC;;;;;;GAMG;AACH,SAAgB,oBAAoB,CAAC,KAA2B,EAAE,OAA0C;IAC1G,MAAM,YAAY,GAAG,IAAA,uBAAe,EAAC,KAAK,CAAC,CAAA;IAC3C,OAAO,KAAK,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE;QACtB,IAAI,CAAC,IAAI,CAAC,QAAQ;YAChB,OAAO,IAAI,CAAC;QAEd,IAAI,UAAU,GAAY,KAAK,CAAC;QAChC,MAAM,WAAW,GAAG,IAAA,eAAK,EAAC,IAAI,CAAC,QAAQ,EAAE;YACvC,cAAc,EAAE;gBACd,KAAK,EAAE,CAAC,IAAI,EAAE,EAAE;oBACd,IAAI,CAAC,YAAY,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,YAAY,KAAK,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC;wBAChE,UAAU,GAAG,IAAI,CAAC;wBAClB,OAAO,IAAI,CAAC;oBACd,CAAC;gBACH,CAAC;aACF;SACF,CAAC,CAAC;QAEH,OAAO,UAAU,CAAC,CAAC,CAAC;YAClB,GAAG,IAAI;YACP,MAAM,EAAE,IAAA,eAAK,EAAC,WAAW,CAAC;YAC1B,QAAQ,EAAE,WAAW;SACtB,CAAC,CAAC,CAAC,IAAI,CAAA;IACV,CAAC,CAAC,CAAA;AACJ,CAAC"}
@@ -0,0 +1,13 @@
1
+ import type { Types } from '@graphql-codegen/plugin-helpers';
2
+ import type { PresetOptions } from '../types';
3
+ /**
4
+ * Check all fragments within the project and ensure that there's at least a fragment for every
5
+ * content type defined in Optimizely CMS. This assumes that when overriding the fragments the
6
+ * project will ensure that the injections are correct.
7
+ *
8
+ * @param files
9
+ * @param options
10
+ * @returns
11
+ */
12
+ export declare function injectComponentDocuments(files: Types.DocumentFile[], options: Types.PresetFnArgs<PresetOptions>): Promise<Types.DocumentFile[]>;
13
+ export default injectComponentDocuments;
@@ -0,0 +1,122 @@
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.injectComponentDocuments = injectComponentDocuments;
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
+ /**
42
+ * Check all fragments within the project and ensure that there's at least a fragment for every
43
+ * content type defined in Optimizely CMS. This assumes that when overriding the fragments the
44
+ * project will ensure that the injections are correct.
45
+ *
46
+ * @param files
47
+ * @param options
48
+ * @returns
49
+ */
50
+ async function injectComponentDocuments(files, options) {
51
+ const allFragments = (0, tools_1.getAllFragments)(files);
52
+ const allGraphTypes = (0, tools_1.getAllTypeNames)(options.schema);
53
+ const addedFiles = [];
54
+ if (options.presetConfig.verbose)
55
+ console.log(`✨ [Optimizely] Generating injection target fragments that have not been defined by the implementation`);
56
+ for (const injectionTarget of Object.getOwnPropertyNames(QueryGen.ContentTypeTarget)) {
57
+ if (!allFragments.some(x => x.fragmentName === injectionTarget)) {
58
+ const vLoc = `opti-cms:/injectiontarget/${injectionTarget}`;
59
+ const rawSDL = `fragment ${injectionTarget} on _IContent { ...IContentData }`;
60
+ if (options.presetConfig.verbose)
61
+ console.log(` - Generated fragment ${injectionTarget} at ${vLoc}`);
62
+ addedFiles.push({
63
+ rawSDL,
64
+ document: (0, graphql_1.parse)(rawSDL),
65
+ location: vLoc,
66
+ hash: vLoc
67
+ });
68
+ }
69
+ }
70
+ if (options.presetConfig.verbose)
71
+ console.log(`✨ [Optimizely] Generating component fragments that have not been defined by the implementation`);
72
+ const allContentTypes = OptiCMS.getAllContentTypes(options.presetConfig.cmsClient, 100, (ct) => {
73
+ return ct.key && ct.source !== 'graph' ? true : false;
74
+ });
75
+ const propTracker = new Map();
76
+ for await (const contentType of allContentTypes) {
77
+ // Skip over content types without a key
78
+ if (!contentType.key)
79
+ continue;
80
+ // Construct the type names expected to be in Graph
81
+ const graphType = QueryGen.getGraphType(contentType);
82
+ const graphPropertyType = QueryGen.getGraphPropertyType(contentType);
83
+ const fragmentName = QueryGen.Tools.ucFirst(graphType) + "Data";
84
+ const propertyFragmentName = QueryGen.Tools.ucFirst(graphPropertyType) + "Data";
85
+ // Check if the types exist
86
+ const graphTypeExists = allGraphTypes.includes(graphType);
87
+ const graphPropertyTypeExists = allGraphTypes.includes(graphPropertyType);
88
+ // Add Component Data Fragment
89
+ if (graphTypeExists && !allFragments.has(fragmentName)) {
90
+ const rawSDL = QueryGen.buildFragment(contentType, fragmentName, false, propTracker);
91
+ const vLoc = QueryGen.buildVirtualLocation(contentType);
92
+ if (rawSDL) {
93
+ if (options.presetConfig.verbose)
94
+ console.log(` - Generated fragment ${fragmentName} for ${contentType.key} at ${vLoc}`);
95
+ addedFiles.push({
96
+ rawSDL,
97
+ document: (0, graphql_1.parse)(rawSDL),
98
+ location: vLoc,
99
+ hash: vLoc
100
+ });
101
+ }
102
+ }
103
+ // Add Component Property Data Fragment
104
+ if (graphPropertyTypeExists && contentType.baseType === '_component' && !allFragments.has(propertyFragmentName)) {
105
+ const rawSDL = QueryGen.buildFragment(contentType, propertyFragmentName, true, propTracker);
106
+ const vLoc = QueryGen.buildVirtualLocation(contentType, { forProperty: true });
107
+ if (rawSDL) {
108
+ if (options.presetConfig.verbose)
109
+ console.log(` - Generated property fragment ${propertyFragmentName} for ${contentType.key} at ${vLoc}`);
110
+ addedFiles.push({
111
+ rawSDL,
112
+ document: (0, graphql_1.parse)(rawSDL),
113
+ location: vLoc,
114
+ hash: vLoc
115
+ });
116
+ }
117
+ }
118
+ }
119
+ return [...files, ...addedFiles];
120
+ }
121
+ exports.default = injectComponentDocuments;
122
+ //# sourceMappingURL=injectComponentDocuments.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"injectComponentDocuments.js","sourceRoot":"","sources":["../../src/_transform/injectComponentDocuments.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAgBA,4DAiFC;AAhGD,qCAA+B;AAC/B,gEAAiD;AACjD,gDAAiC;AAEjC,mCAA0D;AAE1D;;;;;;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AM;oBACN,QAAQ,EAAE,IAAA,eAAK,EAAC,MAAM,CAAC;oBACvB,QAAQ,EAAE,IAAI;oBACd,IAAI,EAAE,IAAI;iBACX,CAAC,CAAA;YACJ,CAAC;QACH,CAAC;QAED,uCAAuC;QACvC,IAAI,uBAAuB,IAAI,WAAW,CAAC,QAAQ,KAAK,YAAY,IAAI,CAAC,YAAY,CAAC,GAAG,CAAC,oBAAoB,CAAC,EAAE,CAAC;YAChH,MAAM,MAAM,GAAG,QAAQ,CAAC,aAAa,CAAC,WAAW,EAAE,oBAAoB,EAAE,IAAI,EAAE,WAAW,CAAC,CAAA;YAC3F,MAAM,IAAI,GAAG,QAAQ,CAAC,oBAAoB,CAAC,WAAW,EAAE,EAAE,WAAW,EAAE,IAAI,EAAE,CAAC,CAAA;YAC9E,IAAI,MAAM,EAAE,CAAC;gBACX,IAAI,OAAO,CAAC,YAAY,CAAC,OAAO;oBAC9B,OAAO,CAAC,GAAG,CAAC,qCAAqC,oBAAoB,QAAQ,WAAW,CAAC,GAAG,OAAO,IAAI,EAAE,CAAC,CAAA;gBAC5G,UAAU,CAAC,IAAI,CAAC;oBACd,MAAM;oBACN,QAAQ,EAAE,IAAA,eAAK,EAAC,MAAM,CAAC;oBACvB,QAAQ,EAAE,IAAI;oBACd,IAAI,EAAE,IAAI;iBACX,CAAC,CAAA;YACJ,CAAC;QACH,CAAC;IACH,CAAC;IAED,OAAO,CAAC,GAAG,KAAK,EAAE,GAAG,UAAU,CAAC,CAAA;AAClC,CAAC;AAED,kBAAe,wBAAwB,CAAA"}
@@ -0,0 +1,4 @@
1
+ import type { Types } from '@graphql-codegen/plugin-helpers';
2
+ import type { PresetOptions } from '../types';
3
+ export declare function injectPageQueries(files: Types.DocumentFile[], options: Types.PresetFnArgs<PresetOptions>): Promise<Types.DocumentFile[]>;
4
+ export default injectPageQueries;
@@ -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.injectPageQueries = injectPageQueries;
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 injectPageQueries(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 pageLevelTypes = OptiCMS.getAllContentTypes(undefined, 100, (ct) => {
47
+ if (ct.source == "graph")
48
+ return false;
49
+ return ["_page", "_experience"].includes((ct.baseType || "").toLowerCase());
50
+ });
51
+ const newFiles = [];
52
+ for await (const pageContentType of pageLevelTypes) {
53
+ const graphDataType = QueryGen.getGraphType(pageContentType);
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 ${pageContentType.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 ${pageContentType.key}, the project already includes a definition for ${queryName}`);
65
+ continue;
66
+ }
67
+ const rawSDL = QueryGen.buildGetQuery(pageContentType, queryName);
68
+ const vLoc = QueryGen.buildVirtualLocation(pageContentType, { type: 'query' });
69
+ if (options.presetConfig.verbose)
70
+ console.log(` - Generated query for ${pageContentType.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 = injectPageQueries;
81
+ //# sourceMappingURL=injectPageQueries.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"injectPageQueries.js","sourceRoot":"","sources":["../../src/_transform/injectPageQueries.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAOA,8CA8CC;AApDD,qCAA+B;AAC/B,gEAAiD;AACjD,gDAAiC;AAEjC,mCAAwD;AAEjD,KAAK,UAAU,iBAAiB,CAAC,KAA2B,EAAE,OAA0C;IAC7G,IAAI,OAAO,CAAC,YAAY,CAAC,OAAO;QAC9B,OAAO,CAAC,GAAG,CAAC,yFAAyF,CAAC,CAAA;IAExG,MAAM,eAAe,GAAG,IAAA,qBAAa,EAAC,KAAK,CAAC,CAAA;IAC5C,MAAM,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,oBAAoB,CAAC,eAAe,EAAE,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC,CAAA;QAC9E,IAAI,OAAO,CAAC,YAAY,CAAC,OAAO;YAC9B,OAAO,CAAC,GAAG,CAAC,6BAA6B,eAAe,CAAC,GAAG,OAAO,IAAI,EAAE,CAAC,CAAA;QAE5E,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,iBAAiB,CAAA"}
@@ -0,0 +1,4 @@
1
+ import type { Types } from '@graphql-codegen/plugin-helpers';
2
+ import type { PresetOptions } from '../types';
3
+ export declare function injectSectionQueries(files: Types.DocumentFile[], options: Types.PresetFnArgs<PresetOptions>): Promise<Types.DocumentFile[]>;
4
+ export default injectSectionQueries;
@@ -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,oBAAoB,CAAC,KAA2B,EAAE,OAA0C;IAChH,IAAI,OAAO,CAAC,YAAY,CAAC,OAAO;QAC9B,OAAO,CAAC,GAAG,CAAC,yFAAyF,CAAC,CAAA;IAExG,MAAM,eAAe,GAAG,IAAA,qBAAa,EAAC,KAAK,CAAC,CAAA;IAC5C,MAAM,aAAa,GAAG,IAAA,uBAAe,EAAC,OAAO,CAAC,MAAM,CAAC,CAAA;IAErD,MAAM,YAAY,GAAG,OAAO,CAAC,kBAAkB,CAAC,SAAS,EAAE,GAAG,EAAE,CAAC,EAAE,EAAE,EAAE;QACrE,IAAI,EAAE,CAAC,MAAM,IAAI,OAAO;YACtB,OAAO,KAAK,CAAC;QACf,OAAO,CAAC,UAAU,CAAC,CAAC,QAAQ,CAAC,CAAC,EAAE,CAAC,QAAQ,IAAI,EAAE,CAAC,CAAC,WAAW,EAAE,CAAC,CAAC;IAClE,CAAC,CAAC,CAAC;IAEH,MAAM,QAAQ,GAAyB,EAAE,CAAA;IACzC,IAAI,KAAK,EAAE,MAAM,kBAAkB,IAAI,YAAY,EAAE,CAAC;QACpD,MAAM,a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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,KAAK,CAAC,CAAA;oBAC5B,CAAC;iBACF;aACF,CAAC,CAAA;QACF,OAAO,IAAI,CAAA;IACb,CAAC,EAAE,EAAE,CAAC,CAAA;I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C,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,YAAY,CAAC,OAAO;QAC9B,OAAO,CAAC,GAAG,CAAC,mGAAmG,CAAC,CAAA;IAElH,mBAAmB;IACnB,MAAM,aAAa,GAAG,KAAK,CAAC,MAAM,CAAW,CAAC,IAAI,EAAE,IAAI,EAAE,EAAE;QAC1D,IAAI,IAAI,CAAC,QAAQ;YAAE,IAAA,eAAK,EAAC,IAAI,CAAC,QAAQ,EAAE;gBACtC,mBAAmB,EAAE;oBACnB,KAAK,CAAC,IAAI;wBACR,IAAI,IAAI,CAAC,SAAS,IAAI,2BAAiB,CAAC,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC,IAAI,EAAE,KAAK,CAAC,IAAI,QAAQ,IAAI,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,MAAM,GAAG,CAAC;4BAClH,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,CAAA;oBAC9B,CAAC;iBACF;aACF,CAAC,CAAA;QACF,OAAO,IAAI,CAAA;IACb,CAAC,EAAE,EAAE,CAAC,CAAA;IAEN,oDAAoD;IACpD,MAAM,UAAU,GAAG,aAAa,CAAC,MAAM,CAA6C,CAAC,IAAI,EAAE,SAAS,EAAE,EAAE;QACtG,IAAI,SAAS,CAAC,UAAU,CAAC,GAAG,CAAC,EAAE,CAAC;YAC9B,IAAI,aAAa,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CAAC,YAAY,CAAC,OAAO;gCAC9B,OAAO,CAAC,GAAG,CAAC,+BAA+B,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC,CAAC,2CAA2C,CAAC,CAAA;4BACrH,UAAU,GAAG,IAAI,CAAA;4BACjB,OAAO;gCACL,GAAG,IAAI;gCACP,IAAI,EAAE;oCACJ,GAAG,IAAI,CAAC,IAAI;oCACZ,KAAK,EAAE,QAAQ,CAAC,SAAS,CAAC,CAAC,CAAC;iCAC7B;6BACyB,CAAA;wBAC9B,CAAC;oBACH,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,3 @@
1
+ import type { TransformOptions } from "../types";
2
+ export declare const defaultOptions: Readonly<Required<TransformOptions>>;
3
+ export declare function pickTransformOptions(options: Record<string, any>): Readonly<Required<TransformOptions>>;