@tinacms/schema-tools 1.3.2 → 1.3.3

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.
@@ -1,475 +0,0 @@
1
- /**
2
-
3
- */
4
- import type { FC } from 'react';
5
- import { TinaSchema } from '../schema';
6
- import { Config } from '../types';
7
- import type { TinaCloudSchemaConfig } from './config';
8
- export declare type UIField<F extends UIField = any, Shape = any> = {
9
- label?: string;
10
- description?: string;
11
- component?: FC<any> | string | null;
12
- parse?: (value: Shape, name: string, field: F) => any;
13
- format?: (value: Shape, name: string, field: F) => any;
14
- validate?(value: Shape, allValues: any, meta: any, field: UIField<F, Shape>): string | object | undefined | void;
15
- /**
16
- * @deprecated use `defaultItem` at the collection level instead
17
- */
18
- defaultValue?: Shape;
19
- };
20
- export interface TinaCloudSchema<WithNamespace extends boolean, Store = any> {
21
- templates?: GlobalTemplate<WithNamespace>[];
22
- collections: TinaCloudCollection<WithNamespace>[];
23
- /**
24
- * @deprecated use `defineConfig` in a config.{js,ts} file instead
25
- */
26
- config?: Config;
27
- }
28
- export declare type TinaCloudSchemaBase = TinaCloudSchema<false>;
29
- export declare type TinaCloudSchemaEnriched = TinaCloudSchema<true>;
30
- /**
31
- * As part of the build process, each node is given a `path: string[]` key
32
- * to help with namespacing type names, this is added as part of the
33
- * createTinaSchema step
34
- */
35
- export interface TinaCloudSchemaWithNamespace {
36
- templates?: GlobalTemplate<true>[];
37
- collections: TinaCloudCollection<true>[];
38
- config?: TinaCloudSchemaConfig;
39
- namespace: string[];
40
- }
41
- export declare type TinaCloudCollection<WithNamespace extends boolean> = CollectionFields<WithNamespace> | CollectionTemplates<WithNamespace>;
42
- export declare type TinaCloudCollectionBase = TinaCloudCollection<false>;
43
- export declare type TinaCloudCollectionEnriched = TinaCloudCollection<true>;
44
- declare type FormatType = 'json' | 'md' | 'markdown' | 'mdx';
45
- declare type Document = {
46
- _sys: {
47
- title?: string;
48
- template: string;
49
- breadcrumbs: string[];
50
- path: string;
51
- basename: string;
52
- relativePath: string;
53
- filename: string;
54
- extension: string;
55
- };
56
- };
57
- export declare type TinaIndex = {
58
- name: string;
59
- fields: {
60
- name: string;
61
- }[];
62
- };
63
- export interface UICollection {
64
- /**
65
- * Customize the way filenames are generated during content creation
66
- */
67
- filename?: {
68
- /**
69
- * A callback which receives form values as an argument. The return value
70
- * here will be used as the filename (the extension is not necessary)
71
- *
72
- * eg:
73
- * ```ts
74
- * slugify: (values) => values.title.toLowerCase().split(" ").join("-")
75
- * ```
76
- */
77
- slugify?: (values: Record<string, any>) => string;
78
- /**
79
- * When set to `true`, editors won't be able to modify the filename
80
- */
81
- readonly?: boolean;
82
- };
83
- allowedActions?: {
84
- create?: boolean;
85
- delete?: boolean;
86
- };
87
- /**
88
- * Forms for this collection will be editable from the global sidebar rather than the form panel
89
- */
90
- global?: boolean | {
91
- icon?: any;
92
- layout: 'fullscreen' | 'popup';
93
- };
94
- /**
95
- * Provide the path that your document is viewable on your site
96
- *
97
- * eg:
98
- * ```ts
99
- * router: ({ document }) => {
100
- * return `blog-posts/${document._sys.filename}`;
101
- * }
102
- * ```
103
- */
104
- router?: (args: {
105
- document: Document;
106
- collection: TinaCloudCollection<true>;
107
- }) => string | undefined;
108
- }
109
- export declare type DefaultItem<ReturnType> = ReturnType | (() => ReturnType);
110
- interface BaseCollection {
111
- label?: string;
112
- name: string;
113
- path: string;
114
- defaultItem?: DefaultItem<Record<string, any>>;
115
- indexes?: TinaIndex[];
116
- format?: FormatType;
117
- /**
118
- * This format will be used to parse the markdown frontmatter
119
- */
120
- frontmatterFormat?: 'yaml' | 'toml' | 'json';
121
- /**
122
- * The delimiters used to parse the frontmatter.
123
- */
124
- frontmatterDelimiters?: [string, string] | string;
125
- ui?: UICollection;
126
- match?: string;
127
- }
128
- export declare type CollectionTemplates<WithNamespace extends boolean> = WithNamespace extends true ? CollectionTemplatesWithNamespace<WithNamespace> : CollectionTemplatesInner<WithNamespace>;
129
- export declare type TinaTemplate = Template<false>;
130
- interface CollectionTemplatesInner<WithNamespace extends boolean> extends BaseCollection {
131
- templates: (string | GlobalTemplate<WithNamespace>)[];
132
- fields?: undefined;
133
- }
134
- export interface CollectionTemplatesWithNamespace<WithNamespace extends boolean> extends BaseCollection {
135
- templates: (string | GlobalTemplate<WithNamespace>)[];
136
- fields?: undefined;
137
- references?: ReferenceType<WithNamespace>[];
138
- namespace: WithNamespace extends true ? string[] : undefined;
139
- }
140
- declare type CollectionFields<WithNamespace extends boolean> = WithNamespace extends true ? CollectionFieldsWithNamespace<WithNamespace> : CollectionFieldsInner<WithNamespace>;
141
- export interface CollectionFieldsWithNamespace<WithNamespace extends boolean> extends BaseCollection {
142
- fields: TinaFieldInner<WithNamespace>[];
143
- templates?: undefined;
144
- references?: ReferenceType<WithNamespace>[];
145
- namespace: string[];
146
- }
147
- interface CollectionFieldsInner<WithNamespace extends boolean> extends BaseCollection {
148
- fields: TinaFieldInner<WithNamespace>[];
149
- templates?: undefined;
150
- }
151
- export declare type TinaFieldInner<WithNamespace extends boolean> = ScalarType<WithNamespace> | ObjectType<WithNamespace> | ReferenceType<WithNamespace> | RichType<WithNamespace>;
152
- export declare type TinaFieldBase = TinaFieldInner<false>;
153
- export declare type TinaFieldEnriched = TinaFieldInner<true> & {
154
- /**
155
- * The parentTypename will always be an object type, either the type of a
156
- * collection (ie. `Post`) or of an object field (ie. `PageBlocks`).
157
- */
158
- parentTypename?: string;
159
- };
160
- export interface TinaField {
161
- name: string;
162
- label?: string;
163
- description?: string;
164
- required?: boolean;
165
- indexed?: boolean;
166
- /**
167
- * Any items passed to the UI field will be passed to the underlying field.
168
- * NOTE: only serializable values are supported, so functions like `validate`
169
- * will be ignored.
170
- */
171
- ui?: Record<string, any>;
172
- }
173
- declare type ScalarType<WithNamespace extends boolean> = WithNamespace extends true ? ScalarTypeWithNamespace : ScalarTypeInner;
174
- export declare type Option = string | {
175
- label?: string;
176
- icon?: FC;
177
- value: string;
178
- };
179
- declare type ScalarTypeInner = TinaField & TinaScalarField & {
180
- options?: Option[];
181
- };
182
- declare type ScalarTypeWithNamespace = TinaField & TinaScalarField & {
183
- options?: Option[];
184
- namespace: string[];
185
- };
186
- declare type TinaScalarField = StringField | BooleanField | DateTimeField | NumberField | ImageField;
187
- declare type StringField = {
188
- type: 'string';
189
- isBody?: boolean;
190
- list?: false;
191
- isTitle?: boolean;
192
- ui?: UIField<any, string>;
193
- } | {
194
- type: 'string';
195
- isBody?: boolean;
196
- list: true;
197
- isTitle?: never;
198
- ui?: UIField<any, string[]> & {
199
- defaultItem?: DefaultItem<string>;
200
- };
201
- };
202
- declare type BooleanField = {
203
- type: 'boolean';
204
- list?: false;
205
- ui?: object | UIField<any, boolean>;
206
- } | {
207
- type: 'boolean';
208
- list: true;
209
- ui?: object | UIField<any, boolean[]>;
210
- };
211
- declare type NumberField = {
212
- type: 'number';
213
- list?: false;
214
- ui?: object | UIField<any, number>;
215
- } | {
216
- type: 'number';
217
- list: true;
218
- ui?: object | UIField<any, number[]>;
219
- };
220
- declare type DateTimeField = {
221
- type: 'datetime';
222
- dateFormat?: string;
223
- timeFormat?: string;
224
- list?: false;
225
- ui?: object | UIField<any, string>;
226
- } | {
227
- type: 'datetime';
228
- dateFormat?: string;
229
- timeFormat?: string;
230
- list: true;
231
- ui?: object | UIField<any, string[]>;
232
- };
233
- declare type ImageField = {
234
- type: 'image';
235
- list?: false;
236
- ui?: object | UIField<any, string>;
237
- } | {
238
- type: 'image';
239
- list: true;
240
- ui?: object | UIField<any, string[]>;
241
- };
242
- export declare type ReferenceType<WithNamespace extends boolean> = WithNamespace extends true ? ReferenceTypeWithNamespace : ReferenceTypeInner;
243
- export declare type RichType<WithNamespace extends boolean> = WithNamespace extends true ? RichTypeWithNamespace : RichTypeInner;
244
- export interface ReferenceTypeInner extends TinaField {
245
- type: 'reference';
246
- list?: boolean;
247
- reverseLookup?: {
248
- label: string;
249
- name: string;
250
- };
251
- collections: string[];
252
- ui?: UIField<any, string[]>;
253
- }
254
- export interface ReferenceTypeWithNamespace extends TinaField {
255
- type: 'reference';
256
- list?: boolean;
257
- collections: string[];
258
- reverseLookup?: {
259
- label: string;
260
- name: string;
261
- };
262
- namespace: string[];
263
- ui?: UIField<any, string[]>;
264
- }
265
- export interface RichTypeWithNamespace extends TinaField {
266
- type: 'rich-text';
267
- namespace: string[];
268
- isBody?: boolean;
269
- list?: boolean;
270
- templates?: (string | (Template<true> & {
271
- inline?: boolean;
272
- }))[];
273
- }
274
- export interface RichTypeInner extends TinaField {
275
- type: 'rich-text';
276
- isBody?: boolean;
277
- list?: boolean;
278
- parser?: {
279
- type: 'markdown';
280
- skipEscaping?: 'all' | 'html' | 'none';
281
- } | {
282
- type: 'mdx';
283
- };
284
- templates?: (string | (Template<false> & {
285
- inline?: boolean;
286
- }))[];
287
- }
288
- export declare type ObjectType<WithNamespace extends boolean> = ObjectTemplates<WithNamespace> | ObjectFields<WithNamespace>;
289
- declare type ObjectTemplates<WithNamespace extends boolean> = WithNamespace extends true ? ObjectTemplatesWithNamespace<WithNamespace> : ObjectTemplatesInner<WithNamespace>;
290
- declare type ObjectTemplatesInner<WithNamespace extends boolean> = ObjectTemplatesInnerWithList<WithNamespace> | ObjectTemplatesInnerWithoutList<WithNamespace>;
291
- interface ObjectTemplatesInnerWithList<WithNamespace extends boolean> extends ObjectTemplatesInnerBase<WithNamespace> {
292
- list?: true;
293
- ui?: object | ({
294
- itemProps?(item: Record<string, any>): {
295
- key?: string;
296
- label?: string;
297
- };
298
- defaultItem?: DefaultItem<Record<string, any>>;
299
- } & UIField<any, string>);
300
- }
301
- interface ObjectTemplatesInnerWithoutList<WithNamespace extends boolean> extends ObjectTemplatesInnerBase<WithNamespace> {
302
- list?: false;
303
- ui?: object | UIField<any, string>;
304
- }
305
- interface ObjectTemplatesInnerBase<WithNamespace extends boolean> extends TinaField {
306
- type: 'object';
307
- visualSelector?: boolean;
308
- required?: false;
309
- list?: boolean;
310
- /**
311
- * templates can either be an array of Tina templates or a reference to
312
- * global template definition.
313
- *
314
- * You should use `templates` when your object can be any one of multiple shapes (polymorphic)
315
- *
316
- * You can only provide one of `fields` or `template`, but not both
317
- */
318
- templates: (string | Template<WithNamespace>)[];
319
- fields?: undefined;
320
- }
321
- interface ObjectTemplatesWithNamespace<WithNamespace extends boolean> extends TinaField {
322
- type: 'object';
323
- visualSelector?: boolean;
324
- required?: false;
325
- ui?: UIField<any, Record<string, any>> & {
326
- itemProps?(item: Record<string, any>): {
327
- key?: string;
328
- label?: string;
329
- };
330
- defaultItem?: DefaultItem<Record<string, any>>;
331
- };
332
- list?: boolean;
333
- /**
334
- * templates can either be an array of Tina templates or a reference to
335
- * global template definition.
336
- *
337
- * You should use `templates` when your object can be any one of multiple shapes (polymorphic)
338
- *
339
- * You can only provide one of `fields` or `template`, but not both
340
- */
341
- templates: (string | Template<WithNamespace>)[];
342
- fields?: undefined;
343
- namespace: WithNamespace extends true ? string[] : undefined;
344
- }
345
- declare type ObjectFields<WithNamespace extends boolean> = WithNamespace extends true ? InnerObjectFieldsWithNamespace<WithNamespace> : InnerObjectFields<WithNamespace>;
346
- interface InnerObjectFields<WithNamespace extends boolean> extends TinaField {
347
- type: 'object';
348
- visualSelector?: boolean;
349
- required?: false;
350
- ui?: UIField<any, Record<string, any>> & {
351
- itemProps?(item: Record<string, any>): {
352
- key?: string;
353
- label?: string;
354
- };
355
- defaultItem?: DefaultItem<Record<string, any>>;
356
- };
357
- /**
358
- * fields can either be an array of Tina fields, or a reference to the fields
359
- * of a global template definition.
360
- *
361
- * You can only provide one of `fields` or `templates`, but not both.
362
- */
363
- fields: string | TinaFieldInner<WithNamespace>[];
364
- templates?: undefined;
365
- list?: boolean;
366
- }
367
- interface InnerObjectFieldsWithNamespace<WithNamespace extends boolean> extends TinaField {
368
- type: 'object';
369
- visualSelector?: boolean;
370
- required?: false;
371
- ui?: UIField<any, Record<string, any>> & {
372
- itemProps?(item: Record<string, any>): {
373
- key?: string;
374
- label?: string;
375
- };
376
- defaultItem?: DefaultItem<Record<string, any>>;
377
- };
378
- /**
379
- * fields can either be an array of Tina fields, or a reference to the fields
380
- * of a global template definition.
381
- *
382
- * You can only provide one of `fields` or `templates`, but not both.
383
- */
384
- fields: string | TinaFieldInner<WithNamespace>[];
385
- templates?: undefined;
386
- namespace: WithNamespace extends true ? string[] : undefined;
387
- list?: boolean;
388
- }
389
- /**
390
- * Global Templates are defined once, and can be used anywhere by referencing the 'name' of the template
391
- *
392
- * TODO: ensure we don't permit infite loop with self-references
393
- */
394
- export declare type GlobalTemplate<WithNamespace extends boolean> = WithNamespace extends true ? {
395
- label: string;
396
- name: string;
397
- ui?: UICollection;
398
- fields: TinaFieldInner<WithNamespace>[];
399
- namespace: WithNamespace extends true ? string[] : undefined;
400
- } : {
401
- label: string;
402
- name: string;
403
- ui?: UICollection;
404
- fields: TinaFieldInner<WithNamespace>[];
405
- };
406
- export declare type TinaCloudTemplateBase = GlobalTemplate<false>;
407
- export declare type TinaCloudTemplateEnriched = GlobalTemplate<true>;
408
- /**
409
- * Templates allow you to define an object as polymorphic
410
- */
411
- export declare type Template<WithNamespace extends boolean> = WithNamespace extends true ? {
412
- label: string;
413
- name: string;
414
- fields: TinaFieldInner<WithNamespace>[];
415
- match?: {
416
- start: string;
417
- end: string;
418
- name?: string;
419
- };
420
- ui?: object | (UIField<any, any> & {
421
- previewSrc: string;
422
- });
423
- namespace: WithNamespace extends true ? string[] : undefined;
424
- } : {
425
- label: string;
426
- name: string;
427
- ui?: object | (UIField<any, any> & {
428
- previewSrc: string;
429
- });
430
- fields: TinaFieldInner<WithNamespace>[];
431
- match?: {
432
- start: string;
433
- end: string;
434
- name?: string;
435
- };
436
- };
437
- export declare type CollectionTemplateableUnion = {
438
- namespace: string[];
439
- type: 'union';
440
- templates: Templateable[];
441
- };
442
- export declare type CollectionTemplateableObject = {
443
- namespace: string[];
444
- type: 'object';
445
- visualSelector?: boolean;
446
- ui?: UIField<any, Record<string, any>> & {
447
- itemProps?(item: Record<string, any>): {
448
- key?: string;
449
- label?: string;
450
- };
451
- defaultItem?: DefaultItem<Record<string, any>>;
452
- };
453
- required?: false;
454
- template: Templateable;
455
- };
456
- export declare type CollectionTemplateable = CollectionTemplateableUnion | CollectionTemplateableObject;
457
- export declare type Collectable = {
458
- namespace: string[];
459
- templates?: (string | Templateable)[];
460
- fields?: string | TinaFieldEnriched[];
461
- references?: ReferenceType<true>[];
462
- };
463
- export declare type Templateable = {
464
- name: string;
465
- namespace: string[];
466
- fields: TinaFieldEnriched[];
467
- ui?: object;
468
- };
469
- export declare type ResolveFormArgs = {
470
- collection: TinaCloudCollection<true>;
471
- basename: string;
472
- template: Templateable;
473
- schema: TinaSchema;
474
- };
475
- export * from './config';
@@ -1,40 +0,0 @@
1
- /**
2
-
3
- */
4
- export interface TinaCloudSchemaConfig<Store = any> {
5
- client?: {
6
- referenceDepth?: number;
7
- };
8
- build?: {
9
- publicFolder: string;
10
- outputFolder: string;
11
- };
12
- /**
13
- * The base branch to pull content from. Note that this is ignored for local development
14
- */
15
- branch?: string;
16
- /**
17
- * Your clientId from app.tina.io
18
- */
19
- clientId?: string;
20
- /**
21
- * Your read only token from app.tina.io
22
- */
23
- token?: string;
24
- media?: {
25
- loadCustomStore?: () => Promise<Store>;
26
- tina?: {
27
- publicFolder: string;
28
- mediaRoot: string;
29
- };
30
- };
31
- /**
32
- * Used to override the default Tina Cloud API URL
33
- */
34
- tinaioConfig?: {
35
- assetsApiUrlOverride?: string;
36
- frontendUrlOverride?: string;
37
- identityApiUrlOverride?: string;
38
- contentApiUrlOverride?: string;
39
- };
40
- }
@@ -1,127 +0,0 @@
1
- /**
2
-
3
- */
4
- import { Option, UICollection } from './SchemaTypes';
5
- /**
6
- * NOTE this is WIP - it's not being used but ideally
7
- * we can start to leverage it for the `defineStaticConfig`
8
- *
9
- * The current schema type defs are way more complex to be
10
- * user-facing. This schema also gets rid of stuff we didn't
11
- * get around to implementing like `templates: string` (which
12
- * were for global templates)
13
- *
14
- */
15
- declare type FC<T> = (props: T) => unknown;
16
- declare type UIField<Type> = {
17
- label?: string;
18
- description?: string;
19
- component?: FC<any> | string | null;
20
- parse?: (value: Type, name: string, field: Field) => any;
21
- format?: (value: Type, name: string, field: Field) => any;
22
- validate?(value: Type, allValues: any, meta: any): Type | undefined | void;
23
- /**
24
- * @deprecated use `defaultItem` at the collection level instead
25
- */
26
- defaultValue?: Type;
27
- };
28
- declare type FieldGeneric<Type> = {
29
- required: true;
30
- list: true;
31
- ui?: UIField<Type[]>;
32
- } | {
33
- required: true;
34
- list?: false | undefined;
35
- ui?: UIField<Type>;
36
- } | {
37
- required?: false | undefined;
38
- list: true;
39
- ui?: UIField<Type[] | undefined>;
40
- } | {
41
- required?: false | undefined;
42
- list?: false | undefined;
43
- ui?: UIField<Type | undefined>;
44
- };
45
- declare type BaseField<Type, Ui extends object = undefined> = {
46
- name: string;
47
- label?: string;
48
- description?: string;
49
- ui?: Ui extends object ? UIField<Type> & Ui : UIField<Type>;
50
- } & FieldGeneric<Type>;
51
- declare type StringFieldBase = {
52
- type: 'string';
53
- /** Designate this field's value as the document title */
54
- isTitle?: boolean;
55
- options?: Option[];
56
- } & BaseField<string>;
57
- declare type StringField = StringFieldBase & FieldGeneric<string>;
58
- declare type NumberField = {
59
- type: 'number';
60
- } & BaseField<number>;
61
- declare type BooleanField = {
62
- type: 'boolean';
63
- } & BaseField<boolean>;
64
- declare type DateTimeField = {
65
- type: 'datetime';
66
- } & BaseField<string>;
67
- declare type ImageField = {
68
- type: 'image';
69
- } & BaseField<string>;
70
- declare type ReferenceField = {
71
- type: 'reference';
72
- collections: string[];
73
- } & BaseField<string>;
74
- declare type RichTextField = {
75
- type: 'rich-text';
76
- /**
77
- * For markdown or MDX formats, this value will be
78
- * saved to the document body
79
- */
80
- isBody?: boolean;
81
- } & BaseField<object> & WithTemplates<true>;
82
- declare type ObjectField = ({
83
- type: 'object';
84
- } & BaseField<object, {
85
- itemProps?(item: Record<string, any>): {
86
- key?: string;
87
- label?: string;
88
- };
89
- }>) & (WithFields | WithTemplates);
90
- declare type Field = StringField | NumberField | BooleanField | DateTimeField | ImageField | ReferenceField | RichTextField | ObjectField;
91
- declare type WithFields = {
92
- fields: Field[];
93
- templates?: never;
94
- };
95
- declare type Template = {
96
- name: string;
97
- label?: string;
98
- fields: Field[];
99
- match?: {
100
- start: string;
101
- end: string;
102
- name?: string;
103
- };
104
- };
105
- declare type WithTemplates<Optional extends boolean = false> = Optional extends true ? {
106
- templates?: Template[];
107
- fields?: never;
108
- } : {
109
- templates: Template[];
110
- fields?: never;
111
- };
112
- declare type TinaCMSCollection = {
113
- label?: string;
114
- name: string;
115
- path: string;
116
- format?: 'json' | 'md' | 'markdown' | 'mdx';
117
- match?: string;
118
- ui?: UICollection;
119
- } & (WithTemplates | WithFields);
120
- /**
121
- * @deprecated use TinaCMSSchema instead
122
- */
123
- export declare type TinaCloudSchema = TinaCMSSchema;
124
- export declare type TinaCMSSchema = {
125
- collections: TinaCMSCollection[];
126
- };
127
- export {};