@krantho/server 0.0.0-stage → 1.0.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/LICENSE +21 -0
- package/dist/cdn/cloudfront.d.ts +9 -0
- package/dist/cdn/cloudfront.d.ts.map +1 -0
- package/dist/cdn/cloudfront.js +35 -0
- package/dist/cdn/cloudfront.js.map +1 -0
- package/dist/cdn/gcp.d.ts +15 -0
- package/dist/cdn/gcp.d.ts.map +1 -0
- package/dist/cdn/gcp.js +60 -0
- package/dist/cdn/gcp.js.map +1 -0
- package/dist/cdn/index.d.ts +9 -0
- package/dist/cdn/index.d.ts.map +1 -0
- package/dist/cdn/index.js +30 -0
- package/dist/cdn/index.js.map +1 -0
- package/dist/cdn/listener.d.ts +14 -0
- package/dist/cdn/listener.d.ts.map +1 -0
- package/dist/cdn/listener.js +53 -0
- package/dist/cdn/listener.js.map +1 -0
- package/dist/cdn/retry.d.ts +3 -0
- package/dist/cdn/retry.d.ts.map +1 -0
- package/dist/cdn/retry.js +17 -0
- package/dist/cdn/retry.js.map +1 -0
- package/dist/cdn/types.d.ts +12 -0
- package/dist/cdn/types.d.ts.map +1 -0
- package/dist/cdn/types.js +2 -0
- package/dist/cdn/types.js.map +1 -0
- package/dist/cdn/vercel.d.ts +9 -0
- package/dist/cdn/vercel.d.ts.map +1 -0
- package/dist/cdn/vercel.js +31 -0
- package/dist/cdn/vercel.js.map +1 -0
- package/dist/content-conflicts.d.ts +18 -0
- package/dist/content-conflicts.d.ts.map +1 -0
- package/dist/content-conflicts.js +22 -0
- package/dist/content-conflicts.js.map +1 -0
- package/dist/content-dates.d.ts +35 -0
- package/dist/content-dates.d.ts.map +1 -0
- package/dist/content-dates.js +85 -0
- package/dist/content-dates.js.map +1 -0
- package/dist/content-loader.d.ts +37 -0
- package/dist/content-loader.d.ts.map +1 -0
- package/dist/content-loader.js +223 -0
- package/dist/content-loader.js.map +1 -0
- package/dist/content-migration.d.ts +101 -0
- package/dist/content-migration.d.ts.map +1 -0
- package/dist/content-migration.js +291 -0
- package/dist/content-migration.js.map +1 -0
- package/dist/convert.d.ts +18 -0
- package/dist/convert.d.ts.map +1 -0
- package/dist/convert.js +152 -0
- package/dist/convert.js.map +1 -0
- package/dist/file-store.d.ts +11 -0
- package/dist/file-store.d.ts.map +1 -0
- package/dist/file-store.js +39 -0
- package/dist/file-store.js.map +1 -0
- package/dist/file-watcher.d.ts +19 -0
- package/dist/file-watcher.d.ts.map +1 -0
- package/dist/file-watcher.js +99 -0
- package/dist/file-watcher.js.map +1 -0
- package/dist/handler.d.ts +61 -0
- package/dist/handler.d.ts.map +1 -0
- package/dist/handler.js +197 -0
- package/dist/handler.js.map +1 -0
- package/dist/import.d.ts +25 -0
- package/dist/import.d.ts.map +1 -0
- package/dist/import.js +71 -0
- package/dist/import.js.map +1 -0
- package/dist/index.d.ts +28 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +19 -0
- package/dist/index.js.map +1 -0
- package/dist/indexnow.d.ts +38 -0
- package/dist/indexnow.d.ts.map +1 -0
- package/dist/indexnow.js +89 -0
- package/dist/indexnow.js.map +1 -0
- package/dist/lazy-handler.d.ts +7 -0
- package/dist/lazy-handler.d.ts.map +1 -0
- package/dist/lazy-handler.js +16 -0
- package/dist/lazy-handler.js.map +1 -0
- package/dist/llm-seed.d.ts +25 -0
- package/dist/llm-seed.d.ts.map +1 -0
- package/dist/llm-seed.js +42 -0
- package/dist/llm-seed.js.map +1 -0
- package/dist/lock-adapters.d.ts +21 -0
- package/dist/lock-adapters.d.ts.map +1 -0
- package/dist/lock-adapters.js +69 -0
- package/dist/lock-adapters.js.map +1 -0
- package/dist/manifest.d.ts +15 -0
- package/dist/manifest.d.ts.map +1 -0
- package/dist/manifest.js +39 -0
- package/dist/manifest.js.map +1 -0
- package/dist/mime-types.d.ts +3 -0
- package/dist/mime-types.d.ts.map +1 -0
- package/dist/mime-types.js +15 -0
- package/dist/mime-types.js.map +1 -0
- package/dist/page-cache-rules.d.ts +41 -0
- package/dist/page-cache-rules.d.ts.map +1 -0
- package/dist/page-cache-rules.js +94 -0
- package/dist/page-cache-rules.js.map +1 -0
- package/dist/page-cache-store.d.ts +11 -0
- package/dist/page-cache-store.d.ts.map +1 -0
- package/dist/page-cache-store.js +46 -0
- package/dist/page-cache-store.js.map +1 -0
- package/dist/page-request.d.ts +26 -0
- package/dist/page-request.d.ts.map +1 -0
- package/dist/page-request.js +29 -0
- package/dist/page-request.js.map +1 -0
- package/dist/persistence.d.ts +36 -0
- package/dist/persistence.d.ts.map +1 -0
- package/dist/persistence.js +108 -0
- package/dist/persistence.js.map +1 -0
- package/dist/preview-token.d.ts +9 -0
- package/dist/preview-token.d.ts.map +1 -0
- package/dist/preview-token.js +14 -0
- package/dist/preview-token.js.map +1 -0
- package/dist/read-cache.d.ts +17 -0
- package/dist/read-cache.d.ts.map +1 -0
- package/dist/read-cache.js +33 -0
- package/dist/read-cache.js.map +1 -0
- package/dist/route-matcher.d.ts +21 -0
- package/dist/route-matcher.d.ts.map +1 -0
- package/dist/route-matcher.js +75 -0
- package/dist/route-matcher.js.map +1 -0
- package/dist/secret-vault.d.ts +20 -0
- package/dist/secret-vault.d.ts.map +1 -0
- package/dist/secret-vault.js +60 -0
- package/dist/secret-vault.js.map +1 -0
- package/dist/seo-config-io.d.ts +51 -0
- package/dist/seo-config-io.d.ts.map +1 -0
- package/dist/seo-config-io.js +151 -0
- package/dist/seo-config-io.js.map +1 -0
- package/dist/seo-seed.d.ts +12 -0
- package/dist/seo-seed.d.ts.map +1 -0
- package/dist/seo-seed.js +100 -0
- package/dist/seo-seed.js.map +1 -0
- package/dist/studio-gate.d.ts +25 -0
- package/dist/studio-gate.d.ts.map +1 -0
- package/dist/studio-gate.js +70 -0
- package/dist/studio-gate.js.map +1 -0
- package/dist/studio.d.ts +17 -0
- package/dist/studio.d.ts.map +1 -0
- package/dist/studio.js +107 -0
- package/dist/studio.js.map +1 -0
- package/dist/webhook-sweep.d.ts +22 -0
- package/dist/webhook-sweep.d.ts.map +1 -0
- package/dist/webhook-sweep.js +33 -0
- package/dist/webhook-sweep.js.map +1 -0
- package/package.json +87 -3
- package/README.md +0 -3
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import type { IPublishedContentLoader, IPublishedSeoLoader } from '@krantho/core';
|
|
2
|
+
import type { KranthoHandlerOptions } from './handler.js';
|
|
3
|
+
/** What server-rendered pages read: published content, the pages' SEO, and a preview view */
|
|
4
|
+
export interface ContentLoader extends IPublishedContentLoader, IPublishedSeoLoader {
|
|
5
|
+
/**
|
|
6
|
+
* The same reads for an editor's preview: a document and its JSON-LD come
|
|
7
|
+
* from its current version, draft included, and nothing is cached
|
|
8
|
+
*/
|
|
9
|
+
readonly preview: IPublishedContentLoader & IPublishedSeoLoader;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Create the content loader server-rendered pages read through.
|
|
13
|
+
*
|
|
14
|
+
* Pages read only the live (published) version of a document — never a newer
|
|
15
|
+
* draft — by collection, slug and locale; an omitted locale is the site's
|
|
16
|
+
* default. The loader takes the configuration and collections the API handler
|
|
17
|
+
* takes, opens persistence through the same factory, and runs the same startup
|
|
18
|
+
* content import and SEO seed before its first read returns — so pages and the
|
|
19
|
+
* API read one database, and a fresh one is filled and configured whichever of
|
|
20
|
+
* them a deployment serves first. The adapter opens on the first read, not at
|
|
21
|
+
* import time, and a failed open is retried on the next read. Reads are cached
|
|
22
|
+
* per `content.cache`, except with `cache.pages: 'next-isr'`, where Next.js
|
|
23
|
+
* caches them, and with `cache.pages: 'cdn'`, where
|
|
24
|
+
* the CDN caches the pages: a publish purges the CDN, and the next render must
|
|
25
|
+
* read the new version, not a cached one the CDN would then keep.
|
|
26
|
+
*
|
|
27
|
+
* It also serves the pages' SEO: configuration properties, and each page's
|
|
28
|
+
* JSON-LD composed from its published fields — in-process, the way the API's
|
|
29
|
+
* preview composes it, so no page calls the site's own API. Its `preview` view
|
|
30
|
+
* reads the current version instead, for an editor previewing a draft.
|
|
31
|
+
*
|
|
32
|
+
* Inside `runPageRequest()` every read records its cache tags into the
|
|
33
|
+
* request, and a preview request reads through the `preview` view;
|
|
34
|
+
* `isPreview()` says which a render reads.
|
|
35
|
+
*/
|
|
36
|
+
export declare function createContentLoader(options: Pick<KranthoHandlerOptions, 'config' | 'collections'>): ContentLoader;
|
|
37
|
+
//# sourceMappingURL=content-loader.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"content-loader.d.ts","sourceRoot":"","sources":["../src/content-loader.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAEV,uBAAuB,EACvB,mBAAmB,EAGpB,MAAM,eAAe,CAAA;AAoBtB,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,cAAc,CAAA;AAWzD,6FAA6F;AAC7F,MAAM,WAAW,aAAc,SAAQ,uBAAuB,EAAE,mBAAmB;IACjF;;;OAGG;IACH,QAAQ,CAAC,OAAO,EAAE,uBAAuB,GAAG,mBAAmB,CAAA;CAChE;AAmBD;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,wBAAgB,mBAAmB,CACjC,OAAO,EAAE,IAAI,CAAC,qBAAqB,EAAE,QAAQ,GAAG,aAAa,CAAC,GAC7D,aAAa,CA4Cf"}
|
|
@@ -0,0 +1,223 @@
|
|
|
1
|
+
import { mkdir } from 'node:fs/promises';
|
|
2
|
+
import { dirname } from 'node:path';
|
|
3
|
+
import { composePageJsonLd } from '@krantho/api';
|
|
4
|
+
import { loadConfig } from '@krantho/config/node';
|
|
5
|
+
import { documentPath, documentReadTags, jsonLdTags, listReadTags, pageCollection, seoReadTags, } from '@krantho/core';
|
|
6
|
+
import { canGetContent, canReadPublished } from '@krantho/persistence';
|
|
7
|
+
import { defineConfig } from '@krantho/schema';
|
|
8
|
+
import { documentSeoProperties } from '@krantho/seo-shared';
|
|
9
|
+
import { importRepositoryContent } from './content-migration.js';
|
|
10
|
+
import { createLockAdapters } from './lock-adapters.js';
|
|
11
|
+
import { inPreviewRequest, recordReadTags } from './page-request.js';
|
|
12
|
+
import { createAdapter } from './persistence.js';
|
|
13
|
+
import { createReadCache } from './read-cache.js';
|
|
14
|
+
import { seedSeoOnce } from './seo-seed.js';
|
|
15
|
+
const liveVersion = (reader, ref, locale) => reader.getPublished(ref.collection, ref.slug, locale);
|
|
16
|
+
const currentVersion = async (reader, ref, locale) => {
|
|
17
|
+
// Every database adapter reads single documents; one that cannot previews nothing
|
|
18
|
+
if (!canGetContent(reader))
|
|
19
|
+
return null;
|
|
20
|
+
const doc = await reader.getContent(ref.collection, ref.slug, locale);
|
|
21
|
+
return doc && doc.meta.status !== 'deleted' ? doc : null;
|
|
22
|
+
};
|
|
23
|
+
/**
|
|
24
|
+
* Create the content loader server-rendered pages read through.
|
|
25
|
+
*
|
|
26
|
+
* Pages read only the live (published) version of a document — never a newer
|
|
27
|
+
* draft — by collection, slug and locale; an omitted locale is the site's
|
|
28
|
+
* default. The loader takes the configuration and collections the API handler
|
|
29
|
+
* takes, opens persistence through the same factory, and runs the same startup
|
|
30
|
+
* content import and SEO seed before its first read returns — so pages and the
|
|
31
|
+
* API read one database, and a fresh one is filled and configured whichever of
|
|
32
|
+
* them a deployment serves first. The adapter opens on the first read, not at
|
|
33
|
+
* import time, and a failed open is retried on the next read. Reads are cached
|
|
34
|
+
* per `content.cache`, except with `cache.pages: 'next-isr'`, where Next.js
|
|
35
|
+
* caches them, and with `cache.pages: 'cdn'`, where
|
|
36
|
+
* the CDN caches the pages: a publish purges the CDN, and the next render must
|
|
37
|
+
* read the new version, not a cached one the CDN would then keep.
|
|
38
|
+
*
|
|
39
|
+
* It also serves the pages' SEO: configuration properties, and each page's
|
|
40
|
+
* JSON-LD composed from its published fields — in-process, the way the API's
|
|
41
|
+
* preview composes it, so no page calls the site's own API. Its `preview` view
|
|
42
|
+
* reads the current version instead, for an editor previewing a draft.
|
|
43
|
+
*
|
|
44
|
+
* Inside `runPageRequest()` every read records its cache tags into the
|
|
45
|
+
* request, and a preview request reads through the `preview` view;
|
|
46
|
+
* `isPreview()` says which a render reads.
|
|
47
|
+
*/
|
|
48
|
+
export function createContentLoader(options) {
|
|
49
|
+
let resolved;
|
|
50
|
+
let opening = null;
|
|
51
|
+
let cache;
|
|
52
|
+
function settings() {
|
|
53
|
+
resolved ??= loadConfig({ code: options.config, env: process.env });
|
|
54
|
+
return resolved;
|
|
55
|
+
}
|
|
56
|
+
function store() {
|
|
57
|
+
opening ??= openStore(settings(), defineConfig({ collections: options.collections })).catch((err) => {
|
|
58
|
+
opening = null;
|
|
59
|
+
throw err;
|
|
60
|
+
});
|
|
61
|
+
return opening;
|
|
62
|
+
}
|
|
63
|
+
function reads() {
|
|
64
|
+
// With Next.js ISR, Next's data cache is the only page-side cache; behind a CDN, the CDN is
|
|
65
|
+
const { content, cache: pageCache } = settings();
|
|
66
|
+
const cachedElsewhere = pageCache.pages === 'next-isr' || pageCache.pages === 'cdn';
|
|
67
|
+
cache ??= createReadCache(cachedElsewhere ? { ...content.cache, enabled: false } : content.cache);
|
|
68
|
+
return cache;
|
|
69
|
+
}
|
|
70
|
+
const uncached = createReadCache({ enabled: false, ttlMs: 0, maxEntries: 1 });
|
|
71
|
+
const view = (version, isPreview, cached) => readView({
|
|
72
|
+
settings,
|
|
73
|
+
store,
|
|
74
|
+
version,
|
|
75
|
+
preview: isPreview,
|
|
76
|
+
cache: cached,
|
|
77
|
+
collections: options.collections,
|
|
78
|
+
});
|
|
79
|
+
const live = view(liveVersion, false, reads);
|
|
80
|
+
const preview = view(currentVersion, true, () => uncached);
|
|
81
|
+
return { ...previewInScope(live, preview), preview };
|
|
82
|
+
}
|
|
83
|
+
/** The live view, served from the preview view while a preview page request runs */
|
|
84
|
+
function previewInScope(live, preview) {
|
|
85
|
+
const active = () => (inPreviewRequest() ? preview : live);
|
|
86
|
+
return {
|
|
87
|
+
isPreview: () => active().isPreview(),
|
|
88
|
+
getPublished: (ref) => active().getPublished(ref),
|
|
89
|
+
listPublished: (collection, locale) => active().listPublished(collection, locale),
|
|
90
|
+
listPublishedSummaries: (collection, locale) => active().listPublishedSummaries(collection, locale),
|
|
91
|
+
seoProperties: (configId, locale) => active().seoProperties(configId, locale),
|
|
92
|
+
jsonLd: (ref, structure) => active().jsonLd(ref, structure),
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* The site's identity from configuration, which the primary site entity
|
|
97
|
+
* carries unless its SEO settings set a value of their own
|
|
98
|
+
*/
|
|
99
|
+
function siteIdentity(site) {
|
|
100
|
+
const identity = { name: site.name, url: site.baseUrl };
|
|
101
|
+
if (site.logo)
|
|
102
|
+
identity['logo'] = site.logo;
|
|
103
|
+
if (site.description)
|
|
104
|
+
identity['description'] = site.description;
|
|
105
|
+
if (site.alternateName)
|
|
106
|
+
identity['alternateName'] = site.alternateName;
|
|
107
|
+
if (site.sameAs.length > 0)
|
|
108
|
+
identity['sameAs'] = site.sameAs;
|
|
109
|
+
return identity;
|
|
110
|
+
}
|
|
111
|
+
/** The page reads over one version of each document; each records its tags into the page request */
|
|
112
|
+
function readView({ settings, store, version, preview, cache, collections, }) {
|
|
113
|
+
const localeOf = (ref) => ref.locale ?? settings().site.defaultLocale;
|
|
114
|
+
return {
|
|
115
|
+
isPreview: async () => preview,
|
|
116
|
+
getPublished: (ref) => {
|
|
117
|
+
recordReadTags(documentReadTags(ref.collection, ref.slug));
|
|
118
|
+
const locale = localeOf(ref);
|
|
119
|
+
return cache().read(`doc:${ref.collection}:${ref.slug}:${locale}`, async () => {
|
|
120
|
+
const doc = await version((await store()).adapter, ref, locale);
|
|
121
|
+
return doc ? toPublished(doc) : null;
|
|
122
|
+
});
|
|
123
|
+
},
|
|
124
|
+
listPublished: (collection, locale) => {
|
|
125
|
+
recordReadTags(listReadTags(collection));
|
|
126
|
+
const loc = locale ?? settings().site.defaultLocale;
|
|
127
|
+
return cache().read(`list:${collection}:${loc}`, async () => {
|
|
128
|
+
const { items } = await (await store()).adapter.query({
|
|
129
|
+
state: 'published',
|
|
130
|
+
projection: 'full',
|
|
131
|
+
collections: [collection],
|
|
132
|
+
locale: loc,
|
|
133
|
+
});
|
|
134
|
+
return items.map(toPublished);
|
|
135
|
+
});
|
|
136
|
+
},
|
|
137
|
+
listPublishedSummaries: (collection, locale) => {
|
|
138
|
+
recordReadTags(listReadTags(collection));
|
|
139
|
+
const loc = locale ?? settings().site.defaultLocale;
|
|
140
|
+
return cache().read(`summaries:${collection}:${loc}`, async () => {
|
|
141
|
+
const { items } = await (await store()).adapter.query({
|
|
142
|
+
state: 'published',
|
|
143
|
+
projection: 'summary',
|
|
144
|
+
collections: [collection],
|
|
145
|
+
locale: loc,
|
|
146
|
+
});
|
|
147
|
+
return items.map(toPublishedSummary);
|
|
148
|
+
});
|
|
149
|
+
},
|
|
150
|
+
seoProperties: (configId, locale) => {
|
|
151
|
+
recordReadTags(seoReadTags(configId));
|
|
152
|
+
return cache().read(`seo:${configId}:${locale ?? settings().site.defaultLocale}`, async () => {
|
|
153
|
+
if (configId.startsWith('doc:')) {
|
|
154
|
+
const key = configId.slice(4);
|
|
155
|
+
const slash = key.indexOf('/');
|
|
156
|
+
if (slash < 1)
|
|
157
|
+
return {};
|
|
158
|
+
const ref = { collection: key.slice(0, slash), slug: key.slice(slash + 1), locale };
|
|
159
|
+
recordReadTags(documentReadTags(ref.collection, ref.slug));
|
|
160
|
+
const doc = await version((await store()).adapter, ref, localeOf(ref));
|
|
161
|
+
return doc ? documentSeoProperties(doc.metadata) : {};
|
|
162
|
+
}
|
|
163
|
+
const entry = await (await store()).seoConfigs?.getConfig(configId);
|
|
164
|
+
const properties = entry?.config.entities[0]?.properties ?? {};
|
|
165
|
+
return configId === 'site'
|
|
166
|
+
? { ...siteIdentity(settings().site), ...properties }
|
|
167
|
+
: properties;
|
|
168
|
+
});
|
|
169
|
+
},
|
|
170
|
+
// Document SEO configuration is per document, shared by its locales; the
|
|
171
|
+
// graph is composed from the requested locale's fields.
|
|
172
|
+
jsonLd: (ref, structure) => {
|
|
173
|
+
recordReadTags(jsonLdTags(ref.collection, ref.slug));
|
|
174
|
+
const locale = localeOf(ref);
|
|
175
|
+
const shape = structure ? `:${JSON.stringify(structure)}` : '';
|
|
176
|
+
return cache().read(`jsonld:${ref.collection}:${ref.slug}:${locale}${shape}`, async () => {
|
|
177
|
+
const { adapter, seoConfigs } = await store();
|
|
178
|
+
const doc = await version(adapter, ref, locale);
|
|
179
|
+
if (!doc)
|
|
180
|
+
return null;
|
|
181
|
+
return composePageJsonLd({
|
|
182
|
+
collection: ref.collection,
|
|
183
|
+
slug: ref.slug,
|
|
184
|
+
path: documentPath(pageCollection(collections, ref.collection), ref.slug),
|
|
185
|
+
fields: doc.fields,
|
|
186
|
+
metadata: doc.metadata,
|
|
187
|
+
documentMeta: doc.meta,
|
|
188
|
+
config: settings(),
|
|
189
|
+
seoConfigs,
|
|
190
|
+
structure,
|
|
191
|
+
});
|
|
192
|
+
});
|
|
193
|
+
},
|
|
194
|
+
};
|
|
195
|
+
}
|
|
196
|
+
async function openStore(config, contentConfig) {
|
|
197
|
+
if (config.persistence.provider === 'sqlite') {
|
|
198
|
+
await mkdir(dirname(config.persistence.sqlite.path), { recursive: true });
|
|
199
|
+
}
|
|
200
|
+
const { adapter, lockDb, contentMigrationAdapter, checkpointAdapter } = await createAdapter(config.persistence, config.site, config.content, contentConfig.collections);
|
|
201
|
+
await importRepositoryContent(adapter, contentConfig, contentMigrationAdapter, checkpointAdapter, config.paths.contentDir, config.content.defaultStatus.filesystem);
|
|
202
|
+
if (!canReadPublished(adapter)) {
|
|
203
|
+
throw new Error(`The ${config.persistence.provider} persistence adapter cannot read published content`);
|
|
204
|
+
}
|
|
205
|
+
const { seoConfigAdapter } = await createLockAdapters(lockDb, config.persistence.provider);
|
|
206
|
+
if (seoConfigAdapter)
|
|
207
|
+
await seedSeoOnce(config, seoConfigAdapter);
|
|
208
|
+
return { adapter, seoConfigs: seoConfigAdapter };
|
|
209
|
+
}
|
|
210
|
+
function toPublishedSummary(doc) {
|
|
211
|
+
return {
|
|
212
|
+
collection: doc.meta.collection,
|
|
213
|
+
slug: doc.meta.slug,
|
|
214
|
+
locale: doc.meta.locale,
|
|
215
|
+
metadata: doc.metadata,
|
|
216
|
+
fields: doc.fields,
|
|
217
|
+
publishedAt: new Date(doc.meta.createdAt),
|
|
218
|
+
};
|
|
219
|
+
}
|
|
220
|
+
function toPublished(doc) {
|
|
221
|
+
return { ...toPublishedSummary(doc), body: doc.body };
|
|
222
|
+
}
|
|
223
|
+
//# sourceMappingURL=content-loader.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"content-loader.js","sourceRoot":"","sources":["../src/content-loader.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,kBAAkB,CAAA;AACxC,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAA;AACnC,OAAO,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAA;AAEhD,OAAO,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAA;AAQjD,OAAO,EACL,YAAY,EACZ,gBAAgB,EAChB,UAAU,EACV,YAAY,EACZ,cAAc,EACd,WAAW,GACZ,MAAM,eAAe,CAAA;AAOtB,OAAO,EAAE,aAAa,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAA;AAEtE,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAA;AAC9C,OAAO,EAAE,qBAAqB,EAAE,MAAM,qBAAqB,CAAA;AAC3D,OAAO,EAAE,uBAAuB,EAAE,MAAM,wBAAwB,CAAA;AAEhE,OAAO,EAAE,kBAAkB,EAAE,MAAM,oBAAoB,CAAA;AACvD,OAAO,EAAE,gBAAgB,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAA;AACpE,OAAO,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAA;AAEhD,OAAO,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAA;AACjD,OAAO,EAA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AAED,SAAS,WAAW,CAAC,GAAoB;IACvC,OAAO,EAAE,GAAG,kBAAkB,CAAC,GAAG,CAAC,EAAE,IAAI,EAAE,GAAG,CAAC,IAAI,EAAE,CAAA;AACvD,CAAC"}
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
import { type ContentDocument, type ContentManifest, type ICheckpointAdapter, type IContentMigrationAdapter, type IPersistenceAdapter, type ISiteSettingsAdapter } from '@krantho/persistence';
|
|
2
|
+
import { type ContentConfig, type ParsedRepositoryContent } from '@krantho/schema';
|
|
3
|
+
import type { ImportableAdapter } from './import.js';
|
|
4
|
+
/** An adapter the migration can import into and read each document's current version from */
|
|
5
|
+
export interface MigratableAdapter extends ImportableAdapter {
|
|
6
|
+
getContent(collection: string, slug: string, locale?: string | undefined): Promise<ContentDocument | null>;
|
|
7
|
+
}
|
|
8
|
+
/** What the migration did with one content file */
|
|
9
|
+
export type FileOutcome =
|
|
10
|
+
/** New or changed in the repository, and not edited in Studio: imported */
|
|
11
|
+
'imported'
|
|
12
|
+
/** The database already holds the file's content */
|
|
13
|
+
| 'unchanged'
|
|
14
|
+
/** Edited in Studio while the file stayed the same: the editor's version stands */
|
|
15
|
+
| 'kept'
|
|
16
|
+
/** Changed in the repository and edited in Studio: recorded as a conflict */
|
|
17
|
+
| 'conflict'
|
|
18
|
+
/** Imported before and deleted in Studio since: stays deleted */
|
|
19
|
+
| 'deleted'
|
|
20
|
+
/** The file fails its collection's schema */
|
|
21
|
+
| 'rejected';
|
|
22
|
+
/** Per-file migration detail */
|
|
23
|
+
export interface ImportDetail {
|
|
24
|
+
collection: string;
|
|
25
|
+
slug: string;
|
|
26
|
+
outcome: FileOutcome;
|
|
27
|
+
}
|
|
28
|
+
/** Result of running content migration on startup */
|
|
29
|
+
export interface ContentMigrationResult {
|
|
30
|
+
action: 'skip' | 'full-import' | 'migrate';
|
|
31
|
+
imported: number;
|
|
32
|
+
conflicts: number;
|
|
33
|
+
rejected: number;
|
|
34
|
+
checkpointVersion: number | null;
|
|
35
|
+
reason?: string | undefined;
|
|
36
|
+
details: ImportDetail[];
|
|
37
|
+
}
|
|
38
|
+
/** A content file read from the repository, ready to compare and import */
|
|
39
|
+
interface RepositoryFile {
|
|
40
|
+
key: string;
|
|
41
|
+
collection: string;
|
|
42
|
+
slug: string;
|
|
43
|
+
filePath: string;
|
|
44
|
+
/** SHA-256 of the file as it is on disk — what the manifest records */
|
|
45
|
+
fileChecksum: string;
|
|
46
|
+
/** Schema-validated fields, or null when the file fails its schema */
|
|
47
|
+
fields: Record<string, unknown> | null;
|
|
48
|
+
/** Why the file fails its schema */
|
|
49
|
+
issues: readonly string[];
|
|
50
|
+
body: string;
|
|
51
|
+
document?: ParsedRepositoryContent | undefined;
|
|
52
|
+
status?: string | undefined;
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Bring the database up to date with the repository's content on startup.
|
|
56
|
+
*
|
|
57
|
+
* Without `<contentDir>/manifest.json` (or a migration adapter) the content is
|
|
58
|
+
* imported into an empty database only. With one, every deployment whose
|
|
59
|
+
* manifest is newer than the database's compares each file with its document:
|
|
60
|
+
* a new or changed file is imported, unless an editor changed the document in
|
|
61
|
+
* Studio since — then the editor's version stands and a changed file is
|
|
62
|
+
* recorded as a conflict. A document deleted in Studio stays deleted.
|
|
63
|
+
*/
|
|
64
|
+
export declare function runContentMigration(adapter: MigratableAdapter, contentConfig: ContentConfig, migrationAdapter: IContentMigrationAdapter | undefined, checkpointAdapter: ICheckpointAdapter | undefined, contentDir: string, defaultStatus?: string): Promise<ContentMigrationResult>;
|
|
65
|
+
/**
|
|
66
|
+
* What to do with one repository file, given its document's current version
|
|
67
|
+
* and the file's checksum when the database last took the repository's
|
|
68
|
+
* content (undefined: the database never saw this file).
|
|
69
|
+
*
|
|
70
|
+
* Content equal to a state the repository held (the document's basis, or what
|
|
71
|
+
* the last deployment took) is not an edit: a document that carries the
|
|
72
|
+
* repository's previous file, as one does after a pull of production's edits was
|
|
73
|
+
* merged, is not reported as edited, and a file at that state is not reported as changed.
|
|
74
|
+
*
|
|
75
|
+
* A version an import wrote is not an edit either, whatever its checksum: nobody changed it since,
|
|
76
|
+
* even when it predates the document's basis and contract. A restore copies the restored version's
|
|
77
|
+
* source but always names who restored it, so only a version with no `changedBy` is an import's.
|
|
78
|
+
*/
|
|
79
|
+
export declare function decideFile(file: Pick<RepositoryFile, 'fileChecksum' | 'fields' | 'body' | 'document'>, current: ContentDocument | null, previousChecksum: string | undefined): FileOutcome;
|
|
80
|
+
/** Read `<contentDir>/manifest.json`, or null when the build wrote none */
|
|
81
|
+
export declare function loadManifest(contentDir: string): Promise<ContentManifest | null>;
|
|
82
|
+
/** Canonical authored content checksum, independent of YAML spelling and key order. */
|
|
83
|
+
export declare function contentChecksum(fields: Record<string, unknown>, body: string): string;
|
|
84
|
+
/**
|
|
85
|
+
* Import the repository's content into the database when it needs it (an
|
|
86
|
+
* empty database, or a newer content manifest), logging what happened. Both
|
|
87
|
+
* the API handler and the page loader run it on first use, so whichever a
|
|
88
|
+
* fresh deployment serves first finds the content in place.
|
|
89
|
+
*
|
|
90
|
+
* @returns how many documents were imported
|
|
91
|
+
*/
|
|
92
|
+
export declare function importRepositoryContent(adapter: IPersistenceAdapter, contentConfig: ContentConfig, migrationAdapter: IContentMigrationAdapter | undefined, checkpointAdapter: ICheckpointAdapter | undefined, contentDir: string, defaultStatus?: string): Promise<number>;
|
|
93
|
+
/**
|
|
94
|
+
* Whether the database holds a content version the site has not announced
|
|
95
|
+
* yet, recording it as announced. The page loader can import a deployment's
|
|
96
|
+
* content before the API handler starts, and only the handler can announce a
|
|
97
|
+
* change, so it announces each new content version once, whoever imported it.
|
|
98
|
+
*/
|
|
99
|
+
export declare function claimContentAnnouncement(migrationAdapter: IContentMigrationAdapter | undefined, settings: ISiteSettingsAdapter | undefined): Promise<boolean>;
|
|
100
|
+
export {};
|
|
101
|
+
//# sourceMappingURL=content-migration.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{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