@firecms/schema_inference 3.0.0-canary.231 → 3.0.0-canary.233
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/builders/reference_property_builder.d.ts +1 -1
- package/dist/builders/string_property_builder.d.ts +1 -1
- package/dist/builders/validation_builder.d.ts +1 -1
- package/dist/cms_types.d.ts +628 -0
- package/dist/collection_builder.d.ts +1 -1
- package/dist/index.es.js +56 -4
- package/dist/index.es.js.map +1 -1
- package/dist/index.umd.js +60 -7
- package/dist/index.umd.js.map +1 -1
- package/dist/types.d.ts +1 -1
- package/dist/util.d.ts +5 -0
- package/package.json +2 -3
- package/src/builders/reference_property_builder.ts +1 -1
- package/src/builders/string_property_builder.ts +1 -1
- package/src/builders/validation_builder.ts +1 -1
- package/src/cms_types.ts +798 -0
- package/src/collection_builder.ts +4 -12
- package/src/test_schemas/test_schema.ts +1 -1
- package/src/types.ts +1 -1
- package/src/util.ts +61 -1
@@ -1,3 +1,3 @@
|
|
1
|
-
import { PropertyValidationSchema } from "@firecms/core";
|
2
1
|
import { InferencePropertyBuilderProps } from "../types";
|
2
|
+
import { PropertyValidationSchema } from "../cms_types";
|
3
3
|
export declare function buildValidation({ totalDocsCount, valuesResult }: InferencePropertyBuilderProps): PropertyValidationSchema | undefined;
|
@@ -0,0 +1,628 @@
|
|
1
|
+
export type CMSType = string | number | boolean | Date | GeoPoint | EntityReference | Record<string, any> | CMSType[];
|
2
|
+
/**
|
3
|
+
* @group Entity properties
|
4
|
+
*/
|
5
|
+
export type DataType<T extends CMSType = CMSType> = T extends string ? "string" : T extends number ? "number" : T extends boolean ? "boolean" : T extends Date ? "date" : T extends GeoPoint ? "geopoint" : T extends Vector ? "vector" : T extends EntityReference ? "reference" : T extends Array<any> ? "array" : T extends Record<string, any> ? "map" : never;
|
6
|
+
/**
|
7
|
+
* New or existing status
|
8
|
+
* @group Models
|
9
|
+
*/
|
10
|
+
export type EntityStatus = "new" | "existing" | "copy";
|
11
|
+
/**
|
12
|
+
* Representation of an entity fetched from the datasource
|
13
|
+
* @group Models
|
14
|
+
*/
|
15
|
+
export interface Entity<M extends object = any> {
|
16
|
+
/**
|
17
|
+
* ID of the entity
|
18
|
+
*/
|
19
|
+
id: string;
|
20
|
+
/**
|
21
|
+
* A string representing the path of the referenced document (relative
|
22
|
+
* to the root of the database).
|
23
|
+
*/
|
24
|
+
path: string;
|
25
|
+
/**
|
26
|
+
* Current values
|
27
|
+
*/
|
28
|
+
values: EntityValues<M>;
|
29
|
+
databaseId?: string;
|
30
|
+
}
|
31
|
+
/**
|
32
|
+
* This type represents a record of key value pairs as described in an
|
33
|
+
* entity collection.
|
34
|
+
* @group Models
|
35
|
+
*/
|
36
|
+
export type EntityValues<M extends object> = M;
|
37
|
+
/**
|
38
|
+
* Class used to create a reference to an entity in a different path
|
39
|
+
*/
|
40
|
+
export declare class EntityReference {
|
41
|
+
/**
|
42
|
+
* ID of the entity
|
43
|
+
*/
|
44
|
+
readonly id: string;
|
45
|
+
/**
|
46
|
+
* A string representing the path of the referenced document (relative
|
47
|
+
* to the root of the database).
|
48
|
+
*/
|
49
|
+
readonly path: string;
|
50
|
+
constructor(id: string, path: string);
|
51
|
+
get pathWithId(): string;
|
52
|
+
isEntityReference(): boolean;
|
53
|
+
}
|
54
|
+
export declare class GeoPoint {
|
55
|
+
/**
|
56
|
+
* The latitude of this GeoPoint instance.
|
57
|
+
*/
|
58
|
+
readonly latitude: number;
|
59
|
+
/**
|
60
|
+
* The longitude of this GeoPoint instance.
|
61
|
+
*/
|
62
|
+
readonly longitude: number;
|
63
|
+
constructor(latitude: number, longitude: number);
|
64
|
+
}
|
65
|
+
export declare class Vector {
|
66
|
+
readonly value: number[];
|
67
|
+
constructor(value: number[]);
|
68
|
+
}
|
69
|
+
/**
|
70
|
+
* @group Entity properties
|
71
|
+
*/
|
72
|
+
export type Property<T extends CMSType = any> = T extends string ? StringProperty : T extends number ? NumberProperty : T extends boolean ? BooleanProperty : T extends Date ? DateProperty : T extends GeoPoint ? GeopointProperty : T extends EntityReference ? ReferenceProperty : T extends Array<CMSType> ? ArrayProperty<T> : T extends Record<string, any> ? MapProperty<T> : any;
|
73
|
+
/**
|
74
|
+
* Interface including all common properties of a CMS property
|
75
|
+
* @group Entity properties
|
76
|
+
*/
|
77
|
+
export interface BaseProperty<T extends CMSType, CustomProps = any> {
|
78
|
+
/**
|
79
|
+
* Datatype of the property
|
80
|
+
*/
|
81
|
+
dataType: DataType;
|
82
|
+
/**
|
83
|
+
* Property name (e.g. Product)
|
84
|
+
*/
|
85
|
+
name?: string;
|
86
|
+
/**
|
87
|
+
* Property description, always displayed under the field
|
88
|
+
*/
|
89
|
+
description?: string;
|
90
|
+
/**
|
91
|
+
* You can use this prop to reuse a property that has been defined
|
92
|
+
* in the top level of the CMS in the prop `fields`.
|
93
|
+
* All the configuration will be taken from the inherited config, and
|
94
|
+
* overwritten by the current property config.
|
95
|
+
*/
|
96
|
+
propertyConfig?: string;
|
97
|
+
/**
|
98
|
+
* Longer description of a field, displayed under a popover
|
99
|
+
*/
|
100
|
+
longDescription?: string;
|
101
|
+
/**
|
102
|
+
* Width in pixels of this column in the collection view. If not set
|
103
|
+
* the width is inferred based on the other configurations
|
104
|
+
*/
|
105
|
+
columnWidth?: number;
|
106
|
+
/**
|
107
|
+
* Do not show this property in the collection view
|
108
|
+
*/
|
109
|
+
hideFromCollection?: boolean;
|
110
|
+
/**
|
111
|
+
* Is this a read only property. When set to true, it gets rendered as a
|
112
|
+
* preview.
|
113
|
+
*/
|
114
|
+
readOnly?: boolean;
|
115
|
+
/**
|
116
|
+
* Is this field disabled.
|
117
|
+
* When set to true, it gets rendered as a
|
118
|
+
* disabled field. You can also specify a configuration for defining the
|
119
|
+
* behaviour of disabled properties (including custom messages, clear value on
|
120
|
+
* disabled or hide the field completely)
|
121
|
+
*/
|
122
|
+
disabled?: boolean | PropertyDisabledConfig;
|
123
|
+
/**
|
124
|
+
* Rules for validating this property
|
125
|
+
*/
|
126
|
+
validation?: PropertyValidationSchema;
|
127
|
+
/**
|
128
|
+
* Additional props that are passed to the components defined in `field`
|
129
|
+
* or in `preview`.
|
130
|
+
*/
|
131
|
+
customProps?: CustomProps;
|
132
|
+
/**
|
133
|
+
* This value will be set by default for new entities.
|
134
|
+
*/
|
135
|
+
defaultValue?: T | null;
|
136
|
+
/**
|
137
|
+
* Should this property be editable. If set to true, the user will be able to modify the property and
|
138
|
+
* save the new config. The saved config will then become the source of truth.
|
139
|
+
*/
|
140
|
+
editable?: boolean;
|
141
|
+
/**
|
142
|
+
* A number between 0 and 100 that indicates the width of the field in the form view.
|
143
|
+
* It defaults to 100, but you can set it to 50 to have two fields in the same row.
|
144
|
+
*/
|
145
|
+
widthPercentage?: number;
|
146
|
+
}
|
147
|
+
/**
|
148
|
+
* @group Entity properties
|
149
|
+
*/
|
150
|
+
export interface PropertyDisabledConfig {
|
151
|
+
/**
|
152
|
+
* Enable this flag if you would like to clear the value of the field
|
153
|
+
* when the corresponding property gets disabled.
|
154
|
+
*
|
155
|
+
* This is useful for keeping data consistency when you have conditional
|
156
|
+
* properties.
|
157
|
+
*/
|
158
|
+
clearOnDisabled?: boolean;
|
159
|
+
/**
|
160
|
+
* Explanation of why this property is disabled (e.g. a different field
|
161
|
+
* needs to be enabled)
|
162
|
+
*/
|
163
|
+
disabledMessage?: string;
|
164
|
+
/**
|
165
|
+
* Set this flag to true if you want to hide this field when disabled
|
166
|
+
*/
|
167
|
+
hidden?: boolean;
|
168
|
+
}
|
169
|
+
/**
|
170
|
+
* We use this type to define mapping between string or number values in
|
171
|
+
* the data source to a label (such in a select dropdown).
|
172
|
+
* The key in this Record is the value saved in the datasource, and the value in
|
173
|
+
* this record is the label displayed in the UI.
|
174
|
+
* You can add additional customization by assigning a {@link EnumValueConfig} for the
|
175
|
+
* label instead of a simple string (for enabling or disabling options and
|
176
|
+
* choosing colors).
|
177
|
+
* If you need to ensure the order of the elements use an array of {@link EnumValueConfig}
|
178
|
+
* @group Entity properties
|
179
|
+
*/
|
180
|
+
export type EnumValues = EnumValueConfig[] | Record<string | number, string | EnumValueConfig>;
|
181
|
+
/**
|
182
|
+
* Configuration for a particular entry in an `EnumValues`
|
183
|
+
* @group Entity properties
|
184
|
+
*/
|
185
|
+
export type EnumValueConfig = {
|
186
|
+
/**
|
187
|
+
* Value stored in the data source.
|
188
|
+
*/
|
189
|
+
id: string | number;
|
190
|
+
/**
|
191
|
+
* Displayed label
|
192
|
+
*/
|
193
|
+
label: string;
|
194
|
+
/**
|
195
|
+
* This value will not be selectable
|
196
|
+
*/
|
197
|
+
disabled?: boolean;
|
198
|
+
};
|
199
|
+
/**
|
200
|
+
* Record of properties of an entity or a map property
|
201
|
+
* @group Entity properties
|
202
|
+
*/
|
203
|
+
export type Properties<M extends Record<string, any> = any> = {
|
204
|
+
[k in keyof M]: Property<M[keyof M]>;
|
205
|
+
};
|
206
|
+
/**
|
207
|
+
* @group Entity properties
|
208
|
+
*/
|
209
|
+
export type PropertyOrBuilder<T extends CMSType = CMSType, M extends Record<string, any> = any> = Property<T>;
|
210
|
+
/**
|
211
|
+
* @group Entity properties
|
212
|
+
*/
|
213
|
+
export type PropertiesOrBuilders<M extends Record<string, any> = any> = {
|
214
|
+
[k in keyof M]: PropertyOrBuilder<M[k], M>;
|
215
|
+
};
|
216
|
+
/**
|
217
|
+
* @group Entity properties
|
218
|
+
*/
|
219
|
+
export interface NumberProperty extends BaseProperty<number> {
|
220
|
+
dataType: "number";
|
221
|
+
/**
|
222
|
+
* You can use the enum values providing a map of possible
|
223
|
+
* exclusive values the property can take, mapped to the label that it is
|
224
|
+
* displayed in the dropdown.
|
225
|
+
*/
|
226
|
+
enumValues?: EnumValues;
|
227
|
+
/**
|
228
|
+
* Rules for validating this property
|
229
|
+
*/
|
230
|
+
validation?: NumberPropertyValidationSchema;
|
231
|
+
/**
|
232
|
+
* Add an icon to clear the value and set it to `null`. Defaults to `false`
|
233
|
+
*/
|
234
|
+
clearable?: boolean;
|
235
|
+
}
|
236
|
+
/**
|
237
|
+
* @group Entity properties
|
238
|
+
*/
|
239
|
+
export interface BooleanProperty extends BaseProperty<boolean> {
|
240
|
+
dataType: "boolean";
|
241
|
+
/**
|
242
|
+
* Rules for validating this property
|
243
|
+
*/
|
244
|
+
validation?: PropertyValidationSchema;
|
245
|
+
}
|
246
|
+
/**
|
247
|
+
* @group Entity properties
|
248
|
+
*/
|
249
|
+
export interface StringProperty extends BaseProperty<string> {
|
250
|
+
dataType: "string";
|
251
|
+
/**
|
252
|
+
* Is this string property long enough so it should be displayed in
|
253
|
+
* a multiple line field. Defaults to false. If set to true,
|
254
|
+
* the number of lines adapts to the content
|
255
|
+
*/
|
256
|
+
multiline?: boolean;
|
257
|
+
/**
|
258
|
+
* Should this string property be displayed as a markdown field. If true,
|
259
|
+
* the field is rendered as a text editors that supports markdown highlight
|
260
|
+
* syntax. It also includes a preview of the result.
|
261
|
+
*/
|
262
|
+
markdown?: boolean;
|
263
|
+
/**
|
264
|
+
* You can use the enum values providing a map of possible
|
265
|
+
* exclusive values the property can take, mapped to the label that it is
|
266
|
+
* displayed in the dropdown. You can use a simple object with the format
|
267
|
+
* `value` => `label`, or with the format `value` => `EnumValueConfig` if you
|
268
|
+
* need extra customization, (like disabling specific options or assigning
|
269
|
+
* colors). If you need to ensure the order of the elements, you can pass
|
270
|
+
* a `Map` instead of a plain object.
|
271
|
+
*
|
272
|
+
*/
|
273
|
+
enumValues?: EnumValues;
|
274
|
+
/**
|
275
|
+
* You can specify a `Storage` configuration. It is used to
|
276
|
+
* indicate that this string refers to a path in your storage provider.
|
277
|
+
*/
|
278
|
+
storage?: StorageConfig;
|
279
|
+
/**
|
280
|
+
* If the value of this property is a URL, you can set this flag to true
|
281
|
+
* to add a link, or one of the supported media types to render a preview
|
282
|
+
*/
|
283
|
+
url?: boolean | PreviewType;
|
284
|
+
/**
|
285
|
+
* Does this field include an email
|
286
|
+
*/
|
287
|
+
email?: boolean;
|
288
|
+
/**
|
289
|
+
* Should this string be rendered as a tag instead of just text.
|
290
|
+
*/
|
291
|
+
previewAsTag?: boolean;
|
292
|
+
/**
|
293
|
+
* Rules for validating this property
|
294
|
+
*/
|
295
|
+
validation?: StringPropertyValidationSchema;
|
296
|
+
/**
|
297
|
+
* Add an icon to clear the value and set it to `null`. Defaults to `false`
|
298
|
+
*/
|
299
|
+
clearable?: boolean;
|
300
|
+
}
|
301
|
+
/**
|
302
|
+
* @group Entity properties
|
303
|
+
*/
|
304
|
+
export interface ArrayProperty<T extends ArrayT[] = any[], ArrayT extends CMSType = any> extends BaseProperty<T> {
|
305
|
+
dataType: "array";
|
306
|
+
/**
|
307
|
+
* The property of this array.
|
308
|
+
* You can specify any property (except another Array property)
|
309
|
+
* You can leave this field empty only if you are providing a custom field,
|
310
|
+
* or using the `oneOf` prop, otherwise an error will be thrown.
|
311
|
+
*/
|
312
|
+
of?: PropertyOrBuilder<ArrayT> | Property<ArrayT>[];
|
313
|
+
/**
|
314
|
+
* Use this field if you would like to have an array of typed objects.
|
315
|
+
* It is useful if you need to have values of different types in the same
|
316
|
+
* array.
|
317
|
+
* Each entry of the array is an object with the shape:
|
318
|
+
* ```
|
319
|
+
* { type: "YOUR_TYPE", value: "YOUR_VALUE"}
|
320
|
+
* ```
|
321
|
+
* Note that you can use any property so `value` can take any value (strings,
|
322
|
+
* numbers, array, objects...)
|
323
|
+
* You can customise the `type` and `value` fields to suit your needs.
|
324
|
+
*
|
325
|
+
* An example use case for this feature may be a blog entry, where you have
|
326
|
+
* images and text blocks using markdown.
|
327
|
+
*/
|
328
|
+
oneOf?: {
|
329
|
+
/**
|
330
|
+
* Record of properties, where the key is the `type` and the value
|
331
|
+
* is the corresponding property
|
332
|
+
*/
|
333
|
+
properties: Properties;
|
334
|
+
/**
|
335
|
+
* Order in which the properties are displayed.
|
336
|
+
* If you are specifying your collection as code, the order is the same as the
|
337
|
+
* one you define in `properties`, and you don't need to specify this prop.
|
338
|
+
*/
|
339
|
+
propertiesOrder?: string[];
|
340
|
+
/**
|
341
|
+
* Name of the field to use as the discriminator for type
|
342
|
+
* Defaults to `type`
|
343
|
+
*/
|
344
|
+
typeField?: string;
|
345
|
+
/**
|
346
|
+
* Name of the field to use as the value
|
347
|
+
* Defaults to `value`
|
348
|
+
*/
|
349
|
+
valueField?: string;
|
350
|
+
};
|
351
|
+
/**
|
352
|
+
* Rules for validating this property
|
353
|
+
*/
|
354
|
+
validation?: ArrayPropertyValidationSchema;
|
355
|
+
/**
|
356
|
+
* Should the field be initially expanded. Defaults to `true`
|
357
|
+
*/
|
358
|
+
expanded?: boolean;
|
359
|
+
/**
|
360
|
+
* Display the child properties directly, without being wrapped in an
|
361
|
+
* extendable panel.
|
362
|
+
*/
|
363
|
+
minimalistView?: boolean;
|
364
|
+
/**
|
365
|
+
* Can the elements in this array be reordered. Defaults to `true`.
|
366
|
+
* This prop has no effect if `disabled` is set to true.
|
367
|
+
*/
|
368
|
+
sortable?: boolean;
|
369
|
+
/**
|
370
|
+
* Can the elements in this array be added. Defaults to `true`
|
371
|
+
* This prop has no effect if `disabled` is set to true.
|
372
|
+
*/
|
373
|
+
canAddElements?: boolean;
|
374
|
+
}
|
375
|
+
/**
|
376
|
+
* @group Entity properties
|
377
|
+
*/
|
378
|
+
export interface MapProperty<T extends Record<string, CMSType> = Record<string, CMSType>> extends BaseProperty<T> {
|
379
|
+
dataType: "map";
|
380
|
+
/**
|
381
|
+
* Record of properties included in this map.
|
382
|
+
*/
|
383
|
+
properties?: PropertiesOrBuilders<T>;
|
384
|
+
/**
|
385
|
+
* Order in which the properties are displayed.
|
386
|
+
* If you are specifying your collection as code, the order is the same as the
|
387
|
+
* one you define in `properties`, and you don't need to specify this prop.
|
388
|
+
*/
|
389
|
+
propertiesOrder?: Extract<keyof T, string>[];
|
390
|
+
/**
|
391
|
+
* Rules for validating this property.
|
392
|
+
* NOTE: If you don't set `required` in the map property, an empty object
|
393
|
+
* will be considered valid, even if you set `required` in the properties.
|
394
|
+
*/
|
395
|
+
validation?: PropertyValidationSchema;
|
396
|
+
/**
|
397
|
+
* Properties that are displayed when rendered as a preview
|
398
|
+
*/
|
399
|
+
previewProperties?: Partial<Extract<keyof T, string>>[];
|
400
|
+
/**
|
401
|
+
* Allow the user to add only some keys in this map.
|
402
|
+
* By default, all properties of the map have the corresponding field in
|
403
|
+
* the form view. Setting this flag to true allows to pick only some.
|
404
|
+
* Useful for map that can have a lot of sub-properties that may not be
|
405
|
+
* needed
|
406
|
+
*/
|
407
|
+
pickOnlySomeKeys?: boolean;
|
408
|
+
/**
|
409
|
+
* Display the child properties as independent columns in the collection
|
410
|
+
* view
|
411
|
+
*/
|
412
|
+
spreadChildren?: boolean;
|
413
|
+
/**
|
414
|
+
* Display the child properties directly, without being wrapped in an
|
415
|
+
* extendable panel. Note that this will also hide the title of this property.
|
416
|
+
*/
|
417
|
+
minimalistView?: boolean;
|
418
|
+
/**
|
419
|
+
* Should the field be initially expanded. Defaults to `true`
|
420
|
+
*/
|
421
|
+
expanded?: boolean;
|
422
|
+
/**
|
423
|
+
* Render this map as a key-value table that allows to use
|
424
|
+
* arbitrary keys. You don't need to define the properties in this case.
|
425
|
+
*/
|
426
|
+
keyValue?: boolean;
|
427
|
+
}
|
428
|
+
/**
|
429
|
+
* @group Entity properties
|
430
|
+
*/
|
431
|
+
export interface DateProperty extends BaseProperty<Date> {
|
432
|
+
dataType: "date";
|
433
|
+
/**
|
434
|
+
* Set the granularity of the field to a date or date + time.
|
435
|
+
* Defaults to `date_time`.
|
436
|
+
*
|
437
|
+
*/
|
438
|
+
mode?: "date" | "date_time";
|
439
|
+
/**
|
440
|
+
* Rules for validating this property
|
441
|
+
*/
|
442
|
+
validation?: DatePropertyValidationSchema;
|
443
|
+
/**
|
444
|
+
* If this flag is set to `on_create` or `on_update` this timestamp is
|
445
|
+
* updated automatically on creation of the entity only or on every
|
446
|
+
* update (including creation). Useful for creating `created_on` or
|
447
|
+
* `updated_on` fields
|
448
|
+
*/
|
449
|
+
autoValue?: "on_create" | "on_update";
|
450
|
+
/**
|
451
|
+
* Add an icon to clear the value and set it to `null`. Defaults to `false`
|
452
|
+
*/
|
453
|
+
clearable?: boolean;
|
454
|
+
}
|
455
|
+
/**
|
456
|
+
* @group Entity properties
|
457
|
+
*/
|
458
|
+
export interface GeopointProperty extends BaseProperty<GeoPoint> {
|
459
|
+
dataType: "geopoint";
|
460
|
+
/**
|
461
|
+
* Rules for validating this property
|
462
|
+
*/
|
463
|
+
validation?: PropertyValidationSchema;
|
464
|
+
}
|
465
|
+
/**
|
466
|
+
* @group Entity properties
|
467
|
+
*/
|
468
|
+
export interface ReferenceProperty extends BaseProperty<EntityReference> {
|
469
|
+
dataType: "reference";
|
470
|
+
/**
|
471
|
+
* Absolute collection path of the collection this reference points to.
|
472
|
+
* The collection of the entity is inferred based on the root navigation, so
|
473
|
+
* the filters and search delegate existing there are applied to this view
|
474
|
+
* as well.
|
475
|
+
* You can leave this prop undefined if the path is not yet know, e.g.
|
476
|
+
* you are using a property builder and the path depends on a different
|
477
|
+
* property.
|
478
|
+
* Note that you can also use a collection alias.
|
479
|
+
*/
|
480
|
+
path?: string;
|
481
|
+
/**
|
482
|
+
* Properties that need to be rendered when displaying a preview of this
|
483
|
+
* reference. If not specified the first 3 are used. Only the first 3
|
484
|
+
* specified values are considered.
|
485
|
+
*/
|
486
|
+
previewProperties?: string[];
|
487
|
+
/**
|
488
|
+
* Should the reference include the ID of the entity. Defaults to `true`
|
489
|
+
*/
|
490
|
+
includeId?: boolean;
|
491
|
+
/**
|
492
|
+
* Should the reference include a link to the entity (open the entity details). Defaults to `true`
|
493
|
+
*/
|
494
|
+
includeEntityLink?: boolean;
|
495
|
+
}
|
496
|
+
export interface PropertyValidationSchema {
|
497
|
+
/**
|
498
|
+
* Is this field required
|
499
|
+
*/
|
500
|
+
required?: boolean;
|
501
|
+
/**
|
502
|
+
* Customize the required message when the property is not set
|
503
|
+
*/
|
504
|
+
requiredMessage?: string;
|
505
|
+
/**
|
506
|
+
* If the unique flag is set to `true`, you can only have one entity in the
|
507
|
+
* collection with this value.
|
508
|
+
*/
|
509
|
+
unique?: boolean;
|
510
|
+
/**
|
511
|
+
* If the uniqueInArray flag is set to `true`, you can only have this value
|
512
|
+
* once per entry in the parent `ArrayProperty`. It has no effect if this
|
513
|
+
* property is not a child of an `ArrayProperty`. It works on direct
|
514
|
+
* children of an `ArrayProperty` or first level children of `MapProperty`
|
515
|
+
*/
|
516
|
+
uniqueInArray?: boolean;
|
517
|
+
}
|
518
|
+
/**
|
519
|
+
* Validation rules for numbers
|
520
|
+
* @group Entity properties
|
521
|
+
*/
|
522
|
+
export interface NumberPropertyValidationSchema extends PropertyValidationSchema {
|
523
|
+
min?: number;
|
524
|
+
max?: number;
|
525
|
+
lessThan?: number;
|
526
|
+
moreThan?: number;
|
527
|
+
positive?: boolean;
|
528
|
+
negative?: boolean;
|
529
|
+
integer?: boolean;
|
530
|
+
}
|
531
|
+
/**
|
532
|
+
* Validation rules for strings
|
533
|
+
* @group Entity properties
|
534
|
+
*/
|
535
|
+
export interface StringPropertyValidationSchema extends PropertyValidationSchema {
|
536
|
+
length?: number;
|
537
|
+
min?: number;
|
538
|
+
max?: number;
|
539
|
+
matches?: string | RegExp;
|
540
|
+
/**
|
541
|
+
* Message displayed when the input does not satisfy the regex in `matches`
|
542
|
+
*/
|
543
|
+
matchesMessage?: string;
|
544
|
+
trim?: boolean;
|
545
|
+
lowercase?: boolean;
|
546
|
+
uppercase?: boolean;
|
547
|
+
}
|
548
|
+
/**
|
549
|
+
* Validation rules for dates
|
550
|
+
* @group Entity properties
|
551
|
+
*/
|
552
|
+
export interface DatePropertyValidationSchema extends PropertyValidationSchema {
|
553
|
+
min?: Date;
|
554
|
+
max?: Date;
|
555
|
+
}
|
556
|
+
/**
|
557
|
+
* Validation rules for arrays
|
558
|
+
* @group Entity properties
|
559
|
+
*/
|
560
|
+
export interface ArrayPropertyValidationSchema extends PropertyValidationSchema {
|
561
|
+
min?: number;
|
562
|
+
max?: number;
|
563
|
+
}
|
564
|
+
/**
|
565
|
+
* Additional configuration related to Storage related fields
|
566
|
+
* @group Entity properties
|
567
|
+
*/
|
568
|
+
export type StorageConfig = {
|
569
|
+
/**
|
570
|
+
* File MIME types that can be uploaded to this reference. Don't specify for
|
571
|
+
* all.
|
572
|
+
* Note that you can also use the asterisk notation, so `image/*`
|
573
|
+
* accepts any image file, and so on.
|
574
|
+
*/
|
575
|
+
acceptedFiles?: FileType[];
|
576
|
+
/**
|
577
|
+
* Specific metadata set in your uploaded file.
|
578
|
+
* For the default Firebase implementation, the values passed here are of type
|
579
|
+
* `firebase.storage.UploadMetadata`
|
580
|
+
*/
|
581
|
+
metadata?: Record<string, unknown>;
|
582
|
+
/**
|
583
|
+
* You can use this prop to customize the uploaded filename.
|
584
|
+
* You can use a function as a callback or a string where you
|
585
|
+
* specify some placeholders that get replaced with the corresponding values.
|
586
|
+
* - `{file}` - Full file name
|
587
|
+
* - `{file.name}` - Name of the file without extension
|
588
|
+
* - `{file.ext}` - Extension of the file
|
589
|
+
* - `{rand}` - Random value used to avoid name collisions
|
590
|
+
* - `{entityId}` - ID of the entity
|
591
|
+
* - `{propertyKey}` - ID of this property
|
592
|
+
* - `{path}` - Path of this entity
|
593
|
+
*
|
594
|
+
* @param context
|
595
|
+
*/
|
596
|
+
fileName?: string;
|
597
|
+
/**
|
598
|
+
* Absolute path in your bucket.
|
599
|
+
*
|
600
|
+
* You can use a function as a callback or a string where you
|
601
|
+
* specify some placeholders that get replaced with the corresponding values.
|
602
|
+
* - `{file}` - Full file name
|
603
|
+
* - `{file.name}` - Name of the file without extension
|
604
|
+
* - `{file.ext}` - Extension of the file
|
605
|
+
* - `{rand}` - Random value used to avoid name collisions
|
606
|
+
* - `{entityId}` - ID of the entity
|
607
|
+
* - `{propertyKey}` - ID of this property
|
608
|
+
* - `{path}` - Path of this entity
|
609
|
+
*/
|
610
|
+
storagePath: string;
|
611
|
+
/**
|
612
|
+
* When set to true, this flag indicates that the download URL of the file
|
613
|
+
* will be saved in the datasource, instead of the storage path.
|
614
|
+
*
|
615
|
+
* Note that the generated URL may use a token that, if disabled, may
|
616
|
+
* make the URL unusable and lose the original reference to Cloud Storage,
|
617
|
+
* so it is not encouraged to use this flag.
|
618
|
+
*
|
619
|
+
* Defaults to false.
|
620
|
+
*/
|
621
|
+
storeUrl?: boolean;
|
622
|
+
/**
|
623
|
+
* Define maximal file size in bytes
|
624
|
+
*/
|
625
|
+
maxSize?: number;
|
626
|
+
};
|
627
|
+
export type FileType = "image/*" | "video/*" | "audio/*" | "application/*" | "text/*" | "font/*" | string;
|
628
|
+
export type PreviewType = "image" | "video" | "audio" | "file";
|
@@ -1,4 +1,4 @@
|
|
1
|
-
import { DataType, Properties, PropertiesOrBuilders, Property } from "
|
1
|
+
import { DataType, Properties, PropertiesOrBuilders, Property } from "./cms_types";
|
2
2
|
export type InferenceTypeBuilder = (value: any) => DataType;
|
3
3
|
export declare function buildEntityPropertiesFromData(data: object[], getType: InferenceTypeBuilder): Promise<Properties>;
|
4
4
|
export declare function buildPropertyFromData(data: any[], property: Property, getType: InferenceTypeBuilder): Property;
|