@velocity-astro/cms-astro 0.0.0-stage → 0.1.0-beta.11
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/README.md +12 -2
- package/bin/velocity-cms.mjs +6 -0
- package/dist/admin-files.d.ts +21 -0
- package/dist/admin-files.d.ts.map +1 -0
- package/dist/admin-files.js +83 -0
- package/dist/admin-files.js.map +1 -0
- package/dist/challenge.d.ts +35 -0
- package/dist/challenge.d.ts.map +1 -0
- package/dist/challenge.js +84 -0
- package/dist/challenge.js.map +1 -0
- package/dist/cli.d.ts +9 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +76 -0
- package/dist/cli.js.map +1 -0
- package/dist/connection.d.ts +26 -0
- package/dist/connection.d.ts.map +1 -0
- package/dist/connection.js +87 -0
- package/dist/connection.js.map +1 -0
- package/dist/editor.d.ts +67 -0
- package/dist/editor.d.ts.map +1 -0
- package/dist/editor.js +194 -0
- package/dist/editor.js.map +1 -0
- package/dist/entry-page.d.ts +37 -0
- package/dist/entry-page.d.ts.map +1 -0
- package/dist/entry-page.js +56 -0
- package/dist/entry-page.js.map +1 -0
- package/dist/form-post.d.ts +114 -0
- package/dist/form-post.d.ts.map +1 -0
- package/dist/form-post.js +298 -0
- package/dist/form-post.js.map +1 -0
- package/dist/hosted.d.ts +76 -0
- package/dist/hosted.d.ts.map +1 -0
- package/dist/hosted.js +104 -0
- package/dist/hosted.js.map +1 -0
- package/dist/image-optimizer.d.ts +35 -0
- package/dist/image-optimizer.d.ts.map +1 -0
- package/dist/image-optimizer.js +76 -0
- package/dist/image-optimizer.js.map +1 -0
- package/dist/index.d.ts +34 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +34 -0
- package/dist/index.js.map +1 -0
- package/dist/init.d.ts +35 -0
- package/dist/init.d.ts.map +1 -0
- package/dist/init.js +140 -0
- package/dist/init.js.map +1 -0
- package/dist/integration.d.ts +72 -0
- package/dist/integration.d.ts.map +1 -0
- package/dist/integration.js +143 -0
- package/dist/integration.js.map +1 -0
- package/dist/link.d.ts +32 -0
- package/dist/link.d.ts.map +1 -0
- package/dist/link.js +80 -0
- package/dist/link.js.map +1 -0
- package/dist/live-loader.d.ts +44 -0
- package/dist/live-loader.d.ts.map +1 -0
- package/dist/live-loader.js +98 -0
- package/dist/live-loader.js.map +1 -0
- package/dist/live-pages.d.ts +69 -0
- package/dist/live-pages.d.ts.map +1 -0
- package/dist/live-pages.js +94 -0
- package/dist/live-pages.js.map +1 -0
- package/dist/loader.d.ts +22 -0
- package/dist/loader.d.ts.map +1 -0
- package/dist/loader.js +62 -0
- package/dist/loader.js.map +1 -0
- package/dist/media-store.d.ts +61 -0
- package/dist/media-store.d.ts.map +1 -0
- package/dist/media-store.js +178 -0
- package/dist/media-store.js.map +1 -0
- package/dist/menu.d.ts +51 -0
- package/dist/menu.d.ts.map +1 -0
- package/dist/menu.js +81 -0
- package/dist/menu.js.map +1 -0
- package/dist/page-head.d.ts +23 -0
- package/dist/page-head.d.ts.map +1 -0
- package/dist/page-head.js +66 -0
- package/dist/page-head.js.map +1 -0
- package/dist/page-marks.d.ts +50 -0
- package/dist/page-marks.d.ts.map +1 -0
- package/dist/page-marks.js +90 -0
- package/dist/page-marks.js.map +1 -0
- package/dist/preview.d.ts +92 -0
- package/dist/preview.d.ts.map +1 -0
- package/dist/preview.js +192 -0
- package/dist/preview.js.map +1 -0
- package/dist/resend-mailer.d.ts +63 -0
- package/dist/resend-mailer.d.ts.map +1 -0
- package/dist/resend-mailer.js +116 -0
- package/dist/resend-mailer.js.map +1 -0
- package/dist/secret.d.ts +8 -0
- package/dist/secret.d.ts.map +1 -0
- package/dist/secret.js +17 -0
- package/dist/secret.js.map +1 -0
- package/dist/single.d.ts +18 -0
- package/dist/single.d.ts.map +1 -0
- package/dist/single.js +37 -0
- package/dist/single.js.map +1 -0
- package/dist/site-editor.d.ts +41 -0
- package/dist/site-editor.d.ts.map +1 -0
- package/dist/site-editor.js +140 -0
- package/dist/site-editor.js.map +1 -0
- package/dist/site-forms.d.ts +54 -0
- package/dist/site-forms.d.ts.map +1 -0
- package/dist/site-forms.js +100 -0
- package/dist/site-forms.js.map +1 -0
- package/dist/site-images.d.ts +17 -0
- package/dist/site-images.d.ts.map +1 -0
- package/dist/site-images.js +22 -0
- package/dist/site-images.js.map +1 -0
- package/dist/site-mail.d.ts +45 -0
- package/dist/site-mail.d.ts.map +1 -0
- package/dist/site-mail.js +84 -0
- package/dist/site-mail.js.map +1 -0
- package/dist/site-media.d.ts +22 -0
- package/dist/site-media.d.ts.map +1 -0
- package/dist/site-media.js +52 -0
- package/dist/site-media.js.map +1 -0
- package/dist/site-name.d.ts +9 -0
- package/dist/site-name.d.ts.map +1 -0
- package/dist/site-name.js +21 -0
- package/dist/site-name.js.map +1 -0
- package/dist/site-plugins.d.ts +10 -0
- package/dist/site-plugins.d.ts.map +1 -0
- package/dist/site-plugins.js +23 -0
- package/dist/site-plugins.js.map +1 -0
- package/dist/site-search.d.ts +12 -0
- package/dist/site-search.d.ts.map +1 -0
- package/dist/site-search.js +79 -0
- package/dist/site-search.js.map +1 -0
- package/dist/site-storage.d.ts +34 -0
- package/dist/site-storage.d.ts.map +1 -0
- package/dist/site-storage.js +118 -0
- package/dist/site-storage.js.map +1 -0
- package/package.json +56 -3
- package/routes/admin.ts +10 -0
- package/routes/api.ts +15 -0
- package/routes/auth.ts +10 -0
- package/routes/due.ts +12 -0
- package/routes/editor.ts +49 -0
- package/routes/form-client.js.ts +173 -0
- package/routes/media.ts +10 -0
- package/routes/pages.ts +13 -0
- package/routes/plugins.ts +10 -0
- package/routes/preview-client.js.ts +18 -0
- package/routes/published.ts +29 -0
- package/routes/schedule.ts +20 -0
- package/routes/search-client.js.ts +33 -0
- package/routes/search.json.ts +10 -0
- package/routes/share-image.png.ts +33 -0
- package/routes/sitemap-live.xml.ts +16 -0
- package/routes/sites.ts +11 -0
- package/routes/submit.ts +22 -0
package/dist/link.js
ADDED
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import { isSafeLink, pageAddress } from '@velocity-astro/cms-core';
|
|
2
|
+
import { sharedConnection, SITE } from './connection.js';
|
|
3
|
+
import { isPreview, noteLinkLeads } from './preview.js';
|
|
4
|
+
/** The language of the pages at a type's `urlPattern`. */
|
|
5
|
+
export const DEFAULT_LOCALE = 'en';
|
|
6
|
+
const PAGE_SIZE = 500;
|
|
7
|
+
const isRecord = (value) => typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
8
|
+
const leaves = (href) => /^[a-z][a-z0-9+.-]*:/i.test(href);
|
|
9
|
+
/** Every entry of a type. */
|
|
10
|
+
export async function entriesOf(cms, type) {
|
|
11
|
+
const entries = [];
|
|
12
|
+
for (let offset = 0;; offset += PAGE_SIZE) {
|
|
13
|
+
const page = await cms.content.find(SITE, { typeId: type.id, limit: PAGE_SIZE, offset });
|
|
14
|
+
entries.push(...page.items);
|
|
15
|
+
if (offset + page.items.length >= page.total || page.items.length === 0)
|
|
16
|
+
break;
|
|
17
|
+
}
|
|
18
|
+
return entries;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Turns the values of `link` fields into addresses for pages in one language. A type's entries
|
|
22
|
+
* are read once however many links point there, so make one for a page and use it for every link.
|
|
23
|
+
* `preview` follows the versions being worked on.
|
|
24
|
+
*/
|
|
25
|
+
export function linkResolver(cms, locale, preview = false) {
|
|
26
|
+
let types;
|
|
27
|
+
const read = new Map();
|
|
28
|
+
return async (link) => {
|
|
29
|
+
// An address typed where a link is now chosen, kept from before, still leads where it did.
|
|
30
|
+
if (typeof link === 'string')
|
|
31
|
+
return link.trim() !== '' && isSafeLink(link.trim()) ? { href: link.trim(), external: leaves(link.trim()) } : undefined;
|
|
32
|
+
if (!isRecord(link))
|
|
33
|
+
return undefined;
|
|
34
|
+
if (link['kind'] === 'address' && typeof link['href'] === 'string') {
|
|
35
|
+
return isSafeLink(link['href']) ? { href: link['href'], external: leaves(link['href']) } : undefined;
|
|
36
|
+
}
|
|
37
|
+
if (link['kind'] !== 'entry')
|
|
38
|
+
return undefined;
|
|
39
|
+
// A link to an entry goes to wherever that entry's page is now, in this language if it has
|
|
40
|
+
// one. An entry that is gone, or not published, has no page: there is no link.
|
|
41
|
+
types ??= cms.schema.list();
|
|
42
|
+
const type = (await types).find((candidate) => candidate.key === link['type']);
|
|
43
|
+
if (!type)
|
|
44
|
+
return undefined;
|
|
45
|
+
if (!read.has(type.id))
|
|
46
|
+
read.set(type.id, entriesOf(cms, type));
|
|
47
|
+
const versions = ((await read.get(type.id)) ?? []).filter((entry) => entry.translationGroup === link['entry']);
|
|
48
|
+
const target = versions.find((entry) => entry.locale === locale) ?? versions.find((entry) => entry.locale === DEFAULT_LOCALE);
|
|
49
|
+
const shown = target && (preview ? { slug: target.slug, data: target.data } : target.published);
|
|
50
|
+
const href = target && shown ? pageAddress(type, { locale: target.locale, slug: shown.slug, data: shown.data }, DEFAULT_LOCALE) : null;
|
|
51
|
+
return href === null ? undefined : { href, external: false };
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Where a `link` field's value leads, for the page being drawn:
|
|
56
|
+
*
|
|
57
|
+
* ```astro
|
|
58
|
+
* const button = await linkTo(Astro, buttonLink);
|
|
59
|
+
* {button && <a href={button.href}>{buttonLabel}</a>}
|
|
60
|
+
* ```
|
|
61
|
+
*
|
|
62
|
+
* A link to an entry is that entry's address today, in the page's language. It answers with
|
|
63
|
+
* nothing when the entry is not published, the address is not one a site may link to, or
|
|
64
|
+
* anything goes wrong: a page is never lost over a button.
|
|
65
|
+
*/
|
|
66
|
+
export async function linkTo(page, link) {
|
|
67
|
+
try {
|
|
68
|
+
const { cms } = await sharedConnection({});
|
|
69
|
+
const target = await linkResolver(cms, page.currentLocale ?? DEFAULT_LOCALE, isPreview())(link);
|
|
70
|
+
// Beside the editor's form, the page is told where a link to an entry leads, to find its button by.
|
|
71
|
+
if (target && isRecord(link) && typeof link['type'] === 'string' && typeof link['entry'] === 'string')
|
|
72
|
+
noteLinkLeads(link['type'], link['entry'], target.href);
|
|
73
|
+
return target;
|
|
74
|
+
}
|
|
75
|
+
catch (error) {
|
|
76
|
+
console.error('[velocity-cms] A link could not be worked out, so it is left off the page.', error);
|
|
77
|
+
return undefined;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
//# sourceMappingURL=link.js.map
|
package/dist/link.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"link.js","sourceRoot":"","sources":["../src/link.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,WAAW,EAA6C,MAAM,0BAA0B,CAAC;AAC9G,OAAO,EAAE,gBAAgB,EAAE,IAAI,EAAE,MAAM,iBAAiB,CAAC;AAEzD,OAAO,EAAE,SAAS,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAExD,0DAA0D;AAC1D,MAAM,CAAC,MAAM,cAAc,GAAG,IAAI,CAAC;AACnC,MAAM,SAAS,GAAG,GAAG,CAAC;AAStB,MAAM,QAAQ,GAAG,CAAC,KAAc,EAAoC,EAAE,CAAC,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;AAC5I,MAAM,MAAM,GAAG,CAAC,IAAY,EAAE,EAAE,CAAC,sBAAsB,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AAEnE,6BAA6B;AAC7B,MAAM,CAAC,KAAK,UAAU,SAAS,CAAC,GAAQ,EAAE,IAAoB;IAC5D,MAAM,OAAO,GAAY,EAAE,CAAC;IAC5B,KAAK,IAAI,MAAM,GAAG,CAAC,GAAI,MAAM,IAAI,SAAS,EAAE,CAAC;QAC3C,MAAM,IAAI,GAAG,MAAM,GAAG,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI,EAAE,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,EAAE,KAA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AI,EAAE,EAAE,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,IAAI,EAAE,KAAK,CAAC,IAAI,EAAE,IAAI,EAAE,KAAK,CAAC,IAAI,EAAE,EAAE,cAAc,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;QACvI,OAAO,IAAI,KAAK,IAAI,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,QAAQ,EAAE,KAAK,EAAE,CAAC;IAC/D,CAAC,CAAC;AACJ,CAAC;AAED;;;;;;;;;;;GAWG;AACH,MAAM,CAAC,KAAK,UAAU,MAAM,CAAC,IAAe,EAAE,IAAa;IACzD,IAAI,CAAC;QACH,MAAM,EAAE,GAAG,EAAE,GAAG,MAAM,gBAAgB,CAAC,EAAE,CAAC,CAAC;QAC3C,MAAM,MAAM,GAAG,MAAM,YAAY,CAAC,GAAG,EAAE,IAAI,CAAC,aAAa,IAAI,cAAc,EAAE,SAAS,EAAE,CAAC,CAAC,IAAI,CAAC,CAAC;QAChG,oGAAoG;QACpG,IAAI,MAAM,IAAI,QAAQ,CAAC,IAAI,CAAC,IAAI,OAAO,IAAI,CAAC,MAAM,CAAC,KAAK,QAAQ,IAAI,OAAO,IAAI,CAAC,OAAO,CAAC,KAAK,QAAQ;YAAE,aAAa,CAAC,IAAI,CAAC,MAAM,CAAC,EAAE,IAAI,CAAC,OAAO,CAAC,EAAE,MAAM,CAAC,IAAI,CAAC,CAAC;QAC/J,OAAO,MAAM,CAAC;IAChB,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,OAAO,CAAC,KAAK,CAAC,4EAA4E,EAAE,KAAK,CAAC,CAAC;QACnG,OAAO,SAAS,CAAC;IACnB,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import type { LiveLoader } from 'astro/loaders';
|
|
2
|
+
import { type ConnectionOptions } from './connection.js';
|
|
3
|
+
export interface CmsLiveLoaderOptions extends ConnectionOptions {
|
|
4
|
+
/** The key of the content type to load, e.g. `listings`. */
|
|
5
|
+
readonly type: string;
|
|
6
|
+
}
|
|
7
|
+
export interface CmsEntryFilter {
|
|
8
|
+
/** `<locale>/<slug>`, the same id the build-time loader gives an entry. */
|
|
9
|
+
readonly id: string;
|
|
10
|
+
}
|
|
11
|
+
export interface CmsCollectionFilter {
|
|
12
|
+
readonly locale?: string;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* The cache tag every page showing entries of a type carries, for a site that clears pages of one
|
|
16
|
+
* type itself. A publish clears the site's own tag (`siteCacheTag`), which every hint carries too.
|
|
17
|
+
*/
|
|
18
|
+
export declare const typeTag: (typeKey: string) => string;
|
|
19
|
+
/** The cache tag for one entry, for pages that show only that entry. Like `typeTag`, for a site's own use. */
|
|
20
|
+
export declare const entryTag: (typeKey: string, id: string) => string;
|
|
21
|
+
/**
|
|
22
|
+
* A number that goes up every time published content changes. Anything a site derives from live
|
|
23
|
+
* content and keeps in memory can be stored beside this number and thrown away when it moves.
|
|
24
|
+
*/
|
|
25
|
+
export declare const liveContentVersion: () => number;
|
|
26
|
+
/** Tells this server that published content changed. Called on publish, before clearing the page cache. */
|
|
27
|
+
export declare function invalidateLiveContent(): void;
|
|
28
|
+
/**
|
|
29
|
+
* A live loader: pages rendered on demand read published entries straight from the CMS, so a
|
|
30
|
+
* change shows as soon as the page's cache is cleared instead of after a rebuild.
|
|
31
|
+
*
|
|
32
|
+
* Each entry comes back with cache tags. Pass an entry to `Astro.cache.set()` and the page is
|
|
33
|
+
* cached under those tags: the site's own (`siteCacheTag`), which every publish clears, so the page
|
|
34
|
+
* is fresh at once, and the type's and the entry's, for a site that clears them itself.
|
|
35
|
+
*
|
|
36
|
+
* ```ts
|
|
37
|
+
* // src/live.config.ts
|
|
38
|
+
* export const collections = {
|
|
39
|
+
* listings: defineLiveCollection({ loader: cmsLiveLoader({ type: 'listings' }), schema }),
|
|
40
|
+
* };
|
|
41
|
+
* ```
|
|
42
|
+
*/
|
|
43
|
+
export declare function cmsLiveLoader(options: CmsLiveLoaderOptions): LiveLoader<Record<string, unknown>, CmsEntryFilter, CmsCollectionFilter>;
|
|
44
|
+
//# sourceMappingURL=live-loader.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"live-loader.d.ts","sourceRoot":"","sources":["../src/live-loader.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAEhD,OAAO,EAA0B,KAAK,iBAAiB,EAAE,MAAM,iBAAiB,CAAC;AAIjF,MAAM,WAAW,oBAAqB,SAAQ,iBAAiB;IAC7D,4DAA4D;IAC5D,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;CACvB;AAED,MAAM,WAAW,cAAc;IAC7B,2EAA2E;IAC3E,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;CACrB;AAED,MAAM,WAAW,mBAAmB;IAClC,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC;CAC1B;AAED;;;GAGG;AACH,eAAO,MAAM,OAAO,GAAI,SAAS,MAAM,KAAG,MAA0B,CAAC;AAErE,8GAA8G;AAC9G,eAAO,MAAM,QAAQ,GAAI,SAAS,MAAM,EAAE,IAAI,MAAM,KAAG,MAAgC,CAAC;AAMxF;;;GAGG;AACH,eAAO,MAAM,kBAAkB,QAAO,MAAwB,CAAC;AAE/D,2GAA2G;AAC3G,wBAAgB,qBAAqB,IAAI,IAAI,CAE5C;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,aAAa,CAC3B,OAAO,EAAE,oBAAoB,GAC5B,UAAU,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,cAAc,EAAE,mBAAmB,CAAC,CA0D1E"}
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import { isLiveType } from '@velocity-astro/cms-core';
|
|
2
|
+
import { sharedConnection, SITE } from './connection.js';
|
|
3
|
+
import { siteCacheTag } from './hosted.js';
|
|
4
|
+
import { isPreview, withPreviewDraft } from './preview.js';
|
|
5
|
+
/**
|
|
6
|
+
* The cache tag every page showing entries of a type carries, for a site that clears pages of one
|
|
7
|
+
* type itself. A publish clears the site's own tag (`siteCacheTag`), which every hint carries too.
|
|
8
|
+
*/
|
|
9
|
+
export const typeTag = (typeKey) => `cms:${typeKey}`;
|
|
10
|
+
/** The cache tag for one entry, for pages that show only that entry. Like `typeTag`, for a site's own use. */
|
|
11
|
+
export const entryTag = (typeKey, id) => `cms:${typeKey}:${id}`;
|
|
12
|
+
const PAGE_SIZE = 500;
|
|
13
|
+
let contentVersion = 0;
|
|
14
|
+
/**
|
|
15
|
+
* A number that goes up every time published content changes. Anything a site derives from live
|
|
16
|
+
* content and keeps in memory can be stored beside this number and thrown away when it moves.
|
|
17
|
+
*/
|
|
18
|
+
export const liveContentVersion = () => contentVersion;
|
|
19
|
+
/** Tells this server that published content changed. Called on publish, before clearing the page cache. */
|
|
20
|
+
export function invalidateLiveContent() {
|
|
21
|
+
contentVersion++;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* A live loader: pages rendered on demand read published entries straight from the CMS, so a
|
|
25
|
+
* change shows as soon as the page's cache is cleared instead of after a rebuild.
|
|
26
|
+
*
|
|
27
|
+
* Each entry comes back with cache tags. Pass an entry to `Astro.cache.set()` and the page is
|
|
28
|
+
* cached under those tags: the site's own (`siteCacheTag`), which every publish clears, so the page
|
|
29
|
+
* is fresh at once, and the type's and the entry's, for a site that clears them itself.
|
|
30
|
+
*
|
|
31
|
+
* ```ts
|
|
32
|
+
* // src/live.config.ts
|
|
33
|
+
* export const collections = {
|
|
34
|
+
* listings: defineLiveCollection({ loader: cmsLiveLoader({ type: 'listings' }), schema }),
|
|
35
|
+
* };
|
|
36
|
+
* ```
|
|
37
|
+
*/
|
|
38
|
+
export function cmsLiveLoader(options) {
|
|
39
|
+
const tag = typeTag(options.type);
|
|
40
|
+
const toLive = (cms, type, entry) => {
|
|
41
|
+
// A preview reads the version being worked on. Everyone else reads the published one.
|
|
42
|
+
const shown = cms.content.toPublic(type, withPreviewDraft(entry), isPreview() ? 'working' : 'published');
|
|
43
|
+
const id = `${shown.locale}/${shown.slug}`;
|
|
44
|
+
return {
|
|
45
|
+
id,
|
|
46
|
+
data: { ...shown.data, slug: shown.slug, locale: shown.locale },
|
|
47
|
+
// The site's tag first: a publish clears it, on a server of one site or of many.
|
|
48
|
+
cacheHint: { tags: [siteCacheTag(), tag, entryTag(options.type, id)], lastModified: new Date(entry.updatedAt) },
|
|
49
|
+
};
|
|
50
|
+
};
|
|
51
|
+
return {
|
|
52
|
+
name: 'velocity-cms-live',
|
|
53
|
+
async loadCollection({ filter }) {
|
|
54
|
+
try {
|
|
55
|
+
const { cms } = await sharedConnection(options);
|
|
56
|
+
const type = await cms.schema.getByKey(options.type);
|
|
57
|
+
// An archived type has no pages: its entries are kept, and shown to nobody.
|
|
58
|
+
if (!isLiveType(type))
|
|
59
|
+
return { entries: [], cacheHint: { tags: [siteCacheTag(), tag] } };
|
|
60
|
+
const entries = [];
|
|
61
|
+
for (let offset = 0;; offset += PAGE_SIZE) {
|
|
62
|
+
const page = await cms.content.find(SITE, {
|
|
63
|
+
typeId: type.id,
|
|
64
|
+
...(!isPreview() && { status: 'published' }),
|
|
65
|
+
...(filter?.locale !== undefined && { locale: filter.locale }),
|
|
66
|
+
limit: PAGE_SIZE,
|
|
67
|
+
offset,
|
|
68
|
+
});
|
|
69
|
+
entries.push(...page.items.map((entry) => toLive(cms, type, entry)));
|
|
70
|
+
if (offset + page.items.length >= page.total || page.items.length === 0)
|
|
71
|
+
break;
|
|
72
|
+
}
|
|
73
|
+
return { entries, cacheHint: { tags: [siteCacheTag(), tag] } };
|
|
74
|
+
}
|
|
75
|
+
catch (error) {
|
|
76
|
+
return { error: error instanceof Error ? error : new Error(String(error)) };
|
|
77
|
+
}
|
|
78
|
+
},
|
|
79
|
+
async loadEntry({ filter }) {
|
|
80
|
+
try {
|
|
81
|
+
const { cms } = await sharedConnection(options);
|
|
82
|
+
const type = await cms.schema.getByKey(options.type);
|
|
83
|
+
if (!isLiveType(type))
|
|
84
|
+
return undefined;
|
|
85
|
+
const separator = filter.id.indexOf('/');
|
|
86
|
+
const locale = filter.id.slice(0, separator);
|
|
87
|
+
const slug = filter.id.slice(separator + 1);
|
|
88
|
+
const version = isPreview() ? 'working' : 'published';
|
|
89
|
+
const match = await cms.content.findBySlug(SITE, { typeId: type.id, locale, slug, version });
|
|
90
|
+
return match ? toLive(cms, type, match) : undefined;
|
|
91
|
+
}
|
|
92
|
+
catch (error) {
|
|
93
|
+
return { error: error instanceof Error ? error : new Error(String(error)) };
|
|
94
|
+
}
|
|
95
|
+
},
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
//# sourceMappingURL=live-loader.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"live-loader.js","sourceRoot":"","sources":["../src/live-loader.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAmC,MAAM,0BAA0B,CAAC;AACvF,OAAO,EAAE,gBAAgB,EAAE,IAAI,EAA0B,MAAM,iBAAiB,CAAC;AACjF,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAC3C,OAAO,EAAE,SAAS,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAgB3D;;;GAGG;AACH,MAAM,CAAC,MAAM,OAAO,GAAG,CAAC,OAAe,EAAU,EAAE,CAAC,OAAO,OAAO,EAAE,CAAC;AAErE,8GAA8G;AAC9G,MAAM,CAAC,MAAM,QAAQ,GAAG,CAAC,OAAe,EAAE,EAAU,EAAU,EAAE,CAAC,OAAO,OAAO,IAAI,EAAE,EAAE,CAAC;AAExF,MAAM,SAAS,GAAG,GAAG,CAAC;AAEtB,IAAI,cAAc,GAAG,CAAC,CAAC;AAEvB;;;GAGG;AACH,MAAM,CAAC,MAAM,kBAAkB,GAAG,GAAW,EAAE,CAAC,cAAc,CAAC;AAE/D,2G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C;KACF,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
export interface StaticPath {
|
|
2
|
+
readonly params: Readonly<Record<string, string | undefined>>;
|
|
3
|
+
readonly props?: Readonly<Record<string, unknown>>;
|
|
4
|
+
}
|
|
5
|
+
/** A page file as Vite hands it over: its component, and the functions that list its addresses. */
|
|
6
|
+
export interface PageModule<Component = unknown> {
|
|
7
|
+
readonly default: Component;
|
|
8
|
+
readonly getStaticPaths?: () => readonly StaticPath[] | Promise<readonly StaticPath[]>;
|
|
9
|
+
/** What a detail page (`listings/[slug].astro`) exports once it is rendered on demand. */
|
|
10
|
+
readonly livePaths?: () => readonly StaticPath[] | Promise<readonly StaticPath[]>;
|
|
11
|
+
}
|
|
12
|
+
/** The path whose params are the ones in this request, as Astro would have matched at build time. */
|
|
13
|
+
export declare function matchParams<Path extends StaticPath>(paths: readonly Path[], params: Readonly<Record<string, string | undefined>>): Path | undefined;
|
|
14
|
+
/**
|
|
15
|
+
* Velocity gives every translated page its own catch-all route under `[lang]`, and tells them
|
|
16
|
+
* apart with `getStaticPaths`. Rendered on demand, the first of those routes would take every
|
|
17
|
+
* address. So one route takes them all and asks each page whether the address is its own.
|
|
18
|
+
*/
|
|
19
|
+
export declare function matchLocalizedPage<Component>(pages: Readonly<Record<string, PageModule<Component>>>, lang: string | undefined, rest: string | undefined): Promise<{
|
|
20
|
+
Page: Component;
|
|
21
|
+
props: Readonly<Record<string, unknown>>;
|
|
22
|
+
} | undefined>;
|
|
23
|
+
export interface LiveAddress {
|
|
24
|
+
readonly path: string;
|
|
25
|
+
/** True for a default-language page with a fixed address, which the build's own sitemap already has. */
|
|
26
|
+
readonly fixed: boolean;
|
|
27
|
+
/** False for pages the site keeps out of search engines, such as search results. */
|
|
28
|
+
readonly listed: boolean;
|
|
29
|
+
}
|
|
30
|
+
export interface PageSources {
|
|
31
|
+
/** File names of the pages with a fixed address: `/src/pages/about.astro`. */
|
|
32
|
+
readonly fixed: readonly string[];
|
|
33
|
+
/** Detail pages by file name: `/src/pages/listings/[slug].astro`. */
|
|
34
|
+
readonly detail: Readonly<Record<string, PageModule>>;
|
|
35
|
+
/** Translated pages, wherever the site keeps them. */
|
|
36
|
+
readonly localized: Readonly<Record<string, PageModule>>;
|
|
37
|
+
/** The pages people made in the editor, which no file lists: `/our-story/`. */
|
|
38
|
+
readonly entries?: readonly string[];
|
|
39
|
+
/** Addresses to leave out of the sitemap. */
|
|
40
|
+
readonly unlisted?: readonly string[];
|
|
41
|
+
}
|
|
42
|
+
/** Every address the site renders on demand, in a stable order. */
|
|
43
|
+
export declare function liveAddresses(sources: PageSources): Promise<LiveAddress[]>;
|
|
44
|
+
interface LiveEntry<Data> {
|
|
45
|
+
readonly id: string;
|
|
46
|
+
readonly collection: string;
|
|
47
|
+
readonly data: Data;
|
|
48
|
+
}
|
|
49
|
+
interface LiveResult {
|
|
50
|
+
readonly entries?: readonly {
|
|
51
|
+
id: string;
|
|
52
|
+
data: unknown;
|
|
53
|
+
}[];
|
|
54
|
+
readonly error?: Error;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Stands in for `getCollection`: same call, same entries, read from the CMS at request time.
|
|
58
|
+
* Entries are checked with the collection's own schema, read once per publish and kept in memory.
|
|
59
|
+
* A preview reads the versions being worked on, fresh every time and never remembered.
|
|
60
|
+
*
|
|
61
|
+
* ```ts
|
|
62
|
+
* export const liveCollection = liveCollections(getLiveCollection, { listings: listingsSchema });
|
|
63
|
+
* ```
|
|
64
|
+
*/
|
|
65
|
+
export declare function liveCollections<Schemas extends Record<string, {
|
|
66
|
+
parse(data: unknown): unknown;
|
|
67
|
+
}>>(getLiveCollection: (name: string) => Promise<LiveResult>, schemas: Schemas): (name: keyof Schemas & string, filter?: (entry: LiveEntry<ReturnType<Schemas[keyof Schemas & string]["parse"]>>) => boolean) => Promise<LiveEntry<ReturnType<Schemas[keyof Schemas & string]["parse"]>>[]>;
|
|
68
|
+
export {};
|
|
69
|
+
//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O,SAAS,MAAM,CAAC,MAAM,EAAE;IAAE,KAAK,CAAC,IAAI,EAAE,OAAO,GAAG,OAAO,CAAA;CAAE,CAAC,EAC/F,iBAAiB,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,OAAO,CAAC,UAAU,CAAC,EACxD,OAAO,EAAE,OAAO,IAcqB,4BAAU,EAAE,SAAS,CAAC,KAAK,iEAAO,KAAK,OAAO,KAAG,OAAO,CAAC,iEAAO,CAAC,CAevG"}
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What a site needs once its pages are rendered on demand: the work `getStaticPaths` did at build
|
|
3
|
+
* time, done per request instead, and the list of addresses the build used to know by itself.
|
|
4
|
+
*/
|
|
5
|
+
import { isPreview } from './preview.js';
|
|
6
|
+
import { liveContentVersion } from './live-loader.js';
|
|
7
|
+
const same = (a, b) => (a || undefined) === (b || undefined);
|
|
8
|
+
/** The path whose params are the ones in this request, as Astro would have matched at build time. */
|
|
9
|
+
export function matchParams(paths, params) {
|
|
10
|
+
return paths.find((path) => Object.entries(path.params).every(([key, value]) => same(params[key], value)));
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Velocity gives every translated page its own catch-all route under `[lang]`, and tells them
|
|
14
|
+
* apart with `getStaticPaths`. Rendered on demand, the first of those routes would take every
|
|
15
|
+
* address. So one route takes them all and asks each page whether the address is its own.
|
|
16
|
+
*/
|
|
17
|
+
export async function matchLocalizedPage(pages, lang, rest) {
|
|
18
|
+
if (!lang)
|
|
19
|
+
return undefined;
|
|
20
|
+
for (const page of Object.values(pages)) {
|
|
21
|
+
const paths = (await page.getStaticPaths?.()) ?? [];
|
|
22
|
+
const match = paths.find(({ params }) => {
|
|
23
|
+
const { lang: pathLang, ...others } = params;
|
|
24
|
+
return pathLang === lang && same(Object.values(others)[0], rest);
|
|
25
|
+
});
|
|
26
|
+
if (match)
|
|
27
|
+
return { Page: page.default, props: match.props ?? {} };
|
|
28
|
+
}
|
|
29
|
+
return undefined;
|
|
30
|
+
}
|
|
31
|
+
/** Every address the site renders on demand, in a stable order. */
|
|
32
|
+
export async function liveAddresses(sources) {
|
|
33
|
+
const fixed = new Set();
|
|
34
|
+
for (const file of sources.fixed) {
|
|
35
|
+
const name = file.slice(file.lastIndexOf('/') + 1, -'.astro'.length);
|
|
36
|
+
if (name !== '404' && !name.includes('['))
|
|
37
|
+
fixed.add(name === 'index' ? '/' : `/${name}/`);
|
|
38
|
+
}
|
|
39
|
+
const paths = [...fixed];
|
|
40
|
+
for (const [file, page] of Object.entries(sources.detail)) {
|
|
41
|
+
const section = file.split('/').at(-2);
|
|
42
|
+
for (const { params } of (await page.livePaths?.()) ?? [])
|
|
43
|
+
paths.push(`/${section}/${params.slug}/`);
|
|
44
|
+
}
|
|
45
|
+
for (const page of Object.values(sources.localized)) {
|
|
46
|
+
for (const { params } of (await page.getStaticPaths?.()) ?? []) {
|
|
47
|
+
const { lang, ...others } = params;
|
|
48
|
+
const rest = Object.values(others)[0];
|
|
49
|
+
paths.push(rest ? `/${lang}/${rest}/` : `/${lang}/`);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
// A page the site builds from a file wins over an entry at the same address, as it does when drawn.
|
|
53
|
+
paths.push(...(sources.entries ?? []));
|
|
54
|
+
const hidden = new Set(sources.unlisted ?? []);
|
|
55
|
+
return [...new Set(paths)].sort().map((path) => ({ path, fixed: fixed.has(path), listed: !hidden.has(path) }));
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Stands in for `getCollection`: same call, same entries, read from the CMS at request time.
|
|
59
|
+
* Entries are checked with the collection's own schema, read once per publish and kept in memory.
|
|
60
|
+
* A preview reads the versions being worked on, fresh every time and never remembered.
|
|
61
|
+
*
|
|
62
|
+
* ```ts
|
|
63
|
+
* export const liveCollection = liveCollections(getLiveCollection, { listings: listingsSchema });
|
|
64
|
+
* ```
|
|
65
|
+
*/
|
|
66
|
+
export function liveCollections(getLiveCollection, schemas) {
|
|
67
|
+
const memo = new Map();
|
|
68
|
+
const load = async (name) => {
|
|
69
|
+
const { entries, error } = await getLiveCollection(`${name}Live`);
|
|
70
|
+
if (error)
|
|
71
|
+
throw error;
|
|
72
|
+
const schema = schemas[name];
|
|
73
|
+
if (!schema)
|
|
74
|
+
throw new Error(`No schema was given for the live collection "${name}".`);
|
|
75
|
+
return (entries ?? []).map((entry) => ({ id: entry.id, collection: name, data: schema.parse(entry.data) }));
|
|
76
|
+
};
|
|
77
|
+
return async function liveCollection(name, filter) {
|
|
78
|
+
let entries;
|
|
79
|
+
if (isPreview()) {
|
|
80
|
+
entries = await load(name);
|
|
81
|
+
}
|
|
82
|
+
else {
|
|
83
|
+
const version = liveContentVersion();
|
|
84
|
+
let cached = memo.get(name);
|
|
85
|
+
if (!cached || cached.version !== version) {
|
|
86
|
+
cached = { version, entries: load(name) };
|
|
87
|
+
memo.set(name, cached);
|
|
88
|
+
}
|
|
89
|
+
entries = await cached.entries;
|
|
90
|
+
}
|
|
91
|
+
return filter ? entries.filter(filter) : [...entries];
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
//# sourceMappingURL=live-pages.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"live-pages.js","sourceRoot":"","sources":["../src/live-pages.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AACzC,OAAO,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAC;AAetD,MAAM,IAAI,GAAG,CAAC,CAAqB,EAAE,CAAqB,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,SAAS,CAAC,KAAK,CAAC,CAAC,IAAI,SAAS,CAAC,CAAC;AAErG,qGAAqG;AACrG,MAAM,UAAU,WAAW,CACzB,KAAsB,EACtB,MAAoD;IAEpD,OAAO,KAAK,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,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O,KAAK,UAAU,cAAc,CAAC,IAAU,EAAE,MAAkC;QACjF,IAAI,OAAgB,CAAC;QACrB,IAAI,SAAS,EAAE,EAAE,CAAC;YAChB,OAAO,GAAG,MAAM,IAAI,CAAC,IAAI,CAAC,CAAC;QAC7B,CAAC;aAAM,CAAC;YACN,MAAM,OAAO,GAAG,kBAAkB,EAAE,CAAC;YACrC,IAAI,MAAM,GAAG,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;YAC5B,IAAI,CAAC,MAAM,IAAI,MAAM,CAAC,OAAO,KAAK,OAAO,EAAE,CAAC;gBAC1C,MAAM,GAAG,EAAE,OAAO,EAAE,OAAO,EAAE,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC;gBAC1C,IAAI,CAAC,GAAG,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;YACzB,CAAC;YACD,OAAO,GAAG,MAAM,MAAM,CAAC,OAAO,CAAC;QACjC,CAAC;QACD,OAAO,MAAM,CAAC,CAAC,CAAC,OAAO,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,CAAC;IACxD,CAAC,CAAC;AACJ,CAAC"}
|
package/dist/loader.d.ts
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { Loader } from 'astro/loaders';
|
|
2
|
+
import { type ConnectionOptions } from './connection.js';
|
|
3
|
+
export interface CmsLoaderOptions extends ConnectionOptions {
|
|
4
|
+
/** The key of the content type to load, e.g. `listings`. */
|
|
5
|
+
readonly type: string;
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* A Content Layer loader that feeds a collection from Velocity CMS.
|
|
9
|
+
*
|
|
10
|
+
* It replaces the `file()` or `glob()` loader in a collection and nothing else: the collection's
|
|
11
|
+
* Zod schema, its pages and its queries stay exactly as they are. Only published entries are
|
|
12
|
+
* loaded, and each gets the id `<locale>/<slug>`, the convention Velocity's templates already use.
|
|
13
|
+
*
|
|
14
|
+
* ```ts
|
|
15
|
+
* const listings = defineCollection({
|
|
16
|
+
* loader: cmsLoader({ type: 'listings' }),
|
|
17
|
+
* schema: z.object({ ... }),
|
|
18
|
+
* });
|
|
19
|
+
* ```
|
|
20
|
+
*/
|
|
21
|
+
export declare function cmsLoader(options: CmsLoaderOptions): Loader;
|
|
22
|
+
//# sourceMappingURL=loader.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"loader.d.ts","sourceRoot":"","sources":["../src/loader.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,eAAe,CAAC;AAE5C,OAAO,EAAiB,KAAK,iBAAiB,EAAE,MAAM,iBAAiB,CAAC;AAExE,MAAM,WAAW,gBAAiB,SAAQ,iBAAiB;IACzD,4DAA4D;IAC5D,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;CACvB;AAID;;;;;;;;;;;;;GAaG;AACH,wBAAgB,SAAS,CAAC,OAAO,EAAE,gBAAgB,GAAG,MAAM,CAyC3D"}
|
package/dist/loader.js
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { isLiveType } from '@velocity-astro/cms-core';
|
|
2
|
+
import { connect, SITE } from './connection.js';
|
|
3
|
+
const PAGE_SIZE = 500;
|
|
4
|
+
/**
|
|
5
|
+
* A Content Layer loader that feeds a collection from Velocity CMS.
|
|
6
|
+
*
|
|
7
|
+
* It replaces the `file()` or `glob()` loader in a collection and nothing else: the collection's
|
|
8
|
+
* Zod schema, its pages and its queries stay exactly as they are. Only published entries are
|
|
9
|
+
* loaded, and each gets the id `<locale>/<slug>`, the convention Velocity's templates already use.
|
|
10
|
+
*
|
|
11
|
+
* ```ts
|
|
12
|
+
* const listings = defineCollection({
|
|
13
|
+
* loader: cmsLoader({ type: 'listings' }),
|
|
14
|
+
* schema: z.object({ ... }),
|
|
15
|
+
* });
|
|
16
|
+
* ```
|
|
17
|
+
*/
|
|
18
|
+
export function cmsLoader(options) {
|
|
19
|
+
return {
|
|
20
|
+
name: 'velocity-cms',
|
|
21
|
+
async load({ store, parseData, generateDigest, logger }) {
|
|
22
|
+
const { cms, close } = await connect(options);
|
|
23
|
+
try {
|
|
24
|
+
const type = await cms.schema.getByKey(options.type);
|
|
25
|
+
const seen = new Set();
|
|
26
|
+
let changed = 0;
|
|
27
|
+
// An archived type has no pages: nothing of it is read, so what the store held is taken out below.
|
|
28
|
+
for (let offset = 0; isLiveType(type); offset += PAGE_SIZE) {
|
|
29
|
+
const page = await cms.content.find(SITE, {
|
|
30
|
+
typeId: type.id,
|
|
31
|
+
status: 'published',
|
|
32
|
+
limit: PAGE_SIZE,
|
|
33
|
+
offset,
|
|
34
|
+
});
|
|
35
|
+
for (const entry of page.items) {
|
|
36
|
+
const live = cms.content.toPublic(type, entry);
|
|
37
|
+
const id = `${live.locale}/${live.slug}`;
|
|
38
|
+
seen.add(id);
|
|
39
|
+
const data = { ...live.data, slug: live.slug, locale: live.locale };
|
|
40
|
+
// The digest lets Astro skip an entry that has not changed since the last build.
|
|
41
|
+
const digest = generateDigest({ revision: entry.published?.revision, data });
|
|
42
|
+
if (store.get(id)?.digest === digest)
|
|
43
|
+
continue;
|
|
44
|
+
store.set({ id, data: await parseData({ id, data }), digest });
|
|
45
|
+
changed++;
|
|
46
|
+
}
|
|
47
|
+
if (offset + page.items.length >= page.total || page.items.length === 0)
|
|
48
|
+
break;
|
|
49
|
+
}
|
|
50
|
+
for (const id of store.keys()) {
|
|
51
|
+
if (!seen.has(id))
|
|
52
|
+
store.delete(id);
|
|
53
|
+
}
|
|
54
|
+
logger.info(`${options.type}: ${seen.size} published, ${changed} changed since the last build`);
|
|
55
|
+
}
|
|
56
|
+
finally {
|
|
57
|
+
close();
|
|
58
|
+
}
|
|
59
|
+
},
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
//# sourceMappingURL=loader.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"loader.js","sourceRoot":"","s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site on a server of its own. */
|
|
3
|
+
export declare class FolderMediaStore implements MediaStore {
|
|
4
|
+
private readonly directory;
|
|
5
|
+
constructor(directory: string);
|
|
6
|
+
put(key: string, file: StoredFile): Promise<void>;
|
|
7
|
+
get(key: string): Promise<StoredFile | null>;
|
|
8
|
+
remove(key: string): Promise<void>;
|
|
9
|
+
}
|
|
10
|
+
export interface S3MediaStoreOptions {
|
|
11
|
+
/** The storage service's address: `https://<account>.r2.cloudflarestorage.com`, `https://s3.eu-west-1.amazonaws.com`. */
|
|
12
|
+
readonly endpoint: string;
|
|
13
|
+
readonly bucket: string;
|
|
14
|
+
readonly accessKeyId: string;
|
|
15
|
+
readonly secretAccessKey: string;
|
|
16
|
+
/** Defaults to `auto`, which is what Cloudflare R2 takes. */
|
|
17
|
+
readonly region?: string;
|
|
18
|
+
/**
|
|
19
|
+
* A folder inside the bucket to keep every file under, such as `sites/s-4f2a`. A host that
|
|
20
|
+
* runs many sites gives each site its own, so one bucket holds them all and no site can
|
|
21
|
+
* name another's file. Lowercase letters, digits and hyphens, in parts divided by `/`.
|
|
22
|
+
*/
|
|
23
|
+
readonly prefix?: string;
|
|
24
|
+
/** Defaults to the server's own `fetch`. */
|
|
25
|
+
readonly fetch?: typeof globalThis.fetch;
|
|
26
|
+
/** Defaults to now. */
|
|
27
|
+
readonly now?: () => Date;
|
|
28
|
+
}
|
|
29
|
+
/** The bucket answered and refused. `status` is its answer; the message holds its own words, for the server's log. */
|
|
30
|
+
export declare class StorageRefusedError extends Error {
|
|
31
|
+
readonly status: number;
|
|
32
|
+
constructor(status: number, message: string);
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Keeps uploads in a bucket that speaks the S3 protocol: Cloudflare R2, Amazon S3, Backblaze B2,
|
|
36
|
+
* MinIO and others. For a site on a host with no disk of its own. The bucket stays private: the
|
|
37
|
+
* site reads from it with its key and serves the files itself.
|
|
38
|
+
*/
|
|
39
|
+
export declare class S3MediaStore implements MediaStore {
|
|
40
|
+
#private;
|
|
41
|
+
constructor(options: S3MediaStoreOptions);
|
|
42
|
+
put(key: string, file: StoredFile): Promise<void>;
|
|
43
|
+
get(key: string): Promise<StoredFile | null>;
|
|
44
|
+
remove(key: string): Promise<void>;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Where this site keeps uploads, from its environment:
|
|
48
|
+
*
|
|
49
|
+
* - `VELOCITY_CMS_S3_BUCKET`, `VELOCITY_CMS_S3_ENDPOINT`, `VELOCITY_CMS_S3_ACCESS_KEY_ID` and
|
|
50
|
+
* `VELOCITY_CMS_S3_SECRET_ACCESS_KEY` (and `VELOCITY_CMS_S3_REGION`): a bucket.
|
|
51
|
+
* - `VELOCITY_CMS_MEDIA_DIR`: a folder.
|
|
52
|
+
* - Neither, with the database in a file: the folder `media` beside the database, since a
|
|
53
|
+
* server that keeps its database on disk has a disk to keep files on.
|
|
54
|
+
* - Neither, with a hosted database: nowhere, and the site takes no uploads.
|
|
55
|
+
*/
|
|
56
|
+
export declare function mediaStoreFromEnv(databaseUrl: string, env?: Readonly<Record<string, string | undefined>>): MediaStore | undefined;
|
|
57
|
+
/** The bucket the server's own settings name, or none. Settings that name only part of one are refused. */
|
|
58
|
+
export declare function bucketFromEnv(env?: Readonly<Record<string, string | undefined>>): S3MediaStore | undefined;
|
|
59
|
+
/** The folder on the server's disk uploads are kept in: the one its settings name, or `media` beside a database that is a file. */
|
|
60
|
+
export declare function folderFromEnv(databaseUrl: string, env?: Readonly<Record<string, string | undefined>>): FolderMediaStore | undefined;
|
|
61
|
+
//# sourceMappingURL=media-store.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"media-store.d.ts","sourceRoot":"","sources":["../src/media-store.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,0BAA0B,CAAC;AAYvE,yFAAyF;AACzF,qBAAa,gBAAiB,YAAW,UAAU;IACrC,OAAO,CAAC,QAAQ,CA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