@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,120 @@
|
|
|
1
|
+
import { mkdir, readFile } from 'node:fs/promises';
|
|
2
|
+
import { dirname, join } from 'node:path';
|
|
3
|
+
import sortKeys from 'sort-keys';
|
|
4
|
+
import { atomicWriteFile } from './utils/atomic-write';
|
|
5
|
+
/**
|
|
6
|
+
* Component Registry for managing linked and unlinked components
|
|
7
|
+
*
|
|
8
|
+
* Registry is stored at {canvasDir}/components/registry.json
|
|
9
|
+
* Component IDs must follow the format: vx-{uuid}
|
|
10
|
+
*/
|
|
11
|
+
export class ComponentRegistry {
|
|
12
|
+
registryPath;
|
|
13
|
+
registry = {};
|
|
14
|
+
initialized = false;
|
|
15
|
+
constructor(canvasDir) {
|
|
16
|
+
this.registryPath = join(canvasDir, 'components', 'registry.json');
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Initialize the registry by loading from disk or creating new
|
|
20
|
+
*/
|
|
21
|
+
async initialize() {
|
|
22
|
+
if (this.initialized)
|
|
23
|
+
return;
|
|
24
|
+
try {
|
|
25
|
+
const content = await readFile(this.registryPath, 'utf-8');
|
|
26
|
+
this.registry = JSON.parse(content);
|
|
27
|
+
}
|
|
28
|
+
catch (error) {
|
|
29
|
+
if (error.code === 'ENOENT') {
|
|
30
|
+
// File doesn't exist, create empty registry
|
|
31
|
+
await this.save();
|
|
32
|
+
}
|
|
33
|
+
else {
|
|
34
|
+
throw error;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
this.initialized = true;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Validate component ID format (vx-{uuid})
|
|
41
|
+
*/
|
|
42
|
+
validateComponentId(id) {
|
|
43
|
+
const uuidRegex = /^vx-[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
|
|
44
|
+
if (!uuidRegex.test(id)) {
|
|
45
|
+
throw new Error('Invalid component ID format. Expected: vx-{uuid}');
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Save registry to disk atomically
|
|
50
|
+
*/
|
|
51
|
+
async save() {
|
|
52
|
+
// Ensure directory exists
|
|
53
|
+
await mkdir(dirname(this.registryPath), { recursive: true });
|
|
54
|
+
// Sort keys for consistent output
|
|
55
|
+
const sorted = sortKeys(this.registry, { deep: true });
|
|
56
|
+
const content = JSON.stringify(sorted, null, 2);
|
|
57
|
+
await atomicWriteFile(this.registryPath, content);
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Register a new component or update existing
|
|
61
|
+
*/
|
|
62
|
+
async register(id, entry) {
|
|
63
|
+
await this.initialize();
|
|
64
|
+
this.validateComponentId(id);
|
|
65
|
+
this.registry[id] = {
|
|
66
|
+
displayName: entry.displayName,
|
|
67
|
+
path: entry.path,
|
|
68
|
+
};
|
|
69
|
+
await this.save();
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Get a component entry by ID
|
|
73
|
+
*/
|
|
74
|
+
async get(id) {
|
|
75
|
+
await this.initialize();
|
|
76
|
+
return this.registry[id] || null;
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Link a component to a path
|
|
80
|
+
*/
|
|
81
|
+
async link(id, path) {
|
|
82
|
+
await this.initialize();
|
|
83
|
+
const entry = this.registry[id];
|
|
84
|
+
if (!entry) {
|
|
85
|
+
throw new Error(`Component ${id} not found in registry`);
|
|
86
|
+
}
|
|
87
|
+
entry.path = path;
|
|
88
|
+
await this.save();
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Unlink a component (set path to null)
|
|
92
|
+
*/
|
|
93
|
+
async unlink(id) {
|
|
94
|
+
await this.initialize();
|
|
95
|
+
const entry = this.registry[id];
|
|
96
|
+
if (!entry) {
|
|
97
|
+
throw new Error(`Component ${id} not found in registry`);
|
|
98
|
+
}
|
|
99
|
+
entry.path = null;
|
|
100
|
+
await this.save();
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* List all components
|
|
104
|
+
*/
|
|
105
|
+
async list() {
|
|
106
|
+
await this.initialize();
|
|
107
|
+
return Object.entries(this.registry).map(([id, entry]) => ({
|
|
108
|
+
id,
|
|
109
|
+
...entry,
|
|
110
|
+
}));
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* Delete a component from registry
|
|
114
|
+
*/
|
|
115
|
+
async delete(id) {
|
|
116
|
+
await this.initialize();
|
|
117
|
+
delete this.registry[id];
|
|
118
|
+
await this.save();
|
|
119
|
+
}
|
|
120
|
+
}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
//#region src/asset-types.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* Browser-safe asset type definitions for @conloca/content-api
|
|
4
|
+
*
|
|
5
|
+
* These types are safe to import in browser environments.
|
|
6
|
+
* The Node.js implementation (AssetManifest class) is in asset-manifest.ts
|
|
7
|
+
*/
|
|
8
|
+
interface AssetEntry {
|
|
9
|
+
filename: string;
|
|
10
|
+
originalName: string;
|
|
11
|
+
mimeType: string;
|
|
12
|
+
size: number;
|
|
13
|
+
width?: number;
|
|
14
|
+
height?: number;
|
|
15
|
+
alt?: string;
|
|
16
|
+
uploadedAt: string;
|
|
17
|
+
uploadedBy?: string;
|
|
18
|
+
/** Folder path relative to assets root, default '/' */
|
|
19
|
+
folder?: string;
|
|
20
|
+
/** Tags for categorization/filtering */
|
|
21
|
+
tags?: string[];
|
|
22
|
+
}
|
|
23
|
+
/** Asset usage reference - tracks where an asset is used */
|
|
24
|
+
interface AssetUsage {
|
|
25
|
+
page: string;
|
|
26
|
+
field: string;
|
|
27
|
+
}
|
|
28
|
+
/** Folder listing result */
|
|
29
|
+
interface FolderListing {
|
|
30
|
+
assets: AssetEntry[];
|
|
31
|
+
folders: {
|
|
32
|
+
name: string;
|
|
33
|
+
path: string;
|
|
34
|
+
}[];
|
|
35
|
+
}
|
|
36
|
+
/** Folder tree node for hierarchical folder view */
|
|
37
|
+
interface FolderTreeNode {
|
|
38
|
+
name: string;
|
|
39
|
+
path: string;
|
|
40
|
+
assetCount: number;
|
|
41
|
+
children: FolderTreeNode[];
|
|
42
|
+
}
|
|
43
|
+
/** Metadata stored per-file in the manifest (keyed by relative path) */
|
|
44
|
+
interface ManifestEntryData {
|
|
45
|
+
alt?: string;
|
|
46
|
+
tags?: string[];
|
|
47
|
+
width?: number;
|
|
48
|
+
height?: number;
|
|
49
|
+
uploadedAt?: string;
|
|
50
|
+
uploadedBy?: string;
|
|
51
|
+
originalName?: string;
|
|
52
|
+
}
|
|
53
|
+
/** Object-keyed manifest structure for O(1) lookup by relative path */
|
|
54
|
+
interface AssetManifestData {
|
|
55
|
+
[relativePath: string]: ManifestEntryData;
|
|
56
|
+
}
|
|
57
|
+
//#endregion
|
|
58
|
+
//#region src/component-registry.types.d.ts
|
|
59
|
+
interface ComponentEntry {
|
|
60
|
+
displayName: string;
|
|
61
|
+
path: string | null;
|
|
62
|
+
}
|
|
63
|
+
interface ComponentEntryWithId extends ComponentEntry {
|
|
64
|
+
id: string;
|
|
65
|
+
}
|
|
66
|
+
interface ComponentRegistry {
|
|
67
|
+
[componentId: string]: ComponentEntry;
|
|
68
|
+
}
|
|
69
|
+
//#endregion
|
|
70
|
+
export { AssetManifestData as a, FolderTreeNode as c, AssetEntry as i, ManifestEntryData as l, ComponentEntryWithId as n, AssetUsage as o, ComponentRegistry as r, FolderListing as s, ComponentEntry as t };
|
|
71
|
+
//# sourceMappingURL=component-registry.types-C0ctF9nh.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"component-registry.types-C0ctF9nh.d.mts","names":[],"sources":["../src/asset-types.ts","../src/component-registry.types.ts"],"mappings":";;;;;;;UAOiB;EACf;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;;EAEA;;EAEA;;;UAIe;EACf;EACA;;;UAIe;EACf,QAAQ;EACR;IAAW;IAAc;;;;UAIV;EACf;EACA;EACA;EACA,UAAU;;;UAIK;EACf;EACA;EACA;EACA;EACA;EACA;EACA;;;UAIe;GACd,uBAAuB;;;;UCxDT;EACf;EACA;;UAGe,6BAA6B;EAC5C;;UAGe;GACd,sBAAsB"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export interface ComponentEntry {
|
|
2
|
+
displayName: string;
|
|
3
|
+
path: string | null;
|
|
4
|
+
}
|
|
5
|
+
export interface ComponentEntryWithId extends ComponentEntry {
|
|
6
|
+
id: string;
|
|
7
|
+
}
|
|
8
|
+
export interface ComponentRegistry {
|
|
9
|
+
[componentId: string]: ComponentEntry;
|
|
10
|
+
}
|
|
11
|
+
//# sourceMappingURL=component-registry.types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"component-registry.types.d.ts","sourceRoot":"","sources":["../src/component-registry.types.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,cAAc;IAC7B,WAAW,EAAE,MAAM,CAAC;IACpB,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;CACrB;AAED,MAAM,WAAW,oBAAqB,SAAQ,cAAc;IAC1D,EAAE,EAAE,MAAM,CAAC;CACZ;AAED,MAAM,WAAW,iBAAiB;IAChC,CAAC,WAAW,EAAE,MAAM,GAAG,cAAc,CAAC;CACvC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import type { Blocks } from './blocks';
|
|
2
|
+
import type { Data } from './data';
|
|
3
|
+
import type { Site } from './site';
|
|
4
|
+
import type { BatchResult, ContentEntry, ContentManifest, CreateContentInput, CreateResult, DeleteLocaleInput, DeleteResult, FindOptions, GlobalFilters, LocalizedEntry, SitesConfig, UpdateLocaleInput, UpdateResult } from './types';
|
|
5
|
+
/**
|
|
6
|
+
* Content API Interface
|
|
7
|
+
*
|
|
8
|
+
* Provides a unified interface for content operations across different storage backends.
|
|
9
|
+
*
|
|
10
|
+
* ## Indexing and Caching
|
|
11
|
+
*
|
|
12
|
+
* Implementations should index content at startup for performance. However, since content
|
|
13
|
+
* files can be modified externally (via git, text editors, etc.), implementations must:
|
|
14
|
+
*
|
|
15
|
+
* 1. Perform read-repair when files are invalid (e.g., VXJSON with incorrect field order)
|
|
16
|
+
* 2. Handle files that were added after the initial indexing
|
|
17
|
+
* 3. Update the index when files are repaired or discovered
|
|
18
|
+
*
|
|
19
|
+
* ## Read-Repair
|
|
20
|
+
*
|
|
21
|
+
* For file-based implementations, read-repair should:
|
|
22
|
+
* - Fix missing required fields (id, created, modified)
|
|
23
|
+
* - Ensure VXJSON files have "content" as the last field
|
|
24
|
+
* - Update the index with repaired content
|
|
25
|
+
* - Write the repaired file back to disk
|
|
26
|
+
*/
|
|
27
|
+
export interface ContentAPI {
|
|
28
|
+
/**
|
|
29
|
+
* Get content with all locales
|
|
30
|
+
* @param id - The content ID
|
|
31
|
+
* @returns The content entry with all locales, or null if not found
|
|
32
|
+
*/
|
|
33
|
+
getContent(id: string): Promise<ContentEntry | null>;
|
|
34
|
+
/**
|
|
35
|
+
* Get content for a specific locale
|
|
36
|
+
*
|
|
37
|
+
* For file-based implementations:
|
|
38
|
+
* - Should handle files added after initial indexing
|
|
39
|
+
* - Should perform read-repair if the file is invalid
|
|
40
|
+
* - Should update the index with discovered/repaired content
|
|
41
|
+
*
|
|
42
|
+
* @param id - The content ID
|
|
43
|
+
* @param locale - The locale code
|
|
44
|
+
* @returns The localized content entry, or null if not found
|
|
45
|
+
*/
|
|
46
|
+
getLocalized(id: string, locale: string): Promise<LocalizedEntry | null>;
|
|
47
|
+
createContent(data: CreateContentInput): Promise<CreateResult>;
|
|
48
|
+
updateLocalized(input: UpdateLocaleInput): Promise<UpdateResult>;
|
|
49
|
+
deleteContent(id: string, etag: string): Promise<DeleteResult>;
|
|
50
|
+
deleteLocalized(input: DeleteLocaleInput): Promise<DeleteResult>;
|
|
51
|
+
getSite(siteName: string): Site | null;
|
|
52
|
+
readonly blocks: Blocks;
|
|
53
|
+
readonly data: Data;
|
|
54
|
+
listAllContent(filters?: GlobalFilters): Generator<ContentManifest>;
|
|
55
|
+
findUntranslatedContent(targetLocale: string, options?: FindOptions): Generator<ContentManifest>;
|
|
56
|
+
readonly sitesConfig: SitesConfig;
|
|
57
|
+
batchUpdate(operations: UpdateLocaleInput[]): Promise<BatchResult>;
|
|
58
|
+
getContentAsBuffer(id: string, locale: string): Promise<{
|
|
59
|
+
buffer: Uint8Array;
|
|
60
|
+
etag: string;
|
|
61
|
+
contentType: 'application/json' | 'text/mdx';
|
|
62
|
+
} | null>;
|
|
63
|
+
}
|
|
64
|
+
//# sourceMappingURL=content-api.interface.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"content-api.interface.d.ts","sourceRoot":"","sources":["../src/content-api.interface.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AACvC,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAC;AACnC,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAC;AACnC,OAAO,KAAK,EACV,WAAW,EACX,YAAY,EACZ,eAAe,EACf,kBAAkB,EAClB,YAAY,EACZ,iBAAiB,EACjB,YAAY,EACZ,WAAW,EACX,aAAa,EACb,cAAc,EACd,WAAW,EACX,iBAAiB,EACjB,YAAY,EACb,MAAM,SAAS,CAAC;AAEjB;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,MAAM,WAAW,UAAU;IAGzB;;;;OAIG;IACH,UAAU,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,YAAY,GAAG,IAAI,CAAC,CAAC;IAErD;;;;;;;;;;;OAWG;IACH,YAAY,CAAC,EAAE,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,cAAc,GAAG,IAAI,CAAC,CAAC;IACzE,aAAa,CAAC,IAAI,EAAE,kBAAkB,GAAG,OAAO,CAAC,YAAY,CAAC,CAAC;IAC/D,eAAe,CAAC,KAAK,EAAE,iBAAiB,GAAG,OAAO,CAAC,YAAY,CAAC,CAAC;IACjE,aAAa,CAAC,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,YAAY,CAAC,CAAC;IAC/D,eAAe,CAAC,KAAK,EAAE,iBAAiB,GAAG,OAAO,CAAC,YAAY,CAAC,CAAC;IAGjE,OAAO,CAAC,QAAQ,EAAE,MAAM,GAAG,IAAI,GAAG,IAAI,CAAC;IACvC,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,IAAI,EAAE,IAAI,CAAC;IAGpB,cAAc,CAAC,OAAO,CAAC,EAAE,aAAa,GAAG,SAAS,CAAC,eAAe,CAAC,CAAC;IACpE,uBAAuB,CAAC,YAAY,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,WAAW,GAAG,SAAS,CAAC,eAAe,CAAC,CAAC;IAGjG,QAAQ,CAAC,WAAW,EAAE,WAAW,CAAC;IAGlC,WAAW,CAAC,UAAU,EAAE,iBAAiB,EAAE,GAAG,OAAO,CAAC,WAAW,CAAC,CAAC;IAGnE,kBAAkB,CAChB,EAAE,EAAE,MAAM,EACV,MAAM,EAAE,MAAM,GACb,OAAO,CAAC;QACT,MAAM,EAAE,UAAU,CAAC;QACnB,IAAI,EAAE,MAAM,CAAC;QACb,WAAW,EAAE,kBAAkB,GAAG,UAAU,CAAC;KAC9C,GAAG,IAAI,CAAC,CAAC;CACX"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import type { ContentIndex } from './content-index';
|
|
2
|
+
import type { ContentManifest, GlobalFilters, SitesConfig } from './types';
|
|
3
|
+
/**
|
|
4
|
+
* Apply filters to a single content manifest
|
|
5
|
+
* Pure function that checks if a manifest matches all provided filters
|
|
6
|
+
*/
|
|
7
|
+
export declare function applyContentFilters(manifest: ContentManifest, filters: GlobalFilters): boolean;
|
|
8
|
+
/**
|
|
9
|
+
* Filter a collection of content manifests based on localization status
|
|
10
|
+
* Returns manifests that match the specified localization criteria
|
|
11
|
+
*/
|
|
12
|
+
export declare function filterByLocalization(allManifests: ContentManifest[], filters: GlobalFilters, siteLocales: string[]): ContentManifest[];
|
|
13
|
+
/**
|
|
14
|
+
* Generator that yields manifests after applying all filters
|
|
15
|
+
*/
|
|
16
|
+
export declare function filteredContentGenerator(contentIndex: ContentIndex, filters: GlobalFilters): Generator<ContentManifest>;
|
|
17
|
+
/**
|
|
18
|
+
* Generator that yields manifests using the most efficient index path
|
|
19
|
+
*/
|
|
20
|
+
export declare function getFilteredManifestsGenerator(contentIndex: ContentIndex, filters: GlobalFilters): Generator<ContentManifest>;
|
|
21
|
+
/**
|
|
22
|
+
* Get filtered manifests using indexes where possible for performance
|
|
23
|
+
* This function leverages ContentIndex's specialized indexes to avoid full scans
|
|
24
|
+
*/
|
|
25
|
+
export declare function getFilteredManifests(contentIndex: ContentIndex, filters: GlobalFilters): ContentManifest[];
|
|
26
|
+
/**
|
|
27
|
+
* Generator that yields manifests after applying all filters
|
|
28
|
+
* This is the main entry point for filtering content using indexes efficiently
|
|
29
|
+
*/
|
|
30
|
+
export declare function filterContentWithIndexes(contentIndex: ContentIndex, filters: GlobalFilters | undefined, sitesConfig: SitesConfig): Generator<ContentManifest>;
|
|
31
|
+
//# sourceMappingURL=content-filters.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"content-filters.d.ts","sourceRoot":"","sources":["../src/content-filters.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAEpD,OAAO,KAAK,EAAE,eAAe,EAAE,aAAa,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAE3E;;;GAGG;AACH,wBAAgB,mBAAmB,CAAC,QAAQ,EAAE,eAAe,EAAE,OAAO,EAAE,aAAa,GAAG,OAAO,CA2C9F;AAED;;;GAGG;AACH,wBAAgB,oBAAoB,CAClC,YAAY,EAAE,eAAe,EAAE,EAC/B,OAAO,EAAE,aAAa,EACtB,WAAW,EAAE,MAAM,EAAE,GACpB,eAAe,EAAE,CAgDnB;AAED;;GAEG;AACH,wBAAiB,wBAAwB,CACvC,YAAY,EAAE,YAAY,EAC1B,OAAO,EAAE,aAAa,GACrB,SAAS,CAAC,eAAe,CAAC,CAM5B;AAED;;GAEG;AACH,wBAAiB,6BAA6B,CAC5C,YAAY,EAAE,YAAY,EAC1B,OAAO,EAAE,aAAa,GACrB,SAAS,CAAC,eAAe,CAAC,CAmD5B;AAED;;;GAGG;AACH,wBAAgB,oBAAoB,CAAC,YAAY,EAAE,YAAY,EAAE,OAAO,EAAE,aAAa,GAAG,eAAe,EAAE,CAE1G;AAED;;;GAGG;AACH,wBAAiB,wBAAwB,CACvC,YAAY,EAAE,YAAY,EAC1B,OAAO,EAAE,aAAa,GAAG,SAAS,EAClC,WAAW,EAAE,WAAW,GACvB,SAAS,CAAC,eAAe,CAAC,CA6E5B"}
|
|
@@ -0,0 +1,246 @@
|
|
|
1
|
+
import { localesOf } from './content-utils';
|
|
2
|
+
/**
|
|
3
|
+
* Apply filters to a single content manifest
|
|
4
|
+
* Pure function that checks if a manifest matches all provided filters
|
|
5
|
+
*/
|
|
6
|
+
export function applyContentFilters(manifest, filters) {
|
|
7
|
+
// Site filter
|
|
8
|
+
if (filters.site && manifest.site !== filters.site)
|
|
9
|
+
return false;
|
|
10
|
+
// Collection filter
|
|
11
|
+
if (filters.collection && manifest.collection !== filters.collection)
|
|
12
|
+
return false;
|
|
13
|
+
// Type filter
|
|
14
|
+
if (filters.type && manifest.type !== filters.type)
|
|
15
|
+
return false;
|
|
16
|
+
// Kind filter
|
|
17
|
+
if (filters.kind && manifest.kind !== filters.kind)
|
|
18
|
+
return false;
|
|
19
|
+
// Locales filter - check if manifest has any of the requested locales
|
|
20
|
+
if (filters.locales && filters.locales.length > 0) {
|
|
21
|
+
const hasAnyLocale = filters.locales.some((locale) => manifest.locales[locale]);
|
|
22
|
+
if (!hasAnyLocale)
|
|
23
|
+
return false;
|
|
24
|
+
}
|
|
25
|
+
// Missing locales filter - content must NOT have any of these locales
|
|
26
|
+
if (filters.missingLocales && filters.missingLocales.length > 0) {
|
|
27
|
+
const hasAnyMissingLocale = filters.missingLocales.some((locale) => manifest.locales[locale]);
|
|
28
|
+
if (hasAnyMissingLocale)
|
|
29
|
+
return false;
|
|
30
|
+
}
|
|
31
|
+
// Published status filter - check all locales
|
|
32
|
+
if (filters.published !== undefined) {
|
|
33
|
+
let hasPublishedLocale = false;
|
|
34
|
+
for (const localeVersion of localesOf(manifest)) {
|
|
35
|
+
if (!localeVersion.unpublishAt) {
|
|
36
|
+
hasPublishedLocale = true;
|
|
37
|
+
break;
|
|
38
|
+
}
|
|
39
|
+
if (new Date(localeVersion.unpublishAt) > new Date()) {
|
|
40
|
+
hasPublishedLocale = true;
|
|
41
|
+
break;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
if (filters.published !== hasPublishedLocale)
|
|
45
|
+
return false;
|
|
46
|
+
}
|
|
47
|
+
// All filters passed
|
|
48
|
+
return true;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Filter a collection of content manifests based on localization status
|
|
52
|
+
* Returns manifests that match the specified localization criteria
|
|
53
|
+
*/
|
|
54
|
+
export function filterByLocalization(allManifests, filters, siteLocales) {
|
|
55
|
+
const results = [];
|
|
56
|
+
if (!filters.localization) {
|
|
57
|
+
// No localization filter - return all manifests that match other filters
|
|
58
|
+
for (const manifest of allManifests) {
|
|
59
|
+
if (applyContentFilters(manifest, filters)) {
|
|
60
|
+
results.push(manifest);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
return results;
|
|
64
|
+
}
|
|
65
|
+
// Apply localization-specific filtering
|
|
66
|
+
switch (filters.localization) {
|
|
67
|
+
case 'one':
|
|
68
|
+
// Find content with exactly one locale
|
|
69
|
+
for (const manifest of allManifests) {
|
|
70
|
+
const localeCount = Object.keys(manifest.locales).length;
|
|
71
|
+
if (localeCount === 1 && applyContentFilters(manifest, filters)) {
|
|
72
|
+
results.push(manifest);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
break;
|
|
76
|
+
case 'complete':
|
|
77
|
+
// Find content with all expected locales
|
|
78
|
+
for (const manifest of allManifests) {
|
|
79
|
+
const hasAllLocales = siteLocales.every((loc) => manifest.locales[loc]);
|
|
80
|
+
if (hasAllLocales && applyContentFilters(manifest, filters)) {
|
|
81
|
+
results.push(manifest);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
break;
|
|
85
|
+
case 'partial':
|
|
86
|
+
// Find content with some but not all translations
|
|
87
|
+
for (const manifest of allManifests) {
|
|
88
|
+
const localeCount = Object.keys(manifest.locales).length;
|
|
89
|
+
const hasPartialLocales = localeCount > 0 && localeCount < siteLocales.length;
|
|
90
|
+
if (hasPartialLocales && applyContentFilters(manifest, filters)) {
|
|
91
|
+
results.push(manifest);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
break;
|
|
95
|
+
}
|
|
96
|
+
return results;
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* Generator that yields manifests after applying all filters
|
|
100
|
+
*/
|
|
101
|
+
export function* filteredContentGenerator(contentIndex, filters) {
|
|
102
|
+
for (const manifest of getFilteredManifestsGenerator(contentIndex, filters)) {
|
|
103
|
+
if (applyContentFilters(manifest, filters)) {
|
|
104
|
+
yield manifest;
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* Generator that yields manifests using the most efficient index path
|
|
110
|
+
*/
|
|
111
|
+
export function* getFilteredManifestsGenerator(contentIndex, filters) {
|
|
112
|
+
// Choose the most efficient index path based on available filters
|
|
113
|
+
// Most specific: site + locale + collection
|
|
114
|
+
if (filters.site && filters.locales?.length === 1 && filters.collection) {
|
|
115
|
+
for (const manifest of contentIndex.getManifestsForSiteLocale(filters.site, filters.locales[0])) {
|
|
116
|
+
if (manifest.collection === filters.collection) {
|
|
117
|
+
yield manifest;
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
return;
|
|
121
|
+
}
|
|
122
|
+
// Site + collection (use optimized method)
|
|
123
|
+
if (filters.site && filters.collection) {
|
|
124
|
+
yield* contentIndex.getManifestsForSiteCollection(filters.site, filters.collection);
|
|
125
|
+
return;
|
|
126
|
+
}
|
|
127
|
+
// Site + single locale (use optimized method)
|
|
128
|
+
if (filters.site && filters.locales?.length === 1) {
|
|
129
|
+
yield* contentIndex.getManifestsForSiteLocale(filters.site, filters.locales[0]);
|
|
130
|
+
return;
|
|
131
|
+
}
|
|
132
|
+
// Just single locale
|
|
133
|
+
if (filters.locales?.length === 1) {
|
|
134
|
+
yield* contentIndex.getManifestsForLocale(filters.locales[0]);
|
|
135
|
+
return;
|
|
136
|
+
}
|
|
137
|
+
// Just site
|
|
138
|
+
if (filters.site) {
|
|
139
|
+
yield* contentIndex.getManifestsForSite(filters.site);
|
|
140
|
+
return;
|
|
141
|
+
}
|
|
142
|
+
// Just collection
|
|
143
|
+
if (filters.collection) {
|
|
144
|
+
yield* contentIndex.getManifestsForCollection(filters.collection);
|
|
145
|
+
return;
|
|
146
|
+
}
|
|
147
|
+
// Kind filter
|
|
148
|
+
if (filters.kind) {
|
|
149
|
+
yield* contentIndex.getManifestsForKind(filters.kind);
|
|
150
|
+
return;
|
|
151
|
+
}
|
|
152
|
+
// No specific filters - yield all manifests
|
|
153
|
+
yield* contentIndex.listAllContent();
|
|
154
|
+
}
|
|
155
|
+
/**
|
|
156
|
+
* Get filtered manifests using indexes where possible for performance
|
|
157
|
+
* This function leverages ContentIndex's specialized indexes to avoid full scans
|
|
158
|
+
*/
|
|
159
|
+
export function getFilteredManifests(contentIndex, filters) {
|
|
160
|
+
return Array.from(getFilteredManifestsGenerator(contentIndex, filters));
|
|
161
|
+
}
|
|
162
|
+
/**
|
|
163
|
+
* Generator that yields manifests after applying all filters
|
|
164
|
+
* This is the main entry point for filtering content using indexes efficiently
|
|
165
|
+
*/
|
|
166
|
+
export function* filterContentWithIndexes(contentIndex, filters, sitesConfig) {
|
|
167
|
+
if (!filters) {
|
|
168
|
+
// No filters - return all content
|
|
169
|
+
yield* contentIndex.listAllContent();
|
|
170
|
+
return;
|
|
171
|
+
}
|
|
172
|
+
// Special optimization for kind + site + collection
|
|
173
|
+
if (filters.kind === 'page' && filters.site && filters.collection) {
|
|
174
|
+
// Check if the site even has this collection
|
|
175
|
+
const siteCollections = contentIndex.getCollectionsForSite(filters.site);
|
|
176
|
+
if (!siteCollections.has(filters.collection)) {
|
|
177
|
+
return; // Early exit - no pages in this collection for this site
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
else if (filters.kind === 'block' && filters.collection) {
|
|
181
|
+
// Check if blocks have this collection
|
|
182
|
+
const blockCollections = contentIndex.getBlockCollections();
|
|
183
|
+
if (!blockCollections.has(filters.collection)) {
|
|
184
|
+
return; // Early exit - no blocks in this collection
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
// Use the most efficient generator based on filters
|
|
188
|
+
let generator;
|
|
189
|
+
// Optimal filter ordering for most specific queries first
|
|
190
|
+
if (filters.kind === 'page' && filters.site && filters.collection) {
|
|
191
|
+
// Most specific for pages: site + collection
|
|
192
|
+
generator = contentIndex.getManifestsForSiteCollection(filters.site, filters.collection);
|
|
193
|
+
}
|
|
194
|
+
else if (filters.kind === 'block' && filters.collection) {
|
|
195
|
+
// Most specific for blocks: kind + collection
|
|
196
|
+
generator = contentIndex.getManifestsForCollection(filters.collection);
|
|
197
|
+
}
|
|
198
|
+
else if (filters.kind) {
|
|
199
|
+
generator = contentIndex.getManifestsForKind(filters.kind);
|
|
200
|
+
}
|
|
201
|
+
else if (filters.site && filters.collection) {
|
|
202
|
+
generator = contentIndex.getManifestsForSiteCollection(filters.site, filters.collection);
|
|
203
|
+
}
|
|
204
|
+
else if (filters.site && filters.locales?.length === 1) {
|
|
205
|
+
// Single locale optimization
|
|
206
|
+
generator = contentIndex.getManifestsForSiteLocale(filters.site, filters.locales[0]);
|
|
207
|
+
}
|
|
208
|
+
else if (filters.site) {
|
|
209
|
+
generator = contentIndex.getManifestsForSite(filters.site);
|
|
210
|
+
}
|
|
211
|
+
else if (filters.collection) {
|
|
212
|
+
generator = contentIndex.getManifestsForCollection(filters.collection);
|
|
213
|
+
}
|
|
214
|
+
else if (filters.locales?.length === 1) {
|
|
215
|
+
// Single locale optimization
|
|
216
|
+
generator = contentIndex.getManifestsForLocale(filters.locales[0]);
|
|
217
|
+
}
|
|
218
|
+
else {
|
|
219
|
+
generator = contentIndex.listAllContent();
|
|
220
|
+
}
|
|
221
|
+
// Apply additional filters
|
|
222
|
+
for (const manifest of generator) {
|
|
223
|
+
if (!applyContentFilters(manifest, filters))
|
|
224
|
+
continue;
|
|
225
|
+
// Localization filter
|
|
226
|
+
if (filters.localization) {
|
|
227
|
+
// Early exit optimization: if complete + missingLocales, no results possible
|
|
228
|
+
if (filters.localization === 'complete' && filters.missingLocales?.length) {
|
|
229
|
+
continue; // Complete means has all locales, can't be missing any
|
|
230
|
+
}
|
|
231
|
+
const siteLocales = filters.site && manifest.kind === 'page'
|
|
232
|
+
? sitesConfig.sites[filters.site]?.locales || sitesConfig.globalLocales
|
|
233
|
+
: sitesConfig.globalLocales;
|
|
234
|
+
const localeCount = Object.keys(manifest.locales).length;
|
|
235
|
+
const hasLocales = siteLocales.filter((l) => manifest.locales[l]).length;
|
|
236
|
+
const totalLocales = siteLocales.length;
|
|
237
|
+
if (filters.localization === 'complete' && hasLocales !== totalLocales)
|
|
238
|
+
continue;
|
|
239
|
+
if (filters.localization === 'partial' && (localeCount <= 1 || hasLocales === totalLocales))
|
|
240
|
+
continue;
|
|
241
|
+
if (filters.localization === 'one' && localeCount !== 1)
|
|
242
|
+
continue;
|
|
243
|
+
}
|
|
244
|
+
yield manifest;
|
|
245
|
+
}
|
|
246
|
+
}
|