@nocobase/plugin-mcp-server 2.1.0-alpha.10 → 2.1.0-alpha.9

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 (78) hide show
  1. package/build.config.ts +0 -1
  2. package/dist/client/index.js +1 -1
  3. package/dist/externalVersion.js +5 -6
  4. package/dist/node_modules/@modelcontextprotocol/sdk/node_modules/http-errors/HISTORY.md +186 -0
  5. package/dist/node_modules/@modelcontextprotocol/sdk/node_modules/http-errors/LICENSE +23 -0
  6. package/dist/node_modules/@modelcontextprotocol/sdk/node_modules/http-errors/README.md +169 -0
  7. package/dist/node_modules/@modelcontextprotocol/sdk/node_modules/http-errors/index.js +290 -0
  8. package/dist/node_modules/@modelcontextprotocol/sdk/node_modules/http-errors/package.json +54 -0
  9. package/dist/node_modules/@modelcontextprotocol/sdk/node_modules/iconv-lite/LICENSE +21 -0
  10. package/dist/node_modules/@modelcontextprotocol/sdk/node_modules/iconv-lite/README.md +138 -0
  11. package/dist/node_modules/@modelcontextprotocol/sdk/node_modules/iconv-lite/encodings/dbcs-codec.js +532 -0
  12. package/dist/node_modules/@modelcontextprotocol/sdk/node_modules/iconv-lite/encodings/dbcs-data.js +185 -0
  13. package/dist/node_modules/@modelcontextprotocol/sdk/node_modules/iconv-lite/encodings/index.js +23 -0
  14. package/dist/node_modules/@modelcontextprotocol/sdk/node_modules/iconv-lite/encodings/internal.js +218 -0
  15. package/dist/node_modules/@modelcontextprotocol/sdk/node_modules/iconv-lite/encodings/sbcs-codec.js +75 -0
  16. package/dist/node_modules/@modelcontextprotocol/sdk/node_modules/iconv-lite/encodings/sbcs-data-generated.js +451 -0
  17. package/dist/node_modules/@modelcontextprotocol/sdk/node_modules/iconv-lite/encodings/sbcs-data.js +178 -0
  18. package/dist/node_modules/@modelcontextprotocol/sdk/node_modules/iconv-lite/encodings/tables/big5-added.json +122 -0
  19. package/dist/node_modules/@modelcontextprotocol/sdk/node_modules/iconv-lite/encodings/tables/cp936.json +264 -0
  20. package/dist/node_modules/@modelcontextprotocol/sdk/node_modules/iconv-lite/encodings/tables/cp949.json +273 -0
  21. package/dist/node_modules/@modelcontextprotocol/sdk/node_modules/iconv-lite/encodings/tables/cp950.json +177 -0
  22. package/dist/node_modules/@modelcontextprotocol/sdk/node_modules/iconv-lite/encodings/tables/eucjp.json +182 -0
  23. package/dist/node_modules/@modelcontextprotocol/sdk/node_modules/iconv-lite/encodings/tables/gb18030-ranges.json +1 -0
  24. package/dist/node_modules/@modelcontextprotocol/sdk/node_modules/iconv-lite/encodings/tables/gbk-added.json +56 -0
  25. package/dist/node_modules/@modelcontextprotocol/sdk/node_modules/iconv-lite/encodings/tables/shiftjis.json +125 -0
  26. package/dist/node_modules/@modelcontextprotocol/sdk/node_modules/iconv-lite/encodings/utf16.js +187 -0
  27. package/dist/node_modules/@modelcontextprotocol/sdk/node_modules/iconv-lite/encodings/utf32.js +307 -0
  28. package/dist/node_modules/@modelcontextprotocol/sdk/node_modules/iconv-lite/encodings/utf7.js +283 -0
  29. package/dist/node_modules/@modelcontextprotocol/sdk/node_modules/iconv-lite/lib/bom-handling.js +48 -0
  30. package/dist/node_modules/@modelcontextprotocol/sdk/node_modules/iconv-lite/lib/helpers/merge-exports.js +13 -0
  31. package/dist/node_modules/@modelcontextprotocol/sdk/node_modules/iconv-lite/lib/index.d.ts +129 -0
  32. package/dist/node_modules/@modelcontextprotocol/sdk/node_modules/iconv-lite/lib/index.js +182 -0
  33. package/dist/node_modules/@modelcontextprotocol/sdk/node_modules/iconv-lite/lib/streams.js +105 -0
  34. package/dist/node_modules/@modelcontextprotocol/sdk/node_modules/iconv-lite/package.json +70 -0
  35. package/dist/node_modules/@modelcontextprotocol/sdk/node_modules/iconv-lite/types/encodings.d.ts +423 -0
  36. package/dist/node_modules/@modelcontextprotocol/sdk/node_modules/raw-body/LICENSE +22 -0
  37. package/dist/node_modules/@modelcontextprotocol/sdk/node_modules/raw-body/README.md +223 -0
  38. package/dist/node_modules/@modelcontextprotocol/sdk/node_modules/raw-body/index.d.ts +85 -0
  39. package/dist/node_modules/@modelcontextprotocol/sdk/node_modules/raw-body/index.js +336 -0
  40. package/dist/node_modules/@modelcontextprotocol/sdk/node_modules/raw-body/package.json +46 -0
  41. package/dist/node_modules/@modelcontextprotocol/sdk/node_modules/statuses/HISTORY.md +87 -0
  42. package/dist/node_modules/@modelcontextprotocol/sdk/node_modules/statuses/LICENSE +23 -0
  43. package/dist/node_modules/@modelcontextprotocol/sdk/node_modules/statuses/README.md +139 -0
  44. package/dist/node_modules/@modelcontextprotocol/sdk/node_modules/statuses/codes.json +65 -0
  45. package/dist/node_modules/@modelcontextprotocol/sdk/node_modules/statuses/index.js +146 -0
  46. package/dist/node_modules/@modelcontextprotocol/sdk/node_modules/statuses/package.json +49 -0
  47. package/dist/node_modules/light-my-request/package.json +1 -1
  48. package/dist/node_modules/openapi-types/package.json +1 -1
  49. package/dist/server/mcp-server.js +3 -4
  50. package/dist/server/mcp-tools.js +0 -56
  51. package/dist/server/plugin.d.ts +1 -10
  52. package/dist/server/plugin.js +4 -116
  53. package/package.json +2 -3
  54. package/dist/node_modules/fast-uri/.gitattributes +0 -2
  55. package/dist/node_modules/fast-uri/.github/.stale.yml +0 -21
  56. package/dist/node_modules/fast-uri/.github/dependabot.yml +0 -13
  57. package/dist/node_modules/fast-uri/.github/tests_checker.yml +0 -8
  58. package/dist/node_modules/fast-uri/.github/workflows/ci.yml +0 -23
  59. package/dist/node_modules/fast-uri/.github/workflows/package-manager-ci.yml +0 -20
  60. package/dist/node_modules/fast-uri/LICENSE +0 -30
  61. package/dist/node_modules/fast-uri/README.md +0 -125
  62. package/dist/node_modules/fast-uri/benchmark.js +0 -105
  63. package/dist/node_modules/fast-uri/index.js +0 -303
  64. package/dist/node_modules/fast-uri/lib/schemes.js +0 -188
  65. package/dist/node_modules/fast-uri/lib/scopedChars.js +0 -30
  66. package/dist/node_modules/fast-uri/lib/utils.js +0 -242
  67. package/dist/node_modules/fast-uri/package.json +0 -39
  68. package/dist/node_modules/fast-uri/test/.gitkeep +0 -0
  69. package/dist/node_modules/fast-uri/test/ajv.test.js +0 -39
  70. package/dist/node_modules/fast-uri/test/compatibility.test.js +0 -131
  71. package/dist/node_modules/fast-uri/test/equal.test.js +0 -103
  72. package/dist/node_modules/fast-uri/test/parse.test.js +0 -318
  73. package/dist/node_modules/fast-uri/test/resolve.test.js +0 -75
  74. package/dist/node_modules/fast-uri/test/serialize.test.js +0 -143
  75. package/dist/node_modules/fast-uri/test/uri-js.test.js +0 -912
  76. package/dist/node_modules/fast-uri/test/util.test.js +0 -23
  77. package/dist/node_modules/fast-uri/types/index.d.ts +0 -53
  78. package/dist/node_modules/fast-uri/types/index.test-d.ts +0 -17
@@ -34,139 +34,29 @@ var import_server = require("@nocobase/server");
34
34
  var import_mcp_tools = require("./mcp-tools");
35
35
  var import_mcp_server = require("./mcp-server");
36
36
  var import_crud_tool = require("./crud-tool");
37
- function normalizeBasePath(path = "") {
38
- const normalized = path.replace(/\/+/g, "/").replace(/\/$/, "");
39
- return normalized || "/";
40
- }
41
37
  class PluginMcpServerServer extends import_server.Plugin {
42
38
  mcpServer;
43
- mcpScopes = ["mcp", "offline_access"];
44
- getApiBasePath() {
45
- return normalizeBasePath(process.env.API_BASE_PATH || "/api");
46
- }
47
- getMcpPath() {
48
- return `${this.getApiBasePath()}/mcp`;
49
- }
50
- getIdpOauthPlugin() {
51
- return this.app.pm.get("idp-oauth");
52
- }
53
- getOauthMetadata(ctx) {
54
- var _a, _b;
55
- const issuer = (_b = (_a = this.getIdpOauthPlugin()) == null ? void 0 : _a.service) == null ? void 0 : _b.getProviderContext(ctx).issuer;
56
- if (!issuer) {
57
- return void 0;
58
- }
59
- return {
60
- issuer,
61
- resource: `${issuer}/mcp`,
62
- resourceMetadataUrl: `${issuer}/.well-known/oauth-protected-resource`
63
- };
64
- }
65
- rewriteUnauthorizedResponse(ctx) {
66
- const metadata = this.getOauthMetadata(ctx);
67
- if (metadata) {
68
- ctx.set(
69
- "WWW-Authenticate",
70
- `Bearer resource_metadata="${metadata.resourceMetadataUrl}", scope="${this.mcpScopes.join(" ")}"`
71
- );
72
- }
73
- ctx.withoutDataWrapping = true;
74
- ctx.type = "application/json";
75
- ctx.status = 401;
76
- ctx.body = {
77
- errors: [{ message: "Authentication required" }]
78
- };
79
- }
80
- registerProtectedResourceMetadataRoute() {
81
- const metadataPath = `${this.getApiBasePath()}/.well-known/oauth-protected-resource`;
82
- this.app.use(
83
- async (ctx, next) => {
84
- if (ctx.path !== metadataPath || ctx.method !== "GET") {
85
- await next();
86
- return;
87
- }
88
- const metadata = this.getOauthMetadata(ctx);
89
- if (!metadata) {
90
- await next();
91
- return;
92
- }
93
- ctx.withoutDataWrapping = true;
94
- ctx.type = "application/json";
95
- ctx.body = {
96
- resource: metadata.resource,
97
- authorization_servers: [metadata.issuer],
98
- scopes_supported: [...this.mcpScopes]
99
- };
100
- },
101
- {
102
- tag: "mcp-oauth-protected-resource",
103
- before: "dataWrapping"
104
- }
105
- );
106
- }
107
- registerIdpResource() {
108
- var _a, _b;
109
- (_b = (_a = this.getIdpOauthPlugin()) == null ? void 0 : _a.service) == null ? void 0 : _b.registerResourceServer("mcp", {
110
- path: "/mcp",
111
- scope: this.mcpScopes.join(" "),
112
- accessTokenFormat: "jwt",
113
- jwt: {
114
- sign: { alg: "RS256" }
115
- }
116
- });
117
- }
118
- unregisterIdpResource() {
119
- var _a, _b, _c;
120
- (_c = (_b = (_a = this.getIdpOauthPlugin()) == null ? void 0 : _a.service) == null ? void 0 : _b.unregisterResourceServer) == null ? void 0 : _c.call(_b, "mcp");
121
- }
122
- async registerMcpTools() {
39
+ registerMcpTools = async () => {
123
40
  const apiTools = await (0, import_mcp_tools.collectMcpToolsFromSwagger)({
124
41
  app: this.app
125
42
  });
126
43
  this.ai.mcpToolsManager.registerTools([...apiTools, (0, import_crud_tool.createCrudTool)({ app: this.app })]);
127
- }
44
+ };
128
45
  async afterAdd() {
129
46
  }
130
47
  async beforeLoad() {
131
48
  }
132
49
  async load() {
133
- var _a;
134
50
  await this.registerMcpTools();
135
- if ((_a = this.getIdpOauthPlugin()) == null ? void 0 : _a.service) {
136
- this.registerIdpResource();
137
- this.registerProtectedResourceMetadataRoute();
138
- }
139
51
  this.mcpServer = new import_mcp_server.McpServer({
140
52
  name: "nocobase-mcp-server",
141
53
  version: this.options.version || "0.0.0",
142
54
  toolsManager: this.ai.mcpToolsManager,
143
55
  logger: this.log
144
56
  });
145
- this.app.use(
146
- async (ctx, next) => {
147
- if (ctx.path !== this.getMcpPath()) {
148
- return next();
149
- }
150
- try {
151
- await next();
152
- } catch (error) {
153
- if (ctx.status === 401 || (error == null ? void 0 : error.status) === 401 || (error == null ? void 0 : error.statusCode) === 401) {
154
- this.rewriteUnauthorizedResponse(ctx);
155
- return;
156
- }
157
- throw error;
158
- }
159
- if (ctx.status === 401) {
160
- this.rewriteUnauthorizedResponse(ctx);
161
- }
162
- },
163
- {
164
- tag: "mcp-unauthorized-response",
165
- before: "dataSource"
166
- }
167
- );
168
- const mcpHandler = async (ctx) => {
57
+ const mcpHandler = async (ctx, next) => {
169
58
  await this.mcpServer.handlePost(ctx);
59
+ await next();
170
60
  };
171
61
  this.app.resourceManager.define({
172
62
  name: "mcp",
@@ -185,10 +75,8 @@ class PluginMcpServerServer extends import_server.Plugin {
185
75
  async afterEnable() {
186
76
  }
187
77
  async afterDisable() {
188
- this.unregisterIdpResource();
189
78
  }
190
79
  async remove() {
191
- this.unregisterIdpResource();
192
80
  }
193
81
  }
194
82
  var plugin_default = PluginMcpServerServer;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@nocobase/plugin-mcp-server",
3
3
  "main": "dist/server/index.js",
4
- "version": "2.1.0-alpha.10",
4
+ "version": "2.1.0-alpha.9",
5
5
  "displayName": "AI: MCP server",
6
6
  "displayName.zh-CN": "AI: MCP 服务器",
7
7
  "description": "An MCP server for building NocoBase systems and supporting business workflows.",
@@ -16,12 +16,11 @@
16
16
  "@modelcontextprotocol/sdk": "^1.27.1",
17
17
  "@nocobase/ai": "2.x",
18
18
  "@nocobase/client": "2.x",
19
- "@nocobase/plugin-idp-oauth": "2.x",
20
19
  "@nocobase/server": "2.x",
21
20
  "@nocobase/test": "2.x"
22
21
  },
23
22
  "keywords": [
24
23
  "AI"
25
24
  ],
26
- "gitHead": "ce790d46c0a5768ca9618c7d0d77ab8300de75c8"
25
+ "gitHead": "f9c6c53772bd5002fa419188d15ab227224f1962"
27
26
  }
@@ -1,2 +0,0 @@
1
- # Set default behavior to automatically convert line endings
2
- * text=auto eol=lf
@@ -1,21 +0,0 @@
1
- # Number of days of inactivity before an issue becomes stale
2
- daysUntilStale: 15
3
- # Number of days of inactivity before a stale issue is closed
4
- daysUntilClose: 7
5
- # Issues with these labels will never be considered stale
6
- exemptLabels:
7
- - "discussion"
8
- - "feature request"
9
- - "bug"
10
- - "help wanted"
11
- - "plugin suggestion"
12
- - "good first issue"
13
- # Label to use when marking an issue as stale
14
- staleLabel: stale
15
- # Comment to post when marking an issue as stale. Set to `false` to disable
16
- markComment: >
17
- This issue has been automatically marked as stale because it has not had
18
- recent activity. It will be closed if no further activity occurs. Thank you
19
- for your contributions.
20
- # Comment to post when closing a stale issue. Set to `false` to disable
21
- closeComment: false
@@ -1,13 +0,0 @@
1
- version: 2
2
- updates:
3
- - package-ecosystem: "github-actions"
4
- directory: "/"
5
- schedule:
6
- interval: "monthly"
7
- open-pull-requests-limit: 10
8
-
9
- - package-ecosystem: "npm"
10
- directory: "/"
11
- schedule:
12
- interval: "weekly"
13
- open-pull-requests-limit: 10
@@ -1,8 +0,0 @@
1
- comment: |
2
- Hello! Thank you for contributing!
3
- It appears that you have changed the code, but the tests that verify your change are missing. Could you please add them?
4
- fileExtensions:
5
- - '.ts'
6
- - '.js'
7
-
8
- testDir: 'test'
@@ -1,23 +0,0 @@
1
- name: CI
2
-
3
- on:
4
- push:
5
- branches:
6
- - main
7
- - master
8
- - next
9
- - 'v*'
10
- paths-ignore:
11
- - 'docs/**'
12
- - '*.md'
13
- pull_request:
14
- paths-ignore:
15
- - 'docs/**'
16
- - '*.md'
17
-
18
- jobs:
19
- test:
20
- uses: fastify/workflows/.github/workflows/plugins-ci.yml@v5.0.0
21
- with:
22
- license-check: true
23
- node-versions: '["16", "18", "20", "22"]'
@@ -1,20 +0,0 @@
1
- name: package-manager-ci
2
-
3
- on:
4
- push:
5
- branches:
6
- - main
7
- - master
8
- - next
9
- - 'v*'
10
- paths-ignore:
11
- - 'docs/**'
12
- - '*.md'
13
- pull_request:
14
- paths-ignore:
15
- - 'docs/**'
16
- - '*.md'
17
-
18
- jobs:
19
- test:
20
- uses: fastify/workflows/.github/workflows/plugins-ci-package-manager.yml@v5.0.0
@@ -1,30 +0,0 @@
1
- Copyright (c) 2021 The Fastify Team
2
- Copyright (c) 2011-2021, Gary Court until https://github.com/garycourt/uri-js/commit/a1acf730b4bba3f1097c9f52e7d9d3aba8cdcaae
3
- All rights reserved.
4
-
5
- Redistribution and use in source and binary forms, with or without
6
- modification, are permitted provided that the following conditions are met:
7
- * Redistributions of source code must retain the above copyright
8
- notice, this list of conditions and the following disclaimer.
9
- * Redistributions in binary form must reproduce the above copyright
10
- notice, this list of conditions and the following disclaimer in the
11
- documentation and/or other materials provided with the distribution.
12
- * The names of any contributors may not be used to endorse or promote
13
- products derived from this software without specific prior written
14
- permission.
15
-
16
- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
17
- ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18
- WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19
- DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS AND CONTRIBUTORS BE LIABLE FOR ANY
20
- DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21
- (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22
- LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23
- ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24
- (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25
- SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26
-
27
- * * *
28
-
29
- The complete list of contributors can be found at:
30
- - https://github.com/garycourt/uri-js/graphs/contributors
@@ -1,125 +0,0 @@
1
- # fast-uri
2
-
3
- <div align="center">
4
-
5
- [![CI](https://github.com/fastify/fast-uri/actions/workflows/ci.yml/badge.svg)](https://github.com/fastify/fast-uri/actions/workflows/ci.yml)
6
- [![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat)](https://standardjs.com/)
7
-
8
- </div>
9
-
10
- Dependency free RFC 3986 URI toolbox.
11
-
12
- ## Usage
13
-
14
- ## Options
15
-
16
- All of the above functions can accept an additional options argument that is an object that can contain one or more of the following properties:
17
-
18
- * `scheme` (string)
19
- Indicates the scheme that the URI should be treated as, overriding the URI's normal scheme parsing behavior.
20
-
21
- * `reference` (string)
22
- If set to `"suffix"`, it indicates that the URI is in the suffix format and the parser will use the option's `scheme` property to determine the URI's scheme.
23
-
24
- * `tolerant` (boolean, false)
25
- If set to `true`, the parser will relax URI resolving rules.
26
-
27
- * `absolutePath` (boolean, false)
28
- If set to `true`, the serializer will not resolve a relative `path` component.
29
-
30
- * `unicodeSupport` (boolean, false)
31
- If set to `true`, the parser will unescape non-ASCII characters in the parsed output as per [RFC 3987](http://www.ietf.org/rfc/rfc3987.txt).
32
-
33
- * `domainHost` (boolean, false)
34
- If set to `true`, the library will treat the `host` component as a domain name, and convert IDNs (International Domain Names) as per [RFC 5891](http://www.ietf.org/rfc/rfc5891.txt).
35
-
36
- ### Parse
37
-
38
- ```js
39
- const uri = require('fast-uri')
40
- uri.parse('uri://user:pass@example.com:123/one/two.three?q1=a1&q2=a2#body')
41
- // Output
42
- {
43
- scheme : "uri",
44
- userinfo : "user:pass",
45
- host : "example.com",
46
- port : 123,
47
- path : "/one/two.three",
48
- query : "q1=a1&q2=a2",
49
- fragment : "body"
50
- }
51
- ```
52
-
53
- ### Serialize
54
-
55
- ```js
56
- const uri = require('fast-uri')
57
- uri.serialize({scheme : "http", host : "example.com", fragment : "footer"})
58
- // Output
59
- "http://example.com/#footer"
60
-
61
- ```
62
-
63
- ### Resolve
64
-
65
- ```js
66
- const uri = require('fast-uri')
67
- uri.resolve("uri://a/b/c/d?q", "../../g")
68
- // Output
69
- "uri://a/g"
70
- ```
71
-
72
- ### Equal
73
-
74
- ```js
75
- const uri = require('fast-uri')
76
- uri.equal("example://a/b/c/%7Bfoo%7D", "eXAMPLE://a/./b/../b/%63/%7bfoo%7d")
77
- // Output
78
- true
79
- ```
80
-
81
- ## Scheme supports
82
-
83
- fast-uri supports inserting custom [scheme](http://en.wikipedia.org/wiki/URI_scheme) dependent processing rules. Currently, fast-uri has built in support for the following schemes:
84
-
85
- * http \[[RFC 2616](http://www.ietf.org/rfc/rfc2616.txt)\]
86
- * https \[[RFC 2818](http://www.ietf.org/rfc/rfc2818.txt)\]
87
- * ws \[[RFC 6455](http://www.ietf.org/rfc/rfc6455.txt)\]
88
- * wss \[[RFC 6455](http://www.ietf.org/rfc/rfc6455.txt)\]
89
- * urn \[[RFC 2141](http://www.ietf.org/rfc/rfc2141.txt)\]
90
- * urn:uuid \[[RFC 4122](http://www.ietf.org/rfc/rfc4122.txt)\]
91
-
92
-
93
- ## Benchmarks
94
-
95
- ```
96
- fast-uri: parse domain x 1,306,864 ops/sec ±0.31% (100 runs sampled)
97
- urijs: parse domain x 483,001 ops/sec ±0.09% (99 runs sampled)
98
- WHATWG URL: parse domain x 862,461 ops/sec ±0.18% (97 runs sampled)
99
- fast-uri: parse IPv4 x 2,381,452 ops/sec ±0.26% (96 runs sampled)
100
- urijs: parse IPv4 x 384,705 ops/sec ±0.34% (99 runs sampled)
101
- WHATWG URL: parse IPv4 NOT SUPPORTED
102
- fast-uri: parse IPv6 x 923,519 ops/sec ±0.09% (100 runs sampled)
103
- urijs: parse IPv6 x 289,070 ops/sec ±0.07% (95 runs sampled)
104
- WHATWG URL: parse IPv6 NOT SUPPORTED
105
- fast-uri: parse URN x 2,596,395 ops/sec ±0.42% (98 runs sampled)
106
- urijs: parse URN x 1,152,412 ops/sec ±0.09% (97 runs sampled)
107
- WHATWG URL: parse URN x 1,183,307 ops/sec ±0.38% (100 runs sampled)
108
- fast-uri: parse URN uuid x 1,666,861 ops/sec ±0.10% (98 runs sampled)
109
- urijs: parse URN uuid x 852,724 ops/sec ±0.17% (95 runs sampled)
110
- WHATWG URL: parse URN uuid NOT SUPPORTED
111
- fast-uri: serialize uri x 1,741,499 ops/sec ±0.57% (95 runs sampled)
112
- urijs: serialize uri x 389,014 ops/sec ±0.28% (93 runs sampled)
113
- fast-uri: serialize IPv6 x 441,095 ops/sec ±0.37% (97 runs sampled)
114
- urijs: serialize IPv6 x 255,443 ops/sec ±0.58% (94 runs sampled)
115
- fast-uri: serialize ws x 1,448,667 ops/sec ±0.25% (97 runs sampled)
116
- urijs: serialize ws x 352,884 ops/sec ±0.08% (96 runs sampled)
117
- fast-uri: resolve x 340,084 ops/sec ±0.98% (98 runs sampled)
118
- urijs: resolve x 225,759 ops/sec ±0.37% (95 runs sampled)
119
- ```
120
-
121
- ## TODO
122
-
123
- - [ ] Support MailTo
124
- - [ ] Be 100% iso compatible with uri-js
125
- - [ ] Add browser test stack
@@ -1,105 +0,0 @@
1
- 'use strict'
2
-
3
- const benchmark = require('benchmark')
4
- const suite = new benchmark.Suite()
5
- const fasturi = require('./')
6
- const urijs = require('uri-js')
7
-
8
- const base = 'uri://a/b/c/d;p?q'
9
-
10
- const domain = 'https://example.com/foo#bar$fiz'
11
- const ipv4 = '//10.10.10.10'
12
- const ipv6 = '//[2001:db8::7]'
13
- const urn = 'urn:foo:a123,456'
14
- const urnuuid = 'urn:uuid:f81d4fae-7dec-11d0-a765-00a0c91e6bf6'
15
-
16
- // Initialization as there is a lot to parse at first
17
- // eg: regexes
18
- fasturi.parse(domain)
19
- urijs.parse(domain)
20
-
21
- suite.add('fast-uri: parse domain', function () {
22
- fasturi.parse(domain)
23
- })
24
- suite.add('urijs: parse domain', function () {
25
- urijs.parse(domain)
26
- })
27
- suite.add('WHATWG URL: parse domain', function () {
28
- // eslint-disable-next-line
29
- new URL(domain)
30
- })
31
- suite.add('fast-uri: parse IPv4', function () {
32
- fasturi.parse(ipv4)
33
- })
34
- suite.add('urijs: parse IPv4', function () {
35
- urijs.parse(ipv4)
36
- })
37
- suite.add('fast-uri: parse IPv6', function () {
38
- fasturi.parse(ipv6)
39
- })
40
- suite.add('urijs: parse IPv6', function () {
41
- urijs.parse(ipv6)
42
- })
43
- suite.add('fast-uri: parse URN', function () {
44
- fasturi.parse(urn)
45
- })
46
- suite.add('urijs: parse URN', function () {
47
- urijs.parse(urn)
48
- })
49
- suite.add('WHATWG URL: parse URN', function () {
50
- // eslint-disable-next-line
51
- new URL(urn)
52
- })
53
- suite.add('fast-uri: parse URN uuid', function () {
54
- fasturi.parse(urnuuid)
55
- })
56
- suite.add('urijs: parse URN uuid', function () {
57
- urijs.parse(urnuuid)
58
- })
59
- suite.add('fast-uri: serialize uri', function () {
60
- fasturi.serialize({
61
- scheme: 'uri',
62
- userinfo: 'foo:bar',
63
- host: 'example.com',
64
- port: 1,
65
- path: 'path',
66
- query: 'query',
67
- fragment: 'fragment'
68
- })
69
- })
70
- suite.add('urijs: serialize uri', function () {
71
- urijs.serialize({
72
- scheme: 'uri',
73
- userinfo: 'foo:bar',
74
- host: 'example.com',
75
- port: 1,
76
- path: 'path',
77
- query: 'query',
78
- fragment: 'fragment'
79
- })
80
- })
81
- suite.add('fast-uri: serialize IPv6', function () {
82
- fasturi.serialize({ host: '2606:2800:220:1:248:1893:25c8:1946' })
83
- })
84
- suite.add('urijs: serialize IPv6', function () {
85
- urijs.serialize({ host: '2606:2800:220:1:248:1893:25c8:1946' })
86
- })
87
- suite.add('fast-uri: serialize ws', function () {
88
- fasturi.serialize({ scheme: 'ws', host: 'example.com', resourceName: '/foo?bar', secure: true })
89
- })
90
- suite.add('urijs: serialize ws', function () {
91
- urijs.serialize({ scheme: 'ws', host: 'example.com', resourceName: '/foo?bar', secure: true })
92
- })
93
- suite.add('fast-uri: resolve', function () {
94
- fasturi.resolve(base, '../../../g')
95
- })
96
- suite.add('urijs: resolve', function () {
97
- urijs.resolve(base, '../../../g')
98
- })
99
- suite.on('cycle', cycle)
100
-
101
- suite.run()
102
-
103
- function cycle (e) {
104
- console.log(e.target.toString())
105
- }