@callstack/repack-dev-server 1.1.0 → 4.0.0-rc.1

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 (82) hide show
  1. package/CHANGELOG.md +16 -0
  2. package/LICENSE +21 -0
  3. package/dist/createServer.d.ts +1 -1
  4. package/dist/createServer.js +15 -17
  5. package/dist/createServer.js.map +1 -1
  6. package/dist/plugins/api/apiPlugin.js +3 -9
  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.d.ts +4 -3
  10. package/dist/plugins/compiler/compilerPlugin.js +8 -18
  11. package/dist/plugins/compiler/compilerPlugin.js.map +1 -1
  12. package/dist/plugins/compiler/index.js.map +1 -1
  13. package/dist/plugins/devtools/devtoolsPlugin.d.ts +4 -3
  14. package/dist/plugins/devtools/devtoolsPlugin.js +6 -8
  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.d.ts +3 -2
  18. package/dist/plugins/favicon/faviconPlugin.js +7 -5
  19. package/dist/plugins/favicon/faviconPlugin.js.map +1 -1
  20. package/dist/plugins/favicon/index.js.map +1 -1
  21. package/dist/plugins/multipart/index.js.map +1 -1
  22. package/dist/plugins/multipart/multipartPlugin.d.ts +3 -2
  23. package/dist/plugins/multipart/multipartPlugin.js +1 -14
  24. package/dist/plugins/multipart/multipartPlugin.js.map +1 -1
  25. package/dist/plugins/symbolicate/Symbolicator.js +13 -32
  26. package/dist/plugins/symbolicate/Symbolicator.js.map +1 -1
  27. package/dist/plugins/symbolicate/index.js.map +1 -1
  28. package/dist/plugins/symbolicate/sybmolicatePlugin.d.ts +4 -3
  29. package/dist/plugins/symbolicate/sybmolicatePlugin.js +2 -4
  30. package/dist/plugins/symbolicate/sybmolicatePlugin.js.map +1 -1
  31. package/dist/plugins/wss/WebSocketRouter.js +2 -6
  32. package/dist/plugins/wss/WebSocketRouter.js.map +1 -1
  33. package/dist/plugins/wss/WebSocketServer.js +2 -5
  34. package/dist/plugins/wss/WebSocketServer.js.map +1 -1
  35. package/dist/plugins/wss/index.js.map +1 -1
  36. package/dist/plugins/wss/servers/HermesInspectorProxy.js +1 -19
  37. package/dist/plugins/wss/servers/HermesInspectorProxy.js.map +1 -1
  38. package/dist/plugins/wss/servers/WebSocketApiServer.js +5 -11
  39. package/dist/plugins/wss/servers/WebSocketApiServer.js.map +1 -1
  40. package/dist/plugins/wss/servers/WebSocketDebuggerServer.js +6 -20
  41. package/dist/plugins/wss/servers/WebSocketDebuggerServer.js.map +1 -1
  42. package/dist/plugins/wss/servers/WebSocketDevClientServer.js +3 -12
  43. package/dist/plugins/wss/servers/WebSocketDevClientServer.js.map +1 -1
  44. package/dist/plugins/wss/servers/WebSocketEventsServer.js +18 -25
  45. package/dist/plugins/wss/servers/WebSocketEventsServer.js.map +1 -1
  46. package/dist/plugins/wss/servers/WebSocketHMRServer.js +3 -13
  47. package/dist/plugins/wss/servers/WebSocketHMRServer.js.map +1 -1
  48. package/dist/plugins/wss/servers/WebSocketMessageServer.d.ts +1 -1
  49. package/dist/plugins/wss/servers/WebSocketMessageServer.js +21 -51
  50. package/dist/plugins/wss/servers/WebSocketMessageServer.js.map +1 -1
  51. package/dist/plugins/wss/wssPlugin.d.ts +4 -3
  52. package/dist/plugins/wss/wssPlugin.js +0 -2
  53. package/dist/plugins/wss/wssPlugin.js.map +1 -1
  54. package/dist/types.d.ts +1 -1
  55. package/dist/types.js +9 -34
  56. package/dist/types.js.map +1 -1
  57. package/package.json +26 -29
  58. package/docs/README.md +0 -28
  59. package/docs/enums/Internal.EventTypes.md +0 -41
  60. package/docs/functions/createServer.md +0 -21
  61. package/docs/interfaces/CodeFrame.md +0 -48
  62. package/docs/interfaces/CompilerDelegate.md +0 -83
  63. package/docs/interfaces/HmrDelegate.md +0 -51
  64. package/docs/interfaces/InputStackFrame.md +0 -76
  65. package/docs/interfaces/ProgressData.md +0 -34
  66. package/docs/interfaces/ReactNativeStackFrame.md +0 -58
  67. package/docs/interfaces/Server.Api.Asset.md +0 -36
  68. package/docs/interfaces/Server.Api.CompilationStats.md +0 -9
  69. package/docs/interfaces/Server.Api.Delegate.md +0 -75
  70. package/docs/interfaces/Server.Config.md +0 -49
  71. package/docs/interfaces/Server.Delegate.md +0 -88
  72. package/docs/interfaces/Server.DelegateContext.md +0 -134
  73. package/docs/interfaces/Server.LoggerDelegate.md +0 -33
  74. package/docs/interfaces/Server.MessagesDelegate.md +0 -44
  75. package/docs/interfaces/Server.Options.md +0 -70
  76. package/docs/interfaces/StackFrame.md +0 -85
  77. package/docs/interfaces/SymbolicatorDelegate.md +0 -77
  78. package/docs/interfaces/SymbolicatorResults.md +0 -30
  79. package/docs/modules/Internal.md +0 -11
  80. package/docs/modules/Server.Api.md +0 -11
  81. package/docs/modules/Server.md +0 -16
  82. package/docs/types/SendProgress.md +0 -26
@@ -1,13 +1,12 @@
1
1
  import { PassThrough } from 'stream';
2
2
  import fastifyPlugin from 'fastify-plugin';
3
-
4
3
  /**
5
4
  * Implementation is based on:
6
5
  * https://github.com/facebook/metro/blob/347b1d7ed87995d7951aaa9fd597c04b06013dac/packages/metro/src/Server/MultipartResponse.js
7
6
  */
7
+
8
8
  const CRLF = '\r\n';
9
9
  const BOUNDARY = '3beqjf3apnqeu3h5jqorms4i';
10
-
11
10
  async function multipartPlugin(instance) {
12
11
  function asMultipart() {
13
12
  // We should check if is included in accept or if accept has multipart/* or */*,
@@ -16,52 +15,40 @@ async function multipartPlugin(instance) {
16
15
  if (this.request.headers.accept !== 'multipart/mixed') {
17
16
  return undefined;
18
17
  }
19
-
20
18
  const headers = {};
21
19
  const stream = new PassThrough();
22
20
  this.code(200).header('Content-Type', `multipart/mixed; boundary="${BOUNDARY}"`).send(stream);
23
-
24
21
  function serializeHeaders(headers) {
25
22
  return Object.keys(headers).map(key => `${key}: ${headers[key]}`).join(CRLF);
26
23
  }
27
-
28
24
  function writeChunk(headers, data, isLast) {
29
25
  let chunk = `${CRLF}--${BOUNDARY}${CRLF}`;
30
-
31
26
  if (headers) {
32
27
  chunk += serializeHeaders(headers) + CRLF + CRLF;
33
28
  }
34
-
35
29
  if (data) {
36
30
  chunk += data;
37
31
  }
38
-
39
32
  if (isLast) {
40
33
  chunk += `${CRLF}--${BOUNDARY}--${CRLF}`;
41
34
  }
42
-
43
35
  stream.write(chunk);
44
36
  }
45
-
46
37
  function setHeader(name, value) {
47
38
  headers[name] = value;
48
39
  }
49
-
50
40
  function end(data) {
51
41
  writeChunk(headers, data, true);
52
42
  stream.end();
53
43
  }
54
-
55
44
  return {
56
45
  writeChunk,
57
46
  setHeader,
58
47
  end
59
48
  };
60
49
  }
61
-
62
50
  instance.decorateReply('asMultipart', asMultipart);
63
51
  }
64
-
65
52
  export default fastifyPlugin(multipartPlugin, {
66
53
  name: 'multipart-plugin'
67
54
  });
@@ -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,WAAT,QAA4B,QAA5B;AAEA,OAAOC,aAAP,MAA0B,gBAA1B;;AAGA;AACA;AACA;AACA;AAEA,MAAMC,IAAI,GAAG,MAAb;AACA,MAAMC,QAAQ,GAAG,0BAAjB;;AAEA,eAAeC,eAAf,CAA+BC,QAA/B,EAA0D;EACxD,SAASC,WAAT,GAAuE;IACrE;IACA;IACA;IACA,IAAI,KAAKC,OAAL,CAAaC,OAAb,CAAqBC,MAArB,KAAgC,iBAApC,EAAuD;MACrD,OAAOC,SAAP;IACD;;IAED,MAAMF,OAA4B,GAAG,EAArC;IACA,MAAMG,MAAM,GAAG,IAAIX,WAAJ,EAAf;IAEA,KAAKY,IAAL,CAAU,GAAV,EACGC,MADH,CACU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Plugin","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,7 +1,6 @@
1
1
  import { URL } from 'url';
2
2
  import { codeFrameColumns } from '@babel/code-frame';
3
3
  import { SourceMapConsumer } from 'source-map';
4
-
5
4
  /**
6
5
  * Class for transforming stack traces from React Native application with using Source Map.
7
6
  * Raw stack frames produced by React Native, points to some location from the bundle
@@ -22,40 +21,37 @@ export class Symbolicator {
22
21
  if (!frame.file) {
23
22
  return;
24
23
  }
25
-
26
24
  const {
27
25
  searchParams,
28
26
  pathname
29
27
  } = new URL(frame.file, 'file://');
30
28
  const platform = searchParams.get('platform');
31
-
32
29
  if (platform) {
33
30
  return platform;
34
31
  } else {
35
32
  const [bundleFilename] = pathname.split('/').reverse();
36
33
  const [, platformOrExtension, extension] = bundleFilename.split('.');
37
-
38
34
  if (extension) {
39
35
  return platformOrExtension;
40
36
  }
41
37
  }
42
38
  }
43
39
  }
40
+
44
41
  /**
45
42
  * Cache with initialized `SourceMapConsumer` to improve symbolication performance.
46
43
  */
47
-
48
-
49
44
  sourceMapConsumerCache = {};
45
+
50
46
  /**
51
47
  * Constructs new `Symbolicator` instance.
52
48
  *
53
49
  * @param delegate Delegate instance with symbolication functions.
54
50
  */
55
-
56
51
  constructor(delegate) {
57
52
  this.delegate = delegate;
58
53
  }
54
+
59
55
  /**
60
56
  * Process raw React Native stack frames and transform them using Source Maps.
61
57
  * Method will try to symbolicate as much data as possible, but if the Source Maps
@@ -68,31 +64,25 @@ export class Symbolicator {
68
64
  * @param stack Raw stack frames.
69
65
  * @returns Symbolicated stack frames.
70
66
  */
71
-
72
-
73
67
  async process(logger, stack) {
74
68
  logger.debug({
75
69
  msg: 'Filtering out unnecessary frames'
76
70
  });
77
71
  const frames = [];
78
-
79
72
  for (const frame of stack) {
80
73
  const {
81
74
  file
82
75
  } = frame;
83
-
84
- if (file !== null && file !== void 0 && file.startsWith('http') && !file.includes('debuggerWorker')) {
76
+ if (file?.startsWith('http') && !file.includes('debuggerWorker')) {
85
77
  frames.push(frame);
86
78
  }
87
79
  }
88
-
89
80
  try {
90
81
  logger.debug({
91
82
  msg: 'Processing frames',
92
83
  frames
93
84
  });
94
85
  const processedFrames = [];
95
-
96
86
  for (const frame of frames) {
97
87
  if (!this.sourceMapConsumerCache[frame.file]) {
98
88
  logger.debug({
@@ -112,7 +102,6 @@ export class Symbolicator {
112
102
  });
113
103
  this.sourceMapConsumerCache[frame.file] = sourceMapConsumer;
114
104
  }
115
-
116
105
  logger.debug({
117
106
  msg: 'Symbolicating frame',
118
107
  frame
@@ -124,7 +113,6 @@ export class Symbolicator {
124
113
  });
125
114
  processedFrames.push(processedFrame);
126
115
  }
127
-
128
116
  const codeFrame = (await this.getCodeFrame(logger, processedFrames)) ?? null;
129
117
  logger.debug({
130
118
  msg: 'Finished symbolicating frames',
@@ -142,36 +130,35 @@ export class Symbolicator {
142
130
  }
143
131
  }
144
132
  }
145
-
146
133
  processFrame(frame) {
147
134
  if (!frame.lineNumber || !frame.column) {
148
- return { ...frame,
135
+ return {
136
+ ...frame,
149
137
  collapse: false
150
138
  };
151
139
  }
152
-
153
140
  const consumer = this.sourceMapConsumerCache[frame.file];
154
-
155
141
  if (!consumer) {
156
- return { ...frame,
142
+ return {
143
+ ...frame,
157
144
  collapse: false
158
145
  };
159
146
  }
160
-
161
147
  const lookup = consumer.originalPositionFor({
162
148
  line: frame.lineNumber,
163
149
  column: frame.column
164
- }); // If lookup fails, we get the same shape object, but with
165
- // all values set to null
150
+ });
166
151
 
152
+ // If lookup fails, we get the same shape object, but with
153
+ // all values set to null
167
154
  if (!lookup.source) {
168
155
  // It is better to gracefully return the original frame
169
156
  // than to throw an exception
170
- return { ...frame,
157
+ return {
158
+ ...frame,
171
159
  collapse: false
172
160
  };
173
161
  }
174
-
175
162
  return {
176
163
  lineNumber: lookup.line || frame.lineNumber,
177
164
  column: lookup.column || frame.column,
@@ -180,22 +167,18 @@ export class Symbolicator {
180
167
  collapse: false
181
168
  };
182
169
  }
183
-
184
170
  async getCodeFrame(logger, processedFrames) {
185
171
  for (const frame of processedFrames) {
186
172
  if (frame.collapse || !frame.lineNumber || !frame.column) {
187
173
  continue;
188
174
  }
189
-
190
175
  if (!this.delegate.shouldIncludeFrame(frame)) {
191
176
  return undefined;
192
177
  }
193
-
194
178
  logger.debug({
195
179
  msg: 'Generating code frame',
196
180
  frame
197
181
  });
198
-
199
182
  try {
200
183
  return {
201
184
  content: codeFrameColumns((await this.delegate.getSource(frame.file)).toString(), {
@@ -218,10 +201,8 @@ export class Symbolicator {
218
201
  error: error.message
219
202
  });
220
203
  }
221
-
222
204
  return undefined;
223
205
  }
224
206
  }
225
-
226
207
  }
227
208
  //# sourceMappingURL=Symbolicator.js.map
@@ -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","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 return;\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 });\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,GAAT,QAAoB,KAApB;AACA,SAASC,gBAAT,QAAiC,mBAAjC;AACA,SAASC,iBAAT,QAAkC,YAAlC;;AAWA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,MAAMC,YAAN,CAAmB;EACxB;AACF;AACA;AACA;AACA;AACA;AACA;AACA;EAC+B,OAAtBC,sBAAsB,CAACC,KAAD,EAAiC;IAC5D,KAAK,MAAMC,KAAX,IAAoBD,KAApB,EAA2B;MACzB,IAAI,CAACC,KAAK,CAACC,IAAX,EAAiB;QACf;MACD;;MAED,MAAM;QAAEC,YAAF;QAAgBC;MAAhB,IAA6B,IAAIT,GAAJ,CAAQM,KAAK,CAACC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,KAAK,CAACoC,UAAzB,IAAuC,CAACpC,KAAK,CAACqC,MAAlD,EAA0D;QACxD;MACD;;MAED,IAAI,CAAC,KAAKxB,QAAL,CAAciC,kBAAd,CAAiC9C,KAAjC,CAAL,EAA8C;QAC5C,OAAO+C,SAAP;MACD;;MAEDhC,MAAM,CAACC,KAAP,CAAa;QACXC,GAAG,EAAE,uBADM;QAEXjB;MAFW,CAAb;;MAKA,IAAI;QACF,OAAO;UACLgD,OAAO,EAAErD,gBAAgB,CACvB,CAAC,MAAM,KAAKkB,QAAL,CAAcoC,SAAd,CAAwBjD,KAAK,CAACC,IAA9B,CAAP,EAA4C4B,QAA5C,EADuB,EAEvB;YACEqB,KAAK,EAAE;cAAEb,MAAM,EAAErC,KAAK,CAACqC,MAAhB;cAAwBK,IAAI,EAAE1C,KAAK,CAACoC;YAApC;UADT,CAFuB,EAKvB;YAAEe,UAAU,EAAE;UAAd,CALuB,CADpB;UAQLC,QAAQ,EAAE;YACRC,GAAG,EAAErD,KAAK,CAACoC,UADH;YAERC,MAAM,EAAErC,KAAK,CAACqC;UAFN,CARL;UAYLiB,QAAQ,EAAEtD,KAAK,CAACC;QAZX,CAAP;MAcD,CAfD,CAeE,OAAOsD,KAAP,EAAc;QACdxC,MAAM,CAACwC,KAAP,CAAa;UACXtC,GAAG,EAAE,6BADM;UAEXsC,KAAK,EAAGA,KAAD,CAAiBC;QAFb,CAAb;MAID;;MAED,OAAOT,SAAP;IACD;EACF;;AArNuB"}
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","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 return;\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 });\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,MA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AK,CAACsC,QAAQ,IAAI,CAACtC,KAAK,CAACoC,UAAU,IAAI,CAACpC,KAAK,CAACqC,MAAM,EAAE;QACxD;MACF;MAEA,IAAI,CAAC,IAAI,CAACxB,QAAQ,CAACiC,kBAAkB,CAAC9C,KAAK,CAAC,EAAE;QAC5C,OAAO+C,SAAS;MAClB;MAEAhC,MAAM,CAACC,KAAK,CAAC;QACXC,GAAG,EAAE,uBAAuB;QAC5BjB;MACF,CAAC,CAAC;MAEF,IAAI;QACF,OAAO;UACLgD,OAAO,EAAErD,gBAAgB,CACvB,CAAC,MAAM,IAAI,CAACkB,QAAQ,CAACoC,SAAS,CAACjD,KAAK,CAACC,IAAI,CAAC,EAAE4B,QAAQ,CAAC,CAAC,EACtD;YACEqB,KAAK,EAAE;cAAEb,MAAM,EAAErC,KAAK,CAACqC,MAAM;cAAEK,IAAI,EAAE1C,KAAK,CAACoC;YAAW;UACxD,CAAC,EACD;YAAEe,UAAU,EAAE;UAAK,CACrB,CAAC;UACDC,QAAQ,EAAE;YACRC,GAAG,EAAErD,KAAK,CAACoC,UAAU;YACrBC,MAAM,EAAErC,KAAK,CAACqC;UAChB,CAAC;UACDiB,QAAQ,EAAEtD,KAAK,CAACC;QAClB,CAAC;MACH,CAAC,CAAC,OAAOsD,KAAK,EAAE;QACdxC,MAAM,CAACwC,KAAK,CAAC;UACXtC,GAAG,EAAE,6BAA6B;UAClCsC,KAAK,EAAGA,KAAK,CAAWC;QAC1B,CAAC,CAAC;MACJ;MAEA,OAAOT,SAAS;IAClB;EACF;AACF"}
@@ -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,O"}
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,6 +1,7 @@
1
- /// <reference types="node" />
1
+ import type { FastifyInstance } from 'fastify';
2
2
  import type { Server } from '../../types';
3
- declare const _default: import("fastify").FastifyPluginAsync<{
3
+ declare function symbolicatePlugin(instance: FastifyInstance, { delegate, }: {
4
4
  delegate: Server.Delegate;
5
- }, import("http").Server>;
5
+ }): Promise<void>;
6
+ declare const _default: typeof symbolicatePlugin;
6
7
  export default _default;
@@ -1,6 +1,5 @@
1
1
  import fastifyPlugin from 'fastify-plugin';
2
2
  import { Symbolicator } from "./Symbolicator.js";
3
-
4
3
  async function symbolicatePlugin(instance, {
5
4
  delegate
6
5
  }) {
@@ -8,12 +7,12 @@ async function symbolicatePlugin(instance, {
8
7
  instance.post('/symbolicate', async (request, reply) => {
9
8
  // React Native sends stack as JSON but tests content-type to text/plain, so
10
9
  // we cannot use JSON schema to validate the body.
10
+
11
11
  try {
12
12
  const {
13
13
  stack
14
14
  } = JSON.parse(request.body);
15
15
  const platform = Symbolicator.inferPlatformFromStack(stack);
16
-
17
16
  if (!platform) {
18
17
  request.log.debug({
19
18
  msg: 'Received stack',
@@ -38,9 +37,8 @@ async function symbolicatePlugin(instance, {
38
37
  }
39
38
  });
40
39
  }
41
-
42
40
  export default fastifyPlugin(symbolicatePlugin, {
43
41
  name: 'symbolicate-plugin',
44
- dependencies: ['fastify-sensible']
42
+ dependencies: ['@fastify/sensible']
45
43
  });
46
44
  //# sourceMappingURL=sybmolicatePlugin.js.map
@@ -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,aAAP,MAA0B,gBAA1B;SAESC,Y;;AAGT,eAAeC,iBAAf,CACEC,QADF,EAEE;EACEC;AADF,CAFF,EAOE;EACA,MAAMC,YAAY,GAAG,IAAIJ,YAAJ,CAAiBG,QAAQ,CAACC,YAA1B,CAArB;EAEAF,QAAQ,CAACG,IAAT,CAAc,cAAd,EAA8B,OAAOC,OAAP,EAAgBC,KAAhB,KAA0B;IACtD;IACA;IAEA,IAAI;MACF,MAAM;QAAEC;MAAF,IAAYC,IAAI,CAACC,KAAL,CAAWJ,OAAO,CAACK,IAAnB,CAAlB;MAGA,MAAMC,QAAQ,GAAGZ,YAAY,CAACa,sBAAb,CAAoCL,KAApC,CAAjB;;MACA,IAAI,CAACI,QAAL,EAAe;QACbN,OAAO,CAACQ,GAAR,CAAYC,KAAZ,CAAkB;UAAEC,GAAG,EAAE,gBAAP;UAAyBR;QAAzB,CAAlB;QACAD,KAAK,CAACU,UAAN,CAAiB,wCAAjB;MACD,CAHD,MAGO;QACLX,OAAO,CAACQ,GAAR,CAAYC,KAAZ,CAAkB;UAAEC,GAAG,EAAE,wBAAP;UAAiCJ,QAAjC;UAA2CJ;QAA3C,CAAlB;QACA,MAAMU,OAAO,GAAG,MAAMd,YAAY,CAACe,OAAb,CAAqBb,OAAO,CAACQ,GAA7B,EAAkCN,KAAlC,CAAtB;QACAD,KAAK,CAACa,IAAN,CAAWF,OAAX;MACD;IACF,CAbD,CAaE,OAAOG,KAAP,EAAc;MACdf,OAAO,CAACQ,GAAR,CAAYO,KAAZ,CAAkB;QAChBL,GAAG,EAAE,uBADW;QAEhBK,KAAK,EAAGA,KAAD,CAAiBC;MAFR,CAAlB;MAIAf,KAAK,CAACgB,mBAAN;IACD;EACF,CAxBD;AAyBD;;AAED,eAAexB,aAAa,CAACE,iBAAD,EAAoB;EAC9CuB,IAAI,EAAE,oBADwC;EAE9CC,YAAY,EAAE,CAAC,kBAAD;AAFgC,CAApB,CAA5B"}
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"}
@@ -11,13 +11,13 @@
11
11
  export class WebSocketRouter {
12
12
  /** The list of all register WebSocket servers. */
13
13
  servers = [];
14
+
14
15
  /**
15
16
  * Create new instance of `WebSocketRouter` and attach it to the given Fastify instance.
16
17
  * Any logging information, will be passed through standard `fastify.log` API.
17
18
  *
18
19
  * @param fastify Fastify instance to attach the WebSocket router to.
19
20
  */
20
-
21
21
  constructor(fastify) {
22
22
  this.fastify = fastify;
23
23
  this.fastify.server.on('upgrade', (request, socket, head) => {
@@ -25,7 +25,6 @@ export class WebSocketRouter {
25
25
  pathname
26
26
  } = new URL(request.url || '', 'http://localhost');
27
27
  let matched = false;
28
-
29
28
  for (const server of this.servers) {
30
29
  if (server.shouldUpgrade(pathname)) {
31
30
  matched = true;
@@ -33,7 +32,6 @@ export class WebSocketRouter {
33
32
  break;
34
33
  }
35
34
  }
36
-
37
35
  if (!matched) {
38
36
  this.fastify.log.debug({
39
37
  msg: 'Destroying socket connection as no server was matched',
@@ -43,6 +41,7 @@ export class WebSocketRouter {
43
41
  }
44
42
  });
45
43
  }
44
+
46
45
  /**
47
46
  * Register a new {@link WebSocketServer}. New connection will now
48
47
  * check if the given server will accept them and forward them.
@@ -50,12 +49,9 @@ export class WebSocketRouter {
50
49
  * @param server WebSocket server to register.
51
50
  * @returns The same instance of the WebSocket server after it's been registered.
52
51
  */
53
-
54
-
55
52
  registerServer(server) {
56
53
  this.servers.push(server);
57
54
  return server;
58
55
  }
59
-
60
56
  }
61
57
  //# sourceMappingURL=WebSocketRouter.js.map
@@ -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 'http';\nimport type { Socket } from 'net';\nimport type { FastifyInstance } from 'fastify';\nimport { WebSocketServer } from './WebSocketServer';\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: WebSocketServer[] = [];\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 WebSocketServer>(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,eAAN,CAAsB;EAC3B;EACUC,OAAO,GAAsB,EAAtB;EAEjB;AACF;AACA;AACA;AACA;AACA;;EACEC,WAAW,CAASC,OAAT,EAAmC;IAAA,KAA1BA,OAA0B,GAA1BA,OAA0B;IAC5C,KAAKA,OAAL,CAAaC,MAAb,CAAoBC,EAApB,CACE,SADF,EAEE,CAACC,OAAD,EAA2BC,MAA3B,EAA2CC,IAA3C,KAA4D;MAC1D,MAAM;QAAEC;MAAF,IAAe,IAAIC,GAAJ,CAAQJ,OAAO,CAACK,GAAR,IAAe,EAAvB,EAA2B,kBAA3B,CAArB;MACA,IAAIC,OAAO,GAAG,KAAd;;MACA,KAAK,MAAMR,MAAX,IAAqB,KAAKH,OAA1B,EAAmC;QACjC,IAAIG,MAAM,CAACS,aAAP,CAAqBJ,QAArB,CAAJ,EAAoC;UAClCG,OAAO,GAAG,IAAV;UACAR,MAAM,CAACU,OAAP,CAAeR,OAAf,EAAwBC,MAAxB,EAAgCC,IAAhC;UACA;QACD;MACF;;MAED,IAAI,CAACI,OAAL,EAAc;QACZ,KAAKT,OAAL,CAAaY,GAAb,CAAiBC,KAAjB,CAAuB;UACrBC,GAAG,EAAE,uDADgB;UAErBR;QAFqB,CAAvB;QAIAF,MAAM,CAACW,OAAP;MACD;IACF,CApBH;EAsBD;EAED;AACF;AACA;AACA;AACA;AACA;AACA;;;EACEC,cAAc,CAA4Bf,MAA5B,EAA0C;IACtD,KAAKH,OAAL,CAAamB,IAAb,CAAkBhB,MAAlB;IACA,OAAOA,MAAP;EACD;;AA7C0B"}
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 'http';\nimport type { Socket } from 'net';\nimport type { FastifyInstance } from 'fastify';\nimport { WebSocketServer } from './WebSocketServer';\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: WebSocketServer[] = [];\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 WebSocketServer>(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,GAAsB,EAAE;;EAEzC;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,CAA4Bf,MAAS,EAAK;IACtD,IAAI,CAACH,OAAO,CAACmB,IAAI,CAAChB,MAAM,CAAC;IACzB,OAAOA,MAAM;EACf;AACF"}
@@ -1,10 +1,10 @@
1
1
  import { WebSocketServer as WebSocketServerImpl } from 'ws';
2
+
2
3
  /**
3
4
  * Abstract class for providing common logic (eg routing) for all WebSocket servers.
4
5
  *
5
6
  * @category Development server
6
7
  */
7
-
8
8
  export class WebSocketServer {
9
9
  /** An instance of the underlying WebSocket server. */
10
10
 
@@ -27,23 +27,20 @@ export class WebSocketServer {
27
27
  this.server.on('connection', this.onConnection.bind(this));
28
28
  this.paths = Array.isArray(path) ? path : [path];
29
29
  }
30
-
31
30
  shouldUpgrade(pathname) {
32
31
  return this.paths.includes(pathname);
33
32
  }
34
-
35
33
  upgrade(request, socket, head) {
36
34
  this.server.handleUpgrade(request, socket, head, webSocket => {
37
35
  this.server.emit('connection', webSocket, request);
38
36
  });
39
37
  }
38
+
40
39
  /**
41
40
  * Process incoming WebSocket connection.
42
41
  *
43
42
  * @param socket Incoming WebSocket connection.
44
43
  * @param request Upgrade request for the connection.
45
44
  */
46
-
47
-
48
45
  }
49
46
  //# sourceMappingURL=WebSocketServer.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"WebSocketServer.js","names":["WebSocketServer","WebSocketServerImpl","constructor","fastify","path","wssOptions","server","noServer","on","onConnection","bind","paths","Array","isArray","shouldUpgrade","pathname","includes","upgrade","request","socket","head","handleUpgrade","webSocket","emit"],"sources":["../../../src/plugins/wss/WebSocketServer.ts"],"sourcesContent":["import type { IncomingMessage } from 'http';\nimport type { Socket } from 'net';\nimport type { FastifyInstance } from 'fastify';\nimport {\n ServerOptions,\n WebSocket,\n WebSocketServer as WebSocketServerImpl,\n} from 'ws';\n\n/**\n * Abstract class for providing common logic (eg routing) for all WebSocket servers.\n *\n * @category Development server\n */\nexport abstract class WebSocketServer {\n /** An instance of the underlying WebSocket server. */\n public readonly server: WebSocketServerImpl;\n\n /** Fastify instance from which {@link server} will receive upgrade connections. */\n protected fastify: FastifyInstance;\n\n public readonly paths: string[];\n\n /**\n * Create a new instance of the WebSocketServer.\n * Any logging information, will be passed through standard `fastify.log` API.\n *\n * @param fastify Fastify instance to which the WebSocket will be attached to.\n * @param path Path on which this WebSocketServer will be accepting connections.\n * @param wssOptions WebSocket Server options.\n */\n constructor(\n fastify: FastifyInstance,\n path: string | string[],\n wssOptions: Omit<\n ServerOptions,\n 'noServer' | 'server' | 'host' | 'port' | 'path'\n > = {}\n ) {\n this.fastify = fastify;\n this.server = new WebSocketServerImpl({\n noServer: true,\n ...wssOptions,\n });\n this.server.on('connection', this.onConnection.bind(this));\n this.paths = Array.isArray(path) ? path : [path];\n }\n\n shouldUpgrade(pathname: string) {\n return this.paths.includes(pathname);\n }\n\n upgrade(request: IncomingMessage, socket: Socket, head: Buffer) {\n this.server.handleUpgrade(request, socket, head, (webSocket) => {\n this.server.emit('connection', webSocket, request);\n });\n }\n\n /**\n * Process incoming WebSocket connection.\n *\n * @param socket Incoming WebSocket connection.\n * @param request Upgrade request for the connection.\n */\n abstract onConnection(socket: WebSocket, request: IncomingMessage): void;\n}\n"],"mappings":"AAGA,SAGEA,eAAe,IAAIC,mBAHrB,QAIO,IAJP;AAMA;AACA;AACA;AACA;AACA;;AACA,OAAO,MAAeD,eAAf,CAA+B;EACpC;;EAGA;;EAKA;AACF;AACA;AACA;AACA;AACA;AACA;AACA;EACEE,WAAW,CACTC,OADS,EAETC,IAFS,EAGTC,UAGC,GAAG,EANK,EAOT;IACA,KAAKF,OAAL,GAAeA,OAAf;IACA,KAAKG,MAAL,GAAc,IAAIL,mBAAJ,CAAwB;MACpCM,QAAQ,EAAE,IAD0B;MAEpC,GAAGF;IAFiC,CAAxB,CAAd;IAIA,KAAKC,MAAL,CAAYE,EAAZ,CAAe,YAAf,EAA6B,KAAKC,YAAL,CAAkBC,IAAlB,CAAuB,IAAvB,CAA7B;IACA,KAAKC,KAAL,GAAaC,KAAK,CAACC,OAAN,CAAcT,IAAd,IAAsBA,IAAtB,GAA6B,CAACA,IAAD,CAA1C;EACD;;EAEDU,aAAa,CAACC,QAAD,EAAmB;IAC9B,OAAO,KAAKJ,KAAL,CAAWK,QAAX,CAAoBD,QAApB,CAAP;EACD;;EAEDE,OAAO,CAACC,OAAD,EAA2BC,MAA3B,EAA2CC,IAA3C,EAAyD;IAC9D,KAAKd,MAAL,CAAYe,aAAZ,CAA0BH,OAA1B,EAAmCC,MAAnC,EAA2CC,IAA3C,EAAkDE,SAAD,IAAe;MAC9D,KAAKhB,MAAL,CAAYiB,IAAZ,CAAiB,YAAjB,EAA+BD,SAA/B,EAA0CJ,OAA1C;IACD,CAFD;EAGD;EAED;AACF;AACA;AACA;AACA;AACA;;;AAjDsC"}
1
+ {"version":3,"file":"WebSocketServer.js","names":["WebSocketServer","WebSocketServerImpl","constructor","fastify","path","wssOptions","server","noServer","on","onConnection","bind","paths","Array","isArray","shouldUpgrade","pathname","includes","upgrade","request","socket","head","handleUpgrade","webSocket","emit"],"sources":["../../../src/plugins/wss/WebSocketServer.ts"],"sourcesContent":["import type { IncomingMessage } from 'http';\nimport type { Socket } from 'net';\nimport type { FastifyInstance } from 'fastify';\nimport {\n ServerOptions,\n WebSocket,\n WebSocketServer as WebSocketServerImpl,\n} from 'ws';\n\n/**\n * Abstract class for providing common logic (eg routing) for all WebSocket servers.\n *\n * @category Development server\n */\nexport abstract class WebSocketServer {\n /** An instance of the underlying WebSocket server. */\n public readonly server: WebSocketServerImpl;\n\n /** Fastify instance from which {@link server} will receive upgrade connections. */\n protected fastify: FastifyInstance;\n\n public readonly paths: string[];\n\n /**\n * Create a new instance of the WebSocketServer.\n * Any logging information, will be passed through standard `fastify.log` API.\n *\n * @param fastify Fastify instance to which the WebSocket will be attached to.\n * @param path Path on which this WebSocketServer will be accepting connections.\n * @param wssOptions WebSocket Server options.\n */\n constructor(\n fastify: FastifyInstance,\n path: string | string[],\n wssOptions: Omit<\n ServerOptions,\n 'noServer' | 'server' | 'host' | 'port' | 'path'\n > = {}\n ) {\n this.fastify = fastify;\n this.server = new WebSocketServerImpl({\n noServer: true,\n ...wssOptions,\n });\n this.server.on('connection', this.onConnection.bind(this));\n this.paths = Array.isArray(path) ? path : [path];\n }\n\n shouldUpgrade(pathname: string) {\n return this.paths.includes(pathname);\n }\n\n upgrade(request: IncomingMessage, socket: Socket, head: Buffer) {\n this.server.handleUpgrade(request, socket, head, (webSocket) => {\n this.server.emit('connection', webSocket, request);\n });\n }\n\n /**\n * Process incoming WebSocket connection.\n *\n * @param socket Incoming WebSocket connection.\n * @param request Upgrade request for the connection.\n */\n abstract onConnection(socket: WebSocket, request: IncomingMessage): void;\n}\n"],"mappings":"AAGA,SAGEA,eAAe,IAAIC,mBAAmB,QACjC,IAAI;;AAEX;AACA;AACA;AACA;AACA;AACA,OAAO,MAAeD,eAAe,CAAC;EACpC;;EAGA;;EAKA;AACF;AACA;AACA;AACA;AACA;AACA;AACA;EACEE,WAAWA,CACTC,OAAwB,EACxBC,IAAuB,EACvBC,UAGC,GAAG,CAAC,CAAC,EACN;IACA,IAAI,CAACF,OAAO,GAAGA,OAAO;IACtB,IAAI,CAACG,MAAM,GAAG,IAAIL,mBAAmB,CAAC;MACpCM,QAAQ,EAAE,IAAI;MACd,GAAGF;IACL,CAAC,CAAC;IACF,IAAI,CAACC,MAAM,CAACE,EAAE,CAAC,YAAY,EAAE,IAAI,CAACC,YAAY,CAACC,IAAI,CAAC,IAAI,CAAC,CAAC;IAC1D,IAAI,CAACC,KAAK,GAAGC,KAAK,CAACC,OAAO,CAACT,IAAI,CAAC,GAAGA,IAAI,GAAG,CAACA,IAAI,CAAC;EAClD;EAEAU,aAAaA,CAACC,QAAgB,EAAE;IAC9B,OAAO,IAAI,CAACJ,KAAK,CAACK,QAAQ,CAACD,QAAQ,CAAC;EACtC;EAEAE,OAAOA,CAACC,OAAwB,EAAEC,MAAc,EAAEC,IAAY,EAAE;IAC9D,IAAI,CAACd,MAAM,CAACe,aAAa,CAACH,OAAO,EAAEC,MAAM,EAAEC,IAAI,EAAGE,SAAS,IAAK;MAC9D,IAAI,CAAChB,MAAM,CAACiB,IAAI,CAAC,YAAY,EAAED,SAAS,EAAEJ,OAAO,CAAC;IACpD,CAAC,CAAC;EACJ;;EAEA;AACF;AACA;AACA;AACA;AACA;AAEA"}
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":["default"],"sources":["../../../src/plugins/wss/index.ts"],"sourcesContent":["export { default } from './wssPlugin';\nexport * from './WebSocketServer';\nexport * from './types';\n"],"mappings":"SAASA,O"}
1
+ {"version":3,"file":"index.js","names":["default"],"sources":["../../../src/plugins/wss/index.ts"],"sourcesContent":["export { default } from './wssPlugin';\nexport * from './WebSocketServer';\nexport * from './types';\n"],"mappings":"SAASA,OAAO;AAAA;AAAA"}