@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,7 @@
|
|
|
1
|
+
import type { Route } from './Route.ts'
|
|
2
|
+
|
|
3
|
+
/* A code-split page entry: imports the page chunk on demand, yielding its default
|
|
4
|
+
Route. The router resolves a loader on first match and caches the result, so
|
|
5
|
+
each page's chunk downloads only when its route is first visited — not all of
|
|
6
|
+
them up front at boot. Mirrors the `_virtual/pages` manifest shape. */
|
|
7
|
+
export type RouteLoader = () => Promise<{ default: Route }>
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/* One pending await block captured during SSR: its boundary id, the promise to
|
|
2
|
+
await, and the string-renderers for the resolved value / error. `blocking` (a
|
|
3
|
+
`then` on the `await` tag) makes `renderToStream` settle it BEFORE the first flush,
|
|
4
|
+
splicing the resolved branch into its empty boundary; absent → streamed after.
|
|
5
|
+
`catch` is absent when the block has no catch branch — a rejection then surfaces
|
|
6
|
+
to the stream/error path instead of rendering an empty branch. */
|
|
7
|
+
export type SsrAwait = {
|
|
8
|
+
id: number
|
|
9
|
+
blocking?: boolean
|
|
10
|
+
promise: () => unknown
|
|
11
|
+
then: (value: unknown) => string
|
|
12
|
+
catch?: (error: unknown) => string
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
/* The result of a component's server `render()`: the pending-shell HTML, the
|
|
16
|
+
serializable document snapshot for client resume, and the await blocks to
|
|
17
|
+
stream. */
|
|
18
|
+
export type SsrRender = {
|
|
19
|
+
html: string
|
|
20
|
+
state: unknown
|
|
21
|
+
awaits: SsrAwait[]
|
|
22
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { SsrRender } from './SsrRender.ts'
|
|
2
|
+
import type { UiProps } from './UiProps.ts'
|
|
3
|
+
|
|
4
|
+
/*
|
|
5
|
+
A compiled abide-ui component's default export: the client mounter, plus `render`
|
|
6
|
+
for SSR and the hydration hooks. This is the shape `compileModule` emits and the
|
|
7
|
+
page/route registries carry — abide-ui's compiled-component shape.
|
|
8
|
+
*/
|
|
9
|
+
export type UiComponent = ((host: Element, props?: UiProps) => () => void) & {
|
|
10
|
+
render: (props?: UiProps) => SsrRender
|
|
11
|
+
hydrate?: (host: Element, props?: UiProps) => () => void
|
|
12
|
+
hydratable?: boolean
|
|
13
|
+
/* Stable module id (project-relative source path) stamped by `compileModule`,
|
|
14
|
+
keying the component in the hot-reload registry — see `mountChild`. */
|
|
15
|
+
__abideId?: string
|
|
16
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/*
|
|
2
|
+
What a component is invoked with. Two real shapes flow through the one parameter.
|
|
3
|
+
A top-level page/layout is called by the router (client) and `renderChain` (SSR)
|
|
4
|
+
with its decoded route params — a plain string map. A nested child is called by
|
|
5
|
+
the compiler-emitted `mountChild` with a map of reactive thunks (each authored
|
|
6
|
+
prop, read in the body as `$props[name]?.()`) plus optional slot builders:
|
|
7
|
+
`$children` for default-slot markup and `$slots[name]` for named slots, each
|
|
8
|
+
mounting into the host element it is handed.
|
|
9
|
+
*/
|
|
10
|
+
export type UiProps =
|
|
11
|
+
| Record<string, string>
|
|
12
|
+
| (Record<string, () => unknown> & {
|
|
13
|
+
$children?: (host: Element) => void
|
|
14
|
+
$slots?: Record<string, (host: Element) => void>
|
|
15
|
+
})
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { detachLink } from './detachLink.ts'
|
|
2
|
+
import type { ReactiveNode } from './types/ReactiveNode.ts'
|
|
3
|
+
|
|
4
|
+
/*
|
|
5
|
+
Detaches a node from every source it reads — the dispose path for a computed or
|
|
6
|
+
effect torn down with its scope. Walks the node's dependency list once, removing
|
|
7
|
+
each edge from its source's subscriber list so no source keeps a back-link to a
|
|
8
|
+
dead observer, then empties the node's own list. The `Set`-era equivalent was
|
|
9
|
+
`for (dep of node.deps) dep.observers.delete(node); node.deps.clear()`.
|
|
10
|
+
*/
|
|
11
|
+
export function unlinkDeps(node: ReactiveNode): void {
|
|
12
|
+
let link = node.depsHead
|
|
13
|
+
while (link !== undefined) {
|
|
14
|
+
const next = link.nextDep
|
|
15
|
+
detachLink(link)
|
|
16
|
+
link = next
|
|
17
|
+
}
|
|
18
|
+
node.depsHead = undefined
|
|
19
|
+
node.depsTail = undefined
|
|
20
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { REACTIVE_CONTEXT } from './REACTIVE_CONTEXT.ts'
|
|
2
|
+
|
|
3
|
+
/*
|
|
4
|
+
Runs `fn` with dependency tracking suspended: reads inside register no
|
|
5
|
+
subscription on the surrounding observer. The inverse of `track` — for a
|
|
6
|
+
reactive computation that must read or build without capturing those reads as
|
|
7
|
+
its own dependencies. The router mounts a page inside an effect, so without this
|
|
8
|
+
the page's build-time reads (every interpolation reads its value once before
|
|
9
|
+
wrapping it in its own effect) would subscribe the router effect to the page's
|
|
10
|
+
state — any in-page change would then re-run the router and re-mount the page.
|
|
11
|
+
*/
|
|
12
|
+
export function untrack<T>(fn: () => T): T {
|
|
13
|
+
const previous = REACTIVE_CONTEXT.observer
|
|
14
|
+
REACTIVE_CONTEXT.observer = undefined
|
|
15
|
+
try {
|
|
16
|
+
return fn()
|
|
17
|
+
} finally {
|
|
18
|
+
REACTIVE_CONTEXT.observer = previous
|
|
19
|
+
}
|
|
20
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Reads the value at a `/`-joined path in a plain tree. `''` is the root. Returns
|
|
3
|
+
undefined if any segment is missing — arrays index by their numeric segment as a
|
|
4
|
+
string, which works because JS array access coerces the key.
|
|
5
|
+
*/
|
|
6
|
+
export function valueAtPath(tree: unknown, path: string): unknown {
|
|
7
|
+
if (path === '') {
|
|
8
|
+
return tree
|
|
9
|
+
}
|
|
10
|
+
let current: unknown = tree
|
|
11
|
+
for (const segment of path.split('/')) {
|
|
12
|
+
if (current === null || typeof current !== 'object') {
|
|
13
|
+
return undefined
|
|
14
|
+
}
|
|
15
|
+
current = (current as Record<string, unknown>)[segment]
|
|
16
|
+
}
|
|
17
|
+
return current
|
|
18
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { trigger } from './trigger.ts'
|
|
2
|
+
import type { ReactiveNode } from './types/ReactiveNode.ts'
|
|
3
|
+
|
|
4
|
+
/*
|
|
5
|
+
Writes a signal node. An `Object.is`-equal write is a no-op — equality at the
|
|
6
|
+
leaf is exactly what stops a no-change patch from waking readers, and (via the
|
|
7
|
+
document's structural sharing) what stops an untouched sibling subtree from
|
|
8
|
+
re-running when its parent changes identity.
|
|
9
|
+
*/
|
|
10
|
+
export function writeNode(node: ReactiveNode, value: unknown): void {
|
|
11
|
+
if (Object.is(node.value, value)) {
|
|
12
|
+
return
|
|
13
|
+
}
|
|
14
|
+
node.value = value
|
|
15
|
+
trigger(node)
|
|
16
|
+
}
|
|
@@ -0,0 +1,227 @@
|
|
|
1
|
+
import type { SocketClientFrame } from '../server/sockets/types/SocketClientFrame.ts'
|
|
2
|
+
import type { SocketServerFrame } from '../server/sockets/types/SocketServerFrame.ts'
|
|
3
|
+
import { SOCKETS_PATH } from '../shared/SOCKETS_PATH.ts'
|
|
4
|
+
import type { SocketChannel } from '../shared/types/SocketChannel.ts'
|
|
5
|
+
import type { SocketSubCallbacks } from '../shared/types/SocketSubCallbacks.ts'
|
|
6
|
+
import { withBase } from '../shared/withBase.ts'
|
|
7
|
+
|
|
8
|
+
let singleton: SocketChannel | undefined
|
|
9
|
+
|
|
10
|
+
/*
|
|
11
|
+
Lazily opens the single multiplexed ws used by every socket proxy on
|
|
12
|
+
the page. Routes inbound frames:
|
|
13
|
+
`msg` → all local subs of that socket
|
|
14
|
+
`replay` → the matching sub (its batched seed)
|
|
15
|
+
`end` → the matching sub
|
|
16
|
+
`err` → the matching sub
|
|
17
|
+
|
|
18
|
+
`msg` frames carry no sub id: one publish from the server fans out to
|
|
19
|
+
every connected ws via Bun's native publish, and each ws delivers the
|
|
20
|
+
message to every local sub of that socket. `replay`/`end`/`err` are
|
|
21
|
+
per-sub — a seed batch belongs to the sub that requested it.
|
|
22
|
+
|
|
23
|
+
Outbound frames sent before `ws.onopen` fires are queued and flushed
|
|
24
|
+
on open. The channel reconnects on close with bounded backoff;
|
|
25
|
+
in-flight subs are torn down with the typed disconnect signal so
|
|
26
|
+
consumers' `for await` loops can surface it, then the connection
|
|
27
|
+
comes back up and fresh subs can be opened. The channel itself never
|
|
28
|
+
re-subscribes across a reconnect — it can't know consumer semantics;
|
|
29
|
+
a delta consumer must reconcile state on a fresh connection (e.g.
|
|
30
|
+
re-fetch a snapshot before reapplying deltas). tail() opts in
|
|
31
|
+
above this layer because its latest-wins/window semantics make replay a
|
|
32
|
+
correct reconciliation; raw `for await` consumers keep manual control.
|
|
33
|
+
|
|
34
|
+
While the backoff timer is armed, `connect()` defers to it: a consumer
|
|
35
|
+
re-subscribing in reaction to the disconnect would otherwise trigger an
|
|
36
|
+
immediate reconnect on every failure cycle, defeating the backoff. Its
|
|
37
|
+
frames queue in `pendingSends` and flush when the timer's attempt opens.
|
|
38
|
+
|
|
39
|
+
Hidden tabs hold no transport: `visibilitychange: hidden` closes the ws
|
|
40
|
+
through the normal drop path above — subs tear down with the typed
|
|
41
|
+
disconnect, and a resyncing consumer's fresh sub frames queue (connect()
|
|
42
|
+
refuses to open while hidden) until the visible transition reconnects and
|
|
43
|
+
flushes them.
|
|
44
|
+
*/
|
|
45
|
+
export function getSocketChannel(): SocketChannel {
|
|
46
|
+
if (singleton) {
|
|
47
|
+
return singleton
|
|
48
|
+
}
|
|
49
|
+
const subs = new Map<string, { socket: string; callbacks: SocketSubCallbacks }>()
|
|
50
|
+
const subsBySocket = new Map<string, Set<string>>()
|
|
51
|
+
let ws: WebSocket | undefined
|
|
52
|
+
let pendingSends: string[] = []
|
|
53
|
+
let backoffMs = 250
|
|
54
|
+
let reconnectTimer: ReturnType<typeof setTimeout> | undefined
|
|
55
|
+
|
|
56
|
+
function flushPending(): void {
|
|
57
|
+
if (!ws || ws.readyState !== WebSocket.OPEN) {
|
|
58
|
+
return
|
|
59
|
+
}
|
|
60
|
+
for (const message of pendingSends) {
|
|
61
|
+
ws.send(message)
|
|
62
|
+
}
|
|
63
|
+
pendingSends = []
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
function send(frame: SocketClientFrame): void {
|
|
67
|
+
const message = JSON.stringify(frame)
|
|
68
|
+
if (ws && ws.readyState === WebSocket.OPEN) {
|
|
69
|
+
ws.send(message)
|
|
70
|
+
return
|
|
71
|
+
}
|
|
72
|
+
pendingSends.push(message)
|
|
73
|
+
connect()
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
function connect(): void {
|
|
77
|
+
/* Backoff window owns reconnection; queued frames flush when its attempt opens. */
|
|
78
|
+
if (reconnectTimer !== undefined) {
|
|
79
|
+
return
|
|
80
|
+
}
|
|
81
|
+
/* Hidden tabs hold no transport — frames queue, the visibility listener reconnects. */
|
|
82
|
+
if (document.hidden) {
|
|
83
|
+
return
|
|
84
|
+
}
|
|
85
|
+
if (ws && (ws.readyState === WebSocket.OPEN || ws.readyState === WebSocket.CONNECTING)) {
|
|
86
|
+
return
|
|
87
|
+
}
|
|
88
|
+
const scheme = window.location.protocol === 'https:' ? 'wss:' : 'ws:'
|
|
89
|
+
// The mount base routes the upgrade through the proxy (/v2/__abide/sockets).
|
|
90
|
+
ws = new WebSocket(`${scheme}//${window.location.host}${withBase(SOCKETS_PATH)}`)
|
|
91
|
+
ws.addEventListener('open', () => {
|
|
92
|
+
backoffMs = 250
|
|
93
|
+
flushPending()
|
|
94
|
+
})
|
|
95
|
+
ws.addEventListener('message', (event) => {
|
|
96
|
+
let frame: SocketServerFrame
|
|
97
|
+
try {
|
|
98
|
+
frame = JSON.parse(event.data) as SocketServerFrame
|
|
99
|
+
} catch {
|
|
100
|
+
return
|
|
101
|
+
}
|
|
102
|
+
if (frame.type === 'msg') {
|
|
103
|
+
/*
|
|
104
|
+
One Bun-published frame fans out to every local sub of
|
|
105
|
+
that socket on this ws — addressed by socket name, not
|
|
106
|
+
per-sub id.
|
|
107
|
+
*/
|
|
108
|
+
const targets = subsBySocket.get(frame.socket)
|
|
109
|
+
if (!targets) {
|
|
110
|
+
return
|
|
111
|
+
}
|
|
112
|
+
for (const subId of targets) {
|
|
113
|
+
subs.get(subId)?.callbacks.onMessage(frame.message)
|
|
114
|
+
}
|
|
115
|
+
return
|
|
116
|
+
}
|
|
117
|
+
if (frame.type === 'replay') {
|
|
118
|
+
subs.get(frame.sub)?.callbacks.onReplay(frame.messages)
|
|
119
|
+
return
|
|
120
|
+
}
|
|
121
|
+
if (frame.type === 'end') {
|
|
122
|
+
const sub = subs.get(frame.sub)
|
|
123
|
+
if (!sub) {
|
|
124
|
+
return
|
|
125
|
+
}
|
|
126
|
+
dropSub(frame.sub)
|
|
127
|
+
sub.callbacks.onEnd()
|
|
128
|
+
return
|
|
129
|
+
}
|
|
130
|
+
if (frame.type === 'err') {
|
|
131
|
+
const sub = subs.get(frame.sub)
|
|
132
|
+
if (!sub) {
|
|
133
|
+
return
|
|
134
|
+
}
|
|
135
|
+
dropSub(frame.sub)
|
|
136
|
+
sub.callbacks.onError(frame.message)
|
|
137
|
+
return
|
|
138
|
+
}
|
|
139
|
+
})
|
|
140
|
+
ws.addEventListener('close', () => {
|
|
141
|
+
const active = [...subs.values()]
|
|
142
|
+
subs.clear()
|
|
143
|
+
subsBySocket.clear()
|
|
144
|
+
/*
|
|
145
|
+
Drop any queued frames too. We've just torn down every local
|
|
146
|
+
sub, so replaying their `sub`/`unsub`/`pub` frames on
|
|
147
|
+
reconnect would open ghost subscriptions on the server that
|
|
148
|
+
no client object tracks (and never gets an `unsub`). This
|
|
149
|
+
keeps the "channel never re-subscribes" contract above
|
|
150
|
+
honest — consumers re-open fresh subs. Cleared before the
|
|
151
|
+
callbacks run so a consumer reacting to the disconnect (its
|
|
152
|
+
catch resolves in a microtask, after this handler) queues
|
|
153
|
+
onto a fresh list.
|
|
154
|
+
*/
|
|
155
|
+
const hadPending = pendingSends.length > 0
|
|
156
|
+
pendingSends = []
|
|
157
|
+
ws = undefined
|
|
158
|
+
for (const sub of active) {
|
|
159
|
+
sub.callbacks.onDisconnect()
|
|
160
|
+
}
|
|
161
|
+
if (active.length === 0 && !hadPending) {
|
|
162
|
+
return
|
|
163
|
+
}
|
|
164
|
+
reconnectTimer = setTimeout(() => {
|
|
165
|
+
reconnectTimer = undefined
|
|
166
|
+
connect()
|
|
167
|
+
}, backoffMs)
|
|
168
|
+
backoffMs = Math.min(backoffMs * 2, 5000)
|
|
169
|
+
})
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
function dropSub(id: string): void {
|
|
173
|
+
const entry = subs.get(id)
|
|
174
|
+
if (!entry) {
|
|
175
|
+
return
|
|
176
|
+
}
|
|
177
|
+
subs.delete(id)
|
|
178
|
+
const set = subsBySocket.get(entry.socket)
|
|
179
|
+
if (set) {
|
|
180
|
+
set.delete(id)
|
|
181
|
+
if (set.size === 0) {
|
|
182
|
+
subsBySocket.delete(entry.socket)
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
/*
|
|
188
|
+
Release the ws when the tab hides rather than hold an idle connection the
|
|
189
|
+
browser throttles. Closing rides the normal drop path (close handler →
|
|
190
|
+
typed disconnect → consumers resync), so by the visible transition the
|
|
191
|
+
resubscribed frames sit in `pendingSends` waiting for the reconnect.
|
|
192
|
+
*/
|
|
193
|
+
document.addEventListener('visibilitychange', () => {
|
|
194
|
+
if (document.hidden) {
|
|
195
|
+
ws?.close()
|
|
196
|
+
return
|
|
197
|
+
}
|
|
198
|
+
if (pendingSends.length > 0) {
|
|
199
|
+
connect()
|
|
200
|
+
}
|
|
201
|
+
})
|
|
202
|
+
|
|
203
|
+
singleton = {
|
|
204
|
+
subscribe(id, socket, replay, callbacks) {
|
|
205
|
+
subs.set(id, { socket, callbacks })
|
|
206
|
+
/* Not getOrInsertComputed: browser-side code, and Safari/Chrome only shipped it within the last browser cycle (26.2 / 145). */
|
|
207
|
+
let set = subsBySocket.get(socket)
|
|
208
|
+
if (!set) {
|
|
209
|
+
set = new Set()
|
|
210
|
+
subsBySocket.set(socket, set)
|
|
211
|
+
}
|
|
212
|
+
set.add(id)
|
|
213
|
+
send({ type: 'sub', sub: id, socket, replay })
|
|
214
|
+
},
|
|
215
|
+
unsubscribe(id) {
|
|
216
|
+
if (!subs.has(id)) {
|
|
217
|
+
return
|
|
218
|
+
}
|
|
219
|
+
dropSub(id)
|
|
220
|
+
send({ type: 'unsub', sub: id })
|
|
221
|
+
},
|
|
222
|
+
publish(socket, message) {
|
|
223
|
+
send({ type: 'pub', socket, message })
|
|
224
|
+
},
|
|
225
|
+
}
|
|
226
|
+
return singleton
|
|
227
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { Socket } from '../server/sockets/types/Socket.ts'
|
|
2
|
+
import { buildSocketOverChannel } from '../shared/buildSocketOverChannel.ts'
|
|
3
|
+
import { getSocketChannel } from './socketChannel.ts'
|
|
4
|
+
|
|
5
|
+
/*
|
|
6
|
+
Client-side substitute for a server-declared Socket. The bundler emits
|
|
7
|
+
one call per socket export under `src/server/sockets/`: server target uses
|
|
8
|
+
defineSocket (real fan-out), browser target uses socketProxy (subscribe
|
|
9
|
+
over the multiplexed ws channel). Both paths produce identical Socket
|
|
10
|
+
shapes so user code reads the same on either side.
|
|
11
|
+
|
|
12
|
+
The Socket surface — bare iteration as the live stream, `.tail(n)` seeded
|
|
13
|
+
from the retained tail, `.publish` sending a server-validated `pub` frame —
|
|
14
|
+
is built by buildSocketOverChannel over the page's lazily-opened singleton
|
|
15
|
+
channel; this module only binds that builder to the browser channel so the
|
|
16
|
+
test harness can reuse the identical surface over its own channel.
|
|
17
|
+
|
|
18
|
+
Backpressure is unbounded — a slow consumer with a chatty socket will
|
|
19
|
+
grow the per-iterator buffer; bounded policies belong in a future
|
|
20
|
+
socketProxy API, not the wire layer.
|
|
21
|
+
*/
|
|
22
|
+
// @readme plumbing
|
|
23
|
+
export function socketProxy<T>(name: string): Socket<T> {
|
|
24
|
+
return buildSocketOverChannel<T>(name, getSocketChannel)
|
|
25
|
+
}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { cacheEntryFromSnapshot } from '../shared/cacheEntryFromSnapshot.ts'
|
|
2
|
+
import { createCacheStore } from '../shared/createCacheStore.ts'
|
|
3
|
+
import { setBaseResolver } from '../shared/setBaseResolver.ts'
|
|
4
|
+
import { setCacheStoreResolver } from '../shared/setCacheStoreResolver.ts'
|
|
5
|
+
import { setGlobalCacheStoreResolver } from '../shared/setGlobalCacheStoreResolver.ts'
|
|
6
|
+
import { setPageResolver } from '../shared/setPageResolver.ts'
|
|
7
|
+
import type { CacheSnapshotEntry } from '../shared/types/CacheSnapshotEntry.ts'
|
|
8
|
+
import { installHotBridge } from './installHotBridge.ts'
|
|
9
|
+
import { probeNavigation } from './probeNavigation.ts'
|
|
10
|
+
import { router } from './router.ts'
|
|
11
|
+
import { clientPage } from './runtime/clientPage.ts'
|
|
12
|
+
import type { RouteLoader } from './runtime/types/RouteLoader.ts'
|
|
13
|
+
|
|
14
|
+
/* The server's __SSR__ payload this entry consumes. */
|
|
15
|
+
type SsrPayload = { cache?: CacheSnapshotEntry[]; base?: string }
|
|
16
|
+
|
|
17
|
+
/*
|
|
18
|
+
The official abide-ui client entry. Reads the server's `window.__SSR__` payload,
|
|
19
|
+
seeds a tab-scoped cache store from the inline snapshot (so a warm `cache()` read
|
|
20
|
+
resolves synchronously and the matching `<template await>` adopts the SSR DOM with
|
|
21
|
+
no re-fetch), installs the mount base, and starts the router — which imports the
|
|
22
|
+
current route's chunk, adopts the server-rendered `#app`, then drives SPA
|
|
23
|
+
navigation — importing each further page's chunk on first visit and probing the
|
|
24
|
+
destination through the server's app.handle so auth/redirect gating still applies.
|
|
25
|
+
Returns a disposer. `target` defaults to `#app`; pass one explicitly in tests.
|
|
26
|
+
*/
|
|
27
|
+
// @readme plumbing
|
|
28
|
+
export function startClient(
|
|
29
|
+
routes: Record<string, RouteLoader>,
|
|
30
|
+
layoutRoutes: Record<string, RouteLoader> = {},
|
|
31
|
+
target: Element | null = typeof document !== 'undefined'
|
|
32
|
+
? document.getElementById('app')
|
|
33
|
+
: null,
|
|
34
|
+
): () => void {
|
|
35
|
+
if (target === null) {
|
|
36
|
+
throw new Error('[abide] startClient: missing #app target')
|
|
37
|
+
}
|
|
38
|
+
/* Dev only: the live-reload script sets `__abideDev` before this module runs,
|
|
39
|
+
so the runtime bridge is in place before any component mounts and records
|
|
40
|
+
its instances (mountChild) for hot replacement. */
|
|
41
|
+
if ((globalThis as { __abideDev?: boolean }).__abideDev) {
|
|
42
|
+
installHotBridge()
|
|
43
|
+
}
|
|
44
|
+
const ssr = (globalThis as { __SSR__?: SsrPayload }).__SSR__ ?? {}
|
|
45
|
+
setBaseResolver(() => ssr.base ?? '')
|
|
46
|
+
/* The `page` proxy reads route/params/url off the router-updated snapshot. */
|
|
47
|
+
setPageResolver(() => clientPage.value)
|
|
48
|
+
|
|
49
|
+
const store = createCacheStore()
|
|
50
|
+
setCacheStoreResolver(() => store)
|
|
51
|
+
/* One tab store: cache(fn, { global: true }) shares it, so global is a no-op here. */
|
|
52
|
+
setGlobalCacheStoreResolver(() => store)
|
|
53
|
+
for (const entry of ssr.cache ?? []) {
|
|
54
|
+
store.entries.set(entry.key, cacheEntryFromSnapshot(entry))
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
return router(target, routes, layoutRoutes, probeNavigation)
|
|
58
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { createSignalNode } from './runtime/createSignalNode.ts'
|
|
2
|
+
import { readNode } from './runtime/readNode.ts'
|
|
3
|
+
import type { State } from './runtime/types/State.ts'
|
|
4
|
+
import { writeNode } from './runtime/writeNode.ts'
|
|
5
|
+
|
|
6
|
+
/*
|
|
7
|
+
A writable reactive cell — abide's from-scratch reactive primitive, with no
|
|
8
|
+
compiler sigil and no external reactivity-library import. `.value` is a
|
|
9
|
+
plain getter/setter over a signal node, so a read/write shows up as exactly that
|
|
10
|
+
in a stack trace. The compiler's job (later) is only to auto-deref `{cell}` in
|
|
11
|
+
templates and tag this declaration as a serializable manifest slot; the runtime
|
|
12
|
+
needs no magic.
|
|
13
|
+
*/
|
|
14
|
+
// @readme plumbing
|
|
15
|
+
export function state<T>(initial: T): State<T> {
|
|
16
|
+
const node = createSignalNode(initial)
|
|
17
|
+
return {
|
|
18
|
+
get value(): T {
|
|
19
|
+
return readNode(node) as T
|
|
20
|
+
},
|
|
21
|
+
set value(next: T) {
|
|
22
|
+
writeNode(node, next)
|
|
23
|
+
},
|
|
24
|
+
}
|
|
25
|
+
}
|