@backstage/plugin-techdocs-backend 2.1.3-next.1 → 2.1.3-next.2
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 +18 -0
- package/dist/cache/cacheMiddleware.cjs.js.map +1 -1
- package/package.json +10 -10
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,23 @@
|
|
|
1
1
|
# @backstage/plugin-techdocs-backend
|
|
2
2
|
|
|
3
|
+
## 2.1.3-next.2
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- de96a60: chore(deps): bump `express` from 4.21.2 to 4.22.0
|
|
8
|
+
- 2bae83a: Corrected `ErrorCallback` type to work with Node 22 types
|
|
9
|
+
- Updated dependencies
|
|
10
|
+
- @backstage/backend-defaults@0.14.0-next.1
|
|
11
|
+
- @backstage/plugin-techdocs-node@1.13.10-next.1
|
|
12
|
+
- @backstage/integration@1.18.3-next.1
|
|
13
|
+
- @backstage/backend-plugin-api@1.6.0-next.1
|
|
14
|
+
- @backstage/catalog-client@1.12.1
|
|
15
|
+
- @backstage/catalog-model@1.7.6
|
|
16
|
+
- @backstage/config@1.3.6
|
|
17
|
+
- @backstage/errors@1.2.7
|
|
18
|
+
- @backstage/types@1.2.2
|
|
19
|
+
- @backstage/plugin-catalog-node@1.20.1-next.1
|
|
20
|
+
|
|
3
21
|
## 2.1.3-next.1
|
|
4
22
|
|
|
5
23
|
### Patch Changes
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cacheMiddleware.cjs.js","sources":["../../src/cache/cacheMiddleware.ts"],"sourcesContent":["/*\n * Copyright 2021 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\nimport { Router } from 'express';\nimport router from 'express-promise-router';\nimport { TechDocsCache } from './TechDocsCache';\nimport { LoggerService } from '@backstage/backend-plugin-api';\n\ntype CacheMiddlewareOptions = {\n cache: TechDocsCache;\n logger: LoggerService;\n};\n\ntype ErrorCallback = (err?: Error) => void;\n\nexport const createCacheMiddleware = ({\n cache,\n}: CacheMiddlewareOptions): Router => {\n const cacheMiddleware = router();\n\n // Middleware that, through socket monkey patching, captures responses as\n // they're sent over /static/docs/* and caches them. Subsequent requests are\n // loaded from cache. Cache key is the object's path (after `/static/docs/`).\n cacheMiddleware.use(async (req, res, next) => {\n const socket = res.socket;\n const isCacheable = req.path.startsWith('/static/docs/');\n const isGetRequest = req.method === 'GET';\n\n // Continue early if this is non-cacheable, or there's no socket.\n if (!isCacheable || !socket) {\n next();\n return;\n }\n\n // Make concrete references to these things.\n const reqPath = decodeURI(req.path.match(/\\/static\\/docs\\/(.*)$/)![1]);\n const realEnd = socket.end.bind(socket);\n const realWrite = socket.write.bind(socket);\n let writeToCache = true;\n const chunks: Buffer[] = [];\n\n // Monkey-patch the response's socket to keep track of chunks as they are\n // written over the wire.\n socket.write = (\n data: string | Uint8Array,\n encoding?: BufferEncoding | ErrorCallback,\n callback?: ErrorCallback,\n ) => {\n // This cast is obviously weird, but it covers a type bug in @types/node\n // which does not gracefully handle union types.\n chunks.push(\n typeof data === 'string' ? Buffer.from(data) : Buffer.from(data),\n );\n if (typeof encoding === 'function') {\n return realWrite(data, encoding);\n }\n return realWrite(data, encoding, callback);\n };\n\n // When a socket is closed, if there were no errors and the data written\n // over the socket should be cached, cache it!\n socket.on('close', async hadError => {\n const content = Buffer.concat(chunks);\n const head = content.toString('utf8', 0, 12);\n if (\n isGetRequest &&\n writeToCache &&\n !hadError &&\n head.match(/HTTP\\/\\d\\.\\d 200/)\n ) {\n await cache.set(reqPath, content);\n }\n });\n\n // Attempt to retrieve data from the cache.\n const cached = await cache.get(reqPath);\n\n // If there is a cache hit, write it out on the socket, ensure we don't re-\n // cache the data, and prevent going back to canonical storage by never\n // calling next().\n if (cached) {\n writeToCache = false;\n realEnd(cached);\n return;\n }\n\n // No data retrieved from cache: allow retrieval from canonical storage.\n next();\n });\n\n return cacheMiddleware;\n};\n"],"names":["router"],"mappings":";;;;;;;;AA2BO,MAAM,wBAAwB,CAAC;AAAA,EACpC;AACF,CAAA,KAAsC;AACpC,EAAA,MAAM,kBAAkBA,uBAAA,EAAO;AAK/B,EAAA,eAAA,CAAgB,GAAA,CAAI,OAAO,GAAA,EAAK,GAAA,EAAK,IAAA,KAAS;AAC5C,IAAA,MAAM,SAAS,GAAA,CAAI,MAAA;AACnB,IAAA,MAAM,WAAA,GAAc,GAAA,CAAI,IAAA,CAAK,UAAA,CAAW,eAAe,CAAA;AACvD,IAAA,MAAM,YAAA,GAAe,IAAI,MAAA,KAAW,KAAA;AAGpC,IAAA,IAAI,CAAC,WAAA,IAAe,CAAC,MAAA,EAAQ;AAC3B,MAAA,IAAA,EAAK;AACL,MAAA;AAAA,IACF;AAGA,IAAA,MAAM,OAAA,GAAU,UAAU,GAAA,CAAI,IAAA,CAAK,MAAM,uBAAuB,CAAA,CAAG,CAAC,CAAC,CAAA;AACrE,IAAA,MAAM,OAAA,GAAU,MAAA,CAAO,GAAA,CAAI,IAAA,CAAK,MAAM,CAAA;AACtC,IAAA,MAAM,SAAA,GAAY,MAAA,CAAO,KAAA,CAAM,IAAA,CAAK,MAAM,CAAA;AAC1C,IAAA,IAAI,YAAA,GAAe,IAAA;AACnB,IAAA,MAAM,SAAmB,EAAC;AAI1B,IAAA,MAAA,CAAO,KAAA,GAAQ,CACb,IAAA,EACA,QAAA,EACA,QAAA,KACG;AAGH,MAAA,MAAA,CAAO,IAAA;AAAA,QACL,OAAO,SAAS,QAAA,GAAW,MAAA,CAAO,KAAK,IAAI,CAAA,GAAI,MAAA,CAAO,IAAA,CAAK,IAAI;AAAA,OACjE;AACA,MAAA,IAAI,OAAO,aAAa,UAAA,EAAY;AAClC,QAAA,OAAO,SAAA,CAAU,MAAM,QAAQ,CAAA;AAAA,MACjC;AACA,MAAA,OAAO,SAAA,CAAU,IAAA,EAAM,QAAA,EAAU,QAAQ,CAAA;AAAA,IAC3C,CAAA;AAIA,IAAA,MAAA,CAAO,EAAA,CAAG,OAAA,EAAS,OAAM,QAAA,KAAY;AACnC,MAAA,MAAM,OAAA,GAAU,MAAA,CAAO,MAAA,CAAO,MAAM,CAAA;AACpC,MAAA,MAAM,IAAA,GAAO,OAAA,CAAQ,QAAA,CAAS,MAAA,EAAQ,GAAG,EAAE,CAAA;AAC3C,MAAA,IACE,gBACA,YAAA,IACA,CAAC,YACD,IAAA,CAAK,KAAA,CAAM,kBAAkB,CAAA,EAC7B;AACA,QAAA,MAAM,KAAA,CAAM,GAAA,CAAI,OAAA,EAAS,OAAO,CAAA;AAAA,MAClC;AAAA,IACF,CAAC,CAAA;AAGD,IAAA,MAAM,MAAA,GAAS,MAAM,KAAA,CAAM,GAAA,CAAI,OAAO,CAAA;AAKtC,IAAA,IAAI,MAAA,EAAQ;AACV,MAAA,YAAA,GAAe,KAAA;AACf,MAAA,OAAA,CAAQ,MAAM,CAAA;AACd,MAAA;AAAA,IACF;AAGA,IAAA,IAAA,EAAK;AAAA,EACP,CAAC,CAAA;AAED,EAAA,OAAO,eAAA;AACT;;;;"}
|
|
1
|
+
{"version":3,"file":"cacheMiddleware.cjs.js","sources":["../../src/cache/cacheMiddleware.ts"],"sourcesContent":["/*\n * Copyright 2021 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\nimport { Router } from 'express';\nimport router from 'express-promise-router';\nimport { TechDocsCache } from './TechDocsCache';\nimport { LoggerService } from '@backstage/backend-plugin-api';\n\ntype CacheMiddlewareOptions = {\n cache: TechDocsCache;\n logger: LoggerService;\n};\n\ntype ErrorCallback = (err?: Error | null) => void;\n\nexport const createCacheMiddleware = ({\n cache,\n}: CacheMiddlewareOptions): Router => {\n const cacheMiddleware = router();\n\n // Middleware that, through socket monkey patching, captures responses as\n // they're sent over /static/docs/* and caches them. Subsequent requests are\n // loaded from cache. Cache key is the object's path (after `/static/docs/`).\n cacheMiddleware.use(async (req, res, next) => {\n const socket = res.socket;\n const isCacheable = req.path.startsWith('/static/docs/');\n const isGetRequest = req.method === 'GET';\n\n // Continue early if this is non-cacheable, or there's no socket.\n if (!isCacheable || !socket) {\n next();\n return;\n }\n\n // Make concrete references to these things.\n const reqPath = decodeURI(req.path.match(/\\/static\\/docs\\/(.*)$/)![1]);\n const realEnd = socket.end.bind(socket);\n const realWrite = socket.write.bind(socket);\n let writeToCache = true;\n const chunks: Buffer[] = [];\n\n // Monkey-patch the response's socket to keep track of chunks as they are\n // written over the wire.\n socket.write = (\n data: string | Uint8Array,\n encoding?: BufferEncoding | ErrorCallback,\n callback?: ErrorCallback,\n ) => {\n // This cast is obviously weird, but it covers a type bug in @types/node\n // which does not gracefully handle union types.\n chunks.push(\n typeof data === 'string' ? Buffer.from(data) : Buffer.from(data),\n );\n if (typeof encoding === 'function') {\n return realWrite(data, encoding);\n }\n return realWrite(data, encoding, callback);\n };\n\n // When a socket is closed, if there were no errors and the data written\n // over the socket should be cached, cache it!\n socket.on('close', async hadError => {\n const content = Buffer.concat(chunks);\n const head = content.toString('utf8', 0, 12);\n if (\n isGetRequest &&\n writeToCache &&\n !hadError &&\n head.match(/HTTP\\/\\d\\.\\d 200/)\n ) {\n await cache.set(reqPath, content);\n }\n });\n\n // Attempt to retrieve data from the cache.\n const cached = await cache.get(reqPath);\n\n // If there is a cache hit, write it out on the socket, ensure we don't re-\n // cache the data, and prevent going back to canonical storage by never\n // calling next().\n if (cached) {\n writeToCache = false;\n realEnd(cached);\n return;\n }\n\n // No data retrieved from cache: allow retrieval from canonical storage.\n next();\n });\n\n return cacheMiddleware;\n};\n"],"names":["router"],"mappings":";;;;;;;;AA2BO,MAAM,wBAAwB,CAAC;AAAA,EACpC;AACF,CAAA,KAAsC;AACpC,EAAA,MAAM,kBAAkBA,uBAAA,EAAO;AAK/B,EAAA,eAAA,CAAgB,GAAA,CAAI,OAAO,GAAA,EAAK,GAAA,EAAK,IAAA,KAAS;AAC5C,IAAA,MAAM,SAAS,GAAA,CAAI,MAAA;AACnB,IAAA,MAAM,WAAA,GAAc,GAAA,CAAI,IAAA,CAAK,UAAA,CAAW,eAAe,CAAA;AACvD,IAAA,MAAM,YAAA,GAAe,IAAI,MAAA,KAAW,KAAA;AAGpC,IAAA,IAAI,CAAC,WAAA,IAAe,CAAC,MAAA,EAAQ;AAC3B,MAAA,IAAA,EAAK;AACL,MAAA;AAAA,IACF;AAGA,IAAA,MAAM,OAAA,GAAU,UAAU,GAAA,CAAI,IAAA,CAAK,MAAM,uBAAuB,CAAA,CAAG,CAAC,CAAC,CAAA;AACrE,IAAA,MAAM,OAAA,GAAU,MAAA,CAAO,GAAA,CAAI,IAAA,CAAK,MAAM,CAAA;AACtC,IAAA,MAAM,SAAA,GAAY,MAAA,CAAO,KAAA,CAAM,IAAA,CAAK,MAAM,CAAA;AAC1C,IAAA,IAAI,YAAA,GAAe,IAAA;AACnB,IAAA,MAAM,SAAmB,EAAC;AAI1B,IAAA,MAAA,CAAO,KAAA,GAAQ,CACb,IAAA,EACA,QAAA,EACA,QAAA,KACG;AAGH,MAAA,MAAA,CAAO,IAAA;AAAA,QACL,OAAO,SAAS,QAAA,GAAW,MAAA,CAAO,KAAK,IAAI,CAAA,GAAI,MAAA,CAAO,IAAA,CAAK,IAAI;AAAA,OACjE;AACA,MAAA,IAAI,OAAO,aAAa,UAAA,EAAY;AAClC,QAAA,OAAO,SAAA,CAAU,MAAM,QAAQ,CAAA;AAAA,MACjC;AACA,MAAA,OAAO,SAAA,CAAU,IAAA,EAAM,QAAA,EAAU,QAAQ,CAAA;AAAA,IAC3C,CAAA;AAIA,IAAA,MAAA,CAAO,EAAA,CAAG,OAAA,EAAS,OAAM,QAAA,KAAY;AACnC,MAAA,MAAM,OAAA,GAAU,MAAA,CAAO,MAAA,CAAO,MAAM,CAAA;AACpC,MAAA,MAAM,IAAA,GAAO,OAAA,CAAQ,QAAA,CAAS,MAAA,EAAQ,GAAG,EAAE,CAAA;AAC3C,MAAA,IACE,gBACA,YAAA,IACA,CAAC,YACD,IAAA,CAAK,KAAA,CAAM,kBAAkB,CAAA,EAC7B;AACA,QAAA,MAAM,KAAA,CAAM,GAAA,CAAI,OAAA,EAAS,OAAO,CAAA;AAAA,MAClC;AAAA,IACF,CAAC,CAAA;AAGD,IAAA,MAAM,MAAA,GAAS,MAAM,KAAA,CAAM,GAAA,CAAI,OAAO,CAAA;AAKtC,IAAA,IAAI,MAAA,EAAQ;AACV,MAAA,YAAA,GAAe,KAAA;AACf,MAAA,OAAA,CAAQ,MAAM,CAAA;AACd,MAAA;AAAA,IACF;AAGA,IAAA,IAAA,EAAK;AAAA,EACP,CAAC,CAAA;AAED,EAAA,OAAO,eAAA;AACT;;;;"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@backstage/plugin-techdocs-backend",
|
|
3
|
-
"version": "2.1.3-next.
|
|
3
|
+
"version": "2.1.3-next.2",
|
|
4
4
|
"description": "The Backstage backend plugin that renders technical documentation for your components",
|
|
5
5
|
"backstage": {
|
|
6
6
|
"role": "backend-plugin",
|
|
@@ -72,17 +72,17 @@
|
|
|
72
72
|
"test": "backstage-cli package test"
|
|
73
73
|
},
|
|
74
74
|
"dependencies": {
|
|
75
|
-
"@backstage/backend-defaults": "0.14.0-next.
|
|
76
|
-
"@backstage/backend-plugin-api": "1.
|
|
75
|
+
"@backstage/backend-defaults": "0.14.0-next.1",
|
|
76
|
+
"@backstage/backend-plugin-api": "1.6.0-next.1",
|
|
77
77
|
"@backstage/catalog-client": "1.12.1",
|
|
78
78
|
"@backstage/catalog-model": "1.7.6",
|
|
79
79
|
"@backstage/config": "1.3.6",
|
|
80
80
|
"@backstage/errors": "1.2.7",
|
|
81
|
-
"@backstage/integration": "1.18.3-next.
|
|
82
|
-
"@backstage/plugin-catalog-node": "1.20.1-next.
|
|
83
|
-
"@backstage/plugin-techdocs-node": "1.13.10-next.
|
|
81
|
+
"@backstage/integration": "1.18.3-next.1",
|
|
82
|
+
"@backstage/plugin-catalog-node": "1.20.1-next.1",
|
|
83
|
+
"@backstage/plugin-techdocs-node": "1.13.10-next.1",
|
|
84
84
|
"@backstage/types": "1.2.2",
|
|
85
|
-
"express": "^4.
|
|
85
|
+
"express": "^4.22.0",
|
|
86
86
|
"express-promise-router": "^4.1.0",
|
|
87
87
|
"fs-extra": "^11.2.0",
|
|
88
88
|
"knex": "^3.0.0",
|
|
@@ -90,9 +90,9 @@
|
|
|
90
90
|
"winston": "^3.2.1"
|
|
91
91
|
},
|
|
92
92
|
"devDependencies": {
|
|
93
|
-
"@backstage/backend-defaults": "0.14.0-next.
|
|
94
|
-
"@backstage/backend-test-utils": "1.10.
|
|
95
|
-
"@backstage/cli": "0.
|
|
93
|
+
"@backstage/backend-defaults": "0.14.0-next.1",
|
|
94
|
+
"@backstage/backend-test-utils": "1.10.2-next.1",
|
|
95
|
+
"@backstage/cli": "0.35.0-next.2",
|
|
96
96
|
"@types/express": "^4.17.6",
|
|
97
97
|
"msw": "^2.0.0",
|
|
98
98
|
"supertest": "^7.0.0"
|