astronaut-cms 0.0.1 → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (119) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +84 -3
  3. package/dist/admin/THIRD_PARTY_LICENSES.md +7598 -0
  4. package/dist/admin/assets/assistant-DkS355co.js +201 -0
  5. package/dist/admin/assets/badge-BXsOvOPX.js +1 -0
  6. package/dist/admin/assets/changes-Ba0G_GN1.js +1 -0
  7. package/dist/admin/assets/client-VKp75fDU.js +5 -0
  8. package/dist/admin/assets/clsx-DB0hHKMi.js +1 -0
  9. package/dist/admin/assets/collapsible-B6P_J0Bg.js +1 -0
  10. package/dist/admin/assets/collapsible-item-UaoJaaPw.js +1 -0
  11. package/dist/admin/assets/collections._collection-BE1enDCq.js +1 -0
  12. package/dist/admin/assets/collections._collection._entry-D3UksnCo.js +52 -0
  13. package/dist/admin/assets/collections._collection.index-BN5d8UIY.js +1 -0
  14. package/dist/admin/assets/component-lookup-CUCiK8Xh.js +4 -0
  15. package/dist/admin/assets/config-Pm_BHLNT.js +1 -0
  16. package/dist/admin/assets/copy-DezZzPMV.js +1 -0
  17. package/dist/admin/assets/css-BGIxQoYs.js +1 -0
  18. package/dist/admin/assets/css-DgaLhXQH.js +1 -0
  19. package/dist/admin/assets/diff-woXpYk--.js +1 -0
  20. package/dist/admin/assets/dist-DzkcSBZl.js +1 -0
  21. package/dist/admin/assets/dist-UbA1s2kM.js +1 -0
  22. package/dist/admin/assets/docx-BctAmX91.js +56 -0
  23. package/dist/admin/assets/editor-FGqMznBK.js +2 -0
  24. package/dist/admin/assets/empty-DSBYiI_7.js +1 -0
  25. package/dist/admin/assets/entry-link-CQLN2Zpf.js +158 -0
  26. package/dist/admin/assets/error-banner-yskeRXe8.js +159 -0
  27. package/dist/admin/assets/errors-DkJ5E_ak.js +1 -0
  28. package/dist/admin/assets/field-BDK5tt3J.js +41 -0
  29. package/dist/admin/assets/field-schema-CacrjSYw.js +1 -0
  30. package/dist/admin/assets/file-text-BzBif8ui.js +1 -0
  31. package/dist/admin/assets/github-dark-C-LZuMrd.js +1 -0
  32. package/dist/admin/assets/github-light-EUqPIrTm.js +1 -0
  33. package/dist/admin/assets/highlighted-body-JLMTFACH-CIQujGv2.js +1 -0
  34. package/dist/admin/assets/html-CvFb5cGI.js +1 -0
  35. package/dist/admin/assets/javascript-BzbQS41l.js +1 -0
  36. package/dist/admin/assets/javascript-CpIGwZ_Y.js +1 -0
  37. package/dist/admin/assets/json-qhed-kSA.js +1 -0
  38. package/dist/admin/assets/jsx-Bz0zcwM4.js +1 -0
  39. package/dist/admin/assets/lib-CMURo-7A.js +21 -0
  40. package/dist/admin/assets/library-Cr3f75Es.js +1 -0
  41. package/dist/admin/assets/list-skeleton-BdTNfVXs.js +1 -0
  42. package/dist/admin/assets/markdown-BYOwaDjH.js +1 -0
  43. package/dist/admin/assets/matchContext-Bq5Es9aD.js +2 -0
  44. package/dist/admin/assets/media-browser-9-CPTCks.js +1 -0
  45. package/dist/admin/assets/media._library-BfFaEZLR.js +1 -0
  46. package/dist/admin/assets/mermaid-WFAXDIZX-CJ3hhA0i.js +1 -0
  47. package/dist/admin/assets/page-header-B4nvAsVA.js +1 -0
  48. package/dist/admin/assets/pdf-DgessaF0.js +106 -0
  49. package/dist/admin/assets/python-gzcpVVnB.js +1 -0
  50. package/dist/admin/assets/react-kbcsfQYH.js +1 -0
  51. package/dist/admin/assets/rolldown-runtime-BWaJ3C7D.js +1 -0
  52. package/dist/admin/assets/routes-CBt04sNR.js +1 -0
  53. package/dist/admin/assets/routes-D7tEdYGV.js +1 -0
  54. package/dist/admin/assets/save-actions-Cz0TkpcP.js +32 -0
  55. package/dist/admin/assets/select-Bv2EoLhN.js +1 -0
  56. package/dist/admin/assets/separator-DlYj_PoQ.js +3 -0
  57. package/dist/admin/assets/shell-DBEiq06l.js +1 -0
  58. package/dist/admin/assets/shellscript-CLZ0U2zV.js +1 -0
  59. package/dist/admin/assets/skeleton-CKiqTaRh.js +1 -0
  60. package/dist/admin/assets/sql-CEbI0hMM.js +1 -0
  61. package/dist/admin/assets/syntax-BAXqRKRO.js +8 -0
  62. package/dist/admin/assets/toggle-Y2UpJZyU.js +1 -0
  63. package/dist/admin/assets/toml-BPTmHmyx.js +1 -0
  64. package/dist/admin/assets/tsx-udAQXfEw.js +1 -0
  65. package/dist/admin/assets/typescript-bsJCZSQ-.js +1 -0
  66. package/dist/admin/assets/ui.module.css-WaO_77ml.js +56 -0
  67. package/dist/admin/assets/use-entries-B2lsaiK9.js +1 -0
  68. package/dist/admin/assets/useSelector-CWr3iU9K.js +1 -0
  69. package/dist/admin/assets/yaml-rwi0_p6S.js +1 -0
  70. package/dist/admin/assets/zwitch-Wwuax-dJ.js +1 -0
  71. package/dist/admin/bootstrap.d.ts +1 -0
  72. package/dist/admin/bootstrap.js +1 -0
  73. package/dist/admin/editor.d.ts +57 -0
  74. package/dist/admin/editor.js +1 -0
  75. package/dist/server/assets.d.ts +2 -0
  76. package/dist/server/assets.js +30 -0
  77. package/dist/server/chunks/anchors-DuZ1fokt.js +86 -0
  78. package/dist/server/chunks/auth-DJP9ryVd.js +44 -0
  79. package/dist/server/chunks/cms-markers-CUqrOnfA.js +78 -0
  80. package/dist/server/chunks/component-lookup-DAFg_Qg8.js +128 -0
  81. package/dist/server/chunks/config-WQqG4mNH.d.ts +193 -0
  82. package/dist/server/chunks/digest-BYzWNJea.js +753 -0
  83. package/dist/server/chunks/entry-checks-CKMag1G4.js +608 -0
  84. package/dist/server/chunks/field-schema-CfdN75jT.js +48 -0
  85. package/dist/server/chunks/http-BnsNh57m.d.ts +35 -0
  86. package/dist/server/chunks/i18n-BPmx7ESy.d.ts +15 -0
  87. package/dist/server/chunks/index-CYbkNvu5.d.ts +22 -0
  88. package/dist/server/chunks/media-BhqUVVYY.js +223 -0
  89. package/dist/server/chunks/paths-CEW9fvg8.js +17 -0
  90. package/dist/server/chunks/paths-Dztx2eUw.js +13 -0
  91. package/dist/server/chunks/types-DOR5XaJO.js +397 -0
  92. package/dist/server/chunks/types-Dkx4Xovf.d.ts +359 -0
  93. package/dist/server/chunks/types-DwA-C6Br.d.ts +266 -0
  94. package/dist/server/chunks/user-config-DoypbpQf.js +283 -0
  95. package/dist/server/chunks/xml-D8qPILJU.js +81 -0
  96. package/dist/server/config.d.ts +3 -0
  97. package/dist/server/config.js +18 -0
  98. package/dist/server/content.d.ts +48 -0
  99. package/dist/server/content.js +89 -0
  100. package/dist/server/endpoint.d.ts +11 -0
  101. package/dist/server/endpoint.js +2712 -0
  102. package/dist/server/integration.d.ts +7 -0
  103. package/dist/server/integration.js +1174 -0
  104. package/dist/server/internal.d.ts +65 -0
  105. package/dist/server/internal.js +30 -0
  106. package/dist/server/server-local.d.ts +453 -0
  107. package/dist/server/server-local.js +336 -0
  108. package/dist/styles/THIRD_PARTY_LICENSES.md +193 -0
  109. package/dist/styles/assets/geist-cyrillic-ext-wght-normal-DjL33-gN.woff2 +0 -0
  110. package/dist/styles/assets/geist-cyrillic-wght-normal-BEAKL7Jp.woff2 +0 -0
  111. package/dist/styles/assets/geist-latin-ext-wght-normal-DC-KSUi6.woff2 +0 -0
  112. package/dist/styles/assets/geist-latin-wght-normal-BgDaEnEv.woff2 +0 -0
  113. package/dist/styles/assets/geist-vietnamese-wght-normal-6IgcOCM7.woff2 +0 -0
  114. package/dist/styles/styles.css +3 -0
  115. package/package.json +151 -5
  116. package/src/astro/Image.astro +28 -0
  117. package/src/astro/Video.astro +44 -0
  118. package/src/astro/admin.astro +137 -0
  119. package/src/astro/licenses.ts +5 -0
@@ -0,0 +1,283 @@
1
+ import { o as CMS_REFERENCE, s as isRecord } from "./field-schema-CfdN75jT.js";
2
+ import { c as schemaHelpers } from "./cms-markers-CUqrOnfA.js";
3
+ import { n as componentEntries } from "./component-lookup-DAFg_Qg8.js";
4
+ import { z } from "zod";
5
+ // src/shared/zod-to-field.ts
6
+ /**
7
+ * Lowers a live Zod v4 schema into a serializable {@link FieldSchema}. Runs in
8
+ * Node (content collections) and in the browser (CMS component props); the
9
+ * resulting plain object is what crosses the boundary, so no Zod instance ever
10
+ * does.
11
+ *
12
+ * Introspection goes entirely through Zod's public surface: `instanceof` against
13
+ * the exported schema classes, their public accessors (`.unwrap()`, `.options`,
14
+ * `.element`, `.shape`, `.valueType`, `.meta()`), the public typed `.def`, and
15
+ * `z.toJSONSchema()` for declarative constraints (min/max, regex, multipleOf, ...).
16
+ */
17
+ var MAX_DEPTH = 10;
18
+ /**
19
+ * Lowers a (live) Zod v4 schema into a serializable {@link FieldSchema}. `i18n`
20
+ * lays a `localized()` field out as one field per content language, the default
21
+ * one required. Without content languages it stays a record.
22
+ */
23
+ function zodToFieldSchema(schema, i18n = null) {
24
+ return lower(schema, 0, i18n);
25
+ }
26
+ function lower(input, depth, i18n) {
27
+ if (depth > MAX_DEPTH) return { type: "unknown" };
28
+ const mods = {};
29
+ const meta = {};
30
+ let schema = input;
31
+ while (schema instanceof z.ZodType) {
32
+ readMeta(schema, meta);
33
+ if (schema instanceof z.ZodOptional) {
34
+ if (!("optional" in mods)) mods.optional = true;
35
+ schema = schema.unwrap();
36
+ } else if (schema instanceof z.ZodNonOptional) {
37
+ if (!("optional" in mods)) mods.optional = false;
38
+ schema = schema.unwrap();
39
+ } else if (schema instanceof z.ZodNullable) {
40
+ mods.nullable = true;
41
+ schema = schema.unwrap();
42
+ } else if (schema instanceof z.ZodDefault || schema instanceof z.ZodPrefault) {
43
+ if (!("default" in mods)) mods.default = schema.def.defaultValue;
44
+ schema = schema.unwrap();
45
+ } else if (schema instanceof z.ZodCatch) {
46
+ mods.catch = true;
47
+ schema = schema.unwrap();
48
+ } else if (schema instanceof z.ZodPipe) schema = schema.out;
49
+ else if (schema instanceof z.ZodReadonly) schema = schema.unwrap();
50
+ else break;
51
+ }
52
+ const base = convertBase(schema, depth, i18n);
53
+ if (mods.optional) base.optional = true;
54
+ if (mods.nullable) base.nullable = true;
55
+ if ("default" in mods) base.default = mods.default;
56
+ if (mods.catch) base.catch = true;
57
+ return Object.assign(base, meta);
58
+ }
59
+ function readMeta(schema, meta) {
60
+ const data = schema.meta();
61
+ if (typeof data?.title === "string") meta.label ??= data.title;
62
+ if (typeof data?.description === "string") meta.description ??= data.description;
63
+ if (typeof data?.group === "string") meta.group ??= data.group;
64
+ if (data?.multiline === true) meta.multiline ??= true;
65
+ if (isStringRecord(data?.labels)) meta.labels ??= data.labels;
66
+ }
67
+ var isStringRecord = (value) => isRecord(value) && Object.values(value).every((label) => typeof label === "string");
68
+ function literalValue(value) {
69
+ if (value === null || typeof value === "string" || typeof value === "number" || typeof value === "boolean") return value;
70
+ throw new Error("CMS schema literals must be strings, numbers, booleans, or null.");
71
+ }
72
+ function constraintsOf(schema) {
73
+ try {
74
+ return z.toJSONSchema(schema, { unrepresentable: "any" });
75
+ } catch {
76
+ return {};
77
+ }
78
+ }
79
+ function realBound(value, sentinel) {
80
+ return typeof value === "number" && value !== sentinel ? value : void 0;
81
+ }
82
+ function convertBase(schema, depth, i18n) {
83
+ if (!(schema instanceof z.ZodType)) return { type: "unknown" };
84
+ const meta = schema.meta();
85
+ if (meta?.["x-cms-image"] === "repo") return {
86
+ type: "image",
87
+ repoOnly: true
88
+ };
89
+ if (meta?.["x-cms-image"]) return { type: "image" };
90
+ if (meta?.["x-cms-file"]) return { type: "file" };
91
+ if (meta?.["x-cms-link"]) return {
92
+ type: "string",
93
+ format: "link"
94
+ };
95
+ const ref = meta?.[CMS_REFERENCE];
96
+ if (typeof ref === "string") return {
97
+ type: "reference",
98
+ collection: ref
99
+ };
100
+ const next = depth + 1;
101
+ if (schema instanceof z.ZodString || schema instanceof z.ZodStringFormat) {
102
+ const js = constraintsOf(schema);
103
+ const field = { type: "string" };
104
+ if (js.format === "email") field.format = "email";
105
+ else if (js.format === "uri") field.format = "url";
106
+ if (typeof js.minLength === "number") field.minLength = js.minLength;
107
+ if (typeof js.maxLength === "number") field.maxLength = js.maxLength;
108
+ if (!field.format && typeof js.pattern === "string") field.pattern = js.pattern;
109
+ if (meta?.["x-cms-anchor"]) field.format = "anchor";
110
+ return field;
111
+ }
112
+ if (schema instanceof z.ZodNumber) {
113
+ const js = constraintsOf(schema);
114
+ const field = { type: "number" };
115
+ if (js.type === "integer") field.integer = true;
116
+ const min = realBound(js.minimum, Number.MIN_SAFE_INTEGER);
117
+ const max = realBound(js.maximum, Number.MAX_SAFE_INTEGER);
118
+ if (min !== void 0) field.min = min;
119
+ if (max !== void 0) field.max = max;
120
+ if (typeof js.exclusiveMinimum === "number") field.exclusiveMin = js.exclusiveMinimum;
121
+ if (typeof js.exclusiveMaximum === "number") field.exclusiveMax = js.exclusiveMaximum;
122
+ if (typeof js.multipleOf === "number") field.multipleOf = js.multipleOf;
123
+ return field;
124
+ }
125
+ if (schema instanceof z.ZodBoolean) return { type: "boolean" };
126
+ if (schema instanceof z.ZodDate) return { type: "date" };
127
+ if (schema instanceof z.ZodEnum) return {
128
+ type: "enum",
129
+ options: schema.options.map(literalValue)
130
+ };
131
+ if (schema instanceof z.ZodLiteral) {
132
+ const values = schema.def.values;
133
+ if (values.length > 1) return {
134
+ type: "union",
135
+ variants: values.map((value) => ({
136
+ type: "literal",
137
+ value: literalValue(value)
138
+ }))
139
+ };
140
+ return {
141
+ type: "literal",
142
+ value: literalValue(values[0])
143
+ };
144
+ }
145
+ if (schema instanceof z.ZodArray) {
146
+ const js = constraintsOf(schema);
147
+ const field = {
148
+ type: "array",
149
+ element: lower(schema.element, next, i18n)
150
+ };
151
+ if (typeof js.minItems === "number") field.minItems = js.minItems;
152
+ if (typeof js.maxItems === "number") field.maxItems = js.maxItems;
153
+ return field;
154
+ }
155
+ if (schema instanceof z.ZodTuple) return {
156
+ type: "tuple",
157
+ items: schema.def.items.map((item) => lower(item, next, i18n))
158
+ };
159
+ if (schema instanceof z.ZodObject) {
160
+ const shape = {};
161
+ for (const [key, value] of Object.entries(schema.shape)) shape[key] = lower(value, next, i18n);
162
+ return schema.def.catchall instanceof z.ZodNever ? {
163
+ type: "object",
164
+ shape,
165
+ strict: true
166
+ } : {
167
+ type: "object",
168
+ shape
169
+ };
170
+ }
171
+ if (schema instanceof z.ZodRecord) {
172
+ const value = lower(schema.valueType, next, i18n);
173
+ if (!meta?.["x-cms-localized"] || !i18n) return {
174
+ type: "record",
175
+ value
176
+ };
177
+ return {
178
+ type: "object",
179
+ shape: Object.fromEntries(i18n.locales.map((locale) => [locale, locale === i18n.defaultLocale ? value : {
180
+ ...value,
181
+ optional: true
182
+ }])),
183
+ strict: true,
184
+ localized: true
185
+ };
186
+ }
187
+ if (schema instanceof z.ZodUnion) {
188
+ const variants = schema.options.map((option) => lower(option, next, i18n));
189
+ const discriminator = schema instanceof z.ZodDiscriminatedUnion ? schema.def.discriminator : void 0;
190
+ return typeof discriminator === "string" ? {
191
+ type: "union",
192
+ discriminator,
193
+ variants
194
+ } : {
195
+ type: "union",
196
+ variants
197
+ };
198
+ }
199
+ if (schema instanceof z.ZodIntersection) {
200
+ const left = lower(schema.def.left, next, i18n);
201
+ const right = lower(schema.def.right, next, i18n);
202
+ if (left.type === "object" && right.type === "object") return {
203
+ type: "object",
204
+ shape: {
205
+ ...left.shape,
206
+ ...right.shape
207
+ }
208
+ };
209
+ return { type: "unknown" };
210
+ }
211
+ if (schema instanceof z.ZodLazy) return lower(schema.unwrap(), next, i18n);
212
+ return { type: "unknown" };
213
+ }
214
+ // src/shared/component-props.ts
215
+ var loweringHelpers = schemaHelpers(() => {
216
+ throw new Error("astronaut-cms: an image() prop is resolved on the site alone.");
217
+ });
218
+ /**
219
+ * A component's props schema, built from the schema helpers when it is declared
220
+ * as a function, and an empty object for a component that declares none.
221
+ */
222
+ function componentSchema({ props }, helpers = loweringHelpers) {
223
+ if (props === void 0) return z.object({});
224
+ return typeof props === "function" ? props(helpers) : props;
225
+ }
226
+ /**
227
+ * Parses a component's attributes by its name, so every `.default()` and
228
+ * transform applies, and keeps any attribute the schema does not declare, such
229
+ * as `class`. Every `image()` prop is resolved with `resolveImage` on the way,
230
+ * so a component receives its images as a collection's `image()` field arrives:
231
+ * as `ImageMetadata`, or an object-store URL. MDX hands a component its
232
+ * attributes verbatim, which is why the generated wrappers run this before
233
+ * rendering it. Every schema is built once.
234
+ */
235
+ function propsResolver(components, resolveImage) {
236
+ const helpers = schemaHelpers(resolveImage);
237
+ const schemas = new Map(componentEntries(components).map(([name, def]) => [name, componentSchema(def, helpers)]));
238
+ return async (name, props) => {
239
+ const schema = schemas.get(name);
240
+ if (!schema) throw new Error(`No component "${name}" in cms.config.`);
241
+ const result = await schema.safeParseAsync(props);
242
+ if (!result.success) throw new Error(`Invalid props for ${name}:\n${z.prettifyError(result.error)}`);
243
+ return {
244
+ ...props,
245
+ ...result.data
246
+ };
247
+ };
248
+ }
249
+ // src/internal/user-config.ts
250
+ /**
251
+ * An MDX body refers to a component by its name alone, so one name may stand
252
+ * for one definition only. A child set may reuse a definition under the same name.
253
+ * `i18n` lays out the `localized()` props, see {@link zodToFieldSchema}.
254
+ */
255
+ function processUserConfig(components, i18n) {
256
+ const seen = /* @__PURE__ */ new Map();
257
+ const walk = (defs) => {
258
+ const result = {};
259
+ for (const [name, def] of Object.entries(defs)) {
260
+ const previous = seen.get(name);
261
+ if (previous && previous !== def) throw new Error(`Component name "${name}" is defined twice in cms.config: names must be unique.`);
262
+ seen.set(name, def);
263
+ result[name] = {
264
+ props: zodToFieldSchema(componentSchema(def), i18n),
265
+ children: typeof def.children === "object" ? walk(def.children) : def.children,
266
+ kind: def.kind ?? "flow",
267
+ label: def.label ?? name,
268
+ description: def.description ?? null,
269
+ summary: def.summary ?? null,
270
+ icon: def.icon ?? null,
271
+ editor: def.editor ?? null,
272
+ collections: def.collections ?? []
273
+ };
274
+ }
275
+ return result;
276
+ };
277
+ return walk(components ?? {});
278
+ }
279
+ /** The collections' icons by name, the one option the manifest cannot carry, being live components. */
280
+ function processCollectionIcons(collections) {
281
+ return Object.fromEntries(Object.entries(collections ?? {}).flatMap(([name, { icon }]) => icon ? [[name, icon]] : []));
282
+ }
283
+ export { zodToFieldSchema as i, processUserConfig as n, propsResolver as r, processCollectionIcons as t };
@@ -0,0 +1,81 @@
1
+ import { z } from "zod";
2
+ import { XMLParser } from "fast-xml-parser";
3
+ // src/shared/ai.ts
4
+ /** The key of a `custom` gateway, optional since a local model server needs none. */
5
+ var AI_API_KEY_ENV = "ASTRONAUT_CMS_AI_API_KEY";
6
+ /**
7
+ * The one statement of where a gateway is. The relay and a browser holding the
8
+ * editor's own key both address it through here, so the two cannot drift into
9
+ * reaching the same gateway by different routes. Null for `netlify`, whose
10
+ * address comes from the server's environment.
11
+ */
12
+ function gatewayAddress(gateway) {
13
+ switch (gateway.type) {
14
+ case "netlify": return null;
15
+ case "vercel": return {
16
+ baseUrl: "https://ai-gateway.vercel.sh/v1",
17
+ headers: {},
18
+ keys: [
19
+ { env: "AI_GATEWAY_API_KEY" },
20
+ { header: "x-vercel-oidc-token" },
21
+ { env: "VERCEL_OIDC_TOKEN" }
22
+ ],
23
+ byok: false
24
+ };
25
+ case "cloudflare": return {
26
+ baseUrl: `https://api.cloudflare.com/client/v4/accounts/${gateway.accountId}/ai/v1`,
27
+ headers: { "cf-aig-gateway-id": gateway.gatewayId ?? "default" },
28
+ keys: [{ env: "CLOUDFLARE_API_TOKEN" }],
29
+ byok: true
30
+ };
31
+ case "custom": return {
32
+ baseUrl: gateway.baseUrl,
33
+ headers: {},
34
+ keys: [{ env: AI_API_KEY_ENV }],
35
+ byok: true
36
+ };
37
+ }
38
+ }
39
+ /** Netlify injects both into its functions, and the relay reads them only as a pair. */
40
+ var NETLIFY_GATEWAY_ENV = ["OPENAI_BASE_URL", "OPENAI_API_KEY"];
41
+ /** Every environment variable the relay may read for a gateway, so the integration can declare them. */
42
+ function gatewayEnv(gateway) {
43
+ const address = gatewayAddress(gateway);
44
+ if (!address) return [...NETLIFY_GATEWAY_ENV];
45
+ return address.keys.flatMap((source) => "env" in source ? [source.env] : []);
46
+ }
47
+ // src/shared/repo.ts
48
+ /**
49
+ * Parsing an `owner/repo` pair, which both the build (resolving the config) and
50
+ * the server (calling the API) need. It lives here rather than beside either of
51
+ * them because an import in the other direction drags a runtime module into the
52
+ * Astro config, where the CMS's virtual modules do not exist yet.
53
+ */
54
+ function parseRepo(repo) {
55
+ const parts = repo.split("/");
56
+ const [owner, name] = parts;
57
+ if (parts.length !== 2 || !owner || !name) throw new Error(`Invalid GitHub repo: ${repo}`);
58
+ return {
59
+ owner,
60
+ repo: name
61
+ };
62
+ }
63
+ // src/shared/xml.ts
64
+ /**
65
+ * XML read into plain values, then checked against the shape the caller
66
+ * expects rather than trusted.
67
+ */
68
+ var parser = new XMLParser({
69
+ parseTagValue: false,
70
+ trimValues: false,
71
+ htmlEntities: true,
72
+ removeNSPrefix: true,
73
+ ignoreDeclaration: true
74
+ });
75
+ /** An element that may repeat, which reads as a lone value when it occurs once. */
76
+ var xmlList = (item) => z.preprocess((value) => value === void 0 ? [] : [value].flat(), z.array(item));
77
+ /** Parse an XML document, rejecting one that is malformed or of another shape. */
78
+ function parseXml(xml, schema) {
79
+ return schema.parse(parser.parse(xml, true));
80
+ }
81
+ export { gatewayAddress as a, NETLIFY_GATEWAY_ENV as i, xmlList as n, gatewayEnv as o, parseRepo as r, parseXml as t };
@@ -0,0 +1,3 @@
1
+ import { a as ComponentDefinition, c as defineCollection, d as anchorMarker, f as fileMarker, h as localizedMarker, i as CollectionRegistry, l as defineComponent, m as linkMarker, n as CollectionName, o as ComponentIcon, p as libraryImage, r as CollectionOptions, s as SchemaHelpers, t as ChildrenConfig, v as JsxEditor, y as JsxEditorProps } from "./chunks/config-WQqG4mNH.js";
2
+ import { i as CollectionSort } from "./chunks/types-DwA-C6Br.js";
3
+ export { ChildrenConfig, CollectionName, CollectionOptions, CollectionRegistry, type CollectionSort, ComponentDefinition, ComponentIcon, type JsxEditor, type JsxEditorProps, SchemaHelpers, anchorMarker as anchor, defineCollection, defineComponent, fileMarker as file, libraryImage, linkMarker as link, localizedMarker as localized };
@@ -0,0 +1,18 @@
1
+ import { a as localizedMarker, i as linkMarker, n as fileMarker, r as libraryImage, t as anchorMarker } from "./chunks/cms-markers-CUqrOnfA.js";
2
+ // src/config.ts
3
+ /**
4
+ * One entry of the `collections` export of `cms.config`, keyed like the
5
+ * collections of `content.config`, as {@link defineComponent} is one entry of
6
+ * `components`.
7
+ */
8
+ function defineCollection(options) {
9
+ return options;
10
+ }
11
+ /**
12
+ * One entry of the `components` export of `cms.config`. The integration renders
13
+ * it in MDX through a generated wrapper, which `astronaut-cms:components` exports.
14
+ */
15
+ function defineComponent(def) {
16
+ return def;
17
+ }
18
+ export { anchorMarker as anchor, defineCollection, defineComponent, fileMarker as file, libraryImage, linkMarker as link, localizedMarker as localized };
@@ -0,0 +1,48 @@
1
+ import { CollectionEntry, CollectionKey } from "astro:content";
2
+ /** What ordering reads off an entry of astro's `getCollection`. */
3
+ interface SortableEntry {
4
+ id: string;
5
+ collection: string;
6
+ }
7
+ /**
8
+ * The entries of one collection, in the order its `sort` option names.
9
+ *
10
+ * @example
11
+ * const events = sortEntries(await getCollection("events"));
12
+ */
13
+ export declare function sortEntries<E extends SortableEntry>(entries: readonly E[]): E[];
14
+ /** An entry of a localized collection as one language shows it. */
15
+ export interface LocalizedEntry<E> {
16
+ entry: E;
17
+ /** The id without its language, shared by every translation. */
18
+ slug: string;
19
+ /** Whether the entry is the default language's, standing in for a missing translation. */
20
+ isFallback: boolean;
21
+ }
22
+ /**
23
+ * The entries of a localized collection in `locale`, each slug once: its own
24
+ * translation, or else the default language's, flagged as a fallback.
25
+ *
26
+ * @example
27
+ * const posts = localizeEntries(await getCollection("posts"), Astro.currentLocale);
28
+ */
29
+ export declare function localizeEntries<E extends {
30
+ id: string;
31
+ }>(entries: readonly E[], locale: string): LocalizedEntry<E>[];
32
+ /**
33
+ * One entry of a localized collection in `locale`, or the default language's
34
+ * when it has no translation, such as the texts of a localized singleton.
35
+ *
36
+ * @example
37
+ * const texts = await getLocalizedEntry("texts", "site", Astro.currentLocale);
38
+ */
39
+ export declare function getLocalizedEntry<C extends CollectionKey>(collection: C, slug: string, locale: string): Promise<LocalizedEntry<CollectionEntry<C>> | undefined>;
40
+ /**
41
+ * The value of a `localized()` field in `locale`, or the default language's,
42
+ * which the build guarantees.
43
+ *
44
+ * @example
45
+ * const title = pickLocale(settings.data.imagefilm.title, Astro.currentLocale);
46
+ */
47
+ export declare function pickLocale<T>(value: Partial<Record<string, T>>, locale: string): T;
48
+ export {};
@@ -0,0 +1,89 @@
1
+ import { a as compareIds, g as splitLocale, h as joinLocale, m as sortByIds } from "./chunks/types-DOR5XaJO.js";
2
+ import { getEntry } from "astro:content";
3
+ import { contentI18n, fileOrder, sorts } from "virtual:astronaut-cms/content";
4
+ // src/content/index.ts
5
+ /**
6
+ * Reading content in the site the way the admin edits it: entry order, and the
7
+ * language of localized collections and fields.
8
+ *
9
+ * Entry order is the same the admin shows. Astro's content store
10
+ * returns a collection sorted by id and keeps no trace of the order a `file()`
11
+ * collection's file holds, so a collection with a `sort` option is ordered here,
12
+ * from what the integration read off the content.
13
+ */
14
+ var ranks = new Map(Object.entries(fileOrder).map(([name, ids]) => [name, new Map(ids.map((id, index) => [id, index]))]));
15
+ /**
16
+ * The entries of one collection, in the order its `sort` option names.
17
+ *
18
+ * @example
19
+ * const events = sortEntries(await getCollection("events"));
20
+ */
21
+ function sortEntries(entries) {
22
+ const collection = entries[0]?.collection ?? "";
23
+ const sort = sorts[collection] ?? "id";
24
+ const rank = ranks.get(collection);
25
+ if (sort !== "file" || !rank) return sortByIds(entries, sort);
26
+ const position = (entry) => rank.get(entry.id) ?? rank.size;
27
+ const compare = compareIds(sort);
28
+ return entries.toSorted((a, b) => position(a) - position(b) || compare(a.id, b.id));
29
+ }
30
+ function languages() {
31
+ if (!contentI18n) throw new Error("astronaut-cms: localized content needs content languages, set `i18n` in astro.config.");
32
+ return contentI18n;
33
+ }
34
+ /**
35
+ * The entries of a localized collection in `locale`, each slug once: its own
36
+ * translation, or else the default language's, flagged as a fallback.
37
+ *
38
+ * @example
39
+ * const posts = localizeEntries(await getCollection("posts"), Astro.currentLocale);
40
+ */
41
+ function localizeEntries(entries, locale) {
42
+ const { locales, defaultLocale } = languages();
43
+ const bySlug = /* @__PURE__ */ new Map();
44
+ for (const entry of entries) {
45
+ const { locale: own, slug } = splitLocale(entry.id, locales);
46
+ if (own === locale) bySlug.set(slug, {
47
+ entry,
48
+ slug,
49
+ isFallback: false
50
+ });
51
+ else if (own === defaultLocale && !bySlug.has(slug)) bySlug.set(slug, {
52
+ entry,
53
+ slug,
54
+ isFallback: true
55
+ });
56
+ }
57
+ return [...bySlug.values()];
58
+ }
59
+ /**
60
+ * One entry of a localized collection in `locale`, or the default language's
61
+ * when it has no translation, such as the texts of a localized singleton.
62
+ *
63
+ * @example
64
+ * const texts = await getLocalizedEntry("texts", "site", Astro.currentLocale);
65
+ */
66
+ async function getLocalizedEntry(collection, slug, locale) {
67
+ const { defaultLocale } = languages();
68
+ const own = await getEntry(collection, joinLocale(locale, slug));
69
+ const entry = own ?? await getEntry(collection, joinLocale(defaultLocale, slug));
70
+ return entry && {
71
+ entry,
72
+ slug,
73
+ isFallback: !own
74
+ };
75
+ }
76
+ /**
77
+ * The value of a `localized()` field in `locale`, or the default language's,
78
+ * which the build guarantees.
79
+ *
80
+ * @example
81
+ * const title = pickLocale(settings.data.imagefilm.title, Astro.currentLocale);
82
+ */
83
+ function pickLocale(value, locale) {
84
+ const { defaultLocale } = languages();
85
+ const picked = value[locale] ?? value[defaultLocale];
86
+ if (picked === void 0) throw new Error(`astronaut-cms: a localized value has neither "${locale}" nor "${defaultLocale}".`);
87
+ return picked;
88
+ }
89
+ export { getLocalizedEntry, localizeEntries, pickLocale, sortEntries };
@@ -0,0 +1,11 @@
1
+ import { APIRoute } from "astro";
2
+ /**
3
+ * The whole API for one request. `clientAddress` is the caller's address as the
4
+ * adapter determined it, which trusts a forwarded header only where the
5
+ * platform sets one.
6
+ */
7
+ export declare function handle(request: Request, clientAddress?: string): Promise<Response>;
8
+ export declare const prerender = false;
9
+ export declare const GET: APIRoute;
10
+ export declare const POST: APIRoute;
11
+ export declare const PUT: APIRoute;