@redocly/framework 1.0.0-next.12 → 1.0.0-next.13

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.
Files changed (235) hide show
  1. package/dist/bundler/build/dependency-pack.js +1 -1
  2. package/dist/bundler/build/output-metadata.js +1 -1
  3. package/dist/bundler/build/run.js +1 -1
  4. package/dist/bundler/build/theme-global-stylesheets.js +1 -1
  5. package/dist/bundler/build/vite-config.js +2 -2
  6. package/dist/bundler/dev/dev-content-build.js +1 -1
  7. package/dist/bundler/dev/routes/dev-problems-route.js +1 -1
  8. package/dist/bundler/dev/routes/source-sync-route.js +1 -1
  9. package/dist/bundler/dev/run.js +1 -1
  10. package/dist/bundler/dev/runtime-app.js +1 -1
  11. package/dist/bundler/dev/vite-chunk-url.js +1 -1
  12. package/dist/bundler/user-markdoc-schema.js +1 -1
  13. package/dist/bundler/vite-config.base.js +5 -5
  14. package/dist/cli/api-docs-build-event.js +1 -1
  15. package/dist/cli/args.js +1 -1
  16. package/dist/cli/commands/build.js +1 -1
  17. package/dist/cli/commands/dev.js +1 -1
  18. package/dist/cli/commands/ingest.js +1 -1
  19. package/dist/cli/commands/translate.js +1 -1
  20. package/dist/cli/problems-output.js +3 -3
  21. package/dist/cli/validate-react-pages.js +1 -1
  22. package/dist/client/UnversionedVersionButton.js +1 -1
  23. package/dist/client/VersionPicker.js +343 -0
  24. package/dist/client/ai-search/use-ai-search.js +1 -1
  25. package/dist/client/analytics-page-view.js +1 -1
  26. package/dist/client/app.js +2 -2
  27. package/dist/client/classic-webview-sync.js +1 -1
  28. package/dist/client/client-entry.js +1 -1
  29. package/dist/client/contexts.js +1 -1
  30. package/dist/client/feedback.js +1 -1
  31. package/dist/client/history-mount.js +6 -5
  32. package/dist/client/l10n/ssr-l10n.js +1 -1
  33. package/dist/client/l10n/use-l10n-config.js +1 -1
  34. package/dist/client/products.js +1 -1
  35. package/dist/client/review/ReviewBar.js +31 -31
  36. package/dist/client/review/login-url.js +1 -1
  37. package/dist/client/review/use-review.js +1 -1
  38. package/dist/client/revisions-history.js +1 -1
  39. package/dist/client/sidebar/SidebarDataProvider.js +1 -1
  40. package/dist/client/sidebar/drilldown.js +1 -1
  41. package/dist/client/ssr.js +1 -1
  42. package/dist/client/telemetry/config.js +1 -1
  43. package/dist/client/theme-logo.js +1 -1
  44. package/dist/client/use-entity-revisions.js +1 -1
  45. package/dist/client/use-page-versions.js +1 -1
  46. package/dist/client/use-search.js +1 -1
  47. package/dist/client/webmcp/tools/shared.js +1 -1
  48. package/dist/client/webmcp/tools/site-tools.js +1 -1
  49. package/dist/client/webmcp/use-webmcp-tools.js +1 -1
  50. package/dist/content-layer/config-schema.js +1 -1
  51. package/dist/content-layer/config.d.ts +8 -0
  52. package/dist/content-layer/config.js +1 -1
  53. package/dist/content-layer/context-state.js +1 -1
  54. package/dist/content-layer/context.d.ts +6 -0
  55. package/dist/content-layer/context.js +1 -1
  56. package/dist/content-layer/database/assets.js +1 -1
  57. package/dist/content-layer/database/blobs.js +1 -1
  58. package/dist/content-layer/database/entities.d.ts +2 -0
  59. package/dist/content-layer/database/entities.js +1 -1
  60. package/dist/content-layer/database/entity-store.js +1 -1
  61. package/dist/content-layer/database/files.js +1 -1
  62. package/dist/content-layer/database/finalize.js +1 -1
  63. package/dist/content-layer/database/invalidation.js +26 -26
  64. package/dist/content-layer/database/link-refs.js +1 -1
  65. package/dist/content-layer/database/origins.d.ts +2 -1
  66. package/dist/content-layer/database/origins.js +1 -1
  67. package/dist/content-layer/database/problems.js +1 -1
  68. package/dist/content-layer/database/reset.js +1 -1
  69. package/dist/content-layer/database/route-query-deps.d.ts +19 -3
  70. package/dist/content-layer/database/route-query-deps.js +1 -1
  71. package/dist/content-layer/database/search-vocab.js +2 -2
  72. package/dist/content-layer/database/static-files.js +1 -1
  73. package/dist/content-layer/ingest/extract-all-phase.js +1 -1
  74. package/dist/content-layer/ingest/finalize-phase.js +1 -1
  75. package/dist/content-layer/ingest/git-last-modified.d.ts +20 -0
  76. package/dist/content-layer/ingest/git-last-modified.js +5 -4
  77. package/dist/content-layer/ingest/hash.js +1 -1
  78. package/dist/content-layer/ingest/hook-inputs.js +1 -1
  79. package/dist/content-layer/ingest/l10n-warnings.js +1 -1
  80. package/dist/content-layer/ingest/normalize-artifacts.js +1 -1
  81. package/dist/content-layer/ingest/run.js +1 -1
  82. package/dist/content-layer/ingest/scan.js +1 -1
  83. package/dist/content-layer/ingest/search-sync.js +1 -1
  84. package/dist/content-layer/ingest/sync.js +1 -1
  85. package/dist/content-layer/link-checker/config-links.js +1 -1
  86. package/dist/content-layer/link-checker/delta.js +1 -1
  87. package/dist/content-layer/link-checker/fingerprint.js +1 -1
  88. package/dist/content-layer/link-checker/load-view.js +1 -1
  89. package/dist/content-layer/link-checker/node-ref.js +1 -1
  90. package/dist/content-layer/link-checker/run-build.js +1 -1
  91. package/dist/content-layer/link-checker/validate.js +1 -1
  92. package/dist/content-layer/loaders/context.js +1 -1
  93. package/dist/content-layer/markdown/client/JsonSchemaTag.js +1 -1
  94. package/dist/content-layer/markdown/client/markdown-text.js +1 -1
  95. package/dist/content-layer/markdown/constants/builtin-tags.js +1 -1
  96. package/dist/content-layer/markdown/nodes/fence.js +1 -1
  97. package/dist/content-layer/markdown/nodes/heading.js +1 -1
  98. package/dist/content-layer/markdown/nodes/table.js +1 -1
  99. package/dist/content-layer/markdown/resolve/markdoc-resolvers/file-reference.js +1 -1
  100. package/dist/content-layer/markdown/resolve/markdoc-resolvers/operation-samples.js +1 -1
  101. package/dist/content-layer/markdown/resolve/markdoc-resolvers/partial.js +1 -1
  102. package/dist/content-layer/markdown/resolve/markdoc-resolvers/svg-content.js +1 -1
  103. package/dist/content-layer/markdown/resolve/markdoc.js +1 -1
  104. package/dist/content-layer/markdown/resolve/references.js +1 -1
  105. package/dist/content-layer/markdown/search/to-markdown.js +2 -2
  106. package/dist/content-layer/markdown/search/to-sections.js +1 -1
  107. package/dist/content-layer/markdown/search/to-text.js +5 -5
  108. package/dist/content-layer/markdown/server/render.js +1 -1
  109. package/dist/content-layer/markdown/service.js +1 -1
  110. package/dist/content-layer/markdown/tags/variant.js +1 -1
  111. package/dist/content-layer/markdown/utils/collect-anchors.js +1 -1
  112. package/dist/content-layer/markdown/utils/first-heading.js +1 -1
  113. package/dist/content-layer/markdown/utils/parse-cache.js +1 -1
  114. package/dist/content-layer/materialization/asset-reconcile.js +1 -1
  115. package/dist/content-layer/materialization/entity.js +1 -1
  116. package/dist/content-layer/materialization/materializer.js +1 -1
  117. package/dist/content-layer/materialization/static-files.js +1 -1
  118. package/dist/content-layer/plugins/execute.js +1 -1
  119. package/dist/content-layer/plugins/index.js +1 -1
  120. package/dist/content-layer/plugins/internal/api-docs/client/template.js +2 -2
  121. package/dist/content-layer/plugins/internal/api-docs/index.js +1 -1
  122. package/dist/content-layer/plugins/internal/api-docs/server/build-definition.d.ts +2 -0
  123. package/dist/content-layer/plugins/internal/api-docs/server/build-definition.js +1 -1
  124. package/dist/content-layer/plugins/internal/api-docs/server/markdown-copy.js +12 -10
  125. package/dist/content-layer/plugins/internal/api-docs/server/options.d.ts +1 -1
  126. package/dist/content-layer/plugins/internal/api-docs/server/options.js +1 -1
  127. package/dist/content-layer/plugins/internal/api-docs/server/search-documents.js +1 -1
  128. package/dist/content-layer/plugins/internal/api-docs/server/spec-download.js +1 -1
  129. package/dist/content-layer/plugins/internal/api-functions/server/dispatch.js +1 -1
  130. package/dist/content-layer/plugins/internal/app-data/index.js +1 -1
  131. package/dist/content-layer/plugins/internal/app-data/logo.js +1 -1
  132. package/dist/content-layer/plugins/internal/app-data/products.js +1 -1
  133. package/dist/content-layer/plugins/internal/assets/index.js +1 -1
  134. package/dist/content-layer/plugins/internal/catalog-classic/client/use-catalog-classic.js +1 -1
  135. package/dist/content-layer/plugins/internal/catalog-classic/index.js +1 -1
  136. package/dist/content-layer/plugins/internal/catalog-classic/resolve-items.js +1 -1
  137. package/dist/content-layer/plugins/internal/index.js +1 -1
  138. package/dist/content-layer/plugins/internal/l10n/index.js +1 -1
  139. package/dist/content-layer/plugins/internal/l10n/translations-loader.js +1 -1
  140. package/dist/content-layer/plugins/internal/markdoc/client/template.js +1 -1
  141. package/dist/content-layer/plugins/internal/markdoc/index.js +1 -1
  142. package/dist/content-layer/plugins/internal/mcp/app-data.js +1 -1
  143. package/dist/content-layer/plugins/internal/mcp/constants.d.ts +4 -3
  144. package/dist/content-layer/plugins/internal/mcp/constants.js +1 -1
  145. package/dist/content-layer/plugins/internal/mcp/content-tools.js +1 -1
  146. package/dist/content-layer/plugins/internal/mcp/ignored-routes.js +1 -1
  147. package/dist/content-layer/plugins/internal/mcp/index.js +1 -1
  148. package/dist/content-layer/plugins/internal/mcp/server/agent-card.js +1 -1
  149. package/dist/content-layer/plugins/internal/mcp/server/audit.js +1 -1
  150. package/dist/content-layer/plugins/internal/mcp/server/auth.js +1 -1
  151. package/dist/content-layer/plugins/internal/mcp/server/codemode/constants.js +1 -1
  152. package/dist/content-layer/plugins/internal/mcp/server/codemode/execute-schema.js +1 -1
  153. package/dist/content-layer/plugins/internal/mcp/server/codemode/prompts.js +8 -8
  154. package/dist/content-layer/plugins/internal/mcp/server/config-gate.js +1 -1
  155. package/dist/content-layer/plugins/internal/mcp/server/custom-tools.js +1 -1
  156. package/dist/content-layer/plugins/internal/mcp/server/gateway/call-api.js +2 -2
  157. package/dist/content-layer/plugins/internal/mcp/server/gateway/credentials-handler.js +1 -1
  158. package/dist/content-layer/plugins/internal/mcp/server/gateway/credentials-page/form-page.js +1 -1
  159. package/dist/content-layer/plugins/internal/mcp/server/gateway/credentials-page/site-branding.js +1 -1
  160. package/dist/content-layer/plugins/internal/mcp/server/gateway/credentials.js +1 -1
  161. package/dist/content-layer/plugins/internal/mcp/server/gateway/elicitation.js +6 -6
  162. package/dist/content-layer/plugins/internal/mcp/server/gateway/index.js +3 -3
  163. package/dist/content-layer/plugins/internal/mcp/server/gateway/subject.js +1 -1
  164. package/dist/content-layer/plugins/internal/mcp/server/gateway/tool-list.js +1 -1
  165. package/dist/content-layer/plugins/internal/mcp/server/gateway/tools.js +4 -4
  166. package/dist/content-layer/plugins/internal/mcp/server/handler.js +1 -1
  167. package/dist/content-layer/plugins/internal/mcp/server/mcp-server.js +1 -1
  168. package/dist/content-layer/plugins/internal/mcp/server/mcp-telemetry.js +1 -1
  169. package/dist/content-layer/plugins/internal/mcp/server/oauth/authorize.js +1 -1
  170. package/dist/content-layer/plugins/internal/mcp/server/oauth/callback.js +1 -1
  171. package/dist/content-layer/plugins/internal/mcp/server/oauth/discovery.js +1 -1
  172. package/dist/content-layer/plugins/internal/mcp/server/oauth/register.js +1 -1
  173. package/dist/content-layer/plugins/internal/mcp/server/oauth/token.js +1 -1
  174. package/dist/content-layer/plugins/internal/mcp/server/server-card.js +1 -1
  175. package/dist/content-layer/plugins/internal/mcp/server/server-info.js +1 -1
  176. package/dist/content-layer/plugins/internal/mcp/server/skills-resources.js +1 -1
  177. package/dist/content-layer/plugins/internal/mcp/server/tools/pages-navigation.js +1 -1
  178. package/dist/content-layer/plugins/internal/mcp/server/tools/pages.js +2 -2
  179. package/dist/content-layer/plugins/internal/mcp/server/tools/schemas.js +1 -1
  180. package/dist/content-layer/plugins/internal/mcp/server/tools/search.js +2 -2
  181. package/dist/content-layer/plugins/internal/mcp/server/workflows/resolve-workflows.js +1 -1
  182. package/dist/content-layer/plugins/internal/mcp/server/workflows/schemas.js +2 -1
  183. package/dist/content-layer/plugins/internal/mcp/server/workflows/tools.js +1 -1
  184. package/dist/content-layer/plugins/internal/mcp/setup-page.js +1 -1
  185. package/dist/content-layer/plugins/internal/mock/server/handler.js +1 -1
  186. package/dist/content-layer/plugins/internal/react-page/index.js +1 -1
  187. package/dist/content-layer/plugins/internal/scorecard-classic/client/template.js +1 -1
  188. package/dist/content-layer/plugins/internal/scorecard-classic/index.js +1 -1
  189. package/dist/content-layer/plugins/internal/sidebar/bundle.js +1 -1
  190. package/dist/content-layer/plugins/internal/sidebar/index.js +2 -2
  191. package/dist/content-layer/plugins/internal/skills/index.js +1 -1
  192. package/dist/content-layer/plugins/internal/skills/server/routes.js +1 -1
  193. package/dist/content-layer/plugins/io.js +1 -1
  194. package/dist/content-layer/plugins/project/load.js +2 -2
  195. package/dist/content-layer/plugins/source-file.js +1 -1
  196. package/dist/content-layer/plugins/utils/link-access.js +1 -1
  197. package/dist/content-layer/plugins/utils/route-index.js +1 -1
  198. package/dist/content-layer/revisions/delete.js +1 -1
  199. package/dist/content-layer/revisions/read.js +1 -1
  200. package/dist/content-layer/search/engine/core/search-engine.js +1 -1
  201. package/dist/content-layer/search/postings/postings-store.js +1 -1
  202. package/dist/content-layer/server/database.js +1 -1
  203. package/dist/content-layer/static/registry.js +1 -1
  204. package/dist/content-layer/templates/template-set.js +1 -1
  205. package/dist/content-layer/versions/redirect.js +1 -1
  206. package/dist/content-layer/versions/resolve.js +1 -1
  207. package/dist/server/app.js +3 -3
  208. package/dist/server/ask-ai/route.js +1 -1
  209. package/dist/server/auth/middleware.js +1 -1
  210. package/dist/server/auth/request.js +1 -1
  211. package/dist/server/auth/routes.js +1 -1
  212. package/dist/server/content.js +12 -12
  213. package/dist/server/cors-proxy/handler.js +1 -1
  214. package/dist/server/feedback/route.js +1 -1
  215. package/dist/server/lambda-entry.js +1 -1
  216. package/dist/server/manifest-assets.js +4 -4
  217. package/dist/server/node-entry.js +1 -1
  218. package/dist/server/plugin-context.js +1 -1
  219. package/dist/server/rbac/content-asset-access.js +1 -1
  220. package/dist/server/runtime-config.js +1 -1
  221. package/dist/server/search/route.js +1 -1
  222. package/dist/server/seo-tags.js +2 -2
  223. package/dist/server/sitemap.js +1 -1
  224. package/dist/server/static-files/serve.js +1 -1
  225. package/dist/server/subprocess/child-entry.js +1 -1
  226. package/dist/server/template-ids.js +1 -1
  227. package/dist/shared/constants/system-routes.js +1 -1
  228. package/dist/shared/rbac/engine.js +0 -0
  229. package/dist/shared/rbac/l10n-rules.js +1 -1
  230. package/dist/shared/rbac/route-scope.js +1 -1
  231. package/dist/shared/rbac/team-templates.js +1 -1
  232. package/dist/shared/types/config.d.ts +2 -1
  233. package/dist/shared/utils/l10n.js +1 -1
  234. package/dist/shared/utils/routes/file-path-to-route-slug.js +1 -1
  235. package/package.json +4 -4
@@ -1 +1 @@
1
- import{toJsonObject as e,toJsonValue as t}from"./database/utils/json.js";import{listL10nDirs as n,resolveLocaleContext as r}from"../shared/utils/l10n.js";import{isClosedToAnonymous as i,parseRbacConfigData as a}from"../shared/rbac/engine.js";import{hashEffectiveConfig as o,resolveSiteConfig as s}from"./database/site-config.js";import{resolveContentPath as c}from"../shared/utils/resolve-content-path.js";import{getProcessEnv as l,getPublicEnv as u,resolveRedoclyEnvironment as d,sanitizeBranchName as f}from"../shared/public-env.js";import{readProjectEnv as p}from"../shared/project-env.js";import{expandConfigRbacForL10n as m}from"../shared/rbac/l10n-rules.js";import{expandConfigRbacTeamTemplates as h,listTeamDirs as g,teamTemplatePrefixes as _}from"../shared/rbac/team-templates.js";import{hashContentBytes as v}from"../shared/utils/content-hash.js";import{resolveConfigRedirects as y}from"./config-redirects.js";import{NESTED_CONFIG_SCHEMA as b,realmConfigSchema as x,sanitizeConfig as S}from"./config-schema.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,r={}){let i=await oe(e,t),a=l();if(!i){let e=[],t=j(C(w($(),a,t=>e.push({code:`configuration/ignored`,message:t})),a),a);return{absolutePath:null,config:t,siteConfig:t,path:null,hash:null,refs:[],problems:e}}let o=await t.readBinaryFile(i.absolutePath),c=[],u=[],d=[],f=L(new TextDecoder().decode(o),i.path),m=[],h=p(a),y={contentDir:e,fs:t,env:h,refs:d,warnings:c,errors:u},b=Q(await W(await B(await R(f,{...y,deprecations:m}),``,y),y)),x={filePath:i.path},S=[],T=K(b.access)?b.access.rbac:void 0,E=Y(b,{dirLocales:await n(e,t),teamDirs:await g(e,t,_(K(T)?T:{})),env:h,pluginSchemas:r,report:e=>S.push({...e,location:x})}),D=j(C(w(E,a,e=>S.push({code:`configuration/ignored`,message:e,location:x})),a),a),{config:O,unsetVars:k}=s(D,h);for(let e of k)c.push(`The config references process.env.${e}, which is not set.`);let A=[...c.map(e=>({code:`configuration/ignored`,message:e,location:x})),...[...new Set(m)].map(e=>({code:`configuration/deprecated`,message:e,location:x})),...u.map(e=>({code:`configuration/invalid`,severity:`error`,message:e,location:x})),...S];return{...i,config:O,siteConfig:D,hash:await v(o),refs:d,problems:A}}function j(e,t){let{grpcDocsEnabled:n,...r}=e;return t.REDOCLY_EXP_GRPC_DOCS_ENABLED===`true`?{...r,grpcDocsEnabled:!0}:r}function M(e,t){return o(e)!==t}async function N(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=Object.fromEntries(e.context.pluginRegistry.list().flatMap(e=>e.configSchema?[[e.id,e.configSchema]]:[])),n=await A(e.context.contentDir,e.context.platform.fs,t);return e.context.config=n.config,e.context.siteConfig=n.siteConfig,e.context.configFilePath=n.path,e.context.configHash=n.hash,e.context.configRefs=n.refs,e.context.configLoaded=!0,n}function P(e,t){let n=E(L(e,t),p(l())).value,{value:r,problems:i}=S(b,n);for(let e of i)e.location={filePath:t};return{config:r,problems:i}}function F(e){return e.endsWith(`/${k}`)}async function I(e){let t=[];for(let n of e.paths)try{let r=await e.fs.readFile(T(e.contentDir,n));t.push(...P(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 L(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 R(e,t){let{env:n,...r}=e;if(!K(n))return e;let i=t.env.PUBLIC_REDOCLY_BRANCH_NAME,a=[...i?[`branch.${f(i)}`]:[],d(t.env.REDOCLY_ENV)],o=e=>t.deprecations.push(e),s=X(r,o);for(let e of a){let r=await z(n[e],e,t);r&&(s=G(s,X(r,o)))}return s}async function z(e,t,n){if(!K(e))return null;if(typeof e.$ref!=`string`)return e;let{$ref:r,...i}=e,a=`env.${t}`,o=V(await H(r,a,n),i,a,n);return K(o)?o:null}async function B(e,t,n){if(Array.isArray(e))return Promise.all(e.map((e,r)=>B(e,`${t}[${r}]`,n)));if(!K(e))return e;if(typeof e.$ref==`string`){let{$ref:r,...i}=e;return V(await H(r,t,n),await B(i,t,n),t,n)}let r={};for(let[i,a]of Object.entries(e))r[i]=await B(a,t===``?i:`${t}.${i}`,n);return r}function V(e,t,n,r){if(Object.keys(t).length===0)return e;if(K(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 H(e,n,r){return U(e,`${n} $ref`,r,e=>t(D.load(e)))}async function U(e,t,n,r,i=`warning`){let a=i===`error`?n.errors:n.warnings,o=c(e,O[0]);if(o===null)return a.push(`${t} "${e}" escapes the content root.`),null;try{let e=await n.fs.readBinaryFile(T(n.contentDir,o));return n.refs.push({path:o,hash:await v(e)}),r(new TextDecoder().decode(e))}catch(n){let r=n instanceof Error?n.message:String(n);return a.push(`Cannot read ${t} "${e}": ${r}`),null}}async function W(e,t){let{seo:n}=e;if(!K(n)||!K(n.llmstxt)||!K(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 U(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 G(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]=K(t)&&K(r)?G(t,r):r}return n}function K(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}const q=[`hide`,`name`,`ignore`,`publicEndpoint`],J=`redocly.apigee`,ee=[`requiresLogin`,`rbac`,`sso`,`idps`,`logoutReturnUrl`,`residency`];function Y(e,t={}){let n=t.report??(()=>{}),i=t.dirLocales??[],a=X(e,e=>n({code:`configuration/deprecated`,message:e}));K(a.mcp)&&a.mcp.docs!==void 0&&n({code:`configuration/deprecated`,message:`The 'mcp.docs' property is deprecated. Use the 'mcp' properties instead.`});let o=S(x(t.pluginSchemas??{}),a,{env:t.env});for(let e of o.problems)n(e);let{redirects:s,access:c,...l}=m(h(te(o.value,t.env),t.teamDirs??{},n),i),d={...l,publicEnv:u()};c&&(d.access=ae(c,n));let f=y(s,r(l.l10n,i));return f&&(d.redirects=f),d}function te(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 X(e,t){return ne(ie(re(Q(e),t)),t)}function ne(e,t){let{developerOnboarding:n}=e;if(!K(n)||!Array.isArray(n.adapters))return e;let r=n.adapters.find(e=>K(e)&&(e.type===`APIGEE_X`||e.type===`APIGEE_EDGE`));if(!K(r)||(t(`The Apigee adapter in 'developerOnboarding' is deprecated. Add the Apigee plugin and move the adapter to 'redocly.apigee'.`),e[J]!==void 0))return e;let{type:i,ignoreApiProducts:a,allowApiProductsOutsideCatalog:o,...s}=r,c={};return a!==void 0&&(c.exclude=a),o!==void 0&&(c.allowOutsideCatalog=o),{...e,[J]:{...s,apiProducts:c}}}function re(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=Z(e));let{access:r}=n;return K(r)&&K(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:Z(r.rbac)}}),n}function Z(e){let{reunite:t,...n}=e;return{...n,platform:e.platform??t}}function ie(e){let{mcp:t}=e;if(!K(t))return e;let{docs:n,...r}=t;if(!K(n))return e;let i={...n};for(let e of q){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=ee.map(t=>[t,e[t]]).filter(([,e])=>e!==void 0);if(t.length===0)return e;let n={...e},r=K(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 ae(e,t){let n=e.rbac?a(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:i(n)}):e}async function oe(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 Y({})}export{k as NESTED_CONFIG_FILENAME,O as REDOCLY_CONFIG_FILENAMES,$ as createEmptyRealmConfig,G as deepMergeConfig,M as isConfigChanged,F as isNestedConfigPath,N as loadContentLayerConfig,A as loadRedoclyConfig,Y as normalizeRedoclyConfig,P as parseNestedConfig,I as readNestedConfigProblems};
1
+ import{toJsonObject as e,toJsonValue as t}from"./database/utils/json.js";import{hashContentBytes as n}from"../shared/utils/content-hash.js";import{getProcessEnv as r,getPublicEnv as i,resolveRedoclyEnvironment as a,sanitizeBranchName as o}from"../shared/public-env.js";import{isClosedToAnonymous as s,parseRbacConfigData as c}from"../shared/rbac/engine.js";import{readProjectEnv as l}from"../shared/project-env.js";import{listL10nDirs as u,resolveLocaleContext as d}from"../shared/utils/l10n.js";import{expandConfigRbacForL10n as f}from"../shared/rbac/l10n-rules.js";import{expandConfigRbacTeamTemplates as p,listTeamDirs as m,teamTemplatePrefixes as h}from"../shared/rbac/team-templates.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,realmConfigSchema as y,sanitizeConfig as b}from"./config-schema.js";import{hashEffectiveConfig as x,resolveSiteConfig as ee}from"./database/site-config.js";import{applyEnforcedAccess as S}from"./enforced-access.js";import{applyPlanGates as C}from"./plan-gates.js";import{posix as w,resolve as T}from"node:path";import E from"js-yaml";import{interpolateEnvVariables as D}from"@redocly/config";const O=[`redocly.yaml`,`redocly.yml`],k=`redocly.yaml`;async function A(e,t,i={}){let a=await le(e,t),o=r();if(!a){let e=[],t=j(S(C($(),o,t=>e.push({code:`configuration/ignored`,message:t})),o),o);return{absolutePath:null,config:t,siteConfig:t,path:null,hash:null,refs:[],problems:e}}let s=await t.readBinaryFile(a.absolutePath),c=[],d=[],f=[],p=L(new TextDecoder().decode(s),a.path),g=[],_=l(o),v={contentDir:e,fs:t,env:_,refs:f,warnings:c,errors:d},y=Q(await te(await B(await R(p,{...v,deprecations:g}),``,v),v)),b={filePath:a.path},x=[],w=G(y.access)?y.access.rbac:void 0,T=q(y,{dirLocales:await u(e,t),teamDirs:await m(e,t,h(G(w)?w:{})),env:_,pluginSchemas:i,report:e=>x.push({...e,location:b})}),E=j(S(C(T,o,e=>x.push({code:`configuration/ignored`,message:e,location:b})),o),o),{config:D,unsetVars:O}=ee(E,_);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:b})),...[...new Set(g)].map(e=>({code:`configuration/deprecated`,message:e,location:b})),...d.map(e=>({code:`configuration/invalid`,severity:`error`,message:e,location:b})),...x];return{...a,config:D,siteConfig:E,hash:await n(s),refs:f,problems:k}}function j(e,t){let{grpcDocsEnabled:n,...r}=e;return t.REDOCLY_EXP_GRPC_DOCS_ENABLED===`true`?{...r,grpcDocsEnabled:!0}:r}function M(e,t){return x(e)!==t}async function N(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=Object.fromEntries(e.context.pluginRegistry.list().flatMap(e=>e.configSchema?[[e.id,e.configSchema]]:[])),n=await A(e.context.contentDir,e.context.platform.fs,t);return e.context.config=n.config,e.context.siteConfig=n.siteConfig,e.context.configFilePath=n.path,e.context.configHash=n.hash,e.context.configRefs=n.refs,e.context.configLoaded=!0,n}function P(e,t){let n=D(L(e,t),l(r())).value,{value:i,problems:a}=b(v,n);a.push(...Y(i,w.dirname(t)));for(let e of a)e.location={filePath:t};return{config:i,problems:a}}function F(e){return e.endsWith(`/${k}`)}async function I(e){let t=[];for(let n of e.paths)try{let r=await e.fs.readFile(T(e.contentDir,n));t.push(...P(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 L(t,n){let r=E.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 R(e,t){let{env:n,...r}=e;if(!G(n))return e;let i=t.env.PUBLIC_REDOCLY_BRANCH_NAME,s=[...i?[`branch.${o(i)}`]:[],a(t.env.REDOCLY_ENV)],c=e=>t.deprecations.push(e),l=X(r,c);for(let e of s){let r=await z(n[e],e,t);r&&(l=W(l,X(r,c)))}return l}async function z(e,t,n){if(!G(e))return null;if(typeof e.$ref!=`string`)return e;let{$ref:r,...i}=e,a=`env.${t}`,o=V(await H(r,a,n),i,a,n);return G(o)?o:null}async function B(e,t,n){if(Array.isArray(e))return Promise.all(e.map((e,r)=>B(e,`${t}[${r}]`,n)));if(!G(e))return e;if(typeof e.$ref==`string`){let{$ref:r,...i}=e;return V(await H(r,t,n),await B(i,t,n),t,n)}let r={};for(let[i,a]of Object.entries(e))r[i]=await B(a,t===``?i:`${t}.${i}`,n);return r}function V(e,t,n,r){if(Object.keys(t).length===0)return e;if(G(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 H(e,n,r){return U(e,`${n} $ref`,r,e=>t(E.load(e)))}async function U(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(!G(n)||!G(n.llmstxt)||!G(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 U(D(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 W(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]=G(t)&&G(r)?W(t,r):r}return n}function G(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}const ne=[`hide`,`name`,`ignore`,`publicEndpoint`],K=`redocly.apigee`,re=[`requiresLogin`,`rbac`,`sso`,`idps`,`logoutReturnUrl`,`residency`];function q(e,t={}){let n=t.report??(()=>{}),r=t.dirLocales??[],a=X(e,e=>n({code:`configuration/deprecated`,message:e}));G(a.mcp)&&a.mcp.docs!==void 0&&n({code:`configuration/deprecated`,message:`The 'mcp.docs' property is deprecated. Use the 'mcp' properties instead.`});let o=b(y(t.pluginSchemas??{}),a,{env:t.env});for(let e of o.problems)n(e);let{redirects:s,access:c,...l}=f(p(ie(o.value,t.env),t.teamDirs??{},n),r),u={...l,publicEnv:i()};c&&(u.access=ce(c,n));let m=_(s,d(l.l10n,r));m&&(u.redirects=m);for(let e of Y(u,``))n(e);return u}function J(e,t){let n=[],r=[];for(let i of typeof e==`string`?[e]:e){let e=w.join(t,i);e===`..`||e.startsWith(`../`)?r.push(i):n.push(e)}return{folders:n,outside:r}}function Y(e,t){return[[`grpc.importPaths`,e.grpc?.importPaths],...Object.entries(e.apis??{}).map(([e,t])=>[`apis.${e}.grpc.importPaths`,t.grpc?.importPaths])].flatMap(([e,n])=>n===void 0?[]:J(n,t).outside.map(t=>({code:`configuration/ignored`,message:`\`${e}\` folder \`${t}\` is outside the content root and is ignored.`})))}function ie(e,t){if(!t)return e;let n={...e};for(let r of[`access`,`l10n`,`redirects`])r in e&&(n[r]=D(e[r],t).value);return n}function X(e,t){return ae(se(oe(Q(e),t)),t)}function ae(e,t){let{developerOnboarding:n}=e;if(!G(n)||!Array.isArray(n.adapters))return e;let r=n.adapters.find(e=>G(e)&&(e.type===`APIGEE_X`||e.type===`APIGEE_EDGE`));if(!G(r)||(t(`The Apigee adapter in 'developerOnboarding' is deprecated. Add the Apigee plugin and move the adapter to 'redocly.apigee'.`),e[K]!==void 0))return e;let{type:i,ignoreApiProducts:a,allowApiProductsOutsideCatalog:o,...s}=r,c={};return a!==void 0&&(c.exclude=a),o!==void 0&&(c.allowOutsideCatalog=o),{...e,[K]:{...s,apiProducts:c}}}function oe(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=Z(e));let{access:r}=n;return G(r)&&G(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:Z(r.rbac)}}),n}function Z(e){let{reunite:t,...n}=e;return{...n,platform:e.platform??t}}function se(e){let{mcp:t}=e;if(!G(t))return e;let{docs:n,...r}=t;if(!G(n))return e;let i={...n};for(let e of ne){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=re.map(t=>[t,e[t]]).filter(([,e])=>e!==void 0);if(t.length===0)return e;let n={...e},r=G(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 ce(e,t){let n=e.rbac?c(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:s(n)}):e}async function le(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 q({})}export{k as NESTED_CONFIG_FILENAME,O as REDOCLY_CONFIG_FILENAMES,$ as createEmptyRealmConfig,W as deepMergeConfig,M as isConfigChanged,F as isNestedConfigPath,N as loadContentLayerConfig,A as loadRedoclyConfig,q as normalizeRedoclyConfig,P as parseNestedConfig,I as readNestedConfigProblems,J as resolveGrpcImportPaths};
@@ -1 +1 @@
1
- import{normalizeBatchSize as e}from"./database/connection.js";import{loadPersistedContentStateEntities as t,loadPersistedContentStateSummary as n}from"./database/files.js";import{contentIgnoreMatcherOf as r}from"./ingest/scan.js";import{createContentOriginKey as i}from"./plugins/utils/origin-key.js";import{comparePrimarySlug as a}from"../shared/utils/routes/compare-primary-slug.js";async function o(e){if(!e.context.state){let t=await n(e.database);e.context.state=l(t,r(e.context.config))}return e.context.state}async function s(n){let r=n.keys!==void 0&&n.keys.length<=e(void 0)?n.keys:void 0,i=u(await t(n.database,r));if(r===void 0){n.state.entitiesByKey=i;return}for(let[e,t]of i)n.state.entitiesByKey.set(e,t)}function c(e,t){for(let[n,r]of e.filesByPath)t(n)&&(e.filesByPath.delete(n),e.ignoredFilesByPath.set(n,r));for(let[n,r]of e.ignoredFilesByPath)t(n)||(e.ignoredFilesByPath.delete(n),e.filesByPath.set(n,r))}function l(e,t){let n=/* @__PURE__ */ new Map,r=/* @__PURE__ */ new Map;for(let i of e.files)(t(i.path)?r:n).set(i.path,i);let o=/* @__PURE__ */ new Map,s=/* @__PURE__ */ new Map,c=/* @__PURE__ */ new Map,l=u(e.entities);for(let t of e.routes){let e=i(t.originPluginId,t.originFilePath),n=o.get(e)??[];if(n.push(t),o.set(e,n),s.set(t.slug,t),t.originFilePath===null)continue;let r=c.get(t.originFilePath);(r===void 0||a(t.slug,r)<0)&&c.set(t.originFilePath,t.slug)}return{wildcardShadows:/* @__PURE__ */ new Set,filePluginsByPath:e.filePluginsByPath,filesByPath:n,ignoredFilesByPath:r,primaryRouteByFilePath:c,routeBySlug:s,routesByOriginKey:o,entitiesByKey:l}}function u(e){return new Map(e.map(e=>[e.key,{id:e.id,key:e.key,kind:e.kind,type:e.type,metadata:e.metadata,dataHash:e.dataHash,pluginId:e.pluginId,loaderId:e.loaderId,loaderArgs:e.loaderArgs,status:e.status,isSystem:e.isSystem===1}]))}export{o as loadContentLayerState,c as partitionIgnoredFiles,s as reloadContentLayerEntities};
1
+ import{contentIgnoreMatcherOf as e}from"./ingest/scan.js";import{normalizeBatchSize as t}from"./database/connection.js";import{createContentOriginKey as n}from"./plugins/utils/origin-key.js";import{loadPersistedContentStateEntities as r,loadPersistedContentStateSummary as i}from"./database/files.js";import{comparePrimarySlug as a}from"../shared/utils/routes/compare-primary-slug.js";async function o(t){if(!t.context.state){let n=await i(t.database);t.context.state=l(n,e(t.context.config))}return t.context.state}async function s(e){let n=e.keys!==void 0&&e.keys.length<=t(void 0)?e.keys:void 0,i=u(await r(e.database,n));if(n===void 0){e.state.entitiesByKey=i;return}for(let[t,n]of i)e.state.entitiesByKey.set(t,n)}function c(e,t){for(let[n,r]of e.filesByPath)t(n)&&(e.filesByPath.delete(n),e.ignoredFilesByPath.set(n,r));for(let[n,r]of e.ignoredFilesByPath)t(n)||(e.ignoredFilesByPath.delete(n),e.filesByPath.set(n,r))}function l(e,t){let r=/* @__PURE__ */ new Map,i=/* @__PURE__ */ new Map;for(let n of e.files)(t(n.path)?i:r).set(n.path,n);let o=/* @__PURE__ */ new Map,s=/* @__PURE__ */ new Map,c=/* @__PURE__ */ new Map,l=u(e.entities);for(let t of e.routes){let e=n(t.originPluginId,t.originFilePath),r=o.get(e)??[];if(r.push(t),o.set(e,r),s.set(t.slug,t),t.originFilePath===null)continue;let i=c.get(t.originFilePath);(i===void 0||a(t.slug,i)<0)&&c.set(t.originFilePath,t.slug)}return{wildcardShadows:/* @__PURE__ */ new Set,filePluginsByPath:e.filePluginsByPath,filesByPath:r,ignoredFilesByPath:i,primaryRouteByFilePath:c,routeBySlug:s,routesByOriginKey:o,entitiesByKey:l}}function u(e){return new Map(e.map(e=>[e.key,{id:e.id,key:e.key,kind:e.kind,type:e.type,metadata:e.metadata,dataHash:e.dataHash,pluginId:e.pluginId,loaderId:e.loaderId,loaderArgs:e.loaderArgs,status:e.status,isSystem:e.isSystem===1}]))}export{o as loadContentLayerState,c as partitionIgnoredFiles,s as reloadContentLayerEntities};
@@ -2,9 +2,11 @@ import type { Platform } from '../platform/types/platform.js';
2
2
  import { type Logger } from '../shared/logger.js';
3
3
  import { type ConfigFileRef, type RealmConfig } from './config.js';
4
4
  import type { CurrentContentFileIndex } from './ingest/current-files.js';
5
+ import type { GitLastModified } from './ingest/git-last-modified.js';
5
6
  import { type ContentPluginRegistry } from './plugins/registry.js';
6
7
  import type { ContentPluginIO } from './plugins/types/io.js';
7
8
  import type { ContentPlugin } from './plugins/types/plugin.js';
9
+ import type { RouteQueryRowsSnapshot } from './database/route-query-deps.js';
8
10
  import type { ContentLayerState } from './context-state.js';
9
11
  export type ContentLayerContext = {
10
12
  config: RealmConfig;
@@ -16,10 +18,14 @@ export type ContentLayerContext = {
16
18
  configLoaded: boolean;
17
19
  contentDir: string;
18
20
  currentFileIndex?: CurrentContentFileIndex;
21
+ /** The commit dates the last ingest read; the next ingest reuses them while HEAD stays. */
22
+ gitLastModified?: GitLastModified;
19
23
  logger: Logger;
20
24
  platform: Platform;
21
25
  pluginIO: ContentPluginIO;
22
26
  pluginRegistry: ContentPluginRegistry;
27
+ /** The stored route queries the last ingest read; the next ingest reuses them while the table is unchanged. */
28
+ routeQueryRows?: RouteQueryRowsSnapshot;
23
29
  state?: ContentLayerState;
24
30
  };
25
31
  export type CreateContentLayerContextOptions = {
@@ -1 +1 @@
1
- import{createLogger as e}from"../shared/logger.js";import{createNodePlatform as t}from"../platform/node/create.js";import{createEmptyRealmConfig as n}from"./config.js";import{createContentPluginIO as r}from"./plugins/io.js";import{createContentPluginRegistry as i}from"./plugins/registry.js";import{resolve as a}from"node:path";function o(o){let s=a(o.contentDir),c=o.platform??t(),l=o.pluginRegistry??i(o.plugins??[],o.logger),u=o.config??n();return{config:u,siteConfig:u,configFilePath:o.configFilePath??null,configHash:null,configRefs:[],configLoaded:o.configLoaded??o.config!==void 0,contentDir:s,currentFileIndex:o.currentFileIndex,logger:o.logger??e(),platform:c,pluginIO:o.pluginIO??r(c.fs),pluginRegistry:l,state:o.state}}function s(e){return e.context?(e.currentFileIndex!==void 0&&(e.context.currentFileIndex=e.currentFileIndex),e.context):o({contentDir:e.contentDir,currentFileIndex:e.currentFileIndex,logger:e.logger,plugins:e.plugins})}export{o as createContentLayerContext,s as resolveContentLayerContext};
1
+ import{createNodePlatform as e}from"../platform/node/create.js";import{createLogger as t}from"../shared/logger.js";import{createEmptyRealmConfig as n}from"./config.js";import{createContentPluginIO as r}from"./plugins/io.js";import{createContentPluginRegistry as i}from"./plugins/registry.js";import{resolve as a}from"node:path";function o(o){let s=a(o.contentDir),c=o.platform??e(),l=o.pluginRegistry??i(o.plugins??[],o.logger),u=o.config??n();return{config:u,siteConfig:u,configFilePath:o.configFilePath??null,configHash:null,configRefs:[],configLoaded:o.configLoaded??o.config!==void 0,contentDir:s,currentFileIndex:o.currentFileIndex,logger:o.logger??t(),platform:c,pluginIO:o.pluginIO??r(c.fs),pluginRegistry:l,state:o.state}}function s(e){return e.context?(e.currentFileIndex!==void 0&&(e.context.currentFileIndex=e.currentFileIndex),e.context):o({contentDir:e.contentDir,currentFileIndex:e.currentFileIndex,logger:e.logger,plugins:e.plugins})}export{o as createContentLayerContext,s as resolveContentLayerContext};
@@ -1 +1 @@
1
- import{runWithSqliteBusyRetry as e}from"./connection.js";import{assetRefs as t,assets as n}from"./schema.js";import{and as r,eq as i,inArray as a,sql as o}from"drizzle-orm";async function s(e,t){if(t.length===0)return[];let o=/* @__PURE__ */ new Set;for(let a of t){let t=await e.select({filename:n.filename}).from(n).where(r(i(n.path,a.path),i(n.hash,a.hash)));for(let e of t)e.filename!==a.filename&&o.add(e.filename)}await e.insert(n).values([...t]).onConflictDoNothing();for(let a of t)await e.update(n).set({filename:a.filename}).where(r(i(n.path,a.path),i(n.hash,a.hash)));if(o.size===0)return[];let s=await e.select({filename:n.filename}).from(n).where(a(n.filename,[...o]));for(let e of s)o.delete(e.filename);return[...o]}async function c(e,n){await e.delete(t).where(i(t.entityId,n.entityId)),n.refs.length!==0&&await e.insert(t).values(n.refs.map(e=>({...e,entityId:n.entityId})))}async function l(e){return(await e.db.selectDistinct({path:n.path}).from(n)).map(e=>e.path)}async function u(e){return e.db.select({path:n.path,hash:n.hash,kind:n.kind,filename:n.filename}).from(n)}async function d(t,r){return e(async()=>{let e=await t.db.delete(n).where(o`(${n.path}, ${n.hash}) NOT IN (SELECT DISTINCT path, hash FROM asset_refs)`).returning(),r=new Set(e.map(e=>e.filename));if(r.size>0){let e=await t.db.select({filename:n.filename}).from(n).where(a(n.filename,[...r]));for(let t of e)r.delete(t.filename)}return{removed:e,orphanedFilenames:[...r]}},{logger:r?.logger,operation:`gc orphan assets`})}export{d as garbageCollectOrphanAssets,l as listAssetSourcePaths,u as listRegisteredAssets,c as replaceAssetRefsForEntityTx,s as upsertAssetsTx};
1
+ import{assetRefs as e,assets as t}from"./schema.js";import{runWithSqliteBusyRetry as n}from"./connection.js";import{and as r,eq as i,inArray as a,sql as o}from"drizzle-orm";async function s(e,n){if(n.length===0)return[];let o=/* @__PURE__ */ new Set;for(let a of n){let n=await e.select({filename:t.filename}).from(t).where(r(i(t.path,a.path),i(t.hash,a.hash)));for(let e of n)e.filename!==a.filename&&o.add(e.filename)}await e.insert(t).values([...n]).onConflictDoNothing();for(let a of n)await e.update(t).set({filename:a.filename}).where(r(i(t.path,a.path),i(t.hash,a.hash)));if(o.size===0)return[];let s=await e.select({filename:t.filename}).from(t).where(a(t.filename,[...o]));for(let e of s)o.delete(e.filename);return[...o]}async function c(t,n){await t.delete(e).where(i(e.entityId,n.entityId)),n.refs.length!==0&&await t.insert(e).values(n.refs.map(e=>({...e,entityId:n.entityId})))}async function l(e){return(await e.db.selectDistinct({path:t.path}).from(t)).map(e=>e.path)}async function u(e){return e.db.select({path:t.path,hash:t.hash,kind:t.kind,filename:t.filename}).from(t)}async function d(e,r){return n(async()=>{let n=await e.db.delete(t).where(o`(${t.path}, ${t.hash}) NOT IN (SELECT DISTINCT path, hash FROM asset_refs)`).returning(),r=new Set(n.map(e=>e.filename));if(r.size>0){let n=await e.db.select({filename:t.filename}).from(t).where(a(t.filename,[...r]));for(let e of n)r.delete(e.filename)}return{removed:n,orphanedFilenames:[...r]}},{logger:r?.logger,operation:`gc orphan assets`})}export{d as garbageCollectOrphanAssets,l as listAssetSourcePaths,u as listRegisteredAssets,c as replaceAssetRefsForEntityTx,s as upsertAssetsTx};
@@ -1 +1 @@
1
- import{runWithSqliteBusyRetry as e}from"./connection.js";import{blobRefs as t,blobs as n}from"./schema.js";import{eq as r,sql as i}from"drizzle-orm";async function a(t,r,i){await e(()=>t.db.insert(n).values({...r,createdAt:Date.now()}).onConflictDoNothing(),{logger:i?.logger,operation:`upsert blob`})}async function o(e,t){let[i]=await e.db.select().from(n).where(r(n.key,t)).limit(1);return i??null}async function s(e,t){let n=await o(e,t.blobKey);if(!n)throw Error(`Blob not found: ${t.blobKey}`);return t.format===`json`?JSON.parse(n.content):t.format===`text`?n.content:Buffer.from(n.content,`base64`)}async function c(e,n){await e.delete(t).where(r(t.entityId,n.entityId)),n.blobKeys.length!==0&&await e.insert(t).values(n.blobKeys.map(e=>({blobKey:e,entityId:n.entityId})))}async function l(t,n){return{removed:(await e(()=>t.db.run(i`DELETE FROM blobs WHERE key NOT IN (SELECT DISTINCT blob_key FROM blob_refs)`),{logger:n?.logger,operation:`gc orphan blobs`})).rowsAffected??0}}export{l as garbageCollectOrphanBlobs,o as getBlob,c as replaceBlobRefsForEntityTx,s as resolveDataRef,a as upsertBlob};
1
+ import{blobRefs as e,blobs as t}from"./schema.js";import{runWithSqliteBusyRetry as n}from"./connection.js";import{eq as r,sql as i}from"drizzle-orm";async function a(e,r,i){await n(()=>e.db.insert(t).values({...r,createdAt:Date.now()}).onConflictDoNothing(),{logger:i?.logger,operation:`upsert blob`})}async function o(e,n){let[i]=await e.db.select().from(t).where(r(t.key,n)).limit(1);return i??null}async function s(e,t){let n=await o(e,t.blobKey);if(!n)throw Error(`Blob not found: ${t.blobKey}`);return t.format===`json`?JSON.parse(n.content):t.format===`text`?n.content:Buffer.from(n.content,`base64`)}async function c(t,n){await t.delete(e).where(r(e.entityId,n.entityId)),n.blobKeys.length!==0&&await t.insert(e).values(n.blobKeys.map(e=>({blobKey:e,entityId:n.entityId})))}async function l(e,t){return{removed:(await n(()=>e.db.run(i`DELETE FROM blobs WHERE key NOT IN (SELECT DISTINCT blob_key FROM blob_refs)`),{logger:t?.logger,operation:`gc orphan blobs`})).rowsAffected??0}}export{l as garbageCollectOrphanBlobs,o as getBlob,c as replaceBlobRefsForEntityTx,s as resolveDataRef,a as upsertBlob};
@@ -2,4 +2,6 @@ import type { ContentLayerDatabase } from './connection.js';
2
2
  import { type EntityRecord } from './schema.js';
3
3
  export declare const generateEntityId: (size?: number) => string;
4
4
  export declare function loadEntityRecordByKey(database: ContentLayerDatabase, key: string): Promise<EntityRecord | null>;
5
+ /** The slug that `/` redirects to on a site without a `/` page; null when the site has none. */
6
+ export declare function loadSiteStart(database: ContentLayerDatabase): Promise<string | null>;
5
7
  export declare function loadStaleEntityRecords(database: ContentLayerDatabase): Promise<EntityRecord[]>;
@@ -1 +1 @@
1
- import{entities as e}from"./schema.js";import{and as t,eq as n}from"drizzle-orm";import{customAlphabet as r}from"nanoid";const i=r(`0123456789ABCDEFGHJKMNPQRSTVWXYZ`,26);async function a(r,i){let[a]=await r.db.select().from(e).where(t(n(e.key,i),n(e.isCurrent,1))).limit(1);return a??null}async function o(r){return r.db.select().from(e).where(t(n(e.status,`stale`),n(e.isCurrent,1))).orderBy(e.key)}export{i as generateEntityId,a as loadEntityRecordByKey,o as loadStaleEntityRecords};
1
+ import{entities as e}from"./schema.js";import{SITE_START_ENTITY_KEY as t}from"../../shared/constants/site-start.js";import{and as n,eq as r}from"drizzle-orm";import{customAlphabet as i}from"nanoid";const a=i(`0123456789ABCDEFGHJKMNPQRSTVWXYZ`,26);async function o(t,i){let[a]=await t.db.select().from(e).where(n(r(e.key,i),r(e.isCurrent,1))).limit(1);return a??null}async function s(i){let[a]=await i.db.select({data:e.data}).from(e).where(n(r(e.key,t),r(e.isCurrent,1))).limit(1);return typeof a?.data==`string`?a.data:null}async function c(t){return t.db.select().from(e).where(n(r(e.status,`stale`),r(e.isCurrent,1))).orderBy(e.key)}export{a as generateEntityId,o as loadEntityRecordByKey,s as loadSiteStart,c as loadStaleEntityRecords};
@@ -1 +1 @@
1
- import{hashJsonValue as e,toStableJsonString as t}from"./utils/json.js";import{compareStrings as n}from"../../shared/utils/compare-strings.js";import{MaterializationError as r}from"../problems/problem-error.js";import{entities as i}from"./schema.js";import{resolveDataRef as a}from"./blobs.js";import{replaceDataRefMarkers as o}from"../materialization/data-ref.js";import{listEntityRevisions as s}from"../revisions/list.js";import{selectEntityRowForRead as c}from"../revisions/read.js";import{and as l,eq as u,inArray as d}from"drizzle-orm";function f(e){let{database:t,state:d}=e,f=typeof e.revisionAsOf==`number`?e.revisionAsOf:null,p=async n=>{if(e.onEntityRead?.(n),f!==null){let e=await c(t.db,n,f);return e?S(e):null}let r=d?.entitiesByKey.get(n);if(r)return S(r);if(d)return null;let[a]=await t.db.select(x()).from(i).where(l(u(i.key,n),u(i.isCurrent,1))).limit(1);return a?S(a):null},g=e=>o(e,e=>a(t,e)),_=async(n,a)=>{let o=d?.entitiesByKey.get(n),[s]=f===null?d&&!o?[]:await t.db.select({status:i.status,data:i.data,dataHash:i.dataHash,type:i.type,metadata:i.metadata,isCurrent:i.isCurrent}).from(i).where(l(u(i.key,n),u(i.isCurrent,1))).limit(1):[await c(t.db,n,f)??void 0];if(!s)throw e.onEntityRead?.(n),Error(`Entity "${n}" is not registered.`);let p;if(s.status===`ready`&&s.data!==null||s.isCurrent!==1)p=s.data,d&&s.isCurrent===1&&f===null&&m(d,n,s);else if(e.materialize)try{p=await e.materialize(n)}catch(t){if(e.onEntityRead?.(n,!0),!a||!(t instanceof r))throw t;return s.data===null?void 0:g(s.data)}else throw Error(`Missing precomputed entity data for "${n}". Rebuild the content entity data before starting the production runtime.`);return e.onEntityRead?.(n),g(p)};return{get:p,async listRevisions(n){for(let t of n)e.onEntityRead?.(t);return s(t.db,n)},async list(r={}){let a=(d?[...d.entitiesByKey.values()].filter(e=>y(e,r)):await t.db.select(x()).from(i).where(l(u(i.isCurrent,1),r.type===void 0?void 0:u(i.type,r.type),r.pluginId===void 0?void 0:u(i.pluginId,r.pluginId)))).map(S).sort((e,t)=>n(e.key,t.key));return e.record?.({kind:`entity-type`,argument:h(r),resultHash:v(a.map(e=>e.key))}),a},load:async e=>await _(e,!1),tryLoad:async e=>await _(e,!0)}}async function p(e,t,n){let[r]=await e.db.select({status:i.status,dataHash:i.dataHash,type:i.type,metadata:i.metadata}).from(i).where(l(u(i.key,n),u(i.isCurrent,1))).limit(1);r&&m(t,n,r)}function m(e,t,n){let r=e.entitiesByKey.get(t);r&&Object.assign(r,{status:n.status,dataHash:n.dataHash,type:n.type,metadata:n.metadata})}function h(e){return t({...e.type===void 0?{}:{type:e.type},...e.pluginId===void 0?{}:{pluginId:e.pluginId}})}function g(t,n){let r=t.entitiesByKey.get(n);return e(r?[r.id,r.kind,r.type,r.metadata,r.dataHash,r.status]:`absent`)}function _(e,t){let r=JSON.parse(t),i=[];for(let t of e.entitiesByKey.values())y(t,r)&&i.push(t.key);return v(i.sort(n))}function v(t){return e([...t])}function y(e,t){return(t.type===void 0||e.type===t.type)&&(t.pluginId===void 0||e.pluginId===t.pluginId)}async function b(e,t){return t.length===0?[]:e.db.select({key:i.key,metadata:i.metadata}).from(i).where(l(d(i.key,[...t]),u(i.isCurrent,1)))}function x(){return{id:i.id,key:i.key,kind:i.kind,type:i.type,metadata:i.metadata,pluginId:i.pluginId,loaderId:i.loaderId,loaderArgs:i.loaderArgs,status:i.status,dataHash:i.dataHash,isSystem:i.isSystem}}function S(e){return{id:e.id,key:e.key,kind:e.kind,type:e.type,metadata:e.metadata,pluginId:e.pluginId,loaderId:e.loaderId,loaderArgs:e.loaderArgs,status:e.status,dataHash:e.dataHash,isSystem:e.isSystem===!0||e.isSystem===1}}export{f as createEntityStore,_ as hashEntityListMembership,g as hashEntityRead,b as loadCurrentEntityMetadata,p as refreshStateEntity};
1
+ import{hashJsonValue as e,toStableJsonString as t}from"./utils/json.js";import{compareStrings as n}from"../../shared/utils/compare-strings.js";import{entities as r}from"./schema.js";import{replaceDataRefMarkers as i}from"../materialization/data-ref.js";import{MaterializationError as a}from"../problems/problem-error.js";import{resolveDataRef as o}from"./blobs.js";import{listEntityRevisions as s}from"../revisions/list.js";import{selectEntityRowForRead as c}from"../revisions/read.js";import{and as l,eq as u,inArray as d}from"drizzle-orm";function f(e){let{database:t,state:d}=e,f=typeof e.revisionAsOf==`number`?e.revisionAsOf:null,p=async n=>{if(e.onEntityRead?.(n),f!==null){let e=await c(t.db,n,f);return e?S(e):null}let i=d?.entitiesByKey.get(n);if(i)return S(i);if(d)return null;let[a]=await t.db.select(x()).from(r).where(l(u(r.key,n),u(r.isCurrent,1))).limit(1);return a?S(a):null},g=e=>i(e,e=>o(t,e)),_=async(n,i)=>{let o=d?.entitiesByKey.get(n),[s]=f===null?d&&!o?[]:await t.db.select({status:r.status,data:r.data,dataHash:r.dataHash,type:r.type,metadata:r.metadata,isCurrent:r.isCurrent}).from(r).where(l(u(r.key,n),u(r.isCurrent,1))).limit(1):[await c(t.db,n,f)??void 0];if(!s)throw e.onEntityRead?.(n),Error(`Entity "${n}" is not registered.`);let p;if(s.status===`ready`&&s.data!==null||s.isCurrent!==1)p=s.data,d&&s.isCurrent===1&&f===null&&m(d,n,s);else if(e.materialize)try{p=await e.materialize(n)}catch(t){if(e.onEntityRead?.(n,!0),!i||!(t instanceof a))throw t;return s.data===null?void 0:g(s.data)}else throw Error(`Missing precomputed entity data for "${n}". Rebuild the content entity data before starting the production runtime.`);return e.onEntityRead?.(n),g(p)};return{get:p,async listRevisions(n){for(let t of n)e.onEntityRead?.(t);return s(t.db,n)},async list(i={}){let a=(d?[...d.entitiesByKey.values()].filter(e=>y(e,i)):await t.db.select(x()).from(r).where(l(u(r.isCurrent,1),i.type===void 0?void 0:u(r.type,i.type),i.pluginId===void 0?void 0:u(r.pluginId,i.pluginId)))).map(S).sort((e,t)=>n(e.key,t.key));return e.record?.({kind:`entity-type`,argument:h(i),resultHash:v(a.map(e=>e.key))}),a},load:async e=>await _(e,!1),tryLoad:async e=>await _(e,!0)}}async function p(e,t,n){let[i]=await e.db.select({status:r.status,dataHash:r.dataHash,type:r.type,metadata:r.metadata}).from(r).where(l(u(r.key,n),u(r.isCurrent,1))).limit(1);i&&m(t,n,i)}function m(e,t,n){let r=e.entitiesByKey.get(t);r&&Object.assign(r,{status:n.status,dataHash:n.dataHash,type:n.type,metadata:n.metadata})}function h(e){return t({...e.type===void 0?{}:{type:e.type},...e.pluginId===void 0?{}:{pluginId:e.pluginId}})}function g(t,n){let r=t.entitiesByKey.get(n);return e(r?[r.id,r.kind,r.type,r.metadata,r.dataHash,r.status]:`absent`)}function _(e,t){let r=JSON.parse(t),i=[];for(let t of e.entitiesByKey.values())y(t,r)&&i.push(t.key);return v(i.sort(n))}function v(t){return e([...t])}function y(e,t){return(t.type===void 0||e.type===t.type)&&(t.pluginId===void 0||e.pluginId===t.pluginId)}async function b(e,t){return t.length===0?[]:e.db.select({key:r.key,metadata:r.metadata}).from(r).where(l(d(r.key,[...t]),u(r.isCurrent,1)))}function x(){return{id:r.id,key:r.key,kind:r.kind,type:r.type,metadata:r.metadata,pluginId:r.pluginId,loaderId:r.loaderId,loaderArgs:r.loaderArgs,status:r.status,dataHash:r.dataHash,isSystem:r.isSystem}}function S(e){return{id:e.id,key:e.key,kind:e.kind,type:e.type,metadata:e.metadata,pluginId:e.pluginId,loaderId:e.loaderId,loaderArgs:e.loaderArgs,status:e.status,dataHash:e.dataHash,isSystem:e.isSystem===!0||e.isSystem===1}}export{f as createEntityStore,_ as hashEntityListMembership,g as hashEntityRead,b as loadCurrentEntityMetadata,p as refreshStateEntity};
@@ -1 +1 @@
1
- import{batchValues as e,normalizeBatchSize as t,runWithSqliteBusyRetry as n}from"./connection.js";import{entities as r,entityDeps as i,filePlugins as a,files as o,originDeps as s,routeDeps as c,routes as l,searchDocuments as u}from"./schema.js";import{garbageCollectOrphanedEntitiesInTransaction as d}from"./invalidation.js";import{deleteProblemsForFilesTx as f}from"./problems.js";import{deleteLinkRowsForFilesTx as p}from"./link-refs.js";import{and as m,eq as h,inArray as g,sql as _}from"drizzle-orm";async function v(e){return e.db.select({hash:o.hash,id:o.id,lastModifiedAt:o.lastModifiedAt,manifestVersion:o.manifestVersion,path:o.path}).from(o).orderBy(o.path)}async function y(t,n){let r=/* @__PURE__ */ new Map;for(let i of e(n,500)){let e=await t.db.select({manifest:o.manifest,path:o.path}).from(o).where(g(o.path,i));for(let t of e)r.set(t.path,JSON.parse(t.manifest))}return r}async function b(e){let t=await e.db.select({fileId:a.fileId,filePath:o.path,pluginId:a.pluginId,pluginVersion:a.pluginVersion}).from(a).innerJoin(o,h(a.fileId,o.id)).orderBy(o.path,a.pluginId),n=/* @__PURE__ */ new Map;for(let e of t){let t=n.get(e.filePath)??[];t.push({fileId:e.fileId,pluginId:e.pluginId,pluginVersion:e.pluginVersion}),n.set(e.filePath,t)}return n}async function x(e){let[t,n,r,i]=await Promise.all([v(e),e.db.select({metadata:l.metadata,originFileId:l.sourceId,originFilePath:o.path,originPluginId:l.pluginId,routeId:l.routeId,sidebarSubtreeEntityKey:l.sidebarSubtreeEntityKey,wildcardPrefix:l.wildcardPrefix,slug:l.slug,requestedSlug:l.requestedSlug,slugType:l.slugType,template:l.template,versionGroup:l.versionGroup,version:l.version,locale:l.locale,isFallback:l.isFallback,canonicalSlug:l.canonicalSlug}).from(l).leftJoin(o,h(l.sourceId,o.id)).orderBy(o.path,l.pluginId,l.routeId),S(e),b(e)]);return{entities:r,filePluginsByPath:i,files:t,routes:n}}async function S(e,t){return e.db.select({id:r.id,isSystem:r.isSystem,key:r.key,kind:r.kind,type:r.type,metadata:r.metadata,dataHash:r.dataHash,loaderArgs:r.loaderArgs,loaderId:r.loaderId,pluginId:r.pluginId,status:r.status}).from(r).where(t===void 0?h(r.isCurrent,1):m(g(r.key,[...t]),h(r.isCurrent,1))).orderBy(r.key)}async function C(r,u){let m=t(u.batchSize);return u.upserts.length===0&&u.removedPaths.length===0?[]:n(()=>r.db.transaction(async t=>{let n=[];for(let r of e(u.upserts,m)){let e=await t.insert(o).values(r).onConflictDoUpdate({target:o.path,set:{hash:_.raw(`excluded.hash`),manifest:_.raw(`excluded.manifest`),manifestVersion:_.raw(`excluded.manifest_v`),lastModifiedAt:_.raw(`excluded.last_modified_at`)}}).returning({id:o.id,path:o.path,hash:o.hash,lastModifiedAt:o.lastModifiedAt,manifestVersion:o.manifestVersion});n.push(...e)}if(u.removedPaths.length>0){let n=(await t.select({id:o.id}).from(o).where(g(o.path,u.removedPaths))).map(e=>e.id);if(n.length>0){for(let r of e(n,m))await t.delete(i).where(g(i.originFileId,r)),await t.delete(s).where(g(s.originFileId,r)),await t.delete(c).where(g(c.originFileId,r)),await t.delete(l).where(g(l.sourceId,r)),await t.delete(a).where(g(a.fileId,r)),await f(t,r,m),await p(t,r,m);for(let r of e(n,m))await t.delete(o).where(g(o.id,r));await d(t)}}return n}),{logger:u.logger,operation:`persist content file state`})}async function w(e,t,r){t.length!==0&&await n(()=>e.db.transaction(async e=>{for(let n of t)await e.update(o).set({lastModifiedAt:n.lastModifiedAt}).where(h(o.path,n.path))}),{logger:r,operation:`refresh file last-modified`})}async function T(e){let[t,n]=await Promise.all([e.db.select({filePath:o.path,slug:l.slug,metadata:l.metadata}).from(l).innerJoin(o,h(l.sourceId,o.id)),e.db.select({slug:u.routeSlug,title:u.title}).from(u).where(g(u.docKey,[`page`,`overview`]))]),r=new Map(n.map(e=>[e.slug,e.title])),i=/* @__PURE__ */ new Map;for(let{filePath:e,slug:n,metadata:a}of t){let t=i.get(e);if(t!==void 0&&t.slug.length<=n.length)continue;let o=r.get(n)||a.title;i.set(e,typeof o==`string`&&o?{slug:n,title:o}:{slug:n})}return i}export{T as listRoutePagesByFile,y as loadFileManifestsByPaths,S as loadPersistedContentStateEntities,x as loadPersistedContentStateSummary,v as loadStoredContentFiles,C as persistContentFileState,w as refreshFileLastModified};
1
+ import{entities as e,entityDeps as t,filePlugins as n,files as r,originDeps as i,routeDeps as a,routes as o,searchDocuments as s}from"./schema.js";import{batchValues as c,normalizeBatchSize as l,runWithSqliteBusyRetry as u}from"./connection.js";import{garbageCollectOrphanedEntitiesInTransaction as d}from"./invalidation.js";import{deleteProblemsForFilesTx as f}from"./problems.js";import{deleteLinkRowsForFilesTx as p}from"./link-refs.js";import{and as m,eq as h,inArray as g,sql as _}from"drizzle-orm";async function v(e){return e.db.select({hash:r.hash,id:r.id,lastModifiedAt:r.lastModifiedAt,manifestVersion:r.manifestVersion,path:r.path}).from(r).orderBy(r.path)}async function y(e,t){let n=/* @__PURE__ */ new Map;for(let i of c(t,500)){let t=await e.db.select({manifest:r.manifest,path:r.path}).from(r).where(g(r.path,i));for(let e of t)n.set(e.path,JSON.parse(e.manifest))}return n}async function b(e){let t=await e.db.select({fileId:n.fileId,filePath:r.path,pluginId:n.pluginId,pluginVersion:n.pluginVersion}).from(n).innerJoin(r,h(n.fileId,r.id)).orderBy(r.path,n.pluginId),i=/* @__PURE__ */ new Map;for(let e of t){let t=i.get(e.filePath)??[];t.push({fileId:e.fileId,pluginId:e.pluginId,pluginVersion:e.pluginVersion}),i.set(e.filePath,t)}return i}async function x(e){let[t,n,i,a]=await Promise.all([v(e),e.db.select({metadata:o.metadata,originFileId:o.sourceId,originFilePath:r.path,originPluginId:o.pluginId,routeId:o.routeId,sidebarSubtreeEntityKey:o.sidebarSubtreeEntityKey,wildcardPrefix:o.wildcardPrefix,slug:o.slug,requestedSlug:o.requestedSlug,slugType:o.slugType,template:o.template,versionGroup:o.versionGroup,version:o.version,locale:o.locale,isFallback:o.isFallback,canonicalSlug:o.canonicalSlug}).from(o).leftJoin(r,h(o.sourceId,r.id)).orderBy(r.path,o.pluginId,o.routeId),S(e),b(e)]);return{entities:i,filePluginsByPath:a,files:t,routes:n}}async function S(t,n){return t.db.select({id:e.id,isSystem:e.isSystem,key:e.key,kind:e.kind,type:e.type,metadata:e.metadata,dataHash:e.dataHash,loaderArgs:e.loaderArgs,loaderId:e.loaderId,pluginId:e.pluginId,status:e.status}).from(e).where(n===void 0?h(e.isCurrent,1):m(g(e.key,[...n]),h(e.isCurrent,1))).orderBy(e.key)}async function C(e,s){let m=l(s.batchSize);return s.upserts.length===0&&s.removedPaths.length===0?[]:u(()=>e.db.transaction(async e=>{let l=[];for(let t of c(s.upserts,m)){let n=await e.insert(r).values(t).onConflictDoUpdate({target:r.path,set:{hash:_.raw(`excluded.hash`),manifest:_.raw(`excluded.manifest`),manifestVersion:_.raw(`excluded.manifest_v`),lastModifiedAt:_.raw(`excluded.last_modified_at`)}}).returning({id:r.id,path:r.path,hash:r.hash,lastModifiedAt:r.lastModifiedAt,manifestVersion:r.manifestVersion});l.push(...n)}if(s.removedPaths.length>0){let l=(await e.select({id:r.id}).from(r).where(g(r.path,s.removedPaths))).map(e=>e.id);if(l.length>0){for(let r of c(l,m))await e.delete(t).where(g(t.originFileId,r)),await e.delete(i).where(g(i.originFileId,r)),await e.delete(a).where(g(a.originFileId,r)),await e.delete(o).where(g(o.sourceId,r)),await e.delete(n).where(g(n.fileId,r)),await f(e,r,m),await p(e,r,m);for(let t of c(l,m))await e.delete(r).where(g(r.id,t));await d(e)}}return l}),{logger:s.logger,operation:`persist content file state`})}async function w(e,t,n){t.length!==0&&await u(()=>e.db.transaction(async e=>{for(let n of t)await e.update(r).set({lastModifiedAt:n.lastModifiedAt}).where(h(r.path,n.path))}),{logger:n,operation:`refresh file last-modified`})}async function T(e){let[t,n]=await Promise.all([e.db.select({filePath:r.path,slug:o.slug,metadata:o.metadata}).from(o).innerJoin(r,h(o.sourceId,r.id)),e.db.select({slug:s.routeSlug,title:s.title}).from(s).where(g(s.docKey,[`page`,`overview`]))]),i=new Map(n.map(e=>[e.slug,e.title])),a=/* @__PURE__ */ new Map;for(let{filePath:e,slug:n,metadata:r}of t){let t=a.get(e);if(t!==void 0&&t.slug.length<=n.length)continue;let o=i.get(n)||r.title;a.set(e,typeof o==`string`&&o?{slug:n,title:o}:{slug:n})}return a}export{T as listRoutePagesByFile,y as loadFileManifestsByPaths,S as loadPersistedContentStateEntities,x as loadPersistedContentStateSummary,v as loadStoredContentFiles,C as persistContentFileState,w as refreshFileLastModified};
@@ -1 +1 @@
1
- import{isJsonObject as e,toJsonObject as t,toStableJsonString as n}from"./utils/json.js";import{compareStrings as r}from"../../shared/utils/compare-strings.js";import{batchValues as i,normalizeBatchSize as a,runWithSqliteBusyRetry as o}from"./connection.js";import{entities as s,entityDeps as c,originDeps as l,pluginHookState as u,routeDeps as d,routeQueryDeps as f,routes as p,staticFiles as m}from"./schema.js";import{generateEntityId as h}from"./entities.js";import{deleteProblemsForPluginHookTx as g,insertProblemsTx as _,replaceGlobalProblemsForKeysTx as v}from"./problems.js";import{writePluginHookState as y}from"./plugin-hook-state.js";import{replaceRouteQueryDepsTx as b}from"./route-query-deps.js";import{upsertEntityDescriptors as x}from"./origins.js";import{inArray as S,notInArray as C,sql as w}from"drizzle-orm";async function T(e,t,n){t.length!==0&&await o(()=>e.db.transaction(async e=>{for(let n of t)await E(e,n)}),{logger:n?.logger,operation:`register system entities`})}async function E(e,t){let[r]=await e.select({id:s.id,kind:s.kind,pluginId:s.pluginId,loaderId:s.loaderId,loaderArgs:s.loaderArgs}).from(s).where(w`${s.key} = ${t.key} and ${s.isCurrent} = 1`).limit(1),i=t.fragmentUpdates?D(r?.loaderArgs??null,t.loaderArgs,t.fragmentUpdates):t.loaderArgs,a=!r||r.kind!==t.kind||r.pluginId!==t.pluginId||r.loaderId!==t.loaderId||n(r.loaderArgs??null)!==n(i??null);await e.insert(s).values({id:r?.id??h(),key:t.key,kind:t.kind,type:t.type,metadata:t.metadata,pluginId:t.pluginId,loaderId:t.loaderId,loaderArgs:i,status:`stale`,data:null,markdoc:null,isSystem:1}).onConflictDoUpdate({target:s.id,set:{kind:w.raw(`excluded.kind`),pluginId:w.raw(`excluded.plugin_id`),loaderId:w.raw(`excluded.loader_id`),loaderArgs:w.raw(`excluded.loader_args`),isSystem:w.raw(`excluded.is_system`)}}),(t.shouldInvalidateValue||a)&&await e.update(s).set({status:`stale`,invalidationSeq:w`${s.invalidationSeq} + 1`}).where(w`${s.key} = ${t.key} and ${s.isCurrent} = 1`)}function D(n,i,a){let o=e(n)&&e(n.fragments)?n.fragments:{},s={};for(let[t,n]of Object.entries(o))e(n)&&typeof n.owner==`string`&&!a.has(n.owner)&&(s[t]=n);for(let[e,t]of a)for(let[n,r]of Object.entries(t??{}))s[n]={owner:e,value:r};let c=t(Object.fromEntries(Object.keys(s).sort(r).map(e=>[e,s[e]])));return{...e(i)?i:{},fragments:c}}function O(t){let n=/* @__PURE__ */ new Set,r=e(t)&&e(t.fragments)?t.fragments:{};for(let t of Object.values(r))e(t)&&typeof t.owner==`string`&&`value`in t&&n.add(t.owner);return n}async function k(e,t){let n=a(t.batchSize);await o(()=>e.db.transaction(async e=>{await e.delete(l).where(w`${l.originPluginId} = ${t.originPluginId} and ${l.originFileId} is null and ${l.hook} = 'finalize'`);for(let r of i(t.dependencies,n))r.length!==0&&await e.insert(l).values(r.map(e=>({accessType:e.accessType,originFileId:null,originPluginId:t.originPluginId,hook:`finalize`,source:e.source,path:e.path,valueHash:e.valueHash})));await b(e,{originPluginId:t.originPluginId,hook:`finalize`,entityId:null,dependencies:t.routeQueries}),await y(e,{pluginId:t.originPluginId,hook:`finalize`,fingerprint:t.fingerprint})}),{logger:t.logger,operation:`replace finalize reads`})}async function A(e,t,n){let r=t.map(e=>`${e.hook}:${e.pluginId}`),i=e=>t.filter(t=>t.hook===e).map(e=>e.pluginId),a=i(`extractAll`),s=i(`finalize`),h=(e,t)=>C(w`${t} || ':' || ${e}`,r),g=e=>w`${e.originFileId} is null and ${e.hook} in ('extractAll', 'finalize') and ${h(e.originPluginId,e.hook)}`;return o(()=>e.db.transaction(async e=>[await e.delete(l).where(g(l)).returning({id:l.id}),await e.delete(c).where(g(c)).returning({id:c.id}),await e.delete(d).where(g(d)).returning({id:d.id}),await e.delete(f).where(w`${f.entityId} is null and ${f.hook} in ('extractAll', 'finalize') and ${h(f.originPluginId,f.hook)}`).returning({id:f.id}),await e.delete(p).where(w`${p.sourceId} is null and ${p.isFallback} = 0 and ${C(p.pluginId,a)}`).returning({id:p.id}),await e.delete(m).where(C(m.ownerPluginId,s)).returning({id:m.path}),await e.delete(u).where(h(u.pluginId,u.hook)).returning({id:u.pluginId})].some(e=>e.length>0)),{logger:n?.logger,operation:`reconcile plugin-scoped rows`})}async function j(e,t){let n=[...t],r=w`${d.originFileId} is null`;return e.db.select({routeSlug:d.routeSlug,key:d.key,originPluginId:d.originPluginId}).from(d).where(n.length===0?r:w`${r} and not (${d.hook} = 'finalize' and ${S(d.originPluginId,n)})`)}async function M(e,t){let n=a(t.batchSize);await o(()=>e.db.transaction(async e=>{await P(e,t.originPluginId),await F(e,t,n)}),{logger:t.logger,operation:`replace finalize artifacts`})}async function N(e,t){await o(()=>e.db.transaction(async e=>{await g(e,t.pluginIds,`finalize`),await _(e,t.pluginProblems),await v(e,`finalize`,t.globalKeys,t.globalProblems)}),{logger:t.logger,operation:`replace finalize problems`})}async function P(e,t){await e.delete(d).where(w`${d.originFileId} is null and ${d.originPluginId} = ${t} and ${d.hook} = 'finalize'`),await e.delete(c).where(w`${c.originFileId} is null and ${c.originPluginId} = ${t} and ${c.hook} = 'finalize'`)}async function F(e,t,n){let r=await x(e,t.entities,n);for(let r of i(t.routeDependencies,n))r.length!==0&&await e.insert(d).values(r.map(e=>({args:e.args,dependencyType:e.dependencyType,key:e.key,originFileId:null,originPluginId:t.originPluginId,hook:`finalize`,routeSlug:e.routeSlug,target:e.target}))).onConflictDoNothing();if(t.entities.length!==0)for(let n of t.entities){let i=r.get(n.key);if(!i)throw Error(`Missing entity row for key "${n.key}".`);await e.insert(c).values({dependencyRef:t.originPluginId,dependencyType:`origin`,entityId:i,originFileId:null,originPluginId:t.originPluginId,hook:`finalize`}).onConflictDoNothing()}}export{O as collectAppDataFragmentOwnerIds,j as loadPluginScopedRouteDepOwners,A as reconcilePluginScopedRows,T as registerSystemEntities,M as replaceFinalizeArtifacts,N as replaceFinalizeProblems,k as replaceFinalizeReads};
1
+ import{isJsonObject as e,toJsonObject as t,toStableJsonString as n}from"./utils/json.js";import{compareStrings as r}from"../../shared/utils/compare-strings.js";import{entities as i,entityDeps as a,originDeps as o,pluginHookState as s,routeDeps as c,routeQueryDeps as l,routes as u,staticFiles as d}from"./schema.js";import{batchValues as f,normalizeBatchSize as p,runWithSqliteBusyRetry as m}from"./connection.js";import{generateEntityId as h}from"./entities.js";import{deleteProblemsForPluginHookTx as g,insertProblemsTx as _,replaceGlobalProblemsForKeysTx as v}from"./problems.js";import{writePluginHookState as y}from"./plugin-hook-state.js";import{replaceRouteQueryDepsTx as b}from"./route-query-deps.js";import{upsertEntityDescriptors as x}from"./origins.js";import{inArray as S,notInArray as C,sql as w}from"drizzle-orm";async function T(e,t,n){t.length!==0&&await m(()=>e.db.transaction(async e=>{for(let n of t)await E(e,n)}),{logger:n?.logger,operation:`register system entities`})}async function E(e,t){let[r]=await e.select({id:i.id,kind:i.kind,pluginId:i.pluginId,loaderId:i.loaderId,loaderArgs:i.loaderArgs}).from(i).where(w`${i.key} = ${t.key} and ${i.isCurrent} = 1`).limit(1),a=t.fragmentUpdates?D(r?.loaderArgs??null,t.loaderArgs,t.fragmentUpdates):t.loaderArgs,o=!r||r.kind!==t.kind||r.pluginId!==t.pluginId||r.loaderId!==t.loaderId||n(r.loaderArgs??null)!==n(a??null);await e.insert(i).values({id:r?.id??h(),key:t.key,kind:t.kind,type:t.type,metadata:t.metadata,pluginId:t.pluginId,loaderId:t.loaderId,loaderArgs:a,status:`stale`,data:null,markdoc:null,isSystem:1}).onConflictDoUpdate({target:i.id,set:{kind:w.raw(`excluded.kind`),pluginId:w.raw(`excluded.plugin_id`),loaderId:w.raw(`excluded.loader_id`),loaderArgs:w.raw(`excluded.loader_args`),isSystem:w.raw(`excluded.is_system`)}}),(t.shouldInvalidateValue||o)&&await e.update(i).set({status:`stale`,invalidationSeq:w`${i.invalidationSeq} + 1`}).where(w`${i.key} = ${t.key} and ${i.isCurrent} = 1`)}function D(n,i,a){let o=e(n)&&e(n.fragments)?n.fragments:{},s={};for(let[t,n]of Object.entries(o))e(n)&&typeof n.owner==`string`&&!a.has(n.owner)&&(s[t]=n);for(let[e,t]of a)for(let[n,r]of Object.entries(t??{}))s[n]={owner:e,value:r};let c=t(Object.fromEntries(Object.keys(s).sort(r).map(e=>[e,s[e]])));return{...e(i)?i:{},fragments:c}}function O(t){let n=/* @__PURE__ */ new Set,r=e(t)&&e(t.fragments)?t.fragments:{};for(let t of Object.values(r))e(t)&&typeof t.owner==`string`&&`value`in t&&n.add(t.owner);return n}async function k(e,t){let n=p(t.batchSize);await m(()=>e.db.transaction(async e=>{await e.delete(o).where(w`${o.originPluginId} = ${t.originPluginId} and ${o.originFileId} is null and ${o.hook} = 'finalize'`);for(let r of f(t.dependencies,n))r.length!==0&&await e.insert(o).values(r.map(e=>({accessType:e.accessType,originFileId:null,originPluginId:t.originPluginId,hook:`finalize`,source:e.source,path:e.path,valueHash:e.valueHash})));await b(e,{originPluginId:t.originPluginId,hook:`finalize`,entityId:null,dependencies:t.routeQueries}),await y(e,{pluginId:t.originPluginId,hook:`finalize`,fingerprint:t.fingerprint})}),{logger:t.logger,operation:`replace finalize reads`})}async function A(e,t,n){let r=t.map(e=>`${e.hook}:${e.pluginId}`),i=e=>t.filter(t=>t.hook===e).map(e=>e.pluginId),f=i(`extractAll`),p=i(`finalize`),h=(e,t)=>C(w`${t} || ':' || ${e}`,r),g=e=>w`${e.originFileId} is null and ${e.hook} in ('extractAll', 'finalize') and ${h(e.originPluginId,e.hook)}`;return m(()=>e.db.transaction(async e=>[await e.delete(o).where(g(o)).returning({id:o.id}),await e.delete(a).where(g(a)).returning({id:a.id}),await e.delete(c).where(g(c)).returning({id:c.id}),await e.delete(l).where(w`${l.entityId} is null and ${l.hook} in ('extractAll', 'finalize') and ${h(l.originPluginId,l.hook)}`).returning({id:l.id}),await e.delete(u).where(w`${u.sourceId} is null and ${u.isFallback} = 0 and ${C(u.pluginId,f)}`).returning({id:u.id}),await e.delete(d).where(C(d.ownerPluginId,p)).returning({id:d.path}),await e.delete(s).where(h(s.pluginId,s.hook)).returning({id:s.pluginId})].some(e=>e.length>0)),{logger:n?.logger,operation:`reconcile plugin-scoped rows`})}async function j(e,t){let n=[...t],r=w`${c.originFileId} is null`;return e.db.select({routeSlug:c.routeSlug,key:c.key,originPluginId:c.originPluginId}).from(c).where(n.length===0?r:w`${r} and not (${c.hook} = 'finalize' and ${S(c.originPluginId,n)})`)}async function M(e,t){let n=p(t.batchSize);await m(()=>e.db.transaction(async e=>{await P(e,t.originPluginId),await F(e,t,n)}),{logger:t.logger,operation:`replace finalize artifacts`})}async function N(e,t){await m(()=>e.db.transaction(async e=>{await g(e,t.pluginIds,`finalize`),await _(e,t.pluginProblems),await v(e,`finalize`,t.globalKeys,t.globalProblems)}),{logger:t.logger,operation:`replace finalize problems`})}async function P(e,t){await e.delete(c).where(w`${c.originFileId} is null and ${c.originPluginId} = ${t} and ${c.hook} = 'finalize'`),await e.delete(a).where(w`${a.originFileId} is null and ${a.originPluginId} = ${t} and ${a.hook} = 'finalize'`)}async function F(e,t,n){let r=await x(e,t.entities,n);for(let r of f(t.routeDependencies,n))r.length!==0&&await e.insert(c).values(r.map(e=>({args:e.args,dependencyType:e.dependencyType,key:e.key,originFileId:null,originPluginId:t.originPluginId,hook:`finalize`,routeSlug:e.routeSlug,target:e.target}))).onConflictDoNothing();if(t.entities.length!==0)for(let n of t.entities){let i=r.get(n.key);if(!i)throw Error(`Missing entity row for key "${n.key}".`);await e.insert(a).values({dependencyRef:t.originPluginId,dependencyType:`origin`,entityId:i,originFileId:null,originPluginId:t.originPluginId,hook:`finalize`}).onConflictDoNothing()}}export{O as collectAppDataFragmentOwnerIds,j as loadPluginScopedRouteDepOwners,A as reconcilePluginScopedRows,T as registerSystemEntities,M as replaceFinalizeArtifacts,N as replaceFinalizeProblems,k as replaceFinalizeReads};
@@ -1,27 +1,27 @@
1
- import{APP_DATA_ENTITY_KEY as e}from"../../shared/constants/app-data.js";import{delocalizeL10nPath as t}from"../../shared/utils/l10n.js";import{runWithSqliteBusyRetry as n}from"./connection.js";import{assetRefs as r,entities as i,entityDeps as a,files as o,linkRefs as s,loaderConfigDeps as c,originDeps as l,pageMarkdown as u,problems as d,searchDocuments as f,searchFragmentParents as p,searchFragmentPostings as m,searchFragmentUsages as h,searchFragments as g,searchPostings as _}from"./schema.js";import{hashContentConfigDependency as v}from"../config-deps.js";import{refreshTermDocCounts as y,selectTermIdsOfDocuments as b,selectTermIdsOfFragments as x}from"./search-vocab.js";import{RETRYABLE_PROBLEM_CODES as S}from"../problems/codes.js";import{createRouteQueryEvaluator as C,isRouteQueryStale as w}from"../plugins/utils/route-index.js";import{compileGlob as T,hashGlobMatches as E,matchGlob as D}from"../plugins/utils/glob.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:l.accessType,originFileId:l.originFileId,originFilePath:o.path,originPluginId:l.originPluginId,hook:l.hook,path:l.path,source:l.source,valueHash:l.valueHash}).from(l).leftJoin(o,k(l.originFileId,o.id)).orderBy(o.path,l.originPluginId,l.path,l.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 E(D(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=v(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 n=await e.db.select({accessType:c.accessType,path:c.path,key:i.key,valueHash:c.valueHash}).from(c).innerJoin(i,k(c.entityId,i.id)).orderBy(i.key,c.path,c.accessType),r=/* @__PURE__ */ new Set;for(let e of n)v(t.config,e)!==e.valueHash&&r.add(e.key);let a=await U(e,{logger:t.logger,reason:`config dependency invalidation`,keys:[...r]});return a.invalidatedKeys.length>0&&t.logger?.debug(`Propagated config dependency invalidation`,{invalidatedKeys:a.invalidatedKeys.length}),a}async function B(e,t={}){let n=await e.db.selectDistinct({key:i.key}).from(d).innerJoin(i,k(d.entityId,i.id)).where(O(k(d.scope,`entity`),A(d.code,[...S]),k(i.isCurrent,1)));return U(e,{logger:t.logger,reason:`retryable problem invalidation`,keys:n.map(e=>e.key)})}async function V(e,t){let n=C(t.state,t.config).memoized(),r=/* @__PURE__ */ new Set;for(let e of t.rows)e.entityId===null||e.hook===`searchable`||r.has(e.entityId)||w(n,e)&&r.add(e.entityId);if(r.size===0)return{invalidatedKeys:[]};let a=await e.db.select({key:i.key}).from(i).where(A(i.id,[...r]));return U(e,{logger:t.logger,reason:`route query invalidation`,keys:a.map(e=>e.key)})}async function H(e,n){if(n.changedFilePaths.length===0)return{invalidatedKeys:[]};let o=/* @__PURE__ */ new Set,s=await e.db.select({key:i.key}).from(i).innerJoin(a,k(a.entityId,i.id)).where(j`${a.dependencyType} in ('file','origin') and ${a.dependencyRef} in ${n.changedFilePaths}`);for(let e of s)o.has(e.key)||o.add(e.key);let c=[...new Set(n.changedFilePaths.map(t).filter(e=>e!==void 0))];if(c.length>0){let t=await e.db.select({key:i.key}).from(i).innerJoin(r,k(r.entityId,i.id)).where(A(r.path,c));for(let e of t)o.add(e.key)}let l=n.membershipChangedPaths??[];if(l.length>0){let t=await e.db.select({key:i.key,pattern:a.dependencyRef}).from(i).innerJoin(a,k(a.entityId,i.id)).where(k(a.dependencyType,`glob`));for(let e of t){let t=T(e.pattern);l.some(t)&&o.add(e.key)}}let u=await U(e,{logger:n.logger,reason:`file dependency invalidation`,keys:[...o]});return u.invalidatedKeys.length>0&&n.logger?.debug(`Propagated entity invalidation`,{changedFilePaths:n.changedFilePaths.length,invalidatedKeys:u.invalidatedKeys.length}),u}async function U(e,t){let r=new Set(t.keys),o=new Set(r),s=[...r];for(;s.length>0;){let t=s;s=[];let n=await e.db.select({key:i.key}).from(i).innerJoin(a,k(a.entityId,i.id)).where(j`${a.dependencyType} = 'entity' and ${a.dependencyRef} in ${t}`);for(let e of n)o.has(e.key)||(o.add(e.key),s.push(e.key))}let c=t.markKeys===!1?[...o].filter(e=>!r.has(e)):[...o];return c.length===0?{invalidatedKeys:[]}:(await n(()=>e.db.update(i).set({status:`stale`,invalidationSeq:j`${i.invalidationSeq} + 1`}).where(O(A(i.key,c),k(i.isCurrent,1))),{logger:t.logger,operation:t.reason}),{invalidatedKeys:c})}async function W(e,t){return n(()=>e.db.transaction(e=>G(e)),{logger:t,operation:`garbage collect orphaned entities`})}async function G(t){let n=j`(${i.isSystem} = 0 or ${i.key} <> ${e}) and ${i.isCurrent} = 1 and not exists (
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 ${a}
4
- where ${a.entityId} = ${i.id}
5
- and ${a.dependencyType} = 'origin'
6
- )`,[r]=await t.select({id:i.id}).from(i).where(n).limit(1);return r!==void 0&&await K(t,n),await t.delete(i).where(j`${i.isCurrent} = 0 and not exists (
7
- select 1 from ${i} as live
8
- where live.key = ${i.key} and live.is_current = 1
9
- )`),{removedOrphans:r!==void 0}}async function K(e,t){await e.delete(c).where(j`${c.entityId} in (
10
- select ${i.id} from ${i} where ${t}
11
- )`);let n=j`select ${f.id} from ${f}
12
- where ${f.entityKey} in (
13
- select ${i.key} from ${i} where ${t}
14
- )`,r=j`select ${g.id} from ${g}
15
- where ${g.entityKey} in (
16
- select ${i.key} from ${i} where ${t}
17
- )`,a=[...await b(e,n),...await x(e,r)];await e.delete(_).where(j`${_.docId} in (${n})`),await e.delete(m).where(j`${m.fragmentId} in (${r})`),await e.delete(p).where(j`${p.docId} in (${n})`),await e.delete(h).where(j`${h.fragmentId} in (${r})`),await e.delete(g).where(j`${g.id} in (${r})`),await y(e,a),await e.delete(f).where(j`${f.entityKey} in (
18
- select ${i.key} from ${i} where ${t}
19
- )`),await e.delete(u).where(j`${u.entityKey} in (
20
- select ${i.key} from ${i} where ${t}
21
- )`),await e.delete(d).where(j`${d.scope} = 'entity' and ${d.entityId} in (
22
- select ${i.id} from ${i} where ${t}
23
- )`);let o=j`${s.entityId} in (
24
- select ${i.id} from ${i} where ${t}
25
- )`;await e.delete(d).where(j`${d.scope} = 'link' and ${d.linkRefId} in (
26
- select ${s.id} from ${s} where ${o}
27
- )`),await e.delete(s).where(o),await e.delete(i).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};
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{batchValues as e}from"./connection.js";import{linkRefs as t,targetInventories as n}from"./schema.js";import{deleteProblemsForLinkRefsTx as r}from"./problems.js";import{and as i,eq as a,inArray as o,isNull as s}from"drizzle-orm";async function c(e,n,r=500){await d(e,(await e.select({id:t.id}).from(t).where(a(t.entityId,n.entityId))).map(e=>e.id),n.drafts,e=>({entityId:n.entityId,originFileId:n.originFileId,originPluginId:n.originPluginId,filePath:e.filePath??n.filePath,kind:e.kind,raw:e.raw,targetKind:e.targetKind,target:e.target,fragment:e.fragment,title:e.title??null,range:e.range??null,data:e.data??null}),r)}async function l(e,n,r=500){await d(e,(await e.select({id:t.id}).from(t).where(i(a(t.originPluginId,n.originPluginId),s(t.entityId)))).map(e=>e.id),n.drafts,e=>({entityId:null,originFileId:null,originPluginId:n.originPluginId,filePath:e.filePath??n.filePath,kind:e.kind,raw:e.raw,targetKind:e.targetKind,target:e.target,fragment:e.fragment,title:e.title??null,range:e.range??null,data:e.data??null}),r)}async function u(e,n){let[r]=await e.db.select({id:t.id}).from(t).where(i(a(t.originPluginId,n),s(t.entityId))).limit(1);return r!==void 0}async function d(n,i,a,s,c){i.length>0&&(await r(n,i,c),await n.delete(t).where(o(t.id,i)));for(let r of e(a,c))await n.insert(t).values(r.map(s))}async function f(e,t){await e.delete(n).where(i(a(n.fileId,t.fileId),a(n.originPluginId,t.originPluginId),a(n.kind,t.draft.kind))),(t.draft.kind!==`subpath`||t.draft.targets.length!==0)&&await e.insert(n).values({fileId:t.fileId,originPluginId:t.originPluginId,kind:t.draft.kind,exhaustive:t.draft.exhaustive,targets:t.draft.targets})}async function p(t,r,i=500){for(let a of e(r,i))await t.delete(n).where(o(n.fileId,a));await m(t,r,i)}async function m(n,a,c=500){for(let l of e(a,c)){let e=await n.select({id:t.id}).from(t).where(i(o(t.originFileId,l),s(t.entityId)));if(e.length===0)continue;let a=e.map(e=>e.id);await r(n,a,c),await n.delete(t).where(o(t.id,a))}}export{p as deleteLinkRowsForFilesTx,m as deleteOriginLinkRefsForFilesTx,u as hasPluginLinkRefs,c as replaceLinkRefsForEntityTx,l as replacePluginLinkRefsTx,f as upsertTargetInventoryTx};
1
+ import{linkRefs as e,targetInventories as t}from"./schema.js";import{batchValues as n}from"./connection.js";import{deleteProblemsForLinkRefsTx as r}from"./problems.js";import{and as i,eq as a,inArray as o,isNull as s}from"drizzle-orm";async function c(t,n,r=500){await d(t,(await t.select({id:e.id}).from(e).where(a(e.entityId,n.entityId))).map(e=>e.id),n.drafts,e=>({entityId:n.entityId,originFileId:n.originFileId,originPluginId:n.originPluginId,filePath:e.filePath??n.filePath,kind:e.kind,raw:e.raw,targetKind:e.targetKind,target:e.target,fragment:e.fragment,title:e.title??null,range:e.range??null,data:e.data??null}),r)}async function l(t,n,r=500){await d(t,(await t.select({id:e.id}).from(e).where(i(a(e.originPluginId,n.originPluginId),s(e.entityId)))).map(e=>e.id),n.drafts,e=>({entityId:null,originFileId:null,originPluginId:n.originPluginId,filePath:e.filePath??n.filePath,kind:e.kind,raw:e.raw,targetKind:e.targetKind,target:e.target,fragment:e.fragment,title:e.title??null,range:e.range??null,data:e.data??null}),r)}async function u(t,n){let[r]=await t.db.select({id:e.id}).from(e).where(i(a(e.originPluginId,n),s(e.entityId))).limit(1);return r!==void 0}async function d(t,i,a,s,c){i.length>0&&(await r(t,i,c),await t.delete(e).where(o(e.id,i)));for(let r of n(a,c))await t.insert(e).values(r.map(s))}async function f(e,n){await e.delete(t).where(i(a(t.fileId,n.fileId),a(t.originPluginId,n.originPluginId),a(t.kind,n.draft.kind))),(n.draft.kind!==`subpath`||n.draft.targets.length!==0)&&await e.insert(t).values({fileId:n.fileId,originPluginId:n.originPluginId,kind:n.draft.kind,exhaustive:n.draft.exhaustive,targets:n.draft.targets})}async function p(e,r,i=500){for(let a of n(r,i))await e.delete(t).where(o(t.fileId,a));await m(e,r,i)}async function m(t,a,c=500){for(let l of n(a,c)){let n=await t.select({id:e.id}).from(e).where(i(o(e.originFileId,l),s(e.entityId)));if(n.length===0)continue;let a=n.map(e=>e.id);await r(t,a,c),await t.delete(e).where(o(e.id,a))}}export{p as deleteLinkRowsForFilesTx,m as deleteOriginLinkRefsForFilesTx,u as hasPluginLinkRefs,c as replaceLinkRefsForEntityTx,l as replacePluginLinkRefsTx,f as upsertTargetInventoryTx};
@@ -12,7 +12,8 @@ export type EntityRuntimeDep = EntityInvalidationDep | {
12
12
  /**
13
13
  * Replaces an entity's runtime (`file`/`entity`/`glob`) deps, reusing its `origin`
14
14
  * dep row's file id. A system entity has no origin dep by construction, so its
15
- * rows persist file-anchor-free (NULL origin file id, plugin-scoped).
15
+ * rows persist file-anchor-free (NULL origin file id, plugin-scoped). Writes nothing
16
+ * when the entity already has exactly these deps.
16
17
  */
17
18
  export declare function replaceEntityRuntimeDeps(tx: DatabaseTransaction, options: {
18
19
  entityId: string;
@@ -1 +1 @@
1
- import{hashJsonValue as e}from"./utils/json.js";import{batchValues as t,normalizeBatchSize as n,runWithSqliteBusyRetry as r}from"./connection.js";import{entities as i,entityDeps as a,filePlugins as o,linkRefs as s,originDeps as c,routeDeps as l,routes as u}from"./schema.js";import{generateEntityId as d}from"./entities.js";import{garbageCollectOrphanedEntitiesInTransaction as f}from"./invalidation.js";import{deleteProblemsForFilesTx as p,deleteProblemsForPluginHookTx as m,insertProblemsTx as h,problemRow as g,replaceGlobalProblemsForKeysTx as _}from"./problems.js";import{deleteOriginLinkRefsForFilesTx as v}from"./link-refs.js";import{detectMarkdocPayloadFlag as y}from"../markdown/server/render.js";import{cutEntityRevisionTx as b}from"../revisions/cut.js";import{writePluginHookState as x}from"./plugin-hook-state.js";import{replaceRouteQueryDepsTx as S}from"./route-query-deps.js";import{and as C,eq as w,inArray as T,sql as E}from"drizzle-orm";async function D(e,n){let[r]=await e.select({originFileId:a.originFileId}).from(a).where(E`${a.entityId} = ${n.entityId} and ${a.dependencyType} = 'origin'`).limit(1);if(await e.delete(a).where(E`${a.entityId} = ${n.entityId} and ${a.dependencyType} in ('file','entity','glob')`),n.deps.length===0)return;if(!r&&!n.isSystem)throw Error(`replaceEntityRuntimeDeps: entity ${n.entityId} has no origin dep row.`);let i=/* @__PURE__ */ new Set,o=[];for(let e of n.deps){let t=e.kind===`file`?e.path:e.kind===`glob`?e.pattern:e.key,a=`${e.kind} ${t}`;i.has(a)||(i.add(a),o.push({entityId:n.entityId,originFileId:r?.originFileId??null,originPluginId:n.originPluginId,hook:`loader`,dependencyType:e.kind,dependencyRef:t}))}for(let n of t(o,500))await e.insert(a).values(n)}async function O(e,t,i){let d=i?.extractAllOrigins??[],p=i?.extractAllFailures??[],m=i?.globalProblems,v=i?.fallbackRoutes,y=(v?.removedSlugs.length??0)+(v?.added.length??0);if(t.length===0&&d.length===0&&p.length===0&&m===void 0&&y===0)return;let b=n(i?.batchSize);await r(()=>e.db.transaction(async e=>{await k(e,{fileIds:t.map(e=>e.fileId),extractAllOrigins:d,extractAllFailures:p,fallbackRoutes:v,batchSize:b}),await F(A(t),b,t=>e.insert(o).values(t));let n=j(t,d,v);await F(n.routes,b,t=>e.insert(u).values(t)),await F(n.routeDeps,b,t=>e.insert(l).values(t));let r=await I(e,n.entityDescriptors,b,i?.revisions);await F(n.originDeps,b,t=>e.insert(c).values(t)),await F(n.linkRefs,b,t=>e.insert(s).values(t));let y=[...n.problems,...p.map(e=>g(e.problem,{scope:`origin`,originFileId:null,originPluginId:e.pluginId,hook:`extractAll`}))];await h(e,y,b),m&&await _(e,m.source,m.keys,m.newProblems),n.entityDescriptors.length>0&&await F(P(n.entityOrigins,r),b,t=>e.insert(a).values(t));for(let t of d)await S(e,{originPluginId:t.originPluginId,hook:`extractAll`,entityId:null,dependencies:t.routeQueries}),await x(e,{pluginId:t.originPluginId,hook:`extractAll`,fingerprint:t.fingerprint});await f(e)}),{logger:i?.logger,operation:`bulk sync origins`})}async function k(e,n){for(let r of t(n.fileIds,n.batchSize))await e.delete(o).where(T(o.fileId,r)),await e.delete(l).where(T(l.originFileId,r)),await e.delete(u).where(T(u.sourceId,r)),await e.delete(a).where(T(a.originFileId,r)),await e.delete(c).where(T(c.originFileId,r));await p(e,n.fileIds,n.batchSize),await v(e,n.fileIds,n.batchSize),await m(e,[...n.extractAllOrigins.map(e=>e.originPluginId),...n.extractAllFailures.map(e=>e.pluginId)],`extractAll`);let r=n.extractAllOrigins.map(e=>e.originPluginId);for(let i of t(r,n.batchSize))await e.delete(l).where(E`${l.originFileId} is null and ${l.hook} = 'extractAll' and ${T(l.originPluginId,i)}`),await e.delete(u).where(E`${u.sourceId} is null and ${T(u.pluginId,i)}`),await e.delete(a).where(E`${a.originFileId} is null and ${a.hook} = 'extractAll' and ${T(a.originPluginId,i)}`),await e.delete(c).where(E`${c.originFileId} is null and ${c.hook} = 'extractAll' and ${T(c.originPluginId,i)}`);if(n.fallbackRoutes){let{pluginId:r,removedSlugs:i,added:a}=n.fallbackRoutes,o=[.../* @__PURE__ */ new Set([...i,...a.map(e=>e.slug)])];for(let i of t(o,n.batchSize))await e.delete(u).where(E`${u.sourceId} is null and ${u.pluginId} = ${r} and ${T(u.slug,i)}`)}}function A(e){let t=[];for(let n of e)for(let e of n.plugins)t.push({fileId:n.fileId,pluginId:e.id,pluginVersion:e.version});return t}function j(e,t,n){let r={routes:[],routeDeps:[],originDeps:[],entityDescriptors:[],entityOrigins:[],problems:[],linkRefs:[]};for(let t of e)for(let e of t.origins)N(e,r);for(let e of t)N(e,r);for(let e of n?.added??[])r.routes.push(M(e,null));return r}function M(e,t){return{metadata:e.metadata,pluginId:e.pluginId,routeId:e.routeId,sidebarSubtreeEntityKey:e.sidebarSubtreeEntityKey,wildcardPrefix:e.wildcardPrefix??!1,slug:e.slug,requestedSlug:e.requestedSlug,slugType:e.slugType,sourceId:t,template:e.template,versionGroup:e.versionGroup,version:e.version,locale:e.locale,isFallback:e.isFallback,canonicalSlug:e.canonicalSlug}}function N(e,t){for(let n of e.routes)t.routes.push(M(n,e.originFileId));for(let n of e.routeDependencies)t.routeDeps.push({args:n.args,dependencyType:n.dependencyType,key:n.key,originFileId:e.originFileId,originPluginId:e.originPluginId,hook:e.hook,routeSlug:n.routeSlug,target:n.target});for(let n of e.originDependencies)t.originDeps.push({accessType:n.accessType,originFileId:e.originFileId,originPluginId:e.originPluginId,hook:e.hook,source:n.source,path:n.path,valueHash:n.valueHash});for(let n of e.problems)t.problems.push(g(n,{scope:`origin`,originFileId:e.originFileId,originPluginId:e.originPluginId,hook:e.hook}));e.entities.length>0&&(t.entityDescriptors.push(...e.entities),t.entityOrigins.push({originFileId:e.originFileId,originFilePath:e.originFilePath,originPluginId:e.originPluginId,hook:e.hook,descriptors:e.entities}));for(let n of e.linkRefs??[]){let r=n.filePath??e.originFilePath;r!==null&&t.linkRefs.push({entityId:null,originFileId:e.originFileId,originPluginId:e.originPluginId,filePath:r,kind:n.kind,raw:n.raw,targetKind:n.targetKind,target:n.target,fragment:n.fragment,title:n.title??null,range:n.range??null})}}function P(e,t){let n=[];for(let r of e)for(let e of r.descriptors){let i=t.get(e.key);if(!i)throw Error(`bulkSyncOrigins: missing entity id for key "${e.key}" after upsert.`);n.push({dependencyRef:r.originFilePath??r.originPluginId,dependencyType:`origin`,entityId:i,originFileId:r.originFileId,originPluginId:r.originPluginId,hook:r.hook})}return n}async function F(e,n,r){for(let i of t(e,n))i.length>0&&await r(i)}async function I(n,r,a=500,o){if(r.length===0)return/* @__PURE__ */ new Map;let s=/* @__PURE__ */ new Map;for(let e of r)s.set(e.key,e);let c=[...s.keys()],l=/* @__PURE__ */ new Map,u=/* @__PURE__ */ new Map;for(let e of t(c,a)){let t=await n.select({id:i.id,key:i.key,kind:i.kind,type:i.type,metadata:i.metadata,pluginId:i.pluginId,loaderId:i.loaderId,loaderArgs:i.loaderArgs,data:i.data,markdoc:i.markdoc,dataHash:i.dataHash,version:i.version,revisionCreatedAt:i.revisionCreatedAt}).from(i).where(C(T(i.key,e),w(i.isCurrent,1)));for(let e of t)l.set(e.key,e.id),u.set(e.key,e)}let f=Date.now(),p=[];for(let t of s.values()){let r=u.get(t.key),i=r?.id??d();l.set(t.key,i);let a=t.kind===`inline`?`ready`:t.shouldInvalidateValue||!r?`stale`:`ready`,s=t.kind===`inline`?t.value:null,c=s===null?null:e(s),m=r?.revisionCreatedAt??f;t.kind===`inline`&&r&&(r.dataHash??null)!==c&&(o?.trackedKeys.has(t.key)&&await b(n,{current:r,max:o.max}),m=Math.max(f,r.revisionCreatedAt+1)),p.push({id:i,key:t.key,kind:t.kind,type:t.type,metadata:t.metadata,pluginId:t.pluginId,loaderId:t.loaderId,loaderArgs:t.loaderArgs,status:a,data:s,markdoc:s===null?null:y(JSON.stringify(s)),dataHash:c,isSystem:+!!t.isSystem,version:t.version,isCurrent:1,revisionCreatedAt:m})}for(let e of t(p,a))e.length!==0&&await n.insert(i).values(e).onConflictDoUpdate({target:i.id,set:{kind:E.raw(`excluded.kind`),type:E.raw(`excluded.type`),metadata:E.raw(`CASE WHEN excluded.kind = 'inline' OR excluded.status = 'stale' THEN excluded.metadata ELSE entities.metadata END`),pluginId:E.raw(`excluded.plugin_id`),loaderId:E.raw(`excluded.loader_id`),loaderArgs:E.raw(`excluded.loader_args`),status:E.raw(`CASE WHEN excluded.kind = 'inline' OR excluded.status = 'stale' THEN excluded.status ELSE entities.status END`),data:E.raw(`CASE WHEN excluded.kind = 'inline' THEN excluded.data ELSE entities.data END`),markdoc:E.raw(`CASE WHEN excluded.kind = 'inline' THEN excluded.markdoc ELSE entities.markdoc END`),dataHash:E.raw(`CASE WHEN excluded.kind = 'inline' THEN excluded.data_hash ELSE entities.data_hash END`),isSystem:E.raw(`excluded.is_system`),version:E.raw(`excluded.version`),revisionCreatedAt:E.raw(`excluded.revision_created_at`),invalidationSeq:E`case when excluded.status = 'stale' then ${i.invalidationSeq} + 1 else ${i.invalidationSeq} end`}});return l}export{O as bulkSyncOrigins,D as replaceEntityRuntimeDeps,I as upsertEntityDescriptors};
1
+ import{hashJsonValue as e}from"./utils/json.js";import{entities as t,entityDeps as n,filePlugins as r,linkRefs as i,originDeps as a,routeDeps as o,routes as s}from"./schema.js";import{batchValues as c,normalizeBatchSize as l,runWithSqliteBusyRetry as u}from"./connection.js";import{generateEntityId as d}from"./entities.js";import{garbageCollectOrphanedEntitiesInTransaction as f}from"./invalidation.js";import{deleteProblemsForFilesTx as p,deleteProblemsForPluginHookTx as m,insertProblemsTx as h,problemRow as g,replaceGlobalProblemsForKeysTx as _}from"./problems.js";import{deleteOriginLinkRefsForFilesTx as v}from"./link-refs.js";import{detectMarkdocPayloadFlag as y}from"../markdown/server/render.js";import{cutEntityRevisionTx as b}from"../revisions/cut.js";import{writePluginHookState as x}from"./plugin-hook-state.js";import{replaceRouteQueryDepsTx as S}from"./route-query-deps.js";import{and as C,eq as w,inArray as T,sql as E}from"drizzle-orm";async function D(e,t){let[r]=await e.select({originFileId:n.originFileId}).from(n).where(E`${n.entityId} = ${t.entityId} and ${n.dependencyType} = 'origin'`).limit(1);if(t.deps.length>0&&!r&&!t.isSystem)throw Error(`replaceEntityRuntimeDeps: entity ${t.entityId} has no origin dep row.`);let i=/* @__PURE__ */ new Set,a=[];for(let e of t.deps){let n=e.kind===`file`?e.path:e.kind===`glob`?e.pattern:e.key,o=`${e.kind} ${n}`;i.has(o)||(i.add(o),a.push({entityId:t.entityId,originFileId:r?.originFileId??null,originPluginId:t.originPluginId,hook:`loader`,dependencyType:e.kind,dependencyRef:n}))}let o=E`${n.entityId} = ${t.entityId} and ${n.dependencyType} in ('file','entity','glob')`,s=await e.select({type:n.dependencyType,ref:n.dependencyRef}).from(n).where(o);if(!(s.length===a.length&&s.every(e=>i.has(`${e.type} ${e.ref}`)))){await e.delete(n).where(o);for(let t of c(a,500))await e.insert(n).values(t)}}async function O(e,t,c){let d=c?.extractAllOrigins??[],p=c?.extractAllFailures??[],m=c?.globalProblems,v=c?.fallbackRoutes,y=(v?.removedSlugs.length??0)+(v?.added.length??0);if(t.length===0&&d.length===0&&p.length===0&&m===void 0&&y===0)return;let b=l(c?.batchSize);await u(()=>e.db.transaction(async e=>{await k(e,{fileIds:t.map(e=>e.fileId),extractAllOrigins:d,extractAllFailures:p,fallbackRoutes:v,batchSize:b}),await F(A(t),b,t=>e.insert(r).values(t));let l=j(t,d,v);await F(l.routes,b,t=>e.insert(s).values(t)),await F(l.routeDeps,b,t=>e.insert(o).values(t));let u=await I(e,l.entityDescriptors,b,c?.revisions);await F(l.originDeps,b,t=>e.insert(a).values(t)),await F(l.linkRefs,b,t=>e.insert(i).values(t));let y=[...l.problems,...p.map(e=>g(e.problem,{scope:`origin`,originFileId:null,originPluginId:e.pluginId,hook:`extractAll`}))];await h(e,y,b),m&&await _(e,m.source,m.keys,m.newProblems),l.entityDescriptors.length>0&&await F(P(l.entityOrigins,u),b,t=>e.insert(n).values(t));for(let t of d)await S(e,{originPluginId:t.originPluginId,hook:`extractAll`,entityId:null,dependencies:t.routeQueries}),await x(e,{pluginId:t.originPluginId,hook:`extractAll`,fingerprint:t.fingerprint});await f(e)}),{logger:c?.logger,operation:`bulk sync origins`})}async function k(e,t){for(let i of c(t.fileIds,t.batchSize))await e.delete(r).where(T(r.fileId,i)),await e.delete(o).where(T(o.originFileId,i)),await e.delete(s).where(T(s.sourceId,i)),await e.delete(n).where(T(n.originFileId,i)),await e.delete(a).where(T(a.originFileId,i));await p(e,t.fileIds,t.batchSize),await v(e,t.fileIds,t.batchSize),await m(e,[...t.extractAllOrigins.map(e=>e.originPluginId),...t.extractAllFailures.map(e=>e.pluginId)],`extractAll`);let i=t.extractAllOrigins.map(e=>e.originPluginId);for(let r of c(i,t.batchSize))await e.delete(o).where(E`${o.originFileId} is null and ${o.hook} = 'extractAll' and ${T(o.originPluginId,r)}`),await e.delete(s).where(E`${s.sourceId} is null and ${T(s.pluginId,r)}`),await e.delete(n).where(E`${n.originFileId} is null and ${n.hook} = 'extractAll' and ${T(n.originPluginId,r)}`),await e.delete(a).where(E`${a.originFileId} is null and ${a.hook} = 'extractAll' and ${T(a.originPluginId,r)}`);if(t.fallbackRoutes){let{pluginId:n,removedSlugs:r,added:i}=t.fallbackRoutes,a=[.../* @__PURE__ */ new Set([...r,...i.map(e=>e.slug)])];for(let r of c(a,t.batchSize))await e.delete(s).where(E`${s.sourceId} is null and ${s.pluginId} = ${n} and ${T(s.slug,r)}`)}}function A(e){let t=[];for(let n of e)for(let e of n.plugins)t.push({fileId:n.fileId,pluginId:e.id,pluginVersion:e.version});return t}function j(e,t,n){let r={routes:[],routeDeps:[],originDeps:[],entityDescriptors:[],entityOrigins:[],problems:[],linkRefs:[]};for(let t of e)for(let e of t.origins)N(e,r);for(let e of t)N(e,r);for(let e of n?.added??[])r.routes.push(M(e,null));return r}function M(e,t){return{metadata:e.metadata,pluginId:e.pluginId,routeId:e.routeId,sidebarSubtreeEntityKey:e.sidebarSubtreeEntityKey,wildcardPrefix:e.wildcardPrefix??!1,slug:e.slug,requestedSlug:e.requestedSlug,slugType:e.slugType,sourceId:t,template:e.template,versionGroup:e.versionGroup,version:e.version,locale:e.locale,isFallback:e.isFallback,canonicalSlug:e.canonicalSlug}}function N(e,t){for(let n of e.routes)t.routes.push(M(n,e.originFileId));for(let n of e.routeDependencies)t.routeDeps.push({args:n.args,dependencyType:n.dependencyType,key:n.key,originFileId:e.originFileId,originPluginId:e.originPluginId,hook:e.hook,routeSlug:n.routeSlug,target:n.target});for(let n of e.originDependencies)t.originDeps.push({accessType:n.accessType,originFileId:e.originFileId,originPluginId:e.originPluginId,hook:e.hook,source:n.source,path:n.path,valueHash:n.valueHash});for(let n of e.problems)t.problems.push(g(n,{scope:`origin`,originFileId:e.originFileId,originPluginId:e.originPluginId,hook:e.hook}));e.entities.length>0&&(t.entityDescriptors.push(...e.entities),t.entityOrigins.push({originFileId:e.originFileId,originFilePath:e.originFilePath,originPluginId:e.originPluginId,hook:e.hook,descriptors:e.entities}));for(let n of e.linkRefs??[]){let r=n.filePath??e.originFilePath;r!==null&&t.linkRefs.push({entityId:null,originFileId:e.originFileId,originPluginId:e.originPluginId,filePath:r,kind:n.kind,raw:n.raw,targetKind:n.targetKind,target:n.target,fragment:n.fragment,title:n.title??null,range:n.range??null})}}function P(e,t){let n=[];for(let r of e)for(let e of r.descriptors){let i=t.get(e.key);if(!i)throw Error(`bulkSyncOrigins: missing entity id for key "${e.key}" after upsert.`);n.push({dependencyRef:r.originFilePath??r.originPluginId,dependencyType:`origin`,entityId:i,originFileId:r.originFileId,originPluginId:r.originPluginId,hook:r.hook})}return n}async function F(e,t,n){for(let r of c(e,t))r.length>0&&await n(r)}async function I(n,r,i=500,a){if(r.length===0)return/* @__PURE__ */ new Map;let o=/* @__PURE__ */ new Map;for(let e of r)o.set(e.key,e);let s=[...o.keys()],l=/* @__PURE__ */ new Map,u=/* @__PURE__ */ new Map;for(let e of c(s,i)){let r=await n.select({id:t.id,key:t.key,kind:t.kind,type:t.type,metadata:t.metadata,pluginId:t.pluginId,loaderId:t.loaderId,loaderArgs:t.loaderArgs,data:t.data,markdoc:t.markdoc,dataHash:t.dataHash,version:t.version,revisionCreatedAt:t.revisionCreatedAt}).from(t).where(C(T(t.key,e),w(t.isCurrent,1)));for(let e of r)l.set(e.key,e.id),u.set(e.key,e)}let f=Date.now(),p=[];for(let t of o.values()){let r=u.get(t.key),i=r?.id??d();l.set(t.key,i);let o=t.kind===`inline`?`ready`:t.shouldInvalidateValue||!r?`stale`:`ready`,s=t.kind===`inline`?t.value:null,c=s===null?null:e(s),m=r?.revisionCreatedAt??f;t.kind===`inline`&&r&&(r.dataHash??null)!==c&&(a?.trackedKeys.has(t.key)&&await b(n,{current:r,max:a.max}),m=Math.max(f,r.revisionCreatedAt+1)),p.push({id:i,key:t.key,kind:t.kind,type:t.type,metadata:t.metadata,pluginId:t.pluginId,loaderId:t.loaderId,loaderArgs:t.loaderArgs,status:o,data:s,markdoc:s===null?null:y(JSON.stringify(s)),dataHash:c,isSystem:+!!t.isSystem,version:t.version,isCurrent:1,revisionCreatedAt:m})}for(let e of c(p,i))e.length!==0&&await n.insert(t).values(e).onConflictDoUpdate({target:t.id,set:{kind:E.raw(`excluded.kind`),type:E.raw(`excluded.type`),metadata:E.raw(`CASE WHEN excluded.kind = 'inline' OR excluded.status = 'stale' THEN excluded.metadata ELSE entities.metadata END`),pluginId:E.raw(`excluded.plugin_id`),loaderId:E.raw(`excluded.loader_id`),loaderArgs:E.raw(`excluded.loader_args`),status:E.raw(`CASE WHEN excluded.kind = 'inline' OR excluded.status = 'stale' THEN excluded.status ELSE entities.status END`),data:E.raw(`CASE WHEN excluded.kind = 'inline' THEN excluded.data ELSE entities.data END`),markdoc:E.raw(`CASE WHEN excluded.kind = 'inline' THEN excluded.markdoc ELSE entities.markdoc END`),dataHash:E.raw(`CASE WHEN excluded.kind = 'inline' THEN excluded.data_hash ELSE entities.data_hash END`),isSystem:E.raw(`excluded.is_system`),version:E.raw(`excluded.version`),revisionCreatedAt:E.raw(`excluded.revision_created_at`),invalidationSeq:E`case when excluded.status = 'stale' then ${t.invalidationSeq} + 1 else ${t.invalidationSeq} end`}});return l}export{O as bulkSyncOrigins,D as replaceEntityRuntimeDeps,I as upsertEntityDescriptors};
@@ -1 +1 @@
1
- import{batchValues as e}from"./connection.js";import{linkRefs as t,problems as n}from"./schema.js";import{asc as r,count as i,inArray as a,notInArray as o,sql as s}from"drizzle-orm";function c(e,t){return{scope:t.scope,originFileId:t.scope===`origin`?t.originFileId:null,originPluginId:t.scope===`origin`?t.originPluginId:null,hook:t.scope===`origin`?t.hook:null,entityId:t.scope===`entity`?t.entityId:null,linkRefId:t.scope===`link`?t.linkRefId:null,source:t.scope===`global`?t.source:null,key:t.scope===`global`?t.key??null:null,code:e.code,category:e.category,severity:e.severity,message:e.message,filePath:e.location?.filePath??null,range:e.location?.range??null,snippet:e.location?.snippet??null,data:e.data??null}}async function l(t,r,i=500){for(let a of e(r,i))await t.insert(n).values(a)}async function u(t,r,i=500){for(let o of e(r,i))await t.delete(n).where(s`${n.scope} = 'origin' and ${a(n.originFileId,o)}`)}async function d(e,t,r){t.length!==0&&await e.delete(n).where(s`${n.scope} = 'origin' and ${n.originFileId} is null and ${n.hook} = ${r} and ${a(n.originPluginId,[...t])}`)}async function f(t,r,i,o=500){if(i.length!==0&&r.size!==0){for(let c of e([...r.keys()],o))await t.delete(n).where(s`${n.scope} = 'entity' and ${a(n.entityId,c)} and ${a(n.code,[...i])}`);await l(t,[...r.values()].flat(),o)}}async function p(e,t,r,i){await e.delete(n).where(r.length===0?s`${n.scope} = 'entity' and ${n.entityId} = ${t}`:s`${n.scope} = 'entity' and ${n.entityId} = ${t} and ${o(n.code,[...r])}`),await l(e,i)}async function m(e,t){let[r]=await e.db.select({id:n.id}).from(n).where(s`${n.scope} = 'global' and ${n.source} = ${t}`).limit(1);return r!==void 0}async function h(e,t,r){await e.delete(n).where(s`${n.scope} = 'global' and ${n.source} = ${t}`),await l(e,r)}async function g(e,t,r,i){r.length>0&&await e.delete(n).where(s`${n.scope} = 'global' and ${n.source} = ${t} and ${a(n.key,[...r])}`),await l(e,i)}async function _(t,r,i=500){for(let o of e(r,i))await t.delete(n).where(s`${n.scope} = 'link' and ${a(n.linkRefId,o)}`)}async function v(e){await e.delete(n).where(s`${n.scope} = 'link' and ${n.linkRefId} not in (select ${t.id} from ${t})`)}async function y(e,t,r=500){await e.delete(n).where(s`${n.scope} = 'link'`),await l(e,t,r)}async function b(e,t){return e.db.select().from(n).where(s`${n.scope} = 'global' and ${n.source} = ${t}`)}async function x(e,t){return e.db.select().from(n).where(s`${n.scope} = 'entity' and ${n.entityId} = ${t}`).orderBy(r(n.id))}async function S(e,t={}){let i=e.db.select().from(n).orderBy(r(n.filePath),r(n.linkRefId),r(n.id));return t.limit===void 0?i:i.limit(t.limit)}async function C(e){let t=await e.db.select({severity:n.severity,code:n.code,count:i()}).from(n).groupBy(n.severity,n.code),r=0,a=0,o={},s={};for(let e of t)e.severity===`error`?(r+=e.count,s[e.code]=(s[e.code]??0)+e.count):a+=e.count,o[e.code]=(o[e.code]??0)+e.count;return{errors:r,warnings:a,byCode:o,errorsByCode:s}}function w(e){let t=0,n=0;for(let r of e)r.severity===`error`?t+=1:n+=1;return{errors:t,warnings:n}}export{v as deleteOrphanedLinkProblemsTx,u as deleteProblemsForFilesTx,_ as deleteProblemsForLinkRefsTx,d as deleteProblemsForPluginHookTx,m as hasGlobalProblemsForSource,l as insertProblemsTx,b as listGlobalProblems,S as listProblems,x as listProblemsForEntity,c as problemRow,y as replaceAllLinkProblemsTx,p as replaceEntityProblemsExceptCodesTx,f as replaceEntityProblemsForCodesBatchTx,g as replaceGlobalProblemsForKeysTx,h as replaceGlobalProblemsForSourceTx,w as summarizeProblems,C as summarizeStoredProblems};
1
+ import{linkRefs as e,problems as t}from"./schema.js";import{batchValues as n}from"./connection.js";import{asc as r,count as i,inArray as a,notInArray as o,sql as s}from"drizzle-orm";function c(e,t){return{scope:t.scope,originFileId:t.scope===`origin`?t.originFileId:null,originPluginId:t.scope===`origin`?t.originPluginId:null,hook:t.scope===`origin`?t.hook:null,entityId:t.scope===`entity`?t.entityId:null,linkRefId:t.scope===`link`?t.linkRefId:null,source:t.scope===`global`?t.source:null,key:t.scope===`global`?t.key??null:null,code:e.code,category:e.category,severity:e.severity,message:e.message,filePath:e.location?.filePath??null,range:e.location?.range??null,snippet:e.location?.snippet??null,data:e.data??null}}async function l(e,r,i=500){for(let a of n(r,i))await e.insert(t).values(a)}async function u(e,r,i=500){for(let o of n(r,i))await e.delete(t).where(s`${t.scope} = 'origin' and ${a(t.originFileId,o)}`)}async function d(e,n,r){n.length!==0&&await e.delete(t).where(s`${t.scope} = 'origin' and ${t.originFileId} is null and ${t.hook} = ${r} and ${a(t.originPluginId,[...n])}`)}async function f(e,r,i,o=500){if(i.length!==0&&r.size!==0){for(let c of n([...r.keys()],o))await e.delete(t).where(s`${t.scope} = 'entity' and ${a(t.entityId,c)} and ${a(t.code,[...i])}`);await l(e,[...r.values()].flat(),o)}}async function p(e,n,r,i){await e.delete(t).where(r.length===0?s`${t.scope} = 'entity' and ${t.entityId} = ${n}`:s`${t.scope} = 'entity' and ${t.entityId} = ${n} and ${o(t.code,[...r])}`),await l(e,i)}async function m(e,n){let[r]=await e.db.select({id:t.id}).from(t).where(s`${t.scope} = 'global' and ${t.source} = ${n}`).limit(1);return r!==void 0}async function h(e,n,r){await e.delete(t).where(s`${t.scope} = 'global' and ${t.source} = ${n}`),await l(e,r)}async function g(e,n,r,i){r.length>0&&await e.delete(t).where(s`${t.scope} = 'global' and ${t.source} = ${n} and ${a(t.key,[...r])}`),await l(e,i)}async function _(e,r,i=500){for(let o of n(r,i))await e.delete(t).where(s`${t.scope} = 'link' and ${a(t.linkRefId,o)}`)}async function v(n){await n.delete(t).where(s`${t.scope} = 'link' and ${t.linkRefId} not in (select ${e.id} from ${e})`)}async function y(e,n,r=500){await e.delete(t).where(s`${t.scope} = 'link'`),await l(e,n,r)}async function b(e,n){return e.db.select().from(t).where(s`${t.scope} = 'global' and ${t.source} = ${n}`)}async function x(e,n){return e.db.select().from(t).where(s`${t.scope} = 'entity' and ${t.entityId} = ${n}`).orderBy(r(t.id))}async function S(e,n={}){let i=e.db.select().from(t).orderBy(r(t.filePath),r(t.linkRefId),r(t.id));return n.limit===void 0?i:i.limit(n.limit)}async function C(e){let n=await e.db.select({severity:t.severity,code:t.code,count:i()}).from(t).groupBy(t.severity,t.code),r=0,a=0,o={},s={};for(let e of n)e.severity===`error`?(r+=e.count,s[e.code]=(s[e.code]??0)+e.count):a+=e.count,o[e.code]=(o[e.code]??0)+e.count;return{errors:r,warnings:a,byCode:o,errorsByCode:s}}function w(e){let t=0,n=0;for(let r of e)r.severity===`error`?t+=1:n+=1;return{errors:t,warnings:n}}export{v as deleteOrphanedLinkProblemsTx,u as deleteProblemsForFilesTx,_ as deleteProblemsForLinkRefsTx,d as deleteProblemsForPluginHookTx,m as hasGlobalProblemsForSource,l as insertProblemsTx,b as listGlobalProblems,S as listProblems,x as listProblemsForEntity,c as problemRow,y as replaceAllLinkProblemsTx,p as replaceEntityProblemsExceptCodesTx,f as replaceEntityProblemsForCodesBatchTx,g as replaceGlobalProblemsForKeysTx,h as replaceGlobalProblemsForSourceTx,w as summarizeProblems,C as summarizeStoredProblems};
@@ -1 +1 @@
1
- import{runWithSqliteBusyRetry as e}from"./connection.js";import{assetRefs as t,assets as n,blobRefs as r,blobs as i,entities as a,entityDeps as o,filePlugins as s,files as c,linkCheckCheckpoint as l,linkRefs as u,loaderConfigDeps as d,originDeps as f,pageMarkdown as p,pluginHookState as m,problems as h,reactPageChecks as g,routeDeps as _,routes as v,searchDocuments as y,searchFragmentParents as b,searchFragmentPostings as x,searchFragmentUsages as S,searchFragments as C,searchPostings as w,searchVocab as T,staticFiles as E,targetInventories as D}from"./schema.js";import{ne as O}from"drizzle-orm";async function k(e){let[t]=await e.db.select({id:c.id}).from(c).where(O(c.manifestVersion,6)).limit(1);return t!==void 0}async function A(O,k){await e(()=>O.db.transaction(async e=>{await e.delete(h),await e.delete(l),await e.delete(u),await e.delete(D),await e.delete(o),await e.delete(d),await e.delete(r),await e.delete(t),await e.delete(s),await e.delete(f),await e.delete(_),await e.delete(v),await e.delete(a),await e.delete(c),await e.delete(i),await e.delete(n),await e.delete(E),await e.delete(w),await e.delete(x),await e.delete(b),await e.delete(S),await e.delete(C),await e.delete(T),await e.delete(y),await e.delete(p),await e.delete(m),await e.delete(g)}),{logger:k?.logger,operation:`reset content database`})}export{k as hasStaleManifestVersion,A as resetContentDatabase};
1
+ import{assetRefs as e,assets as t,blobRefs as n,blobs as r,entities as i,entityDeps as a,filePlugins as o,files as s,linkCheckCheckpoint as c,linkRefs as l,loaderConfigDeps as u,originDeps as d,pageMarkdown as f,pluginHookState as p,problems as m,reactPageChecks as h,routeDeps as g,routes as _,searchDocuments as v,searchFragmentParents as y,searchFragmentPostings as b,searchFragmentUsages as x,searchFragments as S,searchPostings as C,searchVocab as w,staticFiles as T,targetInventories as E}from"./schema.js";import{runWithSqliteBusyRetry as D}from"./connection.js";import{ne as O}from"drizzle-orm";async function k(e){let[t]=await e.db.select({id:s.id}).from(s).where(O(s.manifestVersion,6)).limit(1);return t!==void 0}async function A(O,k){await D(()=>O.db.transaction(async D=>{await D.delete(m),await D.delete(c),await D.delete(l),await D.delete(E),await D.delete(a),await D.delete(u),await D.delete(n),await D.delete(e),await D.delete(o),await D.delete(d),await D.delete(g),await D.delete(_),await D.delete(i),await D.delete(s),await D.delete(r),await D.delete(t),await D.delete(T),await D.delete(C),await D.delete(b),await D.delete(y),await D.delete(x),await D.delete(S),await D.delete(w),await D.delete(v),await D.delete(f),await D.delete(p),await D.delete(h)}),{logger:k?.logger,operation:`reset content database`})}export{k as hasStaleManifestVersion,A as resetContentDatabase};
@@ -7,15 +7,31 @@ export type RouteQueryDependencyRow = RouteQueryDependency & {
7
7
  hook: PluginHook;
8
8
  entityId: string | null;
9
9
  };
10
- export declare function loadRouteQueryDependencyRows(database: ContentLayerDatabase): Promise<RouteQueryDependencyRow[]>;
11
- /** Replaces the rows of one `(plugin, hook[, entity])` scope, inside the reader's own output transaction. */
10
+ /** Every stored row, with the row count and the highest id of the table when they were read. */
11
+ export type RouteQueryRowsSnapshot = {
12
+ rowCount: number;
13
+ maxId: number;
14
+ rows: readonly RouteQueryDependencyRow[];
15
+ };
16
+ /**
17
+ * Every row, both scopes. Loaded once per ingest and shared by the finalize trigger and the
18
+ * loader-entity staleness pass. Returns `previous` when the table has not changed since.
19
+ */
20
+ export declare function loadRouteQueryDependencyRows(database: ContentLayerDatabase, previous?: RouteQueryRowsSnapshot): Promise<RouteQueryRowsSnapshot>;
21
+ /**
22
+ * Replaces the rows of one `(plugin, hook[, entity])` scope, inside the reader's own output
23
+ * transaction. Writes nothing when the scope already holds exactly `dependencies`.
24
+ */
12
25
  export declare function replaceRouteQueryDepsTx(tx: DatabaseTransaction, options: {
13
26
  originPluginId: string;
14
27
  hook: PluginHook;
15
28
  entityId: string | null;
16
29
  dependencies: readonly RouteQueryDependency[];
17
30
  }): Promise<void>;
18
- /** Replaces the rows of many `(plugin, hook, entity)` scopes at once, in a few statements. */
31
+ /**
32
+ * Replaces the rows of many `(plugin, hook, entity)` scopes at once, in a few statements.
33
+ * Writes nothing for a scope that already holds exactly its `dependencies`.
34
+ */
19
35
  export declare function replaceEntityRouteQueryDepsTx(tx: DatabaseTransaction, options: {
20
36
  hook: PluginHook;
21
37
  scopes: readonly {
@@ -1 +1 @@
1
- import{batchValues as e,normalizeBatchSize as t}from"./connection.js";import{routeQueryDeps as n}from"./schema.js";import{and as r,eq as i,inArray as a,isNull as o}from"drizzle-orm";async function s(e){return e.db.select({originPluginId:n.originPluginId,hook:n.hook,entityId:n.entityId,kind:n.kind,argument:n.argument,resultHash:n.resultHash}).from(n).orderBy(n.originPluginId,n.hook,n.entityId)}async function c(a,s){await a.delete(n).where(r(i(n.originPluginId,s.originPluginId),i(n.hook,s.hook),s.entityId===null?o(n.entityId):i(n.entityId,s.entityId)));for(let r of e(s.dependencies,t(void 0)))await a.insert(n).values(r.map(e=>({originPluginId:s.originPluginId,hook:s.hook,entityId:s.entityId,kind:e.kind,argument:e.argument,resultHash:e.resultHash})))}async function l(o,s){let c=t(void 0);for(let t of e(s.scopes.map(e=>e.entityId),c))await o.delete(n).where(r(i(n.hook,s.hook),a(n.entityId,t)));let l=s.scopes.flatMap(e=>e.dependencies.map(t=>({originPluginId:e.originPluginId,hook:s.hook,entityId:e.entityId,kind:t.kind,argument:t.argument,resultHash:t.resultHash})));for(let t of e(l,c))await o.insert(n).values(t)}export{s as loadRouteQueryDependencyRows,l as replaceEntityRouteQueryDepsTx,c as replaceRouteQueryDepsTx};
1
+ import{routeQueryDeps as e}from"./schema.js";import{batchValues as t,normalizeBatchSize as n}from"./connection.js";import{and as r,count as i,eq as a,inArray as o,isNull as s,max as c}from"drizzle-orm";async function l(t,n){let[r]=await t.db.select({rowCount:i(),maxId:c(e.id)}).from(e),a=r?.rowCount??0,o=r?.maxId??0;return n!==void 0&&n.rowCount===a&&n.maxId===o?n:{rowCount:a,maxId:o,rows:await t.db.select({originPluginId:e.originPluginId,hook:e.hook,entityId:e.entityId,kind:e.kind,argument:e.argument,resultHash:e.resultHash}).from(e).orderBy(e.originPluginId,e.hook,e.entityId)}}async function u(i,o){let c=r(a(e.originPluginId,o.originPluginId),a(e.hook,o.hook),o.entityId===null?s(e.entityId):a(e.entityId,o.entityId));if(!d(await i.select({kind:e.kind,argument:e.argument,resultHash:e.resultHash}).from(e).where(c),o.dependencies)){await i.delete(e).where(c);for(let r of t(o.dependencies,n(void 0)))await i.insert(e).values(r.map(e=>({originPluginId:o.originPluginId,hook:o.hook,entityId:o.entityId,kind:e.kind,argument:e.argument,resultHash:e.resultHash})))}}function d(e,t){if(e.length!==t.length)return!1;let n=new Map(t.map(e=>[`${e.kind}\u0000${e.argument}`,e.resultHash]));return n.size===t.length&&e.every(e=>n.get(`${e.kind}\u0000${e.argument}`)===e.resultHash)}async function f(i,s){let c=n(void 0),l=t=>r(a(e.hook,s.hook),o(e.entityId,t)),u=/* @__PURE__ */ new Map;for(let n of t(s.scopes.map(e=>e.entityId),c)){let t=await i.select({entityId:e.entityId,kind:e.kind,argument:e.argument,resultHash:e.resultHash}).from(e).where(l(n));for(let{entityId:e,...n}of t){if(e===null)continue;let t=u.get(e)??[];t.push(n),u.set(e,t)}}let f=s.scopes.filter(e=>!d(u.get(e.entityId)??[],e.dependencies));for(let n of t(f.map(e=>e.entityId),c))await i.delete(e).where(l(n));let p=f.flatMap(e=>e.dependencies.map(t=>({originPluginId:e.originPluginId,hook:s.hook,entityId:e.entityId,kind:t.kind,argument:t.argument,resultHash:t.resultHash})));for(let n of t(p,c))await i.insert(e).values(n)}export{l as loadRouteQueryDependencyRows,f as replaceEntityRouteQueryDepsTx,u as replaceRouteQueryDepsTx};
@@ -1,2 +1,2 @@
1
- import{batchValues as e,normalizeBatchSize as t}from"./connection.js";import{searchFragmentPostings as n,searchPostings as r,searchVocab as i}from"./schema.js";import{and as a,eq as o,inArray as s,sql as c}from"drizzle-orm";async function l(e,t){return(await e.selectDistinct({termId:r.termId}).from(r).where(c`${r.docId} in (${t})`)).map(e=>e.termId)}async function u(e,t){return(await e.selectDistinct({termId:n.termId}).from(n).where(c`${n.fragmentId} in (${t})`)).map(e=>e.termId)}async function d(l,u){let d=[...new Set(u)];for(let u of e(d,t(void 0)))await l.update(i).set({docCount:c`(select count(distinct ${r.docId}) from ${r} where ${r.termId} = ${i.id})
2
- + (select count(*) from ${n} where ${n.termId} = ${i.id})`}).where(s(i.id,u)),await l.delete(i).where(a(s(i.id,u),o(i.docCount,0)))}export{d as refreshTermDocCounts,l as selectTermIdsOfDocuments,u as selectTermIdsOfFragments};
1
+ import{searchFragmentPostings as e,searchPostings as t,searchVocab as n}from"./schema.js";import{batchValues as r,normalizeBatchSize as i}from"./connection.js";import{and as a,eq as o,inArray as s,sql as c}from"drizzle-orm";async function l(e,n){return(await e.selectDistinct({termId:t.termId}).from(t).where(c`${t.docId} in (${n})`)).map(e=>e.termId)}async function u(t,n){return(await t.selectDistinct({termId:e.termId}).from(e).where(c`${e.fragmentId} in (${n})`)).map(e=>e.termId)}async function d(l,u){let d=[...new Set(u)];for(let u of r(d,i(void 0)))await l.update(n).set({docCount:c`(select count(distinct ${t.docId}) from ${t} where ${t.termId} = ${n.id})
2
+ + (select count(*) from ${e} where ${e.termId} = ${n.id})`}).where(s(n.id,u)),await l.delete(n).where(a(s(n.id,u),o(n.docCount,0)))}export{d as refreshTermDocCounts,l as selectTermIdsOfDocuments,u as selectTermIdsOfFragments};
@@ -1 +1 @@
1
- import{batchValues as e,normalizeBatchSize as t}from"./connection.js";import{staticFiles as n}from"./schema.js";import{replaceGlobalProblemsForKeysTx as r}from"./problems.js";import{eq as i,inArray as a}from"drizzle-orm";async function o(e){return e.db.select().from(n).orderBy(n.path)}async function s(e,t){t.length!==0&&await e.db.transaction(async e=>{for(let r of t)await e.update(n).set({hash:r.hash,size:r.size}).where(i(n.path,r.path))})}async function c(i,o){(o.ownerPluginIds.length!==0||o.problems!==void 0)&&await i.db.transaction(async i=>{if(o.ownerPluginIds.length>0){await i.delete(n).where(a(n.ownerPluginId,[...o.ownerPluginIds]));for(let r of e(o.rows,t(void 0)))r.length>0&&await i.insert(n).values(r)}o.problems&&await r(i,`static`,o.problems.keys,o.problems.newProblems)})}export{o as listStaticFileRecords,c as replaceStaticFileRows,s as updateStaticFileBodies};
1
+ import{staticFiles as e}from"./schema.js";import{batchValues as t,normalizeBatchSize as n}from"./connection.js";import{replaceGlobalProblemsForKeysTx as r}from"./problems.js";import{eq as i,inArray as a}from"drizzle-orm";async function o(t){return t.db.select().from(e).orderBy(e.path)}async function s(t,n){n.length!==0&&await t.db.transaction(async t=>{for(let r of n)await t.update(e).set({hash:r.hash,size:r.size}).where(i(e.path,r.path))})}async function c(i,o){(o.ownerPluginIds.length!==0||o.problems!==void 0)&&await i.db.transaction(async i=>{if(o.ownerPluginIds.length>0){await i.delete(e).where(a(e.ownerPluginId,[...o.ownerPluginIds]));for(let r of t(o.rows,n(void 0)))r.length>0&&await i.insert(e).values(r)}o.problems&&await r(i,`static`,o.problems.keys,o.problems.newProblems)})}export{o as listStaticFileRecords,c as replaceStaticFileRows,s as updateStaticFileBodies};
@@ -1 +1 @@
1
- import{createTrackedRedoclyConfig as e}from"../config-deps.js";import{dedupeRouteQueryDependencies as t}from"../plugins/utils/route-index.js";import{createRecordingPluginIO as n}from"../plugins/io.js";import{dedupeFileDependencies as r}from"../plugins/execute.js";import"../plugins/index.js";import{extractAllFailedProblem as i}from"../problems/producers.js";import{buildHookSourceFiles as a,createHookEntityStore as o,resolvePluginHookTriggers as s}from"./hook-inputs.js";import{routeKeepsSlug as c}from"./slugger/drop-colliding-routes.js";import{normalizePluginArtifacts as l}from"./normalize-artifacts.js";import{applyOriginRoutesToWorkingState as u,removeOriginFromWorkingState as d}from"./working-state.js";async function f(c){let f=[],p=[],m=c.materializer.state,h=c.context.pluginRegistry.listExtractAllPlugins();if(h.length===0)return{pending:f,failures:p};let g=s(`extractAll`,c.context,m,c.originRows,c.routeQueryRows,c.hookState),_=c.context.pluginRegistry.list().map(e=>e.id);for(let s of h){if(!g.shouldRun(s)||!s.content?.extractAll)continue;let h=c.logger.child(`content-layer:plugin:${s.id}`),v=e(c.context.config),y=[],b=[],x=e=>b.push(e),S=await a(g.matchedPathsOf(s),c.files,{database:c.database,workingState:m}),C;try{C=await s.content.extractAll({files:S,io:n(c.context.platform.fs,c.context.contentDir,()=>m.filesByPath.keys(),e=>y.push(e)),config:v.config,entities:o(c.database,c.materializer,x),logger:h})}catch(e){let t=e instanceof Error?e:Error(String(e));h.warn(`Content plugin extractAll failed`,{plugin:s.id,error:t.message}),p.push({pluginId:s.id,problem:i({pluginId:s.id,message:t.message})});continue}let w=l({context:c.context,filePath:null,pluginId:s.id,routeDrafts:C?.routes??[],standaloneEntities:C?.entities??[]});d(m,_,s.id,null),u(m,_,s.id,null,w.routes),f.push({pluginId:s.id,inputsHash:g.fingerprintOf(s),routes:w.routes,routeDependencies:w.routeDependencies,entities:w.entities,originDependencies:[...v.collectDependencies().map(e=>Object.assign(e,{source:`config`})),...r(y)],routeQueries:t(b)})}return{pending:f,failures:p}}function p(e,t){if(t.size!==0)for(let n of e){n.routes=n.routes.filter(e=>c(t,n.pluginId,null,e));let e=new Set(n.routes.map(e=>`${e.routeId}\u0000${e.requestedSlug}`));n.routeDependencies=n.routeDependencies.filter(t=>e.has(`${t.routeId}\u0000${t.routeSlug}`))}}export{p as dropCollidingExtractAllRoutes,f as runExtractAllPhase};
1
+ import{createRecordingPluginIO as e}from"../plugins/io.js";import{createTrackedRedoclyConfig as t}from"../config-deps.js";import{dedupeFileDependencies as n}from"../plugins/execute.js";import{dedupeRouteQueryDependencies as r}from"../plugins/utils/route-index.js";import"../plugins/index.js";import{extractAllFailedProblem as i}from"../problems/producers.js";import{buildHookSourceFiles as a,createHookEntityStore as o,resolvePluginHookTriggers as s}from"./hook-inputs.js";import{routeKeepsSlug as c}from"./slugger/drop-colliding-routes.js";import{normalizePluginArtifacts as l}from"./normalize-artifacts.js";import{applyOriginRoutesToWorkingState as u,removeOriginFromWorkingState as d}from"./working-state.js";async function f(c){let f=[],p=[],m=c.materializer.state,h=c.context.pluginRegistry.listExtractAllPlugins();if(h.length===0)return{pending:f,failures:p};let g=s(`extractAll`,c.context,m,c.originRows,c.routeQueryRows,c.hookState),_=c.context.pluginRegistry.list().map(e=>e.id);for(let s of h){if(!g.shouldRun(s)||!s.content?.extractAll)continue;let h=c.logger.child(`content-layer:plugin:${s.id}`),v=t(c.context.config),y=[],b=[],x=e=>b.push(e),S=await a(g.matchedPathsOf(s),c.files,{database:c.database,workingState:m}),C;try{C=await s.content.extractAll({files:S,io:e(c.context.platform.fs,c.context.contentDir,()=>m.filesByPath.keys(),e=>y.push(e)),config:v.config,entities:o(c.database,c.materializer,x),logger:h})}catch(e){let t=e instanceof Error?e:Error(String(e));h.warn(`Content plugin extractAll failed`,{plugin:s.id,error:t.message}),p.push({pluginId:s.id,problem:i({pluginId:s.id,message:t.message})});continue}let w=l({context:c.context,filePath:null,pluginId:s.id,routeDrafts:C?.routes??[],standaloneEntities:C?.entities??[]});d(m,_,s.id,null),u(m,_,s.id,null,w.routes),f.push({pluginId:s.id,inputsHash:g.fingerprintOf(s),routes:w.routes,routeDependencies:w.routeDependencies,entities:w.entities,originDependencies:[...v.collectDependencies().map(e=>Object.assign(e,{source:`config`})),...n(y)],routeQueries:r(b)})}return{pending:f,failures:p}}function p(e,t){if(t.size!==0)for(let n of e){n.routes=n.routes.filter(e=>c(t,n.pluginId,null,e));let e=new Set(n.routes.map(e=>`${e.routeId}\u0000${e.requestedSlug}`));n.routeDependencies=n.routeDependencies.filter(t=>e.has(`${t.routeId}\u0000${t.routeSlug}`))}}export{p as dropCollidingExtractAllRoutes,f as runExtractAllPhase};