@tinacms/schema-tools 0.0.0-00d7b85-20251222014449

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.
@@ -0,0 +1,101 @@
1
+ import type { Schema, Collection, Template, Collectable, CollectionTemplateable, TinaField } from '../types/index';
2
+ type Version = {
3
+ fullVersion: string;
4
+ major: string;
5
+ minor: string;
6
+ patch: string;
7
+ };
8
+ type Meta = {
9
+ flags?: string[];
10
+ };
11
+ /**
12
+ * TinaSchema is responsible for allowing you to look up certain
13
+ * properties of the user-provided schema with ease.
14
+ *
15
+ */
16
+ export declare class TinaSchema {
17
+ config: {
18
+ version?: Version;
19
+ meta?: Meta;
20
+ } & Schema;
21
+ schema: Schema<true>;
22
+ /**
23
+ * Create a schema class from a user defined schema object
24
+ */
25
+ constructor(config: {
26
+ version?: Version;
27
+ meta?: Meta;
28
+ } & Schema);
29
+ getIsTitleFieldName: (collection: string) => string;
30
+ getCollectionsByName: (collectionNames: string[]) => Collection<true>[];
31
+ findReferencesFromCollection(name: string): Record<string, string[]>;
32
+ getCollection: (collectionName: string) => Collection<true>;
33
+ getCollections: () => Collection<true>[];
34
+ getCollectionByFullPath: (filepath: string) => Collection<true>;
35
+ getCollectionAndTemplateByFullPath: (filepath: string, templateName?: string) => {
36
+ collection: Collection<true>;
37
+ template: Template<true>;
38
+ } | undefined;
39
+ getTemplateForData: ({ data, collection, }: {
40
+ data?: unknown;
41
+ collection: Collectable;
42
+ }) => Template<true>;
43
+ transformPayload: (collectionName: string, payload: object) => {
44
+ [x: string]: {
45
+ [key: string]: unknown;
46
+ };
47
+ };
48
+ private transformCollectablePayload;
49
+ private transformField;
50
+ isMarkdownCollection: (collectionName: string) => boolean;
51
+ /**
52
+ * Gets the template or templates from the item.
53
+ * Both `object` fields and collections support
54
+ * the ability for an object to be polymorphic,
55
+ * and if it is, we need to build unions, which
56
+ * are more of a headache for non-polymorphic
57
+ * needs, so we also need the ability to just
58
+ * build object types
59
+ *
60
+ *
61
+ */
62
+ getTemplatesForCollectable: (collection: Collectable) => CollectionTemplateable;
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: {
83
+ field: TinaField;
84
+ collection: Collection;
85
+ path: string[];
86
+ }) => void) => void;
87
+ /**
88
+ * This function returns an array of glob matches for a given collection.
89
+ *
90
+ * @param collection The collection to get the matches for. Can be a string or a collection object.
91
+ * @returns An array of glob matches.
92
+ */
93
+ getMatches({ collection: collectionOrString, }: {
94
+ collection: string | Collection;
95
+ }): string[];
96
+ matchFiles({ collection, files, }: {
97
+ collection: string | Collection;
98
+ files: string[];
99
+ }): string[];
100
+ }
101
+ export {};
@@ -0,0 +1,8 @@
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 {};
@@ -0,0 +1,7 @@
1
+ /**
2
+
3
+ */
4
+ export * from './addNamespaceToSchema';
5
+ export * from './TinaSchema';
6
+ export * from './resolveField';
7
+ export * from './resolveForm';
@@ -0,0 +1,14 @@
1
+ /**
2
+
3
+ */
4
+ import type { TinaField } from '../types/index';
5
+ import type { TinaSchema } from './TinaSchema';
6
+ /**
7
+ * Turns a field the schema (schema.{js,ts} file) into a valid front end FieldConfig
8
+ */
9
+ export declare const resolveField: (field: TinaField<true>, schema: TinaSchema) => {
10
+ [key: string]: unknown;
11
+ name: string;
12
+ component: NonNullable<TinaField<true>["ui"]>["component"];
13
+ type: string;
14
+ };
@@ -0,0 +1,26 @@
1
+ /**
2
+
3
+ */
4
+ import type { Template, Collection } from '../types/index';
5
+ import type { TinaSchema } from './TinaSchema';
6
+ /**
7
+ * Given a collection, basename, template and schema. This will transform the given information into a valid frontend form config
8
+ */
9
+ export declare const resolveForm: ({ collection, basename, template, schema, }: ResolveFormArgs) => {
10
+ id: string;
11
+ label: string;
12
+ name: string;
13
+ fields: {
14
+ [key: string]: unknown;
15
+ name: string;
16
+ component: NonNullable<import("..").TinaField<true>["ui"]>["component"];
17
+ type: string;
18
+ }[];
19
+ };
20
+ type ResolveFormArgs = {
21
+ collection: Collection<true>;
22
+ basename: string;
23
+ template: Template<true>;
24
+ schema: TinaSchema;
25
+ };
26
+ export {};