@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,629 @@
|
|
|
1
|
+
import { d as mapLocales, f as mapSiteNames, o as isContentPublished, u as localesOf } from "./content-utils-fWNHTrPy.mjs";
|
|
2
|
+
//#region src/base-content-index.ts
|
|
3
|
+
/**
|
|
4
|
+
* Base class for content indexes (blocks, data)
|
|
5
|
+
* Maintains collection->name->locale lookups with V8-optimized structures
|
|
6
|
+
*/
|
|
7
|
+
var BaseContentIndex = class {
|
|
8
|
+
index = /* @__PURE__ */ new Map();
|
|
9
|
+
contentCache = /* @__PURE__ */ new Map();
|
|
10
|
+
nameIndex = /* @__PURE__ */ new Map();
|
|
11
|
+
collections = /* @__PURE__ */ new Set();
|
|
12
|
+
/**
|
|
13
|
+
* Add or update content in the index
|
|
14
|
+
* Merges manifest locales and updates content cache if provided
|
|
15
|
+
*/
|
|
16
|
+
addContent(identity, localeVersion, content) {
|
|
17
|
+
const existing = this.index.get(identity.id);
|
|
18
|
+
const locale = localeVersion.locale;
|
|
19
|
+
if (existing) {
|
|
20
|
+
const existingLocale = existing.locales[locale];
|
|
21
|
+
if (!existingLocale || existingLocale.etag !== localeVersion.etag) existing.locales[locale] = localeVersion;
|
|
22
|
+
} else {
|
|
23
|
+
const newManifest = {
|
|
24
|
+
id: identity.id,
|
|
25
|
+
type: identity.type,
|
|
26
|
+
kind: identity.kind,
|
|
27
|
+
site: identity.site,
|
|
28
|
+
collection: identity.collection,
|
|
29
|
+
locales: { [locale]: localeVersion }
|
|
30
|
+
};
|
|
31
|
+
this.index.set(identity.id, newManifest);
|
|
32
|
+
this.collections.add(identity.collection);
|
|
33
|
+
}
|
|
34
|
+
if (content !== void 0) {
|
|
35
|
+
const existingCache = this.contentCache.get(identity.id);
|
|
36
|
+
if (existingCache) existingCache[locale] = content;
|
|
37
|
+
else this.contentCache.set(identity.id, { [locale]: content });
|
|
38
|
+
}
|
|
39
|
+
const manifestToIndex = existing || this.index.get(identity.id);
|
|
40
|
+
if (localeVersion.name) {
|
|
41
|
+
if (!this.nameIndex.has(identity.collection)) this.nameIndex.set(identity.collection, /* @__PURE__ */ new Map());
|
|
42
|
+
this.nameIndex.get(identity.collection).set(localeVersion.name, manifestToIndex);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Remove a specific locale from an entry
|
|
47
|
+
*/
|
|
48
|
+
removeLocale(id, locale) {
|
|
49
|
+
const manifest = this.index.get(id);
|
|
50
|
+
if (!manifest || !manifest.locales[locale]) return;
|
|
51
|
+
manifest.locales[locale] = void 0;
|
|
52
|
+
const contentCache = this.contentCache.get(id);
|
|
53
|
+
if (contentCache) delete contentCache[locale];
|
|
54
|
+
if (Object.values(manifest.locales).filter((v) => v !== void 0).length === 0) this.removeEntry(id);
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Remove an entry from the index
|
|
58
|
+
*/
|
|
59
|
+
removeEntry(id) {
|
|
60
|
+
const manifest = this.index.get(id);
|
|
61
|
+
if (!manifest) return;
|
|
62
|
+
for (const localeVersion of localesOf(manifest)) if (localeVersion.name) {
|
|
63
|
+
const collectionMap = this.nameIndex.get(manifest.collection);
|
|
64
|
+
if (collectionMap) collectionMap.delete(localeVersion.name);
|
|
65
|
+
break;
|
|
66
|
+
}
|
|
67
|
+
this.index.delete(id);
|
|
68
|
+
this.contentCache.delete(id);
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Get cached content for a specific locale
|
|
72
|
+
*/
|
|
73
|
+
getCachedContent(id, locale) {
|
|
74
|
+
return this.contentCache.get(id)?.[locale] || null;
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Get content manifest
|
|
78
|
+
*/
|
|
79
|
+
getManifest(id) {
|
|
80
|
+
return this.index.get(id) || null;
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Find entry by name
|
|
84
|
+
*/
|
|
85
|
+
getByName(collection, name, locale) {
|
|
86
|
+
const collectionMap = this.nameIndex.get(collection);
|
|
87
|
+
if (!collectionMap) return null;
|
|
88
|
+
const manifest = collectionMap.get(name);
|
|
89
|
+
if (!manifest) return null;
|
|
90
|
+
if (locale && !manifest.locales[locale]) return null;
|
|
91
|
+
return manifest;
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Generator for all manifests
|
|
95
|
+
*/
|
|
96
|
+
*getAllManifests() {
|
|
97
|
+
for (const manifest of this.index.values()) yield manifest;
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* Generator for manifests by locale
|
|
101
|
+
*/
|
|
102
|
+
*getManifestsByLocale(locale) {
|
|
103
|
+
for (const manifest of this.index.values()) if (manifest.locales[locale]) yield manifest;
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* Generator for manifests by collection
|
|
107
|
+
*/
|
|
108
|
+
*getManifestsByCollection(collection) {
|
|
109
|
+
for (const manifest of this.index.values()) if (manifest.collection === collection) yield manifest;
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* Get the count of indexed content entries (unique IDs)
|
|
113
|
+
*/
|
|
114
|
+
get entryCount() {
|
|
115
|
+
return this.index.size;
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* Clear all indexes
|
|
119
|
+
*/
|
|
120
|
+
clear() {
|
|
121
|
+
this.index.clear();
|
|
122
|
+
this.contentCache.clear();
|
|
123
|
+
this.nameIndex.clear();
|
|
124
|
+
this.collections.clear();
|
|
125
|
+
}
|
|
126
|
+
};
|
|
127
|
+
//#endregion
|
|
128
|
+
//#region src/block-index.ts
|
|
129
|
+
/**
|
|
130
|
+
* V8-optimized index for blocks
|
|
131
|
+
* Maintains collection->name->locale lookups
|
|
132
|
+
*/
|
|
133
|
+
var BlockIndex = class extends BaseContentIndex {
|
|
134
|
+
constructor(locales) {
|
|
135
|
+
super();
|
|
136
|
+
}
|
|
137
|
+
};
|
|
138
|
+
//#endregion
|
|
139
|
+
//#region src/data-index.ts
|
|
140
|
+
/**
|
|
141
|
+
* V8-optimized index for data collections
|
|
142
|
+
* Maintains collection->name->locale lookups
|
|
143
|
+
*/
|
|
144
|
+
var DataIndex = class extends BaseContentIndex {};
|
|
145
|
+
//#endregion
|
|
146
|
+
//#region src/site-index.ts
|
|
147
|
+
/**
|
|
148
|
+
* V8-optimized index for a single site
|
|
149
|
+
* Maintains pathname lookups and collections for one site only
|
|
150
|
+
*/
|
|
151
|
+
var SiteIndex = class {
|
|
152
|
+
locales;
|
|
153
|
+
index = /* @__PURE__ */ new Map();
|
|
154
|
+
contentCache = /* @__PURE__ */ new Map();
|
|
155
|
+
pathnameIndex;
|
|
156
|
+
previousPathnameIndex;
|
|
157
|
+
collections = /* @__PURE__ */ new Set();
|
|
158
|
+
constructor(siteName, locales) {
|
|
159
|
+
this.locales = locales;
|
|
160
|
+
this.pathnameIndex = mapLocales(locales, () => /* @__PURE__ */ new Map());
|
|
161
|
+
this.previousPathnameIndex = mapLocales(locales, () => /* @__PURE__ */ new Map());
|
|
162
|
+
}
|
|
163
|
+
/**
|
|
164
|
+
* Add or update content in the index
|
|
165
|
+
* Merges manifest locales and updates content cache if provided
|
|
166
|
+
*/
|
|
167
|
+
addContent(identity, localeVersion, content) {
|
|
168
|
+
const existing = this.index.get(identity.id);
|
|
169
|
+
const locale = localeVersion.locale;
|
|
170
|
+
if (existing) {
|
|
171
|
+
const existingLocale = existing.locales[locale];
|
|
172
|
+
let oldPathname;
|
|
173
|
+
for (const [pathname, indexedManifest] of this.pathnameIndex[locale].entries()) if (indexedManifest === existing && pathname !== localeVersion.pathname) {
|
|
174
|
+
oldPathname = pathname;
|
|
175
|
+
break;
|
|
176
|
+
}
|
|
177
|
+
if (!oldPathname && existingLocale?.pathname && existingLocale.pathname !== localeVersion.pathname) oldPathname = existingLocale.pathname;
|
|
178
|
+
const hadExistingLocale = !!existingLocale;
|
|
179
|
+
let deletedOldPathname = false;
|
|
180
|
+
let addedNewPathname = false;
|
|
181
|
+
const addedPreviousPathnames = [];
|
|
182
|
+
if (!existingLocale || existingLocale.etag !== localeVersion.etag || existingLocale.modified !== localeVersion.modified || oldPathname && oldPathname !== localeVersion.pathname) try {
|
|
183
|
+
existing.locales[locale] = localeVersion;
|
|
184
|
+
if (localeVersion.pathname) {
|
|
185
|
+
if (oldPathname && oldPathname !== localeVersion.pathname) {
|
|
186
|
+
this.pathnameIndex[locale].delete(oldPathname);
|
|
187
|
+
deletedOldPathname = true;
|
|
188
|
+
if (isContentPublished(localeVersion)) {
|
|
189
|
+
this.previousPathnameIndex[locale].set(oldPathname, existing);
|
|
190
|
+
addedPreviousPathnames.push(oldPathname);
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
this.pathnameIndex[locale].set(localeVersion.pathname, existing);
|
|
194
|
+
addedNewPathname = true;
|
|
195
|
+
}
|
|
196
|
+
if (localeVersion.previousPathnames) {
|
|
197
|
+
for (const prevPath of Object.keys(localeVersion.previousPathnames)) if (!this.previousPathnameIndex[locale].has(prevPath)) {
|
|
198
|
+
this.previousPathnameIndex[locale].set(prevPath, existing);
|
|
199
|
+
addedPreviousPathnames.push(prevPath);
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
} catch (error) {
|
|
203
|
+
if (hadExistingLocale) existing.locales[locale] = existingLocale;
|
|
204
|
+
else existing.locales[locale] = void 0;
|
|
205
|
+
if (deletedOldPathname && oldPathname) this.pathnameIndex[locale].set(oldPathname, existing);
|
|
206
|
+
if (addedNewPathname && localeVersion.pathname) this.pathnameIndex[locale].delete(localeVersion.pathname);
|
|
207
|
+
for (const prevPath of addedPreviousPathnames) this.previousPathnameIndex[locale].delete(prevPath);
|
|
208
|
+
throw error;
|
|
209
|
+
}
|
|
210
|
+
} else {
|
|
211
|
+
const newManifest = {
|
|
212
|
+
id: identity.id,
|
|
213
|
+
type: identity.type,
|
|
214
|
+
kind: identity.kind,
|
|
215
|
+
site: identity.site,
|
|
216
|
+
collection: identity.collection,
|
|
217
|
+
locales: { [locale]: localeVersion }
|
|
218
|
+
};
|
|
219
|
+
this.index.set(identity.id, newManifest);
|
|
220
|
+
this.collections.add(identity.collection);
|
|
221
|
+
if (localeVersion.pathname) this.pathnameIndex[locale].set(localeVersion.pathname, newManifest);
|
|
222
|
+
if (localeVersion.previousPathnames) for (const prevPath of Object.keys(localeVersion.previousPathnames)) this.previousPathnameIndex[locale].set(prevPath, newManifest);
|
|
223
|
+
}
|
|
224
|
+
if (content !== void 0) {
|
|
225
|
+
const existingCache = this.contentCache.get(identity.id);
|
|
226
|
+
if (existingCache) existingCache[locale] = content;
|
|
227
|
+
else this.contentCache.set(identity.id, { [locale]: content });
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
/**
|
|
231
|
+
* Remove a specific locale from an entry
|
|
232
|
+
*/
|
|
233
|
+
removeLocale(id, locale) {
|
|
234
|
+
const manifest = this.index.get(id);
|
|
235
|
+
if (!manifest || !manifest.locales[locale]) return;
|
|
236
|
+
const localeVersion = manifest.locales[locale];
|
|
237
|
+
if (localeVersion.pathname) this.pathnameIndex[locale].delete(localeVersion.pathname);
|
|
238
|
+
if (localeVersion.previousPathnames) for (const prevPath of Object.keys(localeVersion.previousPathnames)) this.previousPathnameIndex[locale].delete(prevPath);
|
|
239
|
+
manifest.locales[locale] = void 0;
|
|
240
|
+
const contentCache = this.contentCache.get(id);
|
|
241
|
+
if (contentCache) delete contentCache[locale];
|
|
242
|
+
if (Object.keys(manifest.locales).length === 0) this.removeEntry(id);
|
|
243
|
+
}
|
|
244
|
+
/**
|
|
245
|
+
* Remove an entry from the index
|
|
246
|
+
*/
|
|
247
|
+
removeEntry(id) {
|
|
248
|
+
const manifest = this.index.get(id);
|
|
249
|
+
if (!manifest) return;
|
|
250
|
+
for (const localeVersion of localesOf(manifest)) {
|
|
251
|
+
const { locale } = localeVersion;
|
|
252
|
+
if (localeVersion.pathname) this.pathnameIndex[locale].delete(localeVersion.pathname);
|
|
253
|
+
if (localeVersion.previousPathnames) for (const prevPath of Object.keys(localeVersion.previousPathnames)) this.previousPathnameIndex[locale].delete(prevPath);
|
|
254
|
+
}
|
|
255
|
+
this.index.delete(id);
|
|
256
|
+
this.contentCache.delete(id);
|
|
257
|
+
}
|
|
258
|
+
/**
|
|
259
|
+
* Get cached content for a specific locale
|
|
260
|
+
*/
|
|
261
|
+
getCachedContent(id, locale) {
|
|
262
|
+
return this.contentCache.get(id)?.[locale] || null;
|
|
263
|
+
}
|
|
264
|
+
/**
|
|
265
|
+
* Get content manifest
|
|
266
|
+
*/
|
|
267
|
+
getManifest(id) {
|
|
268
|
+
return this.index.get(id) || null;
|
|
269
|
+
}
|
|
270
|
+
/**
|
|
271
|
+
* Find content by pathname
|
|
272
|
+
*/
|
|
273
|
+
getByPathname(pathname, locale) {
|
|
274
|
+
if (locale) return this.pathnameIndex[locale]?.get(pathname) || null;
|
|
275
|
+
for (const locale of this.locales) {
|
|
276
|
+
const manifest = this.pathnameIndex[locale].get(pathname);
|
|
277
|
+
if (manifest) return manifest;
|
|
278
|
+
}
|
|
279
|
+
return null;
|
|
280
|
+
}
|
|
281
|
+
/**
|
|
282
|
+
* Find content by previous pathname (for redirects)
|
|
283
|
+
*/
|
|
284
|
+
getByPreviousPathname(pathname, locale) {
|
|
285
|
+
if (locale) return this.previousPathnameIndex[locale]?.get(pathname) || null;
|
|
286
|
+
for (const locale of this.locales) {
|
|
287
|
+
const manifest = this.previousPathnameIndex[locale].get(pathname);
|
|
288
|
+
if (manifest) return manifest;
|
|
289
|
+
}
|
|
290
|
+
return null;
|
|
291
|
+
}
|
|
292
|
+
/**
|
|
293
|
+
* Generator for all manifests
|
|
294
|
+
*/
|
|
295
|
+
*getAllManifests() {
|
|
296
|
+
for (const manifest of this.index.values()) yield manifest;
|
|
297
|
+
}
|
|
298
|
+
/**
|
|
299
|
+
* Generator for manifests by locale
|
|
300
|
+
*/
|
|
301
|
+
*getManifestsByLocale(locale) {
|
|
302
|
+
for (const manifest of this.index.values()) if (manifest.locales[locale]) yield manifest;
|
|
303
|
+
}
|
|
304
|
+
/**
|
|
305
|
+
* Get the count of indexed content entries (unique IDs)
|
|
306
|
+
*/
|
|
307
|
+
get entryCount() {
|
|
308
|
+
return this.index.size;
|
|
309
|
+
}
|
|
310
|
+
/**
|
|
311
|
+
* Clear all indexes
|
|
312
|
+
*/
|
|
313
|
+
clear() {
|
|
314
|
+
this.index.clear();
|
|
315
|
+
this.contentCache.clear();
|
|
316
|
+
for (const locale of this.locales) {
|
|
317
|
+
this.pathnameIndex[locale].clear();
|
|
318
|
+
this.previousPathnameIndex[locale].clear();
|
|
319
|
+
}
|
|
320
|
+
this.collections.clear();
|
|
321
|
+
}
|
|
322
|
+
};
|
|
323
|
+
//#endregion
|
|
324
|
+
//#region src/content-index.ts
|
|
325
|
+
/**
|
|
326
|
+
* ContentIndex coordinates between per-site indexes and the block index
|
|
327
|
+
* This provides efficient filtering by routing to the appropriate specialized index
|
|
328
|
+
*/
|
|
329
|
+
const globalCache = globalThis.__CONLOCA_CONTENT_INDEX_CACHE__ || {};
|
|
330
|
+
if (!globalThis.__CONLOCA_CONTENT_INDEX_CACHE__) globalThis.__CONLOCA_CONTENT_INDEX_CACHE__ = globalCache;
|
|
331
|
+
var ContentIndex = class ContentIndex {
|
|
332
|
+
sitesConfig;
|
|
333
|
+
static get cache() {
|
|
334
|
+
return globalCache;
|
|
335
|
+
}
|
|
336
|
+
siteIndexes;
|
|
337
|
+
blockIndex;
|
|
338
|
+
dataIndex;
|
|
339
|
+
constructor(sitesConfig) {
|
|
340
|
+
this.sitesConfig = sitesConfig;
|
|
341
|
+
this.blockIndex = new BlockIndex(sitesConfig.globalLocales);
|
|
342
|
+
this.dataIndex = new DataIndex();
|
|
343
|
+
this.siteIndexes = mapSiteNames(sitesConfig, (siteName) => {
|
|
344
|
+
const siteConfig = sitesConfig.sites[siteName];
|
|
345
|
+
return new SiteIndex(siteName, siteConfig.locales);
|
|
346
|
+
});
|
|
347
|
+
}
|
|
348
|
+
/**
|
|
349
|
+
* Get cached index or create a new one
|
|
350
|
+
*/
|
|
351
|
+
static async getCachedOrCreate(contentRoot, sitesConfig) {
|
|
352
|
+
if (!ContentIndex.cache[contentRoot]) ContentIndex.cache[contentRoot] = new ContentIndex(sitesConfig);
|
|
353
|
+
return ContentIndex.cache[contentRoot];
|
|
354
|
+
}
|
|
355
|
+
/**
|
|
356
|
+
* Clear all cached indexes
|
|
357
|
+
*/
|
|
358
|
+
static clearCache() {
|
|
359
|
+
for (const key of Object.keys(globalCache)) delete globalCache[key];
|
|
360
|
+
}
|
|
361
|
+
/**
|
|
362
|
+
* Create a new index without caching - for testing
|
|
363
|
+
*/
|
|
364
|
+
static createUncached(sitesConfig) {
|
|
365
|
+
return new ContentIndex(sitesConfig);
|
|
366
|
+
}
|
|
367
|
+
/**
|
|
368
|
+
* Add or update content in the appropriate index
|
|
369
|
+
* Updates a single locale's manifest and content cache if provided
|
|
370
|
+
*/
|
|
371
|
+
addContent(identity, localeVersion, content) {
|
|
372
|
+
if ((identity.kind === "block" || identity.kind === "data") && identity.site) throw new Error(`${identity.kind} cannot have a site property`);
|
|
373
|
+
if (identity.kind === "page" && !identity.site) throw new Error("Pages must have a site property");
|
|
374
|
+
if (identity.kind === "block") this.blockIndex.addContent(identity, localeVersion, content);
|
|
375
|
+
else if (identity.kind === "data") this.dataIndex.addContent(identity, localeVersion, content);
|
|
376
|
+
else {
|
|
377
|
+
const siteIndex = this.siteIndexes[identity.site];
|
|
378
|
+
if (siteIndex) siteIndex.addContent(identity, localeVersion, content);
|
|
379
|
+
}
|
|
380
|
+
}
|
|
381
|
+
/**
|
|
382
|
+
* Remove a specific locale from content
|
|
383
|
+
*/
|
|
384
|
+
removeLocale(id, locale) {
|
|
385
|
+
const manifest = this.getManifest(id);
|
|
386
|
+
if (!manifest) return;
|
|
387
|
+
if (manifest.kind === "block") this.blockIndex.removeLocale(id, locale);
|
|
388
|
+
else if (manifest.kind === "data") this.dataIndex.removeLocale(id, locale);
|
|
389
|
+
else {
|
|
390
|
+
const siteIndex = this.siteIndexes[manifest.site];
|
|
391
|
+
if (siteIndex) siteIndex.removeLocale(id, locale);
|
|
392
|
+
}
|
|
393
|
+
}
|
|
394
|
+
/**
|
|
395
|
+
* Get cached content
|
|
396
|
+
*/
|
|
397
|
+
getCachedContent(id, locale) {
|
|
398
|
+
const manifest = this.getManifest(id);
|
|
399
|
+
if (!manifest) return null;
|
|
400
|
+
if (manifest.kind === "block") return this.blockIndex.getCachedContent(id, locale);
|
|
401
|
+
if (manifest.kind === "data") return this.dataIndex.getCachedContent(id, locale);
|
|
402
|
+
const siteIndex = this.siteIndexes[manifest.site];
|
|
403
|
+
return siteIndex ? siteIndex.getCachedContent(id, locale) : null;
|
|
404
|
+
}
|
|
405
|
+
/**
|
|
406
|
+
* Remove an entry from all indexes
|
|
407
|
+
*/
|
|
408
|
+
removeEntry(id) {
|
|
409
|
+
this.blockIndex.removeEntry(id);
|
|
410
|
+
this.dataIndex.removeEntry(id);
|
|
411
|
+
for (const site in this.siteIndexes) {
|
|
412
|
+
const siteIndex = this.siteIndexes[site];
|
|
413
|
+
if (siteIndex) siteIndex.removeEntry(id);
|
|
414
|
+
}
|
|
415
|
+
}
|
|
416
|
+
/**
|
|
417
|
+
* Get content manifest for a content ID
|
|
418
|
+
*/
|
|
419
|
+
getManifest(id) {
|
|
420
|
+
let manifest = this.blockIndex.getManifest(id);
|
|
421
|
+
if (manifest) return manifest;
|
|
422
|
+
manifest = this.dataIndex.getManifest(id);
|
|
423
|
+
if (manifest) return manifest;
|
|
424
|
+
for (const site in this.siteIndexes) {
|
|
425
|
+
const siteIndex = this.siteIndexes[site];
|
|
426
|
+
if (siteIndex) {
|
|
427
|
+
manifest = siteIndex.getManifest(id);
|
|
428
|
+
if (manifest) return manifest;
|
|
429
|
+
}
|
|
430
|
+
}
|
|
431
|
+
return null;
|
|
432
|
+
}
|
|
433
|
+
/**
|
|
434
|
+
* Get a specific locale manifest
|
|
435
|
+
*/
|
|
436
|
+
getLocaleVersion(id, locale) {
|
|
437
|
+
const manifest = this.getManifest(id);
|
|
438
|
+
if (!manifest) return null;
|
|
439
|
+
return manifest.locales[locale] || null;
|
|
440
|
+
}
|
|
441
|
+
/**
|
|
442
|
+
* Get site index
|
|
443
|
+
*/
|
|
444
|
+
getSiteIndex(site) {
|
|
445
|
+
return this.siteIndexes[site] || null;
|
|
446
|
+
}
|
|
447
|
+
/**
|
|
448
|
+
* Get block index
|
|
449
|
+
*/
|
|
450
|
+
getBlockIndex() {
|
|
451
|
+
return this.blockIndex;
|
|
452
|
+
}
|
|
453
|
+
/**
|
|
454
|
+
* Find content by pathname (delegates to site indexes)
|
|
455
|
+
*/
|
|
456
|
+
getByPathname(site, pathname, locale) {
|
|
457
|
+
const siteIndex = this.siteIndexes[site];
|
|
458
|
+
return siteIndex ? siteIndex.getByPathname(pathname, locale) : null;
|
|
459
|
+
}
|
|
460
|
+
/**
|
|
461
|
+
* Find content by previous pathname (for redirects)
|
|
462
|
+
*/
|
|
463
|
+
getByPreviousPathname(site, pathname, locale) {
|
|
464
|
+
const siteIndex = this.siteIndexes[site];
|
|
465
|
+
return siteIndex ? siteIndex.getByPreviousPathname(pathname, locale) : null;
|
|
466
|
+
}
|
|
467
|
+
/**
|
|
468
|
+
* Find block by name
|
|
469
|
+
*/
|
|
470
|
+
getBlockByName(collection, name, locale) {
|
|
471
|
+
return this.blockIndex.getByName(collection, name, locale);
|
|
472
|
+
}
|
|
473
|
+
/**
|
|
474
|
+
* Get data index
|
|
475
|
+
*/
|
|
476
|
+
getDataIndex() {
|
|
477
|
+
return this.dataIndex;
|
|
478
|
+
}
|
|
479
|
+
/**
|
|
480
|
+
* Find data entry by name
|
|
481
|
+
*/
|
|
482
|
+
getDataByName(collection, name, locale) {
|
|
483
|
+
return this.dataIndex.getByName(collection, name, locale);
|
|
484
|
+
}
|
|
485
|
+
/**
|
|
486
|
+
* Get all collections for data
|
|
487
|
+
*/
|
|
488
|
+
getDataCollections() {
|
|
489
|
+
return this.dataIndex.collections;
|
|
490
|
+
}
|
|
491
|
+
/**
|
|
492
|
+
* List all content (for iteration)
|
|
493
|
+
*/
|
|
494
|
+
*listAllContent() {
|
|
495
|
+
yield* this.blockIndex.getAllManifests();
|
|
496
|
+
yield* this.dataIndex.getAllManifests();
|
|
497
|
+
for (const site in this.siteIndexes) {
|
|
498
|
+
const siteIndex = this.siteIndexes[site];
|
|
499
|
+
if (siteIndex) yield* siteIndex.getAllManifests();
|
|
500
|
+
}
|
|
501
|
+
}
|
|
502
|
+
/**
|
|
503
|
+
* Generator for all sites
|
|
504
|
+
*/
|
|
505
|
+
*allSites() {
|
|
506
|
+
for (const site in this.siteIndexes) if (this.siteIndexes[site]) yield site;
|
|
507
|
+
}
|
|
508
|
+
/**
|
|
509
|
+
* Get all collections for a site
|
|
510
|
+
*/
|
|
511
|
+
getCollectionsForSite(site) {
|
|
512
|
+
const siteIndex = this.siteIndexes[site];
|
|
513
|
+
return siteIndex ? siteIndex.collections : /* @__PURE__ */ new Set();
|
|
514
|
+
}
|
|
515
|
+
/**
|
|
516
|
+
* Get all collections for blocks
|
|
517
|
+
*/
|
|
518
|
+
getBlockCollections() {
|
|
519
|
+
return this.blockIndex.collections;
|
|
520
|
+
}
|
|
521
|
+
/**
|
|
522
|
+
* Get default locale for a site
|
|
523
|
+
*/
|
|
524
|
+
getDefaultLocale(site) {
|
|
525
|
+
if (!site) return this.sitesConfig.globalLocales[0];
|
|
526
|
+
return this.sitesConfig.sites[site]?.defaultLocale || this.sitesConfig.globalLocales[0];
|
|
527
|
+
}
|
|
528
|
+
/**
|
|
529
|
+
* Find content missing a specific locale
|
|
530
|
+
*/
|
|
531
|
+
*findUntranslatedContent(targetLocale, options) {
|
|
532
|
+
for (const manifest of this.blockIndex.getAllManifests()) if (!manifest.locales[targetLocale]) {
|
|
533
|
+
if (!options?.includeUnpublished) {
|
|
534
|
+
let hasPublishedLocale = false;
|
|
535
|
+
for (const locale of localesOf(manifest)) if (!locale.unpublishAt || new Date(locale.unpublishAt) > /* @__PURE__ */ new Date()) {
|
|
536
|
+
hasPublishedLocale = true;
|
|
537
|
+
break;
|
|
538
|
+
}
|
|
539
|
+
if (!hasPublishedLocale) continue;
|
|
540
|
+
}
|
|
541
|
+
yield manifest;
|
|
542
|
+
}
|
|
543
|
+
for (const siteName in this.siteIndexes) {
|
|
544
|
+
const siteIndex = this.siteIndexes[siteName];
|
|
545
|
+
if (!siteIndex || options?.excludeSites?.includes(siteName)) continue;
|
|
546
|
+
for (const manifest of siteIndex.getAllManifests()) if (!manifest.locales[targetLocale]) {
|
|
547
|
+
if (!options?.includeUnpublished) {
|
|
548
|
+
let hasPublishedLocale = false;
|
|
549
|
+
for (const locale of localesOf(manifest)) if (!locale.unpublishAt || new Date(locale.unpublishAt) > /* @__PURE__ */ new Date()) {
|
|
550
|
+
hasPublishedLocale = true;
|
|
551
|
+
break;
|
|
552
|
+
}
|
|
553
|
+
if (!hasPublishedLocale) continue;
|
|
554
|
+
}
|
|
555
|
+
yield manifest;
|
|
556
|
+
}
|
|
557
|
+
}
|
|
558
|
+
}
|
|
559
|
+
/**
|
|
560
|
+
* Generators for efficient filtering
|
|
561
|
+
*/
|
|
562
|
+
*getManifestsForKind(kind) {
|
|
563
|
+
if (kind === "block") yield* this.blockIndex.getAllManifests();
|
|
564
|
+
else if (kind === "data") yield* this.dataIndex.getAllManifests();
|
|
565
|
+
else for (const site in this.siteIndexes) {
|
|
566
|
+
const siteIndex = this.siteIndexes[site];
|
|
567
|
+
if (siteIndex) yield* siteIndex.getAllManifests();
|
|
568
|
+
}
|
|
569
|
+
}
|
|
570
|
+
*getManifestsForSite(site) {
|
|
571
|
+
const siteIndex = this.siteIndexes[site];
|
|
572
|
+
if (siteIndex) yield* siteIndex.getAllManifests();
|
|
573
|
+
}
|
|
574
|
+
*getManifestsForSiteLocale(site, locale) {
|
|
575
|
+
const siteIndex = this.siteIndexes[site];
|
|
576
|
+
if (siteIndex) yield* siteIndex.getManifestsByLocale(locale);
|
|
577
|
+
}
|
|
578
|
+
*getManifestsForSiteCollection(site, collection) {
|
|
579
|
+
const siteIndex = this.siteIndexes[site];
|
|
580
|
+
if (siteIndex) {
|
|
581
|
+
for (const manifest of siteIndex.getAllManifests()) if (manifest.collection === collection) yield manifest;
|
|
582
|
+
}
|
|
583
|
+
}
|
|
584
|
+
*getManifestsForLocale(locale) {
|
|
585
|
+
yield* this.blockIndex.getManifestsByLocale(locale);
|
|
586
|
+
yield* this.dataIndex.getManifestsByLocale(locale);
|
|
587
|
+
for (const site in this.siteIndexes) {
|
|
588
|
+
const siteIndex = this.siteIndexes[site];
|
|
589
|
+
if (siteIndex) yield* siteIndex.getManifestsByLocale(locale);
|
|
590
|
+
}
|
|
591
|
+
}
|
|
592
|
+
*getManifestsForCollection(collection) {
|
|
593
|
+
yield* this.blockIndex.getManifestsByCollection(collection);
|
|
594
|
+
yield* this.dataIndex.getManifestsByCollection(collection);
|
|
595
|
+
for (const site in this.siteIndexes) {
|
|
596
|
+
const siteIndex = this.siteIndexes[site];
|
|
597
|
+
if (siteIndex) {
|
|
598
|
+
for (const manifest of siteIndex.getAllManifests()) if (manifest.collection === collection) yield manifest;
|
|
599
|
+
}
|
|
600
|
+
}
|
|
601
|
+
}
|
|
602
|
+
/**
|
|
603
|
+
* Get the count of indexed content entries
|
|
604
|
+
*/
|
|
605
|
+
get entryCount() {
|
|
606
|
+
let count = this.blockIndex.entryCount;
|
|
607
|
+
count += this.dataIndex.entryCount;
|
|
608
|
+
for (const site in this.siteIndexes) {
|
|
609
|
+
const siteIndex = this.siteIndexes[site];
|
|
610
|
+
if (siteIndex) count += siteIndex.entryCount;
|
|
611
|
+
}
|
|
612
|
+
return count;
|
|
613
|
+
}
|
|
614
|
+
/**
|
|
615
|
+
* Clear all indexes
|
|
616
|
+
*/
|
|
617
|
+
clear() {
|
|
618
|
+
this.blockIndex.clear();
|
|
619
|
+
this.dataIndex.clear();
|
|
620
|
+
for (const site in this.siteIndexes) {
|
|
621
|
+
const siteIndex = this.siteIndexes[site];
|
|
622
|
+
if (siteIndex) siteIndex.clear();
|
|
623
|
+
}
|
|
624
|
+
}
|
|
625
|
+
};
|
|
626
|
+
//#endregion
|
|
627
|
+
export { ContentIndex as t };
|
|
628
|
+
|
|
629
|
+
//# sourceMappingURL=content-index-D092_vk1.mjs.map
|