@tinacms/schema-tools 0.0.3 → 0.0.4

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/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # @tinacms/schema-tools
2
2
 
3
+ ## 0.0.4
4
+
5
+ ### Patch Changes
6
+
7
+ - 6e2ed31a2: Added `isTitle` property to the schema that allows the title to be displayed in the CMS
8
+
3
9
  ## 0.0.3
4
10
 
5
11
  ### Patch Changes
package/dist/index.js CHANGED
@@ -185,6 +185,11 @@ function hasDuplicates(array) {
185
185
  var TinaSchema = class {
186
186
  constructor(config) {
187
187
  this.config = config;
188
+ this.getIsTitleFieldName = (collection) => {
189
+ const col = this.getCollection(collection);
190
+ const field = col == null ? void 0 : col.fields.find((x) => x.type === "string" && x.isTitle);
191
+ return field == null ? void 0 : field.name;
192
+ };
188
193
  this.getCollectionsByName = (collectionNames) => {
189
194
  return this.schema.collections.filter((collection) => collectionNames.includes(collection.name));
190
195
  };
@@ -533,7 +538,8 @@ var StringField = TinaScalerBase.extend({
533
538
  type: import_zod2.z.literal("string", {
534
539
  invalid_type_error: typeTypeError,
535
540
  required_error: typeRequiredError
536
- })
541
+ }),
542
+ isTitle: import_zod2.z.boolean().optional()
537
543
  });
538
544
  var BooleanField = TinaScalerBase.extend({
539
545
  type: import_zod2.z.literal("boolean", {
@@ -621,6 +627,22 @@ var TinaFieldZod = import_zod2.z.lazy(() => {
621
627
  };
622
628
  }
623
629
  }).superRefine((val, ctx) => {
630
+ if (val.type === "string") {
631
+ if (val.isTitle) {
632
+ if (val.list) {
633
+ ctx.addIssue({
634
+ code: import_zod2.z.ZodIssueCode.custom,
635
+ message: "You can not have `list: true` when using `isTitle`"
636
+ });
637
+ }
638
+ if (!val.required) {
639
+ ctx.addIssue({
640
+ code: import_zod2.z.ZodIssueCode.custom,
641
+ message: "You must have { required: true } when using `isTitle`"
642
+ });
643
+ }
644
+ }
645
+ }
624
646
  if (val.type === "object") {
625
647
  const message = "Must provide one of templates or fields in your collection";
626
648
  let isValid = Boolean(val == null ? void 0 : val.templates) || Boolean(val == null ? void 0 : val.fields);
@@ -668,6 +690,11 @@ var TinaCloudCollectionBase = import_zod3.z.object({
668
690
  var TinaCloudCollection = TinaCloudCollectionBase.extend({
669
691
  fields: import_zod3.z.array(TinaFieldZod).min(1).optional().refine((val) => !hasDuplicates(val == null ? void 0 : val.map((x) => x.name)), {
670
692
  message: "Fields must have a unique name"
693
+ }).refine((val) => {
694
+ const arr = (val == null ? void 0 : val.filter((x) => x.type === "string" && x.isTitle)) || [];
695
+ return arr.length < 2;
696
+ }, {
697
+ message: "Fields can only have one use of `isTitle`"
671
698
  }),
672
699
  templates: import_zod3.z.array(Template).min(1).optional().refine((val) => !hasDuplicates(val == null ? void 0 : val.map((x) => x.name)), {
673
700
  message: "Templates must have a unique name"
@@ -41,6 +41,7 @@ export declare class TinaSchema {
41
41
  version?: Version;
42
42
  meta?: Meta;
43
43
  } & TinaCloudSchemaBase);
44
+ getIsTitleFieldName: (collection: string) => string;
44
45
  getCollectionsByName: (collectionNames: string[]) => TinaCloudCollection<true>[];
45
46
  getAllCollectionPaths: () => string[];
46
47
  getCollection: (collectionName: string) => TinaCloudCollection<true>;
@@ -108,11 +108,13 @@ declare type StringField = {
108
108
  type: 'string';
109
109
  isBody?: boolean;
110
110
  list?: false;
111
+ isTitle?: boolean;
111
112
  ui?: UIField<any, string>;
112
113
  } | {
113
114
  type: 'string';
114
115
  isBody?: boolean;
115
116
  list: true;
117
+ isTitle?: never;
116
118
  ui?: UIField<any, string[]>;
117
119
  };
118
120
  declare type BooleanField = {
@@ -17,7 +17,7 @@ export declare const TinaCloudSchemaZod: z.ZodEffects<z.ZodObject<{
17
17
  name: z.ZodString;
18
18
  format: z.ZodOptional<z.ZodEnum<["json", "md", "markdown", "mdx"]>>;
19
19
  }, {
20
- fields: z.ZodEffects<z.ZodOptional<z.ZodArray<z.ZodType<import("..").TinaFieldInner<false>, z.ZodTypeDef, import("..").TinaFieldInner<false>>, "many">>, import("..").TinaFieldInner<false>[], import("..").TinaFieldInner<false>[]>;
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<{
22
22
  label: z.ZodString;
23
23
  name: z.ZodString;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tinacms/schema-tools",
3
- "version": "0.0.3",
3
+ "version": "0.0.4",
4
4
  "main": "dist/index.js",
5
5
  "typings": "dist/index.d.ts",
6
6
  "files": [