@tinacms/schema-tools 0.0.0-c8b1d84-20241003015733 → 0.0.0-ccab7a5-20251124054446
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 +232 -175
- package/dist/index.mjs +232 -175
- package/dist/schema/TinaSchema.d.ts +21 -1
- package/dist/schema/addNamespaceToSchema.d.ts +8 -4
- package/dist/types/index.d.ts +63 -23
- package/dist/util/normalizePath.d.ts +8 -0
- package/dist/validate/fields.d.ts +0 -3
- package/dist/validate/schema.d.ts +101 -39
- package/dist/validate/tinaCloudSchemaConfig.d.ts +37 -0
- package/dist/validate/util.d.ts +3 -0
- package/package.json +6 -6
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;
|
|
@@ -1662,6 +1646,9 @@ const parseURL = (url) => {
|
|
|
1662
1646
|
};
|
|
1663
1647
|
};
|
|
1664
1648
|
const normalizePath = (filepath) => filepath.replace(/\\/g, "/");
|
|
1649
|
+
const canonicalPath = (filepath) => {
|
|
1650
|
+
return normalizePath(filepath).split("/").filter((name2) => name2 !== "").join("/");
|
|
1651
|
+
};
|
|
1665
1652
|
class TinaSchema {
|
|
1666
1653
|
/**
|
|
1667
1654
|
* Create a schema class from a user defined schema object
|
|
@@ -1711,21 +1698,21 @@ class TinaSchema {
|
|
|
1711
1698
|
};
|
|
1712
1699
|
this.getCollectionByFullPath = (filepath) => {
|
|
1713
1700
|
const fileExtension = filepath.split(".").pop();
|
|
1714
|
-
const
|
|
1701
|
+
const canonicalFilepath = canonicalPath(filepath);
|
|
1715
1702
|
const possibleCollections = this.getCollections().filter((collection) => {
|
|
1716
1703
|
var _a, _b;
|
|
1717
|
-
if (!
|
|
1704
|
+
if (!canonicalFilepath.endsWith(`.gitkeep.${collection.format || "md"}`) && fileExtension !== (collection.format || "md")) {
|
|
1718
1705
|
return false;
|
|
1719
1706
|
}
|
|
1720
1707
|
if (((_a = collection == null ? void 0 : collection.match) == null ? void 0 : _a.include) || ((_b = collection == null ? void 0 : collection.match) == null ? void 0 : _b.exclude)) {
|
|
1721
1708
|
const matches = this.getMatches({ collection });
|
|
1722
|
-
const match = picomatch$1.isMatch(
|
|
1709
|
+
const match = picomatch$1.isMatch(canonicalFilepath, matches);
|
|
1723
1710
|
if (!match) {
|
|
1724
1711
|
return false;
|
|
1725
1712
|
}
|
|
1726
1713
|
}
|
|
1727
|
-
const
|
|
1728
|
-
return
|
|
1714
|
+
const collectionPath = canonicalPath(collection.path);
|
|
1715
|
+
return collectionPath === "" || canonicalFilepath.startsWith(`${collectionPath}/`);
|
|
1729
1716
|
});
|
|
1730
1717
|
if (possibleCollections.length === 0) {
|
|
1731
1718
|
throw new Error(`Unable to find collection for file at ${filepath}`);
|
|
@@ -1943,7 +1930,7 @@ class TinaSchema {
|
|
|
1943
1930
|
}
|
|
1944
1931
|
}
|
|
1945
1932
|
};
|
|
1946
|
-
this.
|
|
1933
|
+
this.legacyWalkFields = (cb) => {
|
|
1947
1934
|
const walk = (collectionOrObject, collection, path) => {
|
|
1948
1935
|
if (collectionOrObject.templates) {
|
|
1949
1936
|
collectionOrObject.templates.forEach((template) => {
|
|
@@ -1965,7 +1952,7 @@ class TinaSchema {
|
|
|
1965
1952
|
collections.forEach((collection) => walk(collection, collection, []));
|
|
1966
1953
|
};
|
|
1967
1954
|
this.schema = config;
|
|
1968
|
-
this.
|
|
1955
|
+
this.legacyWalkFields(({ field, collection }) => {
|
|
1969
1956
|
if (!("searchable" in field)) {
|
|
1970
1957
|
if (field.type === "image") {
|
|
1971
1958
|
field.searchable = false;
|
|
@@ -1986,6 +1973,67 @@ class TinaSchema {
|
|
|
1986
1973
|
field.uid = field.uid || false;
|
|
1987
1974
|
});
|
|
1988
1975
|
}
|
|
1976
|
+
findReferencesFromCollection(name2) {
|
|
1977
|
+
const result = {};
|
|
1978
|
+
this.walkFields(({ field, collection: c, path }) => {
|
|
1979
|
+
if (c.name !== name2) {
|
|
1980
|
+
return;
|
|
1981
|
+
}
|
|
1982
|
+
if (field.type === "reference") {
|
|
1983
|
+
field.collections.forEach((name22) => {
|
|
1984
|
+
if (result[name22] === void 0) {
|
|
1985
|
+
result[name22] = [];
|
|
1986
|
+
}
|
|
1987
|
+
result[name22].push(path);
|
|
1988
|
+
});
|
|
1989
|
+
}
|
|
1990
|
+
});
|
|
1991
|
+
return result;
|
|
1992
|
+
}
|
|
1993
|
+
/**
|
|
1994
|
+
* Walk all fields in tina schema
|
|
1995
|
+
*
|
|
1996
|
+
* @param cb callback function invoked for each field
|
|
1997
|
+
*/
|
|
1998
|
+
walkFields(cb) {
|
|
1999
|
+
const walk = (collectionOrObject, collection, path = "$") => {
|
|
2000
|
+
if (collectionOrObject.templates) {
|
|
2001
|
+
collectionOrObject.templates.forEach((template) => {
|
|
2002
|
+
const templatePath = `${path}.${template.name}`;
|
|
2003
|
+
template.fields.forEach((field) => {
|
|
2004
|
+
const fieldPath = field.list ? `${templatePath}[*].${field.name}` : `${templatePath}.${field.name}`;
|
|
2005
|
+
cb({ field, collection, path: fieldPath });
|
|
2006
|
+
if (field.type === "object") {
|
|
2007
|
+
walk(field, collection, fieldPath);
|
|
2008
|
+
}
|
|
2009
|
+
});
|
|
2010
|
+
});
|
|
2011
|
+
}
|
|
2012
|
+
if (collectionOrObject.fields) {
|
|
2013
|
+
collectionOrObject.fields.forEach((field) => {
|
|
2014
|
+
const fieldPath = field.list ? `${path}.${field.name}[*]` : `${path}.${field.name}`;
|
|
2015
|
+
cb({ field, collection, path: fieldPath });
|
|
2016
|
+
if (field.type === "object" && field.fields) {
|
|
2017
|
+
walk(field, collection, fieldPath);
|
|
2018
|
+
} else if (field.templates) {
|
|
2019
|
+
field.templates.forEach((template) => {
|
|
2020
|
+
const templatePath = `${fieldPath}.${template.name}`;
|
|
2021
|
+
template.fields.forEach((field2) => {
|
|
2022
|
+
const fieldPath2 = field2.list ? `${templatePath}[*].${field2.name}` : `${templatePath}.${field2.name}`;
|
|
2023
|
+
cb({ field: field2, collection, path: fieldPath2 });
|
|
2024
|
+
if (field2.type === "object") {
|
|
2025
|
+
walk(field2, collection, fieldPath2);
|
|
2026
|
+
}
|
|
2027
|
+
});
|
|
2028
|
+
});
|
|
2029
|
+
}
|
|
2030
|
+
});
|
|
2031
|
+
}
|
|
2032
|
+
};
|
|
2033
|
+
this.getCollections().forEach((collection) => {
|
|
2034
|
+
walk(collection, collection);
|
|
2035
|
+
});
|
|
2036
|
+
}
|
|
1989
2037
|
/**
|
|
1990
2038
|
* This function returns an array of glob matches for a given collection.
|
|
1991
2039
|
*
|
|
@@ -1997,16 +2045,16 @@ class TinaSchema {
|
|
|
1997
2045
|
}) {
|
|
1998
2046
|
var _a, _b;
|
|
1999
2047
|
const collection = typeof collectionOrString === "string" ? this.getCollection(collectionOrString) : collectionOrString;
|
|
2000
|
-
const
|
|
2001
|
-
const pathSuffix =
|
|
2048
|
+
const collectionPath = canonicalPath(collection.path);
|
|
2049
|
+
const pathSuffix = collectionPath ? "/" : "";
|
|
2002
2050
|
const format = collection.format || "md";
|
|
2003
2051
|
const matches = [];
|
|
2004
2052
|
if ((_a = collection == null ? void 0 : collection.match) == null ? void 0 : _a.include) {
|
|
2005
|
-
const match = `${
|
|
2053
|
+
const match = `${collectionPath}${pathSuffix}${collection.match.include}.${format}`;
|
|
2006
2054
|
matches.push(match);
|
|
2007
2055
|
}
|
|
2008
2056
|
if ((_b = collection == null ? void 0 : collection.match) == null ? void 0 : _b.exclude) {
|
|
2009
|
-
const exclude = `!(${
|
|
2057
|
+
const exclude = `!(${collectionPath}${pathSuffix}${collection.match.exclude}.${format})`;
|
|
2010
2058
|
matches.push(exclude);
|
|
2011
2059
|
}
|
|
2012
2060
|
return matches;
|
|
@@ -2199,6 +2247,15 @@ const resolveForm = ({
|
|
|
2199
2247
|
})
|
|
2200
2248
|
};
|
|
2201
2249
|
};
|
|
2250
|
+
const CONTENT_FORMATS = [
|
|
2251
|
+
"mdx",
|
|
2252
|
+
"md",
|
|
2253
|
+
"markdown",
|
|
2254
|
+
"json",
|
|
2255
|
+
"yaml",
|
|
2256
|
+
"yml",
|
|
2257
|
+
"toml"
|
|
2258
|
+
];
|
|
2202
2259
|
const parseZodError = ({ zodError }) => {
|
|
2203
2260
|
var _a, _b, _c, _d;
|
|
2204
2261
|
const errors = zodError.flatten((issue) => {
|
|
@@ -2208,9 +2265,12 @@ const parseZodError = ({ zodError }) => {
|
|
|
2208
2265
|
moreInfo.push(parseZodError({ zodError: unionError }));
|
|
2209
2266
|
});
|
|
2210
2267
|
}
|
|
2211
|
-
const errorMessage =
|
|
2268
|
+
const errorMessage = `${issue == null ? void 0 : issue.message}
|
|
2269
|
+
Additional information:
|
|
2270
|
+
- Error found at path ${issue.path.join(
|
|
2212
2271
|
"."
|
|
2213
|
-
)}
|
|
2272
|
+
)}
|
|
2273
|
+
`;
|
|
2214
2274
|
const errorMessages = [errorMessage, ...moreInfo];
|
|
2215
2275
|
return {
|
|
2216
2276
|
errors: errorMessages
|
|
@@ -2245,6 +2305,9 @@ If you need to use this value in your content you can use the \`nameOverride\` p
|
|
|
2245
2305
|
});
|
|
2246
2306
|
}
|
|
2247
2307
|
});
|
|
2308
|
+
const duplicateFieldErrorMessage = (fields) => `Fields must have unique names. Found duplicate field names: [${fields}]`;
|
|
2309
|
+
const duplicateTemplateErrorMessage = (templates) => `Templates must have unique names. Found duplicate template names: [${templates}]`;
|
|
2310
|
+
const duplicateCollectionErrorMessage = (collection) => `Collections must have unique names. Found duplicate collection names: [${collection}]`;
|
|
2248
2311
|
const TypeName = [
|
|
2249
2312
|
"string",
|
|
2250
2313
|
"boolean",
|
|
@@ -2255,10 +2318,11 @@ const TypeName = [
|
|
|
2255
2318
|
"reference",
|
|
2256
2319
|
"rich-text"
|
|
2257
2320
|
];
|
|
2258
|
-
const
|
|
2259
|
-
const
|
|
2260
|
-
|
|
2261
|
-
|
|
2321
|
+
const formattedTypes = ` - ${TypeName.join("\n - ")}`;
|
|
2322
|
+
const typeTypeError = `Invalid \`type\` property. \`type\` expected to be one of the following values:
|
|
2323
|
+
${formattedTypes}`;
|
|
2324
|
+
const typeRequiredError = `Missing \`type\` property. Please add a \`type\` property with one of the following:
|
|
2325
|
+
${formattedTypes}`;
|
|
2262
2326
|
const Option = z.union(
|
|
2263
2327
|
[
|
|
2264
2328
|
z.string(),
|
|
@@ -2344,7 +2408,7 @@ const TinaFieldZod = z.lazy(() => {
|
|
|
2344
2408
|
if (dups) {
|
|
2345
2409
|
ctx.addIssue({
|
|
2346
2410
|
code: z.ZodIssueCode.custom,
|
|
2347
|
-
message:
|
|
2411
|
+
message: duplicateFieldErrorMessage(dups)
|
|
2348
2412
|
});
|
|
2349
2413
|
}
|
|
2350
2414
|
});
|
|
@@ -2354,21 +2418,21 @@ const TinaFieldZod = z.lazy(() => {
|
|
|
2354
2418
|
invalid_type_error: typeTypeError,
|
|
2355
2419
|
required_error: typeRequiredError
|
|
2356
2420
|
}),
|
|
2357
|
-
fields: z.array(TinaFieldZod).min(1).optional().superRefine((val, ctx) => {
|
|
2421
|
+
fields: z.array(TinaFieldZod).min(1, "Property `fields` cannot be empty.").optional().superRefine((val, ctx) => {
|
|
2358
2422
|
const dups = findDuplicates(val == null ? void 0 : val.map((x) => x.name));
|
|
2359
2423
|
if (dups) {
|
|
2360
2424
|
ctx.addIssue({
|
|
2361
2425
|
code: z.ZodIssueCode.custom,
|
|
2362
|
-
message:
|
|
2426
|
+
message: duplicateFieldErrorMessage(dups)
|
|
2363
2427
|
});
|
|
2364
2428
|
}
|
|
2365
2429
|
}),
|
|
2366
|
-
templates: z.array(TemplateTemp).min(1).optional().superRefine((val, ctx) => {
|
|
2430
|
+
templates: z.array(TemplateTemp).min(1, "Property `templates` cannot be empty.").optional().superRefine((val, ctx) => {
|
|
2367
2431
|
const dups = findDuplicates(val == null ? void 0 : val.map((x) => x.name));
|
|
2368
2432
|
if (dups) {
|
|
2369
2433
|
ctx.addIssue({
|
|
2370
2434
|
code: z.ZodIssueCode.custom,
|
|
2371
|
-
message:
|
|
2435
|
+
message: duplicateTemplateErrorMessage(dups)
|
|
2372
2436
|
});
|
|
2373
2437
|
}
|
|
2374
2438
|
})
|
|
@@ -2383,7 +2447,7 @@ const TinaFieldZod = z.lazy(() => {
|
|
|
2383
2447
|
if (dups) {
|
|
2384
2448
|
ctx.addIssue({
|
|
2385
2449
|
code: z.ZodIssueCode.custom,
|
|
2386
|
-
message:
|
|
2450
|
+
message: duplicateTemplateErrorMessage(dups)
|
|
2387
2451
|
});
|
|
2388
2452
|
}
|
|
2389
2453
|
})
|
|
@@ -2403,10 +2467,17 @@ const TinaFieldZod = z.lazy(() => {
|
|
|
2403
2467
|
],
|
|
2404
2468
|
{
|
|
2405
2469
|
errorMap: (issue, ctx) => {
|
|
2406
|
-
var _a;
|
|
2470
|
+
var _a, _b;
|
|
2407
2471
|
if (issue.code === "invalid_union_discriminator") {
|
|
2472
|
+
if (!((_a = ctx.data) == null ? void 0 : _a.type)) {
|
|
2473
|
+
return {
|
|
2474
|
+
message: `Missing \`type\` property in field \`${ctx.data.name}\`. Please add a \`type\` property with one of the following:
|
|
2475
|
+
${formattedTypes}`
|
|
2476
|
+
};
|
|
2477
|
+
}
|
|
2408
2478
|
return {
|
|
2409
|
-
message: `Invalid \`type\` property. In the schema is 'type: ${(
|
|
2479
|
+
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:
|
|
2480
|
+
${formattedTypes}`
|
|
2410
2481
|
};
|
|
2411
2482
|
}
|
|
2412
2483
|
return {
|
|
@@ -2416,77 +2487,52 @@ const TinaFieldZod = z.lazy(() => {
|
|
|
2416
2487
|
}
|
|
2417
2488
|
).superRefine((val, ctx) => {
|
|
2418
2489
|
if (val.type === "string") {
|
|
2419
|
-
|
|
2420
|
-
|
|
2421
|
-
|
|
2422
|
-
|
|
2423
|
-
|
|
2424
|
-
${
|
|
2425
|
-
|
|
2426
|
-
null,
|
|
2427
|
-
2
|
|
2428
|
-
)}
|
|
2429
|
-
`
|
|
2430
|
-
});
|
|
2431
|
-
}
|
|
2432
|
-
if (!val.required) {
|
|
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
|
-
}
|
|
2490
|
+
const stringifiedField = JSON.stringify(val, null, 2);
|
|
2491
|
+
if (val.isTitle && val.list) {
|
|
2492
|
+
ctx.addIssue({
|
|
2493
|
+
code: z.ZodIssueCode.custom,
|
|
2494
|
+
message: `\`list: true\` is not allowed when using \`isTitle\` for fields of \`type: string\`. Error found in field:
|
|
2495
|
+
${stringifiedField}`
|
|
2496
|
+
});
|
|
2444
2497
|
}
|
|
2445
|
-
if (val.
|
|
2498
|
+
if (val.isTitle && !val.required) {
|
|
2499
|
+
ctx.addIssue({
|
|
2500
|
+
code: z.ZodIssueCode.custom,
|
|
2501
|
+
message: `Property \`required: true\` is required when using \`isTitle\` for fields of \`type: string\`. Error found in field:
|
|
2502
|
+
${stringifiedField}`
|
|
2503
|
+
});
|
|
2504
|
+
}
|
|
2505
|
+
if (val.uid && val.list) {
|
|
2446
2506
|
if (val.list) {
|
|
2447
2507
|
ctx.addIssue({
|
|
2448
2508
|
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
|
-
`
|
|
2509
|
+
message: `\`list: true\` is not allowed when using \`uid\` for fields of \`type: string\`. Error found in field:
|
|
2510
|
+
${stringifiedField}`
|
|
2468
2511
|
});
|
|
2469
2512
|
}
|
|
2470
2513
|
}
|
|
2514
|
+
if (val.uid && !val.required) {
|
|
2515
|
+
ctx.addIssue({
|
|
2516
|
+
code: z.ZodIssueCode.custom,
|
|
2517
|
+
message: `Property \`required: true\` is required when using \`uid\` for fields of \`type: string\`. Error found in field:
|
|
2518
|
+
${stringifiedField}`
|
|
2519
|
+
});
|
|
2520
|
+
}
|
|
2471
2521
|
}
|
|
2472
2522
|
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) {
|
|
2523
|
+
if (!(val == null ? void 0 : val.templates) && !(val == null ? void 0 : val.fields)) {
|
|
2476
2524
|
ctx.addIssue({
|
|
2477
2525
|
code: z.ZodIssueCode.custom,
|
|
2478
|
-
message
|
|
2526
|
+
message: "Fields of `type: object` must have either `templates` or `fields` property."
|
|
2527
|
+
});
|
|
2528
|
+
return false;
|
|
2529
|
+
}
|
|
2530
|
+
if ((val == null ? void 0 : val.templates) && (val == null ? void 0 : val.fields)) {
|
|
2531
|
+
ctx.addIssue({
|
|
2532
|
+
code: z.ZodIssueCode.custom,
|
|
2533
|
+
message: "Fields of `type: object` must have either `templates` or `fields` property, not both."
|
|
2479
2534
|
});
|
|
2480
2535
|
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
2536
|
}
|
|
2491
2537
|
}
|
|
2492
2538
|
return true;
|
|
@@ -2513,25 +2559,33 @@ const tinaConfigZod = z$1.object({
|
|
|
2513
2559
|
searchClient: z$1.any().optional(),
|
|
2514
2560
|
indexBatchSize: z$1.number().gte(1).optional(),
|
|
2515
2561
|
maxSearchIndexFieldLength: z$1.number().gte(1).optional()
|
|
2562
|
+
}).optional(),
|
|
2563
|
+
ui: z$1.object({
|
|
2564
|
+
previewUrl: z$1.function().optional(),
|
|
2565
|
+
optOutOfUpdateCheck: z$1.boolean().optional(),
|
|
2566
|
+
regexValidation: z$1.object({
|
|
2567
|
+
folderNameRegex: z$1.string().refine(
|
|
2568
|
+
(val) => {
|
|
2569
|
+
try {
|
|
2570
|
+
new RegExp(val);
|
|
2571
|
+
return true;
|
|
2572
|
+
} catch (error) {
|
|
2573
|
+
return false;
|
|
2574
|
+
}
|
|
2575
|
+
},
|
|
2576
|
+
{ message: "folderNameRegex is not a valid regex pattern" }
|
|
2577
|
+
).optional()
|
|
2578
|
+
}).optional()
|
|
2516
2579
|
}).optional()
|
|
2517
2580
|
});
|
|
2518
2581
|
const validateTinaCloudSchemaConfig = (config) => {
|
|
2519
2582
|
const newConfig = tinaConfigZod.parse(config);
|
|
2520
2583
|
return newConfig;
|
|
2521
2584
|
};
|
|
2522
|
-
const FORMATS = [
|
|
2523
|
-
"json",
|
|
2524
|
-
"md",
|
|
2525
|
-
"markdown",
|
|
2526
|
-
"mdx",
|
|
2527
|
-
"toml",
|
|
2528
|
-
"yaml",
|
|
2529
|
-
"yml"
|
|
2530
|
-
];
|
|
2531
2585
|
const Template = z.object({
|
|
2532
2586
|
label: z.string({
|
|
2533
|
-
invalid_type_error: "label
|
|
2534
|
-
required_error: "label
|
|
2587
|
+
invalid_type_error: "Invalid data type for property `label`. Must be of type `string`",
|
|
2588
|
+
required_error: "Missing `label` property. Property `label` is required."
|
|
2535
2589
|
}),
|
|
2536
2590
|
name,
|
|
2537
2591
|
fields: z.array(TinaFieldZod)
|
|
@@ -2541,7 +2595,7 @@ const Template = z.object({
|
|
|
2541
2595
|
if (dups) {
|
|
2542
2596
|
ctx.addIssue({
|
|
2543
2597
|
code: z.ZodIssueCode.custom,
|
|
2544
|
-
message:
|
|
2598
|
+
message: duplicateFieldErrorMessage(dups)
|
|
2545
2599
|
});
|
|
2546
2600
|
}
|
|
2547
2601
|
});
|
|
@@ -2551,7 +2605,7 @@ const CollectionBaseSchema = z.object({
|
|
|
2551
2605
|
if (val === "relativePath") {
|
|
2552
2606
|
ctx.addIssue({
|
|
2553
2607
|
code: z.ZodIssueCode.custom,
|
|
2554
|
-
message: `name cannot be 'relativePath'
|
|
2608
|
+
message: "Invalid `name` property. `name` cannot be 'relativePath' as it is a reserved field name."
|
|
2555
2609
|
});
|
|
2556
2610
|
}
|
|
2557
2611
|
}),
|
|
@@ -2559,72 +2613,73 @@ const CollectionBaseSchema = z.object({
|
|
|
2559
2613
|
if (val === ".") {
|
|
2560
2614
|
ctx.addIssue({
|
|
2561
2615
|
code: z.ZodIssueCode.custom,
|
|
2562
|
-
message: `path cannot be '.'. Please use '/' or '' instead.
|
|
2616
|
+
message: "Invalid `path` property. `path` cannot be '.'. Please use '/' or '' instead."
|
|
2563
2617
|
});
|
|
2564
2618
|
}
|
|
2565
2619
|
}),
|
|
2566
|
-
format: z.enum(
|
|
2620
|
+
format: z.enum(CONTENT_FORMATS).optional(),
|
|
2567
2621
|
isAuthCollection: z.boolean().optional(),
|
|
2568
2622
|
isDetached: z.boolean().optional()
|
|
2569
2623
|
});
|
|
2570
2624
|
const TinaCloudCollection = CollectionBaseSchema.extend({
|
|
2571
|
-
fields: z.array(TinaFieldZod).min(1).optional().superRefine((val, ctx) => {
|
|
2625
|
+
fields: z.array(TinaFieldZod).min(1, "Property `fields` cannot be empty.").optional().superRefine((val, ctx) => {
|
|
2572
2626
|
const dups = findDuplicates(val == null ? void 0 : val.map((x) => x.name));
|
|
2573
2627
|
if (dups) {
|
|
2574
2628
|
ctx.addIssue({
|
|
2575
2629
|
code: z.ZodIssueCode.custom,
|
|
2576
|
-
message:
|
|
2630
|
+
message: duplicateFieldErrorMessage(dups)
|
|
2577
2631
|
});
|
|
2578
2632
|
}
|
|
2579
|
-
}).
|
|
2580
|
-
|
|
2581
|
-
(
|
|
2582
|
-
|
|
2583
|
-
|
|
2584
|
-
|
|
2585
|
-
|
|
2586
|
-
|
|
2587
|
-
|
|
2588
|
-
|
|
2589
|
-
|
|
2590
|
-
|
|
2591
|
-
|
|
2592
|
-
|
|
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"
|
|
2633
|
+
}).superRefine((val, ctx) => {
|
|
2634
|
+
const arr = (val == null ? void 0 : val.filter((x) => x.type === "string" && x.isTitle)) || [];
|
|
2635
|
+
if (arr.length > 1) {
|
|
2636
|
+
ctx.addIssue({
|
|
2637
|
+
code: z.ZodIssueCode.custom,
|
|
2638
|
+
message: `The following fields have the property \`isTitle\`: [${arr.map((field) => field.name).join(", ")}]. Only one can contain the property \`isTitle\`.`
|
|
2639
|
+
});
|
|
2640
|
+
}
|
|
2641
|
+
}).superRefine((val, ctx) => {
|
|
2642
|
+
const arr = (val == null ? void 0 : val.filter((x) => x.uid)) || [];
|
|
2643
|
+
if (arr.length > 2) {
|
|
2644
|
+
ctx.addIssue({
|
|
2645
|
+
code: z.ZodIssueCode.custom,
|
|
2646
|
+
message: `The following fields have the property \`uid\`: [${arr.map((field) => field.name).join(", ")}]. Only one can contain the property \`uid\`.`
|
|
2647
|
+
});
|
|
2605
2648
|
}
|
|
2606
|
-
),
|
|
2607
|
-
|
|
2649
|
+
}).superRefine((val, ctx) => {
|
|
2650
|
+
const arr = (val == null ? void 0 : val.filter((x) => x.type === "password")) || [];
|
|
2651
|
+
if (arr.length > 2) {
|
|
2652
|
+
ctx.addIssue({
|
|
2653
|
+
code: z.ZodIssueCode.custom,
|
|
2654
|
+
message: `The following fields have \`type: password\`: [${arr.map((field) => field.name).join(", ")}]. Only one can be of \`type: password\`.`
|
|
2655
|
+
});
|
|
2656
|
+
}
|
|
2657
|
+
}),
|
|
2658
|
+
templates: z.array(Template).min(1, "Property `templates` cannot be empty.").optional().superRefine((val, ctx) => {
|
|
2608
2659
|
const dups = findDuplicates(val == null ? void 0 : val.map((x) => x.name));
|
|
2609
2660
|
if (dups) {
|
|
2610
2661
|
ctx.addIssue({
|
|
2611
2662
|
code: z.ZodIssueCode.custom,
|
|
2612
|
-
message:
|
|
2663
|
+
message: duplicateFieldErrorMessage(dups)
|
|
2613
2664
|
});
|
|
2614
2665
|
}
|
|
2615
2666
|
})
|
|
2616
|
-
}).
|
|
2617
|
-
(val)
|
|
2618
|
-
|
|
2619
|
-
|
|
2620
|
-
|
|
2621
|
-
}
|
|
2622
|
-
|
|
2623
|
-
|
|
2624
|
-
|
|
2625
|
-
|
|
2626
|
-
|
|
2627
|
-
|
|
2667
|
+
}).superRefine((val, ctx) => {
|
|
2668
|
+
if (!(val == null ? void 0 : val.templates) && !(val == null ? void 0 : val.fields)) {
|
|
2669
|
+
ctx.addIssue({
|
|
2670
|
+
code: z.ZodIssueCode.custom,
|
|
2671
|
+
message: "Fields of `type: object` must have either `templates` or `fields` property."
|
|
2672
|
+
});
|
|
2673
|
+
return false;
|
|
2674
|
+
}
|
|
2675
|
+
if ((val == null ? void 0 : val.templates) && (val == null ? void 0 : val.fields)) {
|
|
2676
|
+
ctx.addIssue({
|
|
2677
|
+
code: z.ZodIssueCode.custom,
|
|
2678
|
+
message: "Fields of `type: object` must have either `templates` or `fields` property, not both."
|
|
2679
|
+
});
|
|
2680
|
+
return false;
|
|
2681
|
+
}
|
|
2682
|
+
});
|
|
2628
2683
|
const TinaCloudSchemaZod = z.object({
|
|
2629
2684
|
collections: z.array(TinaCloudCollection),
|
|
2630
2685
|
config: tinaConfigZod.optional()
|
|
@@ -2634,14 +2689,14 @@ const TinaCloudSchemaZod = z.object({
|
|
|
2634
2689
|
if (dups) {
|
|
2635
2690
|
ctx.addIssue({
|
|
2636
2691
|
code: z.ZodIssueCode.custom,
|
|
2637
|
-
message:
|
|
2692
|
+
message: duplicateCollectionErrorMessage(dups),
|
|
2638
2693
|
fatal: true
|
|
2639
2694
|
});
|
|
2640
2695
|
}
|
|
2641
2696
|
if (((_b = val.collections) == null ? void 0 : _b.filter((x) => x.isAuthCollection).length) > 1) {
|
|
2642
2697
|
ctx.addIssue({
|
|
2643
2698
|
code: z.ZodIssueCode.custom,
|
|
2644
|
-
message:
|
|
2699
|
+
message: "Only one collection can be marked as `isAuthCollection`.",
|
|
2645
2700
|
fatal: true
|
|
2646
2701
|
});
|
|
2647
2702
|
}
|
|
@@ -2649,7 +2704,7 @@ const TinaCloudSchemaZod = z.object({
|
|
|
2649
2704
|
if (media && media.tina && media.loadCustomStore) {
|
|
2650
2705
|
ctx.addIssue({
|
|
2651
2706
|
code: z.ZodIssueCode.custom,
|
|
2652
|
-
message: "
|
|
2707
|
+
message: "Cannot have both `loadCustomStore` and `tina`. Must use one or the other.",
|
|
2653
2708
|
fatal: true,
|
|
2654
2709
|
path: ["config", "media"]
|
|
2655
2710
|
});
|
|
@@ -2658,7 +2713,7 @@ const TinaCloudSchemaZod = z.object({
|
|
|
2658
2713
|
if (search && search.tina && search.searchClient) {
|
|
2659
2714
|
ctx.addIssue({
|
|
2660
2715
|
code: z.ZodIssueCode.custom,
|
|
2661
|
-
message: "
|
|
2716
|
+
message: "Cannot have both `searchClient` and `tina`. Must use one or the other.",
|
|
2662
2717
|
fatal: true,
|
|
2663
2718
|
path: ["config", "search"]
|
|
2664
2719
|
});
|
|
@@ -2676,17 +2731,19 @@ const validateSchema = ({ schema }) => {
|
|
|
2676
2731
|
} catch (e) {
|
|
2677
2732
|
if (e instanceof ZodError) {
|
|
2678
2733
|
const errors = parseZodError({ zodError: e });
|
|
2679
|
-
throw new TinaSchemaValidationError(errors.join("
|
|
2734
|
+
throw new TinaSchemaValidationError(errors.join("\n"));
|
|
2680
2735
|
}
|
|
2681
2736
|
throw new Error(e);
|
|
2682
2737
|
}
|
|
2683
2738
|
};
|
|
2684
2739
|
export {
|
|
2740
|
+
CONTENT_FORMATS,
|
|
2685
2741
|
NAMER,
|
|
2686
2742
|
TINA_HOST,
|
|
2687
2743
|
TinaSchema,
|
|
2688
2744
|
TinaSchemaValidationError,
|
|
2689
2745
|
addNamespaceToSchema,
|
|
2746
|
+
canonicalPath,
|
|
2690
2747
|
normalizePath,
|
|
2691
2748
|
parseURL,
|
|
2692
2749
|
resolveField,
|