@redocly/framework 1.0.0-next.1 → 1.0.0-next.2

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 (146) hide show
  1. package/dist/bundler/build/output-metadata.js +1 -1
  2. package/dist/bundler/build/run.js +1 -1
  3. package/dist/cli/args.js +1 -1
  4. package/dist/cli/commands/translate.js +1 -1
  5. package/dist/cli/validate-react-pages.js +1 -1
  6. package/dist/content-layer/config-schema.d.ts +7 -2
  7. package/dist/content-layer/config-schema.js +1 -1
  8. package/dist/content-layer/config.d.ts +22 -9
  9. package/dist/content-layer/config.js +1 -1
  10. package/dist/content-layer/context.d.ts +2 -0
  11. package/dist/content-layer/context.js +1 -1
  12. package/dist/content-layer/database/assets.js +1 -1
  13. package/dist/content-layer/database/blobs.js +1 -1
  14. package/dist/content-layer/database/entity-store.d.ts +5 -0
  15. package/dist/content-layer/database/entity-store.js +1 -1
  16. package/dist/content-layer/database/files.js +1 -1
  17. package/dist/content-layer/database/finalize.js +1 -1
  18. package/dist/content-layer/database/invalidation.d.ts +6 -0
  19. package/dist/content-layer/database/invalidation.js +26 -26
  20. package/dist/content-layer/database/link-refs.js +1 -1
  21. package/dist/content-layer/database/origins.js +1 -1
  22. package/dist/content-layer/database/problems.js +1 -1
  23. package/dist/content-layer/database/reset.js +1 -1
  24. package/dist/content-layer/database/route-query-deps.js +1 -1
  25. package/dist/content-layer/database/schema.d.ts +33 -0
  26. package/dist/content-layer/database/schema.js +1 -1
  27. package/dist/content-layer/database/search-vocab.js +2 -2
  28. package/dist/content-layer/database/site-config.d.ts +23 -0
  29. package/dist/content-layer/database/site-config.js +1 -1
  30. package/dist/content-layer/database/static-files.js +1 -1
  31. package/dist/content-layer/ingest/finalize-phase.js +1 -1
  32. package/dist/content-layer/ingest/hook-inputs.js +1 -1
  33. package/dist/content-layer/ingest/run.js +1 -1
  34. package/dist/content-layer/ingest/search-sync.js +1 -1
  35. package/dist/content-layer/ingest/sync.js +1 -1
  36. package/dist/content-layer/link-checker/delta.js +1 -1
  37. package/dist/content-layer/loaders/context.js +1 -1
  38. package/dist/content-layer/markdown/constants/tag-sets.d.ts +2 -0
  39. package/dist/content-layer/markdown/constants/tag-sets.js +1 -1
  40. package/dist/content-layer/markdown/nodes/table.js +1 -1
  41. package/dist/content-layer/markdown/resolve/ast.js +1 -1
  42. package/dist/content-layer/markdown/resolve/markdoc-resolvers/code-snippet.js +5 -4
  43. package/dist/content-layer/markdown/resolve/markdoc-resolvers/code-walkthrough/filesets.js +1 -1
  44. package/dist/content-layer/markdown/resolve/markdoc-resolvers/diagram-file.js +1 -1
  45. package/dist/content-layer/markdown/resolve/markdoc-resolvers/file-reference.js +1 -1
  46. package/dist/content-layer/markdown/resolve/markdoc-resolvers/json-schema.d.ts +2 -1
  47. package/dist/content-layer/markdown/resolve/markdoc-resolvers/json-schema.js +1 -1
  48. package/dist/content-layer/markdown/resolve/markdoc-resolvers/operation-samples.js +1 -1
  49. package/dist/content-layer/markdown/resolve/markdoc-resolvers/partial.js +1 -1
  50. package/dist/content-layer/markdown/resolve/markdoc-resolvers/svg-content.js +1 -1
  51. package/dist/content-layer/markdown/resolve/markdoc.js +1 -1
  52. package/dist/content-layer/markdown/resolve/render-diagrams.d.ts +8 -1
  53. package/dist/content-layer/markdown/resolve/render-diagrams.js +1 -1
  54. package/dist/content-layer/markdown/tags/markdoc-error.d.ts +8 -0
  55. package/dist/content-layer/markdown/tags/markdoc-error.js +1 -1
  56. package/dist/content-layer/markdown/utils/node-source-range.d.ts +3 -3
  57. package/dist/content-layer/markdown/utils/node-source-range.js +1 -1
  58. package/dist/content-layer/materialization/asset-reconcile.js +1 -1
  59. package/dist/content-layer/materialization/entity.js +1 -1
  60. package/dist/content-layer/materialization/static-files.js +1 -1
  61. package/dist/content-layer/plan-gates.js +1 -1
  62. package/dist/content-layer/plugins/internal/api-docs/client/template.js +4 -4
  63. package/dist/content-layer/plugins/internal/api-docs/index.js +1 -1
  64. package/dist/content-layer/plugins/internal/api-docs/server/build-sidebar.js +1 -1
  65. package/dist/content-layer/plugins/internal/api-docs/server/search-documents.d.ts +1 -1
  66. package/dist/content-layer/plugins/internal/api-docs/server/search-documents.js +1 -1
  67. package/dist/content-layer/plugins/internal/catalog-classic/resolve-items.d.ts +1 -1
  68. package/dist/content-layer/plugins/internal/catalog-classic/sidebars.d.ts +1 -1
  69. package/dist/content-layer/plugins/internal/markdoc/index.js +1 -1
  70. package/dist/content-layer/plugins/internal/mcp/content-tools.d.ts +4 -1
  71. package/dist/content-layer/plugins/internal/mcp/content-tools.js +1 -1
  72. package/dist/content-layer/plugins/internal/mcp/index.js +1 -1
  73. package/dist/content-layer/plugins/internal/mcp/server/agent-card.js +1 -1
  74. package/dist/content-layer/plugins/internal/mcp/server/auth.js +1 -1
  75. package/dist/content-layer/plugins/internal/mcp/server/handler.js +1 -1
  76. package/dist/content-layer/plugins/internal/mcp/server/oauth/discovery.js +1 -1
  77. package/dist/content-layer/plugins/internal/mcp/server/server-card.js +1 -1
  78. package/dist/content-layer/plugins/internal/mcp/server/skills-resources.js +1 -1
  79. package/dist/content-layer/plugins/internal/react-page/index.js +1 -1
  80. package/dist/content-layer/plugins/internal/sidebar/bundle.d.ts +2 -1
  81. package/dist/content-layer/plugins/internal/sidebar/bundle.js +1 -1
  82. package/dist/content-layer/plugins/internal/sidebar/index.d.ts +2 -1
  83. package/dist/content-layer/plugins/internal/sidebar/index.js +1 -1
  84. package/dist/content-layer/plugins/internal/skills/server/routes.js +1 -1
  85. package/dist/content-layer/plugins/types/search.d.ts +13 -2
  86. package/dist/content-layer/plugins/utils/link-access.js +1 -1
  87. package/dist/content-layer/problems/codes.d.ts +10 -0
  88. package/dist/content-layer/problems/codes.js +1 -1
  89. package/dist/content-layer/revisions/delete.js +1 -1
  90. package/dist/content-layer/search/engine/core/search-engine.js +1 -1
  91. package/dist/content-layer/search/facet-rows.js +1 -1
  92. package/dist/content-layer/search/keywords.d.ts +18 -0
  93. package/dist/content-layer/search/keywords.js +1 -0
  94. package/dist/content-layer/search/postings/postings-store.d.ts +14 -0
  95. package/dist/content-layer/search/postings/postings-store.js +1 -1
  96. package/dist/content-layer/search/store.d.ts +3 -1
  97. package/dist/content-layer/server/database.js +1 -1
  98. package/dist/content-layer/static/registry.js +1 -1
  99. package/dist/content-layer/versions/group-info.d.ts +21 -0
  100. package/dist/content-layer/versions/group-info.js +1 -0
  101. package/dist/content-layer/versions/redirect.d.ts +13 -11
  102. package/dist/content-layer/versions/redirect.js +1 -1
  103. package/dist/content-layer/versions/resolve.d.ts +1 -21
  104. package/dist/content-layer/versions/resolve.js +1 -1
  105. package/dist/content-layer/versions/version-groups.d.ts +1 -1
  106. package/dist/content-layer/versions/version-groups.js +1 -1
  107. package/dist/server/__tests__/rbac-fixture.js +1 -1
  108. package/dist/server/app.js +3 -3
  109. package/dist/server/content.js +9 -9
  110. package/dist/server/lambda-entry.js +1 -1
  111. package/dist/server/node-entry.js +1 -1
  112. package/dist/server/page-handlers.js +2 -2
  113. package/dist/server/plugin-context.js +1 -1
  114. package/dist/server/project-env.d.ts +12 -0
  115. package/dist/server/project-env.js +1 -0
  116. package/dist/server/redirects.js +1 -1
  117. package/dist/server/runtime-config.js +1 -1
  118. package/dist/server/search/route.js +1 -1
  119. package/dist/server/static-files/serve.js +1 -1
  120. package/dist/server/subprocess/child-entry.js +1 -1
  121. package/dist/server/subprocess/host.js +1 -1
  122. package/dist/server/subprocess/runner.js +1 -1
  123. package/dist/shared/constants/dependency-pack.js +1 -1
  124. package/dist/shared/constants/l10n/langs/ar.js +1 -1
  125. package/dist/shared/constants/l10n/langs/de.js +1 -1
  126. package/dist/shared/constants/l10n/langs/en.js +1 -1
  127. package/dist/shared/constants/l10n/langs/es.js +1 -1
  128. package/dist/shared/constants/l10n/langs/fr.js +1 -1
  129. package/dist/shared/constants/l10n/langs/hi.js +1 -1
  130. package/dist/shared/constants/l10n/langs/it.js +1 -1
  131. package/dist/shared/constants/l10n/langs/ja.js +1 -1
  132. package/dist/shared/constants/l10n/langs/ko.js +1 -1
  133. package/dist/shared/constants/l10n/langs/pl.js +1 -1
  134. package/dist/shared/constants/l10n/langs/pt-br.js +1 -1
  135. package/dist/shared/constants/l10n/langs/pt.js +1 -1
  136. package/dist/shared/constants/l10n/langs/ru.js +1 -1
  137. package/dist/shared/constants/l10n/langs/uk.js +1 -1
  138. package/dist/shared/constants/l10n/langs/zh.js +1 -1
  139. package/dist/shared/plan-gates.d.ts +3 -2
  140. package/dist/shared/search/facets.d.ts +5 -0
  141. package/dist/shared/search/facets.js +1 -1
  142. package/dist/shared/types/search.d.ts +1 -0
  143. package/dist/shared/types/sidebar.d.ts +1 -0
  144. package/drizzle/20261103061150_site_config_effective_hash/migration.sql +1 -0
  145. package/drizzle/20261105151816_search_http_path_tokens/migration.sql +1 -0
  146. package/package.json +7 -6
@@ -1 +1 @@
1
- import{loadContentLayerConfig as e}from"../../content-layer/config.js";import{ROUTE_SLUGS_FILENAME as t,RUNTIME_ROUTE_SLUGS_DIRNAME as n,RUNTIME_SSR_DIRNAME as r,serverModuleChunkPath as i}from"../../shared/constants/runtime-layout.js";import{resolveContentLayerContext as a}from"../../content-layer/context.js";import{openContentLayerDatabase as o}from"../../content-layer/database/connection.js";import{createEntityStore as s}from"../../content-layer/database/entity-store.js";import{createRouteIndex as c}from"../../content-layer/plugins/utils/route-index.js";import{createContentPlugins as l}from"../../content-layer/plugins/create-content-plugins.js";import"../../content-layer/plugins/index.js";import{listAssetSourcePaths as u}from"../../content-layer/database/assets.js";import{listProblems as d,summarizeStoredProblems as f}from"../../content-layer/database/problems.js";import{listRoutePagesByFile as p}from"../../content-layer/database/files.js";import"../../content-layer/server/database.js";import{loadContentLayerState as m}from"../../content-layer/context-state.js";import{assertValidMcpToolFiles as h}from"../../content-layer/plugins/internal/mcp/build-check.js";import{compileAssetAudienceTable as g}from"../../content-layer/markdown/resolve/audience-tag.js";import{pathToFileURL as _}from"node:url";import{dirname as v,join as y}from"node:path";import{mkdir as b,writeFile as x}from"node:fs/promises";const S=`build-metadata.json`;async function C(e){let t={},{access:n}=e.context.config;t.access={requiresLogin:n?.requiresLogin===!0,rbacConfigured:n?.rbac!==void 0};let r=await g(n?.rbac,await u(e.database));return r&&(t.contentAssetAudiences={schemaVersion:1,tags:r}),t.problems=await T(e.database),Object.assign(t,await E(e)),t}function w(e){let t=e.filePath===null?void 0:{filePath:e.filePath,...e.range===null?{}:{range:e.range},...e.snippet===null?{}:{snippet:e.snippet}};return{code:e.code,category:e.category,severity:e.severity,message:e.message,...t===void 0?{}:{location:t},data:e.data}}async function T(e,{limit:t=1e4}={}){let n=await f(e),r=await d(e,{limit:t});return{schemaVersion:1,summary:{...n,truncated:n.errors+n.warnings>t},problems:r.map(w)}}async function E(e){let{context:t,database:n}=e,r=await m({context:t,database:n}),i=c(r,t.config),a=s({database:n,state:r}),o={};for(let e of t.pluginRegistry.listBuildMetadataPlugins()){let n=await e.buildMetadata?.({config:t.config,routes:i,entities:a,logger:t.logger.child(`content-layer:build-metadata:${e.id}`)});n!==void 0&&(o[e.id]=n)}return o}async function D(e){let{context:t,database:n,outputDir:a}=e,o=await m({context:t,database:n}),c=s({database:n,state:o}),l=y(a,r);await h({entities:c,loadContentModule:async e=>{let t=y(l,i(e));return await import(_(t).href)},pluginToolNames:t.pluginRegistry.listMcpTools().map(e=>e.declaration.name),...e.logger?{logger:e.logger}:{}})}async function O(e,r){let i=y(r,n,t);await b(v(i),{recursive:!0});let a=await p(e);await x(i,JSON.stringify(Object.fromEntries(a)),`utf8`)}async function k(t){let n=a({contentDir:t.contentDir,context:t.context,logger:t.logger,plugins:l(t.contentDir)});await e({context:n});let r=t.database??await o({contentDir:t.contentDir,databaseUrl:t.databaseUrl,logger:t.logger,runMigrations:!1});try{await D({database:r,context:n,outputDir:t.outputDir,...t.logger?{logger:t.logger}:{}});let e={formatVersion:1,sections:await C({database:r,context:n,logger:t.logger})},i=y(t.outputDir,S);return await x(i,`${JSON.stringify(e,null,2)}\n`,`utf8`),await O(r,t.outputDir),i}finally{t.database||await r.close()}}export{S as BUILD_OUTPUT_METADATA_FILENAME,C as collectBuildOutputMetadataSections,T as collectProblemsSection,k as writeBuildOutputMetadata};
1
+ import{loadContentLayerConfig as e}from"../../content-layer/config.js";import{ROUTE_SLUGS_FILENAME as t,RUNTIME_ROUTE_SLUGS_DIRNAME as n,RUNTIME_SSR_DIRNAME as r,serverModuleChunkPath as i}from"../../shared/constants/runtime-layout.js";import{resolveContentLayerContext as a}from"../../content-layer/context.js";import{openContentLayerDatabase as o}from"../../content-layer/database/connection.js";import{createEntityStore as s}from"../../content-layer/database/entity-store.js";import{createRouteIndex as c}from"../../content-layer/plugins/utils/route-index.js";import{createContentPlugins as l}from"../../content-layer/plugins/create-content-plugins.js";import"../../content-layer/plugins/index.js";import{listProblems as u,summarizeStoredProblems as d}from"../../content-layer/database/problems.js";import{assertValidMcpToolFiles as f}from"../../content-layer/plugins/internal/mcp/build-check.js";import{listAssetSourcePaths as p}from"../../content-layer/database/assets.js";import{listRoutePagesByFile as m}from"../../content-layer/database/files.js";import"../../content-layer/server/database.js";import{compileAssetAudienceTable as h}from"../../content-layer/markdown/resolve/audience-tag.js";import{loadContentLayerState as g}from"../../content-layer/context-state.js";import{pathToFileURL as _}from"node:url";import{dirname as v,join as y}from"node:path";import{mkdir as b,writeFile as x}from"node:fs/promises";const S=`build-metadata.json`;async function C(e){let t={},{access:n}=e.context.config;t.access={requiresLogin:n?.requiresLogin===!0,rbacConfigured:n?.rbac!==void 0};let r=await h(n?.rbac,await p(e.database));return r&&(t.contentAssetAudiences={schemaVersion:1,tags:r}),t.problems=await T(e.database),Object.assign(t,await E(e)),t}function w(e){let t=e.filePath===null?void 0:{filePath:e.filePath,...e.range===null?{}:{range:e.range},...e.snippet===null?{}:{snippet:e.snippet}};return{code:e.code,category:e.category,severity:e.severity,message:e.message,...t===void 0?{}:{location:t},data:e.data}}async function T(e,{limit:t=1e4}={}){let n=await d(e),r=await u(e,{limit:t});return{schemaVersion:1,summary:{...n,truncated:n.errors+n.warnings>t},problems:r.map(w)}}async function E(e){let{context:t,database:n}=e,r=await g({context:t,database:n}),i=c(r,t.config),a=s({database:n,state:r}),o={};for(let e of t.pluginRegistry.listBuildMetadataPlugins()){let n=await e.buildMetadata?.({config:t.config,routes:i,entities:a,logger:t.logger.child(`content-layer:build-metadata:${e.id}`)});n!==void 0&&(o[e.id]=n)}return o}async function D(e){let{context:t,database:n,outputDir:a}=e,o=await g({context:t,database:n}),c=s({database:n,state:o}),l=y(a,r);await f({entities:c,loadContentModule:async e=>{let t=y(l,i(e));return await import(_(t).href)},pluginToolNames:t.pluginRegistry.listMcpTools().map(e=>e.declaration.name),...e.logger?{logger:e.logger}:{}})}async function O(e,r){let i=y(r,n,t);await b(v(i),{recursive:!0});let a=await m(e);await x(i,JSON.stringify(Object.fromEntries(a)),`utf8`)}async function k(t){let n=a({contentDir:t.contentDir,context:t.context,logger:t.logger,plugins:l(t.contentDir)});await e({context:n});let r=t.database??await o({contentDir:t.contentDir,databaseUrl:t.databaseUrl,logger:t.logger,runMigrations:!1});try{await D({database:r,context:n,outputDir:t.outputDir,...t.logger?{logger:t.logger}:{}});let e={formatVersion:1,sections:await C({database:r,context:n,logger:t.logger})},i=y(t.outputDir,S);return await x(i,`${JSON.stringify(e,null,2)}\n`,`utf8`),await O(r,t.outputDir),i}finally{t.database||await r.close()}}export{S as BUILD_OUTPUT_METADATA_FILENAME,C as collectBuildOutputMetadataSections,T as collectProblemsSection,k as writeBuildOutputMetadata};
@@ -1 +1 @@
1
- import{formatCount as e}from"../../shared/log-format.js";import{createLogger as t}from"../../shared/logger.js";import{loadContentLayerConfig as n}from"../../content-layer/config.js";import{resolveContentLayerContext as r}from"../../content-layer/context.js";import{openContentLayerDatabase as i}from"../../content-layer/database/connection.js";import{createRouteIndex as a}from"../../content-layer/plugins/utils/route-index.js";import{MaterializationError as o}from"../../content-layer/problems/problem-error.js";import{createContentPlugins as s}from"../../content-layer/plugins/create-content-plugins.js";import"../../content-layer/plugins/index.js";import{silentReporter as c}from"../../shared/reporter.js";import{loadStaleEntityRecords as l}from"../../content-layer/database/entities.js";import{listStaticFileRecords as u}from"../../content-layer/database/static-files.js";import{loadContentLayerState as d,reloadContentLayerEntities as f}from"../../content-layer/context-state.js";import{garbageCollectOrphanAssetFiles as p}from"../../content-layer/materialization/asset-reconcile.js";import{collectStaticProducerKeys as m,materializeStaticProducers as h}from"../../content-layer/materialization/static-files.js";import{materializeEntityByKey as g}from"../../content-layer/materialization/entity.js";import{promiseMapLimit as _}from"../../shared/utils/promise-map-limit.js";import{resolveRevisionsConfig as v}from"../../content-layer/revisions/config.js";import{createBuildTimeEntityLoaderContextFactory as y}from"../../content-layer/loaders/context.js";import{runSearchSync as b}from"../../content-layer/ingest/search-sync.js";import{createStaticAudienceResolver as x}from"../../content-layer/static/audience.js";var S=class extends Error{name=`BuildOptionsError`};function C(e,t){if(t===`aws-lambda`&&e===`local`)throw new S(`--platform aws-lambda is incompatible with --target local. Lambda has a read-only, ephemeral filesystem; use --target cloud (a Realm DB database).`)}async function w(e){let n=e.platform??`nodejs`;C(e.target,n);let r=(e.logger??t()).child(`runtime:build`),{buildRuntime:i}=await import(`./vite-config.js`),a=await i({contentDir:e.contentDir,target:e.target,platform:n,logger:r,reporter:e.reporter??c,templateSet:e.templateSet,serverModuleSet:e.serverModuleSet,devLogin:e.devLogin??!1});return r.debug(`Built runtime`,{outputDir:a.outputDir,target:e.target,platform:n}),a}async function T(t){let g=r({contentDir:t.contentDir,context:t.context,logger:t.logger,plugins:s(t.contentDir)}),v=g.logger.child(`content-layer:entity`);await n({context:g});let y=t.database===void 0,S=t.database??await i({contentDir:g.contentDir,databaseUrl:t.databaseUrl,logger:v,migrationsDir:t.migrationsDir,runMigrations:t.runMigrations,platform:g.platform});try{let n=await d({context:g,database:S}),r=await l(S),i=await u(S),s=m(i),y=r.filter(e=>e.kind!==`inline`&&e.loaderId!==null&&g.pluginRegistry.getEntityLoaderById(e.loaderId)!==void 0),C=y.filter(e=>!s.has(e.key)),w=y.filter(e=>s.has(e.key)),T=E(g,S),D=t.reporter??c,O=C.length;await D.run(`Preparing content items`,async e=>{let t=0,n=0;await _(C,8,async r=>{let i=Date.now();try{await T(r),v.debug(`materialized ${r.key} (+${Date.now()-i}ms)`)}catch(e){if(!(e instanceof o))throw e;n+=1,v.debug(`Could not materialize ${r.key}; recorded the problem`)}t+=1,e.progress(t,O)});let r=await p(g.pluginIO,{contentDir:g.contentDir,database:S,logger:v});return r.removedRows>0&&v.debug(`post-materialize asset GC removed orphan assets`,{count:r.removedRows,swept:r.sweptFilenames.length}),n},t=>{if(O===0)return`All content items are prepared`;let n=`Prepared ${e(O-t)} content ${O-t===1?`item`:`items`}`;return t>0?`${n} (${e(t)} failed)`:n}),O>0&&await f({state:n,database:S,keys:C.map(e=>e.key)});let k=await D.run(`Indexing search`,e=>b({context:g,database:S,inlineSearchables:t.inlineSearchables,onProgress:(t,n)=>e.progress(t,n)}),t=>`Indexed ${e(t.synced)} content ${t.synced===1?`item`:`items`} for search`);return await D.run(`Writing static files`,()=>h({io:g.pluginIO,contentDir:g.contentDir,database:S,rows:i,staleProducers:w,materializeEntity:T,resolveAudience:x({config:g.config,routes:a(n,g.config)}),logger:v}),t=>`Wrote ${e(t.files.length)} static ${t.files.length===1?`file`:`files`}`),{entityCount:O+w.length,problems:k.problems}}finally{y&&await S.close()}}function E(e,t){let n=v(e.config),r=n?{max:n.max,capture:!0,isTracked:n.isTracked}:void 0,i=y(e,t,{revisions:r});return async n=>{await g({database:t,key:n.key,loaderRegistry:e.pluginRegistry,loaderContextFactory:i,contentDir:e.contentDir,revisions:r});let a=e.state?.entitiesByKey.get(n.key);e.state&&a&&e.state.entitiesByKey.set(n.key,{...a,status:`ready`})}}export{S as BuildOptionsError,C as assertRuntimeBuildOptions,w as runBuild,T as runContentEntityBuild};
1
+ import{formatCount as e}from"../../shared/log-format.js";import{createLogger as t}from"../../shared/logger.js";import{loadContentLayerConfig as n}from"../../content-layer/config.js";import{resolveContentLayerContext as r}from"../../content-layer/context.js";import{openContentLayerDatabase as i}from"../../content-layer/database/connection.js";import{createRouteIndex as a}from"../../content-layer/plugins/utils/route-index.js";import{MaterializationError as o}from"../../content-layer/problems/problem-error.js";import{createContentPlugins as s}from"../../content-layer/plugins/create-content-plugins.js";import"../../content-layer/plugins/index.js";import{silentReporter as c}from"../../shared/reporter.js";import{loadStaleEntityRecords as l}from"../../content-layer/database/entities.js";import{listStaticFileRecords as u}from"../../content-layer/database/static-files.js";import{loadContentLayerState as d,reloadContentLayerEntities as f}from"../../content-layer/context-state.js";import{garbageCollectOrphanAssetFiles as p}from"../../content-layer/materialization/asset-reconcile.js";import{collectStaticProducerKeys as m,materializeStaticProducers as h}from"../../content-layer/materialization/static-files.js";import{materializeEntityByKey as g}from"../../content-layer/materialization/entity.js";import{promiseMapLimit as _}from"../../shared/utils/promise-map-limit.js";import{resolveRevisionsConfig as v}from"../../content-layer/revisions/config.js";import{createBuildTimeEntityLoaderContextFactory as y}from"../../content-layer/loaders/context.js";import{runSearchSync as b}from"../../content-layer/ingest/search-sync.js";import{createStaticAudienceResolver as x}from"../../content-layer/static/audience.js";var S=class extends Error{name=`BuildOptionsError`};function C(e,t){if(t===`aws-lambda`&&e===`local`)throw new S(`--platform aws-lambda is incompatible with --target local. Lambda has a read-only, ephemeral filesystem; use --target cloud (a Realm DB database).`)}async function w(e){let n=e.platform??`nodejs`;C(e.target,n);let r=(e.logger??t()).child(`runtime:build`),{buildRuntime:i}=await import(`./vite-config.js`),a=await i({contentDir:e.contentDir,target:e.target,platform:n,logger:r,reporter:e.reporter??c,templateSet:e.templateSet,serverModuleSet:e.serverModuleSet,devLogin:e.devLogin??!1});return r.debug(`Built runtime`,{outputDir:a.outputDir,target:e.target,platform:n}),a}async function T(t){let g=r({contentDir:t.contentDir,context:t.context,logger:t.logger,plugins:s(t.contentDir)}),v=g.logger.child(`content-layer:entity`);await n({context:g});let y=t.database===void 0,S=t.database??await i({contentDir:g.contentDir,databaseUrl:t.databaseUrl,logger:v,migrationsDir:t.migrationsDir,runMigrations:t.runMigrations,platform:g.platform});try{let n=await d({context:g,database:S}),r=await l(S),i=await u(S),s=m(i),y=r.filter(e=>e.kind!==`inline`&&e.loaderId!==null&&g.pluginRegistry.getEntityLoaderById(e.loaderId)!==void 0),C=y.filter(e=>!s.has(e.key)),w=y.filter(e=>s.has(e.key)),T=E(g,S),D=t.reporter??c,O=C.length;await D.run(`Preparing content items`,async e=>{let t=0,n=0;await _(C,8,async r=>{let i=Date.now();try{await T(r),v.debug(`materialized ${r.key} (+${Date.now()-i}ms)`)}catch(e){if(!(e instanceof o))throw e;n+=1,v.debug(`Could not materialize ${r.key}; recorded the problem`)}t+=1,e.progress(t,O)});let r=await p(g.pluginIO,{contentDir:g.contentDir,database:S,logger:v});return r.removedRows>0&&v.debug(`post-materialize asset GC removed orphan assets`,{count:r.removedRows,swept:r.sweptFilenames.length}),n},t=>{if(O===0)return`All content items are prepared`;let n=`Prepared ${e(O-t)} content ${O-t===1?`item`:`items`}`;return t>0?`${n} (${e(t)} failed)`:n}),O>0&&await f({state:n,database:S,keys:C.map(e=>e.key)});let k=await D.run(`Indexing search`,e=>b({context:g,database:S,inlineSearchables:t.inlineSearchables,onProgress:(t,n)=>e.progress(t,n)}),t=>`Indexed ${e(t.synced)} content ${t.synced===1?`item`:`items`} for search`);return await D.run(`Writing static files`,()=>h({io:g.pluginIO,contentDir:g.contentDir,database:S,rows:i,staleProducers:w,materializeEntity:T,resolveAudience:x({config:g.config,routes:a(n,g.config)}),logger:v}),t=>`Wrote ${e(t.files.length)} static ${t.files.length===1?`file`:`files`}`),{entityCount:O+w.length,problems:k.problems}}finally{y&&await S.close()}}function E(e,t){let n=v(e.config),r=n?{max:n.max,capture:!0,isTracked:n.isTracked}:void 0,i=y(e,t,{revisions:r});return async n=>{await g({database:t,key:n.key,loaderRegistry:e.pluginRegistry,loaderContextFactory:i,contentDir:e.contentDir,revisions:r,logger:e.logger});let a=e.state?.entitiesByKey.get(n.key);e.state&&a&&e.state.entitiesByKey.set(n.key,{...a,status:`ready`})}}export{S as BuildOptionsError,C as assertRuntimeBuildOptions,w as runBuild,T as runContentEntityBuild};
package/dist/cli/args.js CHANGED
@@ -1 +1 @@
1
- import{createLogger as e,isLogLevel as t}from"../shared/logger.js";import{isRemoteDatabaseUrl as n}from"../content-layer/database/utils/is-remote-database-url.js";import{createReporter as r}from"../shared/reporter.js";import{loadProjectEnv as i}from"../shared/load-dot-env.js";import{BuildOptionsError as a}from"../bundler/build/run.js";import{CliUsageError as o,parseArgs as s}from"./parse-args.js";import{resolve as c}from"node:path";const l={alias:{h:`help`,D:`debug`,d:`project-dir`},boolean:[`help`,`h`],string:[`project-dir`,`db`,`log-level`]};function u(e){let t=c(y(e[`project-dir`],`--project-dir`)??process.env.REDOCLY_CONTENT_DIR??`.`),n=h(e.db),r=x(e.debug),a=g(e[`log-level`]);i(t);let o=a??_(process.env.REDOCLY_LOG_LEVEL);return{contentDir:t,databaseUrl:n,level:o,debug:r,stacks:r!==!1||o===`debug`,expandPhases:r===!0||o===`debug`}}function d(t,n){let i=e({level:t.level===`debug`?`debug`:`http`,debug:t.debug,output:n});return p(i),{...t,logger:i,reporter:r(n)}}let f;function p(e){if(f===void 0){let e=process.listeners(`warning`).find(e=>e.name===`onWarning`);if(e===void 0||Reflect.get(process,`traceProcessWarnings`)===!0)return;process.off(`warning`,e),process.on(`warning`,e=>{m.has(e.code??``)||f?.warn(e.message,{code:e.code})})}f=e}const m=/* @__PURE__ */ new Set([`MODULE_TYPELESS_PACKAGE_JSON`]);function h(e){let t=y(e,`--db`);if(t!==void 0&&n(t))throw new o(`Invalid value for --db. Expected a local path or file: URL.`);return t}function g(e){if(e!==void 0){if(t(e))return e;throw new o(`Invalid value for --log-level. Expected "debug", "http", "info", "warn" or "error".`)}}function _(e){let n=e?.toLowerCase();return t(n)?n:void 0}function v(e){if(e!==void 0){if(typeof e==`number`&&Number.isInteger(e)&&e>0)return e;if(typeof e==`string`&&/^[1-9]\d*$/.test(e))return Number(e);throw new o(`Invalid value for --port. Expected a positive integer.`)}}function y(e,t){if(e!==void 0){if(typeof e!=`string`||e.trim()===``)throw new o(`Invalid value for ${t}. Expected a non-empty string.`);return e}}function b(e){return typeof e==`string`&&e.length>0?e.split(`,`):void 0}function x(e){if(e===void 0||e===!1)return!1;if(e===!0)return!0;if(typeof e==`string`){let t=S([e]);if(t.length===0)throw T();return t}if(Array.isArray(e)&&e.every(e=>typeof e==`string`)){let t=S(e);if(t.length===0)throw T();return t}throw T()}function S(e){let t=/* @__PURE__ */ new Set;for(let n of e)for(let e of n.split(`,`)){let n=e.trim();n!==``&&t.add(n)}return[...t]}function C(e){if(e===void 0)return`local`;if(e===`local`||e===`cloud`)return e;throw new o(`Invalid value for --target. Expected "local" or "cloud".`)}function w(e){if(e===void 0)return`nodejs`;if(e===`nodejs`||e===`aws-lambda`)return e;throw new o(`Invalid value for --platform. Expected "nodejs" or "aws-lambda".`)}function T(){return new o(`Invalid value for --debug. Expected a stream name or a comma-separated list.`)}function E(e,t){if(e instanceof o||e instanceof a)return t.stderr(e.message),1;throw e}export{l as COMMON_FLAGS,o as CliUsageError,s as parseArgs,C as parseBuildTarget,x as parseDebugFlag,b as parseHintsFlag,w as parseHostPlatform,y as parseOptionalStringFlag,v as parsePort,E as reportUsageError,u as resolveCommonArgs,d as setUpLogging};
1
+ import{createLogger as e,isLogLevel as t}from"../shared/logger.js";import{isRemoteDatabaseUrl as n}from"../content-layer/database/utils/is-remote-database-url.js";import{createReporter as r}from"../shared/reporter.js";import{BuildOptionsError as i}from"../bundler/build/run.js";import{loadProjectEnv as a}from"../shared/load-dot-env.js";import{CliUsageError as o,parseArgs as s}from"./parse-args.js";import{resolve as c}from"node:path";const l={alias:{h:`help`,D:`debug`,d:`project-dir`},boolean:[`help`,`h`],string:[`project-dir`,`db`,`log-level`]};function u(e){let t=c(y(e[`project-dir`],`--project-dir`)??process.env.REDOCLY_CONTENT_DIR??`.`),n=h(e.db),r=x(e.debug),i=g(e[`log-level`]);a(t);let o=i??_(process.env.REDOCLY_LOG_LEVEL);return{contentDir:t,databaseUrl:n,level:o,debug:r,stacks:r!==!1||o===`debug`,expandPhases:r===!0||o===`debug`}}function d(t,n){let i=e({level:t.level===`debug`?`debug`:`http`,debug:t.debug,output:n});return p(i),{...t,logger:i,reporter:r(n)}}let f;function p(e){if(f===void 0){let e=process.listeners(`warning`).find(e=>e.name===`onWarning`);if(e===void 0||Reflect.get(process,`traceProcessWarnings`)===!0)return;process.off(`warning`,e),process.on(`warning`,e=>{m.has(e.code??``)||f?.warn(e.message,{code:e.code})})}f=e}const m=/* @__PURE__ */ new Set([`MODULE_TYPELESS_PACKAGE_JSON`]);function h(e){let t=y(e,`--db`);if(t!==void 0&&n(t))throw new o(`Invalid value for --db. Expected a local path or file: URL.`);return t}function g(e){if(e!==void 0){if(t(e))return e;throw new o(`Invalid value for --log-level. Expected "debug", "http", "info", "warn" or "error".`)}}function _(e){let n=e?.toLowerCase();return t(n)?n:void 0}function v(e){if(e!==void 0){if(typeof e==`number`&&Number.isInteger(e)&&e>0)return e;if(typeof e==`string`&&/^[1-9]\d*$/.test(e))return Number(e);throw new o(`Invalid value for --port. Expected a positive integer.`)}}function y(e,t){if(e!==void 0){if(typeof e!=`string`||e.trim()===``)throw new o(`Invalid value for ${t}. Expected a non-empty string.`);return e}}function b(e){return typeof e==`string`&&e.length>0?e.split(`,`):void 0}function x(e){if(e===void 0||e===!1)return!1;if(e===!0)return!0;if(typeof e==`string`){let t=S([e]);if(t.length===0)throw T();return t}if(Array.isArray(e)&&e.every(e=>typeof e==`string`)){let t=S(e);if(t.length===0)throw T();return t}throw T()}function S(e){let t=/* @__PURE__ */ new Set;for(let n of e)for(let e of n.split(`,`)){let n=e.trim();n!==``&&t.add(n)}return[...t]}function C(e){if(e===void 0)return`local`;if(e===`local`||e===`cloud`)return e;throw new o(`Invalid value for --target. Expected "local" or "cloud".`)}function w(e){if(e===void 0)return`nodejs`;if(e===`nodejs`||e===`aws-lambda`)return e;throw new o(`Invalid value for --platform. Expected "nodejs" or "aws-lambda".`)}function T(){return new o(`Invalid value for --debug. Expected a stream name or a comma-separated list.`)}function E(e,t){if(e instanceof o||e instanceof i)return t.stderr(e.message),1;throw e}export{l as COMMON_FLAGS,o as CliUsageError,s as parseArgs,C as parseBuildTarget,x as parseDebugFlag,b as parseHintsFlag,w as parseHostPlatform,y as parseOptionalStringFlag,v as parsePort,E as reportUsageError,u as resolveCommonArgs,d as setUpLogging};
@@ -1,2 +1,2 @@
1
- import{createNodePlatformFs as e}from"../../platform/node/fs.js";import{ANSI as t,paint as n}from"../../shared/log-format.js";import{stopwatch as r}from"../../shared/logger.js";import{DEFAULT_LOCALE_PLACEHOLDER as i,L10N_DIR as a,TRANSLATIONS_FILE_NAMES as o}from"../../shared/constants/l10n/defaults.js";import{compareStrings as s}from"../../shared/utils/compare-strings.js";import{isObject as c}from"../../shared/utils/is-object.js";import{l10nDirOf as l,listL10nDirs as u,normalizeL10nConfig as d}from"../../shared/utils/l10n.js";import{loadRedoclyConfig as f}from"../../content-layer/config.js";import{contentIgnoreMatcherOf as p,scanContentFiles as m}from"../../content-layer/ingest/scan.js";import{SIDEBAR_FILENAME_REGEX as h}from"../../content-layer/plugins/internal/sidebar/index.js";import{defaultTranslationImports as g}from"../../shared/constants/l10n/default-translations.js";import{formatFailure as _,printTranslateHelp as v,shouldUseColors as y}from"../output.js";import{CliUsageError as b,parseArgs as x}from"../parse-args.js";import{COMMON_FLAGS as S,reportUsageError as C,resolveCommonArgs as w}from"../args.js";import{join as T,posix as E}from"node:path";import D from"js-yaml";import O from"node:process";import{createInterface as k}from"node:readline/promises";const A=`default`,j=/^[\w-]+$/,M=/^translations\.ya?ml$/i,N=D.FAILSAFE_SCHEMA.extend({implicit:[new D.Type(`tag:yaml.org,2002:null`,{kind:`scalar`,resolve:e=>[`~`,`null`,`Null`,`NULL`].includes(e),construct:()=>null})]});async function P(i,a,o){let s=x(i,{alias:{h:`help`,d:`project-dir`,D:`debug`},boolean:[...S.boolean,`debug`],string:[`project-dir`]});if(s.help)return v(a.stdout),0;let c,l,u=s._.map(String);try{if({contentDir:c,stacks:l}=w(s),u.length===0)throw new b(`Locale is required but was not provided.`);let e=u.find(e=>!j.test(e));if(e!==void 0)throw new b(`Invalid locale "${e}". Use letters, digits, "-" and "_" only.`)}catch(e){return C(e,a)}let d=y(),p=r();try{let r=e(),{config:i}=await f(c,r),s=await F(c,r,i,u),l=await(o.confirm??(e=>W(e,a)))(U(s,d));if(l===void 0)return a.stderr(`The confirmation prompt got no answer. No files changed.`),1;if(!l)return a.stdout(`No files changed.`),0;for(let e of s)await r.writeFile(T(c,e.path),D.dump(e.translations),{recursive:!0});return a.stdout(n(`✓ Translations updated`,t.bold+t.green,d)),0}catch(e){return a.stdout(_(`Translate failed`,p(),e,{colors:d,stacks:l})),1}}async function F(e,t,n,r){let{defaultLocale:i}=d(n.l10n),c=await u(e,t),l=r[0]===`all`?[A,...c]:r,f=await I(e,t,n),p=/* @__PURE__ */ new Map;for(let n of l){let r=n===A||n.toLowerCase()===i.toLowerCase(),l=r?``:E.join(a,c.find(e=>H(e,n))??n),u=await B(e,t,l),d=u??E.join(l,o[0]);if(p.has(d))continue;let m=u?V(await t.readFile(T(e,u)),u):{},h={...await R(r?i:n),...f,...m};p.set(d,{path:d,exists:u!==void 0,translations:Object.fromEntries(Object.entries(h).sort(([e],[t])=>s(e,t)))})}return[...p.values()]}async function I(e,t,n){let r=p(n),i=(await m({fs:t,rootDir:e})).filter(e=>h.test(e.path)&&l(e.path)===void 0&&!r(e.path));return{...L(await Promise.all(i.map(async e=>D.load(await t.readFile(e.absolutePath),{filename:e.path})))),...L(n)}}function L(e){let t={};if(Array.isArray(e)){for(let n of e)Object.assign(t,L(n));return t}if(!c(e))return t;for(let[n,r]of Object.entries(e)){if(!n.endsWith(`TranslationKey`)||typeof r!=`string`){Object.assign(t,L(r));continue}let i=n.slice(0,-14),a=e[i];i.trim()===``||r.trim()===``||a!=null&&typeof a!=`string`||(t[r]=a??``)}return t}async function R(e){let t=e.split(`-`)[0];return{...await g[i](),...await z(t),...H(t,e)?{}:await z(e)}}async function z(e){let t=Object.keys(g).find(t=>H(t,e));return t===void 0?{}:g[t]()}async function B(e,t,n){for(let r of await t.readdir(T(e,n))){if(!M.test(r.name))continue;let i=E.join(n,r.name);if(r.type===`file`||r.type===`symlink`&&(await t.stat(T(e,i)))?.type===`file`)return i}}function V(e,t){let n=D.load(e,{filename:t,schema:N})??{};if(!c(n))throw Error(`${t} must map translation keys to texts. No files changed.`);return n}function H(e,t){return e.toLowerCase()===t.toLowerCase()}function U(e,r){let i=e=>e.map(e=>` - ${n(e.path,t.cyan,r)}`),a=e.filter(e=>!e.exists),o=e.filter(e=>e.exists),s=[`Confirm the following actions:`,``];return a.length>0&&s.push(`Create new files with translations stubs:`,...i(a),``),o.length>0&&s.push(`Update translations files with missing phrases (this doesn't rewrite existing data values):`,...i(o),``),s.push(`Continue? (Y/n) `),s.join(`
1
+ import{createNodePlatformFs as e}from"../../platform/node/fs.js";import{ANSI as t,paint as n}from"../../shared/log-format.js";import{stopwatch as r}from"../../shared/logger.js";import{DEFAULT_LOCALE_PLACEHOLDER as i,L10N_DIR as a,TRANSLATIONS_FILE_NAMES as o}from"../../shared/constants/l10n/defaults.js";import{compareStrings as s}from"../../shared/utils/compare-strings.js";import{isObject as c}from"../../shared/utils/is-object.js";import{l10nDirOf as l,listL10nDirs as u,normalizeL10nConfig as d}from"../../shared/utils/l10n.js";import{loadRedoclyConfig as f}from"../../content-layer/config.js";import{contentIgnoreMatcherOf as p,scanContentFiles as m}from"../../content-layer/ingest/scan.js";import{SIDEBAR_FILENAME_REGEX as h}from"../../content-layer/plugins/internal/sidebar/index.js";import{formatFailure as g,printTranslateHelp as _,shouldUseColors as v}from"../output.js";import{defaultTranslationImports as y}from"../../shared/constants/l10n/default-translations.js";import{CliUsageError as b,parseArgs as x}from"../parse-args.js";import{COMMON_FLAGS as S,reportUsageError as C,resolveCommonArgs as w}from"../args.js";import{join as T,posix as E}from"node:path";import D from"js-yaml";import O from"node:process";import{createInterface as k}from"node:readline/promises";const A=`default`,j=/^[\w-]+$/,M=/^translations\.ya?ml$/i,N=D.FAILSAFE_SCHEMA.extend({implicit:[new D.Type(`tag:yaml.org,2002:null`,{kind:`scalar`,resolve:e=>[`~`,`null`,`Null`,`NULL`].includes(e),construct:()=>null})]});async function P(i,a,o){let s=x(i,{alias:{h:`help`,d:`project-dir`,D:`debug`},boolean:[...S.boolean,`debug`],string:[`project-dir`]});if(s.help)return _(a.stdout),0;let c,l,u=s._.map(String);try{if({contentDir:c,stacks:l}=w(s),u.length===0)throw new b(`Locale is required but was not provided.`);let e=u.find(e=>!j.test(e));if(e!==void 0)throw new b(`Invalid locale "${e}". Use letters, digits, "-" and "_" only.`)}catch(e){return C(e,a)}let d=v(),p=r();try{let r=e(),{config:i}=await f(c,r),s=await F(c,r,i,u),l=await(o.confirm??(e=>W(e,a)))(U(s,d));if(l===void 0)return a.stderr(`The confirmation prompt got no answer. No files changed.`),1;if(!l)return a.stdout(`No files changed.`),0;for(let e of s)await r.writeFile(T(c,e.path),D.dump(e.translations),{recursive:!0});return a.stdout(n(`✓ Translations updated`,t.bold+t.green,d)),0}catch(e){return a.stdout(g(`Translate failed`,p(),e,{colors:d,stacks:l})),1}}async function F(e,t,n,r){let{defaultLocale:i}=d(n.l10n),c=await u(e,t),l=r[0]===`all`?[A,...c]:r,f=await I(e,t,n),p=/* @__PURE__ */ new Map;for(let n of l){let r=n===A||n.toLowerCase()===i.toLowerCase(),l=r?``:E.join(a,c.find(e=>H(e,n))??n),u=await B(e,t,l),d=u??E.join(l,o[0]);if(p.has(d))continue;let m=u?V(await t.readFile(T(e,u)),u):{},h={...await R(r?i:n),...f,...m};p.set(d,{path:d,exists:u!==void 0,translations:Object.fromEntries(Object.entries(h).sort(([e],[t])=>s(e,t)))})}return[...p.values()]}async function I(e,t,n){let r=p(n),i=(await m({fs:t,rootDir:e})).filter(e=>h.test(e.path)&&l(e.path)===void 0&&!r(e.path));return{...L(await Promise.all(i.map(async e=>D.load(await t.readFile(e.absolutePath),{filename:e.path})))),...L(n)}}function L(e){let t={};if(Array.isArray(e)){for(let n of e)Object.assign(t,L(n));return t}if(!c(e))return t;for(let[n,r]of Object.entries(e)){if(!n.endsWith(`TranslationKey`)||typeof r!=`string`){Object.assign(t,L(r));continue}let i=n.slice(0,-14),a=e[i];i.trim()===``||r.trim()===``||a!=null&&typeof a!=`string`||(t[r]=a??``)}return t}async function R(e){let t=e.split(`-`)[0];return{...await y[i](),...await z(t),...H(t,e)?{}:await z(e)}}async function z(e){let t=Object.keys(y).find(t=>H(t,e));return t===void 0?{}:y[t]()}async function B(e,t,n){for(let r of await t.readdir(T(e,n))){if(!M.test(r.name))continue;let i=E.join(n,r.name);if(r.type===`file`||r.type===`symlink`&&(await t.stat(T(e,i)))?.type===`file`)return i}}function V(e,t){let n=D.load(e,{filename:t,schema:N})??{};if(!c(n))throw Error(`${t} must map translation keys to texts. No files changed.`);return n}function H(e,t){return e.toLowerCase()===t.toLowerCase()}function U(e,r){let i=e=>e.map(e=>` - ${n(e.path,t.cyan,r)}`),a=e.filter(e=>!e.exists),o=e.filter(e=>e.exists),s=[`Confirm the following actions:`,``];return a.length>0&&s.push(`Create new files with translations stubs:`,...i(a),``),o.length>0&&s.push(`Update translations files with missing phrases (this doesn't rewrite existing data values):`,...i(o),``),s.push(`Continue? (Y/n) `),s.join(`
2
2
  `)}async function W(e,t){let n=k({input:t.terminal?.stdin??O.stdin,output:t.terminal?.stdout??O.stdout});n.once(`SIGINT`,()=>n.close());let r=new Promise(e=>n.once(`close`,()=>e(void 0)));try{let t=await Promise.race([n.question(e),r]);if(t===void 0)return;let i=t.trim().toLowerCase();return i===``||i===`y`||i===`yes`}finally{n.close()}}export{P as runTranslate};
@@ -1 +1 @@
1
- import{hashJsonValue as e,hashString as t}from"../content-layer/database/utils/json.js";import{hashContentBytes as n}from"../shared/utils/content-hash.js";import{RBAC_TEAM_ANONYMOUS as r,RBAC_TEAM_AUTHENTICATED as i}from"../server/rbac/types.js";import{isObject as a}from"../shared/utils/is-object.js";import{loadContentLayerConfig as o}from"../content-layer/config.js";import{RUNTIME_SSR_DIRNAME as s,RUNTIME_SSR_ENTRY_FILENAME as c}from"../shared/constants/runtime-layout.js";import{resolveContentLayerContext as l}from"../content-layer/context.js";import{openContentLayerDatabase as u}from"../content-layer/database/connection.js";import{entities as d,pageMarkdown as f,reactPageChecks as p,routeDeps as m,routes as h}from"../content-layer/database/schema.js";import{createRouteQueryEvaluator as g}from"../content-layer/plugins/utils/route-index.js";import{APP_DATA_ENTITY_KEY as _}from"../shared/constants/app-data.js";import{SIDEBAR_BACK_LINK_ROUTE_DEP_KEY as v,SIDEBAR_BREADCRUMBS_ROUTE_DEP_KEY as y,SIDEBAR_ROUTE_DEP_KEY as b,isLocalizedSidebarDepKey as x}from"../shared/constants/route-deps.js";import{SOURCE_TEMPLATE_PREFIX as S}from"../shared/constants/template-ids.js";import{createContentPlugins as C}from"../content-layer/plugins/create-content-plugins.js";import"../content-layer/plugins/index.js";import{readPackageVersion as w}from"./output.js";import{createMarkdownCopyRule as ee}from"../content-layer/markdown-copy-rule.js";import"../content-layer/server/database.js";import{extractRbacTeamNames as te}from"../server/auth/dev-login-teams.js";import{resolvePageOwnTitle as T,resolveRuntimePage as E}from"../server/content.js";import{collectChunks as D,loadTemplateManifestKeys as O,loadViteManifest as k}from"../server/manifest-assets.js";import{loadRuntimeConfig as A}from"../server/runtime-config.js";import{loadContentLayerState as j}from"../content-layer/context-state.js";import{createProblem as M}from"../content-layer/problems/codes.js";import{toRbacTeams as N}from"../content-layer/ingest/rbac-teams.js";import{htmlToMarkdownDoc as P}from"../content-layer/markdown/search/html-to-markdown.js";import{pathToFileURL as ne}from"node:url";import{join as F}from"node:path";import{readFile as re}from"node:fs/promises";import{and as I,asc as ie,eq as L,gte as R,inArray as z,lt as B}from"drizzle-orm";const V=/\.page\.tsx?$/i,H=/-[\w-]{8}\.mjs\b/g,U=`http://localhost`,W=`react-page:markdown:`,G=[b,v,y];async function K(e){let t=[...e.sourceTemplates].filter(e=>V.test(e));if(t.length===0)return await e.database?.db.transaction(async e=>{await e.delete(p),await e.delete(f).where(ae())}),{pageCount:0,renderedCount:0,problems:[]};let n=e.database===void 0,a=e.database??await u({contentDir:e.contentDir,databaseUrl:e.databaseUrl,logger:e.logger,runMigrations:!1});try{let n=l({contentDir:e.contentDir,context:e.context,logger:e.logger,plugins:e.context?[]:C(e.contentDir)}),{config:u}=await o({context:n}),d=await j({context:n,database:a}),m=await A(a),h=F(e.outputDir,s),_,v=await oe(a,t),y=await se({config:m,database:a,pages:v,ssrDir:h}),b=await le(a),x=g(d,u).index(),S=ee(u),w={...m,access:{...m.access,rbac:void 0}},T=[r,i,...te(m)],E=[],D=/* @__PURE__ */ new Map,O=[];for(let t of v){let{path:r,slug:i}=t,o=y.get(q(t));if(o!==void 0&&b.get(q(t))===o)continue;_??=await import(ne(F(h,c)).href);let s={context:n,database:a,ssr:_,slug:i,logger:e.logger},l=(await Q({...s,config:w,teams:T}))?.error;if(l!==void 0){D.set(q(t),void 0),E.push(M({code:`react-page/render-failed`,message:`Runtime error${t.locale?` in locale ${t.locale}`:``}: ${l.message}`,location:{filePath:r}}));continue}D.set(q(t),o);for(let n of t.slugs){let i=x.get(n),a=i&&S.allows(i)?ue(i.access):void 0;if(i===void 0||a===void 0)continue;let c=await Q({...s,slug:n,config:m,teams:a});if(c?.error!==void 0)e.logger?.warn(`No Markdown for the React page ${r} at ${n}: ${c.error.message}`);else if(c!==null){let e=q(t);O.push(...await de({key:e,html:c.html,route:i,fingerprint:o}))}}}let k=[...b.keys()].filter(e=>!y.has(e));if(D.size>0||k.length>0){let e=new Map([...b].filter(([e])=>y.has(e)));for(let[t,n]of D)n===void 0?e.delete(t):e.set(t,n);let t=[...e].map(([e,t])=>Object.assign(J(e),{fingerprint:t})),n=[...k,...D.keys()].map(Y);await a.db.transaction(async e=>{await e.delete(p);for(let n=0;n<t.length;n+=500)await e.insert(p).values(t.slice(n,n+500));for(let t of X(n))await e.delete(f).where(z(f.entityKey,t));for(let t=0;t<O.length;t+=500)await e.insert(f).values(O.slice(t,t+500))})}return{pageCount:v.length,renderedCount:D.size,problems:E}}finally{n&&await a.close()}}function q(e){return`${e.path}\u0000${e.locale}`}function J(e){let t=e.lastIndexOf(`\0`);return{path:e.slice(0,t),locale:e.slice(t+1)}}function Y(e){let{path:t,locale:n}=J(e);return`${W}${n}/${t}`}function ae(){return I(R(f.entityKey,W),B(f.entityKey,`${W.slice(0,-1)};`))}async function oe(e,t){let n=[];for(let r of X(t.map(e=>`${S}${e}`)))n.push(...await e.db.select({slug:h.slug,locale:h.locale,isFallback:h.isFallback,canonicalSlug:h.canonicalSlug,template:h.template,metadata:h.metadata}).from(h).where(z(h.template,r)).orderBy(ie(h.id)));let r=/* @__PURE__ */ new Map;for(let{isFallback:e,canonicalSlug:t,...i}of n){let n={path:i.template.slice(S.length),slugs:[i.slug],depsSlug:e&&t?t:i.slug,...i},a=r.get(q(n));a?a.slugs.push(i.slug):r.set(q(n),n)}return[...r.values()]}async function se(t){let[n,r]=await Promise.all([k(t.ssrDir),O(t.ssrDir)]),i=await ce(t.database,t.pages.map(e=>e.depsSlug)),a=Z(t.ssrDir),o=async(e,t)=>(await Promise.all([...D(n,e,t)].map(a))).sort(),s=Object.values(n).find(e=>e.isEntry),[l]=await t.database.db.select({dataHash:d.dataHash}).from(d).where(I(L(d.isCurrent,1),L(d.key,_))),u={version:w(),config:e(t.config),appData:l?.dataHash??null,entry:await a(c),entryChunks:s?await o(s):[]},f=/* @__PURE__ */ new Map;for(let a of t.pages){let t=n[r[a.template]??``];f.set(q(a),t===void 0?void 0:e({...u,chunks:await o(t,{dynamicImports:!0}),route:{slug:a.slug,template:a.template,metadata:a.metadata},deps:i.get(a.depsSlug)??[]}))}return f}async function ce(e,t){let n=[];for(let r of X(t))n.push(...await e.db.select().from(m).where(z(m.routeSlug,r)));let r=n.filter(e=>!G.includes(e.key)&&!x(e.key)),i=[...new Set(r.filter(e=>e.dependencyType===`entity`).map(e=>e.target))],a=/* @__PURE__ */ new Map;for(let t of X(i)){let n=await e.db.select({key:d.key,dataHash:d.dataHash}).from(d).where(I(L(d.isCurrent,1),z(d.key,t)));for(let e of n)a.set(e.key,e.dataHash)}let o=/* @__PURE__ */ new Map;for(let e of r.sort((e,t)=>e.key<t.key?-1:+(e.key>t.key))){let t=o.get(e.routeSlug)??[];t.push({key:e.key,type:e.dependencyType,target:e.target,args:e.args,dataHash:a.get(e.target)??null}),o.set(e.routeSlug,t)}return o}function*X(e){for(let t=0;t<e.length;t+=50)yield e.slice(t,t+50)}function Z(e){let n=/* @__PURE__ */ new Map;return r=>{let i=n.get(r);return i===void 0&&(i=re(F(e,r),`utf8`).then(e=>t(e.replace(H,`.mjs`))),n.set(r,i)),i}}async function le(e){let t=await e.db.select().from(p);return new Map(t.map(e=>[q(e),e.fingerprint]))}function ue(e){let t=N(e);if(t.includes(`anonymous`))return[r];if(t.includes(`authenticated`))return[i]}async function de(e){let{chunks:t,headings:r}=P(e.html),{metadata:i}=e.route,o=a(i.seo)?i.seo:{},s=a(i.search)?i.search:{},c=[o.description,i.description].find(e=>typeof e==`string`&&e.trim()!==``),l=T(i,typeof s.title==`string`?s.title.trim():void 0)??r.find(e=>e!==null)?.heading??null,u=w();return Promise.all(t.map(async(t,i)=>({entityKey:Y(e.key),chunkIndex:i,routeSlug:e.route.slug,text:t,heading:r[i]?.heading??null,anchor:r[i]?.anchor??null,title:l,description:c??null,rbacTeams:N(e.route.access),hash:await n(new TextEncoder().encode(t)),sourceHash:e.fingerprint??``,pluginVersion:u})))}async function Q(e){try{let t=await $(e,e.slug);if(t.page.status===302&&t.redirectTo!==void 0&&(t=await $(e,t.redirectTo)),t.page.status!==200)return null;let n=await e.ssr.render(t.page,t.resolvedLoaderData,t.url,U),r=await new Response(n.stream).text();return n.renderError?{error:n.renderError}:{html:r}}catch(e){return{error:e instanceof Error?e:Error(String(e))}}}async function $(e,t){let n=`${U}${t}`,r={headers:{},ip:null,method:`GET`,teams:e.teams,url:n,userAgent:null};return{...await E({config:e.config,contentDir:e.context.contentDir,context:e.context,database:e.database,logger:e.logger,request:r,url:n}),url:n}}export{K as validateReactPages};
1
+ import{hashJsonValue as e,hashString as t}from"../content-layer/database/utils/json.js";import{hashContentBytes as n}from"../shared/utils/content-hash.js";import{RBAC_TEAM_ANONYMOUS as r,RBAC_TEAM_AUTHENTICATED as i}from"../server/rbac/types.js";import{isObject as a}from"../shared/utils/is-object.js";import{getProcessEnv as o}from"../shared/public-env.js";import{entities as s,pageMarkdown as c,reactPageChecks as l,routeDeps as u,routes as d}from"../content-layer/database/schema.js";import{loadContentLayerConfig as f}from"../content-layer/config.js";import{RUNTIME_SSR_DIRNAME as p,RUNTIME_SSR_ENTRY_FILENAME as m}from"../shared/constants/runtime-layout.js";import{resolveContentLayerContext as h}from"../content-layer/context.js";import{openContentLayerDatabase as g}from"../content-layer/database/connection.js";import{createRouteQueryEvaluator as ee}from"../content-layer/plugins/utils/route-index.js";import{APP_DATA_ENTITY_KEY as _}from"../shared/constants/app-data.js";import{SIDEBAR_BACK_LINK_ROUTE_DEP_KEY as v,SIDEBAR_BREADCRUMBS_ROUTE_DEP_KEY as y,SIDEBAR_ROUTE_DEP_KEY as b,isLocalizedSidebarDepKey as x}from"../shared/constants/route-deps.js";import{SOURCE_TEMPLATE_PREFIX as S}from"../shared/constants/template-ids.js";import{createContentPlugins as C}from"../content-layer/plugins/create-content-plugins.js";import"../content-layer/plugins/index.js";import{readPackageVersion as w}from"./output.js";import{createProblem as T}from"../content-layer/problems/codes.js";import"../content-layer/server/database.js";import{loadContentLayerState as E}from"../content-layer/context-state.js";import{toRbacTeams as D}from"../content-layer/ingest/rbac-teams.js";import{createMarkdownCopyRule as O}from"../content-layer/markdown-copy-rule.js";import{extractRbacTeamNames as k}from"../server/auth/dev-login-teams.js";import{resolvePageOwnTitle as A,resolveRuntimePage as j}from"../server/content.js";import{collectChunks as M,loadTemplateManifestKeys as N,loadViteManifest as te}from"../server/manifest-assets.js";import{loadRuntimeConfig as ne}from"../server/runtime-config.js";import{htmlToMarkdownDoc as re}from"../content-layer/markdown/search/html-to-markdown.js";import{pathToFileURL as ie}from"node:url";import{join as P}from"node:path";import{readFile as F}from"node:fs/promises";import{and as I,asc as L,eq as R,gte as z,inArray as B,lt as V}from"drizzle-orm";const H=/\.page\.tsx?$/i,U=/-[\w-]{8}\.mjs\b/g,W=`http://localhost`,G=`react-page:markdown:`,K=[b,v,y];async function q(e){let t=[...e.sourceTemplates].filter(e=>H.test(e));if(t.length===0)return await e.database?.db.transaction(async e=>{await e.delete(l),await e.delete(c).where(ae())}),{pageCount:0,renderedCount:0,problems:[]};let n=e.database===void 0,a=e.database??await g({contentDir:e.contentDir,databaseUrl:e.databaseUrl,logger:e.logger,runMigrations:!1});try{let n=h({contentDir:e.contentDir,context:e.context,logger:e.logger,plugins:e.context?[]:C(e.contentDir)}),{config:s}=await f({context:n}),u=await E({context:n,database:a}),{config:d}=await ne(a,o()),g=P(e.outputDir,p),_,v=await oe(a,t),y=await se({config:d,database:a,pages:v,ssrDir:g}),b=await ue(a),x=ee(u,s).index(),S=O(s),w={...d,access:{...d.access,rbac:void 0}},D=[r,i,...k(d)],A=[],j=/* @__PURE__ */ new Map,M=[];for(let t of v){let{path:r,slug:i}=t,o=y.get(J(t));if(o!==void 0&&b.get(J(t))===o)continue;_??=await import(ie(P(g,m)).href);let s={context:n,database:a,ssr:_,slug:i,logger:e.logger},c=(await Q({...s,config:w,teams:D}))?.error;if(c!==void 0){j.set(J(t),void 0),A.push(T({code:`react-page/render-failed`,message:`Runtime error${t.locale?` in locale ${t.locale}`:``}: ${c.message}`,location:{filePath:r}}));continue}j.set(J(t),o);for(let n of t.slugs){let i=x.get(n),a=i&&S.allows(i)?de(i.access):void 0;if(i===void 0||a===void 0)continue;let c=await Q({...s,slug:n,config:d,teams:a});if(c?.error!==void 0)e.logger?.warn(`No Markdown for the React page ${r} at ${n}: ${c.error.message}`);else if(c!==null){let e=J(t);M.push(...await fe({key:e,html:c.html,route:i,fingerprint:o}))}}}let N=[...b.keys()].filter(e=>!y.has(e));if(j.size>0||N.length>0){let e=new Map([...b].filter(([e])=>y.has(e)));for(let[t,n]of j)n===void 0?e.delete(t):e.set(t,n);let t=[...e].map(([e,t])=>Object.assign(Y(e),{fingerprint:t})),n=[...N,...j.keys()].map(X);await a.db.transaction(async e=>{await e.delete(l);for(let n=0;n<t.length;n+=500)await e.insert(l).values(t.slice(n,n+500));for(let t of Z(n))await e.delete(c).where(B(c.entityKey,t));for(let t=0;t<M.length;t+=500)await e.insert(c).values(M.slice(t,t+500))})}return{pageCount:v.length,renderedCount:j.size,problems:A}}finally{n&&await a.close()}}function J(e){return`${e.path}\u0000${e.locale}`}function Y(e){let t=e.lastIndexOf(`\0`);return{path:e.slice(0,t),locale:e.slice(t+1)}}function X(e){let{path:t,locale:n}=Y(e);return`${G}${n}/${t}`}function ae(){return I(z(c.entityKey,G),V(c.entityKey,`${G.slice(0,-1)};`))}async function oe(e,t){let n=[];for(let r of Z(t.map(e=>`${S}${e}`)))n.push(...await e.db.select({slug:d.slug,locale:d.locale,isFallback:d.isFallback,canonicalSlug:d.canonicalSlug,template:d.template,metadata:d.metadata}).from(d).where(B(d.template,r)).orderBy(L(d.id)));let r=/* @__PURE__ */ new Map;for(let{isFallback:e,canonicalSlug:t,...i}of n){let n={path:i.template.slice(S.length),slugs:[i.slug],depsSlug:e&&t?t:i.slug,...i},a=r.get(J(n));a?a.slugs.push(i.slug):r.set(J(n),n)}return[...r.values()]}async function se(t){let[n,r]=await Promise.all([te(t.ssrDir),N(t.ssrDir)]),i=await ce(t.database,t.pages.map(e=>e.depsSlug)),a=le(t.ssrDir),o=async(e,t)=>(await Promise.all([...M(n,e,t)].map(a))).sort(),c=Object.values(n).find(e=>e.isEntry),[l]=await t.database.db.select({dataHash:s.dataHash}).from(s).where(I(R(s.isCurrent,1),R(s.key,_))),u={version:w(),config:e(t.config),appData:l?.dataHash??null,entry:await a(m),entryChunks:c?await o(c):[]},d=/* @__PURE__ */ new Map;for(let a of t.pages){let t=n[r[a.template]??``];d.set(J(a),t===void 0?void 0:e({...u,chunks:await o(t,{dynamicImports:!0}),route:{slug:a.slug,template:a.template,metadata:a.metadata},deps:i.get(a.depsSlug)??[]}))}return d}async function ce(e,t){let n=[];for(let r of Z(t))n.push(...await e.db.select().from(u).where(B(u.routeSlug,r)));let r=n.filter(e=>!K.includes(e.key)&&!x(e.key)),i=[...new Set(r.filter(e=>e.dependencyType===`entity`).map(e=>e.target))],a=/* @__PURE__ */ new Map;for(let t of Z(i)){let n=await e.db.select({key:s.key,dataHash:s.dataHash}).from(s).where(I(R(s.isCurrent,1),B(s.key,t)));for(let e of n)a.set(e.key,e.dataHash)}let o=/* @__PURE__ */ new Map;for(let e of r.sort((e,t)=>e.key<t.key?-1:+(e.key>t.key))){let t=o.get(e.routeSlug)??[];t.push({key:e.key,type:e.dependencyType,target:e.target,args:e.args,dataHash:a.get(e.target)??null}),o.set(e.routeSlug,t)}return o}function*Z(e){for(let t=0;t<e.length;t+=50)yield e.slice(t,t+50)}function le(e){let n=/* @__PURE__ */ new Map;return r=>{let i=n.get(r);return i===void 0&&(i=F(P(e,r),`utf8`).then(e=>t(e.replace(U,`.mjs`))),n.set(r,i)),i}}async function ue(e){let t=await e.db.select().from(l);return new Map(t.map(e=>[J(e),e.fingerprint]))}function de(e){let t=D(e);if(t.includes(`anonymous`))return[r];if(t.includes(`authenticated`))return[i]}async function fe(e){let{chunks:t,headings:r}=re(e.html),{metadata:i}=e.route,o=a(i.seo)?i.seo:{},s=a(i.search)?i.search:{},c=[o.description,i.description].find(e=>typeof e==`string`&&e.trim()!==``),l=A(i,typeof s.title==`string`?s.title.trim():void 0)??r.find(e=>e!==null)?.heading??null,u=w();return Promise.all(t.map(async(t,i)=>({entityKey:X(e.key),chunkIndex:i,routeSlug:e.route.slug,text:t,heading:r[i]?.heading??null,anchor:r[i]?.anchor??null,title:l,description:c??null,rbacTeams:D(e.route.access),hash:await n(new TextEncoder().encode(t)),sourceHash:e.fingerprint??``,pluginVersion:u})))}async function Q(e){try{let t=await $(e,e.slug);if(t.page.status===302&&t.redirectTo!==void 0&&(t=await $(e,t.redirectTo)),t.page.status!==200)return null;let n=await e.ssr.render(t.page,t.resolvedLoaderData,t.url,W),r=await new Response(n.stream).text();return n.renderError?{error:n.renderError}:{html:r}}catch(e){return{error:e instanceof Error?e:Error(String(e))}}}async function $(e,t){let n=`${W}${t}`,r={headers:{},ip:null,method:`GET`,teams:e.teams,url:n,userAgent:null};return{...await j({config:e.config,contentDir:e.context.contentDir,context:e.context,database:e.database,logger:e.logger,request:r,url:n}),url:n}}export{q as validateReactPages};
@@ -1,3 +1,4 @@
1
+ import { type EnvLookup } from '@redocly/config';
1
2
  import type { ProblemDraft } from './problems/types.js';
2
3
  /**
3
4
  * The JSON Schema keywords the config schemas use; `sanitizeConfig` implements these and
@@ -39,6 +40,10 @@ export type SanitizedConfig = {
39
40
  * `value` without the settings `schema` rejects; each removed setting is one
40
41
  * `configuration/invalid` error. An unknown key inside a known section stays and is one
41
42
  * `configuration/ignored` warning; a conflict the schema forbids stays and is an error.
42
- * Apart from those kept keys, the result validates against the schema.
43
+ * Apart from those kept keys, the result validates against the schema. A string with a
44
+ * `{{ process.env.X }}` reference is judged by its value in `env` and kept as written, so
45
+ * the result resolves again against another environment.
43
46
  */
44
- export declare function sanitizeConfig(schema: ConfigSchema, value: Record<string, unknown>): SanitizedConfig;
47
+ export declare function sanitizeConfig(schema: ConfigSchema, value: Record<string, unknown>, options?: {
48
+ env?: EnvLookup;
49
+ }): SanitizedConfig;
@@ -1 +1 @@
1
- import{isObject as e}from"../shared/utils/is-object.js";import{productConfigOverrideSchema as t,rootRedoclyConfigSchema as n}from"@redocly/config";const r=n.properties,i={type:`string`,pattern:`\\S`},a={...r.apis.additionalProperties,required:[`root`]},o={...r.scripts.properties.head.items,required:[`src`]},s=r.redirects.additionalProperties,c=r.theme.properties.asyncapi,l={type:`object`,additionalProperties:a},u={...r.scripts,properties:{head:{type:`array`,items:o},body:{type:`array`,items:o}}},d={...r.redirects,propertyNames:i,additionalProperties:{...s,properties:{...s.properties,to:i},required:[`to`]}},f={type:`object`,properties:{include:{type:`array`,items:{type:`string`,minLength:1}},max:{type:`integer`,minimum:1}},additionalProperties:!1},p={type:`object`,properties:{anchors:{type:`object`,properties:{hide:{type:`boolean`}},additionalProperties:!1}},additionalProperties:!1},m={...n,properties:{...r,apis:l,asyncapi:c,linkChecker:p,redirects:d,revisions:f,scripts:u},additionalProperties:!0},h={...t,properties:{...t.properties,apis:l,asyncapi:c,graphql:r.graphql}},g={type:`object`,properties:{banner:r.banner}},_=Symbol(`drop`);function v(t,n){let r=[],i=y(t,structuredClone(n),``,r);return{value:e(i)?i:{},problems:r}}function y(t,n,r,i){if(t===!0)return n;if(t===!1)return k(i,r,`is not allowed`);let a=b(t,n);if(a!==void 0)return k(i,r,a);let o=n;return e(n)?o=x(t,n,r,i):Array.isArray(n)&&(o=C(t,n,r,i)),o!==_&&t.oneOf&&(o=w(t.oneOf,t.discriminator,n,o,r,i)),o!==_&&t.not!==void 0&&T(t.not,o)&&i.push({code:`configuration/invalid`,message:`${A(r)} ${O(t.not)}.`}),o}function b(e,t){if(e.type!==void 0&&!E(t,e.type))return`must be ${e.type}`;if(e.enum&&!e.enum.some(e=>D(e,t)))return`must be one of: ${e.enum.join(`, `)}`;if(e.const!==void 0&&!D(e.const,t))return`must be ${JSON.stringify(e.const)}`;if(typeof t==`string`){if(e.minLength!==void 0&&t.length<e.minLength)return e.minLength===1?`must not be empty`:`must have at least ${e.minLength} characters`;if(e.pattern!==void 0&&!new RegExp(e.pattern,`u`).test(t))return e.pattern===`\\S`?`must not be empty`:`must match the pattern ${e.pattern}`}if(typeof t==`number`&&e.minimum!==void 0&&t<e.minimum)return`must be at least ${e.minimum}`}function x(e,t,n,r){let i=[];for(let[a,o]of Object.entries(t)){let t=j(n,a);if(e.propertyNames!==void 0&&!T(e.propertyNames,a)){k(r,t,`has an invalid name`);continue}let s=S(e,a);if(s===void 0){r.push({code:`configuration/ignored`,message:`\`${t}\` is not a known option and is ignored.`}),i.push([a,o]);continue}let c=y(s,o,t,r);c!==_&&i.push([a,c])}let a=Object.fromEntries(i),o=e.required??[],s=o.find(e=>!Object.hasOwn(t,e));if(s!==void 0)return k(r,n,`must have required property '${s}'`);if(e.minProperties!==void 0){if(Object.keys(t).length<e.minProperties)return k(r,n,e.minProperties===1?`must not be empty`:`must have at least ${e.minProperties} properties`);if(Object.keys(a).length<e.minProperties)return _}return o.every(e=>Object.hasOwn(a,e))?a:_}function S(e,t){if(e.properties&&Object.hasOwn(e.properties,t))return e.properties[t];for(let[n,r]of Object.entries(e.patternProperties??{}))if(new RegExp(n,`u`).test(t))return r;return e.additionalProperties===!1?void 0:e.additionalProperties??!0}function C(e,t,n,r){let{items:i}=e,a=i===void 0?t:t.flatMap((e,t)=>{let a=y(i,e,j(n,t),r);return a===_?[]:[a]});if(e.minItems!==void 0){if(t.length<e.minItems)return k(r,n,e.minItems===1?`must not be empty`:`must have at least ${e.minItems} items`);if(a.length<e.minItems)return _}return e.uniqueItems&&new Set(t.map(e=>JSON.stringify(e))).size<t.length?k(r,n,`must not have duplicate items`):a}function w(t,n,r,i,a,o){if(n){let r=n.propertyName,s=e(i)?i[r]:void 0,c=t.find(e=>{let t=typeof e==`object`?e.properties?.[r]:void 0;return s!==void 0&&typeof t==`object`&&t.const===s});return c===void 0?k(o,a,`has an invalid value`):y(c,i,a,o)}let s=e=>t.filter(t=>T(t,e)).length;return s(r)===1?s(i)===1?i:_:k(o,a,`has an invalid value`)}function T(e,t){let n=[];return y(e,t,``,n),n.length===0}function E(t,n){switch(n){case`object`:return e(t);case`array`:return Array.isArray(t);case`integer`:return Number.isInteger(t);case`number`:return typeof t==`number`&&Number.isFinite(t);default:return typeof t===n}}function D(e,t){return JSON.stringify(e)===JSON.stringify(t)}function O(e){let t=typeof e==`object`?e.required:void 0;return t?`must not set both ${t.map(e=>`\`${e}\``).join(` and `)}`:`has a value that is not allowed`}function k(e,t,n){return e.push({code:`configuration/invalid`,message:`${A(t)} ${n} and is ignored.`}),_}function A(e){return e===``?`The config`:`\`${e}\``}function j(e,t){return typeof t==`number`?`${e}[${t}]`:/^[A-Za-z_$][\w$]*$/.test(t)?e===``?t:`${e}.${t}`:`${e}[${JSON.stringify(t)}]`}export{h as NESTED_CONFIG_SCHEMA,g as PAGE_BANNER_SCHEMA,m as REALM_CONFIG_SCHEMA,v as sanitizeConfig};
1
+ import{isObject as e}from"../shared/utils/is-object.js";import{interpolateEnvVariables as t,productConfigOverrideSchema as n,rootRedoclyConfigSchema as r}from"@redocly/config";const i=r.properties,a={type:`string`,pattern:`\\S`},o={...i.apis.additionalProperties,required:[`root`]},s={...i.scripts.properties.head.items,required:[`src`]},c=i.redirects.additionalProperties,l=i.theme.properties.asyncapi,u={type:`object`,additionalProperties:o},d={...i.scripts,properties:{head:{type:`array`,items:s},body:{type:`array`,items:s}}},f={...i.redirects,propertyNames:a,additionalProperties:{...c,properties:{...c.properties,to:a},required:[`to`]}},p={type:`object`,properties:{include:{type:`array`,items:{type:`string`,minLength:1}},max:{type:`integer`,minimum:1}},additionalProperties:!1},m={type:`object`,properties:{anchors:{type:`object`,properties:{hide:{type:`boolean`}},additionalProperties:!1}},additionalProperties:!1},h={...r,properties:{...i,apis:u,asyncapi:l,linkChecker:m,redirects:f,revisions:p,scripts:d},additionalProperties:!0},g={...n,properties:{...n.properties,apis:u,asyncapi:l,graphql:i.graphql}},_={type:`object`,properties:{banner:i.banner}},v=Symbol(`drop`);function y(n,r,i={}){let{env:a}=i,o={problems:[],resolve:a?e=>t(e,a).value:e=>e},s=b(n,structuredClone(r),``,o);return{value:e(s)?s:{},problems:o.problems}}function b(t,n,r,i){if(t===!0)return n;if(t===!1)return j(i,r,`is not allowed`);let a=S(t,x(n,i));if(a!==void 0)return j(i,r,a);let o=n;return e(n)?o=C(t,n,r,i):Array.isArray(n)&&(o=T(t,n,r,i)),o!==v&&t.oneOf&&(o=E(t.oneOf,t.discriminator,n,o,r,i)),o!==v&&t.not!==void 0&&D(t.not,o,i)&&i.problems.push({code:`configuration/invalid`,message:`${M(r)} ${A(t.not)}.`}),o}function x(e,t){return typeof e==`string`?t.resolve(e):e}function S(e,t){if(e.type!==void 0&&!O(t,e.type))return`must be ${e.type}`;if(e.enum&&!e.enum.some(e=>k(e,t)))return`must be one of: ${e.enum.join(`, `)}`;if(e.const!==void 0&&!k(e.const,t))return`must be ${JSON.stringify(e.const)}`;if(typeof t==`string`){if(e.minLength!==void 0&&t.length<e.minLength)return e.minLength===1?`must not be empty`:`must have at least ${e.minLength} characters`;if(e.pattern!==void 0&&!new RegExp(e.pattern,`u`).test(t))return e.pattern===`\\S`?`must not be empty`:`must match the pattern ${e.pattern}`}if(typeof t==`number`&&e.minimum!==void 0&&t<e.minimum)return`must be at least ${e.minimum}`}function C(e,t,n,r){let i=[];for(let[a,o]of Object.entries(t)){let t=N(n,a);if(e.propertyNames!==void 0&&!D(e.propertyNames,a,r)){j(r,t,`has an invalid name`);continue}let s=w(e,a);if(s===void 0){r.problems.push({code:`configuration/ignored`,message:`\`${t}\` is not a known option and is ignored.`}),i.push([a,o]);continue}let c=b(s,o,t,r);c!==v&&i.push([a,c])}let a=Object.fromEntries(i),o=e.required??[],s=o.find(e=>!Object.hasOwn(t,e));if(s!==void 0)return j(r,n,`must have required property '${s}'`);if(e.minProperties!==void 0){if(Object.keys(t).length<e.minProperties)return j(r,n,e.minProperties===1?`must not be empty`:`must have at least ${e.minProperties} properties`);if(Object.keys(a).length<e.minProperties)return v}return o.every(e=>Object.hasOwn(a,e))?a:v}function w(e,t){if(e.properties&&Object.hasOwn(e.properties,t))return e.properties[t];for(let[n,r]of Object.entries(e.patternProperties??{}))if(new RegExp(n,`u`).test(t))return r;return e.additionalProperties===!1?void 0:e.additionalProperties??!0}function T(e,t,n,r){let{items:i}=e,a=i===void 0?t:t.flatMap((e,t)=>{let a=b(i,e,N(n,t),r);return a===v?[]:[a]});if(e.minItems!==void 0){if(t.length<e.minItems)return j(r,n,e.minItems===1?`must not be empty`:`must have at least ${e.minItems} items`);if(a.length<e.minItems)return v}return e.uniqueItems&&new Set(t.map(e=>JSON.stringify(e))).size<t.length?j(r,n,`must not have duplicate items`):a}function E(t,n,r,i,a,o){if(n){let r=n.propertyName,s=e(i)?x(i[r],o):void 0,c=t.find(e=>{let t=typeof e==`object`?e.properties?.[r]:void 0;return s!==void 0&&typeof t==`object`&&t.const===s});return c===void 0?j(o,a,`has an invalid value`):b(c,i,a,o)}let s=e=>t.filter(t=>D(t,e,o)).length;return s(r)===1?s(i)===1?i:v:j(o,a,`has an invalid value`)}function D(e,t,n){let r={problems:[],resolve:n.resolve};return b(e,t,``,r),r.problems.length===0}function O(t,n){switch(n){case`object`:return e(t);case`array`:return Array.isArray(t);case`integer`:return Number.isInteger(t);case`number`:return typeof t==`number`&&Number.isFinite(t);default:return typeof t===n}}function k(e,t){return JSON.stringify(e)===JSON.stringify(t)}function A(e){let t=typeof e==`object`?e.required:void 0;return t?`must not set both ${t.map(e=>`\`${e}\``).join(` and `)}`:`has a value that is not allowed`}function j(e,t,n){return e.problems.push({code:`configuration/invalid`,message:`${M(t)} ${n} and is ignored.`}),v}function M(e){return e===``?`The config`:`\`${e}\``}function N(e,t){return typeof t==`number`?`${e}[${t}]`:/^[A-Za-z_$][\w$]*$/.test(t)?e===``?t:`${e}.${t}`:`${e}[${JSON.stringify(t)}]`}export{g as NESTED_CONFIG_SCHEMA,_ as PAGE_BANNER_SCHEMA,h as REALM_CONFIG_SCHEMA,y as sanitizeConfig};
@@ -1,5 +1,6 @@
1
1
  import type { PlatformFs } from '../platform/types/fs.js';
2
2
  import { type TeamDirs } from '../server/rbac/team-templates.js';
3
+ import { type ProcessEnv } from '../shared/public-env.js';
3
4
  import type { NestedConfig, RealmConfig } from '../shared/types/config.js';
4
5
  import type { ContentLayerContext } from './context.js';
5
6
  import type { ProblemDraft } from './problems/types.js';
@@ -14,7 +15,14 @@ export type ConfigFileRef = {
14
15
  };
15
16
  export type LoadedRedoclyConfig = {
16
17
  absolutePath: string | null;
18
+ /** The effective config: `siteConfig` with its references resolved against the build environment. */
17
19
  config: RealmConfig;
20
+ /**
21
+ * The normalized config with its `{{ process.env.X }}` references kept, except in `access`,
22
+ * `l10n` and `redirects`: what ingest stores, so a host resolves them against its own
23
+ * environment.
24
+ */
25
+ siteConfig: RealmConfig;
18
26
  path: string | null;
19
27
  hash: string | null;
20
28
  /** The files the config read (`$ref` targets, `env` overrides, `details.path`); a change to one is a config change. */
@@ -24,18 +32,20 @@ export type LoadedRedoclyConfig = {
24
32
  };
25
33
  type ConfigObject = Record<string, unknown>;
26
34
  /**
27
- * The effective config: the file's `env` overrides for the current branch and
28
- * environment merged in, then `{{ process.env.X }}` references replaced, then the
29
- * features that the `PLAN_GATES` plan lacks turned off, then the access that
30
- * `REDOCLY_ENFORCE_LOGIN` and `REDOCLY_ENFORCE_RESIDENCY` enforce applied.
35
+ * The config: the file's `env` overrides for the current branch and environment merged
36
+ * in, the features that the `PLAN_GATES` plan lacks turned off, and the access that
37
+ * `REDOCLY_ENFORCE_LOGIN` and `REDOCLY_ENFORCE_RESIDENCY` enforce applied. `siteConfig`
38
+ * keeps the `{{ process.env.X }}` references, judged by their values in the environment;
39
+ * `config` has them replaced. A reference reads the view a host gives it (`readProjectEnv`).
31
40
  */
32
41
  export declare function loadRedoclyConfig(contentDir: string, fs: PlatformFs): Promise<LoadedRedoclyConfig>;
33
42
  /**
34
- * Whether the effective config differs from `stored`, the one the last ingest kept; `null`
35
- * (no ingest yet) counts as changed. The effective config also reads the environment and
36
- * the `@l10n/` and `{folder}` directories, so a change there counts like a file edit.
43
+ * Whether the effective config differs from the one whose digest the last ingest stored;
44
+ * `null` (no ingest yet, or a row an older ingest wrote) counts as changed. The effective config
45
+ * also reads the environment and the `@l10n/` and `{folder}` directories, so a change there
46
+ * counts like a file edit.
37
47
  */
38
- export declare function isConfigChanged(config: RealmConfig, stored: RealmConfig | null): boolean;
48
+ export declare function isConfigChanged(config: RealmConfig, storedHash: string | null): boolean;
39
49
  export declare function loadContentLayerConfig(options: {
40
50
  context: ContentLayerContext;
41
51
  force?: boolean;
@@ -64,7 +74,9 @@ export declare function deepMergeConfig(base: ConfigObject, override: ConfigObje
64
74
  * The config every consumer reads: the deprecated root access keys move into `access.*`
65
75
  * (an `access.*` value wins), `reunite` and `access.rbac.reunite` move to `platform` (a
66
76
  * `platform` value wins), the `mcp.docs` options move into `mcp`, settings the config
67
- * schema rejects are removed, `access.rbac` `{folder}` rules are written per team directory,
77
+ * schema rejects are removed (a `{{ process.env.X }}` string is judged by its value in `env`
78
+ * and kept as written, except in `access`, `l10n` and `redirects`, which are resolved),
79
+ * `access.rbac` `{folder}` rules are written per team directory,
68
80
  * `access.rbac.content` and `redirects` cover every content locale, `access.requiresLogin`
69
81
  * follows the rbac rules when `access.rbac` is set, and the `PUBLIC_*` environment is
70
82
  * attached. `report` receives one problem per removed, ignored, or deprecated setting.
@@ -72,6 +84,7 @@ export declare function deepMergeConfig(base: ConfigObject, override: ConfigObje
72
84
  export declare function normalizeRedoclyConfig(config: Record<string, unknown>, options?: {
73
85
  dirLocales?: readonly string[];
74
86
  teamDirs?: TeamDirs;
87
+ env?: ProcessEnv;
75
88
  report?: (problem: ProblemDraft) => void;
76
89
  }): RealmConfig;
77
90
  export declare function createEmptyRealmConfig(): RealmConfig;
@@ -1 +1 @@
1
- import{toJsonObject as e,toJsonValue as t}from"./database/utils/json.js";import{hashContentBytes as n}from"../shared/utils/content-hash.js";import{isClosedToAnonymous as r,parseRbacConfigData as i}from"../server/rbac/engine.js";import{listL10nDirs as a,resolveLocaleContext as o}from"../shared/utils/l10n.js";import{expandConfigRbacForL10n as s}from"../server/rbac/l10n-rules.js";import{expandConfigRbacTeamTemplates as c,listTeamDirs as l,teamTemplatePrefixes as u}from"../server/rbac/team-templates.js";import{getProcessEnv as d,getPublicEnv as f,resolveRedoclyEnvironment as p,sanitizeBranchName as m}from"../shared/public-env.js";import{resolveContentPath as h}from"../shared/utils/resolve-content-path.js";import{resolveConfigRedirects as g}from"./config-redirects.js";import{NESTED_CONFIG_SCHEMA as _,REALM_CONFIG_SCHEMA as v,sanitizeConfig as y}from"./config-schema.js";import{applyEnforcedAccess as b}from"./enforced-access.js";import{applyPlanGates as x}from"./plan-gates.js";import{resolve as S}from"node:path";import{interpolateEnvVariables as C}from"@redocly/config";import w from"js-yaml";const T=[`redocly.yaml`,`redocly.yml`],E=`redocly.yaml`;async function D(e,t){let r=await Q(e,t),i=d();if(!r){let e=[];return{absolutePath:null,config:b(x($(),i,t=>e.push({code:`configuration/ignored`,message:t})),i),path:null,hash:null,refs:[],problems:e}}let o=await t.readBinaryFile(r.absolutePath),s=[],c=[],f=[],p=N(new TextDecoder().decode(o),r.path),m=[],h={contentDir:e,fs:t,refs:f,warnings:s,errors:c},g=await I(await P(p,{...h,env:i,deprecations:m}),``,h),{value:_,unsetVars:v}=C(g,i);for(let e of v)s.push(`The config references process.env.${e}, which is not set.`);let y=X(await B(_,h)),S={filePath:r.path},w=[...s.map(e=>({code:`configuration/ignored`,message:e,location:S})),...[...new Set(m)].map(e=>({code:`configuration/deprecated`,message:e,location:S})),...c.map(e=>({code:`configuration/invalid`,severity:`error`,message:e,location:S}))],T=H(y.access)?y.access.rbac:void 0,E=G(y,{dirLocales:await a(e,t),teamDirs:await l(e,t,u(H(T)?T:{})),report:e=>w.push({...e,location:S})});return{...r,config:b(x(E,i,e=>w.push({code:`configuration/ignored`,message:e,location:S})),i),hash:await n(o),refs:f,problems:w}}function O(e,t){return t===null||JSON.stringify(e)!==JSON.stringify(t)}async function k(e){if(e.context.configLoaded&&e.force!==!0)return{absolutePath:e.context.configFilePath?S(e.context.contentDir,e.context.configFilePath):null,config:e.context.config,path:e.context.configFilePath,hash:e.context.configHash,refs:e.context.configRefs,problems:[]};let t=await D(e.context.contentDir,e.context.platform.fs);return e.context.config=t.config,e.context.configFilePath=t.path,e.context.configHash=t.hash,e.context.configRefs=t.refs,e.context.configLoaded=!0,t}function A(e,t){let n=C(N(e,t),d()).value,{value:r,problems:i}=y(_,n);for(let e of i)e.location={filePath:t};return{config:r,problems:i}}function j(e){return e.endsWith(`/${E}`)}async function M(e){let t=[];for(let n of e.paths)try{let r=await e.fs.readFile(S(e.contentDir,n));t.push(...A(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 N(t,n){let r=w.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 P(e,t){let{env:n,...r}=e;if(!H(n))return e;let i=t.env.PUBLIC_REDOCLY_BRANCH_NAME,a=[...i?[`branch.${m(i)}`]:[],p(t.env.REDOCLY_ENV)],o=e=>t.deprecations.push(e),s=K(r,o);for(let e of a){let r=await F(n[e],e,t);r&&(s=V(s,K(r,o)))}return s}async function F(e,t,n){if(!H(e))return null;if(typeof e.$ref!=`string`)return e;let{$ref:r,...i}=e,a=`env.${t}`,o=L(await R(r,a,n),i,a,n);return H(o)?o:null}async function I(e,t,n){if(Array.isArray(e))return Promise.all(e.map((e,r)=>I(e,`${t}[${r}]`,n)));if(!H(e))return e;if(typeof e.$ref==`string`){let{$ref:r,...i}=e;return L(await R(r,t,n),await I(i,t,n),t,n)}let r={};for(let[i,a]of Object.entries(e))r[i]=await I(a,t===``?i:`${t}.${i}`,n);return r}function L(e,t,n,r){if(Object.keys(t).length===0)return e;if(H(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 R(e,n,r){return z(e,`${n} $ref`,r,e=>t(w.load(e)))}async function z(e,t,r,i,a=`warning`){let o=a===`error`?r.errors:r.warnings,s=h(e,T[0]);if(s===null)return o.push(`${t} "${e}" escapes the content root.`),null;try{let e=await r.fs.readBinaryFile(S(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 B(e,t){let{seo:n}=e;if(!H(n)||!H(n.llmstxt)||!H(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 z(r,`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,content:a}};return{...e,seo:{...n,llmstxt:o}}}function V(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]=H(t)&&H(r)?V(t,r):r}return n}function H(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}const U=[`hide`,`name`,`ignore`,`publicEndpoint`],W=[`requiresLogin`,`rbac`,`sso`,`idps`,`logoutReturnUrl`,`residency`];function G(e,t={}){let n=t.report??(()=>{}),r=t.dirLocales??[],i=K(e,e=>n({code:`configuration/deprecated`,message:e}));H(i.mcp)&&i.mcp.docs!==void 0&&n({code:`configuration/deprecated`,message:`The 'mcp.docs' property is deprecated. Use the 'mcp' properties instead.`});let a=y(v,i);for(let e of a.problems)n(e);let{redirects:l,access:u,...d}=s(c(a.value,t.teamDirs??{},n),r),p={...d,publicEnv:f()};u&&(p.access=Z(u,n));let m=g(l,o(d.l10n,r));return m&&(p.redirects=m),p}function K(e,t){return Y(q(X(e),t))}function q(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=J(e));let{access:r}=n;return H(r)&&H(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:J(r.rbac)}}),n}function J(e){let{reunite:t,...n}=e;return{...n,platform:e.platform??t}}function Y(e){let{mcp:t}=e;if(!H(t))return e;let{docs:n,...r}=t;if(!H(n))return e;let i={...n};for(let e of U){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 X(e){let t=W.map(t=>[t,e[t]]).filter(([,e])=>e!==void 0);if(t.length===0)return e;let n={...e},r=H(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 Z(e,t){let n=e.rbac?i(e.rbac,e=>t({code:`configuration/invalid`,message:e})):null;return n?(e.requiresLogin===!0&&t({code:`configuration/ignored`,message:`access.requiresLogin is ignored because access.rbac is also configured — the two are mutually exclusive. Remove one.`}),{...e,requiresLogin:r(n)}):e}async function Q(e,t){for(let n of T){let r=S(e,n);if(await t.exists(r))return{absolutePath:r,path:n}}return null}function $(){return G({})}export{E as NESTED_CONFIG_FILENAME,T as REDOCLY_CONFIG_FILENAMES,$ as createEmptyRealmConfig,V as deepMergeConfig,O as isConfigChanged,j as isNestedConfigPath,k as loadContentLayerConfig,D as loadRedoclyConfig,G as normalizeRedoclyConfig,A as parseNestedConfig,M 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{isClosedToAnonymous as r,parseRbacConfigData as i}from"../server/rbac/engine.js";import{readProjectEnv as a}from"../server/project-env.js";import{listL10nDirs as o,resolveLocaleContext as s}from"../shared/utils/l10n.js";import{expandConfigRbacForL10n as c}from"../server/rbac/l10n-rules.js";import{expandConfigRbacTeamTemplates as l,listTeamDirs as u,teamTemplatePrefixes as d}from"../server/rbac/team-templates.js";import{getProcessEnv as f,getPublicEnv as p,resolveRedoclyEnvironment as m,sanitizeBranchName as h}from"../shared/public-env.js";import{resolveContentPath as g}from"../shared/utils/resolve-content-path.js";import{resolveConfigRedirects as _}from"./config-redirects.js";import{NESTED_CONFIG_SCHEMA as v,REALM_CONFIG_SCHEMA as y,sanitizeConfig as b}from"./config-schema.js";import{hashEffectiveConfig as x,resolveSiteConfig as S}from"./database/site-config.js";import{applyEnforcedAccess as C}from"./enforced-access.js";import{applyPlanGates as w}from"./plan-gates.js";import{resolve as T}from"node:path";import{interpolateEnvVariables as E}from"@redocly/config";import D from"js-yaml";const O=[`redocly.yaml`,`redocly.yml`],k=`redocly.yaml`;async function A(e,t){let r=await re(e,t),i=f();if(!r){let e=[],t=C(w($(),i,t=>e.push({code:`configuration/ignored`,message:t})),i);return{absolutePath:null,config:t,siteConfig:t,path:null,hash:null,refs:[],problems:e}}let s=await t.readBinaryFile(r.absolutePath),c=[],l=[],p=[],m=F(new TextDecoder().decode(s),r.path),h=[],g=a(i),_={contentDir:e,fs:t,env:g,refs:p,warnings:c,errors:l},v=Q(await te(await R(await I(m,{..._,deprecations:h}),``,_),_)),y={filePath:r.path},b=[],x=U(v.access)?v.access.rbac:void 0,T=K(v,{dirLocales:await o(e,t),teamDirs:await u(e,t,d(U(x)?x:{})),env:g,report:e=>b.push({...e,location:y})}),E=C(w(T,i,e=>b.push({code:`configuration/ignored`,message:e,location:y})),i),{config:D,unsetVars:O}=S(E,g);for(let e of O)c.push(`The config references process.env.${e}, which is not set.`);let k=[...c.map(e=>({code:`configuration/ignored`,message:e,location:y})),...[...new Set(h)].map(e=>({code:`configuration/deprecated`,message:e,location:y})),...l.map(e=>({code:`configuration/invalid`,severity:`error`,message:e,location:y})),...b];return{...r,config:D,siteConfig:E,hash:await n(s),refs:p,problems:k}}function j(e,t){return x(e)!==t}async function ee(e){if(e.context.configLoaded&&e.force!==!0)return{absolutePath:e.context.configFilePath?T(e.context.contentDir,e.context.configFilePath):null,config:e.context.config,siteConfig:e.context.siteConfig,path:e.context.configFilePath,hash:e.context.configHash,refs:e.context.configRefs,problems:[]};let t=await A(e.context.contentDir,e.context.platform.fs);return e.context.config=t.config,e.context.siteConfig=t.siteConfig,e.context.configFilePath=t.path,e.context.configHash=t.hash,e.context.configRefs=t.refs,e.context.configLoaded=!0,t}function M(e,t){let n=E(F(e,t),a(f())).value,{value:r,problems:i}=b(v,n);for(let e of i)e.location={filePath:t};return{config:r,problems:i}}function N(e){return e.endsWith(`/${k}`)}async function P(e){let t=[];for(let n of e.paths)try{let r=await e.fs.readFile(T(e.contentDir,n));t.push(...M(r,n).problems)}catch(e){let r=e instanceof Error?e.message:String(e);t.push({code:`configuration/invalid`,message:`The config cannot be read: ${r}`,location:{filePath:n}})}return t}function F(t,n){let r=D.load(t);if(r==null)return{};try{return e(r)}catch(e){throw Error(`Expected ${n} to contain a YAML object.`,{cause:e})}}async function I(e,t){let{env:n,...r}=e;if(!U(n))return e;let i=t.env.PUBLIC_REDOCLY_BRANCH_NAME,a=[...i?[`branch.${h(i)}`]:[],m(t.env.REDOCLY_ENV)],o=e=>t.deprecations.push(e),s=J(r,o);for(let e of a){let r=await L(n[e],e,t);r&&(s=H(s,J(r,o)))}return s}async function L(e,t,n){if(!U(e))return null;if(typeof e.$ref!=`string`)return e;let{$ref:r,...i}=e,a=`env.${t}`,o=z(await B(r,a,n),i,a,n);return U(o)?o:null}async function R(e,t,n){if(Array.isArray(e))return Promise.all(e.map((e,r)=>R(e,`${t}[${r}]`,n)));if(!U(e))return e;if(typeof e.$ref==`string`){let{$ref:r,...i}=e;return z(await B(r,t,n),await R(i,t,n),t,n)}let r={};for(let[i,a]of Object.entries(e))r[i]=await R(a,t===``?i:`${t}.${i}`,n);return r}function z(e,t,n,r){if(Object.keys(t).length===0)return e;if(U(e))return{...e,...t};if(e==null)return t;let i=Array.isArray(e)?`list`:`scalar`;return r.warnings.push(`${n===``?`The config`:n} has keys next to a $ref to a ${i}; only the referenced file applies.`),e}function B(e,n,r){return V(e,`${n} $ref`,r,e=>t(D.load(e)))}async function V(e,t,r,i,a=`warning`){let o=a===`error`?r.errors:r.warnings,s=g(e,O[0]);if(s===null)return o.push(`${t} "${e}" escapes the content root.`),null;try{let e=await r.fs.readBinaryFile(T(r.contentDir,s));return r.refs.push({path:s,hash:await n(e)}),i(new TextDecoder().decode(e))}catch(n){let r=n instanceof Error?n.message:String(n);return o.push(`Cannot read ${t} "${e}": ${r}`),null}}async function te(e,t){let{seo:n}=e;if(!U(n)||!U(n.llmstxt)||!U(n.llmstxt.details))return e;let{path:r,...i}=n.llmstxt.details;if(typeof r!=`string`)return e;let a=null;i.content===void 0?a=await V(E(r,t.env).value,`seo.llmstxt.details.path`,t,e=>e,`error`):t.errors.push(`seo.llmstxt.details.path and seo.llmstxt.details.content are mutually exclusive; the path is ignored.`);let o={...n.llmstxt,details:a===null?i:{...i,path:r,content:a}};return{...e,seo:{...n,llmstxt:o}}}function H(e,t){let n={...e};for(let[e,r]of Object.entries(t)){if(e===`__proto__`||e===`constructor`||e===`prototype`)continue;let t=n[e];n[e]=U(t)&&U(r)?H(t,r):r}return n}function U(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}const W=[`hide`,`name`,`ignore`,`publicEndpoint`],G=[`requiresLogin`,`rbac`,`sso`,`idps`,`logoutReturnUrl`,`residency`];function K(e,t={}){let n=t.report??(()=>{}),r=t.dirLocales??[],i=J(e,e=>n({code:`configuration/deprecated`,message:e}));U(i.mcp)&&i.mcp.docs!==void 0&&n({code:`configuration/deprecated`,message:`The 'mcp.docs' property is deprecated. Use the 'mcp' properties instead.`});let a=b(y,i,{env:t.env});for(let e of a.problems)n(e);let{redirects:o,access:u,...d}=c(l(q(a.value,t.env),t.teamDirs??{},n),r),f={...d,publicEnv:p()};u&&(f.access=ne(u,n));let m=_(o,s(d.l10n,r));return m&&(f.redirects=m),f}function q(e,t){if(!t)return e;let n={...e};for(let r of[`access`,`l10n`,`redirects`])r in e&&(n[r]=E(e[r],t).value);return n}function J(e,t){return Z(Y(Q(e),t))}function Y(e,t){let n=e;e.reunite!==void 0&&(t(`The 'reunite' property is deprecated. Use 'platform' instead.`),e.platform!==void 0&&e.platform!==null&&t(`Both 'platform' and 'reunite' are set. 'reunite' is ignored, so remove it.`),n=X(e));let{access:r}=n;return U(r)&&U(r.rbac)&&r.rbac.reunite!==void 0&&(t(`The 'access.rbac.reunite' property is deprecated. Use 'access.rbac.platform' instead.`),n={...n,access:{...r,rbac:X(r.rbac)}}),n}function X(e){let{reunite:t,...n}=e;return{...n,platform:e.platform??t}}function Z(e){let{mcp:t}=e;if(!U(t))return e;let{docs:n,...r}=t;if(!U(n))return e;let i={...n};for(let e of W){let t=n[e];delete i[e],t!==void 0&&(r[e]===void 0||r[e]===null||e===`hide`&&t===!0)&&(r[e]=t)}return{...e,mcp:{...r,docs:i}}}function Q(e){let t=G.map(t=>[t,e[t]]).filter(([,e])=>e!==void 0);if(t.length===0)return e;let n={...e},r=U(e.access)?{...e.access}:{};for(let[e,i]of t)delete n[e],(r[e]===void 0||r[e]===null)&&(r[e]=i);return{...n,access:r}}function ne(e,t){let n=e.rbac?i(e.rbac,e=>t({code:`configuration/invalid`,message:e})):null;return n?(e.requiresLogin===!0&&t({code:`configuration/ignored`,message:`access.requiresLogin is ignored because access.rbac is also configured — the two are mutually exclusive. Remove one.`}),{...e,requiresLogin:r(n)}):e}async function re(e,t){for(let n of O){let r=T(e,n);if(await t.exists(r))return{absolutePath:r,path:n}}return null}function $(){return K({})}export{k as NESTED_CONFIG_FILENAME,O as REDOCLY_CONFIG_FILENAMES,$ as createEmptyRealmConfig,H as deepMergeConfig,j as isConfigChanged,N as isNestedConfigPath,ee as loadContentLayerConfig,A as loadRedoclyConfig,K as normalizeRedoclyConfig,M as parseNestedConfig,P as readNestedConfigProblems};
@@ -8,6 +8,8 @@ import type { ContentPlugin } from './plugins/types/plugin.js';
8
8
  import type { ContentLayerState } from './context-state.js';
9
9
  export type ContentLayerContext = {
10
10
  config: RealmConfig;
11
+ /** `config` as ingest stores it: `LoadedRedoclyConfig.siteConfig`. */
12
+ siteConfig: RealmConfig;
11
13
  configFilePath: string | null;
12
14
  configHash: string | null;
13
15
  configRefs: readonly ConfigFileRef[];
@@ -1 +1 @@
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);return{config:o.config??n(),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
+ 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){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)))}}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};
@@ -53,3 +53,8 @@ export declare function createEntityStore(options: EntityStoreOptions): EntitySt
53
53
  export declare function hashEntityRead(state: ContentStateView, key: string): string;
54
54
  /** Re-runs a stored `entity-type` query against `state`; the hash `list` recorded. */
55
55
  export declare function hashEntityListMembership(state: ContentStateView, argument: string): string;
56
+ /** The current metadata of `keys` in one read; a key with no current entity is absent. */
57
+ export declare function loadCurrentEntityMetadata(database: ContentLayerDatabase, keys: readonly string[]): Promise<{
58
+ key: string;
59
+ metadata: JsonObject | null;
60
+ }[]>;
@@ -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{replaceDataRefMarkers as r}from"../materialization/data-ref.js";import{entities as i}from"./schema.js";import{resolveDataRef as a}from"./blobs.js";import{listEntityRevisions as o}from"../revisions/list.js";import{selectEntityRowForRead as s}from"../revisions/read.js";import{and as c,eq as l}from"drizzle-orm";function u(e){let{database:t,state:u}=e,m=typeof e.revisionAsOf==`number`?e.revisionAsOf:null;return{get:async n=>{if(e.onEntityRead?.(n),m!==null){let e=await s(t.db,n,m);return e?y(e):null}let r=u?.entitiesByKey.get(n);if(r)return y(r);if(u)return null;let[a]=await t.db.select(v()).from(i).where(c(l(i.key,n),l(i.isCurrent,1))).limit(1);return a?y(a):null},async listRevisions(n){for(let t of n)e.onEntityRead?.(t);return o(t.db,n)},async list(r={}){let a=(u?[...u.entitiesByKey.values()].filter(e=>_(e,r)):await t.db.select(v()).from(i).where(c(l(i.isCurrent,1),r.type===void 0?void 0:l(i.type,r.type),r.pluginId===void 0?void 0:l(i.pluginId,r.pluginId)))).map(y).sort((e,t)=>n(e.key,t.key));return e.record?.({kind:`entity-type`,argument:p(r),resultHash:g(a.map(e=>e.key))}),a},async load(n){let o=u?.entitiesByKey.get(n),[p]=m===null?u&&!o?[]:await t.db.select({status:i.status,data:i.data,dataHash:i.dataHash,metadata:i.metadata,isCurrent:i.isCurrent}).from(i).where(c(l(i.key,n),l(i.isCurrent,1))).limit(1):[await s(t.db,n,m)??void 0];if(!p)throw e.onEntityRead?.(n),Error(`Entity "${n}" is not registered.`);let h;if(p.status===`ready`&&p.data!==null||p.isCurrent!==1)h=p.data,u&&p.isCurrent===1&&m===null&&f(u,n,p);else if(e.materialize)h=await e.materialize(n),u&&await d(t,u,n);else throw Error(`Missing precomputed entity data for "${n}". Rebuild the content entity data before starting the production runtime.`);return e.onEntityRead?.(n),await r(h,e=>a(t,e))}}}async function d(e,t,n){let[r]=await e.db.select({status:i.status,dataHash:i.dataHash,metadata:i.metadata}).from(i).where(c(l(i.key,n),l(i.isCurrent,1))).limit(1);r&&f(t,n,r)}function f(e,t,n){let r=e.entitiesByKey.get(t);r&&Object.assign(r,{status:n.status,dataHash:n.dataHash,metadata:n.metadata})}function p(e){return t({...e.type===void 0?{}:{type:e.type},...e.pluginId===void 0?{}:{pluginId:e.pluginId}})}function m(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 h(e,t){let r=JSON.parse(t),i=[];for(let t of e.entitiesByKey.values())_(t,r)&&i.push(t.key);return g(i.sort(n))}function g(t){return e([...t])}function _(e,t){return(t.type===void 0||e.type===t.type)&&(t.pluginId===void 0||e.pluginId===t.pluginId)}function v(){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 y(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{u as createEntityStore,h as hashEntityListMembership,m as hashEntityRead};
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{resolveDataRef as a}from"./blobs.js";import{listEntityRevisions as o}from"../revisions/list.js";import{selectEntityRowForRead as s}from"../revisions/read.js";import{and as c,eq as l,inArray as u}from"drizzle-orm";function d(e){let{database:t,state:u}=e,d=typeof e.revisionAsOf==`number`?e.revisionAsOf:null;return{get:async n=>{if(e.onEntityRead?.(n),d!==null){let e=await s(t.db,n,d);return e?x(e):null}let i=u?.entitiesByKey.get(n);if(i)return x(i);if(u)return null;let[a]=await t.db.select(b()).from(r).where(c(l(r.key,n),l(r.isCurrent,1))).limit(1);return a?x(a):null},async listRevisions(n){for(let t of n)e.onEntityRead?.(t);return o(t.db,n)},async list(i={}){let a=(u?[...u.entitiesByKey.values()].filter(e=>v(e,i)):await t.db.select(b()).from(r).where(c(l(r.isCurrent,1),i.type===void 0?void 0:l(r.type,i.type),i.pluginId===void 0?void 0:l(r.pluginId,i.pluginId)))).map(x).sort((e,t)=>n(e.key,t.key));return e.record?.({kind:`entity-type`,argument:m(i),resultHash:_(a.map(e=>e.key))}),a},async load(n){let o=u?.entitiesByKey.get(n),[m]=d===null?u&&!o?[]:await t.db.select({status:r.status,data:r.data,dataHash:r.dataHash,metadata:r.metadata,isCurrent:r.isCurrent}).from(r).where(c(l(r.key,n),l(r.isCurrent,1))).limit(1):[await s(t.db,n,d)??void 0];if(!m)throw e.onEntityRead?.(n),Error(`Entity "${n}" is not registered.`);let h;if(m.status===`ready`&&m.data!==null||m.isCurrent!==1)h=m.data,u&&m.isCurrent===1&&d===null&&p(u,n,m);else if(e.materialize)h=await e.materialize(n),u&&await f(t,u,n);else throw Error(`Missing precomputed entity data for "${n}". Rebuild the content entity data before starting the production runtime.`);return e.onEntityRead?.(n),await i(h,e=>a(t,e))}}}async function f(e,t,n){let[i]=await e.db.select({status:r.status,dataHash:r.dataHash,metadata:r.metadata}).from(r).where(c(l(r.key,n),l(r.isCurrent,1))).limit(1);i&&p(t,n,i)}function p(e,t,n){let r=e.entitiesByKey.get(t);r&&Object.assign(r,{status:n.status,dataHash:n.dataHash,metadata:n.metadata})}function m(e){return t({...e.type===void 0?{}:{type:e.type},...e.pluginId===void 0?{}:{pluginId:e.pluginId}})}function h(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 g(e,t){let r=JSON.parse(t),i=[];for(let t of e.entitiesByKey.values())v(t,r)&&i.push(t.key);return _(i.sort(n))}function _(t){return e([...t])}function v(e,t){return(t.type===void 0||e.type===t.type)&&(t.pluginId===void 0||e.pluginId===t.pluginId)}async function y(e,t){return t.length===0?[]:e.db.select({key:r.key,metadata:r.metadata}).from(r).where(c(u(r.key,[...t]),l(r.isCurrent,1)))}function b(){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 x(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{d as createEntityStore,g as hashEntityListMembership,h as hashEntityRead,y as loadCurrentEntityMetadata};
@@ -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{deleteProblemsForFilesTx as d}from"./problems.js";import{garbageCollectOrphanedEntitiesInTransaction as f}from"./invalidation.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 d(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 f(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{deleteProblemsForPluginHookTx as h,insertProblemsTx as g,replaceGlobalProblemsForKeysTx as _}from"./problems.js";import{generateEntityId as v}from"./entities.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??v(),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 h(e,t.pluginIds,`finalize`),await g(e,t.pluginProblems),await _(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};
@@ -51,6 +51,12 @@ export declare function propagateConfigDependencyInvalidation(database: ContentL
51
51
  }): Promise<{
52
52
  invalidatedKeys: readonly string[];
53
53
  }>;
54
+ /** Marks stale the entities whose last load reported a problem in `RETRYABLE_PROBLEM_CODES`. */
55
+ export declare function propagateRetryableProblemInvalidation(database: ContentLayerDatabase, options?: {
56
+ logger?: Logger;
57
+ }): Promise<{
58
+ invalidatedKeys: readonly string[];
59
+ }>;
54
60
  /**
55
61
  * Re-runs every loader-scoped route query against `state` and marks the
56
62
  * entities whose result changed stale (entity-to-entity edges included).
@@ -1,27 +1,27 @@
1
- import{delocalizeL10nPath as e}from"../../shared/utils/l10n.js";import{compileGlob as t,hashGlobMatches as n,matchGlob as r}from"../plugins/utils/glob.js";import{hashContentConfigDependency as i}from"../config-deps.js";import{runWithSqliteBusyRetry as a}from"./connection.js";import{assetRefs as o,entities as s,entityDeps as c,files as l,linkRefs as u,loaderConfigDeps as d,originDeps as f,pageMarkdown as p,problems as m,searchDocuments as h,searchFragmentParents as g,searchFragmentPostings as _,searchFragmentUsages as v,searchFragments as y,searchPostings as b}from"./schema.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{and as D,eq as O,inArray as k,sql as A}from"drizzle-orm";async function j(e){return await e.db.select({accessType:f.accessType,originFileId:f.originFileId,originFilePath:l.path,originPluginId:f.originPluginId,hook:f.hook,path:f.path,source:f.source,valueHash:f.valueHash}).from(f).leftJoin(l,O(f.originFileId,l.id)).orderBy(l.path,f.originPluginId,f.path,f.accessType)}function M(e,t){let n=/* @__PURE__ */ new Map,r=I(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 L([...n.values()])}function N(e,t){let n=/* @__PURE__ */ new Map;for(let r of e){if(r.source===`config`||r.originFileId===null||r.originFilePath===null||P(r,t)===r.valueHash)continue;let e=`${r.originPluginId}:${r.originFilePath}`;n.has(e)||n.set(e,r)}return L([...n.values()])}function P(e,t){if(e.source===`glob`)return n(r(t.filesByPath.keys(),e.path));let i=t.filesByPath.get(e.path)??t.ignoredFilesByPath?.get(e.path);return e.accessType===`presence`?i?`present`:`absent`:i?.hash??null}function F(e,t,n){let r=/* @__PURE__ */ new Set,i=I(n.config);for(let a of e)a.originFileId!==null||a.hook!==t||r.has(a.originPluginId)||(a.source===`config`?i(a):P(a,n))!==a.valueHash&&r.add(a.originPluginId);return r}function I(e){let t=/* @__PURE__ */ new Map;return n=>{let r=`${n.accessType}\u0000${n.path}`,a=t.get(r);return a===void 0&&(a=i(e,n),t.set(r,a)),a}}function L(e){return e.sort((e,t)=>{let n=e.originFilePath.localeCompare(t.originFilePath);return n===0?e.originPluginId.localeCompare(t.originPluginId):n})}async function R(e,t){let n=await e.db.select({accessType:d.accessType,path:d.path,key:s.key,valueHash:d.valueHash}).from(d).innerJoin(s,O(d.entityId,s.id)).orderBy(s.key,d.path,d.accessType),r=/* @__PURE__ */ new Set;for(let e of n)i(t.config,e)!==e.valueHash&&r.add(e.key);let a=await V(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 z(e,t){let n=x(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)||S(n,e)&&r.add(e.entityId);if(r.size===0)return{invalidatedKeys:[]};let i=await e.db.select({key:s.key}).from(s).where(k(s.id,[...r]));return V(e,{logger:t.logger,reason:`route query invalidation`,keys:i.map(e=>e.key)})}async function B(n,r){if(r.changedFilePaths.length===0)return{invalidatedKeys:[]};let i=/* @__PURE__ */ new Set,a=await n.db.select({key:s.key}).from(s).innerJoin(c,O(c.entityId,s.id)).where(A`${c.dependencyType} in ('file','origin') and ${c.dependencyRef} in ${r.changedFilePaths}`);for(let e of a)i.has(e.key)||i.add(e.key);let l=[...new Set(r.changedFilePaths.map(e).filter(e=>e!==void 0))];if(l.length>0){let e=await n.db.select({key:s.key}).from(s).innerJoin(o,O(o.entityId,s.id)).where(k(o.path,l));for(let t of e)i.add(t.key)}let u=r.membershipChangedPaths??[];if(u.length>0){let e=await n.db.select({key:s.key,pattern:c.dependencyRef}).from(s).innerJoin(c,O(c.entityId,s.id)).where(O(c.dependencyType,`glob`));for(let n of e){let e=t(n.pattern);u.some(e)&&i.add(n.key)}}let d=await V(n,{logger:r.logger,reason:`file dependency invalidation`,keys:[...i]});return d.invalidatedKeys.length>0&&r.logger?.debug(`Propagated entity invalidation`,{changedFilePaths:r.changedFilePaths.length,invalidatedKeys:d.invalidatedKeys.length}),d}async function V(e,t){let n=new Set(t.keys),r=new Set(n),i=[...n];for(;i.length>0;){let t=i;i=[];let n=await e.db.select({key:s.key}).from(s).innerJoin(c,O(c.entityId,s.id)).where(A`${c.dependencyType} = 'entity' and ${c.dependencyRef} in ${t}`);for(let e of n)r.has(e.key)||(r.add(e.key),i.push(e.key))}let o=t.markKeys===!1?[...r].filter(e=>!n.has(e)):[...r];return o.length===0?{invalidatedKeys:[]}:(await a(()=>e.db.update(s).set({status:`stale`,invalidationSeq:A`${s.invalidationSeq} + 1`}).where(D(k(s.key,o),O(s.isCurrent,1))),{logger:t.logger,operation:t.reason}),{invalidatedKeys:o})}async function H(e,t){return a(()=>e.db.transaction(e=>U(e)),{logger:t,operation:`garbage collect orphaned entities`})}async function U(e){let t=A`(${s.isSystem} = 0 or ${s.key} <> ${C}) and ${s.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 ${c}
4
- where ${c.entityId} = ${s.id}
5
- and ${c.dependencyType} = 'origin'
6
- )`,[n]=await e.select({id:s.id}).from(s).where(t).limit(1);return n!==void 0&&await W(e,t),await e.delete(s).where(A`${s.isCurrent} = 0 and not exists (
7
- select 1 from ${s} as live
8
- where live.key = ${s.key} and live.is_current = 1
9
- )`),{removedOrphans:n!==void 0}}async function W(e,t){await e.delete(d).where(A`${d.entityId} in (
10
- select ${s.id} from ${s} where ${t}
11
- )`);let n=A`select ${h.id} from ${h}
12
- where ${h.entityKey} in (
13
- select ${s.key} from ${s} where ${t}
14
- )`,r=A`select ${y.id} from ${y}
15
- where ${y.entityKey} in (
16
- select ${s.key} from ${s} where ${t}
17
- )`,i=[...await T(e,n),...await E(e,r)];await e.delete(b).where(A`${b.docId} in (${n})`),await e.delete(_).where(A`${_.fragmentId} in (${r})`),await e.delete(g).where(A`${g.docId} in (${n})`),await e.delete(v).where(A`${v.fragmentId} in (${r})`),await e.delete(y).where(A`${y.id} in (${r})`),await w(e,i),await e.delete(h).where(A`${h.entityKey} in (
18
- select ${s.key} from ${s} where ${t}
19
- )`),await e.delete(p).where(A`${p.entityKey} in (
20
- select ${s.key} from ${s} where ${t}
21
- )`),await e.delete(m).where(A`${m.scope} = 'entity' and ${m.entityId} in (
22
- select ${s.id} from ${s} where ${t}
23
- )`);let a=A`${u.entityId} in (
24
- select ${s.id} from ${s} where ${t}
25
- )`;await e.delete(m).where(A`${m.scope} = 'link' and ${m.linkRefId} in (
26
- select ${u.id} from ${u} where ${a}
27
- )`),await e.delete(u).where(a),await e.delete(s).where(t)}export{M as computeDirtyConfigOrigins,N as computeDirtyFileOrigins,F as computeDirtyPluginScopedOrigins,H as garbageCollectOrphanedEntities,U as garbageCollectOrphanedEntitiesInTransaction,j as loadOriginDependencyRows,R as propagateConfigDependencyInvalidation,B as propagateEntityInvalidation,V as propagateEntityInvalidationFromKeys,z 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};