@atlaskit/node-data-provider 4.4.0 → 4.5.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.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,14 @@
1
1
  # @atlaskit/node-data-provider
2
2
 
3
+ ## 4.5.0
4
+
5
+ ### Minor Changes
6
+
7
+ - [#193382](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/pull-requests/193382)
8
+ [`5c827a7e9ac42`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/5c827a7e9ac42) -
9
+ [https://product-fabric.atlassian.net/browse/ED-28627](ED-28627) - add `duration` and `success` to
10
+ `prefetchNodeDataProvidersData` result
11
+
3
12
  ## 4.4.0
4
13
 
5
14
  ### Minor Changes
@@ -20,14 +20,28 @@ var _findNodesToPrefetch = require("./find-nodes-to-prefetch");
20
20
  */
21
21
  /**
22
22
  * Represents the aggregated SSR data for all node data providers.
23
- * It's a map where each key is a provider's name and the value is the {@link SsrData} for that provider.
24
- * This structure is used to hydrate the client-side caches.
23
+ * Each key is a provider's name, and the value contains the fetch status, duration,
24
+ * and a map of node data keys to their prefetched data.
25
25
  *
26
26
  * @example
27
+ * ```
27
28
  * {
28
- * 'mentionProvider': { 'mention-1': { id: '1', name: 'John Doe' } },
29
- * 'emojiProvider': { 'emoji-123': { shortName: ':smile:', representation: '😊' } }
29
+ * mentionProvider: {
30
+ * success: true,
31
+ * duration: 220,
32
+ * data: {
33
+ * 'mention-1': { id: '1', name: 'John Doe' }
34
+ * }
35
+ * },
36
+ * emojiProvider: {
37
+ * success: true,
38
+ * duration: 110,
39
+ * data: {
40
+ * 'emoji-123': { shortName: ':smile:', representation: '😊' }
41
+ * }
42
+ * }
30
43
  * }
44
+ * ```
31
45
  */
32
46
  /**
33
47
  * Fetches data for nodes in the document that are supported by the given providers.
@@ -49,7 +63,7 @@ var _findNodesToPrefetch = require("./find-nodes-to-prefetch");
49
63
  * },
50
64
  * ];
51
65
  *
52
- * window['__SSR_EDITOR_NODE_DATA_PROVIDERS_DATA__'] = await prefetchNodeDataProvidersData({
66
+ * const data = await prefetchNodeDataProvidersData({
53
67
  * providers,
54
68
  * doc,
55
69
  * timeout: 1_000,
@@ -59,7 +73,7 @@ var _findNodesToPrefetch = require("./find-nodes-to-prefetch");
59
73
  *
60
74
  * @param props The properties for prefetching node data.
61
75
  * @returns Record of provider names to their respective SSR data,
62
- * where each SSR data is a record of node data keys to the fetched data.
76
+ * success status, and duration of the fetch operation.
63
77
  */
64
78
  function prefetchNodeDataProvidersData(_x) {
65
79
  return _prefetchNodeDataProvidersData.apply(this, arguments);
@@ -101,39 +115,47 @@ function _prefetchNodeDataProvidersData() {
101
115
  });
102
116
  promises = nodesWithProviders.map( /*#__PURE__*/function () {
103
117
  var _ref6 = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee(_ref5) {
104
- var nodes, provider, timeout, timeoutPromise, data;
118
+ var nodes, provider, timeout, start, getDurationFromStart, timeoutPromise, data;
105
119
  return _regenerator.default.wrap(function _callee$(_context) {
106
120
  while (1) switch (_context.prev = _context.next) {
107
121
  case 0:
122
+ getDurationFromStart = function _getDurationFromStart() {
123
+ return Math.min(performance.now() - start, timeout);
124
+ };
108
125
  nodes = _ref5.nodes, provider = _ref5.provider, timeout = _ref5.timeout;
109
- _context.prev = 1;
110
- timeoutPromise = new Promise(function (resolve) {
126
+ start = performance.now();
127
+ _context.prev = 3;
128
+ timeoutPromise = new Promise(function (_, reject) {
111
129
  setTimeout(function () {
112
- resolve([]);
130
+ reject();
113
131
  }, timeout);
114
132
  });
115
- _context.next = 5;
133
+ _context.next = 7;
116
134
  return Promise.race([provider.fetchNodesData(nodes), timeoutPromise]);
117
- case 5:
135
+ case 7:
118
136
  data = _context.sent;
119
137
  return _context.abrupt("return", {
120
138
  provider: provider,
139
+ success: true,
140
+ duration: getDurationFromStart(),
121
141
  nodes: nodes,
122
142
  data: data
123
143
  });
124
- case 9:
125
- _context.prev = 9;
126
- _context.t0 = _context["catch"](1);
144
+ case 11:
145
+ _context.prev = 11;
146
+ _context.t0 = _context["catch"](3);
127
147
  return _context.abrupt("return", {
128
148
  provider: provider,
149
+ success: false,
150
+ duration: getDurationFromStart(),
129
151
  nodes: nodes,
130
152
  data: []
131
153
  });
132
- case 12:
154
+ case 14:
133
155
  case "end":
134
156
  return _context.stop();
135
157
  }
136
- }, _callee, null, [[1, 9]]);
158
+ }, _callee, null, [[3, 11]]);
137
159
  }));
138
160
  return function (_x2) {
139
161
  return _ref6.apply(this, arguments);
@@ -145,14 +167,21 @@ function _prefetchNodeDataProvidersData() {
145
167
  results = _context2.sent;
146
168
  return _context2.abrupt("return", results.reduce(function (acc, _ref7) {
147
169
  var provider = _ref7.provider,
170
+ success = _ref7.success,
171
+ duration = _ref7.duration,
148
172
  nodes = _ref7.nodes,
149
173
  data = _ref7.data;
150
- acc[provider.name] = data.reduce(function (providerSsrData, nodeData, nodeIndex) {
174
+ var ssrData = data.reduce(function (providerSsrData, nodeData, nodeIndex) {
151
175
  var node = nodes[nodeIndex];
152
176
  var nodeDataKey = provider.nodeDataKey(node);
153
177
  providerSsrData[nodeDataKey] = nodeData;
154
178
  return providerSsrData;
155
179
  }, {});
180
+ acc[provider.name] = {
181
+ data: ssrData,
182
+ success: success,
183
+ duration: duration
184
+ };
156
185
  return acc;
157
186
  }, {}));
158
187
  case 9:
@@ -13,14 +13,28 @@ import { findNodesToPrefetch } from './find-nodes-to-prefetch';
13
13
 
14
14
  /**
15
15
  * Represents the aggregated SSR data for all node data providers.
16
- * It's a map where each key is a provider's name and the value is the {@link SsrData} for that provider.
17
- * This structure is used to hydrate the client-side caches.
16
+ * Each key is a provider's name, and the value contains the fetch status, duration,
17
+ * and a map of node data keys to their prefetched data.
18
18
  *
19
19
  * @example
20
+ * ```
20
21
  * {
21
- * 'mentionProvider': { 'mention-1': { id: '1', name: 'John Doe' } },
22
- * 'emojiProvider': { 'emoji-123': { shortName: ':smile:', representation: '😊' } }
22
+ * mentionProvider: {
23
+ * success: true,
24
+ * duration: 220,
25
+ * data: {
26
+ * 'mention-1': { id: '1', name: 'John Doe' }
27
+ * }
28
+ * },
29
+ * emojiProvider: {
30
+ * success: true,
31
+ * duration: 110,
32
+ * data: {
33
+ * 'emoji-123': { shortName: ':smile:', representation: '😊' }
34
+ * }
35
+ * }
23
36
  * }
37
+ * ```
24
38
  */
25
39
 
26
40
  /**
@@ -43,7 +57,7 @@ import { findNodesToPrefetch } from './find-nodes-to-prefetch';
43
57
  * },
44
58
  * ];
45
59
  *
46
- * window['__SSR_EDITOR_NODE_DATA_PROVIDERS_DATA__'] = await prefetchNodeDataProvidersData({
60
+ * const data = await prefetchNodeDataProvidersData({
47
61
  * providers,
48
62
  * doc,
49
63
  * timeout: 1_000,
@@ -53,7 +67,7 @@ import { findNodesToPrefetch } from './find-nodes-to-prefetch';
53
67
  *
54
68
  * @param props The properties for prefetching node data.
55
69
  * @returns Record of provider names to their respective SSR data,
56
- * where each SSR data is a record of node data keys to the fetched data.
70
+ * success status, and duration of the fetch operation.
57
71
  */
58
72
  export async function prefetchNodeDataProvidersData({
59
73
  providers,
@@ -91,21 +105,29 @@ export async function prefetchNodeDataProvidersData({
91
105
  provider,
92
106
  timeout
93
107
  }) => {
108
+ const start = performance.now();
109
+ function getDurationFromStart() {
110
+ return Math.min(performance.now() - start, timeout);
111
+ }
94
112
  try {
95
- const timeoutPromise = new Promise(resolve => {
113
+ const timeoutPromise = new Promise((_, reject) => {
96
114
  setTimeout(() => {
97
- resolve([]);
115
+ reject();
98
116
  }, timeout);
99
117
  });
100
118
  const data = await Promise.race([provider.fetchNodesData(nodes), timeoutPromise]);
101
119
  return {
102
120
  provider,
121
+ success: true,
122
+ duration: getDurationFromStart(),
103
123
  nodes,
104
124
  data
105
125
  };
106
126
  } catch {
107
127
  return {
108
128
  provider,
129
+ success: false,
130
+ duration: getDurationFromStart(),
109
131
  nodes,
110
132
  data: []
111
133
  };
@@ -114,15 +136,22 @@ export async function prefetchNodeDataProvidersData({
114
136
  const results = await Promise.all(promises);
115
137
  return results.reduce((acc, {
116
138
  provider,
139
+ success,
140
+ duration,
117
141
  nodes,
118
142
  data
119
143
  }) => {
120
- acc[provider.name] = data.reduce((providerSsrData, nodeData, nodeIndex) => {
144
+ const ssrData = data.reduce((providerSsrData, nodeData, nodeIndex) => {
121
145
  const node = nodes[nodeIndex];
122
146
  const nodeDataKey = provider.nodeDataKey(node);
123
147
  providerSsrData[nodeDataKey] = nodeData;
124
148
  return providerSsrData;
125
149
  }, {});
150
+ acc[provider.name] = {
151
+ data: ssrData,
152
+ success,
153
+ duration
154
+ };
126
155
  return acc;
127
156
  }, {});
128
157
  }
@@ -15,14 +15,28 @@ import { findNodesToPrefetch } from './find-nodes-to-prefetch';
15
15
 
16
16
  /**
17
17
  * Represents the aggregated SSR data for all node data providers.
18
- * It's a map where each key is a provider's name and the value is the {@link SsrData} for that provider.
19
- * This structure is used to hydrate the client-side caches.
18
+ * Each key is a provider's name, and the value contains the fetch status, duration,
19
+ * and a map of node data keys to their prefetched data.
20
20
  *
21
21
  * @example
22
+ * ```
22
23
  * {
23
- * 'mentionProvider': { 'mention-1': { id: '1', name: 'John Doe' } },
24
- * 'emojiProvider': { 'emoji-123': { shortName: ':smile:', representation: '😊' } }
24
+ * mentionProvider: {
25
+ * success: true,
26
+ * duration: 220,
27
+ * data: {
28
+ * 'mention-1': { id: '1', name: 'John Doe' }
29
+ * }
30
+ * },
31
+ * emojiProvider: {
32
+ * success: true,
33
+ * duration: 110,
34
+ * data: {
35
+ * 'emoji-123': { shortName: ':smile:', representation: '😊' }
36
+ * }
37
+ * }
25
38
  * }
39
+ * ```
26
40
  */
27
41
 
28
42
  /**
@@ -45,7 +59,7 @@ import { findNodesToPrefetch } from './find-nodes-to-prefetch';
45
59
  * },
46
60
  * ];
47
61
  *
48
- * window['__SSR_EDITOR_NODE_DATA_PROVIDERS_DATA__'] = await prefetchNodeDataProvidersData({
62
+ * const data = await prefetchNodeDataProvidersData({
49
63
  * providers,
50
64
  * doc,
51
65
  * timeout: 1_000,
@@ -55,7 +69,7 @@ import { findNodesToPrefetch } from './find-nodes-to-prefetch';
55
69
  *
56
70
  * @param props The properties for prefetching node data.
57
71
  * @returns Record of provider names to their respective SSR data,
58
- * where each SSR data is a record of node data keys to the fetched data.
72
+ * success status, and duration of the fetch operation.
59
73
  */
60
74
  export function prefetchNodeDataProvidersData(_x) {
61
75
  return _prefetchNodeDataProvidersData.apply(this, arguments);
@@ -97,39 +111,47 @@ function _prefetchNodeDataProvidersData() {
97
111
  });
98
112
  promises = nodesWithProviders.map( /*#__PURE__*/function () {
99
113
  var _ref6 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(_ref5) {
100
- var nodes, provider, timeout, timeoutPromise, data;
114
+ var nodes, provider, timeout, start, getDurationFromStart, timeoutPromise, data;
101
115
  return _regeneratorRuntime.wrap(function _callee$(_context) {
102
116
  while (1) switch (_context.prev = _context.next) {
103
117
  case 0:
118
+ getDurationFromStart = function _getDurationFromStart() {
119
+ return Math.min(performance.now() - start, timeout);
120
+ };
104
121
  nodes = _ref5.nodes, provider = _ref5.provider, timeout = _ref5.timeout;
105
- _context.prev = 1;
106
- timeoutPromise = new Promise(function (resolve) {
122
+ start = performance.now();
123
+ _context.prev = 3;
124
+ timeoutPromise = new Promise(function (_, reject) {
107
125
  setTimeout(function () {
108
- resolve([]);
126
+ reject();
109
127
  }, timeout);
110
128
  });
111
- _context.next = 5;
129
+ _context.next = 7;
112
130
  return Promise.race([provider.fetchNodesData(nodes), timeoutPromise]);
113
- case 5:
131
+ case 7:
114
132
  data = _context.sent;
115
133
  return _context.abrupt("return", {
116
134
  provider: provider,
135
+ success: true,
136
+ duration: getDurationFromStart(),
117
137
  nodes: nodes,
118
138
  data: data
119
139
  });
120
- case 9:
121
- _context.prev = 9;
122
- _context.t0 = _context["catch"](1);
140
+ case 11:
141
+ _context.prev = 11;
142
+ _context.t0 = _context["catch"](3);
123
143
  return _context.abrupt("return", {
124
144
  provider: provider,
145
+ success: false,
146
+ duration: getDurationFromStart(),
125
147
  nodes: nodes,
126
148
  data: []
127
149
  });
128
- case 12:
150
+ case 14:
129
151
  case "end":
130
152
  return _context.stop();
131
153
  }
132
- }, _callee, null, [[1, 9]]);
154
+ }, _callee, null, [[3, 11]]);
133
155
  }));
134
156
  return function (_x2) {
135
157
  return _ref6.apply(this, arguments);
@@ -141,14 +163,21 @@ function _prefetchNodeDataProvidersData() {
141
163
  results = _context2.sent;
142
164
  return _context2.abrupt("return", results.reduce(function (acc, _ref7) {
143
165
  var provider = _ref7.provider,
166
+ success = _ref7.success,
167
+ duration = _ref7.duration,
144
168
  nodes = _ref7.nodes,
145
169
  data = _ref7.data;
146
- acc[provider.name] = data.reduce(function (providerSsrData, nodeData, nodeIndex) {
170
+ var ssrData = data.reduce(function (providerSsrData, nodeData, nodeIndex) {
147
171
  var node = nodes[nodeIndex];
148
172
  var nodeDataKey = provider.nodeDataKey(node);
149
173
  providerSsrData[nodeDataKey] = nodeData;
150
174
  return providerSsrData;
151
175
  }, {});
176
+ acc[provider.name] = {
177
+ data: ssrData,
178
+ success: success,
179
+ duration: duration
180
+ };
152
181
  return acc;
153
182
  }, {}));
154
183
  case 9:
@@ -15,17 +15,35 @@ type SsrData = {
15
15
  };
16
16
  /**
17
17
  * Represents the aggregated SSR data for all node data providers.
18
- * It's a map where each key is a provider's name and the value is the {@link SsrData} for that provider.
19
- * This structure is used to hydrate the client-side caches.
18
+ * Each key is a provider's name, and the value contains the fetch status, duration,
19
+ * and a map of node data keys to their prefetched data.
20
20
  *
21
21
  * @example
22
+ * ```
22
23
  * {
23
- * 'mentionProvider': { 'mention-1': { id: '1', name: 'John Doe' } },
24
- * 'emojiProvider': { 'emoji-123': { shortName: ':smile:', representation: '😊' } }
24
+ * mentionProvider: {
25
+ * success: true,
26
+ * duration: 220,
27
+ * data: {
28
+ * 'mention-1': { id: '1', name: 'John Doe' }
29
+ * }
30
+ * },
31
+ * emojiProvider: {
32
+ * success: true,
33
+ * duration: 110,
34
+ * data: {
35
+ * 'emoji-123': { shortName: ':smile:', representation: '😊' }
36
+ * }
37
+ * }
25
38
  * }
39
+ * ```
26
40
  */
27
41
  type NodeDataProvidersSsrData = {
28
- [providerName: string]: SsrData;
42
+ [providerName: string]: {
43
+ success: boolean;
44
+ duration: number;
45
+ data: SsrData;
46
+ };
29
47
  };
30
48
  interface Props {
31
49
  /**
@@ -91,7 +109,7 @@ interface Props {
91
109
  * },
92
110
  * ];
93
111
  *
94
- * window['__SSR_EDITOR_NODE_DATA_PROVIDERS_DATA__'] = await prefetchNodeDataProvidersData({
112
+ * const data = await prefetchNodeDataProvidersData({
95
113
  * providers,
96
114
  * doc,
97
115
  * timeout: 1_000,
@@ -101,7 +119,7 @@ interface Props {
101
119
  *
102
120
  * @param props The properties for prefetching node data.
103
121
  * @returns Record of provider names to their respective SSR data,
104
- * where each SSR data is a record of node data keys to the fetched data.
122
+ * success status, and duration of the fetch operation.
105
123
  */
106
124
  export declare function prefetchNodeDataProvidersData({ providers, doc, timeout, maxNodesToVisit, }: Props): Promise<NodeDataProvidersSsrData>;
107
125
  export {};
@@ -15,17 +15,35 @@ type SsrData = {
15
15
  };
16
16
  /**
17
17
  * Represents the aggregated SSR data for all node data providers.
18
- * It's a map where each key is a provider's name and the value is the {@link SsrData} for that provider.
19
- * This structure is used to hydrate the client-side caches.
18
+ * Each key is a provider's name, and the value contains the fetch status, duration,
19
+ * and a map of node data keys to their prefetched data.
20
20
  *
21
21
  * @example
22
+ * ```
22
23
  * {
23
- * 'mentionProvider': { 'mention-1': { id: '1', name: 'John Doe' } },
24
- * 'emojiProvider': { 'emoji-123': { shortName: ':smile:', representation: '😊' } }
24
+ * mentionProvider: {
25
+ * success: true,
26
+ * duration: 220,
27
+ * data: {
28
+ * 'mention-1': { id: '1', name: 'John Doe' }
29
+ * }
30
+ * },
31
+ * emojiProvider: {
32
+ * success: true,
33
+ * duration: 110,
34
+ * data: {
35
+ * 'emoji-123': { shortName: ':smile:', representation: '😊' }
36
+ * }
37
+ * }
25
38
  * }
39
+ * ```
26
40
  */
27
41
  type NodeDataProvidersSsrData = {
28
- [providerName: string]: SsrData;
42
+ [providerName: string]: {
43
+ success: boolean;
44
+ duration: number;
45
+ data: SsrData;
46
+ };
29
47
  };
30
48
  interface Props {
31
49
  /**
@@ -91,7 +109,7 @@ interface Props {
91
109
  * },
92
110
  * ];
93
111
  *
94
- * window['__SSR_EDITOR_NODE_DATA_PROVIDERS_DATA__'] = await prefetchNodeDataProvidersData({
112
+ * const data = await prefetchNodeDataProvidersData({
95
113
  * providers,
96
114
  * doc,
97
115
  * timeout: 1_000,
@@ -101,7 +119,7 @@ interface Props {
101
119
  *
102
120
  * @param props The properties for prefetching node data.
103
121
  * @returns Record of provider names to their respective SSR data,
104
- * where each SSR data is a record of node data keys to the fetched data.
122
+ * success status, and duration of the fetch operation.
105
123
  */
106
124
  export declare function prefetchNodeDataProvidersData({ providers, doc, timeout, maxNodesToVisit, }: Props): Promise<NodeDataProvidersSsrData>;
107
125
  export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/node-data-provider",
3
- "version": "4.4.0",
3
+ "version": "4.5.0",
4
4
  "description": "Node data provider for @atlaskit/editor-core plugins and @atlaskit/renderer",
5
5
  "author": "Atlassian Pty Ltd",
6
6
  "license": "Apache-2.0",
@@ -24,12 +24,12 @@
24
24
  "dependencies": {
25
25
  "@atlaskit/adf-schema": "^50.0.1",
26
26
  "@atlaskit/adf-utils": "^19.20.0",
27
- "@atlaskit/editor-json-transformer": "^8.24.0",
27
+ "@atlaskit/editor-json-transformer": "^8.25.0",
28
28
  "@atlaskit/editor-prosemirror": "7.0.0",
29
29
  "@babel/runtime": "^7.0.0"
30
30
  },
31
31
  "peerDependencies": {
32
- "@atlaskit/editor-common": "^107.12.0"
32
+ "@atlaskit/editor-common": "^107.13.0"
33
33
  },
34
34
  "devDependencies": {
35
35
  "typescript": "~5.4.2"