vike 0.4.229-commit-58f7ed0 → 0.4.229-commit-5da80bf
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/dist/cjs/client/server-routing-runtime/utils.js +1 -0
- package/dist/cjs/client/shared/{preparePageContextForUserConsumptionClientSide.js → preparePageContextForPublicUsageClientShared.js} +15 -19
- package/dist/cjs/node/api/build.js +1 -5
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/configDefinitionsBuiltIn.js +4 -0
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.js +12 -6
- package/dist/cjs/node/plugin/shared/loggerNotProd.js +2 -2
- package/dist/cjs/node/prerender/runPrerender.js +42 -38
- package/dist/cjs/node/prerender/utils.js +1 -1
- package/dist/cjs/node/runtime/globalContext.js +13 -27
- package/dist/cjs/node/runtime/html/serializeContext.js +1 -1
- package/dist/cjs/node/runtime/renderPage/createHttpResponse/getCacheControl.js +7 -5
- package/dist/cjs/node/runtime/renderPage/createHttpResponse.js +0 -1
- package/dist/cjs/node/runtime/renderPage/createPageContextServerSide.js +6 -9
- package/dist/cjs/node/runtime/renderPage/execHookServer.js +11 -0
- package/dist/cjs/node/runtime/renderPage/executeOnBeforeRenderAndDataHooks.js +14 -15
- package/dist/cjs/node/runtime/renderPage/executeOnRenderHtmlHook.js +8 -12
- package/dist/cjs/node/runtime/renderPage/{loadUserFilesServerSide.js → loadPageConfigsLazyServerSide.js} +4 -4
- package/dist/cjs/node/runtime/renderPage/preparePageContextForPublicUsageServer.js +10 -0
- package/dist/cjs/node/runtime/renderPage/renderPageAlreadyRouted.js +5 -5
- package/dist/cjs/node/runtime/renderPage.js +9 -7
- package/dist/cjs/node/runtime/utils.js +1 -1
- package/dist/cjs/shared/NOT_SERIALIZABLE.js +0 -1
- package/dist/cjs/shared/addIs404ToPageProps.js +0 -7
- package/dist/cjs/shared/createGlobalContextShared.js +37 -8
- package/dist/cjs/shared/createPageContextShared.js +16 -11
- package/dist/cjs/shared/getPageContext.js +3 -3
- package/dist/cjs/shared/getPageContextUrlComputed.js +2 -36
- package/dist/cjs/shared/getProxyForPublicUsage.js +106 -0
- package/dist/cjs/shared/hooks/execHook.js +164 -0
- package/dist/cjs/shared/hooks/getHook.js +23 -4
- package/dist/cjs/shared/page-configs/{getPageConfigUserFriendly.js → getUserFriendlyConfigs.js} +54 -47
- package/dist/cjs/shared/prepareGlobalContextForPublicUsage.js +10 -0
- package/dist/cjs/shared/preparePageContextForPublicUsage.js +75 -0
- package/dist/cjs/shared/route/abort.js +2 -2
- package/dist/cjs/shared/route/executeGuardHook.js +4 -9
- package/dist/cjs/shared/route/executeOnBeforeRouteHook.js +4 -3
- package/dist/cjs/shared/route/index.js +2 -4
- package/dist/cjs/shared/route/loadPageRoutes.js +6 -0
- package/dist/cjs/shared/route/resolveRouteFunction.js +14 -10
- package/dist/cjs/shared/utils.js +2 -0
- package/dist/cjs/utils/PROJECT_VERSION.js +1 -1
- package/dist/cjs/utils/objectAssign.js +3 -3
- package/dist/cjs/utils/objectDefineProperty.js +1 -1
- package/dist/esm/client/client-routing-runtime/{createPageContext.d.ts → createPageContextClientSide.d.ts} +21 -13
- package/dist/esm/client/client-routing-runtime/{createPageContext.js → createPageContextClientSide.js} +9 -11
- package/dist/esm/client/client-routing-runtime/getPageContextFromHooks.d.ts +400 -15
- package/dist/esm/client/client-routing-runtime/getPageContextFromHooks.js +46 -44
- package/dist/esm/client/client-routing-runtime/globalContext.d.ts +11 -1
- package/dist/esm/client/client-routing-runtime/prefetch.d.ts +3 -8
- package/dist/esm/client/client-routing-runtime/prefetch.js +3 -3
- package/dist/esm/client/client-routing-runtime/preparePageContextForPublicUsageClient.d.ts +11 -0
- package/dist/esm/client/client-routing-runtime/preparePageContextForPublicUsageClient.js +5 -0
- package/dist/esm/client/client-routing-runtime/renderPageClientSide.d.ts +135 -0
- package/dist/esm/client/client-routing-runtime/renderPageClientSide.js +79 -78
- package/dist/esm/client/client-routing-runtime/utils.d.ts +1 -0
- package/dist/esm/client/client-routing-runtime/utils.js +1 -0
- package/dist/esm/client/server-routing-runtime/createPageContextClientSide.d.ts +19 -13
- package/dist/esm/client/server-routing-runtime/createPageContextClientSide.js +12 -15
- package/dist/esm/client/server-routing-runtime/entry.js +4 -4
- package/dist/esm/client/server-routing-runtime/globalContext.d.ts +11 -1
- package/dist/esm/client/server-routing-runtime/preparePageContextForPublicUsageClient.d.ts +9 -0
- package/dist/esm/client/server-routing-runtime/preparePageContextForPublicUsageClient.js +5 -0
- package/dist/esm/client/server-routing-runtime/utils.d.ts +1 -0
- package/dist/esm/client/server-routing-runtime/utils.js +1 -0
- package/dist/esm/client/shared/createGetGlobalContextClient.d.ts +11 -1
- package/dist/esm/client/shared/executeOnRenderClientHook.d.ts +3 -3
- package/dist/esm/client/shared/executeOnRenderClientHook.js +4 -13
- package/dist/esm/client/shared/{loadUserFilesClientSide.d.ts → loadPageConfigsLazyClientSide.d.ts} +2 -2
- package/dist/esm/client/shared/{loadUserFilesClientSide.js → loadPageConfigsLazyClientSide.js} +4 -4
- package/dist/esm/client/shared/preparePageContextForPublicUsageClientShared.d.ts +11 -0
- package/dist/esm/client/shared/preparePageContextForPublicUsageClientShared.js +40 -0
- package/dist/esm/node/api/build.js +1 -2
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/configDefinitionsBuiltIn.js +4 -0
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.d.ts +1 -1
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.js +12 -6
- package/dist/esm/node/plugin/shared/loggerNotProd.js +1 -1
- package/dist/esm/node/prerender/runPrerender.d.ts +37 -73
- package/dist/esm/node/prerender/runPrerender.js +42 -38
- package/dist/esm/node/prerender/utils.d.ts +1 -1
- package/dist/esm/node/prerender/utils.js +1 -1
- package/dist/esm/node/runtime/globalContext.d.ts +46 -251
- package/dist/esm/node/runtime/globalContext.js +14 -28
- package/dist/esm/node/runtime/html/serializeContext.d.ts +1 -1
- package/dist/esm/node/runtime/html/serializeContext.js +1 -1
- package/dist/esm/node/runtime/renderPage/createHttpResponse/getCacheControl.d.ts +1 -1
- package/dist/esm/node/runtime/renderPage/createHttpResponse/getCacheControl.js +7 -5
- package/dist/esm/node/runtime/renderPage/createHttpResponse.js +0 -1
- package/dist/esm/node/runtime/renderPage/createPageContextServerSide.d.ts +26 -41
- package/dist/esm/node/runtime/renderPage/createPageContextServerSide.js +7 -10
- package/dist/esm/node/runtime/renderPage/execHookServer.d.ts +12 -0
- package/dist/esm/node/runtime/renderPage/execHookServer.js +9 -0
- package/dist/esm/node/runtime/renderPage/executeOnBeforeRenderAndDataHooks.d.ts +2 -3
- package/dist/esm/node/runtime/renderPage/executeOnBeforeRenderAndDataHooks.js +14 -15
- package/dist/esm/node/runtime/renderPage/executeOnRenderHtmlHook.d.ts +4 -2
- package/dist/esm/node/runtime/renderPage/executeOnRenderHtmlHook.js +8 -12
- package/dist/esm/node/runtime/renderPage/{loadUserFilesServerSide.d.ts → loadPageConfigsLazyServerSide.d.ts} +6 -6
- package/dist/esm/node/runtime/renderPage/{loadUserFilesServerSide.js → loadPageConfigsLazyServerSide.js} +4 -4
- package/dist/esm/node/runtime/renderPage/preparePageContextForPublicUsageServer.d.ts +20 -0
- package/dist/esm/node/runtime/renderPage/preparePageContextForPublicUsageServer.js +8 -0
- package/dist/esm/node/runtime/renderPage/renderPageAlreadyRouted.d.ts +38 -74
- package/dist/esm/node/runtime/renderPage/renderPageAlreadyRouted.js +5 -5
- package/dist/esm/node/runtime/renderPage.d.ts +21 -39
- package/dist/esm/node/runtime/renderPage.js +9 -7
- package/dist/esm/node/runtime/utils.d.ts +1 -1
- package/dist/esm/node/runtime/utils.js +1 -1
- package/dist/esm/shared/NOT_SERIALIZABLE.js +0 -1
- package/dist/esm/shared/addIs404ToPageProps.d.ts +1 -6
- package/dist/esm/shared/addIs404ToPageProps.js +1 -8
- package/dist/esm/shared/createGlobalContextShared.d.ts +28 -6
- package/dist/esm/shared/createGlobalContextShared.js +37 -8
- package/dist/esm/shared/createPageContextShared.d.ts +7 -6
- package/dist/esm/shared/createPageContextShared.js +17 -12
- package/dist/esm/shared/getPageContext.d.ts +1 -1
- package/dist/esm/shared/getPageContext.js +1 -1
- package/dist/esm/shared/getPageContextUrlComputed.d.ts +2 -5
- package/dist/esm/shared/getPageContextUrlComputed.js +3 -37
- package/dist/esm/shared/getPageFiles.d.ts +1 -1
- package/dist/esm/shared/getProxyForPublicUsage.d.ts +12 -0
- package/dist/esm/shared/getProxyForPublicUsage.js +104 -0
- package/dist/esm/shared/hooks/execHook.d.ts +63 -0
- package/dist/esm/shared/hooks/execHook.js +162 -0
- package/dist/esm/shared/hooks/getHook.d.ts +10 -11
- package/dist/esm/shared/hooks/getHook.js +23 -4
- package/dist/esm/shared/page-configs/Config.d.ts +11 -4
- package/dist/esm/shared/page-configs/{getPageConfigUserFriendly.d.ts → getUserFriendlyConfigs.d.ts} +8 -6
- package/dist/esm/shared/page-configs/{getPageConfigUserFriendly.js → getUserFriendlyConfigs.js} +55 -48
- package/dist/esm/shared/prepareGlobalContextForPublicUsage.d.ts +7 -0
- package/dist/esm/shared/prepareGlobalContextForPublicUsage.js +8 -0
- package/dist/esm/shared/preparePageContextForPublicUsage.d.ts +12 -0
- package/dist/esm/shared/preparePageContextForPublicUsage.js +73 -0
- package/dist/esm/shared/route/abort.js +1 -1
- package/dist/esm/shared/route/executeGuardHook.d.ts +4 -3
- package/dist/esm/shared/route/executeGuardHook.js +4 -9
- package/dist/esm/shared/route/executeOnBeforeRouteHook.js +4 -3
- package/dist/esm/shared/route/index.js +2 -4
- package/dist/esm/shared/route/loadPageRoutes.d.ts +2 -1
- package/dist/esm/shared/route/loadPageRoutes.js +7 -1
- package/dist/esm/shared/route/resolveRouteFunction.d.ts +2 -2
- package/dist/esm/shared/route/resolveRouteFunction.js +14 -10
- package/dist/esm/shared/types.d.ts +14 -4
- package/dist/esm/shared/utils.d.ts +2 -0
- package/dist/esm/shared/utils.js +2 -0
- package/dist/esm/types/index.d.ts +1 -1
- package/dist/esm/utils/PROJECT_VERSION.d.ts +1 -1
- package/dist/esm/utils/PROJECT_VERSION.js +1 -1
- package/dist/esm/utils/objectAssign.d.ts +1 -1
- package/dist/esm/utils/objectAssign.js +3 -3
- package/dist/esm/utils/objectDefineProperty.d.ts +0 -1
- package/dist/esm/utils/objectDefineProperty.js +1 -1
- package/package.json +2 -2
- package/dist/cjs/client/shared/getPageContextProxyForUser.js +0 -16
- package/dist/cjs/node/runtime/renderPage/preparePageContextForUserConsumptionServerSide.js +0 -16
- package/dist/cjs/shared/getPageConfigsRuntime.js +0 -23
- package/dist/cjs/shared/hooks/executeHook.js +0 -87
- package/dist/cjs/shared/hooks/executeHookGeneric.js +0 -18
- package/dist/cjs/shared/preparePageContextForUserConsumption.js +0 -34
- package/dist/cjs/utils/getPublicProxy.js +0 -27
- package/dist/esm/client/shared/getPageContextProxyForUser.d.ts +0 -2
- package/dist/esm/client/shared/getPageContextProxyForUser.js +0 -14
- package/dist/esm/client/shared/preparePageContextForUserConsumptionClientSide.d.ts +0 -12
- package/dist/esm/client/shared/preparePageContextForUserConsumptionClientSide.js +0 -44
- package/dist/esm/node/runtime/renderPage/preparePageContextForUserConsumptionServerSide.d.ts +0 -24
- package/dist/esm/node/runtime/renderPage/preparePageContextForUserConsumptionServerSide.js +0 -14
- package/dist/esm/shared/getPageConfigsRuntime.d.ts +0 -14
- package/dist/esm/shared/getPageConfigsRuntime.js +0 -21
- package/dist/esm/shared/hooks/executeHook.d.ts +0 -21
- package/dist/esm/shared/hooks/executeHook.js +0 -85
- package/dist/esm/shared/hooks/executeHookGeneric.d.ts +0 -8
- package/dist/esm/shared/hooks/executeHookGeneric.js +0 -16
- package/dist/esm/shared/preparePageContextForUserConsumption.d.ts +0 -5
- package/dist/esm/shared/preparePageContextForUserConsumption.js +0 -32
- package/dist/esm/utils/getPublicProxy.d.ts +0 -2
- package/dist/esm/utils/getPublicProxy.js +0 -25
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.execHook = execHook;
|
|
4
|
+
exports.execHookSingle = execHookSingle;
|
|
5
|
+
exports.execHookSingleWithReturn = execHookSingleWithReturn;
|
|
6
|
+
exports.execHookErrorHandling = execHookErrorHandling;
|
|
7
|
+
exports.execHooksErrorHandling = execHooksErrorHandling;
|
|
8
|
+
exports.execHookWithoutPageContext = execHookWithoutPageContext;
|
|
9
|
+
exports.execHookGlobal = execHookGlobal;
|
|
10
|
+
exports.execHookSync = execHookSync;
|
|
11
|
+
exports.getPageContext = getPageContext;
|
|
12
|
+
exports.providePageContext = providePageContext;
|
|
13
|
+
exports.isUserHookError = isUserHookError;
|
|
14
|
+
const assert_js_1 = require("../../utils/assert.js");
|
|
15
|
+
const getGlobalObject_js_1 = require("../../utils/getGlobalObject.js");
|
|
16
|
+
const humanizeTime_js_1 = require("../../utils/humanizeTime.js");
|
|
17
|
+
const isObject_js_1 = require("../../utils/isObject.js");
|
|
18
|
+
const getHook_js_1 = require("./getHook.js");
|
|
19
|
+
const preparePageContextForPublicUsage_js_1 = require("../preparePageContextForPublicUsage.js");
|
|
20
|
+
const globalObject = (0, getGlobalObject_js_1.getGlobalObject)('utils/execHook.ts', {
|
|
21
|
+
userHookErrors: new WeakMap(),
|
|
22
|
+
pageContext: null
|
|
23
|
+
});
|
|
24
|
+
async function execHookSingle(hook, pageContext, preparePageContextForPublicUsage) {
|
|
25
|
+
const res = await execHooksErrorHandling([hook], pageContext, preparePageContextForPublicUsage);
|
|
26
|
+
if ('err' in res)
|
|
27
|
+
throw res.err;
|
|
28
|
+
const { hookReturn } = res.hooks[0];
|
|
29
|
+
(0, assert_js_1.assertUsage)(hookReturn === undefined, `The ${hook.hookName}() hook defined by ${hook.hookFilePath} isn't allowed to return a value`);
|
|
30
|
+
}
|
|
31
|
+
async function execHookSingleWithReturn(hook, pageContext, preparePageContextForPublicUsage) {
|
|
32
|
+
const res = await execHooksErrorHandling([hook], pageContext, preparePageContextForPublicUsage);
|
|
33
|
+
if ('err' in res)
|
|
34
|
+
throw res.err;
|
|
35
|
+
const { hookReturn } = res.hooks[0];
|
|
36
|
+
return { hookReturn };
|
|
37
|
+
}
|
|
38
|
+
async function execHook(hookName, pageContext, preparePageContextForPublicUsage) {
|
|
39
|
+
const res = await execHookErrorHandling(hookName, pageContext, preparePageContextForPublicUsage);
|
|
40
|
+
if ('err' in res)
|
|
41
|
+
throw res.err;
|
|
42
|
+
return res.hooks;
|
|
43
|
+
}
|
|
44
|
+
async function execHookErrorHandling(hookName, pageContext, preparePageContextForPublicUsage) {
|
|
45
|
+
const hooks = (0, getHook_js_1.getHookFromPageContextNew)(hookName, pageContext);
|
|
46
|
+
return execHooksErrorHandling(hooks, pageContext, preparePageContextForPublicUsage);
|
|
47
|
+
}
|
|
48
|
+
async function execHooksErrorHandling(hooks, pageContext, preparePageContextForPublicUsage) {
|
|
49
|
+
if (!hooks.length)
|
|
50
|
+
return { hooks: [] };
|
|
51
|
+
const pageContextForPublicUsage = preparePageContextForPublicUsage(pageContext);
|
|
52
|
+
let hooksWithResult;
|
|
53
|
+
let err;
|
|
54
|
+
try {
|
|
55
|
+
hooksWithResult = await Promise.all(hooks.map(async (hook) => {
|
|
56
|
+
const hookReturn = await execHookAsync(() => hook.hookFn(pageContextForPublicUsage), hook, pageContextForPublicUsage);
|
|
57
|
+
return { ...hook, hookReturn };
|
|
58
|
+
}));
|
|
59
|
+
}
|
|
60
|
+
catch (err_) {
|
|
61
|
+
err = err_;
|
|
62
|
+
}
|
|
63
|
+
if (hooksWithResult) {
|
|
64
|
+
return { hooks: hooksWithResult };
|
|
65
|
+
}
|
|
66
|
+
else {
|
|
67
|
+
return { hooks, err };
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
async function execHookGlobal(hookName, pageConfigGlobal, pageContext, hookArg, prepareForPublicUsage) {
|
|
71
|
+
const hooks = (0, getHook_js_1.getHookFromPageConfigGlobalCumulative)(pageConfigGlobal, hookName);
|
|
72
|
+
const hookArgForPublicUsage = prepareForPublicUsage(hookArg);
|
|
73
|
+
await Promise.all(hooks.map(async (hook) => {
|
|
74
|
+
await execHookAsync(() => hook.hookFn(hookArgForPublicUsage), hook, pageContext);
|
|
75
|
+
}));
|
|
76
|
+
}
|
|
77
|
+
function isUserHookError(err) {
|
|
78
|
+
if (!(0, isObject_js_1.isObject)(err))
|
|
79
|
+
return false;
|
|
80
|
+
return globalObject.userHookErrors.get(err) ?? false;
|
|
81
|
+
}
|
|
82
|
+
async function execHookWithoutPageContext(hookFnCaller, hook) {
|
|
83
|
+
const { hookName, hookFilePath, hookTimeout } = hook;
|
|
84
|
+
const hookReturn = await execHookAsync(hookFnCaller, { hookName, hookFilePath, hookTimeout }, null);
|
|
85
|
+
return hookReturn;
|
|
86
|
+
}
|
|
87
|
+
function execHookAsync(hookFnCaller, hook, pageContextForPublicUsage) {
|
|
88
|
+
const { hookName, hookFilePath, hookTimeout: { error: timeoutErr, warning: timeoutWarn } } = hook;
|
|
89
|
+
let resolve;
|
|
90
|
+
let reject;
|
|
91
|
+
const promise = new Promise((resolve_, reject_) => {
|
|
92
|
+
resolve = (ret) => {
|
|
93
|
+
clearTimeouts();
|
|
94
|
+
resolve_(ret);
|
|
95
|
+
};
|
|
96
|
+
reject = (err) => {
|
|
97
|
+
clearTimeouts();
|
|
98
|
+
reject_(err);
|
|
99
|
+
};
|
|
100
|
+
});
|
|
101
|
+
const clearTimeouts = () => {
|
|
102
|
+
if (currentTimeoutWarn)
|
|
103
|
+
clearTimeout(currentTimeoutWarn);
|
|
104
|
+
if (currentTimeoutErr)
|
|
105
|
+
clearTimeout(currentTimeoutErr);
|
|
106
|
+
};
|
|
107
|
+
const currentTimeoutWarn = isNotDisabled(timeoutWarn) &&
|
|
108
|
+
setTimeout(() => {
|
|
109
|
+
(0, assert_js_1.assertWarning)(false, `The ${hookName}() hook defined by ${hookFilePath} is slow: it's taking more than ${(0, humanizeTime_js_1.humanizeTime)(timeoutWarn)} (https://vike.dev/hooksTimeout)`, { onlyOnce: false });
|
|
110
|
+
}, timeoutWarn);
|
|
111
|
+
const currentTimeoutErr = isNotDisabled(timeoutErr) &&
|
|
112
|
+
setTimeout(() => {
|
|
113
|
+
const err = (0, assert_js_1.getProjectError)(`The ${hookName}() hook defined by ${hookFilePath} timed out: it didn't finish after ${(0, humanizeTime_js_1.humanizeTime)(timeoutErr)} (https://vike.dev/hooksTimeout)`);
|
|
114
|
+
reject(err);
|
|
115
|
+
}, timeoutErr);
|
|
116
|
+
(async () => {
|
|
117
|
+
try {
|
|
118
|
+
providePageContext(pageContextForPublicUsage);
|
|
119
|
+
const ret = await hookFnCaller();
|
|
120
|
+
resolve(ret);
|
|
121
|
+
}
|
|
122
|
+
catch (err) {
|
|
123
|
+
if ((0, isObject_js_1.isObject)(err)) {
|
|
124
|
+
globalObject.userHookErrors.set(err, { hookName, hookFilePath });
|
|
125
|
+
}
|
|
126
|
+
reject(err);
|
|
127
|
+
}
|
|
128
|
+
})();
|
|
129
|
+
return promise;
|
|
130
|
+
}
|
|
131
|
+
function execHookSync(hook, pageContext, preparePageContextForPublicUsage) {
|
|
132
|
+
const pageContextForPublicUsage = preparePageContextForPublicUsage(pageContext);
|
|
133
|
+
providePageContext(pageContextForPublicUsage);
|
|
134
|
+
const hookReturn = hook.hookFn(pageContextForPublicUsage);
|
|
135
|
+
return { hookReturn };
|
|
136
|
+
}
|
|
137
|
+
function isNotDisabled(timeout) {
|
|
138
|
+
return !!timeout && timeout !== Infinity;
|
|
139
|
+
}
|
|
140
|
+
/**
|
|
141
|
+
* Access `pageContext` object inside Vike hooks, in order to create universal hooks.
|
|
142
|
+
*
|
|
143
|
+
* https://vike.dev/getPageContext
|
|
144
|
+
*/
|
|
145
|
+
function getPageContext() {
|
|
146
|
+
const { pageContext } = globalObject;
|
|
147
|
+
if (!pageContext)
|
|
148
|
+
return pageContext;
|
|
149
|
+
const pageContextForPublicUsage = (0, preparePageContextForPublicUsage_js_1.preparePageContextForPublicUsage)(pageContext);
|
|
150
|
+
return pageContextForPublicUsage;
|
|
151
|
+
}
|
|
152
|
+
/**
|
|
153
|
+
* Provide `pageContext` for universal hooks.
|
|
154
|
+
*
|
|
155
|
+
* https://vike.dev/getPageContext
|
|
156
|
+
*/
|
|
157
|
+
function providePageContext(pageContext) {
|
|
158
|
+
globalObject.pageContext = pageContext;
|
|
159
|
+
// Promise.resolve() is quicker than process.nextTick() and setImmediate()
|
|
160
|
+
// https://stackoverflow.com/questions/67949576/process-nexttick-before-promise-resolve-then
|
|
161
|
+
Promise.resolve().then(() => {
|
|
162
|
+
globalObject.pageContext = null;
|
|
163
|
+
});
|
|
164
|
+
}
|
|
@@ -4,10 +4,10 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.getHookFromPageContext = getHookFromPageContext;
|
|
7
|
+
exports.getHookFromPageContextNew = getHookFromPageContextNew;
|
|
7
8
|
exports.getHookFromPageConfig = getHookFromPageConfig;
|
|
8
9
|
exports.getHookFromPageConfigGlobal = getHookFromPageConfigGlobal;
|
|
9
10
|
exports.getHookFromPageConfigGlobalCumulative = getHookFromPageConfigGlobalCumulative;
|
|
10
|
-
exports.assertHook = assertHook;
|
|
11
11
|
exports.getHook_setIsPrerenderering = getHook_setIsPrerenderering;
|
|
12
12
|
exports.getHookTimeoutDefault = getHookTimeoutDefault;
|
|
13
13
|
const getGlobalObject_js_1 = require("../../utils/getGlobalObject.js");
|
|
@@ -25,12 +25,34 @@ function getHookFromPageContext(pageContext, hookName) {
|
|
|
25
25
|
const hookFn = pageContext.exports[hookName];
|
|
26
26
|
if (hookFn === null)
|
|
27
27
|
return null;
|
|
28
|
+
// TO-DO/eventually: use pageContext.configEntries in favor of pageContext.exportsAll once V0.4 is removed
|
|
28
29
|
const file = pageContext.exportsAll[hookName][0];
|
|
29
30
|
(0, utils_js_1.assert)(file.exportValue === hookFn);
|
|
30
31
|
const hookFilePath = file.filePath;
|
|
31
32
|
(0, utils_js_1.assert)(hookFilePath);
|
|
32
33
|
return getHook(hookFn, hookName, hookFilePath, hookTimeout);
|
|
33
34
|
}
|
|
35
|
+
// TO-DO/eventually: remove getHookFromPageContext() in favor of getHookFromPageContextNew()
|
|
36
|
+
function getHookFromPageContextNew(hookName, pageContext) {
|
|
37
|
+
const { hooksTimeout } = pageContext.config;
|
|
38
|
+
const hookTimeout = getHookTimeout(hooksTimeout, hookName);
|
|
39
|
+
const hooks = [];
|
|
40
|
+
/* TO-DO/eventually: use pageContext.configEntries in favor of pageContext.exportsAll once V0.4 is removed
|
|
41
|
+
pageContext.configEntries[hookName]?.forEach((val) => {
|
|
42
|
+
const hookFn = val.configValue
|
|
43
|
+
if (hookFn === null) return
|
|
44
|
+
const hookFilePath = val.configDefinedByFile
|
|
45
|
+
*/
|
|
46
|
+
pageContext.exportsAll[hookName]?.forEach((val) => {
|
|
47
|
+
const hookFn = val.exportValue;
|
|
48
|
+
if (hookFn === null)
|
|
49
|
+
return;
|
|
50
|
+
const hookFilePath = val.filePath;
|
|
51
|
+
(0, utils_js_1.assert)(hookFilePath);
|
|
52
|
+
hooks.push(getHook(hookFn, hookName, hookFilePath, hookTimeout));
|
|
53
|
+
});
|
|
54
|
+
return hooks;
|
|
55
|
+
}
|
|
34
56
|
function getHookFromPageConfig(pageConfig, hookName) {
|
|
35
57
|
const configValue = (0, getConfigValueRuntime_js_1.getConfigValueRuntime)(pageConfig, hookName);
|
|
36
58
|
if (!configValue?.value)
|
|
@@ -79,9 +101,6 @@ function getHookFromConfigValue(configValue) {
|
|
|
79
101
|
const hookFilePath = (0, helpers_js_1.getHookFilePathToShowToUser)(configValue.definedAtData);
|
|
80
102
|
return { hookFn, hookFilePath };
|
|
81
103
|
}
|
|
82
|
-
function assertHook(pageContext, hookName) {
|
|
83
|
-
getHookFromPageContext(pageContext, hookName);
|
|
84
|
-
}
|
|
85
104
|
function assertHookFn(hookFn, { hookName, hookFilePath }) {
|
|
86
105
|
(0, utils_js_1.assert)(hookName && hookFilePath);
|
|
87
106
|
(0, utils_js_1.assert)(!hookName.endsWith(')'));
|
package/dist/cjs/shared/page-configs/{getPageConfigUserFriendly.js → getUserFriendlyConfigs.js}
RENAMED
|
@@ -3,16 +3,16 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.
|
|
7
|
-
exports.
|
|
8
|
-
exports.
|
|
6
|
+
exports.getUserFriendlyConfigsGlobal = getUserFriendlyConfigsGlobal;
|
|
7
|
+
exports.getUserFriendlyConfigsPageEager = getUserFriendlyConfigsPageEager;
|
|
8
|
+
exports.getUserFriendlyConfigsPageLazy = getUserFriendlyConfigsPageLazy;
|
|
9
9
|
const assert_exports_old_design_js_1 = require("../getPageFiles/assert_exports_old_design.js");
|
|
10
10
|
const getConfigDefinedAt_js_1 = require("./getConfigDefinedAt.js");
|
|
11
11
|
const helpers_js_1 = require("./helpers.js");
|
|
12
12
|
const utils_js_1 = require("../utils.js");
|
|
13
13
|
const picocolors_1 = __importDefault(require("@brillout/picocolors"));
|
|
14
|
-
function
|
|
15
|
-
const pageConfigUserFriendly =
|
|
14
|
+
function getUserFriendlyConfigsPageEager(pageConfigGlobalValues, pageConfig, pageConfigValues) {
|
|
15
|
+
const pageConfigUserFriendly = getUserFriendlyConfigs_public({ pageConfigGlobalValues, pageConfigValues });
|
|
16
16
|
let page;
|
|
17
17
|
if (!pageConfig.isErrorPage) {
|
|
18
18
|
const route = pageConfigUserFriendly.config.route ?? pageConfig.routeFilesystem.routeString;
|
|
@@ -29,8 +29,8 @@ function getPageConfigUserFriendly(pageConfigGlobalValues, pageConfig, pageConfi
|
|
|
29
29
|
}
|
|
30
30
|
return [pageConfig.pageId, page];
|
|
31
31
|
}
|
|
32
|
-
function
|
|
33
|
-
const pageConfigUserFriendly =
|
|
32
|
+
function getUserFriendlyConfigs_public({ pageConfigGlobalValues, pageConfigValues }) {
|
|
33
|
+
const pageConfigUserFriendly = getUserFriendlyConfigs_base({ pageConfigGlobalValues, pageConfigValues });
|
|
34
34
|
return getPublicCopy(pageConfigUserFriendly);
|
|
35
35
|
}
|
|
36
36
|
function getPublicCopy(pageConfigUserFriendly) {
|
|
@@ -42,15 +42,17 @@ function getPublicCopy(pageConfigUserFriendly) {
|
|
|
42
42
|
_from: p.from
|
|
43
43
|
};
|
|
44
44
|
}
|
|
45
|
-
function
|
|
45
|
+
function getUserFriendlyConfigs_base({ pageConfigGlobalValues, pageConfigValues }) {
|
|
46
46
|
const configValues = { ...pageConfigGlobalValues, ...pageConfigValues };
|
|
47
|
-
return
|
|
47
|
+
return getUserFriendlyConfigs_V1Design({ configValues });
|
|
48
48
|
}
|
|
49
|
-
function
|
|
50
|
-
const pageConfigGlobalUserFriendly =
|
|
49
|
+
function getUserFriendlyConfigsGlobal({ pageConfigGlobalValues }) {
|
|
50
|
+
const pageConfigGlobalUserFriendly = getUserFriendlyConfigs_V1Design({ configValues: pageConfigGlobalValues });
|
|
51
51
|
return getPublicCopy(pageConfigGlobalUserFriendly);
|
|
52
52
|
}
|
|
53
|
-
function
|
|
53
|
+
function getUserFriendlyConfigsPageLazy(pageFiles, // V0.4 design
|
|
54
|
+
pageConfig, // V1 design
|
|
55
|
+
pageConfigGlobal) {
|
|
54
56
|
const config = {};
|
|
55
57
|
const configEntries = {}; // TODO/v1-release: remove
|
|
56
58
|
const exportsAll = {}; // TODO/v1-release: remove
|
|
@@ -75,7 +77,7 @@ function getPageConfigUserFriendly_oldDesign(pageFiles, pageConfig, pageConfigGl
|
|
|
75
77
|
let sources;
|
|
76
78
|
let from;
|
|
77
79
|
if (pageConfig) {
|
|
78
|
-
const res =
|
|
80
|
+
const res = getUserFriendlyConfigs_base({
|
|
79
81
|
pageConfigGlobalValues: pageConfigGlobal.configValues,
|
|
80
82
|
pageConfigValues: pageConfig.configValues
|
|
81
83
|
});
|
|
@@ -95,7 +97,7 @@ function getPageConfigUserFriendly_oldDesign(pageFiles, pageConfig, pageConfigGl
|
|
|
95
97
|
configsComputed: {}
|
|
96
98
|
};
|
|
97
99
|
}
|
|
98
|
-
const pageExports =
|
|
100
|
+
const pageExports = {};
|
|
99
101
|
const exports = {};
|
|
100
102
|
Object.entries(exportsAll).forEach(([exportName, values]) => {
|
|
101
103
|
values.forEach(({ exportValue, _fileType, _isFromDefaultExport }) => {
|
|
@@ -118,13 +120,27 @@ function getPageConfigUserFriendly_oldDesign(pageFiles, pageConfig, pageConfigGl
|
|
|
118
120
|
// TODO/eventually: deprecate/remove every prop below
|
|
119
121
|
configEntries,
|
|
120
122
|
exports,
|
|
121
|
-
exportsAll
|
|
122
|
-
pageExports
|
|
123
|
+
exportsAll
|
|
123
124
|
};
|
|
125
|
+
// TODO/v1-release: remove
|
|
126
|
+
(0, utils_js_1.objectDefineProperty)(pageContextExports, 'pageExports', {
|
|
127
|
+
get: () => {
|
|
128
|
+
// We only show the warning in Node.js because when using Client Routing Vue integration uses `Object.assign(pageContextReactive, pageContext)` which will wrongully trigger the warning. There is no cross-browser way to catch whether the property accessor was initiated by an `Object.assign()` call.
|
|
129
|
+
if (!(0, utils_js_1.isBrowser)()) {
|
|
130
|
+
(0, utils_js_1.assertWarning)(false, 'pageContext.pageExports is outdated, use pageContext.exports instead', {
|
|
131
|
+
onlyOnce: true,
|
|
132
|
+
showStackTrace: true
|
|
133
|
+
});
|
|
134
|
+
}
|
|
135
|
+
return pageExports;
|
|
136
|
+
},
|
|
137
|
+
enumerable: false,
|
|
138
|
+
configurable: true
|
|
139
|
+
});
|
|
124
140
|
return pageContextExports;
|
|
125
141
|
}
|
|
126
142
|
// V1 design
|
|
127
|
-
function
|
|
143
|
+
function getUserFriendlyConfigs_V1Design(pageConfig) {
|
|
128
144
|
const config = {};
|
|
129
145
|
const configEntries = {};
|
|
130
146
|
const exportsAll = {};
|
|
@@ -140,19 +156,30 @@ function getPageConfigUserFriendly_V1Design(pageConfig) {
|
|
|
140
156
|
sources[configName] ?? (sources[configName] = []);
|
|
141
157
|
sources[configName].push(src);
|
|
142
158
|
};
|
|
143
|
-
|
|
144
|
-
const
|
|
145
|
-
const
|
|
146
|
-
const configDefinedAt = (0, getConfigDefinedAt_js_1.getConfigDefinedAtOptional)('Config', configName, configValue.definedAtData);
|
|
147
|
-
config[configName] = config[configName] ?? value;
|
|
159
|
+
const addLegacy = (configName, value, definedAtData) => {
|
|
160
|
+
const configValueFilePathToShowToUser = (0, helpers_js_1.getConfigValueFilePathToShowToUser)(definedAtData);
|
|
161
|
+
const configDefinedAt = (0, getConfigDefinedAt_js_1.getConfigDefinedAtOptional)('Config', configName, definedAtData);
|
|
148
162
|
configEntries[configName] = configEntries[configName] ?? [];
|
|
149
|
-
// Currently each configName has only one entry. Adding an entry for each overriden config value isn't implemented yet. (This is an isomorphic file and it isn't clear whether this can/should be implemented on the client-side. We should load a minimum amount of code on the client-side.)
|
|
150
|
-
(0, utils_js_1.assert)(configEntries[configName].length === 0);
|
|
151
163
|
configEntries[configName].push({
|
|
152
164
|
configValue: value,
|
|
153
165
|
configDefinedAt,
|
|
154
166
|
configDefinedByFile: configValueFilePathToShowToUser
|
|
155
167
|
});
|
|
168
|
+
// TODO/v1-release: remove
|
|
169
|
+
const exportName = configName;
|
|
170
|
+
exportsAll[exportName] = exportsAll[exportName] ?? [];
|
|
171
|
+
exportsAll[exportName].push({
|
|
172
|
+
exportValue: value,
|
|
173
|
+
exportSource: configDefinedAt,
|
|
174
|
+
filePath: configValueFilePathToShowToUser,
|
|
175
|
+
_filePath: configValueFilePathToShowToUser,
|
|
176
|
+
_fileType: null,
|
|
177
|
+
_isFromDefaultExport: null
|
|
178
|
+
});
|
|
179
|
+
};
|
|
180
|
+
Object.entries(pageConfig.configValues).forEach(([configName, configValue]) => {
|
|
181
|
+
const { value } = configValue;
|
|
182
|
+
config[configName] = config[configName] ?? value;
|
|
156
183
|
if (configValue.type === 'standard') {
|
|
157
184
|
const src = {
|
|
158
185
|
type: 'configsStandard',
|
|
@@ -161,6 +188,7 @@ function getPageConfigUserFriendly_V1Design(pageConfig) {
|
|
|
161
188
|
};
|
|
162
189
|
addSrc(src, configName);
|
|
163
190
|
from.configsStandard[configName] = src;
|
|
191
|
+
addLegacy(configName, value, configValue.definedAtData);
|
|
164
192
|
}
|
|
165
193
|
if (configValue.type === 'cumulative') {
|
|
166
194
|
const src = {
|
|
@@ -169,6 +197,7 @@ function getPageConfigUserFriendly_V1Design(pageConfig) {
|
|
|
169
197
|
const definedAtFile = configValue.definedAtData[i];
|
|
170
198
|
(0, utils_js_1.assert)(definedAtFile);
|
|
171
199
|
const definedAt = (0, getConfigDefinedAt_js_1.getDefinedAtString)(definedAtFile, configName);
|
|
200
|
+
addLegacy(configName, value, definedAtFile);
|
|
172
201
|
return {
|
|
173
202
|
value,
|
|
174
203
|
definedAt
|
|
@@ -185,18 +214,8 @@ function getPageConfigUserFriendly_V1Design(pageConfig) {
|
|
|
185
214
|
};
|
|
186
215
|
addSrc(src, configName);
|
|
187
216
|
from.configsComputed[configName] = src;
|
|
217
|
+
addLegacy(configName, value, configValue.definedAtData);
|
|
188
218
|
}
|
|
189
|
-
// TODO/v1-release: remove
|
|
190
|
-
const exportName = configName;
|
|
191
|
-
exportsAll[exportName] = exportsAll[exportName] ?? [];
|
|
192
|
-
exportsAll[exportName].push({
|
|
193
|
-
exportValue: value,
|
|
194
|
-
exportSource: configDefinedAt,
|
|
195
|
-
filePath: configValueFilePathToShowToUser,
|
|
196
|
-
_filePath: configValueFilePathToShowToUser,
|
|
197
|
-
_fileType: null,
|
|
198
|
-
_isFromDefaultExport: null
|
|
199
|
-
});
|
|
200
219
|
});
|
|
201
220
|
return {
|
|
202
221
|
config: config,
|
|
@@ -244,15 +263,3 @@ function getExportValues(pageFile) {
|
|
|
244
263
|
});
|
|
245
264
|
return exportValues;
|
|
246
265
|
}
|
|
247
|
-
// TODO/v1-release: remove
|
|
248
|
-
function createObjectWithDeprecationWarning() {
|
|
249
|
-
return new Proxy({}, {
|
|
250
|
-
get(...args) {
|
|
251
|
-
// We only show the warning in Node.js because when using Client Routing Vue integration uses `Object.assign(pageContextReactive, pageContext)` which will wrongully trigger the warning. There is no cross-browser way to catch whether the property accessor was initiated by an `Object.assign()` call.
|
|
252
|
-
if (!(0, utils_js_1.isBrowser)()) {
|
|
253
|
-
(0, utils_js_1.assertWarning)(false, '`pageContext.pageExports` is outdated. Use `pageContext.exports` instead, see https://vike.dev/exports', { onlyOnce: true, showStackTrace: true });
|
|
254
|
-
}
|
|
255
|
-
return Reflect.get(...args);
|
|
256
|
-
}
|
|
257
|
-
});
|
|
258
|
-
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.prepareGlobalContextForPublicUsage = prepareGlobalContextForPublicUsage;
|
|
4
|
+
const getProxyForPublicUsage_js_1 = require("./getProxyForPublicUsage.js");
|
|
5
|
+
const utils_js_1 = require("./utils.js");
|
|
6
|
+
function prepareGlobalContextForPublicUsage(globalContext) {
|
|
7
|
+
(0, utils_js_1.assert)(globalContext._isOriginalObject); // ensure we preserve the original object reference
|
|
8
|
+
const globalContextPublic = (0, getProxyForPublicUsage_js_1.getProxyForPublicUsage)(globalContext, 'globalContext');
|
|
9
|
+
return globalContextPublic;
|
|
10
|
+
}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.preparePageContextForPublicUsage = preparePageContextForPublicUsage;
|
|
4
|
+
exports.assertPropertyGetters = assertPropertyGetters;
|
|
5
|
+
const utils_js_1 = require("./utils.js");
|
|
6
|
+
const addIs404ToPageProps_js_1 = require("./addIs404ToPageProps.js");
|
|
7
|
+
const prepareGlobalContextForPublicUsage_js_1 = require("./prepareGlobalContextForPublicUsage.js");
|
|
8
|
+
const getProxyForPublicUsage_js_1 = require("./getProxyForPublicUsage.js");
|
|
9
|
+
function preparePageContextForPublicUsage(pageContext) {
|
|
10
|
+
(0, utils_js_1.assert)(pageContext._isOriginalObject); // ensure we preserve the original object reference
|
|
11
|
+
const globalContextPublic = (0, prepareGlobalContextForPublicUsage_js_1.prepareGlobalContextForPublicUsage)(pageContext._globalContext);
|
|
12
|
+
(0, utils_js_1.objectAssign)(pageContext, {
|
|
13
|
+
globalContext: globalContextPublic
|
|
14
|
+
});
|
|
15
|
+
(0, addIs404ToPageProps_js_1.addIs404ToPageProps)(pageContext);
|
|
16
|
+
// TODO/next-major-release: remove
|
|
17
|
+
if (!('_pageId' in pageContext)) {
|
|
18
|
+
Object.defineProperty(pageContext, '_pageId', {
|
|
19
|
+
get() {
|
|
20
|
+
(0, utils_js_1.assertWarning)(false, 'pageContext._pageId has been renamed to pageContext.pageId', {
|
|
21
|
+
showStackTrace: true,
|
|
22
|
+
onlyOnce: true
|
|
23
|
+
});
|
|
24
|
+
return pageContext.pageId;
|
|
25
|
+
},
|
|
26
|
+
enumerable: false
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
// For a more readable `console.log(pageContext)` output
|
|
30
|
+
sortPageContext(pageContext);
|
|
31
|
+
const pageContextPublic = (0, getProxyForPublicUsage_js_1.getProxyForPublicUsageFlat)(pageContext, 'pageContext',
|
|
32
|
+
// We must skip it in the client-side because of the reactivity mechanism of UI frameworks like Solid.
|
|
33
|
+
// - TODO/now: double check whether that's true
|
|
34
|
+
true);
|
|
35
|
+
return pageContextPublic;
|
|
36
|
+
}
|
|
37
|
+
// Sort `pageContext` keys alphabetically, in order to make reading the `console.log(pageContext)` output easier
|
|
38
|
+
function sortPageContext(pageContext) {
|
|
39
|
+
return;
|
|
40
|
+
let descriptors = Object.getOwnPropertyDescriptors(pageContext);
|
|
41
|
+
for (const key of Object.keys(pageContext))
|
|
42
|
+
delete pageContext[key];
|
|
43
|
+
descriptors = Object.fromEntries(Object.entries(descriptors).sort(([key1], [key2]) => (0, utils_js_1.compareString)(key1, key2)));
|
|
44
|
+
Object.defineProperties(pageContext, descriptors);
|
|
45
|
+
}
|
|
46
|
+
function assertPropertyGetters(pageContext) {
|
|
47
|
+
/*
|
|
48
|
+
If the isPropertyGetter() assertions fail then it's most likely because Object.assign() was used instead of `objectAssign()`:
|
|
49
|
+
```js
|
|
50
|
+
const PageContextUrlComputed = getPageContextUrlComputed(pageContext)
|
|
51
|
+
|
|
52
|
+
// ❌ Breaks the property descriptors/getters of pageContext defined by getPageContextUrlComputed() such as pageContext.urlPathname
|
|
53
|
+
Object.assign(pageContext, pageContextUrlComputed)
|
|
54
|
+
|
|
55
|
+
// ❌ Also breaks property descriptors/getters
|
|
56
|
+
const pageContext = { ...pageContextUrlComputed }
|
|
57
|
+
|
|
58
|
+
// ✅ Preserves property descriptors/getters (see objectAssign() implementation)
|
|
59
|
+
objectAssign(pageContext, pageContextUrlComputed)
|
|
60
|
+
```
|
|
61
|
+
*/
|
|
62
|
+
;
|
|
63
|
+
[
|
|
64
|
+
'urlPathname',
|
|
65
|
+
// TODO/v1-release: remove
|
|
66
|
+
'urlParsed',
|
|
67
|
+
// TODO/v1-release: remove
|
|
68
|
+
'url',
|
|
69
|
+
// TODO/v1-release: remove
|
|
70
|
+
'pageExports'
|
|
71
|
+
].forEach((prop) => {
|
|
72
|
+
if (pageContext.prop)
|
|
73
|
+
(0, utils_js_1.assert)((0, utils_js_1.isPropertyGetter)(pageContext, prop));
|
|
74
|
+
});
|
|
75
|
+
}
|
|
@@ -12,7 +12,7 @@ exports.logAbortErrorHandled = logAbortErrorHandled;
|
|
|
12
12
|
exports.getPageContextFromAllRewrites = getPageContextFromAllRewrites;
|
|
13
13
|
exports.AbortRender = AbortRender;
|
|
14
14
|
exports.assertNoInfiniteAbortLoop = assertNoInfiniteAbortLoop;
|
|
15
|
-
const
|
|
15
|
+
const execHook_js_1 = require("../hooks/execHook.js");
|
|
16
16
|
const utils_js_1 = require("./utils.js");
|
|
17
17
|
const picocolors_1 = __importDefault(require("@brillout/picocolors"));
|
|
18
18
|
/**
|
|
@@ -124,7 +124,7 @@ function logAbortErrorHandled(err, isProduction, pageContext) {
|
|
|
124
124
|
(0, utils_js_1.assert)(urlCurrent);
|
|
125
125
|
const abortCall = err._pageContextAbort._abortCall;
|
|
126
126
|
(0, utils_js_1.assert)(abortCall);
|
|
127
|
-
const hookLoc = (0,
|
|
127
|
+
const hookLoc = (0, execHook_js_1.isUserHookError)(err);
|
|
128
128
|
let thrownBy = '';
|
|
129
129
|
if (hookLoc) {
|
|
130
130
|
thrownBy = ` by ${picocolors_1.default.cyan(`${hookLoc.hookName}()`)} hook defined at ${hookLoc.hookFilePath}`;
|
|
@@ -3,11 +3,12 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.executeGuardHook = executeGuardHook;
|
|
4
4
|
const getHook_js_1 = require("../hooks/getHook.js");
|
|
5
5
|
const utils_js_1 = require("./utils.js");
|
|
6
|
-
const
|
|
6
|
+
const execHook_js_1 = require("../hooks/execHook.js");
|
|
7
7
|
const errIntro = 'The guard() hook defined by';
|
|
8
|
-
async function executeGuardHook(pageContext,
|
|
8
|
+
async function executeGuardHook(pageContext, prepareForPublicUsage) {
|
|
9
9
|
let hook;
|
|
10
10
|
if (pageContext._pageFilesAll.length > 0) {
|
|
11
|
+
// TODO/v1-release: remove
|
|
11
12
|
// V0.4 design
|
|
12
13
|
(0, utils_js_1.assert)(pageContext._pageConfigs.length === 0);
|
|
13
14
|
hook = findPageGuard(pageContext.pageId, pageContext._pageFilesAll);
|
|
@@ -18,13 +19,7 @@ async function executeGuardHook(pageContext, prepareForUserConsumption) {
|
|
|
18
19
|
}
|
|
19
20
|
if (!hook)
|
|
20
21
|
return;
|
|
21
|
-
|
|
22
|
-
let pageContextForUserConsumption = pageContext;
|
|
23
|
-
const res = prepareForUserConsumption(pageContext);
|
|
24
|
-
if (res)
|
|
25
|
-
pageContextForUserConsumption = res;
|
|
26
|
-
const hookResult = await (0, executeHook_js_1.executeHook)(() => guard(pageContextForUserConsumption), hook, pageContext);
|
|
27
|
-
(0, utils_js_1.assertUsage)(hookResult === undefined, `${errIntro} ${hook.hookFilePath} returns a value, but guard() shouldn't return any value`);
|
|
22
|
+
await (0, execHook_js_1.execHookSingle)(hook, pageContext, prepareForPublicUsage);
|
|
28
23
|
}
|
|
29
24
|
function findPageGuard(pageId, pageFilesAll) {
|
|
30
25
|
const pageRouteFile = pageFilesAll.find((p) => p.pageId === pageId && p.fileType === '.page.route');
|
|
@@ -8,7 +8,8 @@ const assertPageContextProvidedByUser_js_1 = require("../assertPageContextProvid
|
|
|
8
8
|
const utils_js_1 = require("./utils.js");
|
|
9
9
|
const resolveRouteFunction_js_1 = require("./resolveRouteFunction.js");
|
|
10
10
|
const picocolors_1 = __importDefault(require("@brillout/picocolors"));
|
|
11
|
-
const
|
|
11
|
+
const execHook_js_1 = require("../hooks/execHook.js");
|
|
12
|
+
const preparePageContextForPublicUsage_js_1 = require("../preparePageContextForPublicUsage.js");
|
|
12
13
|
async function executeOnBeforeRouteHook(pageContext) {
|
|
13
14
|
const pageContextFromOnBeforeRouteHook = {};
|
|
14
15
|
if (!pageContext._onBeforeRouteHook)
|
|
@@ -38,10 +39,10 @@ async function executeOnBeforeRouteHook(pageContext) {
|
|
|
38
39
|
return pageContextFromOnBeforeRouteHook;
|
|
39
40
|
}
|
|
40
41
|
async function getPageContextFromHook(onBeforeRouteHook, pageContext) {
|
|
41
|
-
let hookReturn =
|
|
42
|
+
let { hookReturn } = (0, execHook_js_1.execHookSync)(onBeforeRouteHook, pageContext, preparePageContextForPublicUsage_js_1.preparePageContextForPublicUsage);
|
|
42
43
|
(0, resolveRouteFunction_js_1.assertSyncRouting)(hookReturn, `The onBeforeRoute() hook ${onBeforeRouteHook.hookFilePath}`);
|
|
43
44
|
// TODO/v1-release: make executeOnBeforeRouteHook() and route() sync
|
|
44
|
-
hookReturn = await
|
|
45
|
+
hookReturn = await hookReturn;
|
|
45
46
|
const errPrefix = `The onBeforeRoute() hook defined by ${onBeforeRouteHook.hookFilePath}`;
|
|
46
47
|
(0, utils_js_1.assertUsage)(hookReturn === null ||
|
|
47
48
|
hookReturn === undefined ||
|
|
@@ -11,7 +11,6 @@ if ((0, isBrowser_js_1.isBrowser)()) {
|
|
|
11
11
|
(0, assertRoutingType_js_1.assertClientRouting)();
|
|
12
12
|
}
|
|
13
13
|
const utils_js_1 = require("./utils.js");
|
|
14
|
-
const getPageContextUrlComputed_js_1 = require("../getPageContextUrlComputed.js");
|
|
15
14
|
const resolvePrecedence_js_1 = require("./resolvePrecedence.js");
|
|
16
15
|
const resolveRouteString_js_1 = require("./resolveRouteString.js");
|
|
17
16
|
const resolveRouteFunction_js_1 = require("./resolveRouteFunction.js");
|
|
@@ -20,7 +19,6 @@ const debug_js_1 = require("./debug.js");
|
|
|
20
19
|
const picocolors_1 = __importDefault(require("@brillout/picocolors"));
|
|
21
20
|
async function route(pageContext, skipOnBeforeRouteHook) {
|
|
22
21
|
(0, debug_js_1.debug)('Pages routes:', pageContext._pageRoutes);
|
|
23
|
-
(0, getPageContextUrlComputed_js_1.assertPageContextUrl)(pageContext);
|
|
24
22
|
const pageContextFromRoute = {};
|
|
25
23
|
// onBeforeRoute()
|
|
26
24
|
if (!skipOnBeforeRouteHook) {
|
|
@@ -74,8 +72,8 @@ async function route(pageContext, skipOnBeforeRouteHook) {
|
|
|
74
72
|
}
|
|
75
73
|
// Route Function defined in `.page.route.js`
|
|
76
74
|
if (pageRoute.routeType === 'FUNCTION') {
|
|
77
|
-
const { routeFunction,
|
|
78
|
-
const match = await (0, resolveRouteFunction_js_1.resolveRouteFunction)(routeFunction, pageContext,
|
|
75
|
+
const { routeFunction, routeFunctionFilePath } = pageRoute;
|
|
76
|
+
const match = await (0, resolveRouteFunction_js_1.resolveRouteFunction)(routeFunction, pageContext, routeFunctionFilePath);
|
|
79
77
|
if (match) {
|
|
80
78
|
const { routeParams, precedence } = match;
|
|
81
79
|
routeMatches.push({ pageId, precedence, routeParams, routeType });
|
|
@@ -46,6 +46,10 @@ function getPageRoutes(filesystemRoots, pageFilesAll, pageConfigs, allPageIds) {
|
|
|
46
46
|
};
|
|
47
47
|
}
|
|
48
48
|
else {
|
|
49
|
+
const { definedAtData } = configValue;
|
|
50
|
+
(0, utils_js_1.assert)(!(0, utils_js_2.isArray)(definedAtData) && !definedAtData.definedBy);
|
|
51
|
+
const { filePathToShowToUser } = definedAtData;
|
|
52
|
+
(0, utils_js_1.assert)(filePathToShowToUser);
|
|
49
53
|
(0, utils_js_1.assert)((0, utils_js_2.isCallable)(route));
|
|
50
54
|
// TODO/next-major: remove
|
|
51
55
|
if ((0, getConfigValueRuntime_js_1.getConfigValueRuntime)(pageConfig, 'iKnowThePerformanceRisksOfAsyncRouteFunctions', 'boolean'))
|
|
@@ -54,6 +58,7 @@ function getPageRoutes(filesystemRoots, pageFilesAll, pageConfigs, allPageIds) {
|
|
|
54
58
|
pageId,
|
|
55
59
|
comesFromV1PageConfig,
|
|
56
60
|
routeFunction: route,
|
|
61
|
+
routeFunctionFilePath: filePathToShowToUser,
|
|
57
62
|
routeDefinedAtString: definedAtString,
|
|
58
63
|
routeType: 'FUNCTION'
|
|
59
64
|
};
|
|
@@ -127,6 +132,7 @@ function getPageRoutes(filesystemRoots, pageFilesAll, pageConfigs, allPageIds) {
|
|
|
127
132
|
pageId,
|
|
128
133
|
comesFromV1PageConfig,
|
|
129
134
|
routeFunction,
|
|
135
|
+
routeFunctionFilePath: filePath,
|
|
130
136
|
routeDefinedAtString: filePath,
|
|
131
137
|
routeType: 'FUNCTION'
|
|
132
138
|
});
|