canopycms 0.8.0 → 0.8.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -5,9 +5,9 @@ packages release together, at one version.
5
5
 
6
6
  ## This build
7
7
 
8
- Version `0.8.0`, built from [`f47713d`](https://github.com/safeinsights/canopycms/tree/f47713db8d2e5c0dbb3b7ef77ea4b03c1939595a).
8
+ Version `0.8.1`, built from [`67d7e59`](https://github.com/safeinsights/canopycms/tree/67d7e59ebd472b09175d09c620d8e2d06d333496).
9
9
 
10
- Its entries are [0.8.0](#080), under **Released**.
10
+ Its entries are [0.8.1](#081), under **Released**.
11
11
 
12
12
  If you upgraded from a build on another branch, compare the `<!-- changeset: … -->` slugs in your previous build's `CHANGELOG.md` (`npm pack canopycms@<old>` fetches it) with this one's: entries whose slug your old file lacks are new to you.
13
13
 
@@ -24,7 +24,7 @@ Each entry has up to three parts:
24
24
  `node_modules/canopycms/CHANGELOG.md`, assembled for that build: its **This build** section lists
25
25
  what is new since the previous int on the same branch, or on a stable release links its entries, and its links point at the commit the build
26
26
  came from. The copy in the repository holds released history and the entries from before changesets;
27
- every entry written since is a file in [`.changeset/`](https://github.com/safeinsights/canopycms/blob/f47713db8d2e5c0dbb3b7ef77ea4b03c1939595a/.changeset/README.md) until a stable release
27
+ every entry written since is a file in [`.changeset/`](https://github.com/safeinsights/canopycms/blob/67d7e59ebd472b09175d09c620d8e2d06d333496/.changeset/README.md) until a stable release
28
28
  moves it here.
29
29
 
30
30
  **Find your starting point.** From a stable pin, start at the first version under **Released**
@@ -62,6 +62,16 @@ entries under **Released**.
62
62
 
63
63
  ## Released
64
64
 
65
+ ### 0.8.1
66
+
67
+ #### Content reads stop re-reading and re-parsing the schema cache
68
+
69
+ <!-- changeset: schema-cache-read-once -->
70
+
71
+ _First in 0.8.1._
72
+
73
+ **What changed.** An adopter's request measured every `read()` and `readByUrlPath()` reading and parsing the branch's whole schema cache file, up to five times per page. Each process now keeps the schema it parsed and reuses it while the file is unchanged, still checking its freshness on every read. `readByUrlPath()` resolves the branch's schema once for both of the paths it tries. A build resolves the schema once per process instead of on every read. The cache file is written without indentation, under half its former size.
74
+
65
75
  ### 0.8.0
66
76
 
67
77
  <!-- changeset: merge-main-0-7-1-into-int-e -->
@@ -251,7 +261,7 @@ _First in 0.7.0._
251
261
 
252
262
  **What changed.** The pull request a submit opens now lists the branch's unresolved editor comment threads: where each one is, the first line of its first comment (80 characters at most) and a link to it in the editor. Once every thread is resolved, it says so. The list is updated whenever a comment is added, replied to or resolved, as well as on submit. Comment excerpts are visible to everyone who can read the pull request, which on a public repository means everyone. Open threads do not block the merge or keep the pull request in draft. A pull request opened before this release shows no list until its branch is next submitted.
253
263
 
254
- **To adopt.** Nothing, if your deploy replaces the worker along with the CMS, as `cdk deploy` of the canopycms-cdk stack does with the default `workerCode`. A worker on an earlier release fails each update of the list and marks the branch's sync failed until a later task succeeds, so a pipeline that leaves the worker behind must roll it no later than the CMS: see [Rolling the worker from CI](https://github.com/safeinsights/canopycms/blob/f47713db8d2e5c0dbb3b7ef77ea4b03c1939595a/docs/deploying-to-aws.md#rolling-the-worker-from-ci).
264
+ **To adopt.** Nothing, if your deploy replaces the worker along with the CMS, as `cdk deploy` of the canopycms-cdk stack does with the default `workerCode`. A worker on an earlier release fails each update of the list and marks the branch's sync failed until a later task succeeds, so a pipeline that leaves the worker behind must roll it no later than the CMS: see [Rolling the worker from CI](https://github.com/safeinsights/canopycms/blob/67d7e59ebd472b09175d09c620d8e2d06d333496/docs/deploying-to-aws.md#rolling-the-worker-from-ci).
255
265
 
256
266
  #### Pull request bodies link back to the editor
257
267
 
@@ -261,7 +271,7 @@ _First in 0.7.0._
261
271
 
262
272
  **What changed.** The pull request a submit opens links to the branch in the editor, and each changed entry to that entry. A notice tells reviewers that comments on the pull request do not reach the editor, so the author will not see them. The links use the editor's URL from the submit, accepted only when its host is the one the request was addressed to (`X-Forwarded-Host`, else `Host`), which holds behind `canopycms-cdk`'s CloudFront distribution as it stands.
263
273
 
264
- **To adopt.** Nothing, unless a proxy in front of the CMS sets neither header to the editor's public host: then set `editorUrl` in your Canopy config to the editor page's URL, e.g. `editorUrl: 'https://cms.example.org/edit'`. See [the config reference](https://github.com/safeinsights/canopycms/blob/f47713db8d2e5c0dbb3b7ef77ea4b03c1939595a/README.md#definecanopyconfig-options).
274
+ **To adopt.** Nothing, unless a proxy in front of the CMS sets neither header to the editor's public host: then set `editorUrl` in your Canopy config to the editor page's URL, e.g. `editorUrl: 'https://cms.example.org/edit'`. See [the config reference](https://github.com/safeinsights/canopycms/blob/67d7e59ebd472b09175d09c620d8e2d06d333496/README.md#definecanopyconfig-options).
265
275
 
266
276
  #### CloudFront origin read timeout accepted up to 120 s; the editor waits 135 s
267
277
 
@@ -347,7 +357,7 @@ _First in 0.6.0._
347
357
 
348
358
  **What changed.** `CanopyCmsService` takes `clerkOrganizationsAsGroups` (default `true`, unchanged), which the worker honours; in a deployment it, not the plugin's `useOrganizationsAsGroups`, decides the groups. When Clerk refuses the organization list with a 403 (Organizations disabled), the refresh now writes users with no groups and logs a warning, instead of failing whole; any other failure still keeps the last snapshot. Memberships are fetched instance-wide rather than per user. The scaffolds write `false` explicitly: `useOrganizationsAsGroups` in `canopycms init`'s `canopy.ts`, and `clerkOrganizationsAsGroups` in `canopycms init-deploy aws`'s CDK stack.
349
359
 
350
- **To adopt.** On a Clerk instance without Organizations, set `clerkOrganizationsAsGroups: false` on `CanopyCmsService` and `useOrganizationsAsGroups: false` in `createClerkAuthPlugin`. See [Deploying to AWS](https://github.com/safeinsights/canopycms/blob/f47713db8d2e5c0dbb3b7ef77ea4b03c1939595a/docs/deploying-to-aws.md).
360
+ **To adopt.** On a Clerk instance without Organizations, set `clerkOrganizationsAsGroups: false` on `CanopyCmsService` and `useOrganizationsAsGroups: false` in `createClerkAuthPlugin`. See [Deploying to AWS](https://github.com/safeinsights/canopycms/blob/67d7e59ebd472b09175d09c620d8e2d06d333496/docs/deploying-to-aws.md).
351
361
 
352
362
  ### 0.5.0
353
363
 
@@ -359,7 +369,7 @@ _First in 0.5.0._
359
369
 
360
370
  **What changed.** A `type: 'reference', list: true` field now edits as rows in stored order, like an `object` list: drag a row or use its "…" menu to move or remove it, open a row to swap its entry in place, and pick from Add under the rows to append. Neither control offers an entry the list already holds. Any `list: true` field, and any `block` field, takes `maxItems`. The editor stops adding at the cap and says why, a save over it is refused, and a production build fails on an entry over it, naming the entry, field, count and cap. Adding `maxItems` to a list that already holds more therefore fails the build until an editor removes the extra items. `maxItems` on a field that holds no items is refused when the entry schema registry is created.
361
371
 
362
- **To adopt.** Set `maxItems: 3` on the list field in its entry schema. See [Field Types](https://github.com/safeinsights/canopycms/blob/f47713db8d2e5c0dbb3b7ef77ea4b03c1939595a/README.md#field-types).
372
+ **To adopt.** Set `maxItems: 3` on the list field in its entry schema. See [Field Types](https://github.com/safeinsights/canopycms/blob/67d7e59ebd472b09175d09c620d8e2d06d333496/README.md#field-types).
363
373
 
364
374
  #### SEO field location moves into config; reference pickers mark hidden entries and take a sort order — **breaking: `createNextCanopyContext({ seo })` and `AIContentConfig.seo` are removed**
365
375
 
@@ -369,7 +379,7 @@ _First in 0.5.0._
369
379
 
370
380
  **What changed.** `defineCanopyConfig` takes `seo: { group?, fields? }`, the one place every surface reads an entry's `noindex` flag: the sitemap and `entryToMetadata` that `createNextCanopyContext` returns, AI content and the editor's reference picker. A per-call `seo`/`group`/`fields` still overrides it. The free `generateContentSitemap` takes `seo` as an argument and refuses to run without it when the config sets one; `createNextCanopyContext` and the AI content config refuse a leftover `seo`. A reference picker now badges an entry hidden from search as "Hidden from search", and picking one adds a note naming the setting on that entry's form, since a page listing only indexed entries won't show it. A reference field takes `optionSort`: `'label'` (the default), `'collection'`, or `{ field, direction }`. Point `field` at an ISO date, since strings compare as text.
371
381
 
372
- **To adopt.** Move `seo` from `createNextCanopyContext({ seo })` and from `defineAIContentConfig({ seo })` into `defineCanopyConfig({ seo })`. See [Sitemap and SEO Metadata](https://github.com/safeinsights/canopycms/blob/f47713db8d2e5c0dbb3b7ef77ea4b03c1939595a/README.md#sitemap-and-seo-metadata) and [How References Work in the Editor](https://github.com/safeinsights/canopycms/blob/f47713db8d2e5c0dbb3b7ef77ea4b03c1939595a/README.md#how-references-work-in-the-editor).
382
+ **To adopt.** Move `seo` from `createNextCanopyContext({ seo })` and from `defineAIContentConfig({ seo })` into `defineCanopyConfig({ seo })`. See [Sitemap and SEO Metadata](https://github.com/safeinsights/canopycms/blob/67d7e59ebd472b09175d09c620d8e2d06d333496/README.md#sitemap-and-seo-metadata) and [How References Work in the Editor](https://github.com/safeinsights/canopycms/blob/67d7e59ebd472b09175d09c620d8e2d06d333496/README.md#how-references-work-in-the-editor).
373
383
 
374
384
  **Now deletable.** A shared `seo` constant passed separately to the Next context and the AI content config.
375
385
 
@@ -397,7 +407,7 @@ resolved without it.
397
407
  **To adopt.** Where a reference renders its target's prose, set `includeBody: true` on that
398
408
  reference field. Code that reads the body from a link-only reference's resolved type now sees
399
409
  `string | undefined`; either set `includeBody: true` or handle the missing value. See
400
- [Resolving References in a Listing](https://github.com/safeinsights/canopycms/blob/f47713db8d2e5c0dbb3b7ef77ea4b03c1939595a/README.md#resolving-references-in-a-listing).
410
+ [Resolving References in a Listing](https://github.com/safeinsights/canopycms/blob/67d7e59ebd472b09175d09c620d8e2d06d333496/README.md#resolving-references-in-a-listing).
401
411
 
402
412
  ### 0.3.3
403
413
 
@@ -814,7 +824,7 @@ URL.
814
824
  2. For a branch preview: wrap views with `withCanopyPreview` in a `'use client'` module, add
815
825
  `app/preview/[[...path]]/page.server.tsx`, set `editor.previewPrefix: '/preview'`, and serve that
816
826
  route with `frame-ancestors 'self'`, not `X-Frame-Options: DENY` (see
817
- [Live Preview](https://github.com/safeinsights/canopycms/blob/f47713db8d2e5c0dbb3b7ef77ea4b03c1939595a/README.md#live-preview)).
827
+ [Live Preview](https://github.com/safeinsights/canopycms/blob/67d7e59ebd472b09175d09c620d8e2d06d333496/README.md#live-preview)).
818
828
  3. A test reading view content from the route's server HTML must load the page in a browser.
819
829
  Server output rendered during a preview request carries the signed-in asset prefix; keep it out
820
830
  of cross-request caches (`unstable_cache`, module memos).
@@ -829,7 +839,7 @@ kept site styles ahead of Mantine's in the preview.
829
839
  server components. A string path marks the form's spelling (`'a.0.b'` marks `a[0].b`), and an empty
830
840
  path marks nothing. The editor counts and logs marks naming no field. `createEntrySchemaRegistry`
831
841
  refuses a field name that is empty, all digits or contains `.`, `[` or `]`. See
832
- [Live Preview](https://github.com/safeinsights/canopycms/blob/f47713db8d2e5c0dbb3b7ef77ea4b03c1939595a/README.md#live-preview).
842
+ [Live Preview](https://github.com/safeinsights/canopycms/blob/67d7e59ebd472b09175d09c620d8e2d06d333496/README.md#live-preview).
833
843
 
834
844
  **To adopt.** Fix each path that stops compiling; the error lists valid ones. Rewrite computed paths
835
845
  as literal segments, or type that component's prop as plain `FieldProps`. Pass `fieldProps` as
@@ -911,7 +921,7 @@ or a failed render) renders as its plain text, with no URL; any other form of th
911
921
  fields are nested or renamed, pass the AI config's `seo` the same object you pass
912
922
  `createNextCanopyContext({ seo })`, so the sitemap and AI content read the flag from the same
913
923
  place. A field that links to a hidden section by plain URL needs a field transform; the README
914
- shows [the recipe](https://github.com/safeinsights/canopycms/blob/f47713db8d2e5c0dbb3b7ef77ea4b03c1939595a/README.md#ai-content-configuration).
924
+ shows [the recipe](https://github.com/safeinsights/canopycms/blob/67d7e59ebd472b09175d09c620d8e2d06d333496/README.md#ai-content-configuration).
915
925
 
916
926
  **Now deletable.** An `exclude.where` that re-read the `noindex` flag by hand.
917
927
 
@@ -933,7 +943,7 @@ A `markdown` field with `renderAs: 'mdx'` is checked as MDX, and `mdxAllow` narr
933
943
  field or site-wide. New: field options `renderAs`, `mdxAllow`; config key `mdxAllow`; type
934
944
  `MdxAllowlist`. (int.110) A component prop allowance can be `'string'` (or
935
945
  `{ type: 'string', maxLength }`): a quoted value only, never bare or `{…}`. See
936
- [MDX content cannot run code](https://github.com/safeinsights/canopycms/blob/f47713db8d2e5c0dbb3b7ef77ea4b03c1939595a/README.md#mdx-content-cannot-run-code).
946
+ [MDX content cannot run code](https://github.com/safeinsights/canopycms/blob/67d7e59ebd472b09175d09c620d8e2d06d333496/README.md#mdx-content-cannot-run-code).
937
947
 
938
948
  **To adopt.** Set `renderAs: 'mdx'` on each `markdown` field your site compiles as MDX, and
939
949
  `mdxAllow` to what your renderer takes. Set `executable: true` only on a field whose editors you
@@ -1070,7 +1080,7 @@ a format check.
1070
1080
 
1071
1081
  - (int.93) Submit commits gain an `Edited-by: Name (id)` trailer; PR bodies gain a section that
1072
1082
  re-submits replace, keeping human text. Options: `gitEditedByTrailers`, `gitCoAuthoredByTrailers`
1073
- ([reference](https://github.com/safeinsights/canopycms/blob/f47713db8d2e5c0dbb3b7ef77ea4b03c1939595a/README.md#definecanopyconfig-options)).
1083
+ ([reference](https://github.com/safeinsights/canopycms/blob/67d7e59ebd472b09175d09c620d8e2d06d333496/README.md#definecanopyconfig-options)).
1074
1084
  - (int.110) Submit-commit trailers name every user who saved since the last submit commit, and
1075
1085
  the PR-body section every user who edited the branch, not only the submitter; settings commits
1076
1086
  (permissions, groups) carry the acting user's trailer.
@@ -1094,7 +1104,7 @@ saves only push the branch, and no failing PR task lands in System health.
1094
1104
  that entry type goes unavailable: the editor says so, and its entries answer 503 with
1095
1105
  `code: 'SCHEMA_UNAVAILABLE'`. Builds, static deploys and `generate-ai-content` still fail. The
1096
1106
  worker holds the base branch for up to 30 minutes while that lasts; see
1097
- [New schemas wait for the editor deploy](https://github.com/safeinsights/canopycms/blob/f47713db8d2e5c0dbb3b7ef77ea4b03c1939595a/docs/deploying-to-aws.md#new-schemas-wait-for-the-editor-deploy).
1107
+ [New schemas wait for the editor deploy](https://github.com/safeinsights/canopycms/blob/67d7e59ebd472b09175d09c620d8e2d06d333496/docs/deploying-to-aws.md#new-schemas-wait-for-the-editor-deploy).
1098
1108
  Public types gain optional `unavailable` on `EntryTypeConfig` and `FlatSchemaItem`, optional
1099
1109
  `ApiResponse.code`, and a required `SchemaResolutionResult.issues`.
1100
1110
 
@@ -1132,7 +1142,7 @@ hang until the drain heartbeat lets termination continue. Its in-flight task is
1132
1142
  new stack needs no steps.
1133
1143
 
1134
1144
  **What changed.** (int.109) Detailed in
1135
- [The worker instance](https://github.com/safeinsights/canopycms/blob/f47713db8d2e5c0dbb3b7ef77ea4b03c1939595a/docs/deploying-to-aws.md#the-worker-instance): IMDSv2 with a hop limit of 1; the
1145
+ [The worker instance](https://github.com/safeinsights/canopycms/blob/67d7e59ebd472b09175d09c620d8e2d06d333496/docs/deploying-to-aws.md#the-worker-instance): IMDSv2 with a hop limit of 1; the
1136
1146
  bundle is one file whose sha256 user data checks, readable as that one object; a file-system policy
1137
1147
  refusing clients without TLS or IAM, replacing the worker's
1138
1148
  `AmazonElasticFileSystemClientReadWriteAccess`; an encrypted gp3 root volume; a boot-time upgrade to
@@ -1186,10 +1196,10 @@ failure and exits non-zero on `selfStopped`, with a code outside `RestartPrevent
1186
1196
  with its hash, as `worker/dist/index.js` and `index.js.sha256`. The default, `'asset'`, is
1187
1197
  unchanged.
1188
1198
  - `CanopyCmsService` alarms when the worker logs no git sync for 30 minutes. See
1189
- [Worker-down alarm](https://github.com/safeinsights/canopycms/blob/f47713db8d2e5c0dbb3b7ef77ea4b03c1939595a/docs/deploying-to-aws.md#worker-down-alarm).
1199
+ [Worker-down alarm](https://github.com/safeinsights/canopycms/blob/67d7e59ebd472b09175d09c620d8e2d06d333496/docs/deploying-to-aws.md#worker-down-alarm).
1190
1200
 
1191
1201
  **To adopt.** Optional. For parameter-only change sets, see
1192
- [Rolling the worker from CI](https://github.com/safeinsights/canopycms/blob/f47713db8d2e5c0dbb3b7ef77ea4b03c1939595a/docs/deploying-to-aws.md#rolling-the-worker-from-ci). For the alarm, pass
1202
+ [Rolling the worker from CI](https://github.com/safeinsights/canopycms/blob/67d7e59ebd472b09175d09c620d8e2d06d333496/docs/deploying-to-aws.md#rolling-the-worker-from-ci). For the alarm, pass
1193
1203
  `alarmTopic`.
1194
1204
 
1195
1205
  **Now deletable.** A manual `cdk deploy` after each canopycms bump whose only purpose is moving the
@@ -1200,7 +1210,7 @@ worker, and a hand-built alarm on the worker log group.
1200
1210
  **What changed.** (int.112) The boot's `dnf upgrade` could be OOM-killed on every retry. A 1 GiB
1201
1211
  swap file now goes on first; an upgrade that still fails starts the worker unpatched and notifies
1202
1212
  `alarmTopic` if set; a retried step names itself when it gives up. See
1203
- [The worker instance](https://github.com/safeinsights/canopycms/blob/f47713db8d2e5c0dbb3b7ef77ea4b03c1939595a/docs/deploying-to-aws.md#the-worker-instance).
1213
+ [The worker instance](https://github.com/safeinsights/canopycms/blob/67d7e59ebd472b09175d09c620d8e2d06d333496/docs/deploying-to-aws.md#the-worker-instance).
1204
1214
 
1205
1215
  **To adopt.** Deploy, which replaces the worker instance. The bundle needs none of this, so it is
1206
1216
  not Template first and the worker contract stays at 1.
@@ -1266,7 +1276,7 @@ and operations may reuse GitHub fetches under 30 seconds old.
1266
1276
 
1267
1277
  **To adopt.** Nothing. Seeding `remote.git` stages a copy of the repository beside the gateway's
1268
1278
  mirror, so the root volume needs room for two
1269
- ([details](https://github.com/safeinsights/canopycms/blob/f47713db8d2e5c0dbb3b7ef77ea4b03c1939595a/docs/deploying-to-aws.md#the-worker-instance)).
1279
+ ([details](https://github.com/safeinsights/canopycms/blob/67d7e59ebd472b09175d09c620d8e2d06d333496/docs/deploying-to-aws.md#the-worker-instance)).
1270
1280
 
1271
1281
  #### The worker follows a rebased or deleted GitHub branch
1272
1282
 
@@ -1288,7 +1298,7 @@ changes the template too (the fallback bundle's key and hash), so only the contr
1288
1298
  bundle-only roll is safe.
1289
1299
 
1290
1300
  **To adopt.** Parameter mode: gate bundle-only rolls on the contract
1291
- ([recipe](https://github.com/safeinsights/canopycms/blob/f47713db8d2e5c0dbb3b7ef77ea4b03c1939595a/docs/deploying-to-aws.md#rolling-the-worker-from-ci)). The gate refuses a stack without the
1301
+ ([recipe](https://github.com/safeinsights/canopycms/blob/67d7e59ebd472b09175d09c620d8e2d06d333496/docs/deploying-to-aws.md#rolling-the-worker-from-ci)). The gate refuses a stack without the
1292
1302
  `WorkerContract` output, so `cdk deploy` the template once, which adds it. A hand-installed unit
1293
1303
  copies its `Environment=CANOPYCMS_WORKER_CONTRACT=` line from `worker/canopy-worker.service`.
1294
1304
 
@@ -1305,8 +1315,8 @@ units from the bundle's contract: 2 gets the split, an older bundle the single u
1305
1315
  template, then roll the bundle; on an older template it stops with `template too old for this
1306
1316
  bundle`. Inspect EFS only through `sudo /opt/canopy-worker/canopy-inspect <command>`, never from a root shell. A hand install
1307
1317
  takes `worker/`'s three units and `gateway.env.example`
1308
- ([steps](https://github.com/safeinsights/canopycms/blob/f47713db8d2e5c0dbb3b7ef77ea4b03c1939595a/docs/deploying-to-aws.md#installing-the-units-by-hand)). After the first deploy, run the
1309
- [checklist](https://github.com/safeinsights/canopycms/blob/f47713db8d2e5c0dbb3b7ef77ea4b03c1939595a/docs/deploying-to-aws.md#first-deploy-checklist).
1318
+ ([steps](https://github.com/safeinsights/canopycms/blob/67d7e59ebd472b09175d09c620d8e2d06d333496/docs/deploying-to-aws.md#installing-the-units-by-hand)). After the first deploy, run the
1319
+ [checklist](https://github.com/safeinsights/canopycms/blob/67d7e59ebd472b09175d09c620d8e2d06d333496/docs/deploying-to-aws.md#first-deploy-checklist).
1310
1320
 
1311
1321
  #### `canopycms-cdk`: `CanopyCmsService.attachTo`, and editor response headers — **behaviour change if you frame the CMS**
1312
1322
 
@@ -1317,7 +1327,7 @@ response headers policy. `CanopyCmsDistribution` sends the same headers: `frame-
1317
1327
  `X-Frame-Options: SAMEORIGIN`, `nosniff`, HSTS and `X-Robots-Tag: noindex`. Unless your app sends
1318
1328
  its own framing headers, no other origin can frame the editor or any page the CMS domain serves. Every such page is
1319
1329
  marked `noindex`. The editor's default preview is same-origin and unaffected. See
1320
- [Serving the editor from a distribution you already own](https://github.com/safeinsights/canopycms/blob/f47713db8d2e5c0dbb3b7ef77ea4b03c1939595a/docs/deploying-to-aws.md#serving-the-editor-from-a-distribution-you-already-own).
1330
+ [Serving the editor from a distribution you already own](https://github.com/safeinsights/canopycms/blob/67d7e59ebd472b09175d09c620d8e2d06d333496/docs/deploying-to-aws.md#serving-the-editor-from-a-distribution-you-already-own).
1321
1331
 
1322
1332
  **To adopt.** If you wired the Function URL into your own distribution by hand, delete those
1323
1333
  behaviors and call `attachTo`, passing your CMS build's `assetPrefix` as `editorAssetPrefix` and a
@@ -1493,7 +1503,7 @@ one the exclusions leave out. A throw or any other return is logged and treated
1493
1503
  **To adopt.** If your site's routes, sitemap or bylines decide that some entries have no page,
1494
1504
  apply the same rule here, for example `referenceLink: (target, { body }) =>
1495
1505
  !body?.trim() ? false : undefined` in `defineAIContentConfig` from `canopycms/ai`. See
1496
- [AI Content Configuration](https://github.com/safeinsights/canopycms/blob/f47713db8d2e5c0dbb3b7ef77ea4b03c1939595a/README.md#ai-content-configuration).
1506
+ [AI Content Configuration](https://github.com/safeinsights/canopycms/blob/67d7e59ebd472b09175d09c620d8e2d06d333496/README.md#ai-content-configuration).
1497
1507
 
1498
1508
  **Now deletable.** A `fieldTransforms` entry that re-renders a reference field only to drop or
1499
1509
  change its link.
@@ -1568,7 +1578,7 @@ _First in int.115._
1568
1578
  entry the base branch also changed, the "updated on the base branch" notice and the branch's
1569
1579
  conflict count now stay until the branch merges, so a reviewer still sees which entries replaced a
1570
1580
  base change. They used to clear on the next sync, about five minutes later. README's new [Drafts
1571
- and Unpublishing](https://github.com/safeinsights/canopycms/blob/f47713db8d2e5c0dbb3b7ef77ea4b03c1939595a/README.md#drafts-and-unpublishing) section covers long-lived branches and
1581
+ and Unpublishing](https://github.com/safeinsights/canopycms/blob/67d7e59ebd472b09175d09c620d8e2d06d333496/README.md#drafts-and-unpublishing) section covers long-lived branches and
1572
1582
  unpublishing.
1573
1583
 
1574
1584
  #### The editor calls the content drawer "All content"
@@ -1880,7 +1890,7 @@ editor carries an unsaved draft of a stamped entry onto its stamped version.
1880
1890
  The flag is refused off a top-level `datetime`, on `list: true`, and with `required: true`.
1881
1891
 
1882
1892
  **To adopt.** Add `stampOnPublish: true` to the date field your site sorts or labels by, such as
1883
- `{ name: 'publishedAt', type: 'datetime', stampOnPublish: true }`. See [Stamping a publication date](https://github.com/safeinsights/canopycms/blob/f47713db8d2e5c0dbb3b7ef77ea4b03c1939595a/README.md#stamping-a-publication-date).
1893
+ `{ name: 'publishedAt', type: 'datetime', stampOnPublish: true }`. See [Stamping a publication date](https://github.com/safeinsights/canopycms/blob/67d7e59ebd472b09175d09c620d8e2d06d333496/README.md#stamping-a-publication-date).
1884
1894
 
1885
1895
  **Now deletable.** A build step or hook that writes a missing publication date into new entries.
1886
1896
 
@@ -1927,7 +1937,7 @@ preview/form divider is now keyboard-resizable within the same 15–85% the spli
1927
1937
  stored at, and `react-split-pane` is no longer a dependency.
1928
1938
  `EditorPanes`, `EditorPanesProps`, the `PaneLayout` type and the `SPLIT_PERCENT_*` and `DEFAULT_*_SPLIT_PERCENT` constants are
1929
1939
  no longer exported from `canopycms/client`. See
1930
- [Your root layout](https://github.com/safeinsights/canopycms/blob/f47713db8d2e5c0dbb3b7ef77ea4b03c1939595a/README.md#editor-customization).
1940
+ [Your root layout](https://github.com/safeinsights/canopycms/blob/67d7e59ebd472b09175d09c620d8e2d06d333496/README.md#editor-customization).
1931
1941
 
1932
1942
  **To adopt.** Nothing, unless you import `EditorPanes` or those constants: render `CanopyEditor`
1933
1943
  instead, which lays out its own panes. Hiding your site chrome on the editor route is now
@@ -2038,7 +2048,7 @@ never ended. `canopycms-auth-clerk` skips it while the editor is mounted, and ex
2038
2048
  **To adopt.** Nothing for the editor, if your edit page uses `useClerkAuthConfig()` or
2039
2049
  `ClerkSignIn`. If your CMS build renders `<SignIn>`, `UserButton` or `OrganizationSwitcher` on your
2040
2050
  own pages, mount the hook as in
2041
- [Clerk components on your own pages](https://github.com/safeinsights/canopycms/blob/f47713db8d2e5c0dbb3b7ef77ea4b03c1939595a/packages/canopycms-auth-clerk/README.md#clerk-components-on-your-own-pages).
2051
+ [Clerk components on your own pages](https://github.com/safeinsights/canopycms/blob/67d7e59ebd472b09175d09c620d8e2d06d333496/packages/canopycms-auth-clerk/README.md#clerk-components-on-your-own-pages).
2042
2052
  Your own Server Actions in the CMS build still 403 behind OAC.
2043
2053
 
2044
2054
  **Now deletable.** Any local patch of `window.__internal_onBeforeSetActive` (or 6.x's
@@ -2079,12 +2089,12 @@ fast naming the ARN, the field and the keys present, never a value.
2079
2089
  **To adopt.** Nothing, unless one of those secrets holds a JSON document: then set the matching
2080
2090
  prop. The scaffolded stack fills them from the repository _variables_
2081
2091
  `CANOPY_GITHUB_TOKEN_SECRET_JSON_FIELD` and `CLERK_SECRET_KEY_SECRET_JSON_FIELD`
2082
- ([why the prefix](https://github.com/safeinsights/canopycms/blob/f47713db8d2e5c0dbb3b7ef77ea4b03c1939595a/docs/deploying-to-aws.md#repository-secrets-and-variables)); a stack scaffolded earlier
2092
+ ([why the prefix](https://github.com/safeinsights/canopycms/blob/67d7e59ebd472b09175d09c620d8e2d06d333496/docs/deploying-to-aws.md#repository-secrets-and-variables)); a stack scaffolded earlier
2083
2093
  adds the props to `infrastructure/bin/app.ts` and `infrastructure/lib/cms-stack.ts` and the two `env`
2084
2094
  lines to `.github/workflows/deploy-cms.yml`, or re-runs the generator and diffs. `cdk synth` refuses a `…JsonField` prop without its `…SecretArn`, and an ARN carrying the ECS `:KEY::` suffix
2085
2095
  (also in `secretsArns`). Don't use CDK's `secretValueFromJson`: it resolves the plaintext into the deployed
2086
2096
  resource's configuration, readable by anyone who can describe it. Only `CLERK_SECRET_KEY` goes through Secrets Manager; `CLERK_JWT_KEY` and the publishable
2087
- key are public material ([Security Model](https://github.com/safeinsights/canopycms/blob/f47713db8d2e5c0dbb3b7ef77ea4b03c1939595a/docs/deploying-to-aws.md#security-model)).
2097
+ key are public material ([Security Model](https://github.com/safeinsights/canopycms/blob/67d7e59ebd472b09175d09c620d8e2d06d333496/docs/deploying-to-aws.md#security-model)).
2088
2098
 
2089
2099
  **Now deletable.** A wrapper that fetches the secret, parses it and re-exports one field into the
2090
2100
  worker's environment, such as a `jq` step in user data or a wrapper entrypoint around
@@ -2096,7 +2106,7 @@ worker's environment, such as a `jq` step in user data or a wrapper entrypoint a
2096
2106
  `githubToken` is not deprecated and stays the documented default; `canopycms` neither depends on
2097
2107
  nor imports `@octokit/auth-app`. Register one App per site, not one shared across repositories:
2098
2108
  anyone holding an App's key can mint a token for any of its installations
2099
- ([why](https://github.com/safeinsights/canopycms/blob/f47713db8d2e5c0dbb3b7ef77ea4b03c1939595a/ARCHITECTURE.md#why-one-github-app-per-site-not-one-shared-across-an-organisation)).
2109
+ ([why](https://github.com/safeinsights/canopycms/blob/67d7e59ebd472b09175d09c620d8e2d06d333496/ARCHITECTURE.md#why-one-github-app-per-site-not-one-shared-across-an-organisation)).
2100
2110
 
2101
2111
  **To adopt with `canopycms-cdk`** (existing stacks need no edit). `CanopyCmsServiceProps` takes
2102
2112
  `githubAppId`, `githubAppInstallationId`, `githubAppPrivateKeySecretArn` and
@@ -2109,7 +2119,7 @@ anyone holding an App's key can mint a token for any of its installations
2109
2119
  `verify` checks an existing installation's permissions: run it, since an App missing a
2110
2120
  permission only shows up later, as `sync-failed`. `create` needs an interactive terminal and
2111
2121
  never edits an existing JSON secret (create one and point the JSON-field prop at it)
2112
- ([details](https://github.com/safeinsights/canopycms/blob/f47713db8d2e5c0dbb3b7ef77ea4b03c1939595a/docs/deploying-to-aws.md#register-it-with-canopycms-init-github-app)).
2122
+ ([details](https://github.com/safeinsights/canopycms/blob/67d7e59ebd472b09175d09c620d8e2d06d333496/docs/deploying-to-aws.md#register-it-with-canopycms-init-github-app)).
2113
2123
  2. Set the three props and **remove `githubTokenSecretArn`** (with its JSON field). A partial set
2114
2124
  of the three is refused at synth, and so is an App alongside a token.
2115
2125
  3. In the generated workflow, store them as `CANOPY_GITHUB_APP_ID`,
@@ -2120,7 +2130,7 @@ anyone holding an App's key can mint a token for any of its installations
2120
2130
 
2121
2131
  The private key is ARN-only; passing the key itself is refused at synth. Its ARN joins the worker's
2122
2132
  IAM policy automatically, so you need not add it to `secretsArns`. See
2123
- [Authenticating as a GitHub App](https://github.com/safeinsights/canopycms/blob/f47713db8d2e5c0dbb3b7ef77ea4b03c1939595a/docs/deploying-to-aws.md#authenticating-as-a-github-app).
2133
+ [Authenticating as a GitHub App](https://github.com/safeinsights/canopycms/blob/67d7e59ebd472b09175d09c620d8e2d06d333496/docs/deploying-to-aws.md#authenticating-as-a-github-app).
2124
2134
 
2125
2135
  ```bash
2126
2136
  canopycms init-github-app create -- \
@@ -2168,7 +2178,7 @@ downloads the `.pem` from the App's settings page.
2168
2178
 
2169
2179
  **What changed.** The worker re-reads a Secrets Manager secret (the GitHub token or the Clerk secret
2170
2180
  key) when the operation using it fails. Timings, costs and the store-before-revoke order are in
2171
- [Rotating a secret](https://github.com/safeinsights/canopycms/blob/f47713db8d2e5c0dbb3b7ef77ea4b03c1939595a/docs/deploying-to-aws.md#rotating-a-secret).
2181
+ [Rotating a secret](https://github.com/safeinsights/canopycms/blob/67d7e59ebd472b09175d09c620d8e2d06d333496/docs/deploying-to-aws.md#rotating-a-secret).
2172
2182
 
2173
2183
  **To adopt.** Nothing for credentials from `*_SECRET_ARN`, which is every scaffolded deployment. A
2174
2184
  GitHub App private key is still read only at boot: store the new key, replace the instance, and
@@ -2222,12 +2232,12 @@ also check the bucket policy for its grant.
2222
2232
  5. `withCanopy()` adds sharp's libvips to Next's file tracing (not for a static export) and, on
2223
2233
  Next 16 and later, sets `turbopack: {}` when your config has neither `turbopack` nor your own
2224
2234
  `webpack` and it can read your Next version. A webpack build still fails its image transforms
2225
- ([Dual Build Support](https://github.com/safeinsights/canopycms/blob/f47713db8d2e5c0dbb3b7ef77ea4b03c1939595a/docs/deploying-to-aws.md#dual-build-support)).
2235
+ ([Dual Build Support](https://github.com/safeinsights/canopycms/blob/67d7e59ebd472b09175d09c620d8e2d06d333496/docs/deploying-to-aws.md#dual-build-support)).
2226
2236
 
2227
2237
  **Breaking:** a stack setting `platform` on `fromImageAsset` without `architecture` gets an arm64
2228
2238
  function while `platform` still decides the image, so `Platform.LINUX_AMD64` builds an image the
2229
2239
  function cannot run. A stack setting neither moves to arm64 with a matching image, built under QEMU
2230
- on an x86 host ([Where the image is built](https://github.com/safeinsights/canopycms/blob/f47713db8d2e5c0dbb3b7ef77ea4b03c1939595a/docs/deploying-to-aws.md#where-the-image-is-built)).
2240
+ on an x86 host ([Where the image is built](https://github.com/safeinsights/canopycms/blob/67d7e59ebd472b09175d09c620d8e2d06d333496/docs/deploying-to-aws.md#where-the-image-is-built)).
2231
2241
 
2232
2242
  **To adopt.**
2233
2243
 
@@ -2256,7 +2266,7 @@ reason; `platform` on `fromImageAsset`; and, with `withCanopy()`, a hand-written
2256
2266
 
2257
2267
  **What changed.** `media.uploadUrl` (s3 adapter; an absolute http(s) URL or a site-relative path)
2258
2268
  replaces the `url` that `beginUpload()` returns, leaving the presign's `fields` untouched, so
2259
- uploads can be same-origin. See [Media Configuration](https://github.com/safeinsights/canopycms/blob/f47713db8d2e5c0dbb3b7ef77ea4b03c1939595a/README.md#media-configuration) for the
2269
+ uploads can be same-origin. See [Media Configuration](https://github.com/safeinsights/canopycms/blob/67d7e59ebd472b09175d09c620d8e2d06d333496/README.md#media-configuration) for the
2260
2270
  CloudFront behavior it expects.
2261
2271
 
2262
2272
  **To adopt.** Optional. Set it from an environment variable: a site-relative value works only where
@@ -2281,7 +2291,7 @@ needs `lazyPublicTransforms: true`) let you pass a deterministically named role,
2281
2291
  bucket's stack computes `arn:aws:iam::<account>:role/<name>` from literals instead of a
2282
2292
  `Fn::GetStackOutput` reference only the CDK CLI resolves. The constructs re-attach
2283
2293
  `AWSLambdaBasicExecutionRole` (and the VPC policy) that `lambda.Function` drops from a role you
2284
- pass. See [Cross-account asset bucket](https://github.com/safeinsights/canopycms/blob/f47713db8d2e5c0dbb3b7ef77ea4b03c1939595a/docs/deploying-to-aws.md#cross-account-asset-bucket).
2294
+ pass. See [Cross-account asset bucket](https://github.com/safeinsights/canopycms/blob/67d7e59ebd472b09175d09c620d8e2d06d333496/docs/deploying-to-aws.md#cross-account-asset-bucket).
2285
2295
 
2286
2296
  **To adopt.** Optional:
2287
2297
 
@@ -2391,7 +2401,7 @@ public JWKS PEM, used only to verify signatures.
2391
2401
  to variables (Settings → Secrets and variables → Actions → Variables); `bin/app.ts` refuses the
2392
2402
  deploy at synth while it is unset. Check that `bin/app.ts` passes `CLERK_SECRET_KEY` as
2393
2403
  `clerkSecretKeySecretArn` (read by the worker), never in the Lambda's `environment`, unless you keep
2394
- `clerkMiddleware` ([Security Model](https://github.com/safeinsights/canopycms/blob/f47713db8d2e5c0dbb3b7ef77ea4b03c1939595a/docs/deploying-to-aws.md#security-model)).
2404
+ `clerkMiddleware` ([Security Model](https://github.com/safeinsights/canopycms/blob/67d7e59ebd472b09175d09c620d8e2d06d333496/docs/deploying-to-aws.md#security-model)).
2395
2405
 
2396
2406
  #### `readByUrlPath` answers only where `listEntries` publishes — **breaking (routing)**
2397
2407
 
@@ -2490,7 +2500,7 @@ basePath: process.env.NEXT_PUBLIC_BASE_PATH,
2490
2500
  Then pass `baseUrl` to `assetUrl` only if Next serves `/assets` (local adapter, `next dev`, S3 with
2491
2501
  no distribution): `assetUrl(image, { width: 960, baseUrl: BASE_PATH })`. Assets on CloudFront via
2492
2502
  `AssetSupport` stay at the distribution root; pass no `baseUrl` (mount table under "Where `/assets`
2493
- is mounted" in [Media Configuration](https://github.com/safeinsights/canopycms/blob/f47713db8d2e5c0dbb3b7ef77ea4b03c1939595a/README.md#media-configuration)). Two traps:
2503
+ is mounted" in [Media Configuration](https://github.com/safeinsights/canopycms/blob/67d7e59ebd472b09175d09c620d8e2d06d333496/README.md#media-configuration)). Two traps:
2494
2504
 
2495
2505
  - Don't pass a deployment `basePath` to `contentStaticParams({ basePath })`; that option filters by
2496
2506
  a nested route prefix and emits zero params, building green.
@@ -2649,7 +2659,7 @@ Under `exactOptionalPropertyTypes: true`, omit keys instead of assigning `undefi
2649
2659
  `withTrailingSlash` and `isAbsoluteUrl` from `canopycms/server`; `defineSeoFieldGroup()` from
2650
2660
  `canopycms`; `generateContentSitemap` and `entryToMetadata` from `canopycms-next`, bound on
2651
2661
  `createNextCanopyContext`'s result. See
2652
- [Sitemap and SEO Metadata](https://github.com/safeinsights/canopycms/blob/f47713db8d2e5c0dbb3b7ef77ea4b03c1939595a/README.md#sitemap-and-seo-metadata). Every routable entry type is in
2662
+ [Sitemap and SEO Metadata](https://github.com/safeinsights/canopycms/blob/67d7e59ebd472b09175d09c620d8e2d06d333496/README.md#sitemap-and-seo-metadata). Every routable entry type is in
2653
2663
  the sitemap unless `exclude`d or `noindex`; one `noindex` predicate drives both robots metadata and
2654
2664
  sitemap exclusion. `trailingSlash` is never inferred. `lastModified` defaults to `updatedAt`, a
2655
2665
  filesystem mtime. An empty SEO field counts as unset. `siteUrl` must be absolute, colliding URLs are
@@ -2706,7 +2716,7 @@ underscore-prefixed files are skipped.
2706
2716
 
2707
2717
  **What changed.** New scaffolds write `defaultBranchAccess: 'deny'` and
2708
2718
  `defaultPathAccess: { read: 'allow' }`
2709
- ([Public read on server deployments](https://github.com/safeinsights/canopycms/blob/f47713db8d2e5c0dbb3b7ef77ea4b03c1939595a/README.md#public-read-on-server-deployments)).
2719
+ ([Public read on server deployments](https://github.com/safeinsights/canopycms/blob/67d7e59ebd472b09175d09c620d8e2d06d333496/README.md#public-read-on-server-deployments)).
2710
2720
 
2711
2721
  **To adopt.** An older scaffold's `defaultBranchAccess: 'allow'` is wider than recommended;
2712
2722
  consider `'deny'`. If you deleted `defaultPathAccess: { read: 'allow' }`, anonymous visitors get no content until you
@@ -2759,7 +2769,7 @@ re-checked an entry's type (a `switch` on `meta.entryType` can merge them into o
2759
2769
  **What changed.** `BlockComponentRegistry<Blocks>` (types only, from `canopycms`; `BlockValueOf<Blocks, 'hero'>`
2760
2770
  gives one template's value type) requires exactly
2761
2771
  one component per block template name when written as an object literal. See
2762
- [Block Component Registries](https://github.com/safeinsights/canopycms/blob/f47713db8d2e5c0dbb3b7ef77ea4b03c1939595a/README.md#block-component-registries) and
2772
+ [Block Component Registries](https://github.com/safeinsights/canopycms/blob/67d7e59ebd472b09175d09c620d8e2d06d333496/README.md#block-component-registries) and
2763
2773
  `apps/example1/app/components/PostView.tsx`.
2764
2774
 
2765
2775
  ```ts
@@ -2781,7 +2791,7 @@ templates against the schema.
2781
2791
 
2782
2792
  **What changed.** Spreading a `const` field array into several schemas, and nesting
2783
2793
  `defineInlineFieldGroup()` inside a block template, are documented
2784
- ([Reusable Field Fragments](https://github.com/safeinsights/canopycms/blob/f47713db8d2e5c0dbb3b7ef77ea4b03c1939595a/README.md#reusable-field-fragments)); `defineFieldFragment()` is an
2794
+ ([Reusable Field Fragments](https://github.com/safeinsights/canopycms/blob/67d7e59ebd472b09175d09c620d8e2d06d333496/README.md#reusable-field-fragments)); `defineFieldFragment()` is an
2785
2795
  identity helper for them.
2786
2796
 
2787
2797
  ```ts
@@ -2800,7 +2810,7 @@ field by composing from the same `const` field object.
2800
2810
  A block template holding a `reference` field is a shared block; `read()`/`readByUrlPath()` resolve
2801
2811
  it, and listings do with
2802
2812
  [`resolveReferences`](#listings-resolve-references-and-a-resolved-reference-carries-urlpath-and-optionally-its-body-16--breaking-type-level)
2803
- (0.0.64). See [Shared / Referenced Blocks](https://github.com/safeinsights/canopycms/blob/f47713db8d2e5c0dbb3b7ef77ea4b03c1939595a/README.md#shared--referenced-blocks).
2813
+ (0.0.64). See [Shared / Referenced Blocks](https://github.com/safeinsights/canopycms/blob/67d7e59ebd472b09175d09c620d8e2d06d333496/README.md#shared--referenced-blocks).
2804
2814
 
2805
2815
  **Now deletable.** A second `read()` in page code to unwrap a shared block's reference.
2806
2816
 
@@ -2822,7 +2832,7 @@ Not retro-documented, apart from these:
2822
2832
 
2823
2833
  #### The registry is keyed by entry-type name (0.0.42)
2824
2834
 
2825
- **What changed.** `createEntrySchemaRegistry` keys are the entry-type names that `.collection.json` files name in `entry.schema`, and `EntryTypesFromRegistry` derives the typed entry-type map from them. Schema-variable keys (`{ postSchema }`) still work but derive nothing; [README's registry convention](https://github.com/safeinsights/canopycms/blob/f47713db8d2e5c0dbb3b7ef77ea4b03c1939595a/README.md#convention-why-key-the-registry-by-entry-type-name) says when to keep them.
2835
+ **What changed.** `createEntrySchemaRegistry` keys are the entry-type names that `.collection.json` files name in `entry.schema`, and `EntryTypesFromRegistry` derives the typed entry-type map from them. Schema-variable keys (`{ postSchema }`) still work but derive nothing; [README's registry convention](https://github.com/safeinsights/canopycms/blob/67d7e59ebd472b09175d09c620d8e2d06d333496/README.md#convention-why-key-the-registry-by-entry-type-name) says when to keep them.
2826
2836
 
2827
2837
  **To adopt.**
2828
2838
 
@@ -33,8 +33,15 @@ export interface ResolvedBranchSchema {
33
33
  issues: SchemaIssue[];
34
34
  }
35
35
  /**
36
- * Per-branch schema cache: one file in {@link schemaCacheDir} with no in-memory
37
- * layer, so it stays coherent across Lambda invocations.
36
+ * Per-branch schema cache: one file in {@link schemaCacheDir}, the only state
37
+ * shared across processes. Each process keeps the entries it parsed or wrote,
38
+ * keyed by the file's identity, so it parses an unchanged file once while the
39
+ * entry stays in its size-bounded memo. Every call still opens the file and
40
+ * runs every freshness check below on the entry, and the file is only ever
41
+ * replaced by rename (see {@link fileIdentity}), so a process is as fresh as if
42
+ * it re-read the file. The identity is fstat'ed on an open handle because NFS
43
+ * revalidates attributes on open (close-to-open), while a bare stat() may
44
+ * answer from its attribute cache.
38
45
  *
39
46
  * Freshness follows the generation-marker protocol owned by
40
47
  * resource-generation.ts, and this is one of that protocol's durable-snapshot
@@ -58,6 +65,16 @@ export interface ResolvedBranchSchema {
58
65
  export declare class BranchSchemaCache {
59
66
  /** Tracks when we last checked mtimes per contentRoot, to debounce rapid requests */
60
67
  private lastMtimeCheck;
68
+ /** Parsed cache files, by absolute path; see the class doc. */
69
+ private readonly snapshots;
70
+ /**
71
+ * In-flight resolves of the checkout during a build, by content root and registry. A build
72
+ * reads a checkout that does not change under it, so those two are its whole input and the
73
+ * result needs no revalidation. Only {@link isBuildMode}: `CANOPY_BUILD_MODE` is a build and
74
+ * script switch, and a long-lived process setting it would see a schema edit only on
75
+ * restart. A rejected resolve is dropped, so a strict-mode failure fails every read.
76
+ */
77
+ private readonly buildResolves;
61
78
  private readonly devMode;
62
79
  constructor(mode?: OperatingMode);
63
80
  /**
@@ -79,6 +96,9 @@ export declare class BranchSchemaCache {
79
96
  */
80
97
  protected resolveFresh(contentRoot: string, entrySchemaRegistry: EntrySchemaRegistry, unknownSchema: UnknownSchemaPolicy): Promise<SchemaResolutionResult>;
81
98
  private loadFromCacheOrResolve;
99
+ private resolveForBuild;
100
+ /** The parsed cache file, or null when it is absent or unreadable. */
101
+ private readSnapshot;
82
102
  /**
83
103
  * Resolve the schema fresh from disk and persist it (subject to the
84
104
  * skip-persist rule below), UNCONDITIONALLY -- never through the cache-read
@@ -1,5 +1,6 @@
1
1
  import fs from 'node:fs/promises';
2
2
  import path from 'node:path';
3
+ import { LRUCache } from 'lru-cache';
3
4
  import { resolveSchema, isValidSchema } from './schema/resolver.js';
4
5
  import { registryFingerprint } from './schema/registry-fingerprint.js';
5
6
  import { flattenSchema } from './config/flatten.js';
@@ -13,6 +14,8 @@ import { canopyLogWarn } from './utils/logger.js';
13
14
  const SCHEMA_CACHE_VERSION = 4;
14
15
  /** Minimum interval between mtime staleness checks (ms) */
15
16
  const MTIME_CHECK_DEBOUNCE_MS = 1000;
17
+ /** Cap on the parsed snapshots one process keeps, counted in bytes of their files. */
18
+ const SNAPSHOT_MEMO_MAX_BYTES = 64 * 1024 * 1024;
16
19
  /** File name of the schema cache inside {@link schemaCacheDir}. */
17
20
  export const SCHEMA_CACHE_FILE = 'schema-cache.json';
18
21
  /** resource-generation.ts resource key for the schema cache's marker. */
@@ -65,6 +68,13 @@ async function isStaleByMtime(dir, cachedAt) {
65
68
  }
66
69
  return false;
67
70
  }
71
+ /**
72
+ * Names one version of a file. Every write of the schema cache renames a new temp file into
73
+ * place, so a rewrite always changes the inode, whatever token or content it carries.
74
+ */
75
+ function fileIdentity(stat) {
76
+ return `${stat.dev}:${stat.ino}:${stat.size}:${stat.mtimeNs}`;
77
+ }
68
78
  /**
69
79
  * Directory holding a branch's schema cache: `{branchRoot}/.git/canopycms` when
70
80
  * the branch root is a full clone (every canopycms branch workspace is), else
@@ -80,8 +90,15 @@ async function schemaCacheDir(branchRoot) {
80
90
  return isClone ? path.join(gitDir, 'canopycms') : path.join(branchRoot, CANOPY_META_DIR);
81
91
  }
82
92
  /**
83
- * Per-branch schema cache: one file in {@link schemaCacheDir} with no in-memory
84
- * layer, so it stays coherent across Lambda invocations.
93
+ * Per-branch schema cache: one file in {@link schemaCacheDir}, the only state
94
+ * shared across processes. Each process keeps the entries it parsed or wrote,
95
+ * keyed by the file's identity, so it parses an unchanged file once while the
96
+ * entry stays in its size-bounded memo. Every call still opens the file and
97
+ * runs every freshness check below on the entry, and the file is only ever
98
+ * replaced by rename (see {@link fileIdentity}), so a process is as fresh as if
99
+ * it re-read the file. The identity is fstat'ed on an open handle because NFS
100
+ * revalidates attributes on open (close-to-open), while a bare stat() may
101
+ * answer from its attribute cache.
85
102
  *
86
103
  * Freshness follows the generation-marker protocol owned by
87
104
  * resource-generation.ts, and this is one of that protocol's durable-snapshot
@@ -106,6 +123,19 @@ export class BranchSchemaCache {
106
123
  constructor(mode = 'prod') {
107
124
  /** Tracks when we last checked mtimes per contentRoot, to debounce rapid requests */
108
125
  this.lastMtimeCheck = new Map();
126
+ /** Parsed cache files, by absolute path; see the class doc. */
127
+ this.snapshots = new LRUCache({
128
+ maxSize: SNAPSHOT_MEMO_MAX_BYTES,
129
+ sizeCalculation: (snapshot) => Math.max(1, snapshot.bytes),
130
+ });
131
+ /**
132
+ * In-flight resolves of the checkout during a build, by content root and registry. A build
133
+ * reads a checkout that does not change under it, so those two are its whole input and the
134
+ * result needs no revalidation. Only {@link isBuildMode}: `CANOPY_BUILD_MODE` is a build and
135
+ * script switch, and a long-lived process setting it would see a schema edit only on
136
+ * restart. A rejected resolve is dropped, so a strict-mode failure fails every read.
137
+ */
138
+ this.buildResolves = new Map();
109
139
  this.devMode = mode === 'dev';
110
140
  }
111
141
  /**
@@ -135,17 +165,12 @@ export class BranchSchemaCache {
135
165
  async loadFromCacheOrResolve(branchRoot, entrySchemaRegistry, contentRootName) {
136
166
  const contentRoot = path.join(branchRoot, contentRootName);
137
167
  const fromCheckout = this.readsCheckout(branchRoot);
168
+ if (fromCheckout && isBuildMode()) {
169
+ return this.resolveForBuild(branchRoot, entrySchemaRegistry, contentRootName);
170
+ }
138
171
  if (!fromCheckout) {
139
172
  const cachePath = path.join(await schemaCacheDir(branchRoot), SCHEMA_CACHE_FILE);
140
- let cacheData = null;
141
- try {
142
- const cacheContent = await fs.readFile(cachePath, 'utf-8');
143
- cacheData = JSON.parse(cacheContent);
144
- }
145
- catch {
146
- // Cache doesn't exist or can't be read
147
- cacheData = null;
148
- }
173
+ let cacheData = await this.readSnapshot(cachePath);
149
174
  // Strict version check, not truthiness: a snapshot from an older version
150
175
  // left on EFS by a rolling deploy has no `generation` field, and an
151
176
  // `undefined` token breaks the freshness comparison below.
@@ -187,6 +212,44 @@ export class BranchSchemaCache {
187
212
  fromCheckout,
188
213
  });
189
214
  }
215
+ resolveForBuild(branchRoot, entrySchemaRegistry, contentRootName) {
216
+ const key = `${path.resolve(branchRoot, contentRootName)}\0${registryFingerprint(entrySchemaRegistry)}`;
217
+ let pending = this.buildResolves.get(key);
218
+ if (!pending) {
219
+ pending = this.resolveFreshAndPersist(branchRoot, entrySchemaRegistry, contentRootName, {
220
+ fromCheckout: true,
221
+ });
222
+ this.buildResolves.set(key, pending);
223
+ pending.catch(() => this.buildResolves.delete(key));
224
+ }
225
+ return pending;
226
+ }
227
+ /** The parsed cache file, or null when it is absent or unreadable. */
228
+ async readSnapshot(cachePath) {
229
+ let handle;
230
+ try {
231
+ handle = await fs.open(cachePath, 'r');
232
+ }
233
+ catch {
234
+ return null;
235
+ }
236
+ try {
237
+ const stat = await handle.stat({ bigint: true });
238
+ const identity = fileIdentity(stat);
239
+ const memo = this.snapshots.get(cachePath);
240
+ if (memo?.identity === identity)
241
+ return memo.entry;
242
+ const entry = JSON.parse(await fs.readFile(handle, 'utf-8'));
243
+ this.snapshots.set(cachePath, { identity, entry, bytes: Number(stat.size) });
244
+ return entry;
245
+ }
246
+ catch {
247
+ return null;
248
+ }
249
+ finally {
250
+ await handle.close().catch(() => { });
251
+ }
252
+ }
190
253
  /**
191
254
  * Resolve the schema fresh from disk and persist it (subject to the
192
255
  * skip-persist rule below), UNCONDITIONALLY -- never through the cache-read
@@ -241,16 +304,29 @@ export class BranchSchemaCache {
241
304
  };
242
305
  // Temp file then rename, with the temp file unlinked on a failed
243
306
  // rename so a transient error leaves no stray `.tmp` beside the cache.
307
+ // The memo is seeded from the temp file's own identity, which the
308
+ // rename keeps: stat'ing cachePath afterwards could see a concurrent
309
+ // writer's file and pair it with this entry. It holds the parsed body,
310
+ // as every reader does, not the resolver's objects, which alias the
311
+ // registry and keep values JSON changes or drops.
244
312
  await fs.mkdir(cacheDir, { recursive: true });
245
313
  const tmpPath = path.join(cacheDir, `schema-cache.tmp.${Date.now()}.${Math.random()}.json`);
246
- await fs.writeFile(tmpPath, JSON.stringify(newCache, null, 2), 'utf-8');
314
+ const body = JSON.stringify(newCache);
315
+ let identity;
247
316
  try {
317
+ await fs.writeFile(tmpPath, body, 'utf-8');
318
+ identity = fileIdentity(await fs.stat(tmpPath, { bigint: true }));
248
319
  await fs.rename(tmpPath, cachePath);
249
320
  }
250
321
  catch (err) {
251
322
  await fs.unlink(tmpPath).catch(() => { });
252
323
  throw err;
253
324
  }
325
+ this.snapshots.set(cachePath, {
326
+ identity,
327
+ entry: JSON.parse(body),
328
+ bytes: Buffer.byteLength(body),
329
+ });
254
330
  }
255
331
  // else: the marker read failed for a reason other than "never bumped",
256
332
  // so no token can be attributed to this resolve, and a snapshot stamped
package/dist/cli/cli.js CHANGED
@@ -3405,6 +3405,7 @@ import path72 from "node:path";
3405
3405
  import { randomUUID as randomUUID2 } from "node:crypto";
3406
3406
  import fs72 from "node:fs/promises";
3407
3407
  import path82 from "node:path";
3408
+ import { LRUCache } from "lru-cache";
3408
3409
  import { promises as fs62 } from "fs";
3409
3410
  import { join } from "pathe";
3410
3411
  import { z as z7 } from "zod";
@@ -5706,6 +5707,9 @@ async function isStaleByMtime(dir, cachedAt) {
5706
5707
  }
5707
5708
  return false;
5708
5709
  }
5710
+ function fileIdentity(stat) {
5711
+ return `${stat.dev}:${stat.ino}:${stat.size}:${stat.mtimeNs}`;
5712
+ }
5709
5713
  async function schemaCacheDir(branchRoot) {
5710
5714
  const gitDir = path82.join(branchRoot, ".git");
5711
5715
  const isClone = await fs72.stat(gitDir).then((stat) => stat.isDirectory(), () => false);
@@ -8432,7 +8436,7 @@ async function generateAIContentCLI(options) {
8432
8436
  console.log(` Output: ${result.outputDir}
8433
8437
  `);
8434
8438
  }
8435
- var __defProp3, __getOwnPropNames3, __esm3, __export3, init_error3, init_atomic_write2, init_field_traversal, ITEM_KEY, ITEM_KEY_PATTERN, isItemKey, BASE58, isListField, init_item_keys, active2, init_logger2, SENTINEL_BASE2, DOT_SEGMENT2, init_sanitize_href2, init_normalize, RESERVED_SETTINGS_BRANCH_PREFIX2, init_branch_name, BASE58_PATTERN2, CONTENT_ID_PATTERN2, PHYSICAL_SEGMENT_PATTERN2, MAX_BRANCH_NAME_LENGTH2, init_validation, ROOT_COLLECTION_ID, init_types2, normalizePathValue, flattenSchema, init_flatten, scalarFieldTypes2, markdownFieldTypes2, primitiveFieldTypes2, fieldTypes2, init_types22, SAFE_HTML_TAGS2, COMPONENT_NAME2, MDX_BINDINGS2, FORBIDDEN_ATTRIBUTES2, init_mdx_allowlist2, fieldBaseSchema2, selectOptionSchema2, referenceOptionSchema2, primitiveFieldSchema2, mdxPropAllowSchema2, mdxAllowlistSchema2, markdownFieldSchema2, ASPECT_RATIO_RE2, imageFieldSchema2, selectFieldSchema2, referenceSortFieldSchema2, referenceFieldSchema2, fieldHolder2, blockSchema2, blockFieldSchema2, objectFieldSchema2, inlineGroupFieldSchema2, customFieldSchema2, knownFieldSchema2, fieldSchema2, init_field2, relativePathSchema2, entryTypeSchema2, collectionSchema2, init_collection2, uploadTargetUrlSchema2, previewPrefixSchema2, editorUrlSchema2, init_url2, mediaSchema2, init_media2, defaultBranchAccessSchema2, defaultPathAccessLevelSchema2, defaultPathAccessLevelsSchema2, defaultPathAccessSchema2, defaultBaseBranchSchema2, defaultRemoteNameSchema2, defaultRemoteUrlSchema2, gitBotAuthorNameSchema2, gitBotAuthorEmailSchema2, githubTokenEnvVarSchema2, operatingModeSchema2, deployedAsSchema2, contentRootSchema2, sourceRootSchema2, basePathSchema2, deploymentNameSchema2, devContentSyncSchema2, devConfigSchema2, editorConfigSchema2, seoFieldNameSchema2, seoSchema2, CanopyConfigSchema2, DEFAULT_PROD_WORKSPACE2, init_config3, SERVER_MODE_ENV_VAR, BROWSER_MODE_ENV_VAR, warned22, init_mode_env, forEachReferenceField, init_validation2, ProdClientSafeStrategy2, DevClientSafeStrategy2, clientStrategyCache, init_client_safe_strategy, warned3, VALID_DEPLOYMENT_NAME2, isValidDeploymentName2, init_deployment_name, warned4, DEPLOYMENT_PLACEHOLDER2, DEFAULT_BRANCH_NAMESPACE_TEMPLATE2, BRANCH_NAMESPACE_ENV2, init_branch_namespace, init_config22, ProdStrategy2, DevStrategy2, strategyCache2, init_client_unsafe_strategy, operating_mode_exports, init_operating_mode, task_queue_config_exports2, init_task_queue_config2, worker_status_exports, WORKER_STATUS_FILE, init_worker_status, BLOCK_DISCRIMINATOR_KEYS, BLOCK_STRUCTURAL_KEYS, envFlag2, LOG_LEVELS2, DebugLogger2, testLogger2, MARKDOWN_EXPORT_OPTIONS, BULLETS, DELIMITERS, EMPHASIS, STRONG, RULE, WORD_CHAR, GAP, Restyler, END, FRESH, LINE_WIDTH, MIN_LINE_WIDTH, SourceSplicer, log2, MAX_LCS_CELLS, Splicer, log22, EVIDENCE_MAX_DEPTH, log3, locks, PROVISIONING_LOCK_STALE_MS, sleep, META_DIR, CONTENT_WRITE_LOCK_NAME, DEFAULT_CONTENT_WRITE_LOCK_WAIT_MS, ContentWriteLockBusyError, sleep2, CONTENT_WRITE_LOCK_STALE_MS, heldRoots, getFormatExtension, isDataOnlyFormat, asRecord, DEFAULT_SEO_FIELD_NAMES, asRecord2, asText, asFlag, asImageUrl, asOgType, asTwitterCard, RESTRICTED_REFERENCE_MARKER, SEO_GROUP_FIELDS, MAX_WARNED, warned5, SchemaUnavailableError, isValidId, parseTypedFilename, EMPTY_LOGICAL_PATH, ENTRY_EXTENSIONS, ContentIdIndex, CONTENT_EXTENSIONS, registry, finalization, log4, META_DIR2, entryTypeMetaSchema, collectionMetaSchema, rootCollectionMetaSchema, fingerprints, editDistance, closestName, forEachEntryType, collectEntryTypeNames, validateReferenceEntryTypes, isDeployedStatic, isBuildMode, readsFromCheckout, STATIC_DEPLOY_USER, storage, log5, BaseBranchUnresolvedError, NETWORK_SCHEME_PATTERN, TRANSPORT_HELPER_PATTERN, LEADING_OPTION_PATTERN, WINDOWS_DRIVE_PATTERN, COLON_BEFORE_SLASH_PATTERN, MISSING_REMOTE_REF_REASONS, CANOPY_META_DIR, SCHEMA_CACHE_VERSION, MTIME_CHECK_DEBOUNCE_MS, SCHEMA_CACHE_FILE, SCHEMA_GENERATION_RESOURCE, reportedIssues, BranchSchemaCache, RESOURCE, BranchPathError, resolveContentBranchesRoot, ContentStoreError, ContentConflictError, EntryGoneError, BranchSyncingError, DuplicateContentIdError, UrlPathConflictError, isEmptyFieldValue, DEFAULT_INDEX_FRESHNESS_INTERVAL_MS, FORCED_REFRESH_MIN_INTERVAL_MS, STALE_LOOKUP, isMissingReference, createReferenceResolveCache, ContentStore, ATTR_CONTENT, BLOCK_PREFIX, BLOCK_SUFFIX, BLOCK_RESTORE_RE, INLINE_PREFIX, INLINE_SUFFIX, INLINE_RESTORE_RE, DEFAULT_REFERENCE_RENDERING, FLAT_CELL_TYPES, log6, BASE58_CHAR, ENTRY_LINK_PATTERN, INLINE_LINK_TARGET, BranchMetadataCorruptError, BRANCH_META_DIR, BRANCH_META_FILE, branchMetadataFilePath, UNKNOWN_TIME, enumOf, branchMetadataShape, branchMetadataSchema, branchMetadataFileSchema, log7, REGISTRY_FILE, REGISTRY_STALE_FILE, REGISTRY_TEMP_FILE, REGISTRY_VERSION, RESOURCE2, GET_MISS_REFRESH_MIN_INTERVAL_MS, snapshotSchema, reportedUnreadable, BranchRegistry, log8, OccWriteConflictError, CURRENT_SCHEMA_VERSION, BranchMetadataConflictError, BranchMetadataFileManager, loadBranchContext, GitProcessError, STDERR_CAP_BYTES, KILL_GRACE_MS, log9, GIT_ENV_PASSTHROUGH, FORCE_C_LOCALE, GIT_NETWORK_ENV_PASSTHROUGH, NO_AUTO_GC_CONFIG, HASH_INACTIVITY_TIMEOUT_MS, MAX_HASH_RUNS, LS_REMOTE_INACTIVITY_TIMEOUT_MS, symlinkBlobSha, REMOTE_GIT_CONFIG, REMOTE_GIT_MAX_LOOSE_OBJECTS, REMOTE_GIT_MAX_PACKS, PARALLEL_CHECKOUT_ARGS, remoteInitLocks, GITHUB_TRACKING_REF_PREFIX, BaseBranchMissingError, GitConflictError, GitRemoteRefMissingError, RemoteNotReadyError, SettingsRemoteUnreadableError, SettingsBranchDivergedError, SETTINGS_BRANCH_FILES, SettingsBranchHasContentHistoryError, GitManager, PUBLISH_LOCK_WAIT_MS, CREATE_RESIDUE_MIN_QUIET_MS, STAGING_MAX_AGE_MS, REPAIR_MAX_AGE_MS, DELETING_MAX_AGE_MS, SETTINGS_TRASH_MAX_AGE_MS, BranchProvisioningBusyError, BranchDirOccupiedError, STAGING_PREFIX, REPAIR_PREFIX, TRASH_PREFIX, stagingDirName, NO_GIT, RENAME_BLOCKED, SPARSE_CONE_RECORD, defaultSink, sink, ProvisionLog, testHooks, provisionsInFlight, BranchWorkspaceManager, log10, normalizePath, parseEntryParts, parseEntryData, readEntryData, createReferenceResolver, withoutUnavailableEntries, resolveCollectionItemReferences, looksLikeMalformedEntry, listCollectionEntries, MAX_INPUT_PIXELS, CROP_PRECISION, KNOWN_FIELD_TYPES, STRING_FIELD_TYPES, selectOptionValues, GENERATED_RECORD_FILENAME, SAFE_BUILD_ID, BUILD_ID_RULE, jiti;
8439
+ var __defProp3, __getOwnPropNames3, __esm3, __export3, init_error3, init_atomic_write2, init_field_traversal, ITEM_KEY, ITEM_KEY_PATTERN, isItemKey, BASE58, isListField, init_item_keys, active2, init_logger2, SENTINEL_BASE2, DOT_SEGMENT2, init_sanitize_href2, init_normalize, RESERVED_SETTINGS_BRANCH_PREFIX2, init_branch_name, BASE58_PATTERN2, CONTENT_ID_PATTERN2, PHYSICAL_SEGMENT_PATTERN2, MAX_BRANCH_NAME_LENGTH2, init_validation, ROOT_COLLECTION_ID, init_types2, normalizePathValue, flattenSchema, init_flatten, scalarFieldTypes2, markdownFieldTypes2, primitiveFieldTypes2, fieldTypes2, init_types22, SAFE_HTML_TAGS2, COMPONENT_NAME2, MDX_BINDINGS2, FORBIDDEN_ATTRIBUTES2, init_mdx_allowlist2, fieldBaseSchema2, selectOptionSchema2, referenceOptionSchema2, primitiveFieldSchema2, mdxPropAllowSchema2, mdxAllowlistSchema2, markdownFieldSchema2, ASPECT_RATIO_RE2, imageFieldSchema2, selectFieldSchema2, referenceSortFieldSchema2, referenceFieldSchema2, fieldHolder2, blockSchema2, blockFieldSchema2, objectFieldSchema2, inlineGroupFieldSchema2, customFieldSchema2, knownFieldSchema2, fieldSchema2, init_field2, relativePathSchema2, entryTypeSchema2, collectionSchema2, init_collection2, uploadTargetUrlSchema2, previewPrefixSchema2, editorUrlSchema2, init_url2, mediaSchema2, init_media2, defaultBranchAccessSchema2, defaultPathAccessLevelSchema2, defaultPathAccessLevelsSchema2, defaultPathAccessSchema2, defaultBaseBranchSchema2, defaultRemoteNameSchema2, defaultRemoteUrlSchema2, gitBotAuthorNameSchema2, gitBotAuthorEmailSchema2, githubTokenEnvVarSchema2, operatingModeSchema2, deployedAsSchema2, contentRootSchema2, sourceRootSchema2, basePathSchema2, deploymentNameSchema2, devContentSyncSchema2, devConfigSchema2, editorConfigSchema2, seoFieldNameSchema2, seoSchema2, CanopyConfigSchema2, DEFAULT_PROD_WORKSPACE2, init_config3, SERVER_MODE_ENV_VAR, BROWSER_MODE_ENV_VAR, warned22, init_mode_env, forEachReferenceField, init_validation2, ProdClientSafeStrategy2, DevClientSafeStrategy2, clientStrategyCache, init_client_safe_strategy, warned3, VALID_DEPLOYMENT_NAME2, isValidDeploymentName2, init_deployment_name, warned4, DEPLOYMENT_PLACEHOLDER2, DEFAULT_BRANCH_NAMESPACE_TEMPLATE2, BRANCH_NAMESPACE_ENV2, init_branch_namespace, init_config22, ProdStrategy2, DevStrategy2, strategyCache2, init_client_unsafe_strategy, operating_mode_exports, init_operating_mode, task_queue_config_exports2, init_task_queue_config2, worker_status_exports, WORKER_STATUS_FILE, init_worker_status, BLOCK_DISCRIMINATOR_KEYS, BLOCK_STRUCTURAL_KEYS, envFlag2, LOG_LEVELS2, DebugLogger2, testLogger2, MARKDOWN_EXPORT_OPTIONS, BULLETS, DELIMITERS, EMPHASIS, STRONG, RULE, WORD_CHAR, GAP, Restyler, END, FRESH, LINE_WIDTH, MIN_LINE_WIDTH, SourceSplicer, log2, MAX_LCS_CELLS, Splicer, log22, EVIDENCE_MAX_DEPTH, log3, locks, PROVISIONING_LOCK_STALE_MS, sleep, META_DIR, CONTENT_WRITE_LOCK_NAME, DEFAULT_CONTENT_WRITE_LOCK_WAIT_MS, ContentWriteLockBusyError, sleep2, CONTENT_WRITE_LOCK_STALE_MS, heldRoots, getFormatExtension, isDataOnlyFormat, asRecord, DEFAULT_SEO_FIELD_NAMES, asRecord2, asText, asFlag, asImageUrl, asOgType, asTwitterCard, RESTRICTED_REFERENCE_MARKER, SEO_GROUP_FIELDS, MAX_WARNED, warned5, SchemaUnavailableError, isValidId, parseTypedFilename, EMPTY_LOGICAL_PATH, ENTRY_EXTENSIONS, ContentIdIndex, CONTENT_EXTENSIONS, registry, finalization, log4, META_DIR2, entryTypeMetaSchema, collectionMetaSchema, rootCollectionMetaSchema, fingerprints, editDistance, closestName, forEachEntryType, collectEntryTypeNames, validateReferenceEntryTypes, isDeployedStatic, isBuildMode, readsFromCheckout, STATIC_DEPLOY_USER, storage, log5, BaseBranchUnresolvedError, NETWORK_SCHEME_PATTERN, TRANSPORT_HELPER_PATTERN, LEADING_OPTION_PATTERN, WINDOWS_DRIVE_PATTERN, COLON_BEFORE_SLASH_PATTERN, MISSING_REMOTE_REF_REASONS, CANOPY_META_DIR, SCHEMA_CACHE_VERSION, MTIME_CHECK_DEBOUNCE_MS, SNAPSHOT_MEMO_MAX_BYTES, SCHEMA_CACHE_FILE, SCHEMA_GENERATION_RESOURCE, reportedIssues, BranchSchemaCache, RESOURCE, BranchPathError, resolveContentBranchesRoot, ContentStoreError, ContentConflictError, EntryGoneError, BranchSyncingError, DuplicateContentIdError, UrlPathConflictError, isEmptyFieldValue, DEFAULT_INDEX_FRESHNESS_INTERVAL_MS, FORCED_REFRESH_MIN_INTERVAL_MS, STALE_LOOKUP, isMissingReference, createReferenceResolveCache, ContentStore, ATTR_CONTENT, BLOCK_PREFIX, BLOCK_SUFFIX, BLOCK_RESTORE_RE, INLINE_PREFIX, INLINE_SUFFIX, INLINE_RESTORE_RE, DEFAULT_REFERENCE_RENDERING, FLAT_CELL_TYPES, log6, BASE58_CHAR, ENTRY_LINK_PATTERN, INLINE_LINK_TARGET, BranchMetadataCorruptError, BRANCH_META_DIR, BRANCH_META_FILE, branchMetadataFilePath, UNKNOWN_TIME, enumOf, branchMetadataShape, branchMetadataSchema, branchMetadataFileSchema, log7, REGISTRY_FILE, REGISTRY_STALE_FILE, REGISTRY_TEMP_FILE, REGISTRY_VERSION, RESOURCE2, GET_MISS_REFRESH_MIN_INTERVAL_MS, snapshotSchema, reportedUnreadable, BranchRegistry, log8, OccWriteConflictError, CURRENT_SCHEMA_VERSION, BranchMetadataConflictError, BranchMetadataFileManager, loadBranchContext, GitProcessError, STDERR_CAP_BYTES, KILL_GRACE_MS, log9, GIT_ENV_PASSTHROUGH, FORCE_C_LOCALE, GIT_NETWORK_ENV_PASSTHROUGH, NO_AUTO_GC_CONFIG, HASH_INACTIVITY_TIMEOUT_MS, MAX_HASH_RUNS, LS_REMOTE_INACTIVITY_TIMEOUT_MS, symlinkBlobSha, REMOTE_GIT_CONFIG, REMOTE_GIT_MAX_LOOSE_OBJECTS, REMOTE_GIT_MAX_PACKS, PARALLEL_CHECKOUT_ARGS, remoteInitLocks, GITHUB_TRACKING_REF_PREFIX, BaseBranchMissingError, GitConflictError, GitRemoteRefMissingError, RemoteNotReadyError, SettingsRemoteUnreadableError, SettingsBranchDivergedError, SETTINGS_BRANCH_FILES, SettingsBranchHasContentHistoryError, GitManager, PUBLISH_LOCK_WAIT_MS, CREATE_RESIDUE_MIN_QUIET_MS, STAGING_MAX_AGE_MS, REPAIR_MAX_AGE_MS, DELETING_MAX_AGE_MS, SETTINGS_TRASH_MAX_AGE_MS, BranchProvisioningBusyError, BranchDirOccupiedError, STAGING_PREFIX, REPAIR_PREFIX, TRASH_PREFIX, stagingDirName, NO_GIT, RENAME_BLOCKED, SPARSE_CONE_RECORD, defaultSink, sink, ProvisionLog, testHooks, provisionsInFlight, BranchWorkspaceManager, log10, normalizePath, parseEntryParts, parseEntryData, readEntryData, createReferenceResolver, withoutUnavailableEntries, resolveCollectionItemReferences, looksLikeMalformedEntry, listCollectionEntries, MAX_INPUT_PIXELS, CROP_PRECISION, KNOWN_FIELD_TYPES, STRING_FIELD_TYPES, selectOptionValues, GENERATED_RECORD_FILENAME, SAFE_BUILD_ID, BUILD_ID_RULE, jiti;
8436
8440
  var init_generate_ai_content = __esm({
8437
8441
  "dist/cli/generate-ai-content.js"() {
8438
8442
  "use strict";
@@ -10878,12 +10882,18 @@ var init_generate_ai_content = __esm({
10878
10882
  init_logger2();
10879
10883
  SCHEMA_CACHE_VERSION = 4;
10880
10884
  MTIME_CHECK_DEBOUNCE_MS = 1e3;
10885
+ SNAPSHOT_MEMO_MAX_BYTES = 64 * 1024 * 1024;
10881
10886
  SCHEMA_CACHE_FILE = "schema-cache.json";
10882
10887
  SCHEMA_GENERATION_RESOURCE = "schema";
10883
10888
  reportedIssues = /* @__PURE__ */ new Set();
10884
10889
  BranchSchemaCache = class {
10885
10890
  constructor(mode = "prod") {
10886
10891
  this.lastMtimeCheck = /* @__PURE__ */ new Map();
10892
+ this.snapshots = new LRUCache({
10893
+ maxSize: SNAPSHOT_MEMO_MAX_BYTES,
10894
+ sizeCalculation: (snapshot) => Math.max(1, snapshot.bytes)
10895
+ });
10896
+ this.buildResolves = /* @__PURE__ */ new Map();
10887
10897
  this.devMode = mode === "dev";
10888
10898
  }
10889
10899
  /**
@@ -10913,15 +10923,12 @@ var init_generate_ai_content = __esm({
10913
10923
  async loadFromCacheOrResolve(branchRoot, entrySchemaRegistry, contentRootName) {
10914
10924
  const contentRoot = path82.join(branchRoot, contentRootName);
10915
10925
  const fromCheckout = this.readsCheckout(branchRoot);
10926
+ if (fromCheckout && isBuildMode()) {
10927
+ return this.resolveForBuild(branchRoot, entrySchemaRegistry, contentRootName);
10928
+ }
10916
10929
  if (!fromCheckout) {
10917
10930
  const cachePath = path82.join(await schemaCacheDir(branchRoot), SCHEMA_CACHE_FILE);
10918
- let cacheData = null;
10919
- try {
10920
- const cacheContent = await fs72.readFile(cachePath, "utf-8");
10921
- cacheData = JSON.parse(cacheContent);
10922
- } catch {
10923
- cacheData = null;
10924
- }
10931
+ let cacheData = await this.readSnapshot(cachePath);
10925
10932
  if (cacheData && cacheData.version === SCHEMA_CACHE_VERSION && cacheData.registryFingerprint === registryFingerprint(entrySchemaRegistry)) {
10926
10933
  const read = await readResourceGeneration(branchRoot, SCHEMA_GENERATION_RESOURCE);
10927
10934
  if (isGenerationCurrent(cacheData.generation, read)) {
@@ -10951,6 +10958,42 @@ var init_generate_ai_content = __esm({
10951
10958
  fromCheckout
10952
10959
  });
10953
10960
  }
10961
+ resolveForBuild(branchRoot, entrySchemaRegistry, contentRootName) {
10962
+ const key = `${path82.resolve(branchRoot, contentRootName)}\0${registryFingerprint(entrySchemaRegistry)}`;
10963
+ let pending = this.buildResolves.get(key);
10964
+ if (!pending) {
10965
+ pending = this.resolveFreshAndPersist(branchRoot, entrySchemaRegistry, contentRootName, {
10966
+ fromCheckout: true
10967
+ });
10968
+ this.buildResolves.set(key, pending);
10969
+ pending.catch(() => this.buildResolves.delete(key));
10970
+ }
10971
+ return pending;
10972
+ }
10973
+ /** The parsed cache file, or null when it is absent or unreadable. */
10974
+ async readSnapshot(cachePath) {
10975
+ let handle;
10976
+ try {
10977
+ handle = await fs72.open(cachePath, "r");
10978
+ } catch {
10979
+ return null;
10980
+ }
10981
+ try {
10982
+ const stat = await handle.stat({ bigint: true });
10983
+ const identity = fileIdentity(stat);
10984
+ const memo = this.snapshots.get(cachePath);
10985
+ if (memo?.identity === identity)
10986
+ return memo.entry;
10987
+ const entry = JSON.parse(await fs72.readFile(handle, "utf-8"));
10988
+ this.snapshots.set(cachePath, { identity, entry, bytes: Number(stat.size) });
10989
+ return entry;
10990
+ } catch {
10991
+ return null;
10992
+ } finally {
10993
+ await handle.close().catch(() => {
10994
+ });
10995
+ }
10996
+ }
10954
10997
  /**
10955
10998
  * Resolve the schema fresh from disk and persist it (subject to the
10956
10999
  * skip-persist rule below), UNCONDITIONALLY -- never through the cache-read
@@ -10992,14 +11035,22 @@ var init_generate_ai_content = __esm({
10992
11035
  };
10993
11036
  await fs72.mkdir(cacheDir, { recursive: true });
10994
11037
  const tmpPath = path82.join(cacheDir, `schema-cache.tmp.${Date.now()}.${Math.random()}.json`);
10995
- await fs72.writeFile(tmpPath, JSON.stringify(newCache, null, 2), "utf-8");
11038
+ const body = JSON.stringify(newCache);
11039
+ let identity;
10996
11040
  try {
11041
+ await fs72.writeFile(tmpPath, body, "utf-8");
11042
+ identity = fileIdentity(await fs72.stat(tmpPath, { bigint: true }));
10997
11043
  await fs72.rename(tmpPath, cachePath);
10998
11044
  } catch (err2) {
10999
11045
  await fs72.unlink(tmpPath).catch(() => {
11000
11046
  });
11001
11047
  throw err2;
11002
11048
  }
11049
+ this.snapshots.set(cachePath, {
11050
+ identity,
11051
+ entry: JSON.parse(body),
11052
+ bytes: Buffer.byteLength(body)
11053
+ });
11003
11054
  }
11004
11055
  }
11005
11056
  reportSchemaIssues(issues);
@@ -18064,10 +18115,12 @@ var init_meta_loader = __esm({
18064
18115
  });
18065
18116
 
18066
18117
  // dist/branch-schema-cache.js
18067
- var SCHEMA_GENERATION_RESOURCE2;
18118
+ import { LRUCache as LRUCache2 } from "lru-cache";
18119
+ var SNAPSHOT_MEMO_MAX_BYTES2, SCHEMA_GENERATION_RESOURCE2;
18068
18120
  var init_branch_schema_cache = __esm({
18069
18121
  "dist/branch-schema-cache.js"() {
18070
18122
  "use strict";
18123
+ SNAPSHOT_MEMO_MAX_BYTES2 = 64 * 1024 * 1024;
18071
18124
  SCHEMA_GENERATION_RESOURCE2 = "schema";
18072
18125
  }
18073
18126
  });
@@ -4443,6 +4443,7 @@ function isGenerationCurrent(snapshotToken, read) {
4443
4443
  // dist/branch-schema-cache.js
4444
4444
  import fs7 from "node:fs/promises";
4445
4445
  import path8 from "node:path";
4446
+ import { LRUCache } from "lru-cache";
4446
4447
 
4447
4448
  // dist/schema/meta-loader.js
4448
4449
  import { promises as fs6 } from "fs";
@@ -4902,6 +4903,7 @@ async function resolveBaseBranch(options) {
4902
4903
  init_logger();
4903
4904
  var SCHEMA_CACHE_VERSION = 4;
4904
4905
  var MTIME_CHECK_DEBOUNCE_MS = 1e3;
4906
+ var SNAPSHOT_MEMO_MAX_BYTES = 64 * 1024 * 1024;
4905
4907
  var SCHEMA_CACHE_FILE = "schema-cache.json";
4906
4908
  var SCHEMA_GENERATION_RESOURCE = "schema";
4907
4909
  var reportedIssues = /* @__PURE__ */ new Set();
@@ -4935,6 +4937,9 @@ async function isStaleByMtime(dir, cachedAt) {
4935
4937
  }
4936
4938
  return false;
4937
4939
  }
4940
+ function fileIdentity(stat) {
4941
+ return `${stat.dev}:${stat.ino}:${stat.size}:${stat.mtimeNs}`;
4942
+ }
4938
4943
  async function schemaCacheDir(branchRoot) {
4939
4944
  const gitDir = path8.join(branchRoot, ".git");
4940
4945
  const isClone = await fs7.stat(gitDir).then((stat) => stat.isDirectory(), () => false);
@@ -4943,6 +4948,11 @@ async function schemaCacheDir(branchRoot) {
4943
4948
  var BranchSchemaCache = class {
4944
4949
  constructor(mode = "prod") {
4945
4950
  this.lastMtimeCheck = /* @__PURE__ */ new Map();
4951
+ this.snapshots = new LRUCache({
4952
+ maxSize: SNAPSHOT_MEMO_MAX_BYTES,
4953
+ sizeCalculation: (snapshot) => Math.max(1, snapshot.bytes)
4954
+ });
4955
+ this.buildResolves = /* @__PURE__ */ new Map();
4946
4956
  this.devMode = mode === "dev";
4947
4957
  }
4948
4958
  /**
@@ -4972,15 +4982,12 @@ var BranchSchemaCache = class {
4972
4982
  async loadFromCacheOrResolve(branchRoot, entrySchemaRegistry, contentRootName) {
4973
4983
  const contentRoot = path8.join(branchRoot, contentRootName);
4974
4984
  const fromCheckout = this.readsCheckout(branchRoot);
4985
+ if (fromCheckout && isBuildMode()) {
4986
+ return this.resolveForBuild(branchRoot, entrySchemaRegistry, contentRootName);
4987
+ }
4975
4988
  if (!fromCheckout) {
4976
4989
  const cachePath = path8.join(await schemaCacheDir(branchRoot), SCHEMA_CACHE_FILE);
4977
- let cacheData = null;
4978
- try {
4979
- const cacheContent = await fs7.readFile(cachePath, "utf-8");
4980
- cacheData = JSON.parse(cacheContent);
4981
- } catch {
4982
- cacheData = null;
4983
- }
4990
+ let cacheData = await this.readSnapshot(cachePath);
4984
4991
  if (cacheData && cacheData.version === SCHEMA_CACHE_VERSION && cacheData.registryFingerprint === registryFingerprint(entrySchemaRegistry)) {
4985
4992
  const read = await readResourceGeneration(branchRoot, SCHEMA_GENERATION_RESOURCE);
4986
4993
  if (isGenerationCurrent(cacheData.generation, read)) {
@@ -5010,6 +5017,42 @@ var BranchSchemaCache = class {
5010
5017
  fromCheckout
5011
5018
  });
5012
5019
  }
5020
+ resolveForBuild(branchRoot, entrySchemaRegistry, contentRootName) {
5021
+ const key = `${path8.resolve(branchRoot, contentRootName)}\0${registryFingerprint(entrySchemaRegistry)}`;
5022
+ let pending = this.buildResolves.get(key);
5023
+ if (!pending) {
5024
+ pending = this.resolveFreshAndPersist(branchRoot, entrySchemaRegistry, contentRootName, {
5025
+ fromCheckout: true
5026
+ });
5027
+ this.buildResolves.set(key, pending);
5028
+ pending.catch(() => this.buildResolves.delete(key));
5029
+ }
5030
+ return pending;
5031
+ }
5032
+ /** The parsed cache file, or null when it is absent or unreadable. */
5033
+ async readSnapshot(cachePath) {
5034
+ let handle;
5035
+ try {
5036
+ handle = await fs7.open(cachePath, "r");
5037
+ } catch {
5038
+ return null;
5039
+ }
5040
+ try {
5041
+ const stat = await handle.stat({ bigint: true });
5042
+ const identity = fileIdentity(stat);
5043
+ const memo = this.snapshots.get(cachePath);
5044
+ if (memo?.identity === identity)
5045
+ return memo.entry;
5046
+ const entry = JSON.parse(await fs7.readFile(handle, "utf-8"));
5047
+ this.snapshots.set(cachePath, { identity, entry, bytes: Number(stat.size) });
5048
+ return entry;
5049
+ } catch {
5050
+ return null;
5051
+ } finally {
5052
+ await handle.close().catch(() => {
5053
+ });
5054
+ }
5055
+ }
5013
5056
  /**
5014
5057
  * Resolve the schema fresh from disk and persist it (subject to the
5015
5058
  * skip-persist rule below), UNCONDITIONALLY -- never through the cache-read
@@ -5051,14 +5094,22 @@ var BranchSchemaCache = class {
5051
5094
  };
5052
5095
  await fs7.mkdir(cacheDir, { recursive: true });
5053
5096
  const tmpPath = path8.join(cacheDir, `schema-cache.tmp.${Date.now()}.${Math.random()}.json`);
5054
- await fs7.writeFile(tmpPath, JSON.stringify(newCache, null, 2), "utf-8");
5097
+ const body = JSON.stringify(newCache);
5098
+ let identity;
5055
5099
  try {
5100
+ await fs7.writeFile(tmpPath, body, "utf-8");
5101
+ identity = fileIdentity(await fs7.stat(tmpPath, { bigint: true }));
5056
5102
  await fs7.rename(tmpPath, cachePath);
5057
5103
  } catch (err) {
5058
5104
  await fs7.unlink(tmpPath).catch(() => {
5059
5105
  });
5060
5106
  throw err;
5061
5107
  }
5108
+ this.snapshots.set(cachePath, {
5109
+ identity,
5110
+ entry: JSON.parse(body),
5111
+ bytes: Buffer.byteLength(body)
5112
+ });
5062
5113
  }
5063
5114
  }
5064
5115
  reportSchemaIssues(issues);
@@ -89,20 +89,34 @@ export interface ContentReadMeta {
89
89
  /** The entry's URL path with no query, by the rule `listEntries` uses. */
90
90
  urlPath: string;
91
91
  }
92
+ /** What a content read resolves to. */
93
+ export interface ContentReadResult<T = unknown> {
94
+ data: T;
95
+ /**
96
+ * The requested `entryPath` and slug as a percent-encoded URL path, plus `?branch=<name>`.
97
+ * Through an entry-type `entryPath` it is not the entry's URL. Compare entries by
98
+ * `meta.urlPath`.
99
+ */
100
+ path: string;
101
+ meta: ContentReadMeta;
102
+ }
92
103
  export interface ContentReader {
93
- read: <T = unknown>(input: ReadContentInput, message?: string) => Promise<{
94
- data: T;
95
- /**
96
- * The requested `entryPath` and slug as a percent-encoded URL path, plus `?branch=<name>`.
97
- * Through an entry-type `entryPath` it is not the entry's URL. Compare entries by
98
- * `meta.urlPath`.
99
- */
100
- path: string;
101
- meta: ContentReadMeta;
102
- }>;
104
+ read: <T = unknown>(input: ReadContentInput, message?: string) => Promise<ContentReadResult<T>>;
105
+ }
106
+ /** @internal The reader `CanopyContext` (context.ts) builds on. */
107
+ export interface ContentReaderInternal extends ContentReader {
108
+ /**
109
+ * Read the first of `inputs` that resolves, against one store resolved once for their branch,
110
+ * so a lookup trying several paths resolves the branch and its schema once. Every input must
111
+ * name the same branch and user. An error `isMiss` accepts moves on to the next input; null
112
+ * when every input misses, or when resolving the branch itself throws a miss.
113
+ */
114
+ readFirst: <T = unknown>(inputs: readonly ReadContentInput[], isMiss: (err: unknown, input: ReadContentInput) => boolean) => Promise<ContentReadResult<T> | null>;
103
115
  }
104
116
  /**
105
117
  * Server-side helper to read content directly from a branch workspace. A branch with no workspace
106
118
  * reads as NOT_FOUND unless `allowCreateBranch` or a `getBranchContext` resolver says otherwise.
107
119
  */
108
120
  export declare const createContentReader: (options: ContentReaderOptions) => ContentReader;
121
+ /** @internal {@link createContentReader} plus `readFirst`, for context.ts. */
122
+ export declare const createContentReaderInternal: (options: ContentReaderOptions) => ContentReaderInternal;
@@ -16,6 +16,11 @@ import { CONTENT_READER_USER_ID } from './system-users.js';
16
16
  * reads as NOT_FOUND unless `allowCreateBranch` or a `getBranchContext` resolver says otherwise.
17
17
  */
18
18
  export const createContentReader = (options) => {
19
+ const { read } = createContentReaderInternal(options);
20
+ return { read };
21
+ };
22
+ /** @internal {@link createContentReader} plus `readFirst`, for context.ts. */
23
+ export const createContentReaderInternal = (options) => {
19
24
  const services = options.services;
20
25
  const operatingMode = services.config.mode;
21
26
  const basePathOverride = options.basePathOverride;
@@ -127,9 +132,9 @@ export const createContentReader = (options) => {
127
132
  const url = encodedSlug ? `${trimmed}/${encodedSlug}` : trimmed || '/';
128
133
  return appendBranch(url);
129
134
  };
130
- const readDocument = async (input) => {
131
- const { entryPath, slug, branchName, user } = resolveTarget(input);
132
- const { context, branchRoot, store } = await resolveStore(branchName);
135
+ const readDocument = async (input, resolved) => {
136
+ const { entryPath, slug, user } = resolveTarget(input);
137
+ const { context, branchRoot, store } = resolved;
133
138
  // Rule 1 of urlAddressableOnly (see ReadContentInput): a published URL's non-slug segments
134
139
  // are collection names, so a candidate landing on an entry-TYPE item can only ever produce a
135
140
  // URL enumeration never emits. NO_SCHEMA_ITEM is what assertCollection raises for exactly
@@ -216,9 +221,9 @@ export const createContentReader = (options) => {
216
221
  throw err;
217
222
  }
218
223
  };
219
- const read = async (input, message) => {
224
+ const readResolved = async (input, resolved, message) => {
220
225
  const { entryPath, slug, branchName } = resolveTarget(input);
221
- const result = await readDocument(input);
226
+ const result = await readDocument(input, resolved);
222
227
  if (!result || typeof result.doc !== 'object' || !('data' in result.doc)) {
223
228
  const defaultMessage = `Content not found for ${entryPath}${slug ? `/${slug}` : ''} on branch ${branchName}`;
224
229
  throw new ContentStoreError(message ?? defaultMessage, 'NOT_FOUND');
@@ -242,5 +247,37 @@ export const createContentReader = (options) => {
242
247
  });
243
248
  return { data, path, meta: { physicalPath, entryType, entryId, slug: entrySlug, urlPath } };
244
249
  };
245
- return { read };
250
+ const read = async (input, message) => {
251
+ const { branchName } = resolveTarget(input);
252
+ return readResolved(input, await resolveStore(branchName), message);
253
+ };
254
+ const readFirst = async (inputs, isMiss) => {
255
+ const [first] = inputs;
256
+ if (!first)
257
+ return null;
258
+ if (inputs.some((input) => input.branch !== first.branch || input.user !== first.user)) {
259
+ throw new Error('readFirst: every input must name the same branch and user');
260
+ }
261
+ let resolved;
262
+ try {
263
+ resolved = await resolveStore(resolveTarget(first).branchName);
264
+ }
265
+ catch (err) {
266
+ if (isMiss(err, first))
267
+ return null;
268
+ throw err;
269
+ }
270
+ for (const input of inputs) {
271
+ try {
272
+ return await readResolved(input, resolved);
273
+ }
274
+ catch (err) {
275
+ if (isMiss(err, input))
276
+ continue;
277
+ throw err;
278
+ }
279
+ }
280
+ return null;
281
+ };
282
+ return { read, readFirst };
246
283
  };
package/dist/context.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import { isDeployedStatic, isBuildMode, readsFromCheckout, STATIC_DEPLOY_USER } from './build-mode.js';
2
- import { createContentReader } from './content-reader.js';
2
+ import { createContentReaderInternal } from './content-reader.js';
3
3
  import { ContentStoreError } from './content-store.js';
4
4
  import { createLogicalPath, namesNoWorkspace, parseSlug, resolveBranchPaths, } from './paths/index.js';
5
5
  import { resolveUrlPathCandidates } from './url-path-resolver.js';
@@ -129,7 +129,7 @@ export function createCanopyContext(options) {
129
129
  };
130
130
  // The reader resolves every branch through resolveBranch; a null reads as
131
131
  // NOT_FOUND. Reads from the checkout bypass the resolver inside the reader.
132
- const baseReader = createContentReader({
132
+ const baseReader = createContentReaderInternal({
133
133
  services,
134
134
  defaultBranch: activeBranch,
135
135
  getBranchContext: (branchName) => resolveBranch(otherBranch(branchName)),
@@ -140,7 +140,7 @@ export function createCanopyContext(options) {
140
140
  // function rather than an optional second parameter on the
141
141
  // `CanopyContext['read']`-typed closure, so the two call sites stay visible
142
142
  // and nobody widens the public API by accident.
143
- const readWithOptions = async (input, extra) => {
143
+ const toReadInput = (input, extra) => {
144
144
  const entryPath = createLogicalPath(input.entryPath);
145
145
  let slug;
146
146
  if (input.slug) {
@@ -161,53 +161,55 @@ export function createCanopyContext(options) {
161
161
  resolveReferences: input.resolveReferences ?? true,
162
162
  ...extra,
163
163
  };
164
- return baseReader.read(readInput);
164
+ return readInput;
165
165
  };
166
- const read = (input) => readWithOptions(input);
166
+ const read = async (input) => baseReader.read(toReadInput(input));
167
167
  const readByUrlPath = async (urlPath, options) => {
168
168
  const contentRoot = services.config.contentRoot || 'content';
169
169
  const candidates = resolveUrlPathCandidates(urlPath, contentRoot);
170
170
  if (candidates.length === 0)
171
171
  return null;
172
172
  const { branch, resolveReferences } = options ?? {};
173
- for (const candidate of candidates) {
174
- // Skip a candidate whose slug isn't valid (/favicon.ico, Next internals
175
- // the [...slug] route catches). None can match an entry, so treat it as
176
- // a miss rather than let read() throw "Invalid slug".
177
- if (!parseSlug(candidate.slug).ok)
178
- continue;
179
- try {
180
- return await readWithOptions({
181
- entryPath: candidate.entryPath,
182
- slug: candidate.slug,
183
- branch,
184
- resolveReferences,
185
- },
186
- // A read BY PUBLISHED URL accepts only what listEntries publishes.
187
- // See ReadContentInput.urlAddressableOnly for the two rules, and
188
- // why they live in the reader (which holds the branch-correct
189
- // schema) rather than the candidate builder (pure and schema-free).
190
- { urlAddressableOnly: true });
191
- }
192
- catch (err) {
193
- // Swallow a candidate path's "not found", and FORBIDDEN so a denied
194
- // or anonymous read renders as the adopter's 404 rather than an
195
- // unhandled 500. Real errors (validation, corruption, anything not a
196
- // ContentStoreError) rethrow.
197
- if (err instanceof ContentStoreError && isPageSwallowable(err)) {
198
- if (err.code === 'FORBIDDEN') {
199
- log.debug('readByUrlPath', 'Read denied, treating as not-found: ' + err.message, {
200
- urlPath,
201
- entryPath: candidate.entryPath,
202
- slug: candidate.slug,
203
- });
204
- }
205
- continue;
206
- }
207
- throw err;
173
+ // Swallow a candidate path's "not found", and FORBIDDEN so a denied or
174
+ // anonymous read renders as the adopter's 404 rather than an unhandled
175
+ // 500. Real errors (validation, corruption, anything not a
176
+ // ContentStoreError) rethrow.
177
+ const isMiss = (err, input) => {
178
+ if (!(err instanceof ContentStoreError && isPageSwallowable(err)))
179
+ return false;
180
+ if (err.code === 'FORBIDDEN') {
181
+ log.debug('readByUrlPath', 'Read denied, treating as not-found: ' + err.message, {
182
+ urlPath,
183
+ entryPath: input?.entryPath,
184
+ slug: input?.slug,
185
+ });
208
186
  }
187
+ return true;
188
+ };
189
+ // Converting every candidate up front throws nothing a candidate-by-candidate
190
+ // loop would not: a valid slug holds no `..`, so the index candidate's path
191
+ // fails createLogicalPath only when the entry candidate's does.
192
+ let inputs;
193
+ try {
194
+ inputs = candidates
195
+ // Skip a candidate whose slug isn't valid (/favicon.ico, Next internals
196
+ // the [...slug] route catches). None can match an entry, so treat it as
197
+ // a miss rather than let read() throw "Invalid slug".
198
+ .filter((candidate) => parseSlug(candidate.slug).ok)
199
+ .map((candidate) => toReadInput({ entryPath: candidate.entryPath, slug: candidate.slug, branch, resolveReferences },
200
+ // A read BY PUBLISHED URL accepts only what listEntries publishes.
201
+ // See ReadContentInput.urlAddressableOnly for the two rules, and
202
+ // why they live in the reader (which holds the branch-correct
203
+ // schema) rather than the candidate builder (pure and schema-free).
204
+ { urlAddressableOnly: true }));
209
205
  }
210
- return null;
206
+ catch (err) {
207
+ if (isMiss(err))
208
+ return null;
209
+ throw err;
210
+ }
211
+ // One branch and schema resolve for every candidate.
212
+ return baseReader.readFirst(inputs, isMiss);
211
213
  };
212
214
  /**
213
215
  * What a batch read (listEntries / buildContentTree) lists from: the branch's
package/dist/server.d.ts CHANGED
@@ -1,4 +1,9 @@
1
- export * from './content-reader.js';
1
+ /**
2
+ * The lower-level reader under `CanopyContext.read`: reads one entry from a branch as a user
3
+ * the caller passes explicitly, checking that user's read access first except in a static
4
+ * deployment or a build. See README.md, "Advanced: Using createContentReader Directly".
5
+ */
6
+ export { createContentReader, type ContentReader, type ContentReaderOptions, type ContentReadMeta, type ContentReadResult, type ReadContentInput, } from './content-reader.js';
2
7
  export * from './services.js';
3
8
  export * from './build-mode.js';
4
9
  export * from './context.js';
package/dist/server.js CHANGED
@@ -2,7 +2,12 @@
2
2
  // TypeScript's propagation through `export { X } from './module.js'` is inconsistent across LSP
3
3
  // versions and module-resolution modes and adopters would otherwise get no hover text. Follow the
4
4
  // pattern for new top-level public re-exports (see DEVELOPING.md).
5
- export * from './content-reader.js';
5
+ /**
6
+ * The lower-level reader under `CanopyContext.read`: reads one entry from a branch as a user
7
+ * the caller passes explicitly, checking that user's read access first except in a static
8
+ * deployment or a build. See README.md, "Advanced: Using createContentReader Directly".
9
+ */
10
+ export { createContentReader, } from './content-reader.js';
6
11
  export * from './services.js';
7
12
  export * from './build-mode.js';
8
13
  export * from './context.js';
package/dist/version.d.ts CHANGED
@@ -1 +1 @@
1
- export declare const CANOPYCMS_VERSION = "0.8.0";
1
+ export declare const CANOPYCMS_VERSION = "0.8.1";
package/dist/version.js CHANGED
@@ -1,3 +1,3 @@
1
1
  // Generated by scripts/bump-version.mjs, its only writer. The package builds with plain
2
2
  // tsc (rootDir: src), so src/ cannot import ../package.json; version.test.ts keeps the two equal.
3
- export const CANOPYCMS_VERSION = '0.8.0';
3
+ export const CANOPYCMS_VERSION = '0.8.1';
@@ -424,14 +424,14 @@ declare const errorEnvelope: z.ZodDiscriminatedUnion<"kind", [z.ZodObject<{
424
424
  message: string;
425
425
  reason: "settings" | "protected" | "invalid" | "other-settings" | "outside-namespace" | "not-a-commit" | "too-long";
426
426
  kind: "refusal";
427
- operation: "push" | "pull-request" | "delete";
427
+ operation: "push" | "delete" | "pull-request";
428
428
  }, {
429
429
  branch: string;
430
430
  push: boolean;
431
431
  message: string;
432
432
  reason: "settings" | "protected" | "invalid" | "other-settings" | "outside-namespace" | "not-a-commit" | "too-long";
433
433
  kind: "refusal";
434
- operation: "push" | "pull-request" | "delete";
434
+ operation: "push" | "delete" | "pull-request";
435
435
  }>, z.ZodObject<{
436
436
  kind: z.ZodLiteral<"push">;
437
437
  pushKind: z.ZodEnum<["rejected", "rejected-after-stale-lease"]>;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "//": "@codemirror/language, @lezer/highlight: workaround — @mdxeditor/editor uses cm6-theme-basic-light which peer-requires these but mdxeditor doesn't declare them as dependencies",
3
3
  "name": "canopycms",
4
- "version": "0.8.0",
4
+ "version": "0.8.1",
5
5
  "description": "CanopyCMS core package: schema-driven content, branch-aware editing, and editor UI for Next.js.",
6
6
  "license": "MIT",
7
7
  "repository": {