@atxp/server 0.2.22 → 0.3.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 (164) hide show
  1. package/dist/_virtual/_commonjsHelpers.js +8 -0
  2. package/dist/_virtual/_commonjsHelpers.js.map +1 -0
  3. package/dist/_virtual/bom-handling.js +4 -0
  4. package/dist/_virtual/bom-handling.js.map +1 -0
  5. package/dist/_virtual/dbcs-codec.js +4 -0
  6. package/dist/_virtual/dbcs-codec.js.map +1 -0
  7. package/dist/_virtual/index.js +8 -0
  8. package/dist/_virtual/index.js.map +1 -0
  9. package/dist/_virtual/index2.js +4 -0
  10. package/dist/_virtual/index2.js.map +1 -0
  11. package/dist/_virtual/index3.js +4 -0
  12. package/dist/_virtual/index3.js.map +1 -0
  13. package/dist/_virtual/index4.js +4 -0
  14. package/dist/_virtual/index4.js.map +1 -0
  15. package/dist/_virtual/index5.js +4 -0
  16. package/dist/_virtual/index5.js.map +1 -0
  17. package/dist/_virtual/inherits.js +4 -0
  18. package/dist/_virtual/inherits.js.map +1 -0
  19. package/dist/_virtual/inherits_browser.js +4 -0
  20. package/dist/_virtual/inherits_browser.js.map +1 -0
  21. package/dist/_virtual/sbcs-codec.js +4 -0
  22. package/dist/_virtual/sbcs-codec.js.map +1 -0
  23. package/dist/_virtual/utf16.js +4 -0
  24. package/dist/_virtual/utf16.js.map +1 -0
  25. package/dist/_virtual/utf32.js +4 -0
  26. package/dist/_virtual/utf32.js.map +1 -0
  27. package/dist/_virtual/utf7.js +4 -0
  28. package/dist/_virtual/utf7.js.map +1 -0
  29. package/dist/atxpContext.js +9 -6
  30. package/dist/atxpContext.js.map +1 -1
  31. package/dist/atxpServer.js +19 -27
  32. package/dist/atxpServer.js.map +1 -1
  33. package/dist/core/mcp.js +39 -0
  34. package/dist/core/mcp.js.map +1 -0
  35. package/dist/{oAuthChallenge.js → core/oauth.js} +21 -12
  36. package/dist/core/oauth.js.map +1 -0
  37. package/dist/{token.js → core/token.js} +13 -7
  38. package/dist/core/token.js.map +1 -0
  39. package/dist/getResource.js +5 -3
  40. package/dist/getResource.js.map +1 -1
  41. package/dist/index.cjs +13727 -0
  42. package/dist/index.cjs.map +1 -0
  43. package/dist/index.d.ts +141 -5
  44. package/dist/index.js +13708 -5
  45. package/dist/index.js.map +1 -1
  46. package/dist/{http.js → node/http.js} +21 -20
  47. package/dist/node/http.js.map +1 -0
  48. package/dist/node/oauth.js +23 -0
  49. package/dist/node/oauth.js.map +1 -0
  50. package/dist/node/token.js +15 -0
  51. package/dist/node/token.js.map +1 -0
  52. package/dist/node_modules/bytes/index.js +181 -0
  53. package/dist/node_modules/bytes/index.js.map +1 -0
  54. package/dist/node_modules/depd/index.js +551 -0
  55. package/dist/node_modules/depd/index.js.map +1 -0
  56. package/dist/node_modules/http-errors/index.js +307 -0
  57. package/dist/node_modules/http-errors/index.js.map +1 -0
  58. package/dist/node_modules/iconv-lite/encodings/dbcs-codec.js +599 -0
  59. package/dist/node_modules/iconv-lite/encodings/dbcs-codec.js.map +1 -0
  60. package/dist/node_modules/iconv-lite/encodings/dbcs-data.js +207 -0
  61. package/dist/node_modules/iconv-lite/encodings/dbcs-data.js.map +1 -0
  62. package/dist/node_modules/iconv-lite/encodings/index.js +45 -0
  63. package/dist/node_modules/iconv-lite/encodings/index.js.map +1 -0
  64. package/dist/node_modules/iconv-lite/encodings/internal.js +211 -0
  65. package/dist/node_modules/iconv-lite/encodings/internal.js.map +1 -0
  66. package/dist/node_modules/iconv-lite/encodings/sbcs-codec.js +84 -0
  67. package/dist/node_modules/iconv-lite/encodings/sbcs-codec.js.map +1 -0
  68. package/dist/node_modules/iconv-lite/encodings/sbcs-data-generated.js +461 -0
  69. package/dist/node_modules/iconv-lite/encodings/sbcs-data-generated.js.map +1 -0
  70. package/dist/node_modules/iconv-lite/encodings/sbcs-data.js +188 -0
  71. package/dist/node_modules/iconv-lite/encodings/sbcs-data.js.map +1 -0
  72. package/dist/node_modules/iconv-lite/encodings/tables/big5-added.json.js +507 -0
  73. package/dist/node_modules/iconv-lite/encodings/tables/big5-added.json.js.map +1 -0
  74. package/dist/node_modules/iconv-lite/encodings/tables/cp936.json.js +2622 -0
  75. package/dist/node_modules/iconv-lite/encodings/tables/cp936.json.js.map +1 -0
  76. package/dist/node_modules/iconv-lite/encodings/tables/cp949.json.js +2381 -0
  77. package/dist/node_modules/iconv-lite/encodings/tables/cp949.json.js.map +1 -0
  78. package/dist/node_modules/iconv-lite/encodings/tables/cp950.json.js +730 -0
  79. package/dist/node_modules/iconv-lite/encodings/tables/cp950.json.js.map +1 -0
  80. package/dist/node_modules/iconv-lite/encodings/tables/eucjp.json.js +823 -0
  81. package/dist/node_modules/iconv-lite/encodings/tables/eucjp.json.js.map +1 -0
  82. package/dist/node_modules/iconv-lite/encodings/tables/gb18030-ranges.json.js +425 -0
  83. package/dist/node_modules/iconv-lite/encodings/tables/gb18030-ranges.json.js.map +1 -0
  84. package/dist/node_modules/iconv-lite/encodings/tables/gbk-added.json.js +265 -0
  85. package/dist/node_modules/iconv-lite/encodings/tables/gbk-added.json.js.map +1 -0
  86. package/dist/node_modules/iconv-lite/encodings/tables/shiftjis.json.js +549 -0
  87. package/dist/node_modules/iconv-lite/encodings/tables/shiftjis.json.js.map +1 -0
  88. package/dist/node_modules/iconv-lite/encodings/utf16.js +207 -0
  89. package/dist/node_modules/iconv-lite/encodings/utf16.js.map +1 -0
  90. package/dist/node_modules/iconv-lite/encodings/utf32.js +330 -0
  91. package/dist/node_modules/iconv-lite/encodings/utf32.js.map +1 -0
  92. package/dist/node_modules/iconv-lite/encodings/utf7.js +298 -0
  93. package/dist/node_modules/iconv-lite/encodings/utf7.js.map +1 -0
  94. package/dist/node_modules/iconv-lite/lib/bom-handling.js +62 -0
  95. package/dist/node_modules/iconv-lite/lib/bom-handling.js.map +1 -0
  96. package/dist/node_modules/iconv-lite/lib/index.js +193 -0
  97. package/dist/node_modules/iconv-lite/lib/index.js.map +1 -0
  98. package/dist/node_modules/iconv-lite/lib/streams.js +121 -0
  99. package/dist/node_modules/iconv-lite/lib/streams.js.map +1 -0
  100. package/dist/node_modules/inherits/inherits.js +22 -0
  101. package/dist/node_modules/inherits/inherits.js.map +1 -0
  102. package/dist/node_modules/inherits/inherits_browser.js +39 -0
  103. package/dist/node_modules/inherits/inherits_browser.js.map +1 -0
  104. package/dist/node_modules/raw-body/index.js +352 -0
  105. package/dist/node_modules/raw-body/index.js.map +1 -0
  106. package/dist/node_modules/safer-buffer/safer.js +89 -0
  107. package/dist/node_modules/safer-buffer/safer.js.map +1 -0
  108. package/dist/node_modules/setprototypeof/index.js +27 -0
  109. package/dist/node_modules/setprototypeof/index.js.map +1 -0
  110. package/dist/node_modules/statuses/codes.json.js +68 -0
  111. package/dist/node_modules/statuses/codes.json.js.map +1 -0
  112. package/dist/node_modules/statuses/index.js +158 -0
  113. package/dist/node_modules/statuses/index.js.map +1 -0
  114. package/dist/node_modules/toidentifier/index.js +42 -0
  115. package/dist/node_modules/toidentifier/index.js.map +1 -0
  116. package/dist/node_modules/unpipe/index.js +79 -0
  117. package/dist/node_modules/unpipe/index.js.map +1 -0
  118. package/dist/oAuthMetadata.js +7 -4
  119. package/dist/oAuthMetadata.js.map +1 -1
  120. package/dist/paymentServer.js +5 -20
  121. package/dist/paymentServer.js.map +1 -1
  122. package/dist/protectedResourceMetadata.js +7 -4
  123. package/dist/protectedResourceMetadata.js.map +1 -1
  124. package/dist/requirePayment.js +7 -4
  125. package/dist/requirePayment.js.map +1 -1
  126. package/dist/types.js +4 -2
  127. package/dist/types.js.map +1 -1
  128. package/dist/webapi/mcp.js +25 -0
  129. package/dist/webapi/mcp.js.map +1 -0
  130. package/dist/webapi/oauth.js +21 -0
  131. package/dist/webapi/oauth.js.map +1 -0
  132. package/dist/webapi/token.js +15 -0
  133. package/dist/webapi/token.js.map +1 -0
  134. package/package.json +21 -7
  135. package/dist/atxpContext.d.ts +0 -6
  136. package/dist/atxpContext.d.ts.map +0 -1
  137. package/dist/atxpServer.d.ts +0 -12
  138. package/dist/atxpServer.d.ts.map +0 -1
  139. package/dist/getResource.d.ts +0 -4
  140. package/dist/getResource.d.ts.map +0 -1
  141. package/dist/http.d.ts +0 -7
  142. package/dist/http.d.ts.map +0 -1
  143. package/dist/http.js.map +0 -1
  144. package/dist/index.d.ts.map +0 -1
  145. package/dist/oAuthChallenge.d.ts +0 -4
  146. package/dist/oAuthChallenge.d.ts.map +0 -1
  147. package/dist/oAuthChallenge.js.map +0 -1
  148. package/dist/oAuthMetadata.d.ts +0 -6
  149. package/dist/oAuthMetadata.d.ts.map +0 -1
  150. package/dist/paymentServer.d.ts +0 -62
  151. package/dist/paymentServer.d.ts.map +0 -1
  152. package/dist/protectedResourceMetadata.d.ts +0 -5
  153. package/dist/protectedResourceMetadata.d.ts.map +0 -1
  154. package/dist/requirePayment.d.ts +0 -3
  155. package/dist/requirePayment.d.ts.map +0 -1
  156. package/dist/serverTestHelpers.d.ts +0 -55
  157. package/dist/serverTestHelpers.d.ts.map +0 -1
  158. package/dist/serverTestHelpers.js +0 -88
  159. package/dist/serverTestHelpers.js.map +0 -1
  160. package/dist/token.d.ts +0 -4
  161. package/dist/token.d.ts.map +0 -1
  162. package/dist/token.js.map +0 -1
  163. package/dist/types.d.ts +0 -60
  164. package/dist/types.d.ts.map +0 -1
@@ -1,27 +1,26 @@
1
- import getRawBody from "raw-body";
2
- import contentType from "content-type";
3
- import { isJSONRPCRequest } from "@modelcontextprotocol/sdk/types.js";
4
- import { parseMcpMessages } from "@atxp/common";
1
+ import getRawBody from '../_virtual/index.js';
2
+ import contentType from 'content-type';
3
+ import { isJSONRPCRequest } from '@modelcontextprotocol/sdk/types.js';
4
+ import { parseMcpMessages } from '@atxp/common';
5
+ import { parseMcpRequestsCore } from '../core/mcp.js';
6
+
5
7
  // Useful reference for dealing with low-level http requests:
6
8
  // https://github.com/modelcontextprotocol/typescript-sdk/blob/c6ac083b1b37b222b5bfba5563822daa5d03372e/src/server/streamableHttp.ts#L375
7
9
  // Using the same value as MCP SDK
8
10
  const MAXIMUM_MESSAGE_SIZE = "4mb";
9
- export async function parseMcpRequests(config, requestUrl, req, parsedBody) {
10
- if (!req.method) {
11
- return [];
12
- }
13
- if (req.method.toLowerCase() !== 'post') {
14
- return [];
15
- }
16
- // The middleware has to be mounted at the root to serve the protected resource metadata,
17
- // but the actual MCP server it's controlling is specified by the mountPath.
18
- const path = requestUrl.pathname.replace(/\/$/, '');
19
- const mountPath = config.mountPath.replace(/\/$/, '');
20
- if (path !== mountPath && path !== `${mountPath}/message`) {
21
- config.logger.debug(`Request path (${path}) does not match the mountPath (${mountPath}), skipping MCP middleware`);
11
+ /**
12
+ * Node.js HTTP implementation of MCP request parsing
13
+ * Handles Node.js IncomingMessage parsing and delegates to core logic
14
+ */
15
+ async function parseMcpRequests(config, requestUrl, req, parsedBody) {
16
+ parsedBody = parsedBody ?? await parseBody(req, config.logger);
17
+ // Use the shared core logic for basic validation and filtering
18
+ const basicMessages = parseMcpRequestsCore(config, requestUrl, req.method || '', parsedBody);
19
+ // Only proceed with MCP processing if the basic validation passed
20
+ if (basicMessages.length === 0) {
22
21
  return [];
23
22
  }
24
- parsedBody = parsedBody ?? await parseBody(req, config.logger);
23
+ // Apply additional MCP-specific processing (parseMcpMessages handles SSE and other formats)
25
24
  const messages = await parseMcpMessages(parsedBody, config.logger);
26
25
  const requests = messages.filter(msg => isJSONRPCRequest(msg));
27
26
  if (requests.length !== messages.length) {
@@ -29,7 +28,7 @@ export async function parseMcpRequests(config, requestUrl, req, parsedBody) {
29
28
  }
30
29
  return requests;
31
30
  }
32
- export async function parseBody(req, logger) {
31
+ async function parseBody(req, logger) {
33
32
  try {
34
33
  const ct = req.headers["content-type"];
35
34
  let encoding = "utf-8";
@@ -48,4 +47,6 @@ export async function parseBody(req, logger) {
48
47
  return undefined;
49
48
  }
50
49
  }
51
- //# sourceMappingURL=http.js.map
50
+
51
+ export { parseBody, parseMcpRequests };
52
+ //# sourceMappingURL=http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AAU,CAAC,OAAO,IAAI,OAAO;QACnD;AAEA,QAAA,MAAM,IAAI,GAAG,MAAM,UAAU,CAAC,GAAG,EAAE;AACjC,YAAA,KAAK,EAAE,oBAAoB;YAC3B,QAAQ;AACT,SAAA,CAAC;QACF,OAAO,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,QAAQ,EAAE,CAAC;IACpC;IAAE,OAAO,KAAK,EAAE;AACd,QAAA,MAAM,CAAC,KAAK,CAAE,KAAe,CAAC,OAAO,CAAC;AACtC,QAAA,OAAO,SAAS;IAClB;AACF;;;;"}
@@ -0,0 +1,23 @@
1
+ import { createOAuthChallengeResponseCore } from '../core/oauth.js';
2
+
3
+ /**
4
+ * Node.js HTTP implementation of OAuth challenge sending
5
+ * Uses Node.js ServerResponse and delegates to core logic
6
+ */
7
+ function sendOAuthChallenge(res, tokenCheck) {
8
+ // Use the shared core logic to get response data
9
+ const responseData = createOAuthChallengeResponseCore(tokenCheck);
10
+ if (!responseData) {
11
+ return false;
12
+ }
13
+ // Apply the response data to Node.js ServerResponse
14
+ Object.entries(responseData.headers).forEach(([key, value]) => {
15
+ res.setHeader(key, value);
16
+ });
17
+ res.writeHead(responseData.status);
18
+ res.end(responseData.body);
19
+ return true;
20
+ }
21
+
22
+ export { sendOAuthChallenge };
23
+ //# sourceMappingURL=oauth.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"oauth.js","sources":["../../src/node/oauth.ts"],"sourcesContent":[null],"names":[],"mappings":";;AAIA;;;AAGG;AACG,SAAU,kBAAkB,CAAC,GAAmB,EAAE,UAAsB,EAAA;;AAE5E,IAAA,MAAM,YAAY,GAAG,gCAAgC,CAAC,UAAU,CAAC;IAEjE,IAAI,CAAC,YAAY,EAAE;AACjB,QAAA,OAAO,KAAK;IACd;;AAGA,IAAA,MAAM,CAAC,OAAO,CAAC,YAAY,CAAC,OAAO,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,GAAG,EAAE,KAAK,CAAC,KAAI;AAC5D,QAAA,GAAG,CAAC,SAAS,CAAC,GAAG,EAAE,KAAK,CAAC;AAC3B,IAAA,CAAC,CAAC;AACF,IAAA,GAAG,CAAC,SAAS,CAAC,YAAY,CAAC,MAAM,CAAC;AAClC,IAAA,GAAG,CAAC,GAAG,CAAC,YAAY,CAAC,IAAI,CAAC;AAE1B,IAAA,OAAO,IAAI;AACb;;;;"}
@@ -0,0 +1,15 @@
1
+ import { checkTokenCore } from '../core/token.js';
2
+
3
+ /**
4
+ * Node.js HTTP implementation of token checking
5
+ * Extracts data from Node.js IncomingMessage and delegates to core logic
6
+ */
7
+ async function checkToken(config, resourceURL, req) {
8
+ // Extract the authorization header from Node.js request
9
+ const authorizationHeader = req.headers.authorization || null;
10
+ // Use the shared core logic
11
+ return checkTokenCore(config, resourceURL, authorizationHeader);
12
+ }
13
+
14
+ export { checkToken };
15
+ //# sourceMappingURL=token.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"token.js","sources":["../../src/node/token.ts"],"sourcesContent":[null],"names":[],"mappings":";;AAIA;;;AAGG;AACI,eAAe,UAAU,CAAC,MAAkB,EAAE,WAAgB,EAAE,GAAoB,EAAA;;IAEzF,MAAM,mBAAmB,GAAG,GAAG,CAAC,OAAO,CAAC,aAAa,IAAI,IAAI;;IAG7D,OAAO,cAAc,CAAC,MAAM,EAAE,WAAW,EAAE,mBAAmB,CAAC;AACjE;;;;"}
@@ -0,0 +1,181 @@
1
+ import { __module as bytes } from '../../_virtual/index2.js';
2
+
3
+ /*!
4
+ * bytes
5
+ * Copyright(c) 2012-2014 TJ Holowaychuk
6
+ * Copyright(c) 2015 Jed Watson
7
+ * MIT Licensed
8
+ */
9
+
10
+ var hasRequiredBytes;
11
+
12
+ function requireBytes () {
13
+ if (hasRequiredBytes) return bytes.exports;
14
+ hasRequiredBytes = 1;
15
+
16
+ /**
17
+ * Module exports.
18
+ * @public
19
+ */
20
+
21
+ bytes.exports = bytes$1;
22
+ bytes.exports.format = format;
23
+ bytes.exports.parse = parse;
24
+
25
+ /**
26
+ * Module variables.
27
+ * @private
28
+ */
29
+
30
+ var formatThousandsRegExp = /\B(?=(\d{3})+(?!\d))/g;
31
+
32
+ var formatDecimalsRegExp = /(?:\.0*|(\.[^0]+)0+)$/;
33
+
34
+ var map = {
35
+ b: 1,
36
+ kb: 1 << 10,
37
+ mb: 1 << 20,
38
+ gb: 1 << 30,
39
+ tb: Math.pow(1024, 4),
40
+ pb: Math.pow(1024, 5),
41
+ };
42
+
43
+ var parseRegExp = /^((-|\+)?(\d+(?:\.\d+)?)) *(kb|mb|gb|tb|pb)$/i;
44
+
45
+ /**
46
+ * Convert the given value in bytes into a string or parse to string to an integer in bytes.
47
+ *
48
+ * @param {string|number} value
49
+ * @param {{
50
+ * case: [string],
51
+ * decimalPlaces: [number]
52
+ * fixedDecimals: [boolean]
53
+ * thousandsSeparator: [string]
54
+ * unitSeparator: [string]
55
+ * }} [options] bytes options.
56
+ *
57
+ * @returns {string|number|null}
58
+ */
59
+
60
+ function bytes$1(value, options) {
61
+ if (typeof value === 'string') {
62
+ return parse(value);
63
+ }
64
+
65
+ if (typeof value === 'number') {
66
+ return format(value, options);
67
+ }
68
+
69
+ return null;
70
+ }
71
+
72
+ /**
73
+ * Format the given value in bytes into a string.
74
+ *
75
+ * If the value is negative, it is kept as such. If it is a float,
76
+ * it is rounded.
77
+ *
78
+ * @param {number} value
79
+ * @param {object} [options]
80
+ * @param {number} [options.decimalPlaces=2]
81
+ * @param {number} [options.fixedDecimals=false]
82
+ * @param {string} [options.thousandsSeparator=]
83
+ * @param {string} [options.unit=]
84
+ * @param {string} [options.unitSeparator=]
85
+ *
86
+ * @returns {string|null}
87
+ * @public
88
+ */
89
+
90
+ function format(value, options) {
91
+ if (!Number.isFinite(value)) {
92
+ return null;
93
+ }
94
+
95
+ var mag = Math.abs(value);
96
+ var thousandsSeparator = (options && options.thousandsSeparator) || '';
97
+ var unitSeparator = (options && options.unitSeparator) || '';
98
+ var decimalPlaces = (options && options.decimalPlaces !== undefined) ? options.decimalPlaces : 2;
99
+ var fixedDecimals = Boolean(options && options.fixedDecimals);
100
+ var unit = (options && options.unit) || '';
101
+
102
+ if (!unit || !map[unit.toLowerCase()]) {
103
+ if (mag >= map.pb) {
104
+ unit = 'PB';
105
+ } else if (mag >= map.tb) {
106
+ unit = 'TB';
107
+ } else if (mag >= map.gb) {
108
+ unit = 'GB';
109
+ } else if (mag >= map.mb) {
110
+ unit = 'MB';
111
+ } else if (mag >= map.kb) {
112
+ unit = 'KB';
113
+ } else {
114
+ unit = 'B';
115
+ }
116
+ }
117
+
118
+ var val = value / map[unit.toLowerCase()];
119
+ var str = val.toFixed(decimalPlaces);
120
+
121
+ if (!fixedDecimals) {
122
+ str = str.replace(formatDecimalsRegExp, '$1');
123
+ }
124
+
125
+ if (thousandsSeparator) {
126
+ str = str.split('.').map(function (s, i) {
127
+ return i === 0
128
+ ? s.replace(formatThousandsRegExp, thousandsSeparator)
129
+ : s
130
+ }).join('.');
131
+ }
132
+
133
+ return str + unitSeparator + unit;
134
+ }
135
+
136
+ /**
137
+ * Parse the string value into an integer in bytes.
138
+ *
139
+ * If no unit is given, it is assumed the value is in bytes.
140
+ *
141
+ * @param {number|string} val
142
+ *
143
+ * @returns {number|null}
144
+ * @public
145
+ */
146
+
147
+ function parse(val) {
148
+ if (typeof val === 'number' && !isNaN(val)) {
149
+ return val;
150
+ }
151
+
152
+ if (typeof val !== 'string') {
153
+ return null;
154
+ }
155
+
156
+ // Test if the string passed is valid
157
+ var results = parseRegExp.exec(val);
158
+ var floatValue;
159
+ var unit = 'b';
160
+
161
+ if (!results) {
162
+ // Nothing could be extracted from the given string
163
+ floatValue = parseInt(val, 10);
164
+ unit = 'b';
165
+ } else {
166
+ // Retrieve the value and the unit
167
+ floatValue = parseFloat(results[1]);
168
+ unit = results[4].toLowerCase();
169
+ }
170
+
171
+ if (isNaN(floatValue)) {
172
+ return null;
173
+ }
174
+
175
+ return Math.floor(map[unit] * floatValue);
176
+ }
177
+ return bytes.exports;
178
+ }
179
+
180
+ export { requireBytes as __require };
181
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sources":["../../../../../node_modules/bytes/index.js"],"sourcesContent":["/*!\n * bytes\n * Copyright(c) 2012-2014 TJ Holowaychuk\n * Copyright(c) 2015 Jed Watson\n * MIT Licensed\n */\n\n'use strict';\n\n/**\n * Module exports.\n * @public\n */\n\nmodule.exports = bytes;\nmodule.exports.format = format;\nmodule.exports.parse = parse;\n\n/**\n * Module variables.\n * @private\n */\n\nvar formatThousandsRegExp = /\\B(?=(\\d{3})+(?!\\d))/g;\n\nvar formatDecimalsRegExp = /(?:\\.0*|(\\.[^0]+)0+)$/;\n\nvar map = {\n b: 1,\n kb: 1 << 10,\n mb: 1 << 20,\n gb: 1 << 30,\n tb: Math.pow(1024, 4),\n pb: Math.pow(1024, 5),\n};\n\nvar parseRegExp = /^((-|\\+)?(\\d+(?:\\.\\d+)?)) *(kb|mb|gb|tb|pb)$/i;\n\n/**\n * Convert the given value in bytes into a string or parse to string to an integer in bytes.\n *\n * @param {string|number} value\n * @param {{\n * case: [string],\n * decimalPlaces: [number]\n * fixedDecimals: [boolean]\n * thousandsSeparator: [string]\n * unitSeparator: [string]\n * }} [options] bytes options.\n *\n * @returns {string|number|null}\n */\n\nfunction bytes(value, options) {\n if (typeof value === 'string') {\n return parse(value);\n }\n\n if (typeof value === 'number') {\n return format(value, options);\n }\n\n return null;\n}\n\n/**\n * Format the given value in bytes into a string.\n *\n * If the value is negative, it is kept as such. If it is a float,\n * it is rounded.\n *\n * @param {number} value\n * @param {object} [options]\n * @param {number} [options.decimalPlaces=2]\n * @param {number} [options.fixedDecimals=false]\n * @param {string} [options.thousandsSeparator=]\n * @param {string} [options.unit=]\n * @param {string} [options.unitSeparator=]\n *\n * @returns {string|null}\n * @public\n */\n\nfunction format(value, options) {\n if (!Number.isFinite(value)) {\n return null;\n }\n\n var mag = Math.abs(value);\n var thousandsSeparator = (options && options.thousandsSeparator) || '';\n var unitSeparator = (options && options.unitSeparator) || '';\n var decimalPlaces = (options && options.decimalPlaces !== undefined) ? options.decimalPlaces : 2;\n var fixedDecimals = Boolean(options && options.fixedDecimals);\n var unit = (options && options.unit) || '';\n\n if (!unit || !map[unit.toLowerCase()]) {\n if (mag >= map.pb) {\n unit = 'PB';\n } else if (mag >= map.tb) {\n unit = 'TB';\n } else if (mag >= map.gb) {\n unit = 'GB';\n } else if (mag >= map.mb) {\n unit = 'MB';\n } else if (mag >= map.kb) {\n unit = 'KB';\n } else {\n unit = 'B';\n }\n }\n\n var val = value / map[unit.toLowerCase()];\n var str = val.toFixed(decimalPlaces);\n\n if (!fixedDecimals) {\n str = str.replace(formatDecimalsRegExp, '$1');\n }\n\n if (thousandsSeparator) {\n str = str.split('.').map(function (s, i) {\n return i === 0\n ? s.replace(formatThousandsRegExp, thousandsSeparator)\n : s\n }).join('.');\n }\n\n return str + unitSeparator + unit;\n}\n\n/**\n * Parse the string value into an integer in bytes.\n *\n * If no unit is given, it is assumed the value is in bytes.\n *\n * @param {number|string} val\n *\n * @returns {number|null}\n * @public\n */\n\nfunction parse(val) {\n if (typeof val === 'number' && !isNaN(val)) {\n return val;\n }\n\n if (typeof val !== 'string') {\n return null;\n }\n\n // Test if the string passed is valid\n var results = parseRegExp.exec(val);\n var floatValue;\n var unit = 'b';\n\n if (!results) {\n // Nothing could be extracted from the given string\n floatValue = parseInt(val, 10);\n unit = 'b'\n } else {\n // Retrieve the value and the unit\n floatValue = parseFloat(results[1]);\n unit = results[4].toLowerCase();\n }\n\n if (isNaN(floatValue)) {\n return null;\n }\n\n return Math.floor(map[unit] * floatValue);\n}\n"],"names":["bytesModule","bytes"],"mappings":";;;;;;;;;;;;;;;AASA;AACA;AACA;AACA;;AAEA,CAAAA,KAAA,CAAA,OAAc,GAAGC,OAAK;AACtB,CAAAD,KAAA,CAAA,OAAA,CAAA,MAAqB,GAAG,MAAM;AAC9B,CAAAA,KAAA,CAAA,OA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