@tinacms/schema-tools 0.0.0-d9672bc-20250218033222 → 0.0.0-db8aa8e-20250228034006

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 CHANGED
@@ -1945,8 +1945,29 @@
1945
1945
  }
1946
1946
  }
1947
1947
  };
1948
+ this.legacyWalkFields = (cb) => {
1949
+ const walk = (collectionOrObject, collection, path) => {
1950
+ if (collectionOrObject.templates) {
1951
+ collectionOrObject.templates.forEach((template) => {
1952
+ template.fields.forEach((field) => {
1953
+ cb({ field, collection, path: [...path, template.name] });
1954
+ });
1955
+ });
1956
+ }
1957
+ if (collectionOrObject.fields) {
1958
+ collectionOrObject.fields.forEach((field) => {
1959
+ cb({ field, collection, path: [...path, field.name] });
1960
+ if (field.type === "rich-text" || field.type === "object") {
1961
+ walk(field, collection, [...path, field.name]);
1962
+ }
1963
+ });
1964
+ }
1965
+ };
1966
+ const collections = this.getCollections();
1967
+ collections.forEach((collection) => walk(collection, collection, []));
1968
+ };
1948
1969
  this.schema = config;
1949
- this.walkFields(({ field, collection }) => {
1970
+ this.legacyWalkFields(({ field, collection }) => {
1950
1971
  if (!("searchable" in field)) {
1951
1972
  if (field.type === "image") {
1952
1973
  field.searchable = false;
@@ -1984,6 +2005,11 @@
1984
2005
  });
1985
2006
  return result;
1986
2007
  }
2008
+ /**
2009
+ * Walk all fields in tina schema
2010
+ *
2011
+ * @param cb callback function invoked for each field
2012
+ */
1987
2013
  walkFields(cb) {
1988
2014
  const walk = (collectionOrObject, collection, path = "$") => {
1989
2015
  if (collectionOrObject.templates) {
@@ -2004,6 +2030,17 @@
2004
2030
  cb({ field, collection, path: fieldPath });
2005
2031
  if (field.type === "object" && field.fields) {
2006
2032
  walk(field, collection, fieldPath);
2033
+ } else if (field.templates) {
2034
+ field.templates.forEach((template) => {
2035
+ const templatePath = `${fieldPath}.${template.name}`;
2036
+ template.fields.forEach((field2) => {
2037
+ const fieldPath2 = field2.list ? `${templatePath}[*].${field2.name}` : `${templatePath}.${field2.name}`;
2038
+ cb({ field: field2, collection, path: fieldPath2 });
2039
+ if (field2.type === "object") {
2040
+ walk(field2, collection, fieldPath2);
2041
+ }
2042
+ });
2043
+ });
2007
2044
  }
2008
2045
  });
2009
2046
  }
package/dist/index.mjs CHANGED
@@ -1927,8 +1927,29 @@ class TinaSchema {
1927
1927
  }
1928
1928
  }
1929
1929
  };
1930
+ this.legacyWalkFields = (cb) => {
1931
+ const walk = (collectionOrObject, collection, path) => {
1932
+ if (collectionOrObject.templates) {
1933
+ collectionOrObject.templates.forEach((template) => {
1934
+ template.fields.forEach((field) => {
1935
+ cb({ field, collection, path: [...path, template.name] });
1936
+ });
1937
+ });
1938
+ }
1939
+ if (collectionOrObject.fields) {
1940
+ collectionOrObject.fields.forEach((field) => {
1941
+ cb({ field, collection, path: [...path, field.name] });
1942
+ if (field.type === "rich-text" || field.type === "object") {
1943
+ walk(field, collection, [...path, field.name]);
1944
+ }
1945
+ });
1946
+ }
1947
+ };
1948
+ const collections = this.getCollections();
1949
+ collections.forEach((collection) => walk(collection, collection, []));
1950
+ };
1930
1951
  this.schema = config;
1931
- this.walkFields(({ field, collection }) => {
1952
+ this.legacyWalkFields(({ field, collection }) => {
1932
1953
  if (!("searchable" in field)) {
1933
1954
  if (field.type === "image") {
1934
1955
  field.searchable = false;
@@ -1966,6 +1987,11 @@ class TinaSchema {
1966
1987
  });
1967
1988
  return result;
1968
1989
  }
1990
+ /**
1991
+ * Walk all fields in tina schema
1992
+ *
1993
+ * @param cb callback function invoked for each field
1994
+ */
1969
1995
  walkFields(cb) {
1970
1996
  const walk = (collectionOrObject, collection, path = "$") => {
1971
1997
  if (collectionOrObject.templates) {
@@ -1986,6 +2012,17 @@ class TinaSchema {
1986
2012
  cb({ field, collection, path: fieldPath });
1987
2013
  if (field.type === "object" && field.fields) {
1988
2014
  walk(field, collection, fieldPath);
2015
+ } else if (field.templates) {
2016
+ field.templates.forEach((template) => {
2017
+ const templatePath = `${fieldPath}.${template.name}`;
2018
+ template.fields.forEach((field2) => {
2019
+ const fieldPath2 = field2.list ? `${templatePath}[*].${field2.name}` : `${templatePath}.${field2.name}`;
2020
+ cb({ field: field2, collection, path: fieldPath2 });
2021
+ if (field2.type === "object") {
2022
+ walk(field2, collection, fieldPath2);
2023
+ }
2024
+ });
2025
+ });
1989
2026
  }
1990
2027
  });
1991
2028
  }
@@ -1,4 +1,4 @@
1
- import type { Schema, Collection, Template, Collectable, CollectionTemplateable } from '../types/index';
1
+ import type { Schema, Collection, Template, Collectable, CollectionTemplateable, TinaField } from '../types/index';
2
2
  type Version = {
3
3
  fullVersion: string;
4
4
  major: string;
@@ -60,12 +60,30 @@ export declare class TinaSchema {
60
60
  *
61
61
  */
62
62
  getTemplatesForCollectable: (collection: Collectable) => CollectionTemplateable;
63
+ /**
64
+ * Walk all fields in tina schema
65
+ *
66
+ * @param cb callback function invoked for each field
67
+ */
63
68
  walkFields(cb: (args: {
64
69
  field: any;
65
70
  collection: any;
66
71
  path: string;
67
72
  isListItem?: boolean;
68
73
  }) => void): void;
74
+ /**
75
+ * Walk all fields in Tina Schema
76
+ *
77
+ * This is a legacy version to preserve backwards compatibility for the tina generated schema. It does not
78
+ * traverse fields in object lists in rich-text templates.
79
+ *
80
+ * @param cb callback function invoked for each field
81
+ */
82
+ legacyWalkFields: (cb: (args: {
83
+ field: TinaField;
84
+ collection: Collection;
85
+ path: string[];
86
+ }) => void) => void;
69
87
  /**
70
88
  * This function returns an array of glob matches for a given collection.
71
89
  *
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tinacms/schema-tools",
3
- "version": "0.0.0-d9672bc-20250218033222",
3
+ "version": "0.0.0-db8aa8e-20250228034006",
4
4
  "main": "dist/index.js",
5
5
  "module": "./dist/index.mjs",
6
6
  "exports": {
@@ -25,14 +25,14 @@
25
25
  "devDependencies": {
26
26
  "@types/jest": "^29.5.14",
27
27
  "@types/micromatch": "^4.0.9",
28
- "@types/react": "^18.3.12",
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.6.3",
33
+ "typescript": "^5.7.3",
34
34
  "yup": "^0.32.11",
35
- "@tinacms/scripts": "1.3.1"
35
+ "@tinacms/scripts": "0.0.0-db8aa8e-20250228034006"
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.23.8"
51
+ "zod": "^3.24.2"
52
52
  },
53
53
  "scripts": {
54
54
  "build": "tinacms-scripts build",