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

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
package/dist/init.d.ts ADDED
@@ -0,0 +1,33 @@
1
+ export interface InitOptions {
2
+ /** The site's folder. */
3
+ readonly dir: string;
4
+ readonly print: (line: string) => void;
5
+ /** Makes the site's secret. Tests give their own. */
6
+ readonly secret?: () => string;
7
+ }
8
+ export interface InitResult {
9
+ readonly code: number;
10
+ /** The settings as they now are in `.env`, for whatever runs next in the same command. */
11
+ readonly env: Readonly<Record<string, string>>;
12
+ }
13
+ /** The settings a `.env` file holds, by name. Quotes around a value are taken off. */
14
+ export declare function readEnvFile(text: string): Record<string, string>;
15
+ /**
16
+ * The config with the integration added, or `null` when it cannot be added with certainty. Only
17
+ * a config with one `integrations: [` list is changed; anything else is the person's to edit,
18
+ * with the two lines printed for them.
19
+ */
20
+ export declare function withIntegration(config: string): string | null;
21
+ /**
22
+ * Sets a site up for the CMS, in its folder: a secret and the database's place in `.env`, both
23
+ * kept out of git, and the integration in the Astro config. It can be run again: it adds only
24
+ * what is missing and never changes a value that is there.
25
+ */
26
+ export declare function initSite({ dir, print, secret }: InitOptions): InitResult;
27
+ /**
28
+ * Reads the CMS's own settings from the site's `.env` files into the environment, where the CMS
29
+ * looks for them. Astro reads those files for the site's code but not for the server it runs
30
+ * while developing and building. A setting the environment already has is left as it is.
31
+ */
32
+ export declare function loadCmsEnv(dir: string, mode: string, env?: Record<string, string | undefined>): void;
33
+ //# sourceMappingURL=init.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"init.d.ts","sourceRoot":"","sources":["../src/init.ts"],"names":[],"mappings":"AASA,MAAM,WAAW,WAAW;IAC1B,yBAAyB;IACzB,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;IACrB,QAAQ,CAAC,KAAK,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,CAAC;IACvC,qDAAqD;IACrD,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,MAAM,CAAC;CAChC;AAED,MAAM,WAAW,UAAU;IACzB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,0FAA0F;IAC1F,QAAQ,CAAC,GAAG,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC;CAChD;AAED,sFAAsF;AACtF,wBAAgB,WAAW,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAQhE;AAED;;;;GAIG;AACH,wBAAgB,eAAe,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAgB7D;AAED;;;;GAIG;AACH,wBAAgB,QAAQ,CAAC,EAAE,GAAG,EAAE,KAAK,EAAE,MAAoD,EAAE,EAAE,WAAW,GAAG,UAAU,CA2DtH;AAED;;;;GAIG;AACH,wBAAgB,UAAU,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,GAAG,GAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,CAAe,GAAG,IAAI,CASjH"}
package/dist/init.js ADDED
@@ -0,0 +1,125 @@
1
+ import { randomBytes } from 'node:crypto';
2
+ import fs from 'node:fs';
3
+ import path from 'node:path';
4
+ const PACKAGE = '@velocity-astro/cms-astro';
5
+ const CONFIG_FILES = ['astro.config.mjs', 'astro.config.ts', 'astro.config.js', 'astro.config.mts'];
6
+ /** Where the database is kept unless the site says otherwise (see `connect`). */
7
+ const DATA_FOLDER = 'cms';
8
+ /** The settings a `.env` file holds, by name. Quotes around a value are taken off. */
9
+ export function readEnvFile(text) {
10
+ const found = {};
11
+ for (const line of text.split(/\r?\n/)) {
12
+ const match = /^\s*(?:export\s+)?([A-Za-z_][A-Za-z0-9_]*)\s*=\s*(.*?)\s*$/.exec(line);
13
+ if (!match || match[1] === undefined)
14
+ continue;
15
+ found[match[1]] = (match[2] ?? '').replace(/^(['"])(.*)\1$/, '$2');
16
+ }
17
+ return found;
18
+ }
19
+ /**
20
+ * The config with the integration added, or `null` when it cannot be added with certainty. Only
21
+ * a config with one `integrations: [` list is changed; anything else is the person's to edit,
22
+ * with the two lines printed for them.
23
+ */
24
+ export function withIntegration(config) {
25
+ const lists = config.match(/\bintegrations\s*:\s*\[/g) ?? [];
26
+ if (lists.length !== 1 || lists[0] === undefined)
27
+ return null;
28
+ const at = config.indexOf(lists[0]) + lists[0].length;
29
+ const rest = config.slice(at);
30
+ // An empty list takes the call alone; a list with something in it takes it first, with a comma.
31
+ const isEmpty = /^\s*\]/.test(rest);
32
+ // A list written over several lines takes a line of its own, set in as its neighbours are.
33
+ const lines = /^[ \t]*\r?\n([ \t]*)/.exec(rest);
34
+ const added = config.slice(0, at) + (isEmpty ? 'velocityCms()' : lines ? `\n${lines[1] ?? ''}velocityCms(),` : 'velocityCms(), ') + rest;
35
+ const imports = [...added.matchAll(/^import\s.*$/gm)];
36
+ const last = imports.at(-1);
37
+ const line = `import velocityCms from '${PACKAGE}';`;
38
+ if (!last || last.index === undefined)
39
+ return `${line}\n\n${added}`;
40
+ const end = last.index + last[0].length;
41
+ return `${added.slice(0, end)}\n${line}${added.slice(end)}`;
42
+ }
43
+ /**
44
+ * Sets a site up for the CMS, in its folder: a secret and the database's place in `.env`, both
45
+ * kept out of git, and the integration in the Astro config. It can be run again: it adds only
46
+ * what is missing and never changes a value that is there.
47
+ */
48
+ export function initSite({ dir, print, secret = () => randomBytes(32).toString('base64url') }) {
49
+ const at = (file) => path.join(dir, file);
50
+ const configFile = CONFIG_FILES.find((file) => fs.existsSync(at(file)));
51
+ if (!configFile) {
52
+ print(`There is no Astro site in this folder (no ${CONFIG_FILES[0]}). Run this in the site's own folder.`);
53
+ return { code: 1, env: {} };
54
+ }
55
+ // 1. The secret, in .env. A value that is there is never replaced: sessions and saved keys depend on it.
56
+ const envText = fs.existsSync(at('.env')) ? fs.readFileSync(at('.env'), 'utf8') : '';
57
+ const env = readEnvFile(envText);
58
+ const lines = [];
59
+ if (!env['VELOCITY_CMS_SECRET']) {
60
+ env['VELOCITY_CMS_SECRET'] = secret();
61
+ lines.push('# Signs sessions, preview links and the keys plugins save. Keep it out of git, and set the same name on your host.', `VELOCITY_CMS_SECRET=${env['VELOCITY_CMS_SECRET']}`);
62
+ }
63
+ if (!env['VELOCITY_CMS_ORIGIN']) {
64
+ env['VELOCITY_CMS_ORIGIN'] = 'http://localhost:4321';
65
+ lines.push("# The site's address on this computer. On your host, set it to the real one, such as https://example.com.", `VELOCITY_CMS_ORIGIN=${env['VELOCITY_CMS_ORIGIN']}`);
66
+ }
67
+ if (lines.length > 0) {
68
+ fs.writeFileSync(at('.env'), `${envText}${envText === '' || envText.endsWith('\n') ? '' : '\n'}${envText === '' ? '' : '\n'}${lines.join('\n')}\n`);
69
+ print('.env: added the settings the CMS needs.');
70
+ }
71
+ else {
72
+ print('.env: already has the settings the CMS needs.');
73
+ }
74
+ // 2. Neither the secret nor the database belongs in git.
75
+ const ignoreText = fs.existsSync(at('.gitignore')) ? fs.readFileSync(at('.gitignore'), 'utf8') : '';
76
+ const ignored = ignoreText.split(/\r?\n/).map((line) => line.trim());
77
+ // The database's folder is named from the top, so a `src/cms` of the site's own is still kept.
78
+ const bare = (entry) => entry.replace(/^\/|\/$/g, '');
79
+ const missing = ['.env', `/${DATA_FOLDER}/`].filter((entry) => !ignored.some((line) => bare(line) === bare(entry)));
80
+ if (missing.length > 0) {
81
+ fs.writeFileSync(at('.gitignore'), `${ignoreText}${ignoreText === '' || ignoreText.endsWith('\n') ? '' : '\n'}${missing.join('\n')}\n`);
82
+ print(`.gitignore: now leaves out ${missing.join(' and ')}.`);
83
+ }
84
+ // 3. The integration.
85
+ const config = fs.readFileSync(at(configFile), 'utf8');
86
+ if (config.includes(PACKAGE)) {
87
+ print(`${configFile}: already has the CMS.`);
88
+ }
89
+ else {
90
+ const next = withIntegration(config);
91
+ if (next) {
92
+ fs.writeFileSync(at(configFile), next);
93
+ print(`${configFile}: added the CMS to integrations.`);
94
+ }
95
+ else {
96
+ print(`${configFile}: add these two lines yourself, since the file is not laid out as expected:\n\n import velocityCms from '${PACKAGE}';\n integrations: [velocityCms()],\n`);
97
+ }
98
+ }
99
+ const latest = fs.readFileSync(at(configFile), 'utf8');
100
+ if (!/\badapter\s*:/.test(latest)) {
101
+ print(`${configFile}: has no adapter yet. The editor and live pages run on a server, so add one for where the site will live, for example \`npx astro add node\`.`);
102
+ }
103
+ if (!/\bsite\s*:/.test(latest)) {
104
+ print(`${configFile}: has no \`site\` yet. Set it to the site's address before you deploy, so sign-in links lead there.`);
105
+ }
106
+ return { code: 0, env };
107
+ }
108
+ /**
109
+ * Reads the CMS's own settings from the site's `.env` files into the environment, where the CMS
110
+ * looks for them. Astro reads those files for the site's code but not for the server it runs
111
+ * while developing and building. A setting the environment already has is left as it is.
112
+ */
113
+ export function loadCmsEnv(dir, mode, env = process.env) {
114
+ // Later files are the more specific, so they are read first and win.
115
+ for (const file of [`.env.${mode}.local`, '.env.local', `.env.${mode}`, '.env']) {
116
+ const full = path.join(dir, file);
117
+ if (!fs.existsSync(full))
118
+ continue;
119
+ for (const [name, value] of Object.entries(readEnvFile(fs.readFileSync(full, 'utf8')))) {
120
+ if (name.startsWith('VELOCITY_CMS_') && !env[name])
121
+ env[name] = value;
122
+ }
123
+ }
124
+ }
125
+ //# sourceMappingURL=init.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"init.js","sourceRoot":"","sources":["../src/init.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC1C,OAAO,EAAE,MAAM,SAAS,CAAC;AACzB,OAAO,IAAI,MAAM,WAAW,CAAC;AAE7B,MAAM,OAAO,GAAG,2BAA2B,CAAC;AAC5C,MAAM,YAAY,GAAG,CAAC,kBAAkB,EAAE,iBAAiB,EAAE,iBAAiB,EAAE,kBAAkB,CAAC,CAAC;AACpG,iFAAiF;AACjF,MAAM,WAAW,GAAG,KAAK,CAAC;AAgB1B,sFAAsF;AACtF,MAAM,UAAU,WAAW,CAAC,IAAY;IACtC,MAAM,KAAK,GAA2B,EAAE,CAAC;IACzC,KAAK,MAAM,IAAI,IAAI,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,EAAE,CAAC;QACvC,MAAM,KAAK,GAAG,4DAA4D,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QACtF,IAAI,CAAC,KAAK,IAAI,KAAK,CAAC,CAAC,CAAC,KAAK,SAAS;YAAE,SAAS;QAC/C,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC,OAAO,CAAC,gBAAgB,EAAE,IAAI,CAAC,CAAC;IACrE,CAAC;IACD,OAAO,KAAK,CAAC;AACf,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,eAAe,CAAC,MAAc;IAC5C,MAAM,K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AAC,UAAU,CAAC,EAAE,MAAM,CAAC,CAAC;IACvD,IAAI,CAAC,eAAe,CAAC,IAAI,CAAC,MAAM,CAAC,EAAE,CAAC;QAClC,KAAK,CAAC,GAAG,UAAU,+IAA+I,CAAC,CAAC;IACtK,CAAC;IACD,IAAI,CAAC,YAAY,CAAC,IAAI,CAAC,MAAM,CAAC,EAAE,CAAC;QAC/B,KAAK,CAAC,GAAG,UAAU,qGAAqG,CAAC,CAAC;IAC5H,CAAC;IACD,OAAO,EAAE,IAAI,EAAE,CAAC,EAAE,GAAG,EAAE,CAAC;AAC1B,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,UAAU,CAAC,GAAW,EAAE,IAAY,EAAE,MAA0C,OAAO,CAAC,GAAG;IACzG,qEAAqE;IACrE,KAAK,MAAM,IAAI,IAAI,CAAC,QAAQ,IAAI,QAAQ,EAAE,YAAY,EAAE,QAAQ,IAAI,EAAE,EAAE,MAAM,CAAC,EAAE,CAAC;QAChF,MAAM,IAAI,GAAG,IAAI,CAAC,IAAI,CAAC,GAAG,EAAE,IAAI,CAAC,CAAC;QAClC,IAAI,CAAC,EAAE,CAAC,UAAU,CAAC,IAAI,CAAC;YAAE,SAAS;QACnC,KAAK,MAAM,CAAC,IAAI,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,WAAW,CAAC,EAAE,CAAC,YAAY,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC;YACvF,IAAI,IAAI,CAAC,UAAU,CAAC,eAAe,CAAC,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC;gBAAE,GAAG,CAAC,IAAI,CAAC,GAAG,KAAK,CAAC;QACxE,CAAC;IACH,CAAC;AACH,CAAC"}
@@ -0,0 +1,63 @@
1
+ import type { AstroIntegration } from 'astro';
2
+ export interface VelocityCmsOptions {
3
+ /** Addresses to leave out of the sitemap, such as search results: `['/search/', '/es/buscar/']`. */
4
+ readonly unlisted?: readonly string[];
5
+ /** The site's name, shown in the editor, in sign-in emails and in the passkey prompt. */
6
+ readonly siteName?: string;
7
+ /**
8
+ * The file whose default export delivers sign-in links by email (a `Mailer`), from the
9
+ * project's root: `'./src/cms-mailer.ts'`. Without one, links are printed to the server's log.
10
+ */
11
+ readonly mailer?: string;
12
+ /**
13
+ * The folder of images that image fields choose from, from the project's root:
14
+ * `'./src/assets/photos'`. An image is called by its file name without the ending.
15
+ */
16
+ readonly images?: string;
17
+ /**
18
+ * The site's plugins, each a package name or a file from the project's root whose default
19
+ * export is a `definePlugin(...)`: `['@velocity-astro/cms-plugin-seo', './src/cms/ratings.ts']`.
20
+ * A plugin that cannot start is switched off and listed, with the reason, under Plugins in the editor.
21
+ */
22
+ readonly plugins?: readonly string[];
23
+ /**
24
+ * The content types whose entries are pages one route of the site draws, such as the pages
25
+ * people build in the editor: `['pages']`. Their addresses join the sitemap, search and share
26
+ * images, which otherwise know only the pages the site has files for.
27
+ */
28
+ readonly entryPages?: readonly string[];
29
+ }
30
+ /**
31
+ * The Velocity CMS integration. Add it to `integrations` in `astro.config.mjs`.
32
+ *
33
+ * It gives a site with live pages what the build used to make from finished pages, and the
34
+ * addresses that go with them:
35
+ *
36
+ * - `/sitemap-live.xml`: the live pages' share of the sitemap
37
+ * - `/og/<page>.png`: a share image for any live page, drawn on first use (on a Velocity site, which has the card drawing)
38
+ * - `/api/cms/search.json` and `/cms-search.js`: search from the CMS database
39
+ * - `/api/cms/submit/<form>` and `/cms-form.js`: where a form posts, and the script that sends it in place
40
+ * - `/api/cms/published`: where a publish is announced
41
+ * - `/media/<file>`: the images people upload in the editor
42
+ * - preview links, through a middleware
43
+ *
44
+ * And it switches the editor on:
45
+ *
46
+ * - `/admin`: the editor, whose image fields choose from the folder named by `images`
47
+ * - `/api/cms/*`: the API the editor calls
48
+ * - `/api/cms/auth/*`: sign-in with an email link or a passkey
49
+ *
50
+ * Uploads are kept in a folder beside a database that is a file, or in an S3-compatible bucket
51
+ * named by the `VELOCITY_CMS_S3_*` environment variables (see `mediaStoreFromEnv`). A host with
52
+ * neither takes no uploads, and image fields choose from the `images` folder alone.
53
+ *
54
+ * The editor needs `VELOCITY_CMS_SECRET` and the site's address (`site` in the Astro config).
55
+ * `npx velocity-cms init <email> <name>` sets both up in a new site and makes the first owner;
56
+ * `npx velocity-cms owner <email> <name>` makes the first owner alone.
57
+ *
58
+ * It also keeps this package out of the site's bundle. The package opens a SQLite database
59
+ * through a native module, which a bundler cannot carry. The routes above are the exception:
60
+ * they are compiled with the site, because they need to see the site's own pages.
61
+ */
62
+ export default function velocityCms(options?: VelocityCmsOptions): AstroIntegration;
63
+ //# sourceMappingURL=integration.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"integration.d.ts","sourceRoot":"","sources":["../src/integration.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,OAAO,CAAC;AAY9C,MAAM,WAAW,kBAAkB;IACjC,oGAAoG;IACpG,QAAQ,CAAC,QAAQ,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;IACtC,yFAAyF;IACzF,QAAQ,CAAC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAC3B;;;OAGG;IACH,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC;IACzB;;;OAGG;IACH,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC;IACzB;;;;OAIG;IACH,QAAQ,CAAC,OAAO,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;IACrC;;;;OAIG;IACH,QAAQ,CAAC,UAAU,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;CACzC;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AACH,MAAM,CAAC,OAAO,UAAU,WAAW,CAAC,OAAO,GAAE,kBAAuB,GAAG,gBAAgB,CAiFtF"}
@@ -0,0 +1,129 @@
1
+ import fs from 'node:fs';
2
+ import path from 'node:path';
3
+ import { fileURLToPath } from 'node:url';
4
+ import { loadCmsEnv } from './init.js';
5
+ const PACKAGE = '@velocity-astro/cms-astro';
6
+ const OPTIONS = 'virtual:velocity-cms/options';
7
+ const MAILER = 'virtual:velocity-cms/mailer';
8
+ const PLUGINS = 'virtual:velocity-cms/plugins';
9
+ const IMAGES = 'virtual:velocity-cms/images';
10
+ const IMAGE_FILES = '*.{jpg,jpeg,png,webp,avif,gif}';
11
+ const ADMIN_PATH = '/admin';
12
+ const route = (file) => fileURLToPath(new URL(`../routes/${file}`, import.meta.url));
13
+ /**
14
+ * The Velocity CMS integration. Add it to `integrations` in `astro.config.mjs`.
15
+ *
16
+ * It gives a site with live pages what the build used to make from finished pages, and the
17
+ * addresses that go with them:
18
+ *
19
+ * - `/sitemap-live.xml`: the live pages' share of the sitemap
20
+ * - `/og/<page>.png`: a share image for any live page, drawn on first use (on a Velocity site, which has the card drawing)
21
+ * - `/api/cms/search.json` and `/cms-search.js`: search from the CMS database
22
+ * - `/api/cms/submit/<form>` and `/cms-form.js`: where a form posts, and the script that sends it in place
23
+ * - `/api/cms/published`: where a publish is announced
24
+ * - `/media/<file>`: the images people upload in the editor
25
+ * - preview links, through a middleware
26
+ *
27
+ * And it switches the editor on:
28
+ *
29
+ * - `/admin`: the editor, whose image fields choose from the folder named by `images`
30
+ * - `/api/cms/*`: the API the editor calls
31
+ * - `/api/cms/auth/*`: sign-in with an email link or a passkey
32
+ *
33
+ * Uploads are kept in a folder beside a database that is a file, or in an S3-compatible bucket
34
+ * named by the `VELOCITY_CMS_S3_*` environment variables (see `mediaStoreFromEnv`). A host with
35
+ * neither takes no uploads, and image fields choose from the `images` folder alone.
36
+ *
37
+ * The editor needs `VELOCITY_CMS_SECRET` and the site's address (`site` in the Astro config).
38
+ * `npx velocity-cms init <email> <name>` sets both up in a new site and makes the first owner;
39
+ * `npx velocity-cms owner <email> <name>` makes the first owner alone.
40
+ *
41
+ * It also keeps this package out of the site's bundle. The package opens a SQLite database
42
+ * through a native module, which a bundler cannot carry. The routes above are the exception:
43
+ * they are compiled with the site, because they need to see the site's own pages.
44
+ */
45
+ export default function velocityCms(options = {}) {
46
+ let clientDir = '';
47
+ let site;
48
+ let root = '';
49
+ return {
50
+ name: PACKAGE,
51
+ hooks: {
52
+ 'astro:config:setup': ({ config, command, updateConfig, addMiddleware, injectRoute }) => {
53
+ root = fileURLToPath(config.root);
54
+ // The secret a person put in .env must reach the server that runs here, not only the site's code.
55
+ loadCmsEnv(root, command === 'dev' ? 'development' : 'production');
56
+ addMiddleware({ entrypoint: `${PACKAGE}/middleware`, order: 'pre' });
57
+ // Entries set to go out at a time are looked for as pages are asked for.
58
+ addMiddleware({ entrypoint: route('due.ts'), order: 'pre' });
59
+ // Loaded with the server, so the plugins are known before the first request.
60
+ if ((options.plugins ?? []).length > 0)
61
+ addMiddleware({ entrypoint: route('plugins.ts'), order: 'pre' });
62
+ injectRoute({ pattern: '/sitemap-live.xml', entrypoint: route('sitemap-live.xml.ts') });
63
+ // Share images are drawn by Velocity's own card drawing. A site without it keeps its own.
64
+ if (fs.existsSync(path.join(root, 'integrations', 'og-images.mjs')))
65
+ injectRoute({ pattern: '/og/[...live].png', entrypoint: route('share-image.png.ts') });
66
+ injectRoute({ pattern: '/api/cms/search.json', entrypoint: route('search.json.ts') });
67
+ injectRoute({ pattern: '/api/cms/published', entrypoint: route('published.ts') });
68
+ injectRoute({ pattern: '/cms-search.js', entrypoint: route('search-client.js.ts') });
69
+ injectRoute({ pattern: '/cms-form.js', entrypoint: route('form-client.js.ts') });
70
+ injectRoute({ pattern: '/cms-preview.js', entrypoint: route('preview-client.js.ts') });
71
+ injectRoute({ pattern: '/media/[file]', entrypoint: route('media.ts') });
72
+ injectRoute({ pattern: '/api/cms/submit/[form]', entrypoint: route('submit.ts') });
73
+ injectRoute({ pattern: '/api/cms/schedule', entrypoint: route('schedule.ts') });
74
+ injectRoute({ pattern: '/api/cms/auth/[...path]', entrypoint: route('auth.ts') });
75
+ injectRoute({ pattern: '/api/cms/[...path]', entrypoint: route('api.ts') });
76
+ injectRoute({ pattern: `${ADMIN_PATH}/[...path]`, entrypoint: route('admin.ts') });
77
+ const external = { resolve: { external: [PACKAGE] } };
78
+ updateConfig({
79
+ vite: {
80
+ ssr: { external: [PACKAGE] },
81
+ // Astro builds prerendered pages in their own Vite environment, which does not read `ssr`.
82
+ environments: { ssr: external, prerender: external, astro: external },
83
+ plugins: [
84
+ {
85
+ name: 'velocity-cms:options',
86
+ resolveId: (id) => (id === OPTIONS || id === MAILER || id === IMAGES || id === PLUGINS ? `\0${id}` : undefined),
87
+ load: (id) => {
88
+ if (id === `\0${OPTIONS}`) {
89
+ const editor = { site, siteName: options.siteName ?? 'Velocity CMS', adminPath: ADMIN_PATH };
90
+ return `export default ${JSON.stringify({ unlisted: options.unlisted ?? [], entryPages: options.entryPages ?? [], clientDir, editor })};`;
91
+ }
92
+ if (id === `\0${MAILER}`) {
93
+ return options.mailer
94
+ ? `export { default } from ${JSON.stringify(path.resolve(root, options.mailer))};`
95
+ : 'export default undefined;';
96
+ }
97
+ if (id === `\0${PLUGINS}`) {
98
+ // A path is the project's own file; anything else is a package the site installed.
99
+ const from = (plugin) => (/^\.{0,2}\//.test(plugin) ? path.resolve(root, plugin) : plugin);
100
+ const names = (options.plugins ?? []).map((plugin, index) => `import plugin${index} from ${JSON.stringify(from(plugin))};`);
101
+ return [...names, `export default [${names.map((_, index) => `plugin${index}`).join(', ')}];`].join('\n');
102
+ }
103
+ if (id === `\0${IMAGES}`) {
104
+ if (!options.images)
105
+ return 'export default undefined;';
106
+ const folder = path.relative(root, path.resolve(root, options.images)).split(path.sep).join('/');
107
+ return [
108
+ "import { getImage } from 'astro:assets';",
109
+ `import { folderImages } from ${JSON.stringify(PACKAGE)};`,
110
+ `const files = import.meta.glob(${JSON.stringify(`/${folder}/${IMAGE_FILES}`)}, { eager: true, import: 'default' });`,
111
+ // A small copy for the editor, made by the site's own image service.
112
+ 'export default folderImages(files, async (file) => (await getImage({ src: file, width: 480 })).src);',
113
+ ].join('\n');
114
+ }
115
+ return undefined;
116
+ },
117
+ },
118
+ ],
119
+ },
120
+ });
121
+ },
122
+ 'astro:config:done': ({ config }) => {
123
+ clientDir = fileURLToPath(config.adapter ? config.build.client : config.outDir);
124
+ site = config.site;
125
+ },
126
+ },
127
+ };
128
+ }
129
+ //# sourceMappingURL=integration.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"integration.js","sourceRoot":"","sources":["../src/integration.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,SAAS,CAAC;AACzB,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAEzC,OAAO,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AAEvC,MAAM,OAAO,GAAG,2BAA2B,CAAC;AAC5C,MAAM,OAAO,GAAG,8BAA8B,CAAC;AAC/C,MAAM,MAAM,GAAG,6BAA6B,CAAC;AAC7C,MAAM,OAAO,GAAG,8BAA8B,CAAC;AAC/C,MAAM,MAAM,GAAG,6BAA6B,CAAC;AAC7C,MAAM,WAAW,GAAG,gCAAgC,CAAC;AACrD,MAAM,UAAU,GAAG,QAAQ,CAAC;AAC5B,MAAM,KAAK,GAAG,CAAC,IAAY,EAAE,EAAE,CAAC,aAAa,CAAC,IAAI,GAAG,CAAC,aAAa,IAAI,EAAE,EAAE,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC;AA+B7F;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AACH,MAAM,CAAC,OAAO,UAAU,WAAW,CAAC,UAA8B,EAAE;IAClE,IAAI,SAAS,GAAG,EAAE,CAAC;IACnB,IAAI,IAAwB,CAAC;IAC7B,IAAI,IAAI,GAAG,EAAE,CAAC;IACd,OAAO;QACL,IAAI,EAAE,OAAO;QACb,KAAK,EAAE;YACL,oBAAoB,EAAE,CAAC,EAAE,MAAM,EAAE,OAAO,EAAE,YAAY,EAAE,aAAa,EAAE,WAAW,EAAE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,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;gBAChF,IAAI,GAAG,MAAM,CAAC,IAAI,CAAC;YACrB,CAAC;SACF;KACF,CAAC;AACJ,CAAC"}
package/dist/link.d.ts ADDED
@@ -0,0 +1,32 @@
1
+ import { type Cms, type ContentTypeDef, type Entry } from '@velocity-astro/cms-core';
2
+ import type { DrawnPage } from './page-head.js';
3
+ /** The language of the pages at a type's `urlPattern`. */
4
+ export declare const DEFAULT_LOCALE = "en";
5
+ /** Where a link leads, ready to be written into a page. */
6
+ export interface LinkTarget {
7
+ readonly href: string;
8
+ /** True when the link leaves the site. */
9
+ readonly external: boolean;
10
+ }
11
+ /** Every entry of a type. */
12
+ export declare function entriesOf(cms: Cms, type: ContentTypeDef): Promise<Entry[]>;
13
+ /**
14
+ * Turns the values of `link` fields into addresses for pages in one language. A type's entries
15
+ * are read once however many links point there, so make one for a page and use it for every link.
16
+ * `preview` follows the versions being worked on.
17
+ */
18
+ export declare function linkResolver(cms: Cms, locale: string, preview?: boolean): (link: unknown) => Promise<LinkTarget | undefined>;
19
+ /**
20
+ * Where a `link` field's value leads, for the page being drawn:
21
+ *
22
+ * ```astro
23
+ * const button = await linkTo(Astro, buttonLink);
24
+ * {button && <a href={button.href}>{buttonLabel}</a>}
25
+ * ```
26
+ *
27
+ * A link to an entry is that entry's address today, in the page's language. It answers with
28
+ * nothing when the entry is not published, the address is not one a site may link to, or
29
+ * anything goes wrong: a page is never lost over a button.
30
+ */
31
+ export declare function linkTo(page: DrawnPage, link: unknown): Promise<LinkTarget | undefined>;
32
+ //# sourceMappingURL=link.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"link.d.ts","sourceRoot":"","sources":["../src/link.ts"],"names":[],"mappings":"AAAA,OAAO,EAA2B,KAAK,GAAG,EAAE,KAAK,cAAc,EAAE,KAAK,KAAK,EAAE,MAAM,0BAA0B,CAAC;AAE9G,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAGhD,0DAA0D;AAC1D,eAAO,MAAM,cAAc,OAAO,CAAC;AAGnC,2DAA2D;AAC3D,MAAM,WAAW,UAAU;IACzB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,0CAA0C;IAC1C,QAAQ,CAAC,QAAQ,EAAE,OAAO,CAAC;CAC5B;AAKD,6BAA6B;AAC7B,wBAAsB,SAAS,CAAC,GAAG,EAAE,GAAG,EAAE,IAAI,EAAE,cAAc,GAAG,OAAO,CAAC,KAAK,EAAE,CAAC,CAQhF;AAED;;;;GAIG;AACH,wBAAgB,YAAY,CAAC,GAAG,EAAE,GAAG,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,UAAQ,GAAG,CAAC,IAAI,EAAE,OAAO,KAAK,OAAO,CAAC,UAAU,GAAG,SAAS,CAAC,CAuB1H;AAED;;;;;;;;;;;GAWG;AACH,wBAAsB,MAAM,CAAC,IAAI,EAAE,SAAS,EAAE,IAAI,EAAE,OAAO,GAAG,OAAO,CAAC,UAAU,GAAG,SAAS,CAAC,CAQ5F"}
package/dist/link.js ADDED
@@ -0,0 +1,76 @@
1
+ import { isSafeLink, pageAddress } from '@velocity-astro/cms-core';
2
+ import { sharedConnection, SITE } from './connection.js';
3
+ import { isPreview } 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
+ return await linkResolver(cms, page.currentLocale ?? DEFAULT_LOCALE, isPreview())(link);
70
+ }
71
+ catch (error) {
72
+ console.error('[velocity-cms] A link could not be worked out, so it is left off the page.', error);
73
+ return undefined;
74
+ }
75
+ }
76
+ //# sourceMappingURL=link.js.map
@@ -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,MAAM,cAAc,CAAC;AAEzC,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,KAAK,EAAE,SAAS,EAAE,MAAM,EAAE,CAAC,CAAC;QACzF,OAAO,CAAC,IAAI,CAAC,GAAG,IAAI,C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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,OAAO,MAAM,YAAY,CAAC,GAAG,EAAE,IAAI,CAAC,aAAa,IAAI,cAAc,EAAE,SAAS,EAAE,CAAC,CAAC,IAAI,CAAC,CAAC;IAC1F,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,40 @@
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
+ /** The cache tag every page showing entries of a type carries. Publishing clears it. */
15
+ export declare const typeTag: (typeKey: string) => string;
16
+ /** The cache tag for one entry, for pages that show only that entry. */
17
+ export declare const entryTag: (typeKey: string, id: string) => string;
18
+ /**
19
+ * A number that goes up every time published content changes. Anything a site derives from live
20
+ * content and keeps in memory can be stored beside this number and thrown away when it moves.
21
+ */
22
+ export declare const liveContentVersion: () => number;
23
+ /** Tells this server that published content changed. Called on publish, before clearing the page cache. */
24
+ export declare function invalidateLiveContent(): void;
25
+ /**
26
+ * A live loader: pages rendered on demand read published entries straight from the CMS, so a
27
+ * change shows as soon as the page's cache is cleared instead of after a rebuild.
28
+ *
29
+ * Each entry comes back with cache tags. Pass an entry to `Astro.cache.set()` and the page is
30
+ * cached under those tags; clearing `typeTag('listings')` on publish refreshes every such page.
31
+ *
32
+ * ```ts
33
+ * // src/live.config.ts
34
+ * export const collections = {
35
+ * listings: defineLiveCollection({ loader: cmsLiveLoader({ type: 'listings' }), schema }),
36
+ * };
37
+ * ```
38
+ */
39
+ export declare function cmsLiveLoader(options: CmsLiveLoaderOptions): LiveLoader<Record<string, unknown>, CmsEntryFilter, CmsCollectionFilter>;
40
+ //# 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;AAGjF,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,wFAAwF;AACxF,eAAO,MAAM,OAAO,GAAI,SAAS,MAAM,KAAG,MAA0B,CAAC;AAErE,wEAAwE;AACxE,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;;;;;;;;;;;;;GAaG;AACH,wBAAgB,aAAa,CAC3B,OAAO,EAAE,oBAAoB,GAC5B,UAAU,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,cAAc,EAAE,mBAAmB,CAAC,CAyD1E"}