vike 0.4.171 → 0.4.172
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/node/plugin/plugins/buildConfig.js +3 -4
- package/dist/cjs/node/plugin/plugins/devConfig/determineOptimizeDeps.js +18 -15
- package/dist/cjs/node/plugin/plugins/devConfig/index.js +2 -1
- package/dist/cjs/node/plugin/plugins/envVars.js +2 -1
- package/dist/cjs/node/plugin/plugins/extractAssetsPlugin.js +1 -1
- package/dist/cjs/node/plugin/plugins/importUserCode/{generateEagerImport.js → addImportStatement.js} +8 -10
- package/dist/cjs/node/plugin/plugins/importUserCode/getVirtualFileImportUserCode.js +0 -1
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/configDefinitionsBuiltIn.js +3 -3
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/loadFileAtConfigTime.js +2 -2
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.js +31 -75
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVirtualFilePageConfigValuesAll.js +4 -43
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVirtualFilePageConfigs.js +9 -50
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/isRuntimeEnvMatch.js +6 -0
- package/dist/cjs/node/plugin/shared/addSsrMiddleware.js +17 -2
- package/dist/cjs/node/prerender/runPrerender.js +35 -15
- package/dist/cjs/node/prerender/utils.js +1 -0
- package/dist/cjs/node/runtime/html/injectAssets/getHtmlTags.js +3 -3
- package/dist/cjs/node/runtime/html/injectAssets/getViteDevScripts.js +2 -1
- package/dist/cjs/node/runtime/html/injectAssets/mergeScriptTags.js +2 -8
- package/dist/cjs/node/runtime/html/renderHtml.js +19 -20
- package/dist/cjs/node/runtime/html/stream.js +9 -9
- package/dist/cjs/node/runtime/renderPage/analyzePage.js +9 -7
- package/dist/cjs/node/runtime/renderPage/createHttpResponseObject/getCacheControl.js +1 -1
- package/dist/cjs/node/runtime/renderPage/executeOnBeforeRenderAndDataHooks.js +2 -2
- package/dist/cjs/node/runtime/renderPage/executeOnRenderHtmlHook.js +8 -8
- package/dist/cjs/node/runtime/renderPage/getHttpResponseBody.js +2 -2
- package/dist/cjs/node/runtime/renderPage/loadUserFilesServerSide.js +4 -5
- package/dist/cjs/node/runtime/renderPage/logErrorHint.js +91 -282
- package/dist/cjs/node/runtime/renderPage/preparePageContextForUserConsumptionServerSide.js +2 -2
- package/dist/cjs/node/runtime/renderPage/renderPageAlreadyRouted.js +30 -10
- package/dist/cjs/node/runtime/renderPage.js +17 -13
- package/dist/cjs/node/runtime/utils.js +2 -0
- package/dist/cjs/node/shared/assertV1Design.js +3 -4
- package/dist/cjs/shared/getPageContext.js +5 -0
- package/dist/cjs/shared/{addUrlComputedProps.js → getPageContextUrlComputed.js} +52 -42
- package/dist/cjs/shared/getPageFiles/analyzeClientSide.js +2 -2
- package/dist/cjs/shared/getPageFiles/getExports.js +49 -1
- package/dist/cjs/shared/getPageFiles/parseGlobResults.js +15 -8
- package/dist/cjs/shared/hooks/executeHook.js +22 -3
- package/dist/cjs/shared/hooks/getHook.js +2 -2
- package/dist/cjs/shared/page-configs/getConfigValue.js +14 -17
- package/dist/cjs/shared/page-configs/getConfigValueBuildTime.js +70 -0
- package/dist/cjs/shared/page-configs/loadConfigValues.js +3 -12
- package/dist/cjs/shared/page-configs/serialize/assertPageConfigsSerialized.js +0 -18
- package/dist/cjs/shared/page-configs/serialize/parsePageConfigs.js +110 -16
- package/dist/cjs/shared/page-configs/serialize/serializeConfigValues.js +198 -0
- package/dist/cjs/shared/route/executeGuardHook.js +1 -1
- package/dist/cjs/shared/route/executeOnBeforeRouteHook.js +1 -1
- package/dist/cjs/shared/route/index.js +2 -2
- package/dist/cjs/shared/route/loadPageRoutes.js +2 -2
- package/dist/cjs/shared/route/resolveRouteFunction.js +2 -2
- package/dist/cjs/shared/sortPageContext.js +4 -8
- package/dist/cjs/shared/utils.js +2 -0
- package/dist/cjs/utils/assert.js +1 -1
- package/dist/cjs/utils/assertNodeVersion.js +1 -1
- package/dist/cjs/utils/changeEnumerable.js +9 -0
- package/dist/cjs/utils/escapeHtml.js +14 -0
- package/dist/cjs/utils/getPropAccessNotation.js +1 -4
- package/dist/cjs/utils/hasProp.js +5 -7
- package/dist/cjs/utils/normalizeHeaders.js +13 -0
- package/dist/cjs/utils/objectAssign.js +1 -1
- package/dist/cjs/utils/objectDefineProperty.js +8 -0
- package/dist/cjs/utils/objectKeys.js +8 -4
- package/dist/cjs/utils/projectInfo.js +1 -1
- package/dist/esm/client/client-routing-runtime/createPageContext.d.ts +6 -4
- package/dist/esm/client/client-routing-runtime/createPageContext.js +4 -3
- package/dist/esm/client/client-routing-runtime/getPageContextFromHooks.js +16 -12
- package/dist/esm/client/client-routing-runtime/installClientRouter.js +18 -10
- package/dist/esm/client/client-routing-runtime/renderPageClientSide.js +3 -3
- package/dist/esm/client/server-routing-runtime/getPageContext.d.ts +4 -4
- 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/executeOnRenderClientHook.js +1 -1
- package/dist/esm/client/shared/getPageContextProxyForUser.d.ts +3 -2
- package/dist/esm/client/shared/getPageContextProxyForUser.js +35 -48
- package/dist/esm/client/shared/loadUserFilesClientSide.js +4 -4
- package/dist/esm/node/plugin/plugins/buildConfig.js +3 -4
- package/dist/esm/node/plugin/plugins/devConfig/determineOptimizeDeps.js +18 -15
- package/dist/esm/node/plugin/plugins/devConfig/index.js +2 -1
- package/dist/esm/node/plugin/plugins/envVars.js +2 -1
- package/dist/esm/node/plugin/plugins/extractAssetsPlugin.js +1 -1
- package/dist/esm/node/plugin/plugins/importUserCode/addImportStatement.d.ts +14 -0
- package/dist/esm/node/plugin/plugins/importUserCode/{generateEagerImport.js → addImportStatement.js} +7 -9
- package/dist/esm/node/plugin/plugins/importUserCode/getVirtualFileImportUserCode.js +0 -1
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/configDefinitionsBuiltIn.d.ts +2 -1
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/configDefinitionsBuiltIn.js +3 -3
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/loadFileAtConfigTime.js +2 -2
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.js +31 -75
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVirtualFilePageConfigValuesAll.js +4 -43
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVirtualFilePageConfigs.js +9 -50
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/isRuntimeEnvMatch.d.ts +1 -0
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/isRuntimeEnvMatch.js +6 -0
- package/dist/esm/node/plugin/shared/addSsrMiddleware.js +14 -2
- package/dist/esm/node/prerender/runPrerender.js +37 -17
- package/dist/esm/node/prerender/utils.d.ts +1 -0
- package/dist/esm/node/prerender/utils.js +1 -0
- package/dist/esm/node/runtime/html/injectAssets/getHtmlTags.js +3 -3
- package/dist/esm/node/runtime/html/injectAssets/getViteDevScripts.js +3 -2
- package/dist/esm/node/runtime/html/injectAssets/mergeScriptTags.d.ts +1 -1
- package/dist/esm/node/runtime/html/injectAssets/mergeScriptTags.js +2 -8
- package/dist/esm/node/runtime/html/renderHtml.js +19 -20
- package/dist/esm/node/runtime/html/stream.d.ts +1 -1
- package/dist/esm/node/runtime/html/stream.js +9 -9
- package/dist/esm/node/runtime/renderPage/analyzePage.js +9 -7
- package/dist/esm/node/runtime/renderPage/createHttpResponseObject/getCacheControl.js +2 -2
- package/dist/esm/node/runtime/renderPage/executeOnBeforeRenderAndDataHooks.js +2 -2
- package/dist/esm/node/runtime/renderPage/executeOnRenderHtmlHook.js +8 -8
- package/dist/esm/node/runtime/renderPage/getHttpResponseBody.js +2 -2
- package/dist/esm/node/runtime/renderPage/loadUserFilesServerSide.d.ts +1 -6
- package/dist/esm/node/runtime/renderPage/loadUserFilesServerSide.js +4 -5
- package/dist/esm/node/runtime/renderPage/logErrorHint.d.ts +2 -6
- package/dist/esm/node/runtime/renderPage/logErrorHint.js +92 -283
- package/dist/esm/node/runtime/renderPage/preparePageContextForUserConsumptionServerSide.d.ts +2 -2
- package/dist/esm/node/runtime/renderPage/preparePageContextForUserConsumptionServerSide.js +2 -2
- package/dist/esm/node/runtime/renderPage/renderPageAlreadyRouted.d.ts +65 -39
- package/dist/esm/node/runtime/renderPage/renderPageAlreadyRouted.js +31 -11
- package/dist/esm/node/runtime/renderPage.js +17 -13
- package/dist/esm/node/runtime/utils.d.ts +2 -0
- package/dist/esm/node/runtime/utils.js +2 -0
- package/dist/esm/node/shared/assertV1Design.d.ts +2 -2
- package/dist/esm/node/shared/assertV1Design.js +3 -4
- package/dist/esm/shared/VikeNamespace.d.ts +9 -0
- package/dist/esm/shared/getPageContext.d.ts +1 -0
- package/dist/esm/shared/getPageContext.js +1 -0
- package/dist/esm/shared/{addUrlComputedProps.d.ts → getPageContextUrlComputed.d.ts} +23 -21
- package/dist/esm/shared/{addUrlComputedProps.js → getPageContextUrlComputed.js} +52 -42
- package/dist/esm/shared/getPageFiles/analyzeClientSide.js +3 -3
- package/dist/esm/shared/getPageFiles/getExports.d.ts +36 -0
- package/dist/esm/shared/getPageFiles/getExports.js +50 -2
- package/dist/esm/shared/getPageFiles/parseGlobResults.js +14 -7
- package/dist/esm/shared/hooks/executeHook.d.ts +10 -1
- package/dist/esm/shared/hooks/executeHook.js +21 -2
- package/dist/esm/shared/hooks/getHook.d.ts +2 -2
- package/dist/esm/shared/hooks/getHook.js +3 -3
- package/dist/esm/shared/page-configs/Config/PageContextConfig.d.ts +2 -2
- package/dist/esm/shared/page-configs/PageConfig.d.ts +14 -8
- package/dist/esm/shared/page-configs/getConfigValue.d.ts +12 -12
- package/dist/esm/shared/page-configs/getConfigValue.js +13 -16
- package/dist/esm/shared/page-configs/getConfigValueBuildTime.d.ts +9 -0
- package/dist/esm/shared/page-configs/getConfigValueBuildTime.js +67 -0
- package/dist/esm/shared/page-configs/loadConfigValues.js +3 -12
- package/dist/esm/shared/page-configs/serialize/PageConfigSerialized.d.ts +17 -21
- package/dist/esm/shared/page-configs/serialize/assertPageConfigsSerialized.d.ts +1 -5
- package/dist/esm/shared/page-configs/serialize/assertPageConfigsSerialized.js +1 -16
- package/dist/esm/shared/page-configs/serialize/parsePageConfigs.d.ts +4 -1
- package/dist/esm/shared/page-configs/serialize/parsePageConfigs.js +109 -15
- package/dist/esm/shared/page-configs/serialize/serializeConfigValues.d.ts +5 -0
- package/dist/esm/shared/page-configs/serialize/serializeConfigValues.js +192 -0
- package/dist/esm/shared/route/executeGuardHook.js +1 -1
- package/dist/esm/shared/route/executeOnBeforeRouteHook.js +1 -1
- package/dist/esm/shared/route/index.d.ts +3 -3
- package/dist/esm/shared/route/index.js +2 -2
- package/dist/esm/shared/route/loadPageRoutes.js +3 -3
- package/dist/esm/shared/route/resolveRouteFunction.d.ts +2 -2
- package/dist/esm/shared/route/resolveRouteFunction.js +2 -2
- package/dist/esm/shared/sortPageContext.js +4 -8
- package/dist/esm/shared/types.d.ts +32 -6
- 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/assert.js +1 -1
- package/dist/esm/utils/assertNodeVersion.js +1 -1
- package/dist/esm/utils/changeEnumerable.d.ts +2 -0
- package/dist/esm/utils/changeEnumerable.js +5 -0
- package/dist/esm/utils/escapeHtml.d.ts +1 -0
- package/dist/esm/utils/escapeHtml.js +10 -0
- package/dist/esm/utils/getPropAccessNotation.d.ts +1 -2
- package/dist/esm/utils/getPropAccessNotation.js +2 -6
- package/dist/esm/utils/hasProp.d.ts +4 -13
- package/dist/esm/utils/hasProp.js +5 -7
- package/dist/esm/utils/normalizeHeaders.d.ts +1 -0
- package/dist/esm/utils/normalizeHeaders.js +9 -0
- package/dist/esm/utils/objectAssign.js +1 -1
- package/dist/esm/utils/objectDefineProperty.d.ts +4 -0
- package/dist/esm/utils/objectDefineProperty.js +4 -0
- package/dist/esm/utils/objectKeys.d.ts +1 -3
- package/dist/esm/utils/objectKeys.js +8 -4
- package/dist/esm/utils/projectInfo.d.ts +2 -2
- package/dist/esm/utils/projectInfo.js +1 -1
- package/package.json +21 -12
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getConfigValuesSerialized.js +0 -76
- package/dist/cjs/node/plugin/shared/getConfigValueSourcesNotOverriden.js +0 -14
- package/dist/cjs/node/shared/getClientEntry.js +0 -12
- package/dist/cjs/shared/page-configs/serialize/parseConfigValuesImported.js +0 -85
- package/dist/cjs/shared/page-configs/serialize/parseConfigValuesSerialized.js +0 -24
- package/dist/cjs/shared/page-configs/serialize/serializeConfigValue.js +0 -50
- package/dist/esm/node/plugin/plugins/importUserCode/generateEagerImport.d.ts +0 -16
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getConfigValuesSerialized.d.ts +0 -5
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getConfigValuesSerialized.js +0 -70
- package/dist/esm/node/plugin/shared/getConfigValueSourcesNotOverriden.d.ts +0 -5
- package/dist/esm/node/plugin/shared/getConfigValueSourcesNotOverriden.js +0 -11
- package/dist/esm/node/shared/getClientEntry.d.ts +0 -3
- package/dist/esm/node/shared/getClientEntry.js +0 -9
- package/dist/esm/shared/page-configs/serialize/parseConfigValuesImported.d.ts +0 -4
- package/dist/esm/shared/page-configs/serialize/parseConfigValuesImported.js +0 -82
- package/dist/esm/shared/page-configs/serialize/parseConfigValuesSerialized.d.ts +0 -4
- package/dist/esm/shared/page-configs/serialize/parseConfigValuesSerialized.js +0 -21
- package/dist/esm/shared/page-configs/serialize/serializeConfigValue.d.ts +0 -8
- package/dist/esm/shared/page-configs/serialize/serializeConfigValue.js +0 -47
|
@@ -0,0 +1,192 @@
|
|
|
1
|
+
export { serializeConfigValues };
|
|
2
|
+
import { assertIsNotProductionRuntime } from '../../../utils/assertIsNotProductionRuntime.js';
|
|
3
|
+
import { assert, assertUsage, getPropAccessNotation } from '../../../node/plugin/utils.js';
|
|
4
|
+
import { addImportStatement } from '../../../node/plugin/plugins/importUserCode/addImportStatement.js';
|
|
5
|
+
import { parsePointerImportData } from '../../../node/plugin/plugins/importUserCode/v1-design/getVikeConfig/transformFileImports.js';
|
|
6
|
+
import { getConfigValueFilePathToShowToUser } from '../helpers.js';
|
|
7
|
+
import { stringify } from '@brillout/json-serializer/stringify';
|
|
8
|
+
import pc from '@brillout/picocolors';
|
|
9
|
+
const REPLACE_ME_BEFORE = '__VIKE__REPLACE_ME_BEFORE__';
|
|
10
|
+
const REPLACE_ME_AFTER = '__VIKE__REPLACE_ME_AFTER__';
|
|
11
|
+
// This file is never loaded on the client-side but we save it under the vike/shared/ directory in order to collocate it with parsePageConfigs()
|
|
12
|
+
// - vike/shared/page-configs/serialize/parsePageConfigs.ts
|
|
13
|
+
// - parsePageConfigs() is loaded on both the client- and server-side.
|
|
14
|
+
assertIsNotProductionRuntime();
|
|
15
|
+
function serializeConfigValues(pageConfig, importStatements, isEnvMatch, tabspace) {
|
|
16
|
+
const lines = [];
|
|
17
|
+
tabspace += ' ';
|
|
18
|
+
Object.entries(pageConfig.configValuesComputed ?? {}).forEach(([configName, configValuesComputed]) => {
|
|
19
|
+
if (!isEnvMatch(configValuesComputed.configEnv))
|
|
20
|
+
return;
|
|
21
|
+
// Is there a use case for overriding computed values? If yes, then configValeSources has higher precedence
|
|
22
|
+
if (pageConfig.configValueSources[configName])
|
|
23
|
+
return;
|
|
24
|
+
const valueData = serializeWithJson(configValuesComputed.value, configName, null, importStatements);
|
|
25
|
+
const configValueBase = {
|
|
26
|
+
type: 'computed',
|
|
27
|
+
definedAtData: null
|
|
28
|
+
};
|
|
29
|
+
serializeConfigValue(configValueBase, valueData, configName, lines, tabspace);
|
|
30
|
+
});
|
|
31
|
+
Object.entries(pageConfig.configValueSources).forEach(([configName, sources]) => {
|
|
32
|
+
const configDef = pageConfig.configDefinitions[configName];
|
|
33
|
+
assert(configDef);
|
|
34
|
+
if (!configDef.cumulative) {
|
|
35
|
+
const configValueSource = sources[0];
|
|
36
|
+
assert(configValueSource);
|
|
37
|
+
assert(sources.slice(1).every((s) => s.isOverriden === true));
|
|
38
|
+
if (!isEnvMatch(configValueSource.configEnv))
|
|
39
|
+
return;
|
|
40
|
+
const { valueData, definedAtFile } = serializeConfigValueSource(configValueSource, configName, importStatements);
|
|
41
|
+
const configValueBase = {
|
|
42
|
+
type: 'standard',
|
|
43
|
+
definedAtData: definedAtFile
|
|
44
|
+
};
|
|
45
|
+
serializeConfigValue(configValueBase, valueData, configName, lines, tabspace);
|
|
46
|
+
}
|
|
47
|
+
else {
|
|
48
|
+
const valueDataList = [];
|
|
49
|
+
const definedAtData = [];
|
|
50
|
+
sources
|
|
51
|
+
.filter((s) => !s.isOverriden)
|
|
52
|
+
.forEach((configValueSource) => {
|
|
53
|
+
if (!isEnvMatch(configValueSource.configEnv))
|
|
54
|
+
return;
|
|
55
|
+
const { valueData, definedAtFile } = serializeConfigValueSource(configValueSource, configName, importStatements);
|
|
56
|
+
valueDataList.push(valueData);
|
|
57
|
+
definedAtData.push(definedAtFile);
|
|
58
|
+
});
|
|
59
|
+
if (valueDataList.length === 0)
|
|
60
|
+
return;
|
|
61
|
+
const configValueBase = {
|
|
62
|
+
type: 'cumulative',
|
|
63
|
+
definedAtData
|
|
64
|
+
};
|
|
65
|
+
serializeConfigValue(configValueBase, valueDataList, configName, lines, tabspace);
|
|
66
|
+
}
|
|
67
|
+
});
|
|
68
|
+
return lines;
|
|
69
|
+
}
|
|
70
|
+
function serializeConfigValueSource(configValueSource, configName, importStatements) {
|
|
71
|
+
assert(configValueSource.isOverriden === false);
|
|
72
|
+
let valueData;
|
|
73
|
+
if ('value' in configValueSource) {
|
|
74
|
+
valueData = serializeWithJson(configValueSource.value, configName, configValueSource.definedAtFilePath, importStatements);
|
|
75
|
+
}
|
|
76
|
+
else {
|
|
77
|
+
valueData = serializeWithImport(configValueSource, importStatements);
|
|
78
|
+
}
|
|
79
|
+
const definedAtFile = {
|
|
80
|
+
filePathToShowToUser: configValueSource.definedAtFilePath.filePathToShowToUser,
|
|
81
|
+
fileExportPathToShowToUser: configValueSource.definedAtFilePath.fileExportPathToShowToUser
|
|
82
|
+
};
|
|
83
|
+
return { valueData, definedAtFile };
|
|
84
|
+
}
|
|
85
|
+
function serializeConfigValue(configValueBase, valueData, configName, lines, tabspace) {
|
|
86
|
+
lineAdd(`[${JSON.stringify(configName)}]: {`);
|
|
87
|
+
{
|
|
88
|
+
tab();
|
|
89
|
+
lineAdd(`type: "${configValueBase.type}",`);
|
|
90
|
+
lineAdd(`definedAtData: ${JSON.stringify(configValueBase.definedAtData)},`);
|
|
91
|
+
lineAdd(`valueSerialized:`);
|
|
92
|
+
if (!Array.isArray(valueData)) {
|
|
93
|
+
serializeValueData(valueData);
|
|
94
|
+
}
|
|
95
|
+
else {
|
|
96
|
+
lineAppend(' [');
|
|
97
|
+
valueData.forEach(serializeValueData);
|
|
98
|
+
lineAppend(` ],`);
|
|
99
|
+
}
|
|
100
|
+
untab();
|
|
101
|
+
}
|
|
102
|
+
lineAdd('},');
|
|
103
|
+
return;
|
|
104
|
+
function serializeValueData(valueData) {
|
|
105
|
+
lineAppend(` {`);
|
|
106
|
+
tab();
|
|
107
|
+
lineAdd(`type: "${valueData.type}",`);
|
|
108
|
+
const valueProp = valueData.type !== 'plus-file' ? 'value' : 'exportValues';
|
|
109
|
+
lineAdd(`${valueProp}: ${valueData.valueAsJsCode},`);
|
|
110
|
+
untab();
|
|
111
|
+
lineAdd(`},`);
|
|
112
|
+
}
|
|
113
|
+
function lineAppend(str) {
|
|
114
|
+
const i = lines.length - 1;
|
|
115
|
+
lines[i] = lines[i] += str;
|
|
116
|
+
}
|
|
117
|
+
function lineAdd(str) {
|
|
118
|
+
lines.push(`${tabspace}${str}`);
|
|
119
|
+
}
|
|
120
|
+
function tab() {
|
|
121
|
+
tabspace += ' ';
|
|
122
|
+
}
|
|
123
|
+
function untab() {
|
|
124
|
+
tabspace = tabspace.slice(2);
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
function serializeWithImport(configValueSource, importStatements) {
|
|
128
|
+
assert(!configValueSource.valueIsFilePath);
|
|
129
|
+
const { valueIsImportedAtRuntime, valueIsDefinedByPlusFile, definedAtFilePath } = configValueSource;
|
|
130
|
+
assert(valueIsImportedAtRuntime);
|
|
131
|
+
const { filePathAbsoluteVite, fileExportName } = definedAtFilePath;
|
|
132
|
+
if (valueIsDefinedByPlusFile)
|
|
133
|
+
assert(fileExportName === undefined);
|
|
134
|
+
const { importName } = addImportStatement(importStatements, filePathAbsoluteVite, fileExportName || '*');
|
|
135
|
+
return {
|
|
136
|
+
type: valueIsDefinedByPlusFile ? 'plus-file' : 'pointer-import',
|
|
137
|
+
valueAsJsCode: importName
|
|
138
|
+
};
|
|
139
|
+
}
|
|
140
|
+
function serializeWithJson(value, configName, definedAtData, importStatements) {
|
|
141
|
+
const valueAsJsCode = valueToJson(value, configName, definedAtData, importStatements);
|
|
142
|
+
return {
|
|
143
|
+
type: 'js-serialized',
|
|
144
|
+
valueAsJsCode
|
|
145
|
+
};
|
|
146
|
+
}
|
|
147
|
+
function valueToJson(value, configName, definedAtData, importStatements) {
|
|
148
|
+
const valueName = `config${getPropAccessNotation(configName)}`;
|
|
149
|
+
let configValueSerialized;
|
|
150
|
+
try {
|
|
151
|
+
configValueSerialized = stringify(value, {
|
|
152
|
+
valueName,
|
|
153
|
+
forbidReactElements: true,
|
|
154
|
+
replacer(_, value) {
|
|
155
|
+
if (typeof value === 'string') {
|
|
156
|
+
const importData = parsePointerImportData(value);
|
|
157
|
+
if (importData) {
|
|
158
|
+
const { importName } = addImportStatement(importStatements, importData.importPath, importData.exportName);
|
|
159
|
+
const replacement = [REPLACE_ME_BEFORE, importName, REPLACE_ME_AFTER].join('');
|
|
160
|
+
return { replacement };
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
});
|
|
165
|
+
}
|
|
166
|
+
catch (err) {
|
|
167
|
+
logJsonSerializeError(err, configName, definedAtData);
|
|
168
|
+
assert(false);
|
|
169
|
+
}
|
|
170
|
+
configValueSerialized = configValueSerialized.replaceAll(`"${REPLACE_ME_BEFORE}`, '');
|
|
171
|
+
configValueSerialized = configValueSerialized.replaceAll(`${REPLACE_ME_AFTER}"`, '');
|
|
172
|
+
assert(!configValueSerialized.includes(REPLACE_ME_BEFORE));
|
|
173
|
+
assert(!configValueSerialized.includes(REPLACE_ME_AFTER));
|
|
174
|
+
return configValueSerialized;
|
|
175
|
+
}
|
|
176
|
+
function logJsonSerializeError(err, configName, definedAtData) {
|
|
177
|
+
/*
|
|
178
|
+
// import { isJsonSerializerError } from '@brillout/json-serializer/stringify'
|
|
179
|
+
let serializationErrMsg = ''
|
|
180
|
+
if (isJsonSerializerError(err)) {
|
|
181
|
+
serializationErrMsg = err.messageCore
|
|
182
|
+
} else {
|
|
183
|
+
// When a property getter throws an error
|
|
184
|
+
console.error('Serialization error:')
|
|
185
|
+
console.error(err)
|
|
186
|
+
serializationErrMsg = 'see serialization error printed above'
|
|
187
|
+
}
|
|
188
|
+
//*/
|
|
189
|
+
const configValueFilePathToShowToUser = getConfigValueFilePathToShowToUser(definedAtData);
|
|
190
|
+
assert(configValueFilePathToShowToUser);
|
|
191
|
+
assertUsage(false, `${pc.cyan(configName)} defined by ${configValueFilePathToShowToUser} must be defined over a so-called "pointer import", see https://vike.dev/config#pointer-imports`);
|
|
192
|
+
}
|
|
@@ -21,7 +21,7 @@ async function executeGuardHook(pageContext, prepareForUserConsumption) {
|
|
|
21
21
|
const res = prepareForUserConsumption(pageContext);
|
|
22
22
|
if (res)
|
|
23
23
|
pageContextForUserConsumption = res;
|
|
24
|
-
const hookResult = await executeHook(() => guard(pageContextForUserConsumption), hook);
|
|
24
|
+
const hookResult = await executeHook(() => guard(pageContextForUserConsumption), hook, pageContext);
|
|
25
25
|
assertUsage(hookResult === undefined, `${errIntro} ${hook.hookFilePath} returns a value, but guard() shouldn't return any value`);
|
|
26
26
|
}
|
|
27
27
|
function findPageGuard(pageId, pageFilesAll) {
|
|
@@ -36,7 +36,7 @@ async function getPageContextFromHook(onBeforeRouteHook, pageContext) {
|
|
|
36
36
|
let hookReturn = onBeforeRouteHook.hookFn(pageContext);
|
|
37
37
|
assertSyncRouting(hookReturn, `The onBeforeRoute() hook ${onBeforeRouteHook.hookFilePath}`);
|
|
38
38
|
// TODO/v1-release: make executeOnBeforeRouteHook() and route() sync
|
|
39
|
-
hookReturn = await executeHook(() => hookReturn, onBeforeRouteHook);
|
|
39
|
+
hookReturn = await executeHook(() => hookReturn, onBeforeRouteHook, pageContext);
|
|
40
40
|
const errPrefix = `The onBeforeRoute() hook defined by ${onBeforeRouteHook.hookFilePath}`;
|
|
41
41
|
assertUsage(hookReturn === null ||
|
|
42
42
|
hookReturn === undefined ||
|
|
@@ -4,18 +4,18 @@ export type { PageContextFromRoute };
|
|
|
4
4
|
export type { PageRoutes };
|
|
5
5
|
export type { RouteMatches };
|
|
6
6
|
import type { PageFile } from '../getPageFiles.js';
|
|
7
|
-
import {
|
|
7
|
+
import { type PageContextUrlInternal, type PageContextUrlSource } from '../getPageContextUrlComputed.js';
|
|
8
8
|
import type { PageRoutes, RouteType } from './loadPageRoutes.js';
|
|
9
9
|
import type { PageConfigRuntime, PageConfigGlobalRuntime } from '../page-configs/PageConfig.js';
|
|
10
10
|
import type { Hook } from '../hooks/getHook.js';
|
|
11
|
-
type PageContextForRoute =
|
|
11
|
+
type PageContextForRoute = PageContextUrlInternal & {
|
|
12
12
|
_pageFilesAll: PageFile[];
|
|
13
13
|
_pageConfigs: PageConfigRuntime[];
|
|
14
14
|
_allPageIds: string[];
|
|
15
15
|
_pageConfigGlobal: PageConfigGlobalRuntime;
|
|
16
16
|
_pageRoutes: PageRoutes;
|
|
17
17
|
_onBeforeRouteHook: Hook | null;
|
|
18
|
-
} &
|
|
18
|
+
} & PageContextUrlSource;
|
|
19
19
|
type PageContextFromRoute = {
|
|
20
20
|
_pageId: string | null;
|
|
21
21
|
routeParams: Record<string, string>;
|
|
@@ -6,7 +6,7 @@ if (isBrowser()) {
|
|
|
6
6
|
assertClientRouting();
|
|
7
7
|
}
|
|
8
8
|
import { assert, assertUsage, isPlainObject, objectAssign } from './utils.js';
|
|
9
|
-
import {
|
|
9
|
+
import { assertPageContextUrl } from '../getPageContextUrlComputed.js';
|
|
10
10
|
import { resolvePrecendence } from './resolvePrecedence.js';
|
|
11
11
|
import { resolveRouteString } from './resolveRouteString.js';
|
|
12
12
|
import { resolveRouteFunction } from './resolveRouteFunction.js';
|
|
@@ -15,7 +15,7 @@ import { debug } from './debug.js';
|
|
|
15
15
|
import pc from '@brillout/picocolors';
|
|
16
16
|
async function route(pageContextForRoute) {
|
|
17
17
|
debug('Pages routes:', pageContextForRoute._pageRoutes);
|
|
18
|
-
|
|
18
|
+
assertPageContextUrl(pageContextForRoute);
|
|
19
19
|
const pageContextFromRoute = {};
|
|
20
20
|
// onBeforeRoute()
|
|
21
21
|
const pageContextFromOnBeforeRouteHook = await executeOnBeforeRouteHook(pageContextForRoute);
|
|
@@ -3,7 +3,7 @@ import { isErrorPageId } from '../error-page.js';
|
|
|
3
3
|
import { assert, assertUsage, hasProp, slice } from './utils.js';
|
|
4
4
|
import { deduceRouteStringFromFilesystemPath } from './deduceRouteStringFromFilesystemPath.js';
|
|
5
5
|
import { isCallable } from '../utils.js';
|
|
6
|
-
import {
|
|
6
|
+
import { getConfigValueRuntime } from '../page-configs/getConfigValue.js';
|
|
7
7
|
import { getDefinedAtString } from '../page-configs/getConfigDefinedAt.js';
|
|
8
8
|
import { warnDeprecatedAllowKey } from './resolveRouteFunction.js';
|
|
9
9
|
import { getHookFromPageConfigGlobal, getHookTimeoutDefault } from '../hooks/getHook.js';
|
|
@@ -28,7 +28,7 @@ function getPageRoutes(filesystemRoots, pageFilesAll, pageConfigs, allPageIds) {
|
|
|
28
28
|
let pageRoute = null;
|
|
29
29
|
{
|
|
30
30
|
const configName = 'route';
|
|
31
|
-
const configValue =
|
|
31
|
+
const configValue = getConfigValueRuntime(pageConfig, configName);
|
|
32
32
|
if (configValue) {
|
|
33
33
|
const route = configValue.value;
|
|
34
34
|
assert(configValue.definedAtData);
|
|
@@ -44,7 +44,7 @@ function getPageRoutes(filesystemRoots, pageFilesAll, pageConfigs, allPageIds) {
|
|
|
44
44
|
}
|
|
45
45
|
else {
|
|
46
46
|
assert(isCallable(route));
|
|
47
|
-
if (
|
|
47
|
+
if (getConfigValueRuntime(pageConfig, 'iKnowThePerformanceRisksOfAsyncRouteFunctions', 'boolean'))
|
|
48
48
|
warnDeprecatedAllowKey();
|
|
49
49
|
pageRoute = {
|
|
50
50
|
pageId,
|
|
@@ -2,8 +2,8 @@ export { resolveRouteFunction };
|
|
|
2
2
|
export { assertRouteParams };
|
|
3
3
|
export { assertSyncRouting };
|
|
4
4
|
export { warnDeprecatedAllowKey };
|
|
5
|
-
import {
|
|
6
|
-
declare function resolveRouteFunction(routeFunction: Function, pageContext:
|
|
5
|
+
import { PageContextUrlInternal } from '../getPageContextUrlComputed.js';
|
|
6
|
+
declare function resolveRouteFunction(routeFunction: Function, pageContext: PageContextUrlInternal, routeDefinedAtString: string): Promise<null | {
|
|
7
7
|
precedence: number | null;
|
|
8
8
|
routeParams: Record<string, string>;
|
|
9
9
|
}>;
|
|
@@ -2,11 +2,11 @@ export { resolveRouteFunction };
|
|
|
2
2
|
export { assertRouteParams };
|
|
3
3
|
export { assertSyncRouting };
|
|
4
4
|
export { warnDeprecatedAllowKey };
|
|
5
|
-
import {
|
|
5
|
+
import { assertPageContextUrl } from '../getPageContextUrlComputed.js';
|
|
6
6
|
import { assert, assertUsage, assertWarning, hasProp, isPlainObject, isPromise } from './utils.js';
|
|
7
7
|
import pc from '@brillout/picocolors';
|
|
8
8
|
async function resolveRouteFunction(routeFunction, pageContext, routeDefinedAtString) {
|
|
9
|
-
|
|
9
|
+
assertPageContextUrl(pageContext);
|
|
10
10
|
let result = routeFunction(pageContext);
|
|
11
11
|
assertSyncRouting(result, `The Route Function ${routeDefinedAtString}`);
|
|
12
12
|
// TODO/v1-release: make resolveRouteFunction() and route() sync
|
|
@@ -2,13 +2,9 @@ import { compareString } from './utils.js';
|
|
|
2
2
|
export { sortPageContext };
|
|
3
3
|
// Sort `pageContext` keys alphabetically, in order to make reading `console.log(pageContext)` easier
|
|
4
4
|
function sortPageContext(pageContext) {
|
|
5
|
-
|
|
6
|
-
for (const key
|
|
5
|
+
let descriptors = Object.getOwnPropertyDescriptors(pageContext);
|
|
6
|
+
for (const key of Object.keys(pageContext))
|
|
7
7
|
delete pageContext[key];
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
.sort(([key1], [key2]) => compareString(key1, key2))
|
|
11
|
-
.forEach(([key, val]) => {
|
|
12
|
-
pageContext[key] = val;
|
|
13
|
-
});
|
|
8
|
+
descriptors = Object.fromEntries(Object.entries(descriptors).sort(([key1], [key2]) => compareString(key1, key2)));
|
|
9
|
+
Object.defineProperties(pageContext, descriptors);
|
|
14
10
|
}
|
|
@@ -7,8 +7,8 @@ export { PageContextBuiltInServerInternal };
|
|
|
7
7
|
export { PageContextBuiltInServer_deprecated as PageContextBuiltInServer };
|
|
8
8
|
export { PageContextBuiltInClientWithClientRouting_deprecated as PageContextBuiltInClientWithClientRouting };
|
|
9
9
|
export { PageContextBuiltInClientWithServerRouting_deprecated as PageContextBuiltInClientWithServerRouting };
|
|
10
|
-
import type {
|
|
11
|
-
import type { ConfigEntries, ExportsAll } from './getPageFiles/getExports.js';
|
|
10
|
+
import type { PageContextUrlInternal, PageContextUrlClient, PageContextUrlServer } from './getPageContextUrlComputed.js';
|
|
11
|
+
import type { ConfigEntries, ExportsAll, From, Source, Sources } from './getPageFiles/getExports.js';
|
|
12
12
|
import type { Config } from './page-configs/Config.js';
|
|
13
13
|
import type { PageContextConfig } from './page-configs/Config/PageContextConfig.js';
|
|
14
14
|
import type { AbortStatusCode } from './route/abort.js';
|
|
@@ -59,6 +59,26 @@ type PageContextBuiltInCommon<Data> = {
|
|
|
59
59
|
* https://vike.dev/renderPage
|
|
60
60
|
*/
|
|
61
61
|
urlOriginal: string;
|
|
62
|
+
/**
|
|
63
|
+
* The HTTP Headers of the incoming HTTP Request.
|
|
64
|
+
*
|
|
65
|
+
* As a string object normalized by Vike.
|
|
66
|
+
*
|
|
67
|
+
* See also:
|
|
68
|
+
* - https://vike.dev/headers
|
|
69
|
+
* - `pageContext.headersOriginal`
|
|
70
|
+
*/
|
|
71
|
+
headers: Record<string, string> | null;
|
|
72
|
+
/**
|
|
73
|
+
* The HTTP Headers of the incoming HTTP Request.
|
|
74
|
+
*
|
|
75
|
+
* The original object provided by the server.
|
|
76
|
+
*
|
|
77
|
+
* See also:
|
|
78
|
+
* - https://vike.dev/headers
|
|
79
|
+
* - `pageContext.headers`
|
|
80
|
+
*/
|
|
81
|
+
headersOriginal?: unknown;
|
|
62
82
|
/** If an error occurs, whether the error is a `404 Page Not Found`.
|
|
63
83
|
*
|
|
64
84
|
* https://vike.dev/error-page
|
|
@@ -88,13 +108,19 @@ type PageContextBuiltInCommon<Data> = {
|
|
|
88
108
|
* https://vike.dev/errors
|
|
89
109
|
*/
|
|
90
110
|
errorWhileRendering?: unknown;
|
|
111
|
+
/** @experimental https://github.com/vikejs/vike/issues/1268 */
|
|
112
|
+
from: From;
|
|
113
|
+
/** @experimental https://github.com/vikejs/vike/issues/1268 */
|
|
114
|
+
source: Source;
|
|
115
|
+
/** @experimental https://github.com/vikejs/vike/issues/1268 */
|
|
116
|
+
sources: Sources;
|
|
91
117
|
/** @deprecated */
|
|
92
118
|
url: string;
|
|
93
119
|
/** @deprecated */
|
|
94
120
|
pageExports: Record<string, unknown>;
|
|
95
121
|
};
|
|
96
|
-
type PageContextBuiltInServer<Data> = PageContextBuiltInCommon<Data> &
|
|
97
|
-
type PageContextBuiltInClientWithClientRouting<Data> = Partial<PageContextBuiltInCommon<Data>> & Pick<PageContextBuiltInCommon<Data>, 'Page' | 'pageExports' | 'config' | 'configEntries' | 'exports' | 'exportsAll' | 'abortReason' | 'data'> & {
|
|
122
|
+
type PageContextBuiltInServer<Data> = PageContextBuiltInCommon<Data> & PageContextUrlServer;
|
|
123
|
+
type PageContextBuiltInClientWithClientRouting<Data> = Partial<PageContextBuiltInCommon<Data>> & Pick<PageContextBuiltInCommon<Data>, 'Page' | 'pageExports' | 'config' | 'configEntries' | 'exports' | 'exportsAll' | 'abortReason' | 'data' | 'source' | 'sources' | 'from'> & {
|
|
98
124
|
/** Whether the current page is already rendered to HTML */
|
|
99
125
|
isHydration: boolean;
|
|
100
126
|
/**
|
|
@@ -103,7 +129,7 @@ type PageContextBuiltInClientWithClientRouting<Data> = Partial<PageContextBuiltI
|
|
|
103
129
|
* The value is `true` when the user clicks on his browser's backward navigation button, or when invoking `history.back()`.
|
|
104
130
|
*/
|
|
105
131
|
isBackwardNavigation: boolean | null;
|
|
106
|
-
} &
|
|
132
|
+
} & PageContextUrlClient;
|
|
107
133
|
type PageContextBuiltInClientWithServerRouting<Data> = Partial<PageContextBuiltInCommon<Data>> & Pick<PageContextBuiltInCommon<Data>, 'Page' | 'pageExports' | 'exports' | 'abortReason' | 'data'> & {
|
|
108
134
|
/**
|
|
109
135
|
* Whether the current page is already rendered to HTML.
|
|
@@ -119,7 +145,7 @@ type PageContextBuiltInClientWithServerRouting<Data> = Partial<PageContextBuiltI
|
|
|
119
145
|
isBackwardNavigation: null;
|
|
120
146
|
};
|
|
121
147
|
/** For Vike internal use */
|
|
122
|
-
type PageContextBuiltInServerInternal = Omit<PageContextBuiltInCommon<unknown> &
|
|
148
|
+
type PageContextBuiltInServerInternal = Omit<PageContextBuiltInCommon<unknown> & PageContextUrlInternal, 'data'>;
|
|
123
149
|
/** @deprecated
|
|
124
150
|
* Replace:
|
|
125
151
|
* ```
|
|
@@ -21,3 +21,5 @@ export * from '../utils/checkType.js';
|
|
|
21
21
|
export * from '../utils/getValuePrintable.js';
|
|
22
22
|
export * from '../utils/escapeRegex.js';
|
|
23
23
|
export * from '../utils/isArray.js';
|
|
24
|
+
export * from '../utils/changeEnumerable.js';
|
|
25
|
+
export * from '../utils/objectDefineProperty.js';
|
package/dist/esm/shared/utils.js
CHANGED
|
@@ -25,3 +25,5 @@ export * from '../utils/checkType.js';
|
|
|
25
25
|
export * from '../utils/getValuePrintable.js';
|
|
26
26
|
export * from '../utils/escapeRegex.js';
|
|
27
27
|
export * from '../utils/isArray.js';
|
|
28
|
+
export * from '../utils/changeEnumerable.js';
|
|
29
|
+
export * from '../utils/objectDefineProperty.js';
|
|
@@ -10,7 +10,7 @@ export type { Config, ConfigMeta as Meta, DataAsync, DataSync, GuardAsync, Guard
|
|
|
10
10
|
export type { ConfigEnv } from '../shared/page-configs/PageConfig.js';
|
|
11
11
|
export type { ConfigDefinition, ConfigEffect } from '../node/plugin/plugins/importUserCode/v1-design/getVikeConfig/configDefinitionsBuiltIn.js';
|
|
12
12
|
export type { ConfigEntries } from '../shared/getPageFiles/getExports.js';
|
|
13
|
-
export type { Url } from '../shared/
|
|
13
|
+
export type { Url } from '../shared/getPageContextUrlComputed.js';
|
|
14
14
|
export type { InjectFilterEntry } from '../node/runtime/html/injectAssets/getHtmlTags.js';
|
|
15
15
|
export { defineConfig } from './defineConfig.js';
|
|
16
16
|
import type { ConfigEnv } from '../shared/page-configs/PageConfig.js';
|
package/dist/esm/utils/assert.js
CHANGED
|
@@ -92,7 +92,7 @@ function assertWarning(condition, msg, { onlyOnce, showStackTrace }) {
|
|
|
92
92
|
}
|
|
93
93
|
globalObject.onBeforeLog?.();
|
|
94
94
|
if (showStackTrace) {
|
|
95
|
-
const err =
|
|
95
|
+
const err = createErrorWithCleanStackTrace(msg, numberOfStackTraceLinesToRemove);
|
|
96
96
|
globalObject.showStackTraceList.add(err);
|
|
97
97
|
globalObject.logger(err, 'warn');
|
|
98
98
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function escapeHtml(unsafeString: string): string;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
// Copied from https://stackoverflow.com/questions/6234773/can-i-escape-html-special-chars-in-javascript/6234804#6234804
|
|
2
|
+
export function escapeHtml(unsafeString) {
|
|
3
|
+
const safe = unsafeString
|
|
4
|
+
.replace(/&/g, '&')
|
|
5
|
+
.replace(/</g, '<')
|
|
6
|
+
.replace(/>/g, '>')
|
|
7
|
+
.replace(/"/g, '"')
|
|
8
|
+
.replace(/'/g, ''');
|
|
9
|
+
return safe;
|
|
10
|
+
}
|
|
@@ -1,2 +1 @@
|
|
|
1
|
-
export
|
|
2
|
-
declare function getPropAccessNotation(key: string): `.${string}` | `[${string}]`;
|
|
1
|
+
export declare function getPropAccessNotation(key: unknown): `.${string}` | `[${string}]`;
|
|
@@ -1,7 +1,3 @@
|
|
|
1
|
-
export
|
|
2
|
-
|
|
3
|
-
return isKeyDotNotationCompatible(key) ? `.${key}` : `[${JSON.stringify(key)}]`;
|
|
4
|
-
}
|
|
5
|
-
function isKeyDotNotationCompatible(key) {
|
|
6
|
-
return /^[a-z0-9\$_]+$/i.test(key);
|
|
1
|
+
export function getPropAccessNotation(key) {
|
|
2
|
+
return typeof key === 'string' && /^[a-z0-9\$_]+$/i.test(key) ? `.${key}` : `[${JSON.stringify(key)}]`;
|
|
7
3
|
}
|
|
@@ -1,15 +1,6 @@
|
|
|
1
1
|
export { hasProp };
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
declare function hasProp<ObjectType, PropName extends PropertyKey>(obj: ObjectType, prop: PropName, type
|
|
6
|
-
declare function hasProp<ObjectType, PropName extends PropertyKey>(obj: ObjectType, prop: PropName, type: 'array'): obj is ObjectType & Record<PropName, unknown[]>;
|
|
7
|
-
declare function hasProp<ObjectType, PropName extends PropertyKey>(obj: ObjectType, prop: PropName, type: 'string[]'): obj is ObjectType & Record<PropName, string[]>;
|
|
8
|
-
declare function hasProp<ObjectType, PropName extends PropertyKey>(obj: ObjectType, prop: PropName, type: 'string{}'): obj is ObjectType & Record<PropName, Record<string, string>>;
|
|
9
|
-
declare function hasProp<ObjectType, PropName extends PropertyKey>(obj: ObjectType, prop: PropName, type: 'function'): obj is ObjectType & Record<PropName, (...args: any[]) => unknown>;
|
|
10
|
-
declare function hasProp<ObjectType, PropName extends PropertyKey>(obj: ObjectType, prop: PropName, type: 'undefined'): obj is ObjectType & Record<PropName, undefined>;
|
|
11
|
-
declare function hasProp<ObjectType, PropName extends PropertyKey>(obj: ObjectType, prop: PropName, type: 'null'): obj is ObjectType & Record<PropName, null>;
|
|
12
|
-
declare function hasProp<ObjectType, PropName extends PropertyKey>(obj: ObjectType, prop: PropName, type: 'true'): obj is ObjectType & Record<PropName, true>;
|
|
13
|
-
declare function hasProp<ObjectType, PropName extends PropertyKey>(obj: ObjectType, prop: PropName, type: 'false'): obj is ObjectType & Record<PropName, false>;
|
|
2
|
+
export type { ResolveTypeAsString };
|
|
3
|
+
type TypeAsString = 'object' | 'string{}' | 'string[]' | 'array' | 'function' | 'number' | 'string' | 'boolean' | 'true' | 'false' | 'null' | 'undefined' | undefined;
|
|
4
|
+
type ResolveTypeAsString<Type extends TypeAsString = undefined> = Type extends 'object' ? Record<string, unknown> : Type extends 'string{}' ? Record<string, string> : Type extends 'string[]' ? string[] : Type extends 'array' ? unknown[] : Type extends 'function' ? (...args: any[]) => unknown : Type extends 'number' ? number : Type extends 'string' ? string : Type extends 'boolean' ? boolean : Type extends 'true' ? true : Type extends 'false' ? false : Type extends 'null' ? null : Type extends 'undefined' ? undefined : Type extends undefined ? unknown : never;
|
|
5
|
+
declare function hasProp<ObjectType, PropName extends PropertyKey, Type extends TypeAsString = undefined>(obj: ObjectType, prop: PropName, type?: Type): obj is ObjectType & Record<PropName, ResolveTypeAsString<Type>>;
|
|
14
6
|
declare function hasProp<ObjectType, PropName extends PropertyKey, Enum>(obj: ObjectType, prop: PropName, type: Enum[]): obj is ObjectType & Record<PropName, Enum>;
|
|
15
|
-
declare function hasProp<ObjectType, PropName extends PropertyKey>(obj: ObjectType, prop: PropName): obj is ObjectType & Record<PropName, unknown>;
|
|
@@ -1,21 +1,22 @@
|
|
|
1
1
|
export { hasProp };
|
|
2
|
-
// - https://2ality.com/2020/06/type-guards-assertion-functions-typescript.html
|
|
3
|
-
// - https://www.typescriptlang.org/play?#code/GYVwdgxgLglg9mABDAzgFQJ4AcCmdgAUAbgIYA2IOAXIiWBgDSJTbWIDkARnHGTnewCUNUhRzIUibr35gA3AFgAUKEiwEEzLnzFylGnUbNWNdmBABbTjgBOQkXvGpE5q7cUrw0eElRa8hKL6tPRMLLimKFA2MGAA5vaIQU6SUTHxHqreGn6sOskGocYRHOAA1mBwAO5gickSiOWVNZle6r7oeYGOhUbhbGmxcYgAvKVgFdW1wlI8fHSIAN7KiMiExeIjW+OTNeyIgksrq4g2OFAgNkjRlMcAvsdnF1cb+EmOo9v9Hg9KyhAIKK0GhNKajRAAFgATMplCQUChbFACLltIQSEwzJZrHZBIJ-oCZAA6MhwOIEEj4v6eNQ+WgIpEEAFgAAmMHaIImzTAM3hiJsUEkzLZ7SOShOa0QTIQIp8hyelzAx1WUAAFjZqi4cFVEABRGwamwEdgAQQZArpADESDAyEJlHcgA
|
|
4
2
|
import { isCallable } from './isCallable.js';
|
|
5
3
|
import { isObject } from './isObject.js';
|
|
6
4
|
import { isArrayOfStrings } from './isArrayOfStrings.js';
|
|
7
5
|
import { isObjectOfStrings } from './isObjectOfStrings.js';
|
|
8
6
|
import { isArray } from './isArray.js';
|
|
9
|
-
function hasProp(obj, prop, type
|
|
7
|
+
function hasProp(obj, prop, type) {
|
|
10
8
|
if (!isObject(obj))
|
|
11
9
|
return false;
|
|
12
10
|
if (!(prop in obj)) {
|
|
13
11
|
return type === 'undefined';
|
|
14
12
|
}
|
|
15
|
-
if (type ===
|
|
13
|
+
if (type === undefined) {
|
|
16
14
|
return true;
|
|
17
15
|
}
|
|
18
16
|
const propValue = obj[prop];
|
|
17
|
+
if (type === 'undefined') {
|
|
18
|
+
return propValue === undefined;
|
|
19
|
+
}
|
|
19
20
|
if (type === 'array') {
|
|
20
21
|
return isArray(propValue);
|
|
21
22
|
}
|
|
@@ -37,9 +38,6 @@ function hasProp(obj, prop, type = 'unknown') {
|
|
|
37
38
|
if (type === 'null') {
|
|
38
39
|
return propValue === null;
|
|
39
40
|
}
|
|
40
|
-
if (type === 'undefined') {
|
|
41
|
-
return propValue === undefined;
|
|
42
|
-
}
|
|
43
41
|
if (type === 'true') {
|
|
44
42
|
return propValue === true;
|
|
45
43
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function normalizeHeaders(headersOriginal: unknown): Record<string, string>;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export function normalizeHeaders(
|
|
2
|
+
/* This type is precise, too precise which can be annoying: e.g. cannot pass a string[][] argument because it doesn't match the more precise [string,string][] type.
|
|
3
|
+
headersOriginal ConstructorParameters<typeof Headers>[0]
|
|
4
|
+
*/
|
|
5
|
+
headersOriginal) {
|
|
6
|
+
const headersStandard = new Headers(headersOriginal);
|
|
7
|
+
const headers = Object.fromEntries(headersStandard.entries());
|
|
8
|
+
return headers;
|
|
9
|
+
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
export { objectAssign };
|
|
2
2
|
// Same as Object.assign() but:
|
|
3
3
|
// - With type inference
|
|
4
|
-
// - Preserves property descriptors, which we need for preserving the getters added by
|
|
4
|
+
// - Preserves property descriptors, which we need for preserving the getters added by getPageContextUrlComputed()
|
|
5
5
|
function objectAssign(obj, objAddendum) {
|
|
6
6
|
if (objAddendum) {
|
|
7
7
|
Object.defineProperties(obj, Object.getOwnPropertyDescriptors(objAddendum));
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
/** Like Object.defineProperty() but with type inference */
|
|
2
|
+
export declare function objectDefineProperty<Obj extends object, Prop extends PropertyKey, PropertyType>(obj: Obj, prop: Prop, { get, ...args }: {
|
|
3
|
+
get: () => PropertyType;
|
|
4
|
+
} & Omit<PropertyDescriptor, 'set' | 'get'>): asserts obj is Obj & Record<Prop, PropertyType>;
|
|
@@ -1,10 +1,8 @@
|
|
|
1
1
|
export { objectEntries };
|
|
2
2
|
export { objectFromEntries };
|
|
3
3
|
export { objectKeys };
|
|
4
|
-
type ValueOf<T> = T[keyof T];
|
|
5
|
-
type Entries<T> = [keyof T, ValueOf<T>][];
|
|
6
4
|
/** Same as Object.entries() but with type inference */
|
|
7
|
-
declare function objectEntries<T extends object>(obj: T):
|
|
5
|
+
declare function objectEntries<T extends object>(obj: T): [keyof T, T[keyof T]][];
|
|
8
6
|
/** Same as Object.fromEntries() but with type inference */
|
|
9
7
|
declare function objectFromEntries<T extends [PropertyKey, unknown][]>(arr: T): Record<T[number][0], T[number][1]>;
|
|
10
8
|
/** Same as Object.keys() but with type inference */
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
export { objectEntries };
|
|
2
2
|
export { objectFromEntries };
|
|
3
3
|
export { objectKeys };
|
|
4
|
+
// export { forEach }
|
|
4
5
|
// https://stackoverflow.com/questions/60141960/typescript-key-value-relation-preserving-object-entries-type/75337277#75337277
|
|
5
6
|
/** Same as Object.entries() but with type inference */
|
|
6
7
|
function objectEntries(obj) {
|
|
@@ -16,8 +17,11 @@ function objectFromEntries(arr) {
|
|
|
16
17
|
function objectKeys(obj) {
|
|
17
18
|
return Object.keys(obj);
|
|
18
19
|
}
|
|
19
|
-
/*
|
|
20
|
-
function
|
|
21
|
-
|
|
20
|
+
/* Not used yet, but can be quite useful.
|
|
21
|
+
function forEach<Obj extends object>(
|
|
22
|
+
obj: Obj,
|
|
23
|
+
iterator: <Key extends keyof Obj>(key: Key, val: Obj[Key]) => void
|
|
24
|
+
): void {
|
|
25
|
+
Object.entries(obj).forEach(([key, val]) => iterator(key as keyof Obj, val))
|
|
22
26
|
}
|
|
23
|
-
|
|
27
|
+
//*/
|