@redocly/framework 1.0.0-next.4 → 1.0.0-next.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/bundler/build/output-metadata.js +1 -1
- package/dist/bundler/build/run.js +1 -1
- package/dist/bundler/build/vite-config.js +2 -2
- package/dist/bundler/dev/materialization-sweeper.js +1 -1
- package/dist/bundler/dev/routes/dev-problems-route.js +1 -1
- package/dist/bundler/dev/routes/source-sync-route.js +1 -1
- package/dist/bundler/dev/run.js +1 -1
- package/dist/bundler/dev/runtime-app.js +1 -1
- package/dist/bundler/dev/vite-chunk-url.js +1 -1
- package/dist/bundler/user-markdoc-schema.js +1 -1
- package/dist/bundler/vite-config.base.js +3 -3
- package/dist/cli/commands/build.js +1 -1
- package/dist/cli/commands/dev.js +1 -1
- package/dist/cli/commands/ingest.js +1 -1
- package/dist/cli/commands/translate.js +2 -2
- package/dist/cli/dev-console/index.js +1 -1
- package/dist/cli/log-output/index.js +1 -1
- package/dist/cli/validate-react-pages.js +1 -1
- package/dist/client/RuntimeLink.js +1 -1
- package/dist/client/ai-search/use-ai-search.js +1 -1
- package/dist/client/analytics-page-view.js +1 -1
- package/dist/client/app.js +3 -3
- package/dist/client/client-entry.js +1 -1
- package/dist/client/contexts.js +1 -1
- package/dist/client/dev-problems/ProblemsBar.js +1 -1
- package/dist/client/feedback.js +1 -1
- package/dist/client/l10n/use-l10n-config.js +1 -1
- package/dist/client/products.js +1 -1
- package/dist/client/review/ReviewBar.js +50 -50
- package/dist/client/review/use-review.js +1 -1
- package/dist/client/sidebar/SidebarDataProvider.js +1 -1
- package/dist/client/sidebar/drilldown.js +1 -1
- package/dist/client/ssr.js +1 -1
- package/dist/client/telemetry/config.js +1 -1
- package/dist/client/use-entity-revisions.js +1 -1
- package/dist/client/use-page-versions.js +1 -1
- package/dist/client/use-search.js +1 -1
- package/dist/client/webmcp/tools/shared.js +1 -1
- package/dist/client/webmcp/tools/site-tools.js +1 -1
- package/dist/client/webmcp/use-webmcp-tools.js +1 -1
- package/dist/content-layer/config.js +1 -1
- package/dist/content-layer/database/invalidation.js +26 -26
- package/dist/content-layer/ingest/finalize-phase.js +1 -1
- package/dist/content-layer/ingest/normalize-artifacts.js +1 -1
- package/dist/content-layer/ingest/run.js +1 -1
- package/dist/content-layer/ingest/search-sync.js +1 -1
- package/dist/content-layer/ingest/sync.js +1 -1
- package/dist/content-layer/link-checker/load-view.js +1 -1
- package/dist/content-layer/link-checker/validate.js +1 -1
- package/dist/content-layer/loaders/context.js +1 -1
- package/dist/content-layer/markdown/client/markdown-text.js +1 -1
- package/dist/content-layer/markdown/constants/builtin-tags.js +1 -1
- package/dist/content-layer/markdown/constants/markdown-text-tag-set.js +1 -1
- package/dist/content-layer/markdown/constants/tag-sets.js +1 -1
- package/dist/content-layer/markdown/nodes/heading.js +1 -1
- package/dist/content-layer/markdown/resolve/ast.js +1 -1
- package/dist/content-layer/markdown/resolve/markdoc-resolvers/json-schema.js +1 -1
- package/dist/content-layer/markdown/resolve/markdoc-resolvers/operation-samples.js +1 -1
- package/dist/content-layer/markdown/resolve/markdoc-resolvers/partial.js +1 -1
- package/dist/content-layer/markdown/resolve/markdoc.js +1 -1
- package/dist/content-layer/markdown/resolve/references.js +1 -1
- package/dist/content-layer/markdown/search/to-markdown.js +1 -1
- package/dist/content-layer/markdown/search/to-sections.js +1 -1
- package/dist/content-layer/markdown/server/render.js +1 -1
- package/dist/content-layer/markdown/service.js +1 -1
- package/dist/content-layer/markdown/tags/partial.d.ts +7 -2
- package/dist/content-layer/markdown/tags/partial.js +1 -1
- package/dist/content-layer/markdown/tags/variant.js +1 -1
- package/dist/content-layer/markdown/types/service.d.ts +2 -0
- package/dist/content-layer/markdown/utils/parse-cache.js +1 -1
- package/dist/content-layer/markdown/utils/reparse-example-fences.d.ts +4 -1
- package/dist/content-layer/markdown/utils/reparse-example-fences.js +1 -1
- package/dist/content-layer/markdown/utils/substitute-variables.js +1 -1
- package/dist/content-layer/markdown/utils/walk-markdoc-ast.d.ts +2 -2
- package/dist/content-layer/markdown/utils/walk-markdoc-ast.js +1 -1
- package/dist/content-layer/plugins/index.js +1 -1
- package/dist/content-layer/plugins/internal/api-docs/client/template.js +2 -2
- package/dist/content-layer/plugins/internal/api-docs/index.js +1 -1
- package/dist/content-layer/plugins/internal/api-docs/server/markdown-docs.js +13 -13
- package/dist/content-layer/plugins/internal/api-docs/server/options.js +1 -1
- package/dist/content-layer/plugins/internal/app-data/banner.js +1 -1
- package/dist/content-layer/plugins/internal/app-data/index.js +1 -1
- package/dist/content-layer/plugins/internal/catalog-classic/client/use-catalog-classic.js +1 -1
- package/dist/content-layer/plugins/internal/catalog-classic/index.js +1 -1
- package/dist/content-layer/plugins/internal/index.js +1 -1
- package/dist/content-layer/plugins/internal/markdoc/client/template.js +1 -1
- package/dist/content-layer/plugins/internal/markdoc/index.js +1 -1
- package/dist/content-layer/plugins/internal/mcp/constants.d.ts +6 -0
- package/dist/content-layer/plugins/internal/mcp/constants.js +1 -1
- package/dist/content-layer/plugins/internal/mcp/content-tools.js +1 -1
- package/dist/content-layer/plugins/internal/mcp/ignored-routes.js +1 -1
- package/dist/content-layer/plugins/internal/mcp/server/audit.js +1 -1
- package/dist/content-layer/plugins/internal/mcp/server/codemode/capabilities.js +3 -3
- package/dist/content-layer/plugins/internal/mcp/server/codemode/constants.js +1 -1
- package/dist/content-layer/plugins/internal/mcp/server/codemode/discover.js +1 -1
- package/dist/content-layer/plugins/internal/mcp/server/codemode/execute-schema.js +1 -1
- package/dist/content-layer/plugins/internal/mcp/server/codemode/execution-budget.js +1 -0
- package/dist/content-layer/plugins/internal/mcp/server/codemode/index.js +1 -1
- package/dist/content-layer/plugins/internal/mcp/server/codemode/prompts.js +8 -8
- package/dist/content-layer/plugins/internal/mcp/server/codemode/read-result.js +1 -0
- package/dist/content-layer/plugins/internal/mcp/server/codemode/return-last-expression.js +6 -0
- package/dist/content-layer/plugins/internal/mcp/server/codemode/returns-from-top-level.js +1 -0
- package/dist/content-layer/plugins/internal/mcp/server/codemode/sandbox.js +1 -1
- package/dist/content-layer/plugins/internal/mcp/server/codemode/tool-declarations.js +4 -0
- package/dist/content-layer/plugins/internal/mcp/server/codemode/tool-list.js +1 -1
- package/dist/content-layer/plugins/internal/mcp/server/codemode/unknown-tool-hint.js +3 -0
- package/dist/content-layer/plugins/internal/mcp/server/gateway/api-call-operations.js +1 -1
- package/dist/content-layer/plugins/internal/mcp/server/gateway/credentials-page/site-branding.js +1 -1
- package/dist/content-layer/plugins/internal/mcp/server/gateway/credentials.js +1 -1
- package/dist/content-layer/plugins/internal/mcp/server/gateway/elicitation.js +6 -6
- package/dist/content-layer/plugins/internal/mcp/server/gateway/index.js +3 -3
- package/dist/content-layer/plugins/internal/mcp/server/gateway/subject.js +1 -1
- package/dist/content-layer/plugins/internal/mcp/server/gateway/tools.js +4 -4
- package/dist/content-layer/plugins/internal/mcp/server/gateway/upstream-auth-scheme.js +2 -2
- package/dist/content-layer/plugins/internal/mcp/server/mcp-server.js +1 -1
- package/dist/content-layer/plugins/internal/mcp/server/mcp-telemetry.js +1 -1
- package/dist/content-layer/plugins/internal/mcp/server/oauth/authorize.js +1 -1
- package/dist/content-layer/plugins/internal/mcp/server/rate-limit.js +1 -1
- package/dist/content-layer/plugins/internal/mcp/server/server-info.js +1 -1
- package/dist/content-layer/plugins/internal/mcp/server/tools/graphql-constants.js +1 -0
- package/dist/content-layer/plugins/internal/mcp/server/tools/graphql-document.js +1 -1
- package/dist/content-layer/plugins/internal/mcp/server/tools/graphql.js +1 -1
- package/dist/content-layer/plugins/internal/mcp/server/tools/openapi-catalog.js +1 -1
- package/dist/content-layer/plugins/internal/mcp/server/tools/openapi-document.js +1 -1
- package/dist/content-layer/plugins/internal/mcp/server/tools/openapi.js +1 -1
- package/dist/content-layer/plugins/internal/mcp/server/tools/pages-constants.js +1 -0
- package/dist/content-layer/plugins/internal/mcp/server/tools/pages-navigation.js +1 -1
- package/dist/content-layer/plugins/internal/mcp/server/tools/pages.js +3 -3
- package/dist/content-layer/plugins/internal/mcp/server/tools/schemas.js +1 -0
- package/dist/content-layer/plugins/internal/mcp/server/tools/search.js +1 -1
- package/dist/content-layer/plugins/internal/mcp/server/tools/submit-feedback.js +1 -1
- package/dist/content-layer/plugins/internal/mcp/server/tools/whoami.js +1 -1
- package/dist/content-layer/plugins/internal/mock/server/handler.js +1 -1
- package/dist/content-layer/plugins/internal/scorecard-classic/index.js +1 -1
- package/dist/content-layer/plugins/internal/sidebar/bundle.js +1 -1
- package/dist/content-layer/plugins/internal/sidebar/index.js +2 -2
- package/dist/content-layer/plugins/internal/skills/index.js +1 -1
- package/dist/content-layer/plugins/project/load.js +2 -2
- package/dist/content-layer/plugins/utils/link-access.js +1 -1
- package/dist/content-layer/plugins/utils/route-index.js +1 -1
- package/dist/content-layer/versions/redirect.js +1 -1
- package/dist/content-layer/versions/resolve.js +1 -1
- package/dist/server/__tests__/rbac-fixture.js +1 -1
- package/dist/server/app.js +3 -3
- package/dist/server/ask-ai/route.js +1 -1
- package/dist/server/auth/middleware.js +1 -1
- package/dist/server/auth/request.js +1 -1
- package/dist/server/auth/routes.js +1 -1
- package/dist/server/constants/system-routes.js +1 -1
- package/dist/server/content.js +13 -13
- package/dist/server/cors-proxy/handler.js +1 -1
- package/dist/server/feedback/route.js +1 -1
- package/dist/server/lambda-entry.js +1 -1
- package/dist/server/manifest-assets.js +4 -4
- package/dist/server/node-entry.js +1 -1
- package/dist/server/plugin-context.js +1 -1
- package/dist/server/rbac/l10n-rules.js +1 -1
- package/dist/server/rbac/team-templates.js +1 -1
- package/dist/server/search/route.js +1 -1
- package/dist/server/seo-tags.js +2 -2
- package/dist/server/static-files/serve.js +1 -1
- package/dist/shared/utils/routes/file-path-to-route-slug.js +1 -1
- package/package.json +2 -4
|
@@ -1 +1 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{REVISIONS_ROUTE_DEP_KEY as e}from"../shared/constants/revisions.js";import{LoaderDataContext as t}from"./contexts.js";import{useContext as n}from"react";const r={entityKey:null,items:[]};function i(t){let n=t[e];return!n||!Array.isArray(n.items)?r:{entityKey:typeof n.entityKey==`string`?n.entityKey:null,items:n.items}}function a(e){let{entityKey:t,items:n}=i(e);return!!t&&n.length>0}function o(e){let{items:r}=i(n(t));return{query:{data:void 0,isLoading:!1,isError:!1},items:r}}export{a as hasEntityRevisions,i as selectEntityRevisions,o as useFetchCatalogEntityRevisions};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{compareVersions as e,toPhysicalVersionedSlug as t,toPublicVersionedSlug as n,versionRoutePrefix as r}from"../shared/constants/versions.js";import{PageContext as i,SidebarDataContext as a}from"./contexts.js";import{useContext as o,useMemo as s}from"react";const c=[];function l(e){return{name:typeof e?.version==`string`?e.version:void 0,group:typeof e?.versionGroup==`string`?e.versionGroup:void 0}}function u(i,a){let{name:o,group:s}=l(a);if(s===void 0||o===void 0)return c;let u=/* @__PURE__ */ new Map,d=e=>{for(let t of e){if(typeof t!=`object`||!t)continue;let e=t;if(e.versionGroup===s&&typeof e.version==`string`&&typeof e.link==`string`){let t=u.get(e.version);t||(t={firstLink:e.link,isDefault:!1,links:/* @__PURE__ */ new Set},u.set(e.version,t)),t.links.add(e.link),e.isDefaultVersion===!0&&(t.isDefault=!0),t.label===void 0&&typeof e.versionLabel==`string`&&(t.label=e.versionLabel)}Array.isArray(e.items)&&d(e.items)}};if(d(i??[]),u.size===0)return c;let f=a?.slug??``,p=t(f,s,o),m=p===null?null:p.slice(r(s,o).length),h=(e,t)=>{if(m===null)return t.firstLink;let i=n(`${r(s,e)}${m}`,s,e,t.isDefault);return t.links.has(i)?i:t.firstLink};return[...u.entries()].sort(([t],[n])=>e(n,t)).map(([e,t])=>({version:e,label:t.label??e,link:e===o?f:h(e,t),default:t.isDefault,active:e===o,folderId:e}))}function d(){let e=o(a),t=o(i);return{versions:s(()=>u(e.allItems??e.items,t),[e,t])}}export{l as selectActiveVersion,u as selectPageVersions,d as usePageVersionsImpl};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{SEARCH_GROUP_FACET_FIELD as e,readSearchAppData as t}from"../shared/search/facets.js";import{
|
|
1
|
+
import{SEARCH_GROUP_FACET_FIELD as e,readSearchAppData as t}from"../shared/search/facets.js";import{SEARCH_FACETS_ROUTE_PATH as n,SEARCH_ROUTE_PATH as r}from"../shared/constants/search.js";import{APP_DATA_LOADER_KEY as i}from"../shared/constants/app-data.js";import{withPathPrefix as a}from"../shared/path-prefix.js";import{LoaderDataContext as o,PageContext as s}from"./contexts.js";import{readAppData as c}from"../shared/utils/app-data.js";import{useL10nConfig as l}from"./l10n/use-l10n-config.js";import{telemetry as u}from"./telemetry/telemetry.js";import{selectActiveVersion as d}from"./use-page-versions.js";import{SEARCH_DEBOUNCE_TIME_MS as f}from"@redocly/theme/core/constants";import{useCallback as p,useContext as m,useEffect as h,useMemo as g,useRef as _,useState as v}from"react";import{getBaseDataAttributes as y}from"@redocly/theme/core/utils";import{SearchSessionContext as b}from"@redocly/theme/core/contexts";async function x(e,t,n){let r=await fetch(a(e),{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify(t),signal:n});if(!r.ok)throw Error(r.statusText||`Search request failed (${r.status})`);return await r.json()}function S(e,t){return x(r,e,t)}function C(e){return Object.fromEntries(e.map(e=>[e.field,e.values]))}function w(e,t){return x(n,e,t)}function T(e){return c(e).theme?.aiAssistant?.hide===!1}function E(){let e=m(o),t=m(s);return{askAi:T(e)&&t?.aiAvailable===!0}}function D(e){return e.filter(e=>e.values.length>0).map(({field:e,values:t})=>({field:e,values:[...t]}))}function O(){let e=m(s),{currentLocale:t,defaultLocale:n}=l(),r=t===n?void 0:t,{name:i,group:a}=d(e);return g(()=>({locale:r,version:a!==void 0&&i!==void 0?{group:a,version:i}:void 0}),[r,a,i])}const k=(e,t)=>e.map(e=>({...e,isCounterVisible:t}));function A(n,r){let a=r===!1,{askAi:s}=E(),c=m(o),l=m(b)?.searchSessionId,d=O(),x=g(()=>t(c[i]),[c]),[T,A]=v(``),[j,M]=v([]),[ee,N]=v({}),[P,F]=v({}),[I,L]=v({}),[R,z]=v({}),[B,V]=v(!1),[H,U]=v(null),[W,G]=v(!1),K=_(null),q=_(null),J=_(!1),Y=g(()=>D(j),[j]),X=Y.length>0,Z=p(()=>{q.current=null,N({}),F({}),z({})},[]),Q=p((e,t,n)=>{K.current?.abort();let r=new AbortController;return K.current=r,V(!0),U(null),S(e,r.signal).then(e=>{r.signal.aborted||t(e)}).catch(e=>{r.signal.aborted||(U(e instanceof Error?e.message:`Search request failed`),n())}).finally(()=>{r.signal.aborted||V(!1)})},[]),$=p(async e=>{let t=e.trim();if(t===``&&!X){K.current?.abort(),J.current=!1,Z(),G(!1),U(null),V(!1);return}let r={query:t,...d,filter:Y,product:n};J.current=!0,await Q(r,i=>{J.current=!1,q.current=r,N(i.documents),F(i.facets??{}),z(i.groupCounts??{}),G(!0),t.length>1&&u.sendSearchQueryMessage([{...y(`searchQuery`,`search`),query:e,resultCount:Object.values(i.documents).reduce((e,t)=>e+t.length,0).toString(),...l?{searchSessionId:l}:{},...n?{product:n}:{}}])},()=>{J.current=!1,Z()})},[d,Y,X,Q,Z,n,l]),te=p(e=>{let t=typeof e==`function`?e(void 0):e,n=q.current;t&&n&&!J.current&&Q({...n,loadMore:t},e=>{let n=e.documents[t.groupKey]??[];N(e=>({...e,[t.groupKey]:[...e[t.groupKey]??[],...n]})),z(t=>({...t,...e.groupCounts}))},()=>{})},[Q]);h(()=>{if(r)return;(T.trim()!==``||X)&&V(!0);let e=setTimeout(()=>{$(T)},f);return()=>clearTimeout(e)},[T,r,X,$]),h(()=>{if(!x.advanced||!a)return;let e=new AbortController;return w({...d,product:n},e.signal).then(e=>L(C(e))).catch(()=>{e.signal.aborted||L({})}),()=>e.abort()},[x.advanced,a,d,n]),h(()=>()=>K.current?.abort(),[]);let ne=p(async()=>{await $(T)},[T,$]),re=g(()=>x.facets.map(e=>({...e,values:W?k(P[e.field]??[],!0):k(I[e.field]??[],!1)})),[x.facets,W,P,I]);return{advancedSearch:x.advanced,askAi:s,facets:re,filter:j,groupCounts:R,groupField:e,isSearchLoading:B,items:ee,query:T,searchError:H,setFilter:M,setLoadMore:te,setQuery:A,retrySearch:ne}}function j(e){let n=O(),r=m(o),a=g(()=>t(r[i]).facets.find(t=>t.field===e),[r,e]),[s,c]=v(null),[l,u]=v(null);return h(()=>{if(l===null){c(null);return}let t=new AbortController;return w({...n,field:e,query:l.query,filter:D(l.filter),facetQuery:l.facetQuery},t.signal).then(t=>{c(a?{...a,values:k(C(t)[e]??[],!0)}:null)}).catch(()=>{t.signal.aborted||c(null)}),()=>t.abort()},[e,n,l,a]),{searchFacet:s,setSearchFacet:c,setSearchFacetQuery:u}}export{S as fetchSearch,w as fetchSearchFacets,j as useFacetQuery,A as useSearch,E as useSearchFeatures,O as useSearchScope};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{normalizeRouteSlug as e}from"../../../shared/utils/routes/normalize-route-slug.js";import{
|
|
1
|
+
import{normalizeRouteSlug as e}from"../../../shared/utils/routes/normalize-route-slug.js";import{splitUrlSuffix as t}from"../../../shared/utils/routes/split-url-suffix.js";import{stripPathPrefix as n}from"../../../shared/path-prefix.js";import{markdownCopyUrl as r}from"../../../shared/utils/routes/markdown-copy-url.js";function i(i){let{path:a}=t(i);return r(e(n(a)??a))}const a=`https://site.invalid`;function o(e){let t=e.trim();if(!t.startsWith(`/`))return;let n=URL.parse(t,a);if(n?.origin===a)return`${n.pathname}${n.search}${n.hash}`}async function s(e){let t=await fetch(e,{headers:{accept:`text/plain`}});if(t.ok&&!t.headers.get(`content-type`)?.startsWith(`text/html`))return await t.text()}function c(e,t,n){let r=typeof e==`number`?e:Number(e);return!Number.isFinite(r)||r<=0?t:Math.min(Math.floor(r),n)}export{c as clampLimit,s as fetchText,i as markdownPathForRoute,o as toSitePath};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{isObject as e}from"../../../shared/utils/is-object.js";import{FEEDBACK_ROUTE_PATH as t}from"../../../shared/constants/feedback.js";import{SEARCH_ROUTE_PATH as n}from"../../../shared/constants/search.js";import{
|
|
1
|
+
import{isObject as e}from"../../../shared/utils/is-object.js";import{FEEDBACK_ROUTE_PATH as t}from"../../../shared/constants/feedback.js";import{SEARCH_ROUTE_PATH as n}from"../../../shared/constants/search.js";import{SKILLS_INDEX_SLUG as r}from"../../../content-layer/plugins/utils/skill-paths.js";import{clampLimit as i,fetchText as a,markdownPathForRoute as o,toSitePath as s}from"./shared.js";import{agentErrorResult as c,agentJsonResult as l,agentTextResult as u,collectOperations as d}from"@redocly/api-docs/lib/services/agent-tools/index.js";function f(e){return[...e.feedbackHidden?[]:[y(e)],{name:`get_current_page`,title:`Get current page`,description:`Report which documentation page the user is looking at right now, including the product and version in scope and whether it is an API reference page. Call this first so an answer matches what is on screen.`,inputSchema:{type:`object`,properties:{},additionalProperties:!1},annotations:{readOnlyHint:!0},execute:async()=>p(e)},{name:`search_docs`,title:`Search documentation`,description:`Search this documentation site and return matching pages with their titles and URLs. Use it to find the page that answers a question before reading it.`,inputSchema:{type:`object`,properties:{query:{type:`string`,description:`What to search for`},limit:{type:`integer`,description:`Maximum number of results, 10 by default`}},required:[`query`],additionalProperties:!1},annotations:{readOnlyHint:!0,untrustedContentHint:!0},execute:async t=>m(e,t)},{name:`read_page`,title:`Read a page`,description:`Return the full Markdown source of a documentation page. Omit the url to read the page the user is currently on.`,inputSchema:{type:`object`,properties:{url:{type:`string`,description:`Site-relative page path, for example /guides/quickstart`}},additionalProperties:!1},annotations:{readOnlyHint:!0,untrustedContentHint:!0},execute:async t=>h(e,t)},{name:`get_site_overview`,title:`Get site overview`,description:`Return the outline of this documentation site: its sections and the pages inside them, limited to what the current user may see. Use it to orient before searching.`,inputSchema:{type:`object`,properties:{},additionalProperties:!1},annotations:{readOnlyHint:!0,untrustedContentHint:!0},execute:async()=>g(e)},{name:`read_skill`,title:`Read an agent skill`,description:`List the agent skills this site publishes, or read one by name. A skill explains how to carry out a task against the documented product.`,inputSchema:{type:`object`,properties:{name:{type:`string`,description:`Skill name; omit to list every skill`}},additionalProperties:!1},annotations:{readOnlyHint:!0,untrustedContentHint:!0},execute:async t=>v(e,t)},{name:`navigate_page`,title:`Open a page`,description:`Move the browser tab to another page of this documentation site, so the user sees what an answer is based on. Accepts site-relative paths only.`,inputSchema:{type:`object`,properties:{url:{type:`string`,description:`Site-relative page path, optionally with a #section anchor`}},required:[`url`],additionalProperties:!1},annotations:{readOnlyHint:!1},execute:async t=>x(e,t)}]}async function p(e){let t=e.versions.find(e=>e.active);return l({url:e.pathname,title:e.pageTitle??document.title,locale:e.locale,product:e.product,version:t?.label??t?.version,isApiReference:!!e.apiDocs,...e.apiDocs?{apiBasePath:e.withPrefix(e.apiDocs.baseSlug),apiSpecType:e.apiDocs.store.specType,operationCount:d(e.apiDocs.items).length}:{}})}async function m(e,t){let r=typeof t.query==`string`?t.query.trim():``;if(!r)return c(`Provide a query to search for.`);let a=i(t.limit,10,50),o={query:r,...e.searchScope},s=await fetch(e.sitePathUrl(n),{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify(o)});if(!s.ok)return c(`Search failed with status ${s.status}.`);let{documents:d}=await s.json(),f=Object.entries(d).flatMap(([e,t])=>t.map(({document:t})=>({section:e,document:t}))).slice(0,a).map(({section:t,document:n})=>({title:n.title,url:e.withPrefix(n.url),section:t,method:n.httpMethod?.toUpperCase(),path:n.httpMethod?n.httpPath:void 0,deprecated:n.deprecated?!0:void 0,snippet:n.text.slice(0,300)}));return f.length?l({query:r,resultCount:f.length,results:f}):u(`No documentation pages matched "${r}".`)}async function h(e,t){let n=typeof t.url==`string`&&t.url.trim()?t.url.trim():e.pathname,r=s(n);if(!r)return c(`Provide a site-relative path that starts with "/".`);let i=await a(e.routeUrl(o(r)));return i?u(i):c(`${r} has no Markdown version. Either the path is wrong, or the page is built from code rather than Markdown. Use search_docs to find a documentation page.`)}async function g(e){let t=_(e.sidebarItems,e.withPrefix,0);if(t.length)return l({product:e.product,pages:t});let n=await a(e.sitePathUrl(`/llms.txt`));return n?u(n):c(`This site publishes no navigation tree.`)}function _(t,n,r){if(r>=3)return[];let i=[];for(let a of t){if(!e(a))continue;let t=typeof a.label==`string`?a.label:``,o=typeof a.link==`string`?a.link:void 0;if(!t&&!o)continue;let s=Array.isArray(a.items)?_(a.items,n,r+1):[];i.push({title:t,...o?{url:n(o)}:{},...s.length?{pages:s}:{}})}return i}async function v(t,n){let i=await fetch(t.sitePathUrl(r),{headers:{accept:`application/json`}});if(!i.ok)return c(`This site does not publish agent skills.`);let o=await i.json(),s=e(o)&&Array.isArray(o.skills)?o.skills:[],d=typeof n.name==`string`?n.name.trim():``;if(!d)return l({skills:s.map(e=>({name:e.name,description:e.description}))});let f=s.find(e=>e.name.toLowerCase()===d.toLowerCase());if(!f){let e=s.map(e=>e.name).join(`, `);return c(`No skill named "${d}". Available skills: ${e||`none`}.`)}let p=await a(t.routeUrl(f.url));return p?u(p):c(`The "${f.name}" skill could not be read.`)}function y(e){return{name:`leave_feedback`,title:`Leave feedback on a page`,description:`Report that a documentation page is wrong, outdated, confusing or incomplete. Use it only when the user agrees, and summarize the problem in their words. Reports reach the team that owns the page.`,inputSchema:{type:`object`,properties:{summary:{type:`string`,description:`One sentence naming the problem`},details:{type:`string`,description:`What is wrong and what the page should say`},url:{type:`string`,description:`Site-relative path of the page; the current page by default`}},required:[`summary`],additionalProperties:!1},annotations:{readOnlyHint:!1,consequentialHint:!0},execute:async t=>b(e,t)}}async function b(e,n){let r=typeof n.summary==`string`?n.summary.trim():``;if(!r)return c(`Describe the problem in one sentence.`);let i=typeof n.details==`string`?n.details.trim():``,a=typeof n.url==`string`&&n.url.trim()?n.url.trim():e.pathname,o=s(a);if(!o)return c(`Provide a site-relative path that starts with "/".`);let l=await fetch(e.sitePathUrl(t),{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({component:`comment`,path:e.routeUrl(o),comment:i?`${r}\n\n${i}`:r,agent:`webmcp-browser-agent`,origin:`mcp`})});return l.ok?u(`Thanks. The feedback about ${o} reached the documentation team.`):c(l.status===403||l.status===404?`Feedback cannot be left for ${o}.`:`Feedback could not be sent, status ${l.status}.`)}async function x(e,t){let n=typeof t.url==`string`?s(t.url):void 0;return n?(await e.navigate(n),u(`Opened ${n}.`)):c(`Provide a site-relative path that starts with "/". This tool cannot leave the documentation site.`)}export{f as buildSiteTools};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{stripPathPrefix as e,withPathPrefix as t}from"../../shared/path-prefix.js";import{API_DOCS_RENDER_DEP_KEY as n}from"../../content-layer/plugins/internal/api-docs/server/shared.js";import{LoaderDataContext as r,PageContext as i,SidebarDataContext as a}from"../contexts.js";import{useL10nConfig as o}from"../l10n/use-l10n-config.js";import{useCurrentProduct as s}from"../ProductsProvider.js";import{telemetry as c}from"../telemetry/telemetry.js";import{usePageVersionsImpl as l}from"../use-page-versions.js";import{useSearchScope as u}from"../use-search.js";import{rebaseItemLinks as d}from"../../content-layer/plugins/internal/api-docs/client/rebase-item-links.js";import{buildApiTools as f}from"./tools/api-tools.js";import{buildSiteTools as p}from"./tools/site-tools.js";import{useContext as m,useEffect as h,useRef as g}from"react";import{useLocation as _,useNavigate as v}from"react-router";import{useThemeConfig as y}from"@redocly/theme/core/hooks";import{registerAgentTools as b}from"@redocly/api-docs/lib/services/agent-tools/index.js";import{getModelContext as x}from"@redocly/api-docs/lib/services/agent-tools/webmcp.js";function S(){let c=_(),d=v(),{currentLocale:S}=o(),w=u(),{versions:E}=l(),D=m(a).items,O=s(),k=m(i),A=m(r)[n],j=k?.slug.toLowerCase(),M=y().feedback?.hide===!0,N=k?.metadata?.seo,P={pathname:t(c.pathname),pageTitle:N?.title,locale:S,searchScope:w,product:O?.name??O?.slug,versions:E,sidebarItems:D??[],feedbackHidden:M,navigate:async t=>{let{pathname:n,search:r,hash:i}=new URL(t,window.location.origin);await d({pathname:e(n)??n,search:r,hash:i})},withPrefix:t,routeUrl:e=>new URL(e,window.location.origin).toString(),sitePathUrl:e=>new URL(t(e),window.location.origin).toString()},F=g(P);Object.assign(F.current,P),h(()=>{let e=new AbortController;return b(p(F.current),e.signal,T(`site`)),()=>e.abort()},[M]),h(()=>{if(!x())return;let e=F.current,t=C(A,j);if(e.apiDocs=t,!t)return;let n=new AbortController;return b(f(e,t),n.signal,T(`apiReference`)),()=>{n.abort(),e.apiDocs=void 0}},[A,j])}function C(e,t){if(Array.isArray(e?.items)&&t!==void 0)return{items:e.basePath===t?e.items:d(e.items,e.basePath,t),store:e.store,baseSlug:t}}const w={id:`agentTools`,object:`feature`,uri:`urn:redocly:realm:ui:feature:agentTools`};function T(e){return{registered:t=>c.sendAgentToolsRegisteredMessage([{...w,toolCount:t,scope:e}]),called:(e,t)=>c.sendAgentToolCalledMessage([{...w,toolName:e,outcome:t}])}}export{S as useWebMcpTools};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{toJsonObject as e,toJsonValue as t}from"./database/utils/json.js";import{
|
|
1
|
+
import{toJsonObject as e,toJsonValue as t}from"./database/utils/json.js";import{hashContentBytes as n}from"../shared/utils/content-hash.js";import{isClosedToAnonymous as r,parseRbacConfigData as i}from"../server/rbac/engine.js";import{readProjectEnv as a}from"../server/project-env.js";import{listL10nDirs as o,resolveLocaleContext as s}from"../shared/utils/l10n.js";import{expandConfigRbacForL10n as c}from"../server/rbac/l10n-rules.js";import{expandConfigRbacTeamTemplates as l,listTeamDirs as u,teamTemplatePrefixes as d}from"../server/rbac/team-templates.js";import{getProcessEnv as f,getPublicEnv as p,resolveRedoclyEnvironment as m,sanitizeBranchName as h}from"../shared/public-env.js";import{resolveContentPath as g}from"../shared/utils/resolve-content-path.js";import{resolveConfigRedirects as _}from"./config-redirects.js";import{NESTED_CONFIG_SCHEMA as v,REALM_CONFIG_SCHEMA as y,sanitizeConfig as b}from"./config-schema.js";import{hashEffectiveConfig as x,resolveSiteConfig as S}from"./database/site-config.js";import{applyEnforcedAccess as C}from"./enforced-access.js";import{applyPlanGates as w}from"./plan-gates.js";import{resolve as T}from"node:path";import{interpolateEnvVariables as E}from"@redocly/config";import D from"js-yaml";const O=[`redocly.yaml`,`redocly.yml`],k=`redocly.yaml`;async function A(e,t){let r=await re(e,t),i=f();if(!r){let e=[],t=C(w($(),i,t=>e.push({code:`configuration/ignored`,message:t})),i);return{absolutePath:null,config:t,siteConfig:t,path:null,hash:null,refs:[],problems:e}}let s=await t.readBinaryFile(r.absolutePath),c=[],l=[],p=[],m=F(new TextDecoder().decode(s),r.path),h=[],g=a(i),_={contentDir:e,fs:t,env:g,refs:p,warnings:c,errors:l},v=Q(await te(await R(await I(m,{..._,deprecations:h}),``,_),_)),y={filePath:r.path},b=[],x=U(v.access)?v.access.rbac:void 0,T=K(v,{dirLocales:await o(e,t),teamDirs:await u(e,t,d(U(x)?x:{})),env:g,report:e=>b.push({...e,location:y})}),E=C(w(T,i,e=>b.push({code:`configuration/ignored`,message:e,location:y})),i),{config:D,unsetVars:O}=S(E,g);for(let e of O)c.push(`The config references process.env.${e}, which is not set.`);let k=[...c.map(e=>({code:`configuration/ignored`,message:e,location:y})),...[...new Set(h)].map(e=>({code:`configuration/deprecated`,message:e,location:y})),...l.map(e=>({code:`configuration/invalid`,severity:`error`,message:e,location:y})),...b];return{...r,config:D,siteConfig:E,hash:await n(s),refs:p,problems:k}}function j(e,t){return x(e)!==t}async function ee(e){if(e.context.configLoaded&&e.force!==!0)return{absolutePath:e.context.configFilePath?T(e.context.contentDir,e.context.configFilePath):null,config:e.context.config,siteConfig:e.context.siteConfig,path:e.context.configFilePath,hash:e.context.configHash,refs:e.context.configRefs,problems:[]};let t=await A(e.context.contentDir,e.context.platform.fs);return e.context.config=t.config,e.context.siteConfig=t.siteConfig,e.context.configFilePath=t.path,e.context.configHash=t.hash,e.context.configRefs=t.refs,e.context.configLoaded=!0,t}function M(e,t){let n=E(F(e,t),a(f())).value,{value:r,problems:i}=b(v,n);for(let e of i)e.location={filePath:t};return{config:r,problems:i}}function N(e){return e.endsWith(`/${k}`)}async function P(e){let t=[];for(let n of e.paths)try{let r=await e.fs.readFile(T(e.contentDir,n));t.push(...M(r,n).problems)}catch(e){let r=e instanceof Error?e.message:String(e);t.push({code:`configuration/invalid`,message:`The config cannot be read: ${r}`,location:{filePath:n}})}return t}function F(t,n){let r=D.load(t);if(r==null)return{};try{return e(r)}catch(e){throw Error(`Expected ${n} to contain a YAML object.`,{cause:e})}}async function I(e,t){let{env:n,...r}=e;if(!U(n))return e;let i=t.env.PUBLIC_REDOCLY_BRANCH_NAME,a=[...i?[`branch.${h(i)}`]:[],m(t.env.REDOCLY_ENV)],o=e=>t.deprecations.push(e),s=J(r,o);for(let e of a){let r=await L(n[e],e,t);r&&(s=H(s,J(r,o)))}return s}async function L(e,t,n){if(!U(e))return null;if(typeof e.$ref!=`string`)return e;let{$ref:r,...i}=e,a=`env.${t}`,o=z(await B(r,a,n),i,a,n);return U(o)?o:null}async function R(e,t,n){if(Array.isArray(e))return Promise.all(e.map((e,r)=>R(e,`${t}[${r}]`,n)));if(!U(e))return e;if(typeof e.$ref==`string`){let{$ref:r,...i}=e;return z(await B(r,t,n),await R(i,t,n),t,n)}let r={};for(let[i,a]of Object.entries(e))r[i]=await R(a,t===``?i:`${t}.${i}`,n);return r}function z(e,t,n,r){if(Object.keys(t).length===0)return e;if(U(e))return{...e,...t};if(e==null)return t;let i=Array.isArray(e)?`list`:`scalar`;return r.warnings.push(`${n===``?`The config`:n} has keys next to a $ref to a ${i}; only the referenced file applies.`),e}function B(e,n,r){return V(e,`${n} $ref`,r,e=>t(D.load(e)))}async function V(e,t,r,i,a=`warning`){let o=a===`error`?r.errors:r.warnings,s=g(e,O[0]);if(s===null)return o.push(`${t} "${e}" escapes the content root.`),null;try{let e=await r.fs.readBinaryFile(T(r.contentDir,s));return r.refs.push({path:s,hash:await n(e)}),i(new TextDecoder().decode(e))}catch(n){let r=n instanceof Error?n.message:String(n);return o.push(`Cannot read ${t} "${e}": ${r}`),null}}async function te(e,t){let{seo:n}=e;if(!U(n)||!U(n.llmstxt)||!U(n.llmstxt.details))return e;let{path:r,...i}=n.llmstxt.details;if(typeof r!=`string`)return e;let a=null;i.content===void 0?a=await V(E(r,t.env).value,`seo.llmstxt.details.path`,t,e=>e,`error`):t.errors.push(`seo.llmstxt.details.path and seo.llmstxt.details.content are mutually exclusive; the path is ignored.`);let o={...n.llmstxt,details:a===null?i:{...i,path:r,content:a}};return{...e,seo:{...n,llmstxt:o}}}function H(e,t){let n={...e};for(let[e,r]of Object.entries(t)){if(e===`__proto__`||e===`constructor`||e===`prototype`)continue;let t=n[e];n[e]=U(t)&&U(r)?H(t,r):r}return n}function U(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}const W=[`hide`,`name`,`ignore`,`publicEndpoint`],G=[`requiresLogin`,`rbac`,`sso`,`idps`,`logoutReturnUrl`,`residency`];function K(e,t={}){let n=t.report??(()=>{}),r=t.dirLocales??[],i=J(e,e=>n({code:`configuration/deprecated`,message:e}));U(i.mcp)&&i.mcp.docs!==void 0&&n({code:`configuration/deprecated`,message:`The 'mcp.docs' property is deprecated. Use the 'mcp' properties instead.`});let a=b(y,i,{env:t.env});for(let e of a.problems)n(e);let{redirects:o,access:u,...d}=c(l(q(a.value,t.env),t.teamDirs??{},n),r),f={...d,publicEnv:p()};u&&(f.access=ne(u,n));let m=_(o,s(d.l10n,r));return m&&(f.redirects=m),f}function q(e,t){if(!t)return e;let n={...e};for(let r of[`access`,`l10n`,`redirects`])r in e&&(n[r]=E(e[r],t).value);return n}function J(e,t){return Z(Y(Q(e),t))}function Y(e,t){let n=e;e.reunite!==void 0&&(t(`The 'reunite' property is deprecated. Use 'platform' instead.`),e.platform!==void 0&&e.platform!==null&&t(`Both 'platform' and 'reunite' are set. 'reunite' is ignored, so remove it.`),n=X(e));let{access:r}=n;return U(r)&&U(r.rbac)&&r.rbac.reunite!==void 0&&(t(`The 'access.rbac.reunite' property is deprecated. Use 'access.rbac.platform' instead.`),n={...n,access:{...r,rbac:X(r.rbac)}}),n}function X(e){let{reunite:t,...n}=e;return{...n,platform:e.platform??t}}function Z(e){let{mcp:t}=e;if(!U(t))return e;let{docs:n,...r}=t;if(!U(n))return e;let i={...n};for(let e of W){let t=n[e];delete i[e],t!==void 0&&(r[e]===void 0||r[e]===null||e===`hide`&&t===!0)&&(r[e]=t)}return{...e,mcp:{...r,docs:i}}}function Q(e){let t=G.map(t=>[t,e[t]]).filter(([,e])=>e!==void 0);if(t.length===0)return e;let n={...e},r=U(e.access)?{...e.access}:{};for(let[e,i]of t)delete n[e],(r[e]===void 0||r[e]===null)&&(r[e]=i);return{...n,access:r}}function ne(e,t){let n=e.rbac?i(e.rbac,e=>t({code:`configuration/invalid`,message:e})):null;return n?(e.requiresLogin===!0&&t({code:`configuration/ignored`,message:`access.requiresLogin is ignored because access.rbac is also configured — the two are mutually exclusive. Remove one.`}),{...e,requiresLogin:r(n)}):e}async function re(e,t){for(let n of O){let r=T(e,n);if(await t.exists(r))return{absolutePath:r,path:n}}return null}function $(){return K({})}export{k as NESTED_CONFIG_FILENAME,O as REDOCLY_CONFIG_FILENAMES,$ as createEmptyRealmConfig,H as deepMergeConfig,j as isConfigChanged,N as isNestedConfigPath,ee as loadContentLayerConfig,A as loadRedoclyConfig,K as normalizeRedoclyConfig,M as parseNestedConfig,P as readNestedConfigProblems};
|
|
@@ -1,27 +1,27 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{delocalizeL10nPath as e}from"../../shared/utils/l10n.js";import{assetRefs as t,entities as n,entityDeps as r,files as i,linkRefs as a,loaderConfigDeps as o,originDeps as s,pageMarkdown as c,problems as l,searchDocuments as u,searchFragmentParents as d,searchFragmentPostings as f,searchFragmentUsages as p,searchFragments as m,searchPostings as h}from"./schema.js";import{compileGlob as g,hashGlobMatches as _,matchGlob as v}from"../plugins/utils/glob.js";import{hashContentConfigDependency as y}from"../config-deps.js";import{runWithSqliteBusyRetry as b}from"./connection.js";import{createRouteQueryEvaluator as x,isRouteQueryStale as S}from"../plugins/utils/route-index.js";import{APP_DATA_ENTITY_KEY as C}from"../../shared/constants/app-data.js";import{refreshTermDocCounts as w,selectTermIdsOfDocuments as T,selectTermIdsOfFragments as E}from"./search-vocab.js";import{RETRYABLE_PROBLEM_CODES as D}from"../problems/codes.js";import{and as O,eq as k,inArray as A,sql as j}from"drizzle-orm";async function M(e){return await e.db.select({accessType:s.accessType,originFileId:s.originFileId,originFilePath:i.path,originPluginId:s.originPluginId,hook:s.hook,path:s.path,source:s.source,valueHash:s.valueHash}).from(s).leftJoin(i,k(s.originFileId,i.id)).orderBy(i.path,s.originPluginId,s.path,s.accessType)}function N(e,t){let n=/* @__PURE__ */ new Map,r=L(t);for(let t of e){if(t.source!==`config`||t.originFileId===null||t.originFilePath===null||r(t)===t.valueHash)continue;let e=`${t.originPluginId}:${t.originFilePath}`;n.has(e)||n.set(e,t)}return R([...n.values()])}function P(e,t){let n=/* @__PURE__ */ new Map;for(let r of e){if(r.source===`config`||r.originFileId===null||r.originFilePath===null||F(r,t)===r.valueHash)continue;let e=`${r.originPluginId}:${r.originFilePath}`;n.has(e)||n.set(e,r)}return R([...n.values()])}function F(e,t){if(e.source===`glob`)return _(v(t.filesByPath.keys(),e.path));let n=t.filesByPath.get(e.path)??t.ignoredFilesByPath?.get(e.path);return e.accessType===`presence`?n?`present`:`absent`:n?.hash??null}function I(e,t,n){let r=/* @__PURE__ */ new Set,i=L(n.config);for(let a of e)a.originFileId!==null||a.hook!==t||r.has(a.originPluginId)||(a.source===`config`?i(a):F(a,n))!==a.valueHash&&r.add(a.originPluginId);return r}function L(e){let t=/* @__PURE__ */ new Map;return n=>{let r=`${n.accessType}\u0000${n.path}`,i=t.get(r);return i===void 0&&(i=y(e,n),t.set(r,i)),i}}function R(e){return e.sort((e,t)=>{let n=e.originFilePath.localeCompare(t.originFilePath);return n===0?e.originPluginId.localeCompare(t.originPluginId):n})}async function z(e,t){let r=await e.db.select({accessType:o.accessType,path:o.path,key:n.key,valueHash:o.valueHash}).from(o).innerJoin(n,k(o.entityId,n.id)).orderBy(n.key,o.path,o.accessType),i=/* @__PURE__ */ new Set;for(let e of r)y(t.config,e)!==e.valueHash&&i.add(e.key);let a=await U(e,{logger:t.logger,reason:`config dependency invalidation`,keys:[...i]});return a.invalidatedKeys.length>0&&t.logger?.debug(`Propagated config dependency invalidation`,{invalidatedKeys:a.invalidatedKeys.length}),a}async function B(e,t={}){let r=await e.db.selectDistinct({key:n.key}).from(l).innerJoin(n,k(l.entityId,n.id)).where(O(k(l.scope,`entity`),A(l.code,[...D]),k(n.isCurrent,1)));return U(e,{logger:t.logger,reason:`retryable problem invalidation`,keys:r.map(e=>e.key)})}async function V(e,t){let r=x(t.state,t.config).memoized(),i=/* @__PURE__ */ new Set;for(let e of t.rows)e.entityId===null||e.hook===`searchable`||i.has(e.entityId)||S(r,e)&&i.add(e.entityId);if(i.size===0)return{invalidatedKeys:[]};let a=await e.db.select({key:n.key}).from(n).where(A(n.id,[...i]));return U(e,{logger:t.logger,reason:`route query invalidation`,keys:a.map(e=>e.key)})}async function H(i,a){if(a.changedFilePaths.length===0)return{invalidatedKeys:[]};let o=/* @__PURE__ */ new Set,s=await i.db.select({key:n.key}).from(n).innerJoin(r,k(r.entityId,n.id)).where(j`${r.dependencyType} in ('file','origin') and ${r.dependencyRef} in ${a.changedFilePaths}`);for(let e of s)o.has(e.key)||o.add(e.key);let c=[...new Set(a.changedFilePaths.map(e).filter(e=>e!==void 0))];if(c.length>0){let e=await i.db.select({key:n.key}).from(n).innerJoin(t,k(t.entityId,n.id)).where(A(t.path,c));for(let t of e)o.add(t.key)}let l=a.membershipChangedPaths??[];if(l.length>0){let e=await i.db.select({key:n.key,pattern:r.dependencyRef}).from(n).innerJoin(r,k(r.entityId,n.id)).where(k(r.dependencyType,`glob`));for(let t of e){let e=g(t.pattern);l.some(e)&&o.add(t.key)}}let u=await U(i,{logger:a.logger,reason:`file dependency invalidation`,keys:[...o]});return u.invalidatedKeys.length>0&&a.logger?.debug(`Propagated entity invalidation`,{changedFilePaths:a.changedFilePaths.length,invalidatedKeys:u.invalidatedKeys.length}),u}async function U(e,t){let i=new Set(t.keys),a=new Set(i),o=[...i];for(;o.length>0;){let t=o;o=[];let i=await e.db.select({key:n.key}).from(n).innerJoin(r,k(r.entityId,n.id)).where(j`${r.dependencyType} = 'entity' and ${r.dependencyRef} in ${t}`);for(let e of i)a.has(e.key)||(a.add(e.key),o.push(e.key))}let s=t.markKeys===!1?[...a].filter(e=>!i.has(e)):[...a];return s.length===0?{invalidatedKeys:[]}:(await b(()=>e.db.update(n).set({status:`stale`,invalidationSeq:j`${n.invalidationSeq} + 1`}).where(O(A(n.key,s),k(n.isCurrent,1))),{logger:t.logger,operation:t.reason}),{invalidatedKeys:s})}async function W(e,t){return b(()=>e.db.transaction(e=>G(e)),{logger:t,operation:`garbage collect orphaned entities`})}async function G(e){let t=j`(${n.isSystem} = 0 or ${n.key} <> ${C}) and ${n.isCurrent} = 1 and not exists (
|
|
2
2
|
select 1
|
|
3
|
-
from ${
|
|
4
|
-
where ${
|
|
5
|
-
and ${
|
|
6
|
-
)`,[
|
|
7
|
-
select 1 from ${
|
|
8
|
-
where live.key = ${
|
|
9
|
-
)`),{removedOrphans:
|
|
10
|
-
select ${
|
|
11
|
-
)`);let
|
|
12
|
-
where ${
|
|
13
|
-
select ${
|
|
14
|
-
)`,i=j`select ${
|
|
15
|
-
where ${
|
|
16
|
-
select ${
|
|
17
|
-
)`,
|
|
18
|
-
select ${
|
|
19
|
-
)`),await e.delete(
|
|
20
|
-
select ${
|
|
21
|
-
)`),await e.delete(
|
|
22
|
-
select ${
|
|
23
|
-
)`);let
|
|
24
|
-
select ${
|
|
25
|
-
)`;await e.delete(
|
|
26
|
-
select ${
|
|
27
|
-
)`),await e.delete(
|
|
3
|
+
from ${r}
|
|
4
|
+
where ${r.entityId} = ${n.id}
|
|
5
|
+
and ${r.dependencyType} = 'origin'
|
|
6
|
+
)`,[i]=await e.select({id:n.id}).from(n).where(t).limit(1);return i!==void 0&&await K(e,t),await e.delete(n).where(j`${n.isCurrent} = 0 and not exists (
|
|
7
|
+
select 1 from ${n} as live
|
|
8
|
+
where live.key = ${n.key} and live.is_current = 1
|
|
9
|
+
)`),{removedOrphans:i!==void 0}}async function K(e,t){await e.delete(o).where(j`${o.entityId} in (
|
|
10
|
+
select ${n.id} from ${n} where ${t}
|
|
11
|
+
)`);let r=j`select ${u.id} from ${u}
|
|
12
|
+
where ${u.entityKey} in (
|
|
13
|
+
select ${n.key} from ${n} where ${t}
|
|
14
|
+
)`,i=j`select ${m.id} from ${m}
|
|
15
|
+
where ${m.entityKey} in (
|
|
16
|
+
select ${n.key} from ${n} where ${t}
|
|
17
|
+
)`,s=[...await T(e,r),...await E(e,i)];await e.delete(h).where(j`${h.docId} in (${r})`),await e.delete(f).where(j`${f.fragmentId} in (${i})`),await e.delete(d).where(j`${d.docId} in (${r})`),await e.delete(p).where(j`${p.fragmentId} in (${i})`),await e.delete(m).where(j`${m.id} in (${i})`),await w(e,s),await e.delete(u).where(j`${u.entityKey} in (
|
|
18
|
+
select ${n.key} from ${n} where ${t}
|
|
19
|
+
)`),await e.delete(c).where(j`${c.entityKey} in (
|
|
20
|
+
select ${n.key} from ${n} where ${t}
|
|
21
|
+
)`),await e.delete(l).where(j`${l.scope} = 'entity' and ${l.entityId} in (
|
|
22
|
+
select ${n.id} from ${n} where ${t}
|
|
23
|
+
)`);let g=j`${a.entityId} in (
|
|
24
|
+
select ${n.id} from ${n} where ${t}
|
|
25
|
+
)`;await e.delete(l).where(j`${l.scope} = 'link' and ${l.linkRefId} in (
|
|
26
|
+
select ${a.id} from ${a} where ${g}
|
|
27
|
+
)`),await e.delete(a).where(g),await e.delete(n).where(t)}export{N as computeDirtyConfigOrigins,P as computeDirtyFileOrigins,I as computeDirtyPluginScopedOrigins,W as garbageCollectOrphanedEntities,G as garbageCollectOrphanedEntitiesInTransaction,M as loadOriginDependencyRows,z as propagateConfigDependencyInvalidation,H as propagateEntityInvalidation,U as propagateEntityInvalidationFromKeys,B as propagateRetryableProblemInvalidation,V as propagateRouteQueryInvalidation};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{hashJsonValue as e,isJsonObject as t,toJsonObject as n}from"../database/utils/json.js";import
|
|
1
|
+
import{hashJsonValue as e,isJsonObject as t,toJsonObject as n}from"../database/utils/json.js";import{compareStrings as r}from"../../shared/utils/compare-strings.js";import{createRecordingPluginIO as i}from"../plugins/io.js";import{createTrackedRedoclyConfig as a}from"../config-deps.js";import{dedupeFileDependencies as o,runContentPluginFinalize as s}from"../plugins/execute.js";import{dedupeRouteQueryDependencies as c}from"../plugins/utils/route-index.js";import"../../shared/constants/app-data.js";import{appDataSystemEntityDescriptor as l,isAppDataFragment as u}from"../plugins/internal/app-data/index.js";import"../plugins/index.js";import{createProblem as d}from"../problems/codes.js";import{propagateEntityInvalidationFromKeys as f}from"../database/invalidation.js";import{listGlobalProblems as p,problemRow as m}from"../database/problems.js";import{listStaticFileRecords as h,replaceStaticFileRows as g}from"../database/static-files.js";import{createSearchHandle as _}from"../search/store.js";import{appDataNamespaceConflictProblem as v,attachConflictProblem as y,finalizeFailedProblem as b,keysBlamingPlugins as x}from"../problems/producers.js";import{buildHookSourceFiles as S,createHookEntityStore as C,finalizeHookInputs as w,resolvePluginHookTriggers as T}from"./hook-inputs.js";import{loadPluginScopedRouteDepOwners as E,registerSystemEntities as D,replaceFinalizeArtifacts as O,replaceFinalizeProblems as k,replaceFinalizeReads as A}from"../database/finalize.js";import{createEntityDescriber as j,normalizeRouteDependency as M}from"./normalize-artifacts.js";import{collectStaticFileRows as N,settleStaticFileClaims as P}from"../static/registry.js";async function F(e){let t=T(`finalize`,e.context,e.workingState,e.pluginScopedOriginRows,e.routeQueryRows,e.hookState,w(e.localeContext)),n=e.context.pluginRegistry.listFinalizePlugins().filter(t.shouldRun).map(e=>({plugin:e,inputsHash:t.fingerprintOf(e)})),r=n.map(({plugin:e})=>e.id),i=await L(e.database,r),a=/* @__PURE__ */ new Map,o=R(e.workingState,e.context),s=/* @__PURE__ */ new Map,c=[],l=[],u=[],d=[];for(let{plugin:r,inputsHash:f}of n){let n=await I({plugin:r,context:e.context,database:e.database,localeContext:e.localeContext,workingState:e.workingState,processedFiles:e.files,matchedPaths:t.matchedPathsOf(r),routeQueries:t.evaluator,attachOwnerByKey:i,staticFilesByPlugin:a,namespaceOwners:o,fragmentUpdates:s,pendingTrackedDependencyWrites:c,inputsHash:f,logger:e.logger,collectEntities:e.collectEntities,conflicts:u,staticProblems:d});for(let e of n.problems)l.push({pluginId:r.id,problem:e})}s.size>0&&await q(e.database,e.context,s);let f=new Set(e.context.pluginRegistry.listFinalizePlugins().map(e=>e.id));if(await W(e,a,d,f),r.length>0){let t=await p(e.database,`finalize`),n=U(t,new Set(r),f);await k(e.database,{pluginIds:r,pluginProblems:l.map(({pluginId:e,problem:t})=>m(t,{scope:`origin`,originFileId:null,originPluginId:e,hook:`finalize`})),globalKeys:[.../* @__PURE__ */ new Set([...u.map(e=>e.key),...x(t,n)])],globalProblems:u.map(e=>m(e.problem,{scope:`global`,source:`finalize`,key:e.key})),logger:e.logger})}for(let t of c)await V(e.database,t);return{ranPluginIds:r}}async function I(e){let t=e.logger.child(`content-layer:plugin:${e.plugin.id}`),r=await S(e.matchedPaths,e.processedFiles,{database:e.database,workingState:e.workingState}),o=a(e.context.config),c=[],l=i(e.context.platform.fs,e.context.contentDir,()=>e.workingState.filesByPath.keys(),e=>c.push(e)),u=[],f=e=>u.push(e),p=await s(e.plugin,{files:r,routes:e.routeQueries.index(f),io:l,config:o.config,localeContext:e.localeContext,entities:C(e.context,e.database,e.workingState,f),search:_(e.database),logger:t});if(!p.ok)return{problems:[b({pluginId:e.plugin.id,message:p.error.message})]};let m=p.value??{};return e.fragmentUpdates.set(e.plugin.id,m.appData===void 0?B(e.plugin.id,e.namespaceOwners):z({pluginId:e.plugin.id,appData:n(m.appData),namespaceOwners:e.namespaceOwners,conflicts:e.conflicts})),e.staticFilesByPlugin.set(e.plugin.id,await H({plugin:e.plugin,result:m,workingState:e.workingState,context:e.context,database:e.database,attachOwnerByKey:e.attachOwnerByKey,recordFileDependency:e=>c.push(e),conflicts:e.conflicts,staticProblems:e.staticProblems,logger:t,collectEntities:e.collectEntities})),e.pendingTrackedDependencyWrites.push({pluginId:e.plugin.id,inputsHash:e.inputsHash,configDependencies:o.collectDependencies(),fileDependencies:c,routeQueryDependencies:u,logger:t}),{problems:(m.problems??[]).map(d)}}async function L(e,t){let n=await E(e,t);return new Map(n.map(e=>[`${e.routeSlug}\u0000${e.key}`,e.originPluginId]))}function R(e,n){let r=/* @__PURE__ */ new Map,i=e.entitiesByKey.get(`app-data`)?.loaderArgs??null,a=t(i)&&t(i.fragments)?i.fragments:{},o=new Set(n.pluginRegistry.listFinalizePlugins().map(e=>e.id));for(let[e,t]of Object.entries(a))u(t)&&o.has(t.owner)&&r.set(e,t.owner);return r}function z(e){B(e.pluginId,e.namespaceOwners);let t={};for(let[n,r]of Object.entries(e.appData)){let i=e.namespaceOwners.get(n);if(i!==void 0&&i!==e.pluginId){e.conflicts.push(v({namespace:n,ownerPluginId:i,pluginId:e.pluginId}));continue}e.namespaceOwners.set(n,e.pluginId),t[n]=r}return t}function B(e,t){for(let[n,r]of t)r===e&&t.delete(n);return null}async function V(e,t){let n=[...t.configDependencies.map(e=>({...e,source:`config`})),...o(t.fileDependencies)];await A(e,{originPluginId:t.pluginId,fingerprint:t.inputsHash,dependencies:n,routeQueries:c(t.routeQueryDependencies),logger:t.logger})}async function H(t){let n=G({context:t.context,pluginId:t.plugin.id,result:t.result,state:t.workingState,attachOwnerByKey:t.attachOwnerByKey,recordFileDependency:t.recordFileDependency,conflicts:t.conflicts,staticProblems:t.staticProblems,logger:t.logger});await O(t.database,{originPluginId:t.plugin.id,routeDependencies:n.routeDependencies,entities:n.entities,logger:t.logger}),t.collectEntities?.(n.entities);let r=n.entities.flatMap(({key:n,kind:r,value:i})=>r===`inline`&&t.workingState.entitiesByKey.get(n)?.dataHash!==(i===null?null:e(i))?[n]:[]);if(r.length>0){let{invalidatedKeys:e}=await f(t.database,{keys:r,reason:`invalidate finalize entity readers`,markKeys:!1,logger:t.logger});for(let n of e){let e=t.workingState.entitiesByKey.get(n);e&&(e.status=`stale`)}}return n.staticFiles}function U(e,t,n){let r=new Set(t);for(let t of e){let e=t.data===null?void 0:t.data.pluginId;typeof e==`string`&&!n.has(e)&&r.add(e)}return r}async function W(e,t,n,r){let i=await h(e.database),a=await p(e.database,`static`),o=i.filter(e=>!t.has(e.ownerPluginId)),s=P({kept:o,collected:[...t],routeBySlug:e.workingState.routeBySlug,reservedSlugs:e.context.pluginRegistry.listReservedSlugs(),problems:n}),c=U(a,new Set(t.keys()),r),l=/* @__PURE__ */ new Set([...n.map(e=>e.key),...o.map(e=>e.path),...x(a,c)]);await g(e.database,{ownerPluginIds:[...s.keys()],rows:[...s].flatMap(([e,t])=>t.map(t=>({...t,ownerPluginId:e}))),problems:{keys:[...l],newProblems:n.map(e=>m(e.problem,{scope:`global`,source:`static`,key:e.key}))}})}function G(e){let t=/* @__PURE__ */ new Map,n=[],i=j(e.context,e.pluginId),a=e=>{t.set(e.key,e)};for(let t of e.result.entities??[])a(i(t));for(let t of e.result.attach??[])K({attachment:t,describeEntity:i,pluginId:e.pluginId,state:e.state,attachOwnerByKey:e.attachOwnerByKey,conflicts:e.conflicts,registerEntity:a,routeDependencies:n});let o=N({pluginId:e.pluginId,declarations:e.result.staticFiles??[],filesByPath:e.state.filesByPath,registerProducer:e=>{let t={...i(e.producer),shouldInvalidateValue:!1};return a(t),t.key},recordFileDependency:e.recordFileDependency,problems:e.staticProblems});return{routeDependencies:n,entities:[...t.values()].sort((e,t)=>r(e.key,t.key)),staticFiles:o}}function K(e){let{attachment:t}=e;if(e.state.routeBySlug.get(t.slug))for(let[n,r]of Object.entries(t.deps)){let i=`${t.slug}\u0000${n}`,a=e.attachOwnerByKey.get(i);if(a!==void 0){a!==e.pluginId&&e.conflicts.push(y({slug:t.slug,key:n,ownerPluginId:a,pluginId:e.pluginId}));continue}e.attachOwnerByKey.set(i,e.pluginId),e.routeDependencies.push(M({dependency:r,describeEntity:e.describeEntity,key:n,registerEntity:e.registerEntity,routeSlug:t.slug}))}}async function q(e,t,n){await D(e,[l({fragmentUpdates:n})],{logger:t.logger.child(`content-layer:db`)})}export{U as claimantsToReplace,F as runFinalizePhase};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{hashJsonValue as e,toJsonObject as t,toJsonValue as n}from"../database/utils/json.js";import{isEntityLoaderReference as r,isInlineEntityReference as i,isRawEntityReference as a}from"../loaders/define.js";import{createStoredEntityReference as o,isServerFnReference as s}from"../plugins/server-fn.js";import{compareStrings as c}from"../../shared/utils/compare-strings.js";import{isObject as l}from"../../shared/utils/is-object.js";import{
|
|
1
|
+
import{hashJsonValue as e,toJsonObject as t,toJsonValue as n}from"../database/utils/json.js";import{isEntityLoaderReference as r,isInlineEntityReference as i,isRawEntityReference as a}from"../loaders/define.js";import{createStoredEntityReference as o,isServerFnReference as s}from"../plugins/server-fn.js";import{compareStrings as c}from"../../shared/utils/compare-strings.js";import{isObject as l}from"../../shared/utils/is-object.js";import{matchContentPathMap as u}from"../plugins/utils/glob.js";import{parseContentVersion as d}from"../plugins/utils/version-path.js";import{isCoreRouteDepKey as f}from"../../shared/constants/route-deps.js";import{LIST_REVISIONS_SERVER_FN_ID as p,REVISIONS_ROUTE_DEP_KEY as m}from"../../shared/constants/revisions.js";import{deriveLocalizedRequestedSlug as h,deriveRequestedSlug as g}from"./slugger/derive-requested-slug.js";function _(e){let n=v(e);if(n===`skip`)return{routeDependencies:[],routes:[],entities:[]};let r=e.filePath===null?null:d(e.filePath),i=b(e.context,e.pluginId,r?.version??null),a=/* @__PURE__ */ new Map,o=[],s=[];for(let t of e.standaloneEntities){let e=i(t);a.set(e.key,e)}let _=/* @__PURE__ */ new Set,x=e.filePath===null?void 0:u(e.filePath,e.context.config.metadataGlobs);for(let c of e.routeDrafts){let{requestedSlug:u,slugType:d,canonicalSlug:v}=n?h({route:c,locale:n.locale,canonicalPath:n.canonicalPath,localeContext:n.localeContext,resolveCanonicalRoute:e.resolveCanonicalRoute}):{...g(c,e.filePath??``),canonicalSlug:``},b=`${c.routeId}\u0000${u}`;if(_.has(b))continue;_.add(b);let{rbac:S,excludeFromSearch:C,...w}=l(c.metadata?.metadata)?c.metadata.metadata:{},T=t({...x,...c.metadata,...w}),E=null;if(c.sidebarSubtree){let e=i(c.sidebarSubtree);a.set(e.key,e),E=e.key}for(let[t,n]of Object.entries(c.deps??{})){let r=y({dependency:n,describeEntity:i,key:t,registerEntity:e=>{a.set(e.key,e)},routeSlug:u,sourcePath:e.filePath??void 0});o.push({...r,routeId:c.routeId})}if(e.filePath!==null&&e.revisions?.isTracked(e.filePath)||r){let e=[...new Set(o.filter(e=>e.routeSlug===u&&e.dependencyType===`entity`&&!f(e.key)).map(e=>e.target))];o.push({args:{entityKeys:e,routeSlug:u},dependencyType:`serverFn`,key:m,routeId:c.routeId,routeSlug:u,target:p}),T.revisionsEnabled=!0}s.push({metadata:T,pluginId:e.pluginId,routeId:c.routeId,sidebarSubtreeEntityKey:E,wildcardPrefix:c.wildcardPrefix===!0,slug:u,requestedSlug:u,slugType:d,template:c.template?.trim()||``,versionGroup:r?.versionGroup??null,version:r?.version??null,locale:n?n.locale:``,isFallback:!1,canonicalSlug:v})}return{routeDependencies:o,routes:s,entities:[...a.values()].sort((e,t)=>c(e.key,t.key))}}function v(e){let{filePath:t,localeContext:n}=e;if(t===null||n===void 0||!n.isL10nPath(t))return null;if(!n.enabled)return`skip`;let{locale:r,canonicalPath:i}=n.splitLocaleFromPath(t);return i===``||!n.isLocale(r)?`skip`:{locale:r,canonicalPath:i,localeContext:n}}function y(e){let{dependency:t,key:n,routeSlug:r}=e;if(s(t))return{args:S(t.args,t=>{let n=e.describeEntity(t);return e.registerEntity(n),n.key}),dependencyType:`serverFn`,key:n,routeSlug:r,target:t.id};if(!a(t)){let t=e.sourcePath?` on "${e.sourcePath}"`:``;throw Error(`Unsupported route dependency "${n}"${t}.`)}let i=e.describeEntity(t);return e.registerEntity(i),{args:null,dependencyType:`entity`,key:n,routeSlug:r,target:i.key}}function b(e,t,n=null){let r=/* @__PURE__ */ new Map;return i=>{let a=r.get(i);return a===void 0&&(a=x(e,t,i,n),r.set(i,a)),a}}function x(t,n,a,s=null){if(i(a)){let t=a.key?.trim()||null;return{loaderArgs:null,kind:`inline`,type:a.type??null,metadata:a.metadata??null,loaderId:null,pluginId:n,shouldInvalidateValue:!1,key:t??`inline:${e(a.value)}`,value:a.value,isSystem:!1,version:s,searchable:a.searchable}}if(!r(a))throw Error(`Unsupported entity reference.`);let c=a.key?.trim()||null,l=S(a.args,e=>o(x(t,n,e,s).key)),u=t.pluginRegistry.getEntityLoaderById(a.id);if(!u)throw Error(`Entity loader "${a.id}" is not registered.`);return{loaderArgs:l,kind:`loader`,type:a.type??null,metadata:a.metadata??null,loaderId:a.id,pluginId:u.pluginId,shouldInvalidateValue:!0,key:c??`${a.id}:${e(l)}`,value:null,isSystem:!1,version:s}}function S(e,t){if(a(e))return t(e);if(Array.isArray(e))return e.map(e=>S(e,t));if(e&&typeof e==`object`){let r=Object.entries(e).map(([e,n])=>[e,S(n,t)]);return n(Object.fromEntries(r))}return n(e)}export{b as createEntityDescriber,x as createEntityDescriptor,_ as normalizePluginArtifacts,y as normalizeRouteDependency};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import"../../shared/constants/app-data.js";import{L10N_DIR as e}from"../../shared/constants/l10n/defaults.js";import{collectL10nDirLocales as t,l10nDirOf as n,resolveLocaleContext as r}from"../../shared/utils/l10n.js";import{formatCount as i}from"../../shared/log-format.js";import{createLogger as a,stopwatch as o}from"../../shared/logger.js";import{loadEffectiveConfigHash as s,writeSiteConfig as c}from"../database/site-config.js";import{isConfigChanged as l,isNestedConfigPath as u,loadContentLayerConfig as ee,readNestedConfigProblems as te}from"../config.js";import{contentIgnoreMatcherOf as ne,normalizeHintPaths as re,scanContentFiles as d}from"./scan.js";import{resolveContentPluginsForFile as f}from"../plugins/registry.js";import{resolveContentLayerContext as ie}from"../context.js";import{openContentLayerDatabase as p}from"../database/connection.js";import{garbageCollectOrphanBlobs as ae}from"../database/blobs.js";import{isPlanFeatureGranted as m}from"../../shared/plan-gates.js";import{listConfiguredProducts as oe,productFolderProblems as se}from"../products.js";import{appDataSystemEntityDescriptor as ce}from"../plugins/internal/app-data/index.js";import{warnWhenProjectPluginsAreNotLoaded as le}from"../plugins/project/loaded-set.js";import{apiOutputFiles as ue,readApiOutputs as de,withApiOutputHints as fe}from"../api-outputs.js";import{createContentPlugins as h}from"../plugins/create-content-plugins.js";import"../plugins/index.js";import{assembleTemplateSet as pe}from"../templates/template-set.js";import{assembleServerModuleSet as me}from"../server-modules/module-set.js";import{listRegisteredAssets as he}from"../database/assets.js";import{createProblem as g}from"../problems/codes.js";import{computeDirtyConfigOrigins as ge,computeDirtyFileOrigins as _e,garbageCollectOrphanedEntities as ve,loadOriginDependencyRows as ye,propagateConfigDependencyInvalidation as be,propagateEntityInvalidation as xe,propagateRetryableProblemInvalidation as Se}from"../database/invalidation.js";import{hasGlobalProblemsForSource as _,listGlobalProblems as Ce,listProblems as we,problemRow as v,replaceGlobalProblemsForKeysTx as Te,replaceGlobalProblemsForSourceTx as y}from"../database/problems.js";import{persistContentFileState as Ee,refreshFileLastModified as De}from"../database/files.js";import{loadContentLayerState as b,partitionIgnoredFiles as Oe}from"../context-state.js";import{hashContentFiles as x}from"./hash.js";import{selectCurrentContentFiles as S}from"./current-files.js";import{collectL10nWarnings as ke,l10nLayoutProblems as Ae,validateL10nConfig as je}from"./l10n-warnings.js";import{garbageCollectOrphanAssetFiles as Me,restoreMissingAssetFiles as Ne}from"../materialization/asset-reconcile.js";import{loadPluginHookState as Pe}from"../database/plugin-hook-state.js";import{loadRouteQueryDependencyRows as Fe}from"../database/route-query-deps.js";import{collectAppDataFragmentOwnerIds as Ie,reconcilePluginScopedRows as Le,registerSystemEntities as Re}from"../database/finalize.js";import{hasStaleManifestVersion as ze,resetContentDatabase as Be}from"../database/reset.js";import{readGitLastModified as Ve}from"./git-last-modified.js";import{createContentScanPlan as He}from"./scan-plan.js";import{collectPageRedirects as C}from"../page-redirects.js";import{runSearchSync as Ue}from"./search-sync.js";import{syncContentFiles as We}from"./sync.js";import{checkAllowedPackages as Ge}from"../allowed-packages.js";import{syncConfigLinkRefs as Ke}from"../link-checker/config-links.js";import{collectCollisionPeerOrigins as qe}from"./slugger/collision-peers.js";async function w(e){let n=ie({contentDir:e.contentDir,context:e.context,currentFileIndex:e.currentFileIndex,logger:e.logger??a(),plugins:h(e.contentDir)}),d=n.contentDir,f=n.logger.child(`content-layer`),m=f.child(`content-layer:scan`),x=f.child(`content-layer:hash`),S=f.child(`content-layer:db`),C=f.child(`content-layer:plan`),w=f.child(`content-layer:diff`),T=f.child(`content-layer:sync`),E=o();f.debug(`Starting content ingest`,{contentDir:d,hints:e.hints??[]});let D=e.database===void 0,O=e.database??await p({contentDir:d,databaseUrl:e.databaseUrl,migrationsDir:e.migrationsDir,runMigrations:e.runMigrations,platform:n.platform,logger:S});try{if(await ze(O)){S.warn(`manifest version changed — resetting content database`);let e=o();await Be(O,{logger:S}),S.info(`Reset content database`,{durationMs:e()}),n.state=void 0}let a=re(d,e.hints??[]),ie=o(),p=o(),h=await b({context:n,database:O}),D=[...h.filesByPath.values(),...h.ignoredFilesByPath.values()].sort((e,t)=>e.path.localeCompare(t.path));S.debug(`Loaded previous content state`,{loadedCount:D.length,totalCount:D.length,durationMs:p()});let j=await ee({context:n,force:!0});await le({contentDir:d,config:j.config,fs:n.platform.fs,logger:f});let M=l(A(j.config,h.routeBySlug.values()),await s(O)),N=je(n.config.l10n);for(let e of N)f.debug(e.message);(M||N.length>0||await _(O,`l10n-config`))&&await O.db.transaction(e=>y(e,`l10n-config`,N.map(e=>v(e,{scope:`global`,source:`l10n-config`})))),(M||j.problems.length>0||await _(O,`config`))&&await O.db.transaction(e=>y(e,`config`,j.problems.map(e=>v(g(e),{scope:`global`,source:`config`}))));let Xe=await Ge(j.config,d,n.platform.fs);(Xe.length>0||await _(O,`allowed-packages`))&&await O.db.transaction(e=>y(e,`allowed-packages`,Xe.map(e=>v(g(e),{scope:`global`,source:`allowed-packages`}))));let P=ne(n.config);Oe(h,P);let F=e=>de({config:n.config,contentDir:d,fs:n.platform.fs,nestedConfigPaths:e,isIgnored:P}),I=M||a.some(u),L=await F([...h.filesByPath.keys()].filter(u)),Ze=o(),R=await He({contentDir:d,fs:n.platform.fs,previousFiles:D,hints:fe(a,L),ignoredDirectories:e.ignoredDirectories,configChanged:I,logger:C});C.debug(`Resolved ingest scan plan`,{hints:R.hintedPaths.length,configChanged:I,scanTargets:R.scanTargets.length,affectedPreviousFiles:R.affectedPreviousFiles.length,durationMs:Ze()});let z=new Map(D.map(e=>[e.path,e.hash])),B=await Ye({contentDir:d,currentFileIndex:n.currentFileIndex,fs:n.platform.fs,scanPlan:R,ignoredDirectories:e.ignoredDirectories,scanLogger:m,hashLogger:x,previous:n.currentFileIndex?void 0:z,onProgress:e.onProgress});(R.hintedPaths.length===0||R.hintedPaths.includes(``))&&(L=await F(B.map(e=>e.path).filter(e=>u(e)&&!P(e))));let Qe=await ue({outputs:L,files:B,contentDir:d,fs:n.platform.fs,previous:z}),V=[...B.filter(e=>!L.has(e.path)),...Qe],H=new Map(await Ve(d,m));for(let[e,t]of L){let n=H.get(t);n!==void 0&&H.set(e,n)}f.info(`Scanned ${i(V.length)} files`,{durationMs:ie()});let $e=o(),U=k(V,R.affectedPreviousFiles,{hintScopes:R.hintScopes,totalPrevious:D.length});w.debug(`Computed content diff`,{...U.summary,durationMs:$e()}),f.info(`Compared with the previous state: ${U.summary.added} added, ${U.summary.changed} changed, ${U.summary.removed} removed, ${U.summary.unchanged} unchanged`);let et=o(),tt=o(),nt=await Ee(O,{upserts:[...U.added.map(e=>({path:e.path,hash:e.hash,lastModifiedAt:H.get(e.path)??null,manifest:JSON.stringify(e.manifest??{}),manifestVersion:e.manifestVersion})),...U.changed.map(e=>({path:e.path,hash:e.nextHash,lastModifiedAt:H.get(e.path)??null,manifest:JSON.stringify(e.file.manifest??{}),manifestVersion:e.file.manifestVersion}))],removedPaths:U.removed.map(e=>e.path),logger:S});S.debug(`Persisted content file state`,{upserts:U.added.length+U.changed.length,removed:U.removed.length,durationMs:tt()});for(let e of U.removed)h.filesByPath.delete(e.path),h.ignoredFilesByPath.delete(e.path);for(let e of nt)(P(e.path)?h.ignoredFilesByPath:h.filesByPath).set(e.path,e);let W=r(n.config.l10n,t(h.filesByPath.keys())),G=n.currentFileIndex!==void 0||I||R.hintedPaths.length===0||R.hintedPaths.includes(``);if(G){let e=Ae(ke({l10n:n.config.l10n,localeContext:W,filePaths:h.filesByPath.keys()})),t=se(oe(n.config),h.filesByPath.keys());for(let t of e)f.debug(t.message);for(let e of t)f.debug(e.message);await O.db.transaction(async n=>{await y(n,`l10n-layout`,e.map(e=>v(e,{scope:`global`,source:`l10n-layout`}))),await y(n,`products`,t.map(e=>v(g(e),{scope:`global`,source:`products`})))})}let K=G?[...h.filesByPath.keys()].filter(u):[...U.added,...U.changed].map(e=>e.path).filter(e=>u(e)&&!P(e)),q=U.removed.map(e=>e.path).filter(u);if(G||K.length>0||q.length>0){let e=(await te({contentDir:d,fs:n.platform.fs,paths:K})).map(e=>v(g(e),{scope:`global`,source:`nested-config`,key:e.location?.filePath}));await O.db.transaction(t=>G?y(t,`nested-config`,e):Te(t,`nested-config`,[...K,...q],e))}let J=V.flatMap(e=>{let t=h.filesByPath.get(e.path),n=H.get(e.path)??null;return!t||t.lastModifiedAt===n?[]:(h.filesByPath.set(e.path,{...t,lastModifiedAt:n}),[{path:e.path,lastModifiedAt:n}])});await De(O,J,S),await xe(O,{changedFilePaths:[...U.added.map(e=>e.path),...U.changed.map(e=>e.path),...U.removed.map(e=>e.path),...J.map(e=>e.path)],membershipChangedPaths:[...U.added,...U.removed].map(e=>e.path).filter(e=>!P(e)),logger:S});let rt=n.pluginRegistry.listExtractAllPlugins(),it=n.pluginRegistry.listFinalizePlugins(),at=new Set(it.map(e=>e.id)),Y=[...Ie(h.entitiesByKey.get(`app-data`)?.loaderArgs??null)].filter(e=>!at.has(e)),ot=await Le(O,[...rt.map(e=>({pluginId:e.id,hook:`extractAll`})),...it.map(e=>({pluginId:e.id,hook:`finalize`}))],{logger:S});Y.length>0&&await Re(O,[ce({fragmentUpdates:new Map(Y.map(e=>[e,null]))})],{logger:S});let[X,st,ct]=await Promise.all([ye(O),Fe(O),Pe(O)]),lt=ge(X,n.config),ut=_e(X,h);await be(O,{config:n.config,logger:S}),await Se(O,{logger:S}),await ve(O,S),(ot||Y.length>0)&&(n.state=void 0,h=await b({context:n,database:O}));let dt=await Ce(O,`slugger`),ft=qe(dt,{touchedPaths:[...U.added.map(e=>e.path),...U.changed.map(e=>e.path),...U.removed.map(e=>e.path),...lt.map(e=>e.originFilePath),...ut.map(e=>e.originFilePath)],storedFilesByPath:h.filesByPath}),Z=Je({context:n,diff:U,currentFiles:V,dirtyOrigins:[...lt,...ut,...ft],hintedPaths:R.hintedPaths,storedFilesByPath:h.filesByPath,storedPluginsByPath:h.filePluginsByPath}),pt=o(),Q=await We({context:n,database:O,localeContext:W,files:Z,removedPaths:new Set(U.removed.map(e=>e.path)),pluginScopedOriginRows:X,routeQueryRows:st,hookState:ct,storedSluggerProblems:dt,captureRevisions:e.captureRevisions,onFileSynced:(t,n)=>e.onProgress?.({stage:`sync`,done:t,total:n})});T.debug(`Synchronized content routes`,{files:Z.length,durationMs:pt()}),await Ke({database:O,config:n.config,configChanged:M,logger:S}),f.info(`Updated content state: ${U.added.length+U.changed.length} upserted, ${U.removed.length} removed, ${Z.length} synced`,{durationMs:et()}),e.searchSync!==!1&&await Ue({context:n,database:O,inlineSearchables:Q.inlineSearchables});let mt=await ae(O,{logger:S});mt.removed>0&&S.debug(`blob GC removed orphan blobs`,{count:mt.removed});let $=await Me(n.pluginIO,{contentDir:d,database:O,logger:S});if($.removedRows>0&&S.debug(`asset GC removed orphan assets`,{count:$.removedRows,swept:$.sweptFilenames.length}),e.reconcileAssetFiles??!0){let e=await Ne(n.pluginIO,{contentDir:d,registered:await he(O)});e.restored.length>0&&f.info(`Restored ${e.restored.length} missing content ${e.restored.length===1?`asset`:`assets`}`),e.missingSources.length>0&&S.warn(`registered assets are missing their source file`,{paths:e.missingSources}),e.failed.length>0&&S.warn(`could not restore missing content assets; /content-assets/* will 404`,{paths:e.failed})}let{routeBySlug:ht}=await b({context:n,database:O});n.config=A(j.config,ht.values()),await c(O,A(j.siteConfig,ht.values()),n.config);try{await O.db.transaction(e=>y(e,`system`,[]))}catch(e){S.warn(`could not clear the stored run failure`,{error:e instanceof Error?e.message:String(e)})}let gt=e.collectProblems===!1?[]:await we(O);f.debug(`Content ingest complete`,{durationMs:E()});let _t=n.state??h,vt=pe({registry:n.pluginRegistry,routes:_t.routeBySlug.values()}),yt=me({registry:n.pluginRegistry,entities:_t.entitiesByKey.values()});return{contentDir:d,diff:U,currentFiles:B,previousFiles:R.affectedPreviousFiles,problems:gt,templateSet:vt,serverModuleSet:yt,inlineSearchables:Q.inlineSearchables,routeChanges:{...Q.routeChanges,unbounded:Q.routeChanges.unbounded||M}}}finally{D&&await O.close()}}function Je(e){let t=/* @__PURE__ */ new Map;for(let n of e.diff.added)t.set(n.path,n);for(let n of e.diff.changed)t.set(n.path,n.file);let n=new Map(e.currentFiles.map(e=>[e.path,e]));for(let n of e.currentFiles)t.has(n.path)||E(e.context,n,e.storedPluginsByPath.get(n.path))&&t.set(n.path,n);for(let r of e.dirtyOrigins){let i=n.get(r.originFilePath)??O(e.context.contentDir,e.storedFilesByPath.get(r.originFilePath));i&&t.set(i.path,i)}let r=[...t.keys(),...e.diff.removed.map(e=>e.path)];for(let i of T(r,e.storedFilesByPath.keys())){if(t.has(i))continue;let r=n.get(i)??O(e.context.contentDir,e.storedFilesByPath.get(i));r&&t.set(i,r)}return Array.from(t.values())}function T(t,r){let i=new Set([...t].filter(t=>!t.startsWith(`${e}/`))),a=[];for(let e of r){let t=n(e);t!==void 0&&i.has(e.slice(`@l10n/${t}/`.length))&&a.push(e)}return a}function E(e,t,n){let r=f(e,t.path).map(e=>({id:e.id,version:e.version})).sort((e,t)=>e.id.localeCompare(t.id)),i=[...n??[]].sort((e,t)=>e.pluginId.localeCompare(t.pluginId));return r.length!==i.length||r.some((e,t)=>{let n=i[t];return n===void 0||n.pluginId!==e.id||n.pluginVersion!==e.version})}function D(e,t){return`${e.replace(/\/$/,``)}/${t}`}function O(e,t){if(t)return{absolutePath:D(e,t.path),hash:t.hash,manifestVersion:t.manifestVersion,path:t.path}}function k(e,t,n={}){let r=new Map(e.map(e=>[e.path,e])),i=new Map(t.map(e=>[e.path,e])),a=n.hintScopes??[],o=[],s=[],c=[],l=[];for(let t of e){let e=i.get(t.path);if(!e){o.push(t);continue}if(e.hash!==t.hash){s.push({path:t.path,previousHash:e.hash,nextHash:t.hash,file:t});continue}c.push(t)}for(let e of t)r.has(e.path)||l.push(e);return{added:o,changed:s,removed:l,unchanged:c,hintScopes:a,summary:{added:o.length,changed:s.length,removed:l.length,unchanged:c.length,totalCurrent:n.totalPrevious===void 0?e.length:n.totalPrevious-l.length+o.length,totalPrevious:n.totalPrevious??t.length}}}async function Ye(e){if(e.currentFileIndex){let t=S({currentFileIndex:e.currentFileIndex,hintScopes:e.scanPlan.hintScopes,hintedPaths:e.scanPlan.hintedPaths});return e.scanLogger.debug(`Using provided current file snapshot`,{count:t.length,totalCount:e.currentFileIndex.size}),t}let t=o(),n=await d({fs:e.fs,rootDir:e.contentDir,targets:e.scanPlan.scanTargets,ignoredDirectories:e.ignoredDirectories,logger:e.scanLogger});e.scanLogger.debug(`Scanned content files`,{count:n.length,durationMs:t()});let r=o(),i=await x(n,{fs:e.fs,logger:e.hashLogger,previous:e.previous,onFileHashed:(t,n)=>e.onProgress?.({stage:`scan`,done:t,total:n})});return e.hashLogger.debug(`Computed content hashes`,{count:i.length,durationMs:r()}),i}function A(e,t){let n=m(e,`redirects`)?C(t):{};return{...e,redirects:{...n,...e.redirects}}}export{k as diffContentFiles,w as runContentIngest};
|
|
1
|
+
import{formatCount as e}from"../../shared/log-format.js";import{createLogger as t,stopwatch as n}from"../../shared/logger.js";import{L10N_DIR as r}from"../../shared/constants/l10n/defaults.js";import{collectL10nDirLocales as i,l10nDirOf as a,resolveLocaleContext as o}from"../../shared/utils/l10n.js";import{loadEffectiveConfigHash as s,writeSiteConfig as c}from"../database/site-config.js";import{isConfigChanged as l,isNestedConfigPath as u,loadContentLayerConfig as ee,readNestedConfigProblems as te}from"../config.js";import{contentIgnoreMatcherOf as ne,normalizeHintPaths as re,scanContentFiles as d}from"./scan.js";import{resolveContentPluginsForFile as f}from"../plugins/registry.js";import{resolveContentLayerContext as ie}from"../context.js";import{openContentLayerDatabase as p}from"../database/connection.js";import{garbageCollectOrphanBlobs as ae}from"../database/blobs.js";import"../../shared/constants/app-data.js";import{isPlanFeatureGranted as m}from"../../shared/plan-gates.js";import{listConfiguredProducts as oe,productFolderProblems as se}from"../products.js";import{appDataSystemEntityDescriptor as ce}from"../plugins/internal/app-data/index.js";import{warnWhenProjectPluginsAreNotLoaded as le}from"../plugins/project/loaded-set.js";import{apiOutputFiles as ue,readApiOutputs as de,withApiOutputHints as fe}from"../api-outputs.js";import{createContentPlugins as h}from"../plugins/create-content-plugins.js";import"../plugins/index.js";import{assembleTemplateSet as pe}from"../templates/template-set.js";import{assembleServerModuleSet as me}from"../server-modules/module-set.js";import{listRegisteredAssets as he}from"../database/assets.js";import{createProblem as g}from"../problems/codes.js";import{computeDirtyConfigOrigins as ge,computeDirtyFileOrigins as _e,garbageCollectOrphanedEntities as ve,loadOriginDependencyRows as ye,propagateConfigDependencyInvalidation as be,propagateEntityInvalidation as xe,propagateRetryableProblemInvalidation as Se}from"../database/invalidation.js";import{hasGlobalProblemsForSource as _,listGlobalProblems as Ce,listProblems as we,problemRow as v,replaceGlobalProblemsForKeysTx as Te,replaceGlobalProblemsForSourceTx as y}from"../database/problems.js";import{persistContentFileState as Ee,refreshFileLastModified as De}from"../database/files.js";import{loadContentLayerState as b,partitionIgnoredFiles as Oe}from"../context-state.js";import{garbageCollectOrphanAssetFiles as ke,restoreMissingAssetFiles as Ae}from"../materialization/asset-reconcile.js";import{loadPluginHookState as je}from"../database/plugin-hook-state.js";import{loadRouteQueryDependencyRows as Me}from"../database/route-query-deps.js";import{runSearchSync as Ne}from"./search-sync.js";import{hashContentFiles as x}from"./hash.js";import{selectCurrentContentFiles as S}from"./current-files.js";import{collectL10nWarnings as Pe,l10nLayoutProblems as Fe,validateL10nConfig as Ie}from"./l10n-warnings.js";import{collectAppDataFragmentOwnerIds as Le,reconcilePluginScopedRows as Re,registerSystemEntities as ze}from"../database/finalize.js";import{hasStaleManifestVersion as Be,resetContentDatabase as Ve}from"../database/reset.js";import{readGitLastModified as He}from"./git-last-modified.js";import{createContentScanPlan as Ue}from"./scan-plan.js";import{collectPageRedirects as C}from"../page-redirects.js";import{syncContentFiles as We}from"./sync.js";import{checkAllowedPackages as Ge}from"../allowed-packages.js";import{syncConfigLinkRefs as Ke}from"../link-checker/config-links.js";import{collectCollisionPeerOrigins as qe}from"./slugger/collision-peers.js";async function w(r){let a=ie({contentDir:r.contentDir,context:r.context,currentFileIndex:r.currentFileIndex,logger:r.logger??t(),plugins:h(r.contentDir)}),d=a.contentDir,f=a.logger.child(`content-layer`),m=f.child(`content-layer:scan`),x=f.child(`content-layer:hash`),S=f.child(`content-layer:db`),C=f.child(`content-layer:plan`),w=f.child(`content-layer:diff`),T=f.child(`content-layer:sync`),E=n();f.debug(`Starting content ingest`,{contentDir:d,hints:r.hints??[]});let D=r.database===void 0,O=r.database??await p({contentDir:d,databaseUrl:r.databaseUrl,migrationsDir:r.migrationsDir,runMigrations:r.runMigrations,platform:a.platform,logger:S});try{if(await Be(O)){S.warn(`manifest version changed — resetting content database`);let e=n();await Ve(O,{logger:S}),S.info(`Reset content database`,{durationMs:e()}),a.state=void 0}let t=re(d,r.hints??[]),ie=n(),p=n(),h=await b({context:a,database:O}),D=[...h.filesByPath.values(),...h.ignoredFilesByPath.values()].sort((e,t)=>e.path.localeCompare(t.path));S.debug(`Loaded previous content state`,{loadedCount:D.length,totalCount:D.length,durationMs:p()});let j=await ee({context:a,force:!0});await le({contentDir:d,config:j.config,fs:a.platform.fs,logger:f});let M=l(A(j.config,h.routeBySlug.values()),await s(O)),N=Ie(a.config.l10n);for(let e of N)f.debug(e.message);(M||N.length>0||await _(O,`l10n-config`))&&await O.db.transaction(e=>y(e,`l10n-config`,N.map(e=>v(e,{scope:`global`,source:`l10n-config`})))),(M||j.problems.length>0||await _(O,`config`))&&await O.db.transaction(e=>y(e,`config`,j.problems.map(e=>v(g(e),{scope:`global`,source:`config`}))));let Xe=await Ge(j.config,d,a.platform.fs);(Xe.length>0||await _(O,`allowed-packages`))&&await O.db.transaction(e=>y(e,`allowed-packages`,Xe.map(e=>v(g(e),{scope:`global`,source:`allowed-packages`}))));let P=ne(a.config);Oe(h,P);let F=e=>de({config:a.config,contentDir:d,fs:a.platform.fs,nestedConfigPaths:e,isIgnored:P}),I=M||t.some(u),L=await F([...h.filesByPath.keys()].filter(u)),Ze=n(),R=await Ue({contentDir:d,fs:a.platform.fs,previousFiles:D,hints:fe(t,L),ignoredDirectories:r.ignoredDirectories,configChanged:I,logger:C});C.debug(`Resolved ingest scan plan`,{hints:R.hintedPaths.length,configChanged:I,scanTargets:R.scanTargets.length,affectedPreviousFiles:R.affectedPreviousFiles.length,durationMs:Ze()});let z=new Map(D.map(e=>[e.path,e.hash])),B=await Ye({contentDir:d,currentFileIndex:a.currentFileIndex,fs:a.platform.fs,scanPlan:R,ignoredDirectories:r.ignoredDirectories,scanLogger:m,hashLogger:x,previous:a.currentFileIndex?void 0:z,onProgress:r.onProgress});(R.hintedPaths.length===0||R.hintedPaths.includes(``))&&(L=await F(B.map(e=>e.path).filter(e=>u(e)&&!P(e))));let Qe=await ue({outputs:L,files:B,contentDir:d,fs:a.platform.fs,previous:z}),V=[...B.filter(e=>!L.has(e.path)),...Qe],H=new Map(await He(d,m));for(let[e,t]of L){let n=H.get(t);n!==void 0&&H.set(e,n)}f.info(`Scanned ${e(V.length)} files`,{durationMs:ie()});let $e=n(),U=k(V,R.affectedPreviousFiles,{hintScopes:R.hintScopes,totalPrevious:D.length});w.debug(`Computed content diff`,{...U.summary,durationMs:$e()}),f.info(`Compared with the previous state: ${U.summary.added} added, ${U.summary.changed} changed, ${U.summary.removed} removed, ${U.summary.unchanged} unchanged`);let et=n(),tt=n(),nt=await Ee(O,{upserts:[...U.added.map(e=>({path:e.path,hash:e.hash,lastModifiedAt:H.get(e.path)??null,manifest:JSON.stringify(e.manifest??{}),manifestVersion:e.manifestVersion})),...U.changed.map(e=>({path:e.path,hash:e.nextHash,lastModifiedAt:H.get(e.path)??null,manifest:JSON.stringify(e.file.manifest??{}),manifestVersion:e.file.manifestVersion}))],removedPaths:U.removed.map(e=>e.path),logger:S});S.debug(`Persisted content file state`,{upserts:U.added.length+U.changed.length,removed:U.removed.length,durationMs:tt()});for(let e of U.removed)h.filesByPath.delete(e.path),h.ignoredFilesByPath.delete(e.path);for(let e of nt)(P(e.path)?h.ignoredFilesByPath:h.filesByPath).set(e.path,e);let W=o(a.config.l10n,i(h.filesByPath.keys())),G=a.currentFileIndex!==void 0||I||R.hintedPaths.length===0||R.hintedPaths.includes(``);if(G){let e=Fe(Pe({l10n:a.config.l10n,localeContext:W,filePaths:h.filesByPath.keys()})),t=se(oe(a.config),h.filesByPath.keys());for(let t of e)f.debug(t.message);for(let e of t)f.debug(e.message);await O.db.transaction(async n=>{await y(n,`l10n-layout`,e.map(e=>v(e,{scope:`global`,source:`l10n-layout`}))),await y(n,`products`,t.map(e=>v(g(e),{scope:`global`,source:`products`})))})}let K=G?[...h.filesByPath.keys()].filter(u):[...U.added,...U.changed].map(e=>e.path).filter(e=>u(e)&&!P(e)),q=U.removed.map(e=>e.path).filter(u);if(G||K.length>0||q.length>0){let e=(await te({contentDir:d,fs:a.platform.fs,paths:K})).map(e=>v(g(e),{scope:`global`,source:`nested-config`,key:e.location?.filePath}));await O.db.transaction(t=>G?y(t,`nested-config`,e):Te(t,`nested-config`,[...K,...q],e))}let J=V.flatMap(e=>{let t=h.filesByPath.get(e.path),n=H.get(e.path)??null;return!t||t.lastModifiedAt===n?[]:(h.filesByPath.set(e.path,{...t,lastModifiedAt:n}),[{path:e.path,lastModifiedAt:n}])});await De(O,J,S),await xe(O,{changedFilePaths:[...U.added.map(e=>e.path),...U.changed.map(e=>e.path),...U.removed.map(e=>e.path),...J.map(e=>e.path)],membershipChangedPaths:[...U.added,...U.removed].map(e=>e.path).filter(e=>!P(e)),logger:S});let rt=a.pluginRegistry.listExtractAllPlugins(),it=a.pluginRegistry.listFinalizePlugins(),at=new Set(it.map(e=>e.id)),Y=[...Le(h.entitiesByKey.get(`app-data`)?.loaderArgs??null)].filter(e=>!at.has(e)),ot=await Re(O,[...rt.map(e=>({pluginId:e.id,hook:`extractAll`})),...it.map(e=>({pluginId:e.id,hook:`finalize`}))],{logger:S});Y.length>0&&await ze(O,[ce({fragmentUpdates:new Map(Y.map(e=>[e,null]))})],{logger:S});let[X,st,ct]=await Promise.all([ye(O),Me(O),je(O)]),lt=ge(X,a.config),ut=_e(X,h);await be(O,{config:a.config,logger:S}),await Se(O,{logger:S}),await ve(O,S),(ot||Y.length>0)&&(a.state=void 0,h=await b({context:a,database:O}));let dt=await Ce(O,`slugger`),ft=qe(dt,{touchedPaths:[...U.added.map(e=>e.path),...U.changed.map(e=>e.path),...U.removed.map(e=>e.path),...lt.map(e=>e.originFilePath),...ut.map(e=>e.originFilePath)],storedFilesByPath:h.filesByPath}),Z=Je({context:a,diff:U,currentFiles:V,dirtyOrigins:[...lt,...ut,...ft],hintedPaths:R.hintedPaths,storedFilesByPath:h.filesByPath,storedPluginsByPath:h.filePluginsByPath}),pt=n(),Q=await We({context:a,database:O,localeContext:W,files:Z,removedPaths:new Set(U.removed.map(e=>e.path)),pluginScopedOriginRows:X,routeQueryRows:st,hookState:ct,storedSluggerProblems:dt,captureRevisions:r.captureRevisions,onFileSynced:(e,t)=>r.onProgress?.({stage:`sync`,done:e,total:t})});T.debug(`Synchronized content routes`,{files:Z.length,durationMs:pt()}),await Ke({database:O,config:a.config,configChanged:M,logger:S}),f.info(`Updated content state: ${U.added.length+U.changed.length} upserted, ${U.removed.length} removed, ${Z.length} synced`,{durationMs:et()}),r.searchSync!==!1&&await Ne({context:a,database:O,inlineSearchables:Q.inlineSearchables});let mt=await ae(O,{logger:S});mt.removed>0&&S.debug(`blob GC removed orphan blobs`,{count:mt.removed});let $=await ke(a.pluginIO,{contentDir:d,database:O,logger:S});if($.removedRows>0&&S.debug(`asset GC removed orphan assets`,{count:$.removedRows,swept:$.sweptFilenames.length}),r.reconcileAssetFiles??!0){let e=await Ae(a.pluginIO,{contentDir:d,registered:await he(O)});e.restored.length>0&&f.info(`Restored ${e.restored.length} missing content ${e.restored.length===1?`asset`:`assets`}`),e.missingSources.length>0&&S.warn(`registered assets are missing their source file`,{paths:e.missingSources}),e.failed.length>0&&S.warn(`could not restore missing content assets; /content-assets/* will 404`,{paths:e.failed})}let{routeBySlug:ht}=await b({context:a,database:O});a.config=A(j.config,ht.values()),await c(O,A(j.siteConfig,ht.values()),a.config);try{await O.db.transaction(e=>y(e,`system`,[]))}catch(e){S.warn(`could not clear the stored run failure`,{error:e instanceof Error?e.message:String(e)})}let gt=r.collectProblems===!1?[]:await we(O);f.debug(`Content ingest complete`,{durationMs:E()});let _t=a.state??h,vt=pe({registry:a.pluginRegistry,routes:_t.routeBySlug.values()}),yt=me({registry:a.pluginRegistry,entities:_t.entitiesByKey.values()});return{contentDir:d,diff:U,currentFiles:B,previousFiles:R.affectedPreviousFiles,problems:gt,templateSet:vt,serverModuleSet:yt,inlineSearchables:Q.inlineSearchables,routeChanges:{...Q.routeChanges,unbounded:Q.routeChanges.unbounded||M}}}finally{D&&await O.close()}}function Je(e){let t=/* @__PURE__ */ new Map;for(let n of e.diff.added)t.set(n.path,n);for(let n of e.diff.changed)t.set(n.path,n.file);let n=new Map(e.currentFiles.map(e=>[e.path,e]));for(let n of e.currentFiles)t.has(n.path)||E(e.context,n,e.storedPluginsByPath.get(n.path))&&t.set(n.path,n);for(let r of e.dirtyOrigins){let i=n.get(r.originFilePath)??O(e.context.contentDir,e.storedFilesByPath.get(r.originFilePath));i&&t.set(i.path,i)}let r=[...t.keys(),...e.diff.removed.map(e=>e.path)];for(let i of T(r,e.storedFilesByPath.keys())){if(t.has(i))continue;let r=n.get(i)??O(e.context.contentDir,e.storedFilesByPath.get(i));r&&t.set(i,r)}return Array.from(t.values())}function T(e,t){let n=new Set([...e].filter(e=>!e.startsWith(`${r}/`))),i=[];for(let e of t){let t=a(e);t!==void 0&&n.has(e.slice(`@l10n/${t}/`.length))&&i.push(e)}return i}function E(e,t,n){let r=f(e,t.path).map(e=>({id:e.id,version:e.version})).sort((e,t)=>e.id.localeCompare(t.id)),i=[...n??[]].sort((e,t)=>e.pluginId.localeCompare(t.pluginId));return r.length!==i.length||r.some((e,t)=>{let n=i[t];return n===void 0||n.pluginId!==e.id||n.pluginVersion!==e.version})}function D(e,t){return`${e.replace(/\/$/,``)}/${t}`}function O(e,t){if(t)return{absolutePath:D(e,t.path),hash:t.hash,manifestVersion:t.manifestVersion,path:t.path}}function k(e,t,n={}){let r=new Map(e.map(e=>[e.path,e])),i=new Map(t.map(e=>[e.path,e])),a=n.hintScopes??[],o=[],s=[],c=[],l=[];for(let t of e){let e=i.get(t.path);if(!e){o.push(t);continue}if(e.hash!==t.hash){s.push({path:t.path,previousHash:e.hash,nextHash:t.hash,file:t});continue}c.push(t)}for(let e of t)r.has(e.path)||l.push(e);return{added:o,changed:s,removed:l,unchanged:c,hintScopes:a,summary:{added:o.length,changed:s.length,removed:l.length,unchanged:c.length,totalCurrent:n.totalPrevious===void 0?e.length:n.totalPrevious-l.length+o.length,totalPrevious:n.totalPrevious??t.length}}}async function Ye(e){if(e.currentFileIndex){let t=S({currentFileIndex:e.currentFileIndex,hintScopes:e.scanPlan.hintScopes,hintedPaths:e.scanPlan.hintedPaths});return e.scanLogger.debug(`Using provided current file snapshot`,{count:t.length,totalCount:e.currentFileIndex.size}),t}let t=n(),r=await d({fs:e.fs,rootDir:e.contentDir,targets:e.scanPlan.scanTargets,ignoredDirectories:e.ignoredDirectories,logger:e.scanLogger});e.scanLogger.debug(`Scanned content files`,{count:r.length,durationMs:t()});let i=n(),a=await x(r,{fs:e.fs,logger:e.hashLogger,previous:e.previous,onFileHashed:(t,n)=>e.onProgress?.({stage:`scan`,done:t,total:n})});return e.hashLogger.debug(`Computed content hashes`,{count:a.length,durationMs:i()}),a}function A(e,t){let n=m(e,`redirects`)?C(t):{};return{...e,redirects:{...n,...e.redirects}}}export{k as diffContentFiles,w as runContentIngest};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{hashJsonValue as e}from"../database/utils/json.js";import{SEARCH_GROUP_FACET_FIELD as t,resolveSearchFacets as n}from"../../shared/search/facets.js";import{findProductForSlug as r}from"../../shared/products.js";import{normalizeRouteSlug as i}from"../../shared/utils/routes/normalize-route-slug.js";import{userMarkdocSchemaDigest as a}from"../markdown/constants/tag-sets.js";import{formatDuration as o}from"../../shared/log-format.js";import{hashContentBytes as s}from"../../shared/utils/content-hash.js";import{isRbacScope as c}from"../../server/rbac/engine.js";import{entities as l,pageMarkdown as u,routeQueryDeps as d,searchDocuments as f}from"../database/schema.js";import{computePathPrefixes as p}from"../../shared/utils/routes/compute-path-prefixes.js";import{replaceDataRefMarkers as m}from"../materialization/data-ref.js";import{batchValues as h,normalizeBatchSize as g}from"../database/connection.js";import{resolveDataRef as _}from"../database/blobs.js";import{createRouteQueryEvaluator as v,dedupeRouteQueryDependencies as y,isRouteQueryStale as b}from"../plugins/utils/route-index.js";import{listConfiguredProducts as x}from"../products.js";import{curationKeywordsOf as S}from"../search/keywords.js";import{createMarkdownCopyRule as ee}from"../markdown-copy-rule.js";import{createProblem as C}from"../problems/codes.js";import{problemRow as w,replaceEntityProblemsForCodesBatchTx as T}from"../database/problems.js";import"../search/postings/postings-store.js";import{createSearchStore as E}from"../search/store.js";import{loadContentLayerState as D}from"../context-state.js";import{replaceEntityRouteQueryDepsTx as O}from"../database/route-query-deps.js";import{loadAttachedRouteSlugs as te}from"../database/route-deps.js";import{toRbacTeams as k,toRbacTeamsWithinRoute as A}from"./rbac-teams.js";import{buildDocumentFacets as j}from"../search/facet-rows.js";import{SEARCH_PROBLEM_CODES as M,searchFacetInvalidProblem as N,searchableFailedProblem as P}from"../problems/producers.js";import{createHookEntityStore as F}from"./hook-inputs.js";import{and as I,eq as L,inArray as R}from"drizzle-orm";function ne(t,n,r,i){let a=[...t].sort(),o=n.map(e=>[e.name,e.slug]);return(t,n)=>{let s=[2,t,a,o,r];return n&&i!==void 0&&s.push(i),e(s)}}async function z(e){let{context:t,database:n}=e,r=t.logger.child(`content-layer:search`),i=[],s=/* @__PURE__ */ new Map,c=new Map(t.pluginRegistry.listEntityLoaders().filter(e=>e.definition.searchable!==void 0||e.definition.markdown!==void 0).map(e=>[e.definition.id,e])),l=e.inlineSearchables??/* @__PURE__ */ new Map,u=e.entityKeys===void 0?void 0:[...e.entityKeys,...l.keys()],d=await re(n,u);if(c.size===0&&l.size===0&&d.size===0)return{synced:0,problems:i};let f=await D({context:t,database:n}),p=E(n),m=v(f,t.config),g=x(t.config),_=q(f,m,g),y=_(),b=J(t),S=ee(t.config),C=ne(b,g,S.settings,a()),T=X(r,{configuredFields:b}),O=0,k=(e,t)=>{i.push(...t),s.set(e,t.map(t=>w(t,{scope:`entity`,entityId:e})))},A=(e,t,n,a)=>{let o=a instanceof Error?a.message:String(a);r.warn(`searchable failed for "${t}"; keeping its last documents: ${o}`);let c=P({entityKey:t,pluginId:n,message:o});i.push(c),s.set(e,[w(c,{scope:`entity`,entityId:e})])},j=async()=>(await B(n,s,M,r),{synced:O,problems:i});u===void 0&&await U({context:t,database:n,state:f,store:p,stored:d,searchableLoaders:c});let N=[];for(let[e,n]of l){let i=f.entitiesByKey.get(e);if(i&&i.kind===`inline`){if(n===void 0){d.has(e)&&await p.removeSource(e);continue}try{let a=await T.prepare(e,n.docs,y);N.push({entityKey:e,docs:a.docs,...Y(e,n,a.docs),sourceHash:C(i.dataHash??``,!1),pluginVersion:t.pluginRegistry.getById(i.pluginId)?.version??``}),k(i.id,[...H(e,n.problems,r),...a.problems])}catch(t){A(i.id,e,i.pluginId,t)}}}if(await p.replaceSourceDocuments(N),O+=N.length,c.size===0)return j();let F=await ie(n,[...c.keys()],e.entityKeys),I=await ae(n,m,F.map(e=>e.id)),L=F.filter(e=>{let n=c.get(e.loaderId),r=n?t.pluginRegistry.getById(n.pluginId)?.version:void 0,i=d.get(e.key);return i===void 0||i.sourceHash!==C(e.dataHash??``,n?.definition.usesProjectMarkdocSchema===!0)||i.pluginVersion!==r||I.has(e.id)});if(L.length===0)return j();let R=await te(n,L.map(e=>e.key)),z=0,G=0,Z=0,Q=0,$=0;for(let r of h(L,50)){z+=1;let i=Date.now(),a=await K(n,r);Z+=Date.now()-i,i=Date.now();let o=[];for(let i of r){let r=c.get(i.loaderId);if(r){try{let e=await W({row:i,entry:r,value:a.get(i.id),attachedSlug:R.get(i.key),context:t,database:n,state:f,evaluator:m,resolveAccess:_,prepare:T.prepare,stampOf:C,allowsMarkdownCopy:S.allows});o.push(e),k(i.id,e.problems)}catch(e){A(i.id,i.key,r.pluginId,e)}G+=1,e.onProgress?.(G,L.length)}}Q+=Date.now()-i,i=Date.now(),await V({context:t,database:n,store:p,outputs:o}),$+=Date.now()-i,O+=o.length}return u===void 0&&r.info(`Synced ${L.length} content ${L.length===1?`item`:`items`} for search in ${z} ${z===1?`chunk`:`chunks`} (load ${o(Z)}, producers ${o(Q)}, writes ${o($)})`),j()}async function B(e,t,n,r){if(t.size!==0)try{await e.db.transaction(e=>T(e,t,n))}catch(e){r.warn(`could not store the search problems of this pass`,{error:e instanceof Error?e.message:String(e)})}}async function V(e){let{context:t,outputs:n}=e;n.length!==0&&await e.database.db.transaction(async r=>{await e.store.replaceSourceDocuments(n.map(e=>({entityKey:e.row.key,docs:e.docs,fragments:e.fragments,uses:e.uses,sourceHash:e.sourceHash,pluginVersion:t.pluginRegistry.getById(e.entry.pluginId)?.version??``})),r),await O(r,{hook:`searchable`,scopes:n.map(e=>({originPluginId:e.entry.pluginId,entityId:e.row.id,dependencies:y(e.reads)}))});for(let e of n){if(await r.delete(u).where(L(u.entityKey,e.row.key)),e.markdownDocs.length===0)continue;let n=t.pluginRegistry.getById(e.entry.pluginId)?.version??``;for(let t of e.markdownDocs){let i=await Promise.all(t.chunks.map(async(r,i)=>{let a=t.headings?.[i]??null;return{entityKey:e.row.key,chunkIndex:i,routeSlug:t.routeSlug,text:r,heading:a?.heading??null,anchor:a?.anchor??null,title:t.title??null,description:t.description??null,rbacTeams:t.rbacTeams,hash:await s(new TextEncoder().encode(r)),sourceHash:e.sourceHash,pluginVersion:n}}));await r.insert(u).values(i)}}})}function H(e,t,n){let r=[],i=/* @__PURE__ */ new Set;for(let e of t??[])M.includes(e.code)?r.push(C(e)):i.add(e.code);for(let t of i)n.warn(`searchable for "${e}" reported problem code "${t}", which the search sync does not own; use one of ${M.join(`, `)}`);return r}async function U(e){for(let t of e.stored.keys()){let n=e.state.entitiesByKey.get(t);n&&(e.context.pluginRegistry.getById(n.pluginId)===void 0||n.kind!==`inline`&&(n.loaderId===null||!e.searchableLoaders.has(n.loaderId)))&&(await e.store.removeSource(t),await e.database.db.delete(u).where(L(u.entityKey,t)))}}async function W(e){let{row:t,entry:n,database:r}=e,i=n.definition.searchable,a=n.definition.markdown,o=e.value;if(!o||o.data===null||o.dataHash===null)throw Error(`Entity "${t.key}" has no stored value.`);let s=e.stampOf(o.dataHash,n.definition.usesProjectMarkdocSchema),c=await m(o.data,e=>_(r,e)),l=[],u=e=>l.push(e),d=e.evaluator.index(u),f=e.attachedSlug===void 0?void 0:d.get(e.attachedSlug),p=e.resolveAccess(u),h={config:e.context.config,entities:F(e.context,r,e.state,u),logger:e.context.logger.child(`content-layer:searchable:${n.definition.id}`),routes:d,route:f},g=i?await i(c,h):{docs:[]},v=a&&e.allowsMarkdownCopy(f)?await a(c,h):null,y=G(t.key,v,e.attachedSlug).map(e=>Object.assign(e,{rbacTeams:p.rbacTeamsForSlug(e.routeSlug)})),b=await e.prepare(t.key,g.docs??[],p);return{row:t,entry:n,docs:b.docs,...Y(t.key,g,b.docs),markdownDocs:y,sourceHash:s,reads:l,problems:[...H(t.key,g.problems,e.context.logger),...b.problems]}}function G(e,t,n){if(t===null)return[];if(!Array.isArray(t))throw Error(`markdown for "${e}" must return an array or null.`);let r=t.length>0&&typeof t[0]==`string`?[{chunks:t}]:t,i=/* @__PURE__ */ new Set,a=[];for(let t of r){let r=t.routeSlug??n;if(r!==void 0){if(!Array.isArray(t.chunks)||t.chunks.some(e=>typeof e!=`string`))throw Error(`markdown for "${e}" returned a document without string chunks.`);if(t.chunks.length!==0){if(i.has(r))throw Error(`markdown for "${e}" returned "${r}" twice.`);i.add(r),a.push({routeSlug:r,chunks:t.chunks,headings:t.headings,...typeof t.title==`string`&&t.title!==``?{title:t.title}:{},...typeof t.description==`string`&&t.description!==``?{description:t.description}:{}})}}}return a}async function K(e,t){let n=await e.db.select({id:l.id,data:l.data,dataHash:l.dataHash}).from(l).where(R(l.id,t.map(e=>e.id)));return new Map(n.map(e=>[e.id,e]))}function q(e,t,n){let i=[...e.routeBySlug.values()].filter(e=>e.wildcardPrefix),a=t=>{if(e.routeBySlug.has(t))return t;let n=new Set(p(t)),r;for(let e of i)n.has(e.slug)&&(r===void 0||e.slug.length>r.length)&&(r=e.slug);return r};return i=>{let o=t.index(i),s=e=>o.getAccess(a(e)??e),c=t=>e.routeBySlug.get(a(t)??t);return{accessForSlug:s,rbacTeamsForSlug:e=>k(s(e)),localeForSlug:e=>c(e)?.locale??``,originFilePathForSlug:e=>c(e)?.originFilePath??null,versionForSlug:e=>{let t=c(e);return t?.versionGroup!=null&&t.version!=null?{group:t.versionGroup,version:t.version}:null},productForSlug:e=>{let t=c(e),i=t?t.canonicalSlug||t.slug:e;return r(n,i)}}}}function J(e){return new Set(n(e.config).map(e=>e.field).filter(e=>e!==t))}function Y(e,t,n){let r=t.fragments??[],i=t.uses??[];if(!Array.isArray(r)||!Array.isArray(i))throw Error(`searchable for "${e}" must return fragments and uses as arrays.`);for(let t of r)if(typeof t.fragmentKey!=`string`||typeof t.name!=`string`)throw Error(`searchable for "${e}" returned a fragment without a key or name.`);let a=new Set(n.map(e=>e.docKey));return{fragments:r,uses:i.filter(e=>a.has(e.docKey))}}function X(e,t){return{async prepare(n,r,a){if(!Array.isArray(r))throw Error(`searchable for "${n}" must return { docs: SearchDocument[] }.`);let o=/* @__PURE__ */ new Set,s=/* @__PURE__ */ new Set,c=[],l=[];for(let u of r){if(Q(n,u),o.has(u.docKey))throw Error(`searchable for "${n}" returned docKey "${u.docKey}" twice.`);o.add(u.docKey);let r=i(u.routeSlug),d=a.accessForSlug(r);if(d===void 0){e.warn(`search document "${u.docKey}" of "${n}" dropped: no route "${r}"`);continue}let{facets:f,rbacScope:p,keywords:m,...h}=u,g=a.productForSlug(r),_=a.versionForSlug(r),v=j({facets:f,configuredFields:t.configuredFields,groupKey:u.groupKey,teams:A(d,p),version:_,product:g?.name??null,keywords:S(m),onDropped:(e,t)=>{let i=`${e}\u0000${t}`;s.has(i)||(s.add(i),c.push(N({entityKey:n,field:e,reason:Z[t],filePath:a.originFilePathForSlug(r)})))}}),y={...h,routeSlug:r,locale:a.localeForSlug(r),facets:v};g&&(y.product={name:g.name,folder:g.folder}),_&&(y.version=_),l.push(y)}return{docs:l,problems:c}}}}const Z={"not-an-object":`facets must be an object of field to string or string list`,reserved:`fields starting with "redocly_" are derived by the engine`,invalid:`a value must be a string, number, boolean, or a list of those`,"too-long":`a value must be at most 500 characters`,"too-many-words":`a keyword must have at most 10 words`};function Q(e,t){let n=t;if(!(typeof n==`object`&&n&&typeof n.docKey==`string`&&n.docKey!==``&&typeof n.routeSlug==`string`&&typeof n.title==`string`&&typeof n.text==`string`))throw Error(`searchable for "${e}" returned an invalid document (docKey, routeSlug, title, text are required strings).`);if(n.rbacScope!==void 0&&!c(n.rbacScope))throw Error(`searchable for "${e}" returned document "${n.docKey}" with an invalid rbacScope.`)}async function re(e,t){let n=/* @__PURE__ */ new Map;for(let r of t===void 0?[void 0]:h(t,g(void 0))){let t=await e.db.selectDistinct({entityKey:f.entityKey,sourceHash:f.sourceHash,pluginVersion:f.pluginVersion}).from(f).where(r===void 0?void 0:R(f.entityKey,[...r]));for(let{entityKey:e,...r}of t)n.set(e,r);let i=await e.db.selectDistinct({entityKey:u.entityKey,sourceHash:u.sourceHash,pluginVersion:u.pluginVersion}).from(u).where(r===void 0?void 0:R(u.entityKey,[...r]));for(let{entityKey:e,...t}of i)n.has(e)||n.set(e,t)}return n}async function ie(e,t,n){return n!==void 0&&n.length===0?[]:(await e.db.select({id:l.id,key:l.key,loaderId:l.loaderId,dataHash:l.dataHash}).from(l).where(I(L(l.status,`ready`),L(l.isCurrent,1),R(l.loaderId,[...t]),n===void 0?void 0:R(l.key,[...n]))).orderBy(l.key)).filter(e=>e.loaderId!==null)}async function ae(e,t,n){let r=/* @__PURE__ */ new Set;if(n.length===0)return r;let i=new Set(n),a=n.length<=g(void 0),o=await e.db.select({entityId:d.entityId,kind:d.kind,argument:d.argument,resultHash:d.resultHash}).from(d).where(I(L(d.hook,`searchable`),a?R(d.entityId,[...n]):void 0));for(let e of o)e.entityId!==null&&i.has(e.entityId)&&!r.has(e.entityId)&&b(t,e)&&r.add(e.entityId);return r}function $(e,t){for(let n of e)n.kind===`inline`&&t.set(n.key,n.searchable)}export{$ as collectInlineSearchables,z as runSearchSync};
|
|
1
|
+
import{hashJsonValue as e}from"../database/utils/json.js";import{SEARCH_GROUP_FACET_FIELD as t,resolveSearchFacets as n}from"../../shared/search/facets.js";import{hashContentBytes as r}from"../../shared/utils/content-hash.js";import{formatDuration as i}from"../../shared/log-format.js";import{isRbacScope as a}from"../../server/rbac/engine.js";import{normalizeRouteSlug as o}from"../../shared/utils/routes/normalize-route-slug.js";import{entities as s,pageMarkdown as c,routeQueryDeps as l,searchDocuments as u}from"../database/schema.js";import{computePathPrefixes as d}from"../../shared/utils/routes/compute-path-prefixes.js";import{replaceDataRefMarkers as f}from"../materialization/data-ref.js";import{batchValues as p,normalizeBatchSize as m}from"../database/connection.js";import{resolveDataRef as h}from"../database/blobs.js";import{createRouteQueryEvaluator as g,dedupeRouteQueryDependencies as _,isRouteQueryStale as v}from"../plugins/utils/route-index.js";import{listConfiguredProducts as y}from"../products.js";import{userMarkdocSchemaDigest as b}from"../markdown/constants/tag-sets.js";import{curationKeywordsOf as x}from"../search/keywords.js";import{findProductForSlug as S}from"../../shared/products.js";import{createMarkdownCopyRule as C}from"../markdown-copy-rule.js";import{createProblem as w}from"../problems/codes.js";import{problemRow as T,replaceEntityProblemsForCodesBatchTx as E}from"../database/problems.js";import"../search/postings/postings-store.js";import{createSearchStore as D}from"../search/store.js";import{loadContentLayerState as ee}from"../context-state.js";import{replaceEntityRouteQueryDepsTx as O}from"../database/route-query-deps.js";import{SEARCH_PROBLEM_CODES as k,searchFacetInvalidProblem as A,searchableFailedProblem as j}from"../problems/producers.js";import{loadAttachedRouteSlugs as M}from"../database/route-deps.js";import{toRbacTeams as N,toRbacTeamsWithinRoute as P}from"./rbac-teams.js";import{buildDocumentFacets as F}from"../search/facet-rows.js";import{createHookEntityStore as I}from"./hook-inputs.js";import{and as L,eq as R,inArray as z}from"drizzle-orm";function te(t,n,r,i){let a=[...t].sort(),o=n.map(e=>[e.name,e.slug]);return(t,n)=>{let s=[2,t,a,o,r];return n&&i!==void 0&&s.push(i),e(s)}}async function B(e){let{context:t,database:n}=e,r=t.logger.child(`content-layer:search`),a=[],o=/* @__PURE__ */ new Map,s=new Map(t.pluginRegistry.listEntityLoaders().filter(e=>e.definition.searchable!==void 0||e.definition.markdown!==void 0).map(e=>[e.definition.id,e])),c=e.inlineSearchables??/* @__PURE__ */ new Map,l=e.entityKeys===void 0?void 0:[...e.entityKeys,...c.keys()],u=await re(n,l);if(s.size===0&&c.size===0&&u.size===0)return{synced:0,problems:a};let d=await ee({context:t,database:n}),f=D(n),m=g(d,t.config),h=y(t.config),_=q(d,m,h),v=_(),x=J(t),S=C(t.config),w=te(x,h,S.settings,b()),E=X(r,{configuredFields:x}),O=0,A=(e,t)=>{a.push(...t),o.set(e,t.map(t=>T(t,{scope:`entity`,entityId:e})))},N=(e,t,n,i)=>{let s=i instanceof Error?i.message:String(i);r.warn(`searchable failed for "${t}"; keeping its last documents: ${s}`);let c=j({entityKey:t,pluginId:n,message:s});a.push(c),o.set(e,[T(c,{scope:`entity`,entityId:e})])},P=async()=>(await ne(n,o,k,r),{synced:O,problems:a});l===void 0&&await U({context:t,database:n,state:d,store:f,stored:u,searchableLoaders:s});let F=[];for(let[e,n]of c){let i=d.entitiesByKey.get(e);if(i&&i.kind===`inline`){if(n===void 0){u.has(e)&&await f.removeSource(e);continue}try{let a=await E.prepare(e,n.docs,v);F.push({entityKey:e,docs:a.docs,...Y(e,n,a.docs),sourceHash:w(i.dataHash??``,!1),pluginVersion:t.pluginRegistry.getById(i.pluginId)?.version??``}),A(i.id,[...H(e,n.problems,r),...a.problems])}catch(t){N(i.id,e,i.pluginId,t)}}}if(await f.replaceSourceDocuments(F),O+=F.length,s.size===0)return P();let I=await ie(n,[...s.keys()],e.entityKeys),L=await ae(n,m,I.map(e=>e.id)),R=I.filter(e=>{let n=s.get(e.loaderId),r=n?t.pluginRegistry.getById(n.pluginId)?.version:void 0,i=u.get(e.key);return i===void 0||i.sourceHash!==w(e.dataHash??``,n?.definition.usesProjectMarkdocSchema===!0)||i.pluginVersion!==r||L.has(e.id)});if(R.length===0)return P();let z=await M(n,R.map(e=>e.key)),B=0,G=0,Z=0,Q=0,$=0;for(let r of p(R,50)){B+=1;let i=Date.now(),a=await K(n,r);Z+=Date.now()-i,i=Date.now();let o=[];for(let i of r){let r=s.get(i.loaderId);if(r){try{let e=await W({row:i,entry:r,value:a.get(i.id),attachedSlug:z.get(i.key),context:t,database:n,state:d,evaluator:m,resolveAccess:_,prepare:E.prepare,stampOf:w,allowsMarkdownCopy:S.allows});o.push(e),A(i.id,e.problems)}catch(e){N(i.id,i.key,r.pluginId,e)}G+=1,e.onProgress?.(G,R.length)}}Q+=Date.now()-i,i=Date.now(),await V({context:t,database:n,store:f,outputs:o}),$+=Date.now()-i,O+=o.length}return l===void 0&&r.info(`Synced ${R.length} content ${R.length===1?`item`:`items`} for search in ${B} ${B===1?`chunk`:`chunks`} (load ${i(Z)}, producers ${i(Q)}, writes ${i($)})`),P()}async function ne(e,t,n,r){if(t.size!==0)try{await e.db.transaction(e=>E(e,t,n))}catch(e){r.warn(`could not store the search problems of this pass`,{error:e instanceof Error?e.message:String(e)})}}async function V(e){let{context:t,outputs:n}=e;n.length!==0&&await e.database.db.transaction(async i=>{await e.store.replaceSourceDocuments(n.map(e=>({entityKey:e.row.key,docs:e.docs,fragments:e.fragments,uses:e.uses,sourceHash:e.sourceHash,pluginVersion:t.pluginRegistry.getById(e.entry.pluginId)?.version??``})),i),await O(i,{hook:`searchable`,scopes:n.map(e=>({originPluginId:e.entry.pluginId,entityId:e.row.id,dependencies:_(e.reads)}))});for(let e of n){if(await i.delete(c).where(R(c.entityKey,e.row.key)),e.markdownDocs.length===0)continue;let n=t.pluginRegistry.getById(e.entry.pluginId)?.version??``;for(let t of e.markdownDocs){let a=await Promise.all(t.chunks.map(async(i,a)=>{let o=t.headings?.[a]??null;return{entityKey:e.row.key,chunkIndex:a,routeSlug:t.routeSlug,text:i,heading:o?.heading??null,anchor:o?.anchor??null,title:t.title??null,description:t.description??null,rbacTeams:t.rbacTeams,hash:await r(new TextEncoder().encode(i)),sourceHash:e.sourceHash,pluginVersion:n}}));await i.insert(c).values(a)}}})}function H(e,t,n){let r=[],i=/* @__PURE__ */ new Set;for(let e of t??[])k.includes(e.code)?r.push(w(e)):i.add(e.code);for(let t of i)n.warn(`searchable for "${e}" reported problem code "${t}", which the search sync does not own; use one of ${k.join(`, `)}`);return r}async function U(e){for(let t of e.stored.keys()){let n=e.state.entitiesByKey.get(t);n&&(e.context.pluginRegistry.getById(n.pluginId)===void 0||n.kind!==`inline`&&(n.loaderId===null||!e.searchableLoaders.has(n.loaderId)))&&(await e.store.removeSource(t),await e.database.db.delete(c).where(R(c.entityKey,t)))}}async function W(e){let{row:t,entry:n,database:r}=e,i=n.definition.searchable,a=n.definition.markdown,o=e.value;if(!o||o.data===null||o.dataHash===null)throw Error(`Entity "${t.key}" has no stored value.`);let s=e.stampOf(o.dataHash,n.definition.usesProjectMarkdocSchema),c=await f(o.data,e=>h(r,e)),l=[],u=e=>l.push(e),d=e.evaluator.index(u),p=e.attachedSlug===void 0?void 0:d.get(e.attachedSlug),m=e.resolveAccess(u),g={config:e.context.config,entities:I(e.context,r,e.state,u),logger:e.context.logger.child(`content-layer:searchable:${n.definition.id}`),routes:d,route:p},_=i?await i(c,g):{docs:[]},v=a&&e.allowsMarkdownCopy(p)?await a(c,g):null,y=G(t.key,v,e.attachedSlug).map(e=>Object.assign(e,{rbacTeams:m.rbacTeamsForSlug(e.routeSlug)})),b=await e.prepare(t.key,_.docs??[],m);return{row:t,entry:n,docs:b.docs,...Y(t.key,_,b.docs),markdownDocs:y,sourceHash:s,reads:l,problems:[...H(t.key,_.problems,e.context.logger),...b.problems]}}function G(e,t,n){if(t===null)return[];if(!Array.isArray(t))throw Error(`markdown for "${e}" must return an array or null.`);let r=t.length>0&&typeof t[0]==`string`?[{chunks:t}]:t,i=/* @__PURE__ */ new Set,a=[];for(let t of r){let r=t.routeSlug??n;if(r!==void 0){if(!Array.isArray(t.chunks)||t.chunks.some(e=>typeof e!=`string`))throw Error(`markdown for "${e}" returned a document without string chunks.`);if(t.chunks.length!==0){if(i.has(r))throw Error(`markdown for "${e}" returned "${r}" twice.`);i.add(r),a.push({routeSlug:r,chunks:t.chunks,headings:t.headings,...typeof t.title==`string`&&t.title!==``?{title:t.title}:{},...typeof t.description==`string`&&t.description!==``?{description:t.description}:{}})}}}return a}async function K(e,t){let n=await e.db.select({id:s.id,data:s.data,dataHash:s.dataHash}).from(s).where(z(s.id,t.map(e=>e.id)));return new Map(n.map(e=>[e.id,e]))}function q(e,t,n){let r=[...e.routeBySlug.values()].filter(e=>e.wildcardPrefix),i=t=>{if(e.routeBySlug.has(t))return t;let n=new Set(d(t)),i;for(let e of r)n.has(e.slug)&&(i===void 0||e.slug.length>i.length)&&(i=e.slug);return i};return r=>{let a=t.index(r),o=e=>a.getAccess(i(e)??e),s=t=>e.routeBySlug.get(i(t)??t);return{accessForSlug:o,rbacTeamsForSlug:e=>N(o(e)),localeForSlug:e=>s(e)?.locale??``,originFilePathForSlug:e=>s(e)?.originFilePath??null,versionForSlug:e=>{let t=s(e);return t?.versionGroup!=null&&t.version!=null?{group:t.versionGroup,version:t.version}:null},productForSlug:e=>{let t=s(e),r=t?t.canonicalSlug||t.slug:e;return S(n,r)}}}}function J(e){return new Set(n(e.config).map(e=>e.field).filter(e=>e!==t))}function Y(e,t,n){let r=t.fragments??[],i=t.uses??[];if(!Array.isArray(r)||!Array.isArray(i))throw Error(`searchable for "${e}" must return fragments and uses as arrays.`);for(let t of r)if(typeof t.fragmentKey!=`string`||typeof t.name!=`string`)throw Error(`searchable for "${e}" returned a fragment without a key or name.`);let a=new Set(n.map(e=>e.docKey));return{fragments:r,uses:i.filter(e=>a.has(e.docKey))}}function X(e,t){return{async prepare(n,r,i){if(!Array.isArray(r))throw Error(`searchable for "${n}" must return { docs: SearchDocument[] }.`);let a=/* @__PURE__ */ new Set,s=/* @__PURE__ */ new Set,c=[],l=[];for(let u of r){if(Q(n,u),a.has(u.docKey))throw Error(`searchable for "${n}" returned docKey "${u.docKey}" twice.`);a.add(u.docKey);let r=o(u.routeSlug),d=i.accessForSlug(r);if(d===void 0){e.warn(`search document "${u.docKey}" of "${n}" dropped: no route "${r}"`);continue}let{facets:f,rbacScope:p,keywords:m,...h}=u,g=i.productForSlug(r),_=i.versionForSlug(r),v=F({facets:f,configuredFields:t.configuredFields,groupKey:u.groupKey,teams:P(d,p),version:_,product:g?.name??null,keywords:x(m),onDropped:(e,t)=>{let a=`${e}\u0000${t}`;s.has(a)||(s.add(a),c.push(A({entityKey:n,field:e,reason:Z[t],filePath:i.originFilePathForSlug(r)})))}}),y={...h,routeSlug:r,locale:i.localeForSlug(r),facets:v};g&&(y.product={name:g.name,folder:g.folder}),_&&(y.version=_),l.push(y)}return{docs:l,problems:c}}}}const Z={"not-an-object":`facets must be an object of field to string or string list`,reserved:`fields starting with "redocly_" are derived by the engine`,invalid:`a value must be a string, number, boolean, or a list of those`,"too-long":`a value must be at most 500 characters`,"too-many-words":`a keyword must have at most 10 words`};function Q(e,t){let n=t;if(!(typeof n==`object`&&n&&typeof n.docKey==`string`&&n.docKey!==``&&typeof n.routeSlug==`string`&&typeof n.title==`string`&&typeof n.text==`string`))throw Error(`searchable for "${e}" returned an invalid document (docKey, routeSlug, title, text are required strings).`);if(n.rbacScope!==void 0&&!a(n.rbacScope))throw Error(`searchable for "${e}" returned document "${n.docKey}" with an invalid rbacScope.`)}async function re(e,t){let n=/* @__PURE__ */ new Map;for(let r of t===void 0?[void 0]:p(t,m(void 0))){let t=await e.db.selectDistinct({entityKey:u.entityKey,sourceHash:u.sourceHash,pluginVersion:u.pluginVersion}).from(u).where(r===void 0?void 0:z(u.entityKey,[...r]));for(let{entityKey:e,...r}of t)n.set(e,r);let i=await e.db.selectDistinct({entityKey:c.entityKey,sourceHash:c.sourceHash,pluginVersion:c.pluginVersion}).from(c).where(r===void 0?void 0:z(c.entityKey,[...r]));for(let{entityKey:e,...t}of i)n.has(e)||n.set(e,t)}return n}async function ie(e,t,n){return n!==void 0&&n.length===0?[]:(await e.db.select({id:s.id,key:s.key,loaderId:s.loaderId,dataHash:s.dataHash}).from(s).where(L(R(s.status,`ready`),R(s.isCurrent,1),z(s.loaderId,[...t]),n===void 0?void 0:z(s.key,[...n]))).orderBy(s.key)).filter(e=>e.loaderId!==null)}async function ae(e,t,n){let r=/* @__PURE__ */ new Set;if(n.length===0)return r;let i=new Set(n),a=n.length<=m(void 0),o=await e.db.select({entityId:l.entityId,kind:l.kind,argument:l.argument,resultHash:l.resultHash}).from(l).where(L(R(l.hook,`searchable`),a?z(l.entityId,[...n]):void 0));for(let e of o)e.entityId!==null&&i.has(e.entityId)&&!r.has(e.entityId)&&v(t,e)&&r.add(e.entityId);return r}function $(e,t){for(let n of e)n.kind===`inline`&&t.set(n.key,n.searchable)}export{$ as collectInlineSearchables,B as runSearchSync};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{L10N_DIR as e}from"../../shared/constants/l10n/defaults.js";import{resolveContentPluginsForFile as t}from"../plugins/registry.js";import{hashContentConfigDependency as n}from"../config-deps.js";import{extractFileContributions as r}from"../plugins/execute.js";import{createSourceFile as i}from"../plugins/source-file.js";import{createContentOriginKey as a}from"../plugins/utils/origin-key.js";import{L10N_PLUGIN_ID as o}from"../plugins/internal/l10n/translations-loader.js";import"../plugins/internal/l10n/index.js";import"../plugins/index.js";import{createProblem as s}from"../problems/codes.js";import{garbageCollectOrphanedEntities as c,propagateRouteQueryInvalidation as l}from"../database/invalidation.js";import{problemRow as u}from"../database/problems.js";import{loadFileManifestsByPaths as d}from"../database/files.js";import{loadContentLayerState as f,reloadContentLayerEntities as p}from"../context-state.js";import{bulkSyncOrigins as m}from"../database/origins.js";import{extractFailedProblem as h,sluggerProblemSources as ee}from"../problems/producers.js";import{
|
|
1
|
+
import{L10N_DIR as e}from"../../shared/constants/l10n/defaults.js";import{resolveContentPluginsForFile as t}from"../plugins/registry.js";import{hashContentConfigDependency as n}from"../config-deps.js";import{extractFileContributions as r}from"../plugins/execute.js";import{createSourceFile as i}from"../plugins/source-file.js";import{createContentOriginKey as a}from"../plugins/utils/origin-key.js";import{L10N_PLUGIN_ID as o}from"../plugins/internal/l10n/translations-loader.js";import"../plugins/internal/l10n/index.js";import"../plugins/index.js";import{createProblem as s}from"../problems/codes.js";import{garbageCollectOrphanedEntities as c,propagateRouteQueryInvalidation as l}from"../database/invalidation.js";import{problemRow as u}from"../database/problems.js";import{loadFileManifestsByPaths as d}from"../database/files.js";import{loadContentLayerState as f,reloadContentLayerEntities as p}from"../context-state.js";import{bulkSyncOrigins as m}from"../database/origins.js";import{extractFailedProblem as h,sluggerProblemSources as ee}from"../problems/producers.js";import{resolveRevisionsConfig as g}from"../revisions/config.js";import{finalizeHookInputs as _,hasAnyPluginHookTrigger as v}from"./hook-inputs.js";import{collectInlineSearchables as y}from"./search-sync.js";import{dropCollidingRoutes as b}from"./slugger/drop-colliding-routes.js";import{allReservedSlugs as te,resolveFinalSlugs as x}from"./slugger/resolve-final-slugs.js";import{normalizePluginArtifacts as S}from"./normalize-artifacts.js";import{runFinalizePhase as C}from"./finalize-phase.js";import{applyOriginRoutesToWorkingState as w,cloneContentLayerState as T,removeFileFromWorkingState as ne,removeOriginFromWorkingState as E}from"./working-state.js";import{dropCollidingExtractAllRoutes as D,runExtractAllPhase as O}from"./extract-all-phase.js";import{diffFallbackRoutes as k,generateFallbackRoutes as A}from"./generate-fallback-routes.js";async function j(n){let s=await f({context:n.context,database:n.database}),l=T(s);for(let e of n.removedPaths)ne(l,e);if(n.files.length===0&&n.removedPaths.size===0&&![`extractAll`,`finalize`].some(e=>v(e,n.context,s,n.pluginScopedOriginRows,n.routeQueryRows,n.hookState,e===`finalize`?_(n.localeContext):void 0)))return await P(n,l),n.context.state=l,{inlineSearchables:/* @__PURE__ */ new Map,routeChanges:{changedSlugs:[],unbounded:!1}};let h=n.context.logger.child(`content-layer:sync`),{localeContext:S}=n,j=I(n.context.config,`/l10n`),M=I(n.context.config,`/metadataGlobs`),N=await O({context:n.context,database:n.database,workingState:l,files:n.files,originRows:n.pluginScopedOriginRows,routeQueryRows:n.routeQueryRows,hookState:n.hookState,logger:n.context.logger.child(`content-layer:extractAll`)}),F=n.context.logger.child(`content-layer:plugin`),R=g(n.context.config),z=n.files.filter(e=>e.manifest===void 0).map(e=>e.path),B=await d(n.database,z),V=n.context.pluginRegistry.list().map(e=>e.id);E(l,V,o,null);let H=[],U=`${e}/`,W=n.files.map(e=>({file:e,localized:Number(e.path.startsWith(U))})).sort((e,t)=>e.localized-t.localized).map(e=>e.file);for(let[e,a]of W.entries()){let o=l.filesByPath.get(a.path)??l.ignoredFilesByPath.get(a.path);if(!o)throw Error(`Missing stored file state for "${a.path}".`);let s=t(n.context,a.path),c=(l.filePluginsByPath.get(a.path)??[]).map(e=>e.pluginId).filter(e=>!s.some(t=>t.id===e)),u=[];for(let e of c)E(l,V,e,a.path),u.push({hook:`extract`,originDependencies:[],originFileId:o.id,originFilePath:a.path,originPluginId:e,routeDependencies:[],routes:[],entities:[],problems:[]});for(let e of s)E(l,V,e.id,a.path);let d=i({path:a.path,hash:a.hash,manifest:a.manifest??B.get(a.path)??{}}),f=await r(s,d,{config:n.context.config,fs:n.context.platform.fs,contentDir:n.context.contentDir,scannedPaths:()=>l.filesByPath.keys(),logger:F});for(let e of f)L({context:n.context,workingState:l,allPluginIds:V,filePath:a.path,fileRecord:o,attempt:e,origins:u,revisions:R,localeContext:S,l10nConfigDependency:j,metadataGlobsConfigDependency:M,pluginLogger:F});let p=s.map(e=>({id:e.id,version:e.version}));H.push({fileId:o.id,filePath:a.path,plugins:p,origins:u}),l.filePluginsByPath.set(a.path,p.map(e=>({fileId:o.id,pluginId:e.id,pluginVersion:e.version}))),n.onFileSynced?.(e+1,W.length)}let G=n.context.pluginRegistry.listReservedSlugs(),{collisions:K,routeBySlug:q,wildcardShadows:J,problems:Y}=x({state:l,previousWildcardShadows:s.wildcardShadows,reservedSlugs:G,logger:h});l.wildcardShadows=J,l.routeBySlug=q;let ie=/* @__PURE__ */ new Set([...n.files.map(e=>e.path),...n.removedPaths,...N.pending.map(e=>e.pluginId),...N.failures.map(e=>e.pluginId)]),X=new Set(Y.map(e=>e.key));for(let e of n.storedSluggerProblems){if(e.key===null)continue;let t=ee(e.data);t.length>0&&t.every(e=>ie.has(e))&&X.add(e.key)}b({state:l,bulkItems:H,collisions:K,allPluginIds:V}),D(N.pending,K);let Z=A({state:l,localeContext:S,reservedSlugs:te(G)}),ae=k(s.routesByOriginKey.get(a(`internal.l10n`,null))??[],Z);w(l,V,o,null,Z);let Q=/* @__PURE__ */ new Map;for(let e of H)for(let t of e.origins)y(t.entities,Q);for(let e of N.pending)y(e.entities,Q);let $=/* @__PURE__ */ new Set;if(R){for(let e of H)if(R.isTracked(e.filePath))for(let t of e.origins)for(let e of t.entities)$.add(e.key)}await m(n.database,H,{logger:F,revisions:R?{max:R.max,trackedKeys:$,capture:n.captureRevisions===!0}:void 0,extractAllOrigins:N.pending.map(e=>({hook:`extractAll`,originFileId:null,originFilePath:null,originPluginId:e.pluginId,originDependencies:e.originDependencies,routeDependencies:e.routeDependencies,routes:e.routes,entities:e.entities,problems:[],fingerprint:e.inputsHash,routeQueries:e.routeQueries})),extractAllFailures:N.failures,globalProblems:{source:`slugger`,keys:[...X],newProblems:Y.map(e=>u(e.problem,{scope:`global`,source:`slugger`,key:e.key}))},fallbackRoutes:{pluginId:o,...ae}}),await p({state:l,database:n.database}),await P(n,l);let oe=await C({context:n.context,database:n.database,localeContext:S,workingState:l,files:n.files,pluginScopedOriginRows:n.pluginScopedOriginRows,routeQueryRows:n.routeQueryRows,hookState:n.hookState,logger:n.context.logger.child(`content-layer:finalize`),collectEntities:e=>y(e,Q)}),se=await c(n.database);return(oe.ranPluginIds.length>0||se.removedOrphans)&&await p({state:l,database:n.database}),n.context.state=l,{inlineSearchables:Q,routeChanges:re(s.routeBySlug,l.routeBySlug)}}function re(e,t){let n=[];for(let[r,i]of e){let e=t.get(r);(e===void 0||e.originFilePath!==i.originFilePath)&&n.push(r)}for(let r of t.keys())e.has(r)||n.push(r);return{changedSlugs:n,unbounded:!M(e,t)}}function M(e,t){let n=N(e),r=N(t);return n.size===r.size&&[...n].every(e=>r.has(e))}function N(e){let t=/* @__PURE__ */ new Set;for(let[n,r]of e)r.wildcardPrefix&&t.add(n);return t}async function P(e,t){let{invalidatedKeys:n}=await l(e.database,{rows:e.routeQueryRows,state:t,config:e.context.config,logger:e.context.logger.child(`content-layer:db`)});for(let e of n){let n=t.entitiesByKey.get(e);n&&(n.status=`stale`)}}function F(e){return[...e.configDependencies.map(e=>({...e,source:`config`})),...e.fileDependencies]}function I(e,t){return{source:`config`,accessType:`value`,path:t,valueHash:n(e,{accessType:`value`,path:t})}}function L(e){let{context:t,workingState:n,allPluginIds:r,filePath:i,fileRecord:o,attempt:c}=e,l=c.result.ok?c.result.value:null,u=e.localeContext.isL10nPath(i)?[...F(c),e.l10nConfigDependency]:F(c);if(!l){e.origins.push({hook:`extract`,originDependencies:u,originFileId:o.id,originFilePath:i,originPluginId:c.plugin.id,routeDependencies:[],routes:[],entities:[],problems:c.result.ok?[]:[h({filePath:i,pluginId:c.plugin.id,message:c.result.error.message})]});return}let d=S({context:t,filePath:i,pluginId:c.plugin.id,revisions:e.revisions,routeDrafts:l.routes,standaloneEntities:l.entities??[],localeContext:e.localeContext,resolveCanonicalRoute:(e,t)=>n.routesByOriginKey.get(a(c.plugin.id,e))?.find(e=>e.routeId===t)});w(n,r,c.plugin.id,i,d.routes),e.origins.push({hook:`extract`,originDependencies:d.routes.length>0?[...u,e.metadataGlobsConfigDependency]:u,originFileId:o.id,originFilePath:i,originPluginId:c.plugin.id,routeDependencies:d.routeDependencies,routes:d.routes,entities:d.entities,problems:(l.problems??[]).map(e=>s({...e,location:e.location??{filePath:i}})),linkRefs:l.linkRefs})}export{j as syncContentFiles};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{collectL10nDirLocales as e,resolveLocaleContext as t}from"../../shared/utils/l10n.js";import{
|
|
1
|
+
import{collectL10nDirLocales as e,resolveLocaleContext as t}from"../../shared/utils/l10n.js";import{files as n,routes as r,staticFiles as i,targetInventories as a}from"../database/schema.js";import{toPublicVersionedSlug as o}from"../../shared/constants/versions.js";import{getVersionCatalog as s}from"../versions/resolve.js";import{buildLinkCheckView as c}from"./view.js";import{asc as l,eq as u}from"drizzle-orm";async function d(o){let{database:s}=o,[d,m,h,g]=await Promise.all([s.db.select({slug:r.slug,wildcardPrefix:r.wildcardPrefix,sourcePath:n.path,version:r.version,versionGroup:r.versionGroup}).from(r).leftJoin(n,u(r.sourceId,n.id)).orderBy(l(r.id)),s.db.select({filePath:n.path,kind:a.kind,exhaustive:a.exhaustive,targets:a.targets}).from(a).innerJoin(n,u(a.fileId,n.id)),s.db.select({path:n.path}).from(n),s.db.select({path:i.path}).from(i)]),_=h.map(e=>e.path),v=t(o.config.l10n,e(_));return c({routes:await p(s,d),filePaths:_,inventories:m,redirects:f(o.config),servedStaticPaths:g.map(e=>`/${e.path}`),localeContext:v,checkAnchors:o.config.linkChecker?.anchors?.hide!==!0})}function f(e){return Object.fromEntries(Object.entries(e.redirects??{}).map(([e,t])=>[e,t.to]))}async function p(e,t){let n=await s(e.db),r=new Set(t.map(e=>e.slug)),i=[];for(let e of t){if(!e.versionGroup||!e.version||(await n.groupInfo(e.versionGroup)).defaultVersion!==e.version)continue;let t=o(e.slug,e.versionGroup,e.version,!0);t!==e.slug&&!r.has(t)&&i.push({...e,slug:t})}return[...t,...i]}export{d as loadLinkCheckView};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{delocalizeL10nPath as e}from"../../shared/utils/l10n.js";import
|
|
1
|
+
import{delocalizeL10nPath as e}from"../../shared/utils/l10n.js";import{filePathToRouteSlug as t}from"../../shared/utils/routes/file-path-to-route-slug.js";import{computePathPrefixes as n}from"../../shared/utils/routes/compute-path-prefixes.js";import{isIndexPagePath as r,resolveRelativeSlug as i}from"../../shared/utils/routes/resolve-relative-slug.js";import{splitHash as a}from"../markdown/resolve/references.js";import"../plugins/internal/api-docs/server/shared.js";import{inventoryKey as o}from"./view.js";import{posix as s}from"node:path";function c(e,t){let n=[];for(let r of e){let e=r.targetKind===`slug`?u(r,t):f(r,t);e!==null&&n.push({ref:r,problem:e})}return n}function l(t,n){let r=[t.target,t.filePath],i=[],a=e=>{t.raw.startsWith(`/`)?i.push(`/${e}`):s.extname(e)===``&&i.push(m(t,e,n))};a(t.target);let o=e(t.target);return o!==void 0&&(r.push(o),a(o)),{filePaths:r,slugs:i}}function u(e,t){let n=d(e,e.target,t);return n===void 0?S(e,e.target):n}function d(e,t,n){let r=n.routeBySlug.get(t);if(r!==void 0)return g(e,r.sourcePath,n,t);if(n.redirects.has(t)||v(t,n)||n.servedStaticPaths.has(t))return null;let i=y(t,n);if(i===null)return;let a=b(n,i.sourcePath,`subpath`);return x(a,i.remainder)&&x(a,i.remainder.toLowerCase())?S(e,t):null}function f(t,n){let r=p(t,t.target,n);if(r!==void 0)return r;let i=e(t.target);if(i!==void 0){let{locale:e}=n.localeContext.splitLocaleFromPath(t.target),r=p(t,i,n,e);if(r!==void 0)return r}return S(t,h(t.target,n))}function p(e,t,n,r){let i=n.primaryRouteByFilePath.get(t);if(i!==void 0)return g(e,t,n,r===void 0?i:n.localeContext.toL10nSlug(i,r));if(n.filePaths.has(t))return null;if(e.raw.startsWith(`/`))return d(e,`/${t}`,n);if(s.extname(t)===``)return e.originPluginId===`internal.api-docs`?null:d(e,m(e,t,n),n)}function m(e,n,o){let s=o.primaryRouteByFilePath.get(e.filePath);if(s===void 0)return t(n);let c=a(e.raw).path.split(`?`,1)[0]??``;return i(c,s,r(e.filePath))}function h(n,r){let i=e(n);if(i===void 0)return t(n);let{locale:a}=r.localeContext.splitLocaleFromPath(n);return r.localeContext.toL10nSlug(t(i),a)}function g(e,t,n,r){if(!n.checkAnchors||e.kind===`image`||e.fragment===null||e.fragment===``||t===null)return null;let i=_(e.fragment);if(i.toLowerCase()===`top`)return null;let a=b(n,t,`anchor`);return x(a,e.fragment)&&x(a,i)?C(e,r):null}function _(e){try{return decodeURIComponent(e)}catch{return e}}function v(e,t){return t.redirectWildcards.some(t=>t===`/`||e===t||e.startsWith(`${t}/`))}function y(e,t){let r=new Set(n(e));for(let n of t.wildcardSlugs){if(!r.has(n))continue;let i=t.routeBySlug.get(n),a=n===`/`?e:e.slice(n.length);return{sourcePath:i?.sourcePath??null,remainder:a.replace(/^\/+/,``)}}return null}function b(e,t,n){return t===null?void 0:e.inventories.get(o(t,n))}function x(e,t){return e!==void 0&&e.exhaustive&&!e.targets.has(t)}function S(e,t){return w(e,`link/missing-target`,e.targetKind===`slug`?`Route "${e.target}" does not exist.`:`"${E(e)}" does not exist.`,T(t,e.fragment))}function C(e,t){return w(e,`link/missing-anchor`,`"#${e.fragment}" does not exist on "${E(e)}".`,T(t,e.fragment))}function w(e,t,n,r){return{code:t,message:n,location:{filePath:e.filePath,...e.range===null?{}:{range:e.range}},data:{raw:e.raw,target:e.target,fragment:e.fragment,kind:e.kind,title:e.title,url:r,...e.data??{}}}}function T(e,t){return t===null||t===``?e:`${e}#${t}`}function E(e){let t=a(e.raw).path;return t===``?e.target:t}export{l as unresolvedFilePathRefReads,c as validateLinkRefs};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{collectL10nDirLocales as e,resolveLocaleContext as t}from"../../shared/utils/l10n.js";import{matchGlob as n}from"../plugins/utils/glob.js";import{createTrackedRedoclyConfig as r}from"../config-deps.js";import{buildDataRefMarker as i,hashBlobContent as a}from"../materialization/data-ref.js";import{resolveDataRef as o,upsertBlob as s}from"../database/blobs.js";import{createEntityStore as c}from"../database/entity-store.js";import{createRouteQueryEvaluator as l}from"../plugins/utils/route-index.js";import{createSearchHandle as u}from"../search/store.js";import{
|
|
1
|
+
import{collectL10nDirLocales as e,resolveLocaleContext as t}from"../../shared/utils/l10n.js";import{matchGlob as n}from"../plugins/utils/glob.js";import{createTrackedRedoclyConfig as r}from"../config-deps.js";import{buildDataRefMarker as i,hashBlobContent as a}from"../materialization/data-ref.js";import{resolveDataRef as o,upsertBlob as s}from"../database/blobs.js";import{createEntityStore as c}from"../database/entity-store.js";import{createRouteQueryEvaluator as l}from"../plugins/utils/route-index.js";import{createSearchHandle as u}from"../search/store.js";import{createAudienceTagResolver as d}from"../markdown/resolve/audience-tag.js";import{materializeEntityByKey as f}from"../materialization/entity.js";import{createMarkdownService as p}from"../markdown/service.js";import{resolve as m}from"node:path";function h(h,g,_={}){let v,y,b,x,S;return function C(w,T,E){let D=h.pluginRegistry.getById(w.pluginId);if(!D)throw Error(`Entity loader "${w.definition.id}" references missing plugin "${w.pluginId}".`);let{state:O}=h;if(!O)throw Error(`Entity loader "${w.definition.id}" ran before content state was loaded.`);let k=r(h.config),A=k.config.access?.rbac,j=h.config.access?.rbac;(j!==v||y===void 0)&&(v=j,y=d(A,e=>h.logger.warn(e)));let M=y,N=k.config.l10n?.defaultLocale;(S===void 0||S.defaultLocale!==N)&&(x??=e(O.filesByPath.keys()),S={defaultLocale:N,locales:t({defaultLocale:N},x).locales});let P=S.locales,F=[],I=[],L=[];return(b?.state!==O||b.config!==h.config)&&(b={state:O,config:h.config,evaluator:l(O,h.config)}),{args:T??{},config:k.config,contentDir:h.contentDir,file:{absolutePath:m(h.contentDir,E),path:E,lastModifiedAt:O.filesByPath.get(E)?.lastModifiedAt??null},io:{...h.pluginIO,async glob(e){return L.push(e),n(O.filesByPath.keys(),e)}},entities:c({database:g,state:O,materialize:e=>f({database:g,key:e,loaderRegistry:h.pluginRegistry,loaderContextFactory:C,contentDir:h.contentDir,revisions:_.revisions,logger:h.logger}),onEntityRead:e=>F.push(e),record:e=>I.push(e)}),search:u(g),logger:h.logger.child(`content-layer:entity:${w.definition.id}`),plugin:{id:D.id,version:D.version},pluginRegistry:h.pluginRegistry,resolveAudienceTag:M,routes:b.evaluator.index(e=>I.push(e)),markdown:p({state:O,resolveAudienceTag:M,contentLocales:P}),createBlobRef:async(e,t)=>{let n=t?.format??`json`,r=typeof e==`string`?e:Buffer.from(e).toString(`base64`),o=a(r);return await s(g,{key:o,content:r,size:r.length}),i(o,n)},resolveDataRef:e=>o(g,e),_trackedConfig:k,_loadedEntityKeys:F,_globPatterns:L,_routeQueries:I}}}export{h as createBuildTimeEntityLoaderContextFactory};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{headingSlugger as e}from"../utils/heading-slugger.js";import{renderMarkdocAst as t}from"./markdoc-components.js";import{buildMarkdownTextTagSet as n}from"../constants/markdown-text-tag-set.js";import r from"@redocly/markdoc";import{userMarkdocFunctions as i,userMarkdocNodes as a,userMarkdocTags as o}from"virtual:realm-markdoc-schema";let s;function c(c){return c?(s??=n({tags:o,nodes:a,functions:i}),e.reset(),t(r.transform(r.parse(c),s))):null}export{c as renderMarkdownText};
|