@cancia/astro 0.0.1 → 0.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/dist/chunk-337LJIKX.js +76 -0
- package/dist/chunk-AE4SIY24.js +63 -0
- package/dist/chunk-BOIQNZAO.js +64 -0
- package/dist/{chunk-YPVZDWTW.js → chunk-IIGDU5SV.js} +1 -1
- package/dist/chunk-MCHQV6Y7.js +155 -0
- package/dist/{chunk-YQDZQSES.js → chunk-ST44VULL.js} +4 -78
- package/dist/endpoints/schemas.js +3 -2
- package/dist/index.d.ts +4 -18
- package/dist/index.js +12 -64
- package/dist/loader/index.js +2 -1
- package/dist/portable-text-BikSqS9T.d.ts +117 -0
- package/dist/richtext/CanciaRichText.astro +44 -0
- package/dist/richtext/Link.astro +25 -0
- package/dist/richtext/index.d.ts +23 -0
- package/dist/richtext/index.js +142 -0
- package/dist/schema/index.d.ts +173 -6
- package/dist/schema/index.js +19 -1
- package/dist/storage/index.d.ts +20 -0
- package/dist/storage/index.js +16 -0
- package/package.json +16 -4
- package/dist/chunk-QAM5VKAF.js +0 -73
package/dist/chunk-QAM5VKAF.js
DELETED
|
@@ -1,73 +0,0 @@
|
|
|
1
|
-
// src/schema/index.ts
|
|
2
|
-
import { z } from "zod";
|
|
3
|
-
function defineList(opts) {
|
|
4
|
-
return {
|
|
5
|
-
label: opts.label,
|
|
6
|
-
labelSingular: opts.labelSingular ?? opts.label.replace(/s$/, ""),
|
|
7
|
-
titleField: opts.titleField,
|
|
8
|
-
bodyField: opts.bodyField,
|
|
9
|
-
slugField: opts.slugField,
|
|
10
|
-
fields: opts.fields,
|
|
11
|
-
validator: z.object(opts.fields)
|
|
12
|
-
};
|
|
13
|
-
}
|
|
14
|
-
function humanise(name) {
|
|
15
|
-
return name.replace(/([A-Z])/g, " $1").replace(/[_-]/g, " ").replace(/^\w/, (c) => c.toUpperCase()).trim();
|
|
16
|
-
}
|
|
17
|
-
function inferWidget(prop, label) {
|
|
18
|
-
if (prop.widget) return prop.widget;
|
|
19
|
-
if (prop.enum) return "select";
|
|
20
|
-
if (prop.type === "boolean") return "checkbox";
|
|
21
|
-
if (prop.type === "number" || prop.type === "integer") return "number";
|
|
22
|
-
if (prop.type === "string") {
|
|
23
|
-
if (prop.format === "uri" || prop.format === "url") return "url";
|
|
24
|
-
if (prop.format === "email") return "email";
|
|
25
|
-
if (prop.format === "date-time" || prop.format === "date") return "datetime";
|
|
26
|
-
if (label.toLowerCase() === "body" || label.toLowerCase() === "content") return "textarea";
|
|
27
|
-
if (prop.maxLength && prop.maxLength > 200) return "textarea";
|
|
28
|
-
return "text";
|
|
29
|
-
}
|
|
30
|
-
return "text";
|
|
31
|
-
}
|
|
32
|
-
function describeProperty(name, prop, required) {
|
|
33
|
-
const label = prop.label ?? humanise(name);
|
|
34
|
-
const desc = {
|
|
35
|
-
name,
|
|
36
|
-
label,
|
|
37
|
-
widget: inferWidget(prop, label),
|
|
38
|
-
required
|
|
39
|
-
};
|
|
40
|
-
if (prop.description) desc.description = prop.description;
|
|
41
|
-
if (prop.placeholder) desc.placeholder = prop.placeholder;
|
|
42
|
-
if (prop.minLength !== void 0) desc.minLength = prop.minLength;
|
|
43
|
-
if (prop.maxLength !== void 0) desc.maxLength = prop.maxLength;
|
|
44
|
-
if (prop.minimum !== void 0) desc.min = prop.minimum;
|
|
45
|
-
if (prop.maximum !== void 0) desc.max = prop.maximum;
|
|
46
|
-
if (prop.enum) desc.options = prop.enum;
|
|
47
|
-
return desc;
|
|
48
|
-
}
|
|
49
|
-
function describeList(name, schema) {
|
|
50
|
-
const json = z.toJSONSchema(schema.validator, {
|
|
51
|
-
metadata: z.globalRegistry
|
|
52
|
-
});
|
|
53
|
-
const properties = json.properties ?? {};
|
|
54
|
-
const requiredSet = new Set(json.required ?? []);
|
|
55
|
-
const fields = Object.keys(schema.fields).map(
|
|
56
|
-
(fieldName) => describeProperty(fieldName, properties[fieldName] ?? {}, requiredSet.has(fieldName))
|
|
57
|
-
);
|
|
58
|
-
return {
|
|
59
|
-
name,
|
|
60
|
-
label: schema.label,
|
|
61
|
-
labelSingular: schema.labelSingular,
|
|
62
|
-
titleField: schema.titleField,
|
|
63
|
-
bodyField: schema.bodyField,
|
|
64
|
-
slugField: schema.slugField,
|
|
65
|
-
fields
|
|
66
|
-
};
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
export {
|
|
70
|
-
z,
|
|
71
|
-
defineList,
|
|
72
|
-
describeList
|
|
73
|
-
};
|