@tinacms/schema-tools 0.0.1 → 0.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +47 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +297 -4
- package/dist/schema/TinaSchema.d.ts +1 -0
- package/dist/types/SchemaTypes.d.ts +14 -4
- package/dist/util/hasDuplicates.d.ts +13 -0
- package/dist/util/index.d.ts +1 -0
- package/dist/util/parseZodErrors.d.ts +16 -0
- package/dist/util/validate.d.ts +2 -2
- package/dist/validate/fields.d.ts +15 -0
- package/dist/validate/index.d.ts +19 -0
- package/dist/validate/properties.d.ts +14 -0
- package/dist/validate/schema.d.ts +139 -0
- package/package.json +6 -2
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
# @tinacms/schema-tools
|
|
2
|
+
|
|
3
|
+
## 0.0.4
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 6e2ed31a2: Added `isTitle` property to the schema that allows the title to be displayed in the CMS
|
|
8
|
+
|
|
9
|
+
## 0.0.3
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- 921709a7e: Adds validation to the schema instead of only using typescript types
|
|
14
|
+
|
|
15
|
+
## 0.0.2
|
|
16
|
+
|
|
17
|
+
### Patch Changes
|
|
18
|
+
|
|
19
|
+
- abf25c673: The schema can now to used on the frontend (optional for now but will be the main path moving forward).
|
|
20
|
+
|
|
21
|
+
### How to migrate.
|
|
22
|
+
|
|
23
|
+
If you gone though the `tinacms init` process there should be a file called `.tina/components/TinaProvider`. In that file you can import the schema from `schema.ts` and add it to the TinaCMS wrapper component.
|
|
24
|
+
|
|
25
|
+
```tsx
|
|
26
|
+
import TinaCMS from 'tinacms'
|
|
27
|
+
import schema, { tinaConfig } from '../schema.ts'
|
|
28
|
+
|
|
29
|
+
// Importing the TinaProvider directly into your page will cause Tina to be added to the production bundle.
|
|
30
|
+
// Instead, import the tina/provider/index default export to have it dynamially imported in edit-moode
|
|
31
|
+
/**
|
|
32
|
+
*
|
|
33
|
+
* @private Do not import this directly, please import the dynamic provider instead
|
|
34
|
+
*/
|
|
35
|
+
const TinaProvider = ({ children }) => {
|
|
36
|
+
return (
|
|
37
|
+
<TinaCMS {...tinaConfig} schema={schema}>
|
|
38
|
+
{children}
|
|
39
|
+
</TinaCMS>
|
|
40
|
+
)
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export default TinaProvider
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
- 801f39f62: Update types
|
|
47
|
+
- e8b0de1f7: Add `parentTypename` to fields to allow us to disambiguate between fields which have the same field names but different types. Example, an event from field name of `blocks.0.title` could belong to a `Cta` block or a `Hero` block, both of which have a `title` field.
|
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -36,8 +36,8 @@ var __objRest = (source, exclude) => {
|
|
|
36
36
|
};
|
|
37
37
|
var __export = (target, all) => {
|
|
38
38
|
__markAsModule(target);
|
|
39
|
-
for (var
|
|
40
|
-
__defProp(target,
|
|
39
|
+
for (var name2 in all)
|
|
40
|
+
__defProp(target, name2, { get: all[name2], enumerable: true });
|
|
41
41
|
};
|
|
42
42
|
var __reExport = (target, module2, desc) => {
|
|
43
43
|
if (module2 && typeof module2 === "object" || typeof module2 === "function") {
|
|
@@ -54,9 +54,11 @@ var __toModule = (module2) => {
|
|
|
54
54
|
// pnp:/home/runner/work/tinacms/tinacms/packages/@tinacms/schema-tools/src/index.ts
|
|
55
55
|
__export(exports, {
|
|
56
56
|
TinaSchema: () => TinaSchema,
|
|
57
|
+
TinaSchemaValidationError: () => TinaSchemaValidationError,
|
|
57
58
|
addNamespaceToSchema: () => addNamespaceToSchema,
|
|
58
59
|
resolveField: () => resolveField,
|
|
59
|
-
resolveForm: () => resolveForm
|
|
60
|
+
resolveForm: () => resolveForm,
|
|
61
|
+
validateSchema: () => validateSchema
|
|
60
62
|
});
|
|
61
63
|
|
|
62
64
|
// pnp:/home/runner/work/tinacms/tinacms/packages/@tinacms/schema-tools/src/schema/addNamespaceToSchema.ts
|
|
@@ -170,10 +172,24 @@ var NAMER = {
|
|
|
170
172
|
}
|
|
171
173
|
};
|
|
172
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;
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
|
|
173
184
|
// pnp:/home/runner/work/tinacms/tinacms/packages/@tinacms/schema-tools/src/schema/TinaSchema.ts
|
|
174
185
|
var TinaSchema = class {
|
|
175
186
|
constructor(config) {
|
|
176
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
|
+
};
|
|
177
193
|
this.getCollectionsByName = (collectionNames) => {
|
|
178
194
|
return this.schema.collections.filter((collection) => collectionNames.includes(collection.name));
|
|
179
195
|
};
|
|
@@ -319,6 +335,7 @@ var TinaSchema = class {
|
|
|
319
335
|
var resolveField = (_a, schema) => {
|
|
320
336
|
var _b = _a, { namespace } = _b, field = __objRest(_b, ["namespace"]);
|
|
321
337
|
var _a2;
|
|
338
|
+
field.parentTypename = NAMER.dataTypeName(namespace.filter((_, i) => i < namespace.length - 1));
|
|
322
339
|
const extraFields = field.ui || {};
|
|
323
340
|
switch (field.type) {
|
|
324
341
|
case "number":
|
|
@@ -444,10 +461,286 @@ var resolveForm = ({
|
|
|
444
461
|
})
|
|
445
462
|
};
|
|
446
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
|
+
});
|
|
477
|
+
}
|
|
478
|
+
const errorMessage = `Error ${issue == null ? void 0 : issue.message} at path ${issue.path.join(".")}`;
|
|
479
|
+
const errorMessages = [errorMessage, ...moreInfo];
|
|
480
|
+
return {
|
|
481
|
+
errors: errorMessages
|
|
482
|
+
};
|
|
483
|
+
});
|
|
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
|
|
488
|
+
];
|
|
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(),
|
|
579
|
+
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"
|
|
586
|
+
});
|
|
587
|
+
const ObjectField = FieldWithList.extend({
|
|
588
|
+
type: import_zod2.z.literal("object", {
|
|
589
|
+
invalid_type_error: typeTypeError,
|
|
590
|
+
required_error: typeRequiredError
|
|
591
|
+
}),
|
|
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"
|
|
597
|
+
})
|
|
598
|
+
});
|
|
599
|
+
const RichTextField = FieldWithList.extend({
|
|
600
|
+
type: import_zod2.z.literal("rich-text", {
|
|
601
|
+
invalid_type_error: typeTypeError,
|
|
602
|
+
required_error: typeRequiredError
|
|
603
|
+
}),
|
|
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"
|
|
606
|
+
})
|
|
607
|
+
});
|
|
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) => {
|
|
619
|
+
var _a;
|
|
620
|
+
if (issue.code === "invalid_union_discriminator") {
|
|
621
|
+
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(", ")}`
|
|
623
|
+
};
|
|
624
|
+
}
|
|
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
|
+
});
|
|
643
|
+
}
|
|
644
|
+
}
|
|
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));
|
|
657
|
+
if (!isValid) {
|
|
658
|
+
ctx.addIssue({
|
|
659
|
+
code: import_zod2.z.ZodIssueCode.custom,
|
|
660
|
+
message
|
|
661
|
+
});
|
|
662
|
+
}
|
|
663
|
+
return isValid;
|
|
664
|
+
}
|
|
665
|
+
}
|
|
666
|
+
return true;
|
|
667
|
+
});
|
|
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"
|
|
693
|
+
}).refine((val) => {
|
|
694
|
+
const arr = (val == null ? void 0 : val.filter((x) => x.type === "string" && x.isTitle)) || [];
|
|
695
|
+
return arr.length < 2;
|
|
696
|
+
}, {
|
|
697
|
+
message: "Fields can only have one use of `isTitle`"
|
|
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"));
|
|
733
|
+
} else {
|
|
734
|
+
throw new Error(e);
|
|
735
|
+
}
|
|
736
|
+
}
|
|
737
|
+
};
|
|
447
738
|
// Annotate the CommonJS export names for ESM import in node:
|
|
448
739
|
0 && (module.exports = {
|
|
449
740
|
TinaSchema,
|
|
741
|
+
TinaSchemaValidationError,
|
|
450
742
|
addNamespaceToSchema,
|
|
451
743
|
resolveField,
|
|
452
|
-
resolveForm
|
|
744
|
+
resolveForm,
|
|
745
|
+
validateSchema
|
|
453
746
|
});
|
|
@@ -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>;
|
|
@@ -61,18 +61,24 @@ export interface CollectionTemplatesWithNamespace<WithNamespace extends boolean>
|
|
|
61
61
|
}
|
|
62
62
|
declare type CollectionFields<WithNamespace extends boolean> = WithNamespace extends true ? CollectionFieldsWithNamespace<WithNamespace> : CollectionFieldsInner<WithNamespace>;
|
|
63
63
|
export interface CollectionFieldsWithNamespace<WithNamespace extends boolean> extends BaseCollection {
|
|
64
|
-
fields:
|
|
64
|
+
fields: TinaFieldInner<WithNamespace>[];
|
|
65
65
|
templates?: undefined;
|
|
66
66
|
references?: ReferenceType<WithNamespace>[];
|
|
67
67
|
namespace: string[];
|
|
68
68
|
}
|
|
69
69
|
interface CollectionFieldsInner<WithNamespace extends boolean> extends BaseCollection {
|
|
70
|
-
fields:
|
|
70
|
+
fields: TinaFieldInner<WithNamespace>[];
|
|
71
71
|
templates?: undefined;
|
|
72
72
|
}
|
|
73
73
|
export declare type TinaFieldInner<WithNamespace extends boolean> = ScalarType<WithNamespace> | ObjectType<WithNamespace> | ReferenceType<WithNamespace> | RichType<WithNamespace>;
|
|
74
74
|
export declare type TinaFieldBase = TinaFieldInner<false>;
|
|
75
|
-
export declare type TinaFieldEnriched = TinaFieldInner<true
|
|
75
|
+
export declare type TinaFieldEnriched = TinaFieldInner<true> & {
|
|
76
|
+
/**
|
|
77
|
+
* The parentTypename will always be an object type, either the type of a
|
|
78
|
+
* collection (ie. `Post`) or of an object field (ie. `PageBlocks`).
|
|
79
|
+
*/
|
|
80
|
+
parentTypename?: string;
|
|
81
|
+
};
|
|
76
82
|
interface TinaField {
|
|
77
83
|
name: string;
|
|
78
84
|
label?: string;
|
|
@@ -83,7 +89,7 @@ interface TinaField {
|
|
|
83
89
|
* NOTE: only serializable values are supported, so functions like `validate`
|
|
84
90
|
* will be ignored.
|
|
85
91
|
*/
|
|
86
|
-
ui?:
|
|
92
|
+
ui?: Record<string, any>;
|
|
87
93
|
}
|
|
88
94
|
declare type ScalarType<WithNamespace extends boolean> = WithNamespace extends true ? ScalarTypeWithNamespace : ScalarTypeInner;
|
|
89
95
|
declare type Option = string | {
|
|
@@ -102,11 +108,13 @@ declare type StringField = {
|
|
|
102
108
|
type: 'string';
|
|
103
109
|
isBody?: boolean;
|
|
104
110
|
list?: false;
|
|
111
|
+
isTitle?: boolean;
|
|
105
112
|
ui?: UIField<any, string>;
|
|
106
113
|
} | {
|
|
107
114
|
type: 'string';
|
|
108
115
|
isBody?: boolean;
|
|
109
116
|
list: true;
|
|
117
|
+
isTitle?: never;
|
|
110
118
|
ui?: UIField<any, string[]>;
|
|
111
119
|
};
|
|
112
120
|
declare type BooleanField = {
|
|
@@ -159,6 +167,7 @@ export interface ReferenceTypeInner extends TinaField {
|
|
|
159
167
|
name: string;
|
|
160
168
|
};
|
|
161
169
|
collections: string[];
|
|
170
|
+
ui?: UIField<any, string[]>;
|
|
162
171
|
}
|
|
163
172
|
export interface ReferenceTypeWithNamespace extends TinaField {
|
|
164
173
|
type: 'reference';
|
|
@@ -169,6 +178,7 @@ export interface ReferenceTypeWithNamespace extends TinaField {
|
|
|
169
178
|
name: string;
|
|
170
179
|
};
|
|
171
180
|
namespace: string[];
|
|
181
|
+
ui?: UIField<any, string[]>;
|
|
172
182
|
}
|
|
173
183
|
export interface RichTypeWithNamespace extends TinaField {
|
|
174
184
|
type: 'rich-text';
|
|
@@ -0,0 +1,13 @@
|
|
|
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
|
+
export declare function hasDuplicates<T = any>(array: T[]): boolean;
|
package/dist/util/index.d.ts
CHANGED
|
@@ -0,0 +1,16 @@
|
|
|
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 type { ZodError } from 'zod';
|
|
14
|
+
export declare const parseZodError: ({ zodError }: {
|
|
15
|
+
zodError: ZodError;
|
|
16
|
+
}) => string[];
|
package/dist/util/validate.d.ts
CHANGED
|
@@ -11,5 +11,5 @@ See the License for the specific language governing permissions and
|
|
|
11
11
|
limitations under the License.
|
|
12
12
|
*/
|
|
13
13
|
import * as yup from 'yup';
|
|
14
|
-
import type {
|
|
15
|
-
export declare function assertShape<T extends unknown>(value: unknown, yupSchema: (args: typeof yup) =>
|
|
14
|
+
import type { AnySchema } from 'yup';
|
|
15
|
+
export declare function assertShape<T extends unknown>(value: unknown, yupSchema: (args: typeof yup) => AnySchema, errorMessage?: string): asserts value is T;
|
|
@@ -0,0 +1,15 @@
|
|
|
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 { z } from 'zod';
|
|
14
|
+
import { TinaFieldInner } from '../types/SchemaTypes';
|
|
15
|
+
export declare const TinaFieldZod: z.ZodType<TinaFieldInner<false>>;
|
|
@@ -0,0 +1,19 @@
|
|
|
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 { TinaCloudSchema } from '../types';
|
|
14
|
+
export declare class TinaSchemaValidationError extends Error {
|
|
15
|
+
constructor(message: any);
|
|
16
|
+
}
|
|
17
|
+
export declare const validateSchema: ({ config, }: {
|
|
18
|
+
config: TinaCloudSchema<false>;
|
|
19
|
+
}) => void;
|
|
@@ -0,0 +1,14 @@
|
|
|
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 { z } from 'zod';
|
|
14
|
+
export declare const name: z.ZodString;
|
|
@@ -0,0 +1,139 @@
|
|
|
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 { z } from 'zod';
|
|
14
|
+
export declare const TinaCloudSchemaZod: z.ZodEffects<z.ZodObject<{
|
|
15
|
+
collections: z.ZodArray<z.ZodEffects<z.ZodObject<z.extendShape<{
|
|
16
|
+
label: z.ZodOptional<z.ZodString>;
|
|
17
|
+
name: z.ZodString;
|
|
18
|
+
format: z.ZodOptional<z.ZodEnum<["json", "md", "markdown", "mdx"]>>;
|
|
19
|
+
}, {
|
|
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
|
+
templates: z.ZodEffects<z.ZodOptional<z.ZodArray<z.ZodEffects<z.ZodObject<{
|
|
22
|
+
label: z.ZodString;
|
|
23
|
+
name: z.ZodString;
|
|
24
|
+
fields: z.ZodArray<z.ZodType<import("..").TinaFieldInner<false>, z.ZodTypeDef, import("..").TinaFieldInner<false>>, "many">;
|
|
25
|
+
}, "strip", z.ZodTypeAny, {
|
|
26
|
+
name?: string;
|
|
27
|
+
fields?: import("..").TinaFieldInner<false>[];
|
|
28
|
+
label?: string;
|
|
29
|
+
}, {
|
|
30
|
+
name?: string;
|
|
31
|
+
fields?: import("..").TinaFieldInner<false>[];
|
|
32
|
+
label?: string;
|
|
33
|
+
}>, {
|
|
34
|
+
name?: string;
|
|
35
|
+
fields?: import("..").TinaFieldInner<false>[];
|
|
36
|
+
label?: string;
|
|
37
|
+
}, {
|
|
38
|
+
name?: string;
|
|
39
|
+
fields?: import("..").TinaFieldInner<false>[];
|
|
40
|
+
label?: string;
|
|
41
|
+
}>, "many">>, {
|
|
42
|
+
name?: string;
|
|
43
|
+
fields?: import("..").TinaFieldInner<false>[];
|
|
44
|
+
label?: string;
|
|
45
|
+
}[], {
|
|
46
|
+
name?: string;
|
|
47
|
+
fields?: import("..").TinaFieldInner<false>[];
|
|
48
|
+
label?: string;
|
|
49
|
+
}[]>;
|
|
50
|
+
}>, "strip", z.ZodTypeAny, {
|
|
51
|
+
name?: string;
|
|
52
|
+
fields?: import("..").TinaFieldInner<false>[];
|
|
53
|
+
templates?: {
|
|
54
|
+
name?: string;
|
|
55
|
+
fields?: import("..").TinaFieldInner<false>[];
|
|
56
|
+
label?: string;
|
|
57
|
+
}[];
|
|
58
|
+
format?: "json" | "md" | "markdown" | "mdx";
|
|
59
|
+
label?: string;
|
|
60
|
+
}, {
|
|
61
|
+
name?: string;
|
|
62
|
+
fields?: import("..").TinaFieldInner<false>[];
|
|
63
|
+
templates?: {
|
|
64
|
+
name?: string;
|
|
65
|
+
fields?: import("..").TinaFieldInner<false>[];
|
|
66
|
+
label?: string;
|
|
67
|
+
}[];
|
|
68
|
+
format?: "json" | "md" | "markdown" | "mdx";
|
|
69
|
+
label?: string;
|
|
70
|
+
}>, {
|
|
71
|
+
name?: string;
|
|
72
|
+
fields?: import("..").TinaFieldInner<false>[];
|
|
73
|
+
templates?: {
|
|
74
|
+
name?: string;
|
|
75
|
+
fields?: import("..").TinaFieldInner<false>[];
|
|
76
|
+
label?: string;
|
|
77
|
+
}[];
|
|
78
|
+
format?: "json" | "md" | "markdown" | "mdx";
|
|
79
|
+
label?: string;
|
|
80
|
+
}, {
|
|
81
|
+
name?: string;
|
|
82
|
+
fields?: import("..").TinaFieldInner<false>[];
|
|
83
|
+
templates?: {
|
|
84
|
+
name?: string;
|
|
85
|
+
fields?: import("..").TinaFieldInner<false>[];
|
|
86
|
+
label?: string;
|
|
87
|
+
}[];
|
|
88
|
+
format?: "json" | "md" | "markdown" | "mdx";
|
|
89
|
+
label?: string;
|
|
90
|
+
}>, "many">;
|
|
91
|
+
}, "strip", z.ZodTypeAny, {
|
|
92
|
+
collections?: {
|
|
93
|
+
name?: string;
|
|
94
|
+
fields?: import("..").TinaFieldInner<false>[];
|
|
95
|
+
templates?: {
|
|
96
|
+
name?: string;
|
|
97
|
+
fields?: import("..").TinaFieldInner<false>[];
|
|
98
|
+
label?: string;
|
|
99
|
+
}[];
|
|
100
|
+
format?: "json" | "md" | "markdown" | "mdx";
|
|
101
|
+
label?: string;
|
|
102
|
+
}[];
|
|
103
|
+
}, {
|
|
104
|
+
collections?: {
|
|
105
|
+
name?: string;
|
|
106
|
+
fields?: import("..").TinaFieldInner<false>[];
|
|
107
|
+
templates?: {
|
|
108
|
+
name?: string;
|
|
109
|
+
fields?: import("..").TinaFieldInner<false>[];
|
|
110
|
+
label?: string;
|
|
111
|
+
}[];
|
|
112
|
+
format?: "json" | "md" | "markdown" | "mdx";
|
|
113
|
+
label?: string;
|
|
114
|
+
}[];
|
|
115
|
+
}>, {
|
|
116
|
+
collections?: {
|
|
117
|
+
name?: string;
|
|
118
|
+
fields?: import("..").TinaFieldInner<false>[];
|
|
119
|
+
templates?: {
|
|
120
|
+
name?: string;
|
|
121
|
+
fields?: import("..").TinaFieldInner<false>[];
|
|
122
|
+
label?: string;
|
|
123
|
+
}[];
|
|
124
|
+
format?: "json" | "md" | "markdown" | "mdx";
|
|
125
|
+
label?: string;
|
|
126
|
+
}[];
|
|
127
|
+
}, {
|
|
128
|
+
collections?: {
|
|
129
|
+
name?: string;
|
|
130
|
+
fields?: import("..").TinaFieldInner<false>[];
|
|
131
|
+
templates?: {
|
|
132
|
+
name?: string;
|
|
133
|
+
fields?: import("..").TinaFieldInner<false>[];
|
|
134
|
+
label?: string;
|
|
135
|
+
}[];
|
|
136
|
+
format?: "json" | "md" | "markdown" | "mdx";
|
|
137
|
+
label?: string;
|
|
138
|
+
}[];
|
|
139
|
+
}>;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tinacms/schema-tools",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.4",
|
|
4
4
|
"main": "dist/index.js",
|
|
5
5
|
"typings": "dist/index.d.ts",
|
|
6
6
|
"files": [
|
|
@@ -20,7 +20,8 @@
|
|
|
20
20
|
"@types/yup": "^0.29.10",
|
|
21
21
|
"jest": "^27.0.6",
|
|
22
22
|
"react": "16.14.0",
|
|
23
|
-
"typescript": "^4.3.5"
|
|
23
|
+
"typescript": "^4.3.5",
|
|
24
|
+
"yup": "^0.32.0"
|
|
24
25
|
},
|
|
25
26
|
"peerDependencies": {
|
|
26
27
|
"react": ">=16.14.0",
|
|
@@ -39,5 +40,8 @@
|
|
|
39
40
|
"repository": {
|
|
40
41
|
"url": "https://github.com/tinacms/tinacms.git",
|
|
41
42
|
"directory": "packages/@tinacms/cli"
|
|
43
|
+
},
|
|
44
|
+
"dependencies": {
|
|
45
|
+
"zod": "^3.14.3"
|
|
42
46
|
}
|
|
43
47
|
}
|