@tinacms/schema-tools 0.0.4 → 0.0.5

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.5
4
+
5
+ ### Patch Changes
6
+
7
+ - f6cb634c2: Added an optional config key to the schema that will be used for tina cloud media store
8
+
3
9
  ## 0.0.4
4
10
 
5
11
  ### 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
@@ -463,11 +464,11 @@ var resolveForm = ({
463
464
  };
464
465
 
465
466
  // pnp:/home/runner/work/tinacms/tinacms/packages/@tinacms/schema-tools/src/validate/index.ts
466
- var import_zod4 = __toModule(require("zod"));
467
+ var import_zod5 = __toModule(require("zod"));
467
468
 
468
469
  // pnp:/home/runner/work/tinacms/tinacms/packages/@tinacms/schema-tools/src/util/parseZodErrors.ts
469
470
  var parseZodError = ({ zodError }) => {
470
- var _a;
471
+ var _a, _b;
471
472
  const errors = zodError.flatten((issue) => {
472
473
  const moreInfo = [];
473
474
  if (issue.code === "invalid_union") {
@@ -483,14 +484,14 @@ var parseZodError = ({ zodError }) => {
483
484
  });
484
485
  const formErrors = errors.formErrors.flatMap((x) => x.errors);
485
486
  const parsedErrors = [
486
- ...((_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)) || [],
487
488
  ...formErrors
488
489
  ];
489
490
  return parsedErrors;
490
491
  };
491
492
 
492
493
  // pnp:/home/runner/work/tinacms/tinacms/packages/@tinacms/schema-tools/src/validate/schema.ts
493
- var import_zod3 = __toModule(require("zod"));
494
+ var import_zod4 = __toModule(require("zod"));
494
495
 
495
496
  // pnp:/home/runner/work/tinacms/tinacms/packages/@tinacms/schema-tools/src/validate/properties.ts
496
497
  var import_zod = __toModule(require("zod"));
@@ -667,28 +668,44 @@ var TinaFieldZod = import_zod2.z.lazy(() => {
667
668
  });
668
669
  });
669
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
+ syncFolder: 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
+
670
687
  // pnp:/home/runner/work/tinacms/tinacms/packages/@tinacms/schema-tools/src/validate/schema.ts
671
688
  var FORMATS = ["json", "md", "markdown", "mdx"];
672
- var Template = import_zod3.z.object({
673
- label: import_zod3.z.string({
689
+ var Template = import_zod4.z.object({
690
+ label: import_zod4.z.string({
674
691
  invalid_type_error: "label must be a string",
675
692
  required_error: "label was not provided but is required"
676
693
  }),
677
694
  name,
678
- fields: import_zod3.z.array(TinaFieldZod)
695
+ fields: import_zod4.z.array(TinaFieldZod)
679
696
  }).refine((val) => {
680
697
  var _a;
681
698
  return !hasDuplicates((_a = val.fields) == null ? void 0 : _a.map((x) => x.name));
682
699
  }, {
683
700
  message: "Fields must have a unique name"
684
701
  });
685
- var TinaCloudCollectionBase = import_zod3.z.object({
686
- label: import_zod3.z.string().optional(),
702
+ var TinaCloudCollectionBase = import_zod4.z.object({
703
+ label: import_zod4.z.string().optional(),
687
704
  name,
688
- format: import_zod3.z.enum(FORMATS).optional()
705
+ format: import_zod4.z.enum(FORMATS).optional()
689
706
  });
690
707
  var TinaCloudCollection = TinaCloudCollectionBase.extend({
691
- 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)), {
692
709
  message: "Fields must have a unique name"
693
710
  }).refine((val) => {
694
711
  const arr = (val == null ? void 0 : val.filter((x) => x.type === "string" && x.isTitle)) || [];
@@ -696,7 +713,7 @@ var TinaCloudCollection = TinaCloudCollectionBase.extend({
696
713
  }, {
697
714
  message: "Fields can only have one use of `isTitle`"
698
715
  }),
699
- 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)), {
700
717
  message: "Templates must have a unique name"
701
718
  })
702
719
  }).refine((val) => {
@@ -708,8 +725,9 @@ var TinaCloudCollection = TinaCloudCollectionBase.extend({
708
725
  return isValid;
709
726
  }
710
727
  }, { message: "Must provide one of templates or fields in your collection" });
711
- var TinaCloudSchemaZod = import_zod3.z.object({
712
- collections: import_zod3.z.array(TinaCloudCollection)
728
+ var TinaCloudSchemaZod = import_zod4.z.object({
729
+ collections: import_zod4.z.array(TinaCloudCollection),
730
+ config: tinaConfigZod.optional()
713
731
  }).refine((val) => !hasDuplicates(val.collections.map((x) => x.name)), {
714
732
  message: "can not have two collections with the same name"
715
733
  });
@@ -727,7 +745,7 @@ var validateSchema = ({
727
745
  try {
728
746
  TinaCloudSchemaZod.parse(config);
729
747
  } catch (e) {
730
- if (e instanceof import_zod4.ZodError) {
748
+ if (e instanceof import_zod5.ZodError) {
731
749
  const errors = parseZodError({ zodError: e });
732
750
  throw new TinaSchemaValidationError(errors.join(", \n"));
733
751
  } else {
@@ -742,5 +760,6 @@ var validateSchema = ({
742
760
  addNamespaceToSchema,
743
761
  resolveField,
744
762
  resolveForm,
745
- validateSchema
763
+ validateSchema,
764
+ validateTinaCloudSchemaConfig
746
765
  });
@@ -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
+ syncFolder: 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>;
@@ -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
  }
@@ -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
+ syncFolder: z.ZodString;
96
+ }, "strict", z.ZodTypeAny, {
97
+ publicFolder?: string;
98
+ syncFolder?: string;
99
+ }, {
100
+ publicFolder?: string;
101
+ syncFolder?: string;
102
+ }>>;
103
+ }, "strip", z.ZodTypeAny, {
104
+ tina?: {
105
+ publicFolder?: string;
106
+ syncFolder?: string;
107
+ };
108
+ }, {
109
+ tina?: {
110
+ publicFolder?: string;
111
+ syncFolder?: string;
112
+ };
113
+ }>>;
114
+ }, "strip", z.ZodTypeAny, {
115
+ media?: {
116
+ tina?: {
117
+ publicFolder?: string;
118
+ syncFolder?: string;
119
+ };
120
+ };
121
+ }, {
122
+ media?: {
123
+ tina?: {
124
+ publicFolder?: string;
125
+ syncFolder?: 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
+ syncFolder?: 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
+ syncFolder?: 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
+ syncFolder?: 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
+ syncFolder?: 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
+ syncFolder: z.ZodString;
20
+ }, "strict", z.ZodTypeAny, {
21
+ publicFolder?: string;
22
+ syncFolder?: string;
23
+ }, {
24
+ publicFolder?: string;
25
+ syncFolder?: string;
26
+ }>>;
27
+ }, "strip", z.ZodTypeAny, {
28
+ tina?: {
29
+ publicFolder?: string;
30
+ syncFolder?: string;
31
+ };
32
+ }, {
33
+ tina?: {
34
+ publicFolder?: string;
35
+ syncFolder?: string;
36
+ };
37
+ }>>;
38
+ }, "strip", z.ZodTypeAny, {
39
+ media?: {
40
+ tina?: {
41
+ publicFolder?: string;
42
+ syncFolder?: string;
43
+ };
44
+ };
45
+ }, {
46
+ media?: {
47
+ tina?: {
48
+ publicFolder?: string;
49
+ syncFolder?: 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.4",
3
+ "version": "0.0.5",
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.8",
20
20
  "@types/yup": "^0.29.10",
21
21
  "jest": "^27.0.6",
22
22
  "react": "16.14.0",