@tinacms/schema-tools 0.0.0-bdc07c1-20250506013835 → 0.0.0-be4681c-20250619070932

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.d.ts CHANGED
@@ -1 +1,6 @@
1
- export * from "../src/index"
1
+ export * from './schema';
2
+ export * from './types/index';
3
+ export * from './validate';
4
+ export * from './util/namer';
5
+ export * from './util/parseURL';
6
+ export * from './util/normalizePath';
package/dist/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  (function(global, factory) {
2
- typeof exports === "object" && typeof module !== "undefined" ? factory(exports, require("yup"), require("url-pattern"), require("zod"), require("@tinacms/common")) : typeof define === "function" && define.amd ? define(["exports", "yup", "url-pattern", "zod", "@tinacms/common"], factory) : (global = typeof globalThis !== "undefined" ? globalThis : global || self, factory(global["@tinacms/schema-tools"] = {}, global.NOOP, global.NOOP, global.NOOP, global.NOOP));
3
- })(this, function(exports2, yup, UrlPattern, z, common) {
2
+ typeof exports === "object" && typeof module !== "undefined" ? factory(exports, require("yup"), require("url-pattern"), require("zod")) : typeof define === "function" && define.amd ? define(["exports", "yup", "url-pattern", "zod"], factory) : (global = typeof globalThis !== "undefined" ? globalThis : global || self, factory(global["@tinacms/schema-tools"] = {}, global.NOOP, global.NOOP, global.NOOP));
3
+ })(this, function(exports2, yup, UrlPattern, z) {
4
4
  "use strict";
5
5
  function _interopNamespaceDefault(e) {
6
6
  const n = Object.create(null, { [Symbol.toStringTag]: { value: "Module" } });
@@ -1664,6 +1664,9 @@
1664
1664
  };
1665
1665
  };
1666
1666
  const normalizePath = (filepath) => filepath.replace(/\\/g, "/");
1667
+ const canonicalPath = (filepath) => {
1668
+ return normalizePath(filepath).split("/").filter((name2) => name2 !== "").join("/");
1669
+ };
1667
1670
  class TinaSchema {
1668
1671
  /**
1669
1672
  * Create a schema class from a user defined schema object
@@ -1713,21 +1716,21 @@
1713
1716
  };
1714
1717
  this.getCollectionByFullPath = (filepath) => {
1715
1718
  const fileExtension = filepath.split(".").pop();
1716
- const normalizedPath = filepath.replace(/\\/g, "/");
1719
+ const canonicalFilepath = canonicalPath(filepath);
1717
1720
  const possibleCollections = this.getCollections().filter((collection) => {
1718
1721
  var _a, _b;
1719
- if (!normalizedPath.endsWith(`.gitkeep.${collection.format || "md"}`) && fileExtension !== (collection.format || "md")) {
1722
+ if (!canonicalFilepath.endsWith(`.gitkeep.${collection.format || "md"}`) && fileExtension !== (collection.format || "md")) {
1720
1723
  return false;
1721
1724
  }
1722
1725
  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)) {
1723
1726
  const matches = this.getMatches({ collection });
1724
- const match = picomatch$1.isMatch(normalizedPath, matches);
1727
+ const match = picomatch$1.isMatch(canonicalFilepath, matches);
1725
1728
  if (!match) {
1726
1729
  return false;
1727
1730
  }
1728
1731
  }
1729
- const path = collection.path ? collection.path.replace(/\/?$/, "/") : "";
1730
- return normalizedPath.startsWith(path);
1732
+ const collectionPath = canonicalPath(collection.path);
1733
+ return collectionPath === "" || canonicalFilepath.startsWith(`${collectionPath}/`);
1731
1734
  });
1732
1735
  if (possibleCollections.length === 0) {
1733
1736
  throw new Error(`Unable to find collection for file at ${filepath}`);
@@ -2060,16 +2063,16 @@
2060
2063
  }) {
2061
2064
  var _a, _b;
2062
2065
  const collection = typeof collectionOrString === "string" ? this.getCollection(collectionOrString) : collectionOrString;
2063
- const normalPath = normalizePath(collection.path);
2064
- const pathSuffix = normalPath ? "/" : "";
2066
+ const collectionPath = canonicalPath(collection.path);
2067
+ const pathSuffix = collectionPath ? "/" : "";
2065
2068
  const format = collection.format || "md";
2066
2069
  const matches = [];
2067
2070
  if ((_a = collection == null ? void 0 : collection.match) == null ? void 0 : _a.include) {
2068
- const match = `${normalPath}${pathSuffix}${collection.match.include}.${format}`;
2071
+ const match = `${collectionPath}${pathSuffix}${collection.match.include}.${format}`;
2069
2072
  matches.push(match);
2070
2073
  }
2071
2074
  if ((_b = collection == null ? void 0 : collection.match) == null ? void 0 : _b.exclude) {
2072
- const exclude = `!(${normalPath}${pathSuffix}${collection.match.exclude}.${format})`;
2075
+ const exclude = `!(${collectionPath}${pathSuffix}${collection.match.exclude}.${format})`;
2073
2076
  matches.push(exclude);
2074
2077
  }
2075
2078
  return matches;
@@ -2262,6 +2265,15 @@
2262
2265
  })
2263
2266
  };
2264
2267
  };
2268
+ const CONTENT_FORMATS = [
2269
+ "mdx",
2270
+ "md",
2271
+ "markdown",
2272
+ "json",
2273
+ "yaml",
2274
+ "yml",
2275
+ "toml"
2276
+ ];
2265
2277
  const parseZodError = ({ zodError }) => {
2266
2278
  var _a, _b, _c, _d;
2267
2279
  const errors = zodError.flatten((issue) => {
@@ -2606,7 +2618,7 @@ ${stringifiedField}`
2606
2618
  });
2607
2619
  }
2608
2620
  }),
2609
- format: z.z.enum(common.CONTENT_FORMATS).optional(),
2621
+ format: z.z.enum(CONTENT_FORMATS).optional(),
2610
2622
  isAuthCollection: z.z.boolean().optional(),
2611
2623
  isDetached: z.z.boolean().optional()
2612
2624
  });
@@ -2725,11 +2737,13 @@ ${stringifiedField}`
2725
2737
  throw new Error(e);
2726
2738
  }
2727
2739
  };
2740
+ exports2.CONTENT_FORMATS = CONTENT_FORMATS;
2728
2741
  exports2.NAMER = NAMER;
2729
2742
  exports2.TINA_HOST = TINA_HOST;
2730
2743
  exports2.TinaSchema = TinaSchema;
2731
2744
  exports2.TinaSchemaValidationError = TinaSchemaValidationError;
2732
2745
  exports2.addNamespaceToSchema = addNamespaceToSchema;
2746
+ exports2.canonicalPath = canonicalPath;
2733
2747
  exports2.normalizePath = normalizePath;
2734
2748
  exports2.parseURL = parseURL;
2735
2749
  exports2.resolveField = resolveField;
package/dist/index.mjs CHANGED
@@ -1,7 +1,6 @@
1
1
  import * as yup from "yup";
2
2
  import UrlPattern from "url-pattern";
3
3
  import z$1, { z, ZodError } from "zod";
4
- import { CONTENT_FORMATS } from "@tinacms/common";
5
4
  function addNamespaceToSchema(maybeNode, namespace = []) {
6
5
  if (typeof maybeNode !== "object" || maybeNode === null) {
7
6
  return maybeNode;
@@ -1647,6 +1646,9 @@ const parseURL = (url) => {
1647
1646
  };
1648
1647
  };
1649
1648
  const normalizePath = (filepath) => filepath.replace(/\\/g, "/");
1649
+ const canonicalPath = (filepath) => {
1650
+ return normalizePath(filepath).split("/").filter((name2) => name2 !== "").join("/");
1651
+ };
1650
1652
  class TinaSchema {
1651
1653
  /**
1652
1654
  * Create a schema class from a user defined schema object
@@ -1696,21 +1698,21 @@ class TinaSchema {
1696
1698
  };
1697
1699
  this.getCollectionByFullPath = (filepath) => {
1698
1700
  const fileExtension = filepath.split(".").pop();
1699
- const normalizedPath = filepath.replace(/\\/g, "/");
1701
+ const canonicalFilepath = canonicalPath(filepath);
1700
1702
  const possibleCollections = this.getCollections().filter((collection) => {
1701
1703
  var _a, _b;
1702
- if (!normalizedPath.endsWith(`.gitkeep.${collection.format || "md"}`) && fileExtension !== (collection.format || "md")) {
1704
+ if (!canonicalFilepath.endsWith(`.gitkeep.${collection.format || "md"}`) && fileExtension !== (collection.format || "md")) {
1703
1705
  return false;
1704
1706
  }
1705
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)) {
1706
1708
  const matches = this.getMatches({ collection });
1707
- const match = picomatch$1.isMatch(normalizedPath, matches);
1709
+ const match = picomatch$1.isMatch(canonicalFilepath, matches);
1708
1710
  if (!match) {
1709
1711
  return false;
1710
1712
  }
1711
1713
  }
1712
- const path = collection.path ? collection.path.replace(/\/?$/, "/") : "";
1713
- return normalizedPath.startsWith(path);
1714
+ const collectionPath = canonicalPath(collection.path);
1715
+ return collectionPath === "" || canonicalFilepath.startsWith(`${collectionPath}/`);
1714
1716
  });
1715
1717
  if (possibleCollections.length === 0) {
1716
1718
  throw new Error(`Unable to find collection for file at ${filepath}`);
@@ -2043,16 +2045,16 @@ class TinaSchema {
2043
2045
  }) {
2044
2046
  var _a, _b;
2045
2047
  const collection = typeof collectionOrString === "string" ? this.getCollection(collectionOrString) : collectionOrString;
2046
- const normalPath = normalizePath(collection.path);
2047
- const pathSuffix = normalPath ? "/" : "";
2048
+ const collectionPath = canonicalPath(collection.path);
2049
+ const pathSuffix = collectionPath ? "/" : "";
2048
2050
  const format = collection.format || "md";
2049
2051
  const matches = [];
2050
2052
  if ((_a = collection == null ? void 0 : collection.match) == null ? void 0 : _a.include) {
2051
- const match = `${normalPath}${pathSuffix}${collection.match.include}.${format}`;
2053
+ const match = `${collectionPath}${pathSuffix}${collection.match.include}.${format}`;
2052
2054
  matches.push(match);
2053
2055
  }
2054
2056
  if ((_b = collection == null ? void 0 : collection.match) == null ? void 0 : _b.exclude) {
2055
- const exclude = `!(${normalPath}${pathSuffix}${collection.match.exclude}.${format})`;
2057
+ const exclude = `!(${collectionPath}${pathSuffix}${collection.match.exclude}.${format})`;
2056
2058
  matches.push(exclude);
2057
2059
  }
2058
2060
  return matches;
@@ -2245,6 +2247,15 @@ const resolveForm = ({
2245
2247
  })
2246
2248
  };
2247
2249
  };
2250
+ const CONTENT_FORMATS = [
2251
+ "mdx",
2252
+ "md",
2253
+ "markdown",
2254
+ "json",
2255
+ "yaml",
2256
+ "yml",
2257
+ "toml"
2258
+ ];
2248
2259
  const parseZodError = ({ zodError }) => {
2249
2260
  var _a, _b, _c, _d;
2250
2261
  const errors = zodError.flatten((issue) => {
@@ -2709,11 +2720,13 @@ const validateSchema = ({ schema }) => {
2709
2720
  }
2710
2721
  };
2711
2722
  export {
2723
+ CONTENT_FORMATS,
2712
2724
  NAMER,
2713
2725
  TINA_HOST,
2714
2726
  TinaSchema,
2715
2727
  TinaSchemaValidationError,
2716
2728
  addNamespaceToSchema,
2729
+ canonicalPath,
2717
2730
  normalizePath,
2718
2731
  parseURL,
2719
2732
  resolveField,
@@ -1,6 +1,23 @@
1
- import { ContentFormat, ContentFrontmatterFormat } from '@tinacms/common';
2
1
  import type { FC } from 'react';
3
2
  import type React from 'react';
3
+ export declare const CONTENT_FORMATS: readonly ["mdx", "md", "markdown", "json", "yaml", "yml", "toml"];
4
+ export type ContentFormat = (typeof CONTENT_FORMATS)[number];
5
+ export type ContentFrontmatterFormat = 'yaml' | 'toml' | 'json';
6
+ export type Parser = {
7
+ type: 'mdx';
8
+ } | {
9
+ type: 'markdown';
10
+ /**
11
+ * Tina will escape entities like `<` and `[` by default. You can choose to turn
12
+ * off all escaping, or specify HTML, so `<div>` will not be turned into `\<div>`
13
+ */
14
+ skipEscaping?: 'all' | 'html' | 'none';
15
+ } | {
16
+ /**
17
+ * Experimental: Returns the native Slate.js document as JSON. Ideal to retain the pure editor content structure.
18
+ */
19
+ type: 'slatejson';
20
+ };
4
21
  type Meta = {
5
22
  active?: boolean;
6
23
  dirty?: boolean;
@@ -213,16 +230,7 @@ export type RichTextField<WithNamespace extends boolean = false> = (FieldGeneric
213
230
  *
214
231
  * Specify `"markdown"` if you're having problems with Tina parsing your content.
215
232
  */
216
- parser?: {
217
- type: 'markdown';
218
- /**
219
- * Tina will escape entities like `<` and `[` by default. You can choose to turn
220
- * off all escaping, or specify HTML, so `<div>` will not be turned into `\<div>`
221
- */
222
- skipEscaping?: 'all' | 'html' | 'none';
223
- } | {
224
- type: 'mdx';
225
- };
233
+ parser?: Parser;
226
234
  };
227
235
  export type RichTextTemplate<WithNamespace extends boolean = false> = Template<WithNamespace> & {
228
236
  inline?: boolean;
@@ -1 +1,9 @@
1
1
  export declare const normalizePath: (filepath: string) => string;
2
+ /**
3
+ * Returns the given path such that:
4
+ * - The path separator is converted from '\' to '/' if necessary.
5
+ * - Duplicate '/' are removed
6
+ * - Leading and trailing '/' are cleared
7
+ * @param filepath Filepath to convert to its canonical form
8
+ */
9
+ export declare const canonicalPath: (filepath: string) => string;
@@ -30,44 +30,44 @@ export declare const TinaCloudSchemaZod: z.ZodEffects<z.ZodObject<{
30
30
  isAuthCollection: z.ZodOptional<z.ZodBoolean>;
31
31
  isDetached: z.ZodOptional<z.ZodBoolean>;
32
32
  }, {
33
- fields: z.ZodEffects<z.ZodEffects<z.ZodEffects<z.ZodEffects<z.ZodOptional<z.ZodArray<z.ZodType<import("..").TinaField, z.ZodTypeDef, import("..").TinaField>, "many">>, import("..").TinaField[], import("..").TinaField[]>, import("..").TinaField[], import("..").TinaField[]>, import("..").TinaField[], import("..").TinaField[]>, import("..").TinaField[], import("..").TinaField[]>;
33
+ fields: z.ZodEffects<z.ZodEffects<z.ZodEffects<z.ZodEffects<z.ZodOptional<z.ZodArray<z.ZodType<import("../types/index").TinaField, z.ZodTypeDef, import("../types/index").TinaField>, "many">>, import("../types/index").TinaField[], import("../types/index").TinaField[]>, import("../types/index").TinaField[], import("../types/index").TinaField[]>, import("../types/index").TinaField[], import("../types/index").TinaField[]>, import("../types/index").TinaField[], import("../types/index").TinaField[]>;
34
34
  templates: z.ZodEffects<z.ZodOptional<z.ZodArray<z.ZodEffects<z.ZodObject<{
35
35
  label: z.ZodString;
36
36
  name: z.ZodEffects<z.ZodString, string, string>;
37
- fields: z.ZodArray<z.ZodType<import("..").TinaField, z.ZodTypeDef, import("..").TinaField>, "many">;
37
+ fields: z.ZodArray<z.ZodType<import("../types/index").TinaField, z.ZodTypeDef, import("../types/index").TinaField>, "many">;
38
38
  }, "strip", z.ZodTypeAny, {
39
39
  name?: string;
40
- fields?: import("..").TinaField[];
40
+ fields?: import("../types/index").TinaField[];
41
41
  label?: string;
42
42
  }, {
43
43
  name?: string;
44
- fields?: import("..").TinaField[];
44
+ fields?: import("../types/index").TinaField[];
45
45
  label?: string;
46
46
  }>, {
47
47
  name?: string;
48
- fields?: import("..").TinaField[];
48
+ fields?: import("../types/index").TinaField[];
49
49
  label?: string;
50
50
  }, {
51
51
  name?: string;
52
- fields?: import("..").TinaField[];
52
+ fields?: import("../types/index").TinaField[];
53
53
  label?: string;
54
54
  }>, "many">>, {
55
55
  name?: string;
56
- fields?: import("..").TinaField[];
56
+ fields?: import("../types/index").TinaField[];
57
57
  label?: string;
58
58
  }[], {
59
59
  name?: string;
60
- fields?: import("..").TinaField[];
60
+ fields?: import("../types/index").TinaField[];
61
61
  label?: string;
62
62
  }[]>;
63
63
  }>, "strip", z.ZodTypeAny, {
64
64
  name?: string;
65
65
  templates?: {
66
66
  name?: string;
67
- fields?: import("..").TinaField[];
67
+ fields?: import("../types/index").TinaField[];
68
68
  label?: string;
69
69
  }[];
70
- fields?: import("..").TinaField[];
70
+ fields?: import("../types/index").TinaField[];
71
71
  label?: string;
72
72
  path?: string;
73
73
  format?: "mdx" | "md" | "markdown" | "json" | "yaml" | "yml" | "toml";
@@ -77,10 +77,10 @@ export declare const TinaCloudSchemaZod: z.ZodEffects<z.ZodObject<{
77
77
  name?: string;
78
78
  templates?: {
79
79
  name?: string;
80
- fields?: import("..").TinaField[];
80
+ fields?: import("../types/index").TinaField[];
81
81
  label?: string;
82
82
  }[];
83
- fields?: import("..").TinaField[];
83
+ fields?: import("../types/index").TinaField[];
84
84
  label?: string;
85
85
  path?: string;
86
86
  format?: "mdx" | "md" | "markdown" | "json" | "yaml" | "yml" | "toml";
@@ -90,10 +90,10 @@ export declare const TinaCloudSchemaZod: z.ZodEffects<z.ZodObject<{
90
90
  name?: string;
91
91
  templates?: {
92
92
  name?: string;
93
- fields?: import("..").TinaField[];
93
+ fields?: import("../types/index").TinaField[];
94
94
  label?: string;
95
95
  }[];
96
- fields?: import("..").TinaField[];
96
+ fields?: import("../types/index").TinaField[];
97
97
  label?: string;
98
98
  path?: string;
99
99
  format?: "mdx" | "md" | "markdown" | "json" | "yaml" | "yml" | "toml";
@@ -103,10 +103,10 @@ export declare const TinaCloudSchemaZod: z.ZodEffects<z.ZodObject<{
103
103
  name?: string;
104
104
  templates?: {
105
105
  name?: string;
106
- fields?: import("..").TinaField[];
106
+ fields?: import("../types/index").TinaField[];
107
107
  label?: string;
108
108
  }[];
109
- fields?: import("..").TinaField[];
109
+ fields?: import("../types/index").TinaField[];
110
110
  label?: string;
111
111
  path?: string;
112
112
  format?: "mdx" | "md" | "markdown" | "json" | "yaml" | "yml" | "toml";
@@ -237,10 +237,10 @@ export declare const TinaCloudSchemaZod: z.ZodEffects<z.ZodObject<{
237
237
  name?: string;
238
238
  templates?: {
239
239
  name?: string;
240
- fields?: import("..").TinaField[];
240
+ fields?: import("../types/index").TinaField[];
241
241
  label?: string;
242
242
  }[];
243
- fields?: import("..").TinaField[];
243
+ fields?: import("../types/index").TinaField[];
244
244
  label?: string;
245
245
  path?: string;
246
246
  format?: "mdx" | "md" | "markdown" | "json" | "yaml" | "yml" | "toml";
@@ -275,10 +275,10 @@ export declare const TinaCloudSchemaZod: z.ZodEffects<z.ZodObject<{
275
275
  name?: string;
276
276
  templates?: {
277
277
  name?: string;
278
- fields?: import("..").TinaField[];
278
+ fields?: import("../types/index").TinaField[];
279
279
  label?: string;
280
280
  }[];
281
- fields?: import("..").TinaField[];
281
+ fields?: import("../types/index").TinaField[];
282
282
  label?: string;
283
283
  path?: string;
284
284
  format?: "mdx" | "md" | "markdown" | "json" | "yaml" | "yml" | "toml";
@@ -313,10 +313,10 @@ export declare const TinaCloudSchemaZod: z.ZodEffects<z.ZodObject<{
313
313
  name?: string;
314
314
  templates?: {
315
315
  name?: string;
316
- fields?: import("..").TinaField[];
316
+ fields?: import("../types/index").TinaField[];
317
317
  label?: string;
318
318
  }[];
319
- fields?: import("..").TinaField[];
319
+ fields?: import("../types/index").TinaField[];
320
320
  label?: string;
321
321
  path?: string;
322
322
  format?: "mdx" | "md" | "markdown" | "json" | "yaml" | "yml" | "toml";
@@ -351,10 +351,10 @@ export declare const TinaCloudSchemaZod: z.ZodEffects<z.ZodObject<{
351
351
  name?: string;
352
352
  templates?: {
353
353
  name?: string;
354
- fields?: import("..").TinaField[];
354
+ fields?: import("../types/index").TinaField[];
355
355
  label?: string;
356
356
  }[];
357
- fields?: import("..").TinaField[];
357
+ fields?: import("../types/index").TinaField[];
358
358
  label?: string;
359
359
  path?: string;
360
360
  format?: "mdx" | "md" | "markdown" | "json" | "yaml" | "yml" | "toml";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tinacms/schema-tools",
3
- "version": "0.0.0-bdc07c1-20250506013835",
3
+ "version": "0.0.0-be4681c-20250619070932",
4
4
  "main": "dist/index.js",
5
5
  "module": "./dist/index.mjs",
6
6
  "exports": {
@@ -32,12 +32,11 @@
32
32
  "ts-jest": "^29.2.5",
33
33
  "typescript": "^5.7.3",
34
34
  "yup": "^0.32.11",
35
- "@tinacms/scripts": "1.3.4"
35
+ "@tinacms/scripts": "1.3.5"
36
36
  },
37
37
  "peerDependencies": {
38
38
  "react": ">=16.14.0",
39
- "yup": "^0.32.0",
40
- "@tinacms/common": "0.0.0-bdc07c1-20250506013835"
39
+ "yup": "^0.32.0"
41
40
  },
42
41
  "publishConfig": {
43
42
  "registry": "https://registry.npmjs.org"