@cedarjs/prerender 7.0.0-rc.128 → 8.0.0-canary.3263

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 (72) hide show
  1. package/dist/browserUtils/index.d.ts +1 -1
  2. package/dist/browserUtils/index.d.ts.map +1 -1
  3. package/dist/build-and-import/buildAndImport.d.ts +1 -1
  4. package/dist/build-and-import/buildAndImport.d.ts.map +1 -1
  5. package/dist/build-and-import/buildAndImport.js +2 -9
  6. package/dist/build-and-import/rollupPlugins/rollup-plugin-cedarjs-routes-auto-loader.d.ts.map +1 -1
  7. package/dist/graphql/graphql.d.ts +17 -2
  8. package/dist/graphql/graphql.d.ts.map +1 -1
  9. package/dist/{cjs/index.d.ts.map → index.d.ts.map} +1 -1
  10. package/dist/index.js +1 -0
  11. package/dist/runPrerender.d.ts.map +1 -0
  12. package/dist/{runPrerenderEsm.js → runPrerender.js} +65 -56
  13. package/package.json +20 -51
  14. package/dist/babelPlugins/babel-plugin-redwood-cell.d.ts +0 -5
  15. package/dist/babelPlugins/babel-plugin-redwood-cell.d.ts.map +0 -1
  16. package/dist/babelPlugins/babel-plugin-redwood-cell.js +0 -98
  17. package/dist/babelPlugins/babel-plugin-redwood-prerender-media-imports.d.ts +0 -5
  18. package/dist/babelPlugins/babel-plugin-redwood-prerender-media-imports.d.ts.map +0 -1
  19. package/dist/babelPlugins/babel-plugin-redwood-prerender-media-imports.js +0 -77
  20. package/dist/babelPlugins/utils.d.ts +0 -2
  21. package/dist/babelPlugins/utils.d.ts.map +0 -1
  22. package/dist/babelPlugins/utils.js +0 -15
  23. package/dist/cjs/apolloState.d.ts +0 -13
  24. package/dist/cjs/apolloState.d.ts.map +0 -1
  25. package/dist/cjs/apolloState.js +0 -30
  26. package/dist/cjs/babelPlugins/babel-plugin-redwood-cell.d.ts +0 -5
  27. package/dist/cjs/babelPlugins/babel-plugin-redwood-cell.d.ts.map +0 -1
  28. package/dist/cjs/babelPlugins/babel-plugin-redwood-cell.js +0 -122
  29. package/dist/cjs/babelPlugins/babel-plugin-redwood-prerender-media-imports.d.ts +0 -5
  30. package/dist/cjs/babelPlugins/babel-plugin-redwood-prerender-media-imports.d.ts.map +0 -1
  31. package/dist/cjs/babelPlugins/babel-plugin-redwood-prerender-media-imports.js +0 -101
  32. package/dist/cjs/babelPlugins/utils.d.ts +0 -2
  33. package/dist/cjs/babelPlugins/utils.d.ts.map +0 -1
  34. package/dist/cjs/babelPlugins/utils.js +0 -49
  35. package/dist/cjs/browserUtils/index.d.ts +0 -8
  36. package/dist/cjs/browserUtils/index.d.ts.map +0 -1
  37. package/dist/cjs/browserUtils/index.js +0 -47
  38. package/dist/cjs/build-and-import/buildAndImport.js +0 -193
  39. package/dist/cjs/build-and-import/load-tsconfig.d.js +0 -1
  40. package/dist/cjs/build-and-import/rollupPlugins/rollup-plugin-cedar-remove-dev-fatal-error-page.js +0 -53
  41. package/dist/cjs/build-and-import/rollupPlugins/rollup-plugin-cedarjs-cell.js +0 -184
  42. package/dist/cjs/build-and-import/rollupPlugins/rollup-plugin-cedarjs-directory-named-imports.js +0 -83
  43. package/dist/cjs/build-and-import/rollupPlugins/rollup-plugin-cedarjs-external.js +0 -125
  44. package/dist/cjs/build-and-import/rollupPlugins/rollup-plugin-cedarjs-ignore-html-and-css-imports.js +0 -48
  45. package/dist/cjs/build-and-import/rollupPlugins/rollup-plugin-cedarjs-inject-file-globals.js +0 -66
  46. package/dist/cjs/build-and-import/rollupPlugins/rollup-plugin-cedarjs-prerender-media-imports.js +0 -118
  47. package/dist/cjs/build-and-import/rollupPlugins/rollup-plugin-cedarjs-routes-auto-loader.js +0 -146
  48. package/dist/cjs/build-and-import/rollupPlugins/utils.js +0 -78
  49. package/dist/cjs/build-and-import/utils.js +0 -68
  50. package/dist/cjs/detection/detection.d.ts +0 -11
  51. package/dist/cjs/detection/detection.d.ts.map +0 -1
  52. package/dist/cjs/detection/detection.js +0 -46
  53. package/dist/cjs/errors.d.ts +0 -19
  54. package/dist/cjs/errors.d.ts.map +0 -1
  55. package/dist/cjs/errors.js +0 -52
  56. package/dist/cjs/graphql/graphql.d.ts +0 -19
  57. package/dist/cjs/graphql/graphql.d.ts.map +0 -1
  58. package/dist/cjs/graphql/graphql.js +0 -152
  59. package/dist/cjs/graphql/node-runner.js +0 -97
  60. package/dist/cjs/graphql/vite-plugin-cedar-auto-import.js +0 -107
  61. package/dist/cjs/index.js +0 -22
  62. package/dist/cjs/internal.d.ts +0 -28
  63. package/dist/cjs/internal.d.ts.map +0 -1
  64. package/dist/cjs/internal.js +0 -135
  65. package/dist/cjs/package.json +0 -1
  66. package/dist/cjs/runPrerender.d.ts.map +0 -1
  67. package/dist/cjs/runPrerender.js +0 -311
  68. package/dist/cjs/runPrerenderEsm.js +0 -308
  69. package/dist/runPrerenderEsm.d.ts +0 -9
  70. package/dist/runPrerenderEsm.d.ts.map +0 -1
  71. /package/dist/{cjs/index.d.ts → index.d.ts} +0 -0
  72. /package/dist/{cjs/runPrerender.d.ts → runPrerender.d.ts} +0 -0
@@ -1,146 +0,0 @@
1
- "use strict";
2
- var __create = Object.create;
3
- var __defProp = Object.defineProperty;
4
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
- var __getOwnPropNames = Object.getOwnPropertyNames;
6
- var __getProtoOf = Object.getPrototypeOf;
7
- var __hasOwnProp = Object.prototype.hasOwnProperty;
8
- var __export = (target, all) => {
9
- for (var name in all)
10
- __defProp(target, name, { get: all[name], enumerable: true });
11
- };
12
- var __copyProps = (to, from, except, desc) => {
13
- if (from && typeof from === "object" || typeof from === "function") {
14
- for (let key of __getOwnPropNames(from))
15
- if (!__hasOwnProp.call(to, key) && key !== except)
16
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
- }
18
- return to;
19
- };
20
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
- // If the importer is in node compatibility mode or this is not an ESM
22
- // file that has been converted to a CommonJS file using a Babel-
23
- // compatible transform (i.e. "__esModule" has not been set), then set
24
- // "default" to the CommonJS "module.exports" for node compatibility.
25
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
- mod
27
- ));
28
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
- var rollup_plugin_cedarjs_routes_auto_loader_exports = {};
30
- __export(rollup_plugin_cedarjs_routes_auto_loader_exports, {
31
- cedarjsRoutesAutoLoaderPlugin: () => cedarjsRoutesAutoLoaderPlugin
32
- });
33
- module.exports = __toCommonJS(rollup_plugin_cedarjs_routes_auto_loader_exports);
34
- var import_path = __toESM(require("path"), 1);
35
- var import_pluginutils = require("@rollup/pluginutils");
36
- var import_project_config = require("@cedarjs/project-config");
37
- var import_utils = require("./utils.js");
38
- function getPathRelativeToSrc(maybeAbsolutePath) {
39
- if (!import_path.default.isAbsolute(maybeAbsolutePath)) {
40
- return maybeAbsolutePath;
41
- }
42
- return `./${import_path.default.relative((0, import_project_config.getPaths)().web.src, maybeAbsolutePath)}`;
43
- }
44
- function withRelativeImports(page) {
45
- return {
46
- ...page,
47
- relativeImport: (0, import_project_config.ensurePosixPath)(getPathRelativeToSrc(page.importPath))
48
- };
49
- }
50
- function cedarjsRoutesAutoLoaderPlugin() {
51
- let pages = (0, import_project_config.processPagesDir)().map(withRelativeImports);
52
- const duplicatePageImportNames = /* @__PURE__ */ new Set();
53
- const sortedPageImportNames = pages.map((page) => page.importName).sort();
54
- for (let i = 0; i < sortedPageImportNames.length - 1; i++) {
55
- if (sortedPageImportNames[i + 1] === sortedPageImportNames[i]) {
56
- duplicatePageImportNames.add(sortedPageImportNames[i]);
57
- }
58
- }
59
- if (duplicatePageImportNames.size > 0) {
60
- const dirList = Array.from(duplicatePageImportNames).map((name) => `'${name}'`).join(", ");
61
- throw new Error(
62
- `Unable to find only a single file ending in 'Page.{js,jsx,ts,tsx}' in the following page directories: ${dirList}`
63
- );
64
- }
65
- const filter = (0, import_pluginutils.createFilter)(["**/src/Routes.{tsx,jsx,js}"]);
66
- return {
67
- name: "cedarjs-routes-auto-loader",
68
- buildStart() {
69
- pages = (0, import_project_config.processPagesDir)().map(withRelativeImports);
70
- },
71
- transform(code, id) {
72
- if (!filter(id)) {
73
- return null;
74
- }
75
- let currentPages = [...pages];
76
- const importRegex = /import\s+(\w+)\s+from\s+['"]([^'"]+)['"]/g;
77
- let match;
78
- const excludedPages = /* @__PURE__ */ new Set();
79
- while ((match = importRegex.exec(code)) !== null) {
80
- const [_fullMatch, defaultImportName, importPath] = match;
81
- const importPathWithoutExtension = importPath.replace(
82
- /\.(js|jsx|ts|tsx)$/,
83
- ""
84
- );
85
- const normalizedPathBase = importPathWithoutExtension.replace(
86
- /\/[^/]+$/,
87
- ""
88
- );
89
- const normalizedPathFull = importPathWithoutExtension;
90
- const userImportRelativePaths = [
91
- getPathRelativeToSrc((0, import_project_config.importStatementPath)(normalizedPathBase)),
92
- getPathRelativeToSrc((0, import_project_config.importStatementPath)(normalizedPathFull))
93
- ];
94
- const pageThatUserImported = currentPages.find((page) => {
95
- const pageRelativeImport = page.relativeImport.replace(
96
- /\.(js|jsx|ts|tsx)$/,
97
- ""
98
- );
99
- const importNameMatches = page.importName === defaultImportName;
100
- const pathMatches = userImportRelativePaths.some(
101
- (path2) => pageRelativeImport === (0, import_project_config.ensurePosixPath)(path2) || pageRelativeImport.endsWith(`/${path2.split("/").pop()}`)
102
- );
103
- return importNameMatches || pathMatches;
104
- });
105
- if (pageThatUserImported) {
106
- excludedPages.add(pageThatUserImported.importName);
107
- currentPages = currentPages.filter(
108
- (page) => page !== pageThatUserImported
109
- );
110
- }
111
- }
112
- if (currentPages.length === 0) {
113
- return { code, map: null };
114
- }
115
- const imports = [];
116
- const declarations = [];
117
- imports.push(`import { lazy } from 'react'`);
118
- for (const { importName, relativeImport } of currentPages) {
119
- if (excludedPages.has(importName)) {
120
- continue;
121
- }
122
- imports.push(
123
- `import __cedarjs_prerender__${importName} from '${relativeImport}';`
124
- );
125
- const declaration = (0, import_utils.dedent)(8)`const ${importName} = {
126
- name: "${importName}",
127
- prerenderLoader: (name) => ({ default: __cedarjs_prerender__${importName} }),
128
- LazyComponent: lazy(() => import("${relativeImport}"))
129
- }`;
130
- declarations.push(declaration);
131
- }
132
- const autoLoaderCode = imports.join("\n") + "\n\n" + declarations.join("\n\n");
133
- const finalCode = `${autoLoaderCode}
134
-
135
- ${code}`;
136
- return {
137
- code: finalCode,
138
- map: null
139
- };
140
- }
141
- };
142
- }
143
- // Annotate the CommonJS export names for ESM import in node:
144
- 0 && (module.exports = {
145
- cedarjsRoutesAutoLoaderPlugin
146
- });
@@ -1,78 +0,0 @@
1
- "use strict";
2
- var __create = Object.create;
3
- var __defProp = Object.defineProperty;
4
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
- var __getOwnPropNames = Object.getOwnPropertyNames;
6
- var __getProtoOf = Object.getPrototypeOf;
7
- var __hasOwnProp = Object.prototype.hasOwnProperty;
8
- var __export = (target, all) => {
9
- for (var name in all)
10
- __defProp(target, name, { get: all[name], enumerable: true });
11
- };
12
- var __copyProps = (to, from, except, desc) => {
13
- if (from && typeof from === "object" || typeof from === "function") {
14
- for (let key of __getOwnPropNames(from))
15
- if (!__hasOwnProp.call(to, key) && key !== except)
16
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
- }
18
- return to;
19
- };
20
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
- // If the importer is in node compatibility mode or this is not an ESM
22
- // file that has been converted to a CommonJS file using a Babel-
23
- // compatible transform (i.e. "__esModule" has not been set), then set
24
- // "default" to the CommonJS "module.exports" for node compatibility.
25
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
- mod
27
- ));
28
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
- var utils_exports = {};
30
- __export(utils_exports, {
31
- convertToDataUrl: () => convertToDataUrl,
32
- dedent: () => dedent
33
- });
34
- module.exports = __toCommonJS(utils_exports);
35
- var import_node_fs = __toESM(require("node:fs"), 1);
36
- var import_mime_types = __toESM(require("mime-types"), 1);
37
- function convertToDataUrl(assetPath) {
38
- try {
39
- const base64AssetContents = import_node_fs.default.readFileSync(assetPath, "base64");
40
- const mimeType = import_mime_types.default.lookup(assetPath);
41
- return `data:${mimeType};base64,${base64AssetContents}`;
42
- } catch {
43
- console.warn(`Could not read file ${assetPath} for conversion to data uri`);
44
- return "";
45
- }
46
- }
47
- function dedent(indentLevel) {
48
- return (strings, ...values) => {
49
- let result = strings[0];
50
- for (let i = 0; i < values.length; i++) {
51
- result += values[i] + strings[i + 1];
52
- }
53
- const lines = result.split("\n");
54
- while (lines.length > 0 && lines[0].trim() === "") {
55
- lines.shift();
56
- }
57
- while (lines.length > 0 && lines[lines.length - 1].trim() === "") {
58
- lines.pop();
59
- }
60
- const minIndent = indentLevel;
61
- const dedentedLines = lines.map((line) => {
62
- if (line.trim() === "") {
63
- return "";
64
- }
65
- const match = line.match(/^(\s*)/);
66
- if (match && match[1].length >= minIndent) {
67
- return line.slice(minIndent);
68
- }
69
- return line;
70
- });
71
- return dedentedLines.join("\n");
72
- };
73
- }
74
- // Annotate the CommonJS export names for ESM import in node:
75
- 0 && (module.exports = {
76
- convertToDataUrl,
77
- dedent
78
- });
@@ -1,68 +0,0 @@
1
- "use strict";
2
- var __create = Object.create;
3
- var __defProp = Object.defineProperty;
4
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
- var __getOwnPropNames = Object.getOwnPropertyNames;
6
- var __getProtoOf = Object.getPrototypeOf;
7
- var __hasOwnProp = Object.prototype.hasOwnProperty;
8
- var __export = (target, all) => {
9
- for (var name in all)
10
- __defProp(target, name, { get: all[name], enumerable: true });
11
- };
12
- var __copyProps = (to, from, except, desc) => {
13
- if (from && typeof from === "object" || typeof from === "function") {
14
- for (let key of __getOwnPropNames(from))
15
- if (!__hasOwnProp.call(to, key) && key !== except)
16
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
- }
18
- return to;
19
- };
20
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
- // If the importer is in node compatibility mode or this is not an ESM
22
- // file that has been converted to a CommonJS file using a Babel-
23
- // compatible transform (i.e. "__esModule" has not been set), then set
24
- // "default" to the CommonJS "module.exports" for node compatibility.
25
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
- mod
27
- ));
28
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
- var utils_exports = {};
30
- __export(utils_exports, {
31
- JS_EXT_RE: () => JS_EXT_RE,
32
- getPkgType: () => getPkgType,
33
- getRandomId: () => getRandomId,
34
- isValidJsFile: () => isValidJsFile,
35
- makeFilePath: () => makeFilePath
36
- });
37
- module.exports = __toCommonJS(utils_exports);
38
- var import_node_fs = __toESM(require("node:fs"), 1);
39
- var import_node_path = __toESM(require("node:path"), 1);
40
- var import_node_url = require("node:url");
41
- const JS_EXT_RE = /\.([mc]?[tj]s|[tj]sx)$/;
42
- function getPkgType() {
43
- try {
44
- const pkg = JSON.parse(
45
- import_node_fs.default.readFileSync(import_node_path.default.resolve("package.json"), "utf-8")
46
- );
47
- return pkg.type;
48
- } catch {
49
- }
50
- return void 0;
51
- }
52
- const getRandomId = () => {
53
- return Math.random().toString(36).substring(2, 15);
54
- };
55
- function isValidJsFile(filepath) {
56
- return JS_EXT_RE.test(filepath);
57
- }
58
- function makeFilePath(path2) {
59
- return (0, import_node_url.pathToFileURL)(path2).href;
60
- }
61
- // Annotate the CommonJS export names for ESM import in node:
62
- 0 && (module.exports = {
63
- JS_EXT_RE,
64
- getPkgType,
65
- getRandomId,
66
- isValidJsFile,
67
- makeFilePath
68
- });
@@ -1,11 +0,0 @@
1
- export declare const detectPrerenderRoutes: () => {
2
- name: string | undefined;
3
- path: string | undefined;
4
- routePath: string | undefined;
5
- hasParams: boolean;
6
- id: string;
7
- isNotFound: boolean;
8
- filePath: string | undefined;
9
- pageIdentifier: string | undefined;
10
- }[];
11
- //# sourceMappingURL=detection.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"detection.d.ts","sourceRoot":"","sources":["../../../src/detection/detection.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,qBAAqB;;;;;;;;;GAqBjC,CAAA"}
@@ -1,46 +0,0 @@
1
- "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __export = (target, all) => {
7
- for (var name in all)
8
- __defProp(target, name, { get: all[name], enumerable: true });
9
- };
10
- var __copyProps = (to, from, except, desc) => {
11
- if (from && typeof from === "object" || typeof from === "function") {
12
- for (let key of __getOwnPropNames(from))
13
- if (!__hasOwnProp.call(to, key) && key !== except)
14
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
- }
16
- return to;
17
- };
18
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
- var detection_exports = {};
20
- __export(detection_exports, {
21
- detectPrerenderRoutes: () => detectPrerenderRoutes
22
- });
23
- module.exports = __toCommonJS(detection_exports);
24
- var import_structure = require("@cedarjs/structure");
25
- const detectPrerenderRoutes = () => {
26
- const routes = (0, import_structure.getProject)().getRouter().routes;
27
- const prerenderRoutes = routes.filter((route) => route.prerender).map((route) => ({
28
- name: route.isNotFound ? "404" : route.name,
29
- // `path` will be updated/expanded later where route parameters will be
30
- // replaced with actual values
31
- path: route.isNotFound ? "/404" : route.path,
32
- // `routePath` is always the path specified on the <Route> component
33
- // (or the special /404 path)
34
- routePath: route.isNotFound ? "/404" : route.path,
35
- hasParams: route.hasParameters,
36
- id: route.id,
37
- isNotFound: route.isNotFound,
38
- filePath: route.page?.filePath,
39
- pageIdentifier: route.page_identifier_str
40
- }));
41
- return prerenderRoutes;
42
- };
43
- // Annotate the CommonJS export names for ESM import in node:
44
- 0 && (module.exports = {
45
- detectPrerenderRoutes
46
- });
@@ -1,19 +0,0 @@
1
- import type { DocumentNode } from 'graphql';
2
- export declare class PrerenderGqlError extends Error {
3
- stack: string;
4
- constructor(message: string);
5
- }
6
- export declare class GqlHandlerImportError extends Error {
7
- stack: string;
8
- constructor(message: string);
9
- }
10
- interface JSONParseErrorArgs {
11
- query: DocumentNode;
12
- variables?: Record<string, unknown>;
13
- result: string;
14
- }
15
- export declare class JSONParseError extends Error {
16
- constructor({ query, variables, result }: JSONParseErrorArgs);
17
- }
18
- export {};
19
- //# sourceMappingURL=errors.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../src/errors.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,SAAS,CAAA;AAG3C,qBAAa,iBAAkB,SAAQ,KAAK;IAC1C,KAAK,EAAE,MAAM,CAAA;gBAED,OAAO,EAAE,MAAM;CAO5B;AAED,qBAAa,qBAAsB,SAAQ,KAAK;IAC9C,KAAK,EAAE,MAAM,CAAA;gBAED,OAAO,EAAE,MAAM;CAO5B;AAED,UAAU,kBAAkB;IAC1B,KAAK,EAAE,YAAY,CAAA;IACnB,SAAS,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;IACnC,MAAM,EAAE,MAAM,CAAA;CACf;AAED,qBAAa,cAAe,SAAQ,KAAK;gBAC3B,EAAE,KAAK,EAAE,SAAS,EAAE,MAAM,EAAE,EAAE,kBAAkB;CAY7D"}
@@ -1,52 +0,0 @@
1
- "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __export = (target, all) => {
7
- for (var name in all)
8
- __defProp(target, name, { get: all[name], enumerable: true });
9
- };
10
- var __copyProps = (to, from, except, desc) => {
11
- if (from && typeof from === "object" || typeof from === "function") {
12
- for (let key of __getOwnPropNames(from))
13
- if (!__hasOwnProp.call(to, key) && key !== except)
14
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
- }
16
- return to;
17
- };
18
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
- var errors_exports = {};
20
- __export(errors_exports, {
21
- GqlHandlerImportError: () => GqlHandlerImportError,
22
- JSONParseError: () => JSONParseError,
23
- PrerenderGqlError: () => PrerenderGqlError
24
- });
25
- module.exports = __toCommonJS(errors_exports);
26
- var import_graphql = require("graphql");
27
- class PrerenderGqlError extends Error {
28
- stack;
29
- constructor(message) {
30
- super("GQL error: " + message);
31
- this.stack = this.message;
32
- }
33
- }
34
- class GqlHandlerImportError extends Error {
35
- stack;
36
- constructor(message) {
37
- super("Gql Handler Import Error: " + message);
38
- this.stack = this.message;
39
- }
40
- }
41
- class JSONParseError extends Error {
42
- constructor({ query, variables, result }) {
43
- const message = "Could not parse the GraphQL response.\n Request: " + (0, import_graphql.print)(query).split("\n").join("\n ") + "\n Variables: " + JSON.stringify(variables) + "\n Response: " + result;
44
- super(message);
45
- }
46
- }
47
- // Annotate the CommonJS export names for ESM import in node:
48
- 0 && (module.exports = {
49
- GqlHandlerImportError,
50
- JSONParseError,
51
- PrerenderGqlError
52
- });
@@ -1,19 +0,0 @@
1
- import type { DocumentNode } from 'graphql';
2
- export type FileImporter = (path: string) => Promise<any>;
3
- /**
4
- * Loads the graphql server, with all the user's settings
5
- * And execute the query against it
6
- *
7
- * Note that this function does NOT throw errors, even when
8
- * there is a GraphQL error. Instead, it returns the result with the graphql
9
- * error.
10
- */
11
- export declare function executeQuery(fileImporter: FileImporter, gqlHandler: (args: any) => Promise<any>, query: DocumentNode, variables?: Record<string, unknown>): Promise<any>;
12
- /**
13
- * Finds the graphql handler, returns a function
14
- * that can be used to execute queries against it
15
- *
16
- * Throws GqlHandlerImportError, so that we can warn the user (but not blow up)
17
- */
18
- export declare function getGqlHandler(fileImporter: FileImporter): Promise<(operation: Record<string, unknown>) => Promise<any>>;
19
- //# sourceMappingURL=graphql.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"graphql.d.ts","sourceRoot":"","sources":["../../../src/graphql/graphql.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,SAAS,CAAA;AAS3C,MAAM,MAAM,YAAY,GAAG,CAAC,IAAI,EAAE,MAAM,KAAK,OAAO,CAAC,GAAG,CAAC,CAAA;AASzD;;;;;;;GAOG;AACH,wBAAsB,YAAY,CAChC,YAAY,EAAE,YAAY,EAC1B,UAAU,EAAE,CAAC,IAAI,EAAE,GAAG,KAAK,OAAO,CAAC,GAAG,CAAC,EACvC,KAAK,EAAE,YAAY,EACnB,SAAS,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,gBAmCpC;AAED;;;;;GAKG;AACH,wBAAsB,aAAa,CAAC,YAAY,EAAE,YAAY,uBAMjC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,mBAUnD"}
@@ -1,152 +0,0 @@
1
- "use strict";
2
- var __create = Object.create;
3
- var __defProp = Object.defineProperty;
4
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
- var __getOwnPropNames = Object.getOwnPropertyNames;
6
- var __getProtoOf = Object.getPrototypeOf;
7
- var __hasOwnProp = Object.prototype.hasOwnProperty;
8
- var __export = (target, all) => {
9
- for (var name in all)
10
- __defProp(target, name, { get: all[name], enumerable: true });
11
- };
12
- var __copyProps = (to, from, except, desc) => {
13
- if (from && typeof from === "object" || typeof from === "function") {
14
- for (let key of __getOwnPropNames(from))
15
- if (!__hasOwnProp.call(to, key) && key !== except)
16
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
- }
18
- return to;
19
- };
20
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
- // If the importer is in node compatibility mode or this is not an ESM
22
- // file that has been converted to a CommonJS file using a Babel-
23
- // compatible transform (i.e. "__esModule" has not been set), then set
24
- // "default" to the CommonJS "module.exports" for node compatibility.
25
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
- mod
27
- ));
28
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
- var graphql_exports = {};
30
- __export(graphql_exports, {
31
- executeQuery: () => executeQuery,
32
- getGqlHandler: () => getGqlHandler
33
- });
34
- module.exports = __toCommonJS(graphql_exports);
35
- var import_path = __toESM(require("path"), 1);
36
- var import_graphql = require("graphql");
37
- var import_project_config = require("@cedarjs/project-config");
38
- var import_graphql2 = require("@cedarjs/web/dist/graphql.js");
39
- var import_errors = require("../errors.js");
40
- async function executeQuery(fileImporter, gqlHandler, query, variables) {
41
- const config = (0, import_project_config.getConfig)();
42
- const operationName = (0, import_graphql2.getOperationName)(query);
43
- const operation = {
44
- operationName,
45
- query: (0, import_graphql.print)(query),
46
- variables
47
- };
48
- if (config.graphql.trustedDocuments) {
49
- const documentsPath = import_path.default.join((0, import_project_config.getPaths)().web.graphql, "graphql");
50
- const documents = await fileImporter(documentsPath);
51
- const documentName = operationName[0].toUpperCase() + operationName.slice(1) + "Document";
52
- const queryHash = documents?.[documentName]?.__meta__?.hash;
53
- operation.query = void 0;
54
- operation.extensions = {
55
- persistedQuery: {
56
- version: 1,
57
- sha256Hash: queryHash
58
- }
59
- };
60
- }
61
- const handlerResult = await gqlHandler(operation);
62
- return handlerResult?.body;
63
- }
64
- async function getGqlHandler(fileImporter) {
65
- const gqlPath = import_path.default.join((0, import_project_config.getPaths)().api.functions, "graphql");
66
- try {
67
- const { handler } = await fileImporter(gqlPath);
68
- return async (operation) => {
69
- return await handler(buildApiEvent(operation), buildContext());
70
- };
71
- } catch {
72
- return () => {
73
- throw new import_errors.GqlHandlerImportError(
74
- `Unable to import GraphQL handler at ${gqlPath}`
75
- );
76
- };
77
- }
78
- }
79
- function buildApiEvent(body) {
80
- return {
81
- body: JSON.stringify(body),
82
- headers: {
83
- origin: "http://localhost:8910",
84
- "content-type": "application/json",
85
- accept: "*/*",
86
- host: "localhost:8910"
87
- },
88
- multiValueHeaders: {},
89
- httpMethod: "POST",
90
- isBase64Encoded: false,
91
- path: "/graphql",
92
- pathParameters: null,
93
- queryStringParameters: {},
94
- multiValueQueryStringParameters: null,
95
- stageVariables: null,
96
- resource: "",
97
- requestContext: {
98
- requestId: "req-3",
99
- identity: {
100
- sourceIp: "::1",
101
- accessKey: null,
102
- accountId: null,
103
- apiKey: null,
104
- apiKeyId: null,
105
- caller: null,
106
- clientCert: null,
107
- cognitoAuthenticationProvider: null,
108
- cognitoAuthenticationType: null,
109
- cognitoIdentityId: null,
110
- cognitoIdentityPoolId: null,
111
- principalOrgId: null,
112
- user: null,
113
- userAgent: null,
114
- userArn: null
115
- },
116
- authorizer: {},
117
- protocol: "http",
118
- httpMethod: "POST",
119
- path: "/graphql",
120
- stage: "",
121
- requestTimeEpoch: 0,
122
- resourceId: "",
123
- resourcePath: "",
124
- accountId: "",
125
- apiId: ""
126
- }
127
- };
128
- }
129
- function buildContext() {
130
- return {
131
- callbackWaitsForEmptyEventLoop: false,
132
- functionName: "",
133
- functionVersion: "",
134
- invokedFunctionArn: "",
135
- memoryLimitInMB: "",
136
- awsRequestId: "",
137
- logGroupName: "",
138
- logStreamName: "",
139
- getRemainingTimeInMillis: () => 100,
140
- done: () => {
141
- },
142
- fail: () => {
143
- },
144
- succeed: () => {
145
- }
146
- };
147
- }
148
- // Annotate the CommonJS export names for ESM import in node:
149
- 0 && (module.exports = {
150
- executeQuery,
151
- getGqlHandler
152
- });