@abide/abide 0.28.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/CHANGELOG.md +607 -0
- package/LICENSE +21 -0
- package/README.md +154 -0
- package/bin/abide.ts +212 -0
- package/package.json +155 -0
- package/src/abideLsp.ts +211 -0
- package/src/abideModules.d.ts +8 -0
- package/src/abideResolverPlugin.ts +923 -0
- package/src/appEntry.ts +151 -0
- package/src/assets/app.html +12 -0
- package/src/build.ts +143 -0
- package/src/buildCli.ts +127 -0
- package/src/buildDisconnected.ts +118 -0
- package/src/bundleApp.ts +147 -0
- package/src/bundleDisconnectedEntry.ts +14 -0
- package/src/checkAbide.ts +77 -0
- package/src/cliEntry.ts +25 -0
- package/src/clientBuildPlugins.ts +33 -0
- package/src/clientEntry.ts +17 -0
- package/src/compile.ts +63 -0
- package/src/controlServerWorker.ts +426 -0
- package/src/devEntry.ts +250 -0
- package/src/discoveryEntry.ts +81 -0
- package/src/lib/bundle/BundleMenu.ts +12 -0
- package/src/lib/bundle/BundleMenuItem.ts +25 -0
- package/src/lib/bundle/BundleWindow.ts +37 -0
- package/src/lib/bundle/WEBVIEW_BUILD_REVISION.ts +9 -0
- package/src/lib/bundle/WEBVIEW_VERSION.ts +7 -0
- package/src/lib/bundle/bindConnectedFlag.ts +29 -0
- package/src/lib/bundle/bindRequestNavigate.ts +34 -0
- package/src/lib/bundle/buildWebviewLib.ts +111 -0
- package/src/lib/bundle/bundled.ts +35 -0
- package/src/lib/bundle/disconnected.abide +236 -0
- package/src/lib/bundle/disconnected.css +9 -0
- package/src/lib/bundle/ensureWebviewLib.ts +20 -0
- package/src/lib/bundle/exitWithParent.ts +28 -0
- package/src/lib/bundle/infoPlist.ts +46 -0
- package/src/lib/bundle/installDownloads.ts +24 -0
- package/src/lib/bundle/installMacMenu.ts +39 -0
- package/src/lib/bundle/listenLocalControlServer.ts +19 -0
- package/src/lib/bundle/native/abideMenu.mm +422 -0
- package/src/lib/bundle/native/webview.h +4557 -0
- package/src/lib/bundle/onMenu.ts +42 -0
- package/src/lib/bundle/openWebview.ts +104 -0
- package/src/lib/bundle/pngToIcns.ts +47 -0
- package/src/lib/bundle/probeAbideServer.ts +57 -0
- package/src/lib/bundle/resolveServerBinary.ts +12 -0
- package/src/lib/bundle/resolveWebviewLib.ts +53 -0
- package/src/lib/bundle/serverBinaryFilename.ts +8 -0
- package/src/lib/bundle/signMacApp.ts +37 -0
- package/src/lib/bundle/spawnEmbeddedServer.ts +64 -0
- package/src/lib/bundle/stableLocalPort.ts +19 -0
- package/src/lib/bundle/waitForServer.ts +23 -0
- package/src/lib/bundle/webviewCachePath.ts +23 -0
- package/src/lib/bundle/webviewLibName.ts +11 -0
- package/src/lib/cli/connectToServer.ts +23 -0
- package/src/lib/cli/createClient.ts +108 -0
- package/src/lib/cli/dispatchCommand.ts +71 -0
- package/src/lib/cli/loadEnvFromBinaryDir.ts +15 -0
- package/src/lib/cli/parseArgvForRpc.ts +100 -0
- package/src/lib/cli/printHelp.ts +119 -0
- package/src/lib/cli/printSessionHelp.ts +27 -0
- package/src/lib/cli/printSessionStatus.ts +21 -0
- package/src/lib/cli/printTrimmed.ts +8 -0
- package/src/lib/cli/printValue.ts +10 -0
- package/src/lib/cli/resolveCliTarget.ts +48 -0
- package/src/lib/cli/runCli.ts +176 -0
- package/src/lib/cli/runSession.ts +108 -0
- package/src/lib/cli/startLocalInstance.ts +14 -0
- package/src/lib/cli/tokenizeLine.ts +51 -0
- package/src/lib/cli/types/CliManifest.ts +9 -0
- package/src/lib/cli/types/CliManifestEntry.ts +17 -0
- package/src/lib/cli/types/CliTarget.ts +13 -0
- package/src/lib/mcp/annotationsForMethod.ts +29 -0
- package/src/lib/mcp/createMcpResourceServer.ts +102 -0
- package/src/lib/mcp/createMcpServer.ts +48 -0
- package/src/lib/mcp/dispatchMcpRequest.ts +138 -0
- package/src/lib/mcp/mcpResourceServerSlot.ts +18 -0
- package/src/lib/mcp/mcpSurface.ts +295 -0
- package/src/lib/mcp/toolResultFromResponse.ts +66 -0
- package/src/lib/mcp/types/JsonRpcRequest.ts +12 -0
- package/src/lib/mcp/types/JsonRpcResponse.ts +20 -0
- package/src/lib/mcp/types/McpResourceContents.ts +10 -0
- package/src/lib/mcp/types/McpResourceDescriptor.ts +6 -0
- package/src/lib/mcp/types/McpResourceServer.ts +12 -0
- package/src/lib/mcp/types/McpServer.ts +9 -0
- package/src/lib/mcp/types/McpServerOptions.ts +16 -0
- package/src/lib/server/AppModule.ts +47 -0
- package/src/lib/server/DELETE.ts +10 -0
- package/src/lib/server/GET.ts +10 -0
- package/src/lib/server/HEAD.ts +10 -0
- package/src/lib/server/PATCH.ts +10 -0
- package/src/lib/server/POST.ts +10 -0
- package/src/lib/server/PUT.ts +10 -0
- package/src/lib/server/agent.ts +86 -0
- package/src/lib/server/appDataDir.ts +16 -0
- package/src/lib/server/cli/buildEnvContent.ts +19 -0
- package/src/lib/server/cli/createTarGz.ts +77 -0
- package/src/lib/server/cli/handleCliDownload.ts +150 -0
- package/src/lib/server/cli/handleCliInstall.ts +37 -0
- package/src/lib/server/cli/installScript.ts +31 -0
- package/src/lib/server/cli/maxSourceMtime.ts +26 -0
- package/src/lib/server/cookies.ts +30 -0
- package/src/lib/server/env.ts +51 -0
- package/src/lib/server/error.ts +73 -0
- package/src/lib/server/json.ts +42 -0
- package/src/lib/server/jsonl.ts +47 -0
- package/src/lib/server/prompts/definePrompt.ts +21 -0
- package/src/lib/server/prompts/promptRegistry.ts +9 -0
- package/src/lib/server/prompts/registerPrompt.ts +6 -0
- package/src/lib/server/prompts/renderPromptTemplate.ts +17 -0
- package/src/lib/server/prompts/types/Prompt.ts +13 -0
- package/src/lib/server/prompts/types/PromptOptions.ts +12 -0
- package/src/lib/server/prompts/types/PromptRegistryEntry.ts +13 -0
- package/src/lib/server/prompts/types/PromptRoutes.ts +10 -0
- package/src/lib/server/reachable.ts +45 -0
- package/src/lib/server/redirect.ts +43 -0
- package/src/lib/server/request.ts +19 -0
- package/src/lib/server/rpc/defineVerb.ts +210 -0
- package/src/lib/server/rpc/dispatchVerbInProcess.ts +46 -0
- package/src/lib/server/rpc/findVerbByCommandName.ts +18 -0
- package/src/lib/server/rpc/parseArgs.ts +127 -0
- package/src/lib/server/rpc/readBodyWithinLimit.ts +44 -0
- package/src/lib/server/rpc/registerVerb.ts +6 -0
- package/src/lib/server/rpc/runWithVerbTimeout.ts +49 -0
- package/src/lib/server/rpc/types/RemoteHandler.ts +27 -0
- package/src/lib/server/rpc/types/RemoteRoutes.ts +13 -0
- package/src/lib/server/rpc/types/TypedResponse.ts +18 -0
- package/src/lib/server/rpc/types/VerbHelper.ts +87 -0
- package/src/lib/server/rpc/types/VerbRegistryEntry.ts +35 -0
- package/src/lib/server/rpc/unprocessed.ts +14 -0
- package/src/lib/server/rpc/verbRegistry.ts +11 -0
- package/src/lib/server/runtime/DEFAULT_PORT.ts +6 -0
- package/src/lib/server/runtime/DEV_READY_MESSAGE.ts +6 -0
- package/src/lib/server/runtime/DEV_REBUILD_MESSAGE.ts +4 -0
- package/src/lib/server/runtime/DEV_RELOAD_CLIENT_SCRIPT.ts +107 -0
- package/src/lib/server/runtime/SSR_SWAP_SCRIPT.ts +16 -0
- package/src/lib/server/runtime/acceptsGzip.ts +24 -0
- package/src/lib/server/runtime/buildCacheSnapshot.ts +61 -0
- package/src/lib/server/runtime/buildHealthPayload.ts +34 -0
- package/src/lib/server/runtime/buildInspectorSurface.ts +37 -0
- package/src/lib/server/runtime/buildOpenApiSpec.ts +106 -0
- package/src/lib/server/runtime/cacheControlForAsset.ts +22 -0
- package/src/lib/server/runtime/containsTraversal.ts +37 -0
- package/src/lib/server/runtime/createAppAssetServer.ts +76 -0
- package/src/lib/server/runtime/createAssetHeaderCache.ts +31 -0
- package/src/lib/server/runtime/createPublicAssetServer.ts +67 -0
- package/src/lib/server/runtime/createReachable.ts +109 -0
- package/src/lib/server/runtime/createRouteDispatcher.ts +127 -0
- package/src/lib/server/runtime/createServer.ts +674 -0
- package/src/lib/server/runtime/createUiPageRenderer.ts +181 -0
- package/src/lib/server/runtime/crossOriginForbidden.ts +17 -0
- package/src/lib/server/runtime/crossOriginGate.ts +29 -0
- package/src/lib/server/runtime/devClientFingerprint.ts +117 -0
- package/src/lib/server/runtime/devHotModuleResponse.ts +40 -0
- package/src/lib/server/runtime/devReloadResponse.ts +41 -0
- package/src/lib/server/runtime/disableIdleTimeoutForStream.ts +27 -0
- package/src/lib/server/runtime/envSchemaStore.ts +15 -0
- package/src/lib/server/runtime/findOpenPort.ts +21 -0
- package/src/lib/server/runtime/getActiveServer.ts +6 -0
- package/src/lib/server/runtime/globToPathSet.ts +29 -0
- package/src/lib/server/runtime/gzipResponse.ts +46 -0
- package/src/lib/server/runtime/inProcessServer.ts +20 -0
- package/src/lib/server/runtime/internalErrorResponse.ts +25 -0
- package/src/lib/server/runtime/isCrossOriginRequest.ts +23 -0
- package/src/lib/server/runtime/listenOnOpenPort.ts +36 -0
- package/src/lib/server/runtime/logExposedSurfaces.ts +156 -0
- package/src/lib/server/runtime/maybeMountInspector.ts +97 -0
- package/src/lib/server/runtime/mimeForExtension.ts +14 -0
- package/src/lib/server/runtime/pageUrlFromStore.ts +15 -0
- package/src/lib/server/runtime/parseIdleTimeout.ts +10 -0
- package/src/lib/server/runtime/parsePort.ts +11 -0
- package/src/lib/server/runtime/registryManifests.ts +66 -0
- package/src/lib/server/runtime/requestContext.ts +5 -0
- package/src/lib/server/runtime/resolvePageSnapshot.ts +25 -0
- package/src/lib/server/runtime/respondWithEmbeddedAsset.ts +18 -0
- package/src/lib/server/runtime/runWithRequestScope.ts +150 -0
- package/src/lib/server/runtime/safeJsonForScript.ts +17 -0
- package/src/lib/server/runtime/serializeCacheSnapshot.ts +45 -0
- package/src/lib/server/runtime/serverSlot.ts +13 -0
- package/src/lib/server/runtime/setActiveServer.ts +6 -0
- package/src/lib/server/runtime/snapshotEntryFromCache.ts +83 -0
- package/src/lib/server/runtime/streamCacheResolutions.ts +37 -0
- package/src/lib/server/runtime/streamFromIterator.ts +86 -0
- package/src/lib/server/runtime/types/Assets.ts +6 -0
- package/src/lib/server/runtime/types/DevReloadStamp.ts +18 -0
- package/src/lib/server/runtime/types/InspectorCacheEntry.ts +24 -0
- package/src/lib/server/runtime/types/InspectorCacheSnapshot.ts +11 -0
- package/src/lib/server/runtime/types/InspectorContext.ts +30 -0
- package/src/lib/server/runtime/types/InspectorSocket.ts +17 -0
- package/src/lib/server/runtime/types/InspectorSurface.ts +13 -0
- package/src/lib/server/runtime/types/InspectorVerb.ts +27 -0
- package/src/lib/server/runtime/types/RequestStore.ts +55 -0
- package/src/lib/server/runtime/warnUnguardedMcp.ts +32 -0
- package/src/lib/server/runtime/withResponseDefaults.ts +24 -0
- package/src/lib/server/server.ts +33 -0
- package/src/lib/server/socket.ts +32 -0
- package/src/lib/server/sockets/createSocketDispatcher.ts +337 -0
- package/src/lib/server/sockets/defineSocket.ts +179 -0
- package/src/lib/server/sockets/lookupSocket.ts +6 -0
- package/src/lib/server/sockets/registerSocket.ts +6 -0
- package/src/lib/server/sockets/socketOperations.ts +36 -0
- package/src/lib/server/sockets/socketRegistry.ts +9 -0
- package/src/lib/server/sockets/types/Socket.ts +23 -0
- package/src/lib/server/sockets/types/SocketClientFrame.ts +19 -0
- package/src/lib/server/sockets/types/SocketOperation.ts +22 -0
- package/src/lib/server/sockets/types/SocketOptions.ts +26 -0
- package/src/lib/server/sockets/types/SocketRegistryEntry.ts +19 -0
- package/src/lib/server/sockets/types/SocketRoutes.ts +10 -0
- package/src/lib/server/sockets/types/SocketServerFrame.ts +24 -0
- package/src/lib/server/sse.ts +54 -0
- package/src/lib/shared/ABIDE_PACKAGE_NAME.ts +7 -0
- package/src/lib/shared/ABIDE_VERSION.ts +9 -0
- package/src/lib/shared/CACHE_CONTROL_VALUES.ts +16 -0
- package/src/lib/shared/CACHE_WRAPPED.ts +8 -0
- package/src/lib/shared/CLI_PATH.ts +7 -0
- package/src/lib/shared/DEV_HOT_PREFIX.ts +7 -0
- package/src/lib/shared/DEV_RELOAD_PATH.ts +6 -0
- package/src/lib/shared/HEALTH_PATH.ts +7 -0
- package/src/lib/shared/HttpError.ts +20 -0
- package/src/lib/shared/IDENTITY_PATH.ts +6 -0
- package/src/lib/shared/INSPECTOR_PATH.ts +7 -0
- package/src/lib/shared/NAV_HEADER.ts +8 -0
- package/src/lib/shared/OFFLINE_HEADER.ts +8 -0
- package/src/lib/shared/REMOTE_FUNCTION.ts +8 -0
- package/src/lib/shared/REPLAYABLE_METHODS.ts +12 -0
- package/src/lib/shared/SOCKETS_PATH.ts +7 -0
- package/src/lib/shared/STREAMING_CONTENT_TYPES.ts +11 -0
- package/src/lib/shared/SocketDisconnectedError.ts +13 -0
- package/src/lib/shared/TEXT_PLAIN.ts +7 -0
- package/src/lib/shared/abideImportName.ts +44 -0
- package/src/lib/shared/abideLog.ts +38 -0
- package/src/lib/shared/activeCacheStore.ts +20 -0
- package/src/lib/shared/activePage.ts +25 -0
- package/src/lib/shared/appDataDir.ts +34 -0
- package/src/lib/shared/appNameSlot.ts +10 -0
- package/src/lib/shared/basePath.ts +10 -0
- package/src/lib/shared/basePathFromAppUrl.ts +20 -0
- package/src/lib/shared/baseSlot.ts +14 -0
- package/src/lib/shared/binaryDirEnvPath.ts +12 -0
- package/src/lib/shared/browserClientFlags.ts +10 -0
- package/src/lib/shared/buildRpcProxy.ts +39 -0
- package/src/lib/shared/buildRpcRequest.ts +70 -0
- package/src/lib/shared/buildSocketOverChannel.ts +58 -0
- package/src/lib/shared/bundleLayout.ts +36 -0
- package/src/lib/shared/cache.ts +951 -0
- package/src/lib/shared/cacheEntryFromSnapshot.ts +59 -0
- package/src/lib/shared/cacheStoreSlot.ts +16 -0
- package/src/lib/shared/cacheStores.ts +10 -0
- package/src/lib/shared/canonicalJson.ts +63 -0
- package/src/lib/shared/carriesBodyArgs.ts +13 -0
- package/src/lib/shared/clearLastConnection.ts +7 -0
- package/src/lib/shared/commandNameForUrl.ts +17 -0
- package/src/lib/shared/createCacheStore.ts +104 -0
- package/src/lib/shared/createChannelLog.ts +122 -0
- package/src/lib/shared/createLifecycleChannel.ts +56 -0
- package/src/lib/shared/createLivenessWatch.ts +118 -0
- package/src/lib/shared/createPushIterator.ts +127 -0
- package/src/lib/shared/createRemoteFunction.ts +122 -0
- package/src/lib/shared/createSubscriber.ts +55 -0
- package/src/lib/shared/createTraceContext.ts +21 -0
- package/src/lib/shared/dataDirEnvPath.ts +12 -0
- package/src/lib/shared/decodeResponse.ts +47 -0
- package/src/lib/shared/detectTarget.ts +27 -0
- package/src/lib/shared/detectVerbMethod.ts +17 -0
- package/src/lib/shared/emitLogRecord.ts +190 -0
- package/src/lib/shared/exeSuffix.ts +9 -0
- package/src/lib/shared/exitOnBuildFailure.ts +17 -0
- package/src/lib/shared/extraForwardHeaders.ts +16 -0
- package/src/lib/shared/fileStem.ts +9 -0
- package/src/lib/shared/findExportCallSite.ts +476 -0
- package/src/lib/shared/formatTraceparent.ts +6 -0
- package/src/lib/shared/forwardHeaders.ts +44 -0
- package/src/lib/shared/getRemoteMeta.ts +5 -0
- package/src/lib/shared/globalCacheStore.ts +15 -0
- package/src/lib/shared/globalCacheStoreSlot.ts +14 -0
- package/src/lib/shared/health.ts +179 -0
- package/src/lib/shared/healthReadSlot.ts +11 -0
- package/src/lib/shared/healthSeedSlot.ts +12 -0
- package/src/lib/shared/html.ts +38 -0
- package/src/lib/shared/importNamesToStrip.ts +13 -0
- package/src/lib/shared/invalidateEvent.ts +11 -0
- package/src/lib/shared/invalidateTripwire.ts +40 -0
- package/src/lib/shared/isAbideHealthPayload.ts +11 -0
- package/src/lib/shared/isCompileTarget.ts +15 -0
- package/src/lib/shared/isDebugEnabled.ts +26 -0
- package/src/lib/shared/isDebugNegated.ts +19 -0
- package/src/lib/shared/isModuleNotFound.ts +16 -0
- package/src/lib/shared/isReadOnlyMethod.ts +14 -0
- package/src/lib/shared/isReplayableMethod.ts +7 -0
- package/src/lib/shared/isStreamingResponse.ts +11 -0
- package/src/lib/shared/isSubscribable.ts +15 -0
- package/src/lib/shared/jsonSchemaForPromptArguments.ts +29 -0
- package/src/lib/shared/jsonSchemaForSchema.ts +39 -0
- package/src/lib/shared/jsonlErrorFrame.ts +24 -0
- package/src/lib/shared/keyForRemoteCall.ts +29 -0
- package/src/lib/shared/keyMatchesPrefix.ts +9 -0
- package/src/lib/shared/lastConnectionPath.ts +7 -0
- package/src/lib/shared/layoutChainForRoute.ts +22 -0
- package/src/lib/shared/loadEnvFile.ts +17 -0
- package/src/lib/shared/loadEnvFromDataDir.ts +14 -0
- package/src/lib/shared/log.ts +24 -0
- package/src/lib/shared/logClosingRecord.ts +28 -0
- package/src/lib/shared/logTapSlot.ts +13 -0
- package/src/lib/shared/manifestModule.ts +39 -0
- package/src/lib/shared/matchesDebugPattern.ts +16 -0
- package/src/lib/shared/memoizeByKey.ts +32 -0
- package/src/lib/shared/normalizeTarget.ts +10 -0
- package/src/lib/shared/online.ts +51 -0
- package/src/lib/shared/page.ts +30 -0
- package/src/lib/shared/pageSlot.ts +17 -0
- package/src/lib/shared/pageUrlForFile.ts +14 -0
- package/src/lib/shared/parseBoundedEnvInt.ts +20 -0
- package/src/lib/shared/parseDebugPatterns.ts +21 -0
- package/src/lib/shared/parseEnv.ts +30 -0
- package/src/lib/shared/parsePromptMarkdown.ts +35 -0
- package/src/lib/shared/parseRouteSegments.ts +22 -0
- package/src/lib/shared/parseTraceparent.ts +26 -0
- package/src/lib/shared/pending.ts +30 -0
- package/src/lib/shared/prepareRpcModule.ts +59 -0
- package/src/lib/shared/prepareSocketModule.ts +49 -0
- package/src/lib/shared/probeRegistries.ts +68 -0
- package/src/lib/shared/producerKey.ts +32 -0
- package/src/lib/shared/programNameForPackage.ts +14 -0
- package/src/lib/shared/promptNameForFile.ts +10 -0
- package/src/lib/shared/queryStringFromArgs.ts +27 -0
- package/src/lib/shared/randomHexId.ts +14 -0
- package/src/lib/shared/readEnvFile.ts +15 -0
- package/src/lib/shared/readLastConnection.ts +18 -0
- package/src/lib/shared/readPackageJson.ts +9 -0
- package/src/lib/shared/recordRemoteMeta.ts +5 -0
- package/src/lib/shared/refreshing.ts +31 -0
- package/src/lib/shared/remoteMetaStore.ts +16 -0
- package/src/lib/shared/requestScopeSlot.ts +15 -0
- package/src/lib/shared/resolveClientFlags.ts +20 -0
- package/src/lib/shared/responseErrorText.ts +9 -0
- package/src/lib/shared/rpcTimeoutSlot.ts +9 -0
- package/src/lib/shared/rpcUrlForFile.ts +19 -0
- package/src/lib/shared/runningAsStandaloneBinary.ts +13 -0
- package/src/lib/shared/selectorMatcher.ts +68 -0
- package/src/lib/shared/selectorPrefix.ts +39 -0
- package/src/lib/shared/serializeEnv.ts +18 -0
- package/src/lib/shared/setAppName.ts +5 -0
- package/src/lib/shared/setBaseResolver.ts +6 -0
- package/src/lib/shared/setCacheStoreResolver.ts +6 -0
- package/src/lib/shared/setGlobalCacheStoreResolver.ts +6 -0
- package/src/lib/shared/setPageResolver.ts +7 -0
- package/src/lib/shared/setRequestScopeResolver.ts +6 -0
- package/src/lib/shared/snippet.ts +25 -0
- package/src/lib/shared/socketNameForFile.ts +11 -0
- package/src/lib/shared/socketTapSlot.ts +12 -0
- package/src/lib/shared/sseErrorFrame.ts +29 -0
- package/src/lib/shared/streamResponse.ts +169 -0
- package/src/lib/shared/stripImport.ts +27 -0
- package/src/lib/shared/subscribableFromResponse.ts +51 -0
- package/src/lib/shared/tailProbeSlot.ts +16 -0
- package/src/lib/shared/toBunRoutePattern.ts +28 -0
- package/src/lib/shared/toScopeSet.ts +4 -0
- package/src/lib/shared/trace.ts +16 -0
- package/src/lib/shared/types/CacheEntry.ts +84 -0
- package/src/lib/shared/types/CacheInvalidation.ts +9 -0
- package/src/lib/shared/types/CacheOnContext.ts +25 -0
- package/src/lib/shared/types/CacheOptions.ts +39 -0
- package/src/lib/shared/types/CacheSelector.ts +17 -0
- package/src/lib/shared/types/CacheSnapshot.ts +16 -0
- package/src/lib/shared/types/CacheSnapshotEntry.ts +17 -0
- package/src/lib/shared/types/CacheStats.ts +13 -0
- package/src/lib/shared/types/CacheStore.ts +39 -0
- package/src/lib/shared/types/ChannelLog.ts +13 -0
- package/src/lib/shared/types/ClientFlags.ts +11 -0
- package/src/lib/shared/types/CompileTarget.ts +6 -0
- package/src/lib/shared/types/FrameworkLog.ts +13 -0
- package/src/lib/shared/types/HttpVerb.ts +1 -0
- package/src/lib/shared/types/LastConnection.ts +9 -0
- package/src/lib/shared/types/Log.ts +13 -0
- package/src/lib/shared/types/LogRecord.ts +42 -0
- package/src/lib/shared/types/LogVoice.ts +7 -0
- package/src/lib/shared/types/PageSnapshot.ts +14 -0
- package/src/lib/shared/types/PromptArgument.ts +12 -0
- package/src/lib/shared/types/RawRemoteFunction.ts +14 -0
- package/src/lib/shared/types/RemoteCallable.ts +12 -0
- package/src/lib/shared/types/RemoteFunction.ts +47 -0
- package/src/lib/shared/types/ReplayableMethod.ts +7 -0
- package/src/lib/shared/types/RequestScopeInfo.ts +16 -0
- package/src/lib/shared/types/RpcInvoker.ts +6 -0
- package/src/lib/shared/types/SocketChannel.ts +17 -0
- package/src/lib/shared/types/SocketSubCallbacks.ts +13 -0
- package/src/lib/shared/types/StandardSchemaV1.ts +56 -0
- package/src/lib/shared/types/StreamedResolution.ts +10 -0
- package/src/lib/shared/types/Subscribable.ts +26 -0
- package/src/lib/shared/types/TailHooks.ts +12 -0
- package/src/lib/shared/types/TailOptions.ts +10 -0
- package/src/lib/shared/types/TraceContext.ts +17 -0
- package/src/lib/shared/url.ts +118 -0
- package/src/lib/shared/withBase.ts +11 -0
- package/src/lib/shared/withBaseUrl.ts +17 -0
- package/src/lib/shared/withJsonSchema.ts +21 -0
- package/src/lib/shared/writeDts.ts +12 -0
- package/src/lib/shared/writeHealthDts.ts +36 -0
- package/src/lib/shared/writeLastConnection.ts +13 -0
- package/src/lib/shared/writePublicAssetsDts.ts +31 -0
- package/src/lib/shared/writeRoutesDts.ts +73 -0
- package/src/lib/shared/writeRpcDts.ts +49 -0
- package/src/lib/shared/writeTestRpcDts.ts +45 -0
- package/src/lib/shared/writeTestSocketsDts.ts +34 -0
- package/src/lib/test/assertAgentFrameConformance.ts +73 -0
- package/src/lib/test/createScriptedSurface.ts +45 -0
- package/src/lib/test/createTestApp.ts +203 -0
- package/src/lib/test/createTestSocketChannel.ts +142 -0
- package/src/lib/ui/README.md +86 -0
- package/src/lib/ui/compile/SSR_ESCAPE.ts +25 -0
- package/src/lib/ui/compile/UI_RUNTIME_IMPORTS.ts +36 -0
- package/src/lib/ui/compile/VOID_TAGS.ts +21 -0
- package/src/lib/ui/compile/abideUiPlugin.ts +65 -0
- package/src/lib/ui/compile/analyzeComponent.ts +117 -0
- package/src/lib/ui/compile/assetModulesFile.ts +32 -0
- package/src/lib/ui/compile/branchElements.ts +50 -0
- package/src/lib/ui/compile/collectAbideDiagnostics.ts +59 -0
- package/src/lib/ui/compile/compileComponent.ts +20 -0
- package/src/lib/ui/compile/compileModule.ts +116 -0
- package/src/lib/ui/compile/compileSSR.ts +36 -0
- package/src/lib/ui/compile/compileShadow.ts +352 -0
- package/src/lib/ui/compile/createShadowLanguageService.ts +197 -0
- package/src/lib/ui/compile/createShadowProgram.ts +96 -0
- package/src/lib/ui/compile/decodeHtmlEntities.ts +49 -0
- package/src/lib/ui/compile/desugarSignals.ts +133 -0
- package/src/lib/ui/compile/escapeHtml.ts +15 -0
- package/src/lib/ui/compile/generateBuild.ts +638 -0
- package/src/lib/ui/compile/generateSSR.ts +380 -0
- package/src/lib/ui/compile/groupBindParts.ts +28 -0
- package/src/lib/ui/compile/hoistCells.ts +120 -0
- package/src/lib/ui/compile/loadShadowTsConfig.ts +31 -0
- package/src/lib/ui/compile/lowerDocAccess.ts +202 -0
- package/src/lib/ui/compile/nearestProjectRoot.ts +16 -0
- package/src/lib/ui/compile/parseTemplate.ts +396 -0
- package/src/lib/ui/compile/partitionSlots.ts +36 -0
- package/src/lib/ui/compile/prepareNestedScript.ts +42 -0
- package/src/lib/ui/compile/remapShadowDiagnostic.ts +30 -0
- package/src/lib/ui/compile/renameSignalRefs.ts +85 -0
- package/src/lib/ui/compile/resolveAbideImports.ts +29 -0
- package/src/lib/ui/compile/scopeCss.ts +115 -0
- package/src/lib/ui/compile/shadowNaming.ts +11 -0
- package/src/lib/ui/compile/sourceToShadowOffset.ts +24 -0
- package/src/lib/ui/compile/staticAttrValue.ts +13 -0
- package/src/lib/ui/compile/stripEffects.ts +32 -0
- package/src/lib/ui/compile/types/AbideDiagnostic.ts +14 -0
- package/src/lib/ui/compile/types/AnalyzedComponent.ts +25 -0
- package/src/lib/ui/compile/types/CompiledShadow.ts +15 -0
- package/src/lib/ui/compile/types/TemplateAttr.ts +16 -0
- package/src/lib/ui/compile/types/TemplateNode.ts +78 -0
- package/src/lib/ui/compile/types/TextPart.ts +8 -0
- package/src/lib/ui/derived.ts +28 -0
- package/src/lib/ui/doc.ts +15 -0
- package/src/lib/ui/dom/appendSnippet.ts +34 -0
- package/src/lib/ui/dom/appendStatic.ts +27 -0
- package/src/lib/ui/dom/appendText.ts +114 -0
- package/src/lib/ui/dom/applyResolved.ts +72 -0
- package/src/lib/ui/dom/attach.ts +20 -0
- package/src/lib/ui/dom/attr.ts +19 -0
- package/src/lib/ui/dom/awaitBlock.ts +224 -0
- package/src/lib/ui/dom/cloneStatic.ts +52 -0
- package/src/lib/ui/dom/each.ts +115 -0
- package/src/lib/ui/dom/eachAsync.ts +153 -0
- package/src/lib/ui/dom/hydrate.ts +35 -0
- package/src/lib/ui/dom/mount.ts +29 -0
- package/src/lib/ui/dom/mountChild.ts +33 -0
- package/src/lib/ui/dom/on.ts +15 -0
- package/src/lib/ui/dom/openChild.ts +22 -0
- package/src/lib/ui/dom/openRoot.ts +20 -0
- package/src/lib/ui/dom/switchBlock.ts +75 -0
- package/src/lib/ui/dom/text.ts +20 -0
- package/src/lib/ui/dom/tryBlock.ts +112 -0
- package/src/lib/ui/dom/types/EachRow.ts +3 -0
- package/src/lib/ui/dom/types/SwitchCase.ts +6 -0
- package/src/lib/ui/dom/when.ts +73 -0
- package/src/lib/ui/effect.ts +16 -0
- package/src/lib/ui/installHotBridge.ts +73 -0
- package/src/lib/ui/matchRoute.ts +89 -0
- package/src/lib/ui/navigate.ts +17 -0
- package/src/lib/ui/probeNavigation.ts +33 -0
- package/src/lib/ui/remoteProxy.ts +97 -0
- package/src/lib/ui/renderChain.ts +50 -0
- package/src/lib/ui/renderToStream.ts +104 -0
- package/src/lib/ui/router.ts +286 -0
- package/src/lib/ui/runtime/OUTLET_TAG.ts +8 -0
- package/src/lib/ui/runtime/OWNER.ts +8 -0
- package/src/lib/ui/runtime/REACTIVE_CONTEXT.ts +14 -0
- package/src/lib/ui/runtime/RENDER.ts +23 -0
- package/src/lib/ui/runtime/RESUME.ts +16 -0
- package/src/lib/ui/runtime/applyPatchToTree.ts +41 -0
- package/src/lib/ui/runtime/claimChild.ts +10 -0
- package/src/lib/ui/runtime/clientPage.ts +16 -0
- package/src/lib/ui/runtime/createComputedNode.ts +16 -0
- package/src/lib/ui/runtime/createDoc.ts +177 -0
- package/src/lib/ui/runtime/createEffectNode.ts +58 -0
- package/src/lib/ui/runtime/createSignalNode.ts +16 -0
- package/src/lib/ui/runtime/detachLink.ts +21 -0
- package/src/lib/ui/runtime/endTracking.ts +24 -0
- package/src/lib/ui/runtime/enterRenderPass.ts +12 -0
- package/src/lib/ui/runtime/exitRenderPass.ts +7 -0
- package/src/lib/ui/runtime/firstOutlet.ts +22 -0
- package/src/lib/ui/runtime/flushEffects.ts +17 -0
- package/src/lib/ui/runtime/hotInstances.ts +10 -0
- package/src/lib/ui/runtime/hotReloadEnabled.ts +8 -0
- package/src/lib/ui/runtime/hotReplace.ts +25 -0
- package/src/lib/ui/runtime/nextBlockId.ts +11 -0
- package/src/lib/ui/runtime/pathExists.ts +23 -0
- package/src/lib/ui/runtime/readNode.ts +17 -0
- package/src/lib/ui/runtime/registerHotInstance.ts +23 -0
- package/src/lib/ui/runtime/runNode.ts +28 -0
- package/src/lib/ui/runtime/runtimePath.ts +9 -0
- package/src/lib/ui/runtime/scope.ts +24 -0
- package/src/lib/ui/runtime/toTeardown.ts +26 -0
- package/src/lib/ui/runtime/track.ts +58 -0
- package/src/lib/ui/runtime/trigger.ts +44 -0
- package/src/lib/ui/runtime/types/Cell.ts +5 -0
- package/src/lib/ui/runtime/types/Derived.ts +3 -0
- package/src/lib/ui/runtime/types/Doc.ts +19 -0
- package/src/lib/ui/runtime/types/EffectResult.ts +10 -0
- package/src/lib/ui/runtime/types/HotInstance.ts +14 -0
- package/src/lib/ui/runtime/types/NavVerdict.ts +9 -0
- package/src/lib/ui/runtime/types/Patch.ts +11 -0
- package/src/lib/ui/runtime/types/ReactiveLink.ts +21 -0
- package/src/lib/ui/runtime/types/ReactiveNode.ts +25 -0
- package/src/lib/ui/runtime/types/Route.ts +8 -0
- package/src/lib/ui/runtime/types/RouteLoader.ts +7 -0
- package/src/lib/ui/runtime/types/SsrRender.ts +22 -0
- package/src/lib/ui/runtime/types/State.ts +3 -0
- package/src/lib/ui/runtime/types/Teardown.ts +5 -0
- package/src/lib/ui/runtime/types/UiComponent.ts +16 -0
- package/src/lib/ui/runtime/types/UiProps.ts +15 -0
- package/src/lib/ui/runtime/unlinkDeps.ts +20 -0
- package/src/lib/ui/runtime/untrack.ts +20 -0
- package/src/lib/ui/runtime/valueAtPath.ts +18 -0
- package/src/lib/ui/runtime/writeNode.ts +16 -0
- package/src/lib/ui/socketChannel.ts +227 -0
- package/src/lib/ui/socketProxy.ts +25 -0
- package/src/lib/ui/startClient.ts +58 -0
- package/src/lib/ui/state.ts +25 -0
- package/src/lib/ui/tail.ts +324 -0
- package/src/lib/ui/types/Layouts.ts +9 -0
- package/src/lib/ui/types/Pages.ts +8 -0
- package/src/preload.ts +19 -0
- package/src/scaffold.ts +153 -0
- package/src/serverBuildPlugins.ts +19 -0
- package/src/serverEntry.ts +95 -0
- package/template/bunfig.toml +4 -0
- package/template/package.json +18 -0
- package/template/src/app.ts +28 -0
- package/template/src/bundle/icon.png +0 -0
- package/template/src/cli/banner.txt +3 -0
- package/template/src/cli/footer.txt +1 -0
- package/template/src/server/config.ts +17 -0
- package/template/src/server/rpc/getHello.ts +36 -0
- package/template/src/ui/Layout.abide +19 -0
- package/template/src/ui/app.css +21 -0
- package/template/src/ui/app.html +24 -0
- package/template/src/ui/pages/about/page.abide +9 -0
- package/template/src/ui/pages/page.abide +22 -0
- package/template/test/app.test.ts +30 -0
- package/template/tsconfig.json +18 -0
- package/tsconfig.app.json +17 -0
|
@@ -0,0 +1,476 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Scans a module source character-by-character — skipping strings,
|
|
3
|
+
templates, comments, and TypeScript generics — for an
|
|
4
|
+
`export const <name> = <IDENT>(...)` binding the caller cares about.
|
|
5
|
+
On a match returns the identifier text, the export name, and the byte
|
|
6
|
+
ranges of the call's open and close parens; the $rpc and $sockets
|
|
7
|
+
rewriters splice their runtime bindings into those ranges.
|
|
8
|
+
|
|
9
|
+
The scanner enforces a single matching export per module: a second match
|
|
10
|
+
throws `singleExportError` so each $rpc / $sockets file is required to
|
|
11
|
+
declare exactly one remote function / socket.
|
|
12
|
+
|
|
13
|
+
A regex pass would be tidier but it can't tell a `GET` mention inside a
|
|
14
|
+
docstring or template literal from the real call, and it can't follow
|
|
15
|
+
nested generics like `GET<Map<K, V>>(`.
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
export type ExportCallSite = {
|
|
19
|
+
ident: string
|
|
20
|
+
exportName: string
|
|
21
|
+
callStart: number
|
|
22
|
+
parenStart: number
|
|
23
|
+
parenEnd: number
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export function findExportCallSite(
|
|
27
|
+
source: string,
|
|
28
|
+
matchIdent: (ident: string) => boolean,
|
|
29
|
+
singleExportError: string,
|
|
30
|
+
): ExportCallSite | undefined {
|
|
31
|
+
let found: ExportCallSite | undefined
|
|
32
|
+
const len = source.length
|
|
33
|
+
let i = 0
|
|
34
|
+
while (i < len) {
|
|
35
|
+
const c = source[i]
|
|
36
|
+
const afterSlash = skipSlashConstruct(source, i)
|
|
37
|
+
if (afterSlash !== undefined) {
|
|
38
|
+
i = afterSlash
|
|
39
|
+
continue
|
|
40
|
+
}
|
|
41
|
+
if (c === '"' || c === "'") {
|
|
42
|
+
i = skipString(source, i + 1, c)
|
|
43
|
+
continue
|
|
44
|
+
}
|
|
45
|
+
if (c === '`') {
|
|
46
|
+
i = skipTemplate(source, i + 1)
|
|
47
|
+
continue
|
|
48
|
+
}
|
|
49
|
+
if (isIdentStart(c) && !isIdentPart(source[i - 1])) {
|
|
50
|
+
let j = i + 1
|
|
51
|
+
while (j < len && isIdentPart(source[j])) {
|
|
52
|
+
j++
|
|
53
|
+
}
|
|
54
|
+
const ident = source.slice(i, j)
|
|
55
|
+
if (matchIdent(ident)) {
|
|
56
|
+
const tail = matchCallTail(source, j)
|
|
57
|
+
if (tail !== undefined) {
|
|
58
|
+
const exportName = detectExportName(source, i)
|
|
59
|
+
if (exportName !== undefined) {
|
|
60
|
+
if (found !== undefined) {
|
|
61
|
+
throw new Error(singleExportError)
|
|
62
|
+
}
|
|
63
|
+
const parenEnd = findCallEnd(source, tail)
|
|
64
|
+
if (parenEnd === undefined) {
|
|
65
|
+
throw new Error(`[abide] unmatched \`(\` after \`${ident}\` identifier`)
|
|
66
|
+
}
|
|
67
|
+
found = {
|
|
68
|
+
ident,
|
|
69
|
+
exportName,
|
|
70
|
+
callStart: i,
|
|
71
|
+
parenStart: tail,
|
|
72
|
+
parenEnd,
|
|
73
|
+
}
|
|
74
|
+
i = parenEnd + 1
|
|
75
|
+
continue
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
i = j
|
|
80
|
+
continue
|
|
81
|
+
}
|
|
82
|
+
i++
|
|
83
|
+
}
|
|
84
|
+
return found
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
function skipString(source: string, start: number, quote: string): number {
|
|
88
|
+
let i = start
|
|
89
|
+
while (i < source.length) {
|
|
90
|
+
const c = source[i]
|
|
91
|
+
if (c === '\\') {
|
|
92
|
+
i += 2
|
|
93
|
+
continue
|
|
94
|
+
}
|
|
95
|
+
if (c === quote) {
|
|
96
|
+
return i + 1
|
|
97
|
+
}
|
|
98
|
+
if (c === '\n') {
|
|
99
|
+
return i
|
|
100
|
+
}
|
|
101
|
+
i++
|
|
102
|
+
}
|
|
103
|
+
return source.length
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
function skipTemplate(source: string, start: number): number {
|
|
107
|
+
let i = start
|
|
108
|
+
while (i < source.length) {
|
|
109
|
+
const c = source[i]
|
|
110
|
+
if (c === '\\') {
|
|
111
|
+
i += 2
|
|
112
|
+
continue
|
|
113
|
+
}
|
|
114
|
+
if (c === '`') {
|
|
115
|
+
return i + 1
|
|
116
|
+
}
|
|
117
|
+
if (c === '$' && source[i + 1] === '{') {
|
|
118
|
+
i = skipTemplateExpression(source, i + 2)
|
|
119
|
+
continue
|
|
120
|
+
}
|
|
121
|
+
i++
|
|
122
|
+
}
|
|
123
|
+
return source.length
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
function skipTemplateExpression(source: string, start: number): number {
|
|
127
|
+
let depth = 1
|
|
128
|
+
let i = start
|
|
129
|
+
while (i < source.length && depth > 0) {
|
|
130
|
+
const c = source[i]
|
|
131
|
+
if (c === '{') {
|
|
132
|
+
depth++
|
|
133
|
+
i++
|
|
134
|
+
continue
|
|
135
|
+
}
|
|
136
|
+
if (c === '}') {
|
|
137
|
+
depth--
|
|
138
|
+
i++
|
|
139
|
+
continue
|
|
140
|
+
}
|
|
141
|
+
if (c === '"' || c === "'") {
|
|
142
|
+
i = skipString(source, i + 1, c)
|
|
143
|
+
continue
|
|
144
|
+
}
|
|
145
|
+
if (c === '`') {
|
|
146
|
+
i = skipTemplate(source, i + 1)
|
|
147
|
+
continue
|
|
148
|
+
}
|
|
149
|
+
const afterSlash = skipSlashConstruct(source, i)
|
|
150
|
+
if (afterSlash !== undefined) {
|
|
151
|
+
i = afterSlash
|
|
152
|
+
continue
|
|
153
|
+
}
|
|
154
|
+
i++
|
|
155
|
+
}
|
|
156
|
+
return i
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
/*
|
|
160
|
+
When `i` sits on a `/` introducing a line comment, block comment, or regex
|
|
161
|
+
literal, returns the index immediately after the construct; undefined when
|
|
162
|
+
the `/` is division (or `i` isn't a `/`). One statement of the skip rules
|
|
163
|
+
shared by every scanner loop so they can't drift.
|
|
164
|
+
*/
|
|
165
|
+
function skipSlashConstruct(source: string, i: number): number | undefined {
|
|
166
|
+
if (source[i] !== '/') {
|
|
167
|
+
return undefined
|
|
168
|
+
}
|
|
169
|
+
const next = source[i + 1]
|
|
170
|
+
if (next === '/') {
|
|
171
|
+
const newline = source.indexOf('\n', i + 2)
|
|
172
|
+
return newline === -1 ? source.length : newline + 1
|
|
173
|
+
}
|
|
174
|
+
if (next === '*') {
|
|
175
|
+
const end = source.indexOf('*/', i + 2)
|
|
176
|
+
return end === -1 ? source.length : end + 2
|
|
177
|
+
}
|
|
178
|
+
if (isRegexContext(source, i)) {
|
|
179
|
+
return skipRegex(source, i + 1)
|
|
180
|
+
}
|
|
181
|
+
return undefined
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
function matchCallTail(source: string, after: number): number | undefined {
|
|
185
|
+
let j = after
|
|
186
|
+
while (j < source.length && isWhitespace(source[j])) {
|
|
187
|
+
j++
|
|
188
|
+
}
|
|
189
|
+
if (source[j] === '<') {
|
|
190
|
+
const closed = skipGenerics(source, j)
|
|
191
|
+
if (closed === undefined) {
|
|
192
|
+
return undefined
|
|
193
|
+
}
|
|
194
|
+
j = closed
|
|
195
|
+
while (j < source.length && isWhitespace(source[j])) {
|
|
196
|
+
j++
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
return source[j] === '(' ? j : undefined
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
/*
|
|
203
|
+
Returns the index immediately after the matching `>` for a generic
|
|
204
|
+
argument list starting at `start`. TypeScript type literals inside the
|
|
205
|
+
generic (`<{ a: string; b: number }>`, function types `<() => X>`,
|
|
206
|
+
tuples `<[A, B]>`, etc.) bring their own paired brackets and
|
|
207
|
+
semicolons, so track depth across `<>`, `()`, `{}`, and `[]` and only
|
|
208
|
+
count a closing `>` when every other bracket is balanced.
|
|
209
|
+
Arrow-function `=>` is treated as a single token so the `>` doesn't
|
|
210
|
+
prematurely close the generic.
|
|
211
|
+
*/
|
|
212
|
+
function skipGenerics(source: string, start: number): number | undefined {
|
|
213
|
+
let angleDepth = 0
|
|
214
|
+
let parenDepth = 0
|
|
215
|
+
let braceDepth = 0
|
|
216
|
+
let bracketDepth = 0
|
|
217
|
+
let i = start
|
|
218
|
+
while (i < source.length) {
|
|
219
|
+
const c = source[i]
|
|
220
|
+
if (c === '"' || c === "'") {
|
|
221
|
+
i = skipString(source, i + 1, c)
|
|
222
|
+
continue
|
|
223
|
+
}
|
|
224
|
+
if (c === '`') {
|
|
225
|
+
i = skipTemplate(source, i + 1)
|
|
226
|
+
continue
|
|
227
|
+
}
|
|
228
|
+
if (c === '<') {
|
|
229
|
+
angleDepth++
|
|
230
|
+
} else if (c === '>') {
|
|
231
|
+
const isArrow = source[i - 1] === '='
|
|
232
|
+
if (!isArrow && parenDepth === 0 && braceDepth === 0 && bracketDepth === 0) {
|
|
233
|
+
angleDepth--
|
|
234
|
+
if (angleDepth === 0) {
|
|
235
|
+
return i + 1
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
} else if (c === '(') {
|
|
239
|
+
parenDepth++
|
|
240
|
+
} else if (c === ')') {
|
|
241
|
+
parenDepth--
|
|
242
|
+
} else if (c === '{') {
|
|
243
|
+
braceDepth++
|
|
244
|
+
} else if (c === '}') {
|
|
245
|
+
braceDepth--
|
|
246
|
+
} else if (c === '[') {
|
|
247
|
+
bracketDepth++
|
|
248
|
+
} else if (c === ']') {
|
|
249
|
+
bracketDepth--
|
|
250
|
+
}
|
|
251
|
+
i++
|
|
252
|
+
}
|
|
253
|
+
return undefined
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
/*
|
|
257
|
+
Walks the call body, skipping strings/templates/comments and respecting
|
|
258
|
+
nested `()` so brackets inside object literals or nested calls don't
|
|
259
|
+
throw the depth count.
|
|
260
|
+
*/
|
|
261
|
+
function findCallEnd(source: string, parenStart: number): number | undefined {
|
|
262
|
+
let depth = 1
|
|
263
|
+
let i = parenStart + 1
|
|
264
|
+
while (i < source.length) {
|
|
265
|
+
const c = source[i]
|
|
266
|
+
if (c === '"' || c === "'") {
|
|
267
|
+
i = skipString(source, i + 1, c)
|
|
268
|
+
continue
|
|
269
|
+
}
|
|
270
|
+
if (c === '`') {
|
|
271
|
+
i = skipTemplate(source, i + 1)
|
|
272
|
+
continue
|
|
273
|
+
}
|
|
274
|
+
const afterSlash = skipSlashConstruct(source, i)
|
|
275
|
+
if (afterSlash !== undefined) {
|
|
276
|
+
i = afterSlash
|
|
277
|
+
continue
|
|
278
|
+
}
|
|
279
|
+
if (c === '(') {
|
|
280
|
+
depth++
|
|
281
|
+
} else if (c === ')') {
|
|
282
|
+
depth--
|
|
283
|
+
if (depth === 0) {
|
|
284
|
+
return i
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
i++
|
|
288
|
+
}
|
|
289
|
+
return undefined
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
/*
|
|
293
|
+
Looks backwards from a `<IDENT>(` callStart to confirm it was bound by
|
|
294
|
+
`export const <name> = ...`. Returns the identifier in `<name>` if so,
|
|
295
|
+
undefined otherwise — used to skip mentions of an identifier that
|
|
296
|
+
isn't the module's declared export.
|
|
297
|
+
*/
|
|
298
|
+
function detectExportName(source: string, callStart: number): string | undefined {
|
|
299
|
+
let i = callStart - 1
|
|
300
|
+
while (i >= 0 && isWhitespace(source[i])) {
|
|
301
|
+
i--
|
|
302
|
+
}
|
|
303
|
+
if (source[i] !== '=') {
|
|
304
|
+
return undefined
|
|
305
|
+
}
|
|
306
|
+
i--
|
|
307
|
+
while (i >= 0 && isWhitespace(source[i])) {
|
|
308
|
+
i--
|
|
309
|
+
}
|
|
310
|
+
const nameEnd = i + 1
|
|
311
|
+
while (i >= 0 && isIdentPart(source[i])) {
|
|
312
|
+
i--
|
|
313
|
+
}
|
|
314
|
+
const nameStart = i + 1
|
|
315
|
+
if (nameStart === nameEnd) {
|
|
316
|
+
return undefined
|
|
317
|
+
}
|
|
318
|
+
const name = source.slice(nameStart, nameEnd)
|
|
319
|
+
while (i >= 0 && isWhitespace(source[i])) {
|
|
320
|
+
i--
|
|
321
|
+
}
|
|
322
|
+
if (!matchesBackwards(source, i, 'const')) {
|
|
323
|
+
return undefined
|
|
324
|
+
}
|
|
325
|
+
i -= 'const'.length
|
|
326
|
+
while (i >= 0 && isWhitespace(source[i])) {
|
|
327
|
+
i--
|
|
328
|
+
}
|
|
329
|
+
if (!matchesBackwards(source, i, 'export')) {
|
|
330
|
+
return undefined
|
|
331
|
+
}
|
|
332
|
+
return name
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
function matchesBackwards(source: string, end: number, keyword: string): boolean {
|
|
336
|
+
const start = end - keyword.length + 1
|
|
337
|
+
if (start < 0) {
|
|
338
|
+
return false
|
|
339
|
+
}
|
|
340
|
+
if (source.slice(start, end + 1) !== keyword) {
|
|
341
|
+
return false
|
|
342
|
+
}
|
|
343
|
+
return start === 0 || !isIdentPart(source[start - 1])
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
function isIdentStart(c: string | undefined): boolean {
|
|
347
|
+
if (c === undefined) {
|
|
348
|
+
return false
|
|
349
|
+
}
|
|
350
|
+
return (c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z') || c === '_' || c === '$'
|
|
351
|
+
}
|
|
352
|
+
|
|
353
|
+
function isIdentPart(c: string | undefined): boolean {
|
|
354
|
+
if (c === undefined) {
|
|
355
|
+
return false
|
|
356
|
+
}
|
|
357
|
+
return isIdentStart(c) || (c >= '0' && c <= '9')
|
|
358
|
+
}
|
|
359
|
+
|
|
360
|
+
function isWhitespace(c: string | undefined): boolean {
|
|
361
|
+
return c === ' ' || c === '\t' || c === '\n' || c === '\r'
|
|
362
|
+
}
|
|
363
|
+
|
|
364
|
+
/*
|
|
365
|
+
A `/` starts a regex literal when the prior expression context expects an
|
|
366
|
+
expression rather than a value — after an open delimiter, operator, or
|
|
367
|
+
expression-prefix keyword (return, typeof, instanceof, in, of, delete,
|
|
368
|
+
void, await, yield, new, throw, case, do). Otherwise `/` is division.
|
|
369
|
+
Without this disambiguation a regex like `/^\//` reads as `/` (division),
|
|
370
|
+
then `^`, `\`, `/`, `/` — and the final `//` pair fakes a line comment
|
|
371
|
+
that swallows the rest of the line, eating any `)` that closes the
|
|
372
|
+
enclosing call.
|
|
373
|
+
*/
|
|
374
|
+
const REGEX_PREFIX_KEYWORDS = new Set([
|
|
375
|
+
'return',
|
|
376
|
+
'typeof',
|
|
377
|
+
'instanceof',
|
|
378
|
+
'in',
|
|
379
|
+
'of',
|
|
380
|
+
'delete',
|
|
381
|
+
'void',
|
|
382
|
+
'await',
|
|
383
|
+
'yield',
|
|
384
|
+
'new',
|
|
385
|
+
'throw',
|
|
386
|
+
'case',
|
|
387
|
+
'do',
|
|
388
|
+
])
|
|
389
|
+
|
|
390
|
+
const REGEX_PUNCTUATION = new Set([
|
|
391
|
+
'(',
|
|
392
|
+
'[',
|
|
393
|
+
'{',
|
|
394
|
+
',',
|
|
395
|
+
';',
|
|
396
|
+
':',
|
|
397
|
+
'?',
|
|
398
|
+
'!',
|
|
399
|
+
'&',
|
|
400
|
+
'|',
|
|
401
|
+
'^',
|
|
402
|
+
'~',
|
|
403
|
+
'+',
|
|
404
|
+
'-',
|
|
405
|
+
'*',
|
|
406
|
+
'%',
|
|
407
|
+
'<',
|
|
408
|
+
'>',
|
|
409
|
+
'=',
|
|
410
|
+
'/',
|
|
411
|
+
])
|
|
412
|
+
|
|
413
|
+
function isRegexContext(source: string, slashIndex: number): boolean {
|
|
414
|
+
let i = slashIndex - 1
|
|
415
|
+
while (i >= 0 && isWhitespace(source[i])) {
|
|
416
|
+
i--
|
|
417
|
+
}
|
|
418
|
+
if (i < 0) {
|
|
419
|
+
return true
|
|
420
|
+
}
|
|
421
|
+
const prev = source[i] as string
|
|
422
|
+
if (REGEX_PUNCTUATION.has(prev)) {
|
|
423
|
+
return true
|
|
424
|
+
}
|
|
425
|
+
if (isIdentPart(prev)) {
|
|
426
|
+
let start = i
|
|
427
|
+
while (start > 0 && isIdentPart(source[start - 1])) {
|
|
428
|
+
start--
|
|
429
|
+
}
|
|
430
|
+
return REGEX_PREFIX_KEYWORDS.has(source.slice(start, i + 1))
|
|
431
|
+
}
|
|
432
|
+
return false
|
|
433
|
+
}
|
|
434
|
+
|
|
435
|
+
/*
|
|
436
|
+
Walks past a regex literal body, respecting character classes (`[...]`
|
|
437
|
+
where `/` is literal) and backslash escapes, then consumes trailing
|
|
438
|
+
flag identifiers. Returns the index immediately after the regex. An
|
|
439
|
+
unterminated regex (newline before closing `/`) returns the newline
|
|
440
|
+
position so the outer scanner can resume normally on the next line.
|
|
441
|
+
*/
|
|
442
|
+
function skipRegex(source: string, start: number): number {
|
|
443
|
+
let i = start
|
|
444
|
+
let inClass = false
|
|
445
|
+
while (i < source.length) {
|
|
446
|
+
const c = source[i]
|
|
447
|
+
if (c === '\\') {
|
|
448
|
+
i += 2
|
|
449
|
+
continue
|
|
450
|
+
}
|
|
451
|
+
if (c === '\n') {
|
|
452
|
+
return i
|
|
453
|
+
}
|
|
454
|
+
if (inClass) {
|
|
455
|
+
if (c === ']') {
|
|
456
|
+
inClass = false
|
|
457
|
+
}
|
|
458
|
+
i++
|
|
459
|
+
continue
|
|
460
|
+
}
|
|
461
|
+
if (c === '[') {
|
|
462
|
+
inClass = true
|
|
463
|
+
i++
|
|
464
|
+
continue
|
|
465
|
+
}
|
|
466
|
+
if (c === '/') {
|
|
467
|
+
let j = i + 1
|
|
468
|
+
while (j < source.length && isIdentPart(source[j])) {
|
|
469
|
+
j++
|
|
470
|
+
}
|
|
471
|
+
return j
|
|
472
|
+
}
|
|
473
|
+
i++
|
|
474
|
+
}
|
|
475
|
+
return source.length
|
|
476
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { TraceContext } from './types/TraceContext.ts'
|
|
2
|
+
|
|
3
|
+
// Serialises a TraceContext to the W3C `traceparent` wire form (version 00).
|
|
4
|
+
export function formatTraceparent(context: TraceContext): string {
|
|
5
|
+
return `00-${context.traceId}-${context.spanId}-${context.flags}`
|
|
6
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { extraForwardHeaders } from './extraForwardHeaders.ts'
|
|
2
|
+
|
|
3
|
+
/*
|
|
4
|
+
Headers abide forwards from an inbound HTTP/MCP request onto every
|
|
5
|
+
synthesized in-process rpc Request — cookies + bearer auth + the four
|
|
6
|
+
forwarding hints proxies set when terminating TLS in front of the app.
|
|
7
|
+
defineVerb uses this when an SSR pass calls a verb in-process; the MCP
|
|
8
|
+
dispatcher uses it when piping a tool invocation through verb.fetch.
|
|
9
|
+
|
|
10
|
+
WARNING — this is an allowlist: every inbound header NOT named here (and
|
|
11
|
+
not added via app.forwardHeaders) is DROPPED on the in-process path. A
|
|
12
|
+
handler that reads e.g. `accept-language`, an idempotency key, a trace
|
|
13
|
+
header, or a custom `x-tenant-*` during SSR or an MCP call sees nothing,
|
|
14
|
+
and the call still succeeds with a degraded request. Add the names you
|
|
15
|
+
rely on via the `forwardHeaders` export in src/app.ts.
|
|
16
|
+
|
|
17
|
+
Centralised so both call sites can't drift on which headers are
|
|
18
|
+
considered "auth/identity" context.
|
|
19
|
+
*/
|
|
20
|
+
const FORWARDED_HEADERS = [
|
|
21
|
+
'cookie',
|
|
22
|
+
'authorization',
|
|
23
|
+
/* W3C trace context rides every hop so a handler reading headers sees the caller's position. */
|
|
24
|
+
'traceparent',
|
|
25
|
+
'tracestate',
|
|
26
|
+
'x-forwarded-for',
|
|
27
|
+
'x-forwarded-proto',
|
|
28
|
+
'x-forwarded-host',
|
|
29
|
+
]
|
|
30
|
+
|
|
31
|
+
export function forwardHeaders(source: Headers): Headers {
|
|
32
|
+
const headers = new Headers()
|
|
33
|
+
// Iterate the two fixed arrays directly — both are request-invariant, so
|
|
34
|
+
// a spread-concat here would allocate a fresh array on every SSR/MCP call.
|
|
35
|
+
const copy = (name: string) => {
|
|
36
|
+
const value = source.get(name)
|
|
37
|
+
if (value) {
|
|
38
|
+
headers.set(name, value)
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
FORWARDED_HEADERS.forEach(copy)
|
|
42
|
+
extraForwardHeaders.get().forEach(copy)
|
|
43
|
+
return headers
|
|
44
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { activeCacheStore } from './activeCacheStore.ts'
|
|
2
|
+
import { globalCacheStoreSlot } from './globalCacheStoreSlot.ts'
|
|
3
|
+
import type { CacheStore } from './types/CacheStore.ts'
|
|
4
|
+
|
|
5
|
+
/*
|
|
6
|
+
Resolves the process-level CacheStore that `cache(fn, { global: true })` entries
|
|
7
|
+
live in. The server entry registers a module-singleton resolver so the store
|
|
8
|
+
survives across requests; the client points it at the active tab store. When no
|
|
9
|
+
resolver is registered (isolated tests, or a client that never set one) it falls
|
|
10
|
+
back to the active store, so `global` degrades to request/tab-scoped rather than
|
|
11
|
+
throwing.
|
|
12
|
+
*/
|
|
13
|
+
export function globalCacheStore(): CacheStore {
|
|
14
|
+
return globalCacheStoreSlot.resolver?.() ?? activeCacheStore()
|
|
15
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { CacheStore } from './types/CacheStore.ts'
|
|
2
|
+
|
|
3
|
+
/*
|
|
4
|
+
Slot for the process-level cache store resolver used by cache() entries opting
|
|
5
|
+
into `global: true`. The server entry registers a module-singleton store that
|
|
6
|
+
outlives any one request; the client entry points it at its single tab store so
|
|
7
|
+
`global` is a no-op there. Unset means no global store is registered, in which
|
|
8
|
+
case globalCacheStore() falls back to the active (request/tab) store.
|
|
9
|
+
*/
|
|
10
|
+
export const globalCacheStoreSlot: {
|
|
11
|
+
resolver: (() => CacheStore | undefined) | undefined
|
|
12
|
+
} = {
|
|
13
|
+
resolver: undefined,
|
|
14
|
+
}
|