@tinacms/schema-tools 1.1.0 → 1.2.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.es.js CHANGED
@@ -293,7 +293,15 @@ class TinaSchema {
293
293
  return { [_template]: this.transformCollectablePayload(rest, field) };
294
294
  }
295
295
  } else {
296
- return value;
296
+ if (field.list) {
297
+ assertShape(value, (yup2) => yup2.array(yup2.object()));
298
+ return value.map((item) => {
299
+ return this.transformCollectablePayload(item, field);
300
+ });
301
+ } else {
302
+ assertShape(value, (yup2) => yup2.object());
303
+ return this.transformCollectablePayload(value, field);
304
+ }
297
305
  }
298
306
  else {
299
307
  return value;
@@ -626,7 +634,8 @@ const TinaFieldZod = z.lazy(() => {
626
634
  fields: z.array(TinaFieldZod),
627
635
  match: z.object({
628
636
  start: z.string(),
629
- end: z.string()
637
+ end: z.string(),
638
+ name: z.string().optional()
630
639
  }).optional()
631
640
  }).superRefine((val, ctx) => {
632
641
  const dups = findDuplicates(val == null ? void 0 : val.fields.map((x) => x.name));
@@ -756,7 +765,7 @@ const validateTinaCloudSchemaConfig = (config) => {
756
765
  const newConfig = tinaConfigZod.parse(config);
757
766
  return newConfig;
758
767
  };
759
- const FORMATS = ["json", "md", "markdown", "mdx"];
768
+ const FORMATS = ["json", "md", "markdown", "mdx", "toml", "yaml"];
760
769
  const Template = z.object({
761
770
  label: z.string({
762
771
  invalid_type_error: "label must be a string",
@@ -776,7 +785,14 @@ const Template = z.object({
776
785
  });
777
786
  const TinaCloudCollectionBase = z.object({
778
787
  label: z.string().optional(),
779
- name,
788
+ name: name.superRefine((val, ctx) => {
789
+ if (val === "relativePath") {
790
+ ctx.addIssue({
791
+ code: z.ZodIssueCode.custom,
792
+ message: `name cannot be 'relativePath'. 'relativePath' is a reserved field name.`
793
+ });
794
+ }
795
+ }),
780
796
  format: z.enum(FORMATS).optional()
781
797
  });
782
798
  const TinaCloudCollection = TinaCloudCollectionBase.extend({
package/dist/index.js CHANGED
@@ -320,7 +320,15 @@
320
320
  return { [_template]: this.transformCollectablePayload(rest, field) };
321
321
  }
322
322
  } else {
323
- return value;
323
+ if (field.list) {
324
+ assertShape(value, (yup2) => yup2.array(yup2.object()));
325
+ return value.map((item) => {
326
+ return this.transformCollectablePayload(item, field);
327
+ });
328
+ } else {
329
+ assertShape(value, (yup2) => yup2.object());
330
+ return this.transformCollectablePayload(value, field);
331
+ }
324
332
  }
325
333
  else {
326
334
  return value;
@@ -653,7 +661,8 @@
653
661
  fields: z.z.array(TinaFieldZod),
654
662
  match: z.z.object({
655
663
  start: z.z.string(),
656
- end: z.z.string()
664
+ end: z.z.string(),
665
+ name: z.z.string().optional()
657
666
  }).optional()
658
667
  }).superRefine((val, ctx) => {
659
668
  const dups = findDuplicates(val == null ? void 0 : val.fields.map((x) => x.name));
@@ -783,7 +792,7 @@ ${JSON.stringify(val, null, 2)}
783
792
  const newConfig = tinaConfigZod.parse(config);
784
793
  return newConfig;
785
794
  };
786
- const FORMATS = ["json", "md", "markdown", "mdx"];
795
+ const FORMATS = ["json", "md", "markdown", "mdx", "toml", "yaml"];
787
796
  const Template = z.z.object({
788
797
  label: z.z.string({
789
798
  invalid_type_error: "label must be a string",
@@ -803,7 +812,14 @@ ${JSON.stringify(val, null, 2)}
803
812
  });
804
813
  const TinaCloudCollectionBase = z.z.object({
805
814
  label: z.z.string().optional(),
806
- name,
815
+ name: name.superRefine((val, ctx) => {
816
+ if (val === "relativePath") {
817
+ ctx.addIssue({
818
+ code: z.z.ZodIssueCode.custom,
819
+ message: `name cannot be 'relativePath'. 'relativePath' is a reserved field name.`
820
+ });
821
+ }
822
+ }),
807
823
  format: z.z.enum(FORMATS).optional()
808
824
  });
809
825
  const TinaCloudCollection = TinaCloudCollectionBase.extend({
@@ -123,6 +123,14 @@ interface BaseCollection {
123
123
  defaultItem?: DefaultItem<Record<string, any>>;
124
124
  indexes?: TinaIndex[];
125
125
  format?: FormatType;
126
+ /**
127
+ * This format will be used to parse the markdown frontmatter
128
+ */
129
+ frontmatterFormat?: 'yaml' | 'toml' | 'json';
130
+ /**
131
+ * The delimiters used to parse the frontmatter.
132
+ */
133
+ frontmatterDelimiters?: [string, string] | string;
126
134
  ui?: UICollection;
127
135
  match?: string;
128
136
  }
@@ -410,6 +418,7 @@ export declare type Template<WithNamespace extends boolean> = WithNamespace exte
410
418
  match?: {
411
419
  start: string;
412
420
  end: string;
421
+ name?: string;
413
422
  };
414
423
  ui?: object | (UIField<any, any> & {
415
424
  previewSrc: string;
@@ -425,6 +434,7 @@ export declare type Template<WithNamespace extends boolean> = WithNamespace exte
425
434
  match?: {
426
435
  start: string;
427
436
  end: string;
437
+ name?: string;
428
438
  };
429
439
  };
430
440
  export declare type CollectionTemplateableUnion = {
@@ -108,6 +108,7 @@ declare type Template = {
108
108
  match?: {
109
109
  start: string;
110
110
  end: string;
111
+ name?: string;
111
112
  };
112
113
  };
113
114
  declare type WithTemplates<Optional extends boolean = false> = Optional extends true ? {
@@ -245,6 +245,7 @@ export declare type RichTextField = (FieldGeneric<RichTextAst, undefined> | Fiel
245
245
  match?: {
246
246
  start: string;
247
247
  end: string;
248
+ name?: string;
248
249
  };
249
250
  })[];
250
251
  };
package/dist/types.d.ts CHANGED
@@ -109,6 +109,8 @@ declare type Component<Type, List> = (props: {
109
109
  meta: Meta;
110
110
  }) => any;
111
111
  declare type UIField<Type, List extends boolean> = {
112
+ max?: List extends true ? number : never;
113
+ min?: List extends true ? number : never;
112
114
  /**
113
115
  * Override the label from parent object
114
116
  */
@@ -273,6 +275,7 @@ export declare type RichTextField = (FieldGeneric<RichTextAst, undefined> | Fiel
273
275
  match?: {
274
276
  start: string;
275
277
  end: string;
278
+ name?: string;
276
279
  };
277
280
  })[];
278
281
  };
@@ -330,7 +333,15 @@ export interface FieldCollection {
330
333
  label?: string;
331
334
  name: string;
332
335
  path: string;
333
- format?: 'json' | 'md' | 'markdown' | 'mdx';
336
+ format?: 'json' | 'md' | 'markdown' | 'mdx' | 'yaml' | 'toml';
337
+ /**
338
+ * This format will be used to parse the markdown frontmatter
339
+ */
340
+ frontmatterFormat?: 'yaml' | 'toml' | 'json';
341
+ /**
342
+ * The delimiters used to parse the frontmatter.
343
+ */
344
+ frontmatterDelimiters?: [string, string] | string;
334
345
  ui?: UICollection & {
335
346
  defaultItem?: DefaultItem<Record<string, any>>;
336
347
  };
@@ -350,7 +361,7 @@ export interface TemplateCollection {
350
361
  label?: string;
351
362
  name: string;
352
363
  path: string;
353
- format?: 'json' | 'md' | 'markdown' | 'mdx';
364
+ format?: 'json' | 'md' | 'markdown' | 'mdx' | 'yaml' | 'toml';
354
365
  ui?: UICollection;
355
366
  /**
356
367
  * @deprecated - use `ui.defaultItem` on the each `template` instead
@@ -415,6 +426,19 @@ export interface Config<CMSCallback = undefined, FormifyCallback = undefined, Do
415
426
  */
416
427
  referenceDepth?: number;
417
428
  };
429
+ /**
430
+ *
431
+ * Tina supports serving content from a separate Git repo. To enable this during local development, point
432
+ * this config at the root of the content repo.
433
+ *
434
+ * NOTE: Relative paths are fine to use here, but you should use an environment variable for this, as each developer on your team may have a different
435
+ * location to the path.
436
+ *
437
+ * ```ts
438
+ * localContentPath: process.env.REMOTE_ROOT_PATH // eg. '../../my-content-repo'
439
+ * ```
440
+ */
441
+ localContentPath?: string;
418
442
  /**
419
443
  * Tina is compiled as a single-page app and placed in the public directory
420
444
  * of your application.
@@ -14,8 +14,8 @@ import { z } from 'zod';
14
14
  export declare const TinaCloudSchemaZod: z.ZodEffects<z.ZodObject<{
15
15
  collections: z.ZodArray<z.ZodEffects<z.ZodObject<z.extendShape<{
16
16
  label: z.ZodOptional<z.ZodString>;
17
- name: z.ZodEffects<z.ZodString, string, string>;
18
- format: z.ZodOptional<z.ZodEnum<["json", "md", "markdown", "mdx"]>>;
17
+ name: z.ZodEffects<z.ZodEffects<z.ZodString, string, string>, string, string>;
18
+ format: z.ZodOptional<z.ZodEnum<["json", "md", "markdown", "mdx", "toml", "yaml"]>>;
19
19
  }, {
20
20
  fields: z.ZodEffects<z.ZodEffects<z.ZodOptional<z.ZodArray<z.ZodType<import("..").TinaFieldInner<false>, z.ZodTypeDef, import("..").TinaFieldInner<false>>, "many">>, import("..").TinaFieldInner<false>[], import("..").TinaFieldInner<false>[]>, import("..").TinaFieldInner<false>[], import("..").TinaFieldInner<false>[]>;
21
21
  templates: z.ZodEffects<z.ZodOptional<z.ZodArray<z.ZodEffects<z.ZodObject<{
@@ -55,7 +55,7 @@ export declare const TinaCloudSchemaZod: z.ZodEffects<z.ZodObject<{
55
55
  fields?: import("..").TinaFieldInner<false>[];
56
56
  label?: string;
57
57
  }[];
58
- format?: "json" | "md" | "markdown" | "mdx";
58
+ format?: "json" | "md" | "markdown" | "mdx" | "yaml" | "toml";
59
59
  label?: string;
60
60
  }, {
61
61
  name?: string;
@@ -65,7 +65,7 @@ export declare const TinaCloudSchemaZod: z.ZodEffects<z.ZodObject<{
65
65
  fields?: import("..").TinaFieldInner<false>[];
66
66
  label?: string;
67
67
  }[];
68
- format?: "json" | "md" | "markdown" | "mdx";
68
+ format?: "json" | "md" | "markdown" | "mdx" | "yaml" | "toml";
69
69
  label?: string;
70
70
  }>, {
71
71
  name?: string;
@@ -75,7 +75,7 @@ export declare const TinaCloudSchemaZod: z.ZodEffects<z.ZodObject<{
75
75
  fields?: import("..").TinaFieldInner<false>[];
76
76
  label?: string;
77
77
  }[];
78
- format?: "json" | "md" | "markdown" | "mdx";
78
+ format?: "json" | "md" | "markdown" | "mdx" | "yaml" | "toml";
79
79
  label?: string;
80
80
  }, {
81
81
  name?: string;
@@ -85,7 +85,7 @@ export declare const TinaCloudSchemaZod: z.ZodEffects<z.ZodObject<{
85
85
  fields?: import("..").TinaFieldInner<false>[];
86
86
  label?: string;
87
87
  }[];
88
- format?: "json" | "md" | "markdown" | "mdx";
88
+ format?: "json" | "md" | "markdown" | "mdx" | "yaml" | "toml";
89
89
  label?: string;
90
90
  }>, "many">;
91
91
  config: z.ZodOptional<z.ZodObject<{
@@ -153,7 +153,7 @@ export declare const TinaCloudSchemaZod: z.ZodEffects<z.ZodObject<{
153
153
  fields?: import("..").TinaFieldInner<false>[];
154
154
  label?: string;
155
155
  }[];
156
- format?: "json" | "md" | "markdown" | "mdx";
156
+ format?: "json" | "md" | "markdown" | "mdx" | "yaml" | "toml";
157
157
  label?: string;
158
158
  }[];
159
159
  config?: {
@@ -177,7 +177,7 @@ export declare const TinaCloudSchemaZod: z.ZodEffects<z.ZodObject<{
177
177
  fields?: import("..").TinaFieldInner<false>[];
178
178
  label?: string;
179
179
  }[];
180
- format?: "json" | "md" | "markdown" | "mdx";
180
+ format?: "json" | "md" | "markdown" | "mdx" | "yaml" | "toml";
181
181
  label?: string;
182
182
  }[];
183
183
  config?: {
@@ -201,7 +201,7 @@ export declare const TinaCloudSchemaZod: z.ZodEffects<z.ZodObject<{
201
201
  fields?: import("..").TinaFieldInner<false>[];
202
202
  label?: string;
203
203
  }[];
204
- format?: "json" | "md" | "markdown" | "mdx";
204
+ format?: "json" | "md" | "markdown" | "mdx" | "yaml" | "toml";
205
205
  label?: string;
206
206
  }[];
207
207
  config?: {
@@ -225,7 +225,7 @@ export declare const TinaCloudSchemaZod: z.ZodEffects<z.ZodObject<{
225
225
  fields?: import("..").TinaFieldInner<false>[];
226
226
  label?: string;
227
227
  }[];
228
- format?: "json" | "md" | "markdown" | "mdx";
228
+ format?: "json" | "md" | "markdown" | "mdx" | "yaml" | "toml";
229
229
  label?: string;
230
230
  }[];
231
231
  config?: {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tinacms/schema-tools",
3
- "version": "1.1.0",
3
+ "version": "1.2.1",
4
4
  "main": "dist/index.js",
5
5
  "module": "./dist/index.es.js",
6
6
  "exports": {
@@ -31,7 +31,7 @@
31
31
  ]
32
32
  },
33
33
  "devDependencies": {
34
- "@tinacms/scripts": "1.0.0",
34
+ "@tinacms/scripts": "1.0.1",
35
35
  "@types/yup": "^0.29.10",
36
36
  "jest": "^27.0.6",
37
37
  "react": "17.0.2",