@tinacms/schema-tools 0.1.8 → 0.2.0
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.es.js +15 -4
- package/dist/index.js +15 -4
- package/dist/types/SchemaTypes.d.ts +20 -2
- package/dist/types/schema2.d.ts +122 -0
- package/dist/validate/index.d.ts +2 -2
- package/package.json +2 -2
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;
|
|
@@ -813,10 +824,10 @@ class TinaSchemaValidationError extends Error {
|
|
|
813
824
|
}
|
|
814
825
|
}
|
|
815
826
|
const validateSchema = ({
|
|
816
|
-
|
|
827
|
+
schema
|
|
817
828
|
}) => {
|
|
818
829
|
try {
|
|
819
|
-
TinaCloudSchemaZod.parse(
|
|
830
|
+
TinaCloudSchemaZod.parse(schema);
|
|
820
831
|
} catch (e) {
|
|
821
832
|
if (e instanceof ZodError) {
|
|
822
833
|
const errors = parseZodError({ zodError: e });
|
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;
|
|
@@ -840,10 +851,10 @@ ${JSON.stringify(val, null, 2)}
|
|
|
840
851
|
}
|
|
841
852
|
}
|
|
842
853
|
const validateSchema = ({
|
|
843
|
-
|
|
854
|
+
schema
|
|
844
855
|
}) => {
|
|
845
856
|
try {
|
|
846
|
-
TinaCloudSchemaZod.parse(
|
|
857
|
+
TinaCloudSchemaZod.parse(schema);
|
|
847
858
|
} catch (e) {
|
|
848
859
|
if (e instanceof z.ZodError) {
|
|
849
860
|
const errors = parseZodError({ zodError: e });
|
|
@@ -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/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 {};
|
package/dist/validate/index.d.ts
CHANGED
|
@@ -15,6 +15,6 @@ export { validateTinaCloudSchemaConfig } from './tinaCloudSchemaConfig';
|
|
|
15
15
|
export declare class TinaSchemaValidationError extends Error {
|
|
16
16
|
constructor(message: any);
|
|
17
17
|
}
|
|
18
|
-
export declare const validateSchema: ({
|
|
19
|
-
|
|
18
|
+
export declare const validateSchema: ({ schema, }: {
|
|
19
|
+
schema: TinaCloudSchema<false>;
|
|
20
20
|
}) => void;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tinacms/schema-tools",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"main": "dist/index.js",
|
|
5
5
|
"module": "./dist/index.es.js",
|
|
6
6
|
"exports": {
|
|
@@ -23,7 +23,7 @@
|
|
|
23
23
|
]
|
|
24
24
|
},
|
|
25
25
|
"devDependencies": {
|
|
26
|
-
"@tinacms/scripts": "0.51.
|
|
26
|
+
"@tinacms/scripts": "0.51.3",
|
|
27
27
|
"@types/yup": "^0.29.10",
|
|
28
28
|
"jest": "^27.0.6",
|
|
29
29
|
"react": "17.0.2",
|