datocms-plugin-sdk 2.0.4 → 2.0.5

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 (131) hide show
  1. package/dist/cjs/guardUtils.js +33 -0
  2. package/dist/cjs/guardUtils.js.map +1 -0
  3. package/dist/cjs/hooks/assetSources.js +25 -0
  4. package/dist/cjs/hooks/assetSources.js.map +1 -1
  5. package/dist/cjs/hooks/buildItemPresentationInfo.js +13 -0
  6. package/dist/cjs/hooks/buildItemPresentationInfo.js.map +1 -1
  7. package/dist/cjs/hooks/contentAreaSidebarItems.js +17 -0
  8. package/dist/cjs/hooks/contentAreaSidebarItems.js.map +1 -1
  9. package/dist/cjs/hooks/customBlockStylesForStructuredTextField.js +14 -0
  10. package/dist/cjs/hooks/customBlockStylesForStructuredTextField.js.map +1 -1
  11. package/dist/cjs/hooks/customMarksForStructuredTextField.js +18 -0
  12. package/dist/cjs/hooks/customMarksForStructuredTextField.js.map +1 -1
  13. package/dist/cjs/hooks/initialLocationQueryForItemSelector.js +12 -0
  14. package/dist/cjs/hooks/initialLocationQueryForItemSelector.js.map +1 -1
  15. package/dist/cjs/hooks/itemCollectionOutlets.js +13 -0
  16. package/dist/cjs/hooks/itemCollectionOutlets.js.map +1 -1
  17. package/dist/cjs/hooks/itemFormOutlets.js +13 -0
  18. package/dist/cjs/hooks/itemFormOutlets.js.map +1 -1
  19. package/dist/cjs/hooks/itemFormSidebarPanels.js +17 -0
  20. package/dist/cjs/hooks/itemFormSidebarPanels.js.map +1 -1
  21. package/dist/cjs/hooks/itemFormSidebars.js +15 -0
  22. package/dist/cjs/hooks/itemFormSidebars.js.map +1 -1
  23. package/dist/cjs/hooks/mainNavigationTabs.js +17 -0
  24. package/dist/cjs/hooks/mainNavigationTabs.js.map +1 -1
  25. package/dist/cjs/hooks/manualFieldExtensions.js +25 -0
  26. package/dist/cjs/hooks/manualFieldExtensions.js.map +1 -1
  27. package/dist/cjs/hooks/overrideFieldExtensions.js +46 -0
  28. package/dist/cjs/hooks/overrideFieldExtensions.js.map +1 -1
  29. package/dist/cjs/hooks/uploadSidebarPanels.js +17 -0
  30. package/dist/cjs/hooks/uploadSidebarPanels.js.map +1 -1
  31. package/dist/cjs/hooks/uploadSidebars.js +15 -0
  32. package/dist/cjs/hooks/uploadSidebars.js.map +1 -1
  33. package/dist/cjs/icon.js +9 -0
  34. package/dist/cjs/icon.js.map +1 -1
  35. package/dist/cjs/manifest.js +17 -17
  36. package/dist/cjs/shared.js +25 -0
  37. package/dist/cjs/shared.js.map +1 -1
  38. package/dist/esm/guardUtils.d.ts +7 -0
  39. package/dist/esm/guardUtils.js +24 -0
  40. package/dist/esm/guardUtils.js.map +1 -0
  41. package/dist/esm/hooks/assetSources.d.ts +11 -1
  42. package/dist/esm/hooks/assetSources.js +24 -1
  43. package/dist/esm/hooks/assetSources.js.map +1 -1
  44. package/dist/esm/hooks/buildItemPresentationInfo.d.ts +11 -0
  45. package/dist/esm/hooks/buildItemPresentationInfo.js +12 -1
  46. package/dist/esm/hooks/buildItemPresentationInfo.js.map +1 -1
  47. package/dist/esm/hooks/contentAreaSidebarItems.d.ts +11 -0
  48. package/dist/esm/hooks/contentAreaSidebarItems.js +16 -1
  49. package/dist/esm/hooks/contentAreaSidebarItems.js.map +1 -1
  50. package/dist/esm/hooks/customBlockStylesForStructuredTextField.d.ts +11 -1
  51. package/dist/esm/hooks/customBlockStylesForStructuredTextField.js +13 -1
  52. package/dist/esm/hooks/customBlockStylesForStructuredTextField.js.map +1 -1
  53. package/dist/esm/hooks/customMarksForStructuredTextField.d.ts +11 -1
  54. package/dist/esm/hooks/customMarksForStructuredTextField.js +17 -1
  55. package/dist/esm/hooks/customMarksForStructuredTextField.js.map +1 -1
  56. package/dist/esm/hooks/initialLocationQueryForItemSelector.d.ts +11 -0
  57. package/dist/esm/hooks/initialLocationQueryForItemSelector.js +11 -1
  58. package/dist/esm/hooks/initialLocationQueryForItemSelector.js.map +1 -1
  59. package/dist/esm/hooks/itemCollectionOutlets.d.ts +11 -1
  60. package/dist/esm/hooks/itemCollectionOutlets.js +12 -1
  61. package/dist/esm/hooks/itemCollectionOutlets.js.map +1 -1
  62. package/dist/esm/hooks/itemFormOutlets.d.ts +11 -0
  63. package/dist/esm/hooks/itemFormOutlets.js +12 -1
  64. package/dist/esm/hooks/itemFormOutlets.js.map +1 -1
  65. package/dist/esm/hooks/itemFormSidebarPanels.d.ts +12 -0
  66. package/dist/esm/hooks/itemFormSidebarPanels.js +16 -1
  67. package/dist/esm/hooks/itemFormSidebarPanels.js.map +1 -1
  68. package/dist/esm/hooks/itemFormSidebars.d.ts +12 -0
  69. package/dist/esm/hooks/itemFormSidebars.js +14 -1
  70. package/dist/esm/hooks/itemFormSidebars.js.map +1 -1
  71. package/dist/esm/hooks/mainNavigationTabs.d.ts +11 -1
  72. package/dist/esm/hooks/mainNavigationTabs.js +16 -1
  73. package/dist/esm/hooks/mainNavigationTabs.js.map +1 -1
  74. package/dist/esm/hooks/manualFieldExtensions.d.ts +12 -0
  75. package/dist/esm/hooks/manualFieldExtensions.js +24 -1
  76. package/dist/esm/hooks/manualFieldExtensions.js.map +1 -1
  77. package/dist/esm/hooks/overrideFieldExtensions.d.ts +20 -0
  78. package/dist/esm/hooks/overrideFieldExtensions.js +43 -1
  79. package/dist/esm/hooks/overrideFieldExtensions.js.map +1 -1
  80. package/dist/esm/hooks/uploadSidebarPanels.d.ts +12 -0
  81. package/dist/esm/hooks/uploadSidebarPanels.js +16 -1
  82. package/dist/esm/hooks/uploadSidebarPanels.js.map +1 -1
  83. package/dist/esm/hooks/uploadSidebars.d.ts +12 -0
  84. package/dist/esm/hooks/uploadSidebars.js +14 -1
  85. package/dist/esm/hooks/uploadSidebars.js.map +1 -1
  86. package/dist/esm/icon.d.ts +1 -0
  87. package/dist/esm/icon.js +8 -1
  88. package/dist/esm/icon.js.map +1 -1
  89. package/dist/esm/manifest.js +17 -17
  90. package/dist/esm/shared.d.ts +12 -0
  91. package/dist/esm/shared.js +23 -1
  92. package/dist/esm/shared.js.map +1 -1
  93. package/dist/types/guardUtils.d.ts +7 -0
  94. package/dist/types/hooks/assetSources.d.ts +11 -1
  95. package/dist/types/hooks/buildItemPresentationInfo.d.ts +11 -0
  96. package/dist/types/hooks/contentAreaSidebarItems.d.ts +11 -0
  97. package/dist/types/hooks/customBlockStylesForStructuredTextField.d.ts +11 -1
  98. package/dist/types/hooks/customMarksForStructuredTextField.d.ts +11 -1
  99. package/dist/types/hooks/initialLocationQueryForItemSelector.d.ts +11 -0
  100. package/dist/types/hooks/itemCollectionOutlets.d.ts +11 -1
  101. package/dist/types/hooks/itemFormOutlets.d.ts +11 -0
  102. package/dist/types/hooks/itemFormSidebarPanels.d.ts +12 -0
  103. package/dist/types/hooks/itemFormSidebars.d.ts +12 -0
  104. package/dist/types/hooks/mainNavigationTabs.d.ts +11 -1
  105. package/dist/types/hooks/manualFieldExtensions.d.ts +12 -0
  106. package/dist/types/hooks/overrideFieldExtensions.d.ts +20 -0
  107. package/dist/types/hooks/uploadSidebarPanels.d.ts +12 -0
  108. package/dist/types/hooks/uploadSidebars.d.ts +12 -0
  109. package/dist/types/icon.d.ts +1 -0
  110. package/dist/types/shared.d.ts +12 -0
  111. package/manifest.json +17 -17
  112. package/package.json +2 -2
  113. package/src/guardUtils.ts +34 -0
  114. package/src/hooks/assetSources.ts +32 -2
  115. package/src/hooks/buildItemPresentationInfo.ts +22 -0
  116. package/src/hooks/contentAreaSidebarItems.ts +32 -1
  117. package/src/hooks/customBlockStylesForStructuredTextField.ts +23 -1
  118. package/src/hooks/customMarksForStructuredTextField.ts +33 -2
  119. package/src/hooks/initialLocationQueryForItemSelector.ts +21 -1
  120. package/src/hooks/itemCollectionOutlets.ts +22 -1
  121. package/src/hooks/itemFormOutlets.ts +20 -0
  122. package/src/hooks/itemFormSidebarPanels.ts +34 -0
  123. package/src/hooks/itemFormSidebars.ts +23 -0
  124. package/src/hooks/mainNavigationTabs.ts +32 -2
  125. package/src/hooks/manualFieldExtensions.ts +42 -0
  126. package/src/hooks/overrideFieldExtensions.ts +64 -0
  127. package/src/hooks/uploadSidebarPanels.ts +34 -0
  128. package/src/hooks/uploadSidebars.ts +23 -0
  129. package/src/icon.ts +12 -0
  130. package/src/manifest.ts +17 -17
  131. package/src/shared.ts +48 -1
package/manifest.json CHANGED
@@ -55,7 +55,7 @@
55
55
  "returnType": "UploadSidebar[]",
56
56
  "location": {
57
57
  "filePath": "src/hooks/uploadSidebars.ts",
58
- "lineNumber": 10
58
+ "lineNumber": 11
59
59
  }
60
60
  },
61
61
  "uploadSidebarPanels": {
@@ -73,7 +73,7 @@
73
73
  "returnType": "UploadSidebarPanel[]",
74
74
  "location": {
75
75
  "filePath": "src/hooks/uploadSidebarPanels.ts",
76
- "lineNumber": 10
76
+ "lineNumber": 18
77
77
  }
78
78
  },
79
79
  "settingsAreaSidebarItemGroups": {
@@ -1478,7 +1478,7 @@
1478
1478
  "itemType": {
1479
1479
  "location": {
1480
1480
  "filePath": "src/hooks/overrideFieldExtensions.ts",
1481
- "lineNumber": 22
1481
+ "lineNumber": 31
1482
1482
  },
1483
1483
  "type": "ItemType"
1484
1484
  }
@@ -1490,7 +1490,7 @@
1490
1490
  "returnType": "FieldExtensionOverride | undefined",
1491
1491
  "location": {
1492
1492
  "filePath": "src/hooks/overrideFieldExtensions.ts",
1493
- "lineNumber": 15
1493
+ "lineNumber": 24
1494
1494
  }
1495
1495
  },
1496
1496
  "onBoot": {
@@ -1618,7 +1618,7 @@
1618
1618
  "returnType": "ManualFieldExtension[]",
1619
1619
  "location": {
1620
1620
  "filePath": "src/hooks/manualFieldExtensions.ts",
1621
- "lineNumber": 10
1621
+ "lineNumber": 18
1622
1622
  }
1623
1623
  },
1624
1624
  "mainNavigationTabs": {
@@ -1636,7 +1636,7 @@
1636
1636
  "returnType": "MainNavigationTab[]",
1637
1637
  "location": {
1638
1638
  "filePath": "src/hooks/mainNavigationTabs.ts",
1639
- "lineNumber": 11
1639
+ "lineNumber": 18
1640
1640
  }
1641
1641
  },
1642
1642
  "itemsDropdownActions": {
@@ -1694,7 +1694,7 @@
1694
1694
  "returnType": "ItemFormSidebar[]",
1695
1695
  "location": {
1696
1696
  "filePath": "src/hooks/itemFormSidebars.ts",
1697
- "lineNumber": 13
1697
+ "lineNumber": 14
1698
1698
  }
1699
1699
  },
1700
1700
  "itemFormSidebarPanels": {
@@ -1717,7 +1717,7 @@
1717
1717
  "returnType": "ItemFormSidebarPanel[]",
1718
1718
  "location": {
1719
1719
  "filePath": "src/hooks/itemFormSidebarPanels.ts",
1720
- "lineNumber": 14
1720
+ "lineNumber": 22
1721
1721
  }
1722
1722
  },
1723
1723
  "itemFormOutlets": {
@@ -1740,7 +1740,7 @@
1740
1740
  "returnType": "ItemFormOutlet[]",
1741
1741
  "location": {
1742
1742
  "filePath": "src/hooks/itemFormOutlets.ts",
1743
- "lineNumber": 13
1743
+ "lineNumber": 14
1744
1744
  }
1745
1745
  },
1746
1746
  "itemFormDropdownActions": {
@@ -1875,7 +1875,7 @@
1875
1875
  "returnType": "ItemCollectionOutlet[]",
1876
1876
  "location": {
1877
1877
  "filePath": "src/hooks/itemCollectionOutlets.ts",
1878
- "lineNumber": 13
1878
+ "lineNumber": 14
1879
1879
  }
1880
1880
  },
1881
1881
  "initialLocationQueryForItemSelector": {
@@ -2649,7 +2649,7 @@
2649
2649
  "itemType": {
2650
2650
  "location": {
2651
2651
  "filePath": "src/hooks/customMarksForStructuredTextField.ts",
2652
- "lineNumber": 22
2652
+ "lineNumber": 29
2653
2653
  },
2654
2654
  "type": "ItemType"
2655
2655
  }
@@ -2661,7 +2661,7 @@
2661
2661
  "returnType": "StructuredTextCustomMark[] | undefined",
2662
2662
  "location": {
2663
2663
  "filePath": "src/hooks/customMarksForStructuredTextField.ts",
2664
- "lineNumber": 15
2664
+ "lineNumber": 22
2665
2665
  }
2666
2666
  },
2667
2667
  "customBlockStylesForStructuredTextField": {
@@ -2684,7 +2684,7 @@
2684
2684
  "itemType": {
2685
2685
  "location": {
2686
2686
  "filePath": "src/hooks/customBlockStylesForStructuredTextField.ts",
2687
- "lineNumber": 22
2687
+ "lineNumber": 23
2688
2688
  },
2689
2689
  "type": "ItemType"
2690
2690
  }
@@ -2696,7 +2696,7 @@
2696
2696
  "returnType": "StructuredTextCustomBlockStyle[] | undefined",
2697
2697
  "location": {
2698
2698
  "filePath": "src/hooks/customBlockStylesForStructuredTextField.ts",
2699
- "lineNumber": 15
2699
+ "lineNumber": 16
2700
2700
  }
2701
2701
  },
2702
2702
  "contentAreaSidebarItems": {
@@ -2714,7 +2714,7 @@
2714
2714
  "returnType": "ContentAreaSidebarItem[]",
2715
2715
  "location": {
2716
2716
  "filePath": "src/hooks/contentAreaSidebarItems.ts",
2717
- "lineNumber": 10
2717
+ "lineNumber": 17
2718
2718
  }
2719
2719
  },
2720
2720
  "buildItemPresentationInfo": {
@@ -2737,7 +2737,7 @@
2737
2737
  "returnType": "MaybePromise<ItemPresentationInfo | undefined>",
2738
2738
  "location": {
2739
2739
  "filePath": "src/hooks/buildItemPresentationInfo.ts",
2740
- "lineNumber": 14
2740
+ "lineNumber": 15
2741
2741
  }
2742
2742
  },
2743
2743
  "assetSources": {
@@ -2755,7 +2755,7 @@
2755
2755
  "returnType": "AssetSource[] | undefined",
2756
2756
  "location": {
2757
2757
  "filePath": "src/hooks/assetSources.ts",
2758
- "lineNumber": 11
2758
+ "lineNumber": 12
2759
2759
  }
2760
2760
  }
2761
2761
  },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "datocms-plugin-sdk",
3
- "version": "2.0.4",
3
+ "version": "2.0.5",
4
4
  "description": "DatoCMS Plugin SDK",
5
5
  "keywords": [
6
6
  "datocms",
@@ -45,5 +45,5 @@
45
45
  "glob": "^11.0.0",
46
46
  "typescript": "^5.6.2"
47
47
  },
48
- "gitHead": "c08f8ec853327a4d0910217284d9406febd42b3e"
48
+ "gitHead": "3691996abdcc5da84a982b31db38154a7540b17f"
49
49
  }
@@ -0,0 +1,34 @@
1
+ export function isNullish(value: unknown): value is null | undefined {
2
+ return value === null || value === undefined;
3
+ }
4
+
5
+ export function isBoolean(value: unknown): value is boolean {
6
+ return typeof value === 'boolean';
7
+ }
8
+
9
+ export function isString(value: unknown): value is string {
10
+ return typeof value === 'string';
11
+ }
12
+
13
+ export function isNumber(value: unknown): value is number {
14
+ return typeof value === 'number';
15
+ }
16
+
17
+ export function isRecord(value: unknown): value is Record<string, unknown> {
18
+ return typeof value === 'object' && value !== null && !Array.isArray(value);
19
+ }
20
+
21
+ export function isArray<T>(
22
+ value: unknown,
23
+ checkItem: (item: unknown) => item is T,
24
+ ): value is T[] {
25
+ return Array.isArray(value) && value.every(checkItem);
26
+ }
27
+
28
+ export function isPlacement(value: unknown) {
29
+ return (
30
+ isArray(value, isString) &&
31
+ value.length === 2 &&
32
+ ['before', 'after'].includes(value[0])
33
+ );
34
+ }
@@ -1,5 +1,6 @@
1
1
  import { Ctx } from '../ctx/base';
2
- import { Icon } from '../icon';
2
+ import { isNullish, isNumber, isRecord, isString } from '../guardUtils.js';
3
+ import { Icon, isIcon } from '../icon';
3
4
 
4
5
  export type AssetSourcesHook = {
5
6
  /**
@@ -13,7 +14,11 @@ export type AssetSourcesHook = {
13
14
 
14
15
  export type AssetSourcesCtx = Ctx;
15
16
 
16
- /** An additional asset source */
17
+ /**
18
+ * An object expressing an additional asset source
19
+ *
20
+ * @see {isAssetSource}
21
+ */
17
22
  export type AssetSource = {
18
23
  /**
19
24
  * ID of the asset source. Will be the first argument for the
@@ -43,3 +48,28 @@ export type AssetSource = {
43
48
  initialHeight?: number;
44
49
  };
45
50
  };
51
+
52
+ /**
53
+ * Type guard for AssetSource.
54
+ * @param value - The value to check.
55
+ * @returns true if the value is an AssetSource, false otherwise.
56
+ */
57
+ export function isAssetSource(value: unknown): value is AssetSource {
58
+ if (isNullish(value)) return false;
59
+ if (!isRecord(value)) return false;
60
+
61
+ const { id, name, icon, modal } = value;
62
+
63
+ return (
64
+ isString(id) &&
65
+ isString(name) &&
66
+ isIcon(icon) &&
67
+ (isNullish(modal) ||
68
+ (isRecord(modal) &&
69
+ (isNullish(modal.width) ||
70
+ (isString(modal.width) &&
71
+ ['s', 'm', 'l', 'xl'].includes(modal.width)) ||
72
+ isNumber(modal.width)) &&
73
+ (isNullish(modal.initialHeight) || isNumber(modal.initialHeight))))
74
+ );
75
+ }
@@ -1,5 +1,6 @@
1
1
  import type { SchemaTypes } from '@datocms/cma-client';
2
2
  import { Ctx } from '../ctx/base';
3
+ import { isNullish, isNumber, isRecord, isString } from '../guardUtils.js';
3
4
  import type { MaybePromise } from '../utils';
4
5
 
5
6
  type Item = SchemaTypes.Item;
@@ -19,6 +20,11 @@ export type BuildItemPresentationInfoHook = {
19
20
 
20
21
  export type BuildItemPresentationInfoCtx = Ctx;
21
22
 
23
+ /**
24
+ * An object expressing how a record should be presented in the interface
25
+ *
26
+ * @see {isItemPresentationInfo}
27
+ */
22
28
  export type ItemPresentationInfo = {
23
29
  /** The title to present the record */
24
30
  title: string;
@@ -33,3 +39,19 @@ export type ItemPresentationInfo = {
33
39
  */
34
40
  rank?: number;
35
41
  };
42
+
43
+ /**
44
+ * Checks if the value is an ItemPresentationInfo type.
45
+ * @param value The value to check.
46
+ * @returns True if the value is an ItemPresentationInfo, false otherwise.
47
+ */
48
+ export function isItemPresentationInfo(
49
+ value: unknown,
50
+ ): value is ItemPresentationInfo {
51
+ return (
52
+ isRecord(value) &&
53
+ isString(value.title) &&
54
+ (isNullish(value.imageUrl) || isString(value.imageUrl)) &&
55
+ (isNullish(value.rank) || isNumber(value.rank))
56
+ );
57
+ }
@@ -1,5 +1,12 @@
1
1
  import { Ctx } from '../ctx/base';
2
- import { Icon } from '../icon';
2
+ import {
3
+ isNullish,
4
+ isNumber,
5
+ isPlacement,
6
+ isRecord,
7
+ isString,
8
+ } from '../guardUtils.js';
9
+ import { Icon, isIcon } from '../icon';
3
10
 
4
11
  export type ContentAreaSidebarItemsHook = {
5
12
  /**
@@ -14,6 +21,11 @@ export type ContentAreaSidebarItemsHook = {
14
21
 
15
22
  export type ContentAreaSidebarItemsCtx = Ctx;
16
23
 
24
+ /**
25
+ * An object expressing an item in the content area sidebar
26
+ *
27
+ * @see {isContentAreaSidebarItem}
28
+ */
17
29
  export type ContentAreaSidebarItem = {
18
30
  /** Label to be shown. Must be unique. */
19
31
  label: string;
@@ -43,3 +55,22 @@ export type ContentAreaSidebarItem = {
43
55
  */
44
56
  rank?: number;
45
57
  };
58
+
59
+ /**
60
+ * Checks if the value is a ContentAreaSidebarItem.
61
+ * @param value - The value to check.
62
+ * @returns True if the value is a ContentAreaSidebarItem, false otherwise.
63
+ */
64
+ export function isContentAreaSidebarItem(
65
+ value: unknown,
66
+ ): value is ContentAreaSidebarItem {
67
+ return (
68
+ isRecord(value) &&
69
+ isString(value.label) &&
70
+ isIcon(value.icon) &&
71
+ isRecord(value.pointsTo) &&
72
+ isString(value.pointsTo.pageId) &&
73
+ (isNullish(value.placement) || isPlacement(value.placement)) &&
74
+ (isNullish(value.rank) || isNumber(value.rank))
75
+ );
76
+ }
@@ -1,6 +1,7 @@
1
1
  import type { SchemaTypes } from '@datocms/cma-client';
2
2
  import { BlockNodeTypeWithCustomStyle } from 'datocms-structured-text-utils';
3
3
  import { Ctx } from '../ctx/base';
4
+ import { isNullish, isNumber, isRecord, isString } from '../guardUtils.js';
4
5
 
5
6
  type Field = SchemaTypes.Field;
6
7
  type ItemType = SchemaTypes.ItemType;
@@ -22,7 +23,11 @@ export type CustomBlockStylesForStructuredTextFieldCtx = Ctx<{
22
23
  itemType: ItemType;
23
24
  }>;
24
25
 
25
- /** An object expressing a custom block style for a Structured Text field */
26
+ /**
27
+ * An object expressing a custom block style for a Structured Text field
28
+ *
29
+ * @see {isStructuredTextCustomBlockStyle}
30
+ */
26
31
  export type StructuredTextCustomBlockStyle = {
27
32
  /** ID of custom block style */
28
33
  id: string;
@@ -40,3 +45,20 @@ export type StructuredTextCustomBlockStyle = {
40
45
  */
41
46
  rank?: number;
42
47
  };
48
+
49
+ /**
50
+ * Checks if the given value is a StructuredTextCustomBlockStyle.
51
+ * @param value - The value to check.
52
+ * @returns True if the value is a StructuredTextCustomBlockStyle, otherwise false.
53
+ */
54
+ export function isStructuredTextCustomBlockStyle(
55
+ value: unknown,
56
+ ): value is StructuredTextCustomBlockStyle {
57
+ return (
58
+ isRecord(value) &&
59
+ isString(value.id) &&
60
+ isString(value.label) &&
61
+ isString(value.node) &&
62
+ (isNullish(value.rank) || isNumber(value.rank))
63
+ );
64
+ }
@@ -1,6 +1,13 @@
1
1
  import type { SchemaTypes } from '@datocms/cma-client';
2
2
  import { Ctx } from '../ctx/base';
3
- import { Icon } from '../icon';
3
+ import {
4
+ isNullish,
5
+ isNumber,
6
+ isPlacement,
7
+ isRecord,
8
+ isString,
9
+ } from '../guardUtils.js';
10
+ import { Icon, isIcon } from '../icon';
4
11
 
5
12
  type Field = SchemaTypes.Field;
6
13
  type ItemType = SchemaTypes.ItemType;
@@ -22,7 +29,11 @@ export type CustomMarksForStructuredTextFieldCtx = Ctx<{
22
29
  itemType: ItemType;
23
30
  }>;
24
31
 
25
- /** An object expressing a custom mark for a Structured Text field */
32
+ /**
33
+ * An object expressing a custom mark for a Structured Text field
34
+ *
35
+ * @see {isStructuredTextCustomMark}
36
+ */
26
37
  export type StructuredTextCustomMark = {
27
38
  /** ID of mark */
28
39
  id: string;
@@ -62,3 +73,23 @@ export type StructuredTextCustomMarkPlacement = [
62
73
  'before' | 'after',
63
74
  'strong' | 'emphasis' | 'underline' | 'code' | 'highlight' | 'strikethrough',
64
75
  ];
76
+
77
+ /**
78
+ * Checks if the given value is a StructuredTextCustomMark.
79
+ * @param value The value to check.
80
+ * @returns True if the value is a StructuredTextCustomMark, false otherwise.
81
+ */
82
+ export function isStructuredTextCustomMark(
83
+ value: unknown,
84
+ ): value is StructuredTextCustomMark {
85
+ return (
86
+ isRecord(value) &&
87
+ isString(value.id) &&
88
+ isString(value.label) &&
89
+ isIcon(value.icon) &&
90
+ (isNullish(value.placement) || isPlacement(value.placement)) &&
91
+ (isNullish(value.rank) || isNumber(value.rank)) &&
92
+ (isNullish(value.keyboardShortcut) || isString(value.keyboardShortcut)) &&
93
+ isRecord(value.appliedStyle)
94
+ );
95
+ }
@@ -1,6 +1,6 @@
1
1
  import type { SchemaTypes } from '@datocms/cma-client';
2
2
  import { Ctx, ItemListLocationQuery } from '../ctx/base';
3
-
3
+ import { isNullish, isNumber, isRecord } from '../guardUtils.js';
4
4
  import { MaybePromise } from '../utils';
5
5
 
6
6
  type Field = SchemaTypes.Field;
@@ -22,6 +22,11 @@ export type InitialLocationQueryForItemSelectorHook = {
22
22
 
23
23
  export type InitialLocationQueryForItemSelectorCtx = Ctx;
24
24
 
25
+ /**
26
+ * An object expressing which filters should be applied to the record selector
27
+ *
28
+ * @see {isInitialLocationQueryForItemSelector}
29
+ */
25
30
  export type InitialLocationQueryForItemSelector = {
26
31
  locationQuery: ItemListLocationQuery;
27
32
  /**
@@ -33,3 +38,18 @@ export type InitialLocationQueryForItemSelector = {
33
38
  */
34
39
  rank?: number;
35
40
  };
41
+
42
+ /**
43
+ * Type guard for InitialLocationQueryForItemSelector
44
+ * @param value - The value to check
45
+ * @returns True if value is of type InitialLocationQueryForItemSelector, false otherwise
46
+ */
47
+ export function isInitialLocationQueryForItemSelector(
48
+ value: unknown,
49
+ ): value is InitialLocationQueryForItemSelector {
50
+ return (
51
+ isRecord(value) &&
52
+ isRecord(value.locationQuery) &&
53
+ (isNullish(value.rank) || isNumber(value.rank))
54
+ );
55
+ }
@@ -1,5 +1,6 @@
1
1
  import type { SchemaTypes } from '@datocms/cma-client';
2
2
  import { Ctx } from '../ctx/base';
3
+ import { isNullish, isNumber, isRecord, isString } from '../guardUtils.js';
3
4
 
4
5
  type ItemType = SchemaTypes.ItemType;
5
6
 
@@ -18,7 +19,11 @@ export type ItemCollectionOutletsHook = {
18
19
 
19
20
  export type ItemCollectionOutletsCtx = Ctx;
20
21
 
21
- /** An outlet to be shown at the top of a record's collection page */
22
+ /**
23
+ * An object expressing an outlet to be shown at the top of a record's collection page
24
+ *
25
+ * @see {isItemCollectionOutlet}
26
+ */
22
27
  export type ItemCollectionOutlet = {
23
28
  /**
24
29
  * ID of the outlet. Will be the first argument for the `renderItemCollectionOutlet`
@@ -35,3 +40,19 @@ export type ItemCollectionOutlet = {
35
40
  /** The initial height to set for the iframe that will render the outlet */
36
41
  initialHeight?: number;
37
42
  };
43
+
44
+ /**
45
+ * Checks if the given value is an ItemCollectionOutlet.
46
+ * @param value - The value to check.
47
+ * @returns True if the value is an ItemCollectionOutlet, false otherwise.
48
+ */
49
+ export function isItemCollectionOutlet(
50
+ value: unknown,
51
+ ): value is ItemCollectionOutlet {
52
+ return (
53
+ isRecord(value) &&
54
+ isString(value.id) &&
55
+ (isNullish(value.rank) || isNumber(value.rank)) &&
56
+ (isNullish(value.initialHeight) || isNumber(value.initialHeight))
57
+ );
58
+ }
@@ -1,5 +1,6 @@
1
1
  import type { SchemaTypes } from '@datocms/cma-client';
2
2
  import { Ctx } from '../ctx/base';
3
+ import { isNullish, isNumber, isRecord, isString } from '../guardUtils.js';
3
4
 
4
5
  type ItemType = SchemaTypes.ItemType;
5
6
 
@@ -18,6 +19,11 @@ export type ItemFormOutletsHook = {
18
19
 
19
20
  export type ItemFormOutletsCtx = Ctx;
20
21
 
22
+ /**
23
+ * An object expressing an outlet to be shown at the top of a record's editing page
24
+ *
25
+ * @see {isItemFormOutlet}
26
+ */
21
27
  export type ItemFormOutlet = {
22
28
  /**
23
29
  * ID of the outlet. Will be the first argument for the `renderItemFormOutlet`
@@ -34,3 +40,17 @@ export type ItemFormOutlet = {
34
40
  /** The initial height to set for the iframe that will render the outlet */
35
41
  initialHeight?: number;
36
42
  };
43
+
44
+ /**
45
+ * Checks if the given value is an ItemFormOutlet.
46
+ * @param value - The value to check.
47
+ * @returns True if the value is an ItemFormOutlet, false otherwise.
48
+ */
49
+ export function isItemFormOutlet(value: unknown): value is ItemFormOutlet {
50
+ return (
51
+ isRecord(value) &&
52
+ isString(value.id) &&
53
+ (isNullish(value.rank) || isNumber(value.rank)) &&
54
+ (isNullish(value.initialHeight) || isNumber(value.initialHeight))
55
+ );
56
+ }
@@ -1,5 +1,13 @@
1
1
  import type { SchemaTypes } from '@datocms/cma-client';
2
2
  import { Ctx } from '../ctx/base';
3
+ import {
4
+ isBoolean,
5
+ isNullish,
6
+ isNumber,
7
+ isPlacement,
8
+ isRecord,
9
+ isString,
10
+ } from '../guardUtils.js';
3
11
  import { ItemFormSidebarPanelPlacement } from '../shared';
4
12
 
5
13
  type ItemType = SchemaTypes.ItemType;
@@ -19,6 +27,12 @@ export type ItemFormSidebarPanelsHook = {
19
27
 
20
28
  export type ItemFormSidebarPanelsCtx = Ctx;
21
29
 
30
+ /**
31
+ * An object expressing a sidebar panel to be shown when the user
32
+ * edits records of a particular model
33
+ *
34
+ * @see {isItemFormSidebarPanel}
35
+ */
22
36
  export type ItemFormSidebarPanel = {
23
37
  /**
24
38
  * ID of the panel. Will be the first argument for the
@@ -52,3 +66,23 @@ export type ItemFormSidebarPanel = {
52
66
  /** The initial height to set for the iframe that will render the sidebar panel */
53
67
  initialHeight?: number;
54
68
  };
69
+
70
+ /**
71
+ * Checks if the given value is an ItemFormSidebarPanel.
72
+ * @param value - The value to check.
73
+ * @returns True if the value is an ItemFormSidebarPanel, false otherwise.
74
+ */
75
+ export function isItemFormSidebarPanel(
76
+ value: unknown,
77
+ ): value is ItemFormSidebarPanel {
78
+ return (
79
+ isRecord(value) &&
80
+ isString(value.id) &&
81
+ isString(value.label) &&
82
+ (isNullish(value.parameters) || isRecord(value.parameters)) &&
83
+ (isNullish(value.startOpen) || isBoolean(value.startOpen)) &&
84
+ (isNullish(value.placement) || isPlacement(value.placement)) &&
85
+ (isNullish(value.rank) || isNumber(value.rank)) &&
86
+ (isNullish(value.initialHeight) || isNumber(value.initialHeight))
87
+ );
88
+ }
@@ -1,5 +1,6 @@
1
1
  import type { SchemaTypes } from '@datocms/cma-client';
2
2
  import { Ctx } from '../ctx/base';
3
+ import { isNullish, isNumber, isRecord, isString } from '../guardUtils.js';
3
4
 
4
5
  type ItemType = SchemaTypes.ItemType;
5
6
 
@@ -18,6 +19,12 @@ export type ItemFormSidebarsHook = {
18
19
 
19
20
  export type ItemFormSidebarsCtx = Ctx;
20
21
 
22
+ /**
23
+ * An object expressing a sidebar to be shown when the user edits
24
+ * records of a particular model
25
+ *
26
+ * @see {isItemFormSidebar}
27
+ */
21
28
  export type ItemFormSidebar = {
22
29
  /**
23
30
  * ID of the sidebar. Will be the first argument for the
@@ -42,3 +49,19 @@ export type ItemFormSidebar = {
42
49
  /** The preferred width for the sidebar */
43
50
  preferredWidth?: number;
44
51
  };
52
+
53
+ /**
54
+ * Type guard to check if the value is an ItemFormSidebar.
55
+ * @param value - The value to check.
56
+ * @returns true if the value is an ItemFormSidebar, false otherwise.
57
+ */
58
+ export function isItemFormSidebar(value: unknown): value is ItemFormSidebar {
59
+ return (
60
+ isRecord(value) &&
61
+ isString(value.id) &&
62
+ isString(value.label) &&
63
+ (isNullish(value.parameters) || isRecord(value.parameters)) &&
64
+ (isNullish(value.rank) || isNumber(value.rank)) &&
65
+ (isNullish(value.preferredWidth) || isNumber(value.preferredWidth))
66
+ );
67
+ }
@@ -1,5 +1,12 @@
1
1
  import { Ctx } from '../ctx/base';
2
- import { Icon } from '../icon';
2
+ import {
3
+ isNullish,
4
+ isNumber,
5
+ isPlacement,
6
+ isRecord,
7
+ isString,
8
+ } from '../guardUtils.js';
9
+ import { Icon, isIcon } from '../icon';
3
10
 
4
11
  export type MainNavigationTabsHook = {
5
12
  /**
@@ -13,7 +20,11 @@ export type MainNavigationTabsHook = {
13
20
 
14
21
  export type MainNavigationTabsCtx = Ctx;
15
22
 
16
- /** A tab to be displayed in the top-bar of the UI */
23
+ /**
24
+ * An object expressing a tab to be displayed in the top-bar of the UI
25
+ *
26
+ * @see {isMainNavigationTab}
27
+ */
17
28
  export type MainNavigationTab = {
18
29
  /** Label to be shown. Must be unique. */
19
30
  label: string;
@@ -45,3 +56,22 @@ export type MainNavigationTab = {
45
56
  */
46
57
  rank?: number;
47
58
  };
59
+
60
+ /**
61
+ * Checks if the given value is a MainNavigationTab.
62
+ * @param value The value to check.
63
+ * @returns True if the value is a MainNavigationTab, false otherwise.
64
+ */
65
+ export function isMainNavigationTab(
66
+ value: unknown,
67
+ ): value is MainNavigationTab {
68
+ return (
69
+ isRecord(value) &&
70
+ isString(value.label) &&
71
+ isIcon(value.icon) &&
72
+ isRecord(value.pointsTo) &&
73
+ isString(value.pointsTo.pageId) &&
74
+ (isNullish(value.placement) || isPlacement(value.placement)) &&
75
+ (isNullish(value.rank) || isNumber(value.rank))
76
+ );
77
+ }