@tinacms/schema-tools 0.0.0-c45ac5d-20241213020122 → 0.0.0-c6915ea-20250421012527
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 +1 -6
- package/dist/index.js +68 -37
- package/dist/index.mjs +68 -37
- package/dist/schema/TinaSchema.d.ts +21 -5
- package/dist/schema/addNamespaceToSchema.d.ts +8 -4
- package/dist/types/index.d.ts +10 -3
- package/package.json +5 -5
package/dist/index.d.ts
CHANGED
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;
|
|
@@ -1961,7 +1945,7 @@
|
|
|
1961
1945
|
}
|
|
1962
1946
|
}
|
|
1963
1947
|
};
|
|
1964
|
-
this.
|
|
1948
|
+
this.legacyWalkFields = (cb) => {
|
|
1965
1949
|
const walk = (collectionOrObject, collection, path) => {
|
|
1966
1950
|
if (collectionOrObject.templates) {
|
|
1967
1951
|
collectionOrObject.templates.forEach((template) => {
|
|
@@ -1983,7 +1967,7 @@
|
|
|
1983
1967
|
collections.forEach((collection) => walk(collection, collection, []));
|
|
1984
1968
|
};
|
|
1985
1969
|
this.schema = config;
|
|
1986
|
-
this.
|
|
1970
|
+
this.legacyWalkFields(({ field, collection }) => {
|
|
1987
1971
|
if (!("searchable" in field)) {
|
|
1988
1972
|
if (field.type === "image") {
|
|
1989
1973
|
field.searchable = false;
|
|
@@ -2004,20 +1988,67 @@
|
|
|
2004
1988
|
field.uid = field.uid || false;
|
|
2005
1989
|
});
|
|
2006
1990
|
}
|
|
2007
|
-
|
|
1991
|
+
findReferencesFromCollection(name2) {
|
|
2008
1992
|
const result = {};
|
|
2009
1993
|
this.walkFields(({ field, collection: c, path }) => {
|
|
1994
|
+
if (c.name !== name2) {
|
|
1995
|
+
return;
|
|
1996
|
+
}
|
|
2010
1997
|
if (field.type === "reference") {
|
|
2011
|
-
|
|
2012
|
-
if (result[
|
|
2013
|
-
result[
|
|
1998
|
+
field.collections.forEach((name22) => {
|
|
1999
|
+
if (result[name22] === void 0) {
|
|
2000
|
+
result[name22] = [];
|
|
2014
2001
|
}
|
|
2015
|
-
result[
|
|
2016
|
-
}
|
|
2002
|
+
result[name22].push(path);
|
|
2003
|
+
});
|
|
2017
2004
|
}
|
|
2018
2005
|
});
|
|
2019
2006
|
return result;
|
|
2020
2007
|
}
|
|
2008
|
+
/**
|
|
2009
|
+
* Walk all fields in tina schema
|
|
2010
|
+
*
|
|
2011
|
+
* @param cb callback function invoked for each field
|
|
2012
|
+
*/
|
|
2013
|
+
walkFields(cb) {
|
|
2014
|
+
const walk = (collectionOrObject, collection, path = "$") => {
|
|
2015
|
+
if (collectionOrObject.templates) {
|
|
2016
|
+
collectionOrObject.templates.forEach((template) => {
|
|
2017
|
+
const templatePath = `${path}.${template.name}`;
|
|
2018
|
+
template.fields.forEach((field) => {
|
|
2019
|
+
const fieldPath = field.list ? `${templatePath}[*].${field.name}` : `${templatePath}.${field.name}`;
|
|
2020
|
+
cb({ field, collection, path: fieldPath });
|
|
2021
|
+
if (field.type === "object") {
|
|
2022
|
+
walk(field, collection, fieldPath);
|
|
2023
|
+
}
|
|
2024
|
+
});
|
|
2025
|
+
});
|
|
2026
|
+
}
|
|
2027
|
+
if (collectionOrObject.fields) {
|
|
2028
|
+
collectionOrObject.fields.forEach((field) => {
|
|
2029
|
+
const fieldPath = field.list ? `${path}.${field.name}[*]` : `${path}.${field.name}`;
|
|
2030
|
+
cb({ field, collection, path: fieldPath });
|
|
2031
|
+
if (field.type === "object" && field.fields) {
|
|
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
|
+
});
|
|
2044
|
+
}
|
|
2045
|
+
});
|
|
2046
|
+
}
|
|
2047
|
+
};
|
|
2048
|
+
this.getCollections().forEach((collection) => {
|
|
2049
|
+
walk(collection, collection);
|
|
2050
|
+
});
|
|
2051
|
+
}
|
|
2021
2052
|
/**
|
|
2022
2053
|
* This function returns an array of glob matches for a given collection.
|
|
2023
2054
|
*
|
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;
|
|
@@ -1943,7 +1927,7 @@ class TinaSchema {
|
|
|
1943
1927
|
}
|
|
1944
1928
|
}
|
|
1945
1929
|
};
|
|
1946
|
-
this.
|
|
1930
|
+
this.legacyWalkFields = (cb) => {
|
|
1947
1931
|
const walk = (collectionOrObject, collection, path) => {
|
|
1948
1932
|
if (collectionOrObject.templates) {
|
|
1949
1933
|
collectionOrObject.templates.forEach((template) => {
|
|
@@ -1965,7 +1949,7 @@ class TinaSchema {
|
|
|
1965
1949
|
collections.forEach((collection) => walk(collection, collection, []));
|
|
1966
1950
|
};
|
|
1967
1951
|
this.schema = config;
|
|
1968
|
-
this.
|
|
1952
|
+
this.legacyWalkFields(({ field, collection }) => {
|
|
1969
1953
|
if (!("searchable" in field)) {
|
|
1970
1954
|
if (field.type === "image") {
|
|
1971
1955
|
field.searchable = false;
|
|
@@ -1986,20 +1970,67 @@ class TinaSchema {
|
|
|
1986
1970
|
field.uid = field.uid || false;
|
|
1987
1971
|
});
|
|
1988
1972
|
}
|
|
1989
|
-
|
|
1973
|
+
findReferencesFromCollection(name2) {
|
|
1990
1974
|
const result = {};
|
|
1991
1975
|
this.walkFields(({ field, collection: c, path }) => {
|
|
1976
|
+
if (c.name !== name2) {
|
|
1977
|
+
return;
|
|
1978
|
+
}
|
|
1992
1979
|
if (field.type === "reference") {
|
|
1993
|
-
|
|
1994
|
-
if (result[
|
|
1995
|
-
result[
|
|
1980
|
+
field.collections.forEach((name22) => {
|
|
1981
|
+
if (result[name22] === void 0) {
|
|
1982
|
+
result[name22] = [];
|
|
1996
1983
|
}
|
|
1997
|
-
result[
|
|
1998
|
-
}
|
|
1984
|
+
result[name22].push(path);
|
|
1985
|
+
});
|
|
1999
1986
|
}
|
|
2000
1987
|
});
|
|
2001
1988
|
return result;
|
|
2002
1989
|
}
|
|
1990
|
+
/**
|
|
1991
|
+
* Walk all fields in tina schema
|
|
1992
|
+
*
|
|
1993
|
+
* @param cb callback function invoked for each field
|
|
1994
|
+
*/
|
|
1995
|
+
walkFields(cb) {
|
|
1996
|
+
const walk = (collectionOrObject, collection, path = "$") => {
|
|
1997
|
+
if (collectionOrObject.templates) {
|
|
1998
|
+
collectionOrObject.templates.forEach((template) => {
|
|
1999
|
+
const templatePath = `${path}.${template.name}`;
|
|
2000
|
+
template.fields.forEach((field) => {
|
|
2001
|
+
const fieldPath = field.list ? `${templatePath}[*].${field.name}` : `${templatePath}.${field.name}`;
|
|
2002
|
+
cb({ field, collection, path: fieldPath });
|
|
2003
|
+
if (field.type === "object") {
|
|
2004
|
+
walk(field, collection, fieldPath);
|
|
2005
|
+
}
|
|
2006
|
+
});
|
|
2007
|
+
});
|
|
2008
|
+
}
|
|
2009
|
+
if (collectionOrObject.fields) {
|
|
2010
|
+
collectionOrObject.fields.forEach((field) => {
|
|
2011
|
+
const fieldPath = field.list ? `${path}.${field.name}[*]` : `${path}.${field.name}`;
|
|
2012
|
+
cb({ field, collection, path: fieldPath });
|
|
2013
|
+
if (field.type === "object" && field.fields) {
|
|
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
|
+
});
|
|
2026
|
+
}
|
|
2027
|
+
});
|
|
2028
|
+
}
|
|
2029
|
+
};
|
|
2030
|
+
this.getCollections().forEach((collection) => {
|
|
2031
|
+
walk(collection, collection);
|
|
2032
|
+
});
|
|
2033
|
+
}
|
|
2003
2034
|
/**
|
|
2004
2035
|
* This function returns an array of glob matches for a given collection.
|
|
2005
2036
|
*
|
|
@@ -28,10 +28,7 @@ export declare class TinaSchema {
|
|
|
28
28
|
} & Schema);
|
|
29
29
|
getIsTitleFieldName: (collection: string) => string;
|
|
30
30
|
getCollectionsByName: (collectionNames: string[]) => Collection<true>[];
|
|
31
|
-
|
|
32
|
-
path: string[];
|
|
33
|
-
field: TinaField;
|
|
34
|
-
}[]>;
|
|
31
|
+
findReferencesFromCollection(name: string): Record<string, string[]>;
|
|
35
32
|
getCollection: (collectionName: string) => Collection<true>;
|
|
36
33
|
getCollections: () => Collection<true>[];
|
|
37
34
|
getCollectionByFullPath: (filepath: string) => Collection<true>;
|
|
@@ -63,7 +60,26 @@ export declare class TinaSchema {
|
|
|
63
60
|
*
|
|
64
61
|
*/
|
|
65
62
|
getTemplatesForCollectable: (collection: Collectable) => CollectionTemplateable;
|
|
66
|
-
|
|
63
|
+
/**
|
|
64
|
+
* Walk all fields in tina schema
|
|
65
|
+
*
|
|
66
|
+
* @param cb callback function invoked for each field
|
|
67
|
+
*/
|
|
68
|
+
walkFields(cb: (args: {
|
|
69
|
+
field: any;
|
|
70
|
+
collection: any;
|
|
71
|
+
path: string;
|
|
72
|
+
isListItem?: boolean;
|
|
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: {
|
|
67
83
|
field: TinaField;
|
|
68
84
|
collection: Collection;
|
|
69
85
|
path: string[];
|
|
@@ -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
|
@@ -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
|
+
/**@deprecated use overrides.toolbar */
|
|
201
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`).
|
|
@@ -357,6 +363,7 @@ interface AuthHooks {
|
|
|
357
363
|
type AuthOptions = AuthHooks & AuthProvider;
|
|
358
364
|
export interface Config<CMSCallback = undefined, FormifyCallback = undefined, DocumentCreatorCallback = undefined, Store = undefined, SearchClient = undefined> {
|
|
359
365
|
contentApiUrlOverride?: string;
|
|
366
|
+
oauth2?: boolean;
|
|
360
367
|
authProvider?: AuthProvider;
|
|
361
368
|
admin?: {
|
|
362
369
|
/**
|
|
@@ -394,7 +401,7 @@ export interface Config<CMSCallback = undefined, FormifyCallback = undefined, Do
|
|
|
394
401
|
token?: string | null;
|
|
395
402
|
ui?: {
|
|
396
403
|
/**
|
|
397
|
-
* When using
|
|
404
|
+
* When using TinaCloud's branching feature, provide the URL for your given branch
|
|
398
405
|
*
|
|
399
406
|
* Eg. If you're deplying to Vercel, and your repo name is 'my-app',
|
|
400
407
|
* Vercel's preview URL would be based on the branch:
|
|
@@ -521,7 +528,7 @@ export interface Config<CMSCallback = undefined, FormifyCallback = undefined, Do
|
|
|
521
528
|
} | {
|
|
522
529
|
searchClient?: never;
|
|
523
530
|
/**
|
|
524
|
-
* Use the
|
|
531
|
+
* Use the TinaCloud search index
|
|
525
532
|
*/
|
|
526
533
|
tina: {
|
|
527
534
|
/**
|
|
@@ -548,7 +555,7 @@ export interface Config<CMSCallback = undefined, FormifyCallback = undefined, Do
|
|
|
548
555
|
maxSearchIndexFieldLength?: number;
|
|
549
556
|
};
|
|
550
557
|
/**
|
|
551
|
-
* Used to override the default
|
|
558
|
+
* Used to override the default TinaCloud API URL
|
|
552
559
|
*
|
|
553
560
|
* [mostly for internal use only]
|
|
554
561
|
*/
|
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-c6915ea-20250421012527",
|
|
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.
|
|
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": "1.3.
|
|
35
|
+
"@tinacms/scripts": "1.3.4"
|
|
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",
|