@tinacms/schema-tools 0.0.4 → 0.0.7

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
@@ -1,746 +1,736 @@
1
- var __create = Object.create;
2
- var __defProp = Object.defineProperty;
3
- var __defProps = Object.defineProperties;
4
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
- var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
6
- var __getOwnPropNames = Object.getOwnPropertyNames;
7
- var __getOwnPropSymbols = Object.getOwnPropertySymbols;
8
- var __getProtoOf = Object.getPrototypeOf;
9
- var __hasOwnProp = Object.prototype.hasOwnProperty;
10
- var __propIsEnum = Object.prototype.propertyIsEnumerable;
11
- var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
12
- var __spreadValues = (a, b) => {
13
- for (var prop in b || (b = {}))
14
- if (__hasOwnProp.call(b, prop))
15
- __defNormalProp(a, prop, b[prop]);
16
- if (__getOwnPropSymbols)
17
- for (var prop of __getOwnPropSymbols(b)) {
18
- if (__propIsEnum.call(b, prop))
19
- __defNormalProp(a, prop, b[prop]);
20
- }
21
- return a;
22
- };
23
- var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
24
- var __markAsModule = (target) => __defProp(target, "__esModule", { value: true });
25
- var __objRest = (source, exclude) => {
26
- var target = {};
27
- for (var prop in source)
28
- if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
29
- target[prop] = source[prop];
30
- if (source != null && __getOwnPropSymbols)
31
- for (var prop of __getOwnPropSymbols(source)) {
32
- if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
33
- target[prop] = source[prop];
34
- }
35
- return target;
36
- };
37
- var __export = (target, all) => {
38
- __markAsModule(target);
39
- for (var name2 in all)
40
- __defProp(target, name2, { get: all[name2], enumerable: true });
41
- };
42
- var __reExport = (target, module2, desc) => {
43
- if (module2 && typeof module2 === "object" || typeof module2 === "function") {
44
- for (let key of __getOwnPropNames(module2))
45
- if (!__hasOwnProp.call(target, key) && key !== "default")
46
- __defProp(target, key, { get: () => module2[key], enumerable: !(desc = __getOwnPropDesc(module2, key)) || desc.enumerable });
47
- }
48
- return target;
49
- };
50
- var __toModule = (module2) => {
51
- return __reExport(__markAsModule(__defProp(module2 != null ? __create(__getProtoOf(module2)) : {}, "default", module2 && module2.__esModule && "default" in module2 ? { get: () => module2.default, enumerable: true } : { value: module2, enumerable: true })), module2);
52
- };
53
-
54
- // pnp:/home/runner/work/tinacms/tinacms/packages/@tinacms/schema-tools/src/index.ts
55
- __export(exports, {
56
- TinaSchema: () => TinaSchema,
57
- TinaSchemaValidationError: () => TinaSchemaValidationError,
58
- addNamespaceToSchema: () => addNamespaceToSchema,
59
- resolveField: () => resolveField,
60
- resolveForm: () => resolveForm,
61
- validateSchema: () => validateSchema
62
- });
63
-
64
- // pnp:/home/runner/work/tinacms/tinacms/packages/@tinacms/schema-tools/src/schema/addNamespaceToSchema.ts
65
- function addNamespaceToSchema(maybeNode, namespace = []) {
66
- if (typeof maybeNode === "string") {
67
- return maybeNode;
1
+ (function(global, factory) {
2
+ typeof exports === "object" && typeof module !== "undefined" ? factory(exports, require("yup"), require("zod")) : typeof define === "function" && define.amd ? define(["exports", "yup", "zod"], factory) : (global = typeof globalThis !== "undefined" ? globalThis : global || self, factory(global["@tinacms/schema-tools"] = {}, global.NOOP, global.NOOP));
3
+ })(this, function(exports2, yup, z) {
4
+ "use strict";
5
+ function _interopDefaultLegacy(e) {
6
+ return e && typeof e === "object" && "default" in e ? e : { "default": e };
68
7
  }
69
- if (typeof maybeNode === "boolean") {
70
- return maybeNode;
71
- }
72
- const newNode = maybeNode;
73
- const keys = Object.keys(maybeNode);
74
- Object.values(maybeNode).map((m, index) => {
75
- const key = keys[index];
76
- if (Array.isArray(m)) {
77
- newNode[key] = m.map((element) => {
78
- if (!element) {
79
- return;
80
- }
81
- if (!element.hasOwnProperty("name")) {
82
- return element;
8
+ function _interopNamespace(e) {
9
+ if (e && e.__esModule)
10
+ return e;
11
+ var n = Object.create(null, { [Symbol.toStringTag]: { value: "Module" } });
12
+ if (e) {
13
+ Object.keys(e).forEach(function(k) {
14
+ if (k !== "default") {
15
+ var d = Object.getOwnPropertyDescriptor(e, k);
16
+ Object.defineProperty(n, k, d.get ? d : {
17
+ enumerable: true,
18
+ get: function() {
19
+ return e[k];
20
+ }
21
+ });
83
22
  }
84
- const value = element.name || element.value;
85
- return addNamespaceToSchema(element, [...namespace, value]);
86
23
  });
87
- } else {
88
- if (!m) {
89
- return;
90
- }
91
- if (!m.hasOwnProperty("name")) {
92
- newNode[key] = m;
93
- } else {
94
- newNode[key] = addNamespaceToSchema(m, [...namespace, m.name]);
95
- }
96
24
  }
97
- });
98
- return __spreadProps(__spreadValues({}, newNode), { namespace });
99
- }
100
-
101
- // pnp:/home/runner/work/tinacms/tinacms/packages/@tinacms/schema-tools/src/util/validate.ts
102
- var yup = __toModule(require("yup"));
103
- function assertShape(value, yupSchema, errorMessage) {
104
- const shape = yupSchema(yup);
105
- try {
106
- shape.validateSync(value);
107
- } catch (e) {
108
- const message = errorMessage || `Failed to assertShape - ${e.message}`;
109
- throw new Error(message);
110
- }
111
- }
112
-
113
- // pnp:/home/runner/work/tinacms/tinacms/packages/@tinacms/schema-tools/src/util/lastItem.ts
114
- var lastItem = (arr) => {
115
- if (typeof arr === "undefined") {
116
- throw new Error("Can not call lastItem when arr is undefined");
117
- }
118
- return arr[arr.length - 1];
119
- };
120
-
121
- // pnp:/home/runner/work/tinacms/tinacms/packages/@tinacms/schema-tools/src/util/namer.ts
122
- var capitalize = (s) => {
123
- if (typeof s !== "string")
124
- return "";
125
- return s.charAt(0).toUpperCase() + s.slice(1);
126
- };
127
- var generateNamespacedFieldName = (names, suffix = "") => {
128
- return (suffix ? [...names, suffix] : names).map(capitalize).join("");
129
- };
130
- var NAMER = {
131
- dataFilterTypeNameOn: (namespace) => {
132
- return generateNamespacedFieldName(namespace, "_FilterOn");
133
- },
134
- dataFilterTypeName: (namespace) => {
135
- return generateNamespacedFieldName(namespace, "Filter");
136
- },
137
- dataMutationTypeNameOn: (namespace) => {
138
- return generateNamespacedFieldName(namespace, "_MutationOn");
139
- },
140
- dataMutationTypeName: (namespace) => {
141
- return generateNamespacedFieldName(namespace, "Mutation");
142
- },
143
- updateName: (namespace) => {
144
- return "update" + generateNamespacedFieldName(namespace, "Document");
145
- },
146
- createName: (namespace) => {
147
- return "create" + generateNamespacedFieldName(namespace, "Document");
148
- },
149
- queryName: (namespace) => {
150
- return "get" + generateNamespacedFieldName(namespace, "Document");
151
- },
152
- generateQueryListName: (namespace) => {
153
- return "get" + generateNamespacedFieldName(namespace, "List");
154
- },
155
- fragmentName: (namespace) => {
156
- return generateNamespacedFieldName(namespace, "") + "Parts";
157
- },
158
- collectionTypeName: (namespace) => {
159
- return generateNamespacedFieldName(namespace, "Collection");
160
- },
161
- documentTypeName: (namespace) => {
162
- return generateNamespacedFieldName(namespace, "Document");
163
- },
164
- dataTypeName: (namespace) => {
165
- return generateNamespacedFieldName(namespace, "");
166
- },
167
- referenceConnectionType: (namespace) => {
168
- return generateNamespacedFieldName(namespace, "Connection");
169
- },
170
- referenceConnectionEdgesTypeName: (namespace) => {
171
- return generateNamespacedFieldName(namespace, "ConnectionEdges");
172
- }
173
- };
174
-
175
- // pnp:/home/runner/work/tinacms/tinacms/packages/@tinacms/schema-tools/src/util/hasDuplicates.ts
176
- function hasDuplicates(array) {
177
- if (!array) {
178
- return false;
179
- } else {
180
- return new Set(array).size !== array.length;
25
+ n["default"] = e;
26
+ return Object.freeze(n);
181
27
  }
182
- }
183
-
184
- // pnp:/home/runner/work/tinacms/tinacms/packages/@tinacms/schema-tools/src/schema/TinaSchema.ts
185
- var TinaSchema = class {
186
- constructor(config) {
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
- };
193
- this.getCollectionsByName = (collectionNames) => {
194
- return this.schema.collections.filter((collection) => collectionNames.includes(collection.name));
195
- };
196
- this.getAllCollectionPaths = () => {
197
- const paths = this.getCollections().map((collection) => `${collection.path}${collection.match || ""}`);
198
- return paths;
199
- };
200
- this.getCollection = (collectionName) => {
201
- const collection = this.schema.collections.find((collection2) => collection2.name === collectionName);
202
- if (!collection) {
203
- throw new Error(`Expected to find collection named ${collectionName}`);
204
- }
205
- const extraFields = {};
206
- const templateInfo = this.getTemplatesForCollectable(collection);
207
- switch (templateInfo.type) {
208
- case "object":
209
- extraFields["fields"] = templateInfo.template.fields;
210
- break;
211
- case "union":
212
- extraFields["templates"] = templateInfo.templates;
213
- break;
214
- }
215
- return __spreadProps(__spreadValues(__spreadValues({
216
- slug: collection.name
217
- }, extraFields), collection), {
218
- format: collection.format || "md"
219
- });
220
- };
221
- this.getCollections = () => {
222
- return this.schema.collections.map((collection) => this.getCollection(collection.name)) || [];
223
- };
224
- this.getGlobalTemplate = (templateName) => {
225
- var _a;
226
- const globalTemplate = (_a = this.schema.templates) == null ? void 0 : _a.find((template) => template.name === templateName);
227
- if (!globalTemplate) {
228
- throw new Error(`Expected to find global template of name ${templateName}`);
229
- }
230
- return globalTemplate;
231
- };
232
- this.getCollectionByFullPath = (filepath) => {
233
- const collection = this.getCollections().find((collection2) => {
234
- return filepath.replace("\\", "/").startsWith(collection2.path);
235
- });
236
- if (!collection) {
237
- throw new Error(`Unable to find collection for file at ${filepath}`);
238
- }
239
- return collection;
240
- };
241
- this.getCollectionAndTemplateByFullPath = (filepath, templateName) => {
242
- let template;
243
- const collection = this.getCollections().find((collection2) => {
244
- return filepath.replace("\\", "/").startsWith(collection2.path);
245
- });
246
- if (!collection) {
247
- throw new Error(`Unable to find collection for file at ${filepath}`);
248
- }
249
- const templates = this.getTemplatesForCollectable(collection);
250
- if (templates.type === "union") {
251
- if (templateName) {
252
- template = templates.templates.find((template2) => lastItem(template2.namespace) === templateName);
253
- if (!template) {
254
- throw new Error(`Unable to determine template for item at ${filepath}`);
28
+ var yup__namespace = /* @__PURE__ */ _interopNamespace(yup);
29
+ var z__default = /* @__PURE__ */ _interopDefaultLegacy(z);
30
+ function addNamespaceToSchema(maybeNode, namespace = []) {
31
+ if (typeof maybeNode === "string") {
32
+ return maybeNode;
33
+ }
34
+ if (typeof maybeNode === "boolean") {
35
+ return maybeNode;
36
+ }
37
+ const newNode = maybeNode;
38
+ const keys = Object.keys(maybeNode);
39
+ Object.values(maybeNode).map((m, index) => {
40
+ const key = keys[index];
41
+ if (Array.isArray(m)) {
42
+ newNode[key] = m.map((element) => {
43
+ if (!element) {
44
+ return;
45
+ }
46
+ if (!element.hasOwnProperty("name")) {
47
+ return element;
255
48
  }
49
+ const value = element.name || element.value;
50
+ return addNamespaceToSchema(element, [...namespace, value]);
51
+ });
52
+ } else {
53
+ if (!m) {
54
+ return;
55
+ }
56
+ if (!m.hasOwnProperty("name")) {
57
+ newNode[key] = m;
256
58
  } else {
257
- throw new Error(`Unable to determine template for item at ${filepath}, no template name provided for collection with multiple templates`);
59
+ newNode[key] = addNamespaceToSchema(m, [...namespace, m.name]);
258
60
  }
259
61
  }
260
- if (templates.type === "object") {
261
- template = templates.template;
262
- }
263
- if (!template) {
264
- throw new Error(`Something went wrong while trying to determine template for ${filepath}`);
265
- }
266
- return { collection, template };
267
- };
268
- this.getTemplateForData = ({
269
- data,
270
- collection
271
- }) => {
272
- const templateInfo = this.getTemplatesForCollectable(collection);
273
- switch (templateInfo.type) {
274
- case "object":
275
- return templateInfo.template;
276
- case "union":
277
- assertShape(data, (yup2) => yup2.object({ _template: yup2.string().required() }));
278
- const template = templateInfo.templates.find((template2) => template2.namespace[template2.namespace.length - 1] === data._template);
279
- if (!template) {
280
- throw new Error(`Expected to find template named '${data._template}' for collection '${lastItem(collection.namespace)}'`);
281
- }
282
- return template;
283
- }
284
- };
285
- this.isMarkdownCollection = (collectionName) => {
286
- const collection = this.getCollection(collectionName);
287
- const format = collection.format;
288
- if (!format) {
289
- return true;
290
- }
291
- if (["markdown", "md"].includes(format)) {
292
- return true;
293
- }
62
+ });
63
+ return { ...newNode, namespace };
64
+ }
65
+ function assertShape(value, yupSchema, errorMessage) {
66
+ const shape = yupSchema(yup__namespace);
67
+ try {
68
+ shape.validateSync(value);
69
+ } catch (e) {
70
+ const message = errorMessage || `Failed to assertShape - ${e.message}`;
71
+ throw new Error(message);
72
+ }
73
+ }
74
+ const lastItem = (arr) => {
75
+ if (typeof arr === "undefined") {
76
+ throw new Error("Can not call lastItem when arr is undefined");
77
+ }
78
+ return arr[arr.length - 1];
79
+ };
80
+ const capitalize = (s) => {
81
+ if (typeof s !== "string")
82
+ return "";
83
+ return s.charAt(0).toUpperCase() + s.slice(1);
84
+ };
85
+ const generateNamespacedFieldName = (names, suffix = "") => {
86
+ return (suffix ? [...names, suffix] : names).map(capitalize).join("");
87
+ };
88
+ const NAMER = {
89
+ dataFilterTypeNameOn: (namespace) => {
90
+ return generateNamespacedFieldName(namespace, "_FilterOn");
91
+ },
92
+ dataFilterTypeName: (namespace) => {
93
+ return generateNamespacedFieldName(namespace, "Filter");
94
+ },
95
+ dataMutationTypeNameOn: (namespace) => {
96
+ return generateNamespacedFieldName(namespace, "_MutationOn");
97
+ },
98
+ dataMutationTypeName: (namespace) => {
99
+ return generateNamespacedFieldName(namespace, "Mutation");
100
+ },
101
+ updateName: (namespace) => {
102
+ return "update" + generateNamespacedFieldName(namespace, "Document");
103
+ },
104
+ createName: (namespace) => {
105
+ return "create" + generateNamespacedFieldName(namespace, "Document");
106
+ },
107
+ queryName: (namespace) => {
108
+ return "get" + generateNamespacedFieldName(namespace, "Document");
109
+ },
110
+ generateQueryListName: (namespace) => {
111
+ return "get" + generateNamespacedFieldName(namespace, "List");
112
+ },
113
+ fragmentName: (namespace) => {
114
+ return generateNamespacedFieldName(namespace, "") + "Parts";
115
+ },
116
+ collectionTypeName: (namespace) => {
117
+ return generateNamespacedFieldName(namespace, "Collection");
118
+ },
119
+ documentTypeName: (namespace) => {
120
+ return generateNamespacedFieldName(namespace, "Document");
121
+ },
122
+ dataTypeName: (namespace) => {
123
+ return generateNamespacedFieldName(namespace, "");
124
+ },
125
+ referenceConnectionType: (namespace) => {
126
+ return generateNamespacedFieldName(namespace, "Connection");
127
+ },
128
+ referenceConnectionEdgesTypeName: (namespace) => {
129
+ return generateNamespacedFieldName(namespace, "ConnectionEdges");
130
+ }
131
+ };
132
+ function hasDuplicates(array) {
133
+ if (!array) {
294
134
  return false;
295
- };
296
- this.getTemplatesForCollectable = (collection) => {
297
- let extraFields = [];
298
- if (collection.references) {
299
- extraFields = collection.references;
300
- }
301
- if (collection.fields) {
302
- const template = typeof collection.fields === "string" ? this.getGlobalTemplate(collection.fields) : collection;
303
- if (typeof template.fields === "string" || typeof template.fields === "undefined") {
304
- throw new Error("Exptected template to have fields but none were found");
135
+ } else {
136
+ return new Set(array).size !== array.length;
137
+ }
138
+ }
139
+ class TinaSchema {
140
+ constructor(config) {
141
+ this.config = config;
142
+ this.getIsTitleFieldName = (collection) => {
143
+ const col = this.getCollection(collection);
144
+ const field = col == null ? void 0 : col.fields.find((x) => x.type === "string" && x.isTitle);
145
+ return field == null ? void 0 : field.name;
146
+ };
147
+ this.getCollectionsByName = (collectionNames) => {
148
+ return this.schema.collections.filter((collection) => collectionNames.includes(collection.name));
149
+ };
150
+ this.getAllCollectionPaths = () => {
151
+ const paths = this.getCollections().map((collection) => `${collection.path}${collection.match || ""}`);
152
+ return paths;
153
+ };
154
+ this.getCollection = (collectionName) => {
155
+ const collection = this.schema.collections.find((collection2) => collection2.name === collectionName);
156
+ if (!collection) {
157
+ throw new Error(`Expected to find collection named ${collectionName}`);
158
+ }
159
+ const extraFields = {};
160
+ const templateInfo = this.getTemplatesForCollectable(collection);
161
+ switch (templateInfo.type) {
162
+ case "object":
163
+ extraFields["fields"] = templateInfo.template.fields;
164
+ break;
165
+ case "union":
166
+ extraFields["templates"] = templateInfo.templates;
167
+ break;
305
168
  }
306
169
  return {
307
- namespace: collection.namespace,
308
- type: "object",
309
- template: __spreadProps(__spreadValues({}, template), {
310
- fields: [...template.fields, ...extraFields]
311
- })
170
+ slug: collection.name,
171
+ ...extraFields,
172
+ ...collection,
173
+ format: collection.format || "md"
312
174
  };
313
- } else {
314
- if (collection.templates) {
175
+ };
176
+ this.getCollections = () => {
177
+ return this.schema.collections.map((collection) => this.getCollection(collection.name)) || [];
178
+ };
179
+ this.getGlobalTemplate = (templateName) => {
180
+ var _a;
181
+ const globalTemplate = (_a = this.schema.templates) == null ? void 0 : _a.find((template) => template.name === templateName);
182
+ if (!globalTemplate) {
183
+ throw new Error(`Expected to find global template of name ${templateName}`);
184
+ }
185
+ return globalTemplate;
186
+ };
187
+ this.getCollectionByFullPath = (filepath) => {
188
+ const collection = this.getCollections().find((collection2) => {
189
+ return filepath.replace("\\", "/").startsWith(collection2.path);
190
+ });
191
+ if (!collection) {
192
+ throw new Error(`Unable to find collection for file at ${filepath}`);
193
+ }
194
+ return collection;
195
+ };
196
+ this.getCollectionAndTemplateByFullPath = (filepath, templateName) => {
197
+ let template;
198
+ const collection = this.getCollections().find((collection2) => {
199
+ return filepath.replace("\\", "/").startsWith(collection2.path);
200
+ });
201
+ if (!collection) {
202
+ throw new Error(`Unable to find collection for file at ${filepath}`);
203
+ }
204
+ const templates = this.getTemplatesForCollectable(collection);
205
+ if (templates.type === "union") {
206
+ if (templateName) {
207
+ template = templates.templates.find((template2) => lastItem(template2.namespace) === templateName);
208
+ if (!template) {
209
+ throw new Error(`Unable to determine template for item at ${filepath}`);
210
+ }
211
+ } else {
212
+ throw new Error(`Unable to determine template for item at ${filepath}, no template name provided for collection with multiple templates`);
213
+ }
214
+ }
215
+ if (templates.type === "object") {
216
+ template = templates.template;
217
+ }
218
+ if (!template) {
219
+ throw new Error(`Something went wrong while trying to determine template for ${filepath}`);
220
+ }
221
+ return { collection, template };
222
+ };
223
+ this.getTemplateForData = ({
224
+ data,
225
+ collection
226
+ }) => {
227
+ const templateInfo = this.getTemplatesForCollectable(collection);
228
+ switch (templateInfo.type) {
229
+ case "object":
230
+ return templateInfo.template;
231
+ case "union":
232
+ assertShape(data, (yup2) => yup2.object({ _template: yup2.string().required() }));
233
+ const template = templateInfo.templates.find((template2) => template2.namespace[template2.namespace.length - 1] === data._template);
234
+ if (!template) {
235
+ throw new Error(`Expected to find template named '${data._template}' for collection '${lastItem(collection.namespace)}'`);
236
+ }
237
+ return template;
238
+ }
239
+ };
240
+ this.isMarkdownCollection = (collectionName) => {
241
+ const collection = this.getCollection(collectionName);
242
+ const format = collection.format;
243
+ if (!format) {
244
+ return true;
245
+ }
246
+ if (["markdown", "md"].includes(format)) {
247
+ return true;
248
+ }
249
+ return false;
250
+ };
251
+ this.getTemplatesForCollectable = (collection) => {
252
+ let extraFields = [];
253
+ if (collection.references) {
254
+ extraFields = collection.references;
255
+ }
256
+ if (collection.fields) {
257
+ const template = typeof collection.fields === "string" ? this.getGlobalTemplate(collection.fields) : collection;
258
+ if (typeof template.fields === "string" || typeof template.fields === "undefined") {
259
+ throw new Error("Exptected template to have fields but none were found");
260
+ }
315
261
  return {
316
262
  namespace: collection.namespace,
317
- type: "union",
318
- templates: collection.templates.map((templateOrTemplateString) => {
319
- const template = typeof templateOrTemplateString === "string" ? this.getGlobalTemplate(templateOrTemplateString) : templateOrTemplateString;
320
- return __spreadProps(__spreadValues({}, template), {
321
- fields: [...template.fields, ...extraFields]
322
- });
323
- })
263
+ type: "object",
264
+ template: {
265
+ ...template,
266
+ fields: [...template.fields, ...extraFields]
267
+ }
324
268
  };
325
269
  } else {
326
- throw new Error(`Expected either fields or templates array to be defined on collection ${collection.namespace.join("_")}`);
270
+ if (collection.templates) {
271
+ return {
272
+ namespace: collection.namespace,
273
+ type: "union",
274
+ templates: collection.templates.map((templateOrTemplateString) => {
275
+ const template = typeof templateOrTemplateString === "string" ? this.getGlobalTemplate(templateOrTemplateString) : templateOrTemplateString;
276
+ return {
277
+ ...template,
278
+ fields: [...template.fields, ...extraFields]
279
+ };
280
+ })
281
+ };
282
+ } else {
283
+ throw new Error(`Expected either fields or templates array to be defined on collection ${collection.namespace.join("_")}`);
284
+ }
327
285
  }
328
- }
329
- };
330
- this.schema = config;
286
+ };
287
+ this.schema = config;
288
+ }
331
289
  }
332
- };
333
-
334
- // pnp:/home/runner/work/tinacms/tinacms/packages/@tinacms/schema-tools/src/schema/resolveField.ts
335
- var resolveField = (_a, schema) => {
336
- var _b = _a, { namespace } = _b, field = __objRest(_b, ["namespace"]);
337
- var _a2;
338
- field.parentTypename = NAMER.dataTypeName(namespace.filter((_, i) => i < namespace.length - 1));
339
- const extraFields = field.ui || {};
340
- switch (field.type) {
341
- case "number":
342
- return __spreadValues(__spreadValues({
343
- component: "number"
344
- }, field), extraFields);
345
- case "datetime":
346
- return __spreadValues(__spreadValues({
347
- component: "date"
348
- }, field), extraFields);
349
- case "boolean":
350
- return __spreadValues(__spreadValues({
351
- component: "toggle"
352
- }, field), extraFields);
353
- case "image":
354
- return __spreadValues(__spreadValues({
355
- component: "image",
356
- clearable: true
357
- }, field), extraFields);
358
- case "string":
359
- if (field.options) {
290
+ const resolveField = ({ namespace, ...field }, schema) => {
291
+ var _a;
292
+ field.parentTypename = NAMER.dataTypeName(namespace.filter((_, i) => i < namespace.length - 1));
293
+ const extraFields = field.ui || {};
294
+ switch (field.type) {
295
+ case "number":
296
+ return {
297
+ component: "number",
298
+ ...field,
299
+ ...extraFields
300
+ };
301
+ case "datetime":
302
+ return {
303
+ component: "date",
304
+ ...field,
305
+ ...extraFields
306
+ };
307
+ case "boolean":
308
+ return {
309
+ component: "toggle",
310
+ ...field,
311
+ ...extraFields
312
+ };
313
+ case "image":
314
+ return {
315
+ component: "image",
316
+ clearable: true,
317
+ ...field,
318
+ ...extraFields
319
+ };
320
+ case "string":
321
+ if (field.options) {
322
+ if (field.list) {
323
+ return {
324
+ component: "checkbox-group",
325
+ ...field,
326
+ ...extraFields,
327
+ options: field.options
328
+ };
329
+ }
330
+ return {
331
+ component: "select",
332
+ ...field,
333
+ ...extraFields,
334
+ options: [{ label: `Choose an option`, value: "" }, ...field.options]
335
+ };
336
+ }
360
337
  if (field.list) {
361
- return __spreadProps(__spreadValues(__spreadValues({
362
- component: "checkbox-group"
363
- }, field), extraFields), {
364
- options: field.options
365
- });
338
+ return {
339
+ component: "list",
340
+ field: {
341
+ component: "text"
342
+ },
343
+ ...field,
344
+ ...extraFields
345
+ };
366
346
  }
367
- return __spreadProps(__spreadValues(__spreadValues({
368
- component: "select"
369
- }, field), extraFields), {
370
- options: [{ label: `Choose an option`, value: "" }, ...field.options]
371
- });
372
- }
373
- if (field.list) {
374
- return __spreadValues(__spreadValues({
375
- component: "list",
376
- field: {
377
- component: "text"
378
- }
379
- }, field), extraFields);
380
- }
381
- return __spreadValues(__spreadValues({
382
- component: "text"
383
- }, field), extraFields);
384
- case "object":
385
- const templateInfo = schema.getTemplatesForCollectable(__spreadProps(__spreadValues({}, field), {
386
- namespace
387
- }));
388
- if (templateInfo.type === "object") {
389
- return __spreadValues(__spreadProps(__spreadValues({}, field), {
390
- component: field.list ? "group-list" : "group",
391
- fields: templateInfo.template.fields.map((field2) => resolveField(field2, schema))
392
- }), extraFields);
393
- } else if (templateInfo.type === "union") {
394
- const templates2 = {};
395
- const typeMap2 = {};
396
- templateInfo.templates.forEach((template) => {
397
- const extraFields2 = template.ui || {};
398
- const templateName = lastItem(template.namespace);
399
- typeMap2[templateName] = NAMER.dataTypeName(template.namespace);
400
- templates2[lastItem(template.namespace)] = __spreadValues({
401
- label: template.label || templateName,
402
- key: templateName,
403
- fields: template.fields.map((field2) => resolveField(field2, schema))
404
- }, extraFields2);
405
- return true;
347
+ return {
348
+ component: "text",
349
+ ...field,
350
+ ...extraFields
351
+ };
352
+ case "object":
353
+ const templateInfo = schema.getTemplatesForCollectable({
354
+ ...field,
355
+ namespace
406
356
  });
407
- return __spreadValues(__spreadProps(__spreadValues({}, field), {
408
- typeMap: typeMap2,
409
- component: field.list ? "blocks" : "not-implemented",
410
- templates: templates2
411
- }), extraFields);
412
- } else {
413
- throw new Error(`Unknown object for resolveField function`);
414
- }
415
- case "rich-text":
416
- const templates = {};
417
- const typeMap = {};
418
- (_a2 = field.templates) == null ? void 0 : _a2.forEach((template) => {
419
- if (typeof template === "string") {
420
- throw new Error(`Global templates not yet supported for rich-text`);
357
+ if (templateInfo.type === "object") {
358
+ return {
359
+ ...field,
360
+ component: field.list ? "group-list" : "group",
361
+ fields: templateInfo.template.fields.map((field2) => resolveField(field2, schema)),
362
+ ...extraFields
363
+ };
364
+ } else if (templateInfo.type === "union") {
365
+ const templates2 = {};
366
+ const typeMap2 = {};
367
+ templateInfo.templates.forEach((template) => {
368
+ const extraFields2 = template.ui || {};
369
+ const templateName = lastItem(template.namespace);
370
+ typeMap2[templateName] = NAMER.dataTypeName(template.namespace);
371
+ templates2[lastItem(template.namespace)] = {
372
+ label: template.label || templateName,
373
+ key: templateName,
374
+ fields: template.fields.map((field2) => resolveField(field2, schema)),
375
+ ...extraFields2
376
+ };
377
+ return true;
378
+ });
379
+ return {
380
+ ...field,
381
+ typeMap: typeMap2,
382
+ component: field.list ? "blocks" : "not-implemented",
383
+ templates: templates2,
384
+ ...extraFields
385
+ };
421
386
  } else {
422
- const extraFields2 = template.ui || {};
423
- const templateName = lastItem(template.namespace);
424
- typeMap[templateName] = NAMER.dataTypeName(template.namespace);
425
- templates[lastItem(template.namespace)] = __spreadValues({
426
- label: template.label || templateName,
427
- key: templateName,
428
- inline: template.inline,
429
- name: templateName,
430
- fields: template.fields.map((field2) => resolveField(field2, schema))
431
- }, extraFields2);
432
- return true;
387
+ throw new Error(`Unknown object for resolveField function`);
433
388
  }
434
- });
435
- return __spreadValues(__spreadProps(__spreadValues({}, field), {
436
- templates: Object.values(templates),
437
- component: "rich-text"
438
- }), extraFields);
439
- case "reference":
440
- return __spreadValues(__spreadProps(__spreadValues({}, field), {
441
- component: "reference"
442
- }), extraFields);
443
- default:
444
- throw new Error(`Unknown field type ${field.type}`);
445
- }
446
- };
447
-
448
- // pnp:/home/runner/work/tinacms/tinacms/packages/@tinacms/schema-tools/src/schema/resolveForm.ts
449
- var resolveForm = ({
450
- collection,
451
- basename,
452
- template,
453
- schema
454
- }) => {
455
- return {
456
- id: basename,
457
- label: collection.label,
458
- name: basename,
459
- fields: template.fields.map((field) => {
460
- return resolveField(field, schema);
461
- })
462
- };
463
- };
464
-
465
- // pnp:/home/runner/work/tinacms/tinacms/packages/@tinacms/schema-tools/src/validate/index.ts
466
- var import_zod4 = __toModule(require("zod"));
467
-
468
- // pnp:/home/runner/work/tinacms/tinacms/packages/@tinacms/schema-tools/src/util/parseZodErrors.ts
469
- var parseZodError = ({ zodError }) => {
470
- var _a;
471
- const errors = zodError.flatten((issue) => {
472
- const moreInfo = [];
473
- if (issue.code === "invalid_union") {
474
- issue.unionErrors.map((unionError) => {
475
- moreInfo.push(parseZodError({ zodError: unionError }));
476
- });
389
+ case "rich-text":
390
+ const templates = {};
391
+ (_a = field.templates) == null ? void 0 : _a.forEach((template) => {
392
+ if (typeof template === "string") {
393
+ throw new Error(`Global templates not yet supported for rich-text`);
394
+ } else {
395
+ const extraFields2 = template.ui || {};
396
+ const templateName = lastItem(template.namespace);
397
+ NAMER.dataTypeName(template.namespace);
398
+ templates[lastItem(template.namespace)] = {
399
+ label: template.label || templateName,
400
+ key: templateName,
401
+ inline: template.inline,
402
+ name: templateName,
403
+ fields: template.fields.map((field2) => resolveField(field2, schema)),
404
+ ...extraFields2
405
+ };
406
+ return true;
407
+ }
408
+ });
409
+ return {
410
+ ...field,
411
+ templates: Object.values(templates),
412
+ component: "rich-text",
413
+ ...extraFields
414
+ };
415
+ case "reference":
416
+ return {
417
+ ...field,
418
+ component: "reference",
419
+ ...extraFields
420
+ };
421
+ default:
422
+ throw new Error(`Unknown field type ${field.type}`);
477
423
  }
478
- const errorMessage = `Error ${issue == null ? void 0 : issue.message} at path ${issue.path.join(".")}`;
479
- const errorMessages = [errorMessage, ...moreInfo];
424
+ };
425
+ const resolveForm = ({
426
+ collection,
427
+ basename,
428
+ template,
429
+ schema
430
+ }) => {
480
431
  return {
481
- errors: errorMessages
432
+ id: basename,
433
+ label: collection.label,
434
+ name: basename,
435
+ fields: template.fields.map((field) => {
436
+ return resolveField(field, schema);
437
+ })
482
438
  };
439
+ };
440
+ const parseZodError = ({ zodError }) => {
441
+ var _a, _b, _c, _d;
442
+ const errors = zodError.flatten((issue) => {
443
+ const moreInfo = [];
444
+ if (issue.code === "invalid_union") {
445
+ issue.unionErrors.map((unionError) => {
446
+ moreInfo.push(parseZodError({ zodError: unionError }));
447
+ });
448
+ }
449
+ const errorMessage = `Error ${issue == null ? void 0 : issue.message} at path ${issue.path.join(".")}`;
450
+ const errorMessages = [errorMessage, ...moreInfo];
451
+ return {
452
+ errors: errorMessages
453
+ };
454
+ });
455
+ const formErrors = errors.formErrors.flatMap((x) => x.errors);
456
+ const parsedErrors = [
457
+ ...((_b = (_a = errors.fieldErrors) == null ? void 0 : _a.collections) == null ? void 0 : _b.flatMap((x) => x.errors)) || [],
458
+ ...((_d = (_c = errors.fieldErrors) == null ? void 0 : _c.config) == null ? void 0 : _d.flatMap((x) => x.errors)) || [],
459
+ ...formErrors
460
+ ];
461
+ return parsedErrors;
462
+ };
463
+ const name = z.z.string({
464
+ required_error: "Name is required but not provided",
465
+ invalid_type_error: "Name must be a string"
483
466
  });
484
- const formErrors = errors.formErrors.flatMap((x) => x.errors);
485
- const parsedErrors = [
486
- ...((_a = errors.fieldErrors) == null ? void 0 : _a.collections.flatMap((x) => x.errors)) || [],
487
- ...formErrors
467
+ const TypeName = [
468
+ "string",
469
+ "boolean",
470
+ "number",
471
+ "datetime",
472
+ "image",
473
+ "object",
474
+ "reference",
475
+ "rich-text"
488
476
  ];
489
- return parsedErrors;
490
- };
491
-
492
- // pnp:/home/runner/work/tinacms/tinacms/packages/@tinacms/schema-tools/src/validate/schema.ts
493
- var import_zod3 = __toModule(require("zod"));
494
-
495
- // pnp:/home/runner/work/tinacms/tinacms/packages/@tinacms/schema-tools/src/validate/properties.ts
496
- var import_zod = __toModule(require("zod"));
497
- var name = import_zod.z.string({
498
- required_error: "Name is required but not provided",
499
- invalid_type_error: "Name must be a string"
500
- });
501
-
502
- // pnp:/home/runner/work/tinacms/tinacms/packages/@tinacms/schema-tools/src/validate/fields.ts
503
- var import_zod2 = __toModule(require("zod"));
504
- var TypeName = [
505
- "string",
506
- "boolean",
507
- "number",
508
- "datetime",
509
- "image",
510
- "object",
511
- "reference",
512
- "rich-text"
513
- ];
514
- var typeTypeError = `type must be one of ${TypeName.join(", ")}`;
515
- var typeRequiredError = `type is required and must be one of ${TypeName.join(", ")}`;
516
- var nameProp = import_zod2.z.string({
517
- required_error: "name must be provided",
518
- invalid_type_error: "name must be a sting"
519
- });
520
- var Option = import_zod2.z.union([import_zod2.z.string(), import_zod2.z.object({ label: import_zod2.z.string(), value: import_zod2.z.string() })], {
521
- errorMap: () => {
522
- return {
523
- message: "Invalid option array. Must be a string[] or {label: string, value: string}[]"
524
- };
525
- }
526
- });
527
- var TinaField = import_zod2.z.object({
528
- name: nameProp,
529
- label: import_zod2.z.string().optional(),
530
- description: import_zod2.z.string().optional(),
531
- required: import_zod2.z.boolean().optional()
532
- });
533
- var FieldWithList = TinaField.extend({ list: import_zod2.z.boolean().optional() });
534
- var TinaScalerBase = FieldWithList.extend({
535
- options: import_zod2.z.array(Option).optional()
536
- });
537
- var StringField = TinaScalerBase.extend({
538
- type: import_zod2.z.literal("string", {
539
- invalid_type_error: typeTypeError,
540
- required_error: typeRequiredError
541
- }),
542
- isTitle: import_zod2.z.boolean().optional()
543
- });
544
- var BooleanField = TinaScalerBase.extend({
545
- type: import_zod2.z.literal("boolean", {
546
- invalid_type_error: typeTypeError,
547
- required_error: typeRequiredError
548
- })
549
- });
550
- var NumberField = TinaScalerBase.extend({
551
- type: import_zod2.z.literal("number", {
552
- invalid_type_error: typeTypeError,
553
- required_error: typeRequiredError
554
- })
555
- });
556
- var ImageField = TinaScalerBase.extend({
557
- type: import_zod2.z.literal("image", {
558
- invalid_type_error: typeTypeError,
559
- required_error: typeRequiredError
560
- })
561
- });
562
- var DateTimeField = TinaScalerBase.extend({
563
- type: import_zod2.z.literal("datetime", {
564
- invalid_type_error: typeTypeError,
565
- required_error: typeRequiredError
566
- }),
567
- dateFormat: import_zod2.z.string().optional(),
568
- timeFormat: import_zod2.z.string().optional()
569
- });
570
- var ReferenceField = FieldWithList.extend({
571
- type: import_zod2.z.literal("reference", {
572
- invalid_type_error: typeTypeError,
573
- required_error: typeRequiredError
574
- })
575
- });
576
- var TinaFieldZod = import_zod2.z.lazy(() => {
577
- const TemplateTemp = import_zod2.z.object({
578
- label: import_zod2.z.string(),
477
+ const typeTypeError = `type must be one of ${TypeName.join(", ")}`;
478
+ const typeRequiredError = `type is required and must be one of ${TypeName.join(", ")}`;
479
+ const nameProp = z.z.string({
480
+ required_error: "name must be provided",
481
+ invalid_type_error: "name must be a sting"
482
+ });
483
+ const Option = z.z.union([z.z.string(), z.z.object({ label: z.z.string(), value: z.z.string() })], {
484
+ errorMap: () => {
485
+ return {
486
+ message: "Invalid option array. Must be a string[] or {label: string, value: string}[]"
487
+ };
488
+ }
489
+ });
490
+ const TinaField = z.z.object({
579
491
  name: nameProp,
580
- fields: import_zod2.z.array(TinaFieldZod)
581
- }).refine((val) => {
582
- var _a;
583
- return !hasDuplicates((_a = val.fields) == null ? void 0 : _a.map((x) => x.name));
584
- }, {
585
- message: "Fields must have a unique name"
492
+ label: z.z.string().optional(),
493
+ description: z.z.string().optional(),
494
+ required: z.z.boolean().optional()
495
+ });
496
+ const FieldWithList = TinaField.extend({ list: z.z.boolean().optional() });
497
+ const TinaScalerBase = FieldWithList.extend({
498
+ options: z.z.array(Option).optional()
586
499
  });
587
- const ObjectField = FieldWithList.extend({
588
- type: import_zod2.z.literal("object", {
500
+ const StringField = TinaScalerBase.extend({
501
+ type: z.z.literal("string", {
589
502
  invalid_type_error: typeTypeError,
590
503
  required_error: typeRequiredError
591
504
  }),
592
- fields: import_zod2.z.array(TinaFieldZod).min(1).optional().refine((val) => !hasDuplicates(val == null ? void 0 : val.map((x) => x.name)), {
593
- message: "Fields must have a unique name"
594
- }),
595
- templates: import_zod2.z.array(TemplateTemp).min(1).optional().refine((val) => !hasDuplicates(val == null ? void 0 : val.map((x) => x.name)), {
596
- message: "Templates must have a unique name"
505
+ isTitle: z.z.boolean().optional()
506
+ });
507
+ const BooleanField = TinaScalerBase.extend({
508
+ type: z.z.literal("boolean", {
509
+ invalid_type_error: typeTypeError,
510
+ required_error: typeRequiredError
597
511
  })
598
512
  });
599
- const RichTextField = FieldWithList.extend({
600
- type: import_zod2.z.literal("rich-text", {
513
+ const NumberField = TinaScalerBase.extend({
514
+ type: z.z.literal("number", {
515
+ invalid_type_error: typeTypeError,
516
+ required_error: typeRequiredError
517
+ })
518
+ });
519
+ const ImageField = TinaScalerBase.extend({
520
+ type: z.z.literal("image", {
521
+ invalid_type_error: typeTypeError,
522
+ required_error: typeRequiredError
523
+ })
524
+ });
525
+ const DateTimeField = TinaScalerBase.extend({
526
+ type: z.z.literal("datetime", {
601
527
  invalid_type_error: typeTypeError,
602
528
  required_error: typeRequiredError
603
529
  }),
604
- templates: import_zod2.z.array(TemplateTemp).optional().refine((val) => !hasDuplicates(val == null ? void 0 : val.map((x) => x.name)), {
605
- message: "Templates must have a unique name"
530
+ dateFormat: z.z.string().optional(),
531
+ timeFormat: z.z.string().optional()
532
+ });
533
+ const ReferenceField = FieldWithList.extend({
534
+ type: z.z.literal("reference", {
535
+ invalid_type_error: typeTypeError,
536
+ required_error: typeRequiredError
606
537
  })
607
538
  });
608
- return import_zod2.z.discriminatedUnion("type", [
609
- StringField,
610
- BooleanField,
611
- NumberField,
612
- ImageField,
613
- DateTimeField,
614
- ReferenceField,
615
- ObjectField,
616
- RichTextField
617
- ], {
618
- errorMap: (issue, ctx) => {
539
+ const TinaFieldZod = z.z.lazy(() => {
540
+ const TemplateTemp = z.z.object({
541
+ label: z.z.string(),
542
+ name: nameProp,
543
+ fields: z.z.array(TinaFieldZod)
544
+ }).refine((val) => {
619
545
  var _a;
620
- if (issue.code === "invalid_union_discriminator") {
546
+ return !hasDuplicates((_a = val.fields) == null ? void 0 : _a.map((x) => x.name));
547
+ }, {
548
+ message: "Fields must have a unique name"
549
+ });
550
+ const ObjectField = FieldWithList.extend({
551
+ type: z.z.literal("object", {
552
+ invalid_type_error: typeTypeError,
553
+ required_error: typeRequiredError
554
+ }),
555
+ fields: z.z.array(TinaFieldZod).min(1).optional().refine((val) => !hasDuplicates(val == null ? void 0 : val.map((x) => x.name)), {
556
+ message: "Fields must have a unique name"
557
+ }),
558
+ templates: z.z.array(TemplateTemp).min(1).optional().refine((val) => !hasDuplicates(val == null ? void 0 : val.map((x) => x.name)), {
559
+ message: "Templates must have a unique name"
560
+ })
561
+ });
562
+ const RichTextField = FieldWithList.extend({
563
+ type: z.z.literal("rich-text", {
564
+ invalid_type_error: typeTypeError,
565
+ required_error: typeRequiredError
566
+ }),
567
+ templates: z.z.array(TemplateTemp).optional().refine((val) => !hasDuplicates(val == null ? void 0 : val.map((x) => x.name)), {
568
+ message: "Templates must have a unique name"
569
+ })
570
+ });
571
+ return z.z.discriminatedUnion("type", [
572
+ StringField,
573
+ BooleanField,
574
+ NumberField,
575
+ ImageField,
576
+ DateTimeField,
577
+ ReferenceField,
578
+ ObjectField,
579
+ RichTextField
580
+ ], {
581
+ errorMap: (issue, ctx) => {
582
+ var _a;
583
+ if (issue.code === "invalid_union_discriminator") {
584
+ return {
585
+ message: `Invalid \`type\` property. In the schema is 'type: ${(_a = ctx.data) == null ? void 0 : _a.type}' and expected one of ${TypeName.join(", ")}`
586
+ };
587
+ }
621
588
  return {
622
- message: `Invalid \`type\` property. In the schema is 'type: ${(_a = ctx.data) == null ? void 0 : _a.type}' and expected one of ${TypeName.join(", ")}`
589
+ message: issue.message
623
590
  };
624
591
  }
625
- return {
626
- message: issue.message
627
- };
628
- }
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
- });
592
+ }).superRefine((val, ctx) => {
593
+ if (val.type === "string") {
594
+ if (val.isTitle) {
595
+ if (val.list) {
596
+ ctx.addIssue({
597
+ code: z.z.ZodIssueCode.custom,
598
+ message: "You can not have `list: true` when using `isTitle`"
599
+ });
600
+ }
601
+ if (!val.required) {
602
+ ctx.addIssue({
603
+ code: z.z.ZodIssueCode.custom,
604
+ message: "You must have { required: true } when using `isTitle`"
605
+ });
606
+ }
643
607
  }
644
608
  }
645
- }
646
- if (val.type === "object") {
647
- const message = "Must provide one of templates or fields in your collection";
648
- let isValid = Boolean(val == null ? void 0 : val.templates) || Boolean(val == null ? void 0 : val.fields);
649
- if (!isValid) {
650
- ctx.addIssue({
651
- code: import_zod2.z.ZodIssueCode.custom,
652
- message
653
- });
654
- return false;
655
- } else {
656
- isValid = !((val == null ? void 0 : val.templates) && (val == null ? void 0 : val.fields));
609
+ if (val.type === "object") {
610
+ const message = "Must provide one of templates or fields in your collection";
611
+ let isValid = Boolean(val == null ? void 0 : val.templates) || Boolean(val == null ? void 0 : val.fields);
657
612
  if (!isValid) {
658
613
  ctx.addIssue({
659
- code: import_zod2.z.ZodIssueCode.custom,
614
+ code: z.z.ZodIssueCode.custom,
660
615
  message
661
616
  });
617
+ return false;
618
+ } else {
619
+ isValid = !((val == null ? void 0 : val.templates) && (val == null ? void 0 : val.fields));
620
+ if (!isValid) {
621
+ ctx.addIssue({
622
+ code: z.z.ZodIssueCode.custom,
623
+ message
624
+ });
625
+ }
626
+ return isValid;
662
627
  }
663
- return isValid;
664
628
  }
665
- }
666
- return true;
629
+ return true;
630
+ });
667
631
  });
668
- });
669
-
670
- // pnp:/home/runner/work/tinacms/tinacms/packages/@tinacms/schema-tools/src/validate/schema.ts
671
- var FORMATS = ["json", "md", "markdown", "mdx"];
672
- var Template = import_zod3.z.object({
673
- label: import_zod3.z.string({
674
- invalid_type_error: "label must be a string",
675
- required_error: "label was not provided but is required"
676
- }),
677
- name,
678
- fields: import_zod3.z.array(TinaFieldZod)
679
- }).refine((val) => {
680
- var _a;
681
- return !hasDuplicates((_a = val.fields) == null ? void 0 : _a.map((x) => x.name));
682
- }, {
683
- message: "Fields must have a unique name"
684
- });
685
- var TinaCloudCollectionBase = import_zod3.z.object({
686
- label: import_zod3.z.string().optional(),
687
- name,
688
- format: import_zod3.z.enum(FORMATS).optional()
689
- });
690
- 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)), {
692
- message: "Fields must have a unique name"
632
+ const tinaConfigKey = z__default["default"].object({
633
+ publicFolder: z__default["default"].string(),
634
+ mediaRoot: z__default["default"].string()
635
+ }).strict().optional();
636
+ const tinaConfigZod = z__default["default"].object({
637
+ media: z__default["default"].object({
638
+ tina: tinaConfigKey,
639
+ loadCustomStore: z__default["default"].function().optional()
640
+ }).optional()
641
+ });
642
+ const validateTinaCloudSchemaConfig = (config) => {
643
+ const newConfig = tinaConfigZod.parse(config);
644
+ return newConfig;
645
+ };
646
+ const FORMATS = ["json", "md", "markdown", "mdx"];
647
+ const Template = z.z.object({
648
+ label: z.z.string({
649
+ invalid_type_error: "label must be a string",
650
+ required_error: "label was not provided but is required"
651
+ }),
652
+ name,
653
+ fields: z.z.array(TinaFieldZod)
693
654
  }).refine((val) => {
694
- const arr = (val == null ? void 0 : val.filter((x) => x.type === "string" && x.isTitle)) || [];
695
- return arr.length < 2;
655
+ var _a;
656
+ return !hasDuplicates((_a = val.fields) == null ? void 0 : _a.map((x) => x.name));
696
657
  }, {
697
- message: "Fields can only have one use of `isTitle`"
698
- }),
699
- templates: import_zod3.z.array(Template).min(1).optional().refine((val) => !hasDuplicates(val == null ? void 0 : val.map((x) => x.name)), {
700
- message: "Templates must have a unique name"
701
- })
702
- }).refine((val) => {
703
- let isValid = Boolean(val == null ? void 0 : val.templates) || Boolean(val == null ? void 0 : val.fields);
704
- if (!isValid) {
705
- return false;
706
- } else {
707
- isValid = !((val == null ? void 0 : val.templates) && (val == null ? void 0 : val.fields));
708
- return isValid;
709
- }
710
- }, { 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)
713
- }).refine((val) => !hasDuplicates(val.collections.map((x) => x.name)), {
714
- message: "can not have two collections with the same name"
715
- });
716
-
717
- // pnp:/home/runner/work/tinacms/tinacms/packages/@tinacms/schema-tools/src/validate/index.ts
718
- var TinaSchemaValidationError = class extends Error {
719
- constructor(message) {
720
- super(message);
721
- this.name = "TinaSchemaValidationError";
722
- }
723
- };
724
- var validateSchema = ({
725
- config
726
- }) => {
727
- try {
728
- TinaCloudSchemaZod.parse(config);
729
- } catch (e) {
730
- if (e instanceof import_zod4.ZodError) {
731
- const errors = parseZodError({ zodError: e });
732
- throw new TinaSchemaValidationError(errors.join(", \n"));
658
+ message: "Fields must have a unique name"
659
+ });
660
+ const TinaCloudCollectionBase = z.z.object({
661
+ label: z.z.string().optional(),
662
+ name,
663
+ format: z.z.enum(FORMATS).optional()
664
+ });
665
+ const TinaCloudCollection = TinaCloudCollectionBase.extend({
666
+ fields: z.z.array(TinaFieldZod).min(1).optional().refine((val) => !hasDuplicates(val == null ? void 0 : val.map((x) => x.name)), {
667
+ message: "Fields must have a unique name"
668
+ }).refine((val) => {
669
+ const arr = (val == null ? void 0 : val.filter((x) => x.type === "string" && x.isTitle)) || [];
670
+ return arr.length < 2;
671
+ }, {
672
+ message: "Fields can only have one use of `isTitle`"
673
+ }),
674
+ templates: z.z.array(Template).min(1).optional().refine((val) => !hasDuplicates(val == null ? void 0 : val.map((x) => x.name)), {
675
+ message: "Templates must have a unique name"
676
+ })
677
+ }).refine((val) => {
678
+ let isValid = Boolean(val == null ? void 0 : val.templates) || Boolean(val == null ? void 0 : val.fields);
679
+ if (!isValid) {
680
+ return false;
733
681
  } else {
734
- throw new Error(e);
682
+ isValid = !((val == null ? void 0 : val.templates) && (val == null ? void 0 : val.fields));
683
+ return isValid;
684
+ }
685
+ }, { message: "Must provide one of templates or fields in your collection" });
686
+ const TinaCloudSchemaZod = z.z.object({
687
+ collections: z.z.array(TinaCloudCollection),
688
+ config: tinaConfigZod.optional()
689
+ }).superRefine((val, ctx) => {
690
+ var _a;
691
+ if (hasDuplicates(val.collections.map((x) => x.name))) {
692
+ ctx.addIssue({
693
+ code: z.z.ZodIssueCode.custom,
694
+ message: "can not have two collections with the same name",
695
+ fatal: true
696
+ });
697
+ }
698
+ const media = (_a = val == null ? void 0 : val.config) == null ? void 0 : _a.media;
699
+ if (media && media.tina && media.loadCustomStore) {
700
+ ctx.addIssue({
701
+ code: z.z.ZodIssueCode.custom,
702
+ message: "can not have both loadCustomStore and tina. Must use one or the other",
703
+ fatal: true,
704
+ path: ["config", "media"]
705
+ });
706
+ }
707
+ });
708
+ class TinaSchemaValidationError extends Error {
709
+ constructor(message) {
710
+ super(message);
711
+ this.name = "TinaSchemaValidationError";
735
712
  }
736
713
  }
737
- };
738
- // Annotate the CommonJS export names for ESM import in node:
739
- 0 && (module.exports = {
740
- TinaSchema,
741
- TinaSchemaValidationError,
742
- addNamespaceToSchema,
743
- resolveField,
744
- resolveForm,
745
- validateSchema
714
+ const validateSchema = ({
715
+ config
716
+ }) => {
717
+ try {
718
+ TinaCloudSchemaZod.parse(config);
719
+ } catch (e) {
720
+ if (e instanceof z.ZodError) {
721
+ const errors = parseZodError({ zodError: e });
722
+ throw new TinaSchemaValidationError(errors.join(", \n"));
723
+ } else {
724
+ throw new Error(e);
725
+ }
726
+ }
727
+ };
728
+ exports2.TinaSchema = TinaSchema;
729
+ exports2.TinaSchemaValidationError = TinaSchemaValidationError;
730
+ exports2.addNamespaceToSchema = addNamespaceToSchema;
731
+ exports2.resolveField = resolveField;
732
+ exports2.resolveForm = resolveForm;
733
+ exports2.validateSchema = validateSchema;
734
+ exports2.validateTinaCloudSchemaConfig = validateTinaCloudSchemaConfig;
735
+ Object.defineProperties(exports2, { __esModule: { value: true }, [Symbol.toStringTag]: { value: "Module" } });
746
736
  });