@stackbit/cms-core 1.0.2-develop.1 → 1.0.2-develop.2

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.
Files changed (64) hide show
  1. package/dist/.tsbuildinfo +1 -1
  2. package/dist/content-store.d.ts +6 -1
  3. package/dist/content-store.d.ts.map +1 -1
  4. package/dist/content-store.js +37 -6
  5. package/dist/content-store.js.map +1 -1
  6. package/dist/types/content-store-api-document-fields.d.ts +3 -33
  7. package/dist/types/content-store-api-document-fields.d.ts.map +1 -1
  8. package/dist/types/content-store-document-fields.d.ts +1 -106
  9. package/dist/types/content-store-document-fields.d.ts.map +1 -1
  10. package/dist/types/content-store-documents.d.ts +4 -2
  11. package/dist/types/content-store-documents.d.ts.map +1 -1
  12. package/dist/types/custom-actions.d.ts +2 -3
  13. package/dist/types/custom-actions.d.ts.map +1 -1
  14. package/dist/types/index.d.ts +1 -0
  15. package/dist/types/index.d.ts.map +1 -1
  16. package/dist/types/index.js +1 -0
  17. package/dist/types/index.js.map +1 -1
  18. package/dist/utils/csi-to-api-docs-converter.d.ts +3 -9
  19. package/dist/utils/csi-to-api-docs-converter.d.ts.map +1 -1
  20. package/dist/utils/csi-to-api-docs-converter.js +23 -27
  21. package/dist/utils/csi-to-api-docs-converter.js.map +1 -1
  22. package/dist/utils/csi-to-store-docs-converter.d.ts.map +1 -1
  23. package/dist/utils/csi-to-store-docs-converter.js +0 -38
  24. package/dist/utils/csi-to-store-docs-converter.js.map +1 -1
  25. package/dist/utils/custom-actions.d.ts +2 -41
  26. package/dist/utils/custom-actions.d.ts.map +1 -1
  27. package/dist/utils/custom-actions.js +3 -198
  28. package/dist/utils/custom-actions.js.map +1 -1
  29. package/dist/utils/custom-search-filters.d.ts +12 -0
  30. package/dist/utils/custom-search-filters.d.ts.map +1 -0
  31. package/dist/utils/custom-search-filters.js +46 -0
  32. package/dist/utils/custom-search-filters.js.map +1 -0
  33. package/dist/utils/field-path-utils.d.ts +1 -1
  34. package/dist/utils/field-path-utils.d.ts.map +1 -1
  35. package/dist/utils/field-path-utils.js +4 -0
  36. package/dist/utils/field-path-utils.js.map +1 -1
  37. package/dist/utils/model-utils.d.ts.map +1 -1
  38. package/dist/utils/model-utils.js +21 -0
  39. package/dist/utils/model-utils.js.map +1 -1
  40. package/dist/utils/store-to-api-docs-converter.d.ts.map +1 -1
  41. package/dist/utils/store-to-api-docs-converter.js +26 -74
  42. package/dist/utils/store-to-api-docs-converter.js.map +1 -1
  43. package/dist/utils/store-to-api-v2-docs-converter.d.ts +2 -3
  44. package/dist/utils/store-to-api-v2-docs-converter.d.ts.map +1 -1
  45. package/dist/utils/store-to-api-v2-docs-converter.js +91 -148
  46. package/dist/utils/store-to-api-v2-docs-converter.js.map +1 -1
  47. package/package.json +5 -5
  48. package/src/content-store.ts +53 -8
  49. package/src/types/content-store-api-document-fields.ts +471 -0
  50. package/src/types/content-store-document-fields.ts +1 -50
  51. package/src/types/content-store-documents.ts +4 -2
  52. package/src/types/custom-actions.ts +2 -3
  53. package/src/types/index.ts +1 -0
  54. package/src/utils/csi-to-api-docs-converter.ts +27 -42
  55. package/src/utils/csi-to-store-docs-converter.ts +1 -42
  56. package/src/utils/custom-actions.ts +4 -277
  57. package/src/utils/field-path-utils.ts +6 -2
  58. package/src/utils/model-utils.ts +20 -2
  59. package/src/utils/store-to-api-docs-converter.ts +26 -79
  60. package/src/utils/store-to-api-v2-docs-converter.ts +441 -0
  61. package/dist/utils/file-cache.d.ts +0 -13
  62. package/dist/utils/file-cache.d.ts.map +0 -1
  63. package/dist/utils/file-cache.js +0 -69
  64. package/dist/utils/file-cache.js.map +0 -1
@@ -3,7 +3,6 @@ import path from 'path';
3
3
  import { omitByNil, omitByUndefined } from '@stackbit/utils';
4
4
  import * as CSITypes from '@stackbit/types';
5
5
  import * as ContentStoreTypes from '../types';
6
- import { APICustomActionField, APICustomActionObject } from '../types';
7
6
 
8
7
  export function mapDocumentsToLocalizedApiObjects({
9
8
  documents,
@@ -32,13 +31,12 @@ function documentToLocalizedApiObject({
32
31
  locale?: string;
33
32
  delegate: CSITypes.ConfigDelegate;
34
33
  }): ContentStoreTypes.APIDocumentObject {
35
- const { type, fields, getPreview, getDocumentActions, ...rest } = document;
34
+ const { fields, getPreview, ...rest } = document;
36
35
  return omitByUndefined({
37
36
  // for historical reasons, stackbit app works with { type: 'object' } not { type: 'document' }
38
37
  type: 'object',
39
- ...rest,
38
+ ..._.omit(rest, ['type']),
40
39
  srcObjectLabel: getPreview({ delegate, locale }).previewTitle,
41
- actions: getDocumentActions?.(),
42
40
  fields: toLocalizedAPIFields({ docFields: fields, delegate, locale })
43
41
  });
44
42
  }
@@ -129,9 +127,6 @@ function toLocalizedAPIField({
129
127
  locale: locale
130
128
  };
131
129
  }
132
- const { getFieldActions, ...restDocField } = docField;
133
- const fieldActions = getFieldActions?.({ locale: docField.localized ? locale : undefined });
134
- docField = restDocField;
135
130
  switch (docField.type) {
136
131
  case 'string':
137
132
  case 'text':
@@ -151,14 +146,12 @@ function toLocalizedAPIField({
151
146
  return {
152
147
  ...base,
153
148
  ...localeProps,
154
- ...localeFields(localized),
155
- actions: fieldActions
149
+ ...localeFields(localized)
156
150
  } as ContentStoreTypes.DocumentStringLikeFieldAPI;
157
151
  }
158
152
  return {
159
153
  ...docField,
160
- ...localeFields(docField.localized),
161
- actions: fieldActions
154
+ ...localeFields(docField.localized)
162
155
  };
163
156
  }
164
157
  case 'file':
@@ -172,21 +165,18 @@ function toLocalizedAPIField({
172
165
  return {
173
166
  ...base,
174
167
  ...localeProps,
175
- ...localeFields(localized),
176
- actions: fieldActions
168
+ ...localeFields(localized)
177
169
  };
178
170
  }
179
171
  return {
180
172
  ...base,
181
173
  isUnset: true,
182
- ...localeFields(localized),
183
- actions: fieldActions
174
+ ...localeFields(localized)
184
175
  };
185
176
  }
186
177
  return {
187
178
  ...docField,
188
- ...localeFields(docField.localized),
189
- actions: fieldActions
179
+ ...localeFields(docField.localized)
190
180
  };
191
181
  }
192
182
  case 'image': {
@@ -204,15 +194,13 @@ function toLocalizedAPIField({
204
194
  ...base,
205
195
  ...localeProps,
206
196
  fields,
207
- ...localeFields(localized),
208
- actions: fieldActions
197
+ ...localeFields(localized)
209
198
  };
210
199
  } else {
211
200
  result = {
212
201
  ...base,
213
202
  isUnset: true,
214
- ...localeFields(localized),
215
- actions: fieldActions
203
+ ...localeFields(localized)
216
204
  };
217
205
  }
218
206
  } else {
@@ -220,8 +208,7 @@ function toLocalizedAPIField({
220
208
  result = {
221
209
  ...docField,
222
210
  type: 'image',
223
- ...localeFields(docField.localized),
224
- actions: fieldActions
211
+ ...localeFields(docField.localized)
225
212
  };
226
213
  } else {
227
214
  const fields = toLocalizedAPIFields({
@@ -233,8 +220,7 @@ function toLocalizedAPIField({
233
220
  ...docField,
234
221
  type: 'image',
235
222
  fields,
236
- ...localeFields(docField.localized),
237
- actions: fieldActions
223
+ ...localeFields(docField.localized)
238
224
  };
239
225
  }
240
226
  }
@@ -245,8 +231,7 @@ function toLocalizedAPIField({
245
231
  const { localized, locales, ...base } = docField;
246
232
  const localeProps = locales && locale ? locales[locale] : undefined;
247
233
  if (localeProps) {
248
- const { fields, getPreview, getObjectActions, locale } = localeProps;
249
- const objectActions = getObjectActions?.();
234
+ const { fields, getPreview, locale } = localeProps;
250
235
  return {
251
236
  ...base,
252
237
  ...localeFields(localized),
@@ -255,7 +240,6 @@ function toLocalizedAPIField({
255
240
  delegate,
256
241
  locale
257
242
  }).previewTitle ?? (isListItem ? 'Item' : 'Object'),
258
- actions: concatObjectAndFieldActions(objectActions, fieldActions),
259
243
  fields: toLocalizedAPIFields({
260
244
  docFields: fields,
261
245
  delegate,
@@ -266,7 +250,6 @@ function toLocalizedAPIField({
266
250
  return {
267
251
  ...base,
268
252
  ...localeFields(localized),
269
- actions: fieldActions,
270
253
  isUnset: true
271
254
  };
272
255
  }
@@ -274,12 +257,10 @@ function toLocalizedAPIField({
274
257
  return {
275
258
  ...docField,
276
259
  type: 'object',
277
- ...localeFields(docField.localized),
278
- actions: fieldActions
260
+ ...localeFields(docField.localized)
279
261
  };
280
262
  }
281
- const { fields, getPreview, getObjectActions, ...rest } = docField;
282
- const objectActions = getObjectActions?.();
263
+ const { fields, getPreview, ...rest } = docField;
283
264
  return {
284
265
  ...rest,
285
266
  type: 'object',
@@ -288,7 +269,6 @@ function toLocalizedAPIField({
288
269
  delegate,
289
270
  locale
290
271
  }).previewTitle ?? (isListItem ? 'Item' : 'Object'),
291
- actions: concatObjectAndFieldActions(objectActions, fieldActions),
292
272
  fields: toLocalizedAPIFields({
293
273
  docFields: fields,
294
274
  delegate,
@@ -302,8 +282,7 @@ function toLocalizedAPIField({
302
282
  const { localized, locales, ...base } = docField;
303
283
  const localeProps = locales && locale ? locales[locale] : undefined;
304
284
  if (localeProps) {
305
- const { fields, getPreview, getObjectActions, ...rest } = localeProps;
306
- const objectActions = getObjectActions?.();
285
+ const { fields, getPreview, ...rest } = localeProps;
307
286
  return {
308
287
  ...base,
309
288
  ...rest,
@@ -313,7 +292,6 @@ function toLocalizedAPIField({
313
292
  delegate,
314
293
  locale
315
294
  }).previewTitle,
316
- actions: concatObjectAndFieldActions(objectActions, fieldActions),
317
295
  fields: toLocalizedAPIFields({
318
296
  docFields: fields,
319
297
  delegate,
@@ -325,20 +303,17 @@ function toLocalizedAPIField({
325
303
  ...base,
326
304
  type: 'object', // API uses 'object' not 'model'
327
305
  isUnset: true,
328
- ...localeFields(localized),
329
- actions: fieldActions
306
+ ...localeFields(localized)
330
307
  };
331
308
  }
332
309
  if (docField.isUnset) {
333
310
  return {
334
311
  ...docField,
335
312
  type: 'object', // API uses 'object' not 'model'
336
- ...localeFields(docField.localized),
337
- actions: fieldActions
313
+ ...localeFields(docField.localized)
338
314
  };
339
315
  } else {
340
- const { fields, getPreview, getObjectActions, ...rest } = docField;
341
- const objectActions = getObjectActions?.();
316
+ const { fields, getPreview, ...rest } = docField;
342
317
  return {
343
318
  ...rest,
344
319
  type: 'object', // API uses 'object' not 'model'
@@ -347,7 +322,6 @@ function toLocalizedAPIField({
347
322
  delegate,
348
323
  locale
349
324
  }).previewTitle,
350
- actions: concatObjectAndFieldActions(objectActions, fieldActions),
351
325
  fields: toLocalizedAPIFields({
352
326
  docFields: fields,
353
327
  delegate,
@@ -366,8 +340,7 @@ function toLocalizedAPIField({
366
340
  type: refType === 'asset' ? 'image' : 'object',
367
341
  isUnset: true,
368
342
  ...base,
369
- ...localeFields(localized),
370
- actions: fieldActions
343
+ ...localeFields(localized)
371
344
  } as ContentStoreTypes.DocumentObjectFieldAPI | ContentStoreTypes.DocumentImageFieldAPI;
372
345
  }
373
346
  return {
@@ -375,8 +348,7 @@ function toLocalizedAPIField({
375
348
  refType: refType === 'asset' ? 'image' : 'object',
376
349
  ...base,
377
350
  ...localeProps,
378
- ...localeFields(localized),
379
- actions: fieldActions
351
+ ...localeFields(localized)
380
352
  };
381
353
  }
382
354
  const { type, refType, ...base } = docField;
@@ -384,16 +356,14 @@ function toLocalizedAPIField({
384
356
  return {
385
357
  type: refType === 'asset' ? 'image' : 'object',
386
358
  ...base,
387
- ...localeFields(docField.localized),
388
- actions: fieldActions
359
+ ...localeFields(docField.localized)
389
360
  };
390
361
  }
391
362
  return {
392
363
  type: 'unresolved_reference',
393
364
  refType: refType === 'asset' ? 'image' : 'object',
394
365
  ...base,
395
- ...localeFields(docField.localized),
396
- actions: fieldActions
366
+ ...localeFields(docField.localized)
397
367
  };
398
368
  }
399
369
  case 'cross-reference': {
@@ -406,8 +376,7 @@ function toLocalizedAPIField({
406
376
  type: 'object',
407
377
  isUnset: true,
408
378
  ...base,
409
- ...localeFields(localized),
410
- actions: fieldActions
379
+ ...localeFields(localized)
411
380
  };
412
381
  }
413
382
  return {
@@ -415,8 +384,7 @@ function toLocalizedAPIField({
415
384
  refType: refType,
416
385
  ...base,
417
386
  ...localeProps,
418
- ...localeFields(localized),
419
- actions: fieldActions
387
+ ...localeFields(localized)
420
388
  };
421
389
  }
422
390
  const { type, refType, ...base } = docField;
@@ -424,16 +392,14 @@ function toLocalizedAPIField({
424
392
  return {
425
393
  type: 'object',
426
394
  ...base,
427
- ...localeFields(docField.localized),
428
- actions: fieldActions
395
+ ...localeFields(docField.localized)
429
396
  };
430
397
  }
431
398
  return {
432
399
  type: 'cross-reference',
433
400
  refType: refType,
434
401
  ...base,
435
- ...localeFields(docField.localized),
436
- actions: fieldActions
402
+ ...localeFields(docField.localized)
437
403
  };
438
404
  }
439
405
  case 'list': {
@@ -443,7 +409,6 @@ function toLocalizedAPIField({
443
409
  return {
444
410
  ...base,
445
411
  ...localeProps,
446
- actions: fieldActions,
447
412
  items: (localeProps?.items ?? []).map(
448
413
  (field) =>
449
414
  toLocalizedAPIField({
@@ -460,7 +425,6 @@ function toLocalizedAPIField({
460
425
  return {
461
426
  ...rest,
462
427
  ...localeFields(docField.localized),
463
- actions: fieldActions,
464
428
  items: items.map(
465
429
  (field) =>
466
430
  toLocalizedAPIField({
@@ -573,20 +537,3 @@ function replaceAssetUrlIfNeeded(staticAssetsPublicPath: string, value: string |
573
537
  }
574
538
  return url;
575
539
  }
576
-
577
- function concatObjectAndFieldActions(
578
- objectActions?: APICustomActionObject[],
579
- fieldActions?: APICustomActionField[]
580
- ): (APICustomActionObject | APICustomActionField)[] | undefined {
581
- let result: (APICustomActionObject | APICustomActionField)[] = [];
582
- if (fieldActions) {
583
- result = result.concat(fieldActions);
584
- }
585
- if (objectActions) {
586
- result = result.concat(objectActions);
587
- }
588
- if (result.length) {
589
- return result;
590
- }
591
- return undefined;
592
- }