datocms-plugin-sdk 2.0.4 → 2.0.6

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 (140) 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 +24 -0
  4. package/dist/cjs/hooks/assetSources.js.map +1 -1
  5. package/dist/cjs/hooks/buildItemPresentationInfo.js +12 -0
  6. package/dist/cjs/hooks/buildItemPresentationInfo.js.map +1 -1
  7. package/dist/cjs/hooks/contentAreaSidebarItems.js +16 -0
  8. package/dist/cjs/hooks/contentAreaSidebarItems.js.map +1 -1
  9. package/dist/cjs/hooks/customBlockStylesForStructuredTextField.js +13 -0
  10. package/dist/cjs/hooks/customBlockStylesForStructuredTextField.js.map +1 -1
  11. package/dist/cjs/hooks/customMarksForStructuredTextField.js +17 -0
  12. package/dist/cjs/hooks/customMarksForStructuredTextField.js.map +1 -1
  13. package/dist/cjs/hooks/initialLocationQueryForItemSelector.js +11 -0
  14. package/dist/cjs/hooks/initialLocationQueryForItemSelector.js.map +1 -1
  15. package/dist/cjs/hooks/itemCollectionOutlets.js +12 -0
  16. package/dist/cjs/hooks/itemCollectionOutlets.js.map +1 -1
  17. package/dist/cjs/hooks/itemFormOutlets.js +12 -0
  18. package/dist/cjs/hooks/itemFormOutlets.js.map +1 -1
  19. package/dist/cjs/hooks/itemFormSidebarPanels.js +16 -0
  20. package/dist/cjs/hooks/itemFormSidebarPanels.js.map +1 -1
  21. package/dist/cjs/hooks/itemFormSidebars.js +14 -0
  22. package/dist/cjs/hooks/itemFormSidebars.js.map +1 -1
  23. package/dist/cjs/hooks/mainNavigationTabs.js +16 -0
  24. package/dist/cjs/hooks/mainNavigationTabs.js.map +1 -1
  25. package/dist/cjs/hooks/manualFieldExtensions.js +24 -0
  26. package/dist/cjs/hooks/manualFieldExtensions.js.map +1 -1
  27. package/dist/cjs/hooks/overrideFieldExtensions.js +35 -0
  28. package/dist/cjs/hooks/overrideFieldExtensions.js.map +1 -1
  29. package/dist/cjs/hooks/uploadSidebarPanels.js +16 -0
  30. package/dist/cjs/hooks/uploadSidebarPanels.js.map +1 -1
  31. package/dist/cjs/hooks/uploadSidebars.js +14 -0
  32. package/dist/cjs/hooks/uploadSidebars.js.map +1 -1
  33. package/dist/cjs/hooks/validateManualFieldExtensionParameters.js +5 -0
  34. package/dist/cjs/hooks/validateManualFieldExtensionParameters.js.map +1 -1
  35. package/dist/cjs/icon.js +9 -0
  36. package/dist/cjs/icon.js.map +1 -1
  37. package/dist/cjs/manifest.js +18 -18
  38. package/dist/cjs/manifest.js.map +1 -1
  39. package/dist/cjs/shared.js +31 -0
  40. package/dist/cjs/shared.js.map +1 -1
  41. package/dist/esm/guardUtils.d.ts +7 -0
  42. package/dist/esm/guardUtils.js +24 -0
  43. package/dist/esm/guardUtils.js.map +1 -0
  44. package/dist/esm/hooks/assetSources.d.ts +7 -1
  45. package/dist/esm/hooks/assetSources.js +22 -1
  46. package/dist/esm/hooks/assetSources.js.map +1 -1
  47. package/dist/esm/hooks/buildItemPresentationInfo.d.ts +7 -0
  48. package/dist/esm/hooks/buildItemPresentationInfo.js +10 -1
  49. package/dist/esm/hooks/buildItemPresentationInfo.js.map +1 -1
  50. package/dist/esm/hooks/contentAreaSidebarItems.d.ts +7 -0
  51. package/dist/esm/hooks/contentAreaSidebarItems.js +14 -1
  52. package/dist/esm/hooks/contentAreaSidebarItems.js.map +1 -1
  53. package/dist/esm/hooks/customBlockStylesForStructuredTextField.d.ts +7 -1
  54. package/dist/esm/hooks/customBlockStylesForStructuredTextField.js +11 -1
  55. package/dist/esm/hooks/customBlockStylesForStructuredTextField.js.map +1 -1
  56. package/dist/esm/hooks/customMarksForStructuredTextField.d.ts +7 -1
  57. package/dist/esm/hooks/customMarksForStructuredTextField.js +15 -1
  58. package/dist/esm/hooks/customMarksForStructuredTextField.js.map +1 -1
  59. package/dist/esm/hooks/initialLocationQueryForItemSelector.d.ts +7 -0
  60. package/dist/esm/hooks/initialLocationQueryForItemSelector.js +9 -1
  61. package/dist/esm/hooks/initialLocationQueryForItemSelector.js.map +1 -1
  62. package/dist/esm/hooks/itemCollectionOutlets.d.ts +7 -1
  63. package/dist/esm/hooks/itemCollectionOutlets.js +10 -1
  64. package/dist/esm/hooks/itemCollectionOutlets.js.map +1 -1
  65. package/dist/esm/hooks/itemFormOutlets.d.ts +7 -0
  66. package/dist/esm/hooks/itemFormOutlets.js +10 -1
  67. package/dist/esm/hooks/itemFormOutlets.js.map +1 -1
  68. package/dist/esm/hooks/itemFormSidebarPanels.d.ts +8 -0
  69. package/dist/esm/hooks/itemFormSidebarPanels.js +14 -1
  70. package/dist/esm/hooks/itemFormSidebarPanels.js.map +1 -1
  71. package/dist/esm/hooks/itemFormSidebars.d.ts +8 -0
  72. package/dist/esm/hooks/itemFormSidebars.js +12 -1
  73. package/dist/esm/hooks/itemFormSidebars.js.map +1 -1
  74. package/dist/esm/hooks/mainNavigationTabs.d.ts +7 -1
  75. package/dist/esm/hooks/mainNavigationTabs.js +14 -1
  76. package/dist/esm/hooks/mainNavigationTabs.js.map +1 -1
  77. package/dist/esm/hooks/manualFieldExtensions.d.ts +8 -0
  78. package/dist/esm/hooks/manualFieldExtensions.js +22 -1
  79. package/dist/esm/hooks/manualFieldExtensions.js.map +1 -1
  80. package/dist/esm/hooks/overrideFieldExtensions.d.ts +6 -0
  81. package/dist/esm/hooks/overrideFieldExtensions.js +31 -1
  82. package/dist/esm/hooks/overrideFieldExtensions.js.map +1 -1
  83. package/dist/esm/hooks/uploadSidebarPanels.d.ts +8 -0
  84. package/dist/esm/hooks/uploadSidebarPanels.js +14 -1
  85. package/dist/esm/hooks/uploadSidebarPanels.js.map +1 -1
  86. package/dist/esm/hooks/uploadSidebars.d.ts +8 -0
  87. package/dist/esm/hooks/uploadSidebars.js +12 -1
  88. package/dist/esm/hooks/uploadSidebars.js.map +1 -1
  89. package/dist/esm/hooks/validateManualFieldExtensionParameters.d.ts +1 -0
  90. package/dist/esm/hooks/validateManualFieldExtensionParameters.js +4 -1
  91. package/dist/esm/hooks/validateManualFieldExtensionParameters.js.map +1 -1
  92. package/dist/esm/icon.d.ts +1 -0
  93. package/dist/esm/icon.js +8 -1
  94. package/dist/esm/icon.js.map +1 -1
  95. package/dist/esm/manifest.js +18 -18
  96. package/dist/esm/manifest.js.map +1 -1
  97. package/dist/esm/shared.d.ts +13 -0
  98. package/dist/esm/shared.js +28 -1
  99. package/dist/esm/shared.js.map +1 -1
  100. package/dist/types/guardUtils.d.ts +7 -0
  101. package/dist/types/hooks/assetSources.d.ts +7 -1
  102. package/dist/types/hooks/buildItemPresentationInfo.d.ts +7 -0
  103. package/dist/types/hooks/contentAreaSidebarItems.d.ts +7 -0
  104. package/dist/types/hooks/customBlockStylesForStructuredTextField.d.ts +7 -1
  105. package/dist/types/hooks/customMarksForStructuredTextField.d.ts +7 -1
  106. package/dist/types/hooks/initialLocationQueryForItemSelector.d.ts +7 -0
  107. package/dist/types/hooks/itemCollectionOutlets.d.ts +7 -1
  108. package/dist/types/hooks/itemFormOutlets.d.ts +7 -0
  109. package/dist/types/hooks/itemFormSidebarPanels.d.ts +8 -0
  110. package/dist/types/hooks/itemFormSidebars.d.ts +8 -0
  111. package/dist/types/hooks/mainNavigationTabs.d.ts +7 -1
  112. package/dist/types/hooks/manualFieldExtensions.d.ts +8 -0
  113. package/dist/types/hooks/overrideFieldExtensions.d.ts +6 -0
  114. package/dist/types/hooks/uploadSidebarPanels.d.ts +8 -0
  115. package/dist/types/hooks/uploadSidebars.d.ts +8 -0
  116. package/dist/types/hooks/validateManualFieldExtensionParameters.d.ts +1 -0
  117. package/dist/types/icon.d.ts +1 -0
  118. package/dist/types/shared.d.ts +13 -0
  119. package/manifest.json +18 -18
  120. package/package.json +2 -2
  121. package/src/guardUtils.ts +34 -0
  122. package/src/hooks/assetSources.ts +39 -2
  123. package/src/hooks/buildItemPresentationInfo.ts +23 -0
  124. package/src/hooks/contentAreaSidebarItems.ts +34 -1
  125. package/src/hooks/customBlockStylesForStructuredTextField.ts +30 -1
  126. package/src/hooks/customMarksForStructuredTextField.ts +35 -2
  127. package/src/hooks/initialLocationQueryForItemSelector.ts +22 -1
  128. package/src/hooks/itemCollectionOutlets.ts +29 -1
  129. package/src/hooks/itemFormOutlets.ts +27 -0
  130. package/src/hooks/itemFormSidebarPanels.ts +36 -0
  131. package/src/hooks/itemFormSidebars.ts +30 -0
  132. package/src/hooks/mainNavigationTabs.ts +34 -2
  133. package/src/hooks/manualFieldExtensions.ts +43 -0
  134. package/src/hooks/overrideFieldExtensions.ts +55 -0
  135. package/src/hooks/uploadSidebarPanels.ts +36 -0
  136. package/src/hooks/uploadSidebars.ts +30 -0
  137. package/src/hooks/validateManualFieldExtensionParameters.ts +8 -0
  138. package/src/icon.ts +12 -0
  139. package/src/manifest.ts +18 -18
  140. package/src/shared.ts +58 -1
@@ -1,6 +1,13 @@
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 {
5
+ isArray,
6
+ isNullish,
7
+ isNumber,
8
+ isRecord,
9
+ isString,
10
+ } from '../guardUtils.js';
4
11
 
5
12
  type Field = SchemaTypes.Field;
6
13
  type ItemType = SchemaTypes.ItemType;
@@ -22,7 +29,11 @@ export type CustomBlockStylesForStructuredTextFieldCtx = Ctx<{
22
29
  itemType: ItemType;
23
30
  }>;
24
31
 
25
- /** An object expressing a custom block style for a Structured Text field */
32
+ /**
33
+ * An object expressing a custom block style for a Structured Text field
34
+ *
35
+ * @see {isStructuredTextCustomBlockStyle}
36
+ */
26
37
  export type StructuredTextCustomBlockStyle = {
27
38
  /** ID of custom block style */
28
39
  id: string;
@@ -40,3 +51,21 @@ export type StructuredTextCustomBlockStyle = {
40
51
  */
41
52
  rank?: number;
42
53
  };
54
+
55
+ export function isStructuredTextCustomBlockStyle(
56
+ value: unknown,
57
+ ): value is StructuredTextCustomBlockStyle {
58
+ return (
59
+ isRecord(value) &&
60
+ isString(value.id) &&
61
+ isString(value.label) &&
62
+ isString(value.node) &&
63
+ (isNullish(value.rank) || isNumber(value.rank))
64
+ );
65
+ }
66
+
67
+ export function isReturnTypeOfCustomBlockStylesForStructuredTextFieldHook(
68
+ value: unknown,
69
+ ): value is StructuredTextCustomBlockStyle[] | undefined {
70
+ return isNullish(value) || isArray(value, isStructuredTextCustomBlockStyle);
71
+ }
@@ -1,6 +1,14 @@
1
1
  import type { SchemaTypes } from '@datocms/cma-client';
2
2
  import { Ctx } from '../ctx/base';
3
- import { Icon } from '../icon';
3
+ import {
4
+ isArray,
5
+ isNullish,
6
+ isNumber,
7
+ isPlacement,
8
+ isRecord,
9
+ isString,
10
+ } from '../guardUtils.js';
11
+ import { Icon, isIcon } from '../icon';
4
12
 
5
13
  type Field = SchemaTypes.Field;
6
14
  type ItemType = SchemaTypes.ItemType;
@@ -22,7 +30,11 @@ export type CustomMarksForStructuredTextFieldCtx = Ctx<{
22
30
  itemType: ItemType;
23
31
  }>;
24
32
 
25
- /** An object expressing a custom mark for a Structured Text field */
33
+ /**
34
+ * An object expressing a custom mark for a Structured Text field
35
+ *
36
+ * @see {isStructuredTextCustomMark}
37
+ */
26
38
  export type StructuredTextCustomMark = {
27
39
  /** ID of mark */
28
40
  id: string;
@@ -62,3 +74,24 @@ export type StructuredTextCustomMarkPlacement = [
62
74
  'before' | 'after',
63
75
  'strong' | 'emphasis' | 'underline' | 'code' | 'highlight' | 'strikethrough',
64
76
  ];
77
+
78
+ export function isStructuredTextCustomMark(
79
+ value: unknown,
80
+ ): value is StructuredTextCustomMark {
81
+ return (
82
+ isRecord(value) &&
83
+ isString(value.id) &&
84
+ isString(value.label) &&
85
+ isIcon(value.icon) &&
86
+ (isNullish(value.placement) || isPlacement(value.placement)) &&
87
+ (isNullish(value.rank) || isNumber(value.rank)) &&
88
+ (isNullish(value.keyboardShortcut) || isString(value.keyboardShortcut)) &&
89
+ isRecord(value.appliedStyle)
90
+ );
91
+ }
92
+
93
+ export function isReturnTypeOfCustomMarksForStructuredTextFieldHook(
94
+ value: unknown,
95
+ ): value is StructuredTextCustomMark[] | undefined {
96
+ return isNullish(value) || isArray(value, isStructuredTextCustomMark);
97
+ }
@@ -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,19 @@ export type InitialLocationQueryForItemSelector = {
33
38
  */
34
39
  rank?: number;
35
40
  };
41
+
42
+ export function isInitialLocationQueryForItemSelector(
43
+ value: unknown,
44
+ ): value is InitialLocationQueryForItemSelector {
45
+ return (
46
+ isRecord(value) &&
47
+ isRecord(value.locationQuery) &&
48
+ (isNullish(value.rank) || isNumber(value.rank))
49
+ );
50
+ }
51
+
52
+ export function isReturnTypeOfInitialLocationQueryForItemSelectorHook(
53
+ value: unknown,
54
+ ): value is InitialLocationQueryForItemSelector | undefined {
55
+ return isNullish(value) || isInitialLocationQueryForItemSelector(value);
56
+ }
@@ -1,5 +1,12 @@
1
1
  import type { SchemaTypes } from '@datocms/cma-client';
2
2
  import { Ctx } from '../ctx/base';
3
+ import {
4
+ isArray,
5
+ isNullish,
6
+ isNumber,
7
+ isRecord,
8
+ isString,
9
+ } from '../guardUtils.js';
3
10
 
4
11
  type ItemType = SchemaTypes.ItemType;
5
12
 
@@ -18,7 +25,11 @@ export type ItemCollectionOutletsHook = {
18
25
 
19
26
  export type ItemCollectionOutletsCtx = Ctx;
20
27
 
21
- /** An outlet to be shown at the top of a record's collection page */
28
+ /**
29
+ * An object expressing an outlet to be shown at the top of a record's collection page
30
+ *
31
+ * @see {isItemCollectionOutlet}
32
+ */
22
33
  export type ItemCollectionOutlet = {
23
34
  /**
24
35
  * ID of the outlet. Will be the first argument for the `renderItemCollectionOutlet`
@@ -35,3 +46,20 @@ export type ItemCollectionOutlet = {
35
46
  /** The initial height to set for the iframe that will render the outlet */
36
47
  initialHeight?: number;
37
48
  };
49
+
50
+ export function isItemCollectionOutlet(
51
+ value: unknown,
52
+ ): value is ItemCollectionOutlet {
53
+ return (
54
+ isRecord(value) &&
55
+ isString(value.id) &&
56
+ (isNullish(value.rank) || isNumber(value.rank)) &&
57
+ (isNullish(value.initialHeight) || isNumber(value.initialHeight))
58
+ );
59
+ }
60
+
61
+ export function isReturnTypeOfItemCollectionOutletsHook(
62
+ value: unknown,
63
+ ): value is ItemCollectionOutlet[] {
64
+ return isArray(value, isItemCollectionOutlet);
65
+ }
@@ -1,5 +1,12 @@
1
1
  import type { SchemaTypes } from '@datocms/cma-client';
2
2
  import { Ctx } from '../ctx/base';
3
+ import {
4
+ isArray,
5
+ isNullish,
6
+ isNumber,
7
+ isRecord,
8
+ isString,
9
+ } from '../guardUtils.js';
3
10
 
4
11
  type ItemType = SchemaTypes.ItemType;
5
12
 
@@ -18,6 +25,11 @@ export type ItemFormOutletsHook = {
18
25
 
19
26
  export type ItemFormOutletsCtx = Ctx;
20
27
 
28
+ /**
29
+ * An object expressing an outlet to be shown at the top of a record's editing page
30
+ *
31
+ * @see {isItemFormOutlet}
32
+ */
21
33
  export type ItemFormOutlet = {
22
34
  /**
23
35
  * ID of the outlet. Will be the first argument for the `renderItemFormOutlet`
@@ -34,3 +46,18 @@ export type ItemFormOutlet = {
34
46
  /** The initial height to set for the iframe that will render the outlet */
35
47
  initialHeight?: number;
36
48
  };
49
+
50
+ export function isItemFormOutlet(value: unknown): value is ItemFormOutlet {
51
+ return (
52
+ isRecord(value) &&
53
+ isString(value.id) &&
54
+ (isNullish(value.rank) || isNumber(value.rank)) &&
55
+ (isNullish(value.initialHeight) || isNumber(value.initialHeight))
56
+ );
57
+ }
58
+
59
+ export function isReturnTypeOfItemFormOutletsHook(
60
+ value: unknown,
61
+ ): value is ItemFormOutlet[] {
62
+ return isArray(value, isItemFormOutlet);
63
+ }
@@ -1,5 +1,14 @@
1
1
  import type { SchemaTypes } from '@datocms/cma-client';
2
2
  import { Ctx } from '../ctx/base';
3
+ import {
4
+ isArray,
5
+ isBoolean,
6
+ isNullish,
7
+ isNumber,
8
+ isPlacement,
9
+ isRecord,
10
+ isString,
11
+ } from '../guardUtils.js';
3
12
  import { ItemFormSidebarPanelPlacement } from '../shared';
4
13
 
5
14
  type ItemType = SchemaTypes.ItemType;
@@ -19,6 +28,12 @@ export type ItemFormSidebarPanelsHook = {
19
28
 
20
29
  export type ItemFormSidebarPanelsCtx = Ctx;
21
30
 
31
+ /**
32
+ * An object expressing a sidebar panel to be shown when the user
33
+ * edits records of a particular model
34
+ *
35
+ * @see {isItemFormSidebarPanel}
36
+ */
22
37
  export type ItemFormSidebarPanel = {
23
38
  /**
24
39
  * ID of the panel. Will be the first argument for the
@@ -52,3 +67,24 @@ export type ItemFormSidebarPanel = {
52
67
  /** The initial height to set for the iframe that will render the sidebar panel */
53
68
  initialHeight?: number;
54
69
  };
70
+
71
+ export function isItemFormSidebarPanel(
72
+ value: unknown,
73
+ ): value is ItemFormSidebarPanel {
74
+ return (
75
+ isRecord(value) &&
76
+ isString(value.id) &&
77
+ isString(value.label) &&
78
+ (isNullish(value.parameters) || isRecord(value.parameters)) &&
79
+ (isNullish(value.startOpen) || isBoolean(value.startOpen)) &&
80
+ (isNullish(value.placement) || isPlacement(value.placement)) &&
81
+ (isNullish(value.rank) || isNumber(value.rank)) &&
82
+ (isNullish(value.initialHeight) || isNumber(value.initialHeight))
83
+ );
84
+ }
85
+
86
+ export function isReturnTypeOfItemFormSidebarPanelsHook(
87
+ value: unknown,
88
+ ): value is ItemFormSidebarPanel[] {
89
+ return isArray(value, isItemFormSidebarPanel);
90
+ }
@@ -1,5 +1,12 @@
1
1
  import type { SchemaTypes } from '@datocms/cma-client';
2
2
  import { Ctx } from '../ctx/base';
3
+ import {
4
+ isArray,
5
+ isNullish,
6
+ isNumber,
7
+ isRecord,
8
+ isString,
9
+ } from '../guardUtils.js';
3
10
 
4
11
  type ItemType = SchemaTypes.ItemType;
5
12
 
@@ -18,6 +25,12 @@ export type ItemFormSidebarsHook = {
18
25
 
19
26
  export type ItemFormSidebarsCtx = Ctx;
20
27
 
28
+ /**
29
+ * An object expressing a sidebar to be shown when the user edits
30
+ * records of a particular model
31
+ *
32
+ * @see {isItemFormSidebar}
33
+ */
21
34
  export type ItemFormSidebar = {
22
35
  /**
23
36
  * ID of the sidebar. Will be the first argument for the
@@ -42,3 +55,20 @@ export type ItemFormSidebar = {
42
55
  /** The preferred width for the sidebar */
43
56
  preferredWidth?: number;
44
57
  };
58
+
59
+ export function isItemFormSidebar(value: unknown): value is ItemFormSidebar {
60
+ return (
61
+ isRecord(value) &&
62
+ isString(value.id) &&
63
+ isString(value.label) &&
64
+ (isNullish(value.parameters) || isRecord(value.parameters)) &&
65
+ (isNullish(value.rank) || isNumber(value.rank)) &&
66
+ (isNullish(value.preferredWidth) || isNumber(value.preferredWidth))
67
+ );
68
+ }
69
+
70
+ export function isReturnTypeOfItemFormSidebarsHook(
71
+ value: unknown,
72
+ ): value is ItemFormSidebar[] {
73
+ return isArray(value, isItemFormSidebar);
74
+ }
@@ -1,5 +1,13 @@
1
1
  import { Ctx } from '../ctx/base';
2
- import { Icon } from '../icon';
2
+ import {
3
+ isArray,
4
+ isNullish,
5
+ isNumber,
6
+ isPlacement,
7
+ isRecord,
8
+ isString,
9
+ } from '../guardUtils.js';
10
+ import { Icon, isIcon } from '../icon';
3
11
 
4
12
  export type MainNavigationTabsHook = {
5
13
  /**
@@ -13,7 +21,11 @@ export type MainNavigationTabsHook = {
13
21
 
14
22
  export type MainNavigationTabsCtx = Ctx;
15
23
 
16
- /** A tab to be displayed in the top-bar of the UI */
24
+ /**
25
+ * An object expressing a tab to be displayed in the top-bar of the UI
26
+ *
27
+ * @see {isMainNavigationTab}
28
+ */
17
29
  export type MainNavigationTab = {
18
30
  /** Label to be shown. Must be unique. */
19
31
  label: string;
@@ -45,3 +57,23 @@ export type MainNavigationTab = {
45
57
  */
46
58
  rank?: number;
47
59
  };
60
+
61
+ export function isMainNavigationTab(
62
+ value: unknown,
63
+ ): value is MainNavigationTab {
64
+ return (
65
+ isRecord(value) &&
66
+ isString(value.label) &&
67
+ isIcon(value.icon) &&
68
+ isRecord(value.pointsTo) &&
69
+ isString(value.pointsTo.pageId) &&
70
+ (isNullish(value.placement) || isPlacement(value.placement)) &&
71
+ (isNullish(value.rank) || isNumber(value.rank))
72
+ );
73
+ }
74
+
75
+ export function isReturnTypeOfMainNavigationTabsHook(
76
+ value: unknown,
77
+ ): value is MainNavigationTab[] {
78
+ return isArray(value, isMainNavigationTab);
79
+ }
@@ -1,4 +1,12 @@
1
1
  import { Ctx } from '../ctx/base';
2
+ import {
3
+ isArray,
4
+ isBoolean,
5
+ isNullish,
6
+ isNumber,
7
+ isRecord,
8
+ isString,
9
+ } from '../guardUtils.js';
2
10
 
3
11
  export type ManualFieldExtensionsHook = {
4
12
  /**
@@ -14,6 +22,12 @@ export type ManualFieldExtensionsHook = {
14
22
 
15
23
  export type ManualFieldExtensionsCtx = Ctx;
16
24
 
25
+ /**
26
+ * An object expressing a field extension that users will be able
27
+ * to install manually in some field
28
+ *
29
+ * @see {isManualFieldExtension}
30
+ */
17
31
  export type ManualFieldExtension = {
18
32
  /**
19
33
  * ID of field extension. Will be the first argument for the
@@ -80,3 +94,32 @@ export type FieldType =
80
94
  | 'structured_text'
81
95
  | 'text'
82
96
  | 'video';
97
+
98
+ export function isManualFieldExtension(
99
+ value: unknown,
100
+ ): value is ManualFieldExtension {
101
+ return (
102
+ isRecord(value) &&
103
+ isString(value.id) &&
104
+ isString(value.name) &&
105
+ isString(value.type) &&
106
+ ['editor', 'addon'].includes(value.type) &&
107
+ (isNullish(value.asSidebarPanel) ||
108
+ isBoolean(value.asSidebarPanel) ||
109
+ (isRecord(value.asSidebarPanel) &&
110
+ isBoolean(value.asSidebarPanel.startOpen))) &&
111
+ ((isString(value.fieldTypes) && value.fieldTypes === 'all') ||
112
+ isArray(value.fieldTypes, isString)) &&
113
+ (isNullish(value.configurable) ||
114
+ isBoolean(value.configurable) ||
115
+ (isRecord(value.configurable) &&
116
+ isNumber(value.configurable.initialHeight))) &&
117
+ (isNullish(value.initialHeight) || isNumber(value.initialHeight))
118
+ );
119
+ }
120
+
121
+ export function isReturnTypeOfManualFieldExtensionsHook(
122
+ value: unknown,
123
+ ): value is ManualFieldExtension[] {
124
+ return isArray(value, isManualFieldExtension);
125
+ }
@@ -1,5 +1,14 @@
1
1
  import type { SchemaTypes } from '@datocms/cma-client';
2
2
  import { Ctx } from '../ctx/base';
3
+ import {
4
+ isArray,
5
+ isBoolean,
6
+ isNullish,
7
+ isNumber,
8
+ isPlacement,
9
+ isRecord,
10
+ isString,
11
+ } from '../guardUtils.js';
3
12
  import { ItemFormSidebarPanelPlacement } from '../shared';
4
13
 
5
14
  type Field = SchemaTypes.Field;
@@ -25,6 +34,8 @@ export type OverrideFieldExtensionsCtx = Ctx<{
25
34
  /**
26
35
  * An object expressing some field extensions you want to force on a particular
27
36
  * field
37
+ *
38
+ * @see {isFieldExtensionOverride}
28
39
  */
29
40
  export type FieldExtensionOverride = {
30
41
  /** Force a field editor/sidebar extension on a field */
@@ -93,3 +104,47 @@ export type AddonOverride = {
93
104
  */
94
105
  initialHeight?: number;
95
106
  };
107
+
108
+ export function isFieldExtensionOverride(
109
+ value: unknown,
110
+ ): value is FieldExtensionOverride {
111
+ return (
112
+ isNullish(value) ||
113
+ (isRecord(value) &&
114
+ (isNullish(value.editor) || isEditorOverride(value.editor)) &&
115
+ (isNullish(value.addons) || isArray(value.addons, isAddonOverride)))
116
+ );
117
+ }
118
+
119
+ export function isEditorOverride(value: unknown): value is EditorOverride {
120
+ return (
121
+ isRecord(value) &&
122
+ isString(value.id) &&
123
+ (isNullish(value.asSidebarPanel) ||
124
+ isBoolean(value.asSidebarPanel) ||
125
+ (isRecord(value.asSidebarPanel) &&
126
+ (isNullish(value.asSidebarPanel.startOpen) ||
127
+ isBoolean(value.asSidebarPanel.startOpen)) &&
128
+ (isNullish(value.asSidebarPanel.placement) ||
129
+ isPlacement(value.asSidebarPanel.placement)))) &&
130
+ (isNullish(value.parameters) || isRecord(value.parameters)) &&
131
+ (isNullish(value.rank) || isNumber(value.rank)) &&
132
+ (isNullish(value.initialHeight) || isNumber(value.initialHeight))
133
+ );
134
+ }
135
+
136
+ export function isAddonOverride(value: unknown): value is AddonOverride {
137
+ return (
138
+ isRecord(value) &&
139
+ isString(value.id) &&
140
+ (isNullish(value.parameters) || isRecord(value.parameters)) &&
141
+ (isNullish(value.rank) || isNumber(value.rank)) &&
142
+ (isNullish(value.initialHeight) || isNumber(value.initialHeight))
143
+ );
144
+ }
145
+
146
+ export function isReturnTypeOfOverrideFieldExtensionsHook(
147
+ value: unknown,
148
+ ): value is FieldExtensionOverride | undefined {
149
+ return isNullish(value) || isFieldExtensionOverride(value);
150
+ }
@@ -1,4 +1,13 @@
1
1
  import { Ctx } from '../ctx/base';
2
+ import {
3
+ isArray,
4
+ isBoolean,
5
+ isNullish,
6
+ isNumber,
7
+ isPlacement,
8
+ isRecord,
9
+ isString,
10
+ } from '../guardUtils.js';
2
11
 
3
12
  export type UploadSidebarPanelsHook = {
4
13
  /**
@@ -12,6 +21,12 @@ export type UploadSidebarPanelsHook = {
12
21
 
13
22
  export type UploadSidebarPanelsCtx = Ctx;
14
23
 
24
+ /**
25
+ * An object expressing a sidebar panel to be shown when the user
26
+ * opens up an asset in the Media Area
27
+ *
28
+ * @see {isUploadSidebarPanel}
29
+ */
15
30
  export type UploadSidebarPanel = {
16
31
  /**
17
32
  * ID of the panel. Will be the first argument for the
@@ -57,3 +72,24 @@ export type UploadSidebarPanelPlacement = [
57
72
  | 'replace'
58
73
  ),
59
74
  ];
75
+
76
+ export function isUploadSidebarPanel(
77
+ value: unknown,
78
+ ): value is UploadSidebarPanel {
79
+ return (
80
+ isRecord(value) &&
81
+ isString(value.id) &&
82
+ isString(value.label) &&
83
+ (isNullish(value.parameters) || isRecord(value.parameters)) &&
84
+ (isNullish(value.startOpen) || isBoolean(value.startOpen)) &&
85
+ (isNullish(value.placement) || isPlacement(value.placement)) &&
86
+ (isNullish(value.rank) || isNumber(value.rank)) &&
87
+ (isNullish(value.initialHeight) || isNumber(value.initialHeight))
88
+ );
89
+ }
90
+
91
+ export function isReturnTypeOfUploadSidebarPanelsHook(
92
+ value: unknown,
93
+ ): value is UploadSidebarPanel[] {
94
+ return isArray(value, isUploadSidebarPanel);
95
+ }
@@ -1,4 +1,11 @@
1
1
  import { Ctx } from '../ctx/base';
2
+ import {
3
+ isArray,
4
+ isNullish,
5
+ isNumber,
6
+ isRecord,
7
+ isString,
8
+ } from '../guardUtils.js';
2
9
 
3
10
  export type UploadSidebarsHook = {
4
11
  /**
@@ -12,6 +19,12 @@ export type UploadSidebarsHook = {
12
19
 
13
20
  export type UploadSidebarsCtx = Ctx;
14
21
 
22
+ /**
23
+ * An object expressing a sidebar to be shown when the user opens
24
+ * up an asset in the Media Area
25
+ *
26
+ * @see {isUploadSidebar}
27
+ */
15
28
  export type UploadSidebar = {
16
29
  /**
17
30
  * ID of the sidebar. Will be the first argument for the
@@ -36,3 +49,20 @@ export type UploadSidebar = {
36
49
  /** The preferred width for the sidebar */
37
50
  preferredWidth?: number;
38
51
  };
52
+
53
+ export function isUploadSidebar(value: unknown): value is UploadSidebar {
54
+ return (
55
+ isRecord(value) &&
56
+ isString(value.id) &&
57
+ isString(value.label) &&
58
+ (isNullish(value.parameters) || isRecord(value.parameters)) &&
59
+ (isNullish(value.rank) || isNumber(value.rank)) &&
60
+ (isNullish(value.preferredWidth) || isNumber(value.preferredWidth))
61
+ );
62
+ }
63
+
64
+ export function isReturnTypeOfUploadSidebarsHook(
65
+ value: unknown,
66
+ ): value is UploadSidebar[] {
67
+ return isArray(value, isUploadSidebar);
68
+ }
@@ -1,3 +1,5 @@
1
+ import { isRecord } from '../guardUtils';
2
+
1
3
  export type ValidateManualFieldExtensionParametersHook = {
2
4
  /**
3
5
  * This function will be called each time the configuration object changes. It
@@ -10,3 +12,9 @@ export type ValidateManualFieldExtensionParametersHook = {
10
12
  parameters: Record<string, unknown>,
11
13
  ) => Record<string, unknown> | Promise<Record<string, unknown>>;
12
14
  };
15
+
16
+ export function isReturnTypeOfValidateManualFieldExtensionParametersHook(
17
+ value: unknown,
18
+ ): value is Record<string, unknown> {
19
+ return isRecord(value);
20
+ }
package/src/icon.ts CHANGED
@@ -1,7 +1,19 @@
1
+ import { isRecord, isString } from './guardUtils.js';
2
+
1
3
  export type Icon =
2
4
  | AwesomeFontIconIdentifier
3
5
  | { type: 'svg'; viewBox: string; content: string };
4
6
 
7
+ export function isIcon(value: unknown): value is Icon {
8
+ return (
9
+ isString(value) ||
10
+ (isRecord(value) &&
11
+ value.type === 'svg' &&
12
+ isString(value.viewBox) &&
13
+ isString(value.content))
14
+ );
15
+ }
16
+
5
17
  export type AwesomeFontIconIdentifier =
6
18
  | '0'
7
19
  | '00'