@tinacms/schema-tools 0.0.3 → 0.0.6

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,23 @@
1
1
  # @tinacms/schema-tools
2
2
 
3
+ ## 0.0.6
4
+
5
+ ### Patch Changes
6
+
7
+ - fb73fb355: Renames syncFolder to a mediaRoot when configuring Repo-Based Media
8
+
9
+ ## 0.0.5
10
+
11
+ ### Patch Changes
12
+
13
+ - f6cb634c2: Added an optional config key to the schema that will be used for tina cloud media store
14
+
15
+ ## 0.0.4
16
+
17
+ ### Patch Changes
18
+
19
+ - 6e2ed31a2: Added `isTitle` property to the schema that allows the title to be displayed in the CMS
20
+
3
21
  ## 0.0.3
4
22
 
5
23
  ### Patch Changes
package/dist/index.js CHANGED
@@ -58,7 +58,8 @@ __export(exports, {
58
58
  addNamespaceToSchema: () => addNamespaceToSchema,
59
59
  resolveField: () => resolveField,
60
60
  resolveForm: () => resolveForm,
61
- validateSchema: () => validateSchema
61
+ validateSchema: () => validateSchema,
62
+ validateTinaCloudSchemaConfig: () => validateTinaCloudSchemaConfig
62
63
  });
63
64
 
64
65
  // pnp:/home/runner/work/tinacms/tinacms/packages/@tinacms/schema-tools/src/schema/addNamespaceToSchema.ts
@@ -185,6 +186,11 @@ function hasDuplicates(array) {
185
186
  var TinaSchema = class {
186
187
  constructor(config) {
187
188
  this.config = config;
189
+ this.getIsTitleFieldName = (collection) => {
190
+ const col = this.getCollection(collection);
191
+ const field = col == null ? void 0 : col.fields.find((x) => x.type === "string" && x.isTitle);
192
+ return field == null ? void 0 : field.name;
193
+ };
188
194
  this.getCollectionsByName = (collectionNames) => {
189
195
  return this.schema.collections.filter((collection) => collectionNames.includes(collection.name));
190
196
  };
@@ -458,11 +464,11 @@ var resolveForm = ({
458
464
  };
459
465
 
460
466
  // pnp:/home/runner/work/tinacms/tinacms/packages/@tinacms/schema-tools/src/validate/index.ts
461
- var import_zod4 = __toModule(require("zod"));
467
+ var import_zod5 = __toModule(require("zod"));
462
468
 
463
469
  // pnp:/home/runner/work/tinacms/tinacms/packages/@tinacms/schema-tools/src/util/parseZodErrors.ts
464
470
  var parseZodError = ({ zodError }) => {
465
- var _a;
471
+ var _a, _b;
466
472
  const errors = zodError.flatten((issue) => {
467
473
  const moreInfo = [];
468
474
  if (issue.code === "invalid_union") {
@@ -478,14 +484,14 @@ var parseZodError = ({ zodError }) => {
478
484
  });
479
485
  const formErrors = errors.formErrors.flatMap((x) => x.errors);
480
486
  const parsedErrors = [
481
- ...((_a = errors.fieldErrors) == null ? void 0 : _a.collections.flatMap((x) => x.errors)) || [],
487
+ ...((_b = (_a = errors.fieldErrors) == null ? void 0 : _a.collections) == null ? void 0 : _b.flatMap((x) => x.errors)) || [],
482
488
  ...formErrors
483
489
  ];
484
490
  return parsedErrors;
485
491
  };
486
492
 
487
493
  // pnp:/home/runner/work/tinacms/tinacms/packages/@tinacms/schema-tools/src/validate/schema.ts
488
- var import_zod3 = __toModule(require("zod"));
494
+ var import_zod4 = __toModule(require("zod"));
489
495
 
490
496
  // pnp:/home/runner/work/tinacms/tinacms/packages/@tinacms/schema-tools/src/validate/properties.ts
491
497
  var import_zod = __toModule(require("zod"));
@@ -533,7 +539,8 @@ var StringField = TinaScalerBase.extend({
533
539
  type: import_zod2.z.literal("string", {
534
540
  invalid_type_error: typeTypeError,
535
541
  required_error: typeRequiredError
536
- })
542
+ }),
543
+ isTitle: import_zod2.z.boolean().optional()
537
544
  });
538
545
  var BooleanField = TinaScalerBase.extend({
539
546
  type: import_zod2.z.literal("boolean", {
@@ -621,6 +628,22 @@ var TinaFieldZod = import_zod2.z.lazy(() => {
621
628
  };
622
629
  }
623
630
  }).superRefine((val, ctx) => {
631
+ if (val.type === "string") {
632
+ if (val.isTitle) {
633
+ if (val.list) {
634
+ ctx.addIssue({
635
+ code: import_zod2.z.ZodIssueCode.custom,
636
+ message: "You can not have `list: true` when using `isTitle`"
637
+ });
638
+ }
639
+ if (!val.required) {
640
+ ctx.addIssue({
641
+ code: import_zod2.z.ZodIssueCode.custom,
642
+ message: "You must have { required: true } when using `isTitle`"
643
+ });
644
+ }
645
+ }
646
+ }
624
647
  if (val.type === "object") {
625
648
  const message = "Must provide one of templates or fields in your collection";
626
649
  let isValid = Boolean(val == null ? void 0 : val.templates) || Boolean(val == null ? void 0 : val.fields);
@@ -645,31 +668,52 @@ var TinaFieldZod = import_zod2.z.lazy(() => {
645
668
  });
646
669
  });
647
670
 
671
+ // pnp:/home/runner/work/tinacms/tinacms/packages/@tinacms/schema-tools/src/validate/tinaCloudSchemaConfig.ts
672
+ var import_zod3 = __toModule(require("zod"));
673
+ var tinaConfigKey = import_zod3.default.object({
674
+ publicFolder: import_zod3.default.string(),
675
+ mediaRoot: import_zod3.default.string()
676
+ }).strict().optional();
677
+ var tinaConfigZod = import_zod3.default.object({
678
+ media: import_zod3.default.object({
679
+ tina: tinaConfigKey
680
+ }).optional()
681
+ });
682
+ var validateTinaCloudSchemaConfig = (config) => {
683
+ const newConfig = tinaConfigZod.parse(config);
684
+ return newConfig;
685
+ };
686
+
648
687
  // pnp:/home/runner/work/tinacms/tinacms/packages/@tinacms/schema-tools/src/validate/schema.ts
649
688
  var FORMATS = ["json", "md", "markdown", "mdx"];
650
- var Template = import_zod3.z.object({
651
- label: import_zod3.z.string({
689
+ var Template = import_zod4.z.object({
690
+ label: import_zod4.z.string({
652
691
  invalid_type_error: "label must be a string",
653
692
  required_error: "label was not provided but is required"
654
693
  }),
655
694
  name,
656
- fields: import_zod3.z.array(TinaFieldZod)
695
+ fields: import_zod4.z.array(TinaFieldZod)
657
696
  }).refine((val) => {
658
697
  var _a;
659
698
  return !hasDuplicates((_a = val.fields) == null ? void 0 : _a.map((x) => x.name));
660
699
  }, {
661
700
  message: "Fields must have a unique name"
662
701
  });
663
- var TinaCloudCollectionBase = import_zod3.z.object({
664
- label: import_zod3.z.string().optional(),
702
+ var TinaCloudCollectionBase = import_zod4.z.object({
703
+ label: import_zod4.z.string().optional(),
665
704
  name,
666
- format: import_zod3.z.enum(FORMATS).optional()
705
+ format: import_zod4.z.enum(FORMATS).optional()
667
706
  });
668
707
  var TinaCloudCollection = TinaCloudCollectionBase.extend({
669
- fields: import_zod3.z.array(TinaFieldZod).min(1).optional().refine((val) => !hasDuplicates(val == null ? void 0 : val.map((x) => x.name)), {
708
+ fields: import_zod4.z.array(TinaFieldZod).min(1).optional().refine((val) => !hasDuplicates(val == null ? void 0 : val.map((x) => x.name)), {
670
709
  message: "Fields must have a unique name"
710
+ }).refine((val) => {
711
+ const arr = (val == null ? void 0 : val.filter((x) => x.type === "string" && x.isTitle)) || [];
712
+ return arr.length < 2;
713
+ }, {
714
+ message: "Fields can only have one use of `isTitle`"
671
715
  }),
672
- templates: import_zod3.z.array(Template).min(1).optional().refine((val) => !hasDuplicates(val == null ? void 0 : val.map((x) => x.name)), {
716
+ templates: import_zod4.z.array(Template).min(1).optional().refine((val) => !hasDuplicates(val == null ? void 0 : val.map((x) => x.name)), {
673
717
  message: "Templates must have a unique name"
674
718
  })
675
719
  }).refine((val) => {
@@ -681,8 +725,9 @@ var TinaCloudCollection = TinaCloudCollectionBase.extend({
681
725
  return isValid;
682
726
  }
683
727
  }, { message: "Must provide one of templates or fields in your collection" });
684
- var TinaCloudSchemaZod = import_zod3.z.object({
685
- collections: import_zod3.z.array(TinaCloudCollection)
728
+ var TinaCloudSchemaZod = import_zod4.z.object({
729
+ collections: import_zod4.z.array(TinaCloudCollection),
730
+ config: tinaConfigZod.optional()
686
731
  }).refine((val) => !hasDuplicates(val.collections.map((x) => x.name)), {
687
732
  message: "can not have two collections with the same name"
688
733
  });
@@ -700,7 +745,7 @@ var validateSchema = ({
700
745
  try {
701
746
  TinaCloudSchemaZod.parse(config);
702
747
  } catch (e) {
703
- if (e instanceof import_zod4.ZodError) {
748
+ if (e instanceof import_zod5.ZodError) {
704
749
  const errors = parseZodError({ zodError: e });
705
750
  throw new TinaSchemaValidationError(errors.join(", \n"));
706
751
  } else {
@@ -715,5 +760,6 @@ var validateSchema = ({
715
760
  addNamespaceToSchema,
716
761
  resolveField,
717
762
  resolveForm,
718
- validateSchema
763
+ validateSchema,
764
+ validateTinaCloudSchemaConfig
719
765
  });
@@ -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>;
@@ -21,9 +21,18 @@ export declare type UIField<F extends UIField = any, Shape = any> = {
21
21
  validate?(value: Shape, allValues: any, meta: any, field: UIField<F, Shape>): string | object | undefined | void;
22
22
  defaultValue?: Shape;
23
23
  };
24
+ export interface TinaCloudSchemaConfig {
25
+ media?: {
26
+ tina?: {
27
+ publicFolder: string;
28
+ mediaRoot: string;
29
+ };
30
+ };
31
+ }
24
32
  export interface TinaCloudSchema<WithNamespace extends boolean> {
25
33
  templates?: GlobalTemplate<WithNamespace>[];
26
34
  collections: TinaCloudCollection<WithNamespace>[];
35
+ config?: TinaCloudSchemaConfig;
27
36
  }
28
37
  export declare type TinaCloudSchemaBase = TinaCloudSchema<false>;
29
38
  export declare type TinaCloudSchemaEnriched = TinaCloudSchema<true>;
@@ -35,6 +44,7 @@ export declare type TinaCloudSchemaEnriched = TinaCloudSchema<true>;
35
44
  export interface TinaCloudSchemaWithNamespace {
36
45
  templates?: GlobalTemplate<true>[];
37
46
  collections: TinaCloudCollection<true>[];
47
+ config?: TinaCloudSchemaConfig;
38
48
  namespace: string[];
39
49
  }
40
50
  export declare type TinaCloudCollection<WithNamespace extends boolean> = CollectionFields<WithNamespace> | CollectionTemplates<WithNamespace>;
@@ -108,11 +118,13 @@ declare type StringField = {
108
118
  type: 'string';
109
119
  isBody?: boolean;
110
120
  list?: false;
121
+ isTitle?: boolean;
111
122
  ui?: UIField<any, string>;
112
123
  } | {
113
124
  type: 'string';
114
125
  isBody?: boolean;
115
126
  list: true;
127
+ isTitle?: never;
116
128
  ui?: UIField<any, string[]>;
117
129
  };
118
130
  declare type BooleanField = {
@@ -11,6 +11,7 @@ See the License for the specific language governing permissions and
11
11
  limitations under the License.
12
12
  */
13
13
  import { TinaCloudSchema } from '../types';
14
+ export { validateTinaCloudSchemaConfig } from './tinaCloudSchemaConfig';
14
15
  export declare class TinaSchemaValidationError extends Error {
15
16
  constructor(message: any);
16
17
  }
@@ -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;
@@ -88,6 +88,44 @@ export declare const TinaCloudSchemaZod: z.ZodEffects<z.ZodObject<{
88
88
  format?: "json" | "md" | "markdown" | "mdx";
89
89
  label?: string;
90
90
  }>, "many">;
91
+ config: z.ZodOptional<z.ZodObject<{
92
+ media: z.ZodOptional<z.ZodObject<{
93
+ tina: z.ZodOptional<z.ZodObject<{
94
+ publicFolder: z.ZodString;
95
+ mediaRoot: z.ZodString;
96
+ }, "strict", z.ZodTypeAny, {
97
+ publicFolder?: string;
98
+ mediaRoot?: string;
99
+ }, {
100
+ publicFolder?: string;
101
+ mediaRoot?: string;
102
+ }>>;
103
+ }, "strip", z.ZodTypeAny, {
104
+ tina?: {
105
+ publicFolder?: string;
106
+ mediaRoot?: string;
107
+ };
108
+ }, {
109
+ tina?: {
110
+ publicFolder?: string;
111
+ mediaRoot?: string;
112
+ };
113
+ }>>;
114
+ }, "strip", z.ZodTypeAny, {
115
+ media?: {
116
+ tina?: {
117
+ publicFolder?: string;
118
+ mediaRoot?: string;
119
+ };
120
+ };
121
+ }, {
122
+ media?: {
123
+ tina?: {
124
+ publicFolder?: string;
125
+ mediaRoot?: string;
126
+ };
127
+ };
128
+ }>>;
91
129
  }, "strip", z.ZodTypeAny, {
92
130
  collections?: {
93
131
  name?: string;
@@ -100,6 +138,14 @@ export declare const TinaCloudSchemaZod: z.ZodEffects<z.ZodObject<{
100
138
  format?: "json" | "md" | "markdown" | "mdx";
101
139
  label?: string;
102
140
  }[];
141
+ config?: {
142
+ media?: {
143
+ tina?: {
144
+ publicFolder?: string;
145
+ mediaRoot?: string;
146
+ };
147
+ };
148
+ };
103
149
  }, {
104
150
  collections?: {
105
151
  name?: string;
@@ -112,6 +158,14 @@ export declare const TinaCloudSchemaZod: z.ZodEffects<z.ZodObject<{
112
158
  format?: "json" | "md" | "markdown" | "mdx";
113
159
  label?: string;
114
160
  }[];
161
+ config?: {
162
+ media?: {
163
+ tina?: {
164
+ publicFolder?: string;
165
+ mediaRoot?: string;
166
+ };
167
+ };
168
+ };
115
169
  }>, {
116
170
  collections?: {
117
171
  name?: string;
@@ -124,6 +178,14 @@ export declare const TinaCloudSchemaZod: z.ZodEffects<z.ZodObject<{
124
178
  format?: "json" | "md" | "markdown" | "mdx";
125
179
  label?: string;
126
180
  }[];
181
+ config?: {
182
+ media?: {
183
+ tina?: {
184
+ publicFolder?: string;
185
+ mediaRoot?: string;
186
+ };
187
+ };
188
+ };
127
189
  }, {
128
190
  collections?: {
129
191
  name?: string;
@@ -136,4 +198,12 @@ export declare const TinaCloudSchemaZod: z.ZodEffects<z.ZodObject<{
136
198
  format?: "json" | "md" | "markdown" | "mdx";
137
199
  label?: string;
138
200
  }[];
201
+ config?: {
202
+ media?: {
203
+ tina?: {
204
+ publicFolder?: string;
205
+ mediaRoot?: string;
206
+ };
207
+ };
208
+ };
139
209
  }>;
@@ -0,0 +1,53 @@
1
+ /**
2
+ Copyright 2021 Forestry.io Holdings, Inc.
3
+ Licensed under the Apache License, Version 2.0 (the "License");
4
+ you may not use this file except in compliance with the License.
5
+ You may obtain a copy of the License at
6
+ http://www.apache.org/licenses/LICENSE-2.0
7
+ Unless required by applicable law or agreed to in writing, software
8
+ distributed under the License is distributed on an "AS IS" BASIS,
9
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10
+ See the License for the specific language governing permissions and
11
+ limitations under the License.
12
+ */
13
+ import { TinaCloudSchemaConfig } from '../types';
14
+ import z from 'zod';
15
+ export declare const tinaConfigZod: z.ZodObject<{
16
+ media: z.ZodOptional<z.ZodObject<{
17
+ tina: z.ZodOptional<z.ZodObject<{
18
+ publicFolder: z.ZodString;
19
+ mediaRoot: z.ZodString;
20
+ }, "strict", z.ZodTypeAny, {
21
+ publicFolder?: string;
22
+ mediaRoot?: string;
23
+ }, {
24
+ publicFolder?: string;
25
+ mediaRoot?: string;
26
+ }>>;
27
+ }, "strip", z.ZodTypeAny, {
28
+ tina?: {
29
+ publicFolder?: string;
30
+ mediaRoot?: string;
31
+ };
32
+ }, {
33
+ tina?: {
34
+ publicFolder?: string;
35
+ mediaRoot?: string;
36
+ };
37
+ }>>;
38
+ }, "strip", z.ZodTypeAny, {
39
+ media?: {
40
+ tina?: {
41
+ publicFolder?: string;
42
+ mediaRoot?: string;
43
+ };
44
+ };
45
+ }, {
46
+ media?: {
47
+ tina?: {
48
+ publicFolder?: string;
49
+ mediaRoot?: string;
50
+ };
51
+ };
52
+ }>;
53
+ export declare const validateTinaCloudSchemaConfig: (config: unknown) => TinaCloudSchemaConfig;
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.6",
4
4
  "main": "dist/index.js",
5
5
  "typings": "dist/index.d.ts",
6
6
  "files": [
@@ -16,7 +16,7 @@
16
16
  ]
17
17
  },
18
18
  "devDependencies": {
19
- "@tinacms/scripts": "0.50.7",
19
+ "@tinacms/scripts": "0.50.9",
20
20
  "@types/yup": "^0.29.10",
21
21
  "jest": "^27.0.6",
22
22
  "react": "16.14.0",