astronaut-cms 0.0.1 → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +84 -3
- package/dist/admin/THIRD_PARTY_LICENSES.md +7646 -0
- package/dist/admin/assets/assistant-DTlSNidc.js +235 -0
- package/dist/admin/assets/badge-BfN73-be.js +1 -0
- package/dist/admin/assets/changes-h1lmD7AA.js +1 -0
- package/dist/admin/assets/client-B4PWCmC4.js +5 -0
- package/dist/admin/assets/clsx-DB0hHKMi.js +1 -0
- package/dist/admin/assets/collapsible-item-zlnNAUdM.js +1 -0
- package/dist/admin/assets/collapsible-mcJ6G3X4.js +1 -0
- package/dist/admin/assets/collections._collection-D-rC9E9v.js +1 -0
- package/dist/admin/assets/collections._collection._entry-UD8hLmC1.js +52 -0
- package/dist/admin/assets/collections._collection.index-Cgc93hCD.js +1 -0
- package/dist/admin/assets/component-lookup-8lVQh8pl.js +4 -0
- package/dist/admin/assets/config-Pm_BHLNT.js +1 -0
- package/dist/admin/assets/copy-DxuErr3x.js +1 -0
- package/dist/admin/assets/css-BGIxQoYs.js +1 -0
- package/dist/admin/assets/css-DgaLhXQH.js +1 -0
- package/dist/admin/assets/diff-woXpYk--.js +1 -0
- package/dist/admin/assets/dist-DVv3ALC7.js +1 -0
- package/dist/admin/assets/dist-Dpyc1riS.js +1 -0
- package/dist/admin/assets/docx-BctAmX91.js +56 -0
- package/dist/admin/assets/editor-BauN0yXd.js +2 -0
- package/dist/admin/assets/empty-DAOUBpWb.js +1 -0
- package/dist/admin/assets/entry-link-DhcL6M5c.js +158 -0
- package/dist/admin/assets/error-banner-CNWZU5u_.js +161 -0
- package/dist/admin/assets/errors-DkJ5E_ak.js +1 -0
- package/dist/admin/assets/field-CbbZZGxO.js +41 -0
- package/dist/admin/assets/field-schema-CacrjSYw.js +1 -0
- package/dist/admin/assets/file-text-Ciz5Mr4S.js +1 -0
- package/dist/admin/assets/github-dark-C-LZuMrd.js +1 -0
- package/dist/admin/assets/github-light-EUqPIrTm.js +1 -0
- package/dist/admin/assets/highlighted-body-JLMTFACH-D1bycIV3.js +1 -0
- package/dist/admin/assets/html-CvFb5cGI.js +1 -0
- package/dist/admin/assets/javascript-BzbQS41l.js +1 -0
- package/dist/admin/assets/javascript-CpIGwZ_Y.js +1 -0
- package/dist/admin/assets/json-qhed-kSA.js +1 -0
- package/dist/admin/assets/jsx-Bz0zcwM4.js +1 -0
- package/dist/admin/assets/lib-CC_S4yjQ.js +21 -0
- package/dist/admin/assets/library-Da82FNwp.js +1 -0
- package/dist/admin/assets/list-skeleton-BXLP4Fak.js +1 -0
- package/dist/admin/assets/markdown-BYOwaDjH.js +1 -0
- package/dist/admin/assets/matchContext-BjW1F-Cq.js +2 -0
- package/dist/admin/assets/media-browser-DeKpWCUD.js +1 -0
- package/dist/admin/assets/media._library-DGnXJc0I.js +1 -0
- package/dist/admin/assets/mermaid-WFAXDIZX-CqFnahFh.js +1 -0
- package/dist/admin/assets/page-header-C2Uwa_yv.js +1 -0
- package/dist/admin/assets/pdf-BSEX-sd8.js +106 -0
- package/dist/admin/assets/python-gzcpVVnB.js +1 -0
- package/dist/admin/assets/react-CXnqG51l.js +1 -0
- package/dist/admin/assets/rolldown-runtime-BWaJ3C7D.js +1 -0
- package/dist/admin/assets/routes-Bx9rPcHA.js +1 -0
- package/dist/admin/assets/routes-D7tEdYGV.js +1 -0
- package/dist/admin/assets/save-actions-DrVgh3KH.js +32 -0
- package/dist/admin/assets/select-CMV39q80.js +1 -0
- package/dist/admin/assets/separator-C9bNKNSU.js +3 -0
- package/dist/admin/assets/shell-DBEiq06l.js +1 -0
- package/dist/admin/assets/shellscript-CLZ0U2zV.js +1 -0
- package/dist/admin/assets/skeleton-DTwTUSqm.js +1 -0
- package/dist/admin/assets/sql-CEbI0hMM.js +1 -0
- package/dist/admin/assets/syntax-DDPd1mQn.js +8 -0
- package/dist/admin/assets/toggle-B6ASf-kL.js +1 -0
- package/dist/admin/assets/toml-BPTmHmyx.js +1 -0
- package/dist/admin/assets/tsx-udAQXfEw.js +1 -0
- package/dist/admin/assets/typescript-bsJCZSQ-.js +1 -0
- package/dist/admin/assets/ui.module.css-BdAmwQeM.js +56 -0
- package/dist/admin/assets/use-entries-CrNqaMfa.js +1 -0
- package/dist/admin/assets/useSelector-Cs39W18m.js +1 -0
- package/dist/admin/assets/yaml-rwi0_p6S.js +1 -0
- package/dist/admin/assets/zwitch-Wwuax-dJ.js +1 -0
- package/dist/admin/bootstrap.d.ts +1 -0
- package/dist/admin/bootstrap.js +1 -0
- package/dist/admin/editor.d.ts +1065 -0
- package/dist/admin/editor.js +1 -0
- package/dist/server/THIRD_PARTY_LICENSES.md +49 -0
- package/dist/server/assets.d.ts +30 -0
- package/dist/server/assets.js +30 -0
- package/dist/server/chunks/anchors-DuZ1fokt.js +86 -0
- package/dist/server/chunks/auth-DJP9ryVd.js +44 -0
- package/dist/server/chunks/cms-markers-CUqrOnfA.js +78 -0
- package/dist/server/chunks/component-lookup-DAFg_Qg8.js +128 -0
- package/dist/server/chunks/config-BsOYly9a.d.ts +1210 -0
- package/dist/server/chunks/digest-tkKu_Wj5.js +753 -0
- package/dist/server/chunks/entry-checks-3SxhoHwH.js +608 -0
- package/dist/server/chunks/field-schema-CfdN75jT.js +48 -0
- package/dist/server/chunks/http-BnsNh57m.d.ts +35 -0
- package/dist/server/chunks/i18n-BPmx7ESy.d.ts +15 -0
- package/dist/server/chunks/index-CYbkNvu5.d.ts +22 -0
- package/dist/server/chunks/media-BhqUVVYY.js +223 -0
- package/dist/server/chunks/paths-CEW9fvg8.js +17 -0
- package/dist/server/chunks/paths-Dztx2eUw.js +13 -0
- package/dist/server/chunks/types-DkkewFTT.js +418 -0
- package/dist/server/chunks/types-Dkx4Xovf.d.ts +359 -0
- package/dist/server/chunks/types-Jew_-Qpp.d.ts +273 -0
- package/dist/server/chunks/user-config-CqNK-Ebs.js +292 -0
- package/dist/server/chunks/xml-D8qPILJU.js +81 -0
- package/dist/server/config.d.ts +3 -0
- package/dist/server/config.js +22 -0
- package/dist/server/content.d.ts +58 -0
- package/dist/server/content.js +83 -0
- package/dist/server/endpoint.d.ts +16 -0
- package/dist/server/endpoint.js +2726 -0
- package/dist/server/integration.d.ts +7 -0
- package/dist/server/integration.js +1187 -0
- package/dist/server/internal.d.ts +100 -0
- package/dist/server/internal.js +30 -0
- package/dist/server/server-local.d.ts +453 -0
- package/dist/server/server-local.js +336 -0
- package/dist/styles/THIRD_PARTY_LICENSES.md +193 -0
- package/dist/styles/assets/geist-cyrillic-ext-wght-normal-DjL33-gN.woff2 +0 -0
- package/dist/styles/assets/geist-cyrillic-wght-normal-BEAKL7Jp.woff2 +0 -0
- package/dist/styles/assets/geist-latin-ext-wght-normal-DC-KSUi6.woff2 +0 -0
- package/dist/styles/assets/geist-latin-wght-normal-BgDaEnEv.woff2 +0 -0
- package/dist/styles/assets/geist-vietnamese-wght-normal-6IgcOCM7.woff2 +0 -0
- package/dist/styles/styles.css +3 -0
- package/package.json +151 -5
- package/src/astro/Image.astro +28 -0
- package/src/astro/Video.astro +44 -0
- package/src/astro/admin.astro +137 -0
- package/src/astro/licenses.ts +5 -0
|
@@ -0,0 +1,292 @@
|
|
|
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
|
+
/**
|
|
280
|
+
* Lowers `cms.config.ts` into its {@link UserModule}.
|
|
281
|
+
* The module is passed whole, so the bundler does not warn about the exports a site leaves out.
|
|
282
|
+
* The collections contribute their icons only, the one option the manifest
|
|
283
|
+
* cannot carry, being live components.
|
|
284
|
+
*/
|
|
285
|
+
function processUserModule({ components, collections = {}, links = [] }, i18n) {
|
|
286
|
+
return {
|
|
287
|
+
components: processUserConfig(components, i18n),
|
|
288
|
+
collectionIcons: Object.fromEntries(Object.entries(collections).flatMap(([name, { icon }]) => icon ? [[name, icon]] : [])),
|
|
289
|
+
links
|
|
290
|
+
};
|
|
291
|
+
}
|
|
292
|
+
export { zodToFieldSchema as i, processUserModule as n, propsResolver as r, processUserConfig 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 { _ as localizedMarker, a as ComponentDefinition, b as JsxEditor, c as SchemaHelpers, d as defineLink, g as linkMarker, h as libraryImage, i as CollectionRegistry, l as defineCollection, m as fileMarker, n as CollectionName, o as ComponentIcon, p as anchorMarker, r as CollectionOptions, s as LinkOptions, t as ChildrenConfig, u as defineComponent, x as JsxEditorProps } from "./chunks/config-BsOYly9a.js";
|
|
2
|
+
import { i as CollectionSort } from "./chunks/types-Jew_-Qpp.js";
|
|
3
|
+
export { ChildrenConfig, CollectionName, CollectionOptions, CollectionRegistry, type CollectionSort, ComponentDefinition, ComponentIcon, type JsxEditor, type JsxEditorProps, LinkOptions, SchemaHelpers, anchorMarker as anchor, defineCollection, defineComponent, defineLink, fileMarker as file, libraryImage, linkMarker as link, localizedMarker as localized };
|
|
@@ -0,0 +1,22 @@
|
|
|
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
|
+
/** One entry of the `links` export of `cms.config`. */
|
|
12
|
+
function defineLink(options) {
|
|
13
|
+
return options;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* One entry of the `components` export of `cms.config`. The integration renders
|
|
17
|
+
* it in MDX through a generated wrapper, which `astronaut-cms:components` exports.
|
|
18
|
+
*/
|
|
19
|
+
function defineComponent(def) {
|
|
20
|
+
return def;
|
|
21
|
+
}
|
|
22
|
+
export { anchorMarker as anchor, defineCollection, defineComponent, defineLink, fileMarker as file, libraryImage, linkMarker as link, localizedMarker as localized };
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Reading content in the site the way the admin edits it: entry order, and the
|
|
3
|
+
* language of localized collections and fields.
|
|
4
|
+
*
|
|
5
|
+
* Entry order is the same the admin shows. Astro's content store
|
|
6
|
+
* returns a collection sorted by id and keeps no trace of the order a `file()`
|
|
7
|
+
* collection's file holds, so a collection with a `sort` option is ordered here,
|
|
8
|
+
* from what the integration read off the content.
|
|
9
|
+
*/
|
|
10
|
+
import { CollectionEntry, CollectionKey } from "astro:content";
|
|
11
|
+
/** What ordering reads off an entry of astro's `getCollection`. */
|
|
12
|
+
interface SortableEntry {
|
|
13
|
+
id: string;
|
|
14
|
+
collection: string;
|
|
15
|
+
data: Readonly<Record<string, unknown>>;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* The entries of one collection, in the order its `sort` option names.
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* const events = sortEntries(await getCollection("events"));
|
|
22
|
+
*/
|
|
23
|
+
export declare function sortEntries<E extends SortableEntry>(entries: readonly E[]): E[];
|
|
24
|
+
/** An entry of a localized collection as one language shows it. */
|
|
25
|
+
export interface LocalizedEntry<E> {
|
|
26
|
+
entry: E;
|
|
27
|
+
/** The id without its language, shared by every translation. */
|
|
28
|
+
slug: string;
|
|
29
|
+
/** Whether the entry is the default language's, standing in for a missing translation. */
|
|
30
|
+
isFallback: boolean;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* The entries of a localized collection in `locale`, each slug once: its own
|
|
34
|
+
* translation, or else the default language's, flagged as a fallback.
|
|
35
|
+
*
|
|
36
|
+
* @example
|
|
37
|
+
* const posts = localizeEntries(await getCollection("posts"), Astro.currentLocale);
|
|
38
|
+
*/
|
|
39
|
+
export declare function localizeEntries<E extends {
|
|
40
|
+
id: string;
|
|
41
|
+
}>(entries: readonly E[], locale: string): LocalizedEntry<E>[];
|
|
42
|
+
/**
|
|
43
|
+
* One entry of a localized collection in `locale`, or the default language's
|
|
44
|
+
* when it has no translation, such as the texts of a localized singleton.
|
|
45
|
+
*
|
|
46
|
+
* @example
|
|
47
|
+
* const texts = await getLocalizedEntry("texts", "site", Astro.currentLocale);
|
|
48
|
+
*/
|
|
49
|
+
export declare function getLocalizedEntry<C extends CollectionKey>(collection: C, slug: string, locale: string): Promise<LocalizedEntry<CollectionEntry<C>> | undefined>;
|
|
50
|
+
/**
|
|
51
|
+
* The value of a `localized()` field in `locale`, or the default language's,
|
|
52
|
+
* which the build guarantees.
|
|
53
|
+
*
|
|
54
|
+
* @example
|
|
55
|
+
* const title = pickLocale(settings.data.imagefilm.title, Astro.currentLocale);
|
|
56
|
+
*/
|
|
57
|
+
export declare function pickLocale<T>(value: Partial<Record<string, T>>, locale: string): T;
|
|
58
|
+
export {};
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import { g as splitLocale, h as joinLocale, p as orderEntries, r as DEFAULT_SORT } from "./chunks/types-DkkewFTT.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
|
+
/**
|
|
15
|
+
* The entries of one collection, in the order its `sort` option names.
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* const events = sortEntries(await getCollection("events"));
|
|
19
|
+
*/
|
|
20
|
+
function sortEntries(entries) {
|
|
21
|
+
const collection = entries[0]?.collection ?? "";
|
|
22
|
+
return orderEntries(entries, sorts[collection] ?? DEFAULT_SORT, (entry, field) => entry.data[field], fileOrder[collection]);
|
|
23
|
+
}
|
|
24
|
+
function languages() {
|
|
25
|
+
if (!contentI18n) throw new Error("astronaut-cms: localized content needs content languages, set `i18n` in astro.config.");
|
|
26
|
+
return contentI18n;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* The entries of a localized collection in `locale`, each slug once: its own
|
|
30
|
+
* translation, or else the default language's, flagged as a fallback.
|
|
31
|
+
*
|
|
32
|
+
* @example
|
|
33
|
+
* const posts = localizeEntries(await getCollection("posts"), Astro.currentLocale);
|
|
34
|
+
*/
|
|
35
|
+
function localizeEntries(entries, locale) {
|
|
36
|
+
const { locales, defaultLocale } = languages();
|
|
37
|
+
const bySlug = /* @__PURE__ */ new Map();
|
|
38
|
+
for (const entry of entries) {
|
|
39
|
+
const { locale: own, slug } = splitLocale(entry.id, locales);
|
|
40
|
+
if (own === locale) bySlug.set(slug, {
|
|
41
|
+
entry,
|
|
42
|
+
slug,
|
|
43
|
+
isFallback: false
|
|
44
|
+
});
|
|
45
|
+
else if (own === defaultLocale && !bySlug.has(slug)) bySlug.set(slug, {
|
|
46
|
+
entry,
|
|
47
|
+
slug,
|
|
48
|
+
isFallback: true
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
return [...bySlug.values()];
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* One entry of a localized collection in `locale`, or the default language's
|
|
55
|
+
* when it has no translation, such as the texts of a localized singleton.
|
|
56
|
+
*
|
|
57
|
+
* @example
|
|
58
|
+
* const texts = await getLocalizedEntry("texts", "site", Astro.currentLocale);
|
|
59
|
+
*/
|
|
60
|
+
async function getLocalizedEntry(collection, slug, locale) {
|
|
61
|
+
const { defaultLocale } = languages();
|
|
62
|
+
const own = await getEntry(collection, joinLocale(locale, slug));
|
|
63
|
+
const entry = own ?? await getEntry(collection, joinLocale(defaultLocale, slug));
|
|
64
|
+
return entry && {
|
|
65
|
+
entry,
|
|
66
|
+
slug,
|
|
67
|
+
isFallback: !own
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* The value of a `localized()` field in `locale`, or the default language's,
|
|
72
|
+
* which the build guarantees.
|
|
73
|
+
*
|
|
74
|
+
* @example
|
|
75
|
+
* const title = pickLocale(settings.data.imagefilm.title, Astro.currentLocale);
|
|
76
|
+
*/
|
|
77
|
+
function pickLocale(value, locale) {
|
|
78
|
+
const { defaultLocale } = languages();
|
|
79
|
+
const picked = value[locale] ?? value[defaultLocale];
|
|
80
|
+
if (picked === void 0) throw new Error(`astronaut-cms: a localized value has neither "${locale}" nor "${defaultLocale}".`);
|
|
81
|
+
return picked;
|
|
82
|
+
}
|
|
83
|
+
export { getLocalizedEntry, localizeEntries, pickLocale, sortEntries };
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Astro-route shell over the server in `handler.ts`: one
|
|
3
|
+
* injected route covering every CMS API path, so the integration injects one
|
|
4
|
+
* thing and the handler does the routing.
|
|
5
|
+
*/
|
|
6
|
+
import { APIRoute } from "astro";
|
|
7
|
+
/**
|
|
8
|
+
* The whole API for one request. `clientAddress` is the caller's address as the
|
|
9
|
+
* adapter determined it, which trusts a forwarded header only where the
|
|
10
|
+
* platform sets one.
|
|
11
|
+
*/
|
|
12
|
+
export declare function handle(request: Request, clientAddress?: string): Promise<Response>;
|
|
13
|
+
export declare const prerender = false;
|
|
14
|
+
export declare const GET: APIRoute;
|
|
15
|
+
export declare const POST: APIRoute;
|
|
16
|
+
export declare const PUT: APIRoute;
|