@tinacms/schema-tools 0.1.9 → 0.2.1
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 -1
- package/dist/index.es.js +14 -3
- package/dist/index.js +14 -3
- package/dist/schema/TinaSchema.d.ts +3 -3
- package/dist/schema/resolveField.d.ts +1 -1
- package/dist/schema/resolveForm.d.ts +1 -1
- package/dist/types/SchemaTypes.d.ts +20 -2
- package/dist/types/index.d.ts +0 -1
- package/dist/types/schema2.d.ts +122 -0
- package/dist/types/types2.d.ts +453 -0
- package/dist/types.d.ts +462 -0
- package/dist/types.es.js +1 -0
- package/dist/types.js +5 -0
- package/dist/validate/index.d.ts +3 -2
- package/dist/validate/tinaCloudSchemaConfig.d.ts +1 -1
- package/package.json +9 -1
- package/dist/types/SchemaTypes2.d.ts +0 -101
package/dist/index.d.ts
CHANGED
package/dist/index.es.js
CHANGED
|
@@ -263,12 +263,23 @@ class TinaSchema {
|
|
|
263
263
|
assertShape(value, (yup2) => yup2.array(yup2.object({ _template: yup2.string().required() })));
|
|
264
264
|
return value.map((item) => {
|
|
265
265
|
const { _template, ...rest } = item;
|
|
266
|
-
|
|
266
|
+
const template = field.templates.find((template2) => {
|
|
267
|
+
if (typeof template2 === "string") {
|
|
268
|
+
return false;
|
|
269
|
+
}
|
|
270
|
+
return template2.name === _template;
|
|
271
|
+
});
|
|
272
|
+
if (typeof template === "string") {
|
|
273
|
+
throw new Error("Global templates not supported");
|
|
274
|
+
}
|
|
275
|
+
return {
|
|
276
|
+
[_template]: this.transformCollectablePayload(rest, template)
|
|
277
|
+
};
|
|
267
278
|
});
|
|
268
279
|
} else {
|
|
269
280
|
assertShape(value, (yup2) => yup2.object({ _template: yup2.string().required() }));
|
|
270
281
|
const { _template, ...rest } = value;
|
|
271
|
-
return { [_template]: rest };
|
|
282
|
+
return { [_template]: this.transformCollectablePayload(rest, field) };
|
|
272
283
|
}
|
|
273
284
|
} else {
|
|
274
285
|
return value;
|
|
@@ -587,7 +598,7 @@ const ReferenceField = FieldWithList.extend({
|
|
|
587
598
|
});
|
|
588
599
|
const TinaFieldZod = z.lazy(() => {
|
|
589
600
|
const TemplateTemp = z.object({
|
|
590
|
-
label: z.string(),
|
|
601
|
+
label: z.string().optional(),
|
|
591
602
|
name: nameProp,
|
|
592
603
|
fields: z.array(TinaFieldZod),
|
|
593
604
|
match: z.object({
|
package/dist/index.js
CHANGED
|
@@ -290,12 +290,23 @@
|
|
|
290
290
|
assertShape(value, (yup2) => yup2.array(yup2.object({ _template: yup2.string().required() })));
|
|
291
291
|
return value.map((item) => {
|
|
292
292
|
const { _template, ...rest } = item;
|
|
293
|
-
|
|
293
|
+
const template = field.templates.find((template2) => {
|
|
294
|
+
if (typeof template2 === "string") {
|
|
295
|
+
return false;
|
|
296
|
+
}
|
|
297
|
+
return template2.name === _template;
|
|
298
|
+
});
|
|
299
|
+
if (typeof template === "string") {
|
|
300
|
+
throw new Error("Global templates not supported");
|
|
301
|
+
}
|
|
302
|
+
return {
|
|
303
|
+
[_template]: this.transformCollectablePayload(rest, template)
|
|
304
|
+
};
|
|
294
305
|
});
|
|
295
306
|
} else {
|
|
296
307
|
assertShape(value, (yup2) => yup2.object({ _template: yup2.string().required() }));
|
|
297
308
|
const { _template, ...rest } = value;
|
|
298
|
-
return { [_template]: rest };
|
|
309
|
+
return { [_template]: this.transformCollectablePayload(rest, field) };
|
|
299
310
|
}
|
|
300
311
|
} else {
|
|
301
312
|
return value;
|
|
@@ -614,7 +625,7 @@
|
|
|
614
625
|
});
|
|
615
626
|
const TinaFieldZod = z.z.lazy(() => {
|
|
616
627
|
const TemplateTemp = z.z.object({
|
|
617
|
-
label: z.z.string(),
|
|
628
|
+
label: z.z.string().optional(),
|
|
618
629
|
name: nameProp,
|
|
619
630
|
fields: z.z.array(TinaFieldZod),
|
|
620
631
|
match: z.z.object({
|
|
@@ -10,7 +10,7 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
10
10
|
See the License for the specific language governing permissions and
|
|
11
11
|
limitations under the License.
|
|
12
12
|
*/
|
|
13
|
-
import { TinaCloudSchemaEnriched, TinaCloudSchemaBase, TinaCloudCollection, Templateable, Collectable, CollectionTemplateable } from '../types';
|
|
13
|
+
import { TinaCloudSchemaEnriched, TinaCloudSchemaBase, TinaCloudCollection, Templateable, Collectable, CollectionTemplateable } from '../types/index';
|
|
14
14
|
declare type Version = {
|
|
15
15
|
fullVersion: string;
|
|
16
16
|
major: string;
|
|
@@ -49,8 +49,8 @@ export declare class TinaSchema {
|
|
|
49
49
|
getGlobalTemplate: (templateName: string) => {
|
|
50
50
|
label: string;
|
|
51
51
|
name: string;
|
|
52
|
-
ui?: import("../types").UICollection;
|
|
53
|
-
fields: import("../types").TinaFieldInner<true>[];
|
|
52
|
+
ui?: import("../types/SchemaTypes").UICollection;
|
|
53
|
+
fields: import("../types/SchemaTypes").TinaFieldInner<true>[];
|
|
54
54
|
namespace: string[];
|
|
55
55
|
};
|
|
56
56
|
getCollectionByFullPath: (filepath: string) => TinaCloudCollection<true>;
|
|
@@ -10,7 +10,7 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
10
10
|
See the License for the specific language governing permissions and
|
|
11
11
|
limitations under the License.
|
|
12
12
|
*/
|
|
13
|
-
import { TinaFieldEnriched } from '../types';
|
|
13
|
+
import { TinaFieldEnriched } from '../types/index';
|
|
14
14
|
import { TinaSchema } from './TinaSchema';
|
|
15
15
|
/**
|
|
16
16
|
*
|
|
@@ -10,7 +10,7 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
10
10
|
See the License for the specific language governing permissions and
|
|
11
11
|
limitations under the License.
|
|
12
12
|
*/
|
|
13
|
-
import type { ResolveFormArgs } from '../types';
|
|
13
|
+
import type { ResolveFormArgs } from '../types/index';
|
|
14
14
|
/**
|
|
15
15
|
* Given a collection, basename, template and schema. This will transform the given information into a valid frontend form config
|
|
16
16
|
*/
|
|
@@ -28,6 +28,9 @@ export declare type UIField<F extends UIField = any, Shape = any> = {
|
|
|
28
28
|
export interface TinaCloudSchema<WithNamespace extends boolean, Store = any> {
|
|
29
29
|
templates?: GlobalTemplate<WithNamespace>[];
|
|
30
30
|
collections: TinaCloudCollection<WithNamespace>[];
|
|
31
|
+
/**
|
|
32
|
+
* @deprecated use `defineConfig` in a config.{js,ts} file instead
|
|
33
|
+
*/
|
|
31
34
|
config?: TinaCloudSchemaConfig<Store>;
|
|
32
35
|
}
|
|
33
36
|
export declare type TinaCloudSchemaBase = TinaCloudSchema<false>;
|
|
@@ -66,8 +69,23 @@ export declare type TinaIndex = {
|
|
|
66
69
|
}[];
|
|
67
70
|
};
|
|
68
71
|
export interface UICollection {
|
|
72
|
+
/**
|
|
73
|
+
* Customize the way filenames are generated during content creation
|
|
74
|
+
*/
|
|
69
75
|
filename?: {
|
|
76
|
+
/**
|
|
77
|
+
* A callback which receives form values as an argument. The return value
|
|
78
|
+
* here will be used as the filename (the extension is not necessary)
|
|
79
|
+
*
|
|
80
|
+
* eg:
|
|
81
|
+
* ```ts
|
|
82
|
+
* slugify: (values) => values.title.toLowerCase().split(" ").join("-")
|
|
83
|
+
* ```
|
|
84
|
+
*/
|
|
70
85
|
slugify?: (values: Record<string, any>) => string;
|
|
86
|
+
/**
|
|
87
|
+
* When set to `true`, editors won't be able to modify the filename
|
|
88
|
+
*/
|
|
71
89
|
readonly?: boolean;
|
|
72
90
|
};
|
|
73
91
|
/**
|
|
@@ -92,7 +110,7 @@ export interface UICollection {
|
|
|
92
110
|
collection: TinaCloudCollection<true>;
|
|
93
111
|
}) => string | undefined;
|
|
94
112
|
}
|
|
95
|
-
declare type DefaultItem<ReturnType> = ReturnType | (() => ReturnType);
|
|
113
|
+
export declare type DefaultItem<ReturnType> = ReturnType | (() => ReturnType);
|
|
96
114
|
interface BaseCollection {
|
|
97
115
|
label?: string;
|
|
98
116
|
name: string;
|
|
@@ -149,7 +167,7 @@ export interface TinaField {
|
|
|
149
167
|
ui?: Record<string, any>;
|
|
150
168
|
}
|
|
151
169
|
declare type ScalarType<WithNamespace extends boolean> = WithNamespace extends true ? ScalarTypeWithNamespace : ScalarTypeInner;
|
|
152
|
-
declare type Option = string | {
|
|
170
|
+
export declare type Option = string | {
|
|
153
171
|
label: string;
|
|
154
172
|
value: string;
|
|
155
173
|
};
|
package/dist/types/index.d.ts
CHANGED
package/dist/types/schema2.d.ts
CHANGED
|
@@ -10,4 +10,126 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
10
10
|
See the License for the specific language governing permissions and
|
|
11
11
|
limitations under the License.
|
|
12
12
|
*/
|
|
13
|
+
import { Option, UICollection } from './SchemaTypes';
|
|
14
|
+
/**
|
|
15
|
+
* NOTE this is WIP - it's not being used but ideally
|
|
16
|
+
* we can start to leverage it for the `defineStaticConfig`
|
|
17
|
+
*
|
|
18
|
+
* The current schema type defs are way more complex to be
|
|
19
|
+
* user-facing. This schema also gets rid of stuff we didn't
|
|
20
|
+
* get around to implementing like `templates: string` (which
|
|
21
|
+
* were for global templates)
|
|
22
|
+
*
|
|
23
|
+
*/
|
|
24
|
+
declare type FC<T> = (props: T) => unknown;
|
|
25
|
+
declare type UIField<Type> = {
|
|
26
|
+
label?: string;
|
|
27
|
+
description?: string;
|
|
28
|
+
component?: FC<any> | string | null;
|
|
29
|
+
parse?: (value: Type, name: string, field: Field) => any;
|
|
30
|
+
format?: (value: Type, name: string, field: Field) => any;
|
|
31
|
+
validate?(value: Type, allValues: any, meta: any): Type | undefined | void;
|
|
32
|
+
/**
|
|
33
|
+
* @deprecated use `defaultItem` at the collection level instead
|
|
34
|
+
*/
|
|
35
|
+
defaultValue?: Type;
|
|
36
|
+
};
|
|
37
|
+
declare type FieldGeneric<Type> = {
|
|
38
|
+
required: true;
|
|
39
|
+
list: true;
|
|
40
|
+
ui?: UIField<Type[]>;
|
|
41
|
+
} | {
|
|
42
|
+
required: true;
|
|
43
|
+
list?: false | undefined;
|
|
44
|
+
ui?: UIField<Type>;
|
|
45
|
+
} | {
|
|
46
|
+
required?: false | undefined;
|
|
47
|
+
list: true;
|
|
48
|
+
ui?: UIField<Type[] | undefined>;
|
|
49
|
+
} | {
|
|
50
|
+
required?: false | undefined;
|
|
51
|
+
list?: false | undefined;
|
|
52
|
+
ui?: UIField<Type | undefined>;
|
|
53
|
+
};
|
|
54
|
+
declare type BaseField<Type, Ui extends object = undefined> = {
|
|
55
|
+
name: string;
|
|
56
|
+
label?: string;
|
|
57
|
+
description?: string;
|
|
58
|
+
ui?: Ui extends object ? UIField<Type> & Ui : UIField<Type>;
|
|
59
|
+
} & FieldGeneric<Type>;
|
|
60
|
+
declare type StringFieldBase = {
|
|
61
|
+
type: 'string';
|
|
62
|
+
/** Designate this field's value as the document title */
|
|
63
|
+
isTitle?: boolean;
|
|
64
|
+
options?: Option[];
|
|
65
|
+
} & BaseField<string>;
|
|
66
|
+
declare type StringField = StringFieldBase & FieldGeneric<string>;
|
|
67
|
+
declare type NumberField = {
|
|
68
|
+
type: 'number';
|
|
69
|
+
} & BaseField<number>;
|
|
70
|
+
declare type BooleanField = {
|
|
71
|
+
type: 'boolean';
|
|
72
|
+
} & BaseField<boolean>;
|
|
73
|
+
declare type DateTimeField = {
|
|
74
|
+
type: 'datetime';
|
|
75
|
+
} & BaseField<string>;
|
|
76
|
+
declare type ImageField = {
|
|
77
|
+
type: 'image';
|
|
78
|
+
} & BaseField<string>;
|
|
79
|
+
declare type ReferenceField = {
|
|
80
|
+
type: 'reference';
|
|
81
|
+
collections: string[];
|
|
82
|
+
} & BaseField<string>;
|
|
83
|
+
declare type RichTextField = {
|
|
84
|
+
type: 'rich-text';
|
|
85
|
+
/**
|
|
86
|
+
* For markdown or MDX formats, this value will be
|
|
87
|
+
* saved to the document body
|
|
88
|
+
*/
|
|
89
|
+
isBody?: boolean;
|
|
90
|
+
} & BaseField<object> & WithTemplates<true>;
|
|
91
|
+
declare type ObjectField = ({
|
|
92
|
+
type: 'object';
|
|
93
|
+
} & BaseField<object, {
|
|
94
|
+
itemProps?(item: Record<string, any>): {
|
|
95
|
+
key?: string;
|
|
96
|
+
label?: string;
|
|
97
|
+
};
|
|
98
|
+
}>) & (WithFields | WithTemplates);
|
|
99
|
+
declare type Field = StringField | NumberField | BooleanField | DateTimeField | ImageField | ReferenceField | RichTextField | ObjectField;
|
|
100
|
+
declare type WithFields = {
|
|
101
|
+
fields: Field[];
|
|
102
|
+
templates?: never;
|
|
103
|
+
};
|
|
104
|
+
declare type Template = {
|
|
105
|
+
name: string;
|
|
106
|
+
label?: string;
|
|
107
|
+
fields: Field[];
|
|
108
|
+
match?: {
|
|
109
|
+
start: string;
|
|
110
|
+
end: string;
|
|
111
|
+
};
|
|
112
|
+
};
|
|
113
|
+
declare type WithTemplates<Optional extends boolean = false> = Optional extends true ? {
|
|
114
|
+
templates?: Template[];
|
|
115
|
+
fields?: never;
|
|
116
|
+
} : {
|
|
117
|
+
templates: Template[];
|
|
118
|
+
fields?: never;
|
|
119
|
+
};
|
|
120
|
+
declare type TinaCMSCollection = {
|
|
121
|
+
label?: string;
|
|
122
|
+
name: string;
|
|
123
|
+
path: string;
|
|
124
|
+
format?: 'json' | 'md' | 'markdown' | 'mdx';
|
|
125
|
+
match?: string;
|
|
126
|
+
ui?: UICollection;
|
|
127
|
+
} & (WithTemplates | WithFields);
|
|
128
|
+
/**
|
|
129
|
+
* @deprecated use TinaCMSSchema instead
|
|
130
|
+
*/
|
|
131
|
+
export declare type TinaCloudSchema = TinaCMSSchema;
|
|
132
|
+
export declare type TinaCMSSchema = {
|
|
133
|
+
collections: TinaCMSCollection[];
|
|
134
|
+
};
|
|
13
135
|
export {};
|