@eutobias/serenojs 0.0.0-stage → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (158) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +682 -2
  3. package/admin-dist/assets/index-B3EgqtT6.js +9 -0
  4. package/admin-dist/assets/index-D2m0Eb4k.css +2 -0
  5. package/admin-dist/index.html +17 -0
  6. package/dist/auth/auth.server.d.ts +31 -0
  7. package/dist/auth/auth.server.js +141 -0
  8. package/dist/auth/config.d.ts +32 -0
  9. package/dist/auth/config.js +25 -0
  10. package/dist/auth/cookies.server.d.ts +7 -0
  11. package/dist/auth/cookies.server.js +65 -0
  12. package/dist/auth/http.server.d.ts +8 -0
  13. package/dist/auth/http.server.js +30 -0
  14. package/dist/auth/password.server.d.ts +2 -0
  15. package/dist/auth/password.server.js +21 -0
  16. package/dist/auth/session.server.d.ts +2 -0
  17. package/dist/auth/session.server.js +14 -0
  18. package/dist/auth/users.server.d.ts +16 -0
  19. package/dist/auth/users.server.js +123 -0
  20. package/dist/config.d.ts +91 -0
  21. package/dist/config.js +39 -0
  22. package/dist/core/backup.server.d.ts +52 -0
  23. package/dist/core/backup.server.js +349 -0
  24. package/dist/core/db.server.d.ts +24 -0
  25. package/dist/core/db.server.js +526 -0
  26. package/dist/core/media.d.ts +22 -0
  27. package/dist/core/media.js +76 -0
  28. package/dist/core/media.server.d.ts +18 -0
  29. package/dist/core/media.server.js +102 -0
  30. package/dist/core/schema.d.ts +26 -0
  31. package/dist/core/schema.js +99 -0
  32. package/dist/core/types.d.ts +143 -0
  33. package/dist/core/types.js +1 -0
  34. package/dist/core/validation.d.ts +16 -0
  35. package/dist/core/validation.js +192 -0
  36. package/dist/locale.d.ts +2 -0
  37. package/dist/locale.js +14 -0
  38. package/dist/runtime.d.ts +8 -0
  39. package/dist/runtime.js +37 -0
  40. package/dist/server/app.d.ts +20 -0
  41. package/dist/server/app.js +661 -0
  42. package/dist/ui/admin/admin-shell.d.ts +16 -0
  43. package/dist/ui/admin/admin-shell.js +38 -0
  44. package/dist/ui/admin/backup-manager.d.ts +5 -0
  45. package/dist/ui/admin/backup-manager.js +165 -0
  46. package/dist/ui/admin/collection-icon.d.ts +22 -0
  47. package/dist/ui/admin/collection-icon.js +34 -0
  48. package/dist/ui/admin/collection-manager.d.ts +7 -0
  49. package/dist/ui/admin/collection-manager.js +212 -0
  50. package/dist/ui/admin/display.d.ts +7 -0
  51. package/dist/ui/admin/display.js +65 -0
  52. package/dist/ui/admin/field-control.d.ts +14 -0
  53. package/dist/ui/admin/field-control.js +58 -0
  54. package/dist/ui/admin/i18n.d.ts +27 -0
  55. package/dist/ui/admin/i18n.js +324 -0
  56. package/dist/ui/admin/item-form.d.ts +20 -0
  57. package/dist/ui/admin/item-form.js +60 -0
  58. package/dist/ui/admin/list-control.d.ts +13 -0
  59. package/dist/ui/admin/list-control.js +31 -0
  60. package/dist/ui/admin/locales.d.ts +4 -0
  61. package/dist/ui/admin/locales.js +8 -0
  62. package/dist/ui/admin/login-form.d.ts +3 -0
  63. package/dist/ui/admin/login-form.js +52 -0
  64. package/dist/ui/admin/media-control.d.ts +14 -0
  65. package/dist/ui/admin/media-control.js +74 -0
  66. package/dist/ui/admin/media-list-control.d.ts +14 -0
  67. package/dist/ui/admin/media-list-control.js +91 -0
  68. package/dist/ui/admin/pagination.d.ts +11 -0
  69. package/dist/ui/admin/pagination.js +14 -0
  70. package/dist/ui/admin/relation-control.d.ts +14 -0
  71. package/dist/ui/admin/relation-control.js +33 -0
  72. package/dist/ui/admin/router.d.ts +17 -0
  73. package/dist/ui/admin/router.js +58 -0
  74. package/dist/ui/admin/runtime.d.ts +28 -0
  75. package/dist/ui/admin/runtime.js +29 -0
  76. package/dist/ui/admin/sidebar.d.ts +13 -0
  77. package/dist/ui/admin/sidebar.js +29 -0
  78. package/dist/ui/admin/standalone-manager.d.ts +11 -0
  79. package/dist/ui/admin/standalone-manager.js +51 -0
  80. package/dist/ui/admin/table.d.ts +21 -0
  81. package/dist/ui/admin/table.js +23 -0
  82. package/dist/ui/admin/toast.d.ts +16 -0
  83. package/dist/ui/admin/toast.js +59 -0
  84. package/dist/ui/admin/users-manager.d.ts +6 -0
  85. package/dist/ui/admin/users-manager.js +157 -0
  86. package/dist/ui/badge.d.ts +9 -0
  87. package/dist/ui/badge.js +14 -0
  88. package/dist/ui/box.d.ts +17 -0
  89. package/dist/ui/box.js +14 -0
  90. package/dist/ui/button.d.ts +25 -0
  91. package/dist/ui/button.js +28 -0
  92. package/dist/ui/card.d.ts +45 -0
  93. package/dist/ui/card.js +49 -0
  94. package/dist/ui/container.d.ts +13 -0
  95. package/dist/ui/container.js +13 -0
  96. package/dist/ui/drawer.d.ts +15 -0
  97. package/dist/ui/drawer.js +31 -0
  98. package/dist/ui/field-wrapper.d.ts +15 -0
  99. package/dist/ui/field-wrapper.js +11 -0
  100. package/dist/ui/index.d.ts +8 -0
  101. package/dist/ui/index.js +8 -0
  102. package/dist/ui/text.d.ts +19 -0
  103. package/dist/ui/text.js +40 -0
  104. package/package.json +81 -3
  105. package/src/admin/app.tsx +371 -0
  106. package/src/admin/index.html +16 -0
  107. package/src/admin/main.tsx +42 -0
  108. package/src/admin/styles.css +9 -0
  109. package/src/auth/auth.server.ts +203 -0
  110. package/src/auth/config.ts +46 -0
  111. package/src/auth/cookies.server.ts +84 -0
  112. package/src/auth/http.server.ts +32 -0
  113. package/src/auth/password.server.ts +25 -0
  114. package/src/auth/session.server.ts +16 -0
  115. package/src/auth/users.server.ts +159 -0
  116. package/src/config.ts +120 -0
  117. package/src/core/backup.server.ts +446 -0
  118. package/src/core/db.server.ts +685 -0
  119. package/src/core/media.server.ts +136 -0
  120. package/src/core/media.ts +91 -0
  121. package/src/core/schema.ts +126 -0
  122. package/src/core/types.ts +194 -0
  123. package/src/core/validation.ts +215 -0
  124. package/src/global.d.ts +1 -0
  125. package/src/locale.ts +16 -0
  126. package/src/runtime.ts +54 -0
  127. package/src/server/app.ts +737 -0
  128. package/src/ui/admin/admin-shell.tsx +106 -0
  129. package/src/ui/admin/backup-manager.tsx +327 -0
  130. package/src/ui/admin/collection-icon.tsx +69 -0
  131. package/src/ui/admin/collection-manager.tsx +408 -0
  132. package/src/ui/admin/display.tsx +138 -0
  133. package/src/ui/admin/field-control.tsx +214 -0
  134. package/src/ui/admin/i18n.tsx +401 -0
  135. package/src/ui/admin/item-form.tsx +200 -0
  136. package/src/ui/admin/list-control.tsx +121 -0
  137. package/src/ui/admin/locales.ts +12 -0
  138. package/src/ui/admin/login-form.tsx +98 -0
  139. package/src/ui/admin/media-control.tsx +161 -0
  140. package/src/ui/admin/media-list-control.tsx +242 -0
  141. package/src/ui/admin/pagination.tsx +58 -0
  142. package/src/ui/admin/relation-control.tsx +142 -0
  143. package/src/ui/admin/router.tsx +105 -0
  144. package/src/ui/admin/runtime.tsx +58 -0
  145. package/src/ui/admin/sidebar.tsx +178 -0
  146. package/src/ui/admin/standalone-manager.tsx +103 -0
  147. package/src/ui/admin/table.tsx +129 -0
  148. package/src/ui/admin/toast.tsx +126 -0
  149. package/src/ui/admin/users-manager.tsx +344 -0
  150. package/src/ui/badge.tsx +27 -0
  151. package/src/ui/box.tsx +33 -0
  152. package/src/ui/button.tsx +77 -0
  153. package/src/ui/card.tsx +92 -0
  154. package/src/ui/container.tsx +28 -0
  155. package/src/ui/drawer.tsx +104 -0
  156. package/src/ui/field-wrapper.tsx +54 -0
  157. package/src/ui/index.ts +8 -0
  158. package/src/ui/text.tsx +93 -0
@@ -0,0 +1,136 @@
1
+ /**
2
+ * Media uploads stored on disk under `public/files`.
3
+ *
4
+ * Values persisted in the DB are served URLs (`/files/<name>`). Uploads are
5
+ * validated against the field's `accept` / `maxSize` config in the collection
6
+ * descriptor, and always blocked for executable/HTML-ish extensions.
7
+ *
8
+ * In production Waku serves `dist/public` statically, so runtime uploads are
9
+ * streamed by the `GET /files/[...path]` route reading this directory.
10
+ */
11
+ import {
12
+ existsSync,
13
+ mkdirSync,
14
+ readFileSync,
15
+ statSync,
16
+ unlinkSync,
17
+ writeFileSync,
18
+ } from "node:fs";
19
+ import { basename, join, resolve } from "node:path";
20
+ import { randomBytes } from "node:crypto";
21
+
22
+ import {
23
+ BLOCKED_EXTENSIONS,
24
+ DEFAULT_MAX_SIZE,
25
+ UPLOAD_URL_PREFIX,
26
+ acceptList,
27
+ extensionOf,
28
+ isAllowedType,
29
+ } from "./media.js";
30
+ import type { FieldDef } from "./types.js";
31
+
32
+ export const UPLOADS_DIR = resolve(process.cwd(), "public/files");
33
+
34
+ const CONTENT_TYPES: Record<string, string> = {
35
+ png: "image/png",
36
+ jpg: "image/jpeg",
37
+ jpeg: "image/jpeg",
38
+ gif: "image/gif",
39
+ webp: "image/webp",
40
+ avif: "image/avif",
41
+ svg: "image/svg+xml",
42
+ ico: "image/x-icon",
43
+ pdf: "application/pdf",
44
+ txt: "text/plain; charset=utf-8",
45
+ csv: "text/csv; charset=utf-8",
46
+ json: "application/json; charset=utf-8",
47
+ zip: "application/zip",
48
+ mp4: "video/mp4",
49
+ webm: "video/webm",
50
+ mp3: "audio/mpeg",
51
+ wav: "audio/wav",
52
+ doc: "application/msword",
53
+ docx: "application/vnd.openxmlformats-officedocument.wordprocessingml.document",
54
+ xls: "application/vnd.ms-excel",
55
+ xlsx: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
56
+ };
57
+
58
+ export class MediaError extends Error {
59
+ status: number;
60
+ constructor(message: string, status = 422) {
61
+ super(message);
62
+ this.status = status;
63
+ }
64
+ }
65
+
66
+ export function contentTypeFor(name: string): string {
67
+ return CONTENT_TYPES[extensionOf(name)] ?? "application/octet-stream";
68
+ }
69
+
70
+ export type StoredUpload = {
71
+ url: string;
72
+ name: string;
73
+ size: number;
74
+ type: string;
75
+ };
76
+
77
+ export async function saveUpload(
78
+ file: File,
79
+ field: FieldDef,
80
+ ): Promise<StoredUpload> {
81
+ const ext = extensionOf(file.name);
82
+ if (!ext) {
83
+ throw new MediaError("Arquivo sem extensão não é permitido.");
84
+ }
85
+ if (BLOCKED_EXTENSIONS.has(ext)) {
86
+ throw new MediaError("Tipo de arquivo não permitido.");
87
+ }
88
+ if (!isAllowedType(field, file.name, file.type || contentTypeFor(file.name))) {
89
+ throw new MediaError(
90
+ `Tipo de arquivo não permitido. Aceitos: ${acceptList(field).join(", ")}.`,
91
+ );
92
+ }
93
+
94
+ const maxSize = field.maxSize ?? DEFAULT_MAX_SIZE;
95
+ if (file.size > maxSize) {
96
+ const mb = (maxSize / 1024 / 1024).toFixed(1);
97
+ throw new MediaError(`Arquivo maior que o limite de ${mb} MB.`, 413);
98
+ }
99
+
100
+ const name = `${Date.now()}-${randomBytes(6).toString("hex")}.${ext}`;
101
+ mkdirSync(UPLOADS_DIR, { recursive: true });
102
+ writeFileSync(join(UPLOADS_DIR, name), Buffer.from(await file.arrayBuffer()));
103
+
104
+ return {
105
+ url: `${UPLOAD_URL_PREFIX}${name}`,
106
+ name,
107
+ size: file.size,
108
+ type: contentTypeFor(name),
109
+ };
110
+ }
111
+
112
+ /** Resolve a stored name to a safe path inside `UPLOADS_DIR`, or null. */
113
+ export function resolveUploadPath(name: string): string | null {
114
+ const safe = basename(name);
115
+ if (!safe || safe !== name || safe.startsWith(".")) return null;
116
+ const path = join(UPLOADS_DIR, safe);
117
+ if (!path.startsWith(UPLOADS_DIR)) return null;
118
+ return existsSync(path) && statSync(path).isFile() ? path : null;
119
+ }
120
+
121
+ export function readUpload(name: string): Buffer | null {
122
+ const path = resolveUploadPath(name);
123
+ return path ? readFileSync(path) : null;
124
+ }
125
+
126
+ export function deleteByUrl(url: string): boolean {
127
+ if (!url.startsWith(UPLOAD_URL_PREFIX)) return false;
128
+ const path = resolveUploadPath(url.slice(UPLOAD_URL_PREFIX.length));
129
+ if (!path) return false;
130
+ try {
131
+ unlinkSync(path);
132
+ return true;
133
+ } catch {
134
+ return false;
135
+ }
136
+ }
@@ -0,0 +1,91 @@
1
+ /**
2
+ * Isomorphic media helpers (no filesystem): type allowlisting and URL checks.
3
+ * Server disk I/O lives in `media.server.ts`.
4
+ */
5
+ import type { FieldDef } from "./types.js";
6
+
7
+ export const UPLOAD_URL_PREFIX = "/files/";
8
+ export const DEFAULT_MAX_SIZE = 10 * 1024 * 1024;
9
+
10
+ /** Default accepted types when a media field omits `accept`. */
11
+ export const DEFAULT_ACCEPT = ["image/*", "application/pdf"];
12
+
13
+ /** Extensions that are never accepted, even if listed in `accept`. */
14
+ export const BLOCKED_EXTENSIONS = new Set([
15
+ "html",
16
+ "htm",
17
+ "xhtml",
18
+ "js",
19
+ "mjs",
20
+ "cjs",
21
+ "php",
22
+ "phtml",
23
+ "exe",
24
+ "sh",
25
+ "bat",
26
+ "cmd",
27
+ "com",
28
+ "jsx",
29
+ "ts",
30
+ "tsx",
31
+ ]);
32
+
33
+ const IMAGE_EXTENSIONS = new Set([
34
+ "png",
35
+ "jpg",
36
+ "jpeg",
37
+ "gif",
38
+ "webp",
39
+ "avif",
40
+ "svg",
41
+ "ico",
42
+ ]);
43
+
44
+ export function extensionOf(filename: string): string {
45
+ const match = /\.([a-zA-Z0-9]+)$/.exec(filename);
46
+ return match ? match[1]!.toLowerCase() : "";
47
+ }
48
+
49
+ /**
50
+ * Accepts a stored media URL: uploaded files (`/files/...`) or committed
51
+ * portfolio assets (`/images/...`). Rejects traversal and external values.
52
+ */
53
+ export function isMediaUrl(value: string): boolean {
54
+ if (!value || value.includes("..")) return false;
55
+ return value.startsWith(UPLOAD_URL_PREFIX) || value.startsWith("/images/");
56
+ }
57
+
58
+ export function isImageUrl(url: string): boolean {
59
+ return IMAGE_EXTENSIONS.has(extensionOf(url));
60
+ }
61
+
62
+ export function acceptList(field: FieldDef): string[] {
63
+ return field.accept && field.accept.length > 0 ? field.accept : DEFAULT_ACCEPT;
64
+ }
65
+
66
+ function matches(pattern: string, ext: string, mime: string): boolean {
67
+ const p = pattern.trim().toLowerCase();
68
+ if (!p) return false;
69
+ if (p.startsWith(".")) return ext === p.slice(1);
70
+ if (p.includes("/")) {
71
+ if (p.endsWith("/*")) return mime.startsWith(p.slice(0, -1));
72
+ return mime === p;
73
+ }
74
+ return ext === p;
75
+ }
76
+
77
+ export function isAllowedType(
78
+ field: FieldDef,
79
+ filename: string,
80
+ mime: string,
81
+ ): boolean {
82
+ const ext = extensionOf(filename);
83
+ if (!ext || BLOCKED_EXTENSIONS.has(ext)) return false;
84
+ const type = mime.toLowerCase();
85
+ return acceptList(field).some((pattern) => matches(pattern, ext, type));
86
+ }
87
+
88
+ /** `accept` attribute string for the file input (best-effort). */
89
+ export function acceptAttribute(field: FieldDef): string {
90
+ return acceptList(field).join(",");
91
+ }
@@ -0,0 +1,126 @@
1
+ import { getDefaultLocale } from "../locale.js";
2
+ import {
3
+ getCmsConfig,
4
+ getCollection as runtimeGetCollection,
5
+ getCollections as runtimeGetCollections,
6
+ localeLabel as runtimeLocaleLabel,
7
+ } from "../runtime.js";
8
+ import type { CollectionDef, FieldDef, FieldValue, LocalizedValue } from "./types.js";
9
+
10
+ /** Field types that are localized by default. */
11
+ const LOCALIZED_TYPES = new Set(["text", "textarea", "email", "list"]);
12
+
13
+ /** Locales stored by a collection (falls back to the global default). */
14
+ export function collectionLocales(collection: CollectionDef): string[] {
15
+ return collection.locales && collection.locales.length > 0
16
+ ? collection.locales
17
+ : [getDefaultLocale()];
18
+ }
19
+
20
+ /** Whether a field is stored once per locale (`name_pt`, `name_en`). */
21
+ export function isLocalizedField(
22
+ collection: CollectionDef,
23
+ field: FieldDef,
24
+ ): boolean {
25
+ if (field.localized !== undefined) return field.localized;
26
+ return LOCALIZED_TYPES.has(field.type);
27
+ }
28
+
29
+ /** Read the value of a (possibly localized) field for one locale. */
30
+ export function valueForLocale(
31
+ collection: CollectionDef,
32
+ field: FieldDef,
33
+ item: Record<string, unknown>,
34
+ locale: string = getDefaultLocale(),
35
+ ): FieldValue {
36
+ const raw = item[field.name];
37
+ if (!isLocalizedField(collection, field)) return raw as FieldValue;
38
+ if (!raw || typeof raw !== "object" || Array.isArray(raw)) return null;
39
+ return (raw as LocalizedValue)[locale] ?? null;
40
+ }
41
+
42
+ export function getCollections(): CollectionDef[] {
43
+ return runtimeGetCollections();
44
+ }
45
+
46
+ export function getCollection(slug: string): CollectionDef | undefined {
47
+ return runtimeGetCollection(slug);
48
+ }
49
+
50
+ export function getSchemaTitle(): string {
51
+ return getCmsConfig().title;
52
+ }
53
+
54
+ /** Admins can label locales passed from the host config. */
55
+ export function getLocaleLabel(code: string): string {
56
+ return runtimeLocaleLabel(code);
57
+ }
58
+
59
+ /** Whether a collection holds exactly one record. */
60
+ export function isStandalone(collection: CollectionDef): boolean {
61
+ return collection.standalone === true;
62
+ }
63
+
64
+ /** SQLite table name for a collection. */
65
+ export function tableName(slug: string): string {
66
+ return `c_${slug.replace(/[^a-zA-Z0-9_]/g, "_")}`;
67
+ }
68
+
69
+ /** Whether a relation field stores a list of target ids. */
70
+ export function relationIsMany(field: FieldDef): boolean {
71
+ return (
72
+ field.type === "relation" &&
73
+ field.relation?.type !== "one-to-one"
74
+ );
75
+ }
76
+
77
+ /** Whether a relation field stores a single target id. */
78
+ export function relationIsOne(field: FieldDef): boolean {
79
+ return field.type === "relation" && field.relation?.type === "one-to-one";
80
+ }
81
+
82
+ /** Default value for a single field. */
83
+ export function fieldDefault(field: FieldDef): FieldValue {
84
+ if (field.defaultValue !== undefined) return field.defaultValue;
85
+ switch (field.type) {
86
+ case "boolean":
87
+ return false;
88
+ case "number":
89
+ return field.min ?? 0;
90
+ case "relation":
91
+ return relationIsMany(field) ? [] : null;
92
+ case "media-list":
93
+ return [];
94
+ case "list":
95
+ return [];
96
+ case "select":
97
+ return field.options?.[0]?.value ?? "";
98
+ default:
99
+ return "";
100
+ }
101
+ }
102
+
103
+ /** Empty record of values for a collection (used by the create form). */
104
+ export function emptyValues(collection: CollectionDef): Record<string, FieldValue> {
105
+ const values: Record<string, FieldValue> = {};
106
+ const locales = collectionLocales(collection);
107
+ for (const field of collection.fields) {
108
+ const fallback = fieldDefault(field);
109
+ values[field.name] = isLocalizedField(collection, field)
110
+ ? Object.fromEntries(locales.map((locale) => [locale, fallback]))
111
+ : fallback;
112
+ }
113
+ return values;
114
+ }
115
+
116
+ /** Human label used when showing a single item (e.g. delete confirmation). */
117
+ export function itemLabel(collection: CollectionDef, item: Record<string, unknown>): string {
118
+ const preferred = collection.fields.find((field) => field.type === "text");
119
+ const candidates = preferred ? [preferred, ...collection.fields] : collection.fields;
120
+
121
+ for (const field of candidates) {
122
+ const value = valueForLocale(collection, field, item);
123
+ if (typeof value === "string" && value.trim()) return value.trim();
124
+ }
125
+ return `#${String(item.id ?? "")}`;
126
+ }
@@ -0,0 +1,194 @@
1
+ /** Feather icon names curated by the admin icon registry. */
2
+ export type CollectionIconName =
3
+ | "archive"
4
+ | "box"
5
+ | "fileText"
6
+ | "folder"
7
+ | "grid"
8
+ | "image"
9
+ | "layout"
10
+ | "settings"
11
+ | "star"
12
+ | "tag"
13
+ | "user"
14
+ | "users";
15
+
16
+ /**
17
+ * Shared descriptor types for the SerenoJS.
18
+ *
19
+ * The whole admin panel is generated from the collection descriptors in
20
+ * `src/schemas`. These types describe those descriptors.
21
+ */
22
+
23
+ export type FieldType =
24
+ | "text"
25
+ | "email"
26
+ | "textarea"
27
+ | "number"
28
+ | "boolean"
29
+ | "select"
30
+ | "date"
31
+ | "relation"
32
+ | "media"
33
+ | "media-list"
34
+ | "list";
35
+
36
+ export type SelectOption = {
37
+ label: string;
38
+ value: string;
39
+ };
40
+
41
+ export type RelationType =
42
+ | "one-to-one"
43
+ | "one-to-many"
44
+ | "many-to-many";
45
+
46
+ export type RelationDef = {
47
+ /** Slug of the target collection. */
48
+ to: string;
49
+ type: RelationType;
50
+ };
51
+
52
+ export type FieldDef = {
53
+ name: string;
54
+ label: string;
55
+ type: FieldType;
56
+ required?: boolean;
57
+ placeholder?: string;
58
+ help?: string;
59
+ /** Only for `select` fields. */
60
+ options?: SelectOption[];
61
+ /** Only for `number` fields. */
62
+ min?: number;
63
+ max?: number;
64
+ /** Only for `relation` fields. */
65
+ relation?: RelationDef;
66
+ /**
67
+ * Only for `media` fields. Accepted types as MIME types (`image/png`,
68
+ * `image/*`) or extensions (`png`, `.png`). Uploads are stored under
69
+ * `public/files` and the field value is the served URL (`/files/<name>`).
70
+ * Omit to allow only images and PDFs.
71
+ */
72
+ accept?: string[];
73
+ /** Only for `media` fields. Maximum upload size in bytes. */
74
+ maxSize?: number;
75
+ /**
76
+ * Whether the field is stored per locale (`name_pt`, `name_en`). When
77
+ * omitted it defaults to `true` for editorial types (`text`, `textarea`,
78
+ * `email`, `list`) and `false` for structural ones. Set explicitly to force
79
+ * a text field (e.g. `slug`, `icon`) to stay language-independent.
80
+ */
81
+ localized?: boolean;
82
+ defaultValue?: string | number | boolean;
83
+ };
84
+
85
+ export type CollectionAccess = {
86
+ /**
87
+ * Who can read (GET) this collection's API. Defaults to `"public"`.
88
+ */
89
+ read?: "public" | "private";
90
+ /**
91
+ * Who can create (POST) items. Defaults to `"private"`.
92
+ */
93
+ create?: "public" | "private";
94
+ /**
95
+ * Who can update (PATCH/PUT) items. Defaults to `"private"`.
96
+ */
97
+ update?: "public" | "private";
98
+ /**
99
+ * Who can delete (DELETE) items. Defaults to `"private"`.
100
+ */
101
+ delete?: "public" | "private";
102
+ };
103
+
104
+ export type CollectionDef = {
105
+ slug: string;
106
+ label: string;
107
+ /** Optional Feather icon name (see `src/components/admin/collection-icon.tsx`). */
108
+ icon?: CollectionIconName;
109
+ description?: string;
110
+ /**
111
+ * Per-operation access control for the generated REST API.
112
+ * `read` defaults to `"public"`; `create`, `update` and `delete` default to
113
+ * `"private"`.
114
+ */
115
+ access?: CollectionAccess;
116
+ /**
117
+ * A standalone collection holds exactly one record (no list view). The admin
118
+ * edits the single item directly and the API exposes it at
119
+ * the configured API path via `GET`/`PATCH`.
120
+ */
121
+ standalone?: boolean;
122
+ /**
123
+ * Locales this collection stores, in tab order (e.g. `["pt", "en"]`).
124
+ * Drives the per-locale columns generated in the table. Defaults to the
125
+ * global `defaultLocale` when omitted.
126
+ */
127
+ locales?: string[];
128
+ /**
129
+ * Ordered list of columns shown in the list view. Accepts field names plus
130
+ * the special `id`, `createdAt` and `updatedAt`. When omitted, all fields
131
+ * plus the managed timestamps are shown.
132
+ */
133
+ list?: string[];
134
+ fields: FieldDef[];
135
+ };
136
+
137
+ export type SchemaDef = {
138
+ title?: string;
139
+ collections: CollectionDef[];
140
+ };
141
+
142
+ /** A single entry of a `media-list` field. */
143
+ export type MediaItem = {
144
+ url: string;
145
+ alt?: string;
146
+ /** At most one item per list is the principal (cover/highlight). */
147
+ primary?: boolean;
148
+ };
149
+
150
+ /** An ordered list of translated values, keyed by locale code. */
151
+ export type LocalizedValue = {
152
+ [locale: string]: FieldValue;
153
+ };
154
+
155
+ /** Primitive value a field can hold. Relation values are numeric ids. */
156
+ export type FieldValue =
157
+ | string
158
+ | number
159
+ | boolean
160
+ | null
161
+ | number[]
162
+ | string[]
163
+ | MediaItem[]
164
+ | LocalizedValue;
165
+
166
+ /** An option shown by a relation control and used to render labels. */
167
+ export type RelationOption = {
168
+ id: number;
169
+ label: string;
170
+ };
171
+
172
+ /** Map of field name to its resolved relation options. */
173
+ export type RelationOptionsMap = Record<string, RelationOption[]>;
174
+
175
+ /** A persisted row plus the two managed timestamps. */
176
+ export type Item = {
177
+ id: number;
178
+ createdAt: string;
179
+ updatedAt: string;
180
+ [key: string]: FieldValue | number;
181
+ };
182
+
183
+ export type ListResult = {
184
+ items: Item[];
185
+ total: number;
186
+ page: number;
187
+ limit: number;
188
+ totalPages: number;
189
+ };
190
+
191
+ /** Shape returned by the mutation endpoints. */
192
+ export type MutationResult = {
193
+ item: Item;
194
+ };