@tinacms/schema-tools 0.0.0-00f6525-20241015065741

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,81 @@
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
+ getCollection: (collectionName: string) => Collection<true>;
32
+ getCollections: () => Collection<true>[];
33
+ getCollectionByFullPath: (filepath: string) => Collection<true>;
34
+ getCollectionAndTemplateByFullPath: (filepath: string, templateName?: string) => {
35
+ collection: Collection<true>;
36
+ template: Template<true>;
37
+ } | undefined;
38
+ getTemplateForData: ({ data, collection, }: {
39
+ data?: unknown;
40
+ collection: Collectable;
41
+ }) => Template<true>;
42
+ transformPayload: (collectionName: string, payload: object) => {
43
+ [x: string]: {
44
+ [key: string]: unknown;
45
+ };
46
+ };
47
+ private transformCollectablePayload;
48
+ private transformField;
49
+ isMarkdownCollection: (collectionName: string) => boolean;
50
+ /**
51
+ * Gets the template or templates from the item.
52
+ * Both `object` fields and collections support
53
+ * the ability for an object to be polymorphic,
54
+ * and if it is, we need to build unions, which
55
+ * are more of a headache for non-polymorphic
56
+ * needs, so we also need the ability to just
57
+ * build object types
58
+ *
59
+ *
60
+ */
61
+ getTemplatesForCollectable: (collection: Collectable) => CollectionTemplateable;
62
+ walkFields: (cb: (args: {
63
+ field: TinaField;
64
+ collection: Collection;
65
+ path: string[];
66
+ }) => void) => void;
67
+ /**
68
+ * This function returns an array of glob matches for a given collection.
69
+ *
70
+ * @param collection The collection to get the matches for. Can be a string or a collection object.
71
+ * @returns An array of glob matches.
72
+ */
73
+ getMatches({ collection: collectionOrString, }: {
74
+ collection: string | Collection;
75
+ }): string[];
76
+ matchFiles({ collection, files, }: {
77
+ collection: string | Collection;
78
+ files: string[];
79
+ }): string[];
80
+ }
81
+ export {};
@@ -0,0 +1,4 @@
1
+ /**
2
+
3
+ */
4
+ export declare function addNamespaceToSchema<T extends object | string>(maybeNode: T, namespace?: string[]): T;
@@ -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("../types/index").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 {};