@wordpress/core-data 4.13.0 → 5.0.0

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 (202) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/README.md +148 -65
  3. package/build/entities.js +38 -51
  4. package/build/entities.js.map +1 -1
  5. package/build/hooks/index.js +14 -0
  6. package/build/hooks/index.js.map +1 -1
  7. package/build/hooks/use-entity-record.js +10 -6
  8. package/build/hooks/use-entity-record.js.map +1 -1
  9. package/build/hooks/use-entity-records.js +2 -0
  10. package/build/hooks/use-entity-records.js.map +1 -1
  11. package/build/hooks/use-query-select.js +5 -2
  12. package/build/hooks/use-query-select.js.map +1 -1
  13. package/build/hooks/use-resource-permissions.js +74 -11
  14. package/build/hooks/use-resource-permissions.js.map +1 -1
  15. package/build/index.js +1 -30
  16. package/build/index.js.map +1 -1
  17. package/build/resolvers.js +59 -39
  18. package/build/resolvers.js.map +1 -1
  19. package/build/selectors.js +9 -46
  20. package/build/selectors.js.map +1 -1
  21. package/build-module/entities.js +38 -52
  22. package/build-module/entities.js.map +1 -1
  23. package/build-module/hooks/index.js +1 -0
  24. package/build-module/hooks/index.js.map +1 -1
  25. package/build-module/hooks/use-entity-record.js +10 -6
  26. package/build-module/hooks/use-entity-record.js.map +1 -1
  27. package/build-module/hooks/use-entity-records.js +2 -0
  28. package/build-module/hooks/use-entity-records.js.map +1 -1
  29. package/build-module/hooks/use-query-select.js +4 -1
  30. package/build-module/hooks/use-query-select.js.map +1 -1
  31. package/build-module/hooks/use-resource-permissions.js +70 -10
  32. package/build-module/hooks/use-resource-permissions.js.map +1 -1
  33. package/build-module/index.js +0 -5
  34. package/build-module/index.js.map +1 -1
  35. package/build-module/resolvers.js +59 -39
  36. package/build-module/resolvers.js.map +1 -1
  37. package/build-module/selectors.js +7 -44
  38. package/build-module/selectors.js.map +1 -1
  39. package/build-types/actions.d.ts +188 -0
  40. package/build-types/actions.d.ts.map +1 -0
  41. package/build-types/batch/create-batch.d.ts +71 -0
  42. package/build-types/batch/create-batch.d.ts.map +1 -0
  43. package/build-types/batch/default-processor.d.ts +11 -0
  44. package/build-types/batch/default-processor.d.ts.map +1 -0
  45. package/build-types/batch/index.d.ts +3 -0
  46. package/build-types/batch/index.d.ts.map +1 -0
  47. package/build-types/entities.d.ts +128 -0
  48. package/build-types/entities.d.ts.map +1 -0
  49. package/build-types/entity-provider.d.ts +68 -0
  50. package/build-types/entity-provider.d.ts.map +1 -0
  51. package/build-types/entity-types/attachment.d.ts +121 -0
  52. package/build-types/entity-types/attachment.d.ts.map +1 -0
  53. package/build-types/entity-types/base-entity-records.d.ts +37 -0
  54. package/build-types/entity-types/base-entity-records.d.ts.map +1 -0
  55. package/build-types/entity-types/comment.d.ts +82 -0
  56. package/build-types/entity-types/comment.d.ts.map +1 -0
  57. package/build-types/entity-types/helpers.d.ts +123 -0
  58. package/build-types/entity-types/helpers.d.ts.map +1 -0
  59. package/build-types/entity-types/index.d.ts +64 -0
  60. package/build-types/entity-types/index.d.ts.map +1 -0
  61. package/build-types/entity-types/menu-location.d.ts +25 -0
  62. package/build-types/entity-types/menu-location.d.ts.map +1 -0
  63. package/build-types/entity-types/nav-menu-item.d.ts +88 -0
  64. package/build-types/entity-types/nav-menu-item.d.ts.map +1 -0
  65. package/build-types/entity-types/nav-menu.d.ts +45 -0
  66. package/build-types/entity-types/nav-menu.d.ts.map +1 -0
  67. package/build-types/entity-types/page.d.ts +120 -0
  68. package/build-types/entity-types/page.d.ts.map +1 -0
  69. package/build-types/entity-types/plugin.d.ts +62 -0
  70. package/build-types/entity-types/plugin.d.ts.map +1 -0
  71. package/build-types/entity-types/post.d.ts +128 -0
  72. package/build-types/entity-types/post.d.ts.map +1 -0
  73. package/build-types/entity-types/settings.d.ts +89 -0
  74. package/build-types/entity-types/settings.d.ts.map +1 -0
  75. package/build-types/entity-types/sidebar.d.ts +55 -0
  76. package/build-types/entity-types/sidebar.d.ts.map +1 -0
  77. package/build-types/entity-types/taxonomy.d.ts +83 -0
  78. package/build-types/entity-types/taxonomy.d.ts.map +1 -0
  79. package/build-types/entity-types/theme.d.ts +206 -0
  80. package/build-types/entity-types/theme.d.ts.map +1 -0
  81. package/build-types/entity-types/type.d.ts +71 -0
  82. package/build-types/entity-types/type.d.ts.map +1 -0
  83. package/build-types/entity-types/user.d.ts +93 -0
  84. package/build-types/entity-types/user.d.ts.map +1 -0
  85. package/build-types/entity-types/widget-type.d.ts +33 -0
  86. package/build-types/entity-types/widget-type.d.ts.map +1 -0
  87. package/build-types/entity-types/widget.d.ts +59 -0
  88. package/build-types/entity-types/widget.d.ts.map +1 -0
  89. package/build-types/entity-types/wp-template-part.d.ts +80 -0
  90. package/build-types/entity-types/wp-template-part.d.ts.map +1 -0
  91. package/build-types/entity-types/wp-template.d.ts +80 -0
  92. package/build-types/entity-types/wp-template.d.ts.map +1 -0
  93. package/build-types/fetch/__experimental-fetch-link-suggestions.d.ts +139 -0
  94. package/build-types/fetch/__experimental-fetch-link-suggestions.d.ts.map +1 -0
  95. package/build-types/fetch/__experimental-fetch-url-data.d.ts +35 -0
  96. package/build-types/fetch/__experimental-fetch-url-data.d.ts.map +1 -0
  97. package/build-types/fetch/index.d.ts +3 -0
  98. package/build-types/fetch/index.d.ts.map +1 -0
  99. package/build-types/hooks/constants.d.ts +7 -0
  100. package/build-types/hooks/constants.d.ts.map +1 -0
  101. package/build-types/hooks/index.d.ts +4 -0
  102. package/build-types/hooks/index.d.ts.map +1 -0
  103. package/build-types/hooks/memoize.d.ts +3 -0
  104. package/build-types/hooks/memoize.d.ts.map +1 -0
  105. package/build-types/hooks/use-entity-record.d.ts +124 -0
  106. package/build-types/hooks/use-entity-record.d.ts.map +1 -0
  107. package/build-types/hooks/use-entity-records.d.ts +49 -0
  108. package/build-types/hooks/use-entity-records.d.ts.map +1 -0
  109. package/build-types/hooks/use-query-select.d.ts +46 -0
  110. package/build-types/hooks/use-query-select.d.ts.map +1 -0
  111. package/build-types/hooks/use-resource-permissions.d.ts +99 -0
  112. package/build-types/hooks/use-resource-permissions.d.ts.map +1 -0
  113. package/build-types/index.d.ts +131 -0
  114. package/build-types/index.d.ts.map +1 -0
  115. package/build-types/locks/actions.d.ts +7 -0
  116. package/build-types/locks/actions.d.ts.map +1 -0
  117. package/build-types/locks/engine.d.ts +5 -0
  118. package/build-types/locks/engine.d.ts.map +1 -0
  119. package/build-types/locks/reducer.d.ts +10 -0
  120. package/build-types/locks/reducer.d.ts.map +1 -0
  121. package/build-types/locks/selectors.d.ts +5 -0
  122. package/build-types/locks/selectors.d.ts.map +1 -0
  123. package/build-types/locks/utils.d.ts +8 -0
  124. package/build-types/locks/utils.d.ts.map +1 -0
  125. package/build-types/name.d.ts +8 -0
  126. package/build-types/name.d.ts.map +1 -0
  127. package/build-types/queried-data/actions.d.ts +32 -0
  128. package/build-types/queried-data/actions.d.ts.map +1 -0
  129. package/build-types/queried-data/get-query-parts.d.ts +60 -0
  130. package/build-types/queried-data/get-query-parts.d.ts.map +1 -0
  131. package/build-types/queried-data/index.d.ts +4 -0
  132. package/build-types/queried-data/index.d.ts.map +1 -0
  133. package/build-types/queried-data/reducer.d.ts +54 -0
  134. package/build-types/queried-data/reducer.d.ts.map +1 -0
  135. package/build-types/queried-data/selectors.d.ts +16 -0
  136. package/build-types/queried-data/selectors.d.ts.map +1 -0
  137. package/build-types/reducer.d.ts +156 -0
  138. package/build-types/reducer.d.ts.map +1 -0
  139. package/build-types/resolvers.d.ts +75 -0
  140. package/build-types/resolvers.d.ts.map +1 -0
  141. package/build-types/selectors.d.ts +524 -0
  142. package/build-types/selectors.d.ts.map +1 -0
  143. package/build-types/types.d.ts +4 -0
  144. package/build-types/types.d.ts.map +1 -0
  145. package/build-types/utils/conservative-map-item.d.ts +12 -0
  146. package/build-types/utils/conservative-map-item.d.ts.map +1 -0
  147. package/build-types/utils/forward-resolver.d.ts +10 -0
  148. package/build-types/utils/forward-resolver.d.ts.map +1 -0
  149. package/build-types/utils/get-normalized-comma-separable.d.ts +12 -0
  150. package/build-types/utils/get-normalized-comma-separable.d.ts.map +1 -0
  151. package/build-types/utils/if-matching-action.d.ts +14 -0
  152. package/build-types/utils/if-matching-action.d.ts.map +1 -0
  153. package/build-types/utils/index.d.ts +9 -0
  154. package/build-types/utils/index.d.ts.map +1 -0
  155. package/build-types/utils/is-raw-attribute.d.ts +10 -0
  156. package/build-types/utils/is-raw-attribute.d.ts.map +1 -0
  157. package/build-types/utils/on-sub-key.d.ts +4 -0
  158. package/build-types/utils/on-sub-key.d.ts.map +1 -0
  159. package/build-types/utils/replace-action.d.ts +13 -0
  160. package/build-types/utils/replace-action.d.ts.map +1 -0
  161. package/build-types/utils/with-weak-map-cache.d.ts +12 -0
  162. package/build-types/utils/with-weak-map-cache.d.ts.map +1 -0
  163. package/package.json +13 -11
  164. package/src/entities.js +325 -0
  165. package/src/entity-types/attachment.ts +3 -4
  166. package/src/entity-types/comment.ts +3 -4
  167. package/src/entity-types/index.ts +31 -88
  168. package/src/entity-types/menu-location.ts +3 -4
  169. package/src/entity-types/nav-menu-item.ts +3 -4
  170. package/src/entity-types/nav-menu.ts +3 -3
  171. package/src/entity-types/page.ts +3 -3
  172. package/src/entity-types/plugin.ts +3 -3
  173. package/src/entity-types/post.ts +3 -3
  174. package/src/entity-types/settings.ts +3 -3
  175. package/src/entity-types/sidebar.ts +3 -4
  176. package/src/entity-types/taxonomy.ts +3 -4
  177. package/src/entity-types/theme.ts +7 -3
  178. package/src/entity-types/type.ts +3 -3
  179. package/src/entity-types/user.ts +3 -3
  180. package/src/entity-types/widget-type.ts +3 -4
  181. package/src/entity-types/widget.ts +3 -3
  182. package/src/entity-types/wp-template-part.ts +3 -4
  183. package/src/entity-types/wp-template.ts +3 -4
  184. package/src/hooks/index.ts +4 -0
  185. package/src/hooks/test/use-entity-record.js +41 -1
  186. package/src/hooks/test/use-resource-permissions.js +32 -36
  187. package/src/hooks/use-entity-record.ts +18 -6
  188. package/src/hooks/use-entity-records.ts +2 -0
  189. package/src/hooks/use-query-select.ts +4 -1
  190. package/src/hooks/use-resource-permissions.ts +84 -20
  191. package/src/index.js +0 -5
  192. package/src/resolvers.js +80 -45
  193. package/src/selectors.ts +202 -341
  194. package/src/test/resolvers.js +118 -4
  195. package/tsconfig.json +21 -0
  196. package/tsconfig.tsbuildinfo +1 -0
  197. package/build/entity-types/entities.js +0 -6
  198. package/build/entity-types/entities.js.map +0 -1
  199. package/build-module/entity-types/entities.js +0 -2
  200. package/build-module/entity-types/entities.js.map +0 -1
  201. package/src/entities.ts +0 -548
  202. package/src/entity-types/entities.ts +0 -130
@@ -0,0 +1,188 @@
1
+ /**
2
+ * Returns an action object used in signalling that authors have been received.
3
+ * Ignored from documentation as it's internal to the data store.
4
+ *
5
+ * @ignore
6
+ *
7
+ * @param {string} queryID Query ID.
8
+ * @param {Array|Object} users Users received.
9
+ *
10
+ * @return {Object} Action object.
11
+ */
12
+ export function receiveUserQuery(queryID: string, users: any[] | any): any;
13
+ /**
14
+ * Returns an action used in signalling that the current user has been received.
15
+ * Ignored from documentation as it's internal to the data store.
16
+ *
17
+ * @ignore
18
+ *
19
+ * @param {Object} currentUser Current user object.
20
+ *
21
+ * @return {Object} Action object.
22
+ */
23
+ export function receiveCurrentUser(currentUser: any): any;
24
+ /**
25
+ * Returns an action object used in adding new entities.
26
+ *
27
+ * @param {Array} entities Entities received.
28
+ *
29
+ * @return {Object} Action object.
30
+ */
31
+ export function addEntities(entities: any[]): any;
32
+ /**
33
+ * Returns an action object used in signalling that entity records have been received.
34
+ *
35
+ * @param {string} kind Kind of the received entity record.
36
+ * @param {string} name Name of the received entity record.
37
+ * @param {Array|Object} records Records received.
38
+ * @param {?Object} query Query Object.
39
+ * @param {?boolean} invalidateCache Should invalidate query caches.
40
+ * @param {?Object} edits Edits to reset.
41
+ * @return {Object} Action object.
42
+ */
43
+ export function receiveEntityRecords(kind: string, name: string, records: any[] | any, query: any | null, invalidateCache: boolean | null | undefined, edits: any | null): any;
44
+ /**
45
+ * Returns an action object used in signalling that the current theme has been received.
46
+ * Ignored from documentation as it's internal to the data store.
47
+ *
48
+ * @ignore
49
+ *
50
+ * @param {Object} currentTheme The current theme.
51
+ *
52
+ * @return {Object} Action object.
53
+ */
54
+ export function receiveCurrentTheme(currentTheme: any): any;
55
+ /**
56
+ * Returns an action object used in signalling that the current global styles id has been received.
57
+ * Ignored from documentation as it's internal to the data store.
58
+ *
59
+ * @ignore
60
+ *
61
+ * @param {string} currentGlobalStylesId The current global styles id.
62
+ *
63
+ * @return {Object} Action object.
64
+ */
65
+ export function __experimentalReceiveCurrentGlobalStylesId(currentGlobalStylesId: string): any;
66
+ /**
67
+ * Returns an action object used in signalling that the theme base global styles have been received
68
+ * Ignored from documentation as it's internal to the data store.
69
+ *
70
+ * @ignore
71
+ *
72
+ * @param {string} stylesheet The theme's identifier
73
+ * @param {Object} globalStyles The global styles object.
74
+ *
75
+ * @return {Object} Action object.
76
+ */
77
+ export function __experimentalReceiveThemeBaseGlobalStyles(stylesheet: string, globalStyles: any): any;
78
+ /**
79
+ * Returns an action object used in signalling that the theme global styles variations have been received.
80
+ * Ignored from documentation as it's internal to the data store.
81
+ *
82
+ * @ignore
83
+ *
84
+ * @param {string} stylesheet The theme's identifier
85
+ * @param {Array} variations The global styles variations.
86
+ *
87
+ * @return {Object} Action object.
88
+ */
89
+ export function __experimentalReceiveThemeGlobalStyleVariations(stylesheet: string, variations: any[]): any;
90
+ /**
91
+ * Returns an action object used in signalling that the index has been received.
92
+ *
93
+ * @deprecated since WP 5.9, this is not useful anymore, use the selector direclty.
94
+ *
95
+ * @return {Object} Action object.
96
+ */
97
+ export function receiveThemeSupports(): any;
98
+ /**
99
+ * Returns an action object used in signalling that the preview data for
100
+ * a given URl has been received.
101
+ * Ignored from documentation as it's internal to the data store.
102
+ *
103
+ * @ignore
104
+ *
105
+ * @param {string} url URL to preview the embed for.
106
+ * @param {*} preview Preview data.
107
+ *
108
+ * @return {Object} Action object.
109
+ */
110
+ export function receiveEmbedPreview(url: string, preview: any): any;
111
+ /**
112
+ * Forces the creation of a new undo level.
113
+ *
114
+ * @return {Object} Action object.
115
+ */
116
+ export function __unstableCreateUndoLevel(): any;
117
+ /**
118
+ * Returns an action object used in signalling that Upload permissions have been received.
119
+ *
120
+ * @deprecated since WP 5.9, use receiveUserPermission instead.
121
+ *
122
+ * @param {boolean} hasUploadPermissions Does the user have permission to upload files?
123
+ *
124
+ * @return {Object} Action object.
125
+ */
126
+ export function receiveUploadPermissions(hasUploadPermissions: boolean): any;
127
+ /**
128
+ * Returns an action object used in signalling that the current user has
129
+ * permission to perform an action on a REST resource.
130
+ * Ignored from documentation as it's internal to the data store.
131
+ *
132
+ * @ignore
133
+ *
134
+ * @param {string} key A key that represents the action and REST resource.
135
+ * @param {boolean} isAllowed Whether or not the user can perform the action.
136
+ *
137
+ * @return {Object} Action object.
138
+ */
139
+ export function receiveUserPermission(key: string, isAllowed: boolean): any;
140
+ /**
141
+ * Returns an action object used in signalling that the autosaves for a
142
+ * post have been received.
143
+ * Ignored from documentation as it's internal to the data store.
144
+ *
145
+ * @ignore
146
+ *
147
+ * @param {number} postId The id of the post that is parent to the autosave.
148
+ * @param {Array|Object} autosaves An array of autosaves or singular autosave object.
149
+ *
150
+ * @return {Object} Action object.
151
+ */
152
+ export function receiveAutosaves(postId: number, autosaves: any[] | any): any;
153
+ export function deleteEntityRecord(kind: string, name: string, recordId: string, query: any | null, { __unstableFetch, throwOnError }?: {
154
+ __unstableFetch?: Function | undefined;
155
+ throwOnError?: boolean | undefined;
156
+ } | undefined): ({ dispatch }: {
157
+ dispatch: any;
158
+ }) => Promise<boolean | undefined>;
159
+ export function editEntityRecord(kind: string, name: string, recordId: number, edits: any, options?: {
160
+ undoIgnore?: boolean | undefined;
161
+ }): any;
162
+ export function undo(): ({ select, dispatch }: {
163
+ select: any;
164
+ dispatch: any;
165
+ }) => void;
166
+ export function redo(): ({ select, dispatch }: {
167
+ select: any;
168
+ dispatch: any;
169
+ }) => void;
170
+ export function saveEntityRecord(kind: string, name: string, record: any, { isAutosave, __unstableFetch, throwOnError, }?: {
171
+ isAutosave?: boolean | undefined;
172
+ __unstableFetch?: Function | undefined;
173
+ throwOnError?: boolean | undefined;
174
+ }): ({ select, resolveSelect, dispatch }: {
175
+ select: any;
176
+ resolveSelect: any;
177
+ dispatch: any;
178
+ }) => Promise<any>;
179
+ export function __experimentalBatch(requests: any[]): (thunkArgs: any) => Promise<any>;
180
+ export function saveEditedEntityRecord(kind: string, name: string, recordId: any, options: any): ({ select, dispatch }: {
181
+ select: any;
182
+ dispatch: any;
183
+ }) => Promise<any>;
184
+ export function __experimentalSaveSpecifiedEntityEdits(kind: string, name: string, recordId: any, itemsToSave: any[], options: any): ({ select, dispatch }: {
185
+ select: any;
186
+ dispatch: any;
187
+ }) => Promise<any>;
188
+ //# sourceMappingURL=actions.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"actions.d.ts","sourceRoot":"","sources":["../src/actions.js"],"names":[],"mappings":"AAqBA;;;;;;;;;;GAUG;AACH,0CALW,MAAM,SACN,WAAY,OAUtB;AAED;;;;;;;;;GASG;AACH,0DAKC;AAED;;;;;;GAMG;AACH,kDAKC;AAED;;;;;;;;;;GAUG;AACH,2CARW,MAAM,QACN,MAAM,WACN,WAAY,0FAkCtB;AAED;;;;;;;;;GASG;AACH,4DAKC;AAED;;;;;;;;;GASG;AACH,kFAJW,MAAM,OAWhB;AAED;;;;;;;;;;GAUG;AACH,uEALW,MAAM,0BAchB;AAED;;;;;;;;;;GAUG;AACH,4EALW,MAAM,0BAchB;AAED;;;;;;GAMG;AACH,4CAQC;AAED;;;;;;;;;;;GAWG;AACH,yCALW,MAAM,qBAWhB;AAwLD;;;;GAIG;AACH,iDAEC;AA8VD;;;;;;;;GAQG;AACH,+DAJW,OAAO,OAWjB;AAED;;;;;;;;;;;GAWG;AACH,2CALW,MAAM,aACN,OAAO,OAUjB;AAED;;;;;;;;;;;GAWG;AACH,yCALW,MAAM,aACN,WAAY,OAUtB;AApkBM,yCAZI,MAAM,QACN,MAAM,YACN,MAAM;;;;;mCA4Ef;AAeK,uCATI,MAAM,QACN,MAAM,YACN,MAAM;IAGY,UAAU;QAoDrC;AAMK;;;WAYL;AAMK;;;WAYL;AAyBK,uCAXI,MAAM,QACN,MAAM;IAGa,UAAU;IACV,eAAe;IAGf,YAAY;;;;;mBAmNxC;AAwBK,uFAoCL;AAUK,6CALI,MAAM,QACN,MAAM;;;mBAwBf;AAWK,6DANI,MAAM,QACN,MAAM;;;mBA4Bf"}
@@ -0,0 +1,71 @@
1
+ /**
2
+ * Creates a batch, which can be used to combine multiple API requests into one
3
+ * API request using the WordPress batch processing API (/v1/batch).
4
+ *
5
+ * ```
6
+ * const batch = createBatch();
7
+ * const dunePromise = batch.add( {
8
+ * path: '/v1/books',
9
+ * method: 'POST',
10
+ * data: { title: 'Dune' }
11
+ * } );
12
+ * const lotrPromise = batch.add( {
13
+ * path: '/v1/books',
14
+ * method: 'POST',
15
+ * data: { title: 'Lord of the Rings' }
16
+ * } );
17
+ * const isSuccess = await batch.run(); // Sends one POST to /v1/batch.
18
+ * if ( isSuccess ) {
19
+ * console.log(
20
+ * 'Saved two books:',
21
+ * await dunePromise,
22
+ * await lotrPromise
23
+ * );
24
+ * }
25
+ * ```
26
+ *
27
+ * @param {Function} [processor] Processor function. Can be used to replace the
28
+ * default functionality which is to send an API
29
+ * request to /v1/batch. Is given an array of
30
+ * inputs and must return a promise that
31
+ * resolves to an array of objects containing
32
+ * either `output` or `error`.
33
+ */
34
+ export default function createBatch(processor?: Function | undefined): {
35
+ /**
36
+ * Adds an input to the batch and returns a promise that is resolved or
37
+ * rejected when the input is processed by `batch.run()`.
38
+ *
39
+ * You may also pass a thunk which allows inputs to be added
40
+ * asychronously.
41
+ *
42
+ * ```
43
+ * // Both are allowed:
44
+ * batch.add( { path: '/v1/books', ... } );
45
+ * batch.add( ( add ) => add( { path: '/v1/books', ... } ) );
46
+ * ```
47
+ *
48
+ * If a thunk is passed, `batch.run()` will pause until either:
49
+ *
50
+ * - The thunk calls its `add` argument, or;
51
+ * - The thunk returns a promise and that promise resolves, or;
52
+ * - The thunk returns a non-promise.
53
+ *
54
+ * @param {any|Function} inputOrThunk Input to add or thunk to execute.
55
+ *
56
+ * @return {Promise|any} If given an input, returns a promise that
57
+ * is resolved or rejected when the batch is
58
+ * processed. If given a thunk, returns the return
59
+ * value of that thunk.
60
+ */
61
+ add(inputOrThunk: any | Function): Promise<any> | any;
62
+ /**
63
+ * Runs the batch. This calls `batchProcessor` and resolves or rejects
64
+ * all promises returned by `add()`.
65
+ *
66
+ * @return {Promise<boolean>} A promise that resolves to a boolean that is true
67
+ * if the processor returned no errors.
68
+ */
69
+ run(): Promise<boolean>;
70
+ };
71
+ //# sourceMappingURL=create-batch.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"create-batch.d.ts","sourceRoot":"","sources":["../../src/batch/create-batch.js"],"names":[],"mappings":"AAKA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgCG;AACH;IAOE;;;;;;;;;;;;;;;;;;;;;;;;;OAyBG;sBANQ,GAAG,WAAS,GAEX,eAAQ,GAAG;IA4BvB;;;;;;OAMG;WAFS,QAAQ,OAAO,CAAC;EAqD7B"}
@@ -0,0 +1,11 @@
1
+ /**
2
+ * Default batch processor. Sends its input requests to /batch/v1.
3
+ *
4
+ * @param {Array} requests List of API requests to perform at once.
5
+ *
6
+ * @return {Promise} Promise that resolves to a list of objects containing
7
+ * either `output` (if that request was succesful) or `error`
8
+ * (if not ).
9
+ */
10
+ export default function defaultProcessor(requests: any[]): Promise<any>;
11
+ //# sourceMappingURL=default-processor.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"default-processor.d.ts","sourceRoot":"","sources":["../../src/batch/default-processor.js"],"names":[],"mappings":"AAuBA;;;;;;;;GAQG;AACH,wEAiDC"}
@@ -0,0 +1,3 @@
1
+ export { default as createBatch } from "./create-batch";
2
+ export { default as defaultProcessor } from "./default-processor";
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/batch/index.js"],"names":[],"mappings":""}
@@ -0,0 +1,128 @@
1
+ export const DEFAULT_ENTITY_KEY: "id";
2
+ export const rootEntitiesConfig: ({
3
+ label: string;
4
+ kind: string;
5
+ name: string;
6
+ baseURL: string;
7
+ baseURLParams: {
8
+ _fields: string;
9
+ context?: undefined;
10
+ };
11
+ getTitle?: undefined;
12
+ key?: undefined;
13
+ plural?: undefined;
14
+ rawAttributes?: undefined;
15
+ transientEdits?: undefined;
16
+ } | {
17
+ label: string;
18
+ name: string;
19
+ kind: string;
20
+ baseURL: string;
21
+ getTitle: (record: any) => any;
22
+ baseURLParams?: undefined;
23
+ key?: undefined;
24
+ plural?: undefined;
25
+ rawAttributes?: undefined;
26
+ transientEdits?: undefined;
27
+ } | {
28
+ label: string;
29
+ name: string;
30
+ kind: string;
31
+ key: string;
32
+ baseURL: string;
33
+ baseURLParams: {
34
+ context: string;
35
+ _fields?: undefined;
36
+ };
37
+ getTitle?: undefined;
38
+ plural?: undefined;
39
+ rawAttributes?: undefined;
40
+ transientEdits?: undefined;
41
+ } | {
42
+ name: string;
43
+ kind: string;
44
+ baseURL: string;
45
+ baseURLParams: {
46
+ context: string;
47
+ _fields?: undefined;
48
+ };
49
+ plural: string;
50
+ label: string;
51
+ rawAttributes: string[];
52
+ getTitle?: undefined;
53
+ key?: undefined;
54
+ transientEdits?: undefined;
55
+ } | {
56
+ name: string;
57
+ kind: string;
58
+ key: string;
59
+ baseURL: string;
60
+ baseURLParams: {
61
+ context: string;
62
+ _fields?: undefined;
63
+ };
64
+ plural: string;
65
+ label: string;
66
+ getTitle?: undefined;
67
+ rawAttributes?: undefined;
68
+ transientEdits?: undefined;
69
+ } | {
70
+ name: string;
71
+ kind: string;
72
+ baseURL: string;
73
+ baseURLParams: {
74
+ context: string;
75
+ _fields?: undefined;
76
+ };
77
+ plural: string;
78
+ transientEdits: {
79
+ blocks: boolean;
80
+ };
81
+ label: string;
82
+ getTitle?: undefined;
83
+ key?: undefined;
84
+ rawAttributes?: undefined;
85
+ } | {
86
+ name: string;
87
+ kind: string;
88
+ baseURL: string;
89
+ baseURLParams: {
90
+ context: string;
91
+ _fields?: undefined;
92
+ };
93
+ plural: string;
94
+ label: string;
95
+ getTitle?: undefined;
96
+ key?: undefined;
97
+ rawAttributes?: undefined;
98
+ transientEdits?: undefined;
99
+ } | {
100
+ label: string;
101
+ name: string;
102
+ kind: string;
103
+ baseURL: string;
104
+ baseURLParams: {
105
+ context: string;
106
+ _fields?: undefined;
107
+ };
108
+ plural: string;
109
+ getTitle: (record: any) => any;
110
+ key?: undefined;
111
+ rawAttributes?: undefined;
112
+ transientEdits?: undefined;
113
+ })[];
114
+ export const additionalEntityConfigLoaders: {
115
+ kind: string;
116
+ loadEntities: typeof loadPostTypeEntities;
117
+ }[];
118
+ export function prePersistPostType(persistedRecord: any, edits: any): any;
119
+ export function getMethodName(kind: string, name: string, prefix?: string, usePlural?: boolean): string;
120
+ export function getOrLoadEntitiesConfig(kind: string): (thunkArgs: object) => Promise<any[]>;
121
+ /**
122
+ * Returns the list of post type entities.
123
+ *
124
+ * @return {Promise} Entities promise
125
+ */
126
+ declare function loadPostTypeEntities(): Promise<any>;
127
+ export {};
128
+ //# sourceMappingURL=entities.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"entities.d.ts","sourceRoot":"","sources":["../src/entities.js"],"names":[],"mappings":"AAiBA,sCAAuC;AAIvC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;KAoJE;AAEF;;;IAGE;AASK,0EAqBN;AAgFM,oCAPI,MAAM,QACN,MAAM,WACN,MAAM,cACN,OAAO,GAEN,MAAM,CAgBjB;AASM,8CAJI,MAAM,eAEO,MAAM,KAAK,cAAc,CAmB/C;AAtHF;;;;GAIG;AACH,sDA+BC"}
@@ -0,0 +1,68 @@
1
+ /**
2
+ * Context provider component for providing
3
+ * an entity for a specific entity.
4
+ *
5
+ * @param {Object} props The component's props.
6
+ * @param {string} props.kind The entity kind.
7
+ * @param {string} props.type The entity name.
8
+ * @param {number} props.id The entity ID.
9
+ * @param {*} props.children The children to wrap.
10
+ *
11
+ * @return {Object} The provided children, wrapped with
12
+ * the entity's context provider.
13
+ */
14
+ export default function EntityProvider({ kind, type: name, id, children }: {
15
+ kind: string;
16
+ type: string;
17
+ id: number;
18
+ children: any;
19
+ }): any;
20
+ /**
21
+ * Hook that returns the ID for the nearest
22
+ * provided entity of the specified type.
23
+ *
24
+ * @param {string} kind The entity kind.
25
+ * @param {string} name The entity name.
26
+ */
27
+ export function useEntityId(kind: string, name: string): any;
28
+ /**
29
+ * Hook that returns the value and a setter for the
30
+ * specified property of the nearest provided
31
+ * entity of the specified type.
32
+ *
33
+ * @param {string} kind The entity kind.
34
+ * @param {string} name The entity name.
35
+ * @param {string} prop The property name.
36
+ * @param {string} [_id] An entity ID to use instead of the context-provided one.
37
+ *
38
+ * @return {[*, Function, *]} An array where the first item is the
39
+ * property value, the second is the
40
+ * setter and the third is the full value
41
+ * object from REST API containing more
42
+ * information like `raw`, `rendered` and
43
+ * `protected` props.
44
+ */
45
+ export function useEntityProp(kind: string, name: string, prop: string, _id?: string | undefined): [any, Function, any];
46
+ /**
47
+ * Hook that returns block content getters and setters for
48
+ * the nearest provided entity of the specified type.
49
+ *
50
+ * The return value has the shape `[ blocks, onInput, onChange ]`.
51
+ * `onInput` is for block changes that don't create undo levels
52
+ * or dirty the post, non-persistent changes, and `onChange` is for
53
+ * peristent changes. They map directly to the props of a
54
+ * `BlockEditorProvider` and are intended to be used with it,
55
+ * or similar components or hooks.
56
+ *
57
+ * @param {string} kind The entity kind.
58
+ * @param {string} name The entity name.
59
+ * @param {Object} options
60
+ * @param {string} [options.id] An entity ID to use instead of the context-provided one.
61
+ *
62
+ * @return {[WPBlock[], Function, Function]} The block array and setters.
63
+ */
64
+ export function useEntityBlockEditor(kind: string, name: string, { id: _id }?: {
65
+ id?: string | undefined;
66
+ }): [WPBlock[], Function, Function];
67
+ export type WPBlock = any;
68
+ //# sourceMappingURL=entity-provider.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"entity-provider.d.ts","sourceRoot":"","sources":["../src/entity-provider.js"],"names":[],"mappings":"AAuDA;;;;;;;;;;;;GAYG;AACH;IARyB,IAAI,EAAlB,MAAM;IACQ,IAAI,EAAlB,MAAM;IACQ,EAAE,EAAhB,MAAM;IACQ,QAAQ;QAQhC;AAED;;;;;;GAMG;AACH,kCAHW,MAAM,QACN,MAAM,OAIhB;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,oCAZW,MAAM,QACN,MAAM,QACN,MAAM,6BAGL,oBAAgB,CAqC3B;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,2CAPW,MAAM,QACN,MAAM;IAEW,EAAE;IAElB,CAAC,OAAO,EAAE,qBAAqB,CAoE1C"}
@@ -0,0 +1,121 @@
1
+ /**
2
+ * Internal dependencies
3
+ */
4
+ import type { Context, ContextualField, MediaType, PostStatus, RenderedText, OmitNevers, CommentingStatus, PingStatus } from './helpers';
5
+ import type { BaseEntityRecords as _BaseEntityRecords } from './base-entity-records';
6
+ declare module './base-entity-records' {
7
+ namespace BaseEntityRecords {
8
+ interface Attachment<C extends Context> {
9
+ /**
10
+ * The date the post was published, in the site's timezone.
11
+ */
12
+ date: string | null;
13
+ /**
14
+ * The date the post was published, as GMT.
15
+ */
16
+ date_gmt: ContextualField<string | null, 'view' | 'edit', C>;
17
+ /**
18
+ * The globally unique identifier for the post.
19
+ */
20
+ guid: ContextualField<RenderedText<C>, 'view' | 'edit', C>;
21
+ /**
22
+ * Unique identifier for the post.
23
+ */
24
+ id: number;
25
+ /**
26
+ * URL to the post.
27
+ */
28
+ link: string;
29
+ /**
30
+ * The date the post was last modified, in the site's timezone.
31
+ */
32
+ modified: ContextualField<string, 'view' | 'edit', C>;
33
+ /**
34
+ * The date the post was last modified, as GMT.
35
+ */
36
+ modified_gmt: ContextualField<string, 'view' | 'edit', C>;
37
+ /**
38
+ * An alphanumeric identifier for the post unique to its type.
39
+ */
40
+ slug: string;
41
+ /**
42
+ * A named status for the post.
43
+ */
44
+ status: ContextualField<PostStatus, 'view' | 'edit', C>;
45
+ /**
46
+ * Type of post.
47
+ */
48
+ type: string;
49
+ /**
50
+ * Permalink template for the post.
51
+ */
52
+ permalink_template: ContextualField<string, 'edit', C>;
53
+ /**
54
+ * Slug automatically generated from the post title.
55
+ */
56
+ generated_slug: ContextualField<string, 'edit', C>;
57
+ /**
58
+ * The title for the post.
59
+ */
60
+ title: RenderedText<C>;
61
+ /**
62
+ * The ID for the author of the post.
63
+ */
64
+ author: number;
65
+ /**
66
+ * Whether or not comments are open on the post.
67
+ */
68
+ comment_status: ContextualField<CommentingStatus, 'view' | 'edit', C>;
69
+ /**
70
+ * Whether or not the post can be pinged.
71
+ */
72
+ ping_status: ContextualField<PingStatus, 'view' | 'edit', C>;
73
+ /**
74
+ * Meta fields.
75
+ */
76
+ meta: ContextualField<Record<string, string>, 'view' | 'edit', C>;
77
+ /**
78
+ * The theme file to use to display the post.
79
+ */
80
+ template: ContextualField<string, 'view' | 'edit', C>;
81
+ /**
82
+ * Alternative text to display when attachment is not displayed.
83
+ */
84
+ alt_text: string;
85
+ /**
86
+ * The attachment caption.
87
+ */
88
+ caption: ContextualField<string, 'edit', C>;
89
+ /**
90
+ * The attachment description.
91
+ */
92
+ description: ContextualField<RenderedText<C>, 'view' | 'edit', C>;
93
+ /**
94
+ * Attachment type.
95
+ */
96
+ media_type: MediaType;
97
+ /**
98
+ * The attachment MIME type.
99
+ */
100
+ mime_type: string;
101
+ /**
102
+ * Details about the media file, specific to its type.
103
+ */
104
+ media_details: Record<string, string>;
105
+ /**
106
+ * The ID for the associated post of the attachment.
107
+ */
108
+ post: ContextualField<number, 'view' | 'edit', C>;
109
+ /**
110
+ * URL to the original attachment file.
111
+ */
112
+ source_url: string;
113
+ /**
114
+ * List of the missing image sizes of the attachment.
115
+ */
116
+ missing_image_sizes: ContextualField<string[], 'edit', C>;
117
+ }
118
+ }
119
+ }
120
+ export declare type Attachment<C extends Context = 'edit'> = OmitNevers<_BaseEntityRecords.Attachment<C>>;
121
+ //# sourceMappingURL=attachment.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"attachment.d.ts","sourceRoot":"","sources":["../../src/entity-types/attachment.ts"],"names":[],"mappings":"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"}
@@ -0,0 +1,37 @@
1
+ /**
2
+ * This module exists solely to make the BaseEntityRecords namespace extensible
3
+ * with declaration merging:
4
+ *
5
+ * ```ts
6
+ * declare module './base-entity-records' {
7
+ * export namespace BaseEntityRecords {
8
+ * export interface Comment< C extends Context > {
9
+ * id: number;
10
+ * // ...
11
+ * }
12
+ * }
13
+ * }
14
+ * ```
15
+ *
16
+ * The huge upside is that consumers of @wordpress/core-data may extend the
17
+ * exported data types using interface merging as follows:
18
+ *
19
+ * ```ts
20
+ * import type { Context } from '@wordpress/core-data';
21
+ * declare module '@wordpress/core-data' {
22
+ * export namespace BaseEntityRecords {
23
+ * export interface Comment< C extends Context > {
24
+ * numberOfViews: number;
25
+ * }
26
+ * }
27
+ * }
28
+ *
29
+ * import type { Comment } from '@wordpress/core-data';
30
+ * const c : Comment< 'view' > = ...;
31
+ *
32
+ * // c.numberOfViews is a number
33
+ * // c.id is still present
34
+ * ```
35
+ */
36
+ export declare namespace BaseEntityRecords { }
37
+ //# sourceMappingURL=base-entity-records.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"base-entity-records.d.ts","sourceRoot":"","sources":["../../src/entity-types/base-entity-records.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkCG;AACH,yBAAiB,iBAAiB,CAAC,GAAE"}