@revealui/core 0.0.1-pre.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +202 -0
- package/LICENSE_SUMMARY.md +55 -0
- package/README.md +201 -0
- package/dist/core/__internal/index.ts +63 -0
- package/dist/core/__tests__/assertNoInfiniteHttpRedirect.spec.ts +76 -0
- package/dist/core/__tests__/deduceRouteStringFromFilesystemPath.spec.ts +88 -0
- package/dist/core/__tests__/freezePartial.spec.ts +40 -0
- package/dist/core/__tests__/getValuePrintable.spec.ts +15 -0
- package/dist/core/__tests__/injectHtmlTags.spec.ts +101 -0
- package/dist/core/__tests__/isHtml.spec.ts +23 -0
- package/dist/core/__tests__/isNpmPackage.spec.ts +93 -0
- package/dist/core/__tests__/normalizeHeaders.spec.ts +142 -0
- package/dist/core/__tests__/parseUrl-extras.spec.ts +60 -0
- package/dist/core/__tests__/parseUrl.spec.ts +1339 -0
- package/dist/core/__tests__/resolvePrecedence/resolvePrecedence_overall.spec.ts +106 -0
- package/dist/core/__tests__/resolvePrecedence/resolvePrecedence_route-strings.spec.ts +99 -0
- package/dist/core/__tests__/resolveRedirects.spec.ts +132 -0
- package/dist/core/__tests__/resolveRouteString.spec.ts +211 -0
- package/dist/core/__tests__/resolveUrlPathname.spec.ts +22 -0
- package/dist/core/__tests__/trimWithAnsi.spec.ts +40 -0
- package/dist/core/api/ssr.ts +63 -0
- package/dist/core/assets/extractAssetsQuery.ts +29 -0
- package/dist/core/assets/index.ts +173 -0
- package/dist/core/assets/inferHtmlTags.ts +61 -0
- package/dist/core/assets/injectHtmlTags.ts +236 -0
- package/dist/core/assets/mergeScriptTags.ts +77 -0
- package/dist/core/assets/sanitizeJson.ts +8 -0
- package/dist/core/cli/bin.ts +161 -0
- package/dist/core/cli/commands/add.ts +158 -0
- package/dist/core/cli/commands/check.ts +47 -0
- package/dist/core/cli/commands/doctor/checks/build.ts +83 -0
- package/dist/core/cli/commands/doctor/checks/config.ts +130 -0
- package/dist/core/cli/commands/doctor/checks/dependencies.ts +144 -0
- package/dist/core/cli/commands/doctor/checks/practices.ts +156 -0
- package/dist/core/cli/commands/doctor/checks/structure.ts +127 -0
- package/dist/core/cli/commands/doctor/fixes/index.ts +136 -0
- package/dist/core/cli/commands/doctor/index.ts +47 -0
- package/dist/core/cli/commands/doctor/print.ts +44 -0
- package/dist/core/cli/commands/doctor/types.ts +16 -0
- package/dist/core/cli/commands/fix.ts +161 -0
- package/dist/core/cli/commands/init.ts +145 -0
- package/dist/core/cli/commands/upgrade.ts +115 -0
- package/dist/core/cli/onLoad.ts +7 -0
- package/dist/core/cli/utils.ts +6 -0
- package/dist/core/components/Config/Config-client.ts +14 -0
- package/dist/core/components/Config/Config-server.ts +16 -0
- package/dist/core/components/Head/Head-client.ts +4 -0
- package/dist/core/components/Head/Head-server.ts +16 -0
- package/dist/core/components/Loading.tsx +23 -0
- package/dist/core/config/findPageConfig.ts +14 -0
- package/dist/core/config/loadConfigValues.ts +28 -0
- package/dist/core/constants/UnifiedConstants.ts +348 -0
- package/dist/core/dom/applyHeadSettings.tsx +13 -0
- package/dist/core/dom/onPageVisibilityChange.ts +17 -0
- package/dist/core/dom/updateDocumentHead.ts +15 -0
- package/dist/core/errors/ErrorHandler.ts +480 -0
- package/dist/core/files/file-system/filesystemPath.ts +27 -0
- package/dist/core/files/file-system/findFile.ts +35 -0
- package/dist/core/files/file-system/findPackageJson.ts +19 -0
- package/dist/core/files/file-system/findPageFiles.ts +40 -0
- package/dist/core/files/file-system/pathShim.ts +16 -0
- package/dist/core/files/file-system/prependEntriesDir.ts +13 -0
- package/dist/core/files/file-system/removeFileExtention.ts +3 -0
- package/dist/core/files/file-system/requireResolve.ts +59 -0
- package/dist/core/files/file-system/scanCodebase.ts +64 -0
- package/dist/core/files/virtual-files/index.ts +31 -0
- package/dist/core/files/virtual-files/virtualFileImportUserCode.ts +34 -0
- package/dist/core/files/virtual-files/virtualFilePageConfigValuesAll.ts +49 -0
- package/dist/core/gaurds/assertions/assert/base.ts +6 -0
- package/dist/core/gaurds/assertions/assert/index.ts +2 -0
- package/dist/core/gaurds/assertions/assert/log.ts +42 -0
- package/dist/core/gaurds/assertions/assertArguments.ts +83 -0
- package/dist/core/gaurds/assertions/assertCast.ts +9 -0
- package/dist/core/gaurds/assertions/assertCommonJS/base.ts +9 -0
- package/dist/core/gaurds/assertions/assertCommonJS/common.ts +30 -0
- package/dist/core/gaurds/assertions/assertCommonJS/index.ts +2 -0
- package/dist/core/gaurds/assertions/assertExtensions/base.ts +187 -0
- package/dist/core/gaurds/assertions/assertExtensions/index.ts +1 -0
- package/dist/core/gaurds/assertions/assertHookReturnedObject.ts +30 -0
- package/dist/core/gaurds/assertions/assertInfo/base.ts +14 -0
- package/dist/core/gaurds/assertions/assertInfo/index.ts +2 -0
- package/dist/core/gaurds/assertions/assertInfo/log.ts +28 -0
- package/dist/core/gaurds/assertions/assertIs404.ts +12 -0
- package/dist/core/gaurds/assertions/assertIsBrowser/base.ts +8 -0
- package/dist/core/gaurds/assertions/assertIsBrowser/index.ts +1 -0
- package/dist/core/gaurds/assertions/assertIsNotBrowser/base.ts +9 -0
- package/dist/core/gaurds/assertions/assertIsNotBrowser/index.ts +1 -0
- package/dist/core/gaurds/assertions/assertIsNotProductionRuntime/base.ts +71 -0
- package/dist/core/gaurds/assertions/assertIsNotProductionRuntime/index.ts +1 -0
- package/dist/core/gaurds/assertions/assertKeys/base.ts +31 -0
- package/dist/core/gaurds/assertions/assertKeys/index.ts +1 -0
- package/dist/core/gaurds/assertions/assertNoInfiniteHttpRedirect.ts +55 -0
- package/dist/core/gaurds/assertions/assertNodeEnv/base.ts +120 -0
- package/dist/core/gaurds/assertions/assertNodeEnv/index.ts +1 -0
- package/dist/core/gaurds/assertions/assertNodeVersion/base.ts +11 -0
- package/dist/core/gaurds/assertions/assertNodeVersion/index.ts +1 -0
- package/dist/core/gaurds/assertions/assertOnBeforeRenderHookReturn.ts +37 -0
- package/dist/core/gaurds/assertions/assertPageContextProvidedByUser.ts +60 -0
- package/dist/core/gaurds/assertions/assertPluginManifest.ts +41 -0
- package/dist/core/gaurds/assertions/assertPlusFileExport.ts +66 -0
- package/dist/core/gaurds/assertions/assertRoutingType/base.ts +41 -0
- package/dist/core/gaurds/assertions/assertRoutingType/index.ts +1 -0
- package/dist/core/gaurds/assertions/assertRuntimeManifest.ts +34 -0
- package/dist/core/gaurds/assertions/assertSingleInstance/index.ts +142 -0
- package/dist/core/gaurds/assertions/assertSingleInstance/onAssertModuleLoad.ts +0 -0
- package/dist/core/gaurds/assertions/assertSingleInstance/onClientEntryClientRouting.ts +0 -0
- package/dist/core/gaurds/assertions/assertSingleInstance/onClientEntryServerRouting.ts +0 -0
- package/dist/core/gaurds/assertions/assertType.ts +12 -0
- package/dist/core/gaurds/assertions/assertUsage/base.ts +43 -0
- package/dist/core/gaurds/assertions/assertUsage/index.ts +3 -0
- package/dist/core/gaurds/assertions/assertUsage/log.ts +29 -0
- package/dist/core/gaurds/assertions/assertUsage/node.ts +16 -0
- package/dist/core/gaurds/assertions/assertV1Design.ts +29 -0
- package/dist/core/gaurds/assertions/assertVersion/base.ts +55 -0
- package/dist/core/gaurds/assertions/assertVersion/index.ts +1 -0
- package/dist/core/gaurds/assertions/assertWarning/base.ts +43 -0
- package/dist/core/gaurds/assertions/assertWarning/index.ts +2 -0
- package/dist/core/gaurds/assertions/assertWarning/log.ts +43 -0
- package/dist/core/gaurds/assertions/checkType.ts +2 -0
- package/dist/core/gaurds/debugger/createDebugger.ts +196 -0
- package/dist/core/gaurds/debugger/debugPageFiles.ts +121 -0
- package/dist/core/gaurds/debugger/index.ts +2 -0
- package/dist/core/gaurds/errors/createErrorWithCleanStackTrace.ts +56 -0
- package/dist/core/gaurds/errors/removeErrMsg.ts +8 -0
- package/dist/core/gaurds/logger/addOnBeforeLogHook/index.ts +7 -0
- package/dist/core/gaurds/logger/formatHintLog.ts +17 -0
- package/dist/core/gaurds/logger/log404/index.spec.snapshot-1 +8 -0
- package/dist/core/gaurds/logger/log404/index.spec.snapshot-2 +9 -0
- package/dist/core/gaurds/logger/log404/index.spec.ts +78 -0
- package/dist/core/gaurds/logger/log404/index.ts +208 -0
- package/dist/core/gaurds/logger/logErrorHint/errors.ts +17 -0
- package/dist/core/gaurds/logger/logErrorHint/getErrorHint.spec.ts +1057 -0
- package/dist/core/gaurds/logger/logErrorHint.ts +196 -0
- package/dist/core/gaurds/logger/loggerNotProd/errorWithCodeSnippet/fixture-errors/errBabelReact.ts +16 -0
- package/dist/core/gaurds/logger/loggerNotProd/errorWithCodeSnippet/fixture-errors/errBabelSolid.ts +16 -0
- package/dist/core/gaurds/logger/loggerNotProd/errorWithCodeSnippet/fixture-errors/errEsbuild.ts +39 -0
- package/dist/core/gaurds/logger/loggerNotProd/errorWithCodeSnippet/fixture-errors/errMdx1.ts +24 -0
- package/dist/core/gaurds/logger/loggerNotProd/errorWithCodeSnippet/fixture-errors/errMdx2.ts +83 -0
- package/dist/core/gaurds/logger/loggerNotProd/errorWithCodeSnippet/fixture-errors/errPostcss.ts +33 -0
- package/dist/core/gaurds/logger/loggerNotProd/errorWithCodeSnippet/fixture-errors/errSwc.ts +20 -0
- package/dist/core/gaurds/logger/loggerNotProd/errorWithCodeSnippet/fixture-errors/errSwcBig.ts +19 -0
- package/dist/core/gaurds/logger/loggerNotProd/errorWithCodeSnippet/fixture-errors/errVueCss.ts +36 -0
- package/dist/core/gaurds/logger/loggerNotProd/errorWithCodeSnippet/fixture-errors/errVueHtml.ts +17 -0
- package/dist/core/gaurds/logger/loggerNotProd/errorWithCodeSnippet/fixture-errors/errVueJavascript.ts +16 -0
- package/dist/core/gaurds/logger/loggerNotProd/errorWithCodeSnippet/getPrettyErrMessage.spec.ts +101 -0
- package/dist/core/gaurds/logger/loggerNotProd/errorWithCodeSnippet/getPrettyErrorWithCodeSnippet.spec.ts +232 -0
- package/dist/core/gaurds/logger/loggerNotProd/errorWithCodeSnippet.ts +212 -0
- package/dist/core/gaurds/logger/loggerNotProd/log.ts +124 -0
- package/dist/core/gaurds/logger/loggerNotProd.ts +271 -0
- package/dist/core/gaurds/logger/loggerProd.ts +37 -0
- package/dist/core/gaurds/logger/loggerRuntime.ts +46 -0
- package/dist/core/gaurds/logger/loggerVite/removeSuperfluousViteLog.ts +30 -0
- package/dist/core/gaurds/logger/loggerVite.ts +65 -0
- package/dist/core/gaurds/logger/overwriteAssertProductionLogger/index.ts +9 -0
- package/dist/core/gaurds/logger/trackLogs.ts +35 -0
- package/dist/core/gaurds/logger/warnIfErrorIsNotObject.ts +31 -0
- package/dist/core/gaurds/normalization/freezePartial.ts +39 -0
- package/dist/core/gaurds/normalization/normalizeHeaders.ts +20 -0
- package/dist/core/gaurds/normalization/normalizeLink.tsx +14 -0
- package/dist/core/gaurds/normalization/normalizeUrlArgument.ts +22 -0
- package/dist/core/gaurds/validators/hasProp.ts +116 -0
- package/dist/core/gaurds/validators/isArray.ts +4 -0
- package/dist/core/gaurds/validators/isArrayOfStrings.ts +7 -0
- package/dist/core/gaurds/validators/isAsset.ts +43 -0
- package/dist/core/gaurds/validators/isBrowser.ts +5 -0
- package/dist/core/gaurds/validators/isBug.ts +5 -0
- package/dist/core/gaurds/validators/isCallable.ts +11 -0
- package/dist/core/gaurds/validators/isClientSideRoutable.ts +19 -0
- package/dist/core/gaurds/validators/isConfigInvalid.ts +10 -0
- package/dist/core/gaurds/validators/isDev.ts +56 -0
- package/dist/core/gaurds/validators/isErrorDebug.ts +7 -0
- package/dist/core/gaurds/validators/isErrorPage.ts +16 -0
- package/dist/core/gaurds/validators/isFilePathAbsoluteFilesystem.ts +55 -0
- package/dist/core/gaurds/validators/isHtml.ts +9 -0
- package/dist/core/gaurds/validators/isNewError.ts +29 -0
- package/dist/core/gaurds/validators/isNodeJS.ts +10 -0
- package/dist/core/gaurds/validators/isNotFalse.ts +3 -0
- package/dist/core/gaurds/validators/isNotNullish.ts +2 -0
- package/dist/core/gaurds/validators/isNpmPackage.ts +127 -0
- package/dist/core/gaurds/validators/isObject.ts +3 -0
- package/dist/core/gaurds/validators/isObjectOfStrings.ts +9 -0
- package/dist/core/gaurds/validators/isObjectWithKeys.ts +18 -0
- package/dist/core/gaurds/validators/isPlainObject.ts +21 -0
- package/dist/core/gaurds/validators/isPromise.ts +9 -0
- package/dist/core/gaurds/validators/isPropertyGetter.ts +4 -0
- package/dist/core/gaurds/validators/isReact.ts +24 -0
- package/dist/core/gaurds/validators/isReactElement.ts +21 -0
- package/dist/core/gaurds/validators/isRevealApp.ts +4 -0
- package/dist/core/gaurds/validators/isSameErrorMessage.ts +8 -0
- package/dist/core/gaurds/validators/isScriptFile.ts +75 -0
- package/dist/core/gaurds/validators/isServerSideError.ts +1 -0
- package/dist/core/gaurds/validators/isViteCliCall.ts +93 -0
- package/dist/core/gaurds/validators/isVitest.ts +7 -0
- package/dist/core/gaurds/validators/rollupIsEsm.ts +14 -0
- package/dist/core/gaurds/validators/viteIsSSR.ts +23 -0
- package/dist/core/globals/contexts/globalContext/getPageFilesExports.ts +28 -0
- package/dist/core/globals/contexts/globalContext/index.ts +374 -0
- package/dist/core/globals/contexts/globalContext/loadImportBuild.ts +44 -0
- package/dist/core/globals/contexts/globalContext/setup.ts +4 -0
- package/dist/core/globals/contexts/index.ts +1 -0
- package/dist/core/globals/logger/index.ts +1 -0
- package/dist/core/globals/logger/numberOfStackTraceLinesToRemove.ts +3 -0
- package/dist/core/globals/objects/index.ts +1 -0
- package/dist/core/globals/objects/log.ts +24 -0
- package/dist/core/globals/patterns/styleFileRE.ts +3 -0
- package/dist/core/globals/tags/addPrefixAssertType.ts +11 -0
- package/dist/core/globals/tags/addPrefixProjectName.ts +9 -0
- package/dist/core/globals/tags/projectTag.ts +3 -0
- package/dist/core/globals/tags/projectTagWithVersion.ts +5 -0
- package/dist/core/globals/versions/PROJECT_VERSION.ts +2 -0
- package/dist/core/globals/versions/projectInfo.ts +5 -0
- package/dist/core/handlers/handleErrorWithoutErrorPage.ts +70 -0
- package/dist/core/handlers/handlePageContext.ts +15 -0
- package/dist/core/handlers/handlePageContextRequestUrl.ts +56 -0
- package/dist/core/handlers/openFacebook.ts +20 -0
- package/dist/core/hocs/clientOnly.tsx +130 -0
- package/dist/core/hooks/callCumulativeHooks.ts +22 -0
- package/dist/core/hooks/executeHook.ts +118 -0
- package/dist/core/hooks/useConfig/configsCumulative.ts +6 -0
- package/dist/core/hooks/useConfig/useConfig-client.ts +82 -0
- package/dist/core/hooks/useConfig/useConfig-server.ts +152 -0
- package/dist/core/hydration/progressive.ts +252 -0
- package/dist/core/index.ts +60 -0
- package/dist/core/islands/index.tsx +198 -0
- package/dist/core/logging/UnifiedLoggerV2.ts +555 -0
- package/dist/core/logging/index.ts +80 -0
- package/dist/core/logging/plugins/FilePlugin.ts +132 -0
- package/dist/core/logging/plugins/PayloadCMSPlugin.ts +71 -0
- package/dist/core/logging/plugins/RemotePlugin.ts +110 -0
- package/dist/core/logging/plugins/index.ts +11 -0
- package/dist/core/naming/UnifiedNaming.ts +424 -0
- package/dist/core/observability/logger.ts +195 -0
- package/dist/core/observability/metrics.ts +156 -0
- package/dist/core/processing/getters/getAssertErrMsg.ts +49 -0
- package/dist/core/processing/getters/getAssetsDir.ts +11 -0
- package/dist/core/processing/getters/getBaseServer.ts +16 -0
- package/dist/core/processing/getters/getCacheControl.ts +26 -0
- package/dist/core/processing/getters/getConfigDefinedAt.ts +73 -0
- package/dist/core/processing/getters/getConfigReveal.ts +14 -0
- package/dist/core/processing/getters/getConfigValue.ts +68 -0
- package/dist/core/processing/getters/getConfigValueBuildTime.ts +92 -0
- package/dist/core/processing/getters/getConfigValueFilePathToShowToUser.ts +17 -0
- package/dist/core/processing/getters/getCurrentUrl.ts +42 -0
- package/dist/core/processing/getters/getEarlyHints.ts +58 -0
- package/dist/core/processing/getters/getEnv.ts +33 -0
- package/dist/core/processing/getters/getErrorPageId.ts +23 -0
- package/dist/core/processing/getters/getExportPath.spec.ts +34 -0
- package/dist/core/processing/getters/getExportPath.ts +33 -0
- package/dist/core/processing/getters/getFileExtension.ts +19 -0
- package/dist/core/processing/getters/getFilePath.ts +269 -0
- package/dist/core/processing/getters/getGlobalObject.ts +53 -0
- package/dist/core/processing/getters/getHeadSetting.tsx +36 -0
- package/dist/core/processing/getters/getHook.ts +222 -0
- package/dist/core/processing/getters/getHookFilePathToShowToUser.ts +12 -0
- package/dist/core/processing/getters/getHtmlTags.ts +341 -0
- package/dist/core/processing/getters/getHttpRequestAsyncStore.ts +122 -0
- package/dist/core/processing/getters/getHttpResponseBody.ts +177 -0
- package/dist/core/processing/getters/getMostSimilar.ts +72 -0
- package/dist/core/processing/getters/getOutDirs.ts +160 -0
- package/dist/core/processing/getters/getPageAssets/getManifestEntry.ts +164 -0
- package/dist/core/processing/getters/getPageAssets/retrieveAssetsDev.ts +96 -0
- package/dist/core/processing/getters/getPageAssets/retrieveAssetsProd.ts +86 -0
- package/dist/core/processing/getters/getPageAssets/sortPageAssetsForEarlyHintsHeader.ts +40 -0
- package/dist/core/processing/getters/getPageAssets.ts +140 -0
- package/dist/core/processing/getters/getPageConfig.ts +14 -0
- package/dist/core/processing/getters/getPageContext.ts +64 -0
- package/dist/core/processing/getters/getPageContextCurrent.ts +19 -0
- package/dist/core/processing/getters/getPageContextFromHooks.ts +335 -0
- package/dist/core/processing/getters/getPageContextProxyForUser.ts +97 -0
- package/dist/core/processing/getters/getPageContextRequestUrl.ts +22 -0
- package/dist/core/processing/getters/getPageContextSerializedInHtml.ts +32 -0
- package/dist/core/processing/getters/getPageContextUrlComputed.ts +410 -0
- package/dist/core/processing/getters/getPageElement.tsx +148 -0
- package/dist/core/processing/getters/getPageFiles/analyzeClientSide.ts +50 -0
- package/dist/core/processing/getters/getPageFiles/analyzePageServerSide.ts +32 -0
- package/dist/core/processing/getters/getPageFiles/getExportNames.ts +16 -0
- package/dist/core/processing/getters/getPageFiles/getExports.ts +193 -0
- package/dist/core/processing/getters/getPageFiles/index.ts +9 -0
- package/dist/core/processing/getters/getPageFiles/parseGlobResults.ts +167 -0
- package/dist/core/processing/getters/getPageFiles/setPageFiles.ts +76 -0
- package/dist/core/processing/getters/getPrefetchSettingResolved.ts.ts +87 -0
- package/dist/core/processing/getters/getProjectError.ts +18 -0
- package/dist/core/processing/getters/getPropAccessNotation.ts +10 -0
- package/dist/core/processing/getters/getRandomId.ts +15 -0
- package/dist/core/processing/getters/getRevalidationKey.ts +5 -0
- package/dist/core/processing/getters/getRevealClientEntry.ts +7 -0
- package/dist/core/processing/getters/getRevealConfig/configDefinitionsBuiltIn.ts +711 -0
- package/dist/core/processing/getters/getRevealConfig/crawlPlusFiles.ts +409 -0
- package/dist/core/processing/getters/getRevealConfig/filesystemRouting.spec.ts +40 -0
- package/dist/core/processing/getters/getRevealConfig/filesystemRouting.ts +286 -0
- package/dist/core/processing/getters/getRevealConfig/index.ts +1641 -0
- package/dist/core/processing/getters/getRevealConfig/loadFileAtConfigTime.ts +181 -0
- package/dist/core/processing/getters/getRevealConfig/resolvePointerImport.ts +240 -0
- package/dist/core/processing/getters/getRevealConfig/transformPointerImports.spec.ts +30 -0
- package/dist/core/processing/getters/getRevealConfig/transformPointerImports.ts +244 -0
- package/dist/core/processing/getters/getRevealConfig/transpileAndExecuteFile.ts +490 -0
- package/dist/core/processing/getters/getTagAttributesString.ts +27 -0
- package/dist/core/processing/getters/getTerminWidth.ts +9 -0
- package/dist/core/processing/getters/getValuePrintable.ts +6 -0
- package/dist/core/processing/getters/getViteDevScript.ts +47 -0
- package/dist/core/processing/iterators/analyzePage.ts +65 -0
- package/dist/core/processing/iterators/includes.ts +10 -0
- package/dist/core/processing/iterators/index.ts +2 -0
- package/dist/core/processing/iterators/objectKeys.ts +6 -0
- package/dist/core/processing/parsers/parseEsModule.ts +43 -0
- package/dist/core/processing/parsers/parseTransform.ts +36 -0
- package/dist/core/processing/serializers/notSerializable.ts +2 -0
- package/dist/core/processing/serializers/replaceWithParserPath.ts +30 -0
- package/dist/core/processing/serializers/serializePage/PageConfigSerialized.ts +45 -0
- package/dist/core/processing/serializers/serializePage/parsePageConfigs.ts +223 -0
- package/dist/core/processing/serializers/serializePage/serializeConfigValues.ts +336 -0
- package/dist/core/processing/serializers/serializePageContextClientSide.ts +179 -0
- package/dist/core/processing/serializers/stringify.ts +188 -0
- package/dist/core/processing/serializers/stringifyTypes.ts +103 -0
- package/dist/core/processing/setters/addIs404ToPageProps.ts +27 -0
- package/dist/core/processing/setters/setAlwaysShowStackTrace.ts +7 -0
- package/dist/core/processing/transformers/augmentType.ts +10 -0
- package/dist/core/processing/transformers/rollupSourceMap.ts +23 -0
- package/dist/core/processing/transformers/slice.ts +52 -0
- package/dist/core/renderer/page/executeOnBeforeRenderAndDataHooks.ts +53 -0
- package/dist/core/renderer/page/executeOnRenderHtmlHook.ts +261 -0
- package/dist/core/renderer/page/index.ts +804 -0
- package/dist/core/renderer/page/inferMediaType.ts +128 -0
- package/dist/core/renderer/page/loadUserFilesServerSide.ts +154 -0
- package/dist/core/renderer/page/preparePageContextForUserConsumption.ts +55 -0
- package/dist/core/renderer/page/preparePageContextForUserConsumptionServerSide.ts +38 -0
- package/dist/core/renderer/page/renderPageAlreadyRouted.ts +373 -0
- package/dist/core/renderer/page/resolveRedirects.ts +75 -0
- package/dist/core/renderer/prerender/index.ts +1 -0
- package/dist/core/renderer/prerender/runPrerender.ts +1141 -0
- package/dist/core/renderer/prerender/utils.ts +22 -0
- package/dist/core/renderer/stream/html.ts +408 -0
- package/dist/core/renderer/stream/index.ts +1001 -0
- package/dist/core/renderer/stream/onLoad.ts +14 -0
- package/dist/core/renderer/stream/react-streaming.ts +69 -0
- package/dist/core/renderer/stream/utils.ts +66 -0
- package/dist/core/resilience/circuit-breaker.ts +212 -0
- package/dist/core/resilience/retry.ts +172 -0
- package/dist/core/result/adapters.ts +254 -0
- package/dist/core/result.ts +332 -0
- package/dist/core/router/abort.ts +339 -0
- package/dist/core/router/apiRoutes.ts +94 -0
- package/dist/core/router/debug.ts +19 -0
- package/dist/core/router/deduceRouteStringFromFilesystemPath.ts +75 -0
- package/dist/core/router/dynamicApiRoutes.ts +18 -0
- package/dist/core/router/dynamicPageRoutes.ts +18 -0
- package/dist/core/router/executeGuardHook.ts +45 -0
- package/dist/core/router/executeOnBeforeRouteHook.ts +161 -0
- package/dist/core/router/index.ts +230 -0
- package/dist/core/router/loadPageRoutes.ts +155 -0
- package/dist/core/router/noRouteMatch.ts +1 -0
- package/dist/core/router/pageRoutes.ts +159 -0
- package/dist/core/router/resolvePrecedence.ts +128 -0
- package/dist/core/router/resolveRoute.ts +29 -0
- package/dist/core/router/resolveRouteFunction.ts +193 -0
- package/dist/core/router/resolveRouteString.ts +204 -0
- package/dist/core/router/resolveRouteUtils.ts +77 -0
- package/dist/core/router/resolveUrlPathname.ts +67 -0
- package/dist/core/router/routeInternal.ts +97 -0
- package/dist/core/router/utils.ts +30 -0
- package/dist/core/services/BaseService.ts +403 -0
- package/dist/core/targets/client/abort.ts +11 -0
- package/dist/core/targets/client/createPageContext.ts +48 -0
- package/dist/core/targets/client/entry.ts +15 -0
- package/dist/core/targets/client/executeOnRenderClientHook.ts +94 -0
- package/dist/core/targets/client/history.ts +142 -0
- package/dist/core/targets/client/index.ts +9 -0
- package/dist/core/targets/client/initClientRouter.ts +48 -0
- package/dist/core/targets/client/initOnLinkClick.ts +54 -0
- package/dist/core/targets/client/loadUserFilesClientSide.ts +92 -0
- package/dist/core/targets/client/navigate.ts +45 -0
- package/dist/core/targets/client/onBrowserHistoryNavigation.ts +85 -0
- package/dist/core/targets/client/onLoad.ts +10 -0
- package/dist/core/targets/client/pageContextInitIsPassedToClient.ts +2 -0
- package/dist/core/targets/client/pageFiles.ts +4 -0
- package/dist/core/targets/client/prefetch.ts +399 -0
- package/dist/core/targets/client/preparePageContextForUserConsumptionClientSide.ts +48 -0
- package/dist/core/targets/client/removeBuiltInOverrides.ts +37 -0
- package/dist/core/targets/client/removeFoucBuster.ts +70 -0
- package/dist/core/targets/client/renderPageClientSide.ts +1817 -0
- package/dist/core/targets/client/router.ts +15 -0
- package/dist/core/targets/client/scrollRestoration.ts +37 -0
- package/dist/core/targets/client/setScrollPosition.ts +87 -0
- package/dist/core/targets/client/skipLink.ts +63 -0
- package/dist/core/targets/client/utils.ts +34 -0
- package/dist/core/targets/http/createHttpResponse.ts +254 -0
- package/dist/core/targets/http/fetchBanner.ts +25 -0
- package/dist/core/targets/http/fetchCard.ts +25 -0
- package/dist/core/targets/http/fetchEvents.ts +25 -0
- package/dist/core/targets/http/fetchHero.ts +25 -0
- package/dist/core/targets/http/fetchMainInfos.ts +25 -0
- package/dist/core/targets/http/fetchPage.ts +78 -0
- package/dist/core/targets/http/fetchPages.ts +70 -0
- package/dist/core/targets/http/fetchVideos.ts +26 -0
- package/dist/core/targets/http/fetchYouTube.ts +90 -0
- package/dist/core/targets/server/entry.ts +43 -0
- package/dist/core/targets/server/middleware/addSsrMiddleware.ts +52 -0
- package/dist/core/targets/server/onLoad.ts +7 -0
- package/dist/core/targets/server/pageFiles.ts +4 -0
- package/dist/core/targets/server/root.ts +10 -0
- package/dist/core/targets/server/utils.ts +20 -0
- package/dist/core/targets/url/index.ts +439 -0
- package/dist/core/targets/url/modifyUrl.ts +45 -0
- package/dist/core/targets/url/parseUrl.ts +440 -0
- package/dist/core/targets/url/parseUrlExtras.ts +193 -0
- package/dist/core/targets/url/redirectHard.ts +3 -0
- package/dist/core/targets/url/updateCurrentPath.ts +52 -0
- package/dist/core/targets/url/urlToFile.ts +47 -0
- package/dist/core/types/UnifiedTypes.ts +493 -0
- package/dist/core/types/contracts.ts +61 -0
- package/dist/core/types/generator.ts +316 -0
- package/dist/core/utils/array/includes.ts +10 -0
- package/dist/core/utils/array/slice.ts +52 -0
- package/dist/core/utils/array/sorter.ts +130 -0
- package/dist/core/utils/array/stringifyStringArray.ts +7 -0
- package/dist/core/utils/array/unique.ts +5 -0
- package/dist/core/utils/async/genPromise.ts +8 -0
- package/dist/core/utils/async/pLimit.ts +157 -0
- package/dist/core/utils/async/sleep.ts +3 -0
- package/dist/core/utils/async/throttle.ts +14 -0
- package/dist/core/utils/index.ts +31 -0
- package/dist/core/utils/object/changeEnumerable.ts +9 -0
- package/dist/core/utils/object/deepEqual.ts +10 -0
- package/dist/core/utils/object/objectAssign.ts +16 -0
- package/dist/core/utils/object/objectDefineProperty.ts +15 -0
- package/dist/core/utils/object/objectEntries.ts +7 -0
- package/dist/core/utils/object/objectEntriesForEach.ts +7 -0
- package/dist/core/utils/object/objectFromEntries.ts +6 -0
- package/dist/core/utils/string/addWhitespace.ts +9 -0
- package/dist/core/utils/string/capitalizeFirstLetter.ts +8 -0
- package/dist/core/utils/string/compareString.ts +7 -0
- package/dist/core/utils/string/escapeHtml.ts +10 -0
- package/dist/core/utils/string/escapeRegex.ts +4 -0
- package/dist/core/utils/string/joinEnglish.ts +18 -0
- package/dist/core/utils/string/removeEmptyLines.ts +6 -0
- package/dist/core/utils/string/stripAnsi.ts +24 -0
- package/dist/core/utils/string/trimWithAnsi.ts +40 -0
- package/dist/core/utils/string/truncateString.ts +19 -0
- package/dist/core/utils/time/humanizeTime.ts +24 -0
- package/dist/exports/RenderErrorPage.js +3 -0
- package/dist/exports/__internal.js +3 -0
- package/dist/exports/abort.js +3 -0
- package/dist/exports/bin-entry.js +3 -0
- package/dist/exports/cli.js +3 -0
- package/dist/exports/client.js +3 -0
- package/dist/exports/config.js +1 -0
- package/dist/exports/helpers.js +1 -0
- package/dist/exports/index.js +33 -0
- package/dist/exports/plugin.js +3 -0
- package/dist/exports/prerender.js +3 -0
- package/dist/exports/router.js +3 -0
- package/dist/exports/routing.js +3 -0
- package/dist/exports/server.js +3 -0
- package/dist/exports/setup.js +3 -0
- package/dist/exports/types.js +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +33 -0
- package/dist/integration/hydration.ts +52 -0
- package/dist/integration/onRenderClient.tsx +377 -0
- package/dist/integration/onRenderHtml.tsx +761 -0
- package/dist/integration/ssrEffect.ts +31 -0
- package/dist/integration/styles.css +141 -0
- package/dist/plugins/baseUrls.ts +54 -0
- package/dist/plugins/buildConfig/index.ts +701 -0
- package/dist/plugins/buildConfig/injectRollupInputs.ts +36 -0
- package/dist/plugins/commonConfig.ts +112 -0
- package/dist/plugins/config/assertResolveAlias.ts +99 -0
- package/dist/plugins/config/assertRevealConfig.ts +116 -0
- package/dist/plugins/config/fixServerAssets.ts +213 -0
- package/dist/plugins/config/index.ts +227 -0
- package/dist/plugins/config/pickFirst.ts +3 -0
- package/dist/plugins/config/resolveBase.ts +78 -0
- package/dist/plugins/devConfig/determineFsAllowList.ts +34 -0
- package/dist/plugins/devConfig/determineOptimizeDeps.ts +129 -0
- package/dist/plugins/devConfig/index.ts +222 -0
- package/dist/plugins/distFileNames.ts +341 -0
- package/dist/plugins/envVars.ts +150 -0
- package/dist/plugins/extractAssetsPlugin.ts +318 -0
- package/dist/plugins/extractExportNamesPlugin.ts +154 -0
- package/dist/plugins/fileEnv.ts +374 -0
- package/dist/plugins/importBuild/getRevealManifest.ts +20 -0
- package/dist/plugins/importBuild/index.ts +120 -0
- package/dist/plugins/importUserCode/addImportStatement.ts +32 -0
- package/dist/plugins/importUserCode/debug.ts +2 -0
- package/dist/plugins/importUserCode/getConfigFileExport.ts +24 -0
- package/dist/plugins/importUserCode/getVirtualFilePageConfigValuesAll.ts +95 -0
- package/dist/plugins/importUserCode/getVirtualFilePageConfigs.ts +150 -0
- package/dist/plugins/importUserCode/index.ts +375 -0
- package/dist/plugins/importUserCode/isRuntimeEnvMatch.ts +31 -0
- package/dist/plugins/index.ts +233 -0
- package/dist/plugins/onLoad.ts +12 -0
- package/dist/plugins/packageJsonFile.ts +62 -0
- package/dist/plugins/payload/index.ts +62 -0
- package/dist/plugins/previewConfig.ts +95 -0
- package/dist/plugins/react/index.ts +72 -0
- package/dist/plugins/removeRequireHookPlugin.ts +27 -0
- package/dist/plugins/resolveClientEntriesDev.ts +87 -0
- package/dist/plugins/reveal/index.ts +39 -0
- package/dist/plugins/reveal/remove-use-client-server.ts +52 -0
- package/dist/plugins/setGlobalContext.ts +53 -0
- package/dist/plugins/suppressRollupWarning.ts +94 -0
- package/dist/plugins/utils.ts +33 -0
- package/dist/plugins/vercel/+config.ts +18 -0
- package/dist/plugins/vercel/functions/assert.ts +13 -0
- package/dist/plugins/vercel/functions/build.ts +484 -0
- package/dist/plugins/vercel/functions/config.ts +147 -0
- package/dist/plugins/vercel/functions/helpers.ts +70 -0
- package/dist/plugins/vercel/functions/prerender.ts +140 -0
- package/dist/plugins/vercel/functions/route-regex.ts +37 -0
- package/dist/plugins/vercel/functions/utils.ts +33 -0
- package/dist/plugins/vercel/functions/vike.ts +754 -0
- package/dist/plugins/vercel/index.ts +186 -0
- package/dist/plugins/vercel/plugin.ts +45 -0
- package/dist/plugins/vercel/schemas/config/prerender-config.ts +20 -0
- package/dist/plugins/vercel/schemas/config/vc-config.ts +45 -0
- package/dist/plugins/vercel/schemas/config/vercel.ts +130 -0
- package/dist/plugins/vercel/schemas/exports.ts +12 -0
- package/dist/plugins/vercel/templates/edge-helpers.ts +72 -0
- package/dist/plugins/vercel/templates/node-helpers.ts +60 -0
- package/dist/plugins/vercel/templates/ssr_.template.ts +25 -0
- package/dist/plugins/vercel/templates/ssr_edge_.template.ts +20 -0
- package/dist/plugins/vercel/templates/utils.ts +31 -0
- package/dist/plugins/workaroundCssModuleHmr.ts +23 -0
- package/dist/types/index.ts +50 -0
- package/dist/types/interfaces/app.ts +700 -0
- package/dist/types/interfaces/client.ts +10 -0
- package/dist/types/interfaces/config.ts +481 -0
- package/dist/types/interfaces/context.ts +677 -0
- package/dist/types/interfaces/error.ts +6 -0
- package/dist/types/interfaces/file.ts +98 -0
- package/dist/types/interfaces/host.ts +209 -0
- package/dist/types/interfaces/log.ts +3 -0
- package/dist/types/interfaces/logic.ts +46 -0
- package/dist/types/interfaces/manifest.ts +15 -0
- package/dist/types/interfaces/node.ts +8 -0
- package/dist/types/interfaces/page.ts +154 -0
- package/dist/types/interfaces/reveal.ts +118 -0
- package/dist/types/interfaces/tag.ts +3 -0
- package/dist/types/modules/assets.d.ts +57 -0
- package/dist/types/modules/env.d.ts +34 -0
- package/dist/types/modules/global.d.ts +10 -0
- package/dist/types/modules/index.d.ts +1 -0
- package/dist/types/modules/node.d.ts +2 -0
- package/dist/types/modules/payload.d.ts +2 -0
- package/dist/types/modules/reveal-vercel.d.ts +19 -0
- package/dist/types/modules/reveal.d.ts +1 -0
- package/dist/types/modules/stripe.d.ts +41 -0
- package/dist/types/modules/supabase.d.ts +19 -0
- package/dist/types/modules/tailwindcss.d.ts +49 -0
- package/dist/types/modules/vite.d.ts +7 -0
- package/dist/types/namespaces/Config.ts +291 -0
- package/dist/types/namespaces/PageContext.ts +23 -0
- package/dist/types/namespaces/RevealNamespace.ts +51 -0
- package/dist/types/namespaces/index.ts +3 -0
- package/dist/ui/accents/DiagonalGrid.tsx +36 -0
- package/dist/ui/accents/Glass.tsx +33 -0
- package/dist/ui/accents/Parallax.tsx +78 -0
- package/dist/ui/accents/Shadow.tsx +28 -0
- package/dist/ui/accents/index.tsx +4 -0
- package/dist/ui/accessibility/index.ts +168 -0
- package/dist/ui/ai/ChatGPTAssistant.tsx +113 -0
- package/dist/ui/ai/index.ts +3 -0
- package/dist/ui/animations/container.ts +7 -0
- package/dist/ui/animations/content.ts +16 -0
- package/dist/ui/animations/fade.ts +16 -0
- package/dist/ui/animations/index.ts +6 -0
- package/dist/ui/animations/slide.ts +23 -0
- package/dist/ui/animations/text.ts +14 -0
- package/dist/ui/animations/transition.ts +1 -0
- package/dist/ui/audio/AudioTrack.tsx +26 -0
- package/dist/ui/audio/index.tsx +1 -0
- package/dist/ui/backgrounds/Diagonal.tsx +46 -0
- package/dist/ui/backgrounds/GradientConic.tsx +21 -0
- package/dist/ui/backgrounds/GradientConicRev.tsx +50 -0
- package/dist/ui/backgrounds/GradientGlass.tsx +28 -0
- package/dist/ui/backgrounds/GradientRadial.tsx +37 -0
- package/dist/ui/backgrounds/GradientRadialLeft.tsx +33 -0
- package/dist/ui/backgrounds/GradientToBottom.tsx +59 -0
- package/dist/ui/backgrounds/GradientToTop.tsx +60 -0
- package/dist/ui/backgrounds/Solid.tsx +50 -0
- package/dist/ui/backgrounds/Straight.tsx +55 -0
- package/dist/ui/backgrounds/TopRight.tsx +15 -0
- package/dist/ui/backgrounds/Wrapper.tsx +33 -0
- package/dist/ui/backgrounds/index.tsx +12 -0
- package/dist/ui/buttons/Button.tsx +54 -0
- package/dist/ui/buttons/DisclosureButton.tsx +35 -0
- package/dist/ui/buttons/GradientButton.tsx +51 -0
- package/dist/ui/buttons/IconButton.tsx +24 -0
- package/dist/ui/buttons/LikeButton.tsx +221 -0
- package/dist/ui/buttons/MobileMenuButton.tsx +63 -0
- package/dist/ui/buttons/MusicButton.tsx +53 -0
- package/dist/ui/buttons/SignUpButton.tsx +18 -0
- package/dist/ui/buttons/index.tsx +8 -0
- package/dist/ui/cards/Card.tsx +255 -0
- package/dist/ui/cards/ProductCard.tsx +291 -0
- package/dist/ui/cards/VideoCard.tsx +201 -0
- package/dist/ui/cards/index.tsx +3 -0
- package/dist/ui/contexts/DisclosureContext.tsx +44 -0
- package/dist/ui/contexts/GlobalContext.tsx +67 -0
- package/dist/ui/contexts/MenuContext.tsx +8 -0
- package/dist/ui/contexts/PageContext.tsx +28 -0
- package/dist/ui/contexts/ThemeContext.tsx +195 -0
- package/dist/ui/controls/MusicHeader.tsx +484 -0
- package/dist/ui/controls/MusicPlayer.tsx +76 -0
- package/dist/ui/controls/MusicSidebar.tsx +118 -0
- package/dist/ui/controls/MusicSlider.tsx +25 -0
- package/dist/ui/controls/MusicUpload.tsx +296 -0
- package/dist/ui/controls/PlayPause.tsx +64 -0
- package/dist/ui/controls/PlayerContent.tsx +205 -0
- package/dist/ui/controls/SearchContent.tsx +58 -0
- package/dist/ui/controls/SearchInput.tsx +118 -0
- package/dist/ui/controls/Searchbar.tsx +53 -0
- package/dist/ui/controls/SidebarItem.tsx +57 -0
- package/dist/ui/controls/SongItem.tsx +45 -0
- package/dist/ui/controls/VideoPlayer.tsx +36 -0
- package/dist/ui/controls/index.tsx +13 -0
- package/dist/ui/dividers/Horizontal.tsx +18 -0
- package/dist/ui/dividers/Transparent.tsx +7 -0
- package/dist/ui/dividers/index.tsx +2 -0
- package/dist/ui/error/ErrorBoundary.tsx +150 -0
- package/dist/ui/error/index.tsx +1 -0
- package/dist/ui/forms/Input.tsx +38 -0
- package/dist/ui/forms/MediaItem.tsx +105 -0
- package/dist/ui/forms/index.tsx +2 -0
- package/dist/ui/game/Enemy.tsx +52 -0
- package/dist/ui/game/Fighters.tsx +38 -0
- package/dist/ui/game/GameControls.tsx +37 -0
- package/dist/ui/game/HealthBar.tsx +18 -0
- package/dist/ui/game/Player.tsx +70 -0
- package/dist/ui/game/index.tsx +5 -0
- package/dist/ui/hooks/useApiData.ts +57 -0
- package/dist/ui/hooks/useAuthModal.ts +18 -0
- package/dist/ui/hooks/useCart.ts +21 -0
- package/dist/ui/hooks/useChatGPT.ts +94 -0
- package/dist/ui/hooks/useCustomProps.ts +31 -0
- package/dist/ui/hooks/useData.ts +10 -0
- package/dist/ui/hooks/useDebounce.ts +52 -0
- package/dist/ui/hooks/useDisclosure.ts +8 -0
- package/dist/ui/hooks/useGame.ts +1147 -0
- package/dist/ui/hooks/useLayoutClasses.ts +70 -0
- package/dist/ui/hooks/useLazyLoad.ts +78 -0
- package/dist/ui/hooks/useLikeSong.ts +22 -0
- package/dist/ui/hooks/useLivePreview.ts +60 -0
- package/dist/ui/hooks/useMenu.ts +6 -0
- package/dist/ui/hooks/useOnPlay.ts +23 -0
- package/dist/ui/hooks/usePageContext.ts +174 -0
- package/dist/ui/hooks/useParallax.ts +161 -0
- package/dist/ui/hooks/usePreviewModal.ts +25 -0
- package/dist/ui/hooks/useScreenSize.ts +56 -0
- package/dist/ui/hooks/useTheme.ts +6 -0
- package/dist/ui/images/Carousel.tsx +326 -0
- package/dist/ui/images/Circle.tsx +9 -0
- package/dist/ui/images/Defs.tsx +7 -0
- package/dist/ui/images/Image.tsx +127 -0
- package/dist/ui/images/ImageGrid.tsx +73 -0
- package/dist/ui/images/Logo.tsx +22 -0
- package/dist/ui/images/Path.tsx +27 -0
- package/dist/ui/images/Pattern.tsx +70 -0
- package/dist/ui/images/PromoBanner.tsx +25 -0
- package/dist/ui/images/Rect.tsx +10 -0
- package/dist/ui/images/SVG.tsx +58 -0
- package/dist/ui/images/Stop.tsx +15 -0
- package/dist/ui/images/index.tsx +12 -0
- package/dist/ui/layouts/classNames.ts +8 -0
- package/dist/ui/layouts/container.ts +20 -0
- package/dist/ui/layouts/flex.ts +13 -0
- package/dist/ui/layouts/grid.ts +11 -0
- package/dist/ui/layouts/main.ts +31 -0
- package/dist/ui/layouts/responsive.ts +28 -0
- package/dist/ui/layouts/stack.ts +24 -0
- package/dist/ui/lists/DescriptionList.tsx +41 -0
- package/dist/ui/lists/DisclosurePanel.tsx +20 -0
- package/dist/ui/lists/JobOpeningsList.tsx +54 -0
- package/dist/ui/lists/List.tsx +18 -0
- package/dist/ui/lists/ListElements.tsx +43 -0
- package/dist/ui/lists/ListItem.tsx +63 -0
- package/dist/ui/lists/ProductList.tsx +37 -0
- package/dist/ui/lists/StatsList.tsx +64 -0
- package/dist/ui/lists/UList.tsx +54 -0
- package/dist/ui/lists/index.ts +9 -0
- package/dist/ui/navigation/DesktopMenu.tsx +14 -0
- package/dist/ui/navigation/Footer.tsx +128 -0
- package/dist/ui/navigation/Link.tsx +225 -0
- package/dist/ui/navigation/MobileMenu.tsx +26 -0
- package/dist/ui/navigation/NavigationLinks.tsx +244 -0
- package/dist/ui/navigation/NotFound.tsx +12 -0
- package/dist/ui/navigation/Route.tsx +120 -0
- package/dist/ui/navigation/Transition.tsx +40 -0
- package/dist/ui/navigation/index.tsx +8 -0
- package/dist/ui/notifications/Banner.tsx +69 -0
- package/dist/ui/notifications/Error.tsx +12 -0
- package/dist/ui/notifications/Loader.tsx +14 -0
- package/dist/ui/notifications/NoResults.tsx +11 -0
- package/dist/ui/notifications/index.tsx +4 -0
- package/dist/ui/providers/AppProvider.tsx +115 -0
- package/dist/ui/providers/DisclosureProvider.tsx +21 -0
- package/dist/ui/providers/MenuProvider.tsx +40 -0
- package/dist/ui/providers/PageContextProvider.tsx +176 -0
- package/dist/ui/providers/ThemeProvider.tsx +196 -0
- package/dist/ui/shells/App.tsx +57 -0
- package/dist/ui/shells/Container.tsx +74 -0
- package/dist/ui/shells/Disclosure.tsx +72 -0
- package/dist/ui/shells/Field.tsx +21 -0
- package/dist/ui/shells/Flex.tsx +193 -0
- package/dist/ui/shells/Grid.tsx +118 -0
- package/dist/ui/shells/Header.tsx +123 -0
- package/dist/ui/shells/Main.tsx +96 -0
- package/dist/ui/shells/Nav.tsx +138 -0
- package/dist/ui/shells/Section.tsx +94 -0
- package/dist/ui/shells/Skeleton.tsx +24 -0
- package/dist/ui/shells/index.ts +11 -0
- package/dist/ui/text/Article.tsx +141 -0
- package/dist/ui/text/Currency.tsx +29 -0
- package/dist/ui/text/Heading.tsx +29 -0
- package/dist/ui/text/Label.tsx +24 -0
- package/dist/ui/text/Motto.tsx +40 -0
- package/dist/ui/text/Paragraph.tsx +20 -0
- package/dist/ui/text/Span.tsx +20 -0
- package/dist/ui/text/TagLine.tsx +20 -0
- package/dist/ui/text/Time.tsx +36 -0
- package/dist/ui/text/WelcomeHeading.tsx +40 -0
- package/dist/ui/text/index.ts +10 -0
- package/dist/ui/video/VideoComponent.tsx +23 -0
- package/dist/ui/video/VideoDetail.tsx +33 -0
- package/dist/ui/video/VideoItem.tsx +51 -0
- package/dist/ui/video/VideoList.tsx +155 -0
- package/dist/ui/video/index.ts +4 -0
- package/package.json +721 -0
|
@@ -0,0 +1,254 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Result Type Adapters
|
|
3
|
+
*
|
|
4
|
+
* Adapter functions to convert Core UnifiedResult to other result types
|
|
5
|
+
* used throughout the codebase. Enables gradual migration to UnifiedResult.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import type {Result} from '../result';
|
|
9
|
+
import {isSuccess} from '../result';
|
|
10
|
+
import type {ApiResponse,ServiceResult} from '../types/contracts';
|
|
11
|
+
|
|
12
|
+
// Extended service result types
|
|
13
|
+
export interface ServiceContext {
|
|
14
|
+
serviceName?: string;
|
|
15
|
+
operation?: string;
|
|
16
|
+
userId?: string;
|
|
17
|
+
[key: string]: unknown;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
// Import ServiceMetrics from BaseService to avoid duplication
|
|
21
|
+
import type {ServiceMetrics} from '../services/BaseService';
|
|
22
|
+
|
|
23
|
+
export interface EnhancedServiceResult<T> {
|
|
24
|
+
success: boolean;
|
|
25
|
+
data?: T;
|
|
26
|
+
error?: string;
|
|
27
|
+
metadata?: Record<string, unknown>;
|
|
28
|
+
context?: ServiceContext;
|
|
29
|
+
metrics?: ServiceMetrics;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
// ApiMetadata type - defined inline if not available
|
|
33
|
+
export interface ApiMetadata {
|
|
34
|
+
requestId?: string;
|
|
35
|
+
timestamp?: Date;
|
|
36
|
+
version?: string;
|
|
37
|
+
[key: string]: unknown;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
// ======
|
|
41
|
+
// SERVICE RESULT ADAPTERS
|
|
42
|
+
// ======
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Convert Result<T, E> to ServiceResult<T>
|
|
46
|
+
* Simple adapter for basic service results
|
|
47
|
+
*/
|
|
48
|
+
export function toServiceResult<T, E = Error>(result: Result<T, E>): ServiceResult<T> {
|
|
49
|
+
if (isSuccess(result)) {
|
|
50
|
+
return {
|
|
51
|
+
success: true,
|
|
52
|
+
data: result.value,
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
return {
|
|
56
|
+
success: false,
|
|
57
|
+
error: result.error instanceof Error ? result.error.message : String(result.error),
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* Convert ServiceResult<T> to Result<T, Error>
|
|
63
|
+
*/
|
|
64
|
+
export function fromServiceResult<T>(serviceResult: ServiceResult<T>): Result<T, Error> {
|
|
65
|
+
if (serviceResult.success && serviceResult.data !== undefined) {
|
|
66
|
+
return { _tag: 'Success', value: serviceResult.data, success: true };
|
|
67
|
+
}
|
|
68
|
+
return {
|
|
69
|
+
_tag: 'Failure',
|
|
70
|
+
error: new Error(serviceResult.error ?? 'Unknown service error'),
|
|
71
|
+
success: false,
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
// ======
|
|
76
|
+
// ENHANCED SERVICE RESULT ADAPTERS
|
|
77
|
+
// ======
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* Convert Result<T, E> to EnhancedServiceResult<T>
|
|
81
|
+
* Includes metrics and context for infrastructure services
|
|
82
|
+
*/
|
|
83
|
+
export function toEnhancedServiceResult<T, E = Error>(
|
|
84
|
+
result: Result<T, E>,
|
|
85
|
+
metrics?: ServiceMetrics,
|
|
86
|
+
context?: ServiceContext
|
|
87
|
+
): EnhancedServiceResult<T> {
|
|
88
|
+
if (isSuccess(result)) {
|
|
89
|
+
return {
|
|
90
|
+
success: true,
|
|
91
|
+
data: result.value,
|
|
92
|
+
...(metrics ? { metadata: { ...metrics } as Record<string, unknown> } : {}),
|
|
93
|
+
...(context ? { context } : {}),
|
|
94
|
+
...(metrics ? { metrics } : {}),
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
const error = result.error instanceof Error ? result.error : new Error(String(result.error));
|
|
98
|
+
|
|
99
|
+
return {
|
|
100
|
+
success: false,
|
|
101
|
+
error: error.message || String(error),
|
|
102
|
+
metadata: {
|
|
103
|
+
code: 'SERVICE_ERROR',
|
|
104
|
+
details: error instanceof Error ? { stack: error.stack } : {},
|
|
105
|
+
timestamp: new Date(),
|
|
106
|
+
...(context ? { context } : {}),
|
|
107
|
+
...(error instanceof Error && error.stack ? { stack: error.stack } : {}),
|
|
108
|
+
...(metrics ? { metrics } : {}),
|
|
109
|
+
},
|
|
110
|
+
...(context ? { context } : {}),
|
|
111
|
+
...(metrics ? { metrics } : {}),
|
|
112
|
+
};
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
/**
|
|
116
|
+
* Convert EnhancedServiceResult<T> to Result<T, Error>
|
|
117
|
+
*/
|
|
118
|
+
export function fromEnhancedServiceResult<T>(
|
|
119
|
+
enhancedResult: EnhancedServiceResult<T>
|
|
120
|
+
): Result<T, Error> {
|
|
121
|
+
if (enhancedResult.success && enhancedResult.data !== undefined) {
|
|
122
|
+
return { _tag: 'Success', value: enhancedResult.data, success: true };
|
|
123
|
+
}
|
|
124
|
+
const error = enhancedResult.error
|
|
125
|
+
? new Error(
|
|
126
|
+
typeof enhancedResult.error === 'string'
|
|
127
|
+
? enhancedResult.error
|
|
128
|
+
: String(enhancedResult.error)
|
|
129
|
+
)
|
|
130
|
+
: new Error('Unknown service error');
|
|
131
|
+
return { _tag: 'Failure', error, success: false };
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
// ======
|
|
135
|
+
// API RESPONSE ADAPTERS
|
|
136
|
+
// ======
|
|
137
|
+
|
|
138
|
+
/**
|
|
139
|
+
* Convert Result<T, E> to ApiResponse<T>
|
|
140
|
+
* For presentation layer API responses
|
|
141
|
+
*/
|
|
142
|
+
export function toApiResponse<T, E = Error>(
|
|
143
|
+
result: Result<T, E>,
|
|
144
|
+
meta?: ApiMetadata
|
|
145
|
+
): ApiResponse<T> {
|
|
146
|
+
if (isSuccess(result)) {
|
|
147
|
+
return {
|
|
148
|
+
status: 200,
|
|
149
|
+
data: result.value,
|
|
150
|
+
...(meta ? { meta } : {}),
|
|
151
|
+
};
|
|
152
|
+
}
|
|
153
|
+
const error = result.error instanceof Error ? result.error : new Error(String(result.error));
|
|
154
|
+
// Using Record<string, unknown> because error may have statusCode property but structure varies
|
|
155
|
+
const errorRecord =
|
|
156
|
+
error as unknown as /* Using Record<string, unknown> because error may have statusCode property but structure varies */ Record<
|
|
157
|
+
string,
|
|
158
|
+
unknown
|
|
159
|
+
>;
|
|
160
|
+
const statusCode = (errorRecord.statusCode as number | undefined) || 500;
|
|
161
|
+
|
|
162
|
+
return {
|
|
163
|
+
status: statusCode,
|
|
164
|
+
error: error.message,
|
|
165
|
+
details: error instanceof Error ? { stack: error.stack } : {},
|
|
166
|
+
};
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
/**
|
|
170
|
+
* Convert ApiResponse<T> to Result<T, Error>
|
|
171
|
+
*/
|
|
172
|
+
export function fromApiResponse<T>(apiResponse: ApiResponse<T>): Result<T, Error> {
|
|
173
|
+
if (
|
|
174
|
+
(apiResponse.status === undefined || (apiResponse.status >= 200 && apiResponse.status < 300)) &&
|
|
175
|
+
apiResponse.data !== undefined
|
|
176
|
+
) {
|
|
177
|
+
return { _tag: 'Success', value: apiResponse.data, success: true };
|
|
178
|
+
}
|
|
179
|
+
const error = new Error(apiResponse.error ?? 'Unknown API error');
|
|
180
|
+
return { _tag: 'Failure', error, success: false };
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
// ======
|
|
184
|
+
// UTILITY FUNCTIONS
|
|
185
|
+
// ======
|
|
186
|
+
|
|
187
|
+
/**
|
|
188
|
+
* Create a success Result from a value
|
|
189
|
+
*/
|
|
190
|
+
export function successResult<T>(value: T): Result<T, never> {
|
|
191
|
+
return { _tag: 'Success', value, success: true };
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
/**
|
|
195
|
+
* Create a failure Result from an error
|
|
196
|
+
*/
|
|
197
|
+
export function failureResult<E>(error: E): Result<never, E> {
|
|
198
|
+
return { _tag: 'Failure', error, success: false };
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
/**
|
|
202
|
+
* Convert multiple Results to a single Result with array
|
|
203
|
+
*/
|
|
204
|
+
export function combineResults<T, E = Error>(results: Result<T, E>[]): Result<T[], E> {
|
|
205
|
+
const values: T[] = [];
|
|
206
|
+
const errors: E[] = [];
|
|
207
|
+
|
|
208
|
+
for (const result of results) {
|
|
209
|
+
if (isSuccess(result)) {
|
|
210
|
+
values.push(result.value);
|
|
211
|
+
} else {
|
|
212
|
+
errors.push(result.error);
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
if (errors.length > 0) {
|
|
217
|
+
// Return first error (could be enhanced to return all errors)
|
|
218
|
+
const firstError = errors[0];
|
|
219
|
+
if (firstError === undefined) {
|
|
220
|
+
// Type assertion needed because E could be any type, but we need to return something
|
|
221
|
+
return { _tag: 'Failure', error: new Error('Unknown error') as E, success: false };
|
|
222
|
+
}
|
|
223
|
+
return { _tag: 'Failure', error: firstError, success: false };
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
return { _tag: 'Success', value: values, success: true };
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
/**
|
|
230
|
+
* Convert Result to a promise that resolves with the value or rejects with error
|
|
231
|
+
*/
|
|
232
|
+
export async function resultToPromise<T, E = Error>(result: Result<T, E>): Promise<T> {
|
|
233
|
+
if (isSuccess(result)) {
|
|
234
|
+
return result.value;
|
|
235
|
+
}
|
|
236
|
+
throw result.error instanceof Error ? result.error : new Error(String(result.error));
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
/**
|
|
240
|
+
* Convert a promise to a Result
|
|
241
|
+
*/
|
|
242
|
+
export async function promiseToResult<T>(promise: Promise<T>): Promise<Result<T, Error>> {
|
|
243
|
+
try {
|
|
244
|
+
const value = await promise;
|
|
245
|
+
return { _tag: 'Success', value, success: true };
|
|
246
|
+
} catch (error) {
|
|
247
|
+
return {
|
|
248
|
+
_tag: 'Failure',
|
|
249
|
+
error: error instanceof Error ? error : new Error(String(error)),
|
|
250
|
+
success: false,
|
|
251
|
+
};
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
|
|
@@ -0,0 +1,332 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Unified Result Pattern
|
|
3
|
+
*
|
|
4
|
+
* Consolidates all result implementations into a single, comprehensive system.
|
|
5
|
+
* Combines the best features from all existing result implementations.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
// ======
|
|
9
|
+
// CORE TYPES
|
|
10
|
+
// ======
|
|
11
|
+
|
|
12
|
+
export type Success<T> = {
|
|
13
|
+
readonly _tag: 'Success';
|
|
14
|
+
readonly value: T;
|
|
15
|
+
readonly success: true;
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
export type Failure<E> = {
|
|
19
|
+
readonly _tag: 'Failure';
|
|
20
|
+
readonly error: E;
|
|
21
|
+
readonly success: false;
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
export type Result<T, E = Error> = Success<T> | Failure<E>;
|
|
25
|
+
|
|
26
|
+
// ======
|
|
27
|
+
// RESULT CLASSES
|
|
28
|
+
// ======
|
|
29
|
+
|
|
30
|
+
export class SuccessResult<T> implements Success<T> {
|
|
31
|
+
readonly _tag = 'Success' as const;
|
|
32
|
+
readonly success = true as const;
|
|
33
|
+
|
|
34
|
+
constructor(readonly value: T) {}
|
|
35
|
+
|
|
36
|
+
isSuccess(): this is Success<T> {
|
|
37
|
+
return true;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
isFailure(): this is never {
|
|
41
|
+
return false;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
map<U>(fn: (value: T) => U): Result<U, never> {
|
|
45
|
+
return new SuccessResult(fn(this.value));
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
flatMap<U, F>(fn: (value: T) => Result<U, F>): Result<U, F> {
|
|
49
|
+
return fn(this.value);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
getOrElse<U>(_defaultValue: U): T | U {
|
|
53
|
+
return this.value;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
getOrThrow(): T {
|
|
57
|
+
return this.value;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
tap(fn: (value: T) => void): Result<T, never> {
|
|
61
|
+
fn(this.value);
|
|
62
|
+
return this;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
mapError<F>(_fn: (error: never) => F): Result<T, F> {
|
|
66
|
+
return this as Result<T, F>;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
export class FailureResult<E> implements Failure<E> {
|
|
71
|
+
readonly _tag = 'Failure' as const;
|
|
72
|
+
readonly success = false as const;
|
|
73
|
+
|
|
74
|
+
constructor(readonly error: E) {}
|
|
75
|
+
|
|
76
|
+
isSuccess(): this is never {
|
|
77
|
+
return false;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
isFailure(): this is Failure<E> {
|
|
81
|
+
return true;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
map<U>(_fn: (value: never) => U): Result<never, E> {
|
|
85
|
+
return this as Result<never, E>;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
flatMap<U, F>(_fn: (value: never) => Result<U, F>): Result<never, E> {
|
|
89
|
+
return this as Result<never, E>;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
getOrElse<U>(defaultValue: U): U {
|
|
93
|
+
return defaultValue;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
getOrThrow(): never {
|
|
97
|
+
throw this.error instanceof Error ? this.error : new Error(String(this.error));
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
tap(fn: (error: E) => void): Result<never, E> {
|
|
101
|
+
fn(this.error);
|
|
102
|
+
return this;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
mapError<F>(fn: (error: E) => F): Result<never, F> {
|
|
106
|
+
return new FailureResult(fn(this.error));
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
// ======
|
|
111
|
+
// CONSTRUCTORS
|
|
112
|
+
// ======
|
|
113
|
+
|
|
114
|
+
export function success<T>(value: T): Result<T, never> {
|
|
115
|
+
return new SuccessResult(value);
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
export function failure<E>(error: E): Result<never, E> {
|
|
119
|
+
return new FailureResult(error);
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
export function ok<T>(value?: T): Result<T, never> {
|
|
123
|
+
return new SuccessResult(value as T);
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
export function fail<E>(error: E): Result<never, E> {
|
|
127
|
+
return new FailureResult(error);
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
// ======
|
|
131
|
+
// TYPE GUARDS
|
|
132
|
+
// ======
|
|
133
|
+
|
|
134
|
+
export function isSuccess<T, E>(result: Result<T, E>): result is Success<T> {
|
|
135
|
+
return result._tag === 'Success';
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
export function isFailure<T, E>(result: Result<T, E>): result is Failure<E> {
|
|
139
|
+
return result._tag === 'Failure';
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
// ======
|
|
143
|
+
// COMBINATORS
|
|
144
|
+
// ======
|
|
145
|
+
|
|
146
|
+
export function combine<T extends readonly unknown[], E>(
|
|
147
|
+
results: {
|
|
148
|
+
[K in keyof T]: Result<T[K], E>;
|
|
149
|
+
}
|
|
150
|
+
): Result<T, E> {
|
|
151
|
+
const values: unknown[] = [];
|
|
152
|
+
|
|
153
|
+
for (let i = 0; i < results.length; i++) {
|
|
154
|
+
const result = results[i];
|
|
155
|
+
if (result && isFailure(result)) {
|
|
156
|
+
return result as Result<T, E>;
|
|
157
|
+
}
|
|
158
|
+
if (result && isSuccess(result)) {
|
|
159
|
+
values[i] = result.value;
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
return success(values as unknown as T);
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
export function combineWithErrors<T extends readonly unknown[], E>(
|
|
167
|
+
results: {
|
|
168
|
+
[K in keyof T]: Result<T[K], E>;
|
|
169
|
+
}
|
|
170
|
+
): Result<T, E[]> {
|
|
171
|
+
const values: unknown[] = [];
|
|
172
|
+
const errors: E[] = [];
|
|
173
|
+
|
|
174
|
+
for (let i = 0; i < results.length; i++) {
|
|
175
|
+
const result = results[i];
|
|
176
|
+
if (result && isSuccess(result)) {
|
|
177
|
+
values[i] = result.value;
|
|
178
|
+
} else if (result && isFailure(result)) {
|
|
179
|
+
errors.push(result.error);
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
if (errors.length > 0) {
|
|
184
|
+
return failure(errors);
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
return success(values as unknown as T);
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
export function sequence<T, E>(results: Result<T, E>[]): Result<T[], E> {
|
|
191
|
+
const values: T[] = [];
|
|
192
|
+
|
|
193
|
+
for (const result of results) {
|
|
194
|
+
if (isFailure(result)) {
|
|
195
|
+
return result as Result<T[], E>;
|
|
196
|
+
}
|
|
197
|
+
if (isSuccess(result)) {
|
|
198
|
+
values.push(result.value);
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
return success(values);
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
export function traverse<T, U, E>(items: T[], fn: (item: T) => Result<U, E>): Result<U[], E> {
|
|
206
|
+
return sequence(items.map(fn));
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
// ======
|
|
210
|
+
// ASYNC UTILITIES
|
|
211
|
+
// ======
|
|
212
|
+
|
|
213
|
+
export async function fromPromise<T>(promise: Promise<T>): Promise<Result<T>> {
|
|
214
|
+
try {
|
|
215
|
+
const value = await promise;
|
|
216
|
+
return success(value);
|
|
217
|
+
} catch (error) {
|
|
218
|
+
return failure(error instanceof Error ? error : new Error(String(error)));
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
export function fromTryCatch<T>(fn: () => T): Result<T> {
|
|
223
|
+
try {
|
|
224
|
+
return success(fn());
|
|
225
|
+
} catch (error) {
|
|
226
|
+
return failure(error instanceof Error ? error : new Error(String(error)));
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
export async function fromTryCatchAsync<T>(fn: () => Promise<T>): Promise<Result<T>> {
|
|
231
|
+
try {
|
|
232
|
+
const value = await fn();
|
|
233
|
+
return success(value);
|
|
234
|
+
} catch (error) {
|
|
235
|
+
return failure(error instanceof Error ? error : new Error(String(error)));
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
// ======
|
|
240
|
+
// PATTERN MATCHING
|
|
241
|
+
// ======
|
|
242
|
+
|
|
243
|
+
export function match<T, E, R>(
|
|
244
|
+
result: Result<T, E>,
|
|
245
|
+
patterns: {
|
|
246
|
+
success: (value: T) => R;
|
|
247
|
+
failure: (error: E) => R;
|
|
248
|
+
}
|
|
249
|
+
): R {
|
|
250
|
+
if (isSuccess(result)) {
|
|
251
|
+
return patterns.success(result.value);
|
|
252
|
+
}
|
|
253
|
+
return patterns.failure(result.error);
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
// ======
|
|
257
|
+
// UTILITY FUNCTIONS
|
|
258
|
+
// ======
|
|
259
|
+
|
|
260
|
+
export function mapResult<T, U, E>(result: Result<T, E>, fn: (value: T) => U): Result<U, E> {
|
|
261
|
+
return result._tag === 'Success' ? success(fn(result.value)) : (result as Result<U, E>);
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
export function flatMapResult<T, U, E, F>(
|
|
265
|
+
result: Result<T, E>,
|
|
266
|
+
fn: (value: T) => Result<U, F>
|
|
267
|
+
): Result<U, E | F> {
|
|
268
|
+
return result._tag === 'Success' ? fn(result.value) : (result as Result<U, E | F>);
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
export function tapResult<T, E>(result: Result<T, E>, fn: (value: T) => void): Result<T, E> {
|
|
272
|
+
if (isSuccess(result)) {
|
|
273
|
+
fn(result.value);
|
|
274
|
+
}
|
|
275
|
+
return result;
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
export function mapErrorResult<T, E, F>(result: Result<T, E>, fn: (error: E) => F): Result<T, F> {
|
|
279
|
+
return result._tag === 'Failure' ? failure(fn(result.error)) : (result as Result<T, F>);
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
export function fromNullable<T>(value: T | null | undefined): Result<T> {
|
|
283
|
+
return value !== null && value !== undefined
|
|
284
|
+
? success(value)
|
|
285
|
+
: failure(new Error('Value is null or undefined'));
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
export function fromPredicate<T, E>(
|
|
289
|
+
value: T,
|
|
290
|
+
predicate: (value: T) => boolean,
|
|
291
|
+
error: E
|
|
292
|
+
): Result<T, E> {
|
|
293
|
+
return predicate(value) ? success(value) : failure(error);
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
export function recover<T, E, F>(
|
|
297
|
+
result: Result<T, E>,
|
|
298
|
+
fn: (error: E) => Result<T, F>
|
|
299
|
+
): Result<T, F> {
|
|
300
|
+
if (isSuccess(result)) {
|
|
301
|
+
return result as Result<T, F>;
|
|
302
|
+
}
|
|
303
|
+
return fn(result.error);
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
export function recoverWith<T, E>(result: Result<T, E>, defaultValue: T): Result<T, never> {
|
|
307
|
+
if (isSuccess(result)) {
|
|
308
|
+
return result;
|
|
309
|
+
}
|
|
310
|
+
return success(defaultValue);
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
/**
|
|
314
|
+
* Get value or default
|
|
315
|
+
*/
|
|
316
|
+
export function getOrElse<T, E>(result: Result<T, E>, defaultValue: T): T {
|
|
317
|
+
if (isSuccess(result)) {
|
|
318
|
+
return result.value;
|
|
319
|
+
}
|
|
320
|
+
return defaultValue;
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
/**
|
|
324
|
+
* Get value or throw
|
|
325
|
+
*/
|
|
326
|
+
export function getOrThrow<T, E>(result: Result<T, E>): T {
|
|
327
|
+
if (isSuccess(result)) {
|
|
328
|
+
return result.value;
|
|
329
|
+
}
|
|
330
|
+
throw result.error instanceof Error ? result.error : new Error(String(result.error));
|
|
331
|
+
}
|
|
332
|
+
|