@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.
- package/dist/asset-manifest.d.ts +23 -0
- package/dist/asset-manifest.d.ts.map +1 -0
- package/dist/asset-manifest.js +73 -0
- package/dist/asset-operations.d.ts +159 -0
- package/dist/asset-operations.d.ts.map +1 -0
- package/dist/asset-operations.js +736 -0
- package/dist/asset-types.d.ts +56 -0
- package/dist/asset-types.d.ts.map +1 -0
- package/dist/asset-types.js +7 -0
- package/dist/base-content-index.d.ts +57 -0
- package/dist/base-content-index.d.ts.map +1 -0
- package/dist/base-content-index.js +179 -0
- package/dist/block-index.d.ts +9 -0
- package/dist/block-index.d.ts.map +1 -0
- package/dist/block-index.js +11 -0
- package/dist/blocks.d.ts +16 -0
- package/dist/blocks.d.ts.map +1 -0
- package/dist/blocks.js +103 -0
- package/dist/cf-access.d.ts +31 -0
- package/dist/cf-access.d.ts.map +1 -0
- package/dist/cf-access.js +66 -0
- package/dist/component-registry.d.ts +50 -0
- package/dist/component-registry.d.ts.map +1 -0
- package/dist/component-registry.js +120 -0
- package/dist/component-registry.types-C0ctF9nh.d.mts +71 -0
- package/dist/component-registry.types-C0ctF9nh.d.mts.map +1 -0
- package/dist/component-registry.types.d.ts +11 -0
- package/dist/component-registry.types.d.ts.map +1 -0
- package/dist/component-registry.types.js +1 -0
- package/dist/content-api.interface.d.ts +64 -0
- package/dist/content-api.interface.d.ts.map +1 -0
- package/dist/content-api.interface.js +1 -0
- package/dist/content-filters.d.ts +31 -0
- package/dist/content-filters.d.ts.map +1 -0
- package/dist/content-filters.js +246 -0
- package/dist/content-index-D092_vk1.mjs +629 -0
- package/dist/content-index-D092_vk1.mjs.map +1 -0
- package/dist/content-index-D6IVMmAB.d.mts +127 -0
- package/dist/content-index-D6IVMmAB.d.mts.map +1 -0
- package/dist/content-index.d.ts +126 -0
- package/dist/content-index.d.ts.map +1 -0
- package/dist/content-index.js +418 -0
- package/dist/content-operations-DIbsxG5A.d.mts +354 -0
- package/dist/content-operations-DIbsxG5A.d.mts.map +1 -0
- package/dist/content-operations.d.ts +93 -0
- package/dist/content-operations.d.ts.map +1 -0
- package/dist/content-operations.js +275 -0
- package/dist/content-reader.d.ts +10 -0
- package/dist/content-reader.d.ts.map +1 -0
- package/dist/content-reader.js +13 -0
- package/dist/content-utils-fWNHTrPy.mjs +280 -0
- package/dist/content-utils-fWNHTrPy.mjs.map +1 -0
- package/dist/content-utils.d.ts +132 -0
- package/dist/content-utils.d.ts.map +1 -0
- package/dist/content-utils.js +352 -0
- package/dist/content-watcher.d.ts +43 -0
- package/dist/content-watcher.d.ts.map +1 -0
- package/dist/content-watcher.js +83 -0
- package/dist/data-DquNIEnQ.mjs +62 -0
- package/dist/data-DquNIEnQ.mjs.map +1 -0
- package/dist/data-index.d.ts +8 -0
- package/dist/data-index.d.ts.map +1 -0
- package/dist/data-index.js +7 -0
- package/dist/data.d.ts +43 -0
- package/dist/data.d.ts.map +1 -0
- package/dist/data.js +103 -0
- package/dist/etag-utils.d.ts +77 -0
- package/dist/etag-utils.d.ts.map +1 -0
- package/dist/etag-utils.js +160 -0
- package/dist/filesystem-content-api-B1KIQJfk.mjs +2 -0
- package/dist/filesystem-content-api-C0HIhqZi.mjs +1620 -0
- package/dist/filesystem-content-api-C0HIhqZi.mjs.map +1 -0
- package/dist/filesystem-content-api-DCdNi-co.d.mts +134 -0
- package/dist/filesystem-content-api-DCdNi-co.d.mts.map +1 -0
- package/dist/filesystem-content-api.d.ts +135 -0
- package/dist/filesystem-content-api.d.ts.map +1 -0
- package/dist/filesystem-content-api.js +2181 -0
- package/dist/git-operations.d.ts +49 -0
- package/dist/git-operations.d.ts.map +1 -0
- package/dist/git-operations.js +252 -0
- package/dist/header-parser.d.ts +37 -0
- package/dist/header-parser.d.ts.map +1 -0
- package/dist/header-parser.js +286 -0
- package/dist/in-memory-content-api.d.ts +35 -0
- package/dist/in-memory-content-api.d.ts.map +1 -0
- package/dist/in-memory-content-api.js +591 -0
- package/dist/index-DxVTFK66.d.mts +105 -0
- package/dist/index-DxVTFK66.d.mts.map +1 -0
- package/dist/index.d.mts +6 -4
- package/dist/index.d.mts.map +1 -1
- package/dist/index.d.ts +19 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +16 -0
- package/dist/index.mjs +37 -5
- package/dist/index.mjs.map +1 -1
- package/dist/indexing.d.mts +152 -0
- package/dist/indexing.d.mts.map +1 -0
- package/dist/indexing.d.ts +5 -0
- package/dist/indexing.d.ts.map +1 -0
- package/dist/indexing.js +7 -0
- package/dist/indexing.mjs +255 -0
- package/dist/indexing.mjs.map +1 -0
- package/dist/json-whitespace-view.d.ts +32 -0
- package/dist/json-whitespace-view.d.ts.map +1 -0
- package/dist/json-whitespace-view.js +152 -0
- package/dist/middleware.d.ts +20 -0
- package/dist/middleware.d.ts.map +1 -0
- package/dist/middleware.js +1031 -0
- package/dist/node.d.mts +28 -126
- package/dist/node.d.mts.map +1 -1
- package/dist/node.d.ts +25 -0
- package/dist/node.d.ts.map +1 -0
- package/dist/node.js +24 -0
- package/dist/node.mjs +199 -2890
- package/dist/node.mjs.map +1 -1
- package/dist/reader.d.mts +15 -0
- package/dist/reader.d.mts.map +1 -0
- package/dist/reader.d.ts +15 -0
- package/dist/reader.d.ts.map +1 -0
- package/dist/reader.js +13 -0
- package/dist/reader.mjs +22 -0
- package/dist/reader.mjs.map +1 -0
- package/dist/schemas/index.d.mts +2 -90
- package/dist/schemas/index.d.ts +102 -0
- package/dist/schemas/index.d.ts.map +1 -0
- package/dist/schemas/index.js +87 -0
- package/dist/schemas/index.mjs +2 -70
- package/dist/schemas-CFRD0FIQ.mjs +84 -0
- package/dist/schemas-CFRD0FIQ.mjs.map +1 -0
- package/dist/{types-BUG0Cfkg.mjs → site-8oaj1Q60.mjs} +20 -222
- package/dist/site-8oaj1Q60.mjs.map +1 -0
- package/dist/site-index-B_254bCc.d.mts +136 -0
- package/dist/site-index-B_254bCc.d.mts.map +1 -0
- package/dist/site-index.d.ts +60 -0
- package/dist/site-index.d.ts.map +1 -0
- package/dist/site-index.js +287 -0
- package/dist/site.d.ts +21 -0
- package/dist/site.d.ts.map +1 -0
- package/dist/site.js +168 -0
- package/dist/types-DOdldbfD.mjs +34 -0
- package/dist/types-DOdldbfD.mjs.map +1 -0
- package/dist/types-DjfhS272.d.mts +456 -0
- package/dist/types-DjfhS272.d.mts.map +1 -0
- package/dist/types.d.ts +453 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +36 -0
- package/dist/url-safe-base64.d.ts +12 -0
- package/dist/url-safe-base64.d.ts.map +1 -0
- package/dist/url-safe-base64.js +40 -0
- package/dist/url-validation.d.ts +14 -0
- package/dist/url-validation.d.ts.map +1 -0
- package/dist/url-validation.js +81 -0
- package/dist/utils/atomic-write.d.ts +6 -0
- package/dist/utils/atomic-write.d.ts.map +1 -0
- package/dist/utils/atomic-write.js +20 -0
- package/dist/utils.d.ts +46 -0
- package/dist/utils.d.ts.map +1 -0
- package/dist/utils.js +70 -0
- package/dist/vite-plugin.d.ts +12 -0
- package/dist/vite-plugin.d.ts.map +1 -0
- package/dist/vite-plugin.js +29 -0
- package/dist/vxjson-qHrgLGip.mjs +555 -0
- package/dist/vxjson-qHrgLGip.mjs.map +1 -0
- package/dist/vxjson-serialize-geF6qvpn.mjs +34 -0
- package/dist/vxjson-serialize-geF6qvpn.mjs.map +1 -0
- package/dist/vxjson-serialize.d.mts +17 -0
- package/dist/vxjson-serialize.d.mts.map +1 -0
- package/dist/vxjson-serialize.d.ts +14 -0
- package/dist/vxjson-serialize.d.ts.map +1 -0
- package/dist/vxjson-serialize.js +50 -0
- package/dist/vxjson-serialize.mjs +2 -0
- package/dist/vxjson.d.ts +112 -0
- package/dist/vxjson.d.ts.map +1 -0
- package/dist/vxjson.js +391 -0
- package/dist/xxhash.d.ts +10 -0
- package/dist/xxhash.d.ts.map +1 -0
- package/dist/xxhash.js +31 -0
- package/package.json +88 -17
- package/dist/content-operations-BZLfJWqT.d.mts +0 -916
- package/dist/content-operations-BZLfJWqT.d.mts.map +0 -1
- package/dist/schemas/index.d.mts.map +0 -1
- package/dist/schemas/index.mjs.map +0 -1
- package/dist/types-BUG0Cfkg.mjs.map +0 -1
|
@@ -0,0 +1,287 @@
|
|
|
1
|
+
import { isContentPublished, localesOf, mapLocales } from './content-utils';
|
|
2
|
+
/**
|
|
3
|
+
* V8-optimized index for a single site
|
|
4
|
+
* Maintains pathname lookups and collections for one site only
|
|
5
|
+
*/
|
|
6
|
+
export class SiteIndex {
|
|
7
|
+
locales;
|
|
8
|
+
// Primary index: id -> ContentManifest
|
|
9
|
+
index = new Map();
|
|
10
|
+
// Content cache: id -> locale -> content (for small files)
|
|
11
|
+
contentCache = new Map();
|
|
12
|
+
// Pathname index: locale -> (pathname -> ContentManifest)
|
|
13
|
+
// Locale level uses V8-optimized record, pathname level uses Map for dynamic keys
|
|
14
|
+
pathnameIndex;
|
|
15
|
+
// Previous pathname index for redirects: locale -> (oldPathname -> ContentManifest)
|
|
16
|
+
// Same structure - record for locales, Map for pathnames
|
|
17
|
+
previousPathnameIndex;
|
|
18
|
+
// Collections used by this site
|
|
19
|
+
collections = new Set();
|
|
20
|
+
constructor(siteName, locales) {
|
|
21
|
+
this.locales = locales;
|
|
22
|
+
// Initialize pathname indexes - V8-optimized record for locales, Maps for pathnames
|
|
23
|
+
this.pathnameIndex = mapLocales(locales, () => new Map());
|
|
24
|
+
this.previousPathnameIndex = mapLocales(locales, () => new Map());
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Add or update content in the index
|
|
28
|
+
* Merges manifest locales and updates content cache if provided
|
|
29
|
+
*/
|
|
30
|
+
addContent(identity, localeVersion, content) {
|
|
31
|
+
// Get existing manifest
|
|
32
|
+
const existing = this.index.get(identity.id);
|
|
33
|
+
const locale = localeVersion.locale;
|
|
34
|
+
if (existing) {
|
|
35
|
+
const existingLocale = existing.locales[locale];
|
|
36
|
+
// Track what we need to rollback
|
|
37
|
+
// First check what pathname currently maps to this manifest in our index
|
|
38
|
+
// This handles in-place updates where the manifest object has already been modified
|
|
39
|
+
let oldPathname;
|
|
40
|
+
// Find all pathnames that currently point to this manifest
|
|
41
|
+
for (const [pathname, indexedManifest] of this.pathnameIndex[locale].entries()) {
|
|
42
|
+
if (indexedManifest === existing && pathname !== localeVersion.pathname) {
|
|
43
|
+
oldPathname = pathname;
|
|
44
|
+
break;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
// If we didn't find it in the index, fall back to what's stored in the existing locale
|
|
48
|
+
if (!oldPathname && existingLocale?.pathname && existingLocale.pathname !== localeVersion.pathname) {
|
|
49
|
+
oldPathname = existingLocale.pathname;
|
|
50
|
+
}
|
|
51
|
+
const hadExistingLocale = !!existingLocale;
|
|
52
|
+
let deletedOldPathname = false;
|
|
53
|
+
let addedNewPathname = false;
|
|
54
|
+
const addedPreviousPathnames = [];
|
|
55
|
+
// Update locale manifest if changed
|
|
56
|
+
// We need to always check for pathname changes, even if other fields haven't changed
|
|
57
|
+
// This handles in-place updates where the manifest is modified before calling addContent
|
|
58
|
+
const needsUpdate = !existingLocale ||
|
|
59
|
+
existingLocale.etag !== localeVersion.etag ||
|
|
60
|
+
existingLocale.modified !== localeVersion.modified ||
|
|
61
|
+
(oldPathname && oldPathname !== localeVersion.pathname);
|
|
62
|
+
if (needsUpdate) {
|
|
63
|
+
try {
|
|
64
|
+
// Update the manifest locale
|
|
65
|
+
existing.locales[locale] = localeVersion;
|
|
66
|
+
// Update pathname indexes after manifest is updated
|
|
67
|
+
if (localeVersion.pathname) {
|
|
68
|
+
// If pathname changed, remove the old one
|
|
69
|
+
if (oldPathname && oldPathname !== localeVersion.pathname) {
|
|
70
|
+
this.pathnameIndex[locale].delete(oldPathname);
|
|
71
|
+
deletedOldPathname = true;
|
|
72
|
+
// Track the old pathname for redirects only if content is published
|
|
73
|
+
if (isContentPublished(localeVersion)) {
|
|
74
|
+
this.previousPathnameIndex[locale].set(oldPathname, existing);
|
|
75
|
+
addedPreviousPathnames.push(oldPathname);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
// Add/update the new pathname
|
|
79
|
+
this.pathnameIndex[locale].set(localeVersion.pathname, existing);
|
|
80
|
+
addedNewPathname = true;
|
|
81
|
+
}
|
|
82
|
+
// Update previous pathname indexes from the manifest
|
|
83
|
+
if (localeVersion.previousPathnames) {
|
|
84
|
+
for (const prevPath of Object.keys(localeVersion.previousPathnames)) {
|
|
85
|
+
// Only add if not already there
|
|
86
|
+
if (!this.previousPathnameIndex[locale].has(prevPath)) {
|
|
87
|
+
this.previousPathnameIndex[locale].set(prevPath, existing);
|
|
88
|
+
addedPreviousPathnames.push(prevPath);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
catch (error) {
|
|
94
|
+
// Rollback only what we changed
|
|
95
|
+
if (hadExistingLocale) {
|
|
96
|
+
existing.locales[locale] = existingLocale;
|
|
97
|
+
}
|
|
98
|
+
else {
|
|
99
|
+
existing.locales[locale] = undefined;
|
|
100
|
+
}
|
|
101
|
+
// Rollback pathname index changes
|
|
102
|
+
if (deletedOldPathname && oldPathname) {
|
|
103
|
+
this.pathnameIndex[locale].set(oldPathname, existing);
|
|
104
|
+
}
|
|
105
|
+
if (addedNewPathname && localeVersion.pathname) {
|
|
106
|
+
this.pathnameIndex[locale].delete(localeVersion.pathname);
|
|
107
|
+
}
|
|
108
|
+
// Rollback previous pathname additions
|
|
109
|
+
for (const prevPath of addedPreviousPathnames) {
|
|
110
|
+
this.previousPathnameIndex[locale].delete(prevPath);
|
|
111
|
+
}
|
|
112
|
+
throw error;
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
else {
|
|
117
|
+
// New content - create ContentManifest with single locale
|
|
118
|
+
const newManifest = {
|
|
119
|
+
id: identity.id,
|
|
120
|
+
type: identity.type,
|
|
121
|
+
kind: identity.kind,
|
|
122
|
+
site: identity.site,
|
|
123
|
+
collection: identity.collection,
|
|
124
|
+
locales: {
|
|
125
|
+
[locale]: localeVersion,
|
|
126
|
+
},
|
|
127
|
+
};
|
|
128
|
+
this.index.set(identity.id, newManifest);
|
|
129
|
+
this.collections.add(identity.collection);
|
|
130
|
+
// Add pathname indexes
|
|
131
|
+
if (localeVersion.pathname) {
|
|
132
|
+
this.pathnameIndex[locale].set(localeVersion.pathname, newManifest);
|
|
133
|
+
}
|
|
134
|
+
if (localeVersion.previousPathnames) {
|
|
135
|
+
for (const prevPath of Object.keys(localeVersion.previousPathnames)) {
|
|
136
|
+
this.previousPathnameIndex[locale].set(prevPath, newManifest);
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
// Update content cache if provided
|
|
141
|
+
if (content !== undefined) {
|
|
142
|
+
const existingCache = this.contentCache.get(identity.id);
|
|
143
|
+
if (existingCache) {
|
|
144
|
+
// Update single locale content
|
|
145
|
+
existingCache[locale] = content;
|
|
146
|
+
}
|
|
147
|
+
else {
|
|
148
|
+
this.contentCache.set(identity.id, { [locale]: content });
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
/**
|
|
153
|
+
* Remove a specific locale from an entry
|
|
154
|
+
*/
|
|
155
|
+
removeLocale(id, locale) {
|
|
156
|
+
const manifest = this.index.get(id);
|
|
157
|
+
if (!manifest || !manifest.locales[locale])
|
|
158
|
+
return;
|
|
159
|
+
const localeVersion = manifest.locales[locale];
|
|
160
|
+
// Remove from pathname indexes
|
|
161
|
+
if (localeVersion.pathname) {
|
|
162
|
+
this.pathnameIndex[locale].delete(localeVersion.pathname);
|
|
163
|
+
}
|
|
164
|
+
if (localeVersion.previousPathnames) {
|
|
165
|
+
for (const prevPath of Object.keys(localeVersion.previousPathnames)) {
|
|
166
|
+
this.previousPathnameIndex[locale].delete(prevPath);
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
// Remove locale from manifest
|
|
170
|
+
manifest.locales[locale] = undefined;
|
|
171
|
+
// Remove from content cache
|
|
172
|
+
const contentCache = this.contentCache.get(id);
|
|
173
|
+
if (contentCache) {
|
|
174
|
+
delete contentCache[locale];
|
|
175
|
+
}
|
|
176
|
+
// If no locales left, remove the entire entry
|
|
177
|
+
if (Object.keys(manifest.locales).length === 0) {
|
|
178
|
+
this.removeEntry(id);
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
/**
|
|
182
|
+
* Remove an entry from the index
|
|
183
|
+
*/
|
|
184
|
+
removeEntry(id) {
|
|
185
|
+
const manifest = this.index.get(id);
|
|
186
|
+
if (!manifest)
|
|
187
|
+
return;
|
|
188
|
+
// Remove from pathname indexes
|
|
189
|
+
for (const localeVersion of localesOf(manifest)) {
|
|
190
|
+
const { locale } = localeVersion;
|
|
191
|
+
if (localeVersion.pathname) {
|
|
192
|
+
this.pathnameIndex[locale].delete(localeVersion.pathname);
|
|
193
|
+
}
|
|
194
|
+
if (localeVersion.previousPathnames) {
|
|
195
|
+
for (const prevPath of Object.keys(localeVersion.previousPathnames)) {
|
|
196
|
+
this.previousPathnameIndex[locale].delete(prevPath);
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
// Remove from primary index
|
|
201
|
+
this.index.delete(id);
|
|
202
|
+
// Remove from content cache
|
|
203
|
+
this.contentCache.delete(id);
|
|
204
|
+
}
|
|
205
|
+
/**
|
|
206
|
+
* Get cached content for a specific locale
|
|
207
|
+
*/
|
|
208
|
+
getCachedContent(id, locale) {
|
|
209
|
+
const localeContent = this.contentCache.get(id);
|
|
210
|
+
return localeContent?.[locale] || null;
|
|
211
|
+
}
|
|
212
|
+
/**
|
|
213
|
+
* Get content manifest
|
|
214
|
+
*/
|
|
215
|
+
getManifest(id) {
|
|
216
|
+
return this.index.get(id) || null;
|
|
217
|
+
}
|
|
218
|
+
/**
|
|
219
|
+
* Find content by pathname
|
|
220
|
+
*/
|
|
221
|
+
getByPathname(pathname, locale) {
|
|
222
|
+
if (locale) {
|
|
223
|
+
return this.pathnameIndex[locale]?.get(pathname) || null;
|
|
224
|
+
}
|
|
225
|
+
// Check all locales
|
|
226
|
+
for (const locale of this.locales) {
|
|
227
|
+
const manifest = this.pathnameIndex[locale].get(pathname);
|
|
228
|
+
if (manifest) {
|
|
229
|
+
return manifest;
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
return null;
|
|
233
|
+
}
|
|
234
|
+
/**
|
|
235
|
+
* Find content by previous pathname (for redirects)
|
|
236
|
+
*/
|
|
237
|
+
getByPreviousPathname(pathname, locale) {
|
|
238
|
+
if (locale) {
|
|
239
|
+
return this.previousPathnameIndex[locale]?.get(pathname) || null;
|
|
240
|
+
}
|
|
241
|
+
// Check all locales
|
|
242
|
+
for (const locale of this.locales) {
|
|
243
|
+
const manifest = this.previousPathnameIndex[locale].get(pathname);
|
|
244
|
+
if (manifest) {
|
|
245
|
+
return manifest;
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
return null;
|
|
249
|
+
}
|
|
250
|
+
/**
|
|
251
|
+
* Generator for all manifests
|
|
252
|
+
*/
|
|
253
|
+
*getAllManifests() {
|
|
254
|
+
for (const manifest of this.index.values()) {
|
|
255
|
+
yield manifest;
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
/**
|
|
259
|
+
* Generator for manifests by locale
|
|
260
|
+
*/
|
|
261
|
+
*getManifestsByLocale(locale) {
|
|
262
|
+
for (const manifest of this.index.values()) {
|
|
263
|
+
if (manifest.locales[locale]) {
|
|
264
|
+
yield manifest;
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
/**
|
|
269
|
+
* Get the count of indexed content entries (unique IDs)
|
|
270
|
+
*/
|
|
271
|
+
get entryCount() {
|
|
272
|
+
return this.index.size;
|
|
273
|
+
}
|
|
274
|
+
/**
|
|
275
|
+
* Clear all indexes
|
|
276
|
+
*/
|
|
277
|
+
clear() {
|
|
278
|
+
this.index.clear();
|
|
279
|
+
this.contentCache.clear();
|
|
280
|
+
// Clear all Maps in the pathname indexes
|
|
281
|
+
for (const locale of this.locales) {
|
|
282
|
+
this.pathnameIndex[locale].clear();
|
|
283
|
+
this.previousPathnameIndex[locale].clear();
|
|
284
|
+
}
|
|
285
|
+
this.collections.clear();
|
|
286
|
+
}
|
|
287
|
+
}
|
package/dist/site.d.ts
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { ContentAPI } from './content-api.interface';
|
|
2
|
+
import type { SiteIndex } from './site-index';
|
|
3
|
+
import type { ContentManifest, CreatePageInput, CreateResult, MoveResult, SiteFilters } from './types';
|
|
4
|
+
export declare class Site {
|
|
5
|
+
private siteName;
|
|
6
|
+
private api;
|
|
7
|
+
private siteIndex;
|
|
8
|
+
constructor(siteName: string, api: ContentAPI, siteIndex: SiteIndex);
|
|
9
|
+
listContent(filters?: SiteFilters): Generator<ContentManifest>;
|
|
10
|
+
listPages(locale?: string): Generator<ContentManifest>;
|
|
11
|
+
get collections(): Set<string>;
|
|
12
|
+
getByPathname(pathname: string, locale?: string): ContentManifest | null;
|
|
13
|
+
getByPreviousPathname(pathname: string, locale?: string): ContentManifest | null;
|
|
14
|
+
move(id: string, locale: string, newPathname: string): Promise<MoveResult>;
|
|
15
|
+
getRedirect(pathname: string): ContentManifest | null;
|
|
16
|
+
isPathnameAvailable(pathname: string, locale: string, excludeId?: string): boolean;
|
|
17
|
+
getPathnameConflict(pathname: string, locale: string, excludeId?: string): string | null;
|
|
18
|
+
isPathnameInRedirects(pathname: string, locale: string): boolean;
|
|
19
|
+
create(data: CreatePageInput): Promise<CreateResult>;
|
|
20
|
+
}
|
|
21
|
+
//# sourceMappingURL=site.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"site.d.ts","sourceRoot":"","sources":["../src/site.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAC;AAE1D,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAC9C,OAAO,KAAK,EAAE,eAAe,EAAE,eAAe,EAAE,YAAY,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAEvG,qBAAa,IAAI;IAEb,OAAO,CAAC,QAAQ;IAChB,OAAO,CAAC,GAAG;IACX,OAAO,CAAC,SAAS;IAHnB,YACU,QAAQ,EAAE,MAAM,EAChB,GAAG,EAAE,UAAU,EACf,SAAS,EAAE,SAAS,EAC1B;IAGH,WAAW,CAAC,OAAO,CAAC,EAAE,WAAW,GAAG,SAAS,CAAC,eAAe,CAAC,CAgC9D;IAGA,SAAS,CAAC,MAAM,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC,eAAe,CAAC,CAKtD;IAGD,IAAI,WAAW,IAAI,GAAG,CAAC,MAAM,CAAC,CAE7B;IAGD,aAAa,CAAC,QAAQ,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,MAAM,GAAG,eAAe,GAAG,IAAI,CAEvE;IAGD,qBAAqB,CAAC,QAAQ,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,MAAM,GAAG,eAAe,GAAG,IAAI,CAE/E;IAGK,IAAI,CAAC,EAAE,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,GAAG,OAAO,CAAC,UAAU,CAAC,CA2C/E;IAGD,WAAW,CAAC,QAAQ,EAAE,MAAM,GAAG,eAAe,GAAG,IAAI,CAEpD;IAGD,mBAAmB,CAAC,QAAQ,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,SAAS,CAAC,EAAE,MAAM,GAAG,OAAO,CAcjF;IAGD,mBAAmB,CAAC,QAAQ,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,SAAS,CAAC,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAMvF;IAGD,qBAAqB,CAAC,QAAQ,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,OAAO,CAE/D;IAGK,MAAM,CAAC,IAAI,EAAE,eAAe,GAAG,OAAO,CAAC,YAAY,CAAC,CA8BzD;CACF"}
|
package/dist/site.js
ADDED
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
import { localesOf } from './content-utils';
|
|
2
|
+
export class Site {
|
|
3
|
+
siteName;
|
|
4
|
+
api;
|
|
5
|
+
siteIndex;
|
|
6
|
+
constructor(siteName, api, siteIndex) {
|
|
7
|
+
this.siteName = siteName;
|
|
8
|
+
this.api = api;
|
|
9
|
+
this.siteIndex = siteIndex;
|
|
10
|
+
}
|
|
11
|
+
// Content discovery
|
|
12
|
+
*listContent(filters) {
|
|
13
|
+
// Get the base manifests using the most efficient method
|
|
14
|
+
let manifests;
|
|
15
|
+
if (filters?.locales && filters.locales.length === 1) {
|
|
16
|
+
manifests = this.siteIndex.getManifestsByLocale(filters.locales[0]);
|
|
17
|
+
}
|
|
18
|
+
else {
|
|
19
|
+
manifests = this.siteIndex.getAllManifests();
|
|
20
|
+
}
|
|
21
|
+
// Apply additional filters if needed
|
|
22
|
+
if (filters?.collection || filters?.type || filters?.published !== undefined) {
|
|
23
|
+
for (const manifest of manifests) {
|
|
24
|
+
if (filters.collection && manifest.collection !== filters.collection)
|
|
25
|
+
continue;
|
|
26
|
+
if (filters.type && manifest.type !== filters.type)
|
|
27
|
+
continue;
|
|
28
|
+
if (filters.published !== undefined) {
|
|
29
|
+
// Check if any locale is published
|
|
30
|
+
let hasPublishedLocale = false;
|
|
31
|
+
for (const locale of localesOf(manifest)) {
|
|
32
|
+
if (!locale.unpublishAt || new Date(locale.unpublishAt) > new Date()) {
|
|
33
|
+
hasPublishedLocale = true;
|
|
34
|
+
break;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
if (filters.published !== hasPublishedLocale)
|
|
38
|
+
continue;
|
|
39
|
+
}
|
|
40
|
+
yield manifest;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
else {
|
|
44
|
+
// No additional filters, yield all manifests
|
|
45
|
+
yield* manifests;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
// List pages (convenience method for middleware)
|
|
49
|
+
*listPages(locale) {
|
|
50
|
+
const filters = {};
|
|
51
|
+
if (locale)
|
|
52
|
+
filters.locales = [locale];
|
|
53
|
+
yield* this.listContent(filters);
|
|
54
|
+
}
|
|
55
|
+
// Get all collections for this site
|
|
56
|
+
get collections() {
|
|
57
|
+
return this.siteIndex.collections;
|
|
58
|
+
}
|
|
59
|
+
// Pathname operations (returns null if available, ContentManifest if taken)
|
|
60
|
+
getByPathname(pathname, locale) {
|
|
61
|
+
return this.siteIndex.getByPathname(pathname, locale);
|
|
62
|
+
}
|
|
63
|
+
// Get by previous pathname (for redirects)
|
|
64
|
+
getByPreviousPathname(pathname, locale) {
|
|
65
|
+
return this.siteIndex.getByPreviousPathname(pathname, locale);
|
|
66
|
+
}
|
|
67
|
+
// Move content (handles rename + redirect tracking)
|
|
68
|
+
async move(id, locale, newPathname) {
|
|
69
|
+
// Check if new pathname is available
|
|
70
|
+
const existing = this.getByPathname(newPathname, locale);
|
|
71
|
+
if (existing && existing.id !== id) {
|
|
72
|
+
return {
|
|
73
|
+
moved: false,
|
|
74
|
+
reason: 'already_exists',
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
// Get current content
|
|
78
|
+
const content = await this.api.getLocalized(id, locale);
|
|
79
|
+
if (!content) {
|
|
80
|
+
return {
|
|
81
|
+
moved: false,
|
|
82
|
+
reason: 'not_found',
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
// Update with new pathname (this will handle previousPathnames)
|
|
86
|
+
const updateResult = await this.api.updateLocalized({
|
|
87
|
+
id,
|
|
88
|
+
locale,
|
|
89
|
+
data: {
|
|
90
|
+
pathname: newPathname,
|
|
91
|
+
meta: content.localized.meta,
|
|
92
|
+
},
|
|
93
|
+
etag: content.localized.etag,
|
|
94
|
+
});
|
|
95
|
+
if (!updateResult.success) {
|
|
96
|
+
return {
|
|
97
|
+
moved: false,
|
|
98
|
+
reason: updateResult.reason,
|
|
99
|
+
error: updateResult.error,
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
return {
|
|
103
|
+
moved: true,
|
|
104
|
+
previousPathname: content.localized.pathname,
|
|
105
|
+
etag: updateResult.etag,
|
|
106
|
+
};
|
|
107
|
+
}
|
|
108
|
+
// Check if pathname is in redirect history
|
|
109
|
+
getRedirect(pathname) {
|
|
110
|
+
return this.siteIndex.getByPreviousPathname(pathname);
|
|
111
|
+
}
|
|
112
|
+
// Validate pathname is available (not taken or in redirects)
|
|
113
|
+
isPathnameAvailable(pathname, locale, excludeId) {
|
|
114
|
+
// Check if pathname is already taken
|
|
115
|
+
const existing = this.getByPathname(pathname, locale);
|
|
116
|
+
if (existing && existing.id !== excludeId) {
|
|
117
|
+
return false;
|
|
118
|
+
}
|
|
119
|
+
// Check if pathname is in redirects
|
|
120
|
+
const redirect = this.getByPreviousPathname(pathname, locale);
|
|
121
|
+
if (redirect && redirect.id !== excludeId) {
|
|
122
|
+
return false;
|
|
123
|
+
}
|
|
124
|
+
return true;
|
|
125
|
+
}
|
|
126
|
+
// Get the ID of content that conflicts with a pathname
|
|
127
|
+
getPathnameConflict(pathname, locale, excludeId) {
|
|
128
|
+
const existing = this.getByPathname(pathname, locale);
|
|
129
|
+
if (existing && existing.id !== excludeId) {
|
|
130
|
+
return existing.id;
|
|
131
|
+
}
|
|
132
|
+
return null;
|
|
133
|
+
}
|
|
134
|
+
// Check if pathname is in redirects
|
|
135
|
+
isPathnameInRedirects(pathname, locale) {
|
|
136
|
+
return this.getByPreviousPathname(pathname, locale) !== null;
|
|
137
|
+
}
|
|
138
|
+
// Create page with validation
|
|
139
|
+
async create(data) {
|
|
140
|
+
// Validate pathname availability for all locales
|
|
141
|
+
for (const [locale, localeData] of Object.entries(data.locales)) {
|
|
142
|
+
const existing = this.getByPathname(localeData.pathname, locale);
|
|
143
|
+
if (existing) {
|
|
144
|
+
return {
|
|
145
|
+
success: false,
|
|
146
|
+
reason: 'pathname_taken',
|
|
147
|
+
error: new Error(`Pathname ${localeData.pathname} is already in use for locale ${locale}`),
|
|
148
|
+
};
|
|
149
|
+
}
|
|
150
|
+
// Check redirects too
|
|
151
|
+
const redirect = this.getRedirect(localeData.pathname);
|
|
152
|
+
if (redirect) {
|
|
153
|
+
return {
|
|
154
|
+
success: false,
|
|
155
|
+
reason: 'pathname_in_redirects',
|
|
156
|
+
error: new Error(`Pathname ${localeData.pathname} is in redirect history for locale ${locale}`),
|
|
157
|
+
};
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
return this.api.createContent({
|
|
161
|
+
kind: 'page',
|
|
162
|
+
site: this.siteName,
|
|
163
|
+
collection: data.collection,
|
|
164
|
+
type: 'puck',
|
|
165
|
+
locales: data.locales,
|
|
166
|
+
});
|
|
167
|
+
}
|
|
168
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
//#region src/types.ts
|
|
2
|
+
const ErrorCodes = {
|
|
3
|
+
CONTENT_NOT_FOUND: "CONTENT_NOT_FOUND",
|
|
4
|
+
LOCALE_NOT_FOUND: "LOCALE_NOT_FOUND",
|
|
5
|
+
COLLECTION_NOT_FOUND: "COLLECTION_NOT_FOUND",
|
|
6
|
+
SITE_NOT_FOUND: "SITE_NOT_FOUND",
|
|
7
|
+
STALE_WRITE: "STALE_WRITE",
|
|
8
|
+
ALREADY_EXISTS: "ALREADY_EXISTS",
|
|
9
|
+
PATHNAME_TAKEN: "PATHNAME_TAKEN",
|
|
10
|
+
INVALID_PATHNAME: "INVALID_PATHNAME",
|
|
11
|
+
NAME_TAKEN: "NAME_TAKEN",
|
|
12
|
+
METADATA_TOO_LARGE: "METADATA_TOO_LARGE",
|
|
13
|
+
WRITE_ERROR: "WRITE_ERROR",
|
|
14
|
+
MISSING_REQUIRED_FIELD: "MISSING_REQUIRED_FIELD",
|
|
15
|
+
INVALID_LOCALE: "INVALID_LOCALE",
|
|
16
|
+
INVALID_CONTENT_TYPE: "INVALID_CONTENT_TYPE",
|
|
17
|
+
INVALID_REQUEST: "INVALID_REQUEST",
|
|
18
|
+
MDX_COMPILE_FAILED: "MDX_COMPILE_FAILED",
|
|
19
|
+
INTERNAL_ERROR: "INTERNAL_ERROR",
|
|
20
|
+
FETCH_ERROR: "FETCH_ERROR",
|
|
21
|
+
GIT_NOT_REPO: "GIT_NOT_REPO",
|
|
22
|
+
GIT_COMMIT_FAILED: "GIT_COMMIT_FAILED",
|
|
23
|
+
GIT_PUSH_FAILED: "GIT_PUSH_FAILED",
|
|
24
|
+
GIT_PULL_FAILED: "GIT_PULL_FAILED",
|
|
25
|
+
GIT_STATUS_FAILED: "GIT_STATUS_FAILED",
|
|
26
|
+
ASSET_NOT_FOUND: "ASSET_NOT_FOUND",
|
|
27
|
+
ASSET_INVALID_FORMAT: "ASSET_INVALID_FORMAT",
|
|
28
|
+
ASSET_TOO_LARGE: "ASSET_TOO_LARGE",
|
|
29
|
+
ASSET_UPLOAD_FAILED: "ASSET_UPLOAD_FAILED"
|
|
30
|
+
};
|
|
31
|
+
//#endregion
|
|
32
|
+
export { ErrorCodes as t };
|
|
33
|
+
|
|
34
|
+
//# sourceMappingURL=types-DOdldbfD.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types-DOdldbfD.mjs","names":[],"sources":["../src/types.ts"],"sourcesContent":["export interface ContentAPIOptions {\n contentRoot: string;\n canvasDir?: string;\n\n /**\n * Optional override for the mdx-type pages path. The canonical home for\n * this value is the resolved site's `mdxPages` field in `sites.json`.\n * This option, when present, wins over the sites.json value — useful\n * for tests and programmatic content-api setups that don't want to\n * round-trip through a sites.json file on disk.\n *\n * Decouples the storage location of mdx pages from Conloca's main content\n * tree so projects can host them wherever their renderer expects to read\n * from. The rendering pipeline is the project's own choice — Conloca only\n * owns CRUD on the file bytes.\n *\n * When omitted AND no site in sites.json has `mdxPages`, .mdx files\n * fall back to living alongside Puck pages at\n * `{contentRoot}/{site}/pages/`.\n */\n mdxPagesRoot?: string;\n\n /**\n * Default locale for mdx pages. The default locale's files live at\n * `{mdxPagesRoot}/{slug}.mdx` (no locale prefix); other locales live at\n * `{mdxPagesRoot}/{locale}/{slug}.mdx`.\n *\n * If omitted, falls back to the first site's `defaultLocale`, or `'en'`.\n */\n mdxPagesDefaultLocale?: string;\n\n /**\n * Site name to associate mdx pages with for pathname collision checking.\n * mdx pages share the URL space with that site's puck pages, so two\n * pages — regardless of type — cannot share a pathname.\n *\n * If omitted, falls back to the first site name in sites.json (or\n * `'default'` when no sites are configured).\n */\n mdxPagesSite?: string;\n\n /**\n * The site's supported locales. When provided, this wins over the\n * `globalLocales` field in sites.json. The locale-detection parsers\n * use this list to decide whether a folder or filename suffix that\n * looks locale-shaped (e.g. `de`, `en-US`) is actually a locale or\n * just a folder that happens to match the pattern.\n *\n * Omit to fall back to sites.json (current behavior).\n */\n availableLocales?: string[];\n\n /**\n * The site's default locale. Wins over both `mdxPagesDefaultLocale`\n * and the per-site `defaultLocale` in sites.json when provided.\n */\n defaultLocale?: string;\n}\n\n// Error response format for all API errors\nexport interface APIError {\n error: {\n code: string; // Machine-readable error code (e.g., 'CONTENT_NOT_FOUND', 'STALE_WRITE')\n message: string; // Human-readable error message\n details?: any; // Optional additional error details\n };\n}\n\nexport interface MDXCompileResponse {\n code: string;\n metadata: Record<string, unknown>;\n}\n\n// Common error codes\nexport const ErrorCodes = {\n // Content errors\n CONTENT_NOT_FOUND: 'CONTENT_NOT_FOUND',\n LOCALE_NOT_FOUND: 'LOCALE_NOT_FOUND',\n COLLECTION_NOT_FOUND: 'COLLECTION_NOT_FOUND',\n SITE_NOT_FOUND: 'SITE_NOT_FOUND',\n\n // Write errors\n STALE_WRITE: 'STALE_WRITE',\n ALREADY_EXISTS: 'ALREADY_EXISTS',\n PATHNAME_TAKEN: 'PATHNAME_TAKEN',\n INVALID_PATHNAME: 'INVALID_PATHNAME',\n NAME_TAKEN: 'NAME_TAKEN',\n METADATA_TOO_LARGE: 'METADATA_TOO_LARGE',\n WRITE_ERROR: 'WRITE_ERROR',\n\n // Validation errors\n MISSING_REQUIRED_FIELD: 'MISSING_REQUIRED_FIELD',\n INVALID_LOCALE: 'INVALID_LOCALE',\n INVALID_CONTENT_TYPE: 'INVALID_CONTENT_TYPE',\n INVALID_REQUEST: 'INVALID_REQUEST',\n MDX_COMPILE_FAILED: 'MDX_COMPILE_FAILED',\n\n // System errors\n INTERNAL_ERROR: 'INTERNAL_ERROR',\n FETCH_ERROR: 'FETCH_ERROR',\n\n // Git errors\n GIT_NOT_REPO: 'GIT_NOT_REPO',\n GIT_COMMIT_FAILED: 'GIT_COMMIT_FAILED',\n GIT_PUSH_FAILED: 'GIT_PUSH_FAILED',\n GIT_PULL_FAILED: 'GIT_PULL_FAILED',\n GIT_STATUS_FAILED: 'GIT_STATUS_FAILED',\n\n // Asset errors\n ASSET_NOT_FOUND: 'ASSET_NOT_FOUND',\n ASSET_INVALID_FORMAT: 'ASSET_INVALID_FORMAT',\n ASSET_TOO_LARGE: 'ASSET_TOO_LARGE',\n ASSET_UPLOAD_FAILED: 'ASSET_UPLOAD_FAILED',\n} as const;\n\nexport type ErrorCode = (typeof ErrorCodes)[keyof typeof ErrorCodes];\n\n// Content type - the format of the content\nexport type ContentType = 'puck' | 'mdx' | 'json';\n\n// Content data - the actual content (puck, mdx, or json data)\nexport interface ContentData {\n puckData?: any;\n mdx?: string;\n data?: Record<string, unknown>;\n}\n\n// Content property that extends manifests with actual content\nexport interface ContentProp {\n content: ContentData;\n}\n\n// Base identity fields shared by all content representations\nexport interface ContentIdentity {\n id: string;\n type: ContentType;\n kind: 'block' | 'page' | 'data';\n site?: string; // Only for pages\n collection: string;\n}\n\n// Locale file data derived from file path\nexport interface LocalePathData {\n locale: string;\n pathname?: string; // pages only - derived from file path\n name?: string; // blocks only - derived from filename\n}\n\n// Localized content manifest - metadata about translated content without the actual content\nexport interface LocaleVersion extends LocalePathData {\n etag: string; // Format: \"metaEtag.contentEtag\"\n created: string;\n modified: string;\n publishAt?: string;\n unpublishAt?: string;\n previousPathnames?: Record<string, string>; // pages only\n meta: ContentMeta; // title, description, seo, etc.\n}\n\n// Manifest for all locales (what's in the index and returned in listings)\nexport interface ContentManifest extends ContentIdentity {\n locales: Record<string, LocaleVersion | undefined>;\n}\n\n// Single locale without content (used for updates/changes)\nexport interface LocalizedManifest extends ContentIdentity {\n localized: LocaleVersion;\n}\n\n// Single locale with content\nexport interface LocalizedEntry extends ContentIdentity {\n localized: LocaleVersion & ContentProp;\n}\n\n// All locales with content\nexport interface ContentEntry extends ContentManifest {\n locales: Record<string, LocaleVersion & ContentProp>;\n}\n\n// Result types\nexport interface UpdateResult {\n success: boolean;\n etag?: string;\n modified?: Date;\n reason?: 'not_found' | 'stale_write' | 'write_error';\n error?: Error;\n currentEtag?: string;\n conflictDetails?: {\n metaChanged: boolean;\n contentChanged: boolean;\n currentMeta?: ContentMeta;\n currentContent?: ContentData;\n localContent?: ContentData;\n };\n}\n\nexport interface MoveResult {\n moved: boolean;\n previousPathname?: string;\n files?: string[];\n reason?: 'not_found' | 'already_exists' | 'stale_write' | 'write_error';\n error?: Error;\n etag?: string;\n}\n\nexport interface ContentListResult {\n items: ContentManifest[];\n total: number;\n hasMore?: boolean;\n}\n\n// Filter types\nexport interface GlobalFilters {\n site?: string;\n collection?: string;\n locales?: string[];\n type?: 'puck' | 'mdx' | 'json';\n published?: boolean;\n kind?: 'block' | 'page' | 'data';\n localization?: 'complete' | 'partial' | 'one';\n missingLocales?: string[];\n}\n\nexport interface SiteFilters {\n collection?: string;\n locales?: string[];\n type?: 'puck' | 'mdx';\n published?: boolean;\n}\n\nexport interface BlockFilters {\n collection?: string;\n locales?: string[];\n}\n\nexport interface FindOptions {\n excludeSites?: string[];\n includeUnpublished?: boolean;\n}\n\n// Input types\n\nexport interface CreateContentInput {\n kind: 'block' | 'page' | 'data';\n site?: string; // Required for pages, must be undefined for blocks and data\n collection: string;\n type: ContentType;\n created?: string; // Optional, will use current time if not provided\n name?: string; // Internal identifier for blocks and data (same across all locales)\n meta?: Partial<ContentMeta>; // Shared metadata defaults (applied to all locales)\n locales: {\n [locale: string]: {\n pathname?: string; // for pages (locale-specific route)\n publishAt?: string | null | false;\n unpublishAt?: string | null | false;\n meta?: Partial<ContentMeta>;\n } & ContentProp;\n };\n}\n\nexport interface CreatePageInput {\n collection: string;\n locales: {\n [locale: string]: {\n pathname: string; // Required pathname for each locale\n publishAt?: string | null | false;\n unpublishAt?: string | null | false;\n meta: ContentMeta; // Required metadata with title for each locale\n content: {\n puckData: any;\n };\n };\n };\n}\n\nexport interface CreateBlockInput {\n collection: string;\n type: 'mdx';\n name: string; // Internal identifier (same across all locales)\n meta?: Partial<ContentMeta>; // Shared metadata defaults\n locales: {\n [locale: string]: {\n publishAt?: string | null | false;\n unpublishAt?: string | null | false;\n meta?: Partial<ContentMeta>; // Locale-specific metadata overrides\n content: {\n mdx: string;\n };\n };\n };\n}\n\nexport interface UpdateLocaleInput {\n id: string;\n locale: string;\n data: LocaleUpdateData;\n etag: string;\n}\n\nexport interface LocaleUpdateData {\n pathname?: string; // for pages - update pathname\n name?: string; // for blocks - update name (filename)\n publishAt?: string | null | false;\n unpublishAt?: string | null | false;\n modified?: string; // Optional, will use current time if not provided\n meta?: Partial<ContentMeta>;\n content?: ContentData;\n}\n\nexport interface DeleteLocaleInput {\n id: string;\n locale: string;\n etag: string;\n}\n\n// Sites configuration\nexport interface SitesConfig {\n sites: {\n [siteName: string]: {\n locales: string[];\n defaultLocale: string;\n domains?: {\n [locale: string]: string;\n };\n /**\n * Optional filesystem path for this site's mdx-type pages.\n * When set, .mdx files under this path are surfaced in the CMS\n * as `kind: 'page'` + `type: 'mdx'` content owned by this site.\n *\n * Path is interpreted relative to the project root (the same\n * cwd Astro uses), not the content root, so it can live anywhere\n * the renderer expects (e.g. `./src/content/docs` for Starlight).\n *\n * When omitted, .mdx files for this site are expected to live\n * alongside Puck (`.vxjson`) pages at `{contentRoot}/{site}/pages/`\n * — the file extension determines the page type.\n */\n mdxPages?: string;\n };\n };\n globalLocales: string[];\n}\n\n// Batch operations\nexport interface BatchResult {\n operations: BatchOperationResult[];\n success: boolean; // true if all operations succeeded\n failed: number;\n updated: number; // number of successfully updated items\n}\n\n// Common metadata structure for all content types (stored in 'meta' field)\nexport interface ContentMeta {\n // Required\n title: string; // Display name for UI\n\n // Common optional fields\n description?: string;\n author?: string;\n tags?: string[];\n\n // SEO (mainly for pages)\n keywords?: string[];\n ogTitle?: string;\n ogDescription?: string;\n ogImage?: string;\n\n // Any additional fields from frontmatter/pageMeta\n [key: string]: any;\n}\n\n// File format types\n\n/**\n * VXJSON (Variant JSON) File Format\n *\n * VXJSON is a specialized JSON format that guarantees:\n * 1. The root is always an object (never an array or primitive)\n * 2. The \"content\" field always comes last in the object\n * 3. Field order is deterministic for consistent ETag calculation\n *\n * This format enables efficient streaming ETag calculation where metadata\n * can be hashed separately from content, supporting partial updates and\n * conflict resolution in CMS scenarios.\n *\n * Files using this format have the extension .vxjson\n */\nexport interface VXJSONFile {\n id: string;\n type: ContentType;\n created: string;\n modified: string;\n publishAt?: string;\n unpublishAt?: string;\n previousPathnames?: Record<string, string>;\n meta: ContentMeta;\n content: ContentData; // Always last field in VXJSON\n}\n\nexport interface MDXFrontmatter {\n id: string;\n type: 'mdx';\n created: string;\n modified: string;\n publishAt?: string;\n unpublishAt?: string;\n meta: ContentMeta;\n}\n\n// All properties are declared in each variant to make destructuring safe and predictable\nexport type WriteResult =\n | { success: true; etag: string; modified?: Date; reason?: undefined; error?: undefined; currentEtag?: undefined }\n | {\n success: false;\n etag?: undefined;\n modified?: undefined;\n reason: 'stale_write';\n error?: undefined;\n currentEtag: string;\n }\n | {\n success: false;\n etag?: undefined;\n modified?: undefined;\n reason: 'already_exists';\n error?: undefined;\n currentEtag: string;\n }\n | {\n success: false;\n etag?: undefined;\n modified?: undefined;\n reason: 'write_error';\n error: Error;\n currentEtag?: string;\n };\n\nexport interface DeleteResult {\n success: boolean;\n error?: Error;\n reason?: 'stale_write' | 'not_found' | 'delete_error';\n currentEtag?: string;\n}\n\nexport interface CreateResult {\n success: boolean;\n id?: string;\n etag?: string;\n created?: Date;\n reason?:\n | 'already_exists'\n | 'write_error'\n | 'invalid_name'\n | 'invalid_pathname'\n | 'name_taken'\n | 'pathname_taken'\n | 'pathname_in_redirects'\n | 'metadata_too_large';\n error?: Error;\n existingId?: string;\n}\n\nexport interface BatchOperationResult {\n id: string;\n locale: string;\n updated: boolean;\n error?: Error;\n etag?: string;\n}\n\n// ===== Data Context Types =====\n\n/**\n * Minimal page reference for listing/navigation in data context.\n *\n * Used in dataBindings.pages for blog listing components\n * and getStaticPaths() to enumerate available pages.\n */\nexport interface PageReference {\n /** Page identifier. */\n id: string;\n /** URL pathname. */\n pathname: string;\n /** Page title (if available without full load). */\n title?: string;\n /** Content collection. */\n collection: string;\n /** Page metadata from content. */\n meta?: Record<string, unknown>;\n /** Page timestamps for sorting and display. */\n timestamps?: {\n created?: Date;\n modified?: Date;\n };\n}\n\n/**\n * A single entry from a data collection.\n *\n * Simplified representation of collection data for use in component resolvers.\n */\nexport interface DataCollectionEntry {\n /** Unique identifier for the entry. */\n id: string;\n /** Human-readable name of the entry. */\n name: string;\n /** The entry's data content. */\n data: Record<string, unknown>;\n /** Optional metadata for the entry. */\n meta?: Record<string, unknown>;\n}\n\n/**\n * Context object passed to Puck component resolvers via metadata.\n *\n * Contains fetched collection data and contextual information\n * for data-driven component rendering.\n */\nexport interface DataContext {\n /** Collection data keyed by collection name. */\n collections: Record<string, DataCollectionEntry[]>;\n /** Pages matching the dataBindings.pages filter. */\n pages?: PageReference[];\n /** Current locale used for data fetching. */\n locale: string;\n /** Site name from routing configuration. */\n siteName: string;\n}\n\n// Internal type for locale data returned by readLocaleFile\nexport interface LocaleFileData {\n locale: string;\n etag: string;\n created: string;\n modified: string;\n publishAt?: string;\n unpublishAt?: string;\n previousPathnames?: Record<string, string>;\n meta: ContentMeta;\n content: {\n puckData?: any;\n mdx?: string;\n data?: Record<string, unknown>;\n };\n}\n"],"mappings":";AA0EA,MAAa,aAAa;CAExB,mBAAmB;CACnB,kBAAkB;CAClB,sBAAsB;CACtB,gBAAgB;CAGhB,aAAa;CACb,gBAAgB;CAChB,gBAAgB;CAChB,kBAAkB;CAClB,YAAY;CACZ,oBAAoB;CACpB,aAAa;CAGb,wBAAwB;CACxB,gBAAgB;CAChB,sBAAsB;CACtB,iBAAiB;CACjB,oBAAoB;CAGpB,gBAAgB;CAChB,aAAa;CAGb,cAAc;CACd,mBAAmB;CACnB,iBAAiB;CACjB,iBAAiB;CACjB,mBAAmB;CAGnB,iBAAiB;CACjB,sBAAsB;CACtB,iBAAiB;CACjB,qBAAqB;AACvB"}
|