@conloca/content-api 0.1.15 → 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 +164 -0
- package/dist/asset-operations.d.ts.map +1 -0
- package/dist/asset-operations.js +784 -0
- package/dist/asset-operations.js.map +1 -0
- package/dist/asset-types.d.ts +72 -0
- package/dist/asset-types.d.ts.map +1 -0
- package/dist/asset-types.js +13 -0
- 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 +63 -0
- package/dist/base-content-index.d.ts.map +1 -0
- package/dist/base-content-index.js +200 -0
- package/dist/base-content-index.js.map +1 -0
- package/dist/cf-access.d.ts +31 -0
- package/dist/cf-access.d.ts.map +1 -0
- package/dist/cf-access.js +67 -0
- package/dist/cf-access.js.map +1 -0
- package/dist/component-registry.d.ts +50 -0
- package/dist/component-registry.d.ts.map +1 -0
- package/dist/component-registry.js +121 -0
- package/dist/component-registry.js.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 +2 -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 +64 -0
- package/dist/content-api.interface.d.ts.map +1 -0
- package/dist/content-api.interface.js +2 -0
- package/dist/content-api.interface.js.map +1 -0
- package/dist/content-filters.d.ts +31 -0
- package/dist/content-filters.d.ts.map +1 -0
- package/dist/content-filters.js +247 -0
- package/dist/content-filters.js.map +1 -0
- package/dist/content-index.d.ts +184 -0
- package/dist/content-index.d.ts.map +1 -0
- package/dist/content-index.js +546 -0
- package/dist/content-index.js.map +1 -0
- package/dist/content-operations.d.ts +157 -0
- package/dist/content-operations.d.ts.map +1 -0
- package/dist/content-operations.js +359 -0
- 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 +10 -0
- package/dist/content-reader.d.ts.map +1 -0
- package/dist/content-reader.js +14 -0
- package/dist/content-reader.js.map +1 -0
- package/dist/content-utils.d.ts +175 -0
- package/dist/content-utils.d.ts.map +1 -0
- package/dist/content-utils.js +421 -0
- package/dist/content-utils.js.map +1 -0
- package/dist/content-watcher.d.ts +43 -0
- package/dist/content-watcher.d.ts.map +1 -0
- package/dist/content-watcher.js +86 -0
- package/dist/content-watcher.js.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 +8 -0
- package/dist/data-index.js.map +1 -0
- package/dist/data.d.ts +35 -0
- package/dist/data.d.ts.map +1 -0
- package/dist/data.js +104 -0
- 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 +77 -0
- package/dist/etag-utils.d.ts.map +1 -0
- package/dist/etag-utils.js +161 -0
- package/dist/etag-utils.js.map +1 -0
- package/dist/filesystem-content-api.d.ts +162 -0
- package/dist/filesystem-content-api.d.ts.map +1 -0
- package/dist/filesystem-content-api.js +2307 -0
- 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 +49 -0
- package/dist/git-operations.d.ts.map +1 -0
- package/dist/git-operations.js +256 -0
- package/dist/git-operations.js.map +1 -0
- package/dist/header-parser.d.ts +37 -0
- package/dist/header-parser.d.ts.map +1 -0
- package/dist/header-parser.js +233 -0
- package/dist/header-parser.js.map +1 -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 +609 -0
- package/dist/in-memory-content-api.js.map +1 -0
- package/dist/index.d.ts +26 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +28 -0
- package/dist/index.js.map +1 -0
- package/dist/indexing.d.ts +5 -0
- package/dist/indexing.d.ts.map +1 -0
- package/dist/indexing.js +8 -0
- package/dist/indexing.js.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 +153 -0
- package/dist/json-whitespace-view.js.map +1 -0
- package/dist/middleware.d.ts +20 -0
- package/dist/middleware.d.ts.map +1 -0
- package/dist/middleware.js +1082 -0
- package/dist/middleware.js.map +1 -0
- package/dist/node.d.ts +32 -0
- package/dist/node.d.ts.map +1 -0
- package/dist/node.js +27 -0
- 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 +15 -0
- package/dist/reader.d.ts.map +1 -0
- package/dist/reader.js +14 -0
- package/dist/reader.js.map +1 -0
- package/dist/schemas/index.d.ts +102 -0
- package/dist/schemas/index.d.ts.map +1 -0
- package/dist/schemas/index.js +88 -0
- package/dist/schemas/index.js.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 +291 -0
- package/dist/site-index.js.map +1 -0
- package/dist/site.d.ts +23 -0
- package/dist/site.d.ts.map +1 -0
- package/dist/site.js +180 -0
- package/dist/site.js.map +1 -0
- package/dist/types.d.ts +641 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +45 -0
- package/dist/types.js.map +1 -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 +41 -0
- package/dist/url-safe-base64.js.map +1 -0
- package/dist/url-validation.d.ts +28 -0
- package/dist/url-validation.d.ts.map +1 -0
- package/dist/url-validation.js +123 -0
- package/dist/url-validation.js.map +1 -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 +21 -0
- package/dist/utils/atomic-write.js.map +1 -0
- package/dist/utils.d.ts +46 -0
- package/dist/utils.d.ts.map +1 -0
- package/dist/utils.js +71 -0
- package/dist/utils.js.map +1 -0
- package/dist/vite-plugin.d.ts +12 -0
- package/dist/vite-plugin.d.ts.map +1 -0
- package/dist/vite-plugin.js +30 -0
- package/dist/vite-plugin.js.map +1 -0
- package/dist/vxjson-serialize.d.ts +13 -0
- package/dist/vxjson-serialize.d.ts.map +1 -0
- package/dist/vxjson-serialize.js +53 -0
- package/dist/vxjson-serialize.js.map +1 -0
- package/dist/vxjson.d.ts +113 -0
- package/dist/vxjson.d.ts.map +1 -0
- package/dist/vxjson.js +381 -0
- package/dist/vxjson.js.map +1 -0
- package/dist/xxhash.d.ts +10 -0
- package/dist/xxhash.d.ts.map +1 -0
- package/dist/xxhash.js +35 -0
- package/dist/xxhash.js.map +1 -0
- package/package.json +132 -34
- 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/component-registry.types-CBGONnYn.d.mts +0 -71
- package/dist/component-registry.types-CBGONnYn.d.mts.map +0 -1
- package/dist/content-operations-Dv67amz3.d.mts +0 -852
- package/dist/content-operations-Dv67amz3.d.mts.map +0 -1
- package/dist/data-Db1Iv9T0.mjs +0 -60
- package/dist/data-Db1Iv9T0.mjs.map +0 -1
- package/dist/filesystem-content-api-C1TM0GLo.d.mts +0 -119
- package/dist/filesystem-content-api-C1TM0GLo.d.mts.map +0 -1
- package/dist/filesystem-content-api-kxKY5IUw.mjs +0 -2678
- package/dist/filesystem-content-api-kxKY5IUw.mjs.map +0 -1
- package/dist/index.d.mts +0 -79
- package/dist/index.d.mts.map +0 -1
- package/dist/index.mjs +0 -47
- package/dist/index.mjs.map +0 -1
- package/dist/node.d.mts +0 -378
- package/dist/node.d.mts.map +0 -1
- package/dist/node.mjs +0 -2618
- package/dist/node.mjs.map +0 -1
- package/dist/reader.d.mts +0 -18
- 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 -90
- package/dist/schemas/index.d.mts.map +0 -1
- package/dist/schemas/index.mjs +0 -70
- package/dist/schemas/index.mjs.map +0 -1
- package/dist/site-vNtJ5jCh.mjs +0 -538
- package/dist/site-vNtJ5jCh.mjs.map +0 -1
- package/dist/types-DWt912tu.mjs +0 -33
- package/dist/types-DWt912tu.mjs.map +0 -1
package/src/node.ts
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Node.js-specific exports for @conloca/content-api
|
|
3
|
+
*
|
|
4
|
+
* These exports require Node.js runtime APIs and should not be imported in browser environments.
|
|
5
|
+
* Use the main package exports for browser-compatible APIs.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
export { type AssetConfig, AssetOperations } from './asset-operations.js';
|
|
9
|
+
export type { AssetEntry, AssetManifestData, AssetMetadata, AssetMetadataPatch } from './asset-types.js';
|
|
10
|
+
// CF Access authentication
|
|
11
|
+
export {
|
|
12
|
+
type CFAccessResult,
|
|
13
|
+
type CFAccessUser,
|
|
14
|
+
extractCFAccessToken,
|
|
15
|
+
validateCFAccessRequest,
|
|
16
|
+
} from './cf-access.js';
|
|
17
|
+
export { ComponentRegistry } from './component-registry.js';
|
|
18
|
+
export * from './component-registry.types.js';
|
|
19
|
+
export type { ContentAPI } from './content-api.interface.js';
|
|
20
|
+
export { ContentIndex } from './content-index.js';
|
|
21
|
+
export * from './content-operations.js';
|
|
22
|
+
export type { ContentFileExtension, ContentPathLayout, LocaleFilename } from './content-path.js';
|
|
23
|
+
export * from './content-utils.js';
|
|
24
|
+
export type { ContentWatcherOptions, WebSocketSender } from './content-watcher.js';
|
|
25
|
+
export { createContentAPI, createContentWatchHandlers } from './content-watcher.js';
|
|
26
|
+
// Node.js specific implementations (require fs, xxhash, etc.)
|
|
27
|
+
export { FileSystemContentAPI, readSitesConfig } from './filesystem-content-api.js';
|
|
28
|
+
export type { FileSystemReaderBackendOptions } from './filesystem-reader-backend.js';
|
|
29
|
+
export { FileSystemReaderBackend } from './filesystem-reader-backend.js';
|
|
30
|
+
export { Fragments } from './fragments.js';
|
|
31
|
+
export type { ParseHeaderResult } from './header-parser.js';
|
|
32
|
+
export { parseContentHeader } from './header-parser.js';
|
|
33
|
+
export { InMemoryContentAPI } from './in-memory-content-api.js';
|
|
34
|
+
export { createContentAPIRouter, createContentMiddleware } from './middleware.js';
|
|
35
|
+
export type { BackendReadResult, ContentReaderBackend } from './reader-backend.js';
|
|
36
|
+
export { Site } from './site.js';
|
|
37
|
+
// Re-export types and utilities that are safe for Node.js environments
|
|
38
|
+
export * from './types.js';
|
|
39
|
+
export type { ConlocaContentOptions } from './vite-plugin.js';
|
|
40
|
+
export { conlocaContent } from './vite-plugin.js';
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { readDate } from './read-date.js';
|
|
2
|
+
import type { ContentIdentity, DataBindingConfig, LocaleVersion, PageReference } from './types.js';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* The timestamps a page reference carries. `published` is the date page lists
|
|
6
|
+
* order by: the page's publish time, or its creation time when it has none.
|
|
7
|
+
* Empty or unreadable dates count as not set.
|
|
8
|
+
*/
|
|
9
|
+
export function pageTimestampsOf(dates: {
|
|
10
|
+
created?: string | Date | null | undefined;
|
|
11
|
+
modified?: string | Date | null | undefined;
|
|
12
|
+
publishAt?: string | Date | null | undefined;
|
|
13
|
+
}): NonNullable<PageReference['timestamps']> {
|
|
14
|
+
const created = readDate(dates.created);
|
|
15
|
+
const modified = readDate(dates.modified);
|
|
16
|
+
const published = readDate(dates.publishAt) ?? created;
|
|
17
|
+
// Spread rather than `key: undefined`, for hosts compiling with exactOptionalPropertyTypes.
|
|
18
|
+
return { ...(created ? { created } : {}), ...(modified ? { modified } : {}), ...(published ? { published } : {}) };
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/** The reference a data-bound block reads for one locale of a page. */
|
|
22
|
+
export function pageReferenceOf(
|
|
23
|
+
entry: Pick<ContentIdentity, 'id' | 'collection'>,
|
|
24
|
+
version: LocaleVersion,
|
|
25
|
+
): PageReference {
|
|
26
|
+
return {
|
|
27
|
+
id: entry.id,
|
|
28
|
+
pathname: version.pathname || '/',
|
|
29
|
+
title: version.meta.title,
|
|
30
|
+
collection: entry.collection,
|
|
31
|
+
meta: version.meta,
|
|
32
|
+
timestamps: pageTimestampsOf(version),
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
type Comparator = (a: PageReference, b: PageReference) => number;
|
|
37
|
+
|
|
38
|
+
/** A page's publish date in ms; a page with none sorts as the oldest. */
|
|
39
|
+
const publishedTime = (page: PageReference) => page.timestamps?.published?.getTime() ?? 0;
|
|
40
|
+
|
|
41
|
+
/** Code-unit order: the same in Bun and every browser, unlike a locale-aware compare. */
|
|
42
|
+
const compareText = (a: string, b: string) => (a < b ? -1 : a > b ? 1 : 0);
|
|
43
|
+
|
|
44
|
+
/** Ties break by path, then id (a path is unique within one language, which is all one list holds). */
|
|
45
|
+
const byPath: Comparator = (a, b) => compareText(a.pathname, b.pathname) || compareText(a.id, b.id);
|
|
46
|
+
|
|
47
|
+
type PageSort = NonNullable<NonNullable<DataBindingConfig['pages']>['sort']>;
|
|
48
|
+
const ORDER = {
|
|
49
|
+
'date-desc': (a, b) => publishedTime(b) - publishedTime(a) || byPath(a, b),
|
|
50
|
+
'date-asc': (a, b) => publishedTime(a) - publishedTime(b) || byPath(a, b),
|
|
51
|
+
title: (a, b) => (a.title || '').localeCompare(b.title || '') || byPath(a, b),
|
|
52
|
+
} satisfies Record<PageSort, Comparator>;
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* The page feed a route's `dataBindings.pages` declares: the pages under
|
|
56
|
+
* `prefix` without the listing page itself, sorted (newest publish date first
|
|
57
|
+
* by default; ties by path) and capped. Shared, so the published page and the
|
|
58
|
+
* editor list the same pages in the same order, whatever order they read them in.
|
|
59
|
+
*/
|
|
60
|
+
export function selectPagesByPrefix(
|
|
61
|
+
pages: PageReference[],
|
|
62
|
+
prefix: string,
|
|
63
|
+
options?: Omit<NonNullable<DataBindingConfig['pages']>, 'prefix'>,
|
|
64
|
+
): PageReference[] {
|
|
65
|
+
let filtered = pages.filter(
|
|
66
|
+
(page) => page.pathname.startsWith(prefix) && page.pathname !== prefix && page.pathname !== prefix.slice(0, -1),
|
|
67
|
+
);
|
|
68
|
+
|
|
69
|
+
filtered.sort(ORDER[options?.sort ?? 'date-desc']);
|
|
70
|
+
|
|
71
|
+
if (options?.limit && options.limit > 0) {
|
|
72
|
+
filtered = filtered.slice(0, options.limit);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
return filtered;
|
|
76
|
+
}
|
package/src/read-date.ts
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/** A stored date as a Date, or undefined when it is empty or cannot be read: such a date counts as not set. */
|
|
2
|
+
export function readDate(value: string | Date | null | undefined): Date | undefined {
|
|
3
|
+
if (!value) return undefined;
|
|
4
|
+
// Copies a Date, so a caller never shares the one it was handed.
|
|
5
|
+
const date = new Date(value);
|
|
6
|
+
return Number.isNaN(date.getTime()) ? undefined : date;
|
|
7
|
+
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Backend-agnostic source of content blob bytes.
|
|
3
|
+
*
|
|
4
|
+
* The implementation shipped here is `FileSystemReaderBackend` — it wraps
|
|
5
|
+
* fast-glob + node:fs open/read. Another backend can supply the bytes by
|
|
6
|
+
* implementing the same interface.
|
|
7
|
+
*
|
|
8
|
+
* The index hydrator (`ContentIndex.indexAll`) consumes this interface and
|
|
9
|
+
* never knows which backend produced the bytes. The interface is deliberately
|
|
10
|
+
* backend-agnostic: no filesystem types, no platform storage types, no Node `Buffer`.
|
|
11
|
+
* Only `Uint8Array` and the discriminated `BackendReadResult` flow through it,
|
|
12
|
+
* so the same hydrator code runs on any JavaScript runtime.
|
|
13
|
+
*/
|
|
14
|
+
export interface ContentReaderBackend {
|
|
15
|
+
/**
|
|
16
|
+
* Stream the set of content paths matching the optional glob, attaching up
|
|
17
|
+
* to `headerBytes` (default 4096) of each blob's bytes plus a `complete`
|
|
18
|
+
* flag set when the buffer holds the entire blob.
|
|
19
|
+
*
|
|
20
|
+
* The header is enough to parse VXJSON manifest metadata and MDX
|
|
21
|
+
* frontmatter without a second read, so the hydrator never has to call
|
|
22
|
+
* `readPath` for index construction.
|
|
23
|
+
*
|
|
24
|
+
* Errors per item are reported as a `BackendReadResult` with `ok: false` —
|
|
25
|
+
* never thrown — so a single corrupt file doesn't abort the whole stream.
|
|
26
|
+
*/
|
|
27
|
+
listContentPaths(opts?: { glob?: string; headerBytes?: number }): AsyncIterable<BackendReadResult>;
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Read the full bytes of a content path. Returns null if the path no
|
|
31
|
+
* longer exists (race against deletion is acceptable).
|
|
32
|
+
*/
|
|
33
|
+
readPath(path: string): Promise<Uint8Array | null>;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Discriminated union for per-item results from `listContentPaths`.
|
|
38
|
+
* `ok: true` carries the header bytes plus size/complete metadata; `ok: false`
|
|
39
|
+
* carries an errno-derived reason and a human-readable message.
|
|
40
|
+
*/
|
|
41
|
+
export type BackendReadResult =
|
|
42
|
+
| {
|
|
43
|
+
ok: true;
|
|
44
|
+
path: string;
|
|
45
|
+
size: number;
|
|
46
|
+
header: Uint8Array; // length <= size; complete === true ⇒ length === size
|
|
47
|
+
complete: boolean;
|
|
48
|
+
}
|
|
49
|
+
| {
|
|
50
|
+
ok: false;
|
|
51
|
+
path: string;
|
|
52
|
+
reason: 'not-found' | 'permission-denied' | 'corrupt-header' | 'io-error';
|
|
53
|
+
message: string;
|
|
54
|
+
};
|
package/src/reader.ts
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Read-only Node.js exports for @conloca/content-api.
|
|
3
|
+
*
|
|
4
|
+
* Intended for static/build-time consumers that need content discovery and reads
|
|
5
|
+
* without importing the full server barrel.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
export type { ContentAPI } from './content-api.interface.js';
|
|
9
|
+
export * from './content-operations.js';
|
|
10
|
+
export { createContentAPI } from './content-reader.js';
|
|
11
|
+
export * from './content-utils.js';
|
|
12
|
+
export { Data } from './data.js';
|
|
13
|
+
export { Fragments } from './fragments.js';
|
|
14
|
+
export { Site } from './site.js';
|
|
15
|
+
export * from './types.js';
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
|
|
3
|
+
// ===== Page Schemas =====
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Base schema for page metadata - editable fields only.
|
|
7
|
+
* Used by CMS forms for dynamic form generation.
|
|
8
|
+
* Add .describe() for form field labels/hints.
|
|
9
|
+
*/
|
|
10
|
+
export const pageEditableSchema = z.object({
|
|
11
|
+
title: z.string().describe('Page title for SEO and browser tab'),
|
|
12
|
+
description: z.string().optional().describe('Meta description for search engines'),
|
|
13
|
+
pathname: z.string().describe('URL path (e.g., /about)'),
|
|
14
|
+
publishAt: z.coerce.date().nullable().optional().describe('Schedule publish date/time'),
|
|
15
|
+
unpublishAt: z.coerce.date().nullable().optional().describe('Schedule unpublish date/time'),
|
|
16
|
+
robots: z.string().optional().describe('Robots meta tag (e.g., index, follow)'),
|
|
17
|
+
canonical: z.string().url().optional().describe('Canonical URL for duplicate content'),
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
export type PageEditable = z.infer<typeof pageEditableSchema>;
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Full page schema with system fields.
|
|
24
|
+
* Used by Astro Content Collections for validation.
|
|
25
|
+
*/
|
|
26
|
+
export const pageMetaSchema = pageEditableSchema.extend({
|
|
27
|
+
id: z.string(),
|
|
28
|
+
locale: z.string(),
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
export type PageMeta = z.infer<typeof pageMetaSchema>;
|
|
32
|
+
|
|
33
|
+
// ===== Fragment Schemas =====
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Base schema for fragment metadata - editable fields only.
|
|
37
|
+
* Used by CMS forms for dynamic form generation.
|
|
38
|
+
* Add .describe() for form field labels/hints.
|
|
39
|
+
*/
|
|
40
|
+
export const fragmentEditableSchema = z.object({
|
|
41
|
+
title: z.string().describe('Display name for the fragment'),
|
|
42
|
+
description: z.string().optional().describe('Brief description of this fragment'),
|
|
43
|
+
category: z.string().optional().describe('Category for organizing fragments (e.g., headers, cta, content)'),
|
|
44
|
+
tags: z.array(z.string()).optional().describe('Tags for filtering and organization'),
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
export type FragmentEditable = z.infer<typeof fragmentEditableSchema>;
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Full fragment schema with system fields.
|
|
51
|
+
* Used by Astro Content Collections for validation.
|
|
52
|
+
*/
|
|
53
|
+
export const fragmentMetaSchema = fragmentEditableSchema.extend({
|
|
54
|
+
id: z.string(),
|
|
55
|
+
locale: z.string(),
|
|
56
|
+
name: z.string(),
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
export type FragmentMeta = z.infer<typeof fragmentMetaSchema>;
|
|
60
|
+
|
|
61
|
+
// ===== MDX Page Schemas =====
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* Base schema for mdx-type page frontmatter — renderer-neutral.
|
|
65
|
+
*
|
|
66
|
+
* Default for the CMS form when editing an mdx page; projects override via
|
|
67
|
+
* `mdxPages.schema` when they want a renderer-specific shape (e.g. an
|
|
68
|
+
* Astro-collection schema with extra fields).
|
|
69
|
+
*
|
|
70
|
+
* Permissive on purpose: `.passthrough()` lets unknown frontmatter keys flow
|
|
71
|
+
* through unchanged so the file's existing fields are never lost on save.
|
|
72
|
+
*/
|
|
73
|
+
export const mdxPageFrontmatterSchema = z
|
|
74
|
+
.object({
|
|
75
|
+
title: z.string().describe('Page title for SEO and browser tab'),
|
|
76
|
+
description: z.string().optional().describe('Meta description for search engines'),
|
|
77
|
+
draft: z.boolean().optional().describe('Hide the page from production builds'),
|
|
78
|
+
})
|
|
79
|
+
.passthrough();
|
|
80
|
+
|
|
81
|
+
export type MdxPageFrontmatter = z.infer<typeof mdxPageFrontmatterSchema>;
|
|
82
|
+
|
|
83
|
+
// ===== Data Schemas =====
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* Base schema for data entry metadata - editable fields only.
|
|
87
|
+
* Used by CMS forms for dynamic form generation.
|
|
88
|
+
* Add .describe() for form field labels/hints.
|
|
89
|
+
*/
|
|
90
|
+
export const dataEditableSchema = z.object({
|
|
91
|
+
title: z.string().describe('Display name for the entry'),
|
|
92
|
+
description: z.string().optional().describe('Brief description of this entry'),
|
|
93
|
+
category: z.string().optional().describe('Category for organizing entries'),
|
|
94
|
+
tags: z.array(z.string()).optional().describe('Tags for filtering and organization'),
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
export type DataEditable = z.infer<typeof dataEditableSchema>;
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* Zod schema for data entry metadata.
|
|
101
|
+
* Covers common organizational fields for structured data collections.
|
|
102
|
+
*/
|
|
103
|
+
export const dataMetaSchema = dataEditableSchema.extend({
|
|
104
|
+
// System fields (added by loader)
|
|
105
|
+
id: z.string(),
|
|
106
|
+
locale: z.string(),
|
|
107
|
+
name: z.string(),
|
|
108
|
+
|
|
109
|
+
// Actual data content (arbitrary JSON structure)
|
|
110
|
+
data: z.record(z.string(), z.unknown()).optional(),
|
|
111
|
+
});
|
|
112
|
+
|
|
113
|
+
export type DataMeta = z.infer<typeof dataMetaSchema>;
|
|
@@ -0,0 +1,330 @@
|
|
|
1
|
+
import { isContentPublished, localesOf, mapLocales } from './content-utils.js';
|
|
2
|
+
import type { ContentData, ContentIdentity, ContentManifest, LocaleVersion } from './types.js';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* V8-optimized index for a single site
|
|
6
|
+
* Maintains pathname lookups and collections for one site only
|
|
7
|
+
*/
|
|
8
|
+
export class SiteIndex {
|
|
9
|
+
// Primary index: id -> ContentManifest
|
|
10
|
+
private index: Map<string, ContentManifest> = new Map();
|
|
11
|
+
|
|
12
|
+
// Content cache: id -> locale -> content (for small files)
|
|
13
|
+
private contentCache: Map<string, Record<string, ContentData | null>> = new Map();
|
|
14
|
+
|
|
15
|
+
// Pathname index: locale -> (pathname -> ContentManifest)
|
|
16
|
+
// Locale level uses V8-optimized record, pathname level uses Map for dynamic keys
|
|
17
|
+
private pathnameIndex: Record<string, Map<string, ContentManifest>>;
|
|
18
|
+
|
|
19
|
+
// Previous pathname index for redirects: locale -> (oldPathname -> ContentManifest)
|
|
20
|
+
// Same structure - record for locales, Map for pathnames
|
|
21
|
+
private previousPathnameIndex: Record<string, Map<string, ContentManifest>>;
|
|
22
|
+
|
|
23
|
+
// Collections used by this site
|
|
24
|
+
readonly collections: Set<string> = new Set();
|
|
25
|
+
|
|
26
|
+
constructor(readonly locales: string[]) {
|
|
27
|
+
// Initialize pathname indexes - V8-optimized record for locales, Maps for pathnames
|
|
28
|
+
this.pathnameIndex = mapLocales(locales, () => new Map());
|
|
29
|
+
this.previousPathnameIndex = mapLocales(locales, () => new Map());
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Add or update content in the index
|
|
34
|
+
* Merges manifest locales and updates content cache if provided
|
|
35
|
+
*/
|
|
36
|
+
addContent(identity: ContentIdentity, localeVersion: LocaleVersion, content?: ContentData | null): void {
|
|
37
|
+
// Get existing manifest
|
|
38
|
+
const existing = this.index.get(identity.id);
|
|
39
|
+
const locale = localeVersion.locale;
|
|
40
|
+
|
|
41
|
+
if (existing) {
|
|
42
|
+
const existingLocale = existing.locales[locale];
|
|
43
|
+
|
|
44
|
+
// Track what we need to rollback
|
|
45
|
+
// First check what pathname currently maps to this manifest in our index
|
|
46
|
+
// This handles in-place updates where the manifest object has already been modified
|
|
47
|
+
let oldPathname: string | undefined;
|
|
48
|
+
|
|
49
|
+
// Find all pathnames that currently point to this manifest
|
|
50
|
+
for (const [pathname, indexedManifest] of this.pathnameIndex[locale].entries()) {
|
|
51
|
+
if (indexedManifest === existing && pathname !== localeVersion.pathname) {
|
|
52
|
+
oldPathname = pathname;
|
|
53
|
+
break;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
// If we didn't find it in the index, fall back to what's stored in the existing locale
|
|
58
|
+
if (!oldPathname && existingLocale?.pathname && existingLocale.pathname !== localeVersion.pathname) {
|
|
59
|
+
oldPathname = existingLocale.pathname;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
const hadExistingLocale = !!existingLocale;
|
|
63
|
+
let deletedOldPathname = false;
|
|
64
|
+
let addedNewPathname = false;
|
|
65
|
+
const addedPreviousPathnames: string[] = [];
|
|
66
|
+
|
|
67
|
+
// Update locale manifest if changed
|
|
68
|
+
// We need to always check for pathname changes, even if other fields haven't changed
|
|
69
|
+
// This handles in-place updates where the manifest is modified before calling addContent
|
|
70
|
+
const needsUpdate =
|
|
71
|
+
!existingLocale ||
|
|
72
|
+
existingLocale.etag !== localeVersion.etag ||
|
|
73
|
+
existingLocale.modified !== localeVersion.modified ||
|
|
74
|
+
(oldPathname && oldPathname !== localeVersion.pathname);
|
|
75
|
+
|
|
76
|
+
if (needsUpdate) {
|
|
77
|
+
try {
|
|
78
|
+
// Update the manifest locale
|
|
79
|
+
existing.locales[locale] = localeVersion;
|
|
80
|
+
|
|
81
|
+
// Update pathname indexes after manifest is updated
|
|
82
|
+
if (localeVersion.pathname) {
|
|
83
|
+
// If pathname changed, remove the old one
|
|
84
|
+
if (oldPathname && oldPathname !== localeVersion.pathname) {
|
|
85
|
+
this.pathnameIndex[locale].delete(oldPathname);
|
|
86
|
+
deletedOldPathname = true;
|
|
87
|
+
|
|
88
|
+
// Track the old pathname for redirects only if content is published
|
|
89
|
+
if (isContentPublished(localeVersion)) {
|
|
90
|
+
this.previousPathnameIndex[locale].set(oldPathname, existing);
|
|
91
|
+
addedPreviousPathnames.push(oldPathname);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
// Add/update the new pathname
|
|
96
|
+
this.pathnameIndex[locale].set(localeVersion.pathname, existing);
|
|
97
|
+
addedNewPathname = true;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
// Update previous pathname indexes from the manifest
|
|
101
|
+
if (localeVersion.previousPathnames) {
|
|
102
|
+
for (const prevPath of Object.keys(localeVersion.previousPathnames)) {
|
|
103
|
+
// Only add if not already there
|
|
104
|
+
if (!this.previousPathnameIndex[locale].has(prevPath)) {
|
|
105
|
+
this.previousPathnameIndex[locale].set(prevPath, existing);
|
|
106
|
+
addedPreviousPathnames.push(prevPath);
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
} catch (error) {
|
|
111
|
+
// Rollback only what we changed
|
|
112
|
+
if (hadExistingLocale) {
|
|
113
|
+
existing.locales[locale] = existingLocale;
|
|
114
|
+
} else {
|
|
115
|
+
existing.locales[locale] = undefined;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
// Rollback pathname index changes
|
|
119
|
+
if (deletedOldPathname && oldPathname) {
|
|
120
|
+
this.pathnameIndex[locale].set(oldPathname, existing);
|
|
121
|
+
}
|
|
122
|
+
if (addedNewPathname && localeVersion.pathname) {
|
|
123
|
+
this.pathnameIndex[locale].delete(localeVersion.pathname);
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
// Rollback previous pathname additions
|
|
127
|
+
for (const prevPath of addedPreviousPathnames) {
|
|
128
|
+
this.previousPathnameIndex[locale].delete(prevPath);
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
throw error;
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
} else {
|
|
135
|
+
// New content - create ContentManifest with single locale
|
|
136
|
+
const newManifest: ContentManifest = {
|
|
137
|
+
id: identity.id,
|
|
138
|
+
type: identity.type,
|
|
139
|
+
kind: identity.kind,
|
|
140
|
+
site: identity.site,
|
|
141
|
+
collection: identity.collection,
|
|
142
|
+
locales: {
|
|
143
|
+
[locale]: localeVersion,
|
|
144
|
+
},
|
|
145
|
+
};
|
|
146
|
+
|
|
147
|
+
this.index.set(identity.id, newManifest);
|
|
148
|
+
this.collections.add(identity.collection);
|
|
149
|
+
|
|
150
|
+
// Add pathname indexes
|
|
151
|
+
if (localeVersion.pathname) {
|
|
152
|
+
this.pathnameIndex[locale].set(localeVersion.pathname, newManifest);
|
|
153
|
+
}
|
|
154
|
+
if (localeVersion.previousPathnames) {
|
|
155
|
+
for (const prevPath of Object.keys(localeVersion.previousPathnames)) {
|
|
156
|
+
this.previousPathnameIndex[locale].set(prevPath, newManifest);
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
// Update content cache if provided
|
|
162
|
+
if (content !== undefined) {
|
|
163
|
+
const existingCache = this.contentCache.get(identity.id);
|
|
164
|
+
if (existingCache) {
|
|
165
|
+
// Update single locale content
|
|
166
|
+
existingCache[locale] = content;
|
|
167
|
+
} else {
|
|
168
|
+
this.contentCache.set(identity.id, { [locale]: content });
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
/**
|
|
174
|
+
* Remove a specific locale from an entry
|
|
175
|
+
*/
|
|
176
|
+
removeLocale(id: string, locale: string): void {
|
|
177
|
+
const manifest = this.index.get(id);
|
|
178
|
+
if (!manifest?.locales[locale]) return;
|
|
179
|
+
|
|
180
|
+
const localeVersion = manifest.locales[locale];
|
|
181
|
+
|
|
182
|
+
// Remove from pathname indexes
|
|
183
|
+
if (localeVersion.pathname) {
|
|
184
|
+
this.pathnameIndex[locale].delete(localeVersion.pathname);
|
|
185
|
+
}
|
|
186
|
+
if (localeVersion.previousPathnames) {
|
|
187
|
+
for (const prevPath of Object.keys(localeVersion.previousPathnames)) {
|
|
188
|
+
this.previousPathnameIndex[locale].delete(prevPath);
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
// Remove locale from manifest
|
|
193
|
+
manifest.locales[locale] = undefined;
|
|
194
|
+
|
|
195
|
+
// Remove from content cache
|
|
196
|
+
const contentCache = this.contentCache.get(id);
|
|
197
|
+
if (contentCache) {
|
|
198
|
+
delete contentCache[locale];
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
// If no DEFINED locales left, remove the entire entry. Count values, not
|
|
202
|
+
// keys — the removal above assigns `undefined` (keeping the key), so the
|
|
203
|
+
// key count never reaches zero (BaseContentIndex.removeLocale already
|
|
204
|
+
// counts defined values; this mirrored it incorrectly).
|
|
205
|
+
if (Object.values(manifest.locales).every((lv) => lv === undefined)) {
|
|
206
|
+
this.removeEntry(id);
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
/**
|
|
211
|
+
* Remove an entry from the index
|
|
212
|
+
*/
|
|
213
|
+
removeEntry(id: string): void {
|
|
214
|
+
const manifest = this.index.get(id);
|
|
215
|
+
if (!manifest) return;
|
|
216
|
+
|
|
217
|
+
// Remove from pathname indexes
|
|
218
|
+
for (const localeVersion of localesOf(manifest)) {
|
|
219
|
+
const { locale } = localeVersion;
|
|
220
|
+
if (localeVersion.pathname) {
|
|
221
|
+
this.pathnameIndex[locale].delete(localeVersion.pathname);
|
|
222
|
+
}
|
|
223
|
+
if (localeVersion.previousPathnames) {
|
|
224
|
+
for (const prevPath of Object.keys(localeVersion.previousPathnames)) {
|
|
225
|
+
this.previousPathnameIndex[locale].delete(prevPath);
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
// Remove from primary index
|
|
231
|
+
this.index.delete(id);
|
|
232
|
+
|
|
233
|
+
// Remove from content cache
|
|
234
|
+
this.contentCache.delete(id);
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
/**
|
|
238
|
+
* Get cached content for a specific locale
|
|
239
|
+
*/
|
|
240
|
+
getCachedContent(id: string, locale: string): ContentData | null {
|
|
241
|
+
const localeContent = this.contentCache.get(id);
|
|
242
|
+
return localeContent?.[locale] || null;
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
/**
|
|
246
|
+
* Get content manifest
|
|
247
|
+
*/
|
|
248
|
+
getManifest(id: string): ContentManifest | null {
|
|
249
|
+
return this.index.get(id) || null;
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
/**
|
|
253
|
+
* Find content by pathname
|
|
254
|
+
*/
|
|
255
|
+
getByPathname(pathname: string, locale?: string): ContentManifest | null {
|
|
256
|
+
if (locale) {
|
|
257
|
+
return this.pathnameIndex[locale]?.get(pathname) || null;
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
// Check all locales
|
|
261
|
+
for (const locale of this.locales) {
|
|
262
|
+
const manifest = this.pathnameIndex[locale].get(pathname);
|
|
263
|
+
if (manifest) {
|
|
264
|
+
return manifest;
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
return null;
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
/**
|
|
272
|
+
* Find content by previous pathname (for redirects)
|
|
273
|
+
*/
|
|
274
|
+
getByPreviousPathname(pathname: string, locale?: string): ContentManifest | null {
|
|
275
|
+
if (locale) {
|
|
276
|
+
return this.previousPathnameIndex[locale]?.get(pathname) || null;
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
// Check all locales
|
|
280
|
+
for (const locale of this.locales) {
|
|
281
|
+
const manifest = this.previousPathnameIndex[locale].get(pathname);
|
|
282
|
+
if (manifest) {
|
|
283
|
+
return manifest;
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
return null;
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
/**
|
|
291
|
+
* Generator for all manifests
|
|
292
|
+
*/
|
|
293
|
+
*getAllManifests(): Generator<ContentManifest> {
|
|
294
|
+
for (const manifest of this.index.values()) {
|
|
295
|
+
yield manifest;
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
/**
|
|
300
|
+
* Generator for manifests by locale
|
|
301
|
+
*/
|
|
302
|
+
*getManifestsByLocale(locale: string): Generator<ContentManifest> {
|
|
303
|
+
for (const manifest of this.index.values()) {
|
|
304
|
+
if (manifest.locales[locale]) {
|
|
305
|
+
yield manifest;
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
/**
|
|
311
|
+
* Get the count of indexed content entries (unique IDs)
|
|
312
|
+
*/
|
|
313
|
+
get entryCount(): number {
|
|
314
|
+
return this.index.size;
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
/**
|
|
318
|
+
* Clear all indexes
|
|
319
|
+
*/
|
|
320
|
+
clear(): void {
|
|
321
|
+
this.index.clear();
|
|
322
|
+
this.contentCache.clear();
|
|
323
|
+
// Clear all Maps in the pathname indexes
|
|
324
|
+
for (const locale of this.locales) {
|
|
325
|
+
this.pathnameIndex[locale].clear();
|
|
326
|
+
this.previousPathnameIndex[locale].clear();
|
|
327
|
+
}
|
|
328
|
+
this.collections.clear();
|
|
329
|
+
}
|
|
330
|
+
}
|