@tinacms/schema-tools 2.10.0 → 2.10.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.
package/dist/index.js CHANGED
@@ -2342,6 +2342,16 @@ const MEDIA_CATEGORIES = {
2342
2342
  audio: ["mp3", "wav", "ogg"],
2343
2343
  document: ["pdf", "json", "csv", "txt"]
2344
2344
  };
2345
+ const MEDIA_CATEGORY_NAMES = [
2346
+ "image",
2347
+ "video",
2348
+ "audio",
2349
+ "document"
2350
+ ];
2351
+ const MEDIA_ACCEPT_VALUES = [
2352
+ ...MEDIA_CATEGORY_NAMES,
2353
+ ...MEDIA_EXTENSIONS
2354
+ ];
2345
2355
  const MEDIA_EXTENSION_ALIASES = {
2346
2356
  jpg: ["jpeg"],
2347
2357
  jpeg: ["jpg"]
@@ -2490,6 +2500,19 @@ const TinaField = z.object({
2490
2500
  required: z.boolean().optional()
2491
2501
  });
2492
2502
  const FieldWithList = TinaField.extend({ list: z.boolean().optional() });
2503
+ const validMediaAcceptList = MEDIA_ACCEPT_VALUES.map(
2504
+ (value) => `\`${value}\``
2505
+ ).join(", ");
2506
+ const MediaAcceptValue = z.enum(MEDIA_ACCEPT_VALUES, {
2507
+ errorMap: (issue, ctx) => {
2508
+ if (issue.code === "invalid_enum_value") {
2509
+ return {
2510
+ message: `Invalid \`accept\` value \`${typeof ctx.data === "string" ? ctx.data : JSON.stringify(ctx.data)}\`. Must be one of: ${validMediaAcceptList}.`
2511
+ };
2512
+ }
2513
+ return { message: ctx.defaultError };
2514
+ }
2515
+ });
2493
2516
  const TinaScalerBase = FieldWithList.extend({
2494
2517
  options: z.array(Option).optional(),
2495
2518
  uid: z.boolean().optional()
@@ -2524,7 +2547,8 @@ const ImageField = TinaScalerBase.extend({
2524
2547
  invalid_type_error: typeTypeError,
2525
2548
  required_error: typeRequiredError
2526
2549
  }),
2527
- uploadDir: z.function().args(z.any()).returns(z.string()).optional()
2550
+ uploadDir: z.function().args(z.any()).returns(z.string()).optional(),
2551
+ accept: z.union([MediaAcceptValue, z.array(MediaAcceptValue)]).optional()
2528
2552
  });
2529
2553
  const DateTimeField = TinaScalerBase.extend({
2530
2554
  type: z.literal("datetime", {
@@ -2565,7 +2589,7 @@ const TinaFieldZod = z.lazy(() => {
2565
2589
  const TemplateTemp = z.object({
2566
2590
  label: z.string().optional(),
2567
2591
  name,
2568
- fields: z.array(TinaFieldZod),
2592
+ fields: z.array(TinaFieldZod).min(1, "Property `fields` cannot be empty."),
2569
2593
  match: z.object({
2570
2594
  start: z.string(),
2571
2595
  end: z.string(),
@@ -2765,7 +2789,7 @@ const Template = z.object({
2765
2789
  required_error: "Missing `label` property. Property `label` is required."
2766
2790
  }),
2767
2791
  name,
2768
- fields: z.array(TinaFieldZod)
2792
+ fields: z.array(TinaFieldZod).min(1, "Property `fields` cannot be empty.")
2769
2793
  }).superRefine((val, ctx) => {
2770
2794
  var _a;
2771
2795
  const dups = findDuplicates((_a = val.fields) == null ? void 0 : _a.map((x) => x.name));
@@ -2957,7 +2981,9 @@ export {
2957
2981
  ERR_HAS_REFERENCES,
2958
2982
  ERR_NOT_INDEXED,
2959
2983
  ERR_PATH_TRAVERSAL,
2984
+ MEDIA_ACCEPT_VALUES,
2960
2985
  MEDIA_CATEGORIES,
2986
+ MEDIA_CATEGORY_NAMES,
2961
2987
  MEDIA_EXTENSIONS,
2962
2988
  MEDIA_MIME_TYPES,
2963
2989
  NAMER,
@@ -221,6 +221,8 @@ export declare const MEDIA_CATEGORIES: {
221
221
  };
222
222
  export type MediaCategory = keyof typeof MEDIA_CATEGORIES;
223
223
  export type MediaAccept = MediaExtension | MediaCategory;
224
+ export declare const MEDIA_CATEGORY_NAMES: readonly ["image", "video", "audio", "document"];
225
+ export declare const MEDIA_ACCEPT_VALUES: readonly ["image", "video", "audio", "document", "jpg", "jpeg", "png", "gif", "webp", "svg", "avif", "ico", "mp4", "webm", "mov", "mp3", "wav", "ogg", "pdf", "json", "csv", "txt"];
224
226
  /**
225
227
  * The MIME type each extension belongs to. Needed because react-dropzone
226
228
  * keys its `accept` by MIME type and drops bare extensions from the native
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@tinacms/schema-tools",
3
3
  "type": "module",
4
- "version": "2.10.0",
4
+ "version": "2.10.1",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
7
7
  "files": [