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