@conloca/content-api 0.1.14 → 0.1.16

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (183) hide show
  1. package/dist/asset-manifest.d.ts +23 -0
  2. package/dist/asset-manifest.d.ts.map +1 -0
  3. package/dist/asset-manifest.js +73 -0
  4. package/dist/asset-operations.d.ts +159 -0
  5. package/dist/asset-operations.d.ts.map +1 -0
  6. package/dist/asset-operations.js +736 -0
  7. package/dist/asset-types.d.ts +56 -0
  8. package/dist/asset-types.d.ts.map +1 -0
  9. package/dist/asset-types.js +7 -0
  10. package/dist/base-content-index.d.ts +57 -0
  11. package/dist/base-content-index.d.ts.map +1 -0
  12. package/dist/base-content-index.js +179 -0
  13. package/dist/block-index.d.ts +9 -0
  14. package/dist/block-index.d.ts.map +1 -0
  15. package/dist/block-index.js +11 -0
  16. package/dist/blocks.d.ts +16 -0
  17. package/dist/blocks.d.ts.map +1 -0
  18. package/dist/blocks.js +103 -0
  19. package/dist/cf-access.d.ts +31 -0
  20. package/dist/cf-access.d.ts.map +1 -0
  21. package/dist/cf-access.js +66 -0
  22. package/dist/component-registry.d.ts +50 -0
  23. package/dist/component-registry.d.ts.map +1 -0
  24. package/dist/component-registry.js +120 -0
  25. package/dist/component-registry.types-C0ctF9nh.d.mts +71 -0
  26. package/dist/component-registry.types-C0ctF9nh.d.mts.map +1 -0
  27. package/dist/component-registry.types.d.ts +11 -0
  28. package/dist/component-registry.types.d.ts.map +1 -0
  29. package/dist/component-registry.types.js +1 -0
  30. package/dist/content-api.interface.d.ts +64 -0
  31. package/dist/content-api.interface.d.ts.map +1 -0
  32. package/dist/content-api.interface.js +1 -0
  33. package/dist/content-filters.d.ts +31 -0
  34. package/dist/content-filters.d.ts.map +1 -0
  35. package/dist/content-filters.js +246 -0
  36. package/dist/content-index-D092_vk1.mjs +629 -0
  37. package/dist/content-index-D092_vk1.mjs.map +1 -0
  38. package/dist/content-index-D6IVMmAB.d.mts +127 -0
  39. package/dist/content-index-D6IVMmAB.d.mts.map +1 -0
  40. package/dist/content-index.d.ts +126 -0
  41. package/dist/content-index.d.ts.map +1 -0
  42. package/dist/content-index.js +418 -0
  43. package/dist/content-operations-DIbsxG5A.d.mts +354 -0
  44. package/dist/content-operations-DIbsxG5A.d.mts.map +1 -0
  45. package/dist/content-operations.d.ts +93 -0
  46. package/dist/content-operations.d.ts.map +1 -0
  47. package/dist/content-operations.js +275 -0
  48. package/dist/content-reader.d.ts +10 -0
  49. package/dist/content-reader.d.ts.map +1 -0
  50. package/dist/content-reader.js +13 -0
  51. package/dist/content-utils-fWNHTrPy.mjs +280 -0
  52. package/dist/content-utils-fWNHTrPy.mjs.map +1 -0
  53. package/dist/content-utils.d.ts +132 -0
  54. package/dist/content-utils.d.ts.map +1 -0
  55. package/dist/content-utils.js +352 -0
  56. package/dist/content-watcher.d.ts +43 -0
  57. package/dist/content-watcher.d.ts.map +1 -0
  58. package/dist/content-watcher.js +83 -0
  59. package/dist/data-DquNIEnQ.mjs +62 -0
  60. package/dist/data-DquNIEnQ.mjs.map +1 -0
  61. package/dist/data-index.d.ts +8 -0
  62. package/dist/data-index.d.ts.map +1 -0
  63. package/dist/data-index.js +7 -0
  64. package/dist/data.d.ts +43 -0
  65. package/dist/data.d.ts.map +1 -0
  66. package/dist/data.js +103 -0
  67. package/dist/etag-utils.d.ts +77 -0
  68. package/dist/etag-utils.d.ts.map +1 -0
  69. package/dist/etag-utils.js +160 -0
  70. package/dist/filesystem-content-api-B1KIQJfk.mjs +2 -0
  71. package/dist/filesystem-content-api-C0HIhqZi.mjs +1620 -0
  72. package/dist/filesystem-content-api-C0HIhqZi.mjs.map +1 -0
  73. package/dist/filesystem-content-api-DCdNi-co.d.mts +134 -0
  74. package/dist/filesystem-content-api-DCdNi-co.d.mts.map +1 -0
  75. package/dist/filesystem-content-api.d.ts +135 -0
  76. package/dist/filesystem-content-api.d.ts.map +1 -0
  77. package/dist/filesystem-content-api.js +2181 -0
  78. package/dist/git-operations.d.ts +49 -0
  79. package/dist/git-operations.d.ts.map +1 -0
  80. package/dist/git-operations.js +252 -0
  81. package/dist/header-parser.d.ts +37 -0
  82. package/dist/header-parser.d.ts.map +1 -0
  83. package/dist/header-parser.js +286 -0
  84. package/dist/in-memory-content-api.d.ts +35 -0
  85. package/dist/in-memory-content-api.d.ts.map +1 -0
  86. package/dist/in-memory-content-api.js +591 -0
  87. package/dist/index-DxVTFK66.d.mts +105 -0
  88. package/dist/index-DxVTFK66.d.mts.map +1 -0
  89. package/dist/index.d.mts +6 -4
  90. package/dist/index.d.mts.map +1 -1
  91. package/dist/index.d.ts +19 -0
  92. package/dist/index.d.ts.map +1 -0
  93. package/dist/index.js +16 -0
  94. package/dist/index.mjs +37 -5
  95. package/dist/index.mjs.map +1 -1
  96. package/dist/indexing.d.mts +152 -0
  97. package/dist/indexing.d.mts.map +1 -0
  98. package/dist/indexing.d.ts +5 -0
  99. package/dist/indexing.d.ts.map +1 -0
  100. package/dist/indexing.js +7 -0
  101. package/dist/indexing.mjs +255 -0
  102. package/dist/indexing.mjs.map +1 -0
  103. package/dist/json-whitespace-view.d.ts +32 -0
  104. package/dist/json-whitespace-view.d.ts.map +1 -0
  105. package/dist/json-whitespace-view.js +152 -0
  106. package/dist/middleware.d.ts +20 -0
  107. package/dist/middleware.d.ts.map +1 -0
  108. package/dist/middleware.js +1031 -0
  109. package/dist/node.d.mts +28 -126
  110. package/dist/node.d.mts.map +1 -1
  111. package/dist/node.d.ts +25 -0
  112. package/dist/node.d.ts.map +1 -0
  113. package/dist/node.js +24 -0
  114. package/dist/node.mjs +199 -2890
  115. package/dist/node.mjs.map +1 -1
  116. package/dist/reader.d.mts +15 -0
  117. package/dist/reader.d.mts.map +1 -0
  118. package/dist/reader.d.ts +15 -0
  119. package/dist/reader.d.ts.map +1 -0
  120. package/dist/reader.js +13 -0
  121. package/dist/reader.mjs +22 -0
  122. package/dist/reader.mjs.map +1 -0
  123. package/dist/schemas/index.d.mts +2 -90
  124. package/dist/schemas/index.d.ts +102 -0
  125. package/dist/schemas/index.d.ts.map +1 -0
  126. package/dist/schemas/index.js +87 -0
  127. package/dist/schemas/index.mjs +2 -70
  128. package/dist/schemas-CFRD0FIQ.mjs +84 -0
  129. package/dist/schemas-CFRD0FIQ.mjs.map +1 -0
  130. package/dist/{types-BUG0Cfkg.mjs → site-8oaj1Q60.mjs} +20 -222
  131. package/dist/site-8oaj1Q60.mjs.map +1 -0
  132. package/dist/site-index-B_254bCc.d.mts +136 -0
  133. package/dist/site-index-B_254bCc.d.mts.map +1 -0
  134. package/dist/site-index.d.ts +60 -0
  135. package/dist/site-index.d.ts.map +1 -0
  136. package/dist/site-index.js +287 -0
  137. package/dist/site.d.ts +21 -0
  138. package/dist/site.d.ts.map +1 -0
  139. package/dist/site.js +168 -0
  140. package/dist/types-DOdldbfD.mjs +34 -0
  141. package/dist/types-DOdldbfD.mjs.map +1 -0
  142. package/dist/types-DjfhS272.d.mts +456 -0
  143. package/dist/types-DjfhS272.d.mts.map +1 -0
  144. package/dist/types.d.ts +453 -0
  145. package/dist/types.d.ts.map +1 -0
  146. package/dist/types.js +36 -0
  147. package/dist/url-safe-base64.d.ts +12 -0
  148. package/dist/url-safe-base64.d.ts.map +1 -0
  149. package/dist/url-safe-base64.js +40 -0
  150. package/dist/url-validation.d.ts +14 -0
  151. package/dist/url-validation.d.ts.map +1 -0
  152. package/dist/url-validation.js +81 -0
  153. package/dist/utils/atomic-write.d.ts +6 -0
  154. package/dist/utils/atomic-write.d.ts.map +1 -0
  155. package/dist/utils/atomic-write.js +20 -0
  156. package/dist/utils.d.ts +46 -0
  157. package/dist/utils.d.ts.map +1 -0
  158. package/dist/utils.js +70 -0
  159. package/dist/vite-plugin.d.ts +12 -0
  160. package/dist/vite-plugin.d.ts.map +1 -0
  161. package/dist/vite-plugin.js +29 -0
  162. package/dist/vxjson-qHrgLGip.mjs +555 -0
  163. package/dist/vxjson-qHrgLGip.mjs.map +1 -0
  164. package/dist/vxjson-serialize-geF6qvpn.mjs +34 -0
  165. package/dist/vxjson-serialize-geF6qvpn.mjs.map +1 -0
  166. package/dist/vxjson-serialize.d.mts +17 -0
  167. package/dist/vxjson-serialize.d.mts.map +1 -0
  168. package/dist/vxjson-serialize.d.ts +14 -0
  169. package/dist/vxjson-serialize.d.ts.map +1 -0
  170. package/dist/vxjson-serialize.js +50 -0
  171. package/dist/vxjson-serialize.mjs +2 -0
  172. package/dist/vxjson.d.ts +112 -0
  173. package/dist/vxjson.d.ts.map +1 -0
  174. package/dist/vxjson.js +391 -0
  175. package/dist/xxhash.d.ts +10 -0
  176. package/dist/xxhash.d.ts.map +1 -0
  177. package/dist/xxhash.js +31 -0
  178. package/package.json +88 -17
  179. package/dist/content-operations-BZLfJWqT.d.mts +0 -916
  180. package/dist/content-operations-BZLfJWqT.d.mts.map +0 -1
  181. package/dist/schemas/index.d.mts.map +0 -1
  182. package/dist/schemas/index.mjs.map +0 -1
  183. package/dist/types-BUG0Cfkg.mjs.map +0 -1
@@ -0,0 +1,591 @@
1
+ import { Blocks } from './blocks';
2
+ import { filterContentWithIndexes } from './content-filters';
3
+ import { ContentIndex } from './content-index';
4
+ import { buildLocaleVersion, buildPathnameHistory, generateContentId, isContentPublished, shouldUpdateModifiedTimestamp, updatePublishDates, validateAndPrepareMetadata, validateCreateContent, } from './content-operations';
5
+ import { getCurrentISODate, localesOf, mapLocales, mapSiteNames, serializeMdxWithFrontmatter } from './content-utils';
6
+ import { Data } from './data';
7
+ import { calculateEtagsFromMdxBuffer, findMdxContentStartPosition } from './etag-utils';
8
+ import { Site } from './site';
9
+ import { VXJSON } from './vxjson';
10
+ /**
11
+ * In-memory implementation of ContentAPI for testing
12
+ * Provides a clean, mock-free way to test the API without filesystem dependencies
13
+ */
14
+ export class InMemoryContentAPI {
15
+ contentIndex;
16
+ sitesConfig;
17
+ blocks;
18
+ data;
19
+ sites;
20
+ constructor(sitesConfig) {
21
+ this.sitesConfig = sitesConfig || {
22
+ sites: {},
23
+ globalLocales: ['en'],
24
+ };
25
+ // Initialize content index (not cached for in-memory)
26
+ this.contentIndex = ContentIndex.createUncached(this.sitesConfig);
27
+ // Initialize blocks
28
+ this.blocks = new Blocks(this, this.contentIndex.getBlockIndex());
29
+ // Initialize data
30
+ this.data = new Data(this, this.contentIndex.getDataIndex());
31
+ // Initialize all sites
32
+ this.sites = mapSiteNames(this.sitesConfig, (siteName) => {
33
+ const siteIndex = this.contentIndex.getSiteIndex(siteName);
34
+ if (!siteIndex) {
35
+ throw new Error(`Site index not found for ${siteName}`);
36
+ }
37
+ return new Site(siteName, this, siteIndex);
38
+ });
39
+ }
40
+ // Core content operations
41
+ async getContent(id) {
42
+ const manifest = this.contentIndex.getManifest(id);
43
+ if (!manifest) {
44
+ return null;
45
+ }
46
+ // Build ContentEntry from manifest and cached content
47
+ const contentEntry = {
48
+ id: manifest.id,
49
+ kind: manifest.kind,
50
+ site: manifest.site,
51
+ collection: manifest.collection,
52
+ type: manifest.type,
53
+ locales: {},
54
+ };
55
+ // Add locale data with content from cache
56
+ for (const localeVersion of localesOf(manifest)) {
57
+ const { locale } = localeVersion;
58
+ const cachedContent = this.contentIndex.getCachedContent(id, locale);
59
+ if (cachedContent) {
60
+ // `content.mdx` is body-only on read — frontmatter is server-
61
+ // owned and exposed via `meta` / `created` / `modified`. Mirrors
62
+ // FileSystemContentAPI.readLocaleFile (see commit a631a43 — the
63
+ // editor cannot round-trip frontmatter as body text without
64
+ // duplicating it on disk).
65
+ contentEntry.locales[locale] = {
66
+ ...localeVersion,
67
+ content: cachedContent,
68
+ };
69
+ }
70
+ }
71
+ return contentEntry;
72
+ }
73
+ async getLocalized(id, locale) {
74
+ const manifest = this.contentIndex.getManifest(id);
75
+ if (!manifest || !manifest.locales[locale]) {
76
+ return null;
77
+ }
78
+ const localeVersion = manifest.locales[locale];
79
+ const cachedContent = this.contentIndex.getCachedContent(id, locale);
80
+ if (!cachedContent) {
81
+ return null;
82
+ }
83
+ // `content.mdx` is body-only on read (see `getContent` above).
84
+ const contentToReturn = { ...cachedContent };
85
+ // Return a deep copy to prevent modifications to the original data
86
+ return {
87
+ id,
88
+ site: manifest.site,
89
+ collection: manifest.collection,
90
+ type: manifest.type,
91
+ kind: manifest.kind,
92
+ localized: {
93
+ ...localeVersion,
94
+ meta: { ...localeVersion.meta },
95
+ content: contentToReturn,
96
+ previousPathnames: localeVersion.previousPathnames ? { ...localeVersion.previousPathnames } : undefined,
97
+ },
98
+ };
99
+ }
100
+ async createContent(data) {
101
+ // Use shared validation
102
+ const validation = validateCreateContent(data, this.sites, this.blocks);
103
+ if (!validation.valid) {
104
+ return {
105
+ success: false,
106
+ reason: validation.reason,
107
+ error: validation.error ? new Error(validation.error) : undefined,
108
+ existingId: validation.existingId,
109
+ };
110
+ }
111
+ // Generate ID
112
+ const id = generateContentId();
113
+ const now = getCurrentISODate();
114
+ const contentCache = {};
115
+ const locales = mapLocales(data.site ? this.sitesConfig.sites[data.site].locales : this.sitesConfig.globalLocales, (locale) => {
116
+ const localeData = data.locales[locale];
117
+ if (!localeData)
118
+ return undefined;
119
+ const meta = { ...data.meta, ...localeData.meta };
120
+ // Calculate dual ETag for this locale
121
+ const fileData = {
122
+ id,
123
+ type: data.type,
124
+ created: now,
125
+ modified: now,
126
+ publishAt: localeData.publishAt && typeof localeData.publishAt === 'string' ? localeData.publishAt : undefined,
127
+ unpublishAt: localeData.unpublishAt && typeof localeData.unpublishAt === 'string' ? localeData.unpublishAt : undefined,
128
+ meta,
129
+ content: localeData.content,
130
+ };
131
+ // Serialize to buffer and calculate ETags based on content type
132
+ let buffer;
133
+ let etag;
134
+ if (data.type === 'mdx') {
135
+ // For MDX content, serialize as frontmatter + content
136
+ const frontmatterData = {
137
+ id,
138
+ created: now,
139
+ modified: now,
140
+ ...(localeData.publishAt && { publishAt: localeData.publishAt }),
141
+ ...(localeData.unpublishAt && { unpublishAt: localeData.unpublishAt }),
142
+ ...meta, // Spread metadata fields directly, not nested
143
+ };
144
+ const mdxContent = serializeMdxWithFrontmatter(frontmatterData, localeData.content.mdx || '');
145
+ buffer = new TextEncoder().encode(mdxContent);
146
+ // Find content start position using shared utility
147
+ const contentPos = findMdxContentStartPosition(buffer);
148
+ // Calculate ETags using MDX-specific logic
149
+ const etagResult = calculateEtagsFromMdxBuffer(buffer, contentPos);
150
+ etag = `${etagResult.metaEtag}.${etagResult.contentEtag}`;
151
+ }
152
+ else {
153
+ // For Puck content, serialize as VXJSON
154
+ const jsonStr = VXJSON.serialize(fileData);
155
+ buffer = Buffer.from(jsonStr, 'utf-8');
156
+ const etagResult = VXJSON.calculateETags(buffer);
157
+ if (!etagResult.success) {
158
+ throw new Error(`Invalid VXJSON format: ${etagResult.error}`);
159
+ }
160
+ etag = etagResult.contentEtag ? `${etagResult.metaEtag}.${etagResult.contentEtag}` : etagResult.metaEtag;
161
+ }
162
+ // Build locale manifest using shared function
163
+ const localeVersion = buildLocaleVersion({
164
+ locale,
165
+ etag,
166
+ created: now,
167
+ modified: now,
168
+ meta,
169
+ kind: data.kind,
170
+ pathname: data.kind === 'page' ? localeData.pathname : undefined,
171
+ name: data.kind === 'block' || data.kind === 'data' ? data.name : undefined,
172
+ publishAt: localeData.publishAt && typeof localeData.publishAt === 'string' ? localeData.publishAt : undefined,
173
+ unpublishAt: localeData.unpublishAt && typeof localeData.unpublishAt === 'string' ? localeData.unpublishAt : undefined,
174
+ });
175
+ contentCache[locale] = localeData.content;
176
+ return localeVersion;
177
+ });
178
+ // Build manifest and content cache
179
+ const manifest = {
180
+ id,
181
+ type: data.type,
182
+ kind: data.kind,
183
+ site: data.site,
184
+ collection: data.collection,
185
+ locales,
186
+ };
187
+ // Update index with each locale
188
+ for (const localeVersion of localesOf(manifest)) {
189
+ this.contentIndex.addContent(manifest, localeVersion, contentCache[localeVersion.locale]);
190
+ }
191
+ // Return the first locale's etag (typically there's only one during creation)
192
+ const firstLocaleEtag = Object.values(manifest.locales)[0]?.etag || '';
193
+ return {
194
+ success: true,
195
+ id,
196
+ etag: firstLocaleEtag,
197
+ created: new Date(now),
198
+ };
199
+ }
200
+ async updateLocalized(input) {
201
+ const { id, locale, data, etag } = input;
202
+ const manifest = this.contentIndex.getManifest(id);
203
+ if (!manifest) {
204
+ return {
205
+ success: false,
206
+ reason: 'not_found',
207
+ };
208
+ }
209
+ // Get the specific locale manifest
210
+ const localeVersion = manifest.locales[locale];
211
+ if (!localeVersion) {
212
+ return {
213
+ success: false,
214
+ reason: 'not_found',
215
+ };
216
+ }
217
+ // Check etag matches
218
+ if (localeVersion.etag !== etag) {
219
+ return {
220
+ success: false,
221
+ reason: 'stale_write',
222
+ currentEtag: localeVersion.etag,
223
+ };
224
+ }
225
+ // Get current content from cache
226
+ const currentContent = this.contentIndex.getCachedContent(id, locale);
227
+ if (!currentContent) {
228
+ return {
229
+ success: false,
230
+ reason: 'not_found',
231
+ };
232
+ }
233
+ // Validate metadata if updating
234
+ if (data.meta) {
235
+ const newMeta = { ...localeVersion.meta, ...data.meta };
236
+ const validation = validateAndPrepareMetadata(newMeta);
237
+ if (!validation.valid) {
238
+ return {
239
+ success: false,
240
+ reason: 'write_error',
241
+ error: new Error(validation.error),
242
+ };
243
+ }
244
+ }
245
+ // Validate pathname change if updating pathname for pages
246
+ if (data.pathname && manifest.kind === 'page' && manifest.site) {
247
+ const site = this.sites[manifest.site];
248
+ if (site) {
249
+ // Check if new pathname is already taken by another content
250
+ const existingId = site.getPathnameConflict(data.pathname, locale, id);
251
+ if (existingId) {
252
+ return {
253
+ success: false,
254
+ reason: 'write_error',
255
+ error: new Error(`Pathname ${data.pathname} is already taken by content ${existingId}`),
256
+ };
257
+ }
258
+ }
259
+ }
260
+ // Update content
261
+ const now = new Date();
262
+ const nowStr = now.toISOString();
263
+ // Build updated locale manifest
264
+ const oldPathname = localeVersion.pathname;
265
+ const updatedLocaleVersion = { ...localeVersion };
266
+ // Update modified timestamp for any changes (content or metadata)
267
+ if (shouldUpdateModifiedTimestamp(data)) {
268
+ // Use provided modified timestamp or current time
269
+ const newModified = data.modified || nowStr;
270
+ updatedLocaleVersion.modified = newModified;
271
+ }
272
+ else if (data.modified) {
273
+ // If modified timestamp is explicitly provided, always use it
274
+ updatedLocaleVersion.modified = data.modified;
275
+ }
276
+ if (data.meta) {
277
+ updatedLocaleVersion.meta = { ...localeVersion.meta, ...data.meta };
278
+ }
279
+ if (data.pathname !== undefined && manifest.kind === 'page') {
280
+ // Build pathname history for published content
281
+ const pathnameHistory = buildPathnameHistory(oldPathname, data.pathname, isContentPublished(localeVersion), nowStr);
282
+ // Merge with existing pathname history
283
+ if (Object.keys(pathnameHistory).length > 0) {
284
+ updatedLocaleVersion.previousPathnames = {
285
+ ...localeVersion.previousPathnames,
286
+ ...pathnameHistory,
287
+ };
288
+ }
289
+ updatedLocaleVersion.pathname = data.pathname;
290
+ }
291
+ // Handle publish date updates using shared function
292
+ updatePublishDates(updatedLocaleVersion, data);
293
+ // Prepare updated content
294
+ const updatedContent = data.content ? { ...currentContent, ...data.content } : currentContent;
295
+ // Calculate new dual ETag by creating a buffer from the in-memory data
296
+ // Structure it like the filesystem JSON files
297
+ const fileData = {
298
+ id: manifest.id,
299
+ type: manifest.type,
300
+ created: updatedLocaleVersion.created,
301
+ modified: updatedLocaleVersion.modified,
302
+ publishAt: updatedLocaleVersion.publishAt,
303
+ unpublishAt: updatedLocaleVersion.unpublishAt,
304
+ meta: updatedLocaleVersion.meta,
305
+ previousPathnames: updatedLocaleVersion.previousPathnames,
306
+ content: updatedContent,
307
+ };
308
+ // Serialize to buffer and calculate ETags based on content type
309
+ let buffer;
310
+ let newEtag;
311
+ if (manifest.type === 'mdx') {
312
+ // For MDX content, serialize as frontmatter + content
313
+ const frontmatterData = {
314
+ id: manifest.id,
315
+ created: updatedLocaleVersion.created,
316
+ modified: updatedLocaleVersion.modified,
317
+ ...(updatedLocaleVersion.publishAt && { publishAt: updatedLocaleVersion.publishAt }),
318
+ ...(updatedLocaleVersion.unpublishAt && { unpublishAt: updatedLocaleVersion.unpublishAt }),
319
+ ...updatedLocaleVersion.meta, // Spread metadata fields directly, not nested
320
+ };
321
+ const mdxContent = serializeMdxWithFrontmatter(frontmatterData, updatedContent.mdx || '');
322
+ buffer = new TextEncoder().encode(mdxContent);
323
+ // Find content start position using shared utility
324
+ const contentPos = findMdxContentStartPosition(buffer);
325
+ // Calculate ETags using MDX-specific logic
326
+ const etagResult = calculateEtagsFromMdxBuffer(buffer, contentPos);
327
+ newEtag = `${etagResult.metaEtag}.${etagResult.contentEtag}`;
328
+ }
329
+ else {
330
+ // For Puck content, serialize as VXJSON
331
+ const jsonStr = VXJSON.serialize(fileData);
332
+ buffer = Buffer.from(jsonStr, 'utf-8');
333
+ const etagResult = VXJSON.calculateETags(buffer);
334
+ if (!etagResult.success) {
335
+ throw new Error(`Invalid VXJSON format: ${etagResult.error}`);
336
+ }
337
+ newEtag = etagResult.contentEtag ? `${etagResult.metaEtag}.${etagResult.contentEtag}` : etagResult.metaEtag;
338
+ }
339
+ updatedLocaleVersion.etag = newEtag;
340
+ // Build updated manifest with only the changed locale
341
+ const updatedManifest = {
342
+ ...manifest,
343
+ locales: {
344
+ ...manifest.locales,
345
+ [locale]: updatedLocaleVersion,
346
+ },
347
+ };
348
+ // Update content in the index (this will handle pathname index updates)
349
+ this.contentIndex.addContent(updatedManifest, updatedLocaleVersion, updatedContent);
350
+ return {
351
+ success: true,
352
+ etag: updatedLocaleVersion.etag,
353
+ modified: now,
354
+ };
355
+ }
356
+ async deleteContent(id, etag) {
357
+ const manifest = this.contentIndex.getManifest(id);
358
+ if (!manifest) {
359
+ return {
360
+ success: false,
361
+ reason: 'not_found',
362
+ error: new Error('Content not found'),
363
+ };
364
+ }
365
+ // Verify etag
366
+ let hasMatchingEtag = false;
367
+ for (const localeVersion of localesOf(manifest)) {
368
+ if (localeVersion.etag === etag) {
369
+ hasMatchingEtag = true;
370
+ break;
371
+ }
372
+ }
373
+ if (!hasMatchingEtag && etag) {
374
+ return {
375
+ success: false,
376
+ reason: 'stale_write',
377
+ currentEtag: Array.from(localesOf(manifest))[0]?.etag || '',
378
+ error: new Error('ETag mismatch'),
379
+ };
380
+ }
381
+ // Remove from index (this also removes from content cache)
382
+ this.contentIndex.removeEntry(id);
383
+ return {
384
+ success: true,
385
+ };
386
+ }
387
+ // Site and blocks access
388
+ getSite(siteName) {
389
+ if (siteName === 'blocks') {
390
+ throw new Error('Use `blocks` property instead of getSite("blocks")');
391
+ }
392
+ const site = this.sites[siteName];
393
+ return site || null;
394
+ }
395
+ // Global operations
396
+ *listAllContent(filters) {
397
+ yield* filterContentWithIndexes(this.contentIndex, filters, this.sitesConfig);
398
+ }
399
+ *findUntranslatedContent(targetLocale, options) {
400
+ // Use the index method which already handles all the filtering efficiently
401
+ yield* this.contentIndex.findUntranslatedContent(targetLocale, options);
402
+ }
403
+ async deleteLocalized(input) {
404
+ const { id, locale, etag } = input;
405
+ // Get existing manifest
406
+ const manifest = this.contentIndex.getManifest(id);
407
+ if (!manifest) {
408
+ return {
409
+ success: false,
410
+ reason: 'not_found',
411
+ error: new Error('Content not found'),
412
+ };
413
+ }
414
+ const localeVersion = manifest.locales[locale];
415
+ if (!localeVersion) {
416
+ return {
417
+ success: false,
418
+ reason: 'not_found',
419
+ error: new Error('Locale not found'),
420
+ };
421
+ }
422
+ // Check etag
423
+ if (localeVersion.etag !== etag) {
424
+ return {
425
+ success: false,
426
+ reason: 'stale_write',
427
+ currentEtag: localeVersion.etag,
428
+ error: new Error('Stale write - etag mismatch'),
429
+ };
430
+ }
431
+ // If only one locale left, remove entire content
432
+ if (Object.keys(manifest.locales).length === 1) {
433
+ this.contentIndex.removeEntry(id);
434
+ }
435
+ else {
436
+ // Build updated manifest without the deleted locale
437
+ const updatedManifest = {
438
+ ...manifest,
439
+ locales: { ...manifest.locales },
440
+ };
441
+ updatedManifest.locales[locale] = undefined;
442
+ // Remove locale from index
443
+ this.contentIndex.removeLocale(manifest.id, locale);
444
+ }
445
+ return {
446
+ success: true,
447
+ };
448
+ }
449
+ async batchUpdate(operations) {
450
+ const results = {
451
+ operations: [],
452
+ success: true,
453
+ failed: 0,
454
+ updated: 0,
455
+ };
456
+ for (const op of operations) {
457
+ const result = await this.updateLocalized(op);
458
+ if (result.success) {
459
+ results.updated++;
460
+ results.operations.push({
461
+ id: op.id,
462
+ locale: op.locale,
463
+ updated: true,
464
+ etag: result.etag,
465
+ });
466
+ }
467
+ else {
468
+ results.failed++;
469
+ results.success = false;
470
+ results.operations.push({
471
+ id: op.id,
472
+ locale: op.locale,
473
+ updated: false,
474
+ error: result.error || new Error(result.reason || 'Update failed'),
475
+ });
476
+ }
477
+ }
478
+ return results;
479
+ }
480
+ // Test helper method to directly set content
481
+ setContent(id, content) {
482
+ // Build manifest from ContentEntry
483
+ const manifest = {
484
+ id: content.id,
485
+ type: content.type,
486
+ kind: content.kind,
487
+ site: content.site,
488
+ collection: content.collection,
489
+ locales: {},
490
+ };
491
+ const contentCache = {};
492
+ for (const [locale, localeData] of Object.entries(content.locales)) {
493
+ const manifestLocale = {
494
+ locale,
495
+ etag: localeData.etag,
496
+ created: localeData.created,
497
+ modified: localeData.modified,
498
+ meta: localeData.meta,
499
+ };
500
+ if (localeData.publishAt !== undefined) {
501
+ manifestLocale.publishAt = localeData.publishAt;
502
+ }
503
+ if (localeData.unpublishAt !== undefined) {
504
+ manifestLocale.unpublishAt = localeData.unpublishAt;
505
+ }
506
+ if (localeData.name) {
507
+ manifestLocale.name = localeData.name;
508
+ }
509
+ if (localeData.pathname) {
510
+ manifestLocale.pathname = localeData.pathname;
511
+ }
512
+ if (localeData.previousPathnames) {
513
+ manifestLocale.previousPathnames = localeData.previousPathnames;
514
+ }
515
+ manifest.locales[locale] = manifestLocale;
516
+ contentCache[locale] = localeData.content;
517
+ }
518
+ // Add to content index with each locale
519
+ for (const localeVersion of localesOf(manifest)) {
520
+ this.contentIndex.addContent(manifest, localeVersion, contentCache[localeVersion.locale]);
521
+ }
522
+ }
523
+ // Test helper to clear all content
524
+ clear() {
525
+ this.contentIndex.clear();
526
+ }
527
+ async getContentAsBuffer(id, locale) {
528
+ const manifest = this.contentIndex.getManifest(id);
529
+ if (!manifest || !manifest.locales[locale]) {
530
+ return null;
531
+ }
532
+ const localeVersion = manifest.locales[locale];
533
+ const cachedContent = this.contentIndex.getCachedContent(id, locale);
534
+ if (!cachedContent) {
535
+ return null;
536
+ }
537
+ // Serialize based on content type
538
+ let buffer;
539
+ let calculatedEtag;
540
+ let contentType;
541
+ if (manifest.type === 'mdx') {
542
+ // For MDX content, serialize as frontmatter + content
543
+ const frontmatterData = {
544
+ id: manifest.id,
545
+ created: localeVersion.created,
546
+ modified: localeVersion.modified,
547
+ ...(localeVersion.publishAt && { publishAt: localeVersion.publishAt }),
548
+ ...(localeVersion.unpublishAt && { unpublishAt: localeVersion.unpublishAt }),
549
+ ...localeVersion.meta, // Spread metadata fields directly, not nested
550
+ };
551
+ const mdxContent = serializeMdxWithFrontmatter(frontmatterData, cachedContent.mdx || '');
552
+ buffer = new TextEncoder().encode(mdxContent);
553
+ // Find content start position using shared utility
554
+ const contentPos = findMdxContentStartPosition(buffer);
555
+ // Calculate ETags using MDX-specific logic
556
+ const etagResult = calculateEtagsFromMdxBuffer(buffer, contentPos);
557
+ calculatedEtag = `${etagResult.metaEtag}.${etagResult.contentEtag}`;
558
+ contentType = 'text/mdx';
559
+ }
560
+ else {
561
+ // For Puck content, serialize as VXJSON
562
+ const fileData = {
563
+ id: manifest.id,
564
+ type: manifest.type,
565
+ created: localeVersion.created,
566
+ modified: localeVersion.modified,
567
+ publishAt: localeVersion.publishAt,
568
+ unpublishAt: localeVersion.unpublishAt,
569
+ meta: localeVersion.meta,
570
+ previousPathnames: localeVersion.previousPathnames,
571
+ content: cachedContent,
572
+ };
573
+ const jsonStr = VXJSON.serialize(fileData);
574
+ buffer = Buffer.from(jsonStr, 'utf-8');
575
+ // Calculate ETags to ensure they match what's stored
576
+ const etagResult = VXJSON.calculateETags(buffer);
577
+ if (!etagResult.success) {
578
+ throw new Error(`Invalid VXJSON format: ${etagResult.error}`);
579
+ }
580
+ calculatedEtag = etagResult.contentEtag
581
+ ? `${etagResult.metaEtag}.${etagResult.contentEtag}`
582
+ : etagResult.metaEtag;
583
+ contentType = 'application/json';
584
+ }
585
+ return {
586
+ buffer,
587
+ etag: calculatedEtag,
588
+ contentType,
589
+ };
590
+ }
591
+ }
@@ -0,0 +1,105 @@
1
+ import { z } from "zod";
2
+ //#region src/schemas/index.d.ts
3
+ /**
4
+ * Base schema for page metadata - editable fields only.
5
+ * Used by CMS forms for dynamic form generation.
6
+ * Add .describe() for form field labels/hints.
7
+ */
8
+ declare const pageEditableSchema: z.ZodObject<{
9
+ title: z.ZodString;
10
+ description: z.ZodOptional<z.ZodString>;
11
+ pathname: z.ZodString;
12
+ publishAt: z.ZodOptional<z.ZodNullable<z.ZodCoercedDate<unknown>>>;
13
+ unpublishAt: z.ZodOptional<z.ZodNullable<z.ZodCoercedDate<unknown>>>;
14
+ robots: z.ZodOptional<z.ZodString>;
15
+ canonical: z.ZodOptional<z.ZodString>;
16
+ }, z.core.$strip>;
17
+ type PageEditable = z.infer<typeof pageEditableSchema>;
18
+ /**
19
+ * Full page schema with system fields.
20
+ * Used by Astro Content Collections for validation.
21
+ */
22
+ declare const pageMetaSchema: z.ZodObject<{
23
+ title: z.ZodString;
24
+ description: z.ZodOptional<z.ZodString>;
25
+ pathname: z.ZodString;
26
+ publishAt: z.ZodOptional<z.ZodNullable<z.ZodCoercedDate<unknown>>>;
27
+ unpublishAt: z.ZodOptional<z.ZodNullable<z.ZodCoercedDate<unknown>>>;
28
+ robots: z.ZodOptional<z.ZodString>;
29
+ canonical: z.ZodOptional<z.ZodString>;
30
+ id: z.ZodString;
31
+ locale: z.ZodString;
32
+ }, z.core.$strip>;
33
+ type PageMeta = z.infer<typeof pageMetaSchema>;
34
+ /**
35
+ * Base schema for block metadata - editable fields only.
36
+ * Used by CMS forms for dynamic form generation.
37
+ * Add .describe() for form field labels/hints.
38
+ */
39
+ declare const blockEditableSchema: z.ZodObject<{
40
+ title: z.ZodString;
41
+ description: z.ZodOptional<z.ZodString>;
42
+ category: z.ZodOptional<z.ZodString>;
43
+ tags: z.ZodOptional<z.ZodArray<z.ZodString>>;
44
+ }, z.core.$strip>;
45
+ type BlockEditable = z.infer<typeof blockEditableSchema>;
46
+ /**
47
+ * Full block schema with system fields.
48
+ * Used by Astro Content Collections for validation.
49
+ */
50
+ declare const blockMetaSchema: z.ZodObject<{
51
+ title: z.ZodString;
52
+ description: z.ZodOptional<z.ZodString>;
53
+ category: z.ZodOptional<z.ZodString>;
54
+ tags: z.ZodOptional<z.ZodArray<z.ZodString>>;
55
+ id: z.ZodString;
56
+ locale: z.ZodString;
57
+ name: z.ZodString;
58
+ }, z.core.$strip>;
59
+ type BlockMeta = z.infer<typeof blockMetaSchema>;
60
+ /**
61
+ * Base schema for mdx-type page frontmatter — renderer-neutral.
62
+ *
63
+ * Default for the CMS form when editing an mdx page; projects override via
64
+ * `mdxPages.schema` when they want a renderer-specific shape (e.g. an
65
+ * Astro-collection schema with extra fields).
66
+ *
67
+ * Permissive on purpose: `.passthrough()` lets unknown frontmatter keys flow
68
+ * through unchanged so the file's existing fields are never lost on save.
69
+ */
70
+ declare const mdxPageFrontmatterSchema: z.ZodObject<{
71
+ title: z.ZodString;
72
+ description: z.ZodOptional<z.ZodString>;
73
+ draft: z.ZodOptional<z.ZodBoolean>;
74
+ }, z.core.$loose>;
75
+ type MdxPageFrontmatter = z.infer<typeof mdxPageFrontmatterSchema>;
76
+ /**
77
+ * Base schema for data entry metadata - editable fields only.
78
+ * Used by CMS forms for dynamic form generation.
79
+ * Add .describe() for form field labels/hints.
80
+ */
81
+ declare const dataEditableSchema: z.ZodObject<{
82
+ title: z.ZodString;
83
+ description: z.ZodOptional<z.ZodString>;
84
+ category: z.ZodOptional<z.ZodString>;
85
+ tags: z.ZodOptional<z.ZodArray<z.ZodString>>;
86
+ }, z.core.$strip>;
87
+ type DataEditable = z.infer<typeof dataEditableSchema>;
88
+ /**
89
+ * Zod schema for data entry metadata.
90
+ * Covers common organizational fields for structured data collections.
91
+ */
92
+ declare const dataMetaSchema: z.ZodObject<{
93
+ title: z.ZodString;
94
+ description: z.ZodOptional<z.ZodString>;
95
+ category: z.ZodOptional<z.ZodString>;
96
+ tags: z.ZodOptional<z.ZodArray<z.ZodString>>;
97
+ id: z.ZodString;
98
+ locale: z.ZodString;
99
+ name: z.ZodString;
100
+ data: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
101
+ }, z.core.$strip>;
102
+ type DataMeta = z.infer<typeof dataMetaSchema>;
103
+ //#endregion
104
+ export { MdxPageFrontmatter as a, blockEditableSchema as c, dataMetaSchema as d, mdxPageFrontmatterSchema as f, DataMeta as i, blockMetaSchema as l, pageMetaSchema as m, BlockMeta as n, PageEditable as o, pageEditableSchema as p, DataEditable as r, PageMeta as s, BlockEditable as t, dataEditableSchema as u };
105
+ //# sourceMappingURL=index-DxVTFK66.d.mts.map