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