@callstack/repack-dev-server 5.0.0-next.1 → 5.0.0-rc.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 (62) hide show
  1. package/CHANGELOG.md +16 -2
  2. package/README.md +1 -1
  3. package/dist/createServer.d.ts +1 -2
  4. package/dist/createServer.js +11 -11
  5. package/dist/createServer.js.map +1 -1
  6. package/dist/index.js.map +1 -1
  7. package/dist/plugins/api/apiPlugin.js.map +1 -1
  8. package/dist/plugins/api/index.js.map +1 -1
  9. package/dist/plugins/compiler/compilerPlugin.js +16 -14
  10. package/dist/plugins/compiler/compilerPlugin.js.map +1 -1
  11. package/dist/plugins/compiler/index.js.map +1 -1
  12. package/dist/plugins/compiler/types.d.ts +4 -3
  13. package/dist/plugins/compiler/types.js.map +1 -1
  14. package/dist/plugins/devtools/devtoolsPlugin.js +1 -1
  15. package/dist/plugins/devtools/devtoolsPlugin.js.map +1 -1
  16. package/dist/plugins/devtools/index.js.map +1 -1
  17. package/dist/plugins/favicon/faviconPlugin.js +2 -2
  18. package/dist/plugins/favicon/faviconPlugin.js.map +1 -1
  19. package/dist/plugins/favicon/index.js.map +1 -1
  20. package/dist/plugins/multipart/index.js.map +1 -1
  21. package/dist/plugins/multipart/multipartPlugin.js +1 -1
  22. package/dist/plugins/multipart/multipartPlugin.js.map +1 -1
  23. package/dist/plugins/multipart/types.d.ts +1 -2
  24. package/dist/plugins/multipart/types.js.map +1 -1
  25. package/dist/plugins/symbolicate/Symbolicator.d.ts +1 -1
  26. package/dist/plugins/symbolicate/Symbolicator.js +6 -7
  27. package/dist/plugins/symbolicate/Symbolicator.js.map +1 -1
  28. package/dist/plugins/symbolicate/index.js.map +1 -1
  29. package/dist/plugins/symbolicate/sybmolicatePlugin.js.map +1 -1
  30. package/dist/plugins/symbolicate/types.d.ts +0 -1
  31. package/dist/plugins/symbolicate/types.js.map +1 -1
  32. package/dist/plugins/wss/WebSocketRouter.d.ts +1 -1
  33. package/dist/plugins/wss/WebSocketRouter.js.map +1 -1
  34. package/dist/plugins/wss/WebSocketServer.d.ts +4 -7
  35. package/dist/plugins/wss/WebSocketServer.js.map +1 -1
  36. package/dist/plugins/wss/WebSocketServerAdapter.d.ts +1 -4
  37. package/dist/plugins/wss/WebSocketServerAdapter.js +2 -2
  38. package/dist/plugins/wss/WebSocketServerAdapter.js.map +1 -1
  39. package/dist/plugins/wss/index.js.map +1 -1
  40. package/dist/plugins/wss/servers/WebSocketApiServer.d.ts +2 -2
  41. package/dist/plugins/wss/servers/WebSocketApiServer.js.map +1 -1
  42. package/dist/plugins/wss/servers/WebSocketDebuggerServer.d.ts +2 -3
  43. package/dist/plugins/wss/servers/WebSocketDebuggerServer.js.map +1 -1
  44. package/dist/plugins/wss/servers/WebSocketDevClientServer.d.ts +1 -1
  45. package/dist/plugins/wss/servers/WebSocketDevClientServer.js.map +1 -1
  46. package/dist/plugins/wss/servers/WebSocketEventsServer.d.ts +2 -2
  47. package/dist/plugins/wss/servers/WebSocketEventsServer.js.map +1 -1
  48. package/dist/plugins/wss/servers/WebSocketHMRServer.d.ts +4 -5
  49. package/dist/plugins/wss/servers/WebSocketHMRServer.js +1 -1
  50. package/dist/plugins/wss/servers/WebSocketHMRServer.js.map +1 -1
  51. package/dist/plugins/wss/servers/WebSocketMessageServer.d.ts +2 -3
  52. package/dist/plugins/wss/servers/WebSocketMessageServer.js +7 -7
  53. package/dist/plugins/wss/servers/WebSocketMessageServer.js.map +1 -1
  54. package/dist/plugins/wss/types.d.ts +2 -5
  55. package/dist/plugins/wss/types.js.map +1 -1
  56. package/dist/plugins/wss/wssPlugin.d.ts +4 -4
  57. package/dist/plugins/wss/wssPlugin.js +4 -4
  58. package/dist/plugins/wss/wssPlugin.js.map +1 -1
  59. package/dist/types.d.ts +15 -1
  60. package/dist/types.js +7 -0
  61. package/dist/types.js.map +1 -1
  62. package/package.json +3 -10
package/CHANGELOG.md CHANGED
@@ -1,8 +1,22 @@
1
1
  # @callstack/repack-dev-server
2
2
 
3
- ## 5.0.0-next.1
3
+ ## 5.0.0-rc.0
4
4
 
5
- ## 5.0.0-next.0
5
+ ## 5.0.0-alpha.0
6
+
7
+ ## 4.3.3
8
+
9
+ ## 4.3.2
10
+
11
+ ## 4.3.1
12
+
13
+ ## 4.3.0
14
+
15
+ ## 4.2.0
16
+
17
+ ## 4.1.1
18
+
19
+ ## 4.1.0
6
20
 
7
21
  ## 4.0.0
8
22
 
package/README.md CHANGED
@@ -2,7 +2,7 @@
2
2
  <img src="https://raw.githubusercontent.com/callstack/repack/HEAD/logo.png">
3
3
  </p>
4
4
  <p align="center">
5
- A Webpack-based toolkit to build your React Native application with full support of Webpack ecosystem.
5
+ A toolkit to build your React Native application with Rspack or Webpack.
6
6
  </p>
7
7
 
8
8
  ---
@@ -1,5 +1,4 @@
1
- /// <reference types="node" />
2
- import { Server } from './types';
1
+ import { type Server } from './types';
3
2
  /**
4
3
  * Create instance of development server, powered by Fastify.
5
4
  *
@@ -1,19 +1,18 @@
1
- import { Writable } from 'stream';
2
- import Fastify from 'fastify';
3
- import fastifySensible from '@fastify/sensible';
1
+ import { Writable } from 'node:stream';
4
2
  import middie from '@fastify/middie';
5
- // eslint-disable-next-line import/no-unresolved -- no main field in package.json
6
- import { createDevMiddleware } from '@react-native/dev-middleware';
3
+ import fastifySensible from '@fastify/sensible';
7
4
  import { debuggerUIMiddleware } from '@react-native-community/cli-debugger-ui';
8
- import { openURLMiddleware, openStackFrameInEditorMiddleware } from '@react-native-community/cli-server-api';
9
- import multipartPlugin from "./plugins/multipart/index.js";
10
- import compilerPlugin from "./plugins/compiler/index.js";
5
+ import { openStackFrameInEditorMiddleware, openURLMiddleware } from '@react-native-community/cli-server-api';
6
+ import { createDevMiddleware } from '@react-native/dev-middleware';
7
+ import Fastify from 'fastify';
11
8
  import apiPlugin from "./plugins/api/index.js";
12
- import wssPlugin from "./plugins/wss/index.js";
9
+ import compilerPlugin from "./plugins/compiler/index.js";
10
+ import devtoolsPlugin from "./plugins/devtools/index.js";
13
11
  import faviconPlugin from "./plugins/favicon/index.js";
14
- import { Internal } from "./types.js";
12
+ import multipartPlugin from "./plugins/multipart/index.js";
15
13
  import symbolicatePlugin from "./plugins/symbolicate/index.js";
16
- import devtoolsPlugin from "./plugins/devtools/index.js";
14
+ import wssPlugin from "./plugins/wss/index.js";
15
+ import { Internal } from "./types.js";
17
16
  /**
18
17
  * Create instance of development server, powered by Fastify.
19
18
  *
@@ -21,6 +20,7 @@ import devtoolsPlugin from "./plugins/devtools/index.js";
21
20
  * @returns `start` and `stop` functions as well as an underlying Fastify `instance`.
22
21
  */
23
22
  export async function createServer(config) {
23
+ // biome-ignore lint/style/useConst: needed in fastify constructor
24
24
  let delegate;
25
25
 
26
26
  /** Fastify instance powering the development server. */
@@ -1 +1 @@
1
- {"version":3,"file":"createServer.js","names":["Writable","Fastify","fastifySensible","middie","createDevMiddleware","debuggerUIMiddleware","openURLMiddleware","openStackFrameInEditorMiddleware","multipartPlugin","compilerPlugin","apiPlugin","wssPlugin","faviconPlugin","Internal","symbolicatePlugin","devtoolsPlugin","createServer","config","delegate","instance","disableRequestLogging","options","logRequests","logger","level","stream","write","chunk","_encoding","callback","log","JSON","parse","toString","onMessage","wss","apiServer","send","https","undefined","notifyBuildStart","platform","event","EventTypes","BuildStart","notifyBuildEnd","BuildEnd","broadcastToHmrClients","clientIds","hmrServer","broadcastToMessageClients","method","params","messageServer","broadcast","devMiddleware","projectRoot","rootDir","serverBaseUrl","host","port","unstable_experiments","enableNewDebugger","experiments","experimentalDebugger","register","endpoints","websocketEndpoints","prefix","use","watchFolders","addHook","request","reply","payload","header","pathname","url","split","endsWith","middleware","get","messages","getHello","getStatus","start","listen","stop","close"],"sources":["../src/createServer.ts"],"sourcesContent":["import { Writable } from 'stream';\nimport Fastify from 'fastify';\nimport fastifySensible from '@fastify/sensible';\nimport middie from '@fastify/middie';\n// eslint-disable-next-line import/no-unresolved -- no main field in package.json\nimport { createDevMiddleware } from '@react-native/dev-middleware';\nimport { debuggerUIMiddleware } from '@react-native-community/cli-debugger-ui';\nimport {\n openURLMiddleware,\n openStackFrameInEditorMiddleware,\n} from '@react-native-community/cli-server-api';\nimport multipartPlugin from './plugins/multipart';\nimport compilerPlugin from './plugins/compiler';\nimport apiPlugin from './plugins/api';\nimport wssPlugin from './plugins/wss';\nimport faviconPlugin from './plugins/favicon';\nimport { Internal, Server } from './types';\nimport symbolicatePlugin from './plugins/symbolicate';\nimport devtoolsPlugin from './plugins/devtools';\n\n/**\n * Create instance of development server, powered by Fastify.\n *\n * @param config Server configuration.\n * @returns `start` and `stop` functions as well as an underlying Fastify `instance`.\n */\nexport async function createServer(config: Server.Config) {\n let delegate: Server.Delegate;\n\n /** Fastify instance powering the development server. */\n const instance = Fastify({\n disableRequestLogging: !config.options.logRequests,\n logger: {\n level: 'trace',\n stream: new Writable({\n write: (chunk, _encoding, callback) => {\n const log = JSON.parse(chunk.toString());\n delegate?.logger.onMessage(log);\n instance.wss?.apiServer.send(log);\n callback();\n },\n }),\n },\n ...(config.options.https ? { https: config.options.https } : undefined),\n });\n\n delegate = await config.delegate({\n log: instance.log,\n notifyBuildStart: (platform) => {\n instance.wss.apiServer.send({\n event: Internal.EventTypes.BuildStart,\n platform,\n });\n },\n notifyBuildEnd: (platform) => {\n instance.wss.apiServer.send({\n event: Internal.EventTypes.BuildEnd,\n platform,\n });\n },\n broadcastToHmrClients: (event, platform, clientIds) => {\n instance.wss.hmrServer.send(event, platform, clientIds);\n },\n broadcastToMessageClients: ({ method, params }) => {\n instance.wss.messageServer.broadcast(method, params);\n },\n });\n\n const devMiddleware = createDevMiddleware({\n projectRoot: config.options.rootDir,\n serverBaseUrl: `http://${config.options.host}:${config.options.port}`,\n logger: instance.log,\n unstable_experiments: {\n enableNewDebugger: config.experiments?.experimentalDebugger,\n },\n });\n\n // Register plugins\n await instance.register(fastifySensible);\n await instance.register(middie);\n await instance.register(wssPlugin, {\n options: {\n ...config.options,\n endpoints: devMiddleware.websocketEndpoints,\n },\n delegate,\n });\n await instance.register(multipartPlugin);\n await instance.register(apiPlugin, {\n delegate,\n prefix: '/api',\n });\n await instance.register(compilerPlugin, {\n delegate,\n });\n\n // TODO: devtoolsPlugin and the following deprecated remote debugger middlewares should be removed after\n // the new (experimental) debugger is stable AND the remote debugger is finally removed from the React Native core.\n // When that happens remember to remove @react-native-community/cli-server-api & @react-native-community/cli-debugger-ui\n // from the dependencies.\n await instance.register(devtoolsPlugin, {\n options: config.options,\n });\n instance.use('/debugger-ui', debuggerUIMiddleware());\n instance.use('/open-url', openURLMiddleware);\n instance.use(\n '/open-stack-frame',\n openStackFrameInEditorMiddleware({\n watchFolders: [config.options.rootDir],\n })\n );\n\n await instance.register(symbolicatePlugin, {\n delegate,\n });\n\n // below is to prevent showing `GET 400 /favicon.ico`\n // errors in console when requesting the bundle via browser\n await instance.register(faviconPlugin);\n\n instance.addHook('onSend', async (request, reply, payload) => {\n reply.header('X-Content-Type-Options', 'nosniff');\n reply.header('X-React-Native-Project-Root', config.options.rootDir);\n\n const [pathname] = request.url.split('?');\n if (pathname.endsWith('.map')) {\n reply.header('Access-Control-Allow-Origin', 'devtools://devtools');\n }\n\n return payload;\n });\n\n // Register dev middleware\n instance.use(devMiddleware.middleware);\n\n // Register routes\n instance.get('/', async () => delegate.messages.getHello());\n instance.get('/status', async () => delegate.messages.getStatus());\n\n /** Start the development server. */\n async function start() {\n await instance.listen({\n port: config.options.port,\n host: config.options.host,\n });\n }\n\n /** Stop the development server. */\n async function stop() {\n await instance.close();\n }\n\n return {\n start,\n stop,\n instance,\n };\n}\n"],"mappings":"AAAA,SAASA,QAAQ,QAAQ,QAAQ;AACjC,OAAOC,OAAO,MAAM,SAAS;AAC7B,OAAOC,eAAe,MAAM,mBAAmB;AAC/C,OAAOC,MAAM,MAAM,iBAAiB;AACpC;AACA,SAASC,mBAAmB,QAAQ,8BAA8B;AAClE,SAASC,oBAAoB,QAAQ,yCAAyC;AAC9E,SACEC,iBAA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C,CAAC;;EAEF;EACAvD,QAAQ,CAACkD,GAAG,CAACd,aAAa,CAACyB,UAAU,CAAC;;EAEtC;EACA7D,QAAQ,CAAC8D,GAAG,CAAC,GAAG,EAAE,YAAY/D,QAAQ,CAACgE,QAAQ,CAACC,QAAQ,CAAC,CAAC,CAAC;EAC3DhE,QAAQ,CAAC8D,GAAG,CAAC,SAAS,EAAE,YAAY/D,QAAQ,CAACgE,QAAQ,CAACE,SAAS,CAAC,CAAC,CAAC;;EAElE;EACA,eAAeC,KAAKA,CAAA,EAAG;IACrB,MAAMlE,QAAQ,CAACmE,MAAM,CAAC;MACpB1B,IAAI,EAAE3C,MAAM,CAACI,OAAO,CAACuC,IAAI;MACzBD,IAAI,EAAE1C,MAAM,CAACI,OAAO,CAACsC;IACvB,CAAC,CAAC;EACJ;;EAEA;EACA,eAAe4B,IAAIA,CAAA,EAAG;IACpB,MAAMpE,QAAQ,CAACqE,KAAK,CAAC,CAAC;EACxB;EAEA,OAAO;IACLH,KAAK;IACLE,IAAI;IACJpE;EACF,CAAC;AACH"}
1
+ {"version":3,"file":"createServer.js","names":["Writable","middie","fastifySensible","debuggerUIMiddleware","openStackFrameInEditorMiddleware","openURLMiddleware","createDevMiddleware","Fastify","apiPlugin","compilerPlugin","devtoolsPlugin","faviconPlugin","multipartPlugin","symbolicatePlugin","wssPlugin","Internal","createServer","config","delegate","instance","disableRequestLogging","options","logRequests","logger","level","stream","write","chunk","_encoding","callback","log","JSON","parse","toString","onMessage","wss","apiServer","send","https","undefined","notifyBuildStart","platform","event","EventTypes","BuildStart","notifyBuildEnd","BuildEnd","broadcastToHmrClients","clientIds","hmrServer","broadcastToMessageClients","method","params","messageServer","broadcast","devMiddleware","projectRoot","rootDir","serverBaseUrl","host","port","unstable_experiments","enableNewDebugger","experiments","experimentalDebugger","register","endpoints","websocketEndpoints","prefix","use","watchFolders","addHook","request","reply","payload","header","pathname","url","split","endsWith","middleware","get","messages","getHello","getStatus","start","listen","stop","close"],"sources":["../src/createServer.ts"],"sourcesContent":["import { Writable } from 'node:stream';\nimport middie from '@fastify/middie';\nimport fastifySensible from '@fastify/sensible';\nimport { debuggerUIMiddleware } from '@react-native-community/cli-debugger-ui';\nimport {\n openStackFrameInEditorMiddleware,\n openURLMiddleware,\n} from '@react-native-community/cli-server-api';\nimport { createDevMiddleware } from '@react-native/dev-middleware';\nimport Fastify from 'fastify';\nimport apiPlugin from './plugins/api';\nimport compilerPlugin from './plugins/compiler';\nimport devtoolsPlugin from './plugins/devtools';\nimport faviconPlugin from './plugins/favicon';\nimport multipartPlugin from './plugins/multipart';\nimport symbolicatePlugin from './plugins/symbolicate';\nimport wssPlugin from './plugins/wss';\nimport { Internal, type Server } from './types';\n\n/**\n * Create instance of development server, powered by Fastify.\n *\n * @param config Server configuration.\n * @returns `start` and `stop` functions as well as an underlying Fastify `instance`.\n */\nexport async function createServer(config: Server.Config) {\n // biome-ignore lint/style/useConst: needed in fastify constructor\n let delegate: Server.Delegate;\n\n /** Fastify instance powering the development server. */\n const instance = Fastify({\n disableRequestLogging: !config.options.logRequests,\n logger: {\n level: 'trace',\n stream: new Writable({\n write: (chunk, _encoding, callback) => {\n const log = JSON.parse(chunk.toString());\n delegate?.logger.onMessage(log);\n instance.wss?.apiServer.send(log);\n callback();\n },\n }),\n },\n ...(config.options.https ? { https: config.options.https } : undefined),\n });\n\n delegate = await config.delegate({\n log: instance.log,\n notifyBuildStart: (platform) => {\n instance.wss.apiServer.send({\n event: Internal.EventTypes.BuildStart,\n platform,\n });\n },\n notifyBuildEnd: (platform) => {\n instance.wss.apiServer.send({\n event: Internal.EventTypes.BuildEnd,\n platform,\n });\n },\n broadcastToHmrClients: (event, platform, clientIds) => {\n instance.wss.hmrServer.send(event, platform, clientIds);\n },\n broadcastToMessageClients: ({ method, params }) => {\n instance.wss.messageServer.broadcast(method, params);\n },\n });\n\n const devMiddleware = createDevMiddleware({\n projectRoot: config.options.rootDir,\n serverBaseUrl: `http://${config.options.host}:${config.options.port}`,\n logger: instance.log,\n unstable_experiments: {\n enableNewDebugger: config.experiments?.experimentalDebugger,\n },\n });\n\n // Register plugins\n await instance.register(fastifySensible);\n await instance.register(middie);\n await instance.register(wssPlugin, {\n options: {\n ...config.options,\n endpoints: devMiddleware.websocketEndpoints,\n },\n delegate,\n });\n await instance.register(multipartPlugin);\n await instance.register(apiPlugin, {\n delegate,\n prefix: '/api',\n });\n await instance.register(compilerPlugin, {\n delegate,\n });\n\n // TODO: devtoolsPlugin and the following deprecated remote debugger middlewares should be removed after\n // the new (experimental) debugger is stable AND the remote debugger is finally removed from the React Native core.\n // When that happens remember to remove @react-native-community/cli-server-api & @react-native-community/cli-debugger-ui\n // from the dependencies.\n await instance.register(devtoolsPlugin, {\n options: config.options,\n });\n instance.use('/debugger-ui', debuggerUIMiddleware());\n instance.use('/open-url', openURLMiddleware);\n instance.use(\n '/open-stack-frame',\n openStackFrameInEditorMiddleware({\n watchFolders: [config.options.rootDir],\n })\n );\n\n await instance.register(symbolicatePlugin, {\n delegate,\n });\n\n // below is to prevent showing `GET 400 /favicon.ico`\n // errors in console when requesting the bundle via browser\n await instance.register(faviconPlugin);\n\n instance.addHook('onSend', async (request, reply, payload) => {\n reply.header('X-Content-Type-Options', 'nosniff');\n reply.header('X-React-Native-Project-Root', config.options.rootDir);\n\n const [pathname] = request.url.split('?');\n if (pathname.endsWith('.map')) {\n reply.header('Access-Control-Allow-Origin', 'devtools://devtools');\n }\n\n return payload;\n });\n\n // Register dev middleware\n instance.use(devMiddleware.middleware);\n\n // Register routes\n instance.get('/', async () => delegate.messages.getHello());\n instance.get('/status', async () => delegate.messages.getStatus());\n\n /** Start the development server. */\n async function start() {\n await instance.listen({\n port: config.options.port,\n host: config.options.host,\n });\n }\n\n /** Stop the development server. */\n async function stop() {\n await instance.close();\n }\n\n return {\n start,\n stop,\n instance,\n };\n}\n"],"mappings":"AAAA,SAASA,QAAQ,QAAQ,aAAa;AACtC,OAAOC,MAAM,MAAM,iBAAiB;AACpC,OAAO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C,IAAIF,QAAQ,CAACG,QAAQ,CAAC,MAAM,CAAC,EAAE;MAC7BN,KAAK,CAACE,MAAM,CAAC,6BAA6B,EAAE,qBAAqB,CAAC;IACpE;IAEA,OAAOD,OAAO;EAChB,CAAC,CAAC;;EAEF;EACAvD,QAAQ,CAACkD,GAAG,CAACd,aAAa,CAACyB,UAAU,CAAC;;EAEtC;EACA7D,QAAQ,CAAC8D,GAAG,CAAC,GAAG,EAAE,YAAY/D,QAAQ,CAACgE,QAAQ,CAACC,QAAQ,CAAC,CAAC,CAAC;EAC3DhE,QAAQ,CAAC8D,GAAG,CAAC,SAAS,EAAE,YAAY/D,QAAQ,CAACgE,QAAQ,CAACE,SAAS,CAAC,CAAC,CAAC;;EAElE;EACA,eAAeC,KAAKA,CAAA,EAAG;IACrB,MAAMlE,QAAQ,CAACmE,MAAM,CAAC;MACpB1B,IAAI,EAAE3C,MAAM,CAACI,OAAO,CAACuC,IAAI;MACzBD,IAAI,EAAE1C,MAAM,CAACI,OAAO,CAACsC;IACvB,CAAC,CAAC;EACJ;;EAEA;EACA,eAAe4B,IAAIA,CAAA,EAAG;IACpB,MAAMpE,QAAQ,CAACqE,KAAK,CAAC,CAAC;EACxB;EAEA,OAAO;IACLH,KAAK;IACLE,IAAI;IACJpE;EACF,CAAC;AACH","ignoreList":[]}
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":[],"sources":["../src/index.ts"],"sourcesContent":["export * from './createServer';\nexport * from './types';\n"],"mappings":""}
1
+ {"version":3,"file":"index.js","names":[],"sources":["../src/index.ts"],"sourcesContent":["export * from './createServer';\nexport * from './types';\n"],"mappings":"","ignoreList":[]}
@@ -1 +1 @@
1
- {"version":3,"file":"apiPlugin.js","names":["paramsSchema","type","properties","platform","required","apiPlugin","instance","delegate","get","_request","reply","api","send","data","getPlatforms","notImplemented","schema","params","request","getAssets","getCompilationStats"],"sources":["../../../src/plugins/api/apiPlugin.ts"],"sourcesContent":["import type { FastifyInstance } from 'fastify';\nimport type { Server } from '../../types';\n\nconst paramsSchema = {\n type: 'object',\n properties: {\n platform: {\n type: 'string',\n },\n },\n required: ['platform'],\n};\n\ntype Params = { platform: string };\n\nasync function apiPlugin(\n instance: FastifyInstance,\n { delegate }: { delegate: Server.Delegate }\n) {\n instance.get('/platforms', async (_request, reply) =>\n delegate.api\n ? reply.send({ data: await delegate.api.getPlatforms() })\n : reply.notImplemented('Missing API delegate implementation')\n );\n\n instance.get<{ Params: Params }>(\n '/:platform/assets',\n { schema: { params: paramsSchema } },\n async (request, reply) =>\n delegate.api\n ? reply.send({\n data: await delegate.api.getAssets(request.params.platform),\n })\n : reply.notImplemented('Missing API delegate implementation')\n );\n\n instance.get<{ Params: Params }>(\n '/:platform/stats',\n { schema: { params: paramsSchema } },\n async (request, reply) =>\n delegate.api\n ? reply.send({\n data: await delegate.api?.getCompilationStats(\n request.params.platform\n ),\n })\n : reply.notImplemented('Missing API delegate implementation')\n );\n}\n\nexport default apiPlugin;\n"],"mappings":"AAGA,MAAMA,YAAY,GAAG;EACnBC,IAAI,EAAE,QAAQ;EACdC,UAAU,EAAE;IACVC,QAAQ,EAAE;MACRF,IAAI,EAAE;IACR;EACF,CAAC;EACDG,QAAQ,EAAE,CAAC,UAAU;AACvB,CAAC;AAID,eAAeC,SAASA,CACtBC,QAAyB,EACzB;EAAEC;AAAwC,CAAC,EAC3C;EACAD,QAAQ,CAACE,GAAG,CAAC,YAAY,EAAE,OAAOC,QAAQ,EAAEC,KAAK,KAC/CH,QAAQ,CAACI,GAAG,GACRD,KAAK,CAACE,IAAI,CAAC;IAAEC,IAAI,EAAE,MAAMN,QAAQ,CAACI,GAAG,CAACG,YAAY,CAAC;EAAE,CAAC,CAAC,GACvDJ,KAAK,CAACK,cAAc,CAAC,qCAAqC,CAChE,CAAC;EAEDT,QAAQ,CAACE,GAAG,CACV,mBAAmB,EACnB;IAAEQ,MAAM,EAAE;MAAEC,MAAM,EAAEjB;IAAa;EAAE,CAAC,EACpC,OAAOkB,OAAO,EAAER,KAAK,KACnBH,QAAQ,CAACI,GAAG,GACRD,KAAK,CAACE,IAAI,CAAC;IACTC,IAAI,EAAE,MAAMN,QAAQ,CAACI,GAAG,CAACQ,SAAS,CAACD,OAAO,CAACD,MAAM,CAACd,QAAQ;EAC5D,CAAC,CAAC,GACFO,KAAK,CAACK,cAAc,CAAC,qCAAqC,CAClE,CAAC;EAEDT,QAAQ,CAACE,GAAG,CACV,kBAAkB,EAClB;IAAEQ,MAAM,EAAE;MAAEC,MAAM,EAAEjB;IAAa;EAAE,CAAC,EACpC,OAAOkB,OAAO,EAAER,KAAK,KACnBH,QAAQ,CAACI,GAAG,GACRD,KAAK,CAACE,IAAI,CAAC;IACTC,IAAI,EAAE,MAAMN,QAAQ,CAACI,GAAG,EAAES,mBAAmB,CAC3CF,OAAO,CAACD,MAAM,CAACd,QACjB;EACF,CAAC,CAAC,GACFO,KAAK,CAACK,cAAc,CAAC,qCAAqC,CAClE,CAAC;AACH;AAEA,eAAeV,SAAS"}
1
+ {"version":3,"file":"apiPlugin.js","names":["paramsSchema","type","properties","platform","required","apiPlugin","instance","delegate","get","_request","reply","api","send","data","getPlatforms","notImplemented","schema","params","request","getAssets","getCompilationStats"],"sources":["../../../src/plugins/api/apiPlugin.ts"],"sourcesContent":["import type { FastifyInstance } from 'fastify';\nimport type { Server } from '../../types';\n\nconst paramsSchema = {\n type: 'object',\n properties: {\n platform: {\n type: 'string',\n },\n },\n required: ['platform'],\n};\n\ntype Params = { platform: string };\n\nasync function apiPlugin(\n instance: FastifyInstance,\n { delegate }: { delegate: Server.Delegate }\n) {\n instance.get('/platforms', async (_request, reply) =>\n delegate.api\n ? reply.send({ data: await delegate.api.getPlatforms() })\n : reply.notImplemented('Missing API delegate implementation')\n );\n\n instance.get<{ Params: Params }>(\n '/:platform/assets',\n { schema: { params: paramsSchema } },\n async (request, reply) =>\n delegate.api\n ? reply.send({\n data: await delegate.api.getAssets(request.params.platform),\n })\n : reply.notImplemented('Missing API delegate implementation')\n );\n\n instance.get<{ Params: Params }>(\n '/:platform/stats',\n { schema: { params: paramsSchema } },\n async (request, reply) =>\n delegate.api\n ? reply.send({\n data: await delegate.api?.getCompilationStats(\n request.params.platform\n ),\n })\n : reply.notImplemented('Missing API delegate implementation')\n );\n}\n\nexport default apiPlugin;\n"],"mappings":"AAGA,MAAMA,YAAY,GAAG;EACnBC,IAAI,EAAE,QAAQ;EACdC,UAAU,EAAE;IACVC,QAAQ,EAAE;MACRF,IAAI,EAAE;IACR;EACF,CAAC;EACDG,QAAQ,EAAE,CAAC,UAAU;AACvB,CAAC;AAID,eAAeC,SAASA,CACtBC,QAAyB,EACzB;EAAEC;AAAwC,CAAC,EAC3C;EACAD,QAAQ,CAACE,GAAG,CAAC,YAAY,EAAE,OAAOC,QAAQ,EAAEC,KAAK,KAC/CH,QAAQ,CAACI,GAAG,GACRD,KAAK,CAACE,IAAI,CAAC;IAAEC,IAAI,EAAE,MAAMN,QAAQ,CAACI,GAAG,CAACG,YAAY,CAAC;EAAE,CAAC,CAAC,GACvDJ,KAAK,CAACK,cAAc,CAAC,qCAAqC,CAChE,CAAC;EAEDT,QAAQ,CAACE,GAAG,CACV,mBAAmB,EACnB;IAAEQ,MAAM,EAAE;MAAEC,MAAM,EAAEjB;IAAa;EAAE,CAAC,EACpC,OAAOkB,OAAO,EAAER,KAAK,KACnBH,QAAQ,CAACI,GAAG,GACRD,KAAK,CAACE,IAAI,CAAC;IACTC,IAAI,EAAE,MAAMN,QAAQ,CAACI,GAAG,CAACQ,SAAS,CAACD,OAAO,CAACD,MAAM,CAACd,QAAQ;EAC5D,CAAC,CAAC,GACFO,KAAK,CAACK,cAAc,CAAC,qCAAqC,CAClE,CAAC;EAEDT,QAAQ,CAACE,GAAG,CACV,kBAAkB,EAClB;IAAEQ,MAAM,EAAE;MAAEC,MAAM,EAAEjB;IAAa;EAAE,CAAC,EACpC,OAAOkB,OAAO,EAAER,KAAK,KACnBH,QAAQ,CAACI,GAAG,GACRD,KAAK,CAACE,IAAI,CAAC;IACTC,IAAI,EAAE,MAAMN,QAAQ,CAACI,GAAG,EAAES,mBAAmB,CAC3CF,OAAO,CAACD,MAAM,CAACd,QACjB;EACF,CAAC,CAAC,GACFO,KAAK,CAACK,cAAc,CAAC,qCAAqC,CAClE,CAAC;AACH;AAEA,eAAeV,SAAS","ignoreList":[]}
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":["default"],"sources":["../../../src/plugins/api/index.ts"],"sourcesContent":["export { default } from './apiPlugin';\n"],"mappings":"SAASA,OAAO"}
1
+ {"version":3,"file":"index.js","names":["default"],"sources":["../../../src/plugins/api/index.ts"],"sourcesContent":["export { default } from './apiPlugin';\n"],"mappings":"SAASA,OAAO","ignoreList":[]}
@@ -16,32 +16,34 @@ async function compilerPlugin(instance, {
16
16
  }
17
17
  },
18
18
  handler: async (request, reply) => {
19
- let file = request.params['*'];
19
+ const filename = request.params['*'];
20
20
  let {
21
21
  platform
22
22
  } = request.query;
23
- if (!file) {
23
+ if (!filename) {
24
24
  // This technically should never happen - this route should not be called if file is missing.
25
- request.log.error(`File was not provided`);
25
+ request.log.error('File was not provided');
26
26
  return reply.notFound();
27
27
  }
28
28
 
29
29
  // Let consumer infer the platform. If function is not provided fallback
30
30
  // to platform query param.
31
31
  platform = delegate.compiler.inferPlatform?.(request.url) ?? platform;
32
- if (!platform) {
33
- request.log.error('Cannot detect platform');
34
- return reply.badRequest('Cannot detect platform');
35
- }
36
-
37
- // If platform happens to be in front of an asset remove it.
38
- if (file.startsWith(`${platform}/`)) {
39
- file = file.replace(`${platform}/`, '');
40
- }
41
32
  const multipart = reply.asMultipart();
33
+ const sendProgress = ({
34
+ completed,
35
+ total
36
+ }) => {
37
+ multipart?.writeChunk({
38
+ 'Content-Type': 'application/json'
39
+ }, JSON.stringify({
40
+ done: completed,
41
+ total
42
+ }));
43
+ };
42
44
  try {
43
- const asset = await delegate.compiler.getAsset(file, platform);
44
- const mimeType = delegate.compiler.getMimeType(file, platform, asset);
45
+ const asset = await delegate.compiler.getAsset(filename, platform, sendProgress);
46
+ const mimeType = delegate.compiler.getMimeType(filename, platform, asset);
45
47
  if (multipart) {
46
48
  const buffer = Buffer.isBuffer(asset) ? asset : Buffer.from(asset);
47
49
  multipart.setHeader('Content-Type', `${mimeType}; charset=UTF-8`);
@@ -1 +1 @@
1
- {"version":3,"file":"compilerPlugin.js","names":["fastifyPlugin","compilerPlugin","instance","delegate","route","method","url","schema","querystring","type","properties","platform","handler","request","reply","file","params","query","log","error","notFound","compiler","inferPlatform","badRequest","startsWith","replace","multipart","asMultipart","asset","getAsset","mimeType","getMimeType","buffer","Buffer","isBuffer","from","setHeader","String","byteLength","end","code","send","message","name","dependencies"],"sources":["../../../src/plugins/compiler/compilerPlugin.ts"],"sourcesContent":["import type { FastifyInstance } from 'fastify';\nimport fastifyPlugin from 'fastify-plugin';\nimport type { Server } from '../../types';\n\nasync function compilerPlugin(\n instance: FastifyInstance,\n { delegate }: { delegate: Server.Delegate }\n) {\n instance.route({\n method: ['GET', 'POST', 'PUT', 'DELETE', 'OPTIONS', 'HEAD'],\n url: '/*',\n schema: {\n querystring: {\n type: 'object',\n properties: {\n platform: {\n type: 'string',\n },\n },\n },\n },\n handler: async (request, reply) => {\n let file = (request.params as { '*'?: string })['*'];\n let { platform } = request.query as { platform?: string };\n\n if (!file) {\n // This technically should never happen - this route should not be called if file is missing.\n request.log.error(`File was not provided`);\n return reply.notFound();\n }\n\n // Let consumer infer the platform. If function is not provided fallback\n // to platform query param.\n platform = delegate.compiler.inferPlatform?.(request.url) ?? platform;\n\n if (!platform) {\n request.log.error('Cannot detect platform');\n return reply.badRequest('Cannot detect platform');\n }\n\n // If platform happens to be in front of an asset remove it.\n if (file.startsWith(`${platform}/`)) {\n file = file.replace(`${platform}/`, '');\n }\n\n const multipart = reply.asMultipart();\n\n try {\n const asset = await delegate.compiler.getAsset(file, platform);\n const mimeType = delegate.compiler.getMimeType(file, platform, asset);\n\n if (multipart) {\n const buffer = Buffer.isBuffer(asset) ? asset : Buffer.from(asset);\n multipart.setHeader('Content-Type', `${mimeType}; charset=UTF-8`);\n multipart.setHeader(\n 'Content-Length',\n String(Buffer.byteLength(buffer))\n );\n multipart.end(buffer);\n } else {\n return reply.code(200).type(mimeType).send(asset);\n }\n } catch (error) {\n request.log.error(error);\n return reply.notFound((error as Error).message);\n }\n },\n });\n}\n\nexport default fastifyPlugin(compilerPlugin, {\n name: 'compiler-plugin',\n dependencies: ['@fastify/sensible', 'multipart-plugin'],\n});\n"],"mappings":"AACA,OAAOA,aAAa,MAAM,gBAAgB;AAG1C,eAAeC,cAAcA,CAC3BC,QAAyB,EACzB;EAAEC;AAAwC,CAAC,EAC3C;EACAD,QAAQ,CAACE,KAAK,CAAC;IACbC,MAAM,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,CAAC;IAC3DC,GAAG,EAAE,IAAI;IACTC,MAAM,EAAE;MACNC,WAAW,EAAE;QACXC,IAAI,EAAE,QAAQ;QACdC,UAAU,EAAE;UACVC,QAAQ,EAAE;YACRF,IAAI,EAAE;UACR;QACF;MACF;IACF,CAAC;IACDG,OAAO,EAAE,MAAAA,CAAOC,OAAO,EAAEC,KAAK,KAAK;MACjC,IAAIC,IAAI,GAAIF,OAAO,CAACG,MAAM,CAAsB,GAAG,CAAC;MACpD,IAAI;QAAEL;MAAS,CAAC,GAAGE,OAAO,CAACI,KAA8B;MAEzD,IAAI,CAACF,IAAI,EAAE;QACT;QACAF,OAAO,CAACK,GAAG,CAACC,KAAK,CAAE,uBAAsB,CAAC;QAC1C,OAAOL,KAAK,CAACM,QAAQ,CAAC,CAAC;MACzB;;MAEA;MACA;MACAT,QAAQ,GAAGR,QAAQ,CAACkB,QAAQ,CAACC,aAAa,GAAGT,OAAO,CAACP,GAAG,CAAC,IAAIK,QAAQ;MAErE,IAAI,CAACA,QAAQ,EAAE;QACbE,OAAO,CAACK,G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AC;AACJ;AAEA,eAAe1C,aAAa,CAACC,cAAc,EAAE;EAC3C0C,IAAI,EAAE,iBAAiB;EACvBC,YAAY,EAAE,CAAC,mBAAmB,EAAE,kBAAkB;AACxD,CAAC,CAAC"}
1
+ {"version":3,"file":"compilerPlugin.js","names":["fastifyPlugin","compilerPlugin","instance","delegate","route","method","url","schema","querystring","type","properties","platform","handler","request","reply","filename","params","query","log","error","notFound","compiler","inferPlatform","multipart","asMultipart","sendProgress","completed","total","writeChunk","JSON","stringify","done","asset","getAsset","mimeType","getMimeType","buffer","Buffer","isBuffer","from","setHeader","String","byteLength","end","code","send","message","name","dependencies"],"sources":["../../../src/plugins/compiler/compilerPlugin.ts"],"sourcesContent":["import type { FastifyInstance } from 'fastify';\nimport fastifyPlugin from 'fastify-plugin';\nimport type { Server } from '../../types';\nimport type { SendProgress } from '../../types';\n\nasync function compilerPlugin(\n instance: FastifyInstance,\n { delegate }: { delegate: Server.Delegate }\n) {\n instance.route({\n method: ['GET', 'POST', 'PUT', 'DELETE', 'OPTIONS', 'HEAD'],\n url: '/*',\n schema: {\n querystring: {\n type: 'object',\n properties: {\n platform: {\n type: 'string',\n },\n },\n },\n },\n handler: async (request, reply) => {\n const filename = (request.params as { '*'?: string })['*'];\n let { platform } = request.query as { platform?: string };\n\n if (!filename) {\n // This technically should never happen - this route should not be called if file is missing.\n request.log.error('File was not provided');\n return reply.notFound();\n }\n\n // Let consumer infer the platform. If function is not provided fallback\n // to platform query param.\n platform = delegate.compiler.inferPlatform?.(request.url) ?? platform;\n\n const multipart = reply.asMultipart();\n\n const sendProgress: SendProgress = ({ completed, total }) => {\n multipart?.writeChunk(\n { 'Content-Type': 'application/json' },\n JSON.stringify({\n done: completed,\n total,\n })\n );\n };\n\n try {\n const asset = await delegate.compiler.getAsset(\n filename,\n platform,\n sendProgress\n );\n const mimeType = delegate.compiler.getMimeType(\n filename,\n platform,\n asset\n );\n\n if (multipart) {\n const buffer = Buffer.isBuffer(asset) ? asset : Buffer.from(asset);\n multipart.setHeader('Content-Type', `${mimeType}; charset=UTF-8`);\n multipart.setHeader(\n 'Content-Length',\n String(Buffer.byteLength(buffer))\n );\n multipart.end(buffer);\n } else {\n return reply.code(200).type(mimeType).send(asset);\n }\n } catch (error) {\n request.log.error(error);\n return reply.notFound((error as Error).message);\n }\n },\n });\n}\n\nexport default fastifyPlugin(compilerPlugin, {\n name: 'compiler-plugin',\n dependencies: ['@fastify/sensible', 'multipart-plugin'],\n});\n"],"mappings":"AACA,OAAOA,aAAa,MAAM,gBAAgB;AAI1C,eAAeC,cAAcA,CAC3BC,QAAyB,EACzB;EAAEC;AAAwC,CAAC,EAC3C;EACAD,QAAQ,CAACE,KAAK,CAAC;IACbC,MAAM,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,CAAC;IAC3DC,GAAG,EAAE,IAAI;IACTC,MAAM,EAAE;MACNC,WAAW,EAAE;QACXC,IAAI,EAAE,QAAQ;QACdC,UAAU,EAAE;UACVC,QAAQ,EAAE;YACRF,IAAI,EAAE;UACR;QACF;MACF;IACF,CAAC;IACDG,OAAO,EAAE,MAAAA,CAAOC,OAAO,EAAEC,KAAK,KAAK;MACjC,MAAMC,QAAQ,GAAIF,OAAO,CAACG,MAAM,CAAsB,GAAG,CAAC;MAC1D,IAAI;QAAEL;MAAS,CAAC,GAAGE,OAAO,CAACI,KAA8B;MAEzD,IAAI,CAACF,QAAQ,EAAE;QACb;QACAF,OAAO,CAACK,GAAG,CAACC,KAAK,CAAC,uBAAuB,CAAC;QAC1C,OAAOL,KAAK,CAACM,QAAQ,CAAC,CAAC;MACzB;;MAEA;MACA;MACAT,QAAQ,GAAGR,QAAQ,CAACkB,QAAQ,CAACC,aAAa,GAAGT,OAAO,CAACP,GAAG,CAAC,IAAIK,QAAQ;MAErE,MAAMY,SAAS,GAAGT,KAAK,CAACU,WAAW,CAAC,CAAC;MAErC,MAAMC,YAA0B,GAAGA,CAA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AAmB,EAAE,kBAAkB;AACxD,CAAC,CAAC","ignoreList":[]}
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":["default"],"sources":["../../../src/plugins/compiler/index.ts"],"sourcesContent":["export { default } from './compilerPlugin';\nexport * from './types';\n"],"mappings":"SAASA,OAAO;AAAA"}
1
+ {"version":3,"file":"index.js","names":["default"],"sources":["../../../src/plugins/compiler/index.ts"],"sourcesContent":["export { default } from './compilerPlugin';\nexport * from './types';\n"],"mappings":"SAASA,OAAO;AAAA","ignoreList":[]}
@@ -1,4 +1,4 @@
1
- /// <reference types="node" />
1
+ import type { SendProgress } from '../../types';
2
2
  /**
3
3
  * Delegate with implementation for compiler-specific functions.
4
4
  */
@@ -10,8 +10,9 @@ export interface CompilerDelegate {
10
10
  *
11
11
  * @param filename Filename of the asset to get.
12
12
  * @param platform Platform of the asset to get.
13
+ * @param sendProgress Function to notify the client who requested the asset about compilation progress.
13
14
  */
14
- getAsset: (filename: string, platform: string) => Promise<string | Buffer>;
15
+ getAsset: (filename: string, platform: string | undefined, sendProgress?: SendProgress) => Promise<string | Buffer>;
15
16
  /**
16
17
  * Detect MIME type of the asset from `filename`, `platform` or `data` (or from combination of either).
17
18
  *
@@ -19,7 +20,7 @@ export interface CompilerDelegate {
19
20
  * @param platform Platform of the asset.
20
21
  * @param data Asset's content.
21
22
  */
22
- getMimeType: (filename: string, platform: string, data: string | Buffer) => string;
23
+ getMimeType: (filename: string, platform: string | undefined, data: string | Buffer) => string;
23
24
  /**
24
25
  * Detect the platform from the URI - either from filename, query params or both.
25
26
  *
@@ -1 +1 @@
1
- {"version":3,"file":"types.js","names":[],"sources":["../../../src/plugins/compiler/types.ts"],"sourcesContent":["/**\n * Delegate with implementation for compiler-specific functions.\n */\nexport interface CompilerDelegate {\n /**\n * Get compiled asset content.\n *\n * If the compilation is in progress, it should wait until compilation finishes and then return the asset.\n *\n * @param filename Filename of the asset to get.\n * @param platform Platform of the asset to get.\n */\n getAsset: (filename: string, platform: string) => Promise<string | Buffer>;\n\n /**\n * Detect MIME type of the asset from `filename`, `platform` or `data` (or from combination of either).\n *\n * @param filename Filename of the asset.\n * @param platform Platform of the asset.\n * @param data Asset's content.\n */\n getMimeType: (\n filename: string,\n platform: string,\n data: string | Buffer\n ) => string;\n\n /**\n * Detect the platform from the URI - either from filename, query params or both.\n *\n * @param uri URI string.\n */\n inferPlatform?: (uri: string) => string | undefined;\n}\n"],"mappings":""}
1
+ {"version":3,"file":"types.js","names":[],"sources":["../../../src/plugins/compiler/types.ts"],"sourcesContent":["import type { SendProgress } from '../../types';\n\n/**\n * Delegate with implementation for compiler-specific functions.\n */\nexport interface CompilerDelegate {\n /**\n * Get compiled asset content.\n *\n * If the compilation is in progress, it should wait until compilation finishes and then return the asset.\n *\n * @param filename Filename of the asset to get.\n * @param platform Platform of the asset to get.\n * @param sendProgress Function to notify the client who requested the asset about compilation progress.\n */\n getAsset: (\n filename: string,\n platform: string | undefined,\n sendProgress?: SendProgress\n ) => Promise<string | Buffer>;\n\n /**\n * Detect MIME type of the asset from `filename`, `platform` or `data` (or from combination of either).\n *\n * @param filename Filename of the asset.\n * @param platform Platform of the asset.\n * @param data Asset's content.\n */\n getMimeType: (\n filename: string,\n platform: string | undefined,\n data: string | Buffer\n ) => string;\n\n /**\n * Detect the platform from the URI - either from filename, query params or both.\n *\n * @param uri URI string.\n */\n inferPlatform?: (uri: string) => string | undefined;\n}\n"],"mappings":"","ignoreList":[]}
@@ -1,5 +1,5 @@
1
- import open from 'open';
2
1
  import fastifyPlugin from 'fastify-plugin';
2
+ import open from 'open';
3
3
  async function devtoolsPlugin(instance, {
4
4
  options
5
5
  }) {
@@ -1 +1 @@
1
- {"version":3,"file":"devtoolsPlugin.js","names":["open","fastifyPlugin","devtoolsPlugin","instance","options","route","method","url","handler","_request","reply","wss","messageServer","broadcast","send","request","customDebugger","process","env","REACT_DEBUGGER","debuggerServer","isDebuggerConnected","https","host","port","log","info","msg","error","name","dependencies"],"sources":["../../../src/plugins/devtools/devtoolsPlugin.ts"],"sourcesContent":["import open from 'open';\nimport type { FastifyInstance } from 'fastify';\nimport fastifyPlugin from 'fastify-plugin';\nimport type { Server } from '../../types';\n\nasync function devtoolsPlugin(\n instance: FastifyInstance,\n { options }: { options: Server.Options }\n) {\n instance.route({\n method: ['GET', 'POST', 'PUT'],\n url: '/reload',\n handler: (_request, reply) => {\n instance.wss.messageServer.broadcast('reload');\n reply.send('OK');\n },\n });\n\n instance.route({\n method: ['GET', 'POST', 'PUT'],\n url: '/launch-js-devtools',\n handler: async (request, reply) => {\n const customDebugger = process.env.REACT_DEBUGGER;\n if (customDebugger) {\n // NOOP for now\n } else if (!instance.wss.debuggerServer.isDebuggerConnected()) {\n const url = `${options.https ? 'https' : 'http'}://${\n options.host || 'localhost'\n }:${options.port}/debugger-ui`;\n try {\n request.log.info({ msg: 'Opening debugger UI', url });\n await open(url);\n } catch (error) {\n if (error) {\n request.log.error({\n msg: 'Cannot open debugger UI',\n url,\n error,\n });\n }\n }\n }\n reply.send('OK');\n },\n });\n}\n\nexport default fastifyPlugin(devtoolsPlugin, {\n name: 'devtools-plugin',\n dependencies: ['wss-plugin'],\n});\n"],"mappings":"AAAA,OAAOA,IAAI,MAAM,MAAM;AAEvB,OAAOC,aAAa,MAAM,gBAAgB;AAG1C,eAAeC,cAAcA,CAC3BC,QAAyB,EACzB;EAAEC;AAAqC,CAAC,EACxC;EACAD,QAAQ,CAACE,KAAK,CAAC;IACbC,MAAM,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,CAAC;IAC9BC,GAAG,EAAE,SAAS;IACdC,OAAO,EAAEA,CAACC,QAAQ,EAAEC,KAAK,KAAK;MAC5BP,QAAQ,CAACQ,GAAG,CAACC,aAAa,CAACC,SAAS,CAAC,QAAQ,CAAC;MAC9CH,KAAK,CAACI,IAAI,CAAC,IAAI,CAAC;IAClB;EACF,CAAC,CAAC;EAEFX,QAAQ,CAACE,KAAK,CAAC;IACbC,MAAM,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,CAAC;IAC9BC,GAAG,EAAE,qBAAqB;IAC1BC,OAAO,EAAE,MAAAA,CAAOO,OAAO,EAAEL,KAAK,KAAK;MACjC,MAAMM,cAAc,GAAGC,OAAO,CAACC,GAAG,CAACC,cAAc;MACjD,IAAIH,cAAc,EAAE;QAClB;MAAA,CACD,MAAM,IAAI,CAACb,QAAQ,CAACQ,GAAG,CAACS,cAAc,CAACC,mBAAmB,CAAC,CAAC,EAAE;QAC7D,MAAMd,GAAG,GAAI,GAAEH,OAAO,CAACkB,KAAK,GAAG,OAAO,GAAG,MAAO,MAC9ClB,OAAO,CAACmB,IAAI,IAAI,WACjB,IAAGnB,OAAO,CAACoB,IAAK,cAAa;QAC9B,IAAI;UACFT,OAAO,CAACU,GAAG,CAACC,IAAI,CAAC;YAAEC,GAAG,EAAE,qBAAqB;YAAEpB;UAAI,CAAC,CAAC;UACrD,MAAMP,IAAI,CAACO,GAAG,CAAC;QACjB,CAAC,CAAC,OAAOqB,KAAK,EAAE;UACd,IAAIA,KAAK,EAAE;YACTb,OAAO,CAACU,GAAG,CAACG,KAAK,CAAC;cAChBD,GAAG,EAAE,yBAAyB;cAC9BpB,GAAG;cACHqB;YACF,CAAC,CAAC;UACJ;QACF;MACF;MACAlB,KAAK,CAACI,IAAI,CAAC,IAAI,CAAC;IAClB;EACF,CAAC,CAAC;AACJ;AAEA,eAAeb,aAAa,CAACC,cAAc,EAAE;EAC3C2B,IAAI,EAAE,iBAAiB;EACvBC,YAAY,EAAE,CAAC,YAAY;AAC7B,CAAC,CAAC"}
1
+ {"version":3,"file":"devtoolsPlugin.js","names":["fastifyPlugin","open","devtoolsPlugin","instance","options","route","method","url","handler","_request","reply","wss","messageServer","broadcast","send","request","customDebugger","process","env","REACT_DEBUGGER","debuggerServer","isDebuggerConnected","https","host","port","log","info","msg","error","name","dependencies"],"sources":["../../../src/plugins/devtools/devtoolsPlugin.ts"],"sourcesContent":["import type { FastifyInstance } from 'fastify';\nimport fastifyPlugin from 'fastify-plugin';\nimport open from 'open';\nimport type { Server } from '../../types';\n\nasync function devtoolsPlugin(\n instance: FastifyInstance,\n { options }: { options: Server.Options }\n) {\n instance.route({\n method: ['GET', 'POST', 'PUT'],\n url: '/reload',\n handler: (_request, reply) => {\n instance.wss.messageServer.broadcast('reload');\n reply.send('OK');\n },\n });\n\n instance.route({\n method: ['GET', 'POST', 'PUT'],\n url: '/launch-js-devtools',\n handler: async (request, reply) => {\n const customDebugger = process.env.REACT_DEBUGGER;\n if (customDebugger) {\n // NOOP for now\n } else if (!instance.wss.debuggerServer.isDebuggerConnected()) {\n const url = `${options.https ? 'https' : 'http'}://${\n options.host || 'localhost'\n }:${options.port}/debugger-ui`;\n try {\n request.log.info({ msg: 'Opening debugger UI', url });\n await open(url);\n } catch (error) {\n if (error) {\n request.log.error({\n msg: 'Cannot open debugger UI',\n url,\n error,\n });\n }\n }\n }\n reply.send('OK');\n },\n });\n}\n\nexport default fastifyPlugin(devtoolsPlugin, {\n name: 'devtools-plugin',\n dependencies: ['wss-plugin'],\n});\n"],"mappings":"AACA,OAAOA,aAAa,MAAM,gBAAgB;AAC1C,OAAOC,IAAI,MAAM,MAAM;AAGvB,eAAeC,cAAcA,CAC3BC,QAAyB,EACzB;EAAEC;AAAqC,CAAC,EACxC;EACAD,QAAQ,CAACE,KAAK,CAAC;IACbC,MAAM,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,CAAC;IAC9BC,GAAG,EAAE,SAAS;IACdC,OAAO,EAAEA,CAACC,QAAQ,EAAEC,KAAK,KAAK;MAC5BP,QAAQ,CAACQ,GAAG,CAACC,aAAa,CAACC,SAAS,CAAC,QAAQ,CAAC;MAC9CH,KAAK,CAACI,IAAI,CAAC,IAAI,CAAC;IAClB;EACF,CAAC,CAAC;EAEFX,QAAQ,CAACE,KAAK,CAAC;IACbC,MAAM,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,CAAC;IAC9BC,GAAG,EAAE,qBAAqB;IAC1BC,OAAO,EAAE,MAAAA,CAAOO,OAAO,EAAEL,KAAK,KAAK;MACjC,MAAMM,cAAc,GAAGC,OAAO,CAACC,GAAG,CAACC,cAAc;MACjD,IAAIH,cAAc,EAAE;QAClB;MAAA,CACD,MAAM,IAAI,CAACb,QAAQ,CAACQ,GAAG,CAACS,cAAc,CAACC,mBAAmB,CAAC,CAAC,EAAE;QAC7D,MAAMd,GAAG,GAAG,GAAGH,OAAO,CAACkB,KAAK,GAAG,OAAO,GAAG,MAAM,MAC7ClB,OAAO,CAACmB,IAAI,IAAI,WAAW,IACzBnB,OAAO,CAACoB,IAAI,cAAc;QAC9B,IAAI;UACFT,OAAO,CAACU,GAAG,CAACC,IAAI,CAAC;YAAEC,GAAG,EAAE,qBAAqB;YAAEpB;UAAI,CAAC,CAAC;UACrD,MAAMN,IAAI,CAACM,GAAG,CAAC;QACjB,CAAC,CAAC,OAAOqB,KAAK,EAAE;UACd,IAAIA,KAAK,EAAE;YACTb,OAAO,CAACU,GAAG,CAACG,KAAK,CAAC;cAChBD,GAAG,EAAE,yBAAyB;cAC9BpB,GAAG;cACHqB;YACF,CAAC,CAAC;UACJ;QACF;MACF;MACAlB,KAAK,CAACI,IAAI,CAAC,IAAI,CAAC;IAClB;EACF,CAAC,CAAC;AACJ;AAEA,eAAed,aAAa,CAACE,cAAc,EAAE;EAC3C2B,IAAI,EAAE,iBAAiB;EACvBC,YAAY,EAAE,CAAC,YAAY;AAC7B,CAAC,CAAC","ignoreList":[]}
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":["default"],"sources":["../../../src/plugins/devtools/index.ts"],"sourcesContent":["export { default } from './devtoolsPlugin';\n"],"mappings":"SAASA,OAAO"}
1
+ {"version":3,"file":"index.js","names":["default"],"sources":["../../../src/plugins/devtools/index.ts"],"sourcesContent":["export { default } from './devtoolsPlugin';\n"],"mappings":"SAASA,OAAO","ignoreList":[]}
@@ -1,5 +1,5 @@
1
- import path from 'path';
2
- import { fileURLToPath } from 'url';
1
+ import path from 'node:path';
2
+ import { fileURLToPath } from 'node:url';
3
3
  import fastifyFavicon from 'fastify-favicon';
4
4
  import fastifyPlugin from 'fastify-plugin';
5
5
 
@@ -1 +1 @@
1
- {"version":3,"file":"faviconPlugin.js","names":["path","fileURLToPath","fastifyFavicon","fastifyPlugin","dirname","import","meta","url","pathToImgDir","join","faviconPlugin","instance","register","name"],"sources":["../../../src/plugins/favicon/faviconPlugin.ts"],"sourcesContent":["import path from 'path';\nimport { fileURLToPath } from 'url';\nimport fastifyFavicon from 'fastify-favicon';\nimport type { FastifyInstance } from 'fastify';\nimport fastifyPlugin from 'fastify-plugin';\n\n// @ts-ignore\nconst dirname = path.dirname(fileURLToPath(import.meta.url));\nconst pathToImgDir = path.join(dirname, '../../img');\n\nasync function faviconPlugin(instance: FastifyInstance) {\n instance.register(fastifyFavicon, { path: pathToImgDir });\n}\n\nexport default fastifyPlugin(faviconPlugin, {\n name: 'favicon-plugin',\n});\n"],"mappings":"AAAA,OAAOA,IAAI,MAAM,MAAM;AACvB,SAASC,aAAa,QAAQ,KAAK;AACnC,OAAOC,cAAc,MAAM,iBAAiB;AAE5C,OAAOC,aAAa,MAAM,gBAAgB;;AAE1C;AACA,MAAMC,OAAO,GAAGJ,IAAI,CAACI,OAAO,CAACH,aAAa,CAACI,MAAM,CAACC,IAAI,CAACC,GAAG,CAAC,CAAC;AAC5D,MAAMC,YAAY,GAAGR,IAAI,CAACS,IAAI,CAACL,OAAO,EAAE,WAAW,CAAC;AAEpD,eAAeM,aAAaA,CAACC,QAAyB,EAAE;EACtDA,QAAQ,CAACC,QAAQ,CAACV,cAAc,EAAE;IAAEF,IAAI,EAAEQ;EAAa,CAAC,CAAC;AAC3D;AAEA,eAAeL,aAAa,CAACO,aAAa,EAAE;EAC1CG,IAAI,EAAE;AACR,CAAC,CAAC"}
1
+ {"version":3,"file":"faviconPlugin.js","names":["path","fileURLToPath","fastifyFavicon","fastifyPlugin","dirname","import","meta","url","pathToImgDir","join","faviconPlugin","instance","register","name"],"sources":["../../../src/plugins/favicon/faviconPlugin.ts"],"sourcesContent":["import path from 'node:path';\nimport { fileURLToPath } from 'node:url';\nimport type { FastifyInstance } from 'fastify';\nimport fastifyFavicon from 'fastify-favicon';\nimport fastifyPlugin from 'fastify-plugin';\n\n// @ts-ignore\nconst dirname = path.dirname(fileURLToPath(import.meta.url));\nconst pathToImgDir = path.join(dirname, '../../img');\n\nasync function faviconPlugin(instance: FastifyInstance) {\n instance.register(fastifyFavicon, { path: pathToImgDir });\n}\n\nexport default fastifyPlugin(faviconPlugin, {\n name: 'favicon-plugin',\n});\n"],"mappings":"AAAA,OAAOA,IAAI,MAAM,WAAW;AAC5B,SAASC,aAAa,QAAQ,UAAU;AAExC,OAAOC,cAAc,MAAM,iBAAiB;AAC5C,OAAOC,aAAa,MAAM,gBAAgB;;AAE1C;AACA,MAAMC,OAAO,GAAGJ,IAAI,CAACI,OAAO,CAACH,aAAa,CAACI,MAAM,CAACC,IAAI,CAACC,GAAG,CAAC,CAAC;AAC5D,MAAMC,YAAY,GAAGR,IAAI,CAACS,IAAI,CAACL,OAAO,EAAE,WAAW,CAAC;AAEpD,eAAeM,aAAaA,CAACC,QAAyB,EAAE;EACtDA,QAAQ,CAACC,QAAQ,CAACV,cAAc,EAAE;IAAEF,IAAI,EAAEQ;EAAa,CAAC,CAAC;AAC3D;AAEA,eAAeL,aAAa,CAACO,aAAa,EAAE;EAC1CG,IAAI,EAAE;AACR,CAAC,CAAC","ignoreList":[]}
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":["default"],"sources":["../../../src/plugins/favicon/index.ts"],"sourcesContent":["export { default } from './faviconPlugin';\n"],"mappings":"SAASA,OAAO"}
1
+ {"version":3,"file":"index.js","names":["default"],"sources":["../../../src/plugins/favicon/index.ts"],"sourcesContent":["export { default } from './faviconPlugin';\n"],"mappings":"SAASA,OAAO","ignoreList":[]}
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":["default"],"sources":["../../../src/plugins/multipart/index.ts"],"sourcesContent":["export { default } from './multipartPlugin';\nexport * from './types';\n"],"mappings":"SAASA,OAAO;AAAA"}
1
+ {"version":3,"file":"index.js","names":["default"],"sources":["../../../src/plugins/multipart/index.ts"],"sourcesContent":["export { default } from './multipartPlugin';\nexport * from './types';\n"],"mappings":"SAASA,OAAO;AAAA","ignoreList":[]}
@@ -1,4 +1,4 @@
1
- import { PassThrough } from 'stream';
1
+ import { PassThrough } from 'node:stream';
2
2
  import fastifyPlugin from 'fastify-plugin';
3
3
  /**
4
4
  * Implementation is based on:
@@ -1 +1 @@
1
- {"version":3,"file":"multipartPlugin.js","names":["PassThrough","fastifyPlugin","CRLF","BOUNDARY","multipartPlugin","instance","asMultipart","request","headers","accept","undefined","stream","code","header","send","serializeHeaders","Object","keys","map","key","join","writeChunk","data","isLast","chunk","write","setHeader","name","value","end","decorateReply"],"sources":["../../../src/plugins/multipart/multipartPlugin.ts"],"sourcesContent":["import type { IncomingHttpHeaders } from 'http';\nimport { PassThrough } from 'stream';\nimport type { FastifyInstance, FastifyReply } from 'fastify';\nimport fastifyPlugin from 'fastify-plugin';\nimport type { MultipartHandler } from './types';\n\n/**\n * Implementation is based on:\n * https://github.com/facebook/metro/blob/347b1d7ed87995d7951aaa9fd597c04b06013dac/packages/metro/src/Server/MultipartResponse.js\n */\n\nconst CRLF = '\\r\\n';\nconst BOUNDARY = '3beqjf3apnqeu3h5jqorms4i';\n\nasync function multipartPlugin(instance: FastifyInstance) {\n function asMultipart(this: FastifyReply): MultipartHandler | undefined {\n // We should check if is included in accept or if accept has multipart/* or */*,\n // but React Native will set accept to exactly `multipart/mixed`, so a simple check\n // will suffice.\n if (this.request.headers.accept !== 'multipart/mixed') {\n return undefined;\n }\n\n const headers: IncomingHttpHeaders = {};\n const stream = new PassThrough();\n\n this.code(200)\n .header('Content-Type', `multipart/mixed; boundary=\"${BOUNDARY}\"`)\n .send(stream);\n\n function serializeHeaders(headers: IncomingHttpHeaders) {\n return Object.keys(headers)\n .map((key) => `${key}: ${headers[key]}`)\n .join(CRLF);\n }\n\n function writeChunk<T>(\n headers: IncomingHttpHeaders,\n data: T,\n isLast?: boolean\n ) {\n let chunk = `${CRLF}--${BOUNDARY}${CRLF}`;\n if (headers) {\n chunk += serializeHeaders(headers) + CRLF + CRLF;\n }\n\n if (data) {\n chunk += data;\n }\n\n if (isLast) {\n chunk += `${CRLF}--${BOUNDARY}--${CRLF}`;\n }\n\n stream.write(chunk);\n }\n\n function setHeader(name: string, value: string | string[] | undefined) {\n headers[name] = value;\n }\n\n function end<T>(data: T) {\n writeChunk(headers, data, true);\n stream.end();\n }\n\n return {\n writeChunk,\n setHeader,\n end,\n };\n }\n\n instance.decorateReply('asMultipart', asMultipart);\n}\n\nexport default fastifyPlugin(multipartPlugin, {\n name: 'multipart-plugin',\n});\n"],"mappings":"AACA,SAASA,WAAW,QAAQ,QAAQ;AAEpC,OAAOC,aAAa,MAAM,gBAAgB;AAG1C;AACA;AACA;AACA;;AAEA,MAAMC,IAAI,GAAG,MAAM;AACnB,MAAMC,QAAQ,GAAG,0BAA0B;AAE3C,eAAeC,eAAeA,CAACC,QAAyB,EAAE;EACxD,SAASC,WAAWA,CAAA,EAAmD;IACrE;IACA;IACA;IACA,IAAI,IAAI,CAACC,OAAO,CAACC,OAAO,CAACC,MAAM,KAAK,iBAAiB,EAAE;MACrD,OAAOC,SAAS;IAClB;IAEA,MAAMF,OAA4B,GAAG,CAAC,CAAC;IACvC,MAAMG,MAAM,GAAG,IAAIX,WAAW,CAAC,CAAC;IAEhC,IAAI,CAACY,IAAI,CAAC,GAAG,CAAC,CACXC,MAAM,CAAC,cAAc,EAAG,8BAA6BV,QAAS,GAAE,CAAC,CACjEW,IAAI,CAACH,MAAM,CAAC;IAEf,SAASI,gBAAgBA,CAACP,OAA4B,EAAE;MACtD,OAAOQ,MAAM,CAACC,IAAI,CAACT,OAAO,CAAC,CACxBU,GAAG,CAAEC,GAAG,IAAM,GAAEA,GAAI,KAAIX,OAAO,CAACW,GAAG,CAAE,EAAC,CAAC,CACvCC,IAAI,CAAClB,IAAI,CAAC;IACf;IAEA,SAASmB,UAAUA,CACjBb,OAA4B,EAC5Bc,IAAO,EACPC,MAAgB,EAChB;MACA,IAAIC,KAAK,GAAI,GAAEtB,IAAK,KAAIC,QAAS,GAAED,IAAK,EAAC;MACzC,IAAIM,OAAO,EAAE;QACXgB,KAAK,IAAIT,gBAAgB,CAACP,OAAO,CAAC,GAAGN,IAAI,GAAGA,IAAI;MAClD;MAEA,IAAIoB,IAAI,EAAE;QACRE,KAAK,IAAIF,IAAI;MACf;MAEA,IAAIC,MAAM,EAAE;QACVC,KAAK,IAAK,GAAEtB,IAAK,KAAIC,QAAS,KAAID,IAAK,EAAC;MAC1C;MAEAS,MAAM,CAACc,KAAK,CAACD,KAAK,CAAC;IACrB;IAEA,SAASE,SAASA,CAACC,IAAY,EAAEC,KAAoC,EAAE;MACrEpB,OAAO,CAACmB,IAAI,CAAC,GAAGC,KAAK;IACvB;IAEA,SAASC,GAAGA,CAAIP,IAAO,EAAE;MACvBD,UAAU,CAACb,OAAO,EAAEc,IAAI,EAAE,IAAI,CAAC;MAC/BX,MAAM,CAACkB,GAAG,CAAC,CAAC;IACd;IAEA,OAAO;MACLR,UAAU;MACVK,SAAS;MACTG;IACF,CAAC;EACH;EAEAxB,QAAQ,CAACyB,aAAa,CAAC,aAAa,EAAExB,WAAW,CAAC;AACpD;AAEA,eAAeL,aAAa,CAACG,eAAe,EAAE;EAC5CuB,IAAI,EAAE;AACR,CAAC,CAAC"}
1
+ {"version":3,"file":"multipartPlugin.js","names":["PassThrough","fastifyPlugin","CRLF","BOUNDARY","multipartPlugin","instance","asMultipart","request","headers","accept","undefined","stream","code","header","send","serializeHeaders","Object","keys","map","key","join","writeChunk","data","isLast","chunk","write","setHeader","name","value","end","decorateReply"],"sources":["../../../src/plugins/multipart/multipartPlugin.ts"],"sourcesContent":["import type { IncomingHttpHeaders } from 'node:http';\nimport { PassThrough } from 'node:stream';\nimport type { FastifyInstance, FastifyReply } from 'fastify';\nimport fastifyPlugin from 'fastify-plugin';\nimport type { MultipartHandler } from './types';\n\n/**\n * Implementation is based on:\n * https://github.com/facebook/metro/blob/347b1d7ed87995d7951aaa9fd597c04b06013dac/packages/metro/src/Server/MultipartResponse.js\n */\n\nconst CRLF = '\\r\\n';\nconst BOUNDARY = '3beqjf3apnqeu3h5jqorms4i';\n\nasync function multipartPlugin(instance: FastifyInstance) {\n function asMultipart(this: FastifyReply): MultipartHandler | undefined {\n // We should check if is included in accept or if accept has multipart/* or */*,\n // but React Native will set accept to exactly `multipart/mixed`, so a simple check\n // will suffice.\n if (this.request.headers.accept !== 'multipart/mixed') {\n return undefined;\n }\n\n const headers: IncomingHttpHeaders = {};\n const stream = new PassThrough();\n\n this.code(200)\n .header('Content-Type', `multipart/mixed; boundary=\"${BOUNDARY}\"`)\n .send(stream);\n\n function serializeHeaders(headers: IncomingHttpHeaders) {\n return Object.keys(headers)\n .map((key) => `${key}: ${headers[key]}`)\n .join(CRLF);\n }\n\n function writeChunk<T>(\n headers: IncomingHttpHeaders,\n data: T,\n isLast?: boolean\n ) {\n let chunk = `${CRLF}--${BOUNDARY}${CRLF}`;\n if (headers) {\n chunk += serializeHeaders(headers) + CRLF + CRLF;\n }\n\n if (data) {\n chunk += data;\n }\n\n if (isLast) {\n chunk += `${CRLF}--${BOUNDARY}--${CRLF}`;\n }\n\n stream.write(chunk);\n }\n\n function setHeader(name: string, value: string | string[] | undefined) {\n headers[name] = value;\n }\n\n function end<T>(data: T) {\n writeChunk(headers, data, true);\n stream.end();\n }\n\n return {\n writeChunk,\n setHeader,\n end,\n };\n }\n\n instance.decorateReply('asMultipart', asMultipart);\n}\n\nexport default fastifyPlugin(multipartPlugin, {\n name: 'multipart-plugin',\n});\n"],"mappings":"AACA,SAASA,WAAW,QAAQ,aAAa;AAEzC,OAAOC,aAAa,MAAM,gBAAgB;AAG1C;AACA;AACA;AACA;;AA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C,KAAK;IACvB;IAEA,SAASC,GAAGA,CAAIP,IAAO,EAAE;MACvBD,UAAU,CAACb,OAAO,EAAEc,IAAI,EAAE,IAAI,CAAC;MAC/BX,MAAM,CAACkB,GAAG,CAAC,CAAC;IACd;IAEA,OAAO;MACLR,UAAU;MACVK,SAAS;MACTG;IACF,CAAC;EACH;EAEAxB,QAAQ,CAACyB,aAAa,CAAC,aAAa,EAAExB,WAAW,CAAC;AACpD;AAEA,eAAeL,aAAa,CAACG,eAAe,EAAE;EAC5CuB,IAAI,EAAE;AACR,CAAC,CAAC","ignoreList":[]}
@@ -1,5 +1,4 @@
1
- /// <reference types="node" />
2
- import type { IncomingHttpHeaders } from 'http';
1
+ import type { IncomingHttpHeaders } from 'node:http';
3
2
  export interface MultipartHandler {
4
3
  writeChunk: <T>(headers: IncomingHttpHeaders, data: T, isLast?: boolean) => void;
5
4
  setHeader: (name: string, value: string | string[] | undefined) => void;
@@ -1 +1 @@
1
- {"version":3,"file":"types.js","names":[],"sources":["../../../src/plugins/multipart/types.ts"],"sourcesContent":["import type { IncomingHttpHeaders } from 'http';\n\nexport interface MultipartHandler {\n writeChunk: <T>(\n headers: IncomingHttpHeaders,\n data: T,\n isLast?: boolean\n ) => void;\n setHeader: (name: string, value: string | string[] | undefined) => void;\n end: <T>(data: T) => void;\n}\n\ndeclare module 'fastify' {\n interface FastifyReply {\n asMultipart: () => MultipartHandler | undefined;\n }\n}\n"],"mappings":""}
1
+ {"version":3,"file":"types.js","names":[],"sources":["../../../src/plugins/multipart/types.ts"],"sourcesContent":["import type { IncomingHttpHeaders } from 'node:http';\n\nexport interface MultipartHandler {\n writeChunk: <T>(\n headers: IncomingHttpHeaders,\n data: T,\n isLast?: boolean\n ) => void;\n setHeader: (name: string, value: string | string[] | undefined) => void;\n end: <T>(data: T) => void;\n}\n\ndeclare module 'fastify' {\n interface FastifyReply {\n asMultipart: () => MultipartHandler | undefined;\n }\n}\n"],"mappings":"","ignoreList":[]}
@@ -1,5 +1,5 @@
1
- import { SourceMapConsumer } from 'source-map';
2
1
  import type { FastifyLoggerInstance } from 'fastify';
2
+ import { SourceMapConsumer } from 'source-map';
3
3
  import type { ReactNativeStackFrame, SymbolicatorDelegate, SymbolicatorResults } from './types';
4
4
  /**
5
5
  * Class for transforming stack traces from React Native application with using Source Map.
@@ -1,4 +1,4 @@
1
- import { URL } from 'url';
1
+ import { URL } from 'node:url';
2
2
  import { codeFrameColumns } from '@babel/code-frame';
3
3
  import { SourceMapConsumer } from 'source-map';
4
4
  /**
@@ -28,12 +28,11 @@ export class Symbolicator {
28
28
  const platform = searchParams.get('platform');
29
29
  if (platform) {
30
30
  return platform;
31
- } else {
32
- const [bundleFilename] = pathname.split('/').reverse();
33
- const [, platformOrExtension, extension] = bundleFilename.split('.');
34
- if (extension) {
35
- return platformOrExtension;
36
- }
31
+ }
32
+ const [bundleFilename] = pathname.split('/').reverse();
33
+ const [, platformOrExtension, extension] = bundleFilename.split('.');
34
+ if (extension) {
35
+ return platformOrExtension;
37
36
  }
38
37
  }
39
38
  }
@@ -1 +1 @@
1
- {"version":3,"file":"Symbolicator.js","names":["URL","codeFrameColumns","SourceMapConsumer","Symbolicator","inferPlatformFromStack","stack","frame","file","searchParams","pathname","platform","get","bundleFilename","split","reverse","platformOrExtension","extension","sourceMapConsumerCache","constructor","delegate","process","logger","debug","msg","frames","startsWith","includes","push","processedFrames","fileUrl","rawSourceMap","getSourceMap","sourceMapLength","length","sourceMapConsumer","toString","processedFrame","processFrame","codeFrame","getCodeFrame","key","destroy","lineNumber","column","collapse","consumer","lookup","originalPositionFor","line","bias","LEAST_UPPER_BOUND","source","methodName","name","shouldIncludeFrame","undefined","content","getSource","start","forceColor","location","row","fileName","error","message"],"sources":["../../../src/plugins/symbolicate/Symbolicator.ts"],"sourcesContent":["import { URL } from 'url';\nimport { codeFrameColumns } from '@babel/code-frame';\nimport { SourceMapConsumer } from 'source-map';\nimport type { FastifyLoggerInstance } from 'fastify';\nimport type {\n CodeFrame,\n InputStackFrame,\n ReactNativeStackFrame,\n StackFrame,\n SymbolicatorDelegate,\n SymbolicatorResults,\n} from './types';\n\n/**\n * Class for transforming stack traces from React Native application with using Source Map.\n * Raw stack frames produced by React Native, points to some location from the bundle\n * eg `index.bundle?platform=ios:567:1234`. By using Source Map for that bundle `Symbolicator`\n * produces frames that point to source code inside your project eg `Hello.tsx:10:9`.\n */\nexport class Symbolicator {\n /**\n * Infer platform from stack frames.\n * Usually at least one frame has `file` field with the bundle URL eg:\n * `http://localhost:8081/index.bundle?platform=ios&...`, which can be used to infer platform.\n *\n * @param stack Array of stack frames.\n * @returns Inferred platform or `undefined` if cannot infer.\n */\n static inferPlatformFromStack(stack: ReactNativeStackFrame[]) {\n for (const frame of stack) {\n if (!frame.file) {\n continue;\n }\n\n const { searchParams, pathname } = new URL(frame.file, 'file://');\n const platform = searchParams.get('platform');\n if (platform) {\n return platform;\n } else {\n const [bundleFilename] = pathname.split('/').reverse();\n const [, platformOrExtension, extension] = bundleFilename.split('.');\n if (extension) {\n return platformOrExtension;\n }\n }\n }\n }\n\n /**\n * Cache with initialized `SourceMapConsumer` to improve symbolication performance.\n */\n sourceMapConsumerCache: Record<string, SourceMapConsumer> = {};\n\n /**\n * Constructs new `Symbolicator` instance.\n *\n * @param delegate Delegate instance with symbolication functions.\n */\n constructor(private delegate: SymbolicatorDelegate) {}\n\n /**\n * Process raw React Native stack frames and transform them using Source Maps.\n * Method will try to symbolicate as much data as possible, but if the Source Maps\n * are not available, invalid or the original positions/data is not found in Source Maps,\n * the method will return raw values - the same as supplied with `stack` parameter.\n * For example out of 10 frames, it's possible that only first 7 will be symbolicated and the\n * remaining 3 will be unchanged.\n *\n * @param logger Fastify logger instance.\n * @param stack Raw stack frames.\n * @returns Symbolicated stack frames.\n */\n async process(\n logger: FastifyLoggerInstance,\n stack: ReactNativeStackFrame[]\n ): Promise<SymbolicatorResults> {\n logger.debug({ msg: 'Filtering out unnecessary frames' });\n\n const frames: InputStackFrame[] = [];\n for (const frame of stack) {\n const { file } = frame;\n if (file?.startsWith('http') && !file.includes('debuggerWorker')) {\n frames.push(frame as InputStackFrame);\n }\n }\n\n try {\n logger.debug({ msg: 'Processing frames', frames });\n\n const processedFrames: StackFrame[] = [];\n for (const frame of frames) {\n if (!this.sourceMapConsumerCache[frame.file]) {\n logger.debug({\n msg: 'Loading raw source map data',\n fileUrl: frame.file,\n });\n\n const rawSourceMap = await this.delegate.getSourceMap(frame.file);\n\n logger.debug({\n msg: 'Creating source map instance',\n fileUrl: frame.file,\n sourceMapLength: rawSourceMap.length,\n });\n const sourceMapConsumer = await new SourceMapConsumer(\n rawSourceMap.toString()\n );\n\n logger.debug({\n msg: 'Saving source map instance into cache',\n fileUrl: frame.file,\n });\n this.sourceMapConsumerCache[frame.file] = sourceMapConsumer;\n }\n\n logger.debug({\n msg: 'Symbolicating frame',\n frame,\n });\n const processedFrame = this.processFrame(frame);\n\n logger.debug({\n msg: 'Finished symbolicating frame',\n frame,\n });\n processedFrames.push(processedFrame);\n }\n\n const codeFrame =\n (await this.getCodeFrame(logger, processedFrames)) ?? null;\n\n logger.debug({\n msg: 'Finished symbolicating frames',\n processedFrames,\n codeFrame,\n });\n\n return {\n stack: processedFrames,\n codeFrame,\n };\n } finally {\n for (const key in this.sourceMapConsumerCache) {\n this.sourceMapConsumerCache[key].destroy();\n delete this.sourceMapConsumerCache[key];\n }\n }\n }\n\n private processFrame(frame: InputStackFrame): StackFrame {\n if (!frame.lineNumber || !frame.column) {\n return {\n ...frame,\n collapse: false,\n };\n }\n\n const consumer = this.sourceMapConsumerCache[frame.file];\n if (!consumer) {\n return {\n ...frame,\n collapse: false,\n };\n }\n\n const lookup = consumer.originalPositionFor({\n line: frame.lineNumber,\n column: frame.column,\n bias: SourceMapConsumer.LEAST_UPPER_BOUND,\n });\n\n // If lookup fails, we get the same shape object, but with\n // all values set to null\n if (!lookup.source) {\n // It is better to gracefully return the original frame\n // than to throw an exception\n return {\n ...frame,\n collapse: false,\n };\n }\n\n return {\n lineNumber: lookup.line || frame.lineNumber,\n column: lookup.column || frame.column,\n file: lookup.source,\n methodName: lookup.name || frame.methodName,\n collapse: false,\n };\n }\n\n private async getCodeFrame(\n logger: FastifyLoggerInstance,\n processedFrames: StackFrame[]\n ): Promise<CodeFrame | undefined> {\n for (const frame of processedFrames) {\n if (frame.collapse || !frame.lineNumber || !frame.column) {\n continue;\n }\n\n if (!this.delegate.shouldIncludeFrame(frame)) {\n return undefined;\n }\n\n logger.debug({\n msg: 'Generating code frame',\n frame,\n });\n\n try {\n return {\n content: codeFrameColumns(\n (await this.delegate.getSource(frame.file)).toString(),\n {\n start: { column: frame.column, line: frame.lineNumber },\n },\n { forceColor: true }\n ),\n location: {\n row: frame.lineNumber,\n column: frame.column,\n },\n fileName: frame.file,\n };\n } catch (error) {\n logger.error({\n msg: 'Failed to create code frame',\n error: (error as Error).message,\n });\n }\n\n return undefined;\n }\n }\n}\n"],"mappings":"AAAA,SAASA,GAAG,QAAQ,KAAK;AACzB,SAASC,gBAAgB,QAAQ,mBAAmB;AACpD,SAASC,iBAAiB,QAAQ,YAAY;AAW9C;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,MAAMC,YAAY,CAAC;EACxB;AACF;AACA;AACA;AACA;AACA;AACA;AACA;EACE,OAAOC,sBAAsBA,CAACC,KAA8B,EAAE;IAC5D,KAAK,MAAMC,KAAK,IAAID,KAAK,EAAE;MACzB,IAAI,CAACC,KAAK,CAACC,IAAI,EAAE;QACf;MACF;MAEA,MAAM;QAAEC,YAAY;QAAEC;MAAS,CAAC,GAAG,IAAIT,GAAG,CAACM,KAAK,CAACC,IAAI,EAAE,SAAS,CAAC;MACjE,MAAMG,QAAQ,GAAGF,YAAY,CAACG,GAAG,CAAC,UAAU,CAAC;MAC7C,IAAID,QAAQ,EAAE;QACZ,OAAOA,QAAQ;MACjB,CAAC,MAAM;QACL,MAAM,CAACE,cAAc,CAAC,GAAGH,QAAQ,CAACI,KAAK,CAAC,GAAG,CAAC,CA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B,CAAChD,KAAK,CAAC,EAAE;QAC5C,OAAOiD,SAAS;MAClB;MAEAlC,MAAM,CAACC,KAAK,CAAC;QACXC,GAAG,EAAE,uBAAuB;QAC5BjB;MACF,CAAC,CAAC;MAEF,IAAI;QACF,OAAO;UACLkD,OAAO,EAAEvD,gBAAgB,CACvB,CAAC,MAAM,IAAI,CAACkB,QAAQ,CAACsC,SAAS,CAACnD,KAAK,CAACC,IAAI,CAAC,EAAE4B,QAAQ,CAAC,CAAC,EACtD;YACEuB,KAAK,EAAE;cAAEf,MAAM,EAAErC,KAAK,CAACqC,MAAM;cAAEK,IAAI,EAAE1C,KAAK,CAACoC;YAAW;UACxD,CAAC,EACD;YAAEiB,UAAU,EAAE;UAAK,CACrB,CAAC;UACDC,QAAQ,EAAE;YACRC,GAAG,EAAEvD,KAAK,CAACoC,UAAU;YACrBC,MAAM,EAAErC,KAAK,CAACqC;UAChB,CAAC;UACDmB,QAAQ,EAAExD,KAAK,CAACC;QAClB,CAAC;MACH,CAAC,CAAC,OAAOwD,KAAK,EAAE;QACd1C,MAAM,CAAC0C,KAAK,CAAC;UACXxC,GAAG,EAAE,6BAA6B;UAClCwC,KAAK,EAAGA,KAAK,CAAWC;QAC1B,CAAC,CAAC;MACJ;MAEA,OAAOT,SAAS;IAClB;EACF;AACF"}
1
+ {"version":3,"file":"Symbolicator.js","names":["URL","codeFrameColumns","SourceMapConsumer","Symbolicator","inferPlatformFromStack","stack","frame","file","searchParams","pathname","platform","get","bundleFilename","split","reverse","platformOrExtension","extension","sourceMapConsumerCache","constructor","delegate","process","logger","debug","msg","frames","startsWith","includes","push","processedFrames","fileUrl","rawSourceMap","getSourceMap","sourceMapLength","length","sourceMapConsumer","toString","processedFrame","processFrame","codeFrame","getCodeFrame","key","destroy","lineNumber","column","collapse","consumer","lookup","originalPositionFor","line","bias","LEAST_UPPER_BOUND","source","methodName","name","shouldIncludeFrame","undefined","content","getSource","start","forceColor","location","row","fileName","error","message"],"sources":["../../../src/plugins/symbolicate/Symbolicator.ts"],"sourcesContent":["import { URL } from 'node:url';\nimport { codeFrameColumns } from '@babel/code-frame';\nimport type { FastifyLoggerInstance } from 'fastify';\nimport { SourceMapConsumer } from 'source-map';\nimport type {\n CodeFrame,\n InputStackFrame,\n ReactNativeStackFrame,\n StackFrame,\n SymbolicatorDelegate,\n SymbolicatorResults,\n} from './types';\n\n/**\n * Class for transforming stack traces from React Native application with using Source Map.\n * Raw stack frames produced by React Native, points to some location from the bundle\n * eg `index.bundle?platform=ios:567:1234`. By using Source Map for that bundle `Symbolicator`\n * produces frames that point to source code inside your project eg `Hello.tsx:10:9`.\n */\nexport class Symbolicator {\n /**\n * Infer platform from stack frames.\n * Usually at least one frame has `file` field with the bundle URL eg:\n * `http://localhost:8081/index.bundle?platform=ios&...`, which can be used to infer platform.\n *\n * @param stack Array of stack frames.\n * @returns Inferred platform or `undefined` if cannot infer.\n */\n static inferPlatformFromStack(stack: ReactNativeStackFrame[]) {\n for (const frame of stack) {\n if (!frame.file) {\n continue;\n }\n\n const { searchParams, pathname } = new URL(frame.file, 'file://');\n const platform = searchParams.get('platform');\n if (platform) {\n return platform;\n }\n const [bundleFilename] = pathname.split('/').reverse();\n const [, platformOrExtension, extension] = bundleFilename.split('.');\n if (extension) {\n return platformOrExtension;\n }\n }\n }\n\n /**\n * Cache with initialized `SourceMapConsumer` to improve symbolication performance.\n */\n sourceMapConsumerCache: Record<string, SourceMapConsumer> = {};\n\n /**\n * Constructs new `Symbolicator` instance.\n *\n * @param delegate Delegate instance with symbolication functions.\n */\n constructor(private delegate: SymbolicatorDelegate) {}\n\n /**\n * Process raw React Native stack frames and transform them using Source Maps.\n * Method will try to symbolicate as much data as possible, but if the Source Maps\n * are not available, invalid or the original positions/data is not found in Source Maps,\n * the method will return raw values - the same as supplied with `stack` parameter.\n * For example out of 10 frames, it's possible that only first 7 will be symbolicated and the\n * remaining 3 will be unchanged.\n *\n * @param logger Fastify logger instance.\n * @param stack Raw stack frames.\n * @returns Symbolicated stack frames.\n */\n async process(\n logger: FastifyLoggerInstance,\n stack: ReactNativeStackFrame[]\n ): Promise<SymbolicatorResults> {\n logger.debug({ msg: 'Filtering out unnecessary frames' });\n\n const frames: InputStackFrame[] = [];\n for (const frame of stack) {\n const { file } = frame;\n if (file?.startsWith('http') && !file.includes('debuggerWorker')) {\n frames.push(frame as InputStackFrame);\n }\n }\n\n try {\n logger.debug({ msg: 'Processing frames', frames });\n\n const processedFrames: StackFrame[] = [];\n for (const frame of frames) {\n if (!this.sourceMapConsumerCache[frame.file]) {\n logger.debug({\n msg: 'Loading raw source map data',\n fileUrl: frame.file,\n });\n\n const rawSourceMap = await this.delegate.getSourceMap(frame.file);\n\n logger.debug({\n msg: 'Creating source map instance',\n fileUrl: frame.file,\n sourceMapLength: rawSourceMap.length,\n });\n const sourceMapConsumer = await new SourceMapConsumer(\n rawSourceMap.toString()\n );\n\n logger.debug({\n msg: 'Saving source map instance into cache',\n fileUrl: frame.file,\n });\n this.sourceMapConsumerCache[frame.file] = sourceMapConsumer;\n }\n\n logger.debug({\n msg: 'Symbolicating frame',\n frame,\n });\n const processedFrame = this.processFrame(frame);\n\n logger.debug({\n msg: 'Finished symbolicating frame',\n frame,\n });\n processedFrames.push(processedFrame);\n }\n\n const codeFrame =\n (await this.getCodeFrame(logger, processedFrames)) ?? null;\n\n logger.debug({\n msg: 'Finished symbolicating frames',\n processedFrames,\n codeFrame,\n });\n\n return {\n stack: processedFrames,\n codeFrame,\n };\n } finally {\n for (const key in this.sourceMapConsumerCache) {\n this.sourceMapConsumerCache[key].destroy();\n delete this.sourceMapConsumerCache[key];\n }\n }\n }\n\n private processFrame(frame: InputStackFrame): StackFrame {\n if (!frame.lineNumber || !frame.column) {\n return {\n ...frame,\n collapse: false,\n };\n }\n\n const consumer = this.sourceMapConsumerCache[frame.file];\n if (!consumer) {\n return {\n ...frame,\n collapse: false,\n };\n }\n\n const lookup = consumer.originalPositionFor({\n line: frame.lineNumber,\n column: frame.column,\n bias: SourceMapConsumer.LEAST_UPPER_BOUND,\n });\n\n // If lookup fails, we get the same shape object, but with\n // all values set to null\n if (!lookup.source) {\n // It is better to gracefully return the original frame\n // than to throw an exception\n return {\n ...frame,\n collapse: false,\n };\n }\n\n return {\n lineNumber: lookup.line || frame.lineNumber,\n column: lookup.column || frame.column,\n file: lookup.source,\n methodName: lookup.name || frame.methodName,\n collapse: false,\n };\n }\n\n private async getCodeFrame(\n logger: FastifyLoggerInstance,\n processedFrames: StackFrame[]\n ): Promise<CodeFrame | undefined> {\n for (const frame of processedFrames) {\n if (frame.collapse || !frame.lineNumber || !frame.column) {\n continue;\n }\n\n if (!this.delegate.shouldIncludeFrame(frame)) {\n return undefined;\n }\n\n logger.debug({\n msg: 'Generating code frame',\n frame,\n });\n\n try {\n return {\n content: codeFrameColumns(\n (await this.delegate.getSource(frame.file)).toString(),\n {\n start: { column: frame.column, line: frame.lineNumber },\n },\n { forceColor: true }\n ),\n location: {\n row: frame.lineNumber,\n column: frame.column,\n },\n fileName: frame.file,\n };\n } catch (error) {\n logger.error({\n msg: 'Failed to create code frame',\n error: (error as Error).message,\n });\n }\n\n return undefined;\n }\n }\n}\n"],"mappings":"AAAA,SAASA,GAAG,QAAQ,UAAU;AAC9B,SAASC,gBAAgB,QAAQ,mBAAmB;AAEpD,SAASC,iBAAiB,QAAQ,YAAY;AAU9C;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,MAAMC,YAAY,CAAC;EACxB;AACF;AACA;AACA;AACA;AACA;AACA;AACA;EACE,OAAOC,sBAAsBA,CAACC,KAA8B,EAAE;IAC5D,KAAK,MAAMC,KAAK,IAAID,KAAK,EAAE;MACzB,IAAI,CAACC,KAAK,CAACC,IAAI,EAAE;QACf;MACF;MAEA,MAAM;QAAEC,YAAY;QAAEC;MAAS,CAAC,GAAG,IAAIT,GAAG,CAACM,KAAK,CAACC,IAAI,EAAE,SAAS,CAAC;MACjE,MAAMG,QAAQ,GAAGF,YAAY,CAACG,GAAG,CAAC,UAAU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AI,CAACtC,KAAK,CAACoC,UAAU,IAAI,CAACpC,KAAK,CAACqC,MAAM,EAAE;QACxD;MACF;MAEA,IAAI,CAAC,IAAI,CAACxB,QAAQ,CAACmC,kBAAkB,CAAChD,KAAK,CAAC,EAAE;QAC5C,OAAOiD,SAAS;MAClB;MAEAlC,MAAM,CAACC,KAAK,CAAC;QACXC,GAAG,EAAE,uBAAuB;QAC5BjB;MACF,CAAC,CAAC;MAEF,IAAI;QACF,OAAO;UACLkD,OAAO,EAAEvD,gBAAgB,CACvB,CAAC,MAAM,IAAI,CAACkB,QAAQ,CAACsC,SAAS,CAACnD,KAAK,CAACC,IAAI,CAAC,EAAE4B,QAAQ,CAAC,CAAC,EACtD;YACEuB,KAAK,EAAE;cAAEf,MAAM,EAAErC,KAAK,CAACqC,MAAM;cAAEK,IAAI,EAAE1C,KAAK,CAACoC;YAAW;UACxD,CAAC,EACD;YAAEiB,UAAU,EAAE;UAAK,CACrB,CAAC;UACDC,QAAQ,EAAE;YACRC,GAAG,EAAEvD,KAAK,CAACoC,UAAU;YACrBC,MAAM,EAAErC,KAAK,CAACqC;UAChB,CAAC;UACDmB,QAAQ,EAAExD,KAAK,CAACC;QAClB,CAAC;MACH,CAAC,CAAC,OAAOwD,KAAK,EAAE;QACd1C,MAAM,CAAC0C,KAAK,CAAC;UACXxC,GAAG,EAAE,6BAA6B;UAClCwC,KAAK,EAAGA,KAAK,CAAWC;QAC1B,CAAC,CAAC;MACJ;MAEA,OAAOT,SAAS;IAClB;EACF;AACF","ignoreList":[]}
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":["default"],"sources":["../../../src/plugins/symbolicate/index.ts"],"sourcesContent":["export { default } from './sybmolicatePlugin';\nexport * from './Symbolicator';\nexport * from './types';\n"],"mappings":"SAASA,OAAO;AAAA;AAAA"}
1
+ {"version":3,"file":"index.js","names":["default"],"sources":["../../../src/plugins/symbolicate/index.ts"],"sourcesContent":["export { default } from './sybmolicatePlugin';\nexport * from './Symbolicator';\nexport * from './types';\n"],"mappings":"SAASA,OAAO;AAAA;AAAA","ignoreList":[]}
@@ -1 +1 @@
1
- {"version":3,"file":"sybmolicatePlugin.js","names":["fastifyPlugin","Symbolicator","symbolicatePlugin","instance","delegate","symbolicator","post","request","reply","stack","JSON","parse","body","platform","inferPlatformFromStack","log","debug","msg","badRequest","results","process","send","error","message","internalServerError","name","dependencies"],"sources":["../../../src/plugins/symbolicate/sybmolicatePlugin.ts"],"sourcesContent":["import type { FastifyInstance } from 'fastify';\nimport fastifyPlugin from 'fastify-plugin';\nimport type { Server } from '../../types';\nimport { Symbolicator } from './Symbolicator';\nimport type { ReactNativeStackFrame } from './types';\n\nasync function symbolicatePlugin(\n instance: FastifyInstance,\n {\n delegate,\n }: {\n delegate: Server.Delegate;\n }\n) {\n const symbolicator = new Symbolicator(delegate.symbolicator);\n\n instance.post('/symbolicate', async (request, reply) => {\n // React Native sends stack as JSON but tests content-type to text/plain, so\n // we cannot use JSON schema to validate the body.\n\n try {\n const { stack } = JSON.parse(request.body as string) as {\n stack: ReactNativeStackFrame[];\n };\n const platform = Symbolicator.inferPlatformFromStack(stack);\n if (!platform) {\n request.log.debug({ msg: 'Received stack', stack });\n reply.badRequest('Cannot infer platform from stack trace');\n } else {\n request.log.debug({ msg: 'Starting symbolication', platform, stack });\n const results = await symbolicator.process(request.log, stack);\n reply.send(results);\n }\n } catch (error) {\n request.log.error({\n msg: 'Failed to symbolicate',\n error: (error as Error).message,\n });\n reply.internalServerError();\n }\n });\n}\n\nexport default fastifyPlugin(symbolicatePlugin, {\n name: 'symbolicate-plugin',\n dependencies: ['@fastify/sensible'],\n});\n"],"mappings":"AACA,OAAOA,aAAa,MAAM,gBAAgB;AAAC,SAElCC,YAAY;AAGrB,eAAeC,iBAAiBA,CAC9BC,QAAyB,EACzB;EACEC;AAGF,CAAC,EACD;EACA,MAAMC,YAAY,GAAG,IAAIJ,YAAY,CAACG,QAAQ,CAACC,YAAY,CAAC;EAE5DF,QAAQ,CAACG,IAAI,CAAC,cAAc,EAAE,OAAOC,OAAO,EAAEC,KAAK,KAAK;IACtD;IACA;;IAEA,IAAI;MACF,MAAM;QAAEC;MAAM,CAAC,GAAGC,IAAI,CAACC,KAAK,CAACJ,OAAO,CAACK,IAAc,CAElD;MACD,MAAMC,QAAQ,GAAGZ,YAAY,CAACa,sBAAsB,CAACL,KAAK,CAAC;MAC3D,IAAI,CAACI,QAAQ,EAAE;QACbN,OAAO,CAACQ,GAAG,CAACC,KAAK,CAAC;UAAEC,GAAG,EAAE,gBAAgB;UAAER;QAAM,CAAC,CAAC;QACnDD,KAAK,CAACU,UAAU,CAAC,wCAAwC,CAAC;MAC5D,CAAC,MAAM;QACLX,OAAO,CAACQ,GAAG,CAACC,KAAK,CAAC;UAAEC,GAAG,EAAE,wBAAwB;UAAEJ,QAAQ;UAAEJ;QAAM,CAAC,CAAC;QACrE,MAAMU,OAAO,GAAG,MAAMd,YAAY,CAACe,OAAO,CAACb,OAAO,CAACQ,GAAG,EAAEN,KAAK,CAAC;QAC9DD,KAAK,CAACa,IAAI,CAACF,OAAO,CAAC;MACrB;IACF,CAAC,CAAC,OAAOG,KAAK,EAAE;MACdf,OAAO,CAACQ,GAAG,CAACO,KAAK,CAAC;QAChBL,GAAG,EAAE,uBAAuB;QAC5BK,KAAK,EAAGA,KAAK,CAAWC;MAC1B,CAAC,CAAC;MACFf,KAAK,CAACgB,mBAAmB,CAAC,CAAC;IAC7B;EACF,CAAC,CAAC;AACJ;AAEA,eAAexB,aAAa,CAACE,iBAAiB,EAAE;EAC9CuB,IAAI,EAAE,oBAAoB;EAC1BC,YAAY,EAAE,CAAC,mBAAmB;AACpC,CAAC,CAAC"}
1
+ {"version":3,"file":"sybmolicatePlugin.js","names":["fastifyPlugin","Symbolicator","symbolicatePlugin","instance","delegate","symbolicator","post","request","reply","stack","JSON","parse","body","platform","inferPlatformFromStack","log","debug","msg","badRequest","results","process","send","error","message","internalServerError","name","dependencies"],"sources":["../../../src/plugins/symbolicate/sybmolicatePlugin.ts"],"sourcesContent":["import type { FastifyInstance } from 'fastify';\nimport fastifyPlugin from 'fastify-plugin';\nimport type { Server } from '../../types';\nimport { Symbolicator } from './Symbolicator';\nimport type { ReactNativeStackFrame } from './types';\n\nasync function symbolicatePlugin(\n instance: FastifyInstance,\n {\n delegate,\n }: {\n delegate: Server.Delegate;\n }\n) {\n const symbolicator = new Symbolicator(delegate.symbolicator);\n\n instance.post('/symbolicate', async (request, reply) => {\n // React Native sends stack as JSON but tests content-type to text/plain, so\n // we cannot use JSON schema to validate the body.\n\n try {\n const { stack } = JSON.parse(request.body as string) as {\n stack: ReactNativeStackFrame[];\n };\n const platform = Symbolicator.inferPlatformFromStack(stack);\n if (!platform) {\n request.log.debug({ msg: 'Received stack', stack });\n reply.badRequest('Cannot infer platform from stack trace');\n } else {\n request.log.debug({ msg: 'Starting symbolication', platform, stack });\n const results = await symbolicator.process(request.log, stack);\n reply.send(results);\n }\n } catch (error) {\n request.log.error({\n msg: 'Failed to symbolicate',\n error: (error as Error).message,\n });\n reply.internalServerError();\n }\n });\n}\n\nexport default fastifyPlugin(symbolicatePlugin, {\n name: 'symbolicate-plugin',\n dependencies: ['@fastify/sensible'],\n});\n"],"mappings":"AACA,OAAOA,aAAa,MAAM,gBAAgB;AAAC,SAElCC,YAAY;AAGrB,eAAeC,iBAAiBA,CAC9BC,QAAyB,EACzB;EACEC;AAGF,CAAC,EACD;EACA,MAAMC,YAAY,GAAG,IAAIJ,YAAY,CAACG,QAAQ,CAACC,YAAY,CAAC;EAE5DF,QAAQ,CAACG,IAAI,CAAC,cAAc,EAAE,OAAOC,OAAO,EAAEC,KAAK,KAAK;IACtD;IACA;;IAEA,IAAI;MACF,MAAM;QAAEC;MAAM,CAAC,GAAGC,IAAI,CAACC,KAAK,CAACJ,OAAO,CAACK,IAAc,CAElD;MACD,MAAMC,QAAQ,GAAGZ,YAAY,CAACa,sBAAsB,CAACL,KAAK,CAAC;MAC3D,IAAI,CAACI,QAAQ,EAAE;QACbN,OAAO,CAACQ,GAAG,CAACC,KAAK,CAAC;UAAEC,GAAG,EAAE,gBAAgB;UAAER;QAAM,CAAC,CAAC;QACnDD,KAAK,CAACU,UAAU,CAAC,wCAAwC,CAAC;MAC5D,CAAC,MAAM;QACLX,OAAO,CAACQ,GAAG,CAACC,KAAK,CAAC;UAAEC,GAAG,EAAE,wBAAwB;UAAEJ,QAAQ;UAAEJ;QAAM,CAAC,CAAC;QACrE,MAAMU,OAAO,GAAG,MAAMd,YAAY,CAACe,OAAO,CAACb,OAAO,CAACQ,GAAG,EAAEN,KAAK,CAAC;QAC9DD,KAAK,CAACa,IAAI,CAACF,OAAO,CAAC;MACrB;IACF,CAAC,CAAC,OAAOG,KAAK,EAAE;MACdf,OAAO,CAACQ,GAAG,CAACO,KAAK,CAAC;QAChBL,GAAG,EAAE,uBAAuB;QAC5BK,KAAK,EAAGA,KAAK,CAAWC;MAC1B,CAAC,CAAC;MACFf,KAAK,CAACgB,mBAAmB,CAAC,CAAC;IAC7B;EACF,CAAC,CAAC;AACJ;AAEA,eAAexB,aAAa,CAACE,iBAAiB,EAAE;EAC9CuB,IAAI,EAAE,oBAAoB;EAC1BC,YAAY,EAAE,CAAC,mBAAmB;AACpC,CAAC,CAAC","ignoreList":[]}
@@ -1,4 +1,3 @@
1
- /// <reference types="node" />
2
1
  /**
3
2
  * Raw React Native stack frame.
4
3
  */
@@ -1 +1 @@
1
- {"version":3,"file":"types.js","names":[],"sources":["../../../src/plugins/symbolicate/types.ts"],"sourcesContent":["/**\n * Raw React Native stack frame.\n */\nexport interface ReactNativeStackFrame {\n lineNumber: number | null;\n column: number | null;\n file: string | null;\n methodName: string;\n}\n\n/**\n * React Native stack frame used as input when processing by {@link Symbolicator}.\n */\nexport interface InputStackFrame extends ReactNativeStackFrame {\n file: string;\n}\n\n/**\n * Final symbolicated stack frame.\n */\nexport interface StackFrame extends InputStackFrame {\n collapse: boolean;\n}\n\n/**\n * Represents [@babel/core-frame](https://babeljs.io/docs/en/babel-code-frame).\n */\nexport interface CodeFrame {\n content: string;\n location: {\n row: number;\n column: number;\n };\n fileName: string;\n}\n\n/**\n * Represents results of running {@link process} method on {@link Symbolicator} instance.\n */\nexport interface SymbolicatorResults {\n codeFrame: CodeFrame | null;\n stack: StackFrame[];\n}\n\n/**\n * Delegate with implementation for symbolication functions.\n */\nexport interface SymbolicatorDelegate {\n /**\n * Get source code of file in the URL.\n *\n * @param fileUrl A full URL pointing to a file.\n */\n getSource: (fileUrl: string) => Promise<string | Buffer>;\n\n /**\n * Get source map for the file in the URL.\n *\n * @param fileUrl A full (usually `http:`) URL pointing to a compiled file.\n * The URL points to a file for which to return source map, not to the source map file itself,\n * e.g: `http://localhost:8081/index.bundle?platform=ios`.\n */\n getSourceMap: (fileUrl: string) => Promise<string | Buffer>;\n\n /**\n * Check if given stack frame should be included in the new symbolicated stack.\n *\n * @param frame Stack frame to check.\n */\n shouldIncludeFrame: (frame: StackFrame) => boolean;\n}\n"],"mappings":""}
1
+ {"version":3,"file":"types.js","names":[],"sources":["../../../src/plugins/symbolicate/types.ts"],"sourcesContent":["/**\n * Raw React Native stack frame.\n */\nexport interface ReactNativeStackFrame {\n lineNumber: number | null;\n column: number | null;\n file: string | null;\n methodName: string;\n}\n\n/**\n * React Native stack frame used as input when processing by {@link Symbolicator}.\n */\nexport interface InputStackFrame extends ReactNativeStackFrame {\n file: string;\n}\n\n/**\n * Final symbolicated stack frame.\n */\nexport interface StackFrame extends InputStackFrame {\n collapse: boolean;\n}\n\n/**\n * Represents [@babel/core-frame](https://babeljs.io/docs/en/babel-code-frame).\n */\nexport interface CodeFrame {\n content: string;\n location: {\n row: number;\n column: number;\n };\n fileName: string;\n}\n\n/**\n * Represents results of running {@link process} method on {@link Symbolicator} instance.\n */\nexport interface SymbolicatorResults {\n codeFrame: CodeFrame | null;\n stack: StackFrame[];\n}\n\n/**\n * Delegate with implementation for symbolication functions.\n */\nexport interface SymbolicatorDelegate {\n /**\n * Get source code of file in the URL.\n *\n * @param fileUrl A full URL pointing to a file.\n */\n getSource: (fileUrl: string) => Promise<string | Buffer>;\n\n /**\n * Get source map for the file in the URL.\n *\n * @param fileUrl A full (usually `http:`) URL pointing to a compiled file.\n * The URL points to a file for which to return source map, not to the source map file itself,\n * e.g: `http://localhost:8081/index.bundle?platform=ios`.\n */\n getSourceMap: (fileUrl: string) => Promise<string | Buffer>;\n\n /**\n * Check if given stack frame should be included in the new symbolicated stack.\n *\n * @param frame Stack frame to check.\n */\n shouldIncludeFrame: (frame: StackFrame) => boolean;\n}\n"],"mappings":"","ignoreList":[]}
@@ -1,5 +1,5 @@
1
1
  import type { FastifyInstance } from 'fastify';
2
- import { WebSocketServerInterface } from './types';
2
+ import type { WebSocketServerInterface } from './types';
3
3
  /**
4
4
  * Class for creating a WebSocket router to forward connections to the
5
5
  * respective {@link WebSocketServer} as long as the connection is accepted for the upgrade by the
@@ -1 +1 @@
1
- {"version":3,"file":"WebSocketRouter.js","names":["WebSocketRouter","servers","constructor","fastify","server","on","request","socket","head","pathname","URL","url","matched","shouldUpgrade","upgrade","log","debug","msg","destroy","registerServer","push"],"sources":["../../../src/plugins/wss/WebSocketRouter.ts"],"sourcesContent":["import type { IncomingMessage } from 'node:http';\nimport type { Socket } from 'node:net';\nimport type { FastifyInstance } from 'fastify';\nimport { WebSocketServerInterface } from './types';\n\n/**\n * Class for creating a WebSocket router to forward connections to the\n * respective {@link WebSocketServer} as long as the connection is accepted for the upgrade by the\n * server.\n *\n * If the connection is not accepted by any `WebSocketServer`, it will be destroyed to avoid\n * creating handling connections and potentially throwing `ECONNRESET` errors.\n *\n * @category Development server\n */\nexport class WebSocketRouter {\n /** The list of all register WebSocket servers. */\n protected servers: WebSocketServerInterface[] = [];\n\n /**\n * Create new instance of `WebSocketRouter` and attach it to the given Fastify instance.\n * Any logging information, will be passed through standard `fastify.log` API.\n *\n * @param fastify Fastify instance to attach the WebSocket router to.\n */\n constructor(private fastify: FastifyInstance) {\n this.fastify.server.on(\n 'upgrade',\n (request: IncomingMessage, socket: Socket, head: Buffer) => {\n const { pathname } = new URL(request.url || '', 'http://localhost');\n let matched = false;\n for (const server of this.servers) {\n if (server.shouldUpgrade(pathname)) {\n matched = true;\n server.upgrade(request, socket, head);\n break;\n }\n }\n\n if (!matched) {\n this.fastify.log.debug({\n msg: 'Destroying socket connection as no server was matched',\n pathname,\n });\n socket.destroy();\n }\n }\n );\n }\n\n /**\n * Register a new {@link WebSocketServer}. New connection will now\n * check if the given server will accept them and forward them.\n *\n * @param server WebSocket server to register.\n * @returns The same instance of the WebSocket server after it's been registered.\n */\n registerServer<T extends WebSocketServerInterface>(server: T): T {\n this.servers.push(server);\n return server;\n }\n}\n"],"mappings":"AAKA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,MAAMA,eAAe,CAAC;EAC3B;EACUC,OAAO,GAA+B,EAAE;;EAElD;AACF;AACA;AACA;AACA;AACA;EACEC,WAAWA,CAASC,OAAwB,EAAE;IAAA,KAA1BA,OAAwB,GAAxBA,OAAwB;IAC1C,IAAI,CAACA,OAAO,CAACC,MAAM,CAACC,EAAE,CACpB,SAAS,EACT,CAACC,OAAwB,EAAEC,MAAc,EAAEC,IAAY,KAAK;MAC1D,MAAM;QAAEC;MAAS,CAAC,GAAG,IAAIC,GAAG,CAACJ,OAAO,CAACK,GAAG,IAAI,EAAE,EAAE,kBAAkB,CAAC;MACnE,IAAIC,OAAO,GAAG,KAAK;MACnB,KAAK,MAAMR,MAAM,IAAI,IAAI,CAACH,OAAO,EAAE;QACjC,IAAIG,MAAM,CAACS,aAAa,CAACJ,QAAQ,CAAC,EAAE;UAClCG,OAAO,GAAG,IAAI;UACdR,MAAM,CAACU,OAAO,CAACR,OAAO,EAAEC,MAAM,EAAEC,IAAI,CAAC;UACrC;QACF;MACF;MAEA,IAAI,CAACI,OAAO,EAAE;QACZ,IAAI,CAACT,OAAO,CAACY,GAAG,CAACC,KAAK,CAAC;UACrBC,GAAG,EAAE,uDAAuD;UAC5DR;QACF,CAAC,CAAC;QACFF,MAAM,CAACW,OAAO,CAAC,CAAC;MAClB;IACF,CACF,CAAC;EACH;;EAEA;AACF;AACA;AACA;AACA;AACA;AACA;EACEC,cAAcA,CAAqCf,MAAS,EAAK;IAC/D,IAAI,CAACH,OAAO,CAACmB,IAAI,CAAChB,MAAM,CAAC;IACzB,OAAOA,MAAM;EACf;AACF"}
1
+ {"version":3,"file":"WebSocketRouter.js","names":["WebSocketRouter","servers","constructor","fastify","server","on","request","socket","head","pathname","URL","url","matched","shouldUpgrade","upgrade","log","debug","msg","destroy","registerServer","push"],"sources":["../../../src/plugins/wss/WebSocketRouter.ts"],"sourcesContent":["import type { IncomingMessage } from 'node:http';\nimport type { Socket } from 'node:net';\nimport type { FastifyInstance } from 'fastify';\nimport type { WebSocketServerInterface } from './types';\n\n/**\n * Class for creating a WebSocket router to forward connections to the\n * respective {@link WebSocketServer} as long as the connection is accepted for the upgrade by the\n * server.\n *\n * If the connection is not accepted by any `WebSocketServer`, it will be destroyed to avoid\n * creating handling connections and potentially throwing `ECONNRESET` errors.\n *\n * @category Development server\n */\nexport class WebSocketRouter {\n /** The list of all register WebSocket servers. */\n protected servers: WebSocketServerInterface[] = [];\n\n /**\n * Create new instance of `WebSocketRouter` and attach it to the given Fastify instance.\n * Any logging information, will be passed through standard `fastify.log` API.\n *\n * @param fastify Fastify instance to attach the WebSocket router to.\n */\n constructor(private fastify: FastifyInstance) {\n this.fastify.server.on(\n 'upgrade',\n (request: IncomingMessage, socket: Socket, head: Buffer) => {\n const { pathname } = new URL(request.url || '', 'http://localhost');\n let matched = false;\n for (const server of this.servers) {\n if (server.shouldUpgrade(pathname)) {\n matched = true;\n server.upgrade(request, socket, head);\n break;\n }\n }\n\n if (!matched) {\n this.fastify.log.debug({\n msg: 'Destroying socket connection as no server was matched',\n pathname,\n });\n socket.destroy();\n }\n }\n );\n }\n\n /**\n * Register a new {@link WebSocketServer}. New connection will now\n * check if the given server will accept them and forward them.\n *\n * @param server WebSocket server to register.\n * @returns The same instance of the WebSocket server after it's been registered.\n */\n registerServer<T extends WebSocketServerInterface>(server: T): T {\n this.servers.push(server);\n return server;\n }\n}\n"],"mappings":"AAKA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,MAAMA,eAAe,CAAC;EAC3B;EACUC,OAAO,GAA+B,EAAE;;EAElD;AACF;AACA;AACA;AACA;AACA;EACEC,WAAWA,CAASC,OAAwB,EAAE;IAAA,KAA1BA,OAAwB,GAAxBA,OAAwB;IAC1C,IAAI,CAACA,OAAO,CAACC,MAAM,CAACC,EAAE,CACpB,SAAS,EACT,CAACC,OAAwB,EAAEC,MAAc,EAAEC,IAAY,KAAK;MAC1D,MAAM;QAAEC;MAAS,CAAC,GAAG,IAAIC,GAAG,CAACJ,OAAO,CAACK,GAAG,IAAI,EAAE,EAAE,kBAAkB,CAAC;MACnE,IAAIC,OAAO,GAAG,KAAK;MACnB,KAAK,MAAMR,MAAM,IAAI,IAAI,CAACH,OAAO,EAAE;QACjC,IAAIG,MAAM,CAACS,aAAa,CAACJ,QAAQ,CAAC,EAAE;UAClCG,OAAO,GAAG,IAAI;UACdR,MAAM,CAACU,OAAO,CAACR,OAAO,EAAEC,MAAM,EAAEC,IAAI,CAAC;UACrC;QACF;MACF;MAEA,IAAI,CAACI,OAAO,EAAE;QACZ,IAAI,CAACT,OAAO,CAACY,GAAG,CAACC,KAAK,CAAC;UACrBC,GAAG,EAAE,uDAAuD;UAC5DR;QACF,CAAC,CAAC;QACFF,MAAM,CAACW,OAAO,CAAC,CAAC;MAClB;IACF,CACF,CAAC;EACH;;EAEA;AACF;AACA;AACA;AACA;AACA;AACA;EACEC,cAAcA,CAAqCf,MAAS,EAAK;IAC/D,IAAI,CAACH,OAAO,CAACmB,IAAI,CAAChB,MAAM,CAAC;IACzB,OAAOA,MAAM;EACf;AACF","ignoreList":[]}