@firecms/core 3.0.0-canary.51 → 3.0.0-canary.53

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.
@@ -38,7 +38,8 @@ export const resolveCollection = <M extends Record<string, any>, >
38
38
  values,
39
39
  previousValues,
40
40
  userConfigPersistence,
41
- fields
41
+ fields,
42
+ ignoreMissingFields = false
42
43
  }: {
43
44
  collection: EntityCollection<M> | ResolvedEntityCollection<M>;
44
45
  path: string,
@@ -47,6 +48,7 @@ export const resolveCollection = <M extends Record<string, any>, >
47
48
  previousValues?: Partial<EntityValues<M>>,
48
49
  userConfigPersistence?: UserConfigurationPersistence;
49
50
  fields?: Record<string, PropertyConfig>;
51
+ ignoreMissingFields?: boolean;
50
52
  }): ResolvedEntityCollection<M> => {
51
53
 
52
54
  const collectionOverride = userConfigPersistence?.getCollectionConfig<M>(path);
@@ -65,7 +67,8 @@ export const resolveCollection = <M extends Record<string, any>, >
65
67
  previousValues: usedPreviousValues,
66
68
  path,
67
69
  entityId,
68
- fields
70
+ fields,
71
+ ignoreMissingFields
69
72
  });
70
73
  if (!childResolvedProperty) return {};
71
74
  return ({
@@ -97,6 +100,7 @@ export const resolveCollection = <M extends Record<string, any>, >
97
100
  export function resolveProperty<T extends CMSType = CMSType, M extends Record<string, any> = any>({
98
101
  propertyOrBuilder,
99
102
  fromBuilder = false,
103
+ ignoreMissingFields = false,
100
104
  ...props
101
105
  }: {
102
106
  propertyKey?: string,
@@ -108,6 +112,7 @@ export function resolveProperty<T extends CMSType = CMSType, M extends Record<st
108
112
  index?: number,
109
113
  fromBuilder?: boolean;
110
114
  fields?: Record<string, PropertyConfig<any>>;
115
+ ignoreMissingFields?: boolean;
111
116
  }): ResolvedProperty<T> | null {
112
117
 
113
118
  if (typeof propertyOrBuilder === "object" && "resolved" in propertyOrBuilder) {
@@ -139,12 +144,14 @@ export function resolveProperty<T extends CMSType = CMSType, M extends Record<st
139
144
  resolvedProperty = resolveProperty({
140
145
  ...props,
141
146
  propertyOrBuilder: result,
142
- fromBuilder: true
147
+ fromBuilder: true,
148
+ ignoreMissingFields
143
149
  });
144
150
  } else {
145
151
  const property = propertyOrBuilder as Property<T>;
146
152
  if (property.dataType === "map" && property.properties) {
147
153
  const properties = resolveProperties({
154
+ ignoreMissingFields,
148
155
  ...props,
149
156
  properties: property.properties,
150
157
  });
@@ -158,6 +165,7 @@ export function resolveProperty<T extends CMSType = CMSType, M extends Record<st
158
165
  resolvedProperty = resolveArrayProperty({
159
166
  property,
160
167
  fromBuilder,
168
+ ignoreMissingFields,
161
169
  ...props
162
170
  }) as ResolvedProperty<any>;
163
171
  } else if ((property.dataType === "string" || property.dataType === "number") && property.enumValues) {
@@ -175,10 +183,10 @@ export function resolveProperty<T extends CMSType = CMSType, M extends Record<st
175
183
 
176
184
  if (resolvedProperty.propertyConfig && !isDefaultFieldConfigId(resolvedProperty.propertyConfig)) {
177
185
  const cmsFields = props.fields;
178
- if (!cmsFields) {
186
+ if (!cmsFields && !ignoreMissingFields) {
179
187
  throw Error(`Trying to resolve a property with key '${resolvedProperty.propertyConfig}' that inherits from a custom property config but no custom property configs were provided. Use the property 'propertyConfigs' in your app config to provide them`);
180
188
  }
181
- const customField: PropertyConfig<any> = cmsFields[resolvedProperty.propertyConfig];
189
+ const customField: PropertyConfig | undefined = cmsFields?.[resolvedProperty.propertyConfig];
182
190
  if (!customField) {
183
191
  console.warn(`Trying to resolve a property with key '${resolvedProperty.propertyConfig}' that inherits from a custom property config but no custom property config with that key was found. Check the 'propertyConfigs' in your app config`)
184
192
  console.warn("Available property configs", cmsFields);
@@ -191,6 +199,7 @@ export function resolveProperty<T extends CMSType = CMSType, M extends Record<st
191
199
  }
192
200
  const customFieldProperty = resolveProperty<any>({
193
201
  propertyOrBuilder: configPropertyOrBuilder,
202
+ ignoreMissingFields,
194
203
  ...props
195
204
  });
196
205
  if (customFieldProperty) {
@@ -211,6 +220,7 @@ export function resolveProperty<T extends CMSType = CMSType, M extends Record<st
211
220
  export function resolveArrayProperty<T extends any[], M>({
212
221
  propertyKey,
213
222
  property,
223
+ ignoreMissingFields = false,
214
224
  ...props
215
225
  }: {
216
226
  propertyKey?: string,
@@ -222,6 +232,7 @@ export function resolveArrayProperty<T extends any[], M>({
222
232
  index?: number,
223
233
  fromBuilder?: boolean;
224
234
  fields?: Record<string, PropertyConfig>;
235
+ ignoreMissingFields?: boolean;
225
236
  }): ResolvedArrayProperty {
226
237
  const propertyValue = propertyKey ? getIn(props.values, propertyKey) : undefined;
227
238
 
@@ -235,6 +246,7 @@ export function resolveArrayProperty<T extends any[], M>({
235
246
  return resolveProperty({
236
247
  propertyKey: `${propertyKey}.${index}`,
237
248
  propertyOrBuilder: p as Property<any>,
249
+ ignoreMissingFields,
238
250
  ...props,
239
251
  index
240
252
  });
@@ -246,6 +258,7 @@ export function resolveArrayProperty<T extends any[], M>({
246
258
  ? propertyValue.map((v: any, index: number) => resolveProperty({
247
259
  propertyKey: `${propertyKey}.${index}`,
248
260
  propertyOrBuilder: of,
261
+ ignoreMissingFields,
249
262
  ...props,
250
263
  index
251
264
  })).filter(e => Boolean(e)) as ResolvedProperty[]
@@ -253,9 +266,10 @@ export function resolveArrayProperty<T extends any[], M>({
253
266
  const ofProperty = resolveProperty({
254
267
  propertyKey: `${propertyKey}`,
255
268
  propertyOrBuilder: of,
269
+ ignoreMissingFields,
256
270
  ...props
257
271
  });
258
- if (!ofProperty)
272
+ if (!ofProperty && !ignoreMissingFields)
259
273
  throw Error("When using a property builder as the 'of' prop of an ArrayProperty, you must return a valid child property")
260
274
  return {
261
275
  ...property,
@@ -275,12 +289,14 @@ export function resolveArrayProperty<T extends any[], M>({
275
289
  return resolveProperty({
276
290
  propertyKey: `${propertyKey}.${index}`,
277
291
  propertyOrBuilder: childProperty,
292
+ ignoreMissingFields,
278
293
  ...props
279
294
  });
280
295
  }).filter(e => Boolean(e)) as ResolvedProperty[]
281
296
  : [];
282
297
  const properties = resolveProperties<any>({
283
298
  properties: property.oneOf.properties,
299
+ ignoreMissingFields,
284
300
  ...props
285
301
  });
286
302
  return {
@@ -312,6 +328,7 @@ export function resolveArrayProperty<T extends any[], M>({
312
328
  */
313
329
  export function resolveProperties<M extends Record<string, any>>({
314
330
  properties,
331
+ ignoreMissingFields,
315
332
  ...props
316
333
  }: {
317
334
  properties: PropertiesOrBuilders<M>,
@@ -322,12 +339,14 @@ export function resolveProperties<M extends Record<string, any>>({
322
339
  index?: number,
323
340
  fromBuilder?: boolean;
324
341
  fields?: Record<string, PropertyConfig>;
342
+ ignoreMissingFields?: boolean;
325
343
  }): ResolvedProperties<M> {
326
344
  return Object.entries<PropertyOrBuilder>(properties as Record<string, PropertyOrBuilder>)
327
345
  .map(([key, property]) => {
328
346
  const childResolvedProperty = resolveProperty({
329
347
  propertyKey: key,
330
348
  propertyOrBuilder: property,
349
+ ignoreMissingFields,
331
350
  ...props
332
351
  });
333
352
  if (!childResolvedProperty) return {};
@@ -349,7 +368,7 @@ export function resolvePropertyEnum(property: StringProperty | NumberProperty, f
349
368
  return {
350
369
  ...property,
351
370
  resolved: true,
352
- enumValues: enumToObjectEntries(property.enumValues)?.filter((value) => value && value.id && value.label) ?? [],
371
+ enumValues: enumToObjectEntries(property.enumValues)?.filter((value) => value && (value.id || value.id === 0) && value.label) ?? [],
353
372
  fromBuilder: fromBuilder ?? false
354
373
  }
355
374
  }