@conloca/content-api 0.1.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.
@@ -0,0 +1,861 @@
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/types.d.ts
59
+ interface ContentAPIOptions {
60
+ contentRoot: string;
61
+ canvasDir?: string;
62
+ }
63
+ interface APIError {
64
+ error: {
65
+ code: string;
66
+ message: string;
67
+ details?: any;
68
+ };
69
+ }
70
+ declare const ErrorCodes: {
71
+ readonly CONTENT_NOT_FOUND: "CONTENT_NOT_FOUND";
72
+ readonly LOCALE_NOT_FOUND: "LOCALE_NOT_FOUND";
73
+ readonly COLLECTION_NOT_FOUND: "COLLECTION_NOT_FOUND";
74
+ readonly SITE_NOT_FOUND: "SITE_NOT_FOUND";
75
+ readonly STALE_WRITE: "STALE_WRITE";
76
+ readonly ALREADY_EXISTS: "ALREADY_EXISTS";
77
+ readonly PATHNAME_TAKEN: "PATHNAME_TAKEN";
78
+ readonly NAME_TAKEN: "NAME_TAKEN";
79
+ readonly METADATA_TOO_LARGE: "METADATA_TOO_LARGE";
80
+ readonly WRITE_ERROR: "WRITE_ERROR";
81
+ readonly MISSING_REQUIRED_FIELD: "MISSING_REQUIRED_FIELD";
82
+ readonly INVALID_LOCALE: "INVALID_LOCALE";
83
+ readonly INVALID_CONTENT_TYPE: "INVALID_CONTENT_TYPE";
84
+ readonly INVALID_REQUEST: "INVALID_REQUEST";
85
+ readonly INTERNAL_ERROR: "INTERNAL_ERROR";
86
+ readonly FETCH_ERROR: "FETCH_ERROR";
87
+ readonly GIT_NOT_REPO: "GIT_NOT_REPO";
88
+ readonly GIT_COMMIT_FAILED: "GIT_COMMIT_FAILED";
89
+ readonly GIT_PUSH_FAILED: "GIT_PUSH_FAILED";
90
+ readonly GIT_STATUS_FAILED: "GIT_STATUS_FAILED";
91
+ readonly ASSET_NOT_FOUND: "ASSET_NOT_FOUND";
92
+ readonly ASSET_INVALID_FORMAT: "ASSET_INVALID_FORMAT";
93
+ readonly ASSET_TOO_LARGE: "ASSET_TOO_LARGE";
94
+ readonly ASSET_UPLOAD_FAILED: "ASSET_UPLOAD_FAILED";
95
+ };
96
+ type ErrorCode = (typeof ErrorCodes)[keyof typeof ErrorCodes];
97
+ type ContentType = 'puck' | 'mdx' | 'json';
98
+ interface ContentData {
99
+ puckData?: any;
100
+ mdx?: string;
101
+ data?: Record<string, unknown>;
102
+ }
103
+ interface ContentProp {
104
+ content: ContentData;
105
+ }
106
+ interface ContentIdentity {
107
+ id: string;
108
+ type: ContentType;
109
+ kind: 'block' | 'page' | 'data';
110
+ site?: string;
111
+ collection: string;
112
+ }
113
+ interface LocalePathData {
114
+ locale: string;
115
+ pathname?: string;
116
+ name?: string;
117
+ }
118
+ interface LocaleVersion extends LocalePathData {
119
+ etag: string;
120
+ created: string;
121
+ modified: string;
122
+ publishAt?: string;
123
+ unpublishAt?: string;
124
+ previousPathnames?: Record<string, string>;
125
+ meta: ContentMeta;
126
+ }
127
+ interface ContentManifest extends ContentIdentity {
128
+ locales: Record<string, LocaleVersion | undefined>;
129
+ }
130
+ interface LocalizedManifest extends ContentIdentity {
131
+ localized: LocaleVersion;
132
+ }
133
+ interface LocalizedEntry extends ContentIdentity {
134
+ localized: LocaleVersion & ContentProp;
135
+ }
136
+ interface ContentEntry extends ContentManifest {
137
+ locales: Record<string, LocaleVersion & ContentProp>;
138
+ }
139
+ interface UpdateResult {
140
+ success: boolean;
141
+ etag?: string;
142
+ modified?: Date;
143
+ reason?: 'not_found' | 'stale_write' | 'write_error';
144
+ error?: Error;
145
+ currentEtag?: string;
146
+ conflictDetails?: {
147
+ metaChanged: boolean;
148
+ contentChanged: boolean;
149
+ currentMeta?: ContentMeta;
150
+ currentContent?: ContentData;
151
+ localContent?: ContentData;
152
+ };
153
+ }
154
+ interface MoveResult {
155
+ moved: boolean;
156
+ previousPathname?: string;
157
+ files?: string[];
158
+ reason?: 'not_found' | 'already_exists' | 'stale_write' | 'write_error';
159
+ error?: Error;
160
+ etag?: string;
161
+ }
162
+ interface ContentListResult {
163
+ items: ContentManifest[];
164
+ total: number;
165
+ hasMore?: boolean;
166
+ }
167
+ interface GlobalFilters {
168
+ site?: string;
169
+ collection?: string;
170
+ locales?: string[];
171
+ type?: 'puck' | 'mdx' | 'json';
172
+ published?: boolean;
173
+ kind?: 'block' | 'page' | 'data';
174
+ localization?: 'complete' | 'partial' | 'one';
175
+ missingLocales?: string[];
176
+ }
177
+ interface SiteFilters {
178
+ collection?: string;
179
+ locales?: string[];
180
+ type?: 'puck' | 'mdx';
181
+ published?: boolean;
182
+ }
183
+ interface BlockFilters {
184
+ collection?: string;
185
+ locales?: string[];
186
+ }
187
+ interface FindOptions {
188
+ excludeSites?: string[];
189
+ includeUnpublished?: boolean;
190
+ }
191
+ interface CreateContentInput {
192
+ kind: 'block' | 'page' | 'data';
193
+ site?: string;
194
+ collection: string;
195
+ type: ContentType;
196
+ created?: string;
197
+ name?: string;
198
+ meta?: Partial<ContentMeta>;
199
+ locales: {
200
+ [locale: string]: {
201
+ pathname?: string;
202
+ publishAt?: string | null | false;
203
+ unpublishAt?: string | null | false;
204
+ meta?: Partial<ContentMeta>;
205
+ } & ContentProp;
206
+ };
207
+ }
208
+ interface CreatePageInput {
209
+ collection: string;
210
+ locales: {
211
+ [locale: string]: {
212
+ pathname: string;
213
+ publishAt?: string | null | false;
214
+ unpublishAt?: string | null | false;
215
+ meta: ContentMeta;
216
+ content: {
217
+ puckData: any;
218
+ };
219
+ };
220
+ };
221
+ }
222
+ interface CreateBlockInput {
223
+ collection: string;
224
+ type: 'mdx';
225
+ name: string;
226
+ meta?: Partial<ContentMeta>;
227
+ locales: {
228
+ [locale: string]: {
229
+ publishAt?: string | null | false;
230
+ unpublishAt?: string | null | false;
231
+ meta?: Partial<ContentMeta>;
232
+ content: {
233
+ mdx: string;
234
+ };
235
+ };
236
+ };
237
+ }
238
+ interface UpdateLocaleInput {
239
+ id: string;
240
+ locale: string;
241
+ data: LocaleUpdateData;
242
+ etag: string;
243
+ }
244
+ interface LocaleUpdateData {
245
+ pathname?: string;
246
+ name?: string;
247
+ publishAt?: string | null | false;
248
+ unpublishAt?: string | null | false;
249
+ modified?: string;
250
+ meta?: Partial<ContentMeta>;
251
+ content?: ContentData;
252
+ }
253
+ interface DeleteLocaleInput {
254
+ id: string;
255
+ locale: string;
256
+ etag: string;
257
+ }
258
+ interface SitesConfig {
259
+ sites: {
260
+ [siteName: string]: {
261
+ locales: string[];
262
+ defaultLocale: string;
263
+ domains?: {
264
+ [locale: string]: string;
265
+ };
266
+ };
267
+ };
268
+ globalLocales: string[];
269
+ }
270
+ interface BatchResult {
271
+ operations: BatchOperationResult[];
272
+ success: boolean;
273
+ failed: number;
274
+ updated: number;
275
+ }
276
+ interface ContentMeta {
277
+ title: string;
278
+ description?: string;
279
+ author?: string;
280
+ tags?: string[];
281
+ keywords?: string[];
282
+ ogTitle?: string;
283
+ ogDescription?: string;
284
+ ogImage?: string;
285
+ [key: string]: any;
286
+ }
287
+ /**
288
+ * VXJSON (Variant JSON) File Format
289
+ *
290
+ * VXJSON is a specialized JSON format that guarantees:
291
+ * 1. The root is always an object (never an array or primitive)
292
+ * 2. The "content" field always comes last in the object
293
+ * 3. Field order is deterministic for consistent ETag calculation
294
+ *
295
+ * This format enables efficient streaming ETag calculation where metadata
296
+ * can be hashed separately from content, supporting partial updates and
297
+ * conflict resolution in CMS scenarios.
298
+ *
299
+ * Files using this format have the extension .vxjson
300
+ */
301
+ interface VXJSONFile {
302
+ id: string;
303
+ type: ContentType;
304
+ created: string;
305
+ modified: string;
306
+ publishAt?: string;
307
+ unpublishAt?: string;
308
+ previousPathnames?: Record<string, string>;
309
+ meta: ContentMeta;
310
+ content: ContentData;
311
+ }
312
+ interface MDXFrontmatter {
313
+ id: string;
314
+ type: 'mdx';
315
+ created: string;
316
+ modified: string;
317
+ publishAt?: string;
318
+ unpublishAt?: string;
319
+ meta: ContentMeta;
320
+ }
321
+ type WriteResult = {
322
+ success: true;
323
+ etag: string;
324
+ modified?: Date;
325
+ reason?: undefined;
326
+ error?: undefined;
327
+ currentEtag?: undefined;
328
+ } | {
329
+ success: false;
330
+ etag?: undefined;
331
+ modified?: undefined;
332
+ reason: 'stale_write';
333
+ error?: undefined;
334
+ currentEtag: string;
335
+ } | {
336
+ success: false;
337
+ etag?: undefined;
338
+ modified?: undefined;
339
+ reason: 'already_exists';
340
+ error?: undefined;
341
+ currentEtag: string;
342
+ } | {
343
+ success: false;
344
+ etag?: undefined;
345
+ modified?: undefined;
346
+ reason: 'write_error';
347
+ error: Error;
348
+ currentEtag?: string;
349
+ };
350
+ interface DeleteResult {
351
+ success: boolean;
352
+ error?: Error;
353
+ reason?: 'stale_write' | 'not_found' | 'delete_error';
354
+ currentEtag?: string;
355
+ }
356
+ interface CreateResult {
357
+ success: boolean;
358
+ id?: string;
359
+ etag?: string;
360
+ created?: Date;
361
+ reason?: 'already_exists' | 'write_error' | 'invalid_name' | 'name_taken' | 'pathname_taken' | 'pathname_in_redirects' | 'metadata_too_large';
362
+ error?: Error;
363
+ existingId?: string;
364
+ }
365
+ interface BatchOperationResult {
366
+ id: string;
367
+ locale: string;
368
+ updated: boolean;
369
+ error?: Error;
370
+ etag?: string;
371
+ }
372
+ interface LocaleFileData {
373
+ locale: string;
374
+ etag: string;
375
+ created: string;
376
+ modified: string;
377
+ publishAt?: string;
378
+ unpublishAt?: string;
379
+ previousPathnames?: Record<string, string>;
380
+ meta: ContentMeta;
381
+ content: {
382
+ puckData?: any;
383
+ mdx?: string;
384
+ data?: Record<string, unknown>;
385
+ };
386
+ }
387
+ //#endregion
388
+ //#region src/base-content-index.d.ts
389
+ /**
390
+ * Base class for content indexes (blocks, data)
391
+ * Maintains collection->name->locale lookups with V8-optimized structures
392
+ */
393
+ declare class BaseContentIndex {
394
+ protected index: Map<string, ContentManifest>;
395
+ protected contentCache: Map<string, Record<string, ContentData | null>>;
396
+ protected nameIndex: Map<string, Map<string, ContentManifest>>;
397
+ readonly collections: Set<string>;
398
+ /**
399
+ * Add or update content in the index
400
+ * Merges manifest locales and updates content cache if provided
401
+ */
402
+ addContent(identity: ContentIdentity, localeVersion: LocaleVersion, content?: ContentData | null): void;
403
+ /**
404
+ * Remove a specific locale from an entry
405
+ */
406
+ removeLocale(id: string, locale: string): void;
407
+ /**
408
+ * Remove an entry from the index
409
+ */
410
+ removeEntry(id: string): void;
411
+ /**
412
+ * Get cached content for a specific locale
413
+ */
414
+ getCachedContent(id: string, locale: string): ContentData | null;
415
+ /**
416
+ * Get content manifest
417
+ */
418
+ getManifest(id: string): ContentManifest | null;
419
+ /**
420
+ * Find entry by name
421
+ */
422
+ getByName(collection: string, name: string, locale?: string): ContentManifest | null;
423
+ /**
424
+ * Generator for all manifests
425
+ */
426
+ getAllManifests(): Generator<ContentManifest>;
427
+ /**
428
+ * Generator for manifests by locale
429
+ */
430
+ getManifestsByLocale(locale: string): Generator<ContentManifest>;
431
+ /**
432
+ * Generator for manifests by collection
433
+ */
434
+ getManifestsByCollection(collection: string): Generator<ContentManifest>;
435
+ /**
436
+ * Get the count of indexed content entries (unique IDs)
437
+ */
438
+ get entryCount(): number;
439
+ /**
440
+ * Clear all indexes
441
+ */
442
+ clear(): void;
443
+ }
444
+ //#endregion
445
+ //#region src/block-index.d.ts
446
+ /**
447
+ * V8-optimized index for blocks
448
+ * Maintains collection->name->locale lookups
449
+ */
450
+ declare class BlockIndex extends BaseContentIndex {
451
+ constructor(locales: string[]);
452
+ }
453
+ //#endregion
454
+ //#region src/data-index.d.ts
455
+ /**
456
+ * V8-optimized index for data collections
457
+ * Maintains collection->name->locale lookups
458
+ */
459
+ declare class DataIndex extends BaseContentIndex {}
460
+ //#endregion
461
+ //#region src/data.d.ts
462
+ interface DataFilters {
463
+ collection?: string;
464
+ locales?: string[];
465
+ }
466
+ interface CreateDataInput {
467
+ collection: string;
468
+ name: string;
469
+ meta?: {
470
+ title?: string;
471
+ description?: string;
472
+ [key: string]: unknown;
473
+ };
474
+ locales: {
475
+ [locale: string]: {
476
+ publishAt?: string | null | false;
477
+ unpublishAt?: string | null | false;
478
+ meta?: {
479
+ title?: string;
480
+ description?: string;
481
+ [key: string]: unknown;
482
+ };
483
+ content: {
484
+ data: Record<string, unknown>;
485
+ };
486
+ };
487
+ };
488
+ }
489
+ declare class Data {
490
+ private api;
491
+ private dataIndex;
492
+ constructor(api: ContentAPI, dataIndex: DataIndex);
493
+ listContent(filters?: DataFilters): Generator<ContentManifest>;
494
+ get collections(): Set<string>;
495
+ getByName(collection: string, name: string, locale?: string): ContentManifest | null;
496
+ isNameAvailable(collection: string, name: string, excludeId?: string): boolean;
497
+ getNameConflict(collection: string, name: string, excludeId?: string): string | null;
498
+ isDataNameValid(dataName: string): boolean;
499
+ create(input: CreateDataInput): Promise<CreateResult>;
500
+ }
501
+ //#endregion
502
+ //#region src/site-index.d.ts
503
+ /**
504
+ * V8-optimized index for a single site
505
+ * Maintains pathname lookups and collections for one site only
506
+ */
507
+ declare class SiteIndex {
508
+ private locales;
509
+ private index;
510
+ private contentCache;
511
+ private pathnameIndex;
512
+ private previousPathnameIndex;
513
+ readonly collections: Set<string>;
514
+ constructor(siteName: string, locales: string[]);
515
+ /**
516
+ * Add or update content in the index
517
+ * Merges manifest locales and updates content cache if provided
518
+ */
519
+ addContent(identity: ContentIdentity, localeVersion: LocaleVersion, content?: ContentData | null): void;
520
+ /**
521
+ * Remove a specific locale from an entry
522
+ */
523
+ removeLocale(id: string, locale: string): void;
524
+ /**
525
+ * Remove an entry from the index
526
+ */
527
+ removeEntry(id: string): void;
528
+ /**
529
+ * Get cached content for a specific locale
530
+ */
531
+ getCachedContent(id: string, locale: string): ContentData | null;
532
+ /**
533
+ * Get content manifest
534
+ */
535
+ getManifest(id: string): ContentManifest | null;
536
+ /**
537
+ * Find content by pathname
538
+ */
539
+ getByPathname(pathname: string, locale?: string): ContentManifest | null;
540
+ /**
541
+ * Find content by previous pathname (for redirects)
542
+ */
543
+ getByPreviousPathname(pathname: string, locale?: string): ContentManifest | null;
544
+ /**
545
+ * Generator for all manifests
546
+ */
547
+ getAllManifests(): Generator<ContentManifest>;
548
+ /**
549
+ * Generator for manifests by locale
550
+ */
551
+ getManifestsByLocale(locale: string): Generator<ContentManifest>;
552
+ /**
553
+ * Get the count of indexed content entries (unique IDs)
554
+ */
555
+ get entryCount(): number;
556
+ /**
557
+ * Clear all indexes
558
+ */
559
+ clear(): void;
560
+ }
561
+ //#endregion
562
+ //#region src/site.d.ts
563
+ declare class Site {
564
+ private siteName;
565
+ private api;
566
+ private siteIndex;
567
+ constructor(siteName: string, api: ContentAPI, siteIndex: SiteIndex);
568
+ listContent(filters?: SiteFilters): Generator<ContentManifest>;
569
+ listPages(locale?: string): Generator<ContentManifest>;
570
+ get collections(): Set<string>;
571
+ getByPathname(pathname: string, locale?: string): ContentManifest | null;
572
+ getByPreviousPathname(pathname: string, locale?: string): ContentManifest | null;
573
+ move(id: string, locale: string, newPathname: string): Promise<MoveResult>;
574
+ getRedirect(pathname: string): ContentManifest | null;
575
+ isPathnameAvailable(pathname: string, locale: string, excludeId?: string): boolean;
576
+ getPathnameConflict(pathname: string, locale: string, excludeId?: string): string | null;
577
+ isPathnameInRedirects(pathname: string, locale: string): boolean;
578
+ create(data: CreatePageInput): Promise<CreateResult>;
579
+ }
580
+ //#endregion
581
+ //#region src/content-api.interface.d.ts
582
+ /**
583
+ * Content API Interface
584
+ *
585
+ * Provides a unified interface for content operations across different storage backends.
586
+ *
587
+ * ## Indexing and Caching
588
+ *
589
+ * Implementations should index content at startup for performance. However, since content
590
+ * files can be modified externally (via git, text editors, etc.), implementations must:
591
+ *
592
+ * 1. Perform read-repair when files are invalid (e.g., VXJSON with incorrect field order)
593
+ * 2. Handle files that were added after the initial indexing
594
+ * 3. Update the index when files are repaired or discovered
595
+ *
596
+ * ## Read-Repair
597
+ *
598
+ * For file-based implementations, read-repair should:
599
+ * - Fix missing required fields (id, created, modified)
600
+ * - Ensure VXJSON files have "content" as the last field
601
+ * - Update the index with repaired content
602
+ * - Write the repaired file back to disk
603
+ */
604
+ interface ContentAPI {
605
+ /**
606
+ * Get content with all locales
607
+ * @param id - The content ID
608
+ * @returns The content entry with all locales, or null if not found
609
+ */
610
+ getContent(id: string): Promise<ContentEntry | null>;
611
+ /**
612
+ * Get content for a specific locale
613
+ *
614
+ * For file-based implementations:
615
+ * - Should handle files added after initial indexing
616
+ * - Should perform read-repair if the file is invalid
617
+ * - Should update the index with discovered/repaired content
618
+ *
619
+ * @param id - The content ID
620
+ * @param locale - The locale code
621
+ * @returns The localized content entry, or null if not found
622
+ */
623
+ getLocalized(id: string, locale: string): Promise<LocalizedEntry | null>;
624
+ createContent(data: CreateContentInput): Promise<CreateResult>;
625
+ updateLocalized(input: UpdateLocaleInput): Promise<UpdateResult>;
626
+ deleteContent(id: string, etag: string): Promise<DeleteResult>;
627
+ deleteLocalized(input: DeleteLocaleInput): Promise<DeleteResult>;
628
+ getSite(siteName: string): Site | null;
629
+ readonly blocks: Blocks;
630
+ readonly data: Data;
631
+ listAllContent(filters?: GlobalFilters): Generator<ContentManifest>;
632
+ findUntranslatedContent(targetLocale: string, options?: FindOptions): Generator<ContentManifest>;
633
+ readonly sitesConfig: SitesConfig;
634
+ batchUpdate(operations: UpdateLocaleInput[]): Promise<BatchResult>;
635
+ getContentAsBuffer(id: string, locale: string): Promise<{
636
+ buffer: Uint8Array;
637
+ etag: string;
638
+ contentType: 'application/json' | 'text/mdx';
639
+ } | null>;
640
+ }
641
+ //#endregion
642
+ //#region src/blocks.d.ts
643
+ declare class Blocks {
644
+ private api;
645
+ private blockIndex;
646
+ constructor(api: ContentAPI, blockIndex: BlockIndex);
647
+ listContent(filters?: BlockFilters): Generator<ContentManifest>;
648
+ get collections(): Set<string>;
649
+ getByName(collection: string, name: string, locale?: string): ContentManifest | null;
650
+ isNameAvailable(collection: string, name: string, excludeId?: string): boolean;
651
+ getNameConflict(collection: string, name: string, excludeId?: string): string | null;
652
+ isBlockNameValid(blockName: string): boolean;
653
+ create(data: CreateBlockInput): Promise<CreateResult>;
654
+ }
655
+ //#endregion
656
+ //#region src/component-registry.types.d.ts
657
+ interface ComponentEntry {
658
+ displayName: string;
659
+ path: string | null;
660
+ }
661
+ interface ComponentEntryWithId extends ComponentEntry {
662
+ id: string;
663
+ }
664
+ interface ComponentRegistry {
665
+ [componentId: string]: ComponentEntry;
666
+ }
667
+ //#endregion
668
+ //#region src/content-utils.d.ts
669
+ declare function localesOf<T>(manifest: {
670
+ locales: Record<string, T | undefined>;
671
+ }): Generator<T>;
672
+ /**
673
+ * Pure utility functions for content operations
674
+ * These functions don't depend on any class state and can be shared
675
+ * between FileSystemContentAPI, InMemoryContentAPI, and other implementations
676
+ */
677
+ /**
678
+ * Check if content is published based on publishAt/unpublishAt dates
679
+ */
680
+ declare function isContentPublished(localeVersion: Pick<LocaleVersion, 'publishAt' | 'unpublishAt'>, now?: Date): boolean;
681
+ /**
682
+ * Validate that metadata doesn't exceed 4KB when serialized
683
+ * This ensures efficient indexing as per the specification
684
+ */
685
+ declare function isMetadataTooLarge(meta: ContentMeta): boolean;
686
+ /**
687
+ * Extract block name from various sources
688
+ * Used when displaying blocks in the UI
689
+ */
690
+ declare function extractBlockName(source: string): string;
691
+ /**
692
+ * Validate block name according to the specification
693
+ * - Cannot contain dots (reserved for locale separator)
694
+ * - Cannot contain slashes (would create subdirectories)
695
+ * - Cannot contain spaces (for clean filenames)
696
+ * - Must have at least one character
697
+ */
698
+ declare function isValidBlockName(name: string): boolean;
699
+ /**
700
+ * Format file size for display with human-readable units
701
+ * @example formatFileSize(1536) // "1.5 KB"
702
+ */
703
+ declare function formatFileSize(bytes: number): string;
704
+ /**
705
+ * Calculate metadata size in bytes
706
+ */
707
+ declare function getMetadataSize(meta: ContentMeta): number;
708
+ /**
709
+ * Check if a pathname is valid
710
+ * - Must start with /
711
+ * - Cannot contain spaces (should be URL-encoded)
712
+ * - Cannot contain special characters that would break URLs
713
+ */
714
+ declare function isValidPathname(pathname: string): boolean;
715
+ /**
716
+ * Normalize a pathname to ensure consistency
717
+ * - Ensure it starts with /
718
+ * - Remove trailing slashes (except for root)
719
+ * - Collapse multiple slashes
720
+ */
721
+ declare function normalizePathname(pathname: string): string;
722
+ /**
723
+ * Generate a content ID in the standard format
724
+ * IDs are prefixed with "vx-" followed by 8 random characters
725
+ */
726
+ declare function generateContentId(): string;
727
+ /**
728
+ * Get the current date/time in ISO format
729
+ * Used for timestamps in content files
730
+ */
731
+ declare function getCurrentISODate(): string;
732
+ /**
733
+ * Parse a date string safely
734
+ * Returns null if invalid
735
+ */
736
+ declare function parseDate(dateStr: string | undefined): Date | null;
737
+ /**
738
+ * Creates a V8-optimized object by mapping site names to values.
739
+ * Ensures all objects have the same hidden class by adding properties in consistent order.
740
+ *
741
+ * @param sitesConfig - Sites configuration containing site names
742
+ * @param factory - Function that creates the value for each site
743
+ * @returns Object with all sites initialized in alphabetical order
744
+ */
745
+ declare function mapSiteNames<T>(sitesConfig: {
746
+ sites: Record<string, any>;
747
+ }, factory: (siteName: string) => T): Record<string, T>;
748
+ /**
749
+ * Creates a V8-optimized object by mapping locale names to values.
750
+ * Ensures all objects have the same hidden class by adding properties in consistent order.
751
+ *
752
+ * @param locales - Array of locale codes
753
+ * @param factory - Function that creates the value for each locale
754
+ * @returns Object with all locales initialized in array order
755
+ */
756
+ declare function mapLocales<T>(locales: string[], factory: (locale: string) => T): Record<string, T>;
757
+ /**
758
+ * Resolves a publish date value to a valid string or undefined.
759
+ * Handles various input types including null, false, and empty strings.
760
+ *
761
+ * @param updateValue - The value being updated (string | null | false | undefined)
762
+ * @param currentValue - The current value to fall back to if updateValue is undefined
763
+ * @returns A valid date string or undefined
764
+ */
765
+ declare function resolvePublishDate(updateValue: string | null | false | undefined, currentValue: string | undefined): string | undefined;
766
+ /**
767
+ * Serializes MDX content with frontmatter.
768
+ * This is used by both FileSystemContentAPI and InMemoryContentAPI to ensure
769
+ * consistent MDX output that includes frontmatter for variable access.
770
+ *
771
+ * @param frontmatterData - The frontmatter data to serialize
772
+ * @param mdxContent - The MDX content (without frontmatter)
773
+ * @returns Complete MDX file content with frontmatter
774
+ */
775
+ declare function serializeMdxWithFrontmatter(frontmatterData: Record<string, any>, mdxContent: string): string;
776
+ //#endregion
777
+ //#region src/content-operations.d.ts
778
+ /**
779
+ * Shared business logic for content operations
780
+ * Used by both FileSystemContentAPI and InMemoryContentAPI
781
+ */
782
+ interface ValidationResult {
783
+ valid: boolean;
784
+ error?: string;
785
+ sortedMeta?: ContentMeta;
786
+ size?: number;
787
+ }
788
+ interface CreateValidationResult {
789
+ valid: boolean;
790
+ error?: string;
791
+ reason?: 'metadata_too_large' | 'pathname_taken' | 'pathname_in_redirects' | 'invalid_name' | 'name_taken';
792
+ existingId?: string;
793
+ }
794
+ /**
795
+ * Validate and prepare metadata for storage
796
+ * Ensures title exists and metadata doesn't exceed 4KB
797
+ */
798
+ declare function validateAndPrepareMetadata(meta: Partial<ContentMeta>): ValidationResult;
799
+ /**
800
+ * Build pathname history update
801
+ */
802
+ declare function buildPathnameHistory(oldPathname: string | undefined, newPathname: string | undefined, isPublished: boolean, now: string): Record<string, string>;
803
+ /**
804
+ * Build a locale manifest
805
+ */
806
+ declare function buildLocaleVersion(params: {
807
+ locale: string;
808
+ etag: string;
809
+ created: string;
810
+ modified: string;
811
+ meta: ContentMeta;
812
+ kind: 'block' | 'page' | 'data';
813
+ publishAt?: string;
814
+ unpublishAt?: string;
815
+ pathname?: string;
816
+ name?: string;
817
+ previousPathnames?: Record<string, string>;
818
+ }): LocaleVersion;
819
+ /**
820
+ * Update publish dates on a locale manifest
821
+ */
822
+ declare function updatePublishDates(manifest: LocaleVersion, data: LocaleUpdateData): void;
823
+ /**
824
+ * Validate content creation data
825
+ */
826
+ declare function validateCreateContent(data: CreateContentInput, sites: Record<string, Site>, blocks: Blocks, dataApi?: {
827
+ isDataNameValid: (name: string) => boolean;
828
+ getNameConflict: (collection: string, name: string) => string | null;
829
+ }): CreateValidationResult;
830
+ /**
831
+ * Update scope bit flags
832
+ * Can be combined with bitwise OR and checked with bitwise AND
833
+ */
834
+ declare const UPDATE_SCOPE: {
835
+ readonly NONE: 0;
836
+ readonly META: number;
837
+ readonly CONTENT: number;
838
+ readonly BOTH: 3;
839
+ };
840
+ type UpdateScope = (typeof UPDATE_SCOPE)[keyof typeof UPDATE_SCOPE];
841
+ /**
842
+ * Determine what parts of content are being updated
843
+ * Returns bit flags that can be checked with bitwise AND
844
+ *
845
+ * Example usage:
846
+ * ```
847
+ * const scope = analyzeUpdateScope(data);
848
+ * if (scope & UPDATE_SCOPE.META) { // metadata is being updated }
849
+ * if (scope & UPDATE_SCOPE.CONTENT) { // content is being updated }
850
+ * if (scope === UPDATE_SCOPE.BOTH) { // both are being updated }
851
+ * ```
852
+ */
853
+ declare function analyzeUpdateScope(data: LocaleUpdateData): UpdateScope;
854
+ /**
855
+ * Determine whether the modified timestamp should be updated
856
+ * Updates for ANY change - either metadata or content
857
+ */
858
+ declare function shouldUpdateModifiedTimestamp(data: LocaleUpdateData): boolean;
859
+ //#endregion
860
+ export { DeleteResult as $, ComponentRegistry as A, ContentData as B, mapSiteNames as C, ManifestEntryData as Ct, serializeMdxWithFrontmatter as D, resolvePublishDate as E, APIError as F, ContentMeta as G, ContentIdentity as H, BatchOperationResult as I, CreateBlockInput as J, ContentProp as K, BatchResult as L, ContentAPI as M, Site as N, ComponentEntry as O, Data as P, DeleteLocaleInput as Q, BlockFilters as R, mapLocales as S, FolderTreeNode as St, parseDate as T, ContentListResult as U, ContentEntry as V, ContentManifest as W, CreatePageInput as X, CreateContentInput as Y, CreateResult as Z, isContentPublished as _, WriteResult as _t, analyzeUpdateScope as a, LocalePathData as at, isValidPathname as b, AssetUsage as bt, shouldUpdateModifiedTimestamp as c, LocalizedEntry as ct, validateCreateContent as d, MoveResult as dt, ErrorCode as et, extractBlockName as f, SiteFilters as ft, getMetadataSize as g, VXJSONFile as gt, getCurrentISODate as h, UpdateResult as ht, ValidationResult as i, LocaleFileData as it, Blocks as j, ComponentEntryWithId as k, updatePublishDates as l, LocalizedManifest as lt, generateContentId as m, UpdateLocaleInput as mt, UPDATE_SCOPE as n, FindOptions as nt, buildLocaleVersion as o, LocaleUpdateData as ot, formatFileSize as p, SitesConfig as pt, ContentType as q, UpdateScope as r, GlobalFilters as rt, buildPathnameHistory as s, LocaleVersion as st, CreateValidationResult as t, ErrorCodes as tt, validateAndPrepareMetadata as u, MDXFrontmatter as ut, isMetadataTooLarge as v, AssetEntry as vt, normalizePathname as w, localesOf as x, FolderListing as xt, isValidBlockName as y, AssetManifestData as yt, ContentAPIOptions as z };
861
+ //# sourceMappingURL=content-operations-CydU4aAl.d.mts.map