@tinacms/schema-tools 0.0.0-d69e892-20241003042309 → 0.0.0-d7c5ec1-20250219020924
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 +142 -154
- package/dist/index.mjs +142 -154
- package/dist/schema/TinaSchema.d.ts +4 -0
- package/dist/schema/addNamespaceToSchema.d.ts +8 -4
- package/dist/types/index.d.ts +9 -2
- package/dist/validate/fields.d.ts +0 -3
- package/dist/validate/schema.d.ts +0 -3
- package/dist/validate/util.d.ts +3 -0
- package/package.json +6 -6
package/dist/index.js
CHANGED
|
@@ -20,42 +20,26 @@
|
|
|
20
20
|
}
|
|
21
21
|
const yup__namespace = /* @__PURE__ */ _interopNamespaceDefault(yup);
|
|
22
22
|
function addNamespaceToSchema(maybeNode, namespace = []) {
|
|
23
|
-
if (typeof maybeNode
|
|
23
|
+
if (typeof maybeNode !== "object" || maybeNode === null) {
|
|
24
24
|
return maybeNode;
|
|
25
25
|
}
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
const keys = Object.keys(maybeNode);
|
|
34
|
-
Object.values(maybeNode).map((m, index) => {
|
|
35
|
-
const key = keys[index];
|
|
36
|
-
if (Array.isArray(m)) {
|
|
37
|
-
newNode[key] = m.map((element) => {
|
|
38
|
-
if (!element) {
|
|
39
|
-
return;
|
|
40
|
-
}
|
|
41
|
-
if (!element.hasOwnProperty("name")) {
|
|
42
|
-
return element;
|
|
26
|
+
const newNode = { ...maybeNode, namespace: [...namespace] };
|
|
27
|
+
Object.entries(maybeNode).forEach(([key, value]) => {
|
|
28
|
+
if (Array.isArray(value)) {
|
|
29
|
+
newNode[key] = value.map((element) => {
|
|
30
|
+
if (element && typeof element === "object" && "name" in element) {
|
|
31
|
+
const valueName = element.name || element.value;
|
|
32
|
+
return addNamespaceToSchema(element, [...namespace, valueName]);
|
|
43
33
|
}
|
|
44
|
-
|
|
45
|
-
return addNamespaceToSchema(element, [...namespace, value]);
|
|
34
|
+
return element;
|
|
46
35
|
});
|
|
36
|
+
} else if (value && typeof value === "object" && "name" in value) {
|
|
37
|
+
newNode[key] = addNamespaceToSchema(value, [...namespace, value.name]);
|
|
47
38
|
} else {
|
|
48
|
-
|
|
49
|
-
return;
|
|
50
|
-
}
|
|
51
|
-
if (!m.hasOwnProperty("name")) {
|
|
52
|
-
newNode[key] = m;
|
|
53
|
-
} else {
|
|
54
|
-
newNode[key] = addNamespaceToSchema(m, [...namespace, m.name]);
|
|
55
|
-
}
|
|
39
|
+
newNode[key] = value;
|
|
56
40
|
}
|
|
57
41
|
});
|
|
58
|
-
return
|
|
42
|
+
return newNode;
|
|
59
43
|
}
|
|
60
44
|
function getDefaultExportFromCjs(x) {
|
|
61
45
|
return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, "default") ? x["default"] : x;
|
|
@@ -2004,6 +1988,20 @@
|
|
|
2004
1988
|
field.uid = field.uid || false;
|
|
2005
1989
|
});
|
|
2006
1990
|
}
|
|
1991
|
+
findReferences(name2) {
|
|
1992
|
+
const result = {};
|
|
1993
|
+
this.walkFields(({ field, collection: c, path }) => {
|
|
1994
|
+
if (field.type === "reference") {
|
|
1995
|
+
if (field.collections.includes(name2)) {
|
|
1996
|
+
if (result[c.name] === void 0) {
|
|
1997
|
+
result[c.name] = [];
|
|
1998
|
+
}
|
|
1999
|
+
result[c.name].push({ path, field });
|
|
2000
|
+
}
|
|
2001
|
+
}
|
|
2002
|
+
});
|
|
2003
|
+
return result;
|
|
2004
|
+
}
|
|
2007
2005
|
/**
|
|
2008
2006
|
* This function returns an array of glob matches for a given collection.
|
|
2009
2007
|
*
|
|
@@ -2226,9 +2224,12 @@
|
|
|
2226
2224
|
moreInfo.push(parseZodError({ zodError: unionError }));
|
|
2227
2225
|
});
|
|
2228
2226
|
}
|
|
2229
|
-
const errorMessage =
|
|
2227
|
+
const errorMessage = `${issue == null ? void 0 : issue.message}
|
|
2228
|
+
Additional information:
|
|
2229
|
+
- Error found at path ${issue.path.join(
|
|
2230
2230
|
"."
|
|
2231
|
-
)}
|
|
2231
|
+
)}
|
|
2232
|
+
`;
|
|
2232
2233
|
const errorMessages = [errorMessage, ...moreInfo];
|
|
2233
2234
|
return {
|
|
2234
2235
|
errors: errorMessages
|
|
@@ -2263,6 +2264,9 @@ If you need to use this value in your content you can use the \`nameOverride\` p
|
|
|
2263
2264
|
});
|
|
2264
2265
|
}
|
|
2265
2266
|
});
|
|
2267
|
+
const duplicateFieldErrorMessage = (fields) => `Fields must have unique names. Found duplicate field names: [${fields}]`;
|
|
2268
|
+
const duplicateTemplateErrorMessage = (templates) => `Templates must have unique names. Found duplicate template names: [${templates}]`;
|
|
2269
|
+
const duplicateCollectionErrorMessage = (collection) => `Collections must have unique names. Found duplicate collection names: [${collection}]`;
|
|
2266
2270
|
const TypeName = [
|
|
2267
2271
|
"string",
|
|
2268
2272
|
"boolean",
|
|
@@ -2273,10 +2277,11 @@ If you need to use this value in your content you can use the \`nameOverride\` p
|
|
|
2273
2277
|
"reference",
|
|
2274
2278
|
"rich-text"
|
|
2275
2279
|
];
|
|
2276
|
-
const
|
|
2277
|
-
const
|
|
2278
|
-
|
|
2279
|
-
|
|
2280
|
+
const formattedTypes = ` - ${TypeName.join("\n - ")}`;
|
|
2281
|
+
const typeTypeError = `Invalid \`type\` property. \`type\` expected to be one of the following values:
|
|
2282
|
+
${formattedTypes}`;
|
|
2283
|
+
const typeRequiredError = `Missing \`type\` property. Please add a \`type\` property with one of the following:
|
|
2284
|
+
${formattedTypes}`;
|
|
2280
2285
|
const Option = z.z.union(
|
|
2281
2286
|
[
|
|
2282
2287
|
z.z.string(),
|
|
@@ -2362,7 +2367,7 @@ If you need to use this value in your content you can use the \`nameOverride\` p
|
|
|
2362
2367
|
if (dups) {
|
|
2363
2368
|
ctx.addIssue({
|
|
2364
2369
|
code: z.z.ZodIssueCode.custom,
|
|
2365
|
-
message:
|
|
2370
|
+
message: duplicateFieldErrorMessage(dups)
|
|
2366
2371
|
});
|
|
2367
2372
|
}
|
|
2368
2373
|
});
|
|
@@ -2372,21 +2377,21 @@ If you need to use this value in your content you can use the \`nameOverride\` p
|
|
|
2372
2377
|
invalid_type_error: typeTypeError,
|
|
2373
2378
|
required_error: typeRequiredError
|
|
2374
2379
|
}),
|
|
2375
|
-
fields: z.z.array(TinaFieldZod).min(1).optional().superRefine((val, ctx) => {
|
|
2380
|
+
fields: z.z.array(TinaFieldZod).min(1, "Property `fields` cannot be empty.").optional().superRefine((val, ctx) => {
|
|
2376
2381
|
const dups = findDuplicates(val == null ? void 0 : val.map((x) => x.name));
|
|
2377
2382
|
if (dups) {
|
|
2378
2383
|
ctx.addIssue({
|
|
2379
2384
|
code: z.z.ZodIssueCode.custom,
|
|
2380
|
-
message:
|
|
2385
|
+
message: duplicateFieldErrorMessage(dups)
|
|
2381
2386
|
});
|
|
2382
2387
|
}
|
|
2383
2388
|
}),
|
|
2384
|
-
templates: z.z.array(TemplateTemp).min(1).optional().superRefine((val, ctx) => {
|
|
2389
|
+
templates: z.z.array(TemplateTemp).min(1, "Property `templates` cannot be empty.").optional().superRefine((val, ctx) => {
|
|
2385
2390
|
const dups = findDuplicates(val == null ? void 0 : val.map((x) => x.name));
|
|
2386
2391
|
if (dups) {
|
|
2387
2392
|
ctx.addIssue({
|
|
2388
2393
|
code: z.z.ZodIssueCode.custom,
|
|
2389
|
-
message:
|
|
2394
|
+
message: duplicateTemplateErrorMessage(dups)
|
|
2390
2395
|
});
|
|
2391
2396
|
}
|
|
2392
2397
|
})
|
|
@@ -2401,7 +2406,7 @@ If you need to use this value in your content you can use the \`nameOverride\` p
|
|
|
2401
2406
|
if (dups) {
|
|
2402
2407
|
ctx.addIssue({
|
|
2403
2408
|
code: z.z.ZodIssueCode.custom,
|
|
2404
|
-
message:
|
|
2409
|
+
message: duplicateTemplateErrorMessage(dups)
|
|
2405
2410
|
});
|
|
2406
2411
|
}
|
|
2407
2412
|
})
|
|
@@ -2421,10 +2426,17 @@ If you need to use this value in your content you can use the \`nameOverride\` p
|
|
|
2421
2426
|
],
|
|
2422
2427
|
{
|
|
2423
2428
|
errorMap: (issue, ctx) => {
|
|
2424
|
-
var _a;
|
|
2429
|
+
var _a, _b;
|
|
2425
2430
|
if (issue.code === "invalid_union_discriminator") {
|
|
2431
|
+
if (!((_a = ctx.data) == null ? void 0 : _a.type)) {
|
|
2432
|
+
return {
|
|
2433
|
+
message: `Missing \`type\` property in field \`${ctx.data.name}\`. Please add a \`type\` property with one of the following:
|
|
2434
|
+
${formattedTypes}`
|
|
2435
|
+
};
|
|
2436
|
+
}
|
|
2426
2437
|
return {
|
|
2427
|
-
message: `Invalid \`type\` property. In the schema is 'type: ${(
|
|
2438
|
+
message: `Invalid \`type\` property in field \`${ctx.data.name}\`. In the schema is 'type: ${(_b = ctx.data) == null ? void 0 : _b.type}' but expected one of the following:
|
|
2439
|
+
${formattedTypes}`
|
|
2428
2440
|
};
|
|
2429
2441
|
}
|
|
2430
2442
|
return {
|
|
@@ -2434,77 +2446,52 @@ If you need to use this value in your content you can use the \`nameOverride\` p
|
|
|
2434
2446
|
}
|
|
2435
2447
|
).superRefine((val, ctx) => {
|
|
2436
2448
|
if (val.type === "string") {
|
|
2437
|
-
|
|
2438
|
-
|
|
2439
|
-
|
|
2440
|
-
|
|
2441
|
-
|
|
2442
|
-
${
|
|
2443
|
-
|
|
2444
|
-
|
|
2445
|
-
|
|
2446
|
-
|
|
2447
|
-
|
|
2448
|
-
|
|
2449
|
-
|
|
2450
|
-
|
|
2451
|
-
ctx.addIssue({
|
|
2452
|
-
code: z.z.ZodIssueCode.custom,
|
|
2453
|
-
message: `Must have { required: true } when using \`isTitle\` Error in value
|
|
2454
|
-
${JSON.stringify(
|
|
2455
|
-
val,
|
|
2456
|
-
null,
|
|
2457
|
-
2
|
|
2458
|
-
)}
|
|
2459
|
-
`
|
|
2460
|
-
});
|
|
2461
|
-
}
|
|
2449
|
+
const stringifiedField = JSON.stringify(val, null, 2);
|
|
2450
|
+
if (val.isTitle && val.list) {
|
|
2451
|
+
ctx.addIssue({
|
|
2452
|
+
code: z.z.ZodIssueCode.custom,
|
|
2453
|
+
message: `\`list: true\` is not allowed when using \`isTitle\` for fields of \`type: string\`. Error found in field:
|
|
2454
|
+
${stringifiedField}`
|
|
2455
|
+
});
|
|
2456
|
+
}
|
|
2457
|
+
if (val.isTitle && !val.required) {
|
|
2458
|
+
ctx.addIssue({
|
|
2459
|
+
code: z.z.ZodIssueCode.custom,
|
|
2460
|
+
message: `Property \`required: true\` is required when using \`isTitle\` for fields of \`type: string\`. Error found in field:
|
|
2461
|
+
${stringifiedField}`
|
|
2462
|
+
});
|
|
2462
2463
|
}
|
|
2463
|
-
if (val.uid) {
|
|
2464
|
+
if (val.uid && val.list) {
|
|
2464
2465
|
if (val.list) {
|
|
2465
2466
|
ctx.addIssue({
|
|
2466
2467
|
code: z.z.ZodIssueCode.custom,
|
|
2467
|
-
message:
|
|
2468
|
-
${
|
|
2469
|
-
val,
|
|
2470
|
-
null,
|
|
2471
|
-
2
|
|
2472
|
-
)}
|
|
2473
|
-
`
|
|
2474
|
-
});
|
|
2475
|
-
}
|
|
2476
|
-
if (!val.required) {
|
|
2477
|
-
ctx.addIssue({
|
|
2478
|
-
code: z.z.ZodIssueCode.custom,
|
|
2479
|
-
message: `Must have { required: true } when using \`uid\` Error in value
|
|
2480
|
-
${JSON.stringify(
|
|
2481
|
-
val,
|
|
2482
|
-
null,
|
|
2483
|
-
2
|
|
2484
|
-
)}
|
|
2485
|
-
`
|
|
2468
|
+
message: `\`list: true\` is not allowed when using \`uid\` for fields of \`type: string\`. Error found in field:
|
|
2469
|
+
${stringifiedField}`
|
|
2486
2470
|
});
|
|
2487
2471
|
}
|
|
2488
2472
|
}
|
|
2473
|
+
if (val.uid && !val.required) {
|
|
2474
|
+
ctx.addIssue({
|
|
2475
|
+
code: z.z.ZodIssueCode.custom,
|
|
2476
|
+
message: `Property \`required: true\` is required when using \`uid\` for fields of \`type: string\`. Error found in field:
|
|
2477
|
+
${stringifiedField}`
|
|
2478
|
+
});
|
|
2479
|
+
}
|
|
2489
2480
|
}
|
|
2490
2481
|
if (val.type === "object") {
|
|
2491
|
-
|
|
2492
|
-
let isValid = Boolean(val == null ? void 0 : val.templates) || Boolean(val == null ? void 0 : val.fields);
|
|
2493
|
-
if (!isValid) {
|
|
2482
|
+
if (!(val == null ? void 0 : val.templates) && !(val == null ? void 0 : val.fields)) {
|
|
2494
2483
|
ctx.addIssue({
|
|
2495
2484
|
code: z.z.ZodIssueCode.custom,
|
|
2496
|
-
message
|
|
2485
|
+
message: "Fields of `type: object` must have either `templates` or `fields` property."
|
|
2486
|
+
});
|
|
2487
|
+
return false;
|
|
2488
|
+
}
|
|
2489
|
+
if ((val == null ? void 0 : val.templates) && (val == null ? void 0 : val.fields)) {
|
|
2490
|
+
ctx.addIssue({
|
|
2491
|
+
code: z.z.ZodIssueCode.custom,
|
|
2492
|
+
message: "Fields of `type: object` must have either `templates` or `fields` property, not both."
|
|
2497
2493
|
});
|
|
2498
2494
|
return false;
|
|
2499
|
-
} else {
|
|
2500
|
-
isValid = !((val == null ? void 0 : val.templates) && (val == null ? void 0 : val.fields));
|
|
2501
|
-
if (!isValid) {
|
|
2502
|
-
ctx.addIssue({
|
|
2503
|
-
code: z.z.ZodIssueCode.custom,
|
|
2504
|
-
message
|
|
2505
|
-
});
|
|
2506
|
-
}
|
|
2507
|
-
return isValid;
|
|
2508
2495
|
}
|
|
2509
2496
|
}
|
|
2510
2497
|
return true;
|
|
@@ -2548,8 +2535,8 @@ ${JSON.stringify(
|
|
|
2548
2535
|
];
|
|
2549
2536
|
const Template = z.z.object({
|
|
2550
2537
|
label: z.z.string({
|
|
2551
|
-
invalid_type_error: "label
|
|
2552
|
-
required_error: "label
|
|
2538
|
+
invalid_type_error: "Invalid data type for property `label`. Must be of type `string`",
|
|
2539
|
+
required_error: "Missing `label` property. Property `label` is required."
|
|
2553
2540
|
}),
|
|
2554
2541
|
name,
|
|
2555
2542
|
fields: z.z.array(TinaFieldZod)
|
|
@@ -2559,7 +2546,7 @@ ${JSON.stringify(
|
|
|
2559
2546
|
if (dups) {
|
|
2560
2547
|
ctx.addIssue({
|
|
2561
2548
|
code: z.z.ZodIssueCode.custom,
|
|
2562
|
-
message:
|
|
2549
|
+
message: duplicateFieldErrorMessage(dups)
|
|
2563
2550
|
});
|
|
2564
2551
|
}
|
|
2565
2552
|
});
|
|
@@ -2569,7 +2556,7 @@ ${JSON.stringify(
|
|
|
2569
2556
|
if (val === "relativePath") {
|
|
2570
2557
|
ctx.addIssue({
|
|
2571
2558
|
code: z.z.ZodIssueCode.custom,
|
|
2572
|
-
message: `name cannot be 'relativePath'
|
|
2559
|
+
message: "Invalid `name` property. `name` cannot be 'relativePath' as it is a reserved field name."
|
|
2573
2560
|
});
|
|
2574
2561
|
}
|
|
2575
2562
|
}),
|
|
@@ -2577,7 +2564,7 @@ ${JSON.stringify(
|
|
|
2577
2564
|
if (val === ".") {
|
|
2578
2565
|
ctx.addIssue({
|
|
2579
2566
|
code: z.z.ZodIssueCode.custom,
|
|
2580
|
-
message: `path cannot be '.'. Please use '/' or '' instead.
|
|
2567
|
+
message: "Invalid `path` property. `path` cannot be '.'. Please use '/' or '' instead."
|
|
2581
2568
|
});
|
|
2582
2569
|
}
|
|
2583
2570
|
}),
|
|
@@ -2586,63 +2573,64 @@ ${JSON.stringify(
|
|
|
2586
2573
|
isDetached: z.z.boolean().optional()
|
|
2587
2574
|
});
|
|
2588
2575
|
const TinaCloudCollection = CollectionBaseSchema.extend({
|
|
2589
|
-
fields: z.z.array(TinaFieldZod).min(1).optional().superRefine((val, ctx) => {
|
|
2576
|
+
fields: z.z.array(TinaFieldZod).min(1, "Property `fields` cannot be empty.").optional().superRefine((val, ctx) => {
|
|
2590
2577
|
const dups = findDuplicates(val == null ? void 0 : val.map((x) => x.name));
|
|
2591
2578
|
if (dups) {
|
|
2592
2579
|
ctx.addIssue({
|
|
2593
2580
|
code: z.z.ZodIssueCode.custom,
|
|
2594
|
-
message:
|
|
2581
|
+
message: duplicateFieldErrorMessage(dups)
|
|
2595
2582
|
});
|
|
2596
2583
|
}
|
|
2597
|
-
}).
|
|
2598
|
-
|
|
2599
|
-
(
|
|
2600
|
-
|
|
2601
|
-
|
|
2602
|
-
|
|
2603
|
-
|
|
2604
|
-
message: "Fields can only have one use of `isTitle`"
|
|
2605
|
-
}
|
|
2606
|
-
).refine(
|
|
2607
|
-
// It is valid if it is 0 or 1
|
|
2608
|
-
(val) => {
|
|
2609
|
-
const arr = (val == null ? void 0 : val.filter((x) => x.uid)) || [];
|
|
2610
|
-
return arr.length < 2;
|
|
2611
|
-
},
|
|
2612
|
-
{
|
|
2613
|
-
message: "Fields can only have one use of `uid`"
|
|
2614
|
-
}
|
|
2615
|
-
).refine(
|
|
2616
|
-
// It is valid if it is 0 or 1
|
|
2617
|
-
(val) => {
|
|
2618
|
-
const arr = (val == null ? void 0 : val.filter((x) => x.type === "password")) || [];
|
|
2619
|
-
return arr.length < 2;
|
|
2620
|
-
},
|
|
2621
|
-
{
|
|
2622
|
-
message: "Fields can only have one use of `password` type"
|
|
2584
|
+
}).superRefine((val, ctx) => {
|
|
2585
|
+
const arr = (val == null ? void 0 : val.filter((x) => x.type === "string" && x.isTitle)) || [];
|
|
2586
|
+
if (arr.length > 1) {
|
|
2587
|
+
ctx.addIssue({
|
|
2588
|
+
code: z.z.ZodIssueCode.custom,
|
|
2589
|
+
message: `The following fields have the property \`isTitle\`: [${arr.map((field) => field.name).join(", ")}]. Only one can contain the property \`isTitle\`.`
|
|
2590
|
+
});
|
|
2623
2591
|
}
|
|
2624
|
-
),
|
|
2625
|
-
|
|
2592
|
+
}).superRefine((val, ctx) => {
|
|
2593
|
+
const arr = (val == null ? void 0 : val.filter((x) => x.uid)) || [];
|
|
2594
|
+
if (arr.length > 2) {
|
|
2595
|
+
ctx.addIssue({
|
|
2596
|
+
code: z.z.ZodIssueCode.custom,
|
|
2597
|
+
message: `The following fields have the property \`uid\`: [${arr.map((field) => field.name).join(", ")}]. Only one can contain the property \`uid\`.`
|
|
2598
|
+
});
|
|
2599
|
+
}
|
|
2600
|
+
}).superRefine((val, ctx) => {
|
|
2601
|
+
const arr = (val == null ? void 0 : val.filter((x) => x.type === "password")) || [];
|
|
2602
|
+
if (arr.length > 2) {
|
|
2603
|
+
ctx.addIssue({
|
|
2604
|
+
code: z.z.ZodIssueCode.custom,
|
|
2605
|
+
message: `The following fields have \`type: password\`: [${arr.map((field) => field.name).join(", ")}]. Only one can be of \`type: password\`.`
|
|
2606
|
+
});
|
|
2607
|
+
}
|
|
2608
|
+
}),
|
|
2609
|
+
templates: z.z.array(Template).min(1, "Property `templates` cannot be empty.").optional().superRefine((val, ctx) => {
|
|
2626
2610
|
const dups = findDuplicates(val == null ? void 0 : val.map((x) => x.name));
|
|
2627
2611
|
if (dups) {
|
|
2628
2612
|
ctx.addIssue({
|
|
2629
2613
|
code: z.z.ZodIssueCode.custom,
|
|
2630
|
-
message:
|
|
2614
|
+
message: duplicateFieldErrorMessage(dups)
|
|
2631
2615
|
});
|
|
2632
2616
|
}
|
|
2633
2617
|
})
|
|
2634
|
-
}).
|
|
2635
|
-
(val)
|
|
2636
|
-
|
|
2637
|
-
|
|
2638
|
-
|
|
2639
|
-
}
|
|
2640
|
-
|
|
2641
|
-
|
|
2642
|
-
|
|
2643
|
-
|
|
2644
|
-
|
|
2645
|
-
|
|
2618
|
+
}).superRefine((val, ctx) => {
|
|
2619
|
+
if (!(val == null ? void 0 : val.templates) && !(val == null ? void 0 : val.fields)) {
|
|
2620
|
+
ctx.addIssue({
|
|
2621
|
+
code: z.z.ZodIssueCode.custom,
|
|
2622
|
+
message: "Fields of `type: object` must have either `templates` or `fields` property."
|
|
2623
|
+
});
|
|
2624
|
+
return false;
|
|
2625
|
+
}
|
|
2626
|
+
if ((val == null ? void 0 : val.templates) && (val == null ? void 0 : val.fields)) {
|
|
2627
|
+
ctx.addIssue({
|
|
2628
|
+
code: z.z.ZodIssueCode.custom,
|
|
2629
|
+
message: "Fields of `type: object` must have either `templates` or `fields` property, not both."
|
|
2630
|
+
});
|
|
2631
|
+
return false;
|
|
2632
|
+
}
|
|
2633
|
+
});
|
|
2646
2634
|
const TinaCloudSchemaZod = z.z.object({
|
|
2647
2635
|
collections: z.z.array(TinaCloudCollection),
|
|
2648
2636
|
config: tinaConfigZod.optional()
|
|
@@ -2652,14 +2640,14 @@ ${JSON.stringify(
|
|
|
2652
2640
|
if (dups) {
|
|
2653
2641
|
ctx.addIssue({
|
|
2654
2642
|
code: z.z.ZodIssueCode.custom,
|
|
2655
|
-
message:
|
|
2643
|
+
message: duplicateCollectionErrorMessage(dups),
|
|
2656
2644
|
fatal: true
|
|
2657
2645
|
});
|
|
2658
2646
|
}
|
|
2659
2647
|
if (((_b = val.collections) == null ? void 0 : _b.filter((x) => x.isAuthCollection).length) > 1) {
|
|
2660
2648
|
ctx.addIssue({
|
|
2661
2649
|
code: z.z.ZodIssueCode.custom,
|
|
2662
|
-
message:
|
|
2650
|
+
message: "Only one collection can be marked as `isAuthCollection`.",
|
|
2663
2651
|
fatal: true
|
|
2664
2652
|
});
|
|
2665
2653
|
}
|
|
@@ -2667,7 +2655,7 @@ ${JSON.stringify(
|
|
|
2667
2655
|
if (media && media.tina && media.loadCustomStore) {
|
|
2668
2656
|
ctx.addIssue({
|
|
2669
2657
|
code: z.z.ZodIssueCode.custom,
|
|
2670
|
-
message: "
|
|
2658
|
+
message: "Cannot have both `loadCustomStore` and `tina`. Must use one or the other.",
|
|
2671
2659
|
fatal: true,
|
|
2672
2660
|
path: ["config", "media"]
|
|
2673
2661
|
});
|
|
@@ -2676,7 +2664,7 @@ ${JSON.stringify(
|
|
|
2676
2664
|
if (search && search.tina && search.searchClient) {
|
|
2677
2665
|
ctx.addIssue({
|
|
2678
2666
|
code: z.z.ZodIssueCode.custom,
|
|
2679
|
-
message: "
|
|
2667
|
+
message: "Cannot have both `searchClient` and `tina`. Must use one or the other.",
|
|
2680
2668
|
fatal: true,
|
|
2681
2669
|
path: ["config", "search"]
|
|
2682
2670
|
});
|
|
@@ -2694,7 +2682,7 @@ ${JSON.stringify(
|
|
|
2694
2682
|
} catch (e) {
|
|
2695
2683
|
if (e instanceof z.ZodError) {
|
|
2696
2684
|
const errors = parseZodError({ zodError: e });
|
|
2697
|
-
throw new TinaSchemaValidationError(errors.join("
|
|
2685
|
+
throw new TinaSchemaValidationError(errors.join("\n"));
|
|
2698
2686
|
}
|
|
2699
2687
|
throw new Error(e);
|
|
2700
2688
|
}
|
package/dist/index.mjs
CHANGED
|
@@ -2,42 +2,26 @@ import * as yup from "yup";
|
|
|
2
2
|
import UrlPattern from "url-pattern";
|
|
3
3
|
import z$1, { z, ZodError } from "zod";
|
|
4
4
|
function addNamespaceToSchema(maybeNode, namespace = []) {
|
|
5
|
-
if (typeof maybeNode
|
|
5
|
+
if (typeof maybeNode !== "object" || maybeNode === null) {
|
|
6
6
|
return maybeNode;
|
|
7
7
|
}
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
const keys = Object.keys(maybeNode);
|
|
16
|
-
Object.values(maybeNode).map((m, index) => {
|
|
17
|
-
const key = keys[index];
|
|
18
|
-
if (Array.isArray(m)) {
|
|
19
|
-
newNode[key] = m.map((element) => {
|
|
20
|
-
if (!element) {
|
|
21
|
-
return;
|
|
22
|
-
}
|
|
23
|
-
if (!element.hasOwnProperty("name")) {
|
|
24
|
-
return element;
|
|
8
|
+
const newNode = { ...maybeNode, namespace: [...namespace] };
|
|
9
|
+
Object.entries(maybeNode).forEach(([key, value]) => {
|
|
10
|
+
if (Array.isArray(value)) {
|
|
11
|
+
newNode[key] = value.map((element) => {
|
|
12
|
+
if (element && typeof element === "object" && "name" in element) {
|
|
13
|
+
const valueName = element.name || element.value;
|
|
14
|
+
return addNamespaceToSchema(element, [...namespace, valueName]);
|
|
25
15
|
}
|
|
26
|
-
|
|
27
|
-
return addNamespaceToSchema(element, [...namespace, value]);
|
|
16
|
+
return element;
|
|
28
17
|
});
|
|
18
|
+
} else if (value && typeof value === "object" && "name" in value) {
|
|
19
|
+
newNode[key] = addNamespaceToSchema(value, [...namespace, value.name]);
|
|
29
20
|
} else {
|
|
30
|
-
|
|
31
|
-
return;
|
|
32
|
-
}
|
|
33
|
-
if (!m.hasOwnProperty("name")) {
|
|
34
|
-
newNode[key] = m;
|
|
35
|
-
} else {
|
|
36
|
-
newNode[key] = addNamespaceToSchema(m, [...namespace, m.name]);
|
|
37
|
-
}
|
|
21
|
+
newNode[key] = value;
|
|
38
22
|
}
|
|
39
23
|
});
|
|
40
|
-
return
|
|
24
|
+
return newNode;
|
|
41
25
|
}
|
|
42
26
|
function getDefaultExportFromCjs(x) {
|
|
43
27
|
return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, "default") ? x["default"] : x;
|
|
@@ -1986,6 +1970,20 @@ class TinaSchema {
|
|
|
1986
1970
|
field.uid = field.uid || false;
|
|
1987
1971
|
});
|
|
1988
1972
|
}
|
|
1973
|
+
findReferences(name2) {
|
|
1974
|
+
const result = {};
|
|
1975
|
+
this.walkFields(({ field, collection: c, path }) => {
|
|
1976
|
+
if (field.type === "reference") {
|
|
1977
|
+
if (field.collections.includes(name2)) {
|
|
1978
|
+
if (result[c.name] === void 0) {
|
|
1979
|
+
result[c.name] = [];
|
|
1980
|
+
}
|
|
1981
|
+
result[c.name].push({ path, field });
|
|
1982
|
+
}
|
|
1983
|
+
}
|
|
1984
|
+
});
|
|
1985
|
+
return result;
|
|
1986
|
+
}
|
|
1989
1987
|
/**
|
|
1990
1988
|
* This function returns an array of glob matches for a given collection.
|
|
1991
1989
|
*
|
|
@@ -2208,9 +2206,12 @@ const parseZodError = ({ zodError }) => {
|
|
|
2208
2206
|
moreInfo.push(parseZodError({ zodError: unionError }));
|
|
2209
2207
|
});
|
|
2210
2208
|
}
|
|
2211
|
-
const errorMessage =
|
|
2209
|
+
const errorMessage = `${issue == null ? void 0 : issue.message}
|
|
2210
|
+
Additional information:
|
|
2211
|
+
- Error found at path ${issue.path.join(
|
|
2212
2212
|
"."
|
|
2213
|
-
)}
|
|
2213
|
+
)}
|
|
2214
|
+
`;
|
|
2214
2215
|
const errorMessages = [errorMessage, ...moreInfo];
|
|
2215
2216
|
return {
|
|
2216
2217
|
errors: errorMessages
|
|
@@ -2245,6 +2246,9 @@ If you need to use this value in your content you can use the \`nameOverride\` p
|
|
|
2245
2246
|
});
|
|
2246
2247
|
}
|
|
2247
2248
|
});
|
|
2249
|
+
const duplicateFieldErrorMessage = (fields) => `Fields must have unique names. Found duplicate field names: [${fields}]`;
|
|
2250
|
+
const duplicateTemplateErrorMessage = (templates) => `Templates must have unique names. Found duplicate template names: [${templates}]`;
|
|
2251
|
+
const duplicateCollectionErrorMessage = (collection) => `Collections must have unique names. Found duplicate collection names: [${collection}]`;
|
|
2248
2252
|
const TypeName = [
|
|
2249
2253
|
"string",
|
|
2250
2254
|
"boolean",
|
|
@@ -2255,10 +2259,11 @@ const TypeName = [
|
|
|
2255
2259
|
"reference",
|
|
2256
2260
|
"rich-text"
|
|
2257
2261
|
];
|
|
2258
|
-
const
|
|
2259
|
-
const
|
|
2260
|
-
|
|
2261
|
-
|
|
2262
|
+
const formattedTypes = ` - ${TypeName.join("\n - ")}`;
|
|
2263
|
+
const typeTypeError = `Invalid \`type\` property. \`type\` expected to be one of the following values:
|
|
2264
|
+
${formattedTypes}`;
|
|
2265
|
+
const typeRequiredError = `Missing \`type\` property. Please add a \`type\` property with one of the following:
|
|
2266
|
+
${formattedTypes}`;
|
|
2262
2267
|
const Option = z.union(
|
|
2263
2268
|
[
|
|
2264
2269
|
z.string(),
|
|
@@ -2344,7 +2349,7 @@ const TinaFieldZod = z.lazy(() => {
|
|
|
2344
2349
|
if (dups) {
|
|
2345
2350
|
ctx.addIssue({
|
|
2346
2351
|
code: z.ZodIssueCode.custom,
|
|
2347
|
-
message:
|
|
2352
|
+
message: duplicateFieldErrorMessage(dups)
|
|
2348
2353
|
});
|
|
2349
2354
|
}
|
|
2350
2355
|
});
|
|
@@ -2354,21 +2359,21 @@ const TinaFieldZod = z.lazy(() => {
|
|
|
2354
2359
|
invalid_type_error: typeTypeError,
|
|
2355
2360
|
required_error: typeRequiredError
|
|
2356
2361
|
}),
|
|
2357
|
-
fields: z.array(TinaFieldZod).min(1).optional().superRefine((val, ctx) => {
|
|
2362
|
+
fields: z.array(TinaFieldZod).min(1, "Property `fields` cannot be empty.").optional().superRefine((val, ctx) => {
|
|
2358
2363
|
const dups = findDuplicates(val == null ? void 0 : val.map((x) => x.name));
|
|
2359
2364
|
if (dups) {
|
|
2360
2365
|
ctx.addIssue({
|
|
2361
2366
|
code: z.ZodIssueCode.custom,
|
|
2362
|
-
message:
|
|
2367
|
+
message: duplicateFieldErrorMessage(dups)
|
|
2363
2368
|
});
|
|
2364
2369
|
}
|
|
2365
2370
|
}),
|
|
2366
|
-
templates: z.array(TemplateTemp).min(1).optional().superRefine((val, ctx) => {
|
|
2371
|
+
templates: z.array(TemplateTemp).min(1, "Property `templates` cannot be empty.").optional().superRefine((val, ctx) => {
|
|
2367
2372
|
const dups = findDuplicates(val == null ? void 0 : val.map((x) => x.name));
|
|
2368
2373
|
if (dups) {
|
|
2369
2374
|
ctx.addIssue({
|
|
2370
2375
|
code: z.ZodIssueCode.custom,
|
|
2371
|
-
message:
|
|
2376
|
+
message: duplicateTemplateErrorMessage(dups)
|
|
2372
2377
|
});
|
|
2373
2378
|
}
|
|
2374
2379
|
})
|
|
@@ -2383,7 +2388,7 @@ const TinaFieldZod = z.lazy(() => {
|
|
|
2383
2388
|
if (dups) {
|
|
2384
2389
|
ctx.addIssue({
|
|
2385
2390
|
code: z.ZodIssueCode.custom,
|
|
2386
|
-
message:
|
|
2391
|
+
message: duplicateTemplateErrorMessage(dups)
|
|
2387
2392
|
});
|
|
2388
2393
|
}
|
|
2389
2394
|
})
|
|
@@ -2403,10 +2408,17 @@ const TinaFieldZod = z.lazy(() => {
|
|
|
2403
2408
|
],
|
|
2404
2409
|
{
|
|
2405
2410
|
errorMap: (issue, ctx) => {
|
|
2406
|
-
var _a;
|
|
2411
|
+
var _a, _b;
|
|
2407
2412
|
if (issue.code === "invalid_union_discriminator") {
|
|
2413
|
+
if (!((_a = ctx.data) == null ? void 0 : _a.type)) {
|
|
2414
|
+
return {
|
|
2415
|
+
message: `Missing \`type\` property in field \`${ctx.data.name}\`. Please add a \`type\` property with one of the following:
|
|
2416
|
+
${formattedTypes}`
|
|
2417
|
+
};
|
|
2418
|
+
}
|
|
2408
2419
|
return {
|
|
2409
|
-
message: `Invalid \`type\` property. In the schema is 'type: ${(
|
|
2420
|
+
message: `Invalid \`type\` property in field \`${ctx.data.name}\`. In the schema is 'type: ${(_b = ctx.data) == null ? void 0 : _b.type}' but expected one of the following:
|
|
2421
|
+
${formattedTypes}`
|
|
2410
2422
|
};
|
|
2411
2423
|
}
|
|
2412
2424
|
return {
|
|
@@ -2416,77 +2428,52 @@ const TinaFieldZod = z.lazy(() => {
|
|
|
2416
2428
|
}
|
|
2417
2429
|
).superRefine((val, ctx) => {
|
|
2418
2430
|
if (val.type === "string") {
|
|
2419
|
-
|
|
2420
|
-
|
|
2421
|
-
|
|
2422
|
-
|
|
2423
|
-
|
|
2424
|
-
${
|
|
2425
|
-
|
|
2426
|
-
|
|
2427
|
-
|
|
2428
|
-
|
|
2429
|
-
|
|
2430
|
-
|
|
2431
|
-
|
|
2432
|
-
|
|
2433
|
-
ctx.addIssue({
|
|
2434
|
-
code: z.ZodIssueCode.custom,
|
|
2435
|
-
message: `Must have { required: true } when using \`isTitle\` Error in value
|
|
2436
|
-
${JSON.stringify(
|
|
2437
|
-
val,
|
|
2438
|
-
null,
|
|
2439
|
-
2
|
|
2440
|
-
)}
|
|
2441
|
-
`
|
|
2442
|
-
});
|
|
2443
|
-
}
|
|
2431
|
+
const stringifiedField = JSON.stringify(val, null, 2);
|
|
2432
|
+
if (val.isTitle && val.list) {
|
|
2433
|
+
ctx.addIssue({
|
|
2434
|
+
code: z.ZodIssueCode.custom,
|
|
2435
|
+
message: `\`list: true\` is not allowed when using \`isTitle\` for fields of \`type: string\`. Error found in field:
|
|
2436
|
+
${stringifiedField}`
|
|
2437
|
+
});
|
|
2438
|
+
}
|
|
2439
|
+
if (val.isTitle && !val.required) {
|
|
2440
|
+
ctx.addIssue({
|
|
2441
|
+
code: z.ZodIssueCode.custom,
|
|
2442
|
+
message: `Property \`required: true\` is required when using \`isTitle\` for fields of \`type: string\`. Error found in field:
|
|
2443
|
+
${stringifiedField}`
|
|
2444
|
+
});
|
|
2444
2445
|
}
|
|
2445
|
-
if (val.uid) {
|
|
2446
|
+
if (val.uid && val.list) {
|
|
2446
2447
|
if (val.list) {
|
|
2447
2448
|
ctx.addIssue({
|
|
2448
2449
|
code: z.ZodIssueCode.custom,
|
|
2449
|
-
message:
|
|
2450
|
-
${
|
|
2451
|
-
val,
|
|
2452
|
-
null,
|
|
2453
|
-
2
|
|
2454
|
-
)}
|
|
2455
|
-
`
|
|
2456
|
-
});
|
|
2457
|
-
}
|
|
2458
|
-
if (!val.required) {
|
|
2459
|
-
ctx.addIssue({
|
|
2460
|
-
code: z.ZodIssueCode.custom,
|
|
2461
|
-
message: `Must have { required: true } when using \`uid\` Error in value
|
|
2462
|
-
${JSON.stringify(
|
|
2463
|
-
val,
|
|
2464
|
-
null,
|
|
2465
|
-
2
|
|
2466
|
-
)}
|
|
2467
|
-
`
|
|
2450
|
+
message: `\`list: true\` is not allowed when using \`uid\` for fields of \`type: string\`. Error found in field:
|
|
2451
|
+
${stringifiedField}`
|
|
2468
2452
|
});
|
|
2469
2453
|
}
|
|
2470
2454
|
}
|
|
2455
|
+
if (val.uid && !val.required) {
|
|
2456
|
+
ctx.addIssue({
|
|
2457
|
+
code: z.ZodIssueCode.custom,
|
|
2458
|
+
message: `Property \`required: true\` is required when using \`uid\` for fields of \`type: string\`. Error found in field:
|
|
2459
|
+
${stringifiedField}`
|
|
2460
|
+
});
|
|
2461
|
+
}
|
|
2471
2462
|
}
|
|
2472
2463
|
if (val.type === "object") {
|
|
2473
|
-
|
|
2474
|
-
let isValid = Boolean(val == null ? void 0 : val.templates) || Boolean(val == null ? void 0 : val.fields);
|
|
2475
|
-
if (!isValid) {
|
|
2464
|
+
if (!(val == null ? void 0 : val.templates) && !(val == null ? void 0 : val.fields)) {
|
|
2476
2465
|
ctx.addIssue({
|
|
2477
2466
|
code: z.ZodIssueCode.custom,
|
|
2478
|
-
message
|
|
2467
|
+
message: "Fields of `type: object` must have either `templates` or `fields` property."
|
|
2468
|
+
});
|
|
2469
|
+
return false;
|
|
2470
|
+
}
|
|
2471
|
+
if ((val == null ? void 0 : val.templates) && (val == null ? void 0 : val.fields)) {
|
|
2472
|
+
ctx.addIssue({
|
|
2473
|
+
code: z.ZodIssueCode.custom,
|
|
2474
|
+
message: "Fields of `type: object` must have either `templates` or `fields` property, not both."
|
|
2479
2475
|
});
|
|
2480
2476
|
return false;
|
|
2481
|
-
} else {
|
|
2482
|
-
isValid = !((val == null ? void 0 : val.templates) && (val == null ? void 0 : val.fields));
|
|
2483
|
-
if (!isValid) {
|
|
2484
|
-
ctx.addIssue({
|
|
2485
|
-
code: z.ZodIssueCode.custom,
|
|
2486
|
-
message
|
|
2487
|
-
});
|
|
2488
|
-
}
|
|
2489
|
-
return isValid;
|
|
2490
2477
|
}
|
|
2491
2478
|
}
|
|
2492
2479
|
return true;
|
|
@@ -2530,8 +2517,8 @@ const FORMATS = [
|
|
|
2530
2517
|
];
|
|
2531
2518
|
const Template = z.object({
|
|
2532
2519
|
label: z.string({
|
|
2533
|
-
invalid_type_error: "label
|
|
2534
|
-
required_error: "label
|
|
2520
|
+
invalid_type_error: "Invalid data type for property `label`. Must be of type `string`",
|
|
2521
|
+
required_error: "Missing `label` property. Property `label` is required."
|
|
2535
2522
|
}),
|
|
2536
2523
|
name,
|
|
2537
2524
|
fields: z.array(TinaFieldZod)
|
|
@@ -2541,7 +2528,7 @@ const Template = z.object({
|
|
|
2541
2528
|
if (dups) {
|
|
2542
2529
|
ctx.addIssue({
|
|
2543
2530
|
code: z.ZodIssueCode.custom,
|
|
2544
|
-
message:
|
|
2531
|
+
message: duplicateFieldErrorMessage(dups)
|
|
2545
2532
|
});
|
|
2546
2533
|
}
|
|
2547
2534
|
});
|
|
@@ -2551,7 +2538,7 @@ const CollectionBaseSchema = z.object({
|
|
|
2551
2538
|
if (val === "relativePath") {
|
|
2552
2539
|
ctx.addIssue({
|
|
2553
2540
|
code: z.ZodIssueCode.custom,
|
|
2554
|
-
message: `name cannot be 'relativePath'
|
|
2541
|
+
message: "Invalid `name` property. `name` cannot be 'relativePath' as it is a reserved field name."
|
|
2555
2542
|
});
|
|
2556
2543
|
}
|
|
2557
2544
|
}),
|
|
@@ -2559,7 +2546,7 @@ const CollectionBaseSchema = z.object({
|
|
|
2559
2546
|
if (val === ".") {
|
|
2560
2547
|
ctx.addIssue({
|
|
2561
2548
|
code: z.ZodIssueCode.custom,
|
|
2562
|
-
message: `path cannot be '.'. Please use '/' or '' instead.
|
|
2549
|
+
message: "Invalid `path` property. `path` cannot be '.'. Please use '/' or '' instead."
|
|
2563
2550
|
});
|
|
2564
2551
|
}
|
|
2565
2552
|
}),
|
|
@@ -2568,63 +2555,64 @@ const CollectionBaseSchema = z.object({
|
|
|
2568
2555
|
isDetached: z.boolean().optional()
|
|
2569
2556
|
});
|
|
2570
2557
|
const TinaCloudCollection = CollectionBaseSchema.extend({
|
|
2571
|
-
fields: z.array(TinaFieldZod).min(1).optional().superRefine((val, ctx) => {
|
|
2558
|
+
fields: z.array(TinaFieldZod).min(1, "Property `fields` cannot be empty.").optional().superRefine((val, ctx) => {
|
|
2572
2559
|
const dups = findDuplicates(val == null ? void 0 : val.map((x) => x.name));
|
|
2573
2560
|
if (dups) {
|
|
2574
2561
|
ctx.addIssue({
|
|
2575
2562
|
code: z.ZodIssueCode.custom,
|
|
2576
|
-
message:
|
|
2563
|
+
message: duplicateFieldErrorMessage(dups)
|
|
2577
2564
|
});
|
|
2578
2565
|
}
|
|
2579
|
-
}).
|
|
2580
|
-
|
|
2581
|
-
(
|
|
2582
|
-
|
|
2583
|
-
|
|
2584
|
-
|
|
2585
|
-
|
|
2586
|
-
message: "Fields can only have one use of `isTitle`"
|
|
2587
|
-
}
|
|
2588
|
-
).refine(
|
|
2589
|
-
// It is valid if it is 0 or 1
|
|
2590
|
-
(val) => {
|
|
2591
|
-
const arr = (val == null ? void 0 : val.filter((x) => x.uid)) || [];
|
|
2592
|
-
return arr.length < 2;
|
|
2593
|
-
},
|
|
2594
|
-
{
|
|
2595
|
-
message: "Fields can only have one use of `uid`"
|
|
2596
|
-
}
|
|
2597
|
-
).refine(
|
|
2598
|
-
// It is valid if it is 0 or 1
|
|
2599
|
-
(val) => {
|
|
2600
|
-
const arr = (val == null ? void 0 : val.filter((x) => x.type === "password")) || [];
|
|
2601
|
-
return arr.length < 2;
|
|
2602
|
-
},
|
|
2603
|
-
{
|
|
2604
|
-
message: "Fields can only have one use of `password` type"
|
|
2566
|
+
}).superRefine((val, ctx) => {
|
|
2567
|
+
const arr = (val == null ? void 0 : val.filter((x) => x.type === "string" && x.isTitle)) || [];
|
|
2568
|
+
if (arr.length > 1) {
|
|
2569
|
+
ctx.addIssue({
|
|
2570
|
+
code: z.ZodIssueCode.custom,
|
|
2571
|
+
message: `The following fields have the property \`isTitle\`: [${arr.map((field) => field.name).join(", ")}]. Only one can contain the property \`isTitle\`.`
|
|
2572
|
+
});
|
|
2605
2573
|
}
|
|
2606
|
-
),
|
|
2607
|
-
|
|
2574
|
+
}).superRefine((val, ctx) => {
|
|
2575
|
+
const arr = (val == null ? void 0 : val.filter((x) => x.uid)) || [];
|
|
2576
|
+
if (arr.length > 2) {
|
|
2577
|
+
ctx.addIssue({
|
|
2578
|
+
code: z.ZodIssueCode.custom,
|
|
2579
|
+
message: `The following fields have the property \`uid\`: [${arr.map((field) => field.name).join(", ")}]. Only one can contain the property \`uid\`.`
|
|
2580
|
+
});
|
|
2581
|
+
}
|
|
2582
|
+
}).superRefine((val, ctx) => {
|
|
2583
|
+
const arr = (val == null ? void 0 : val.filter((x) => x.type === "password")) || [];
|
|
2584
|
+
if (arr.length > 2) {
|
|
2585
|
+
ctx.addIssue({
|
|
2586
|
+
code: z.ZodIssueCode.custom,
|
|
2587
|
+
message: `The following fields have \`type: password\`: [${arr.map((field) => field.name).join(", ")}]. Only one can be of \`type: password\`.`
|
|
2588
|
+
});
|
|
2589
|
+
}
|
|
2590
|
+
}),
|
|
2591
|
+
templates: z.array(Template).min(1, "Property `templates` cannot be empty.").optional().superRefine((val, ctx) => {
|
|
2608
2592
|
const dups = findDuplicates(val == null ? void 0 : val.map((x) => x.name));
|
|
2609
2593
|
if (dups) {
|
|
2610
2594
|
ctx.addIssue({
|
|
2611
2595
|
code: z.ZodIssueCode.custom,
|
|
2612
|
-
message:
|
|
2596
|
+
message: duplicateFieldErrorMessage(dups)
|
|
2613
2597
|
});
|
|
2614
2598
|
}
|
|
2615
2599
|
})
|
|
2616
|
-
}).
|
|
2617
|
-
(val)
|
|
2618
|
-
|
|
2619
|
-
|
|
2620
|
-
|
|
2621
|
-
}
|
|
2622
|
-
|
|
2623
|
-
|
|
2624
|
-
|
|
2625
|
-
|
|
2626
|
-
|
|
2627
|
-
|
|
2600
|
+
}).superRefine((val, ctx) => {
|
|
2601
|
+
if (!(val == null ? void 0 : val.templates) && !(val == null ? void 0 : val.fields)) {
|
|
2602
|
+
ctx.addIssue({
|
|
2603
|
+
code: z.ZodIssueCode.custom,
|
|
2604
|
+
message: "Fields of `type: object` must have either `templates` or `fields` property."
|
|
2605
|
+
});
|
|
2606
|
+
return false;
|
|
2607
|
+
}
|
|
2608
|
+
if ((val == null ? void 0 : val.templates) && (val == null ? void 0 : val.fields)) {
|
|
2609
|
+
ctx.addIssue({
|
|
2610
|
+
code: z.ZodIssueCode.custom,
|
|
2611
|
+
message: "Fields of `type: object` must have either `templates` or `fields` property, not both."
|
|
2612
|
+
});
|
|
2613
|
+
return false;
|
|
2614
|
+
}
|
|
2615
|
+
});
|
|
2628
2616
|
const TinaCloudSchemaZod = z.object({
|
|
2629
2617
|
collections: z.array(TinaCloudCollection),
|
|
2630
2618
|
config: tinaConfigZod.optional()
|
|
@@ -2634,14 +2622,14 @@ const TinaCloudSchemaZod = z.object({
|
|
|
2634
2622
|
if (dups) {
|
|
2635
2623
|
ctx.addIssue({
|
|
2636
2624
|
code: z.ZodIssueCode.custom,
|
|
2637
|
-
message:
|
|
2625
|
+
message: duplicateCollectionErrorMessage(dups),
|
|
2638
2626
|
fatal: true
|
|
2639
2627
|
});
|
|
2640
2628
|
}
|
|
2641
2629
|
if (((_b = val.collections) == null ? void 0 : _b.filter((x) => x.isAuthCollection).length) > 1) {
|
|
2642
2630
|
ctx.addIssue({
|
|
2643
2631
|
code: z.ZodIssueCode.custom,
|
|
2644
|
-
message:
|
|
2632
|
+
message: "Only one collection can be marked as `isAuthCollection`.",
|
|
2645
2633
|
fatal: true
|
|
2646
2634
|
});
|
|
2647
2635
|
}
|
|
@@ -2649,7 +2637,7 @@ const TinaCloudSchemaZod = z.object({
|
|
|
2649
2637
|
if (media && media.tina && media.loadCustomStore) {
|
|
2650
2638
|
ctx.addIssue({
|
|
2651
2639
|
code: z.ZodIssueCode.custom,
|
|
2652
|
-
message: "
|
|
2640
|
+
message: "Cannot have both `loadCustomStore` and `tina`. Must use one or the other.",
|
|
2653
2641
|
fatal: true,
|
|
2654
2642
|
path: ["config", "media"]
|
|
2655
2643
|
});
|
|
@@ -2658,7 +2646,7 @@ const TinaCloudSchemaZod = z.object({
|
|
|
2658
2646
|
if (search && search.tina && search.searchClient) {
|
|
2659
2647
|
ctx.addIssue({
|
|
2660
2648
|
code: z.ZodIssueCode.custom,
|
|
2661
|
-
message: "
|
|
2649
|
+
message: "Cannot have both `searchClient` and `tina`. Must use one or the other.",
|
|
2662
2650
|
fatal: true,
|
|
2663
2651
|
path: ["config", "search"]
|
|
2664
2652
|
});
|
|
@@ -2676,7 +2664,7 @@ const validateSchema = ({ schema }) => {
|
|
|
2676
2664
|
} catch (e) {
|
|
2677
2665
|
if (e instanceof ZodError) {
|
|
2678
2666
|
const errors = parseZodError({ zodError: e });
|
|
2679
|
-
throw new TinaSchemaValidationError(errors.join("
|
|
2667
|
+
throw new TinaSchemaValidationError(errors.join("\n"));
|
|
2680
2668
|
}
|
|
2681
2669
|
throw new Error(e);
|
|
2682
2670
|
}
|
|
@@ -28,6 +28,10 @@ export declare class TinaSchema {
|
|
|
28
28
|
} & Schema);
|
|
29
29
|
getIsTitleFieldName: (collection: string) => string;
|
|
30
30
|
getCollectionsByName: (collectionNames: string[]) => Collection<true>[];
|
|
31
|
+
findReferences(name: string): Record<string, {
|
|
32
|
+
path: string[];
|
|
33
|
+
field: TinaField;
|
|
34
|
+
}[]>;
|
|
31
35
|
getCollection: (collectionName: string) => Collection<true>;
|
|
32
36
|
getCollections: () => Collection<true>[];
|
|
33
37
|
getCollectionByFullPath: (filepath: string) => Collection<true>;
|
|
@@ -1,4 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
type Node = {
|
|
2
|
+
name?: string;
|
|
3
|
+
value?: string;
|
|
4
|
+
namespace?: string[];
|
|
5
|
+
[key: string]: any;
|
|
6
|
+
};
|
|
7
|
+
export declare function addNamespaceToSchema<T extends Node | string>(maybeNode: T, namespace?: string[]): T;
|
|
8
|
+
export {};
|
package/dist/types/index.d.ts
CHANGED
|
@@ -185,7 +185,7 @@ export type ReferenceField = (FieldGeneric<string, undefined, ReferenceFieldOpti
|
|
|
185
185
|
export type PasswordField = (FieldGeneric<string, undefined> | FieldGeneric<string, false>) & BaseField & {
|
|
186
186
|
type: 'password';
|
|
187
187
|
};
|
|
188
|
-
type
|
|
188
|
+
type ToolbarOverrideType = 'heading' | 'link' | 'image' | 'quote' | 'ul' | 'ol' | 'code' | 'codeBlock' | 'bold' | 'italic' | 'raw' | 'embed' | 'mermaid' | 'table';
|
|
189
189
|
type RichTextAst = {
|
|
190
190
|
type: 'root';
|
|
191
191
|
children: Record<string, unknown>[];
|
|
@@ -198,8 +198,14 @@ export type RichTextField<WithNamespace extends boolean = false> = (FieldGeneric
|
|
|
198
198
|
* will be stored as frontmatter
|
|
199
199
|
*/
|
|
200
200
|
isBody?: boolean;
|
|
201
|
-
|
|
201
|
+
/**@deprecated use overrides.toolbar */
|
|
202
|
+
toolbarOverride?: ToolbarOverrideType[];
|
|
202
203
|
templates?: RichTextTemplate<WithNamespace>[];
|
|
204
|
+
overrides?: {
|
|
205
|
+
toolbar?: ToolbarOverrideType[];
|
|
206
|
+
/**Default set to true */
|
|
207
|
+
showFloatingToolbar?: boolean;
|
|
208
|
+
};
|
|
203
209
|
/**
|
|
204
210
|
* By default, Tina parses markdown with MDX, this is a more strict parser
|
|
205
211
|
* that allows you to use structured content inside markdown (via `templates`).
|
|
@@ -630,6 +636,7 @@ type Document = {
|
|
|
630
636
|
relativePath: string;
|
|
631
637
|
filename: string;
|
|
632
638
|
extension: string;
|
|
639
|
+
hasReferences?: boolean;
|
|
633
640
|
};
|
|
634
641
|
};
|
|
635
642
|
export interface UICollection<Form = any, CMS = any, TinaForm = any> {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tinacms/schema-tools",
|
|
3
|
-
"version": "0.0.0-
|
|
3
|
+
"version": "0.0.0-d7c5ec1-20250219020924",
|
|
4
4
|
"main": "dist/index.js",
|
|
5
5
|
"module": "./dist/index.mjs",
|
|
6
6
|
"exports": {
|
|
@@ -23,16 +23,16 @@
|
|
|
23
23
|
]
|
|
24
24
|
},
|
|
25
25
|
"devDependencies": {
|
|
26
|
-
"@types/jest": "^29.5.
|
|
26
|
+
"@types/jest": "^29.5.14",
|
|
27
27
|
"@types/micromatch": "^4.0.9",
|
|
28
|
-
"@types/react": "^18.3.
|
|
28
|
+
"@types/react": "^18.3.18",
|
|
29
29
|
"@types/yup": "^0.29.14",
|
|
30
30
|
"jest": "^29.7.0",
|
|
31
31
|
"react": "^18.3.1",
|
|
32
32
|
"ts-jest": "^29.2.5",
|
|
33
|
-
"typescript": "^5.
|
|
33
|
+
"typescript": "^5.7.3",
|
|
34
34
|
"yup": "^0.32.11",
|
|
35
|
-
"@tinacms/scripts": "
|
|
35
|
+
"@tinacms/scripts": "0.0.0-d7c5ec1-20250219020924"
|
|
36
36
|
},
|
|
37
37
|
"peerDependencies": {
|
|
38
38
|
"react": ">=16.14.0",
|
|
@@ -48,7 +48,7 @@
|
|
|
48
48
|
"dependencies": {
|
|
49
49
|
"picomatch-browser": "2.2.6",
|
|
50
50
|
"url-pattern": "^1.0.3",
|
|
51
|
-
"zod": "^3.
|
|
51
|
+
"zod": "^3.24.2"
|
|
52
52
|
},
|
|
53
53
|
"scripts": {
|
|
54
54
|
"build": "tinacms-scripts build",
|