/
api-node-helpers-docs.js
310 lines (278 loc) · 7.88 KB
/
api-node-helpers-docs.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
/* eslint-disable no-unused-vars */
/***/
const GatsbyReporter = {
/**
* @callback GatsbyReporterFn
* @param {string} message Message to display
* @returns {void}
*/
/**
* @callback GatsbyReporterFnWithError
* @param {string} message Message to display
* @param {Error}[error] Optional error object
* @returns {void}
*/
/**
* @type {GatsbyReporterFn}
* @example
* reporter.info(`text`)
*/
info: true,
/**
* @type {GatsbyReporterFn}
* @example
* reporter.warn(`text`)
*/
warn: true,
/**
* @type {GatsbyReporterFnWithError}
* @example
* reporter.error(`text`, new Error('something'))
*/
error: true,
/**
* @type {GatsbyReporterFnWithError}
* @example
* reporter.panic(`text`, new Error('something'))
*/
panic: true,
/**
* @type {GatsbyReporterFnWithError}
* @example
* reporter.panicOnBuild(`text`, new Error('something'))
*/
panicOnBuild: true,
/**
* Note that this method only works if the --verbose option has
* been passed to the CLI
* @type {GatsbyReporterFn}
* @example
* reporter.verbose(`text`)
*/
verbose: true,
/**
* @callback GatsbyReporterActivityTimerFn
* @param {string} message Timer message to display
* @returns {ITimerReporter}
*/
/**
* Creates a new activity timer with the provided message.
* Check the full [return type definition here](https://github.com/gatsbyjs/gatsby/blob/master/packages/gatsby-cli/src/reporter/reporter-timer.ts#L19).
* @type {GatsbyReporterActivityTimerFn}
* @example
* const activity = reporter.activityTimer(`Timer text`)
*
* activity.start()
* activity.setStatus(`status text`)
* activity.end()
*/
activityTimer: true,
};
/***/
const GatsbyCache = {
/**
* Retrieve cached value
* @param {string} key Cache key
* @returns {Promise<any>} Promise resolving to cached value
* @example
* const value = await cache.get(`unique-key`)
*/
get: true,
/**
* Cache value
* @param {string} key Cache key
* @param {any} value Value to be cached
* @returns {Promise<any>} Promise resolving to cached value
* @example
* await cache.set(`unique-key`, value)
*/
set: true,
/**
* Deletes cached value
* @param {string} key Cache key
* @returns {Promise<void>} Promise resolving once key is deleted from cache
* @example
* await cache.del(`unique-key`)
*/
del: true,
};
/***/
const GatsbyTracing = {
/**
* Global tracer instance. Check
* [opentracing Tracer documentation](https://opentracing-javascript.surge.sh/classes/tracer.html)
* for more details.
* @type {Opentracing.Tracer}
*/
tracer: true,
/**
* Tracer span representing API run. Check
* [opentracing Span documentation](https://opentracing-javascript.surge.sh/classes/span.html)
* for more details.
* @type {Opentracing.Span}
*/
parentSpan: true,
/**
* @callback GatsbyTracing.StartSpan
* @param {string} spanName name of the span
* @returns {Opentracing.Span}
*/
/**
* Start a tracing span. The span will be created as a child of the currently
* running API span. This is a convenience wrapper for
* ```js
* tracing.tracer.startSpan(`span-name`, { childOf: tracing.parentSpan}).
* ```
* @type {GatsbyTracing.StartSpan}
* @example
* exports.sourceNodes = async ({ actions, tracing }) => {
* const span = tracing.startSpan(`foo`)
*
* // Perform any span operations. E.g. add a tag to your span
* span.setTag(`bar`, `baz`)
*
* // Rest of your plugin code
*
* span.finish()
* }
*/
startSpan: true,
};
/**
* Get cache instance by name - this should only be used by plugins that
* accept subplugins.
* @param {string} id Test
* @returns {GatsbyCache} See [`cache`](#cache) section for reference.
*/
module.exports.getCache = true;
/**
* Key-value store used to persist results of time/memory/cpu intensive
* tasks. All functions are async and return promises.
* @type {GatsbyCache}
*/
module.exports.cache = true;
/**
* Create a stable content digest from a string or object, you can use the
* result of this function to set the `internal.contentDigest` field
* on nodes. Gatsby uses the value of this field to invalidate stale data
* when your content changes.
* @param {(string|object)} input
* @returns {string} Hash string
* @example
* const node = {
* ...nodeData,
* internal: {
* type: `TypeOfNode`,
* contentDigest: createContentDigest(nodeData)
* }
* }
*/
module.exports.createContentDigest = true;
/**
* Collection of functions used to programmatically modify Gatsby’s internal state.
*
* See [`actions`](/docs/actions/) reference.
* @type {Actions}
*/
module.exports.actions = true;
/**
* Get content for a node from the plugin that created it.
* @param {Node} node
* @returns {Promise<string>}
* @example
* module.exports = async function onCreateNode(
* { node, loadNodeContent, actions, createNodeId }
* ) {
* if (node.internal.mediaType === 'text/markdown') {
* const { createNode, createParentChildLink } = actions
* const textContent = await loadNodeContent(node)
* // process textContent and create child nodes
* }
* }
*/
module.exports.loadNodeContent = true;
/**
* Internal redux state used for application state. Do not use, unless you
* absolutely must. Store is considered a private API and can change with
* any version.
* @type {Redux.Store}
*/
module.exports.store = true;
/**
* Internal event emitter / listener. Do not use, unless you absolutely
* must. Emitter is considered a private API and can change with any version.
* @type {Emitter}
*/
module.exports.emitter = true;
/**
* Get array of all nodes.
* @returns {Node[]} Array of nodes.
* @example
* const allNodes = getNodes()
*/
module.exports.getNodes = true;
/**
* Get single node by given ID.
* Don't use this in graphql resolvers - see
* [`getNodeAndSavePathDependency`](#getNodeAndSavePathDependency).
* @param {string} ID id of the node.
* @returns {Node} Single node instance.
* @example
* const node = getNode(id)
*/
module.exports.getNode = true;
/**
* Get array of nodes of given type.
* @param {string} Type of nodes
* @returns {Node[]} Array of nodes.
* @example
* const markdownNodes = getNodesByType(`MarkdownRemark`)
*/
module.exports.getNodesByType = true;
/**
* Set of utilities to output information to user
* @type {GatsbyReporter}
*/
module.exports.reporter = true;
/**
* Get single node by given ID and create dependency for given path.
* This should be used instead of `getNode` in graphql resolvers to enable
* tracking dependencies for query results. If it's not used Gatsby will
* not rerun query if node changes leading to stale query results. See
* [Page -> Node Dependency Tracking](/docs/page-node-dependencies/)
* for more details.
* @param {string} ID id of the node.
* @param {string} path of the node.
* @returns {Node} Single node instance.
*/
module.exports.getNodeAndSavePathDependency = true;
/**
* Utility function useful to generate globally unique and stable node IDs.
* It will generate different IDs for different plugins if they use same
* input.
*
* @param {string} input
* @returns {string} UUIDv5 ID string
* @example
* const node = {
* id: createNodeId(`${backendData.type}${backendData.id}`),
* ...restOfNodeData
* }
*/
module.exports.createNodeId = true;
/**
* Set of utilities that allow adding more detailed tracing for plugins.
* Check
* [Performance tracing](https://www.gatsbyjs.org/docs/performance-tracing)
* page for more details.
* @type {GatsbyTracing}
*/
module.exports.tracing = true;
/**
* Use to prefix resources URLs. `pathPrefix` will be either empty string or
* path that starts with slash and doesn't end with slash. Check
* [Adding a Path Prefix](https://www.gatsbyjs.org/docs/path-prefix/)
* page for details about path prefixing.
* @type {string}
*/
module.exports.pathPrefix = true;