@conloca/content-api 0.1.16 → 0.2.0
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-constraints.d.ts +16 -0
- package/dist/asset-constraints.d.ts.map +1 -0
- package/dist/asset-constraints.js +29 -0
- package/dist/asset-constraints.js.map +1 -0
- package/dist/asset-metadata-store.d.ts +60 -0
- package/dist/asset-metadata-store.d.ts.map +1 -0
- package/dist/asset-metadata-store.js +335 -0
- package/dist/asset-metadata-store.js.map +1 -0
- package/dist/asset-operations.d.ts +18 -13
- package/dist/asset-operations.d.ts.map +1 -1
- package/dist/asset-operations.js +302 -254
- package/dist/asset-operations.js.map +1 -0
- package/dist/asset-types.d.ts +23 -7
- package/dist/asset-types.d.ts.map +1 -1
- package/dist/asset-types.js +8 -2
- package/dist/asset-types.js.map +1 -0
- package/dist/asset-usage.d.ts +10 -0
- package/dist/asset-usage.d.ts.map +1 -0
- package/dist/asset-usage.js +49 -0
- package/dist/asset-usage.js.map +1 -0
- package/dist/base-content-index.d.ts +8 -2
- package/dist/base-content-index.d.ts.map +1 -1
- package/dist/base-content-index.js +24 -3
- package/dist/base-content-index.js.map +1 -0
- package/dist/cf-access.js +1 -0
- package/dist/cf-access.js.map +1 -0
- package/dist/component-registry.d.ts +1 -1
- package/dist/component-registry.d.ts.map +1 -1
- package/dist/component-registry.js +2 -1
- package/dist/component-registry.js.map +1 -0
- package/dist/component-registry.types.js +1 -0
- package/dist/component-registry.types.js.map +1 -0
- package/dist/component-vocabulary.d.ts +33 -0
- package/dist/component-vocabulary.d.ts.map +1 -0
- package/dist/component-vocabulary.js +105 -0
- package/dist/component-vocabulary.js.map +1 -0
- package/dist/content-api.interface.d.ts +5 -5
- package/dist/content-api.interface.d.ts.map +1 -1
- package/dist/content-api.interface.js +1 -0
- package/dist/content-api.interface.js.map +1 -0
- package/dist/content-filters.d.ts +2 -2
- package/dist/content-filters.d.ts.map +1 -1
- package/dist/content-filters.js +9 -8
- package/dist/content-filters.js.map +1 -0
- package/dist/content-index.d.ts +74 -16
- package/dist/content-index.d.ts.map +1 -1
- package/dist/content-index.js +183 -55
- package/dist/content-index.js.map +1 -0
- package/dist/content-operations.d.ts +71 -7
- package/dist/content-operations.d.ts.map +1 -1
- package/dist/content-operations.js +166 -82
- package/dist/content-operations.js.map +1 -0
- package/dist/content-path.d.ts +59 -0
- package/dist/content-path.d.ts.map +1 -0
- package/dist/content-path.js +88 -0
- package/dist/content-path.js.map +1 -0
- package/dist/content-reader.d.ts +2 -2
- package/dist/content-reader.d.ts.map +1 -1
- package/dist/content-reader.js +2 -1
- package/dist/content-reader.js.map +1 -0
- package/dist/content-utils.d.ts +53 -10
- package/dist/content-utils.d.ts.map +1 -1
- package/dist/content-utils.js +103 -34
- package/dist/content-utils.js.map +1 -0
- package/dist/content-watcher.d.ts +3 -3
- package/dist/content-watcher.d.ts.map +1 -1
- package/dist/content-watcher.js +13 -10
- package/dist/content-watcher.js.map +1 -0
- package/dist/data-index.d.ts +1 -1
- package/dist/data-index.d.ts.map +1 -1
- package/dist/data-index.js +2 -1
- package/dist/data-index.js.map +1 -0
- package/dist/data.d.ts +5 -13
- package/dist/data.d.ts.map +1 -1
- package/dist/data.js +7 -6
- package/dist/data.js.map +1 -0
- package/dist/editor-data-bindings.d.ts +10 -0
- package/dist/editor-data-bindings.d.ts.map +1 -0
- package/dist/editor-data-bindings.js +67 -0
- package/dist/editor-data-bindings.js.map +1 -0
- package/dist/etag-utils.d.ts.map +1 -1
- package/dist/etag-utils.js +5 -4
- package/dist/etag-utils.js.map +1 -0
- package/dist/filesystem-content-api.d.ts +45 -18
- package/dist/filesystem-content-api.d.ts.map +1 -1
- package/dist/filesystem-content-api.js +407 -281
- package/dist/filesystem-content-api.js.map +1 -0
- package/dist/filesystem-reader-backend.d.ts +46 -0
- package/dist/filesystem-reader-backend.d.ts.map +1 -0
- package/dist/filesystem-reader-backend.js +119 -0
- package/dist/filesystem-reader-backend.js.map +1 -0
- package/dist/fragment-index.d.ts +8 -0
- package/dist/fragment-index.d.ts.map +1 -0
- package/dist/fragment-index.js +8 -0
- package/dist/fragment-index.js.map +1 -0
- package/dist/fragments.d.ts +16 -0
- package/dist/fragments.d.ts.map +1 -0
- package/dist/fragments.js +104 -0
- package/dist/fragments.js.map +1 -0
- package/dist/git-operations.d.ts.map +1 -1
- package/dist/git-operations.js +5 -1
- package/dist/git-operations.js.map +1 -0
- package/dist/header-parser.d.ts +4 -4
- package/dist/header-parser.d.ts.map +1 -1
- package/dist/header-parser.js +8 -61
- package/dist/header-parser.js.map +1 -0
- package/dist/in-memory-content-api.d.ts +7 -7
- package/dist/in-memory-content-api.d.ts.map +1 -1
- package/dist/in-memory-content-api.js +74 -56
- package/dist/in-memory-content-api.js.map +1 -0
- package/dist/index.d.ts +19 -12
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +21 -9
- package/dist/index.js.map +1 -0
- package/dist/indexing.d.ts +4 -4
- package/dist/indexing.d.ts.map +1 -1
- package/dist/indexing.js +6 -5
- package/dist/indexing.js.map +1 -0
- package/dist/json-whitespace-view.js +1 -0
- package/dist/json-whitespace-view.js.map +1 -0
- package/dist/middleware.d.ts +6 -6
- package/dist/middleware.d.ts.map +1 -1
- package/dist/middleware.js +170 -119
- package/dist/middleware.js.map +1 -0
- package/dist/node.d.ts +24 -17
- package/dist/node.d.ts.map +1 -1
- package/dist/node.js +17 -14
- package/dist/node.js.map +1 -0
- package/dist/page-references.d.ts +21 -0
- package/dist/page-references.d.ts.map +1 -0
- package/dist/page-references.js +50 -0
- package/dist/page-references.js.map +1 -0
- package/dist/read-date.d.ts +3 -0
- package/dist/read-date.d.ts.map +1 -0
- package/dist/read-date.js +9 -0
- package/dist/read-date.js.map +1 -0
- package/dist/reader-backend.d.ts +54 -0
- package/dist/reader-backend.d.ts.map +1 -0
- package/dist/reader-backend.js +2 -0
- package/dist/reader-backend.js.map +1 -0
- package/dist/reader.d.ts +8 -8
- package/dist/reader.d.ts.map +1 -1
- package/dist/reader.js +8 -7
- package/dist/reader.js.map +1 -0
- package/dist/schemas/index.d.ts +6 -6
- package/dist/schemas/index.d.ts.map +1 -1
- package/dist/schemas/index.js +9 -8
- package/dist/schemas/index.js.map +1 -0
- package/dist/site-index.d.ts +3 -3
- package/dist/site-index.d.ts.map +1 -1
- package/dist/site-index.js +9 -5
- package/dist/site-index.js.map +1 -0
- package/dist/site.d.ts +5 -3
- package/dist/site.d.ts.map +1 -1
- package/dist/site.js +14 -2
- package/dist/site.js.map +1 -0
- package/dist/types.d.ts +203 -15
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js +9 -0
- package/dist/types.js.map +1 -0
- package/dist/url-safe-base64.js +1 -0
- package/dist/url-safe-base64.js.map +1 -0
- package/dist/url-validation.d.ts +14 -0
- package/dist/url-validation.d.ts.map +1 -1
- package/dist/url-validation.js +56 -14
- package/dist/url-validation.js.map +1 -0
- package/dist/utils/atomic-write.js +1 -0
- package/dist/utils/atomic-write.js.map +1 -0
- package/dist/utils.d.ts +1 -1
- package/dist/utils.js +2 -1
- package/dist/utils.js.map +1 -0
- package/dist/vite-plugin.d.ts +2 -2
- package/dist/vite-plugin.js +5 -4
- package/dist/vite-plugin.js.map +1 -0
- package/dist/vxjson-serialize.d.ts +5 -6
- package/dist/vxjson-serialize.d.ts.map +1 -1
- package/dist/vxjson-serialize.js +13 -10
- package/dist/vxjson-serialize.js.map +1 -0
- package/dist/vxjson.d.ts +4 -3
- package/dist/vxjson.d.ts.map +1 -1
- package/dist/vxjson.js +10 -20
- package/dist/vxjson.js.map +1 -0
- package/dist/xxhash.d.ts.map +1 -1
- package/dist/xxhash.js +6 -2
- package/dist/xxhash.js.map +1 -0
- package/package.json +92 -56
- package/src/asset-constraints.ts +33 -0
- package/src/asset-metadata-store.ts +401 -0
- package/src/asset-operations.ts +914 -0
- package/src/asset-types.ts +74 -0
- package/src/asset-usage.ts +47 -0
- package/src/base-content-index.ts +227 -0
- package/src/cf-access.ts +85 -0
- package/src/component-registry.ts +145 -0
- package/src/component-registry.types.ts +12 -0
- package/src/component-vocabulary.ts +87 -0
- package/src/content-api.interface.ts +94 -0
- package/src/content-filters.ts +278 -0
- package/src/content-index.ts +642 -0
- package/src/content-operations.ts +497 -0
- package/src/content-path.ts +113 -0
- package/src/content-reader.ts +18 -0
- package/src/content-utils.ts +474 -0
- package/src/content-watcher.ts +122 -0
- package/src/data-index.ts +7 -0
- package/src/data.ts +134 -0
- package/src/editor-data-bindings.ts +66 -0
- package/src/etag-utils.ts +204 -0
- package/src/filesystem-content-api.ts +2685 -0
- package/src/filesystem-reader-backend.ts +135 -0
- package/src/fragment-index.ts +7 -0
- package/src/fragments.ts +113 -0
- package/src/git-operations.ts +340 -0
- package/src/header-parser.ts +272 -0
- package/src/in-memory-content-api.ts +760 -0
- package/src/index.ts +45 -0
- package/src/indexing.ts +8 -0
- package/src/json-whitespace-view.ts +155 -0
- package/src/middleware.ts +1341 -0
- package/src/node.ts +40 -0
- package/src/page-references.ts +76 -0
- package/src/read-date.ts +7 -0
- package/src/reader-backend.ts +54 -0
- package/src/reader.ts +15 -0
- package/src/schemas/index.ts +113 -0
- package/src/site-index.ts +330 -0
- package/src/site.ts +198 -0
- package/src/types.ts +759 -0
- package/src/url-safe-base64.ts +38 -0
- package/src/url-validation.ts +121 -0
- package/src/utils/atomic-write.ts +20 -0
- package/src/utils.ts +84 -0
- package/src/vite-plugin.ts +45 -0
- package/src/vxjson-serialize.ts +66 -0
- package/src/vxjson.ts +442 -0
- package/src/xxhash.ts +43 -0
- package/dist/asset-manifest.d.ts +0 -23
- package/dist/asset-manifest.d.ts.map +0 -1
- package/dist/asset-manifest.js +0 -73
- package/dist/block-index.d.ts +0 -9
- package/dist/block-index.d.ts.map +0 -1
- package/dist/block-index.js +0 -11
- package/dist/blocks.d.ts +0 -16
- package/dist/blocks.d.ts.map +0 -1
- package/dist/blocks.js +0 -103
- package/dist/component-registry.types-C0ctF9nh.d.mts +0 -71
- package/dist/component-registry.types-C0ctF9nh.d.mts.map +0 -1
- package/dist/content-index-D092_vk1.mjs +0 -629
- package/dist/content-index-D092_vk1.mjs.map +0 -1
- package/dist/content-index-D6IVMmAB.d.mts +0 -127
- package/dist/content-index-D6IVMmAB.d.mts.map +0 -1
- package/dist/content-operations-DIbsxG5A.d.mts +0 -354
- package/dist/content-operations-DIbsxG5A.d.mts.map +0 -1
- package/dist/content-utils-fWNHTrPy.mjs +0 -280
- package/dist/content-utils-fWNHTrPy.mjs.map +0 -1
- package/dist/data-DquNIEnQ.mjs +0 -62
- package/dist/data-DquNIEnQ.mjs.map +0 -1
- package/dist/filesystem-content-api-B1KIQJfk.mjs +0 -2
- package/dist/filesystem-content-api-C0HIhqZi.mjs +0 -1620
- package/dist/filesystem-content-api-C0HIhqZi.mjs.map +0 -1
- package/dist/filesystem-content-api-DCdNi-co.d.mts +0 -134
- package/dist/filesystem-content-api-DCdNi-co.d.mts.map +0 -1
- package/dist/index-DxVTFK66.d.mts +0 -105
- package/dist/index-DxVTFK66.d.mts.map +0 -1
- package/dist/index.d.mts +0 -80
- package/dist/index.d.mts.map +0 -1
- package/dist/index.mjs +0 -78
- package/dist/index.mjs.map +0 -1
- package/dist/indexing.d.mts +0 -152
- package/dist/indexing.d.mts.map +0 -1
- package/dist/indexing.mjs +0 -255
- package/dist/indexing.mjs.map +0 -1
- package/dist/node.d.mts +0 -373
- package/dist/node.d.mts.map +0 -1
- package/dist/node.mjs +0 -2572
- package/dist/node.mjs.map +0 -1
- package/dist/reader.d.mts +0 -15
- package/dist/reader.d.mts.map +0 -1
- package/dist/reader.mjs +0 -22
- package/dist/reader.mjs.map +0 -1
- package/dist/schemas/index.d.mts +0 -2
- package/dist/schemas/index.mjs +0 -2
- package/dist/schemas-CFRD0FIQ.mjs +0 -84
- package/dist/schemas-CFRD0FIQ.mjs.map +0 -1
- package/dist/site-8oaj1Q60.mjs +0 -366
- package/dist/site-8oaj1Q60.mjs.map +0 -1
- package/dist/site-index-B_254bCc.d.mts +0 -136
- package/dist/site-index-B_254bCc.d.mts.map +0 -1
- package/dist/types-DOdldbfD.mjs +0 -34
- package/dist/types-DOdldbfD.mjs.map +0 -1
- package/dist/types-DjfhS272.d.mts +0 -456
- package/dist/types-DjfhS272.d.mts.map +0 -1
- package/dist/vxjson-qHrgLGip.mjs +0 -555
- package/dist/vxjson-qHrgLGip.mjs.map +0 -1
- package/dist/vxjson-serialize-geF6qvpn.mjs +0 -34
- package/dist/vxjson-serialize-geF6qvpn.mjs.map +0 -1
- package/dist/vxjson-serialize.d.mts +0 -17
- package/dist/vxjson-serialize.d.mts.map +0 -1
- package/dist/vxjson-serialize.mjs +0 -2
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import type { Data } from './data.js';
|
|
2
|
+
import type { Fragments } from './fragments.js';
|
|
3
|
+
import type { Site } from './site.js';
|
|
4
|
+
import type {
|
|
5
|
+
BatchResult,
|
|
6
|
+
ContentEntry,
|
|
7
|
+
ContentManifest,
|
|
8
|
+
CreateContentInput,
|
|
9
|
+
CreateResult,
|
|
10
|
+
DeleteLocaleInput,
|
|
11
|
+
DeleteResult,
|
|
12
|
+
FindOptions,
|
|
13
|
+
GlobalFilters,
|
|
14
|
+
LocalizedEntry,
|
|
15
|
+
SitesConfig,
|
|
16
|
+
UpdateLocaleInput,
|
|
17
|
+
UpdateResult,
|
|
18
|
+
} from './types.js';
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Content API Interface
|
|
22
|
+
*
|
|
23
|
+
* Provides a unified interface for content operations across different storage backends.
|
|
24
|
+
*
|
|
25
|
+
* ## Indexing and Caching
|
|
26
|
+
*
|
|
27
|
+
* Implementations should index content at startup for performance. However, since content
|
|
28
|
+
* files can be modified externally (via git, text editors, etc.), implementations must:
|
|
29
|
+
*
|
|
30
|
+
* 1. Perform read-repair when files are invalid (e.g., VXJSON with incorrect field order)
|
|
31
|
+
* 2. Handle files that were added after the initial indexing
|
|
32
|
+
* 3. Update the index when files are repaired or discovered
|
|
33
|
+
*
|
|
34
|
+
* ## Read-Repair
|
|
35
|
+
*
|
|
36
|
+
* For file-based implementations, read-repair should:
|
|
37
|
+
* - Fix missing required fields (id, created, modified)
|
|
38
|
+
* - Ensure VXJSON files have "content" as the last field
|
|
39
|
+
* - Update the index with repaired content
|
|
40
|
+
* - Write the repaired file back to disk
|
|
41
|
+
*/
|
|
42
|
+
export interface ContentAPI {
|
|
43
|
+
// Core content operations
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Get content with all locales
|
|
47
|
+
* @param id - The content ID
|
|
48
|
+
* @returns The content entry with all locales, or null if not found
|
|
49
|
+
*/
|
|
50
|
+
getContent(id: string): Promise<ContentEntry | null>;
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Get content for a specific locale
|
|
54
|
+
*
|
|
55
|
+
* For file-based implementations:
|
|
56
|
+
* - Should handle files added after initial indexing
|
|
57
|
+
* - Should perform read-repair if the file is invalid
|
|
58
|
+
* - Should update the index with discovered/repaired content
|
|
59
|
+
*
|
|
60
|
+
* @param id - The content ID
|
|
61
|
+
* @param locale - The locale code
|
|
62
|
+
* @returns The localized content entry, or null if not found
|
|
63
|
+
*/
|
|
64
|
+
getLocalized(id: string, locale: string): Promise<LocalizedEntry | null>;
|
|
65
|
+
createContent(data: CreateContentInput): Promise<CreateResult>;
|
|
66
|
+
updateLocalized(input: UpdateLocaleInput): Promise<UpdateResult>;
|
|
67
|
+
deleteContent(id: string, etag: string): Promise<DeleteResult>; // Deletes all locales
|
|
68
|
+
deleteLocalized(input: DeleteLocaleInput): Promise<DeleteResult>; // Deletes single locale
|
|
69
|
+
|
|
70
|
+
// Site, fragments, and data access (getters without arguments)
|
|
71
|
+
getSite(siteName: string): Site | null; // Returns Site instance or null if not found (not for "fragments")
|
|
72
|
+
readonly fragments: Fragments; // Property for shared content fragments
|
|
73
|
+
readonly data: Data; // Property for structured data collections
|
|
74
|
+
|
|
75
|
+
// Global operations
|
|
76
|
+
listAllContent(filters?: GlobalFilters): Generator<ContentManifest>;
|
|
77
|
+
findUntranslatedContent(targetLocale: string, options?: FindOptions): Generator<ContentManifest>;
|
|
78
|
+
|
|
79
|
+
// Configuration
|
|
80
|
+
readonly sitesConfig: SitesConfig;
|
|
81
|
+
|
|
82
|
+
// Batch operations
|
|
83
|
+
batchUpdate(operations: UpdateLocaleInput[]): Promise<BatchResult>;
|
|
84
|
+
|
|
85
|
+
// Efficient streaming operations
|
|
86
|
+
getContentAsBuffer(
|
|
87
|
+
id: string,
|
|
88
|
+
locale: string,
|
|
89
|
+
): Promise<{
|
|
90
|
+
buffer: Uint8Array;
|
|
91
|
+
etag: string;
|
|
92
|
+
contentType: 'application/json' | 'text/mdx';
|
|
93
|
+
} | null>;
|
|
94
|
+
}
|
|
@@ -0,0 +1,278 @@
|
|
|
1
|
+
import type { ContentIndex } from './content-index.js';
|
|
2
|
+
import { localesOf } from './content-utils.js';
|
|
3
|
+
import type { ContentManifest, GlobalFilters, SitesConfig } from './types.js';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Apply filters to a single content manifest
|
|
7
|
+
* Pure function that checks if a manifest matches all provided filters
|
|
8
|
+
*/
|
|
9
|
+
export function applyContentFilters(manifest: ContentManifest, filters: GlobalFilters): boolean {
|
|
10
|
+
// Site filter
|
|
11
|
+
if (filters.site && manifest.site !== filters.site) return false;
|
|
12
|
+
|
|
13
|
+
// Collection filter
|
|
14
|
+
if (filters.collection && manifest.collection !== filters.collection) return false;
|
|
15
|
+
|
|
16
|
+
// Type filter
|
|
17
|
+
if (filters.type && manifest.type !== filters.type) return false;
|
|
18
|
+
|
|
19
|
+
// Kind filter
|
|
20
|
+
if (filters.kind && manifest.kind !== filters.kind) return false;
|
|
21
|
+
|
|
22
|
+
// Locales filter - check if manifest has any of the requested locales
|
|
23
|
+
if (filters.locales && filters.locales.length > 0) {
|
|
24
|
+
const hasAnyLocale = filters.locales.some((locale) => manifest.locales[locale]);
|
|
25
|
+
if (!hasAnyLocale) return false;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
// Missing locales filter - content must NOT have any of these locales
|
|
29
|
+
if (filters.missingLocales && filters.missingLocales.length > 0) {
|
|
30
|
+
const hasAnyMissingLocale = filters.missingLocales.some((locale) => manifest.locales[locale]);
|
|
31
|
+
if (hasAnyMissingLocale) return false;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
// Published status filter - check all locales
|
|
35
|
+
if (filters.published !== undefined) {
|
|
36
|
+
let hasPublishedLocale = false;
|
|
37
|
+
for (const localeVersion of localesOf(manifest)) {
|
|
38
|
+
if (!localeVersion.unpublishAt) {
|
|
39
|
+
hasPublishedLocale = true;
|
|
40
|
+
break;
|
|
41
|
+
}
|
|
42
|
+
if (new Date(localeVersion.unpublishAt) > new Date()) {
|
|
43
|
+
hasPublishedLocale = true;
|
|
44
|
+
break;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
if (filters.published !== hasPublishedLocale) return false;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
// All filters passed
|
|
51
|
+
return true;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Filter a collection of content manifests based on localization status
|
|
56
|
+
* Returns manifests that match the specified localization criteria
|
|
57
|
+
*/
|
|
58
|
+
export function filterByLocalization(
|
|
59
|
+
allManifests: ContentManifest[],
|
|
60
|
+
filters: GlobalFilters,
|
|
61
|
+
siteLocales: string[],
|
|
62
|
+
): ContentManifest[] {
|
|
63
|
+
const results: ContentManifest[] = [];
|
|
64
|
+
|
|
65
|
+
if (!filters.localization) {
|
|
66
|
+
// No localization filter - return all manifests that match other filters
|
|
67
|
+
for (const manifest of allManifests) {
|
|
68
|
+
if (applyContentFilters(manifest, filters)) {
|
|
69
|
+
results.push(manifest);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
return results;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
// Apply localization-specific filtering
|
|
76
|
+
switch (filters.localization) {
|
|
77
|
+
case 'one':
|
|
78
|
+
// Find content with exactly one locale
|
|
79
|
+
for (const manifest of allManifests) {
|
|
80
|
+
const localeCount = Object.keys(manifest.locales).length;
|
|
81
|
+
if (localeCount === 1 && applyContentFilters(manifest, filters)) {
|
|
82
|
+
results.push(manifest);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
break;
|
|
86
|
+
|
|
87
|
+
case 'complete':
|
|
88
|
+
// Find content with all expected locales
|
|
89
|
+
for (const manifest of allManifests) {
|
|
90
|
+
const hasAllLocales = siteLocales.every((loc) => manifest.locales[loc]);
|
|
91
|
+
if (hasAllLocales && applyContentFilters(manifest, filters)) {
|
|
92
|
+
results.push(manifest);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
break;
|
|
96
|
+
|
|
97
|
+
case 'partial':
|
|
98
|
+
// Find content with some but not all translations
|
|
99
|
+
for (const manifest of allManifests) {
|
|
100
|
+
const localeCount = Object.keys(manifest.locales).length;
|
|
101
|
+
const hasPartialLocales = localeCount > 0 && localeCount < siteLocales.length;
|
|
102
|
+
if (hasPartialLocales && applyContentFilters(manifest, filters)) {
|
|
103
|
+
results.push(manifest);
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
break;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
return results;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
/**
|
|
113
|
+
* Generator that yields manifests after applying all filters
|
|
114
|
+
*/
|
|
115
|
+
export function* filteredContentGenerator(
|
|
116
|
+
contentIndex: ContentIndex,
|
|
117
|
+
filters: GlobalFilters,
|
|
118
|
+
): Generator<ContentManifest> {
|
|
119
|
+
for (const manifest of getFilteredManifestsGenerator(contentIndex, filters)) {
|
|
120
|
+
if (applyContentFilters(manifest, filters)) {
|
|
121
|
+
yield manifest;
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
/**
|
|
127
|
+
* Generator that yields manifests using the most efficient index path
|
|
128
|
+
*/
|
|
129
|
+
export function* getFilteredManifestsGenerator(
|
|
130
|
+
contentIndex: ContentIndex,
|
|
131
|
+
filters: GlobalFilters,
|
|
132
|
+
): Generator<ContentManifest> {
|
|
133
|
+
// Choose the most efficient index path based on available filters
|
|
134
|
+
|
|
135
|
+
// Most specific: site + locale + collection
|
|
136
|
+
if (filters.site && filters.locales?.length === 1 && filters.collection) {
|
|
137
|
+
for (const manifest of contentIndex.getManifestsForSiteLocale(filters.site, filters.locales[0])) {
|
|
138
|
+
if (manifest.collection === filters.collection) {
|
|
139
|
+
yield manifest;
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
return;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
// Site + collection (use optimized method)
|
|
146
|
+
if (filters.site && filters.collection) {
|
|
147
|
+
yield* contentIndex.getManifestsForSiteCollection(filters.site, filters.collection);
|
|
148
|
+
return;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
// Site + single locale (use optimized method)
|
|
152
|
+
if (filters.site && filters.locales?.length === 1) {
|
|
153
|
+
yield* contentIndex.getManifestsForSiteLocale(filters.site, filters.locales[0]);
|
|
154
|
+
return;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
// Just single locale
|
|
158
|
+
if (filters.locales?.length === 1) {
|
|
159
|
+
yield* contentIndex.getManifestsForLocale(filters.locales[0]);
|
|
160
|
+
return;
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
// Just site
|
|
164
|
+
if (filters.site) {
|
|
165
|
+
yield* contentIndex.getManifestsForSite(filters.site);
|
|
166
|
+
return;
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
// Just collection
|
|
170
|
+
if (filters.collection) {
|
|
171
|
+
yield* contentIndex.getManifestsForCollection(filters.collection);
|
|
172
|
+
return;
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
// Kind filter
|
|
176
|
+
if (filters.kind) {
|
|
177
|
+
yield* contentIndex.getManifestsForKind(filters.kind);
|
|
178
|
+
return;
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
// No specific filters - yield all manifests
|
|
182
|
+
yield* contentIndex.listAllContent();
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
/**
|
|
186
|
+
* Get filtered manifests using indexes where possible for performance
|
|
187
|
+
* This function leverages ContentIndex's specialized indexes to avoid full scans
|
|
188
|
+
*/
|
|
189
|
+
export function getFilteredManifests(contentIndex: ContentIndex, filters: GlobalFilters): ContentManifest[] {
|
|
190
|
+
return Array.from(getFilteredManifestsGenerator(contentIndex, filters));
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
/**
|
|
194
|
+
* Generator that yields manifests after applying all filters
|
|
195
|
+
* This is the main entry point for filtering content using indexes efficiently
|
|
196
|
+
*/
|
|
197
|
+
export function* filterContentWithIndexes(
|
|
198
|
+
contentIndex: ContentIndex,
|
|
199
|
+
filters: GlobalFilters | undefined,
|
|
200
|
+
sitesConfig: SitesConfig,
|
|
201
|
+
): Generator<ContentManifest> {
|
|
202
|
+
if (!filters) {
|
|
203
|
+
// No filters - return all content
|
|
204
|
+
yield* contentIndex.listAllContent();
|
|
205
|
+
return;
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
// Special optimization for kind + site + collection
|
|
209
|
+
if (filters.kind === 'page' && filters.site && filters.collection) {
|
|
210
|
+
// Check if the site even has this collection
|
|
211
|
+
const siteCollections = contentIndex.getCollectionsForSite(filters.site);
|
|
212
|
+
if (!siteCollections.has(filters.collection)) {
|
|
213
|
+
return; // Early exit - no pages in this collection for this site
|
|
214
|
+
}
|
|
215
|
+
} else if (filters.kind === 'fragment' && filters.collection) {
|
|
216
|
+
// Check if fragments have this collection
|
|
217
|
+
const fragmentCollections = contentIndex.getFragmentCollections();
|
|
218
|
+
if (!fragmentCollections.has(filters.collection)) {
|
|
219
|
+
return; // Early exit - no fragments in this collection
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
// Use the most efficient generator based on filters
|
|
224
|
+
let generator: Generator<ContentManifest>;
|
|
225
|
+
|
|
226
|
+
// Optimal filter ordering for most specific queries first
|
|
227
|
+
if (filters.kind === 'page' && filters.site && filters.collection) {
|
|
228
|
+
// Most specific for pages: site + collection
|
|
229
|
+
generator = contentIndex.getManifestsForSiteCollection(filters.site, filters.collection);
|
|
230
|
+
} else if (filters.kind === 'fragment' && filters.collection) {
|
|
231
|
+
// Most specific for fragments: kind + collection
|
|
232
|
+
generator = contentIndex.getManifestsForCollection(filters.collection);
|
|
233
|
+
} else if (filters.kind) {
|
|
234
|
+
generator = contentIndex.getManifestsForKind(filters.kind);
|
|
235
|
+
} else if (filters.site && filters.collection) {
|
|
236
|
+
generator = contentIndex.getManifestsForSiteCollection(filters.site, filters.collection);
|
|
237
|
+
} else if (filters.site && filters.locales?.length === 1) {
|
|
238
|
+
// Single locale optimization
|
|
239
|
+
generator = contentIndex.getManifestsForSiteLocale(filters.site, filters.locales[0]);
|
|
240
|
+
} else if (filters.site) {
|
|
241
|
+
generator = contentIndex.getManifestsForSite(filters.site);
|
|
242
|
+
} else if (filters.collection) {
|
|
243
|
+
generator = contentIndex.getManifestsForCollection(filters.collection);
|
|
244
|
+
} else if (filters.locales?.length === 1) {
|
|
245
|
+
// Single locale optimization
|
|
246
|
+
generator = contentIndex.getManifestsForLocale(filters.locales[0]);
|
|
247
|
+
} else {
|
|
248
|
+
generator = contentIndex.listAllContent();
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
// Apply additional filters
|
|
252
|
+
for (const manifest of generator) {
|
|
253
|
+
if (!applyContentFilters(manifest, filters)) continue;
|
|
254
|
+
|
|
255
|
+
// Localization filter
|
|
256
|
+
if (filters.localization) {
|
|
257
|
+
// Early exit optimization: if complete + missingLocales, no results possible
|
|
258
|
+
if (filters.localization === 'complete' && filters.missingLocales?.length) {
|
|
259
|
+
continue; // Complete means has all locales, can't be missing any
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
const siteLocales =
|
|
263
|
+
filters.site && manifest.kind === 'page'
|
|
264
|
+
? sitesConfig.sites[filters.site]?.locales || sitesConfig.globalLocales
|
|
265
|
+
: sitesConfig.globalLocales;
|
|
266
|
+
|
|
267
|
+
const localeCount = Object.keys(manifest.locales).length;
|
|
268
|
+
const hasLocales = siteLocales.filter((l) => manifest.locales[l]).length;
|
|
269
|
+
const totalLocales = siteLocales.length;
|
|
270
|
+
|
|
271
|
+
if (filters.localization === 'complete' && hasLocales !== totalLocales) continue;
|
|
272
|
+
if (filters.localization === 'partial' && (localeCount <= 1 || hasLocales === totalLocales)) continue;
|
|
273
|
+
if (filters.localization === 'one' && localeCount !== 1) continue;
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
yield manifest;
|
|
277
|
+
}
|
|
278
|
+
}
|