@velocity-astro/cms-astro 0.0.0-stage → 0.1.0-beta.1

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.
Files changed (121) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +12 -2
  3. package/bin/velocity-cms.mjs +6 -0
  4. package/dist/admin-files.d.ts +21 -0
  5. package/dist/admin-files.d.ts.map +1 -0
  6. package/dist/admin-files.js +77 -0
  7. package/dist/admin-files.js.map +1 -0
  8. package/dist/cli.d.ts +9 -0
  9. package/dist/cli.d.ts.map +1 -0
  10. package/dist/cli.js +75 -0
  11. package/dist/cli.js.map +1 -0
  12. package/dist/connection.d.ts +25 -0
  13. package/dist/connection.d.ts.map +1 -0
  14. package/dist/connection.js +62 -0
  15. package/dist/connection.js.map +1 -0
  16. package/dist/editor.d.ts +65 -0
  17. package/dist/editor.d.ts.map +1 -0
  18. package/dist/editor.js +186 -0
  19. package/dist/editor.js.map +1 -0
  20. package/dist/entry-page.d.ts +37 -0
  21. package/dist/entry-page.d.ts.map +1 -0
  22. package/dist/entry-page.js +56 -0
  23. package/dist/entry-page.js.map +1 -0
  24. package/dist/form-post.d.ts +106 -0
  25. package/dist/form-post.d.ts.map +1 -0
  26. package/dist/form-post.js +291 -0
  27. package/dist/form-post.js.map +1 -0
  28. package/dist/index.d.ts +25 -0
  29. package/dist/index.d.ts.map +1 -0
  30. package/dist/index.js +25 -0
  31. package/dist/index.js.map +1 -0
  32. package/dist/init.d.ts +33 -0
  33. package/dist/init.d.ts.map +1 -0
  34. package/dist/init.js +125 -0
  35. package/dist/init.js.map +1 -0
  36. package/dist/integration.d.ts +63 -0
  37. package/dist/integration.d.ts.map +1 -0
  38. package/dist/integration.js +129 -0
  39. package/dist/integration.js.map +1 -0
  40. package/dist/link.d.ts +32 -0
  41. package/dist/link.d.ts.map +1 -0
  42. package/dist/link.js +76 -0
  43. package/dist/link.js.map +1 -0
  44. package/dist/live-loader.d.ts +40 -0
  45. package/dist/live-loader.d.ts.map +1 -0
  46. package/dist/live-loader.js +92 -0
  47. package/dist/live-loader.js.map +1 -0
  48. package/dist/live-pages.d.ts +69 -0
  49. package/dist/live-pages.d.ts.map +1 -0
  50. package/dist/live-pages.js +94 -0
  51. package/dist/live-pages.js.map +1 -0
  52. package/dist/loader.d.ts +22 -0
  53. package/dist/loader.d.ts.map +1 -0
  54. package/dist/loader.js +62 -0
  55. package/dist/loader.js.map +1 -0
  56. package/dist/media-store.d.ts +46 -0
  57. package/dist/media-store.d.ts.map +1 -0
  58. package/dist/media-store.js +154 -0
  59. package/dist/media-store.js.map +1 -0
  60. package/dist/menu.d.ts +51 -0
  61. package/dist/menu.d.ts.map +1 -0
  62. package/dist/menu.js +81 -0
  63. package/dist/menu.js.map +1 -0
  64. package/dist/page-head.d.ts +23 -0
  65. package/dist/page-head.d.ts.map +1 -0
  66. package/dist/page-head.js +66 -0
  67. package/dist/page-head.js.map +1 -0
  68. package/dist/preview.d.ts +60 -0
  69. package/dist/preview.d.ts.map +1 -0
  70. package/dist/preview.js +126 -0
  71. package/dist/preview.js.map +1 -0
  72. package/dist/resend-mailer.d.ts +46 -0
  73. package/dist/resend-mailer.d.ts.map +1 -0
  74. package/dist/resend-mailer.js +95 -0
  75. package/dist/resend-mailer.js.map +1 -0
  76. package/dist/secret.d.ts +8 -0
  77. package/dist/secret.d.ts.map +1 -0
  78. package/dist/secret.js +16 -0
  79. package/dist/secret.js.map +1 -0
  80. package/dist/site-editor.d.ts +41 -0
  81. package/dist/site-editor.d.ts.map +1 -0
  82. package/dist/site-editor.js +110 -0
  83. package/dist/site-editor.js.map +1 -0
  84. package/dist/site-forms.d.ts +43 -0
  85. package/dist/site-forms.d.ts.map +1 -0
  86. package/dist/site-forms.js +82 -0
  87. package/dist/site-forms.js.map +1 -0
  88. package/dist/site-images.d.ts +17 -0
  89. package/dist/site-images.d.ts.map +1 -0
  90. package/dist/site-images.js +22 -0
  91. package/dist/site-images.js.map +1 -0
  92. package/dist/site-media.d.ts +18 -0
  93. package/dist/site-media.d.ts.map +1 -0
  94. package/dist/site-media.js +43 -0
  95. package/dist/site-media.js.map +1 -0
  96. package/dist/site-plugins.d.ts +10 -0
  97. package/dist/site-plugins.d.ts.map +1 -0
  98. package/dist/site-plugins.js +23 -0
  99. package/dist/site-plugins.js.map +1 -0
  100. package/dist/site-search.d.ts +12 -0
  101. package/dist/site-search.d.ts.map +1 -0
  102. package/dist/site-search.js +79 -0
  103. package/dist/site-search.js.map +1 -0
  104. package/package.json +53 -3
  105. package/routes/admin.ts +10 -0
  106. package/routes/api.ts +15 -0
  107. package/routes/auth.ts +10 -0
  108. package/routes/due.ts +12 -0
  109. package/routes/editor.ts +48 -0
  110. package/routes/form-client.js.ts +105 -0
  111. package/routes/media.ts +10 -0
  112. package/routes/pages.ts +13 -0
  113. package/routes/plugins.ts +10 -0
  114. package/routes/preview-client.js.ts +63 -0
  115. package/routes/published.ts +29 -0
  116. package/routes/schedule.ts +20 -0
  117. package/routes/search-client.js.ts +33 -0
  118. package/routes/search.json.ts +10 -0
  119. package/routes/share-image.png.ts +33 -0
  120. package/routes/sitemap-live.xml.ts +13 -0
  121. package/routes/submit.ts +22 -0
@@ -0,0 +1,92 @@
1
+ import { isLiveType } from '@velocity-astro/cms-core';
2
+ import { sharedConnection, SITE } from './connection.js';
3
+ import { isPreview, withPreviewDraft } from './preview.js';
4
+ /** The cache tag every page showing entries of a type carries. Publishing clears it. */
5
+ export const typeTag = (typeKey) => `cms:${typeKey}`;
6
+ /** The cache tag for one entry, for pages that show only that entry. */
7
+ export const entryTag = (typeKey, id) => `cms:${typeKey}:${id}`;
8
+ const PAGE_SIZE = 500;
9
+ let contentVersion = 0;
10
+ /**
11
+ * A number that goes up every time published content changes. Anything a site derives from live
12
+ * content and keeps in memory can be stored beside this number and thrown away when it moves.
13
+ */
14
+ export const liveContentVersion = () => contentVersion;
15
+ /** Tells this server that published content changed. Called on publish, before clearing the page cache. */
16
+ export function invalidateLiveContent() {
17
+ contentVersion++;
18
+ }
19
+ /**
20
+ * A live loader: pages rendered on demand read published entries straight from the CMS, so a
21
+ * change shows as soon as the page's cache is cleared instead of after a rebuild.
22
+ *
23
+ * Each entry comes back with cache tags. Pass an entry to `Astro.cache.set()` and the page is
24
+ * cached under those tags; clearing `typeTag('listings')` on publish refreshes every such page.
25
+ *
26
+ * ```ts
27
+ * // src/live.config.ts
28
+ * export const collections = {
29
+ * listings: defineLiveCollection({ loader: cmsLiveLoader({ type: 'listings' }), schema }),
30
+ * };
31
+ * ```
32
+ */
33
+ export function cmsLiveLoader(options) {
34
+ const tag = typeTag(options.type);
35
+ const toLive = (cms, type, entry) => {
36
+ // A preview reads the version being worked on. Everyone else reads the published one.
37
+ const shown = cms.content.toPublic(type, withPreviewDraft(entry), isPreview() ? 'working' : 'published');
38
+ const id = `${shown.locale}/${shown.slug}`;
39
+ return {
40
+ id,
41
+ data: { ...shown.data, slug: shown.slug, locale: shown.locale },
42
+ cacheHint: { tags: [tag, entryTag(options.type, id)], lastModified: new Date(entry.updatedAt) },
43
+ };
44
+ };
45
+ return {
46
+ name: 'velocity-cms-live',
47
+ async loadCollection({ filter }) {
48
+ try {
49
+ const { cms } = await sharedConnection(options);
50
+ const type = await cms.schema.getByKey(options.type);
51
+ // An archived type has no pages: its entries are kept, and shown to nobody.
52
+ if (!isLiveType(type))
53
+ return { entries: [], cacheHint: { tags: [tag] } };
54
+ const entries = [];
55
+ for (let offset = 0;; offset += PAGE_SIZE) {
56
+ const page = await cms.content.find(SITE, {
57
+ typeId: type.id,
58
+ ...(!isPreview() && { status: 'published' }),
59
+ ...(filter?.locale !== undefined && { locale: filter.locale }),
60
+ limit: PAGE_SIZE,
61
+ offset,
62
+ });
63
+ entries.push(...page.items.map((entry) => toLive(cms, type, entry)));
64
+ if (offset + page.items.length >= page.total || page.items.length === 0)
65
+ break;
66
+ }
67
+ return { entries, cacheHint: { tags: [tag] } };
68
+ }
69
+ catch (error) {
70
+ return { error: error instanceof Error ? error : new Error(String(error)) };
71
+ }
72
+ },
73
+ async loadEntry({ filter }) {
74
+ try {
75
+ const { cms } = await sharedConnection(options);
76
+ const type = await cms.schema.getByKey(options.type);
77
+ if (!isLiveType(type))
78
+ return undefined;
79
+ const separator = filter.id.indexOf('/');
80
+ const locale = filter.id.slice(0, separator);
81
+ const slug = filter.id.slice(separator + 1);
82
+ const version = isPreview() ? 'working' : 'published';
83
+ const match = await cms.content.findBySlug(SITE, { typeId: type.id, locale, slug, version });
84
+ return match ? toLive(cms, type, match) : undefined;
85
+ }
86
+ catch (error) {
87
+ return { error: error instanceof Error ? error : new Error(String(error)) };
88
+ }
89
+ },
90
+ };
91
+ }
92
+ //# 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,SAAS,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAgB3D,wFAAwF;AACxF,MAAM,CAAC,MAAM,OAAO,GAAG,CAAC,OAAe,EAAU,EAAE,CAAC,OAAO,OAAO,EAAE,CAAC;AAErE,wEAAwE;AACxE,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,2GAA2G;AAC3G,MAAM,UAAU,qBAAqB;IACnC,cAAc,EAAE,CAAC;AACnB,CAAC;AAED;;;;;;;;;;;;;GAaG;AACH,MAAM,UAAU,aAAa,C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,OAAO,CAAC,CAAC;gBAChD,MAAM,IAAI,GAAG,MAAM,GAAG,CAAC,MAAM,CAAC,QAAQ,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;gBACrD,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC;oBAAE,OAAO,SAAS,CAAC;gBACxC,MAAM,SAAS,GAAG,MAAM,CAAC,EAAE,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;gBACzC,MAAM,MAAM,GAAG,MAAM,CAAC,EAAE,CAAC,KAAK,CAAC,CAAC,EAAE,SAAS,CAAC,CAAC;gBAC7C,MAAM,IAAI,GAAG,MAAM,CAAC,EAAE,CAAC,KAAK,CAAC,SAAS,GAAG,CAAC,CAAC,CAAC;gBAC5C,MAAM,OAAO,GAAG,SAAS,EAAE,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,WAAW,CAAC;gBACtD,MAAM,KAAK,GAAG,MAAM,GAAG,CAAC,OAAO,CAAC,UAAU,CAAC,IAAI,EAAE,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC,CAAC;gBAC7F,OAAO,KAAK,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,EAAE,IAAI,EAAE,KAAK,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;YACtD,CAAC;YAAC,OAAO,KAAK,EAAE,CAAC;gBACf,OAAO,EAAE,KAAK,EAAE,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC;YAC9E,CAAC;QACH,CAAC;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
+ //# sourceMappingURL=live-pages.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"live-pages.d.ts","sourceRoot":"","sources":["../src/live-pages.ts"],"names":[],"mappings":"AAOA,MAAM,WAAW,UAAU;IACzB,QAAQ,CAAC,MAAM,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC,CAAC,CAAC;IAC9D,QAAQ,CAAC,KAAK,CAAC,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC;CACpD;AAED,mGAAmG;AACnG,MAAM,WAAW,UAAU,CAAC,SAAS,GAAG,OAAO;IAC7C,QAAQ,CAAC,OAAO,EAAE,SAAS,CAAC;IAC5B,QAAQ,CAAC,cAAc,CAAC,EAAE,MAAM,SAAS,UAAU,EAAE,GAAG,OAAO,CAAC,SAAS,UAAU,EAAE,CAAC,CAAC;IACvF,0FAA0F;IAC1F,QAAQ,CAAC,SAAS,CAAC,EAAE,MAAM,SAAS,UAAU,EAAE,GAAG,OAAO,CAAC,SAAS,UAAU,EAAE,CAAC,CAAC;CACnF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AC;CACvC;AAED,mEAAmE;AACnE,wBAAsB,aAAa,CAAC,OAAO,EAAE,WAAW,GAAG,OAAO,CAAC,WAAW,EAAE,CAAC,CAsBhF;AAED,UAAU,SAAS,CAAC,IAAI;IACtB,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IACpB,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAC5B,QAAQ,CAAC,IAAI,EAAE,IAAI,CAAC;CACrB;AACD,UAAU,UAAU;IAClB,QAAQ,CAAC,OAAO,CAAC,EAAE,SAAS;QAAE,EAAE,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,OAAO,CAAA;KAAE,EAAE,CAAC;IAC5D,QAAQ,CAAC,KAAK,CAAC,EAAE,KAAK,CAAC;CACxB;AAED;;;;;;;;GAQG;AACH,wBAAgB,eAAe,CAAC,OAAO,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,MAAM,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,GAAG,EAAE,KAAK,CAAC,EAAE,EAAE,CAAC,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,EAAE,KAAK,CAAC,CAAC,CAAC,CAAC;AAC7G,CAAC;AAED;;;;GAIG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AC;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"}
@@ -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":"","sources":["../src/loader.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,MAAM,0BAA0B,CAAC;AACtD,OAAO,EAAE,OAAO,EAAE,IAAI,EAA0B,MAAM,iBAAiB,CAAC;AAOxE,MAAM,SAAS,GAAG,GAAG,CAAC;AAEtB;;;;;;;;;;;;;GAaG;AACH,MAAM,UAAU,SAAS,CAAC,OAAyB;IACjD,OAAO;QACL,IAAI,EAAE,cAAc;QACpB,KAAK,CAAC,IAAI,CAAC,EAAE,KAAK,EAAE,SAAS,EAAE,cAAc,EAAE,MAAM,EAAE;YACrD,MAAM,EAAE,GAAG,EAAE,KAAK,EAAE,GAAG,MAAM,OAAO,CAAC,OAAO,CAAC,CAAC;YAC9C,IAAI,CAAC;gBACH,MAAM,IAAI,GAAG,MAAM,GAAG,CAAC,MAAM,CAAC,QAAQ,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;gBAErD,MAAM,IAAI,GAAG,IAAI,GAAG,EAAU,CAAC;gBAC/B,IAAI,OAAO,GAAG,CAAC,CAAC;gBAChB,mGAAmG;gBACnG,KAAK,IAAI,MAAM,GAAG,CAAC,EAAE,UAAU,CAAC,IAAI,CAAC,EAAE,MAAM,IAAI,SAAS,EAAE,CAAC;oBAC3D,MAAM,IAAI,GAAG,MAAM,GAAG,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI,EAAE;wBACxC,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AK,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC;gBACtC,CAAC;gBACD,MAAM,CAAC,IAAI,CAAC,GAAG,OAAO,CAAC,IAAI,KAAK,IAAI,CAAC,IAAI,eAAe,OAAO,+BAA+B,CAAC,CAAC;YAClG,CAAC;oBAAS,CAAC;gBACT,KAAK,EAAE,CAAC;YACV,CAAC;QACH,CAAC;KACF,CAAC;AACJ,CAAC"}
@@ -0,0 +1,46 @@
1
+ import type { MediaStore, StoredFile } from '@velocity-astro/cms-core';
2
+ /** Keeps uploads in a folder on the server's disk. For a 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
+ /** Defaults to the server's own `fetch`. */
19
+ readonly fetch?: typeof globalThis.fetch;
20
+ /** Defaults to now. */
21
+ readonly now?: () => Date;
22
+ }
23
+ /**
24
+ * Keeps uploads in a bucket that speaks the S3 protocol: Cloudflare R2, Amazon S3, Backblaze B2,
25
+ * MinIO and others. For a site on a host with no disk of its own. The bucket stays private: the
26
+ * site reads from it with its key and serves the files itself.
27
+ */
28
+ export declare class S3MediaStore implements MediaStore {
29
+ #private;
30
+ constructor(options: S3MediaStoreOptions);
31
+ put(key: string, file: StoredFile): Promise<void>;
32
+ get(key: string): Promise<StoredFile | null>;
33
+ remove(key: string): Promise<void>;
34
+ }
35
+ /**
36
+ * Where this site keeps uploads, from its environment:
37
+ *
38
+ * - `VELOCITY_CMS_S3_BUCKET`, `VELOCITY_CMS_S3_ENDPOINT`, `VELOCITY_CMS_S3_ACCESS_KEY_ID` and
39
+ * `VELOCITY_CMS_S3_SECRET_ACCESS_KEY` (and `VELOCITY_CMS_S3_REGION`): a bucket.
40
+ * - `VELOCITY_CMS_MEDIA_DIR`: a folder.
41
+ * - Neither, with the database in a file: the folder `media` beside the database, since a
42
+ * server that keeps its database on disk has a disk to keep files on.
43
+ * - Neither, with a hosted database: nowhere, and the site takes no uploads.
44
+ */
45
+ export declare function mediaStoreFromEnv(databaseUrl: string, env?: Readonly<Record<string, string | undefined>>): MediaStore | undefined;
46
+ //# 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,CAAC,SAAS;gBAAT,SAAS,EAAE,MAAM;IAExC,GAAG,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,UAAU,GAAG,OAAO,CAAC,IAAI,CAAC;IAKjD,GAAG,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,UAAU,GAAG,IAAI,CAAC;IAU5C,MAAM,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;CAGzC;AAED,MAAM,WAAW,mBAAmB;IAClC,yHAAyH;IACzH,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;IAC7B,QAAQ,CAAC,eAAe,EAAE,MAAM,CAAC;IACjC,6DAA6D;IAC7D,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC;IACzB,4CAA4C;IAC5C,QAAQ,CAAC,KAAK,CAAC,EAAE,OAAO,UAAU,CAAC,KAAK,CAAC;IACzC,uBAAuB;IACvB,QAAQ,CAAC,GAAG,CAAC,EAAE,MAAM,IAAI,CAAC;CAC3B;AAWD;;;;GAIG;AACH,qBAAa,YAAa,YAAW,UAAU;;gBAIjC,OAAO,EAAE,mBAAmB;IAKlC,GAAG,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,UAAU,GAAG,OAAO,CAAC,IAAI,CAAC;IAKjD,GAAG,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,UAAU,GAAG,IAAI,CAAC;IAQ5C,MAAM,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;CAkDzC;AAED;;;;;;;;;GASG;AACH,wBAAgB,iBAAiB,CAAC,WAAW,EAAE,MAAM,EAAE,GAAG,GAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC,CAAe,GAAG,UAAU,GAAG,SAAS,CAmB9I"}
@@ -0,0 +1,154 @@
1
+ import { mkdir, readFile, rm, writeFile } from 'node:fs/promises';
2
+ import path from 'node:path';
3
+ /** A key is one file name the CMS made: nothing that could name a folder or another place. */
4
+ const KEY = /^[a-z0-9]+(?:-[a-z0-9]+)*\.(?:jpg|png|webp)$/;
5
+ const TYPES = { jpg: 'image/jpeg', png: 'image/png', webp: 'image/webp' };
6
+ const typeOf = (key) => TYPES[key.slice(key.lastIndexOf('.') + 1)] ?? 'application/octet-stream';
7
+ function checked(key) {
8
+ if (!KEY.test(key))
9
+ throw new Error(`"${key}" is not a name an uploaded file can be kept under.`);
10
+ return key;
11
+ }
12
+ /** Keeps uploads in a folder on the server's disk. For a site on a server of its own. */
13
+ export class FolderMediaStore {
14
+ directory;
15
+ constructor(directory) {
16
+ this.directory = directory;
17
+ }
18
+ async put(key, file) {
19
+ await mkdir(this.directory, { recursive: true });
20
+ await writeFile(path.join(this.directory, checked(key)), file.bytes);
21
+ }
22
+ async get(key) {
23
+ if (!KEY.test(key))
24
+ return null;
25
+ try {
26
+ return { bytes: new Uint8Array(await readFile(path.join(this.directory, key))), contentType: typeOf(key) };
27
+ }
28
+ catch (error) {
29
+ if (error.code === 'ENOENT')
30
+ return null;
31
+ throw error;
32
+ }
33
+ }
34
+ async remove(key) {
35
+ if (KEY.test(key))
36
+ await rm(path.join(this.directory, key), { force: true });
37
+ }
38
+ }
39
+ const encoder = new TextEncoder();
40
+ const hex = (bytes) => [...new Uint8Array(bytes)].map((byte) => byte.toString(16).padStart(2, '0')).join('');
41
+ const sha256 = async (bytes) => hex(await crypto.subtle.digest('SHA-256', bytes));
42
+ async function hmac(key, text) {
43
+ const imported = await crypto.subtle.importKey('raw', key, { name: 'HMAC', hash: 'SHA-256' }, false, ['sign']);
44
+ return crypto.subtle.sign('HMAC', imported, encoder.encode(text));
45
+ }
46
+ /**
47
+ * Keeps uploads in a bucket that speaks the S3 protocol: Cloudflare R2, Amazon S3, Backblaze B2,
48
+ * MinIO and others. For a site on a host with no disk of its own. The bucket stays private: the
49
+ * site reads from it with its key and serves the files itself.
50
+ */
51
+ export class S3MediaStore {
52
+ #options;
53
+ #region;
54
+ constructor(options) {
55
+ this.#options = options;
56
+ this.#region = options.region ?? 'auto';
57
+ }
58
+ async put(key, file) {
59
+ const response = await this.#send('PUT', checked(key), file);
60
+ if (!response.ok)
61
+ throw await this.#failure('keep', key, response);
62
+ }
63
+ async get(key) {
64
+ if (!KEY.test(key))
65
+ return null;
66
+ const response = await this.#send('GET', key);
67
+ if (response.status === 404)
68
+ return null;
69
+ if (!response.ok)
70
+ throw await this.#failure('read', key, response);
71
+ return { bytes: new Uint8Array(await response.arrayBuffer()), contentType: response.headers.get('content-type') ?? typeOf(key) };
72
+ }
73
+ async remove(key) {
74
+ if (!KEY.test(key))
75
+ return;
76
+ const response = await this.#send('DELETE', key);
77
+ if (!response.ok && response.status !== 404)
78
+ throw await this.#failure('remove', key, response);
79
+ }
80
+ /** One request, signed the way the protocol asks (Signature Version 4). */
81
+ async #send(method, key, file) {
82
+ const { endpoint, bucket, accessKeyId, secretAccessKey } = this.#options;
83
+ const url = new URL(`${endpoint.replace(/\/+$/, '')}/${encodeURIComponent(bucket)}/${key}`);
84
+ const stamp = (this.#options.now?.() ?? new Date()).toISOString().replace(/[-:]|\.\d{3}/g, '');
85
+ const day = stamp.slice(0, 8);
86
+ const headers = {
87
+ host: url.host,
88
+ 'x-amz-content-sha256': await sha256(file?.bytes ?? new Uint8Array()),
89
+ 'x-amz-date': stamp,
90
+ ...(file && { 'content-type': file.contentType }),
91
+ };
92
+ const names = Object.keys(headers).sort();
93
+ const request = [
94
+ method,
95
+ url.pathname,
96
+ '',
97
+ ...names.map((name) => `${name}:${headers[name]}`),
98
+ '',
99
+ names.join(';'),
100
+ headers['x-amz-content-sha256'],
101
+ ].join('\n');
102
+ const scope = `${day}/${this.#region}/s3/aws4_request`;
103
+ const toSign = ['AWS4-HMAC-SHA256', stamp, scope, await sha256(encoder.encode(request))].join('\n');
104
+ let signingKey = encoder.encode(`AWS4${secretAccessKey}`);
105
+ for (const part of [day, this.#region, 's3', 'aws4_request'])
106
+ signingKey = await hmac(signingKey, part);
107
+ const signature = hex(await hmac(signingKey, toSign));
108
+ const { host: _host, ...sent } = headers;
109
+ return (this.#options.fetch ?? globalThis.fetch)(url, {
110
+ method,
111
+ headers: {
112
+ ...sent,
113
+ authorization: `AWS4-HMAC-SHA256 Credential=${accessKeyId}/${scope}, SignedHeaders=${names.join(';')}, Signature=${signature}`,
114
+ },
115
+ ...(file && { body: file.bytes }),
116
+ });
117
+ }
118
+ /** What went wrong, in the storage service's words. It goes to the server's log, not to the person. */
119
+ async #failure(doing, key, response) {
120
+ const said = (await response.text().catch(() => '')).replace(/\s+/g, ' ').slice(0, 300);
121
+ return new Error(`The storage bucket "${this.#options.bucket}" refused to ${doing} "${key}" (${response.status}). ${said}`.trim());
122
+ }
123
+ }
124
+ /**
125
+ * Where this site keeps uploads, from its environment:
126
+ *
127
+ * - `VELOCITY_CMS_S3_BUCKET`, `VELOCITY_CMS_S3_ENDPOINT`, `VELOCITY_CMS_S3_ACCESS_KEY_ID` and
128
+ * `VELOCITY_CMS_S3_SECRET_ACCESS_KEY` (and `VELOCITY_CMS_S3_REGION`): a bucket.
129
+ * - `VELOCITY_CMS_MEDIA_DIR`: a folder.
130
+ * - Neither, with the database in a file: the folder `media` beside the database, since a
131
+ * server that keeps its database on disk has a disk to keep files on.
132
+ * - Neither, with a hosted database: nowhere, and the site takes no uploads.
133
+ */
134
+ export function mediaStoreFromEnv(databaseUrl, env = process.env) {
135
+ const s3 = {
136
+ bucket: env.VELOCITY_CMS_S3_BUCKET,
137
+ endpoint: env.VELOCITY_CMS_S3_ENDPOINT,
138
+ accessKeyId: env.VELOCITY_CMS_S3_ACCESS_KEY_ID,
139
+ secretAccessKey: env.VELOCITY_CMS_S3_SECRET_ACCESS_KEY,
140
+ };
141
+ const given = Object.values(s3).filter(Boolean).length;
142
+ if (s3.bucket && s3.endpoint && s3.accessKeyId && s3.secretAccessKey) {
143
+ return new S3MediaStore({ ...s3, bucket: s3.bucket, endpoint: s3.endpoint, accessKeyId: s3.accessKeyId, secretAccessKey: s3.secretAccessKey, ...(env.VELOCITY_CMS_S3_REGION && { region: env.VELOCITY_CMS_S3_REGION }) });
144
+ }
145
+ if (given > 0) {
146
+ throw new Error('Uploads are set up only in part. A bucket needs all four of VELOCITY_CMS_S3_BUCKET, VELOCITY_CMS_S3_ENDPOINT, VELOCITY_CMS_S3_ACCESS_KEY_ID and VELOCITY_CMS_S3_SECRET_ACCESS_KEY.');
147
+ }
148
+ if (env.VELOCITY_CMS_MEDIA_DIR)
149
+ return new FolderMediaStore(path.resolve(env.VELOCITY_CMS_MEDIA_DIR));
150
+ if (databaseUrl.startsWith('file:'))
151
+ return new FolderMediaStore(path.join(path.dirname(path.resolve(databaseUrl.slice('file:'.length))), 'media'));
152
+ return undefined;
153
+ }
154
+ //# sourceMappingURL=media-store.js.map
@@ -0,0 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